Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
92182fa
direct vectoring support added
onsdagens Jun 21, 2023
5f7c1ae
provide minimal handlers for hooking the vector table directly
onsdagens Jun 22, 2023
3bc8a0b
merge
onsdagens Jun 22, 2023
3742995
merge
onsdagens Jun 22, 2023
07655ee
changed direct vectoring interrupt enable interface to map to CPU int…
onsdagens Jun 25, 2023
8326536
Merge branch 'esp-rs:main' into runtime
onsdagens Jun 25, 2023
16a7893
direct vectoring interrupt nesting
onsdagens Jun 26, 2023
92148de
Merge branch 'runtime' of github.com:onsdagens/esp-hal into runtime
onsdagens Jun 26, 2023
54821bd
removed unused dependency
onsdagens Jun 26, 2023
e776a24
added tentative c2 and c6 support for direct vector table hooking
onsdagens Jun 26, 2023
082af50
added direct vectoring examples
onsdagens Jun 26, 2023
4a22c64
added direct vectoring examples
onsdagens Jun 26, 2023
c4f9c90
updated changelog
onsdagens Jun 26, 2023
6a91417
sync
onsdagens Jun 26, 2023
8db313d
Merge pull request #6 from onsdagens/esp-rs-master
onsdagens Jun 26, 2023
3bf8358
added direct vectoring to CI
onsdagens Jun 26, 2023
afdb62a
added direct vectoring to CI
onsdagens Jun 26, 2023
be14053
Merge branch 'main' into runtime
onsdagens Jun 26, 2023
e6096bb
Merge branch 'main' into runtime
onsdagens Jul 3, 2023
a4b96a5
Merge branch 'main' into runtime
onsdagens Jul 28, 2023
caa73ca
Added H2 support and example, moved helpers to esp-hal-common
onsdagens Jul 28, 2023
9772065
Added H2 direct vectoring example to CI
onsdagens Jul 28, 2023
3b541c4
Removed remnants of removed feature
onsdagens Jul 28, 2023
82f57ab
C6 and H2 examples fixed
onsdagens Jul 29, 2023
0431816
C6 and H2 examples fixed
onsdagens Jul 29, 2023
871ce4e
C6 and H2 examples fixed
onsdagens Jul 29, 2023
5de2c19
Comment fixed
onsdagens Jul 29, 2023
ff0e89b
Added preemption flag to RT
onsdagens Jul 29, 2023
6288b5b
Merge branch 'main' into runtime
MabezDev Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ jobs:
run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-systick,async
- name: check esp32c2-hal (interrupt-preemption)
run: cd esp32c2-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c2-hal (direct-vectoring)
run: cd esp32c2-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c2-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -177,6 +179,8 @@ jobs:
run: cd esp32c3-hal/ && cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-systick,async
- name: check esp32c3-hal (interrupt-preemption)
run: cd esp32c3-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c3-hal (direct-vectoring)
run: cd esp32c3-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c3-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -219,6 +223,8 @@ jobs:
run: cd esp32c6-hal/ && cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-systick,async
- name: check esp32c6-hal (interrupt-preemption)
run: cd esp32c6-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c6-hal (direct-vectoring)
run: cd esp32c6-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c6-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -261,6 +267,8 @@ jobs:
run: cd esp32h2-hal/ && cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-systick,async
- name: check esp32h2-hal (interrupt-preemption)
run: cd esp32h2-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32h2-hal (direct-vectoring)
run: cd esp32h2-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
# Ensure documentation can be built
- name: rustdoc
run: cd esp32h2-hal/ && cargo doc --features=eh1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add a new RMT driver (#653, #667, #695)
- Implemented calibrated ADC API for ESP32-S3 (#641)
- Add MCPWM DeadTime configuration (#406)
- Add feature enabling directly hooking the interrupt vector table
- Implement sleep with some wakeup methods for `esp32-s3` (#660, #689, #696)

### Changed
Expand Down
4 changes: 3 additions & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ embassy = ["embassy-time"]
embassy-time-systick = []
embassy-time-timg0 = []

interrupt-preemption = []
interrupt-preemption = ["esp-riscv-rt/interrupt-preemption"]


# Architecture-specific features (intended for internal use)
riscv = ["critical-section/restore-state-u8", "esp-riscv-rt", "esp-riscv-rt/zero-bss", "riscv-atomic-emulation-trap"]
Expand All @@ -114,6 +115,7 @@ rv-init-data = ["esp-riscv-rt/init-data", "esp-riscv-rt/init-rw-text"]
rv-zero-rtc-bss = ["esp-riscv-rt/zero-rtc-fast-bss"]
rv-init-rtc-data = ["esp-riscv-rt/init-rtc-fast-data", "esp-riscv-rt/init-rtc-fast-text"]

direct-vectoring = ["esp-riscv-rt/direct-vectoring"]
# Enable the `impl-register-debug` feature for the selected PAC
debug = [
"esp32?/impl-register-debug",
Expand Down
74 changes: 49 additions & 25 deletions esp-hal-common/src/interrupt/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ pub enum InterruptKind {
Edge,
}

/// Enumeration of available CPU interrupts
///
/// Enumeration of available CPU interrupts.
/// It is possible to create a handler for each of the interrupts. (e.g.
/// `interrupt3`)
#[repr(u32)]
Expand Down Expand Up @@ -198,6 +197,7 @@ mod vectored {
///
/// Note that interrupts still need to be enabled globally for interrupts
/// to be serviced.
#[cfg(not(feature = "direct-vectoring"))]
pub fn enable(interrupt: Interrupt, level: Priority) -> Result<(), Error> {
if matches!(level, Priority::None) {
return Err(Error::InvalidInterruptPriority);
Expand All @@ -210,6 +210,30 @@ mod vectored {
}
Ok(())
}
/// Enables an interrupt at a given priority, maps it to the given CPU
/// interrupt and assigns the given priority.
///
/// This can be side-effectful since no guarantees can be made about the
/// CPU interrupt not already being in use.
///
/// Note that interrupts still need to be enabled globally for interrupts
/// to be serviced.
#[cfg(feature = "direct-vectoring")]
pub unsafe fn enable(
interrupt: Interrupt,
level: Priority,
cpu_interrupt: CpuInterrupt,
) -> Result<(), Error> {
if matches!(level, Priority::None) {
return Err(Error::InvalidInterruptPriority);
}
unsafe {
map(crate::get_core(), interrupt, cpu_interrupt);
set_priority(crate::get_core(), cpu_interrupt, level);
enable_cpu_interrupt(cpu_interrupt);
}
Ok(())
}

#[ram]
unsafe fn handle_interrupts(cpu_intr: CpuInterrupt, context: &mut TrapFrame) {
Expand Down Expand Up @@ -368,7 +392,7 @@ pub unsafe extern "C" fn start_trap_rust_hal(trap_frame: *mut TrapFrame) {
handle_exception(pc, trap_frame);
} else {
#[cfg(feature = "interrupt-preemption")]
let interrupt_priority = handle_priority();
let interrupt_priority = _handle_priority();
let code = mcause::read().code();
match code {
1 => interrupt1(trap_frame.as_mut().unwrap()),
Expand Down Expand Up @@ -405,7 +429,7 @@ pub unsafe extern "C" fn start_trap_rust_hal(trap_frame: *mut TrapFrame) {
_ => DefaultHandler(),
};
#[cfg(feature = "interrupt-preemption")]
restore_priority(interrupt_priority);
_restore_priority(interrupt_priority);
}
}

Expand Down Expand Up @@ -532,7 +556,7 @@ pub fn _setup_interrupts() {
}
}

/// Disable the given peripheral interrupt
/// Disable the given peripheral interrupt.
pub fn disable(_core: Cpu, interrupt: Interrupt) {
unsafe {
let interrupt_number = interrupt as isize;
Expand Down Expand Up @@ -578,7 +602,7 @@ pub fn get_status(_core: Cpu) -> u128 {
}
}

/// Assign a peripheral interrupt to an CPU interrupt
/// Assign a peripheral interrupt to an CPU interrupt.
///
/// Great care must be taken when using the `vectored` feature (enabled by
/// default). Avoid interrupts 1 - 15 when interrupt vectoring is enabled.
Expand Down Expand Up @@ -672,7 +696,7 @@ mod classic {

/// Get interrupt priority
#[inline]
pub(super) unsafe fn get_priority(cpu_interrupt: CpuInterrupt) -> Priority {
pub(super) unsafe extern "C" fn get_priority(cpu_interrupt: CpuInterrupt) -> Priority {
let intr = &*crate::peripherals::INTERRUPT_CORE0::PTR;
let intr_prio_base = intr.cpu_int_pri_0.as_ptr();

Expand All @@ -681,11 +705,10 @@ mod classic {
.read_volatile();
core::mem::transmute(prio as u8)
}
#[cfg(all(feature = "interrupt-preemption"))]
use procmacros::ram;
#[cfg(all(feature = "interrupt-preemption"))]
#[ram]
pub(super) unsafe fn handle_priority() -> u32 {
#[cfg(any(feature = "interrupt-preemption", feature = "direct-vectoring"))]
#[no_mangle]
#[link_section = ".trap"]
pub(super) unsafe extern "C" fn _handle_priority() -> u32 {
use super::mcause;
use crate::riscv;
let interrupt_id: usize = mcause::read().code(); // MSB is whether its exception or interrupt.
Expand All @@ -707,9 +730,10 @@ mod classic {
}
prev_interrupt_priority
}
#[cfg(all(feature = "interrupt-preemption"))]
#[ram]
pub(super) unsafe fn restore_priority(stored_prio: u32) {
#[cfg(any(feature = "interrupt-preemption", feature = "direct-vectoring"))]
#[no_mangle]
#[link_section = ".trap"]
pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) {
use crate::riscv;
unsafe {
riscv::interrupt::disable();
Expand Down Expand Up @@ -739,7 +763,7 @@ mod plic {
const PLIC_MXINT_TYPE_REG: u32 = DR_REG_PLIC_MX_BASE + 0x4;
const PLIC_MXINT_CLEAR_REG: u32 = DR_REG_PLIC_MX_BASE + 0x8;
const PLIC_MXINT0_PRI_REG: u32 = DR_REG_PLIC_MX_BASE + 0x10;
#[cfg(feature = "interrupt-preemption")]
#[cfg(any(feature = "interrupt-preemption", feature = "direct-vectoring"))]
const PLIC_MXINT_THRESH_REG: u32 = DR_REG_PLIC_MX_BASE + 0x90;
/// Enable a CPU interrupt
pub unsafe fn enable_cpu_interrupt(which: CpuInterrupt) {
Expand Down Expand Up @@ -797,7 +821,7 @@ mod plic {

/// Get interrupt priority
#[inline]
pub(super) unsafe fn get_priority(cpu_interrupt: CpuInterrupt) -> Priority {
pub(super) unsafe extern "C" fn get_priority(cpu_interrupt: CpuInterrupt) -> Priority {
let plic_mxint_pri_ptr = PLIC_MXINT0_PRI_REG as *mut u32;

let cpu_interrupt_number = cpu_interrupt as isize;
Expand All @@ -806,11 +830,10 @@ mod plic {
.read_volatile();
core::mem::transmute(prio as u8)
}
#[cfg(all(feature = "interrupt-preemption"))]
use procmacros::ram;
#[cfg(all(feature = "interrupt-preemption"))]
#[ram]
pub(super) unsafe fn handle_priority() -> u32 {
#[cfg(any(feature = "interrupt-preemption", feature = "direct-vectoring"))]
#[no_mangle]
#[link_section = ".trap"]
pub(super) unsafe extern "C" fn _handle_priority() -> u32 {
use super::mcause;
use crate::riscv;
let plic_mxint_pri_ptr = PLIC_MXINT0_PRI_REG as *mut u32;
Expand All @@ -829,9 +852,10 @@ mod plic {
}
prev_interrupt_priority
}
#[cfg(all(feature = "interrupt-preemption"))]
#[ram]
pub(super) unsafe fn restore_priority(stored_prio: u32) {
#[cfg(any(feature = "interrupt-preemption", feature = "direct-vectoring"))]
#[no_mangle]
#[link_section = ".trap"]
pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) {
use crate::riscv;
unsafe {
riscv::interrupt::disable();
Expand Down
4 changes: 3 additions & 1 deletion esp-riscv-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ riscv-rt-macros = "0.2.0"
panic-halt = "0.2.0"

[features]
direct-vectoring = []
interrupt-preemption = []
has-mie-mip = []
zero-bss = []
zero-rtc-fast-bss = []
init-data = []
init-rw-text = []
init-rtc-fast-data = []
init-rtc-fast-text = []
init-rtc-fast-text = []
Loading