Page 261 - Embedded Microprocessor Systems Real World Design
P. 261

Keeping Track of  Tasks


                  The RTOS keeps track of  tasks with a  tusk  control block  (TCB). This is where the
                  RTOS  saves  information  about  tasks.  One  TCB  entry  is  made  for  every  task
                  managed by the RTOS. The TCB must store the following:

                    Task  ID.  This is  typically the task number.  Depending on  the  RTOS and  the
                    processor it is running  on, there  may  be  a maximum of  128 tasks,  256 tasks,
                    32,768 tasks, and so on. The maximum number of tasks usually is what can be
                    identified  with  a  byte/word/doubleword  or whatever  the  word  width  of  the
                    processor registers.
                    Task State. Ready, blocked, and so on.
                    Task Priority. The priority level of the task; a numerical value, usually 0 to 127,
                    0 to 32,767, and so on.
                    Task Address. Where in memory the code for the task is located.
                    Task Stack Pointer. The microprocessor stack is used to pass variables and store
                    the context for subroutine calls and interrupts.  Each task needs to be able to
                    perform  subroutine  calls  and  service  interrupts  (or at  least save  the  return
                    address for an interrupt). For this purpose, each task has its own stack. The TCB
                    includes the value of the stack pointer when the task last executed  (or the top
                    of the task stack the first time the task executes).

                     The task stack is stored on the microprocessor stuck. As each task is given control,
                  the microprocessor stack pointer is modified to point to the stack for that task. Each
                  task must  be  allocated sufficient stack space to  save  the  processor  context,  any
                  dynamic/temporary variables stored on the stack, and any information stored to
                   the maximum depth of subroutine calls. The processor context also may need to
                  include things such as the  context  (registers) of  a floating-point coprocessor or
                  something similar. When a task stops running for any reason, the RTOS stores the
                   stack pointer for the task in the TCB.
                     Once  a  task  is  ready to  run  again, the  processor  context needed  to  resume
                  execution where it left off is stored on the task stack. The RTOS must get the stack
                  pointer from the TCB, put that value into the microprocessor stack pointer, and
                  return control to the task.
                     Depending on the RTOS, the TCB may contain additional information such as
                   environment information for dynamically allocated tasks and the like. In addition
                   to a stack for each task, the RTOS will  have a kernel stack for use by  the RTOS
                  itself.








                   242                                             Embedded Microprocessor Systems
   256   257   258   259   260   261   262   263   264   265   266