From 41078a71fe76b11f47a463e64573f2c9f25b2b8f Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 2 Dec 2024 01:22:18 +0800 Subject: [PATCH] feature-out the quantum time --- services/cram-hal-service/src/main.rs | 93 ++++++++++++++------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/services/cram-hal-service/src/main.rs b/services/cram-hal-service/src/main.rs index 39428d8e3..dbb83acc0 100644 --- a/services/cram-hal-service/src/main.rs +++ b/services/cram-hal-service/src/main.rs @@ -13,8 +13,10 @@ use utralib::*; #[cfg(feature = "swap")] use xous::SWAPPER_PID; use xous::sender::Sender; +#[cfg(feature = "pio")] use xous_pio::*; +#[cfg(feature = "quantum-timer")] struct PreemptionHw { pub timer_sm: PioSm, pub irq_csr: CSR, @@ -169,51 +171,54 @@ fn main() { // -------------------- begin timer workaround code // This code should go away with NTO as we have a proper, private ticktimer unit. - let mut pio_ss = xous_pio::PioSharedState::new(); - // map and enable the interrupt for the PIO system timer - let irq18_page = xous::syscall::map_memory( - xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY18_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't claim irq18 csr"); - let mut ptimer = PreemptionHw { - timer_sm: pio_ss.alloc_sm().unwrap(), - irq_csr: CSR::new(irq18_page.as_mut_ptr() as *mut u32), - }; - - // claim the IRQ for the quanta timer - xous::claim_interrupt( - utralib::LITEX_IRQARRAY18_INTERRUPT, - timer_tick, - &mut ptimer as *mut PreemptionHw as *mut usize, - ) - .expect("couldn't claim IRQ"); - - pio_ss.clear_instruction_memory(); - pio_ss.pio.rmwf(utra::rp_pio::SFR_CTRL_EN, 0); - #[rustfmt::skip] - let timer_code = pio_proc::pio_asm!( - "restart:", - "set x, 6", // 4 cycles overhead gets us to 10 iterations per pulse - "waitloop:", - "jmp x-- waitloop", - "irq set 0", - "jmp restart", - ); - let a_prog = LoadedProg::load(timer_code.program, &mut pio_ss).unwrap(); - ptimer.timer_sm.sm_set_enabled(false); - a_prog.setup_default_config(&mut ptimer.timer_sm); - ptimer.timer_sm.config_set_clkdiv(50_000.0f32); // set to 1ms per cycle - ptimer.timer_sm.sm_init(a_prog.entry()); - ptimer.timer_sm.sm_irq0_source_enabled(PioIntSource::Sm, true); - ptimer.timer_sm.sm_set_enabled(true); - - #[cfg(feature = "quantum-timer")] + #[cfg(feature = "pio")] { - ptimer.irq_csr.wfo(utra::irqarray18::EV_ENABLE_PIOIRQ0_DUPE, 1); - log::info!("Quantum timer setup!"); + let mut pio_ss = xous_pio::PioSharedState::new(); + // map and enable the interrupt for the PIO system timer + let irq18_page = xous::syscall::map_memory( + xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY18_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't claim irq18 csr"); + let mut ptimer = PreemptionHw { + timer_sm: pio_ss.alloc_sm().unwrap(), + irq_csr: CSR::new(irq18_page.as_mut_ptr() as *mut u32), + }; + + // claim the IRQ for the quanta timer + xous::claim_interrupt( + utralib::LITEX_IRQARRAY18_INTERRUPT, + timer_tick, + &mut ptimer as *mut PreemptionHw as *mut usize, + ) + .expect("couldn't claim IRQ"); + + pio_ss.clear_instruction_memory(); + pio_ss.pio.rmwf(utra::rp_pio::SFR_CTRL_EN, 0); + #[rustfmt::skip] + let timer_code = pio_proc::pio_asm!( + "restart:", + "set x, 6", // 4 cycles overhead gets us to 10 iterations per pulse + "waitloop:", + "jmp x-- waitloop", + "irq set 0", + "jmp restart", + ); + let a_prog = LoadedProg::load(timer_code.program, &mut pio_ss).unwrap(); + ptimer.timer_sm.sm_set_enabled(false); + a_prog.setup_default_config(&mut ptimer.timer_sm); + ptimer.timer_sm.config_set_clkdiv(50_000.0f32); // set to 1ms per cycle + ptimer.timer_sm.sm_init(a_prog.entry()); + ptimer.timer_sm.sm_irq0_source_enabled(PioIntSource::Sm, true); + ptimer.timer_sm.sm_set_enabled(true); + + #[cfg(feature = "quantum-timer")] + { + ptimer.irq_csr.wfo(utra::irqarray18::EV_ENABLE_PIOIRQ0_DUPE, 1); + log::info!("Quantum timer setup!"); + } } // -------------------- end timer workaround code