Simple Multitasking With Microcontrollers
Simple Multitasking With Microcontrollers
An RTOS is a program
that manages system
resources, schedules the
execution of various tasks
in the system and provides
services for inter-task
synchronization and
messaging. There are many
books and sources of
reference that describe the
operation and principles of
Figure 2: Round-robin scheduling
various RTOS systems.
Every RTOS consists of a
kernel that provides the low
level functions, mainly the
scheduling, creation of
tasks and inter-task
resource management.
Most complex RTOSs also
provide file-handling
services, disk input-output
operations, interrupt
servicing, network
Figure 3: Pre-emptive scheduling
management and user
management.
A task is an independent thread of
the system. Each task has its own context
execution in a multitasking system, usually
consisting of the state of the CPU and
with its own local set of data. A multitasking
associated registers. The scheduler switches
system consists of a number of independent
from one task to another one by performing
tasks, each running its own code and
a context switching where the context of the
communicating with each other in order to
running process is stored and context of the
have orderly access to shared resources. The
next process is loaded appropriately so that
simplest RTOS consists of a scheduler that
execution can continue properly with the next
determines the execution order of the tasks in task. The time taken for the CPU to perform
RTOS
Figure 4: Program
listing of RTOS
21
RTOS
Figure 5: PIC18 microcontroller
stack structure
Figure 6: A simple
RTOS multitasking
example
RTOS
Using RTOS
Here is an example to show how RTOS
can be used in a simple multitasking
application. An LEDs is connected to port pins
RB0 of a PIC18F452 microcontroller, operated
from a 8MHz crystal. Similarly, port pins RB1
and RB2 are connected to push-button
switches such that logic 0 is applied to the
corresponding microcontroller pin when a
switch is pressed. Three tasks named TASK0,
23