diff --git a/apps/ds/src/ds.rs b/apps/ds/src/ds.rs index a3d23bb..7ae7176 100644 --- a/apps/ds/src/ds.rs +++ b/apps/ds/src/ds.rs @@ -65,6 +65,7 @@ impl App for Ds { } fn run(&mut self, rfe: &mut rfe::Rfe) { + self.data.hk.perf.enter(rfe); self.data.out_data.counter += 1; self.data.out_data.bytes_written_this_cycle = 0; while let Some(msg) = rfe.recv() { @@ -169,6 +170,7 @@ impl App for Ds { } self.data.out_data.bytes_written += self.data.out_data.bytes_written_this_cycle; + self.data.hk.perf.exit(rfe); } fn hk(&mut self, rfe: &mut rfe::Rfe) { diff --git a/apps/example/src/example.rs b/apps/example/src/example.rs index 4a10507..3e1a1e0 100644 --- a/apps/example/src/example.rs +++ b/apps/example/src/example.rs @@ -32,6 +32,7 @@ impl App for Example { } fn run(&mut self, rfe: &mut rfe::Rfe) { + self.data.hk.perf.enter(rfe); self.data.out_data.counter += 1; info!("example running {:?}", self.data); while let Some(msg) = rfe.recv() { @@ -52,6 +53,7 @@ impl App for Example { if self.data.out_data.counter > 10 { rfe.send(Msg::ExampleCmd(ExampleCmd::Reset)); }; + self.data.hk.perf.exit(rfe); } fn hk(&mut self, rfe: &mut rfe::Rfe) { diff --git a/apps/hs/src/hs.rs b/apps/hs/src/hs.rs index bf74dc1..6e61638 100644 --- a/apps/hs/src/hs.rs +++ b/apps/hs/src/hs.rs @@ -72,6 +72,7 @@ impl App for Hs<'_> { } fn run(&mut self, rfe: &mut Rfe) { + self.data.hk.perf.enter(rfe); self.data.out_data.counter += 1; while let Some(msg) = rfe.recv() { match msg.msg { @@ -121,6 +122,8 @@ impl App for Hs<'_> { if self.config.temp_checks { self.data.hk.temps = self.grabber.check_temps(); } + + self.data.hk.perf.exit(rfe); } fn hk(&mut self, rfe: &mut Rfe) { diff --git a/apps/to/src/to.rs b/apps/to/src/to.rs index 313e63e..f3ea848 100644 --- a/apps/to/src/to.rs +++ b/apps/to/src/to.rs @@ -99,6 +99,7 @@ impl App for To<'_> { } fn run(&mut self, rfe: &mut Rfe) { + self.data.hk.perf.enter(rfe); self.data.out_data.counter += 1; let mut msgs = Vec::new(); while let Some(msg) = rfe.recv() { @@ -135,6 +136,7 @@ impl App for To<'_> { rfe.post_message(msg); } } + self.data.hk.perf.exit(rfe); } fn hk(&mut self, rfe: &mut Rfe) { diff --git a/builds/ground/Cargo.toml b/builds/ground/Cargo.toml index 6b5b03f..b8a81e9 100644 --- a/builds/ground/Cargo.toml +++ b/builds/ground/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] rfe.path = "../../rfe" +rfe.features = ["std"] anyhow.workspace = true simple_logger = "5.0.0" log.workspace = true diff --git a/rfe/macros/src/macros.rs b/rfe/macros/src/macros.rs index 8398bf5..7b6b271 100644 --- a/rfe/macros/src/macros.rs +++ b/rfe/macros/src/macros.rs @@ -93,7 +93,7 @@ pub fn to_csv_derive(input: TokenStream) -> TokenStream { let field_name = field_ident.to_string(); quote! { { - let mut field_csvs: Vec = (&self.#field_ident as &dyn ToCsv).to_csv(); + let mut field_csvs: alloc::vec::Vec = (&self.#field_ident as &dyn ToCsv).to_csv(); for entry in &mut field_csvs { *entry = format!("{}.{}", #field_name, &entry); } @@ -103,11 +103,11 @@ pub fn to_csv_derive(input: TokenStream) -> TokenStream { quote! { impl ToCsv for #name { - fn to_csv(&self) -> Vec { + fn to_csv(&self) -> alloc::vec::Vec { extern crate alloc; use alloc::format; - let mut values:Vec = Vec::new(); + let mut values:alloc::vec::Vec = alloc::vec::Vec::new(); #(#arms)* for value in &mut values { *value = format!("{}", value); @@ -130,7 +130,7 @@ pub fn to_csv_derive(input: TokenStream) -> TokenStream { } Fields::Unnamed(_) => { quote! {Self::#variant_name(l) => { - let mut field_csvs: Vec = (l as &dyn ToCsv).to_csv(); + let mut field_csvs: alloc::vec::Vec = (l as &dyn ToCsv).to_csv(); for entry in &mut field_csvs { *entry = format!("{}.{}", #variant_name_s, &entry); } @@ -145,10 +145,10 @@ pub fn to_csv_derive(input: TokenStream) -> TokenStream { quote! { impl ToCsv for #name { - fn to_csv(&self) -> Vec { + fn to_csv(&self) -> alloc::vec::Vec { extern crate alloc; use alloc::format; - let mut values: Vec = Vec::new(); + let mut values: alloc::vec::Vec = alloc::vec::Vec::new(); match self { #(#arms)* diff --git a/rfe/src/lib.rs b/rfe/src/lib.rs index 8007abd..c52e81c 100644 --- a/rfe/src/lib.rs +++ b/rfe/src/lib.rs @@ -11,9 +11,7 @@ mod rfe; pub use rfe::*; #[cfg(feature = "to_csv")] -mod to_csv; -#[cfg(feature = "to_csv")] -pub use to_csv::*; +pub mod to_csv; pub mod time; pub mod utils; diff --git a/rfe/src/msg.rs b/rfe/src/msg.rs deleted file mode 100644 index 7b0a12d..0000000 --- a/rfe/src/msg.rs +++ /dev/null @@ -1,222 +0,0 @@ -extern crate alloc; - -use alloc::string::String; -use alloc::vec::Vec; -use bincode::{Decode, Encode}; -use macros::Kind; - -use crate::time::Timestamp; -#[cfg(feature = "to_csv")] -use crate::ToCsv; -#[cfg(feature = "to_csv")] -use macros::ToCsv; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct TargetMsg { - // instance is FROM for tlm, is TO for cmds - pub instance: Instance, - pub msg: MsgKind, -} - -impl TargetMsg { - pub fn new(instance: Instance, msg: MsgKind) -> Self { - Self { instance, msg } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum Instance { - All, - Other, - Example, - Example2, -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ReinitAppCmd { - app_name: String, -} - -#[derive(Debug, Clone, PartialEq, Kind, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum Msg { - None, - SubRequest, - SubList(SubList), - SetTimeCmd(u64), - ReinitApp(ReinitAppCmd), - ExampleHk(ExampleHk), - ExampleOutData(ExampleOutData), - ExampleCmd(ExampleCmd), - DsHk(DsHk), - DsOutData(DsOutData), - DsCmd(DsCmd), - HsHk(HsHk), - HsOutData(HsOutData), - HsCmd(HsCmd), - ToHk(ToHk), - ToOutData(ToOutData), - ToCmd(ToCmd), -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct MsgPacket { - pub instance: Instance, - pub msg: Msg, - pub timestamp: Timestamp, -} - -impl MsgPacket { - pub fn to_target(&self) -> TargetMsg { - TargetMsg::new(self.instance, self.msg.kind()) - } - - pub fn new(instance: Instance, msg: Msg, timestamp: Timestamp) -> Self { - Self { - instance, - msg, - timestamp, - } - } - - pub fn timestamp(&mut self, timestamp: Timestamp) { - self.timestamp = timestamp; - } -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct SubList { - pub subs: Vec, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ExampleHk { - pub counter: u32, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ExampleOutData { - pub counter: u32, -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum ExampleCmd { - Noop, - Reset, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct DsTlmSet { - pub items: Vec, - pub id: TlmSetId, - pub enabled: bool, - pub path: String, -} - -pub type TlmSetId = u16; - -#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct TlmSetItem { - pub target: TargetMsg, - pub decimation: u16, - pub counter: u16, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] - -pub struct DsHk { - pub counter: u32, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct DsOutData { - pub counter: u32, - pub bytes_written: u32, - pub bytes_written_this_cycle: u32, -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum DsCmd { - Noop, - Reset, - CloseAll, - Close(TlmSetId), - AddTlmSet(DsTlmSet), - RemoveTlmSet(TlmSetId), - DisableTlmSet(TlmSetId), - EnablTlmSet(TlmSetId), -} - -#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct HsHk { - pub counter: u32, - pub cpu_usage: Vec, - pub mem_usage: u8, - pub fs_usage: Vec, - pub temps: Vec, - pub cmd_counter: u8, - pub cpu_usage_enabled: bool, - pub mem_usage_enabled: bool, - pub fs_usage_enabled: bool, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct HsOutData { - pub counter: u32, -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum HsCmd { - Noop, - Reset, - WatchdogEnableManual(bool), - WatchdogEnableAuto(bool), - WatchdogResumeAuto, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ToTlmSet { - pub items: Vec, - pub id: TlmSetId, - pub enabled: bool, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ToHk { - pub counter: u32, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub struct ToOutData { - pub counter: u32, -} - -#[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "to_csv", derive(ToCsv))] -pub enum ToCmd { - Noop, - Reset, - AddTlmSet(ToTlmSet), - RemoveTlmSet(TlmSetId), - DisableTlmSet(TlmSetId), - EnablTlmSet(TlmSetId), -} diff --git a/rfe/src/msg/ds.rs b/rfe/src/msg/ds.rs new file mode 100644 index 0000000..21fde9f --- /dev/null +++ b/rfe/src/msg/ds.rs @@ -0,0 +1,48 @@ +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +use crate::utils::PerfData; +use bincode::{Decode, Encode}; +#[cfg(feature = "to_csv")] +use macros::ToCsv; +extern crate alloc; +use alloc::string::String; +use alloc::vec::Vec; + +use super::{TlmSetId, TlmSetItem}; + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct DsTlmSet { + pub items: Vec, + pub id: TlmSetId, + pub enabled: bool, + pub path: String, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct DsHk { + pub perf: PerfData, + pub counter: u32, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct DsOutData { + pub counter: u32, + pub bytes_written: u32, + pub bytes_written_this_cycle: u32, +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum DsCmd { + Noop, + Reset, + CloseAll, + Close(TlmSetId), + AddTlmSet(DsTlmSet), + RemoveTlmSet(TlmSetId), + DisableTlmSet(TlmSetId), + EnablTlmSet(TlmSetId), +} diff --git a/rfe/src/msg/example.rs b/rfe/src/msg/example.rs new file mode 100644 index 0000000..6530b26 --- /dev/null +++ b/rfe/src/msg/example.rs @@ -0,0 +1,27 @@ +extern crate alloc; +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +use crate::utils::PerfData; +use bincode::{Decode, Encode}; +#[cfg(feature = "to_csv")] +use macros::ToCsv; + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ExampleHk { + pub perf: PerfData, + pub counter: u32, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ExampleOutData { + pub counter: u32, +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum ExampleCmd { + Noop, + Reset, +} diff --git a/rfe/src/msg/hs.rs b/rfe/src/msg/hs.rs new file mode 100644 index 0000000..af50fef --- /dev/null +++ b/rfe/src/msg/hs.rs @@ -0,0 +1,39 @@ +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +use crate::utils::PerfData; +use bincode::{Decode, Encode}; +#[cfg(feature = "to_csv")] +use macros::ToCsv; +extern crate alloc; +use alloc::vec::Vec; + +#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct HsHk { + pub perf: PerfData, + pub counter: u32, + pub cpu_usage: Vec, + pub mem_usage: u8, + pub fs_usage: Vec, + pub temps: Vec, + pub cmd_counter: u8, + pub cpu_usage_enabled: bool, + pub mem_usage_enabled: bool, + pub fs_usage_enabled: bool, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct HsOutData { + pub counter: u32, +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum HsCmd { + Noop, + Reset, + WatchdogEnableManual(bool), + WatchdogEnableAuto(bool), + WatchdogResumeAuto, +} diff --git a/rfe/src/msg/mod.rs b/rfe/src/msg/mod.rs new file mode 100644 index 0000000..890956a --- /dev/null +++ b/rfe/src/msg/mod.rs @@ -0,0 +1,114 @@ +extern crate alloc; + +use alloc::string::String; +use alloc::vec::Vec; +use bincode::{Decode, Encode}; +use macros::Kind; + +mod example; +pub use example::*; +mod hs; +pub use hs::*; +mod to; +pub use to::*; +mod ds; +pub use ds::*; + +use crate::time::Timestamp; +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +#[cfg(feature = "to_csv")] +use macros::ToCsv; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct TargetMsg { + // instance is FROM for tlm, is TO for cmds + pub instance: Instance, + pub msg: MsgKind, +} + +impl TargetMsg { + pub fn new(instance: Instance, msg: MsgKind) -> Self { + Self { instance, msg } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum Instance { + All, + Other, + Example, + Example2, +} + +#[derive(Debug, Clone, PartialEq, Kind, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum Msg { + None, + SubRequest, + SubList(SubList), + SetTimeCmd(u64), + ReinitApp(ReinitAppCmd), + ExampleHk(ExampleHk), + ExampleOutData(ExampleOutData), + ExampleCmd(ExampleCmd), + DsHk(DsHk), + DsOutData(DsOutData), + DsCmd(DsCmd), + HsHk(HsHk), + HsOutData(HsOutData), + HsCmd(HsCmd), + ToHk(ToHk), + ToOutData(ToOutData), + ToCmd(ToCmd), +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct MsgPacket { + pub instance: Instance, + pub msg: Msg, + pub timestamp: Timestamp, +} + +impl MsgPacket { + pub fn to_target(&self) -> TargetMsg { + TargetMsg::new(self.instance, self.msg.kind()) + } + + pub fn new(instance: Instance, msg: Msg, timestamp: Timestamp) -> Self { + Self { + instance, + msg, + timestamp, + } + } + + pub fn timestamp(&mut self, timestamp: Timestamp) { + self.timestamp = timestamp; + } +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct SubList { + pub subs: Vec, +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ReinitAppCmd { + app_name: String, +} + +pub type TlmSetId = u16; + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct TlmSetItem { + pub target: TargetMsg, + pub decimation: u16, + pub counter: u16, +} diff --git a/rfe/src/msg/to.rs b/rfe/src/msg/to.rs new file mode 100644 index 0000000..4e0ce4a --- /dev/null +++ b/rfe/src/msg/to.rs @@ -0,0 +1,42 @@ +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +use crate::utils::PerfData; +use bincode::{Decode, Encode}; +#[cfg(feature = "to_csv")] +use macros::ToCsv; +extern crate alloc; +use alloc::vec::Vec; + +use super::{TlmSetId, TlmSetItem}; + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ToTlmSet { + pub items: Vec, + pub id: TlmSetId, + pub enabled: bool, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ToHk { + pub perf: PerfData, + pub counter: u32, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct ToOutData { + pub counter: u32, +} + +#[derive(Debug, Clone, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub enum ToCmd { + Noop, + Reset, + AddTlmSet(ToTlmSet), + RemoveTlmSet(TlmSetId), + DisableTlmSet(TlmSetId), + EnablTlmSet(TlmSetId), +} diff --git a/rfe/src/rfe.rs b/rfe/src/rfe.rs index b8b05da..ec4691c 100644 --- a/rfe/src/rfe.rs +++ b/rfe/src/rfe.rs @@ -127,15 +127,10 @@ impl<'a> Rfe<'a> { self.msgs_recevied.pop_front() } - /// time in 10ms increments starting from power on + /// time starting from power on or program start pub fn get_met_time(&self) -> u64 { - self.time.borrow().time_data.sch_counter - } - - /// time in 10ms increments based on set time. Shows MET until time is set - pub fn get_time(&self) -> u64 { let time = self.time.borrow(); - time.time_data.sch_counter + time.time_data.time_offset + time.time_driver.get_monotonic_time(time.time_data) } /// Time in microseconds relative to system epoch diff --git a/rfe/src/time.rs b/rfe/src/time.rs index f56caf8..3ae4063 100644 --- a/rfe/src/time.rs +++ b/rfe/src/time.rs @@ -1,22 +1,30 @@ +/// Microseconds timestamp pub type Timestamp = u64; #[derive(Debug, Clone, Copy)] pub struct TimeData { pub sch_counter: u64, - pub time_offset: u64, + pub time_offset: Timestamp, } pub trait TimeDriver { /// Time in microseconds relative to system epoch fn get_system_time(&self, time_data: TimeData) -> Timestamp; + + /// Time in microseconds since program start or power on + fn get_monotonic_time(&self, time_data: TimeData) -> Timestamp; } #[cfg(feature = "std")] -pub struct UnixTimeDriver; +pub struct UnixTimeDriver { + start_time: std::time::Instant, +} #[cfg(feature = "std")] impl UnixTimeDriver { pub fn new() -> Self { - Self {} + Self { + start_time: std::time::Instant::now(), + } } } @@ -27,7 +35,11 @@ impl TimeDriver for UnixTimeDriver { SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() - .as_micros() as u64 + .as_micros() as Timestamp + } + + fn get_monotonic_time(&self, _time_data: TimeData) -> Timestamp { + self.start_time.elapsed().as_micros() as Timestamp } } @@ -42,6 +54,10 @@ impl TimeDriver for SchTimeDriver { fn get_system_time(&self, time_data: TimeData) -> Timestamp { time_data.sch_counter + time_data.time_offset } + + fn get_monotonic_time(&self, time_data: TimeData) -> Timestamp { + return time_data.sch_counter * 10000; + } } #[cfg(feature = "rp2040")] @@ -67,4 +83,8 @@ impl TimeDriver for Rp2040TimeDriver { fn get_system_time(&self, time_data: TimeData) -> Timestamp { self.timer.get_counter().ticks() + time_data.time_offset } + + fn get_monotonic_time(&self, _time_data: TimeData) -> Timestamp { + self.timer.get_counter().ticks() + } } diff --git a/rfe/src/utils.rs b/rfe/src/utils.rs index a11a999..2e86396 100644 --- a/rfe/src/utils.rs +++ b/rfe/src/utils.rs @@ -1,3 +1,41 @@ +use crate::time::Timestamp; +use crate::Rfe; +use bincode::{Decode, Encode}; + +extern crate alloc; +#[cfg(feature = "to_csv")] +use crate::to_csv::ToCsv; +#[cfg(feature = "to_csv")] +use macros::ToCsv; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Encode, Decode)] +#[cfg_attr(feature = "to_csv", derive(ToCsv))] +pub struct PerfData { + enter_time: Timestamp, + elapsed: u32, + rate: u32, +} + +impl PerfData { + pub fn new(rfe: &Rfe) -> Self { + Self { + enter_time: rfe.get_met_time(), + elapsed: 0, + rate: 0, + } + } + + pub fn enter(&mut self, rfe: &Rfe) { + let time = rfe.get_met_time(); + self.rate = (time - self.enter_time) as u32; + self.enter_time = time; + } + + pub fn exit(&mut self, rfe: &Rfe) { + let time = rfe.get_met_time(); + self.elapsed = (time - self.enter_time) as u32; + } +} pub struct ManualAuto { value_auto: T,