Download presentation
Presentation is loading. Please wait.
Published byJoseph Cobb Modified over 8 years ago
1
RTOS Implementation - 2006. 12. 18. - Yeon YoonMo
2
Focus RTOS context switch process from the bottom up used example The FreeRTOS Atmel AVR microcontroller port WinAVR development tools
3
The RTOS Tick time measurement is needed sleeping task : waking time blocked task : maximum waiting time tickmeasure time using a tick count variable
4
Tick ISR
5
GCC Signal Attribute interrupts written in C A compare match event on the AVR timer 1 peripheral __attribute__((signal)) modifiedregister that gets modified during the ISR is restored to its original value when the ISR exits a 'return from interrupt' instruction (RETI) to be used
6
code output
7
GCC Naked Attribute entire contextPerforming a context switch requires the entire context to be saved explicitly save all registers → some registers being saved twice The 'naked' attribute prevents the compiler generating any function entry or exit code
8
code output (naked)
9
save & restore context portSAVE_CONTEXT() portRESTORE_CONTEXT()
10
FreeRTOS Tick Code void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void vPortYieldFromTick( void ) __attribute__ ( ( naked ) ); void SIG_OUTPUT_COMPARE1A( void ) { vPortYieldFromTick(); asm volatile ( "reti" ); } void vPortYieldFromTick( void ) { portSAVE_CONTEXT(); vTaskIncrementTick(); vTaskSwitchContext(); portRESTORE_CONTEXT(); asm volatile ( "ret" ); }
11
The AVR Context
12
Saving the Context
13
Restoring the Context
14
Detailed Example a context switch on the AVR microcontroller two tasks low priority : task A high priority :task B
15
Step 1
16
Step 2
17
Step 3
18
Step 4 Incrementing the Tick Count after the TaskA context has been saved vTaskIncrementTick(); TaskBreadyTaskB(higher priority) to become ready to run vTaskSwitchContext() ;
19
Step 5
20
Step 6
21
Step 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.