diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index 217ac3b39a0..ab0446fcfbf 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -5,6 +5,7 @@ use critical_section::Mutex; use crate::ble::btdm::ble_os_adapter_chip_specific::G_OSI_FUNCS; use crate::ble::HciOutCollector; use crate::ble::HCI_OUT_COLLECTOR; +use crate::hal::macros::ram; use crate::{ binary::include::*, compat::{common::str_from_c, queue::SimpleQueue, work_queue::queue_work}, @@ -12,15 +13,6 @@ use crate::{ timer::yield_task, }; -#[cfg(esp32)] -use esp32_hal as hal; -#[cfg(esp32c3)] -use esp32c3_hal as hal; -#[cfg(esp32s3)] -use esp32s3_hal as hal; - -use hal::macros::ram; - #[cfg_attr(esp32c3, path = "os_adapter_esp32c3.rs")] #[cfg_attr(esp32s3, path = "os_adapter_esp32s3.rs")] #[cfg_attr(esp32, path = "os_adapter_esp32.rs")] @@ -226,9 +218,8 @@ unsafe extern "C" fn queue_recv(queue: *const (), item: *const (), block_time_ms block_time_ms ); - // is this ticks or millis? - let end_time = crate::timer::get_systimer_count() - + (block_time_ms as u64 * (crate::timer::TICKS_PER_SECOND / 1000)); + let end_time_ticks = + crate::timer::get_systimer_count() + crate::timer::millis_to_ticks(block_time_ms as u64); // handle the BT_QUEUE if queue == &BT_INTERNAL_QUEUE as *const _ as *const () { @@ -257,7 +248,7 @@ unsafe extern "C" fn queue_recv(queue: *const (), item: *const (), block_time_ms } if block_time_ms != OSI_FUNCS_TIME_BLOCKING - && crate::timer::get_systimer_count() > end_time + && crate::timer::get_systimer_count() > end_time_ticks { trace!("queue_recv returns with timeout"); return -1; @@ -338,18 +329,6 @@ unsafe extern "C" fn cause_sw_intr_to_core(_core: i32, _intr_no: i32) -> i32 { } } -unsafe extern "C" fn malloc(size: u32) -> *const () { - crate::compat::malloc::malloc(size as usize) as *const () -} - -unsafe extern "C" fn malloc_internal(size: u32) -> *const () { - crate::compat::malloc::malloc(size as usize) as *const () -} - -unsafe extern "C" fn free(ptr: *const ()) { - crate::compat::malloc::free(ptr as *const u8); -} - #[allow(unused)] #[ram] unsafe extern "C" fn srand(seed: u32) { diff --git a/esp-wifi/src/ble/mod.rs b/esp-wifi/src/ble/mod.rs index ad83ec0b765..2920d0bfa66 100644 --- a/esp-wifi/src/ble/mod.rs +++ b/esp-wifi/src/ble/mod.rs @@ -19,6 +19,18 @@ pub(crate) use ble::send_hci; pub mod controller; +pub unsafe extern "C" fn malloc(size: u32) -> *mut crate::binary::c_types::c_void { + crate::compat::malloc::malloc(size as usize).cast() +} + +pub unsafe extern "C" fn malloc_internal(size: u32) -> *mut crate::binary::c_types::c_void { + crate::compat::malloc::malloc(size as usize).cast() +} + +pub unsafe extern "C" fn free(ptr: *mut crate::binary::c_types::c_void) { + crate::compat::malloc::free(ptr.cast()) +} + static mut HCI_OUT_COLLECTOR: MaybeUninit = MaybeUninit::uninit(); #[derive(PartialEq, Debug)] diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index d02b670fb1d..b2d8a5c85dd 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -288,8 +288,8 @@ pub struct ext_funcs_t { >, esp_intr_free: Option i32>, - malloc: Option *const u8>, - free: Option, + malloc: Option *mut crate::binary::c_types::c_void>, + free: Option, hal_uart_start_tx: Option, hal_uart_init_cbs: Option< unsafe extern "C" fn( @@ -330,8 +330,8 @@ static G_OSI_FUNCS: ext_funcs_t = ext_funcs_t { ext_version: 0x20221122, esp_intr_alloc: Some(self::ble_os_adapter_chip_specific::esp_intr_alloc), esp_intr_free: Some(esp_intr_free), - malloc: Some(self::malloc), - free: Some(free), + malloc: Some(crate::ble::malloc), + free: Some(crate::ble::free), hal_uart_start_tx: None, hal_uart_init_cbs: None, hal_uart_config: None, @@ -417,14 +417,6 @@ unsafe extern "C" fn esp_intr_free(_ret_handle: *mut *mut crate::binary::c_types todo!(); } -unsafe extern "C" fn malloc(size: u32) -> *const u8 { - crate::compat::malloc::malloc(size as usize) -} - -unsafe extern "C" fn free(ptr: *const crate::binary::c_types::c_void) { - crate::compat::malloc::free(ptr as *const u8); -} - #[repr(C)] pub struct npl_funcs_t { p_ble_npl_os_started: Option bool>, diff --git a/esp-wifi/src/ble/os_adapter_esp32.rs b/esp-wifi/src/ble/os_adapter_esp32.rs index 8245672fa2b..f9ffe910d11 100644 --- a/esp-wifi/src/ble/os_adapter_esp32.rs +++ b/esp-wifi/src/ble/os_adapter_esp32.rs @@ -30,22 +30,22 @@ pub(super) struct osi_funcs_s { version: u32, set_isr: Option i32>, ints_on: Option, - interrupt_disable: Option ()>, - interrupt_restore: Option ()>, - task_yield: Option ()>, - task_yield_from_isr: Option ()>, + interrupt_disable: Option, + interrupt_restore: Option, + task_yield: Option, + task_yield_from_isr: Option, semphr_create: Option *const ()>, - semphr_delete: Option ()>, + semphr_delete: Option, semphr_take_from_isr: Option i32>, semphr_give_from_isr: Option i32>, semphr_take: Option i32>, semphr_give: Option i32>, mutex_create: Option *const ()>, - mutex_delete: Option ()>, + mutex_delete: Option, mutex_lock: Option i32>, mutex_unlock: Option i32>, queue_create: Option *const ()>, - queue_delete: Option ()>, + queue_delete: Option, queue_send: Option i32>, queue_send_from_isr: Option i32>, queue_recv: Option i32>, @@ -61,33 +61,33 @@ pub(super) struct osi_funcs_s { u32, ) -> i32, >, - task_delete: Option ()>, + task_delete: Option, is_in_isr: Option i32>, cause_sw_intr_to_core: Option i32>, - malloc: Option *const ()>, - malloc_internal: Option *const ()>, - free: Option ()>, + malloc: Option *mut crate::binary::c_types::c_void>, + malloc_internal: Option *mut crate::binary::c_types::c_void>, + free: Option, read_efuse_mac: Option i32>, - srand: Option ()>, + srand: Option, rand: Option i32>, btdm_lpcycles_2_hus: Option u32>, btdm_hus_2_lpcycles: Option u32>, btdm_sleep_check_duration: Option i32>, - btdm_sleep_enter_phase1: Option ()>, - btdm_sleep_enter_phase2: Option ()>, - btdm_sleep_exit_phase1: Option ()>, - btdm_sleep_exit_phase2: Option ()>, - btdm_sleep_exit_phase3: Option ()>, + btdm_sleep_enter_phase1: Option, + btdm_sleep_enter_phase2: Option, + btdm_sleep_exit_phase1: Option, + btdm_sleep_exit_phase2: Option, + btdm_sleep_exit_phase3: Option, coex_bt_wakeup_request: Option bool>, - coex_bt_wakeup_request_end: Option ()>, + coex_bt_wakeup_request_end: Option, coex_bt_request: Option i32>, coex_bt_release: Option i32>, coex_register_bt_cb: Option i32>, coex_bb_reset_lock: Option u32>, coex_bb_reset_unlock: Option, coex_schm_register_btdm_callback: Option i32>, - coex_schm_status_bit_clear: Option ()>, - coex_schm_status_bit_set: Option ()>, + coex_schm_status_bit_clear: Option, + coex_schm_status_bit_set: Option, coex_schm_interval_get: Option u32>, coex_schm_curr_period_get: Option u8>, coex_schm_curr_phase_get: Option *const ()>, @@ -95,8 +95,8 @@ pub(super) struct osi_funcs_s { coex_register_wifi_channel_change_callback: Option i32>, set_isr13: Option i32>, - interrupt_l3_disable: Option ()>, - interrupt_l3_restore: Option ()>, + interrupt_l3_disable: Option, + interrupt_l3_restore: Option, custom_queue_create: Option *mut crate::binary::c_types::c_void>, coex_version_get: Option< @@ -137,9 +137,9 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { task_delete: Some(task_delete), is_in_isr: Some(is_in_isr), cause_sw_intr_to_core: Some(cause_sw_intr_to_core), - malloc: Some(malloc), - malloc_internal: Some(malloc_internal), - free: Some(free), + malloc: Some(crate::ble::malloc), + malloc_internal: Some(crate::ble::malloc_internal), + free: Some(crate::ble::free), read_efuse_mac: Some(read_efuse_mac), srand: Some(crate::ble::btdm::srand), rand: Some(crate::ble::btdm::rand), @@ -540,7 +540,7 @@ pub(crate) unsafe extern "C" fn set_isr(n: i32, f: unsafe extern "C" fn(), arg: pub(crate) unsafe extern "C" fn ints_on(mask: u32) { trace!("chip_ints_on esp32 {:b}", mask); - hal::xtensa_lx::interrupt::enable_mask(mask); + crate::hal::xtensa_lx::interrupt::enable_mask(mask); } #[cfg(coex)] @@ -571,15 +571,9 @@ fn async_wakeup_request(event: i32) -> bool { let mut do_wakeup_request = false; match event { - BTDM_ASYNC_WAKEUP_REQ_HCI => { - request_lock = true; - } - BTDM_ASYNC_WAKEUP_REQ_COEX => { - request_lock = false; - } - _ => { - return false; - } + e if e == BTDM_ASYNC_WAKEUP_REQ_HCI => request_lock = true, + e if e == BTDM_ASYNC_WAKEUP_REQ_COEX => request_lock = false, + _ => return false, } extern "C" { @@ -614,15 +608,9 @@ fn async_wakeup_request_end(event: i32) { let request_lock: bool; match event { - BTDM_ASYNC_WAKEUP_REQ_HCI => { - request_lock = true; - } - BTDM_ASYNC_WAKEUP_REQ_COEX => { - request_lock = false; - } - _ => { - return; - } + e if e == BTDM_ASYNC_WAKEUP_REQ_HCI => request_lock = true, + e if e == BTDM_ASYNC_WAKEUP_REQ_COEX => request_lock = false, + _ => return, } extern "C" { diff --git a/esp-wifi/src/ble/os_adapter_esp32c3.rs b/esp-wifi/src/ble/os_adapter_esp32c3.rs index e3b5695954f..b18ec865d5b 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c3.rs @@ -15,25 +15,25 @@ pub(crate) static mut BT_INTERRUPT_FUNCTION8: ( pub(super) struct osi_funcs_s { magic: u32, version: u32, - interrupt_set: Option ()>, - interrupt_clear: Option ()>, - interrupt_handler_set: Option ()>, - interrupt_disable: Option ()>, - interrupt_enable: Option ()>, - task_yield: Option ()>, - task_yield_from_isr: Option ()>, + interrupt_set: Option, + interrupt_clear: Option, + interrupt_handler_set: Option, + interrupt_disable: Option, + interrupt_enable: Option, + task_yield: Option, + task_yield_from_isr: Option, semphr_create: Option *const ()>, - semphr_delete: Option ()>, + semphr_delete: Option, semphr_take_from_isr: Option i32>, semphr_give_from_isr: Option i32>, semphr_take: Option i32>, semphr_give: Option i32>, mutex_create: Option *const ()>, - mutex_delete: Option ()>, + mutex_delete: Option, mutex_lock: Option i32>, mutex_unlock: Option i32>, queue_create: Option *const ()>, - queue_delete: Option ()>, + queue_delete: Option, queue_send: Option i32>, queue_send_from_isr: Option i32>, queue_recv: Option i32>, @@ -49,32 +49,32 @@ pub(super) struct osi_funcs_s { u32, ) -> i32, >, - task_delete: Option ()>, + task_delete: Option, is_in_isr: Option i32>, cause_sw_intr_to_core: Option i32>, - malloc: Option *const ()>, - malloc_internal: Option *const ()>, - free: Option ()>, + malloc: Option *mut crate::binary::c_types::c_void>, + malloc_internal: Option *mut crate::binary::c_types::c_void>, + free: Option, read_efuse_mac: Option i32>, - srand: Option ()>, + srand: Option, rand: Option i32>, btdm_lpcycles_2_hus: Option u32>, btdm_hus_2_lpcycles: Option u32>, btdm_sleep_check_duration: Option i32>, - btdm_sleep_enter_phase1: Option ()>, - btdm_sleep_enter_phase2: Option ()>, - btdm_sleep_exit_phase1: Option ()>, - btdm_sleep_exit_phase2: Option ()>, - btdm_sleep_exit_phase3: Option ()>, - coex_wifi_sleep_set: Option ()>, + btdm_sleep_enter_phase1: Option, + btdm_sleep_enter_phase2: Option, + btdm_sleep_exit_phase1: Option, + btdm_sleep_exit_phase2: Option, + btdm_sleep_exit_phase3: Option, + coex_wifi_sleep_set: Option, coex_core_ble_conn_dyn_prio_get: Option i32>, - coex_schm_status_bit_set: Option ()>, - coex_schm_status_bit_clear: Option ()>, - interrupt_on: Option ()>, - interrupt_off: Option ()>, - esp_hw_power_down: Option ()>, - esp_hw_power_up: Option ()>, - ets_backup_dma_copy: Option ()>, + coex_schm_status_bit_set: Option, + coex_schm_status_bit_clear: Option, + interrupt_on: Option, + interrupt_off: Option, + esp_hw_power_down: Option, + esp_hw_power_up: Option, + ets_backup_dma_copy: Option, } pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { @@ -107,9 +107,9 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { task_delete: Some(task_delete), is_in_isr: Some(is_in_isr), cause_sw_intr_to_core: Some(cause_sw_intr_to_core), - malloc: Some(malloc), - malloc_internal: Some(malloc_internal), - free: Some(free), + malloc: Some(crate::ble::malloc), + malloc_internal: Some(crate::ble::malloc_internal), + free: Some(crate::ble::free), read_efuse_mac: Some(read_efuse_mac), srand: Some(crate::ble::btdm::srand), rand: Some(crate::ble::btdm::rand), diff --git a/esp-wifi/src/ble/os_adapter_esp32s3.rs b/esp-wifi/src/ble/os_adapter_esp32s3.rs index d534f1bcef9..4ff0a1ae8ad 100644 --- a/esp-wifi/src/ble/os_adapter_esp32s3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32s3.rs @@ -15,25 +15,25 @@ pub static mut ISR_INTERRUPT_8: ( pub(super) struct osi_funcs_s { magic: u32, version: u32, - interrupt_set: Option ()>, - interrupt_clear: Option ()>, - interrupt_handler_set: Option ()>, - interrupt_disable: Option ()>, - interrupt_enable: Option ()>, - task_yield: Option ()>, - task_yield_from_isr: Option ()>, + interrupt_set: Option, + interrupt_clear: Option, + interrupt_handler_set: Option, + interrupt_disable: Option, + interrupt_enable: Option, + task_yield: Option, + task_yield_from_isr: Option, semphr_create: Option *const ()>, - semphr_delete: Option ()>, + semphr_delete: Option, semphr_take_from_isr: Option i32>, semphr_give_from_isr: Option i32>, semphr_take: Option i32>, semphr_give: Option i32>, mutex_create: Option *const ()>, - mutex_delete: Option ()>, + mutex_delete: Option, mutex_lock: Option i32>, mutex_unlock: Option i32>, queue_create: Option *const ()>, - queue_delete: Option ()>, + queue_delete: Option, queue_send: Option i32>, queue_send_from_isr: Option i32>, queue_recv: Option i32>, @@ -49,32 +49,32 @@ pub(super) struct osi_funcs_s { u32, ) -> i32, >, - task_delete: Option ()>, + task_delete: Option, is_in_isr: Option i32>, cause_sw_intr_to_core: Option i32>, - malloc: Option *const ()>, - malloc_internal: Option *const ()>, - free: Option ()>, + malloc: Option *mut crate::binary::c_types::c_void>, + malloc_internal: Option *mut crate::binary::c_types::c_void>, + free: Option, read_efuse_mac: Option i32>, - srand: Option ()>, + srand: Option, rand: Option i32>, btdm_lpcycles_2_hus: Option u32>, btdm_hus_2_lpcycles: Option u32>, btdm_sleep_check_duration: Option i32>, - btdm_sleep_enter_phase1: Option ()>, - btdm_sleep_enter_phase2: Option ()>, - btdm_sleep_exit_phase1: Option ()>, - btdm_sleep_exit_phase2: Option ()>, - btdm_sleep_exit_phase3: Option ()>, - coex_wifi_sleep_set: Option ()>, + btdm_sleep_enter_phase1: Option, + btdm_sleep_enter_phase2: Option, + btdm_sleep_exit_phase1: Option, + btdm_sleep_exit_phase2: Option, + btdm_sleep_exit_phase3: Option, + coex_wifi_sleep_set: Option, coex_core_ble_conn_dyn_prio_get: Option i32>, - coex_schm_status_bit_set: Option ()>, - coex_schm_status_bit_clear: Option ()>, - interrupt_on: Option ()>, - interrupt_off: Option ()>, - esp_hw_power_down: Option ()>, - esp_hw_power_up: Option ()>, - ets_backup_dma_copy: Option ()>, + coex_schm_status_bit_set: Option, + coex_schm_status_bit_clear: Option, + interrupt_on: Option, + interrupt_off: Option, + esp_hw_power_down: Option, + esp_hw_power_up: Option, + ets_backup_dma_copy: Option, } pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { @@ -107,9 +107,9 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { task_delete: Some(task_delete), is_in_isr: Some(is_in_isr), cause_sw_intr_to_core: Some(cause_sw_intr_to_core), - malloc: Some(malloc), - malloc_internal: Some(malloc_internal), - free: Some(free), + malloc: Some(crate::ble::malloc), + malloc_internal: Some(crate::ble::malloc_internal), + free: Some(crate::ble::free), read_efuse_mac: Some(read_efuse_mac), srand: Some(crate::ble::btdm::srand), rand: Some(crate::ble::btdm::rand), @@ -178,9 +178,7 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { pub(crate) unsafe extern "C" fn interrupt_on(intr_num: i32) { trace!("interrupt_on {}", intr_num); - unsafe { - esp32s3_hal::xtensa_lx::interrupt::enable_mask(1 << 1); - } + unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(1 << 1) }; } pub(crate) unsafe extern "C" fn interrupt_off(_intr_num: i32) { diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32.rs b/esp-wifi/src/common_adapter/common_adapter_esp32.rs index 7f6b2207e6d..933b42f0d78 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32.rs @@ -1,9 +1,9 @@ use super::phy_init_data::PHY_INIT_DATA_DEFAULT; use crate::binary::include::*; use crate::common_adapter::RADIO_CLOCKS; +use crate::hal::prelude::ram; use crate::hal::system::RadioClockController; use crate::hal::system::RadioPeripherals; -use esp32_hal::prelude::ram; use atomic_polyfill::AtomicU32; use core::sync::atomic::Ordering; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs index cd2185ed362..18529e68b96 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs @@ -1,9 +1,9 @@ use super::phy_init_data::PHY_INIT_DATA_DEFAULT; use crate::binary::include::*; use crate::common_adapter::RADIO_CLOCKS; +use crate::hal::prelude::ram; use crate::hal::system::RadioClockController; use crate::hal::system::RadioPeripherals; -use esp32s2_hal::prelude::ram; use atomic_polyfill::AtomicU32; use core::sync::atomic::Ordering; diff --git a/esp-wifi/src/common_adapter/mod.rs b/esp-wifi/src/common_adapter/mod.rs index 484fdfd6760..678f3507c36 100644 --- a/esp-wifi/src/common_adapter/mod.rs +++ b/esp-wifi/src/common_adapter/mod.rs @@ -35,15 +35,11 @@ pub(crate) static mut RANDOM_GENERATOR: Option = None; pub(crate) static mut RADIO_CLOCKS: Option = None; pub(crate) fn init_rng(rng: Rng) { - unsafe { - crate::common_adapter::RANDOM_GENERATOR = Some(core::mem::transmute(rng)); - } + unsafe { RANDOM_GENERATOR = Some(core::mem::transmute(rng)) }; } pub(crate) fn init_radio_clock_control(rcc: RadioClockControl) { - unsafe { - crate::common_adapter::RADIO_CLOCKS = Some(core::mem::transmute(rcc)); - } + unsafe { RADIO_CLOCKS = Some(core::mem::transmute(rcc)) }; } /**************************************************************************** diff --git a/esp-wifi/src/compat/malloc.rs b/esp-wifi/src/compat/malloc.rs index 8da87f35353..19f9daa0607 100644 --- a/esp-wifi/src/compat/malloc.rs +++ b/esp-wifi/src/compat/malloc.rs @@ -2,7 +2,7 @@ use core::alloc::Layout; use crate::HEAP; -pub unsafe extern "C" fn malloc(size: usize) -> *const u8 { +pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { trace!("alloc {}", size); let total_size = size as usize + 4; @@ -24,7 +24,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *const u8 { ptr.offset(4) } -pub unsafe extern "C" fn free(ptr: *const u8) { +pub unsafe extern "C" fn free(ptr: *mut u8) { trace!("free {:?}", ptr); if ptr.is_null() { @@ -42,7 +42,7 @@ pub unsafe extern "C" fn free(ptr: *const u8) { } #[no_mangle] -pub unsafe extern "C" fn calloc(number: u32, size: usize) -> *const u8 { +pub unsafe extern "C" fn calloc(number: u32, size: usize) -> *mut u8 { trace!("calloc {} {}", number, size); let total_size = number as usize * size; diff --git a/esp-wifi/src/compat/timer_compat.rs b/esp-wifi/src/compat/timer_compat.rs index 2cb3800a9ed..265fd285105 100644 --- a/esp-wifi/src/compat/timer_compat.rs +++ b/esp-wifi/src/compat/timer_compat.rs @@ -27,10 +27,11 @@ pub fn compat_timer_arm(ptimer: *mut c_types::c_void, tmout: u32, repeat: bool) pub fn compat_timer_arm_us(ptimer: *mut c_types::c_void, us: u32, repeat: bool) { let systick = crate::timer::get_systimer_count(); - debug!("timer_arm_us, current time {}", systick); - - let ticks = us as u64 * (crate::timer::TICKS_PER_SECOND / 1_000_000); - debug!("timer_arm_us {:?} {} {}", ptimer, ticks, repeat); + let ticks = crate::timer::micros_to_ticks(us as u64); + debug!( + "timer_arm_us {:x} current: {} ticks: {} repeat: {}", + ptimer as usize, systick, ticks, repeat + ); critical_section::with(|_| unsafe { memory_fence(); @@ -51,7 +52,7 @@ pub fn compat_timer_arm_us(ptimer: *mut c_types::c_void, us: u32, repeat: bool) } pub fn compat_timer_disarm(ptimer: *mut c_types::c_void) { - debug!("timer_disarm {:?}", ptimer); + debug!("timer_disarm {:x}", ptimer as usize); critical_section::with(|_| unsafe { memory_fence(); @@ -70,7 +71,7 @@ pub fn compat_timer_disarm(ptimer: *mut c_types::c_void) { } pub fn compat_timer_done(ptimer: *mut c_types::c_void) { - debug!("timer_done {:?}", ptimer); + debug!("timer_done {:x}", ptimer as usize); critical_section::with(|_| unsafe { memory_fence(); @@ -97,7 +98,10 @@ pub fn compat_timer_setfn( pfunction: *mut c_types::c_void, parg: *mut c_types::c_void, ) { - trace!("timer_setfn {:?} {:?} {:?}", ptimer, pfunction, parg); + debug!( + "timer_setfn {:x} {:?} {:?}", + ptimer as usize, pfunction, parg + ); critical_section::with(|_| unsafe { memory_fence(); @@ -160,7 +164,6 @@ pub fn compat_esp_timer_create( memory_fence(); for i in 0..TIMERS.len() { - debug!("esp_timer_create {}", i); if TIMERS[i].is_none() { TIMERS[i] = Some(Timer { ptimer: &ESP_FAKE_TIMER as *const _ as *mut c_types::c_void, diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index 7e9c359110f..ab3c273af69 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -70,14 +70,14 @@ pub mod tasks; pub(crate) mod memory_fence; use critical_section; -use timer::{get_systimer_count, TICKS_PER_SECOND}; +use timer::{get_systimer_count, ticks_to_millis}; #[cfg(all(feature = "embedded-svc", feature = "wifi"))] pub mod wifi_interface; /// Return the current systimer time in milliseconds pub fn current_millis() -> u64 { - get_systimer_count() / (TICKS_PER_SECOND / 1000) + ticks_to_millis(get_systimer_count()) } #[allow(unused)] diff --git a/esp-wifi/src/tasks.rs b/esp-wifi/src/tasks.rs index d334ecbfed8..97f2f021174 100644 --- a/esp-wifi/src/tasks.rs +++ b/esp-wifi/src/tasks.rs @@ -41,7 +41,7 @@ pub extern "C" fn worker_task2() { for i in 0..TIMERS.len() { if let Some(ref mut timer) = TIMERS[i] { if timer.active && current_timestamp >= timer.expire { - debug!("timer is due.... {:?}", timer.ptimer); + debug!("timer is due.... {:x}", timer.ptimer as usize); let fnctn: fn(*mut c_types::c_void) = mem::transmute(timer.timer_ptr); _ = to_run.enqueue((fnctn, timer.arg_ptr)); diff --git a/esp-wifi/src/timer/mod.rs b/esp-wifi/src/timer/mod.rs index 2a30228b935..06bf80d12ed 100644 --- a/esp-wifi/src/timer/mod.rs +++ b/esp-wifi/src/timer/mod.rs @@ -20,3 +20,23 @@ pub fn setup_timer_isr(timebase: TimeBase) { setup_multitasking(); } + +#[allow(unused)] +pub fn micros_to_ticks(us: u64) -> u64 { + us * (TICKS_PER_SECOND / 1_000_000) +} + +#[allow(unused)] +pub fn millis_to_ticks(ms: u64) -> u64 { + ms * (TICKS_PER_SECOND / 1_000) +} + +#[allow(unused)] +pub fn ticks_to_micros(ticks: u64) -> u64 { + ticks / (TICKS_PER_SECOND / 1_000_000) +} + +#[allow(unused)] +pub fn ticks_to_millis(ticks: u64) -> u64 { + ticks / (TICKS_PER_SECOND / 1_000) +} diff --git a/esp-wifi/src/timer/timer_esp32.rs b/esp-wifi/src/timer/timer_esp32.rs index c2a4848e88e..e06a13a3eff 100644 --- a/esp-wifi/src/timer/timer_esp32.rs +++ b/esp-wifi/src/timer/timer_esp32.rs @@ -1,3 +1,4 @@ +#[cfg(any(feature = "wifi", feature = "ble"))] use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { diff --git a/esp-wifi/src/timer/timer_esp32c2.rs b/esp-wifi/src/timer/timer_esp32c2.rs index 6495ff6ffe6..1efaf6fd95e 100644 --- a/esp-wifi/src/timer/timer_esp32c2.rs +++ b/esp-wifi/src/timer/timer_esp32c2.rs @@ -1,3 +1,4 @@ +#[cfg(any(feature = "wifi", feature = "ble"))] use crate::{ binary, hal::{interrupt, macros::interrupt, peripherals::Interrupt}, diff --git a/esp-wifi/src/timer/timer_esp32c3.rs b/esp-wifi/src/timer/timer_esp32c3.rs index fffd55dce86..c89b735da48 100644 --- a/esp-wifi/src/timer/timer_esp32c3.rs +++ b/esp-wifi/src/timer/timer_esp32c3.rs @@ -1,3 +1,4 @@ +#[cfg(any(feature = "wifi", feature = "ble"))] use crate::{ binary, hal::{interrupt, macros::interrupt, peripherals::Interrupt}, diff --git a/esp-wifi/src/timer/timer_esp32c6.rs b/esp-wifi/src/timer/timer_esp32c6.rs index 2a0334552df..3f0a1d32c5f 100644 --- a/esp-wifi/src/timer/timer_esp32c6.rs +++ b/esp-wifi/src/timer/timer_esp32c6.rs @@ -1,12 +1,11 @@ +#[cfg(any(feature = "wifi", feature = "ble"))] use crate::{ binary, - hal::{ - interrupt, - macros::interrupt, - peripherals::{self, Interrupt}, - }, + hal::{interrupt, macros::interrupt, peripherals::Interrupt}, }; +use crate::hal::peripherals; + pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { diff --git a/esp-wifi/src/timer/timer_esp32s2.rs b/esp-wifi/src/timer/timer_esp32s2.rs index 25708203bd2..92116dc999f 100644 --- a/esp-wifi/src/timer/timer_esp32s2.rs +++ b/esp-wifi/src/timer/timer_esp32s2.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "wifi")] use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { diff --git a/esp-wifi/src/timer/timer_esp32s3.rs b/esp-wifi/src/timer/timer_esp32s3.rs index ade3bc62772..da168a62b63 100644 --- a/esp-wifi/src/timer/timer_esp32s3.rs +++ b/esp-wifi/src/timer/timer_esp32s3.rs @@ -1,3 +1,4 @@ +#[cfg(any(feature = "wifi", feature = "ble"))] use crate::hal::{interrupt, macros::interrupt, peripherals}; pub fn setup_radio_isr() { diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index c8fd69155eb..0c52c281b60 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -139,8 +139,8 @@ impl TryFrom for WifiMode { fn try_from(value: wifi_mode_t) -> Result { #[allow(non_upper_case_globals)] match value { - wifi_mode_t_WIFI_MODE_STA => Ok(WifiMode::Sta), - wifi_mode_t_WIFI_MODE_AP => Ok(WifiMode::Ap), + include::wifi_mode_t_WIFI_MODE_STA => Ok(WifiMode::Sta), + include::wifi_mode_t_WIFI_MODE_AP => Ok(WifiMode::Ap), _ => Err(WifiError::UnknownWifiMode), } } diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 155f6e1ee97..e73d93901cb 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -74,7 +74,6 @@ pub unsafe extern "C" fn set_intr(cpu_no: i32, intr_source: u32, intr_num: u32, intr_num, intr_prio ); - crate::wifi::os_adapter::os_adapter_chip_specific::set_intr( cpu_no, intr_source, @@ -90,9 +89,9 @@ pub unsafe extern "C" fn set_intr(cpu_no: i32, intr_source: u32, intr_num: u32, * Don't support * ****************************************************************************/ -pub unsafe extern "C" fn clear_intr(_intr_source: u32, _intr_num: u32) { +pub unsafe extern "C" fn clear_intr(intr_source: u32, intr_num: u32) { // original code does nothing here - debug!("clear_intr called {} {}", _intr_source, _intr_num); + trace!("clear_intr called {} {}", intr_source, intr_num); } pub static mut ISR_INTERRUPT_1: ( @@ -147,7 +146,7 @@ pub unsafe extern "C" fn set_isr( * ****************************************************************************/ pub unsafe extern "C" fn ints_on(mask: u32) { - trace!("ints_on {:x}", mask); + trace!("chip_ints_on {:x}", mask); crate::wifi::os_adapter::os_adapter_chip_specific::chip_ints_on(mask); } @@ -166,7 +165,9 @@ pub unsafe extern "C" fn ints_on(mask: u32) { * ****************************************************************************/ pub unsafe extern "C" fn ints_off(mask: u32) { - trace!("ints_off - not implemented - {:x}", mask); + trace!("chip_ints_off {:x}", mask); + + crate::wifi::os_adapter::os_adapter_chip_specific::chip_ints_off(mask); } /**************************************************************************** @@ -242,6 +243,7 @@ pub unsafe extern "C" fn spin_lock_delete(lock: *mut crate::binary::c_types::c_v pub unsafe extern "C" fn wifi_int_disable( wifi_int_mux: *mut crate::binary::c_types::c_void, ) -> u32 { + trace!("wifi_int_disable"); crate::wifi::os_adapter::os_adapter_chip_specific::wifi_int_disable(wifi_int_mux) } @@ -264,6 +266,7 @@ pub unsafe extern "C" fn wifi_int_restore( wifi_int_mux: *mut crate::binary::c_types::c_void, tmp: u32, ) { + trace!("wifi_int_restore"); crate::wifi::os_adapter::os_adapter_chip_specific::wifi_int_restore(wifi_int_mux, tmp) } @@ -769,7 +772,7 @@ pub unsafe extern "C" fn task_delay(tick: u32) { ****************************************************************************/ pub unsafe extern "C" fn task_ms_to_tick(ms: u32) -> i32 { trace!("task_ms_to_tick ms {}", ms); - (ms as u64 * crate::timer::TICKS_PER_SECOND / 1000) as i32 + crate::timer::millis_to_ticks(ms as u64) as i32 } /**************************************************************************** @@ -825,7 +828,7 @@ pub unsafe extern "C" fn task_get_max_priority() -> i32 { ****************************************************************************/ #[no_mangle] pub unsafe extern "C" fn malloc(size: usize) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size) as *mut crate::binary::c_types::c_void + crate::compat::malloc::malloc(size).cast() } /**************************************************************************** @@ -843,7 +846,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut crate::binary::c_types::c_v ****************************************************************************/ #[no_mangle] pub unsafe extern "C" fn free(p: *mut crate::binary::c_types::c_void) { - crate::compat::malloc::free(p as *const _ as *const u8); + crate::compat::malloc::free(p.cast()); } /**************************************************************************** @@ -1124,7 +1127,7 @@ pub unsafe extern "C" fn wifi_rtc_disable_iso() { #[no_mangle] pub unsafe extern "C" fn esp_timer_get_time() -> i64 { trace!("esp_timer_get_time"); - (crate::timer::get_systimer_count() / (crate::timer::TICKS_PER_SECOND / 1_000_000)) as i64 + crate::timer::ticks_to_micros(crate::timer::get_systimer_count()) as i64 } /**************************************************************************** @@ -1403,12 +1406,19 @@ pub unsafe extern "C" fn nvs_erase_key( * ****************************************************************************/ pub unsafe extern "C" fn get_random(buf: *mut u8, len: usize) -> crate::binary::c_types::c_int { - for i in 0..len as usize { - buf.add(i) - .write_volatile((crate::wifi::rand() & 0xff) as u8) - } + trace!("get_random"); + if let Some(ref mut rng) = crate::common_adapter::RANDOM_GENERATOR { + let buffer = unsafe { core::slice::from_raw_parts_mut(buf, len) }; - 0 + for chunk in buffer.chunks_mut(4) { + let bytes = rng.random().to_le_bytes(); + chunk.copy_from_slice(&bytes[..chunk.len()]); + } + + 0 + } else { + -1 + } } /**************************************************************************** @@ -1445,15 +1455,14 @@ pub unsafe extern "C" fn get_time( * None * ****************************************************************************/ -#[allow(unreachable_code)] pub unsafe extern "C" fn log_write( - _level: u32, + level: u32, _tag: *const crate::binary::c_types::c_char, - _format: *const crate::binary::c_types::c_char, - _args: ... + format: *const crate::binary::c_types::c_char, + args: ... ) { - let _args = core::mem::transmute(_args); - syslog(_level, _format as *const u8, _args); + let args = core::mem::transmute(args); + syslog(level, format as *const u8, args); } /**************************************************************************** @@ -1474,13 +1483,13 @@ pub unsafe extern "C" fn log_write( ****************************************************************************/ #[allow(improper_ctypes_definitions)] pub unsafe extern "C" fn log_writev( - _level: u32, + level: u32, _tag: *const crate::binary::c_types::c_char, - _format: *const crate::binary::c_types::c_char, - _args: va_list, + format: *const crate::binary::c_types::c_char, + args: va_list, ) { - let _args = core::mem::transmute(_args); - syslog(_level, _format as *const u8, _args); + let args = core::mem::transmute(args); + syslog(level, format as *const u8, args); } /**************************************************************************** @@ -1514,7 +1523,7 @@ pub unsafe extern "C" fn log_timestamp() -> u32 { * ****************************************************************************/ pub unsafe extern "C" fn malloc_internal(size: usize) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size) as *mut crate::binary::c_types::c_void + crate::compat::malloc::malloc(size).cast() } /**************************************************************************** @@ -1710,7 +1719,7 @@ pub unsafe extern "C" fn coex_deinit() { * ****************************************************************************/ pub unsafe extern "C" fn coex_enable() -> crate::binary::c_types::c_int { - debug!("coex_enable"); + trace!("coex_enable"); #[cfg(coex)] return crate::binary::include::coex_enable(); @@ -1727,7 +1736,7 @@ pub unsafe extern "C" fn coex_enable() -> crate::binary::c_types::c_int { * ****************************************************************************/ pub unsafe extern "C" fn coex_disable() { - debug!("coex_disable"); + trace!("coex_disable"); #[cfg(coex)] crate::binary::include::coex_disable(); @@ -1741,7 +1750,7 @@ pub unsafe extern "C" fn coex_disable() { * ****************************************************************************/ pub unsafe extern "C" fn coex_status_get() -> u32 { - debug!("coex_status_get"); + trace!("coex_status_get"); #[cfg(coex)] return crate::binary::include::coex_status_get(); @@ -1757,9 +1766,9 @@ pub unsafe extern "C" fn coex_status_get() -> u32 { * Don't support * ****************************************************************************/ -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_condition_set(type_: u32, dissatisfy: bool) { - debug!("coex_condition_set"); + trace!("coex_condition_set"); #[cfg(coex)] crate::binary::include::coex_condition_set(type_, dissatisfy); @@ -1772,13 +1781,13 @@ pub unsafe extern "C" fn coex_condition_set(type_: u32, dissatisfy: bool) { * Don't support * ****************************************************************************/ -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_wifi_request( event: u32, latency: u32, duration: u32, ) -> crate::binary::c_types::c_int { - debug!("coex_wifi_request"); + trace!("coex_wifi_request"); #[cfg(coex)] return crate::binary::include::coex_wifi_request(event, latency, duration); @@ -1794,9 +1803,9 @@ pub unsafe extern "C" fn coex_wifi_request( * Don't support * ****************************************************************************/ -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_wifi_release(event: u32) -> crate::binary::c_types::c_int { - debug!("coex_wifi_release"); + trace!("coex_wifi_release"); #[cfg(coex)] return crate::binary::include::coex_wifi_release(event); @@ -1812,12 +1821,12 @@ pub unsafe extern "C" fn coex_wifi_release(event: u32) -> crate::binary::c_types * Don't support * ****************************************************************************/ -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_wifi_channel_set( primary: u8, secondary: u8, ) -> crate::binary::c_types::c_int { - debug!("coex_wifi_channel_set"); + trace!("coex_wifi_channel_set"); #[cfg(coex)] return crate::binary::include::coex_wifi_channel_set(primary, secondary); @@ -1833,12 +1842,12 @@ pub unsafe extern "C" fn coex_wifi_channel_set( * Don't support * ****************************************************************************/ -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_event_duration_get( event: u32, duration: *mut u32, ) -> crate::binary::c_types::c_int { - debug!("coex_event_duration_get"); + trace!("coex_event_duration_get"); #[cfg(coex)] return crate::binary::include::coex_event_duration_get(event, duration); @@ -1855,9 +1864,9 @@ pub unsafe extern "C" fn coex_event_duration_get( * ****************************************************************************/ #[cfg(any(esp32c3, esp32c2, esp32c6, esp32s3))] -#[allow(unused_variables)] +#[cfg_attr(not(coex), allow(unused_variables))] pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary::c_types::c_int { - debug!("coex_pti_get"); + trace!("coex_pti_get"); #[cfg(coex)] return crate::binary::include::coex_pti_get(event, pti); @@ -1868,7 +1877,7 @@ pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary #[cfg(any(esp32, esp32s2))] pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary::c_types::c_int { - debug!("coex_pti_get {} {:?}", event, pti); + trace!("coex_pti_get {} {:?}", event, pti); 0 } @@ -1881,7 +1890,7 @@ pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_status_bit_clear(type_: u32, status: u32) { - debug!("coex_schm_status_bit_clear"); + trace!("coex_schm_status_bit_clear"); #[cfg(coex)] crate::binary::include::coex_schm_status_bit_clear(type_, status); @@ -1896,7 +1905,7 @@ pub unsafe extern "C" fn coex_schm_status_bit_clear(type_: u32, status: u32) { ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_status_bit_set(type_: u32, status: u32) { - debug!("coex_schm_status_bit_set"); + trace!("coex_schm_status_bit_set"); #[cfg(coex)] crate::binary::include::coex_schm_status_bit_set(type_, status); @@ -1911,7 +1920,7 @@ pub unsafe extern "C" fn coex_schm_status_bit_set(type_: u32, status: u32) { ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_interval_set(interval: u32) -> crate::binary::c_types::c_int { - debug!("coex_schm_interval_set"); + trace!("coex_schm_interval_set"); #[cfg(coex)] return crate::binary::include::coex_schm_interval_set(interval); @@ -1929,7 +1938,7 @@ pub unsafe extern "C" fn coex_schm_interval_set(interval: u32) -> crate::binary: ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_interval_get() -> u32 { - debug!("coex_schm_interval_get"); + trace!("coex_schm_interval_get"); #[cfg(coex)] return crate::binary::include::coex_schm_interval_get(); @@ -1947,7 +1956,7 @@ pub unsafe extern "C" fn coex_schm_interval_get() -> u32 { ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_curr_period_get() -> u8 { - debug!("coex_schm_curr_period_get"); + trace!("coex_schm_curr_period_get"); #[cfg(coex)] return crate::binary::include::coex_schm_curr_period_get(); @@ -1965,17 +1974,17 @@ pub unsafe extern "C" fn coex_schm_curr_period_get() -> u8 { ****************************************************************************/ #[allow(unused_variables)] pub unsafe extern "C" fn coex_schm_curr_phase_get() -> *mut crate::binary::c_types::c_void { - debug!("coex_schm_curr_phase_get"); + trace!("coex_schm_curr_phase_get"); #[cfg(coex)] return crate::binary::include::coex_schm_curr_phase_get(); #[cfg(not(coex))] - return 0 as *mut crate::binary::c_types::c_void; + return core::ptr::null_mut(); } pub unsafe extern "C" fn coex_schm_process_restart_wrapper() -> esp_wifi_sys::c_types::c_int { - debug!("coex_schm_process_restart_wrapper"); + trace!("coex_schm_process_restart_wrapper"); #[cfg(not(coex))] return 0; @@ -1991,7 +2000,7 @@ pub unsafe extern "C" fn coex_schm_register_cb_wrapper( unsafe extern "C" fn(arg1: esp_wifi_sys::c_types::c_int) -> esp_wifi_sys::c_types::c_int, >, ) -> esp_wifi_sys::c_types::c_int { - debug!("coex_schm_register_cb_wrapper {} {:?}", arg1, cb); + trace!("coex_schm_register_cb_wrapper {} {:?}", arg1, cb); #[cfg(not(coex))] return 0; diff --git a/esp-wifi/src/wifi/os_adapter_esp32.rs b/esp-wifi/src/wifi/os_adapter_esp32.rs index 0b9ee125ee5..b11a2093f30 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32.rs @@ -10,16 +10,16 @@ const DPORT_WIFI_CLK_WIFI_EN_S: u32 = 0; const DPORT_WIFI_CLK_WIFI_EN_M: u32 = (DPORT_WIFI_CLK_WIFI_EN_V) << (DPORT_WIFI_CLK_WIFI_EN_S); pub(crate) fn chip_ints_on(mask: u32) { - trace!("chip_ints_on esp32"); - unsafe { - esp32_hal::xtensa_lx::interrupt::enable_mask(1 << 0); - } + unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(mask) }; +} + +pub(crate) fn chip_ints_off(mask: u32) { + crate::hal::xtensa_lx::interrupt::disable_mask(mask); } pub(crate) unsafe extern "C" fn wifi_int_disable( wifi_int_mux: *mut crate::binary::c_types::c_void, ) -> u32 { - trace!("wifi_int_disable() esp32"); core::mem::transmute(critical_section::acquire()) } @@ -27,7 +27,6 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( wifi_int_mux: *mut crate::binary::c_types::c_void, tmp: u32, ) { - trace!("wifi_int_restore() esp32"); critical_section::release(core::mem::transmute(tmp)) } @@ -40,10 +39,10 @@ pub(crate) unsafe extern "C" fn phy_common_clock_enable() { } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, + _cpu_no: i32, intr_source: u32, intr_num: u32, - intr_prio: i32, + _intr_prio: i32, ) { extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32); @@ -53,16 +52,12 @@ pub(crate) unsafe extern "C" fn set_intr( } pub(crate) unsafe extern "C" fn wifi_clock_enable() { - trace!("wifi_clock_enable"); - let ptr = DPORT_WIFI_CLK_EN_REG as *mut u32; let old = ptr.read_volatile(); ptr.write_volatile(old | DPORT_WIFI_CLK_WIFI_EN_M); } pub(crate) unsafe extern "C" fn wifi_clock_disable() { - trace!("wifi_clock_disable"); - let ptr = DPORT_WIFI_CLK_EN_REG as *mut u32; let old = ptr.read_volatile(); ptr.write_volatile(old & !DPORT_WIFI_CLK_WIFI_EN_M); diff --git a/esp-wifi/src/wifi/os_adapter_esp32c2.rs b/esp-wifi/src/wifi/os_adapter_esp32c2.rs index 3607ae76e89..646e658ffcb 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c2.rs @@ -1,17 +1,18 @@ use crate::hal::{peripherals, riscv}; pub(crate) fn chip_ints_on(mask: u32) { - let cpuint = match mask { - 2 => 1, - _ => panic!("ints_on mask {} not handled", mask), - }; - - trace!("ints_on n={}", cpuint); + unsafe { + (*peripherals::INTERRUPT_CORE0::PTR) + .cpu_int_enable + .modify(|r, w| w.bits(r.bits() | mask)); + } +} +pub(crate) fn chip_ints_off(mask: u32) { unsafe { (*peripherals::INTERRUPT_CORE0::PTR) .cpu_int_enable - .modify(|r, w| w.bits(r.bits() | 1 << cpuint)); + .modify(|r, w| w.bits(r.bits() & !mask)); } } @@ -50,19 +51,11 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, - intr_source: u32, - intr_num: u32, - intr_prio: i32, + _cpu_no: i32, + _intr_source: u32, + _intr_num: u32, + _intr_prio: i32, ) { - trace!( - "set_intr {} {} {} {}", - cpu_no, - intr_source, - intr_num, - intr_prio - ); - // this gets called with // INFO - set_intr 0 2 1 1 (WIFI_PWR) // INFO - set_intr 0 0 1 1 (WIFI_MAC) diff --git a/esp-wifi/src/wifi/os_adapter_esp32c3.rs b/esp-wifi/src/wifi/os_adapter_esp32c3.rs index 3607ae76e89..646e658ffcb 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c3.rs @@ -1,17 +1,18 @@ use crate::hal::{peripherals, riscv}; pub(crate) fn chip_ints_on(mask: u32) { - let cpuint = match mask { - 2 => 1, - _ => panic!("ints_on mask {} not handled", mask), - }; - - trace!("ints_on n={}", cpuint); + unsafe { + (*peripherals::INTERRUPT_CORE0::PTR) + .cpu_int_enable + .modify(|r, w| w.bits(r.bits() | mask)); + } +} +pub(crate) fn chip_ints_off(mask: u32) { unsafe { (*peripherals::INTERRUPT_CORE0::PTR) .cpu_int_enable - .modify(|r, w| w.bits(r.bits() | 1 << cpuint)); + .modify(|r, w| w.bits(r.bits() & !mask)); } } @@ -50,19 +51,11 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, - intr_source: u32, - intr_num: u32, - intr_prio: i32, + _cpu_no: i32, + _intr_source: u32, + _intr_num: u32, + _intr_prio: i32, ) { - trace!( - "set_intr {} {} {} {}", - cpu_no, - intr_source, - intr_num, - intr_prio - ); - // this gets called with // INFO - set_intr 0 2 1 1 (WIFI_PWR) // INFO - set_intr 0 0 1 1 (WIFI_MAC) diff --git a/esp-wifi/src/wifi/os_adapter_esp32c6.rs b/esp-wifi/src/wifi/os_adapter_esp32c6.rs index b883f7daed7..06ae1d5847f 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c6.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c6.rs @@ -1,17 +1,18 @@ use crate::hal::{peripherals, riscv}; pub(crate) fn chip_ints_on(mask: u32) { - let cpuint = match mask { - 2 => 1, - _ => panic!("ints_on mask {} not handled", mask), - }; - - trace!("ints_on n={}", cpuint); + unsafe { + (*peripherals::INTPRI::PTR) + .cpu_int_enable + .modify(|r, w| w.bits(r.bits() | mask)); + } +} +pub(crate) fn chip_ints_off(mask: u32) { unsafe { (*peripherals::INTPRI::PTR) .cpu_int_enable - .modify(|r, w| w.bits(r.bits() | 1 << cpuint)); + .modify(|r, w| w.bits(r.bits() & !mask)); } } @@ -50,19 +51,11 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, - intr_source: u32, - intr_num: u32, - intr_prio: i32, + _cpu_no: i32, + _intr_source: u32, + _intr_num: u32, + _intr_prio: i32, ) { - trace!( - "set_intr {} {} {} {}", - cpu_no, - intr_source, - intr_num, - intr_prio - ); - // this gets called with // INFO - set_intr 0 2 1 1 (WIFI_PWR) // INFO - set_intr 0 0 1 1 (WIFI_MAC) diff --git a/esp-wifi/src/wifi/os_adapter_esp32s2.rs b/esp-wifi/src/wifi/os_adapter_esp32s2.rs index 170a5f2aeab..60070cd4b3e 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s2.rs @@ -3,16 +3,16 @@ #![allow(non_snake_case)] pub(crate) fn chip_ints_on(mask: u32) { - trace!("chip_ints_on esp32"); - unsafe { - esp32s2_hal::xtensa_lx::interrupt::enable_mask(1 << 0); - } + unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(mask) }; +} + +pub(crate) fn chip_ints_off(mask: u32) { + crate::hal::xtensa_lx::interrupt::disable_mask(mask); } pub(crate) unsafe extern "C" fn wifi_int_disable( wifi_int_mux: *mut crate::binary::c_types::c_void, ) -> u32 { - trace!("wifi_int_disable() esp32"); core::mem::transmute(critical_section::acquire()) } @@ -20,15 +20,14 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( wifi_int_mux: *mut crate::binary::c_types::c_void, tmp: u32, ) { - trace!("wifi_int_restore() esp32"); critical_section::release(core::mem::transmute(tmp)) } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, + _cpu_no: i32, intr_source: u32, intr_num: u32, - intr_prio: i32, + _intr_prio: i32, ) { extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32); diff --git a/esp-wifi/src/wifi/os_adapter_esp32s3.rs b/esp-wifi/src/wifi/os_adapter_esp32s3.rs index cb5b8312a14..8604ddd67ea 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s3.rs @@ -3,16 +3,16 @@ #![allow(non_snake_case)] pub(crate) fn chip_ints_on(mask: u32) { - trace!("chip_ints_on esp32"); - unsafe { - esp32s3_hal::xtensa_lx::interrupt::enable_mask(1 << 0); - } + unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(mask) }; +} + +pub(crate) fn chip_ints_off(mask: u32) { + crate::hal::xtensa_lx::interrupt::disable_mask(mask); } pub(crate) unsafe extern "C" fn wifi_int_disable( wifi_int_mux: *mut crate::binary::c_types::c_void, ) -> u32 { - trace!("wifi_int_disable() esp32"); core::mem::transmute(critical_section::acquire()) } @@ -20,15 +20,14 @@ pub(crate) unsafe extern "C" fn wifi_int_restore( wifi_int_mux: *mut crate::binary::c_types::c_void, tmp: u32, ) { - trace!("wifi_int_restore() esp32"); critical_section::release(core::mem::transmute(tmp)) } pub(crate) unsafe extern "C" fn set_intr( - cpu_no: i32, + _cpu_no: i32, intr_source: u32, intr_num: u32, - intr_prio: i32, + _intr_prio: i32, ) { extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32);