Skip to content

Commit

Permalink
move set_isr to chip_specific (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev authored Jan 3, 2024
1 parent 90589fd commit 12477b3
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 103 deletions.
7 changes: 1 addition & 6 deletions esp-wifi/src/timer/timer_esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 2 additions & 12 deletions esp-wifi/src/timer/timer_esp32c2.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
#[allow(unused_imports)]
#[cfg(any(feature = "wifi", feature = "ble"))]
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(
Expand Down
14 changes: 2 additions & 12 deletions esp-wifi/src/timer/timer_esp32c3.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
13 changes: 2 additions & 11 deletions esp-wifi/src/timer/timer_esp32c6.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[cfg(any(feature = "wifi", feature = "ble"))]
#[allow(unused_imports)]
use crate::{
binary,
hal::{interrupt, macros::interrupt, peripherals::Interrupt},
Expand All @@ -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
Expand Down
14 changes: 2 additions & 12 deletions esp-wifi/src/timer/timer_esp32s2.rs
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
14 changes: 2 additions & 12 deletions esp-wifi/src/timer/timer_esp32s3.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
33 changes: 0 additions & 33 deletions esp-wifi/src/wifi/os_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
42 changes: 42 additions & 0 deletions esp-wifi/src/wifi/os_adapter_esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
));
}
}
50 changes: 49 additions & 1 deletion esp-wifi/src/wifi/os_adapter_esp32c2.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
));
}
}
51 changes: 50 additions & 1 deletion esp-wifi/src/wifi/os_adapter_esp32c3.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
));
}
}
Loading

0 comments on commit 12477b3

Please sign in to comment.