獲得更多資料歡迎進入我的網站或者 csdn或者博客園
對於有熱心的小伙伴在微博上私信我,說我的uC/OS-II 一些函數簡介篇幅有些過於長應該分開介紹。應小伙伴的要求,特此將文章分開進行講解。本文主要介紹OSInit()初始化函數
OSInit()主要作用
在uC/OS II的學習中,OSInit(OS_CORE.C )(函數原型位於);是一個重要的函數,它在OS應用中的main()函數中首先被調用,是OS運行的第一個函數,它完成各初始變量的初始化。
主要工作:完成下面的初始化;
OSInitHookBegin(); /* 調用用戶特定的初始化代碼(通過一個接口函數實現用戶要求的插件式進入系統中)*/
OS_InitMisc(); /* 初始化變量*/
OS_InitRdyList(); /* 初始化就緒列表*/
OS_InitTCBList(); /* 初始化OS_TCB空閑列表*/
OS_InitEventList(); /* 初始化OS_EVENT空閑列表*/
OS_InitTaskIdle(); /*創建空閑任務*/
程序注釋詳解:
void OSInit (void)
{
#if OS_TASK_CREATE_EXT_EN > 0u
#if defined(OS_TLS_TBL_SIZE) && (OS_TLS_TBL_SIZE > 0u)
INT8U err;
#endif
#endif
OSInitHookBegin(); /* 調用用戶特定的初始化代碼(通過一個接口函數實現用戶要求的插件式進入系統中)*/
OS_InitMisc(); /* 初始化變量*/ /* Initialize miscellaneous variables */
OS_InitRdyList(); /* 初始化就緒列表*/ /* Initialize the Ready List */
OS_InitTCBList(); /* 初始化OS_TCB空閑列表*/ /* Initialize the free list of OS_TCBs */
OS_InitEventList(); /* 初始化OS_EVENT空閑列表*/ /* Initialize the free list of OS_EVENTs */
#if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
OS_FlagInit(); /* 初始化事件標志結構*/ /* Initialize the event flag structures */
#endif
#if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
OS_MemInit(); /* 初始化內存管理器*/ /* Initialize the memory manager */
#endif
#if (OS_Q_EN > 0u) && (OS_MAX_QS > 0u)
OS_QInit(); /* 初始化消息隊列結構*/ /* Initialize the message queue structures */
#endif
#if OS_TASK_CREATE_EXT_EN > 0u
#if defined(OS_TLS_TBL_SIZE) && (OS_TLS_TBL_SIZE > 0u)
OS_TLS_Init(&err); /* 創建任務前初始化TLS*/ /* Initialize TLS, before creating tasks */
if (err != OS_ERR_NONE) {
return;
}
#endif
#endif
OS_InitTaskIdle(); /* 創建空閑任務(無條件)Create the Idle Task */
#if OS_TASK_STAT_EN > 0u
OS_InitTaskStat(); /* 創建統計任務*/ /* Create the Statistic Task */
#endif
#if OS_TMR_EN > 0u
OSTmr_Init(); /* 初始化時間管理器*/ /* Initialize the Timer Manager */
#endif
OSInitHookEnd(); /*調用用戶特定的初始化代碼*/
#if OS_DEBUG_EN > 0u
OSDebugInit();
#endif
}