mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
feature-out the quantum time
This commit is contained in:
parent
147cfb8c97
commit
41078a71fe
1 changed files with 49 additions and 44 deletions
|
|
@ -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<u32>,
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue