Homepage  

Restoring the Context
[RTOS Implementation Building Blocks]


portRESTORE_CONTEXT() is the reverse of portSAVE_CONTEXT(). The context of the task being resumed was previously stored in the tasks stack. The real time kernel retrieves the stack pointer for the task then POP's the context back into the correct processor registers.
#define portRESTORE_CONTEXT() \ asm volatile ( "lds r26, pxCurrentTCB \n\t" \ (1) "lds r27, pxCurrentTCB + 1 \n\t" \ (2) "ld r28, x+ \n\t" \ "out __SP_L__, r28 \n\t" \ (3) "ld r29, x+ \n\t" \ "out __SP_H__, r29 \n\t" \ (4) "pop r31 \n\t" \ "pop r30 \n\t" \

: : :

"pop r1 \n\t" \ "pop r0 \n\t" \ (5) "out __SREG__, r0 \n\t" \ (6) "pop r0 \n\t" \ (7) );
Referring to the code above:

Next: RTOS Implementation - Putting It All Together


Copyright (C) 2003 - 2008 Richard Barry
Any and all data, files, source code, html content and documentation included in the FreeRTOS distribution or available on this site are the exclusive property of Richard Barry. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Richard Barry.