- OS_EXIT_CRITICAL();
- OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed) */
- psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack */
- err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
- if (err == OS_NO_ERR) {
- if (OSRunning == OS_TRUE) { /* Find HPT if multitasking has started */
- OS_Sched();
- }
- } else {
- OS_ENTER_CRITICAL();
- OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to others */
- OS_EXIT_CRITICAL();
今天好奇怪,完整的函数粘贴不上去,那就算了,
这个函数是OSTaskCreate函数的升级版本,增加了5个参数,分别是
id,0-65535的task id
pbos,指向栈底的指针,在arm中这个指向数组的零地址,
stk_size,就是栈的元素个数
pext,指向一个TCB扩展区的指针,例如在上下文切换时保存浮点寄存器的数值,任务已经执行的时间,任务被切换的次数等
opt,* OS_TASK_OPT_STK_CHK Stack checking to be allowed for the task
* OS_TASK_OPT_STK_CLR Clear the stack when the task is created
* OS_TASK_OPT_SAVE_FP If the CPU has floating-point registers, save them during a context switch.
在执行核心代码之前要进行 比如优先级合法的检测,是否有中断嵌套的检测,相应优先级列表中是否被占用的检测。
与之不同的是 OS_TaskStkClr(pbos, stk_size, opt); 执行栈清空的子函数
- /*
- *********************************************************************************************************
- * CLEAR TASK STACK
- *
- * Description: This function is used to clear the stack of a task (i.e. write all zeros)
- *
- * Arguments : pbos is a pointer to the task's bottom 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). 'pbos' will thus point to the lowest (valid) memory
- * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
- * highest memory location of the stack and the stack will grow with increasing
- * memory locations. 'pbos' MUST point to a valid 'free' data item.
- *
- * size is the number of 'stack elements' to clear.
- *
- * opt contains additional information (or options) about the behavior of the task. The
- * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
- * specific. See OS_TASK_OPT_??? in uCOS-II.H.
- *
- * Returns : none
- *********************************************************************************************************
- */
- #if OS_TASK_CREATE_EXT_EN > 0
- void OS_TaskStkClr (OS_STK *pbos, INT32U size, INT16U opt)
- {
- if ((opt & OS_TASK_OPT_STK_CHK) != 0x0000) { /* See if stack checking has been enabled */
- if ((opt & OS_TASK_OPT_STK_CLR) != 0x0000) { /* See if stack needs to be cleared */
- #if OS_STK_GROWTH == 1
- while (size > 0) { /* Stack grows from HIGH to LOW memory */
- size--;
- *pbos++ = (OS_STK)0; /* Clear from bottom of stack and */
- }
- #else
- while (size > 0) { /* Stack grows from LOW to HIGH memory */
- size--;
- *pbos-- = (OS_STK)0; /* Clear from bottom of stack and down */
- }
- #endif
- }
- }
- }
- #endif
清空函数需要栈底指针,栈大小和操作选项三个参数
只有opt中的栈检查和栈清除位使能时,才执行将栈内元素的值清零的代码段
之后执行相同的初始化栈,初始化TCB的指令
阅读(1655) | 评论(0) | 转发(0) |