#async-task #future #tracing #async #trace #execution-time #gpio-pin

no-std embedded-trace

嵌入式系统的一个未来跟踪实用工具

4 个版本

0.2.2 2023年12月15日
0.2.1 2023年12月15日
0.2.0 2023年12月15日
0.1.0 2023年12月15日

#1814 in 嵌入式开发

每月 28 下载

MIT/Apache

73KB
264

embedded-trace

crates.io docs.rs

嵌入式系统的一个 Future 跟踪实用工具。

该包旨在为测量执行时间和调试 async 任务和 Future 提供工具,适用于 #![no_std] 项目。

gpio_trace

如何使用此库

定义了两个主要特性: TraceFutureInstrument

TraceFuture

TraceFuture 通过添加 trace_tasktrace_polltrace_task_and_poll 方法扩展了标准库的 Future 特性。这些方法各自接受一个或多个实现 Instrument 的类型。这三个提供的方法分别在进入指定的范围时调用 on_enteron_exit。有关更多信息,请参阅 TraceFuture 特性文档。

Instrument

Instrument 代表 TraceFuture 的方法在进入或退出范围时如何发出信号。您可以在自己的类型上实现此特性。仪器模块还提供了常用类型的某些实现。

例如,一个简单的机制可能在进入范围时将 GPIO 引脚设置为高电平,退出时设置为低电平。此仪器在 instruments::gpio 模块中提供。

支持的 GPIO 实现

  • 实现 embedded-hal 版本 1.0 的类型 OutputPin
  • 实现 embedded-hal 版本 0.2 的类型 OutputPin(通过启用 embedded-hal_0_2 Cargo 功能)

使用 GPIO 仪器示例

use core::future::Future;
// `TraceFuture` must be in scope in order to use its methods.
use embedded_trace::{TraceFuture, Gpio, GpioRef};
use embedded_hal::digital::OutputPin;

async fn trace_my_future<F, P1, P2>(future: F, task_pin: P1, poll_pin: &mut P2)
where
    F: Future,
    P1: OutputPin,
    P2: OutputPin
{
    // `Gpio` can be used where we can take the pin...
    let mut task_instrument = Gpio::new(task_pin);
    // ...or `GpioRef` when all we have is a mutable reference to a pin.
    let mut poll_instrument = GpioRef::new(poll_pin);

    // Poll our future while tracing its execution.
    future.trace_task_and_poll(&mut task_instrument, &mut poll_instrument).await;

    // We can reclaim the pin taken by `Gpio`
    let task_pin = task_instrument.free();
}

依赖关系

~105KB