减少空闲任务的资源使用

发布于 2024-09-06 03:16:36 字数 71 浏览 6 评论 0原文

我发现在 uC/OS-II RTOS 中,有一个空闲任务在没有其他任务准备运行时执行。如果空闲任务会消耗资源,我们如何减少它呢?

I find that in uC/OS-II RTOS, there is an idle task that gets executed when no other task is ready to run. If an idle task can consume resources, how can we reduce it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜是你 2024-09-13 03:16:36

通常,空闲任务是指处理器进入低功耗(睡眠)模式(如果它是低功耗系统并且处理器具有这种模式)。这通常是特定的汇编指令,例如在 ARM Cortex M3 上您将执行“WFI”指令。在其他芯片上,核心外部可能有一个特定的寄存器来管理电源(而不是指令)。

请注意,进入低功耗模式之前通常有一些条件(必须满足的要求)。有时您需要在睡觉前锁定中断,有时则需要解锁;检查你的芯片的数据表。

通常在进入低功耗模式之前,您将关闭所有不需要的外围设备。再次检查芯片的数据表。另外,如果您要使用中断来唤醒,请确保外设未断电,并且中断已启用,否则您将无法唤醒。

最后一点:通常在调试时(例如在 JTAG 设备的控制下),进入低功耗模式时会发生奇怪的事情,因此您需要在调试时禁用空闲任务中的“睡眠”,并且仅在没有调试器的情况下运行时才执行此操作。通常这是编译时决定(#ifdef ...)

Usually the idle task is where the processor is put into low power (sleep) mode, if it's a low-power system and the processor has such a mode. This is usually a specific assembly instruction, for example on the ARM Cortex M3 you'd execute the "WFI" instruction. On other chips, there might be a specific register outside the core that manages power (as opposed to an instruction).

Note that there are often conditions (requirements that must be met) before entering low power mode. Sometimes you need to have interrupts locked, sometimes unlocked, before going to sleep; check your chip's datasheet.

Usually before entering low-power mode, you'll power down any peripherals you don't need. Again, check your chip's datasheet. Also if you're going to use an interrupt to wake back up, make sure that the peripheral isn't powered down, and that the interrupt is enabled, otherwise, you won't wake up.

Last point: often when debugging (e.g. under control of a JTAG device), weird things happen when entering low power mode, so you want to disable "sleeping" in the idle task when debugging, and only do this when running without the debugger. Usually this is a compile-time decision (#ifdef ...)

失退 2024-09-13 03:16:36

典型的空闲循环可能会使用很少的处理器门,因此在核心中消耗很少的功率,但如果很重要,您可以在空闲循环中调用睡眠模式,这样就不会执行任何代码 - 核心只是停止。然而,为了维持实时响应,外围设备可能会保持供电并能够生成中断,因此实际上好处可能很小。

就其他资源而言,空闲循环通常只是到当前指令的分支;一条指令,无数据;它不可能比这小得多。提供了uC/OS-II的源代码,大家可以看一下!

当然,如果你通过直接修改或实现钩子来扩展空闲任务,那么资源的使用完全在你的控制范围内,但你不能不劳而获。

A typical idle loop is likely to exercise very few processor gates and therefore consume very little power in the core, but if it is critical you can invoke a sleep mode in the idle loop, so that no code at all is executed - the core just stops. However it is likely that to maintain real-time response peripheral devices will remain powered and able to generate interrupts, so in practice the benefit may be minimal.

In terms of other resources the idle loop will typically be simply a branch to the current instruction; one instruction, no data; it cannot get much smaller than that. The source code for uC/OS-II is provided, so you could just take a look!

Of course if you have extended the idle task by modifying it directly or implementing a hook, that resource usage is entirely within your control, but you cannot get something for nothing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文