Skip to content

Commit

Permalink
Make software interrupts shareable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominaezzz committed Apr 22, 2024
1 parent e0610f7 commit 33baaac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Created virtual peripherals for CPU control and radio clocks, rather than splitting them from `SYSTEM` (#1428)
- `IO`, `ADC`, `DAC`, `RTC*`, `LEDC`, `PWM` and `PCNT` drivers have been converted to camel case format (#1473)
- RNG is no longer TRNG, the `CryptoRng` implementation has been removed. To track this being re-added see #1499 (#1498)
- Make software interrupts shareable (#1500)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<const NUM: u8> SoftwareInterrupt<NUM> {
}

/// Trigger this software-interrupt
pub fn raise(&mut self) {
pub fn raise(&self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let system = unsafe { &*SYSTEM::PTR };
#[cfg(any(esp32c6, esp32h2))]
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<const NUM: u8> SoftwareInterrupt<NUM> {
}

/// Resets this software-interrupt
pub fn reset(&mut self) {
pub fn reset(&self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let system = unsafe { &*SYSTEM::PTR };
#[cfg(any(esp32c6, esp32h2))]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/direct_vectoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn main() -> ! {
fn interrupt20() {
unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") }
critical_section::with(|cs| {
SWINT0.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT0.borrow_ref(cs).as_mut().unwrap().reset();
});

let mut perf_counter: u32 = 0;
Expand Down
16 changes: 8 additions & 8 deletions examples/src/bin/interrupt_preemption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() -> ! {
// exiting the handler Once the handler is exited we expect to see same
// priority and low priority interrupts served in that order.
critical_section::with(|cs| {
SWINT1.borrow_ref_mut(cs).as_mut().unwrap().raise();
SWINT1.borrow_ref(cs).as_mut().unwrap().raise();
});

loop {}
Expand All @@ -73,18 +73,18 @@ fn main() -> ! {
fn swint0_handler() {
esp_println::println!("SW interrupt0");
critical_section::with(|cs| {
SWINT0.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT0.borrow_ref(cs).as_mut().unwrap().reset();
});
}

#[handler(priority = esp_hal::interrupt::Priority::Priority2)]
fn swint1_handler() {
esp_println::println!("SW interrupt1 entry");
critical_section::with(|cs| {
SWINT1.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT2.borrow_ref_mut(cs).as_mut().unwrap().raise(); // raise interrupt at same priority
SWINT3.borrow_ref_mut(cs).as_mut().unwrap().raise(); // raise interrupt at higher priority
SWINT0.borrow_ref_mut(cs).as_mut().unwrap().raise(); // raise interrupt at lower priority
SWINT1.borrow_ref(cs).as_mut().unwrap().reset();
SWINT2.borrow_ref(cs).as_mut().unwrap().raise(); // raise interrupt at same priority
SWINT3.borrow_ref(cs).as_mut().unwrap().raise(); // raise interrupt at higher priority
SWINT0.borrow_ref(cs).as_mut().unwrap().raise(); // raise interrupt at lower priority
});
esp_println::println!("SW interrupt1 exit");
}
Expand All @@ -93,14 +93,14 @@ fn swint1_handler() {
fn swint2_handler() {
esp_println::println!("SW interrupt2");
critical_section::with(|cs| {
SWINT2.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT2.borrow_ref(cs).as_mut().unwrap().reset();
});
}

#[handler(priority = esp_hal::interrupt::Priority::Priority3)]
fn swint3_handler() {
esp_println::println!("SW interrupt3");
critical_section::with(|cs| {
SWINT3.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT3.borrow_ref(cs).as_mut().unwrap().reset();
});
}
16 changes: 8 additions & 8 deletions examples/src/bin/software_interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ fn main() -> ! {
delay.delay_millis(500);
match counter {
0 => critical_section::with(|cs| {
SWINT0.borrow_ref_mut(cs).as_mut().unwrap().raise();
SWINT0.borrow_ref(cs).as_mut().unwrap().raise();
}),
1 => critical_section::with(|cs| {
SWINT1.borrow_ref_mut(cs).as_mut().unwrap().raise();
SWINT1.borrow_ref(cs).as_mut().unwrap().raise();
}),
2 => critical_section::with(|cs| {
SWINT2.borrow_ref_mut(cs).as_mut().unwrap().raise();
SWINT2.borrow_ref(cs).as_mut().unwrap().raise();
}),
3 => {
critical_section::with(|cs| {
SWINT3.borrow_ref_mut(cs).as_mut().unwrap().raise();
SWINT3.borrow_ref(cs).as_mut().unwrap().raise();
});
counter = -1
}
Expand All @@ -94,30 +94,30 @@ fn main() -> ! {
fn swint0_handler() {
esp_println::println!("SW interrupt0");
critical_section::with(|cs| {
SWINT0.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT0.borrow_ref(cs).as_mut().unwrap().reset();
});
}

#[handler]
fn swint1_handler() {
esp_println::println!("SW interrupt1");
critical_section::with(|cs| {
SWINT1.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT1.borrow_ref(cs).as_mut().unwrap().reset();
});
}

#[handler]
fn swint2_handler() {
esp_println::println!("SW interrupt2");
critical_section::with(|cs| {
SWINT2.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT2.borrow_ref(cs).as_mut().unwrap().reset();
});
}

#[handler]
fn swint3_handler() {
esp_println::println!("SW interrupt3");
critical_section::with(|cs| {
SWINT3.borrow_ref_mut(cs).as_mut().unwrap().reset();
SWINT3.borrow_ref(cs).as_mut().unwrap().reset();
});
}

0 comments on commit 33baaac

Please sign in to comment.