ucOS學(xué)習(xí)筆記(3)——ucOS的數(shù)據(jù)結(jié)構(gòu)
typedef struct os_tcb {
OS_STK *OSTCBStkPtr; /* Pointer to current top of stack */
#if OS_TASK_CREATE_EXT_EN > 0
void *OSTCBExtPtr; /* Pointer to user definable data for TCB extension */
OS_STK *OSTCBStkBottom; /* Pointer to bottom of stack */
INT32U OSTCBStkSize; /* Size of task stack (in number of stack elements) */
INT16U OSTCBOpt; /* Task options as passed by OSTaskCreateExt() */
INT16U OSTCBId; /* Task ID (0..65535) */
#endif
struct os_tcb *OSTCBNext; /* Pointer to next TCB in the TCB list */
struct os_tcb *OSTCBPrev; /* Pointer to previous TCB in the TCB list */
#if (OS_EVENT_EN) || (OS_FLAG_EN > 0)
OS_EVENT *OSTCBEventPtr; /* Pointer to event control block */
#endif
#if (OS_EVENT_EN) && (OS_EVENT_MULTI_EN > 0)
OS_EVENT **OSTCBEventMultiPtr; /* Pointer to multiple event control blocks */
#endif
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
void *OSTCBMsg; /* Message received from OSMboxPost() or OSQPost() */
#endif
#if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
#if OS_TASK_DEL_EN > 0
OS_FLAG_NODE *OSTCBFlagNode; /* Pointer to event flag node */
#endif
OS_FLAGS OSTCBFlagsRdy; /* Event flags that made task ready to run */
#endif
INT16U OSTCBDly; /* Nbr ticks to delay task or, timeout waiting for event */
INT8U OSTCBStat; /* Task status */
INT8U OSTCBStatPend; /* Task PEND status */
INT8U OSTCBPrio; /* Task priority (0 == highest) */
INT8U OSTCBX; /* Bit position in group corresponding to task priority */
INT8U OSTCBY; /* Index into ready table corresponding to task priority */
#if OS_LOWEST_PRIO <= 63
INT8U OSTCBBitX; /* Bit mask to access bit position in ready table */
INT8U OSTCBBitY; /* Bit mask to access bit position in ready group */
#else
INT16U OSTCBBitX; /* Bit mask to access bit position in ready table */
INT16U OSTCBBitY; /* Bit mask to access bit position in ready group */
#endif
#if OS_TASK_DEL_EN > 0
INT8U OSTCBDelReq; /* Indicates whether a task needs to delete itself */
#endif
#if OS_TASK_PROFILE_EN > 0
INT32U OSTCBCtxSwCtr; /* Number of time the task was switched in */
INT32U OSTCBCyclesTot; /* Total number of clock cycles the task has been running */
INT32U OSTCBCyclesStart; /* Snapshot of cycle counter at start of task resumption */
OS_STK *OSTCBStkBase; /* Pointer to the beginning of the task stack */
INT32U OSTCBStkUsed; /* Number of bytes used from the stack */
#endif
#if OS_TASK_NAME_SIZE > 1
INT8U OSTCBTaskName[OS_TASK_NAME_SIZE];
#endif
} OS_TCB;
其中
OSTCBStkPtr--任務(wù)棧的指針,在任務(wù)中使用到的所有零時(shí)變量(包括任務(wù)切換時(shí)需要保存的上下文)都保存在OSTCBStkPtr指向的存儲(chǔ)區(qū)域
OSTCBExtPtr--任務(wù)擴(kuò)展數(shù)據(jù)信息指針,目前我理解這一部分主要用于保存任務(wù)名字的ASCII碼
OSTCBStkBottom--任務(wù)棧底指針
OSTCBStkSize--任務(wù)棧的大小
OSTCBNext--任務(wù)控制塊鏈表中的下一任務(wù)指針
OSTCBPrev--任務(wù)控制塊鏈表中的上一任務(wù)指針
OSTCBEventPtr--任務(wù)等待時(shí)間指針,該數(shù)據(jù)結(jié)構(gòu)本身是屬于一個(gè)事件的,任務(wù)也只是屬于事件的一個(gè)候選資源
OSTCBEventMultiPtr--互斥信號(hào)量指針
OSTCBMsg--郵箱指針
任務(wù)私有棧--是任務(wù)執(zhí)行過(guò)程或者任務(wù)數(shù)據(jù)切換過(guò)程用于存放零時(shí)數(shù)據(jù)的一片內(nèi)存區(qū)域
任務(wù)鏈表--為了便于管理ucOS將多個(gè)任務(wù)用鏈表的方式串接起來(lái),這個(gè)鏈表稱(chēng)為任務(wù)鏈表
空任務(wù)鏈表--也是為了便于內(nèi)存分配,ucOS在編譯的時(shí)候就決定了整個(gè)系統(tǒng)最多支持多少個(gè)任務(wù),同時(shí)就為這些任務(wù)預(yù)留了相應(yīng)的任務(wù)控制塊,這部分任務(wù)控制塊就被稱(chēng)為空任務(wù)鏈表。在真正需要使用任務(wù)的時(shí)候,將從空任務(wù)鏈表中獲取任務(wù)控制塊到任務(wù)控制鏈表中
當(dāng)前運(yùn)行任務(wù)指針--指向當(dāng)前正在運(yùn)行的任務(wù)控制塊
任務(wù)鏈表索引--為了更快的查找任務(wù)鏈表,ucOS建立了一個(gè)指向所有任務(wù)控制塊的數(shù)組,這個(gè)數(shù)組就是任務(wù)鏈表索引。該索引以?xún)?yōu)先級(jí)排序
任務(wù)就緒表--已經(jīng)就緒的任務(wù)表
任務(wù)就緒表索引
任務(wù)就緒表輔助登記表--一下三張表都是ucOS為了查找任何一個(gè)任務(wù)都使用相同的查找時(shí)間使用的額外表,它們的唯一作用就是保證系統(tǒng)的時(shí)效性
任務(wù)就緒表輔助注銷(xiāo)表
任務(wù)就緒表輔助查找表
全局變量不完全統(tǒng)計(jì):
OSLockNesting
OSIntNesting
OSCtxSwCtr
OSPrioHighRdy
OSPrioCur
OSTCBHighRdy
OSTCBCur
OSTaskCtr
OSRunning
評(píng)論