Introduction In this lab , we will learn

Slides:



Advertisements
Similar presentations
Real-Time Library: RTX
Advertisements

Lab7: Introduction to Arduino
FreeRTOS.
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Operating Systems Process Scheduling (Ch 3.2, )
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
MicroC/OS-II Embedded Systems Design and Implementation.
Lab 5b: Traffic Stoplight. BYU CS 124RBX4302 Program a pedestrian traffic light for a street with a crosswalk. Use the large red, yellow, and green LEDs.
FreeRTOS.
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
Outline Introduction to MQX Initializing and starting MQX
Real Time Operating System
LAB 8: Program Design Pattern and Software Architecture
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
FreeRTOS.
LAB 12: Timer and Interrupt Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Bit-DSP-MicrocontrollerTMS320F2812 Texas Instruments Incorporated European Customer Training Center University of Applied Sciences Zwickau (FH)
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
Implementation of Embedded OS Lab3 Porting μC/OS-II.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
1 J.O. KLEIN Institut Universitaire de Technologie de CACHAN Université PARIS SUD - FRANCE An Introduction to Real Time Operating System.
1 Round Robin Non-Preemptive Scheduler Lecture 12.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Task Management 김백규. Task states(1/2)  Running  currently utilising the processor.  Ready  tasks are those that are able to execute.  they are not.
LPC2148's RTOS Bruce Chhuon 4/10/07. What is a Real Time Operating System? ● A Real Time Operating System (RTOS) manages hardware and software resources.
MQX GPIO.
Real-time Software Design
Lab 7 Basic 1: Game of Memory
Introduction In this lab , we will learn
Outline Introduction to task synchronization Queues of FreeRTOS
REAL-TIME OPERATING SYSTEMS
CS4101 嵌入式系統概論 General Purpose IO
Val Manes Department of Math & Computer Science
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
CS4101 Introduction to Embedded Systems Lab 8: Tower System
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
CS4101 嵌入式系統概論 Real-Time Operating System
Implementation of Embedded OS
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
Topics Covered What is Real Time Operating System (RTOS)
CS4101 Introduction to Embedded Systems Lab 12: Task Synchronization
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
MCTS Guide to Microsoft Windows 7
Prof. Chung-Ta King Department of Computer Science
Interrupt and Time Management in µC/OS-III
Round Robin Non-Preemptive Scheduler
CS4101 Introduction to Embedded Systems Lab 9: NuMaker ADC and LCD
CS4101 嵌入式系統概論 General Purpose IO
CS4101 嵌入式系統概論 Tasks and Scheduling
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
Real-time Software Design
Writing and Testing Your First RTOS Project with MQX
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
An Embedded Software Primer
Processor Fundamentals
Tonga Institute of Higher Education
ECE 3567 Microcontroller Lab
Stata Basic Course Lab 2.
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
Computer System Laboratory
Introduction to FreeRTOS
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 11: FreeRTOS Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan (Materials are from http://www.freertos.org/RTOS.html)

Introduction In this lab , we will learn How to manage tasks and timers in FreeRTOS? How to port FreeRTOS onto NuMaker TRIO?

Real Time Systems Real time/embedded systems are designed to provide a timely response to real world events Events occurring in the real world can have deadlines before which the real time/embedded system must respond The RTOS scheduling policy must ensure these deadlines are met It is thus important to decide how time is measured and tracked

Time in FreeRTOS FreeRTOS measures time using a tick count variable A timer interrupt (the RTOS tick interrupt) increments the tick count with strict temporal accuracy This allows FreeRTOS to measure time to a resolution of the chosen timer interrupt frequency, configured by the configTICK_RATE_HZ constant in FreeRTOSConfig.h FreeRTOS API calls always specify time in tick interrupts (or ‘ticks’) The portTICK_RATE_MS constant is provided to allow time delays to be converted from the number of tick interrupts into milliseconds

Task Scheduling in FreeRTOS FreeRTOS scheduling: Each time the tick count is incremented, FreeRTOS checks to see if it is now time to unblock or wake a task If the task woken or unblocked during the tick ISR has a priority higher than that of the interrupted task, the newly woken/unblocked task is scheduled to run Such a context switch is said to be preemptive  fixed priority preemptive scheduling

Timers in FreeRTOS FreeRTOS uses software timer Specify a function, called the timer’s callback function, to be executed at a set time in the future Timer must be explicitly created before it can be used It is essential that timer callback functions never attempt to block, e.g., must not call vTaskDelay(), vTaskDelayUntil() Timer functionality provided by a timer service task A set of timer related APIs are provided that use a standard FreeRTOS queue to send commands to the timer service task

Timers in FreeRTOS One-shot timer Auto-reload timer Execute callback function only once and  can be manually re-started Auto-reload timer Automatically restart itself after each execution of its callback function, resulting in periodic callback executions

Timers Configuration (FreeRTOSConfig.h) /* Software timer definitions. */ /* Set to 1 to include timer functionality. */ #define configUSE_TIMERS 1 /* Sets the priority of the timer service task. */ #define configTIMER_TASK_PRIORITY ( 2 ) /* This sets the maximum number of unprocessed commands that the timer command queue can hold at any one time. */ #define configTIMER_QUEUE_LENGTH 5 /* Sets the size of the stack allocated to the timer service task. */ #define configTIMER_TASK_STACK_DEPTH ( 80 )

Example: Create a Timer int main(void) { TimerHandle_t xTimer = NULL; unsigned long ulTimer = 1UL; xTimer = xTimerCreate( "Timer", /* A text name to help debugging */ 1000/portTICK_RATE_MS, /* Timer period, i.e. 1 s */ pdTRUE, /* Timer type, auto-reload or one-shot*/ (void *) pvTimerID, /* Identifier of created timer */ TimerCallbackFunc /* Callback function */ ); if( xTimer != NULL ) { xTimerStart(xTimer, 0); } ulTimer = (unsigned long) 1

Example: Create a Timer void TimerCallbackFunc(TimerHandle_t xTimer) { unsigned long index; /* Identify which timer calls this function */ index = (unsigned long) pvTimerGetTimerID(xTimer); /* Toggle the LED */ GPIO_TOGGLE(PB15); }

Port FreeRTOS onto NuMaker TRIO Download FreeRTOS source code http://sourceforge.net/projects/freertos/files/latest/down load?source=files Use smpl_Debug project of NuMaker as an example below Add head file path into NuMaker project <FreeRTOS>\Source\include <FreeRTOS>\Source\portable\RVDS\ARM_CM0 <FreeRTOS>\Demo\CORTEX_M0_STM32F0518_IAR

Port FreeRTOS onto NuMaker TRIO 1. Click here to call out Options window 2. Click here to add head file path

Port FreeRTOS onto NuMaker TRIO 1. Add new path 2. Find the path

Port FreeRTOS onto NuMaker TRIO

Port FreeRTOS into NuMaker TRIO Add a new Group in the project Add source file into project <FreeRTOS>\Source\<all> <FreeRTOS>\Source\portable\MemMang\heap1.c <FreeRTOS>\Source\portable\RVDS\AMR_M0\port.c

Port FreeRTOS onto NuMaker TRIO 1. Right click to add new Group 2. Double click to add source code

Port FreeRTOS onto NuMaker TRIO Modify <FreeRTOS>/Demo/CORTEX_M0_STM32F0518_IAR /FreeRTOSConfig.h Add #include "Nano1X2Series.h " modify configMINIMAL_STACK_SIZE from 60 to 128 modify configTOTAL_HEAP_SIZE from 6500 to 5*1024 Modify configCHECK_FOR_STACK_OVERFLOW from 2 to 0 Modify <FreeRTOS>/Source/portable/RVDS/ARM_CM0/port.c  Add #include "Nano1X2Series.h"

Sample Code int main(void){ SYS_Init(); GPIOInit(); // Initial GPIO // Create myTask1() with priority 2 // Priorities: Higher numbers are higher priority xTaskCreate(myTask1, "LED1", configMINIMAL_STACK_SIZE, NULL, 2, NULL); //Create myTask2() xTaskCreate(myTask2, "LED2", configMINIMAL_STACK_SIZE, vTaskStartScheduler(); // Start Scheduling /* Will only get here if there was insufficient memory to create the idle task. */ while(1); }

Sample Code void myTask1(){ // Task 1 portTickType xLastWakeTime = xTaskGetTickCount(); while(1){ GPIO_TOGGLE(PA14); // Toggle LED vTaskDelayUntil(&xLastWakeTime, (1000/portTICK_RATE_MS)); // Delay 1000 ms } void myTask2(){ // Task 2 GPIO_TOGGLE(PB15); // Toggle LED (500/portTICK_RATE_MS)); // Delay 500 ms

Lab: Basic 1 Port FreeRTOS onto your NuMaker TRIO Run the sample code successfully Modify the sample code to use two timers instead of two tasks FreeRTOS API http://www.freertos.org/modules.html#API_reference

Lab: Basic 2 Create three tasks Task 1: run every second to do a dumb loop 1000 times and print 0, 1, …, 9 in round robin on the display Task 2: run every 2 seconds to do a dumb loop 500 times and print a, b, …, z in round robin on the display Task 3: run every 0.5 second to detect if light is blocked; if so, print “Dark” on the display, else print “Bright” Remember to clear the display before you print Observe what happen if all three tasks have the same priority. Set the priority of task 3 higher and observe whether the system responds to light changes better.

Lab: Bonus Use FreeRTOS to complete Basic 2 of Lab 8 The traffic light will change to the green light when there is an ambulance passing. Let the blue LED represent the yellow traffic light, and the buzzer indicates the passing of an ambulance. Normally the red LED is on for 3 sec, then the blue LED is on for 2 sec, then the green LED is on for 4 sec, and repeat. The buzzer will be turned on for 4 sec in 2 Hz. The on time is set randomly between 6 and 15 sec. When the buzzer is on, the traffic light will be turned to the green LED. After the buzzer is turned off, the traffic light turns to normal.