• 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

    }

  • 相关阅读:
    Java Class09
    Win11如何获得最佳电源效率?
    Python课程设计之学生信息管理系统
    Java基于SpringBoot+Vue+nodejs的企业公司人事管理系统 Element
    Python全栈工程师之从网页搭建入门到Flask全栈项目实战(4) - Flask模板语法与继承
    【初阶数据结构】深入解析栈:探索底层逻辑
    Go网络编程 Conn接口
    [230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
    redis的数据类型及操作
    什么是DNS劫持?如何进行有效应对?
  • 原文地址:https://blog.csdn.net/m0_54797575/article/details/133388335