main: Make critical_sections as short as possible
This commit is contained in:
parent
e024251260
commit
26a8d0d18a
1 changed files with 73 additions and 62 deletions
19
src/main.rs
19
src/main.rs
|
|
@ -162,9 +162,11 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
|
|
||||||
let mut state = applogic::State::new();
|
let mut state = applogic::State::new();
|
||||||
loop {
|
loop {
|
||||||
embassy_time::Timer::after(embassy_time::Duration::from_millis(5)).await;
|
embassy_time::Timer::after(embassy_time::Duration::from_millis(1)).await;
|
||||||
|
|
||||||
#[cfg(feature = "gnss")]
|
#[cfg(feature = "gnss")]
|
||||||
|
{
|
||||||
|
let mut new_position = false;
|
||||||
critical_section::with(|cs| {
|
critical_section::with(|cs| {
|
||||||
let gnss_update_ref = GNSS_UPDATE.borrow(cs);
|
let gnss_update_ref = GNSS_UPDATE.borrow(cs);
|
||||||
|
|
||||||
|
|
@ -176,11 +178,16 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
let _ = screen::clear(&mut display).inspect_err(log_screen_error);
|
let _ = screen::clear(&mut display).inspect_err(log_screen_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if fix.get_timestamp().is_some() {
|
new_position = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if new_position {
|
||||||
info!("{}", state.print_fix());
|
info!("{}", state.print_fix());
|
||||||
|
|
||||||
// run GLOSA algorithm
|
// run GLOSA algorithm
|
||||||
#[cfg(feature = "spat")]
|
#[cfg(feature = "spat")]
|
||||||
|
{
|
||||||
let signal_groups = state.run_glosa();
|
let signal_groups = state.run_glosa();
|
||||||
|
|
||||||
for sig in &signal_groups {
|
for sig in &signal_groups {
|
||||||
|
|
@ -196,14 +203,19 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
.inspect_err(log_screen_error);
|
.inspect_err(log_screen_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
let mut new_data = None;
|
||||||
critical_section::with(|cs| {
|
critical_section::with(|cs| {
|
||||||
let queue_rc = WIFI_RX_QUEUE.borrow(cs).borrow();
|
let queue_rc = WIFI_RX_QUEUE.borrow(cs).borrow();
|
||||||
// unwrap is fine b/c we stored something in it before
|
// unwrap is fine b/c we stored something in it before
|
||||||
let queue = queue_rc.as_ref().unwrap();
|
let queue = queue_rc.as_ref().unwrap();
|
||||||
|
|
||||||
if let Some(data) = queue.pop() {
|
if let Some(data) = queue.pop() {
|
||||||
|
new_data = Some(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if let Some(data) = new_data {
|
||||||
match c_its_parser::de::decode(&data, c_its_parser::Headers::IEEE802LlcGnBtp) {
|
match c_its_parser::de::decode(&data, c_its_parser::Headers::IEEE802LlcGnBtp) {
|
||||||
Ok(msg) => {
|
Ok(msg) => {
|
||||||
use c_its_parser::ItsMessage;
|
use c_its_parser::ItsMessage;
|
||||||
|
|
@ -258,7 +270,6 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// maintenance
|
// maintenance
|
||||||
state.prune();
|
state.prune();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue