freertos的任务调度器的启动函数分析(根据源码使用)

volatile uint8_t * const pucFirstUserPriorityRegister = ( uint8_t * ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER );

通过宏pucFirstUserPriorityRegister=0xE000E400(根据宏名字,这是NVIC寄存器地址)

查手册知到

中断优先级设置寄存器的第一个寄存器。

ulOriginalPriority = *pucFirstUserPriorityRegister;保存第一个寄存器的值

获取寄存器有效位。

ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;

#define configMAX_SYSCALL_INTERRUPT_PRIORITY   \

 ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

configMAX_SYSCALL_INTERRUPT_PRIORITY=(5<<(8-4))

ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;//为7

   while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE )

        {//portTOP_BIT_OF_BYTE=0x80

        /*有几个有效位,就执行几次*/

            ulMaxPRIGROUPValue--;//最后的值为7-4

            ucMaxPriorityValue <<= ( uint8_t ) 0x01;

        }

        /* Shift the priority group value back to its position within the AIRCR

        register. *///注释表明,将得到的值填入AIRCR寄存器,来确定如何分组。

        ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;//3左移8位

        ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;//仅保留3左移8位后的位为1

这里3左移8位,然后填入PRIGROUP;

    /* Make PendSV and SysTick the lowest priority interrupts. */因为用4位表示优先级,所以这里是15。

    portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;

    portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;

    void vPortSetupTimerInterrupt( void )

{

        /* Configure SysTick to interrupt at the requested rate. *///产生指定周期的中断

        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 );

}

__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

    /* Globally enable interrupts. */

    cpsie i

    cpsie f

    dsb

    isb

    /* Call SVC to start the first task. */

    svc 0

    nop

    nop

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值