(Note: this and the following posts use the “nanoexec” code located at http://github.com/imagecraft and in the JumpStart C for Cortex-M demo install. However, for brevity, some details and data structure fields are omitted.)

Writing a basic multitasking executive is a fairly simple exercise. The basic concept is that a CPU runs a "task" - which is a sequence of code (e.g. a function running an infinite loop) - that, at some point, switches to another task. If task switching (also known as context switching) occurs only when a task explicitly yields control of the CPU, then it is called "cooperative multitasking". If task switching happens periodically, i.e.: through some kind of timer interrupt, then it is known as "preemptive multitasking". Nominally, preemptive multitasking may be slower than cooperative multitasking, but in the world of 32-bit CPUs, there is really no reason not to use preemptive multitasking.

What's the difference? A Multitasking Executive vs. a Kernel

A multitasking executive is a program that manages task switching, and a kernel is a multitasking executive that also provides other services such as timers, inter-task communications, memory management etc.