简体   繁体   English

FreeRTOS 两个 CPU 时钟

[英]FreeRTOS two CPU clocks

Dependent on a HW assembly variant my firmware should operate with 2.1 or 4.2 MHz.取决于硬件组件变体,我的固件应该以 2.1 或 4.2 MHz 运行。 In FreeRTOS configCPU_CLOCK_HZ is already set while compile time.在 FreeRTOS 中, configCPU_CLOCK_HZ已在编译时设置。 Is there any possibility to set this frequency while initialisation time?有没有可能在初始化时间设置这个频率?

configCPU_CLOCK_HZ seems to be used in vPortSetupTimerInterrupt() function, which simply configures SysTick hardware registers (if you're not using tickless mode ). configCPU_CLOCK_HZ似乎在vPortSetupTimerInterrupt() function 中使用,它只是配置 SysTick 硬件寄存器(如果你不使用tickless 模式)。 I guess it should be possible to configure these register manually even when the scheduler is running (but I'm not sure).我想即使调度程序正在运行,也应该可以手动配置这些寄存器(但我不确定)。

But there is probably a better way: vPortSetupTimerInterrupt() is defined with __attribute__((weak)) in the source code.但可能有更好的方法:在源代码中使用__attribute__((weak))定义vPortSetupTimerInterrupt() It means that, if you provide your own version of vPortSetupTimerInterrupt() , it will replace the original one.这意味着,如果您提供自己的vPortSetupTimerInterrupt()版本,它将替换原来的版本。 In your own version, simply load SysTick CTRL & LOAD registers with the appropriate values.在您自己的版本中,只需使用适当的值加载 SysTick CTRL & LOAD 寄存器。

Here is the original version of vPortSetupTimerInterrupt() (This can vary depanding on the uC model):这是vPortSetupTimerInterrupt()的原始版本(这可能因 uC 模型而异):

/*
 * Setup the systick timer to generate the tick interrupts at the required
 * frequency.
 */
__attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
{
    /* Calculate the constants required to configure the tick interrupt. */
    #if ( configUSE_TICKLESS_IDLE == 1 )
        {
            ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );
            xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;
            ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ );
        }
    #endif /* configUSE_TICKLESS_IDLE */

    /* Stop and clear the SysTick. */
    portNVIC_SYSTICK_CTRL_REG = 0UL;
    portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;

    /* 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 );
}

You can probably just copy the original one (without the weak attribute of course) and replace configCPU_CLOCK_HZ with some global variable you set in your code.您可以只复制原始的(当然没有属性)并用您在代码中设置的一些全局变量替换configCPU_CLOCK_HZ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM