硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1945|回复: 11
收起左侧

[ThreadX全家桶] ThreadX低功耗tickless问题

[复制链接]

2

主题

7

回帖

13

积分

新手上路

积分
13
发表于 2022-4-1 13:14:31 | 显示全部楼层 |阅读模式
ThreadX的低功耗这一块tx_low_power_enter 实现是不是过于简单了点,内核systick每间隔一段时间就会唤醒系统的啊?
TX_LOW_POWER_TICKLESS - an optional define to operate ticklessly in low power mode. Symbol TX_LOW_POWER_TIMER_SETUP must also be defined. With this defined, there is no need to set up a low power timer to keep track of time. ThreadX will not maintain/update the internal tick count during or after exiting low power mode.
这个是指的单独使用一个低功耗定时器来做系统时钟吗?如果是类似于freeRTOS的tickless,应该用低功耗定时器来计算系统睡眠器件经过的tick数,感觉这说明也不是这么回事啊?请教大佬们指点一二

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107488
QQ
发表于 2022-4-1 18:12:25 | 显示全部楼层
ThreadX , RTX, FreeRTOS,uCOS基本都一样。

image.png
回复

使用道具 举报

2

主题

7

回帖

13

积分

新手上路

积分
13
 楼主| 发表于 2022-4-2 09:07:54 | 显示全部楼层
eric2013 发表于 2022-4-1 18:12
ThreadX , RTX, FreeRTOS,uCOS基本都一样。

汇编文件里是有进入低功耗的接口,但这种直接进入低功耗,系统滴答时钟的中断(一般设置1ms)会频繁让系统进入睡眠和退出睡眠
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107488
QQ
发表于 2022-4-2 09:16:25 | 显示全部楼层
aeroyuan 发表于 2022-4-2 09:07
汇编文件里是有进入低功耗的接口,但这种直接进入低功耗,系统滴答时钟的中断(一般设置1ms)会频繁让系统 ...

他这个就是获取的可以延迟处于低功耗模式下的时钟节拍数。

这个功能你测试过了没有,建议移植测试下,所有的任务里面什么都不执行(所有外设都关闭初始化,特别时有中断的),while大循环里面仅执行个delay,每个delay都延迟1s执行一次。看下每个ms还唤醒不,还唤醒就不正常了。
回复

使用道具 举报

2

主题

7

回帖

13

积分

新手上路

积分
13
 楼主| 发表于 2022-4-2 09:45:25 | 显示全部楼层
eric2013 发表于 2022-4-2 09:16
他这个就是获取的可以延迟处于低功耗模式下的时钟节拍数。

这个功能你测试过了没有,建议移植测试下, ...

关闭外设和systick吗?那样的话threadx内核必然不会工作的,那么问题来了就需要自己实现唤醒的时间计算和下个任务切换时刻的计算,还得单独弄个定时器
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107488
QQ
发表于 2022-4-2 09:48:21 | 显示全部楼层
aeroyuan 发表于 2022-4-2 09:45
关闭外设和systick吗?那样的话threadx内核必然不会工作的,那么问题来了就需要自己实现唤醒的时间计算和 ...

不是,滴答不用你操作,滴答是ThreadX在使用管理。滴答也关闭了,你还怎么唤醒。
从你的描述来看,貌似还没有测试过这个功能,建议你先测试玩下,熟悉熟悉。
回复

使用道具 举报

2

主题

7

回帖

13

积分

新手上路

积分
13
 楼主| 发表于 2022-4-2 09:51:26 | 显示全部楼层
eric2013 发表于 2022-4-2 09:48
不是,滴答不用你操作,滴答是ThreadX在使用管理。滴答也关闭了,你还怎么唤醒。

滴答需要管理的,不然滴答的中断就会唤醒系统,频繁进出系统。唤醒通过外设的中断来唤醒
回复

使用道具 举报

2

主题

7

回帖

13

积分

新手上路

积分
13
 楼主| 发表于 2022-4-2 09:54:27 | 显示全部楼层
eric2013 发表于 2022-4-2 09:48
不是,滴答不用你操作,滴答是ThreadX在使用管理。滴答也关闭了,你还怎么唤醒。
从你的描述来看,貌似 ...

我测试过,您说的这种直接在tx_low_power_enter接口里面操作芯片进入低功耗模式,会频繁退出又进入,这种是普通模式的低功耗吧,并不是tickless
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107488
QQ
发表于 2022-4-2 09:58:24 | 显示全部楼层
aeroyuan 发表于 2022-4-2 09:51
滴答需要管理的,不然滴答的中断就会唤醒系统,频繁进出系统。唤醒通过外设的中断来唤醒

我们这里讨论的是tickless,外部中断唤醒就是另外一种玩法了。tickless是可以全部ThreadX管理的。

强烈建议你先移植测测,先聊这么多吧


回复

使用道具 举报

2

主题

180

回帖

186

积分

初级会员

积分
186
发表于 2022-4-2 10:00:26 | 显示全部楼层
aeroyuan 发表于 2022-4-2 09:51
滴答需要管理的,不然滴答的中断就会唤醒系统,频繁进出系统。唤醒通过外设的中断来唤醒

????你是不是对tickless有什么误解
回复

使用道具 举报

36

主题

2041

回帖

2149

积分

至尊会员

积分
2149
发表于 2022-4-2 10:43:08 | 显示全部楼层
https://github.com/azure-rtos/th ... ower/tx_low_power.c

看了下源码实现,跟楼主位的英文描述是一致的,threadx这里条件编译很多,所以用法也很多,滴答唤醒是最简单的用法。复杂点的是借助真正的低功耗定时器来计数溢出时间,时间到了唤醒。并更新给滴答(这个是标准用法,看下面源码有实现)。

这里有个问题要注意,M7内核芯片,像H7的滴答定时器中断是无法唤醒停机模式的,而F1和F4可以唤醒,这点在使用的时候要尤其注意。

[C] 纯文本查看 复制代码
VOID  tx_low_power_enter(VOID)
{

TX_INTERRUPT_SAVE_AREA

#ifdef TX_LOW_POWER_TIMER_SETUP
ULONG   tx_low_power_next_expiration;   /* The next timer experation (units of ThreadX timer ticks). */
ULONG   timers_active;
#endif

    /* Disable interrupts while we prepare for low power mode.  */
    TX_DISABLE

    /*  TX_LOW_POWER_TIMER_SETUP is a macro to a routine that sets up a low power
        clock. If such routine does not exist, we can skip the logic that computes
        the next expiration time. */
#ifdef TX_LOW_POWER_TIMER_SETUP

    /*  At this point, we want to enter low power mode, since nothing
        meaningful is going on in the system. However, in order to keep
        the ThreadX timer services accurate, we must first determine the
        next ThreadX timer expiration in terms of ticks. This is
        accomplished via the tx_timer_get_next API.  */
    timers_active =  tx_timer_get_next(&tx_low_power_next_expiration);

    /* There are two possibilities:
        1:  A ThreadX timer is active. tx_timer_get_next returns TX_TRUE.
            Program the hardware timer source such that the next timer
            interrupt is equal to: tx_low_power_next_expiration*tick_frequency.
            In most applications, the tick_frequency is 10ms, but this is
            completely application specific in ThreadX, typically set up 
            in tx_low_level_initialize. Note that in this situation, a low
            power clock must be used in order to wake up the CPU for the next timeout
            event. Therefore an alternative clock must be programmed. 
        2:  There are no ThreadX timers active. tx_timer_get_next returns TX_FALSE.
            2.a: application may choose not to keep the ThreadX internal
            tick count updated (define TX_LOW_POWER_TICKLESS), therefore no need
            to set up a low power clock.
            2.b: Application still needs to keep ThreadX tick up-to-date. In this case
            a low power clock needs to be set up.
    */

#ifndef TX_LOW_POWER_TICKLESS
    /* We still want to keep track of time in low power mode. */
    if (timers_active == TX_FALSE)
    {
        /* Set the next expiration to 0xFFFFFFF, an indication that the timer sleeps for
           maximum amount of time the HW supports.*/
        tx_low_power_next_expiration = 0xFFFFFFFF;
        timers_active = TX_TRUE;
    }
#endif /* TX_LOW_POWER_TICKLESS */

    if (timers_active == TX_TRUE)
    {
        /* A ThreadX timer is active or we simply want to keep track of time. */
        TX_LOW_POWER_TIMER_SETUP(tx_low_power_next_expiration);
    }
#endif /* TX_LOW_POWER_TIMER_SETUP */


    /* Set the flag indicating that low power has been entered. This 
       flag is checked in tx_low_power_exit to determine if the logic
       used to adjust the ThreadX time is required.  */
    tx_low_power_entered =  TX_TRUE;

    /* Re-enable interrupts before low power mode is entered.  */
    TX_RESTORE

    /* User code to enter low power mode. This allows the application to power down
       peripherals and put the processor in sleep mode.
    */
#ifdef TX_LOW_POWER_USER_ENTER
    TX_LOW_POWER_USER_ENTER;
#endif

    /* If the low power code returns, this routine returns to the tx_thread_schedule loop.  */
}
Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2023-3-6 21:52:17 | 显示全部楼层
看了代码,时间给你算好了,但是tickless定时器要你自己选择和设置,可以自行选择使用哪种定时器,继续使用systick或者LPTIMER都可以。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-6-4 02:24 , Processed in 0.211887 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表