?? os_core.c
字號:
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
/*
*********************************************************************************************************
虛擬函數?
描述:此函數不做任務事情,由OSTaskDel().調用
參數:無
返回:無
*********************************************************************************************************
*/
#if OS_TASK_DEL_EN > 0
void OS_Dummy (void)
{ //不做任何事
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MAKE TASK READY TO RUN BASED ON EVENT OCCURING
*
* Description: This function is called by other uC/OS-II services and is used to ready a task that was
* waiting for an event to occur.
*
* Arguments : pevent is a pointer to the event control block corresponding to the event.
*
* msg is a pointer to a message. This pointer is used by message oriented services
* such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
* service functions.
*
* msk is a mask that is used to clear the status byte of the TCB. For example,
* OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
*
* Returns : none
*
* Note : This function is INTERNAL to uC/OS-II and your application should not call it.
基于事件發生使任務準備運行
描述:該函數由UCOS其它服務調用,用于使一個任務就緒,等待一個事件發生
參數:pevent:指向對應事件的ECB的指針
msg:消息指針,由郵箱隊列等消息定向服務使用,該指針不能由其它
服務函數調用
msk:是用于清除TCB狀態字節的掩碼,比如:
OSSemPost() 將傳遞TAT_SEM, OSMboxPost() 將傳遞OS_STAT_MBOX
這個函數看得不是很懂
*********************************************************************************************************
*/
#if OS_EVENT_EN > 0
//能使隊列代碼產生&&申請隊列控制塊最大數不為零||能使郵箱代碼產生||
//能使信號量代碼產生||能使互斥量代碼產生
INT8U OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)
{
OS_TCB *ptcb;
INT8U x;
INT8U y;
INT8U bitx;
INT8U bity;
INT8U prio;
y = OSUnMapTbl[pevent->OSEventGrp]; /* Find highest prio. task waiting for message */
bity = OSMapTbl[y];//尋找等待消息的最高優先級任務
x = OSUnMapTbl[pevent->OSEventTbl[y]];
bitx = OSMapTbl[x];
prio = (INT8U)((y << 3) + x); /* Find priority of task getting the msg */
if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) { /* Remove this task from the waiting list */
//將此任務從等待列表中移除。
pevent->OSEventGrp &= ~bity; /* Clr group bit if this was only task pending */
//如果是唯一掛起的任務,那么清除組位,
}
ptcb = OSTCBPrioTbl[prio]; /* Point to this task's OS_TCB */
//指針指向當前任務的OS_TCB
ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from readying task */
//防止時鐘節拍使任務就緒?這樣就行?
ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Unlink ECB from this task */
//從這樣任務上斷開ECB
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
ptcb->OSTCBMsg = msg; /* Send message directly to waiting task */
//將消息直接發送到等待的任務
#else
msg = msg; /* Prevent compiler warning if not used */
//防止編譯器警告
#endif
ptcb->OSTCBStat &= ~msk; /* Clear bit associated with event type */
//事件狀態位清除
if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is ready (could be susp'd) */
//如果任務就緒,(不能被掛起)
OSRdyGrp |= bity; /* Put task in the ready to run list */
OSRdyTbl[y] |= bitx;
}
return (prio);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MAKE TASK WAIT FOR EVENT TO OCCUR
*
* Description: This function is called by other uC/OS-II services to suspend a task because an event has
* not occurred.
*
* Arguments : pevent is a pointer to the event control block for which the task will be waiting for.
*
* Returns : none
*
* Note : This function is INTERNAL to uC/OS-II and your application should not call it.
使任務等待事件發生
描述:由ucosII服務程序調用去掛起一個任務因為一個事件還沒有發生
參數:pevent 指向將要等待的任務的ECB的指針
返回:無
備注:ucos內部調用,其它應用程序不能調用它
*********************************************************************************************************
*/
#if OS_EVENT_EN > 0
#define OS_EVENT_EN (((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0))
//能使隊列代碼產生&&申請隊列控制塊最大數不為零||能使郵箱代碼產生||
//能使信號量代碼產生||能使互斥量代碼產生
void OS_EventTaskWait (OS_EVENT *pevent)
{
OSTCBCur->OSTCBEventPtr = pevent; /* Store pointer to event control block in TCB */
//保存ECB指針到TCB
if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) { /* Task no longer ready */
//如果任務沒有就緒(那就掛起嗎?)
OSRdyGrp &= ~OSTCBCur->OSTCBBitY; /* Clear event grp bit if this was only task pending */
//如果是沒有一個任務掛起的話就清除事件群位。
}
pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX; /* Put task in waiting list */
pevent->OSEventGrp |= OSTCBCur->OSTCBBitY;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
*
* Description: This function is called by other uC/OS-II services to make a task ready to run because a
* timeout occurred.
*
* Arguments : pevent is a pointer to the event control block which is readying a task.
*
* Returns : none
*
* Note : This function is INTERNAL to uC/OS-II and your application should not call it.
當事件超時,讓任務準備運行
描述:由于超時發生,由ucos調用讓個任務準備運行,
參數:pevent:就緒任務的ECB指針
返回:無
備注:ucos內部函數,其它應用函數不能調用。
*********************************************************************************************************
*/
#if OS_EVENT_EN > 0
void OS_EventTO (OS_EVENT *pevent)
{
if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {
pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
}//如果一組中沒有一個任務掛起就清除該組
OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Set status to ready */
//將當前任務設置為即將運行
OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
//運行就不再等待事物了
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
*
* Description: This function is called by other uC/OS-II services to initialize the event wait list.
*
* Arguments : pevent is a pointer to the event control block allocated to the event.
*
* Returns : none
*
* Note : This function is INTERNAL to uC/OS-II and your application should not call it.
初始化ECB等待列表
描述:由ucos調用初始化事件等待列表
參數:pevent:指向指定事件的ECB的指針
返回:無
備注:內部函數,應用函數不能調用
*********************************************************************************************************
*/
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0)
void OS_EventWaitListInit (OS_EVENT *pevent)
{
INT8U *ptbl;
pevent->OSEventGrp = 0x00; /* No task waiting on event */
//初始化時事件中無等待的任務
ptbl = &pevent->OSEventTbl[0];//取地址
#if OS_EVENT_TBL_SIZE > 0//不采用循環的原因是這樣運行速度更快
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 1
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 2
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 3
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 4
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 5
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 6
*ptbl++ = 0x00;
#endif
#if OS_EVENT_TBL_SIZE > 7
*ptbl = 0x00;
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZATION
* INITIALIZE THE FREE LIST OF EVENT CONTROL BLOCKS
*
* Description: This function is called by OSInit() to initialize the free list of event control blocks.
*
* Arguments : none
*
* Returns : none
描述:初始化事件控制塊空閑列表
參數:無
返回:無
*********************************************************************************************************
*/
static void OS_InitEventList (void)
{
#if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 0)
#if (OS_MAX_EVENTS > 1)//如果任務數大于一
INT16U i;
OS_EVENT *pevent1;
OS_EVENT *pevent2;
pevent1 = &OSEventTbl[0];//事件控制塊方框表
pevent2 = &OSEventTbl[1];
for (i = 0; i < (OS_MAX_EVENTS - 1); i++) { /* Init. list of free EVENT control blocks */
//初始化空ECB鏈表
pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;//狀態設置為掛起
pevent1->OSEventPtr = pevent2;//把它們鏈起來。接起來
pevent1++;
pevent2++;//加吧,加吧,加到OS_MAX_EVENTS - 1
}
pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
pevent1->OSEventPtr = (OS_EVENT *)0;//前趨指向零指針
OSEventFreeList = &OSEventTbl[0];//空表指向OSEventTbl第一個
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -