From a5ebcf5d0fc53dc1344cbe58de0be11fa7241c0b Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Dec 2024 03:28:13 +0800 Subject: [PATCH] refactor reset api for UDMA there's now unfortunately branch divergence in the NTO/MPW code base The methodology is to code like we're running on NTO, and if the "mpw" feature is selected, we put hacks in to run on MPW hardware. Under the theory that MPW should be totally deprecated once NTO comes out, and therefore the hacks should accumulate in the MPW code base (and ideally be somewhat easy to cull when the time comes). --- services/cram-hal-service/Cargo.toml | 1 + services/cram-hal-service/src/api.rs | 3 +++ services/cram-hal-service/src/lib.rs | 16 ++++++++++++++++ services/cram-hal-service/src/main.rs | 14 +++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/services/cram-hal-service/Cargo.toml b/services/cram-hal-service/Cargo.toml index 2ec8d1bd8..e263336bf 100644 --- a/services/cram-hal-service/Cargo.toml +++ b/services/cram-hal-service/Cargo.toml @@ -42,6 +42,7 @@ pio-memlcd = [] rawserial = [] pinger = [] swap = [] +mpw = ["cramium-hal/mpw"] # add this feature to enable pre-emption quantum-timer = ["utralib", "pio"] default = ["app-uart"] diff --git a/services/cram-hal-service/src/api.rs b/services/cram-hal-service/src/api.rs index 6573037ed..0db7e6785 100644 --- a/services/cram-hal-service/src/api.rs +++ b/services/cram-hal-service/src/api.rs @@ -44,6 +44,9 @@ pub enum Opcode { /// I2C operations I2c = 9, + /// Peripheral reset + PeriphReset = 10, + /// Exit server Quit = 255, diff --git a/services/cram-hal-service/src/lib.rs b/services/cram-hal-service/src/lib.rs index 4f78f8771..814d1f2a4 100644 --- a/services/cram-hal-service/src/lib.rs +++ b/services/cram-hal-service/src/lib.rs @@ -66,6 +66,20 @@ impl UdmaGlobal { ) .expect("Couldn't setup UDMA event mapping"); } + + pub fn reset(&self, peripheral: PeriphId) { + xous::send_message( + self.conn, + xous::Message::new_blocking_scalar( + Opcode::PeriphReset.to_usize().unwrap(), + peripheral as u32 as usize, + 0, + 0, + 0, + ), + ) + .expect("Couldn't setup UDMA clock"); + } } impl UdmaGlobalConfig for UdmaGlobal { @@ -79,4 +93,6 @@ impl UdmaGlobalConfig for UdmaGlobal { ) { self.udma_event_map(peripheral, event_type, to_channel); } + + fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); } } diff --git a/services/cram-hal-service/src/main.rs b/services/cram-hal-service/src/main.rs index dbb83acc0..ae93b4338 100644 --- a/services/cram-hal-service/src/main.rs +++ b/services/cram-hal-service/src/main.rs @@ -166,7 +166,13 @@ fn main() { ) }; let mut i2c = unsafe { - cramium_hal::udma::I2c::new_with_ifram(i2c_channel, 400_000, cram_hal_service::PERCLK, i2c_ifram) + cramium_hal::udma::I2c::new_with_ifram( + i2c_channel, + 400_000, + cram_hal_service::PERCLK, + i2c_ifram, + &udma_global, + ) }; // -------------------- begin timer workaround code @@ -371,6 +377,12 @@ fn main() { udma_global.map_event_with_offset(periph, event_offset, to_channel); } } + Opcode::PeriphReset => { + if let Some(scalar) = msg.body.scalar_message() { + let periph: PeriphId = num_traits::FromPrimitive::from_usize(scalar.arg1).unwrap(); + udma_global.reset(periph); + } + } Opcode::I2c => { let mut buf = unsafe { xous_ipc::Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())