RTOS Manual Task Switching
RTOS Manual Task Switching
Real time operating systems are composed of various tasks. Tasks are infinite loop functions that
serve certain functionalities. The operating system Kernel switches the processor resources
(processing time, hardware peripherals, etc.) between tasks. The goal of this lab is to learn how
to manually switch between two tasks.
NOTE: The stack pointer grows upward in the ARM which means the top of stack would be the address with
the lower value. A hint : You may need to flip the image above to match the stack if the values of the stack are
put in ascending order.
Task 3: In the main function, fill the stacks created with the data to make it look as if it was
preempted by an interrupt
According to the ARM exception frame layout attached above. We shall start from the high memory end
of the stack because it grows from high to low memory.
*Refer to the datasheets for the positions of the bits.*
Step 1: Pre decrement the pointer to get to the first address location, we then need to write the THUMB bit in the PSR register
Step 2: Pre decrement the pointer again this time to write the PC. In C you can get the start address of a function using it’s name (
ex: &fun1 ) You need also to cast the pointer to make sure it fits inside the pointer ( ex: (uint32_t)&fun1 )
Step 3: The rest of the registers would not really matter a lot in the switch so for testing we shall set them to values we know so
that we can make sure these values are already copied to the registers.
Step 4: Do steps 1 to 3 again, but this time for the second task. ( Blinky LED 2 ) Step 5: Create an infinite loop at the end of the
main function.