FreeRTOS启动流程

电子说

1.4w人已加入

描述

1. 创建空闲任务

 

xIdleTaskHandle = xTaskCreateStatic(	prvIdleTask,
										configIDLE_TASK_NAME,
										ulIdleTaskStackSize,
										( void * ) NULL, /*lint !e961.  The cast is not redundant for all compilers. */
										portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */
										pxIdleTaskStackBuffer,
										pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */

 

2. 创建定时器任务

 

#if ( configUSE_TIMERS == 1 )
{
	if( xReturn == pdPASS )
	{
		xReturn = xTimerCreateTimerTask();
	}
	else
	{
		mtCOVERAGE_TEST_MARKER();
	}
}
#endif /* configUSE_TIMERS */

 

3. 关闭中断

 

/* Interrupts are turned off here, to ensure a tick does not occur
before or during the call to xPortStartScheduler().  The stacks of
the created tasks contain a status word with interrupts switched on
so interrupts will automatically get re-enabled when the first task
starts to run. */
portDISABLE_INTERRUPTS();

 

4. 初始化全局变量

 

xNextTaskUnblockTime = portMAX_DELAY;
xSchedulerRunning = pdTRUE;
xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;

 

5. 初始化MSP

6. 使能全局中断

7. 调用SVC指令启动第一个任务

 

__asm void prvStartFirstTask( void )
{
	PRESERVE8

	/* Use the NVIC offset register to locate the stack. */
	ldr r0, =0xE000ED08
	ldr r0, [r0]
	ldr r0, [r0]
	/* Set the msp back to the start of the stack. */
	msr msp, r0
	/* Clear the bit that indicates the FPU is in use in case the FPU was used
	before the scheduler was started - which would otherwise result in the
	unnecessary leaving of space in the SVC stack for lazy saving of FPU
	registers. */
	mov r0, #0
	msr control, r0
	/* Globally enable interrupts. */
	cpsie i
	cpsie f
	dsb
	isb
	/* Call SVC to start the first task. */
	svc 0
	nop
	nop
}



审核编辑 黄宇

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分