Skip to content

Commit

Permalink
Support passing the trap frame into interrupt handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Jul 22, 2022
1 parent 40401a4 commit 34c8628
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
6 changes: 5 additions & 1 deletion esp32-hal/examples/gpio_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ fn main() -> ! {

#[ram]
#[interrupt]
fn GPIO() {
fn GPIO(frame: &mut xtensa_lx_rt::exception::Context) {
unsafe {
esp_println::println!(
"GPIO Interrupt with priority {}",
xtensa_lx::interrupt::get_level()
);
esp_println::println!(
"{:?}",
frame
);

(&BUTTON).lock(|data| {
let mut button = data.borrow_mut();
Expand Down
96 changes: 96 additions & 0 deletions esp32-hal/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#![feature(prelude_import)]
#![no_std]
#![no_main]
#[prelude_import]
use core::prelude::rust_2021::*;
#[macro_use]
extern crate core;
#[macro_use]
extern crate compiler_builtins;
use core::cell::RefCell;
use esp32_hal::{
clock::ClockControl,
gpio::{Gpio0, IO},
gpio_types::{Event, Input, Pin, PullDown},
interrupt,
macros::ram,
pac::{self, Peripherals},
prelude::*,
timer::TimerGroup,
Cpu, Delay, RtcCntl,
};
use panic_halt as _;
use xtensa_lx::mutex::{Mutex, SpinLockMutex};
use xtensa_lx_rt::entry;
static mut BUTTON: SpinLockMutex<RefCell<Option<Gpio0<Input<PullDown>>>>> =
SpinLockMutex::new(RefCell::new(None));
#[doc(hidden)]
#[export_name = "main"]
pub unsafe extern "C" fn __xtensa_lx_rt_main_trampoline() {
__xtensa_lx_rt_main()
}
#[inline(always)]
fn __xtensa_lx_rt_main() -> ! {
let peripherals = Peripherals::take().unwrap();
let system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt = timer_group0.wdt;
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
wdt.disable();
rtc_cntl.set_wdt_global_enable(false);
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mut led = io.pins.gpio15.into_push_pull_output();
let mut button = io.pins.gpio0.into_pull_down_input();
button.listen(Event::FallingEdge);
unsafe {
(&BUTTON).lock(|data| (*data).replace(Some(button)));
}
interrupt::vectored::enable_with_priority(
Cpu::ProCpu,
pac::Interrupt::GPIO,
interrupt::vectored::Priority::Priority2,
)
.unwrap();
led.set_high().unwrap();
let mut delay = Delay::new(&clocks);
loop {
led.toggle().unwrap();
delay.delay_ms(500u32);
}
}
#[link_section = ".rwtext"]
#[inline(never)]
#[doc(hidden)]
#[export_name = "GPIO"]
pub unsafe extern "C" fn __esp_hal_internal_GPIO_trampoline(
context: &mut xtensa_lx_rt::exception::Context,
) {
__esp_hal_internal_GPIO()
}
#[inline(always)]
#[link_section = ".rwtext"]
#[inline(never)]
fn __esp_hal_internal_GPIO() {
unsafe {
{
use core::fmt::Write;
::esp_println::Printer
.write_fmt(::core::fmt::Arguments::new_v1(
&["GPIO Interrupt with priority ", "\n"],
&[::core::fmt::ArgumentV1::new_display(
&xtensa_lx::interrupt::get_level(),
)],
))
.ok();
};
(&BUTTON).lock(|data| {
let mut button = data.borrow_mut();
let button = button.as_mut().unwrap();
button.clear_interrupt();
});
}
{
crate::pac::Interrupt::GPIO;
}
}

0 comments on commit 34c8628

Please sign in to comment.