embassy/examples/nrf-rtos-trace/src/bin/rtos_trace.rs

71 lines
1.5 KiB
Rust
Raw Normal View History

2022-08-16 07:17:28 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use core::future::poll_fn;
2022-08-16 07:17:28 +02:00
use core::task::Poll;
use embassy_executor::Spawner;
use embassy_time::{Instant, Timer};
2022-08-16 07:47:18 +02:00
#[cfg(feature = "log")]
use log::*;
use panic_probe as _;
2022-08-16 07:17:28 +02:00
// N.B. systemview_target cannot be used at the same time as defmt_rtt.
use rtos_trace;
use systemview_target::SystemView;
static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new();
2022-08-16 07:47:18 +02:00
rtos_trace::global_trace! {SystemView}
2022-08-16 07:17:28 +02:00
struct TraceInfo();
impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo {
fn system_description() {}
fn sysclock() -> u32 {
64000000
}
}
2022-08-16 07:47:18 +02:00
rtos_trace::global_application_callbacks! {TraceInfo}
2022-08-16 07:17:28 +02:00
#[embassy_executor::task]
async fn run1() {
loop {
#[cfg(feature = "log")]
2022-08-16 07:17:28 +02:00
info!("DING DONG");
#[cfg(not(feature = "log"))]
rtos_trace::trace::marker(13);
Timer::after_ticks(16000).await;
2022-08-16 07:17:28 +02:00
}
}
#[embassy_executor::task]
async fn run2() {
loop {
Timer::at(Instant::from_ticks(0)).await;
}
}
#[embassy_executor::task]
async fn run3() {
poll_fn(|cx| {
2022-08-16 07:17:28 +02:00
cx.waker().wake_by_ref();
Poll::<()>::Pending
})
.await;
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let _p = embassy_nrf::init(Default::default());
2022-08-16 07:17:28 +02:00
LOGGER.init();
#[cfg(feature = "log")]
{
::log::set_logger(&LOGGER).ok();
::log::set_max_level(::log::LevelFilter::Trace);
}
2022-08-16 07:17:28 +02:00
spawner.spawn(run1()).unwrap();
spawner.spawn(run2()).unwrap();
spawner.spawn(run3()).unwrap();
}