当前位置: 代码迷 >> 驱动开发 >> UC/OS 内核 OSTimeDly()函数求解。该怎么解决
  详细解决方案

UC/OS 内核 OSTimeDly()函数求解。该怎么解决

热度:402   发布时间:2016-04-28 11:06:54.0
UC/OS 内核 OSTimeDly()函数求解。

/*
*********************************************************************************************************
* DELAY TASK 'n' TICKS (n from 0 to 65535)
*
* Description: This function is called to delay execution of the currently running task until the
* specified number of system ticks expires. This, of course, directly equates to delaying
* the current task for some time to expire. No delay will result If the specified delay is
* 0. If the specified delay is greater than 0 then, a context switch will result.
*
* Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'.
* Note that by specifying 0, the task will not be delayed.
*
* Returns : none
*********************************************************************************************************
*/

void OSTimeDly (INT16U ticks)
{
  INT8U y;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
  OS_CPU_SR cpu_sr = 0;
#endif



  if (ticks > 0) { /* 0 means no delay! */
  OS_ENTER_CRITICAL();
  y = OSTCBCur->OSTCBY; /* Delay current task */
  OSRdyTbl[y] &= ~OSTCBCur->OSTCBBitX;
  if (OSRdyTbl[y] == 0) {
  OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
  }
  OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */
  OS_EXIT_CRITICAL();
  OS_Sched(); /* Find next task to run! */
  }
}

UCOS的一个任务跳转到执行下一个任务 CONTEST SWITCH,是怎么实现的?
麻烦解释一下上面这个函数。每一行的作用,特别是与CPU相关的。


------解决方案--------------------
这几行代码很简单,不过涉及了UCOSII的任务调度和任务就绪表,lz需要了解一下这两方面的内容;