μC/OS-II---内存管理2(os_core.c)

流程---内存管理扩展

    • 初始化μC/OS-II
    • 创建用户起始任务
    • 开始多任务调度
    • 统计Task
    • 创建用户应用程序任务

μC/OS-II---内存管理2(os_core.c)_第1张图片

初始化μC/OS-II

void  OSInit (void)
{
	OSInitHookBegin();                                           /* Call port specific initialization code   */
	OS_InitMisc();                                               /* Initialize miscellaneous variables       */
	OS_InitRdyList();                                            /* Initialize the Ready List                */
	OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs      */
	OS_InitEventList();                                          /* 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
		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();                                             /* Call port specific init. code            */
	#if OS_DEBUG_EN > 0u
		OSDebugInit();
	#endif
}

创建用户起始任务

#if OS_TASK_CREATE_EN > 0u
INT8U      OSTaskCreate     (
									void           (*task) (void *p_arg),
									void            *p_arg,
									OS_STK          *ptos,
									INT8U            prio
							);
#endif

开始多任务调度

void  OSStart (void)
{
	if (OSRunning == OS_FALSE)
	{
		OS_SchedNew();                               /* Find highest priority's task priority number   */
		OSPrioCur     = OSPrioHighRdy;
		OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
		OSTCBCur      = OSTCBHighRdy;
		OSStartHighRdy();                            /* Execute target specific code to start task     */
	}
}

统计Task

#if OS_TASK_STAT_EN > 0u
void  OSStatInit (void)
{
	#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */
		OS_CPU_SR  cpu_sr = 0u;
	#endif
		OSTimeDly (2u);                              /* Synchronize with clock tick                        */
		OS_ENTER_CRITICAL();
		OSIdleCtr    = 0uL;                          /* Clear idle counter                                 */
		OS_EXIT_CRITICAL();
		OSTimeDly (OS_TICKS_PER_SEC / 10u);          /* Determine MAX. idle counter value for 1/10 second  */
		OS_ENTER_CRITICAL();
		OSIdleCtrMax = OSIdleCtr;                    /* Store maximum idle counter count in 1/10 second    */
		OSStatRdy    = OS_TRUE;
		OS_EXIT_CRITICAL();
}
#endif

创建用户应用程序任务

你可能感兴趣的:(μC/OS-II学习,c语言,开发语言)