This paper discusses how to divide your code into a set of tasks under a Real-Time Operating System (RTOS) by illustrating a few design patterns to help you in that effort, patterns that have turned up repeatedly in our design work.

We’re going to assume that we’re operating with an RTOS that provides a few standard services: a priority-based pre-emptive scheduler, mutexes, message queues, and timing services. These services can make your life simple or they can make your software impossible to understand and analyze. Getting a reasonable set of tasks is a good start towards making the best use of your RTOS. The patterns we’ll discuss fall into three major groups: desynchronizing patterns, synchronizing patterns, and architectural patterns. In addition, we’ll consider how best to write the code for a task in an RTOS.