Skip to content

Commit

Permalink
Update sw int docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 23, 2024
1 parent d702749 commit 0abede1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 54 deletions.
97 changes: 44 additions & 53 deletions esp-hal/src/interrupt/software.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! # Software Interrupts
//!
//! The `SoftwareInterruptControl` struct gives access to the available software
//! interrupts.
//! The [`SoftwareInterruptControl`] struct gives access to the available
//! software interrupts.
//!
//! The `SoftwareInterrupt` struct allows raising or resetting software
//! interrupts using the `raise()` and `reset()` methods.
//! The [`SoftwareInterrupt`] struct allows raising or resetting software
//! interrupts using the [`raise()`][SoftwareInterrupt::raise] and
//! [`reset()`][SoftwareInterrupt::reset] methods.
//!
//! ## Examples
//!
Expand Down Expand Up @@ -44,7 +45,7 @@
//! }
//! ```
use crate::{interrupt::InterruptHandler, peripherals::SYSTEM, InterruptConfigurable};
use crate::{interrupt::InterruptHandler, InterruptConfigurable};

/// A software interrupt can be triggered by software.
#[non_exhaustive]
Expand All @@ -69,64 +70,54 @@ impl<const NUM: u8> SoftwareInterrupt<NUM> {

/// Trigger this software-interrupt
pub fn raise(&self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let system = unsafe { &*SYSTEM::PTR };
#[cfg(any(esp32c6, esp32h2))]
let system = unsafe { &*crate::peripherals::INTPRI::PTR };
cfg_if::cfg_if! {
if #[cfg(any(esp32c6, esp32h2))] {
let system = unsafe { &*crate::peripherals::INTPRI::PTR };
} else {
let system = unsafe { &*crate::peripherals::SYSTEM::PTR };
}
}

match NUM {
0 => {
system
.cpu_intr_from_cpu_0()
.write(|w| w.cpu_intr_from_cpu_0().set_bit());
}
1 => {
system
.cpu_intr_from_cpu_1()
.write(|w| w.cpu_intr_from_cpu_1().set_bit());
}
2 => {
system
.cpu_intr_from_cpu_2()
.write(|w| w.cpu_intr_from_cpu_2().set_bit());
}
3 => {
system
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().set_bit());
}
0 => system
.cpu_intr_from_cpu_0()
.write(|w| w.cpu_intr_from_cpu_0().set_bit()),
1 => system
.cpu_intr_from_cpu_1()
.write(|w| w.cpu_intr_from_cpu_1().set_bit()),
2 => system
.cpu_intr_from_cpu_2()
.write(|w| w.cpu_intr_from_cpu_2().set_bit()),
3 => system
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().set_bit()),
_ => unreachable!(),
}
}

/// Resets this software-interrupt
pub fn reset(&self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let system = unsafe { &*SYSTEM::PTR };
#[cfg(any(esp32c6, esp32h2))]
let system = unsafe { &*crate::peripherals::INTPRI::PTR };
cfg_if::cfg_if! {
if #[cfg(any(esp32c6, esp32h2))] {
let system = unsafe { &*crate::peripherals::INTPRI::PTR };
} else {
let system = unsafe { &*crate::peripherals::SYSTEM::PTR };
}
}

match NUM {
0 => {
system
.cpu_intr_from_cpu_0()
.write(|w| w.cpu_intr_from_cpu_0().clear_bit());
}
1 => {
system
.cpu_intr_from_cpu_1()
.write(|w| w.cpu_intr_from_cpu_1().clear_bit());
}
2 => {
system
.cpu_intr_from_cpu_2()
.write(|w| w.cpu_intr_from_cpu_2().clear_bit());
}
3 => {
system
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().clear_bit());
}
0 => system
.cpu_intr_from_cpu_0()
.write(|w| w.cpu_intr_from_cpu_0().clear_bit()),
1 => system
.cpu_intr_from_cpu_1()
.write(|w| w.cpu_intr_from_cpu_1().clear_bit()),
2 => system
.cpu_intr_from_cpu_2()
.write(|w| w.cpu_intr_from_cpu_2().clear_bit()),
3 => system
.cpu_intr_from_cpu_3()
.write(|w| w.cpu_intr_from_cpu_3().clear_bit()),
_ => unreachable!(),
}
}
Expand Down
4 changes: 3 additions & 1 deletion esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
//! This means you can pass the pin/peripheral or a mutable reference to the
//! pin/peripheral.
//!
//! The later can be used to regain access to the pin when the driver gets
//! The latter can be used to regain access to the pin when the driver gets
//! dropped. Then it's possible to reuse the pin/peripheral for a different
//! purpose.
//!
Expand Down Expand Up @@ -642,6 +642,8 @@ use crate::{
};

/// Initialize the system.
///
/// This function sets up the CPU clock and returns the peripherals and clocks.
pub fn init(clock_config: CpuClock) -> (Peripherals, Clocks<'static>) {
let peripherals = Peripherals::take();
let clocks = ClockControl::new(clock_config).freeze();
Expand Down

0 comments on commit 0abede1

Please sign in to comment.