From 8e8a47fd6698a388c3dd551360a2c6efe27a8fa3 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Sun, 11 Aug 2024 22:21:00 +0200 Subject: [PATCH 1/5] Implemented queue_msg_waiting. --- esp-wifi/src/compat/common.rs | 12 ++++++++++++ esp-wifi/src/wifi/os_adapter.rs | 13 +++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 5fa4a8f4f06..73a5c418fbd 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -308,6 +308,18 @@ pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u3 yield_task(); } } +pub fn number_of_messages_in_queue(queue: *mut c_void) -> u32 { + trace!( + "queue_msg_waiting {queue:?}" + ); + if queue != unsafe { addr_of_mut!(REAL_WIFI_QUEUE).cast() } { + warn!("queue_msg_waiting: Unknown queue."); + return 0; + } + critical_section::with(|_| { + unsafe { REAL_WIFI_QUEUE.len() as u32 } + }) +} /// Implementation of sleep() from newlib in esp-idf. /// components/newlib/time.c diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 805aa64f35c..d9035ca6f61 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -17,14 +17,7 @@ use crate::{ common_adapter::RADIO_CLOCKS, compat::{ common::{ - create_recursive_mutex, - create_wifi_queue, - lock_mutex, - receive_queued, - send_queued, - str_from_c, - thread_sem_get, - unlock_mutex, + create_recursive_mutex, create_wifi_queue, lock_mutex, number_of_messages_in_queue, receive_queued, send_queued, str_from_c, thread_sem_get, unlock_mutex }, malloc::calloc, task_runner::spawn_task, @@ -530,8 +523,8 @@ pub unsafe extern "C" fn queue_recv( /// Message number /// /// ************************************************************************* -pub unsafe extern "C" fn queue_msg_waiting(_queue: *mut crate::binary::c_types::c_void) -> u32 { - todo!("queue_msg_waiting") +pub unsafe extern "C" fn queue_msg_waiting(queue: *mut crate::binary::c_types::c_void) -> u32 { + number_of_messages_in_queue(queue) } /// ************************************************************************** From 7bf4617078ac999862dd09044bff2751a393103a Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Sun, 11 Aug 2024 22:28:14 +0200 Subject: [PATCH 2/5] Fmt. --- esp-wifi/src/compat/common.rs | 8 ++------ esp-wifi/src/wifi/os_adapter.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 73a5c418fbd..234ddecb4aa 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -309,16 +309,12 @@ pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u3 } } pub fn number_of_messages_in_queue(queue: *mut c_void) -> u32 { - trace!( - "queue_msg_waiting {queue:?}" - ); + trace!("queue_msg_waiting {queue:?}"); if queue != unsafe { addr_of_mut!(REAL_WIFI_QUEUE).cast() } { warn!("queue_msg_waiting: Unknown queue."); return 0; } - critical_section::with(|_| { - unsafe { REAL_WIFI_QUEUE.len() as u32 } - }) + critical_section::with(|_| unsafe { REAL_WIFI_QUEUE.len() as u32 }) } /// Implementation of sleep() from newlib in esp-idf. diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index d9035ca6f61..a9b44bacb6a 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -17,7 +17,15 @@ use crate::{ common_adapter::RADIO_CLOCKS, compat::{ common::{ - create_recursive_mutex, create_wifi_queue, lock_mutex, number_of_messages_in_queue, receive_queued, send_queued, str_from_c, thread_sem_get, unlock_mutex + create_recursive_mutex, + create_wifi_queue, + lock_mutex, + number_of_messages_in_queue, + receive_queued, + send_queued, + str_from_c, + thread_sem_get, + unlock_mutex, }, malloc::calloc, task_runner::spawn_task, From e9811d070c4c704e6347e6403c0b62039380b93c Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Sun, 11 Aug 2024 22:35:56 +0200 Subject: [PATCH 3/5] Adjusted changelog. --- esp-wifi/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 7cb45eb81de..b11a898719f 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Implement `embedded_io::{ReadReady, WriteReady}` traits for `WifiStack` (#1882) +- Implement `queue_msg_waiting` on the os_adapter (#1925) ### Changed From d1c7b9bec47f5dba2f4d3efc61ff23acf085b4a5 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Sun, 11 Aug 2024 22:43:22 +0200 Subject: [PATCH 4/5] Fixed CI. --- esp-wifi/src/compat/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 234ddecb4aa..56c453d03c8 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -309,7 +309,7 @@ pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u3 } } pub fn number_of_messages_in_queue(queue: *mut c_void) -> u32 { - trace!("queue_msg_waiting {queue:?}"); + trace!("queue_msg_waiting {:?}", queue); if queue != unsafe { addr_of_mut!(REAL_WIFI_QUEUE).cast() } { warn!("queue_msg_waiting: Unknown queue."); return 0; From 1b84c4e919dfc71ad784069af389f4bbbc59f27d Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Mon, 12 Aug 2024 16:08:52 +0200 Subject: [PATCH 5/5] Fixed pointer mutability. --- esp-wifi/src/compat/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 56c453d03c8..c8a3781eb54 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -308,9 +308,9 @@ pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u3 yield_task(); } } -pub fn number_of_messages_in_queue(queue: *mut c_void) -> u32 { +pub fn number_of_messages_in_queue(queue: *const c_void) -> u32 { trace!("queue_msg_waiting {:?}", queue); - if queue != unsafe { addr_of_mut!(REAL_WIFI_QUEUE).cast() } { + if queue != unsafe { addr_of!(REAL_WIFI_QUEUE).cast() } { warn!("queue_msg_waiting: Unknown queue."); return 0; }