freertos任务调度器

本文详细介绍了FreeRTOS任务调度器的初始化过程,包括创建空闲任务、配置软件定时器、关闭中断、初始化调度器变量,以及设置中断优先级和系统定时器。通过设置 PendSV 和 SYSTICK 中断,以及启用FPU和异常处理,为FreeRTOS的正常运行奠定基础。最后,讲解了如何开始第一个任务以及栈的管理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

任务调度器初始化过程:

1.创建空闲任务
/* The Idle task is being created using dynamically allocated RAM. */
xReturn = xTaskCreate( prvIdleTask,
“IDLE”, configMINIMAL_STACK_SIZE,
( void * ) NULL,
( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),
&xIdleTaskHandle ); /*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();
	}
}

3.关闭中断

4.初始化任务调度器相关变量:
xNextTaskUnblockTime = portMAX_DELAY;
xSchedulerRunning = pdTRUE;
xTickCount = ( TickType_t ) 0U;

调用:xPortStartScheduler() ;
5.1设置PENDSV,SYSTICK中断优先级:
portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;
portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;

5,.2.设置一个系统定时器作为os的滴答节拍:

  • Setup the SysTick timer to generate the tick interrupts at the required

  • frequency.
    */
    #if configOVERRIDE_DEFAULT_TICK_CONFIGURATION == 0

    void vPortSetupTimerInterrupt( void )
    {
    /* Calculate the constants required to configure the tick interrupt. */

     portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
     portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
    

    }

/-----------------------------------------------------------/

在这里插入图片描述

port.c:

/* Constants required to manipulate the core. Registers first… /
#define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000e010 ) )
#define portNVIC_SYSTICK_LOAD_REG ( * ( ( volatile uint32_t * ) 0xe000e014 ) )
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
#define portNVIC_SYSPRI2_REG ( * ( ( volatile uint32_t * ) 0xe000ed20 ) )
/
…then bits in the registers. */
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
#define portNVIC_PENDSVCLEAR_BIT ( 1UL << 27UL )
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )

5.3如果有FPU,使能FPU,开启惰性压栈

6.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值