diff --git a/esp-wifi/src/timer/timer_esp32.rs b/esp-wifi/src/timer/timer_esp32.rs index e06a13a3..b45b1475 100644 --- a/esp-wifi/src/timer/timer_esp32.rs +++ b/esp-wifi/src/timer/timer_esp32.rs @@ -2,12 +2,7 @@ use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - unwrap!(interrupt::enable( - peripherals::Interrupt::WIFI_MAC, - interrupt::Priority::Priority1, - )); - + // wifi enabled in set_isr #[cfg(feature = "ble")] { unwrap!(interrupt::enable( diff --git a/esp-wifi/src/timer/timer_esp32c2.rs b/esp-wifi/src/timer/timer_esp32c2.rs index 1efaf6fd..ff58d3c2 100644 --- a/esp-wifi/src/timer/timer_esp32c2.rs +++ b/esp-wifi/src/timer/timer_esp32c2.rs @@ -1,3 +1,4 @@ +#[allow(unused_imports)] #[cfg(any(feature = "wifi", feature = "ble"))] use crate::{ binary, @@ -5,18 +6,7 @@ use crate::{ }; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - { - unwrap!(interrupt::enable( - Interrupt::WIFI_MAC, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - Interrupt::WIFI_PWR, - interrupt::Priority::Priority1 - )); - } - + // wifi enabled in set_isr #[cfg(feature = "ble")] { unwrap!(interrupt::enable( diff --git a/esp-wifi/src/timer/timer_esp32c3.rs b/esp-wifi/src/timer/timer_esp32c3.rs index c89b735d..ce204351 100644 --- a/esp-wifi/src/timer/timer_esp32c3.rs +++ b/esp-wifi/src/timer/timer_esp32c3.rs @@ -1,22 +1,12 @@ #[cfg(any(feature = "wifi", feature = "ble"))] +#[allow(unused_imports)] use crate::{ binary, hal::{interrupt, macros::interrupt, peripherals::Interrupt}, }; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - { - unwrap!(interrupt::enable( - Interrupt::WIFI_MAC, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - Interrupt::WIFI_PWR, - interrupt::Priority::Priority1 - )); - } - + // wifi enabled in set_isr #[cfg(feature = "ble")] { unwrap!(interrupt::enable( diff --git a/esp-wifi/src/timer/timer_esp32c6.rs b/esp-wifi/src/timer/timer_esp32c6.rs index c45a8d55..06232e8f 100644 --- a/esp-wifi/src/timer/timer_esp32c6.rs +++ b/esp-wifi/src/timer/timer_esp32c6.rs @@ -1,4 +1,5 @@ #[cfg(any(feature = "wifi", feature = "ble"))] +#[allow(unused_imports)] use crate::{ binary, hal::{interrupt, macros::interrupt, peripherals::Interrupt}, @@ -7,17 +8,7 @@ use crate::{ use crate::hal::peripherals; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - { - unwrap!(interrupt::enable( - Interrupt::WIFI_MAC, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - Interrupt::WIFI_PWR, - interrupt::Priority::Priority1 - )); - } + // wifi enabled in set_isr // make sure to disable WIFI_BB/MODEM_PERI_TIMEOUT by mapping it to CPU interrupt 31 which is masked by default // for some reason for this interrupt, mapping it to 0 doesn't deactivate it diff --git a/esp-wifi/src/timer/timer_esp32s2.rs b/esp-wifi/src/timer/timer_esp32s2.rs index 92116dc9..c789085f 100644 --- a/esp-wifi/src/timer/timer_esp32s2.rs +++ b/esp-wifi/src/timer/timer_esp32s2.rs @@ -1,19 +1,9 @@ #[cfg(feature = "wifi")] +#[allow(unused_imports)] use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - { - unwrap!(interrupt::enable( - peripherals::Interrupt::WIFI_MAC, - interrupt::Priority::Priority1, - )); - unwrap!(interrupt::enable( - peripherals::Interrupt::WIFI_PWR, - interrupt::Priority::Priority1, - )); - } - + // wifi enabled in set_isr // ble not supported } diff --git a/esp-wifi/src/timer/timer_esp32s3.rs b/esp-wifi/src/timer/timer_esp32s3.rs index da168a62..d9a3908f 100644 --- a/esp-wifi/src/timer/timer_esp32s3.rs +++ b/esp-wifi/src/timer/timer_esp32s3.rs @@ -1,19 +1,9 @@ #[cfg(any(feature = "wifi", feature = "ble"))] +#[allow(unused_imports)] use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { - #[cfg(feature = "wifi")] - { - unwrap!(interrupt::enable( - peripherals::Interrupt::WIFI_MAC, - interrupt::Priority::Priority1, - )); - unwrap!(interrupt::enable( - peripherals::Interrupt::WIFI_PWR, - interrupt::Priority::Priority1, - )); - } - + // wifi enabled in set_isr #[cfg(feature = "ble")] { unwrap!(interrupt::enable( diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index f5ec650d..60667094 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -400,7 +400,7 @@ static g_wifi_osi_funcs: wifi_osi_funcs_t = wifi_osi_funcs_t { _env_is_chip: Some(env_is_chip), _set_intr: Some(set_intr), _clear_intr: Some(clear_intr), - _set_isr: Some(set_isr), + _set_isr: Some(os_adapter_chip_specific::set_isr), _ints_on: Some(ints_on), _ints_off: Some(ints_off), _is_from_isr: Some(is_from_isr), diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 2afffa25..512ef808 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -100,39 +100,6 @@ pub static mut ISR_INTERRUPT_1: ( *mut crate::binary::c_types::c_void, ) = (core::ptr::null_mut(), core::ptr::null_mut()); -/**************************************************************************** - * Name: esp_set_isr - * - * Description: - * Register interrupt function - * - * Input Parameters: - * n - Interrupt ID - * f - Interrupt function - * arg - Function private data - * - * Returned Value: - * None - * - ****************************************************************************/ -pub unsafe extern "C" fn set_isr( - n: i32, - f: *mut crate::binary::c_types::c_void, - arg: *mut crate::binary::c_types::c_void, -) { - trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); - - match n { - 0 => { - ISR_INTERRUPT_1 = (f, arg); - } - 1 => { - ISR_INTERRUPT_1 = (f, arg); - } - _ => panic!("set_isr - unsupported interrupt number {}", n), - } -} - /**************************************************************************** * Name: esp32c3_ints_on * diff --git a/esp-wifi/src/wifi/os_adapter_esp32.rs b/esp-wifi/src/wifi/os_adapter_esp32.rs index b11a2093..28c8f501 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32.rs @@ -2,6 +2,8 @@ #![allow(dead_code)] #![allow(non_snake_case)] +use crate::hal::{interrupt, peripherals}; + const DR_REG_DPORT_BASE: u32 = 0x3ff00000; const DPORT_WIFI_CLK_EN_REG: u32 = DR_REG_DPORT_BASE + 0x0CC; const DPORT_WIFI_CLK_WIFI_EN: u32 = 0x00000406; @@ -62,3 +64,43 @@ pub(crate) unsafe extern "C" fn wifi_clock_disable() { let old = ptr.read_volatile(); ptr.write_volatile(old & !DPORT_WIFI_CLK_WIFI_EN_M); } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + peripherals::Interrupt::WIFI_MAC, + interrupt::Priority::Priority1, + )); + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32c2.rs b/esp-wifi/src/wifi/os_adapter_esp32c2.rs index 57da8e68..568d331d 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c2.rs @@ -1,4 +1,8 @@ -use crate::hal::{peripherals, riscv}; +use crate::hal::{ + interrupt, + peripherals::{self, Interrupt}, + riscv, +}; pub(crate) fn chip_ints_on(mask: u32) { unsafe { @@ -64,3 +68,47 @@ pub(crate) unsafe extern "C" fn set_intr( // configured in `setup_timer_isr` and messing with the interrupts will // get us into trouble } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + Interrupt::WIFI_MAC, + interrupt::Priority::Priority1 + )); + unwrap!(interrupt::enable( + Interrupt::WIFI_PWR, + interrupt::Priority::Priority1 + )); + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32c3.rs b/esp-wifi/src/wifi/os_adapter_esp32c3.rs index 57da8e68..48d97526 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c3.rs @@ -1,4 +1,8 @@ -use crate::hal::{peripherals, riscv}; +use crate::hal::{ + interrupt, + peripherals::{self, Interrupt}, + riscv, +}; pub(crate) fn chip_ints_on(mask: u32) { unsafe { @@ -64,3 +68,48 @@ pub(crate) unsafe extern "C" fn set_intr( // configured in `setup_timer_isr` and messing with the interrupts will // get us into trouble } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + Interrupt::WIFI_MAC, + interrupt::Priority::Priority1 + )); + unwrap!(interrupt::enable( + Interrupt::WIFI_PWR, + interrupt::Priority::Priority1 + )); + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32c6.rs b/esp-wifi/src/wifi/os_adapter_esp32c6.rs index a4af07d2..d0cda88e 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c6.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c6.rs @@ -1,4 +1,8 @@ -use crate::hal::{peripherals, riscv}; +use crate::hal::{ + interrupt, + peripherals::{self, Interrupt}, + riscv, +}; pub(crate) fn chip_ints_on(mask: u32) { unsafe { @@ -93,3 +97,47 @@ pub(crate) unsafe extern "C" fn sleep_retention_entries_destroy_dummy( ) { todo!() } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + Interrupt::WIFI_MAC, + interrupt::Priority::Priority1 + )); + unwrap!(interrupt::enable( + Interrupt::WIFI_PWR, + interrupt::Priority::Priority1 + )); + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32h2.rs b/esp-wifi/src/wifi/os_adapter_esp32h2.rs index 06ae1d58..6706e081 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32h2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32h2.rs @@ -1,4 +1,8 @@ -use crate::hal::{peripherals, riscv}; +use crate::hal::{ + interrupt, + peripherals::{self, Interrupt}, + riscv, +}; pub(crate) fn chip_ints_on(mask: u32) { unsafe { @@ -93,3 +97,36 @@ pub(crate) unsafe extern "C" fn sleep_retention_entries_destroy_dummy( ) { todo!() } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32s2.rs b/esp-wifi/src/wifi/os_adapter_esp32s2.rs index 60070cd4..57b4bb2d 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s2.rs @@ -2,6 +2,8 @@ #![allow(dead_code)] #![allow(non_snake_case)] +use crate::hal::{interrupt, peripherals}; + pub(crate) fn chip_ints_on(mask: u32) { unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(mask) }; } @@ -43,3 +45,48 @@ pub(crate) unsafe extern "C" fn phy_common_clock_disable() { pub(crate) unsafe extern "C" fn phy_common_clock_enable() { crate::common_adapter::chip_specific::phy_enable_clock(); } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + peripherals::Interrupt::WIFI_MAC, + interrupt::Priority::Priority1, + )); + unwrap!(interrupt::enable( + peripherals::Interrupt::WIFI_PWR, + interrupt::Priority::Priority1, + )); + } +} diff --git a/esp-wifi/src/wifi/os_adapter_esp32s3.rs b/esp-wifi/src/wifi/os_adapter_esp32s3.rs index 8604ddd6..937634e0 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s3.rs @@ -2,6 +2,8 @@ #![allow(dead_code)] #![allow(non_snake_case)] +use crate::hal::{interrupt, peripherals}; + pub(crate) fn chip_ints_on(mask: u32) { unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(mask) }; } @@ -35,3 +37,47 @@ pub(crate) unsafe extern "C" fn set_intr( // Force to bind WiFi interrupt to CPU0 intr_matrix_set(0, intr_source, intr_num); } + +/**************************************************************************** + * Name: esp_set_isr + * + * Description: + * Register interrupt function + * + * Input Parameters: + * n - Interrupt ID + * f - Interrupt function + * arg - Function private data + * + * Returned Value: + * None + * + ****************************************************************************/ +pub unsafe extern "C" fn set_isr( + n: i32, + f: *mut crate::binary::c_types::c_void, + arg: *mut crate::binary::c_types::c_void, +) { + trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); + + match n { + 0 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + 1 => { + crate::wifi::ISR_INTERRUPT_1 = (f, arg); + } + _ => panic!("set_isr - unsupported interrupt number {}", n), + } + #[cfg(feature = "wifi")] + { + unwrap!(interrupt::enable( + peripherals::Interrupt::WIFI_MAC, + interrupt::Priority::Priority1, + )); + unwrap!(interrupt::enable( + peripherals::Interrupt::WIFI_PWR, + interrupt::Priority::Priority1, + )); + } +}