From 0998e94188855b5f890b3c7932745578329995d4 Mon Sep 17 00:00:00 2001 From: Jonas Jacobsson <jonjac-6@student.ltu.se> Date: Mon, 15 Mar 2021 12:31:35 +0000 Subject: [PATCH] Update rtic_bare9.rs --- examples/rtic_bare9.rs | 46 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/examples/rtic_bare9.rs b/examples/rtic_bare9.rs index a1fc61c..6c3d4bb 100644 --- a/examples/rtic_bare9.rs +++ b/examples/rtic_bare9.rs @@ -13,17 +13,23 @@ use stm32f4xx_hal::{ prelude::*, serial::{config::Config, Event, Rx, Serial, Tx}, stm32::USART2, + nb::block, }; use rtic::app; use rtt_target::{rprintln, rtt_init_print}; + #[app(device = stm32f4xx_hal::stm32, peripherals = true)] const APP: () = { struct Resources { // Late resources TX: Tx<USART2>, RX: Rx<USART2>, + #[init(0)] + fel: u32, + #[init(0)] + corr: u32, } // init runs in an interrupt free section @@ -59,7 +65,7 @@ const APP: () = { let (tx, rx) = serial.split(); // Late resources - init::LateResources { TX: tx, RX: rx } + init::LateResources { TX: tx, RX: rx} } // idle may be interrupted by other interrupts/tasks in the system @@ -71,23 +77,51 @@ const APP: () = { } // capacity sets the size of the input buffer (# outstanding messages) - #[task(resources = [TX], priority = 1, capacity = 128)] - fn rx(cx: rx::Context, data: u8) { + #[task(resources = [TX], priority = 2, capacity = 128)] + fn rx(cx: rx::Context,data:u8) { let tx = cx.resources.TX; tx.write(data).unwrap(); + } + + #[task(priority = 1,resources = [fel,corr])] + fn trace(cx: trace::Context, worked: bool,data:u8,){ + match worked{ + true => { + *cx.resources.corr +=1; + rprintln!("Ok {:?}", data); + } + false =>{ + *cx.resources.fel +=1; + rprintln!("some error"); + } + } + rprintln!("correct {}", cx.resources.corr); + rprintln!("errors {}", cx.resources.fel); rprintln!("data {}", data); } // Task bound to the USART2 interrupt. - #[task(binds = USART2, priority = 2, resources = [RX], spawn = [rx])] + #[task(binds = USART2, priority = 3, resources = [RX], spawn = [rx,trace])] fn usart2(cx: usart2::Context) { let rx = cx.resources.RX; - let data = rx.read().unwrap(); + let data; + match (rx.read()) { + Ok(byte) => { + data = byte; + let result = cx.spawn.trace(true,byte); + } + Err(err) => { + data = 0; + rprintln!("Error {:?}", err); + cx.spawn.trace(false,data).unwrap(); + } + } cx.spawn.rx(data).unwrap(); } extern "C" { fn EXTI0(); + fn USART1(); } }; @@ -148,7 +182,7 @@ const APP: () = { // // Were you able to crash it? // -// ** your answer here ** +// Yes // // Notice, the input tracing in `moserial` seems broken, and may loose data. // So don't be alarmed if data is missing, its a GUI tool after all. -- GitLab