一、任务的组成
一个任务由三个组成部分组成:任务程序代码、任务堆栈、任务控制块组成
为了方便管理、ucos 把每一个任务看作一个节点,把它们链接成如图的任务链表:
二、任务状态
嵌入式系统只有一个CPU,一个时刻只能有一个任务占据cpu,根据任务是否占据CPU,可以将任务划分成5种状态:
睡眠状态、就绪状态、运行状态、等待状态、中断服务状态
任务在不同状态之间的转换图:
创建任务代码:
/*
*********************************************************************************************************
* CREATE A TASK
*
* Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
* be created prior to the start of multitasking or by a running task. A task cannot be
* created by an ISR.
*
* Arguments : task is a pointer to the task's code
*
* p_arg is a pointer to an optional data area which can be used to pass parameters to
* the task when the task first executes. Where the task is concerned it thinks
* it was invoked and passed the argument 'p_arg' as follows:
*
* void Task (void *p_arg)
* {
* for (;;) {
* Task code;
* }
* }
*
* ptos is a pointer to the task's top of stack. If the configuration constant
* OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
* memory to low memory). 'pstk' will thus point to the highest (valid) memory
* location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
* lowest memor