esp_wifi/preempt_builtin/timer/
riscv.rs
1#[cfg(any(esp32c6, esp32h2))]
2use peripherals::INTPRI as SystemPeripheral;
3#[cfg(not(any(esp32c6, esp32h2)))]
4use peripherals::SYSTEM as SystemPeripheral;
5
6use crate::{
7 TimeBase,
8 hal::{
9 interrupt::{self, TrapFrame},
10 peripherals::{self, Interrupt},
11 riscv,
12 },
13 preempt_builtin::{task_switch, timer::setup_timebase},
14};
15
16pub(crate) fn setup_timer(timer: TimeBase) {
17 riscv::interrupt::disable();
19
20 setup_timebase(timer);
21}
22
23pub(crate) fn setup_multitasking() {
24 unwrap!(interrupt::enable(
25 Interrupt::FROM_CPU_INTR2,
26 interrupt::Priority::Priority1,
27 ));
28
29 unsafe {
30 riscv::interrupt::enable();
31 }
32}
33
34pub(crate) fn disable_multitasking() {
35 interrupt::disable(crate::hal::system::Cpu::ProCpu, Interrupt::FROM_CPU_INTR2);
36}
37
38#[unsafe(no_mangle)]
39extern "C" fn FROM_CPU_INTR2(trap_frame: &mut TrapFrame) {
40 SystemPeripheral::regs()
42 .cpu_intr_from_cpu_2()
43 .modify(|_, w| w.cpu_intr_from_cpu_2().clear_bit());
44
45 task_switch(trap_frame);
46}
47
48pub(crate) fn yield_task() {
49 SystemPeripheral::regs()
50 .cpu_intr_from_cpu_2()
51 .modify(|_, w| w.cpu_intr_from_cpu_2().set_bit());
52}