Skip to content
Snippets Groups Projects
Commit df291432 authored by Anton's avatar Anton
Browse files

bare9_2

parent 9bb774e9
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,10 @@ const APP: () = { ...@@ -24,6 +24,10 @@ const APP: () = {
// Late resources // Late resources
TX: Tx<USART2>, TX: Tx<USART2>,
RX: Rx<USART2>, RX: Rx<USART2>,
#[init(0)]
corr: u8,
#[init(0)]
fel: u8,
} }
// init runs in an interrupt free section // init runs in an interrupt free section
...@@ -71,23 +75,49 @@ const APP: () = { ...@@ -71,23 +75,49 @@ const APP: () = {
} }
// capacity sets the size of the input buffer (# outstanding messages) // 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) { fn rx(cx: rx::Context, data: u8) {
let tx = cx.resources.TX; let tx = cx.resources.TX;
tx.write(data).unwrap(); 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); rprintln!("data {}", data);
} }
// Task bound to the USART2 interrupt. // 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) { fn usart2(cx: usart2::Context) {
let rx = cx.resources.RX; let rx = cx.resources.RX;
let data = rx.read().unwrap(); match (rx.read()) {
Ok(data) => {
let _ = cx.spawn.trace(true,data);
cx.spawn.rx(data).unwrap(); cx.spawn.rx(data).unwrap();
} }
Err(err) => {
cx.spawn.trace(false,0).unwrap();
}
}
//let data = rx.read().unwrap();
}
extern "C" { extern "C" {
fn EXTI0(); fn EXTI0();
fn USART1();
fn USART3();
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment