added rp2040 stuff
This commit is contained in:
@@ -22,3 +22,5 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = [
|
|||||||
"derive",
|
"derive",
|
||||||
] }
|
] }
|
||||||
simple_logger = "5.0.0"
|
simple_logger = "5.0.0"
|
||||||
|
rp2040-hal = "0.10.2"
|
||||||
|
rp2040-pac = "0.6.0"
|
||||||
|
|||||||
+4
-1
@@ -7,9 +7,10 @@ edition = "2021"
|
|||||||
path = "src/hs.rs"
|
path = "src/hs.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["rp2040"]
|
||||||
std = ["dep:sysinfo"]
|
std = ["dep:sysinfo"]
|
||||||
nix = ["dep:watchdog-device"]
|
nix = ["dep:watchdog-device"]
|
||||||
|
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rfe = { path = "../../rfe" }
|
rfe = { path = "../../rfe" }
|
||||||
@@ -21,3 +22,5 @@ sysinfo = { version = "0.32.0", default-features = false, optional = true, featu
|
|||||||
"disk",
|
"disk",
|
||||||
"system",
|
"system",
|
||||||
] }
|
] }
|
||||||
|
rp2040-hal = { workspace = true, optional = true }
|
||||||
|
rp2040-pac = { workspace = true, optional = true }
|
||||||
|
|||||||
@@ -75,6 +75,12 @@ mod infograbber_std {
|
|||||||
pub use infograbber_std::*;
|
pub use infograbber_std::*;
|
||||||
|
|
||||||
pub struct StubSystemInfoGrabber;
|
pub struct StubSystemInfoGrabber;
|
||||||
|
impl StubSystemInfoGrabber {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SystemInfoGrabber for StubSystemInfoGrabber {
|
impl SystemInfoGrabber for StubSystemInfoGrabber {
|
||||||
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
|
|||||||
@@ -82,3 +82,46 @@ impl<'a> Watchdog for WatchdogRef<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rp2040")]
|
||||||
|
mod watchdog_rp2040 {
|
||||||
|
use rp2040_hal::Watchdog;
|
||||||
|
|
||||||
|
pub struct Rp2040Watchdog {
|
||||||
|
wd: Watchdog,
|
||||||
|
time: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rp2040Watchdog {
|
||||||
|
pub fn new(wd: Watchdog) -> Self {
|
||||||
|
Self {
|
||||||
|
wd,
|
||||||
|
time: 10 * 1000000,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl super::Watchdog for Rp2040Watchdog {
|
||||||
|
fn enable(&mut self) {
|
||||||
|
self.wd
|
||||||
|
.start(rp2040_hal::fugit::Duration::<u32, 1, 1000000>::from_ticks(
|
||||||
|
self.time,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disable(&mut self) {
|
||||||
|
self.wd.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_timeout(&mut self, time: i32) {
|
||||||
|
self.time = time as u32 * 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn feed(&mut self) {
|
||||||
|
self.wd.feed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rp2040")]
|
||||||
|
pub use watchdog_rp2040::*;
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy.git" }
|
embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy.git" }
|
||||||
rfe = { path = "../../rfe", default-features = false }
|
rfe = { path = "../../rfe", default-features = false, features = ["rp2040"] }
|
||||||
to = { path = "../../apps/to", default-features = false }
|
to = { path = "../../apps/to", default-features = false }
|
||||||
|
hs = { path = "../../apps/hs", default-features = false, features = ["rp2040"] }
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
anyhow.default_features = false
|
anyhow.default_features = false
|
||||||
embedded-alloc = "0.6.0"
|
embedded-alloc = "0.6.0"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ mod app {
|
|||||||
};
|
};
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
use fugit::Duration;
|
use fugit::Duration;
|
||||||
|
use hs::{Hs, HsConfig, Rp2040Watchdog, StubSystemInfoGrabber};
|
||||||
use log::info;
|
use log::info;
|
||||||
use msg::{ExampleHk, Instance, MsgKind, MsgPacket, TargetMsg, TlmSetItem, ToTlmSet};
|
use msg::{ExampleHk, Instance, MsgKind, MsgPacket, TargetMsg, TlmSetItem, ToTlmSet};
|
||||||
use rfe::{connector::Connector, Rate, *};
|
use rfe::{connector::Connector, Rate, *};
|
||||||
@@ -30,7 +31,7 @@ mod app {
|
|||||||
use embedded_alloc::LlffHeap as Heap;
|
use embedded_alloc::LlffHeap as Heap;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use rp_pico::XOSC_CRYSTAL_FREQ;
|
use rp_pico::XOSC_CRYSTAL_FREQ;
|
||||||
use time::SchTimeDriver;
|
use time::Rp2040TimeDriver;
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
@@ -96,6 +97,8 @@ mod app {
|
|||||||
struct Local {
|
struct Local {
|
||||||
led: Pin<Gpio25, FunctionSio<SioOutput>, PullNone>,
|
led: Pin<Gpio25, FunctionSio<SioOutput>, PullNone>,
|
||||||
usb: Option<Driver<'static, USB>>,
|
usb: Option<Driver<'static, USB>>,
|
||||||
|
wd: Option<Watchdog>,
|
||||||
|
time_driver: Option<Rp2040TimeDriver>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UsbBinding;
|
struct UsbBinding;
|
||||||
@@ -107,7 +110,7 @@ mod app {
|
|||||||
// Configure the clocks, watchdog - The default is to generate a 125 MHz system clock
|
// Configure the clocks, watchdog - The default is to generate a 125 MHz system clock
|
||||||
Mono::start(ctx.device.TIMER, &mut ctx.device.RESETS); // default rp2040 clock-rate is 125MHz
|
Mono::start(ctx.device.TIMER, &mut ctx.device.RESETS); // default rp2040 clock-rate is 125MHz
|
||||||
let mut watchdog = Watchdog::new(ctx.device.WATCHDOG);
|
let mut watchdog = Watchdog::new(ctx.device.WATCHDOG);
|
||||||
let _clocks = clocks::init_clocks_and_plls(
|
let clocks = clocks::init_clocks_and_plls(
|
||||||
XOSC_CRYSTAL_FREQ,
|
XOSC_CRYSTAL_FREQ,
|
||||||
ctx.device.XOSC,
|
ctx.device.XOSC,
|
||||||
ctx.device.CLOCKS,
|
ctx.device.CLOCKS,
|
||||||
@@ -138,6 +141,12 @@ mod app {
|
|||||||
.into_pull_type::<PullNone>()
|
.into_pull_type::<PullNone>()
|
||||||
.into_push_pull_output();
|
.into_push_pull_output();
|
||||||
|
|
||||||
|
let time_driver = Rp2040TimeDriver::new(
|
||||||
|
unsafe { rp_pico::pac::TIMER::steal() },
|
||||||
|
&mut ctx.device.RESETS,
|
||||||
|
&clocks,
|
||||||
|
);
|
||||||
|
|
||||||
// Spawn heartbeat task
|
// Spawn heartbeat task
|
||||||
blink_instance::spawn().ok();
|
blink_instance::spawn().ok();
|
||||||
usb_logger::spawn().ok();
|
usb_logger::spawn().ok();
|
||||||
@@ -148,6 +157,8 @@ mod app {
|
|||||||
Local {
|
Local {
|
||||||
led,
|
led,
|
||||||
usb: Some(driver),
|
usb: Some(driver),
|
||||||
|
wd: Some(watchdog),
|
||||||
|
time_driver: Some(time_driver),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -165,7 +176,7 @@ mod app {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [led], priority = 1)]
|
#[task(local = [led, wd, time_driver], priority = 1)]
|
||||||
async fn blink_instance(mut ctx: blink_instance::Context) {
|
async fn blink_instance(mut ctx: blink_instance::Context) {
|
||||||
let mut blink_app = BlinkApp {
|
let mut blink_app = BlinkApp {
|
||||||
led_pin: &mut ctx.local.led,
|
led_pin: &mut ctx.local.led,
|
||||||
@@ -188,13 +199,28 @@ mod app {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
let mut to = To::new(&mut log_connector, tlmsets);
|
let mut to = To::new(&mut log_connector, tlmsets);
|
||||||
let time_driver = SchTimeDriver::new();
|
let mut wd = Rp2040Watchdog::new(ctx.local.wd.take().unwrap());
|
||||||
|
let mut grabber = StubSystemInfoGrabber::new();
|
||||||
|
let mut hs = Hs::new(
|
||||||
|
HsConfig {
|
||||||
|
cpu_checks: false,
|
||||||
|
fs_checks: false,
|
||||||
|
mem_checks: false,
|
||||||
|
temp_checks: false,
|
||||||
|
watchdog_enable: true,
|
||||||
|
watchdog_timeout: 10,
|
||||||
|
},
|
||||||
|
&mut grabber,
|
||||||
|
Some(&mut wd),
|
||||||
|
);
|
||||||
|
let time_driver = ctx.local.time_driver.take().unwrap();
|
||||||
let mut instance = RfeInstance::new(Instance::Example, &time_driver);
|
let mut instance = RfeInstance::new(Instance::Example, &time_driver);
|
||||||
instance.add_app("blink_app", &mut blink_app).unwrap();
|
instance.add_app("blink_app", &mut blink_app).unwrap();
|
||||||
instance.add_app("to", &mut to).unwrap();
|
instance.add_app("to", &mut to).unwrap();
|
||||||
|
instance.add_app("hs", &mut hs).unwrap();
|
||||||
|
|
||||||
let mut next_time = Mono::now() + Duration::<u64, 1, 1000000>::from_ticks(10000);
|
let mut next_time = Mono::now() + Duration::<u64, 1, 1000000>::from_ticks(10000);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
instance.run();
|
instance.run();
|
||||||
Mono::delay_until(next_time).await;
|
Mono::delay_until(next_time).await;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
std = ["dep:mio"]
|
std = ["dep:mio"]
|
||||||
|
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||||
to_csv = []
|
to_csv = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@@ -14,4 +15,6 @@ anyhow.workspace = true
|
|||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
mio = { version = "1.0.2", features = ["net", "os-poll"], optional = true }
|
mio = { version = "1.0.2", features = ["net", "os-poll"], optional = true }
|
||||||
|
rp2040-hal = { workspace = true, optional = true }
|
||||||
|
rp2040-pac = { workspace = true, optional = true }
|
||||||
macros.path = "macros"
|
macros.path = "macros"
|
||||||
|
|||||||
@@ -43,3 +43,28 @@ impl TimeDriver for SchTimeDriver {
|
|||||||
time_data.sch_counter + time_data.time_offset
|
time_data.sch_counter + time_data.time_offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rp2040")]
|
||||||
|
pub struct Rp2040TimeDriver {
|
||||||
|
timer: rp2040_hal::timer::Timer,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rp2040")]
|
||||||
|
impl Rp2040TimeDriver {
|
||||||
|
pub fn new(
|
||||||
|
timer: rp2040_pac::TIMER,
|
||||||
|
resets: &mut rp2040_pac::RESETS,
|
||||||
|
clocks: &rp2040_hal::clocks::ClocksManager,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
timer: rp2040_hal::timer::Timer::new(timer, resets, clocks),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rp2040")]
|
||||||
|
impl TimeDriver for Rp2040TimeDriver {
|
||||||
|
fn get_system_time(&self, time_data: TimeData) -> Timestamp {
|
||||||
|
self.timer.get_counter().ticks() + time_data.time_offset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user