added rp2040 stuff
This commit is contained in:
@@ -22,3 +22,5 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = [
|
||||
"derive",
|
||||
] }
|
||||
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"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["rp2040"]
|
||||
std = ["dep:sysinfo"]
|
||||
nix = ["dep:watchdog-device"]
|
||||
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||
|
||||
[dependencies]
|
||||
rfe = { path = "../../rfe" }
|
||||
@@ -21,3 +22,5 @@ sysinfo = { version = "0.32.0", default-features = false, optional = true, featu
|
||||
"disk",
|
||||
"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 struct StubSystemInfoGrabber;
|
||||
impl StubSystemInfoGrabber {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl SystemInfoGrabber for StubSystemInfoGrabber {
|
||||
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
||||
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]
|
||||
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 }
|
||||
hs = { path = "../../apps/hs", default-features = false, features = ["rp2040"] }
|
||||
anyhow.workspace = true
|
||||
anyhow.default_features = false
|
||||
embedded-alloc = "0.6.0"
|
||||
|
||||
@@ -16,6 +16,7 @@ mod app {
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use fugit::Duration;
|
||||
use hs::{Hs, HsConfig, Rp2040Watchdog, StubSystemInfoGrabber};
|
||||
use log::info;
|
||||
use msg::{ExampleHk, Instance, MsgKind, MsgPacket, TargetMsg, TlmSetItem, ToTlmSet};
|
||||
use rfe::{connector::Connector, Rate, *};
|
||||
@@ -30,7 +31,7 @@ mod app {
|
||||
use embedded_alloc::LlffHeap as Heap;
|
||||
use panic_halt as _;
|
||||
use rp_pico::XOSC_CRYSTAL_FREQ;
|
||||
use time::SchTimeDriver;
|
||||
use time::Rp2040TimeDriver;
|
||||
extern crate alloc;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
@@ -96,6 +97,8 @@ mod app {
|
||||
struct Local {
|
||||
led: Pin<Gpio25, FunctionSio<SioOutput>, PullNone>,
|
||||
usb: Option<Driver<'static, USB>>,
|
||||
wd: Option<Watchdog>,
|
||||
time_driver: Option<Rp2040TimeDriver>,
|
||||
}
|
||||
|
||||
struct UsbBinding;
|
||||
@@ -107,7 +110,7 @@ mod app {
|
||||
// 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
|
||||
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,
|
||||
ctx.device.XOSC,
|
||||
ctx.device.CLOCKS,
|
||||
@@ -138,6 +141,12 @@ mod app {
|
||||
.into_pull_type::<PullNone>()
|
||||
.into_push_pull_output();
|
||||
|
||||
let time_driver = Rp2040TimeDriver::new(
|
||||
unsafe { rp_pico::pac::TIMER::steal() },
|
||||
&mut ctx.device.RESETS,
|
||||
&clocks,
|
||||
);
|
||||
|
||||
// Spawn heartbeat task
|
||||
blink_instance::spawn().ok();
|
||||
usb_logger::spawn().ok();
|
||||
@@ -148,6 +157,8 @@ mod app {
|
||||
Local {
|
||||
led,
|
||||
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) {
|
||||
let mut blink_app = BlinkApp {
|
||||
led_pin: &mut ctx.local.led,
|
||||
@@ -188,10 +199,25 @@ mod app {
|
||||
},
|
||||
);
|
||||
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);
|
||||
instance.add_app("blink_app", &mut blink_app).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);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ edition = "2021"
|
||||
[features]
|
||||
default = []
|
||||
std = ["dep:mio"]
|
||||
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||
to_csv = []
|
||||
|
||||
[dependencies]
|
||||
@@ -14,4 +15,6 @@ anyhow.workspace = true
|
||||
hashbrown.workspace = true
|
||||
log.workspace = 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"
|
||||
|
||||
@@ -43,3 +43,28 @@ impl TimeDriver for SchTimeDriver {
|
||||
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