10.8. Advanced Topics: Context Switching in Action

To demonstrate the context switching operation in a real example, here we use a simple task scheduler that switches between four tasks in a round robin arrangement. If multiple LEDs are available, each of the tasks toggles one of the LED at different speed.
The context switching operation is carried out by the PendSV exception handler. Since the exception sequence already saved registers R0–R3, R12, LR, Return Address and xPSR, the PendSV only needs to store R4–R11 to the process stack (Figure 10.15).
image
Figure 10.15 Context switching from one task to another.
The code for the project can be implemented ...

Get The Definitive Guide to ARM® Cortex®-M0 and Cortex-M0+ Processors, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.