ARM RTX Real-Time Operating System
ARM RTX Real-Time Operating System
Agenda
Agenda: CMSIS Super-loop vs. RTOS Round Robin RTOS Create a Project Debugging Cooperative Multitasking RTOS Objects Semaphore Example Interrupts Preemptive Task Switching
CMSIS:
CMSIS-Core CMSIS-DSP
Standard header files for various Cortex-M processors. Simplify startup routines. Startup.s and system.c System View Description (SVD) XML files. (peripherals)
Digital Signal processing libraries Free for Cortex-M0, M3 and M4
Version 3.0
CMSIS-RTOS CMSIS-DAP
A standard API for RTOSs Includes RTX a BSD license this means it if free A standard to connect on-board debug adapters Uses USB and a small processor on the PC board.
Bytes <4K
< 500
250
< 200 Cycles Not Applicable for Cortex M
RAM Space
(each active task requires an own stack space)
RTX Performance
Task Specifications
Interupt Latency
Cycles
n/a
1,147
403
461
218 192 89
Send semaphore
72
RTX MODES
Round Robin:
Each task given a time slice. When slice is up switches to next task. If task not done will complete it later.
Pre-emptive:
Co-operative:
Uses DAP R/W if using a real chip Shows what is running and waiting etc. Updates in real-time.
With the Simulator or if chip uses SWV. Updates in real-time. Shows when tasks operating.
Can zoom in to look at times. Very useful for debugging and configuring RX
NOTE: Cortex-M use SysTick Timer. Is Interrupt 15. RTX uses SVCall instruction to access privileged
resources. Is Interrupt 11. RTX will use special features of Cortex-M for most efficient operation.
OSTID t_phaseA;
os_tsk_delete_self ();
os_dly_wait (8);
(number of SysTick ticks) (10 msec) Task is put in WAIT_DLY state. When Delay done, is put in READY state.
Events:
Send event signal to clock task:
os_evt_set (0x0001, task); (bit pattern event flag number, OS_TID task name)
Wait for an event flag 0x0001
os_evt_wait_and (0x0001, 0xffff); os_evt_wait_or (0x0001, 0xffff); (event flag number, timeout value) and: waits for a number of event flags. or: waits for one event flag.
Mutex
Declare a mutex:
Interrupt 1()
Interrupt 2()
Interrupt 3()
Using a RTOS
Giving Even More Control to Your Project
Using an RTOS
Programs are made up of multiple files and functions
Main.c IO.c
Math.c
Debug info()
Using an RTOS
Functions can be grouped together logically
Main.c IO.c
Math.c
HighPri()
Init_periph() Low_pwr_check() Wait() Master_switch()
Check_ext_1()
Foo() Bar()
Test()
Do_it() Check_serial() Check_input() Check_ports()
Check_flags()
Check_clock()
Config_LCD()
Wipe_screen() Set_cursor() Write_regs() Write_row()
Set_globals()
Interupt_ISRS() Debug info()
Open_port()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
Divide() HighPri() Bar() Low_pwr_check() Check_ports() Open_port() Check_ext_1()
Check_clock() Check_serial()
Float()
Do_it()
Check_input() Wipe_screen()
Master_switch()
Set_cursor()
Write_regs() Write_row()
Check_flags()
Interupt_ISRS() Wait() Debug info()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
Divide() HighPri() Bar() Low_pwr_check() Check_ports() Open_port() Do_it() Check_input() Wipe_screen() Master_switch() Set_globals() Foo() Test() Calc_Global_foo()
Check_clock() Check_serial()
Task A
Check_ext_1()
Float()
Set_cursor()
Write_regs() Write_row()
Check_flags()
Interupt_ISRS() Wait() Debug info()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
Divide() HighPri() Bar() Low_pwr_check() Check_ports() Open_port() Do_it() Check_input() Wipe_screen() Master_switch()
Check_clock() Check_serial()
Task A
Check_ext_1()
Float()
Kernel
Check_flags()
Interupt_ISRS() Wait() Debug info()
Set_cursor()
Write_regs() Write_row()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
Divide() Config_LCD() Shift_reg() Init_periph() HighPri() Bar() Low_pwr_check() Check_ports() Open_port() Do_it()
Check_clock() Check_serial()
Task A
Check_ext_1()
Task B
Check_input() Wipe_screen()
Float()
Master_switch()
Kernel
Check_flags()
Interupt_ISRS() Wait() Debug info()
Set_cursor()
Write_regs() Write_row()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
HighPri() Bar() Low_pwr_check() Check_ports() Open_port()
Master_switch()
Task B
Check_input() Wipe_screen()
Float()
Do_it()
Set_globals() Foo()
Set_cursor()
Write_regs() Write_row()
Check_flags()
Test()
Interupt_ISRS() Wait()
Calc_Global_foo()
Debug info()
RTOS -Tasks
Logical Groups can be managed by an RTOS task Tasks can share functions
Divide() Config_LCD() Shift_reg() Init_periph()
Master_switch()
Check_clock()
Check_serial()
Check_ext_1()
Float()
Do_it()
Check_input()
Wipe_screen()
Set_globals() Foo()
Set_cursor()
Check_flags()
Test()
Interupt_ISRS() Wait()
Calc_Global_foo()
Write_regs() Write_row()
Debug info()
Creating Tasks
__task void taskA (void) { While(1) { } } __task void taskB (void) { While(1) { } } __task void taskC (void) { While(1) { } } __task void taskD (void) { While(1) { } }
Tasks are logical components of your project Tasks do not replace functions They call functions
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
Adding os_dly_wait() will force taskD to switch earlier than the Round Robin timeout
Adding os_dly_wait() will force taskD to switch earlier than the Round Robin timeout
TASK A
TASK D
TASK B
TASK C
TASK A
TASK D
os_dly_wait(20)
TASK B
TASK C
TASK A
TASK D
os_dly_wait(20)
TASK B
TASK C
TASK A
TASK D
TASK B
TASK C
WAIT_SEM WAIT_MUT
INACTIVE WAIT_MBX
Use waits and events to control your code, instead of relying on a Round robin Task switch More efficient use of your resources
Use waits and events to control your code, instead of relying on a Round robin Task switch More efficient use of your resources
RTOS Objects
Use Cooperative Multitasking for Greater Efficiency
Cooperative Multitasking
Round Robin is not scalable Cooperative Multitasking gives more flexibility The task scheduler processes all
the tasks and then puts the highest ready task into the running state The highest priority task can then continue with its execution
TASK A
TASK D
TASK B
TASK C
Cooperative Multitasking
Round Robin is not scalable Cooperative Multitasking gives more flexibility The task scheduler processes all
the tasks and then puts the highest ready task into the running state The highest priority task can then continue with its execution
TASK A
TASK D
TASK B
TASK C
__task void taskB (void) { While(1) { Printf(And were rolling, rolling, rolling down the); } __task void taskC (void) { While(1) { Printf(I tell ya, life ain't easy for a boy named Sue); }
Serial Out Oh, Swee And wer I tell y t Caroli e rollin a, life
__task void taskB (void) { While(1) { Printf(And were rolling, rolling, rolling down the); } __task void taskC (void) { While(1) { Printf(I tell ya, life ain't easy for a boy named Sue); }
__task void taskB (void) { While(1) { Printf(And were rolling, rolling, rolling down the); } __task void taskC (void) { While(1) { Printf(I tell ya, life ain't easy for a boy named Sue); }
Serial Out Oh, sweet Caroline, Good times never seem And were rolling, rolling, rolling down the
Mutexes
(Mutual exclusion locks) A software object that locks a common resource Similar to a semaphore But any task can release a semaphore token Only the task that locks the common resource can access it Big feature Priority inheritance (more later)
M M
TASK A
TASK D
TASK B
TASK C
TASK C
TASK B TASK B
TASK A
TASK A
Time
TASK A
Time slice
Preemption
TASK C
TASK B TASK B
TASK A
TASK A
Time
TASK A
THE END
That gives a brief introduction to ARM RTX !
Other Examples
Evaluation tools can be found at: www.keil.com/demo
RTX examples can be found on your hard drive at: C:\keil\ARM\RL\RTX\Examples\ RL-ARM Getting Started Guide: http://www.keil.com/rl-arm/rl-gettingstarted.asp
PRIMARY
18 140 171 149 186 205 200 217 227
ACCENT
18 140 171 253 201 134 254 225 186
159 180 59
159 180 59
145 27 29
145 27 29
109 102 95
55 55 104