Skip to content
Snippets Groups Projects
Commit 2655c566 authored by Josef Utbult's avatar Josef Utbult
Browse files

bare9_2

parent 3d8d588b
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,9 @@ const APP: () = { ...@@ -24,6 +24,9 @@ const APP: () = {
// Late resources // Late resources
TX: Tx<USART2>, TX: Tx<USART2>,
RX: Rx<USART2>, RX: Rx<USART2>,
received: u8,
errors: u8,
changed: bool,
} }
// init runs in an interrupt free section // init runs in an interrupt free section
...@@ -57,16 +60,40 @@ const APP: () = { ...@@ -57,16 +60,40 @@ const APP: () = {
// Separate out the sender and receiver of the serial port // Separate out the sender and receiver of the serial port
let (tx, rx) = serial.split(); let (tx, rx) = serial.split();
let received = 0;
let errors = 0;
let changed = false;
// Late resources // Late resources
init::LateResources { TX: tx, RX: rx } init::LateResources {
TX: tx,
RX: rx,
received: received,
errors: errors,
changed: changed,
}
} }
// idle may be interrupted by other interrupts/tasks in the system // idle may be interrupted by other interrupts/tasks in the system
#[idle()] #[idle(resources = [received, errors, changed])]
fn idle(_cx: idle::Context) -> ! { fn idle(mut _cx: idle::Context) -> ! {
loop { loop {
continue; let mut changed = false;
_cx.resources.changed.lock(|mut _changed| {
changed = *_changed;
});
if changed{
_cx.resources.received.lock(|received| {
rprintln!("Received {}", *received);
});
_cx.resources.errors.lock(|errors| {
rprintln!("Errors {}", *errors);
});
_cx.resources.changed.lock(|changed| {
*changed = false;
});
}
} }
} }
...@@ -78,12 +105,20 @@ const APP: () = { ...@@ -78,12 +105,20 @@ const APP: () = {
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 = 2, resources = [RX, received, errors, changed], spawn = [rx])]
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(); let data = rx.read();
cx.spawn.rx(data).unwrap(); if data.is_err(){
*(cx.resources.errors) += 1;
}
else{
*(cx.resources.received) += 1;
cx.spawn.rx(data.unwrap()).unwrap();
}
*(cx.resources.changed) = true;
} }
extern "C" { extern "C" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment