uC / OS-III study notes (a) Task Manager

uC / OS-III study notes (a) Task Manager

Task Status

uC / OS-III task five states, can be converted to each other:
Here Insert Picture Description
Here Insert Picture Description

Task control block

OS_TCB is a task control block structure, a lot of this member variable structure for saving task information, we use OSTaskCreat () function to create a task when task control block is allocated to the task.

struct os_tcb{
	CPU_STK		*stkPtr;
	void		*ExtPtr;
	...
}

Task stack

  1. Defined task stack
#define TASK_STK_SIZE 64 //任务堆栈大小
CPU TASK_STK[TASK_STK_SIZE]; //定义任务堆栈
  1. Task stack usage
    we use OSTaskCreat () you can pass the task to the task stack creation of a function to create a task.
OSTaskCreat(
	...
	(CPU_STK*)      &TASK_STK[0],     //任务堆栈基地址
	(CPU_STK_SIZE)  TASK_STK_SIZE/10, //任务堆栈深度限位
	(CPU_STK_SIZE)  TASK_STK_SIZE,    //任务堆栈大小
	...)

When creating a task stack initialization tasks will be to complete the stack initialization function is OSTaskStInit (), the user can not call this function, which is OSTask () when creating a task called.

Task ready list

uC / OS-III will be ready task on the task ready list, task ready list bit map table includes a priority OSPrioTbl [] a list of ready tasks and OSRadyList []

  1. Bit priority mapping table
    priority table for storing bit map which is currently in the priority task ready, when one of the tasks will be ready after the positions corresponding to the task priority 1, this indicates a priority task in the ready status.
    Here Insert Picture Description
    About three priority operation function
  • OS_PrioGetHighest () Gets Ready highest priority task
  • OS_PrioInsert () will be a task in the task table corresponding position ready 1
  • OS_PrioRemove () will be a task in the task ready list corresponding bit is cleared
  1. Ready task list
    task ready list used to record all ready tasks in each priority level, OSRdyList [] define the type, the array element is os.h OS_RDY_LIST, a structure is defined as follows:
struct os_rdy_list{
	OS_TCB	   *HeaderPtr;   //链表头指针
	OS_TCB	   *TailPtr;     //链表尾指针
	OS_OBJ_QTY  NbrEntries;  //此优先级下的任务数量
};

uC / OS-III supports the round-robin scheduling, a plurality of lower priority task, task ready list is used to manage multiple tasks at the same priority. For example OSRdyList [0] is used to manage all the tasks under the priority 0.

The task ready list manipulation functions are:
Here Insert Picture Description

Task scheduling

Task scheduling is to allow the ready list the highest priority task to obtain the right to use the CPU, high-priority task can preempt lower priority task. The task scheduler in two ways:

  1. Task-level scheduler OSSched ()

  2. Interrupt level scheduler OSIntExit ()

In addition to the task-level scheduler and interrupt-level scheduler, as well as round-robin scheduler .

After uC / OS-III allowed a period of time for the task to run right to use the CPU, so the next task to run the same priority.
Here Insert Picture Description

Published 17 original articles · won praise 21 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43116606/article/details/104276295