Chinaunix首页 | 论坛 | 博客
  • 博客访问: 434011
  • 博文数量: 103
  • 博客积分: 1455
  • 博客等级: 上尉
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-15 22:17
文章分类

全部博文(103)

文章存档

2013年(4)

2012年(99)

我的朋友

分类: LINUX

2012-11-14 11:21:43



 

点击(此处)折叠或打开

  1. OS_EXIT_CRITICAL();

  2.         OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed) */

  3.         psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack */
  4.         err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
  5.         if (err == OS_NO_ERR) {
  6.             if (OSRunning == OS_TRUE) { /* Find HPT if multitasking has started */
  7.                 OS_Sched();
  8.             }
  9.         } else {
  10.             OS_ENTER_CRITICAL();
  11.             OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to others */
  12.             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); 执行栈清空的子函数

点击(此处)折叠或打开

  1. /*
  2. *********************************************************************************************************
  3. * CLEAR TASK STACK
  4. *
  5. * Description: This function is used to clear the stack of a task (i.e. write all zeros)
  6. *
  7. * Arguments : pbos is a pointer to the task's bottom of stack. If the configuration constant
  8. * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
  9. * memory to low memory). 'pbos' will thus point to the lowest (valid) memory
  10. * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
  11. * highest memory location of the stack and the stack will grow with increasing
  12. * memory locations. 'pbos' MUST point to a valid 'free' data item.
  13. *
  14. * size is the number of 'stack elements' to clear.
  15. *
  16. * opt contains additional information (or options) about the behavior of the task. The
  17. * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
  18. * specific. See OS_TASK_OPT_??? in uCOS-II.H.
  19. *
  20. * Returns : none
  21. *********************************************************************************************************
  22. */
  23. #if OS_TASK_CREATE_EXT_EN > 0
  24. void OS_TaskStkClr (OS_STK *pbos, INT32U size, INT16U opt)
  25. {
  26.     if ((opt & OS_TASK_OPT_STK_CHK) != 0x0000) { /* See if stack checking has been enabled */
  27.         if ((opt & OS_TASK_OPT_STK_CLR) != 0x0000) { /* See if stack needs to be cleared */
  28. #if OS_STK_GROWTH == 1
  29.             while (size > 0) { /* Stack grows from HIGH to LOW memory */
  30.                 size--;
  31.                 *pbos++ = (OS_STK)0; /* Clear from bottom of stack and */
  32.             }
  33. #else
  34.             while (size > 0) { /* Stack grows from LOW to HIGH memory */
  35.                 size--;
  36.                 *pbos-- = (OS_STK)0; /* Clear from bottom of stack and down */
  37.             }
  38. #endif
  39.         }
  40.     }
  41. }

  42. #endif

清空函数需要栈底指针,栈大小和操作选项三个参数

只有opt中的栈检查和栈清除位使能时,才执行将栈内元素的值清零的代码段

之后执行相同的初始化栈,初始化TCB的指令

 

 

 

                                           

阅读(1655) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~