From df291432edd7ffe11343a24a8b0dbd1e307e46ec Mon Sep 17 00:00:00 2001
From: Anton <anton.frappe@outlook.com>
Date: Sun, 14 Mar 2021 16:33:40 +0100
Subject: [PATCH] bare9_2

---
 examples/rtic_bare9.rs | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/examples/rtic_bare9.rs b/examples/rtic_bare9.rs
index 495730f..42e1a6e 100644
--- a/examples/rtic_bare9.rs
+++ b/examples/rtic_bare9.rs
@@ -24,7 +24,11 @@ const APP: () = {
         // Late resources
         TX: Tx<USART2>,
         RX: Rx<USART2>,
-    }
+        #[init(0)]
+        corr: u8,
+        #[init(0)]
+        fel: u8,
+    }   
 
     // init runs in an interrupt free section
     #[init]
@@ -59,7 +63,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 +75,49 @@ const APP: () = {
     }
 
     // capacity sets the size of the input buffer (# outstanding messages)
-    #[task(resources = [TX], priority = 1, capacity = 128)]
+    #[task(resources = [TX], priority = 2, capacity = 128)]
     fn rx(cx: rx::Context, data: u8) {
         let tx = cx.resources.TX;
         tx.write(data).unwrap();
+    }
+
+    #[task(resources = [fel,corr], priority = 1)]
+    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();
-        cx.spawn.rx(data).unwrap();
+        match (rx.read()) {
+            Ok(data) => {
+                let _ = cx.spawn.trace(true,data);
+                cx.spawn.rx(data).unwrap();
+            }
+            Err(err) => {
+                cx.spawn.trace(false,0).unwrap();
+            }
+        }
+        //let data = rx.read().unwrap();
     }
 
     extern "C" {
         fn EXTI0();
+        fn USART1();
+        fn USART3();
     }
 };
 
-- 
GitLab