aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2022-08-16 01:17:28 -0400
committerQuentin Smith <[email protected]>2022-08-16 01:17:28 -0400
commitc1d8c8cf36e3d13daf0eb93b56d8e149acf55b27 (patch)
tree5f76e21edc00dd58fefa36bfd9bd90eeaac89db2 /examples/nrf/src/bin
parent0bf178dd1b11d97f20cb93c5fdb0c779259be0f8 (diff)
Add example of rtos-trace / SystemView
Diffstat (limited to 'examples/nrf/src/bin')
-rw-r--r--examples/nrf/src/bin/rtos_trace.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf/src/bin/rtos_trace.rs
new file mode 100644
index 000000000..8b4f5b755
--- /dev/null
+++ b/examples/nrf/src/bin/rtos_trace.rs
@@ -0,0 +1,64 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use core::task::Poll;
6
7use embassy_executor::executor::Spawner;
8use embassy_executor::time::{Duration, Instant, Timer};
9use embassy_nrf::Peripherals;
10
11// N.B. systemview_target cannot be used at the same time as defmt_rtt.
12
13use rtos_trace;
14use systemview_target::SystemView;
15use panic_probe as _;
16use log::*;
17
18static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new();
19rtos_trace::global_trace!{SystemView}
20
21struct TraceInfo();
22
23impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo {
24 fn system_description() {}
25 fn sysclock() -> u32 {
26 64000000
27 }
28}
29rtos_trace::global_application_callbacks!{TraceInfo}
30
31#[embassy_executor::task]
32async fn run1() {
33 loop {
34 info!("DING DONG");
35 Timer::after(Duration::from_ticks(16000)).await;
36 }
37}
38
39#[embassy_executor::task]
40async fn run2() {
41 loop {
42 Timer::at(Instant::from_ticks(0)).await;
43 }
44}
45
46#[embassy_executor::task]
47async fn run3() {
48 futures::future::poll_fn(|cx| {
49 cx.waker().wake_by_ref();
50 Poll::<()>::Pending
51 })
52 .await;
53}
54
55#[embassy_executor::main]
56async fn main(spawner: Spawner, _p: Peripherals) {
57 LOGGER.init();
58 ::log::set_logger(&LOGGER).ok();
59 ::log::set_max_level(::log::LevelFilter::Trace);
60
61 spawner.spawn(run1()).unwrap();
62 spawner.spawn(run2()).unwrap();
63 spawner.spawn(run3()).unwrap();
64}