Skip to content

Commit

Permalink
refactor(threads): use CPU INTR0 for scheduler on esp
Browse files Browse the repository at this point in the history
  • Loading branch information
elenaf9 committed Oct 24, 2024
1 parent fc65556 commit 4bbeb02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/riot-rs-esp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub fn init() -> OptionalPeripherals {
// in `riot_rs_threads::arch::xtensa`.
// So, re-enable it here.

// Panics if `FROM_CPU_INTR1` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// Panics if `FROM_CPU_INTR0` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// which isn't the case.
interrupt::enable(Interrupt::FROM_CPU_INTR1, interrupt::Priority::min()).unwrap();
interrupt::enable(Interrupt::FROM_CPU_INTR0, interrupt::Priority::min()).unwrap();
}

#[cfg(feature = "wifi-esp")]
Expand Down
18 changes: 9 additions & 9 deletions src/riot-rs-threads/src/arch/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl Arch for Cpu {
fn schedule() {
unsafe {
(&*SYSTEM::PTR)
.cpu_intr_from_cpu_1()
.modify(|_, w| w.cpu_intr_from_cpu_1().set_bit());
.cpu_intr_from_cpu_0()
.modify(|_, w| w.cpu_intr_from_cpu_0().set_bit());
}
}

Expand All @@ -40,11 +40,11 @@ impl Arch for Cpu {

/// Enable and trigger the appropriate software interrupt.
fn start_threading() {
interrupt::disable(EspHalCpu::ProCpu, Interrupt::FROM_CPU_INTR1);
interrupt::disable(EspHalCpu::ProCpu, Interrupt::FROM_CPU_INTR0);
Self::schedule();
// Panics if `FROM_CPU_INTR1` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// Panics if `FROM_CPU_INTR0` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// which isn't the case.
interrupt::enable(Interrupt::FROM_CPU_INTR1, interrupt::Priority::min()).unwrap();
interrupt::enable(Interrupt::FROM_CPU_INTR0, interrupt::Priority::min()).unwrap();
}
}

Expand Down Expand Up @@ -103,12 +103,12 @@ fn copy_registers(src: &TrapFrame, dst: &mut TrapFrame) {
/// Handler for software interrupt 0, which we use for context switching.
#[allow(non_snake_case)]
#[no_mangle]
extern "C" fn FROM_CPU_INTR1(trap_frame: &mut TrapFrame) {
extern "C" fn FROM_CPU_INTR0(trap_frame: &mut TrapFrame) {
unsafe {
// clear FROM_CPU_INTR1
// clear FROM_CPU_INTR0
(&*SYSTEM::PTR)
.cpu_intr_from_cpu_1()
.modify(|_, w| w.cpu_intr_from_cpu_1().clear_bit());
.cpu_intr_from_cpu_0()
.modify(|_, w| w.cpu_intr_from_cpu_0().clear_bit());

sched(trap_frame)
}
Expand Down
18 changes: 9 additions & 9 deletions src/riot-rs-threads/src/arch/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl Arch for Cpu {
fn schedule() {
unsafe {
(&*SYSTEM::PTR)
.cpu_intr_from_cpu_1()
.modify(|_, w| w.cpu_intr_from_cpu_1().set_bit());
.cpu_intr_from_cpu_0()
.modify(|_, w| w.cpu_intr_from_cpu_0().set_bit());
}
}

Expand Down Expand Up @@ -45,11 +45,11 @@ impl Arch for Cpu {
}

fn start_threading() {
interrupt::disable(esp_hal::Cpu::ProCpu, Interrupt::FROM_CPU_INTR1);
interrupt::disable(esp_hal::Cpu::ProCpu, Interrupt::FROM_CPU_INTR0);
Self::schedule();
// Panics if `FROM_CPU_INTR1` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// Panics if `FROM_CPU_INTR0` is among `esp_hal::interrupt::RESERVED_INTERRUPTS`,
// which isn't the case.
interrupt::enable(Interrupt::FROM_CPU_INTR1, interrupt::Priority::min()).unwrap();
interrupt::enable(Interrupt::FROM_CPU_INTR0, interrupt::Priority::min()).unwrap();
}
}

Expand All @@ -60,12 +60,12 @@ const fn default_trap_frame() -> TrapFrame {
/// Handler for software interrupt 0, which we use for context switching.
#[allow(non_snake_case)]
#[no_mangle]
extern "C" fn FROM_CPU_INTR1(trap_frame: &mut TrapFrame) {
extern "C" fn FROM_CPU_INTR0(trap_frame: &mut TrapFrame) {
unsafe {
// clear FROM_CPU_INTR1
// clear FROM_CPU_INTR0
(&*SYSTEM::PTR)
.cpu_intr_from_cpu_1()
.modify(|_, w| w.cpu_intr_from_cpu_1().clear_bit());
.cpu_intr_from_cpu_0()
.modify(|_, w| w.cpu_intr_from_cpu_0().clear_bit());

sched(trap_frame)
}
Expand Down

0 comments on commit 4bbeb02

Please sign in to comment.