@@ -16,10 +16,11 @@ use portable_atomic::{AtomicU32, Ordering};
1616use crate :: {
1717 binary:: {
1818 c_types:: { c_int, c_ulong, c_void} ,
19- include:: { esp_event_base_t, esp_timer_get_time } ,
19+ include:: esp_event_base_t,
2020 } ,
2121 compat:: { common:: * , semaphore:: * } ,
2222 hal:: { self , clock:: ModemClockController , ram} ,
23+ time:: blob_ticks_to_micros,
2324} ;
2425
2526#[ cfg_attr( esp32c3, path = "common_adapter_esp32c3.rs" ) ]
@@ -121,7 +122,7 @@ pub unsafe extern "C" fn semphr_delete(semphr: *mut c_void) {
121122#[ ram]
122123pub unsafe extern "C" fn semphr_take ( semphr : * mut c_void , tick : u32 ) -> i32 {
123124 trace ! ( ">>>> semphr_take {:?} block_time_tick {}" , semphr, tick) ;
124- sem_take ( semphr, tick)
125+ sem_take ( semphr, blob_ticks_to_micros ( tick) )
125126}
126127
127128#[ ram]
@@ -198,9 +199,11 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> c_int {
198199 }
199200 }
200201
202+ const ESP_MAC_WIFI_SOFTAP : u32 = 1 ;
203+ const ESP_MAC_BT : u32 = 2 ;
204+
201205 unsafe {
202- // ESP_MAC_WIFI_SOFTAP
203- if type_ == 1 {
206+ if type_ == ESP_MAC_WIFI_SOFTAP {
204207 let tmp = mac. offset ( 0 ) . read_volatile ( ) ;
205208 for i in 0 ..64 {
206209 mac. offset ( 0 ) . write_volatile ( tmp | 0x02 ) ;
@@ -211,10 +214,7 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> c_int {
211214 break ;
212215 }
213216 }
214- }
215-
216- // ESP_MAC_BT
217- if type_ == 2 {
217+ } else if type_ == ESP_MAC_BT {
218218 let tmp = mac. offset ( 0 ) . read_volatile ( ) ;
219219 for i in 0 ..64 {
220220 mac. offset ( 0 ) . write_volatile ( tmp | 0x02 ) ;
@@ -228,6 +228,8 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> c_int {
228228
229229 mac. offset ( 5 )
230230 . write_volatile ( mac. offset ( 5 ) . read_volatile ( ) + 1 ) ;
231+ } else {
232+ return -1 ;
231233 }
232234 }
233235
@@ -273,20 +275,20 @@ pub unsafe extern "C" fn ets_timer_setfn(
273275}
274276
275277#[ cfg( feature = "wifi" ) ]
276- pub unsafe extern "C" fn ets_timer_arm ( timer : * mut c_void , tmout : u32 , repeat : bool ) {
277- crate :: compat:: timer_compat:: compat_timer_arm ( timer. cast ( ) , tmout , repeat) ;
278+ pub unsafe extern "C" fn ets_timer_arm ( timer : * mut c_void , ms : u32 , repeat : bool ) {
279+ crate :: compat:: timer_compat:: compat_timer_arm ( timer. cast ( ) , ms , repeat) ;
278280}
279281
280282#[ cfg( feature = "wifi" ) ]
281- pub unsafe extern "C" fn ets_timer_arm_us ( timer : * mut c_void , tmout : u32 , repeat : bool ) {
282- crate :: compat:: timer_compat:: compat_timer_arm_us ( timer. cast ( ) , tmout , repeat) ;
283+ pub unsafe extern "C" fn ets_timer_arm_us ( timer : * mut c_void , us : u32 , repeat : bool ) {
284+ crate :: compat:: timer_compat:: compat_timer_arm_us ( timer. cast ( ) , us , repeat) ;
283285}
284286
285287#[ unsafe( no_mangle) ]
286288pub unsafe extern "C" fn __esp_radio_gettimeofday ( tv : * mut timeval , _tz : * mut ( ) ) -> i32 {
287289 if !tv. is_null ( ) {
288290 unsafe {
289- let microseconds = esp_timer_get_time ( ) ;
291+ let microseconds = __esp_radio_esp_timer_get_time ( ) ;
290292 ( * tv) . tv_sec = ( microseconds / 1_000_000 ) as u64 ;
291293 ( * tv) . tv_usec = ( microseconds % 1_000_000 ) as u32 ;
292294 }
@@ -312,9 +314,10 @@ pub unsafe extern "C" fn __esp_radio_esp_timer_get_time() -> i64 {
312314 // will not need to have a scheduler in their firmware.
313315 cfg_if:: cfg_if! {
314316 if #[ cfg( any( feature = "wifi" , feature = "ble" ) ) ] {
315- crate :: time :: ticks_to_micros ( crate :: preempt:: now( ) ) as i64
317+ crate :: preempt:: now( ) as i64
316318 } else {
317- unreachable!( )
319+ // In this case we don't have a scheduler, we can return esp-hal's timestamp.
320+ esp_hal:: time:: Instant :: now( ) . duration_since_epoch( ) . as_micros( ) as i64
318321 }
319322 }
320323}
@@ -492,7 +495,11 @@ pub unsafe extern "C" fn queue_send(
492495 item : * mut c_void ,
493496 block_time_tick : u32 ,
494497) -> i32 {
495- crate :: compat:: queue:: queue_send_to_back ( queue. cast ( ) , item. cast_const ( ) , block_time_tick)
498+ crate :: compat:: queue:: queue_send_to_back (
499+ queue. cast ( ) ,
500+ item. cast_const ( ) ,
501+ blob_ticks_to_micros ( block_time_tick) ,
502+ )
496503}
497504
498505/// **************************************************************************
@@ -539,7 +546,11 @@ pub unsafe extern "C" fn queue_send_to_back(
539546 item : * mut c_void ,
540547 block_time_tick : u32 ,
541548) -> i32 {
542- crate :: compat:: queue:: queue_send_to_back ( queue. cast ( ) , item, block_time_tick)
549+ crate :: compat:: queue:: queue_send_to_back (
550+ queue. cast ( ) ,
551+ item,
552+ blob_ticks_to_micros ( block_time_tick) ,
553+ )
543554}
544555
545556/// **************************************************************************
@@ -562,7 +573,11 @@ pub unsafe extern "C" fn queue_send_to_front(
562573 item : * mut c_void ,
563574 block_time_tick : u32 ,
564575) -> i32 {
565- crate :: compat:: queue:: queue_send_to_front ( queue. cast ( ) , item, block_time_tick)
576+ crate :: compat:: queue:: queue_send_to_front (
577+ queue. cast ( ) ,
578+ item,
579+ blob_ticks_to_micros ( block_time_tick) ,
580+ )
566581}
567582
568583/// **************************************************************************
@@ -583,9 +598,9 @@ pub unsafe extern "C" fn queue_send_to_front(
583598pub unsafe extern "C" fn queue_recv (
584599 queue : * mut c_void ,
585600 item : * mut c_void ,
586- block_time_tick : u32 ,
601+ block_time_ms : u32 ,
587602) -> i32 {
588- crate :: compat:: queue:: queue_receive ( queue. cast ( ) , item, block_time_tick )
603+ crate :: compat:: queue:: queue_receive ( queue. cast ( ) , item, blob_ticks_to_micros ( block_time_ms ) )
589604}
590605
591606pub unsafe extern "C" fn queue_recv_from_isr (
0 commit comments