Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilay Katsnelson committed May 11, 2024
1 parent 777e0ec commit 430b2f5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
1 change: 0 additions & 1 deletion boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::app::recovery_counter_tick;
use crate::app::{fire_drogue, fire_main};
use crate::state_machine::RocketStates;
use common_arm::{spawn, HydraError};
Expand Down
32 changes: 13 additions & 19 deletions boards/recovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,21 @@ mod app {
loop {}

Check warning on line 146 in boards/recovery/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

empty `loop {}` wastes CPU cycles

warning: empty `loop {}` wastes CPU cycles --> boards/recovery/src/main.rs:146:9 | 146 | loop {} | ^^^^^^^ | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop = note: `#[warn(clippy::empty_loop)]` on by default
}

// handle recovery counter
// start a counter
#[task(local = [recovery_timer])]
fn recovery_counter_tick(cx: recovery_counter_tick::Context) {
let timer = cx.local.recovery_timer;
// only start timer if it is not already running
if timer.wait().is_ok() {
// interrupt handler for recovery counter
#[task(binds=TC2, shared=[data_manager, recovery_timer])]
fn recovery_counter_tick(mut cx: recovery_counter_tick::Context) {
cx.shared.recovery_timer.lock(|timer| {
if timer.wait().is_ok() {
cx.shared.data_manager.lock(|data| {
data.recovery_counter += 1;
});
}
// restart timer after interrupt
let duration_mins = atsamd_hal::fugit::MinutesDurationU32::minutes(1);
// timer requires specific duration format
let timer_duration: atsamd_hal::fugit::Duration<u32, 1, 1000000000> =
duration_mins.convert();
timer.enable_interrupt(); // clear interrupt?
let timer_duration: atsamd_hal::fugit::Duration<u32, 1, 1000000000> = duration_mins.convert();
timer.enable_interrupt(); // clear interrupt
timer.start(timer_duration);
}
}

// interrupt handler for when counter is finished
#[task(binds=TC2, shared=[data_manager])]
fn recovery_counter_finish(mut cx: recovery_counter_finish::Context) {
cx.shared.data_manager.lock(|data| {
data.recovery_counter += 1;
});
}

Expand Down Expand Up @@ -209,7 +203,7 @@ mod app {

/// Runs the state machine.
/// This takes control of the shared resources.
#[task(priority = 3, local = [state_machine], shared = [can0, gpio, data_manager, &em])]
#[task(priority = 3, local = [state_machine], shared = [can0, gpio, data_manager, &em, recovery_timer])]
fn run_sm(mut cx: run_sm::Context) {
cx.local.state_machine.run(&mut StateMachineContext {
shared_resources: &mut cx.shared,
Expand Down
5 changes: 3 additions & 2 deletions boards/recovery/src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use enum_dispatch::enum_dispatch;
use messages::state;
use rtic::Mutex;
pub use states::Initializing;
use atsamd_hal::timer::TimerCounter2;

pub trait StateMachineSharedResources {
fn lock_can(&mut self, f: &dyn Fn(&mut CanDevice0));

Check warning on line 18 in boards/recovery/src/state_machine/mod.rs

View workflow job for this annotation

GitHub Actions / All

methods `lock_can`, `lock_data_manager`, `lock_gpio`, and `lock_recovery_timer` are never used

Check warning on line 18 in boards/recovery/src/state_machine/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

methods `lock_can`, `lock_data_manager`, `lock_gpio`, and `lock_recovery_timer` are never used

warning: methods `lock_can`, `lock_data_manager`, `lock_gpio`, and `lock_recovery_timer` are never used --> boards/recovery/src/state_machine/mod.rs:18:8 | 17 | pub trait StateMachineSharedResources { | --------------------------- methods in this trait 18 | fn lock_can(&mut self, f: &dyn Fn(&mut CanDevice0)); | ^^^^^^^^ 19 | fn lock_data_manager(&mut self, f: &dyn Fn(&mut DataManager)); | ^^^^^^^^^^^^^^^^^ 20 | fn lock_gpio(&mut self, f: &dyn Fn(&mut GPIOManager)); | ^^^^^^^^^ 21 | fn lock_recovery_timer(&mut self, f: &dyn Fn(&mut TimerCounter2)); | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
fn lock_data_manager(&mut self, f: &dyn Fn(&mut DataManager));
fn lock_gpio(&mut self, f: &dyn Fn(&mut GPIOManager));
fn lock_timer(&mut self, f: &dyn Fn(&mut TimerCounter2));
fn lock_recovery_timer(&mut self, f: &dyn Fn(&mut TimerCounter2));
}

impl<'a> StateMachineSharedResources for crate::app::__rtic_internal_run_smSharedResources<'a> {
Expand All @@ -30,7 +31,7 @@ impl<'a> StateMachineSharedResources for crate::app::__rtic_internal_run_smShare
fn lock_gpio(&mut self, fun: &dyn Fn(&mut GPIOManager)) {
self.gpio.lock(fun)
}
fn lock_timer(&mut self, fun: &dyn Fn(&mut TimerCounter2)) {
fn lock_recovery_timer(&mut self, fun: &dyn Fn(&mut TimerCounter2)) {
self.recovery_timer.lock(fun)
}
}
Expand Down
13 changes: 10 additions & 3 deletions boards/recovery/src/state_machine/states/terminal_descent.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::Descent;
use crate::app::fire_main;
use crate::state_machine::{
RocketStates, State, StateMachineContext, TransitionInto, WaitForRecovery,
RocketStates, State, StateMachineContext, StateMachineSharedResources, TransitionInto, WaitForRecovery

Check warning on line 4 in boards/recovery/src/state_machine/states/terminal_descent.rs

View workflow job for this annotation

GitHub Actions / All

unused import: `StateMachineSharedResources`

Check warning on line 4 in boards/recovery/src/state_machine/states/terminal_descent.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `StateMachineSharedResources`

warning: unused import: `StateMachineSharedResources` --> boards/recovery/src/state_machine/states/terminal_descent.rs:4:47 | 4 | RocketStates, State, StateMachineContext, StateMachineSharedResources, TransitionInto, WaitForRecovery | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
};
use crate::{no_transition, transition};
use atsamd_hal::timer_traits::InterruptDrivenTimer;
use common_arm::spawn;
use defmt::{write, Format, Formatter};
use rtic::mutex::Mutex;
use atsamd_hal::prelude::_embedded_hal_timer_CountDown;

#[derive(Debug, Clone)]
pub struct TerminalDescent {}
Expand All @@ -17,8 +19,13 @@ impl State for TerminalDescent {
spawn!(fire_main)?;
Ok(())
});
context.shared_resources.timer.lock(|timer| {
timer.start();
// context.shared_resources.
context.shared_resources.recovery_timer.lock(|timer| {
timer.enable_interrupt();
let duration_mins = atsamd_hal::fugit::MinutesDurationU32::minutes(1);
// timer requires specific duration format
let timer_duration: atsamd_hal::fugit::Duration<u32, 1, 1000000000> = duration_mins.convert();
timer.start(timer_duration);
});
}
fn step(&mut self, context: &mut StateMachineContext) -> Option<RocketStates> {
Expand Down
5 changes: 3 additions & 2 deletions boards/recovery/src/state_machine/states/wait_for_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use messages::command::{Command, PowerDown, RadioRate, RadioRateChange};
use messages::sender::Sender::SensorBoard;
use messages::Message;
use rtic::mutex::Mutex;
use atsamd_hal::prelude::_atsamd_hal_timer_traits_InterruptDrivenTimer;

#[derive(Debug, Clone)]
pub struct WaitForRecovery {}
Expand All @@ -32,8 +33,8 @@ impl State for WaitForRecovery {
})
});
}
context.shared_resources.timer.lock(|timer| {
timer.disable_interrupts();
context.shared_resources.recovery_timer.lock(|timer| {
timer.disable_interrupt();
})
}
fn step(&mut self, _context: &mut StateMachineContext) -> Option<RocketStates> {
Expand Down

0 comments on commit 430b2f5

Please sign in to comment.