esp_wifi/wifi/
os_adapter.rs

1#[cfg_attr(esp32c3, path = "os_adapter_esp32c3.rs")]
2#[cfg_attr(esp32c2, path = "os_adapter_esp32c2.rs")]
3#[cfg_attr(esp32c6, path = "os_adapter_esp32c6.rs")]
4#[cfg_attr(esp32h2, path = "os_adapter_esp32h2.rs")]
5#[cfg_attr(esp32, path = "os_adapter_esp32.rs")]
6#[cfg_attr(esp32s3, path = "os_adapter_esp32s3.rs")]
7#[cfg_attr(esp32s2, path = "os_adapter_esp32s2.rs")]
8pub(crate) mod os_adapter_chip_specific;
9
10use core::{cell::RefCell, ptr::addr_of_mut};
11
12use enumset::EnumSet;
13
14use super::WifiEvent;
15use crate::{
16    compat::{
17        common::{
18            ConcurrentQueue,
19            create_queue,
20            create_recursive_mutex,
21            delete_queue,
22            lock_mutex,
23            number_of_messages_in_queue,
24            receive_queued,
25            send_queued,
26            str_from_c,
27            thread_sem_get,
28            unlock_mutex,
29        },
30        malloc::calloc,
31    },
32    hal::{
33        clock::RadioClockController,
34        peripherals::RADIO_CLK,
35        sync::{Locked, RawMutex},
36    },
37    memory_fence::memory_fence,
38    preempt::yield_task,
39};
40
41static WIFI_LOCK: RawMutex = RawMutex::new();
42
43static mut QUEUE_HANDLE: *mut ConcurrentQueue = core::ptr::null_mut();
44
45// useful for waiting for events - clear and wait for the event bit to be set
46// again
47pub(crate) static WIFI_EVENTS: Locked<RefCell<EnumSet<WifiEvent>>> =
48    Locked::new(RefCell::new(enumset::enum_set!()));
49
50/// **************************************************************************
51/// Name: wifi_env_is_chip
52///
53/// Description:
54///   Config chip environment
55///
56/// Returned Value:
57///   True if on chip or false if on FPGA.
58///
59/// *************************************************************************
60pub unsafe extern "C" fn env_is_chip() -> bool {
61    true
62}
63
64/// **************************************************************************
65/// Name: wifi_set_intr
66///
67/// Description:
68///   Do nothing
69///
70/// Input Parameters:
71///     cpu_no      - The CPU which the interrupt number belongs.
72///     intr_source - The interrupt hardware source number.
73///     intr_num    - The interrupt number CPU.
74///     intr_prio   - The interrupt priority.
75///
76/// Returned Value:
77///     None
78///
79/// *************************************************************************
80pub unsafe extern "C" fn set_intr(cpu_no: i32, intr_source: u32, intr_num: u32, intr_prio: i32) {
81    trace!(
82        "set_intr {} {} {} {}",
83        cpu_no, intr_source, intr_num, intr_prio
84    );
85    unsafe {
86        crate::wifi::os_adapter::os_adapter_chip_specific::set_intr(
87            cpu_no,
88            intr_source,
89            intr_num,
90            intr_prio,
91        );
92    }
93}
94
95/// **************************************************************************
96/// Name: wifi_clear_intr
97///
98/// Description:
99///   Don't support
100///
101/// *************************************************************************
102pub unsafe extern "C" fn clear_intr(intr_source: u32, intr_num: u32) {
103    // original code does nothing here
104    trace!("clear_intr called {} {}", intr_source, intr_num);
105}
106
107pub static mut ISR_INTERRUPT_1: (
108    *mut crate::binary::c_types::c_void,
109    *mut crate::binary::c_types::c_void,
110) = (core::ptr::null_mut(), core::ptr::null_mut());
111
112/// **************************************************************************
113/// Name: esp32c3_ints_on
114///
115/// Description:
116///   Enable Wi-Fi interrupt
117///
118/// Input Parameters:
119///   mask - No mean
120///
121/// Returned Value:
122///   None
123///
124/// *************************************************************************
125pub unsafe extern "C" fn ints_on(mask: u32) {
126    trace!("chip_ints_on {:x}", mask);
127
128    crate::wifi::os_adapter::os_adapter_chip_specific::chip_ints_on(mask);
129}
130
131/// **************************************************************************
132/// Name: esp32c3_ints_off
133///
134/// Description:
135///   Disable Wi-Fi interrupt
136///
137/// Input Parameters:
138///   mask - No mean
139///
140/// Returned Value:
141///   None
142///
143/// *************************************************************************
144pub unsafe extern "C" fn ints_off(mask: u32) {
145    trace!("chip_ints_off {:x}", mask);
146
147    crate::wifi::os_adapter::os_adapter_chip_specific::chip_ints_off(mask);
148}
149
150/// **************************************************************************
151/// Name: wifi_is_from_isr
152///
153/// Description:
154///   Check current is in interrupt
155///
156/// Input Parameters:
157///   None
158///
159/// Returned Value:
160///   true if in interrupt or false if not
161///
162/// *************************************************************************
163pub unsafe extern "C" fn is_from_isr() -> bool {
164    true
165}
166
167/// **************************************************************************
168/// Name: esp_spin_lock_create
169///
170/// Description:
171///   Create spin lock in SMP mode
172///
173/// Input Parameters:
174///   None
175///
176/// Returned Value:
177///   Spin lock data pointer
178///
179/// *************************************************************************
180pub unsafe extern "C" fn spin_lock_create() -> *mut crate::binary::c_types::c_void {
181    let ptr = crate::compat::common::sem_create(1, 1);
182
183    trace!("spin_lock_create {:?}", ptr);
184    ptr as *mut crate::binary::c_types::c_void
185}
186
187/// **************************************************************************
188/// Name: esp_spin_lock_delete
189///
190/// Description:
191///   Delete spin lock
192///
193/// Input Parameters:
194///   lock - Spin lock data pointer
195///
196/// Returned Value:
197///   None
198///
199/// *************************************************************************
200pub unsafe extern "C" fn spin_lock_delete(lock: *mut crate::binary::c_types::c_void) {
201    trace!("spin_lock_delete {:?}", lock);
202
203    crate::compat::common::sem_delete(lock);
204}
205
206/// **************************************************************************
207/// Name: esp_wifi_int_disable
208///
209/// Description:
210///   Enter critical section by disabling interrupts and taking the spin lock
211///   if in SMP mode.
212///
213/// Input Parameters:
214///   wifi_int_mux - Spin lock data pointer
215///
216/// Returned Value:
217///   CPU PS value.
218///
219/// *************************************************************************
220pub unsafe extern "C" fn wifi_int_disable(
221    _wifi_int_mux: *mut crate::binary::c_types::c_void,
222) -> u32 {
223    trace!("wifi_int_disable");
224    // TODO: can we use wifi_int_mux?
225    let token = unsafe { WIFI_LOCK.acquire() };
226    unsafe { core::mem::transmute::<esp_hal::sync::RestoreState, u32>(token) }
227}
228
229/// **************************************************************************
230/// Name: esp_wifi_int_restore
231///
232/// Description:
233///   Exit from critical section by enabling interrupts and releasing the spin
234///   lock if in SMP mode.
235///
236/// Input Parameters:
237///   wifi_int_mux - Spin lock data pointer
238///   tmp          - CPU PS value.
239///
240/// Returned Value:
241///   None
242///
243/// *************************************************************************
244pub unsafe extern "C" fn wifi_int_restore(
245    _wifi_int_mux: *mut crate::binary::c_types::c_void,
246    tmp: u32,
247) {
248    trace!("wifi_int_restore");
249    let token = unsafe { core::mem::transmute::<u32, esp_hal::sync::RestoreState>(tmp) };
250    unsafe { WIFI_LOCK.release(token) }
251}
252
253/// **************************************************************************
254/// Name: esp_task_yield_from_isr
255///
256/// Description:
257///   Do nothing in NuttX
258///
259/// Input Parameters:
260///   None
261///
262/// Returned Value:
263///   None
264///
265/// *************************************************************************
266pub unsafe extern "C" fn task_yield_from_isr() {
267    // original: /* Do nothing */
268    trace!("task_yield_from_isr");
269    yield_task();
270}
271
272/// **************************************************************************
273/// Name: esp_thread_semphr_get
274///
275/// Description:
276///   Get thread self's semaphore
277///
278/// Input Parameters:
279///   None
280///
281/// Returned Value:
282///   Semaphore data pointer
283///
284/// *************************************************************************
285pub unsafe extern "C" fn wifi_thread_semphr_get() -> *mut crate::binary::c_types::c_void {
286    thread_sem_get()
287}
288
289/// **************************************************************************
290/// Name: esp_mutex_create
291///
292/// Description:
293///   Create mutex
294///
295/// Input Parameters:
296///   None
297///
298/// Returned Value:
299///   Mutex data pointer
300///
301/// *************************************************************************
302pub unsafe extern "C" fn mutex_create() -> *mut crate::binary::c_types::c_void {
303    todo!("mutex_create")
304}
305
306/// **************************************************************************
307/// Name: esp_recursive_mutex_create
308///
309/// Description:
310///   Create recursive mutex
311///
312/// Input Parameters:
313///   None
314///
315/// Returned Value:
316///   Recursive mutex data pointer
317///
318/// *************************************************************************
319pub unsafe extern "C" fn recursive_mutex_create() -> *mut crate::binary::c_types::c_void {
320    create_recursive_mutex()
321}
322
323/// **************************************************************************
324/// Name: esp_mutex_delete
325///
326/// Description:
327///   Delete mutex
328///
329/// Input Parameters:
330///   mutex_data - mutex data pointer
331///
332/// Returned Value:
333///   None
334///
335/// *************************************************************************
336pub unsafe extern "C" fn mutex_delete(mutex: *mut crate::binary::c_types::c_void) {
337    crate::compat::common::mutex_delete(mutex);
338}
339
340/// **************************************************************************
341/// Name: esp_mutex_lock
342///
343/// Description:
344///   Lock mutex
345///
346/// Input Parameters:
347///   mutex_data - mutex data pointer
348///
349/// Returned Value:
350///   True if success or false if fail
351///
352/// *************************************************************************
353pub unsafe extern "C" fn mutex_lock(mutex: *mut crate::binary::c_types::c_void) -> i32 {
354    lock_mutex(mutex)
355}
356
357/// **************************************************************************
358/// Name: esp_mutex_unlock
359///
360/// Description:
361///   Unlock mutex
362///
363/// Input Parameters:
364///   mutex_data - mutex data pointer
365///
366/// Returned Value:
367///   True if success or false if fail
368///
369/// *************************************************************************
370pub unsafe extern "C" fn mutex_unlock(mutex: *mut crate::binary::c_types::c_void) -> i32 {
371    unlock_mutex(mutex)
372}
373
374/// **************************************************************************
375/// Name: esp_queue_create
376///
377/// Description:
378///   Create message queue
379///
380/// Input Parameters:
381///   queue_len - queue message number
382///   item_size - message size
383///
384/// Returned Value:
385///   Message queue data pointer
386///
387/// *************************************************************************
388pub unsafe extern "C" fn queue_create(
389    queue_len: u32,
390    item_size: u32,
391) -> *mut crate::binary::c_types::c_void {
392    // TODO remove this once fixed in esp_supplicant AND we updated to the fixed
393    // version - JIRA: WIFI-6676
394    let (queue_len, item_size) = if queue_len != 3 && item_size != 4 {
395        (queue_len, item_size)
396    } else {
397        warn!("Fixing queue item_size");
398        (3, 8)
399    };
400
401    create_queue(queue_len as i32, item_size as i32).cast()
402}
403
404/// **************************************************************************
405/// Name: esp_queue_delete
406///
407/// Description:
408///   Delete message queue
409///
410/// Input Parameters:
411///   queue - Message queue data pointer
412///
413/// Returned Value:
414///   None
415///
416/// *************************************************************************
417pub unsafe extern "C" fn queue_delete(queue: *mut crate::binary::c_types::c_void) {
418    delete_queue(queue.cast());
419}
420
421/// **************************************************************************
422/// Name: esp_queue_send
423///
424/// Description:
425///   Send message of low priority to queue within a certain period of time
426///
427/// Input Parameters:
428///   queue - Message queue data pointer
429///   item  - Message data pointer
430///   ticks - Wait ticks
431///
432/// Returned Value:
433///   True if success or false if fail
434///
435/// *************************************************************************
436pub unsafe extern "C" fn queue_send(
437    queue: *mut crate::binary::c_types::c_void,
438    item: *mut crate::binary::c_types::c_void,
439    block_time_tick: u32,
440) -> i32 {
441    send_queued(queue.cast(), item, block_time_tick)
442}
443
444/// **************************************************************************
445/// Name: esp_queue_send_from_isr
446///
447/// Description:
448///   Send message of low priority to queue in ISR within
449///   a certain period of time
450///
451/// Input Parameters:
452///   queue - Message queue data pointer
453///   item  - Message data pointer
454///   hptw  - No mean
455///
456/// Returned Value:
457///   True if success or false if fail
458///
459/// *************************************************************************
460pub unsafe extern "C" fn queue_send_from_isr(
461    queue: *mut crate::binary::c_types::c_void,
462    item: *mut crate::binary::c_types::c_void,
463    _hptw: *mut crate::binary::c_types::c_void,
464) -> i32 {
465    trace!("queue_send_from_isr");
466    unsafe {
467        *(_hptw as *mut u32) = 1;
468        queue_send(queue, item, 1000)
469    }
470}
471
472/// **************************************************************************
473/// Name: esp_queue_send_to_back
474///
475/// Description:
476///   Send message of low priority to queue within a certain period of time
477///
478/// Input Parameters:
479///   queue - Message queue data pointer
480///   item  - Message data pointer
481///   ticks - Wait ticks
482///
483/// Returned Value:
484///   True if success or false if fail
485///
486/// *************************************************************************
487pub unsafe extern "C" fn queue_send_to_back(
488    _queue: *mut crate::binary::c_types::c_void,
489    _item: *mut crate::binary::c_types::c_void,
490    _block_time_tick: u32,
491) -> i32 {
492    todo!("queue_send_to_back")
493}
494
495/// **************************************************************************
496/// Name: esp_queue_send_from_to_front
497///
498/// Description:
499///   Send message of high priority to queue within a certain period of time
500///
501/// Input Parameters:
502///   queue - Message queue data pointer
503///   item  - Message data pointer
504///   ticks - Wait ticks
505///
506/// Returned Value:
507///   True if success or false if fail
508///
509/// *************************************************************************
510pub unsafe extern "C" fn queue_send_to_front(
511    _queue: *mut crate::binary::c_types::c_void,
512    _item: *mut crate::binary::c_types::c_void,
513    _block_time_tick: u32,
514) -> i32 {
515    todo!("queue_send_to_front")
516}
517
518/// **************************************************************************
519/// Name: esp_queue_recv
520///
521/// Description:
522///   Receive message from queue within a certain period of time
523///
524/// Input Parameters:
525///   queue - Message queue data pointer
526///   item  - Message data pointer
527///   ticks - Wait ticks
528///
529/// Returned Value:
530///   True if success or false if fail
531///
532/// *************************************************************************
533pub unsafe extern "C" fn queue_recv(
534    queue: *mut crate::binary::c_types::c_void,
535    item: *mut crate::binary::c_types::c_void,
536    block_time_tick: u32,
537) -> i32 {
538    receive_queued(queue.cast(), item, block_time_tick)
539}
540
541/// **************************************************************************
542/// Name: esp_queue_msg_waiting
543///
544/// Description:
545///   Get message number in the message queue
546///
547/// Input Parameters:
548///   queue - Message queue data pointer
549///
550/// Returned Value:
551///   Message number
552///
553/// *************************************************************************
554pub unsafe extern "C" fn queue_msg_waiting(queue: *mut crate::binary::c_types::c_void) -> u32 {
555    number_of_messages_in_queue(queue.cast())
556}
557
558/// **************************************************************************
559/// Name: esp_event_group_create
560///
561/// Description:
562///   Don't support
563///
564/// *************************************************************************
565pub unsafe extern "C" fn event_group_create() -> *mut crate::binary::c_types::c_void {
566    todo!("event_group_create")
567}
568
569/// **************************************************************************
570/// Name: esp_event_group_delete
571///
572/// Description:
573///   Don't support
574///
575/// *************************************************************************
576pub unsafe extern "C" fn event_group_delete(_event: *mut crate::binary::c_types::c_void) {
577    todo!("event_group_delete")
578}
579
580/// **************************************************************************
581/// Name: esp_event_group_set_bits
582///
583/// Description:
584///   Don't support
585///
586/// *************************************************************************
587pub unsafe extern "C" fn event_group_set_bits(
588    _event: *mut crate::binary::c_types::c_void,
589    _bits: u32,
590) -> u32 {
591    todo!("event_group_set_bits")
592}
593
594/// **************************************************************************
595/// Name: esp_event_group_clear_bits
596///
597/// Description:
598///   Don't support
599///
600/// *************************************************************************
601pub unsafe extern "C" fn event_group_clear_bits(
602    _event: *mut crate::binary::c_types::c_void,
603    _bits: u32,
604) -> u32 {
605    todo!("event_group_clear_bits")
606}
607
608/// **************************************************************************
609/// Name: esp_event_group_wait_bits
610///
611/// Description:
612///   Don't support
613///
614/// *************************************************************************
615pub unsafe extern "C" fn event_group_wait_bits(
616    _event: *mut crate::binary::c_types::c_void,
617    _bits_to_wait_for: u32,
618    _clear_on_exit: crate::binary::c_types::c_int,
619    _wait_for_all_bits: crate::binary::c_types::c_int,
620    _block_time_tick: u32,
621) -> u32 {
622    todo!("event_group_wait_bits")
623}
624
625/// **************************************************************************
626/// Name: esp_task_create_pinned_to_core
627///
628/// Description:
629///   Create task and bind it to target CPU, the task will run when it
630///   is created
631///
632/// Input Parameters:
633///   entry       - Task entry
634///   name        - Task name
635///   stack_depth - Task stack size
636///   param       - Task private data
637///   prio        - Task priority
638///   task_handle - Task handle pointer which is used to pause, resume
639///                 and delete the task
640///   core_id     - CPU which the task runs in
641///
642/// Returned Value:
643///   True if success or false if fail
644///
645/// *************************************************************************
646pub unsafe extern "C" fn task_create_pinned_to_core(
647    task_func: *mut crate::binary::c_types::c_void,
648    name: *const crate::binary::c_types::c_char,
649    stack_depth: u32,
650    param: *mut crate::binary::c_types::c_void,
651    prio: u32,
652    task_handle: *mut crate::binary::c_types::c_void,
653    core_id: u32,
654) -> i32 {
655    trace!(
656        "task_create_pinned_to_core task_func {:?} name {} stack_depth {} param {:?} prio {}, task_handle {:?} core_id {}",
657        task_func,
658        unsafe { str_from_c(name as _) },
659        stack_depth,
660        param,
661        prio,
662        task_handle,
663        core_id
664    );
665
666    unsafe {
667        let task_func = core::mem::transmute::<
668            *mut crate::binary::c_types::c_void,
669            extern "C" fn(*mut esp_wifi_sys::c_types::c_void),
670        >(task_func);
671
672        let task = crate::preempt::task_create(task_func, param, stack_depth as usize);
673        *(task_handle as *mut usize) = task as usize;
674
675        1
676    }
677}
678
679/// **************************************************************************
680/// Name: esp_task_create
681///
682/// Description:
683///   Create task and the task will run when it is created
684///
685/// Input Parameters:
686///   entry       - Task entry
687///   name        - Task name
688///   stack_depth - Task stack size
689///   param       - Task private data
690///   prio        - Task priority
691///   task_handle - Task handle pointer which is used to pause, resume
692///                 and delete the task
693///
694/// Returned Value:
695///   True if success or false if fail
696///
697/// *************************************************************************
698pub unsafe extern "C" fn task_create(
699    task_func: *mut crate::binary::c_types::c_void,
700    name: *const crate::binary::c_types::c_char,
701    stack_depth: u32,
702    param: *mut crate::binary::c_types::c_void,
703    prio: u32,
704    task_handle: *mut crate::binary::c_types::c_void,
705) -> i32 {
706    unsafe { task_create_pinned_to_core(task_func, name, stack_depth, param, prio, task_handle, 0) }
707}
708
709/// **************************************************************************
710/// Name: esp_task_delete
711///
712/// Description:
713///   Delete the target task
714///
715/// Input Parameters:
716///   task_handle - Task handle pointer which is used to pause, resume
717///                 and delete the task
718///
719/// Returned Value:
720///   None
721///
722/// *************************************************************************
723pub unsafe extern "C" fn task_delete(task_handle: *mut crate::binary::c_types::c_void) {
724    trace!("task delete called for {:?}", task_handle);
725
726    let task = if task_handle.is_null() {
727        crate::preempt::current_task()
728    } else {
729        task_handle as *mut _
730    };
731    crate::preempt::schedule_task_deletion(task);
732}
733
734/// **************************************************************************
735/// Name: esp_task_delay
736///
737/// Description:
738///   Current task wait for some ticks
739///
740/// Input Parameters:
741///   tick - Waiting ticks
742///
743/// Returned Value:
744///   None
745///
746/// *************************************************************************
747pub unsafe extern "C" fn task_delay(tick: u32) {
748    trace!("task_delay tick {}", tick);
749    let start_time = crate::time::systimer_count();
750    while crate::time::elapsed_time_since(start_time) < tick as u64 {
751        yield_task();
752    }
753}
754
755/// **************************************************************************
756/// Name: esp_task_ms_to_tick
757///
758/// Description:
759///   Transform from millim seconds to system ticks
760///
761/// Input Parameters:
762///   ms - Millim seconds
763///
764/// Returned Value:
765///   System ticks
766///
767/// *************************************************************************
768pub unsafe extern "C" fn task_ms_to_tick(ms: u32) -> i32 {
769    trace!("task_ms_to_tick ms {}", ms);
770    crate::time::millis_to_ticks(ms as u64) as i32
771}
772
773/// **************************************************************************
774/// Name: esp_task_get_current_task
775///
776/// Description:
777///   Transform from millim seconds to system ticks
778///
779/// Input Parameters:
780///   ms - Millim seconds
781///
782/// Returned Value:
783///   System ticks
784///
785/// *************************************************************************
786pub unsafe extern "C" fn task_get_current_task() -> *mut crate::binary::c_types::c_void {
787    let res = crate::preempt::current_task() as *mut crate::binary::c_types::c_void;
788    trace!("task get current task - return {:?}", res);
789
790    res
791}
792
793/// **************************************************************************
794/// Name: esp_task_get_max_priority
795///
796/// Description:
797///   Get OS task maximum priority
798///
799/// Input Parameters:
800///   None
801///
802/// Returned Value:
803///   Task maximum priority
804///
805/// *************************************************************************
806pub unsafe extern "C" fn task_get_max_priority() -> i32 {
807    trace!("task_get_max_priority");
808    255
809}
810
811/// **************************************************************************
812/// Name: esp_malloc
813///
814/// Description:
815///   Allocate a block of memory
816///
817/// Input Parameters:
818///   size - memory size
819///
820/// Returned Value:
821///   Memory pointer
822///
823/// *************************************************************************
824pub unsafe extern "C" fn malloc(size: usize) -> *mut crate::binary::c_types::c_void {
825    unsafe { crate::compat::malloc::malloc(size).cast() }
826}
827
828/// **************************************************************************
829/// Name: esp_free
830///
831/// Description:
832///   Free a block of memory
833///
834/// Input Parameters:
835///   ptr - memory block
836///
837/// Returned Value:
838///   No
839///
840/// *************************************************************************
841pub unsafe extern "C" fn free(p: *mut crate::binary::c_types::c_void) {
842    unsafe {
843        crate::compat::malloc::free(p.cast());
844    }
845}
846
847/// **************************************************************************
848/// Name: esp_event_post
849///
850/// Description:
851///   Active work queue and let the work to process the cached event
852///
853/// Input Parameters:
854///   event_base      - Event set name
855///   event_id        - Event ID
856///   event_data      - Event private data
857///   event_data_size - Event data size
858///   ticks           - Waiting system ticks
859///
860/// Returned Value:
861///   0 if success or -1 if fail
862///
863/// *************************************************************************
864pub unsafe extern "C" fn event_post(
865    event_base: *const crate::binary::c_types::c_char,
866    event_id: i32,
867    event_data: *mut crate::binary::c_types::c_void,
868    event_data_size: usize,
869    ticks_to_wait: u32,
870) -> i32 {
871    trace!(
872        "event_post {:?} {} {:?} {} {:?}",
873        event_base, event_id, event_data, event_data_size, ticks_to_wait
874    );
875    use num_traits::FromPrimitive;
876
877    let event = unwrap!(WifiEvent::from_i32(event_id));
878    trace!("EVENT: {:?}", event);
879
880    WIFI_EVENTS.with(|events| events.borrow_mut().insert(event));
881    let handled =
882        unsafe { super::event::dispatch_event_handler(event, event_data, event_data_size) };
883
884    super::state::update_state(event, handled);
885
886    event.waker().wake();
887
888    match event {
889        WifiEvent::StaConnected | WifiEvent::StaDisconnected => {
890            crate::wifi::embassy::STA_LINK_STATE_WAKER.wake();
891        }
892
893        WifiEvent::ApStart | WifiEvent::ApStop => {
894            crate::wifi::embassy::AP_LINK_STATE_WAKER.wake();
895        }
896
897        _ => {}
898    }
899
900    memory_fence();
901
902    0
903}
904
905/// **************************************************************************
906/// Name: esp_get_free_heap_size
907///
908/// Description:
909///   Get free heap size by byte
910///
911/// Input Parameters:
912///   None
913///
914/// Returned Value:
915///   Free heap size
916///
917/// *************************************************************************
918pub unsafe extern "C" fn get_free_heap_size() -> u32 {
919    unsafe extern "C" {
920        fn esp_wifi_free_internal_heap() -> usize;
921    }
922
923    unsafe { esp_wifi_free_internal_heap() as u32 }
924}
925
926/// **************************************************************************
927/// Name: esp_rand
928///
929/// Description:
930///   Get random data of type uint32_t
931///
932/// Input Parameters:
933///   None
934///
935/// Returned Value:
936///   Random data
937///
938/// *************************************************************************
939pub unsafe extern "C" fn rand() -> u32 {
940    unsafe { crate::common_adapter::random() }
941}
942
943/// **************************************************************************
944/// Name: esp_dport_access_stall_other_cpu_start
945///
946/// Description:
947///   Don't support
948///
949/// *************************************************************************
950pub unsafe extern "C" fn dport_access_stall_other_cpu_start_wrap() {
951    trace!("dport_access_stall_other_cpu_start_wrap")
952}
953
954/// **************************************************************************
955/// Name: esp_dport_access_stall_other_cpu_end
956///
957/// Description:
958///   Don't support
959///
960/// *************************************************************************
961pub unsafe extern "C" fn dport_access_stall_other_cpu_end_wrap() {
962    trace!("dport_access_stall_other_cpu_end_wrap")
963}
964/// **************************************************************************
965/// Name: wifi_apb80m_request
966///
967/// Description:
968///   Take Wi-Fi lock in auto-sleep
969///
970/// *************************************************************************
971pub unsafe extern "C" fn wifi_apb80m_request() {
972    trace!("wifi_apb80m_request - no-op")
973}
974/// **************************************************************************
975/// Name: wifi_apb80m_release
976///
977/// Description:
978///   Release Wi-Fi lock in auto-sleep
979///
980/// *************************************************************************
981pub unsafe extern "C" fn wifi_apb80m_release() {
982    trace!("wifi_apb80m_release - no-op")
983}
984
985/// **************************************************************************
986/// Name: esp32c3_phy_disable
987///
988/// Description:
989///   Deinitialize PHY hardware
990///
991/// Input Parameters:
992///   None
993///
994/// Returned Value:
995///   None
996///
997/// *************************************************************************
998pub unsafe extern "C" fn phy_disable() {
999    trace!("phy_disable");
1000
1001    unsafe {
1002        crate::common_adapter::chip_specific::phy_disable();
1003    }
1004}
1005
1006/// **************************************************************************
1007/// Name: esp32c3_phy_enable
1008///
1009/// Description:
1010///   Initialize PHY hardware
1011///
1012/// Input Parameters:
1013///   None
1014///
1015/// Returned Value:
1016///   None
1017///
1018/// *************************************************************************
1019pub unsafe extern "C" fn phy_enable() {
1020    // quite some code needed here
1021    trace!("phy_enable");
1022
1023    unsafe {
1024        crate::common_adapter::chip_specific::phy_enable();
1025    }
1026}
1027
1028/// **************************************************************************
1029/// Name: wifi_phy_update_country_info
1030///
1031/// Description:
1032///   Don't support
1033///
1034/// *************************************************************************
1035#[allow(clippy::unnecessary_cast)]
1036pub unsafe extern "C" fn phy_update_country_info(
1037    country: *const crate::binary::c_types::c_char,
1038) -> crate::binary::c_types::c_int {
1039    unsafe {
1040        // not implemented in original code
1041        trace!("phy_update_country_info {}", str_from_c(country.cast()));
1042        -1
1043    }
1044}
1045
1046/// **************************************************************************
1047/// Name: wifi_reset_mac
1048///
1049/// Description:
1050///   Reset Wi-Fi hardware MAC
1051///
1052/// Input Parameters:
1053///   None
1054///
1055/// Returned Value:
1056///   None
1057///
1058/// *************************************************************************
1059pub unsafe extern "C" fn wifi_reset_mac() {
1060    trace!("wifi_reset_mac");
1061    // stealing RADIO_CLK is safe since it is passed (as mutable reference or by
1062    // value) into `init`
1063    let radio_clocks = unsafe { RADIO_CLK::steal() };
1064    RadioClockController::new(radio_clocks).reset_mac();
1065}
1066
1067/// **************************************************************************
1068/// Name: wifi_clock_enable
1069///
1070/// Description:
1071///   Enable Wi-Fi clock
1072///
1073/// Input Parameters:
1074///   None
1075///
1076/// Returned Value:
1077///   None
1078///
1079/// *************************************************************************
1080pub unsafe extern "C" fn wifi_clock_enable() {
1081    trace!("wifi_clock_enable");
1082    // stealing RADIO_CLK is safe since it is passed (as mutable reference or by
1083    // value) into `init`
1084    let radio_clocks = unsafe { RADIO_CLK::steal() };
1085    RadioClockController::new(radio_clocks).enable_wifi(true);
1086}
1087
1088/// **************************************************************************
1089/// Name: wifi_clock_disable
1090///
1091/// Description:
1092///   Disable Wi-Fi clock
1093///
1094/// Input Parameters:
1095///   None
1096///
1097/// Returned Value:
1098///   None
1099///
1100/// *************************************************************************
1101pub unsafe extern "C" fn wifi_clock_disable() {
1102    trace!("wifi_clock_disable");
1103    // stealing RADIO_CLK is safe since it is passed (as mutable reference or by
1104    // value) into `init`
1105    let radio_clocks = unsafe { RADIO_CLK::steal() };
1106    RadioClockController::new(radio_clocks).enable_wifi(false);
1107}
1108
1109/// **************************************************************************
1110/// Name: wifi_rtc_enable_iso
1111///
1112/// Description:
1113///   Don't support
1114///
1115/// *************************************************************************
1116pub unsafe extern "C" fn wifi_rtc_enable_iso() {
1117    todo!("wifi_rtc_enable_iso")
1118}
1119
1120/// **************************************************************************
1121/// Name: wifi_rtc_disable_iso
1122///
1123/// Description:
1124///   Don't support
1125///
1126/// *************************************************************************
1127pub unsafe extern "C" fn wifi_rtc_disable_iso() {
1128    todo!("wifi_rtc_disable_iso")
1129}
1130
1131/// **************************************************************************
1132/// Name: esp_timer_get_time
1133///
1134/// Description:
1135///   Get time in microseconds since boot.
1136///
1137/// Returned Value:
1138///   System time in micros
1139///
1140/// *************************************************************************
1141#[unsafe(no_mangle)]
1142pub unsafe extern "C" fn esp_timer_get_time() -> i64 {
1143    trace!("esp_timer_get_time");
1144    crate::time::ticks_to_micros(crate::time::systimer_count()) as i64
1145}
1146
1147/// **************************************************************************
1148/// Name: esp_nvs_set_i8
1149///
1150/// Description:
1151///   Save data of type int8_t into file system
1152///
1153/// Input Parameters:
1154///   handle - NVS handle
1155///   key    - Data index
1156///   value  - Stored data
1157///
1158/// Returned Value:
1159///   0 if success or -1 if fail
1160///
1161/// *************************************************************************
1162pub unsafe extern "C" fn nvs_set_i8(
1163    _handle: u32,
1164    _key: *const crate::binary::c_types::c_char,
1165    _value: i8,
1166) -> crate::binary::c_types::c_int {
1167    debug!("nvs_set_i8");
1168    -1
1169}
1170
1171/// **************************************************************************
1172/// Name: esp_nvs_get_i8
1173///
1174/// Description:
1175///   Read data of type int8_t from file system
1176///
1177/// Input Parameters:
1178///   handle    - NVS handle
1179///   key       - Data index
1180///   out_value - Read buffer pointer
1181///
1182/// Returned Value:
1183///   0 if success or -1 if fail
1184///
1185/// *************************************************************************
1186pub unsafe extern "C" fn nvs_get_i8(
1187    _handle: u32,
1188    _key: *const crate::binary::c_types::c_char,
1189    _out_value: *mut i8,
1190) -> crate::binary::c_types::c_int {
1191    todo!("nvs_get_i8")
1192}
1193
1194/// **************************************************************************
1195/// Name: esp_nvs_set_u8
1196///
1197/// Description:
1198///   Save data of type uint8_t into file system
1199///
1200/// Input Parameters:
1201///   handle - NVS handle
1202///   key    - Data index
1203///   value  - Stored data
1204///
1205/// Returned Value:
1206///   0 if success or -1 if fail
1207///
1208/// *************************************************************************
1209pub unsafe extern "C" fn nvs_set_u8(
1210    _handle: u32,
1211    _key: *const crate::binary::c_types::c_char,
1212    _value: u8,
1213) -> crate::binary::c_types::c_int {
1214    todo!("nvs_set_u8")
1215}
1216
1217/// **************************************************************************
1218/// Name: esp_nvs_get_u8
1219///
1220/// Description:
1221///   Read data of type uint8_t from file system
1222///
1223/// Input Parameters:
1224///   handle    - NVS handle
1225///   key       - Data index
1226///   out_value - Read buffer pointer
1227///
1228/// Returned Value:
1229///   0 if success or -1 if fail
1230///
1231/// *************************************************************************
1232pub unsafe extern "C" fn nvs_get_u8(
1233    _handle: u32,
1234    _key: *const crate::binary::c_types::c_char,
1235    _out_value: *mut u8,
1236) -> crate::binary::c_types::c_int {
1237    todo!("nvs_get_u8")
1238}
1239
1240/// **************************************************************************
1241/// Name: esp_nvs_set_u16
1242///
1243/// Description:
1244///   Save data of type uint16_t into file system
1245///
1246/// Input Parameters:
1247///   handle - NVS handle
1248///   key    - Data index
1249///   value  - Stored data
1250///
1251/// Returned Value:
1252///   0 if success or -1 if fail
1253///
1254/// *************************************************************************
1255pub unsafe extern "C" fn nvs_set_u16(
1256    _handle: u32,
1257    _key: *const crate::binary::c_types::c_char,
1258    _value: u16,
1259) -> crate::binary::c_types::c_int {
1260    todo!("nvs_set_u16")
1261}
1262
1263/// **************************************************************************
1264/// Name: esp_nvs_get_u16
1265///
1266/// Description:
1267///   Read data of type uint16_t from file system
1268///
1269/// Input Parameters:
1270///   handle    - NVS handle
1271///   key       - Data index
1272///   out_value - Read buffer pointer
1273///
1274/// Returned Value:
1275///   0 if success or -1 if fail
1276///
1277/// *************************************************************************
1278pub unsafe extern "C" fn nvs_get_u16(
1279    _handle: u32,
1280    _key: *const crate::binary::c_types::c_char,
1281    _out_value: *mut u16,
1282) -> crate::binary::c_types::c_int {
1283    todo!("nvs_get_u16")
1284}
1285
1286/// **************************************************************************
1287/// Name: esp_nvs_open
1288///
1289/// Description:
1290///   Create a file system storage data object
1291///
1292/// Input Parameters:
1293///   name       - Storage index
1294///   open_mode  - Storage mode
1295///   out_handle - Storage handle
1296///
1297/// Returned Value:
1298///   0 if success or -1 if fail
1299///
1300/// *************************************************************************
1301pub unsafe extern "C" fn nvs_open(
1302    _name: *const crate::binary::c_types::c_char,
1303    _open_mode: u32,
1304    _out_handle: *mut u32,
1305) -> crate::binary::c_types::c_int {
1306    todo!("nvs_open")
1307}
1308
1309/// **************************************************************************
1310/// Name: esp_nvs_close
1311///
1312/// Description:
1313///   Close storage data object and free resource
1314///
1315/// Input Parameters:
1316///   handle - NVS handle
1317///
1318/// Returned Value:
1319///   0 if success or -1 if fail
1320///
1321/// *************************************************************************
1322pub unsafe extern "C" fn nvs_close(_handle: u32) {
1323    todo!("nvs_close")
1324}
1325
1326/// **************************************************************************
1327/// Name: esp_nvs_commit
1328///
1329/// Description:
1330///   This function has no practical effect
1331///
1332/// *************************************************************************
1333pub unsafe extern "C" fn nvs_commit(_handle: u32) -> crate::binary::c_types::c_int {
1334    todo!("nvs_commit")
1335}
1336
1337/// **************************************************************************
1338/// Name: esp_nvs_set_blob
1339///
1340/// Description:
1341///   Save a block of data into file system
1342///
1343/// Input Parameters:
1344///   handle - NVS handle
1345///   key    - Data index
1346///   value  - Stored buffer pointer
1347///   length - Buffer length
1348///
1349/// Returned Value:
1350///   0 if success or -1 if fail
1351///
1352/// *************************************************************************
1353pub unsafe extern "C" fn nvs_set_blob(
1354    _handle: u32,
1355    _key: *const crate::binary::c_types::c_char,
1356    _value: *const crate::binary::c_types::c_void,
1357    _length: usize,
1358) -> crate::binary::c_types::c_int {
1359    todo!("nvs_set_blob")
1360}
1361
1362/// **************************************************************************
1363/// Name: esp_nvs_get_blob
1364///
1365/// Description:
1366///   Read a block of data from file system
1367///
1368/// Input Parameters:
1369///   handle    - NVS handle
1370///   key       - Data index
1371///   out_value - Read buffer pointer
1372///   length    - Buffer length
1373///
1374/// Returned Value:
1375///   0 if success or -1 if fail
1376///
1377/// *************************************************************************
1378pub unsafe extern "C" fn nvs_get_blob(
1379    _handle: u32,
1380    _key: *const crate::binary::c_types::c_char,
1381    _out_value: *mut crate::binary::c_types::c_void,
1382    _length: *mut usize,
1383) -> crate::binary::c_types::c_int {
1384    todo!("nvs_get_blob")
1385}
1386
1387/// **************************************************************************
1388/// Name: esp_nvs_erase_key
1389///
1390/// Description:
1391///   Read a block of data from file system
1392///
1393/// Input Parameters:
1394///   handle    - NVS handle
1395///   key       - Data index
1396///
1397/// Returned Value:
1398///   0 if success or -1 if fail
1399///
1400/// *************************************************************************
1401pub unsafe extern "C" fn nvs_erase_key(
1402    _handle: u32,
1403    _key: *const crate::binary::c_types::c_char,
1404) -> crate::binary::c_types::c_int {
1405    todo!("nvs_erase_key")
1406}
1407
1408/// **************************************************************************
1409/// Name: esp_get_random
1410///
1411/// Description:
1412///   Fill random data int given buffer of given length
1413///
1414/// Input Parameters:
1415///   buf - buffer pointer
1416///   len - buffer length
1417///
1418/// Returned Value:
1419///   0 if success or -1 if fail
1420///
1421/// *************************************************************************
1422pub unsafe extern "C" fn get_random(buf: *mut u8, len: usize) -> crate::binary::c_types::c_int {
1423    trace!("get_random");
1424    unsafe {
1425        crate::common_adapter::esp_fill_random(buf, len as u32);
1426    }
1427    0
1428}
1429
1430/// **************************************************************************
1431/// Name: esp_get_time
1432///
1433/// Description:
1434///   Get std C time
1435///
1436/// Input Parameters:
1437///   t - buffer to store time of type timeval
1438///
1439/// Returned Value:
1440///   0 if success or -1 if fail
1441///
1442/// *************************************************************************
1443pub unsafe extern "C" fn get_time(
1444    _t: *mut crate::binary::c_types::c_void,
1445) -> crate::binary::c_types::c_int {
1446    todo!("get_time")
1447}
1448
1449/// **************************************************************************
1450/// Name: esp_log_write
1451///
1452/// Description:
1453///   Output log with by format string and its arguments
1454///
1455/// Input Parameters:
1456///   level  - log level, no mean here
1457///   tag    - log TAG, no mean here
1458///   format - format string
1459///
1460/// Returned Value:
1461///   None
1462///
1463/// *************************************************************************
1464#[cfg(feature = "sys-logs")]
1465pub unsafe extern "C" fn log_write(
1466    level: u32,
1467    _tag: *const crate::binary::c_types::c_char,
1468    format: *const crate::binary::c_types::c_char,
1469    args: ...
1470) {
1471    crate::binary::log::syslog(level, format as _, args);
1472}
1473
1474/// **************************************************************************
1475/// Name: esp_log_writev
1476///
1477/// Description:
1478///   Output log with by format string and its arguments
1479///
1480/// Input Parameters:
1481///   level  - log level, no mean here
1482///   tag    - log TAG, no mean here
1483///   format - format string
1484///   args   - arguments list
1485///
1486/// Returned Value:
1487///   None
1488///
1489/// *************************************************************************
1490#[cfg(feature = "sys-logs")]
1491#[allow(improper_ctypes_definitions)]
1492pub unsafe extern "C" fn log_writev(
1493    level: u32,
1494    _tag: *const crate::binary::c_types::c_char,
1495    format: *const crate::binary::c_types::c_char,
1496    args: crate::binary::include::va_list,
1497) {
1498    crate::binary::log::syslog(
1499        level,
1500        format as _,
1501        core::mem::transmute::<crate::binary::include::va_list, core::ffi::VaListImpl<'_>>(args),
1502    );
1503}
1504
1505/// **************************************************************************
1506/// Name: esp_log_timestamp
1507///
1508/// Description:
1509///   Get system time by millim second
1510///
1511/// Input Parameters:
1512///   None
1513///
1514/// Returned Value:
1515///   System time
1516///
1517/// *************************************************************************
1518pub unsafe extern "C" fn log_timestamp() -> u32 {
1519    esp_hal::time::Instant::now()
1520        .duration_since_epoch()
1521        .as_millis() as u32
1522}
1523
1524/// **************************************************************************
1525/// Name: esp_malloc_internal
1526///
1527/// Description:
1528///   Drivers allocate a block of memory
1529///
1530/// Input Parameters:
1531///   size - memory size
1532///
1533/// Returned Value:
1534///   Memory pointer
1535///
1536/// *************************************************************************
1537pub unsafe extern "C" fn malloc_internal(size: usize) -> *mut crate::binary::c_types::c_void {
1538    unsafe { crate::compat::malloc::malloc(size).cast() }
1539}
1540
1541/// **************************************************************************
1542/// Name: esp_realloc_internal
1543///
1544/// Description:
1545///   Drivers allocate a block of memory by old memory block
1546///
1547/// Input Parameters:
1548///   ptr  - old memory pointer
1549///   size - memory size
1550///
1551/// Returned Value:
1552///   New memory pointer
1553///
1554/// *************************************************************************
1555pub unsafe extern "C" fn realloc_internal(
1556    _ptr: *mut crate::binary::c_types::c_void,
1557    _size: usize,
1558) -> *mut crate::binary::c_types::c_void {
1559    todo!("realloc_internal")
1560}
1561
1562/// **************************************************************************
1563/// Name: esp_calloc_internal
1564///
1565/// Description:
1566///   Drivers allocate some continuous blocks of memory
1567///
1568/// Input Parameters:
1569///   n    - memory block number
1570///   size - memory block size
1571///
1572/// Returned Value:
1573///   New memory pointer
1574///
1575/// *************************************************************************
1576pub unsafe extern "C" fn calloc_internal(
1577    n: usize,
1578    size: usize,
1579) -> *mut crate::binary::c_types::c_void {
1580    unsafe { calloc(n as u32, size) as *mut crate::binary::c_types::c_void }
1581}
1582
1583/// **************************************************************************
1584/// Name: esp_zalloc_internal
1585///
1586/// Description:
1587///   Drivers allocate a block of memory and clear it with 0
1588///
1589/// Input Parameters:
1590///   size - memory size
1591///
1592/// Returned Value:
1593///   New memory pointer
1594///
1595/// *************************************************************************
1596pub unsafe extern "C" fn zalloc_internal(size: usize) -> *mut crate::binary::c_types::c_void {
1597    unsafe { calloc(size as u32, 1usize) as *mut crate::binary::c_types::c_void }
1598}
1599
1600/// **************************************************************************
1601/// Name: esp_wifi_malloc
1602///
1603/// Description:
1604///   Applications allocate a block of memory
1605///
1606/// Input Parameters:
1607///   size - memory size
1608///
1609/// Returned Value:
1610///   Memory pointer
1611///
1612/// *************************************************************************
1613pub unsafe extern "C" fn wifi_malloc(size: usize) -> *mut crate::binary::c_types::c_void {
1614    unsafe { malloc(size) }
1615}
1616
1617/// **************************************************************************
1618/// Name: esp_wifi_realloc
1619///
1620/// Description:
1621///   Applications allocate a block of memory by old memory block
1622///
1623/// Input Parameters:
1624///   ptr  - old memory pointer
1625///   size - memory size
1626///
1627/// Returned Value:
1628///   New memory pointer
1629///
1630/// *************************************************************************
1631pub unsafe extern "C" fn wifi_realloc(
1632    _ptr: *mut crate::binary::c_types::c_void,
1633    _size: usize,
1634) -> *mut crate::binary::c_types::c_void {
1635    todo!("wifi_realloc")
1636}
1637
1638/// **************************************************************************
1639/// Name: esp_wifi_calloc
1640///
1641/// Description:
1642///   Applications allocate some continuous blocks of memory
1643///
1644/// Input Parameters:
1645///   n    - memory block number
1646///   size - memory block size
1647///
1648/// Returned Value:
1649///   New memory pointer
1650///
1651/// *************************************************************************
1652pub unsafe extern "C" fn wifi_calloc(n: usize, size: usize) -> *mut crate::binary::c_types::c_void {
1653    trace!("wifi_calloc {} {}", n, size);
1654    unsafe { calloc(n as u32, size) as *mut crate::binary::c_types::c_void }
1655}
1656
1657/// **************************************************************************
1658/// Name: esp_wifi_zalloc
1659///
1660/// Description:
1661///   Applications allocate a block of memory and clear it with 0
1662///
1663/// Input Parameters:
1664///   size - memory size
1665///
1666/// Returned Value:
1667///   New memory pointer
1668///
1669/// *************************************************************************
1670pub unsafe extern "C" fn wifi_zalloc(size: usize) -> *mut crate::binary::c_types::c_void {
1671    unsafe { wifi_calloc(size, 1) }
1672}
1673
1674/// **************************************************************************
1675/// Name: esp_wifi_create_queue
1676///
1677/// Description:
1678///   Create Wi-Fi static message queue
1679///
1680/// Input Parameters:
1681///   queue_len - queue message number
1682///   item_size - message size
1683///
1684/// Returned Value:
1685///   Wi-Fi static message queue data pointer
1686///
1687/// *************************************************************************
1688pub unsafe extern "C" fn wifi_create_queue(
1689    queue_len: crate::binary::c_types::c_int,
1690    item_size: crate::binary::c_types::c_int,
1691) -> *mut crate::binary::c_types::c_void {
1692    unsafe {
1693        let queue = create_queue(queue_len, item_size);
1694        QUEUE_HANDLE = queue;
1695
1696        addr_of_mut!(QUEUE_HANDLE).cast()
1697    }
1698}
1699
1700/// **************************************************************************
1701/// Name: esp_wifi_delete_queue
1702///
1703/// Description:
1704///   Delete Wi-Fi static message queue
1705///
1706/// Input Parameters:
1707///   queue - Wi-Fi static message queue data pointer
1708///
1709/// Returned Value:
1710///   None
1711///
1712/// *************************************************************************
1713pub unsafe extern "C" fn wifi_delete_queue(queue: *mut crate::binary::c_types::c_void) {
1714    trace!("wifi_delete_queue {:?}", queue);
1715    unsafe {
1716        if core::ptr::eq(queue, addr_of_mut!(QUEUE_HANDLE).cast()) {
1717            delete_queue(QUEUE_HANDLE);
1718        } else {
1719            warn!("unknown queue when trying to delete WIFI queue");
1720        }
1721    }
1722}
1723
1724/// **************************************************************************
1725/// Name: wifi_coex_deinit
1726///
1727/// Description:
1728///   Don't support
1729///
1730/// *************************************************************************
1731pub unsafe extern "C" fn coex_deinit() {
1732    trace!("coex_deinit");
1733
1734    #[cfg(coex)]
1735    unsafe {
1736        crate::binary::include::coex_deinit()
1737    };
1738}
1739
1740/// **************************************************************************
1741/// Name: wifi_coex_enable
1742///
1743/// Description:
1744///   Don't support
1745///
1746/// *************************************************************************
1747pub unsafe extern "C" fn coex_enable() -> crate::binary::c_types::c_int {
1748    trace!("coex_enable");
1749
1750    #[cfg(coex)]
1751    return unsafe { crate::binary::include::coex_enable() };
1752
1753    #[cfg(not(coex))]
1754    0
1755}
1756
1757/// **************************************************************************
1758/// Name: wifi_coex_disable
1759///
1760/// Description:
1761///   Don't support
1762///
1763/// *************************************************************************
1764pub unsafe extern "C" fn coex_disable() {
1765    trace!("coex_disable");
1766
1767    #[cfg(coex)]
1768    unsafe {
1769        crate::binary::include::coex_disable()
1770    };
1771}
1772
1773/// **************************************************************************
1774/// Name: esp_coex_status_get
1775///
1776/// Description:
1777///   Don't support
1778///
1779/// *************************************************************************
1780pub unsafe extern "C" fn coex_status_get() -> u32 {
1781    trace!("coex_status_get");
1782
1783    #[cfg(coex)]
1784    return unsafe { crate::binary::include::coex_status_get() };
1785
1786    #[cfg(not(coex))]
1787    0
1788}
1789
1790/// **************************************************************************
1791/// Name: esp_coex_wifi_request
1792///
1793/// Description:
1794///   Don't support
1795///
1796/// *************************************************************************
1797#[cfg_attr(not(coex), allow(unused_variables))]
1798pub unsafe extern "C" fn coex_wifi_request(
1799    event: u32,
1800    latency: u32,
1801    duration: u32,
1802) -> crate::binary::c_types::c_int {
1803    trace!("coex_wifi_request");
1804
1805    #[cfg(coex)]
1806    return unsafe { crate::binary::include::coex_wifi_request(event, latency, duration) };
1807
1808    #[cfg(not(coex))]
1809    0
1810}
1811
1812/// **************************************************************************
1813/// Name: esp_coex_wifi_release
1814///
1815/// Description:
1816///   Don't support
1817///
1818/// *************************************************************************
1819#[cfg_attr(not(coex), allow(unused_variables))]
1820pub unsafe extern "C" fn coex_wifi_release(event: u32) -> crate::binary::c_types::c_int {
1821    trace!("coex_wifi_release");
1822
1823    #[cfg(coex)]
1824    return unsafe { crate::binary::include::coex_wifi_release(event) };
1825
1826    #[cfg(not(coex))]
1827    0
1828}
1829
1830/// **************************************************************************
1831/// Name: wifi_coex_wifi_set_channel
1832///
1833/// Description:
1834///   Don't support
1835///
1836/// *************************************************************************
1837#[cfg_attr(not(coex), allow(unused_variables))]
1838pub unsafe extern "C" fn coex_wifi_channel_set(
1839    primary: u8,
1840    secondary: u8,
1841) -> crate::binary::c_types::c_int {
1842    trace!("coex_wifi_channel_set");
1843
1844    #[cfg(coex)]
1845    return unsafe { crate::binary::include::coex_wifi_channel_set(primary, secondary) };
1846
1847    #[cfg(not(coex))]
1848    0
1849}
1850
1851/// **************************************************************************
1852/// Name: wifi_coex_get_event_duration
1853///
1854/// Description:
1855///   Don't support
1856///
1857/// *************************************************************************
1858#[cfg_attr(not(coex), allow(unused_variables))]
1859pub unsafe extern "C" fn coex_event_duration_get(
1860    event: u32,
1861    duration: *mut u32,
1862) -> crate::binary::c_types::c_int {
1863    trace!("coex_event_duration_get");
1864
1865    #[cfg(coex)]
1866    return unsafe { crate::binary::include::coex_event_duration_get(event, duration) };
1867
1868    #[cfg(not(coex))]
1869    0
1870}
1871
1872/// **************************************************************************
1873/// Name: wifi_coex_get_pti
1874///
1875/// Description:
1876///   Don't support
1877///
1878/// *************************************************************************
1879#[cfg(any(esp32c3, esp32c2, esp32c6, esp32s3))]
1880#[cfg_attr(not(coex), allow(unused_variables))]
1881pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary::c_types::c_int {
1882    trace!("coex_pti_get");
1883
1884    #[cfg(coex)]
1885    return unsafe { crate::binary::include::coex_pti_get(event, pti) };
1886
1887    #[cfg(not(coex))]
1888    0
1889}
1890
1891#[cfg(any(esp32, esp32s2))]
1892pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary::c_types::c_int {
1893    trace!("coex_pti_get {} {:?}", event, pti);
1894    0
1895}
1896
1897/// **************************************************************************
1898/// Name: wifi_coex_clear_schm_status_bit
1899///
1900/// Description:
1901///   Don't support
1902///
1903/// *************************************************************************
1904#[allow(unused_variables)]
1905pub unsafe extern "C" fn coex_schm_status_bit_clear(type_: u32, status: u32) {
1906    trace!("coex_schm_status_bit_clear");
1907
1908    #[cfg(coex)]
1909    unsafe {
1910        crate::binary::include::coex_schm_status_bit_clear(type_, status)
1911    };
1912}
1913
1914/// **************************************************************************
1915/// Name: wifi_coex_set_schm_status_bit
1916///
1917/// Description:
1918///   Don't support
1919///
1920/// *************************************************************************
1921#[allow(unused_variables)]
1922pub unsafe extern "C" fn coex_schm_status_bit_set(type_: u32, status: u32) {
1923    trace!("coex_schm_status_bit_set");
1924
1925    #[cfg(coex)]
1926    unsafe {
1927        crate::binary::include::coex_schm_status_bit_set(type_, status)
1928    };
1929}
1930
1931/// **************************************************************************
1932/// Name: wifi_coex_set_schm_interval
1933///
1934/// Description:
1935///   Don't support
1936///
1937/// *************************************************************************
1938#[allow(unused_variables)]
1939pub unsafe extern "C" fn coex_schm_interval_set(interval: u32) -> crate::binary::c_types::c_int {
1940    trace!("coex_schm_interval_set");
1941
1942    #[cfg(coex)]
1943    return unsafe { crate::binary::include::coex_schm_interval_set(interval) };
1944
1945    #[cfg(not(coex))]
1946    0
1947}
1948
1949/// **************************************************************************
1950/// Name: wifi_coex_get_schm_interval
1951///
1952/// Description:
1953///   Don't support
1954///
1955/// *************************************************************************
1956#[allow(unused_variables)]
1957pub unsafe extern "C" fn coex_schm_interval_get() -> u32 {
1958    trace!("coex_schm_interval_get");
1959
1960    #[cfg(coex)]
1961    return unsafe { crate::binary::include::coex_schm_interval_get() };
1962
1963    #[cfg(not(coex))]
1964    0
1965}
1966
1967/// **************************************************************************
1968/// Name: wifi_coex_get_schm_curr_period
1969///
1970/// Description:
1971///   Don't support
1972///
1973/// *************************************************************************
1974#[allow(unused_variables)]
1975pub unsafe extern "C" fn coex_schm_curr_period_get() -> u8 {
1976    trace!("coex_schm_curr_period_get");
1977
1978    #[cfg(coex)]
1979    return unsafe { crate::binary::include::coex_schm_curr_period_get() };
1980
1981    #[cfg(not(coex))]
1982    0
1983}
1984
1985/// **************************************************************************
1986/// Name: wifi_coex_get_schm_curr_phase
1987///
1988/// Description:
1989///   Don't support
1990///
1991/// *************************************************************************
1992#[allow(unused_variables)]
1993pub unsafe extern "C" fn coex_schm_curr_phase_get() -> *mut crate::binary::c_types::c_void {
1994    trace!("coex_schm_curr_phase_get");
1995
1996    #[cfg(coex)]
1997    return unsafe { crate::binary::include::coex_schm_curr_phase_get() };
1998
1999    #[cfg(not(coex))]
2000    return core::ptr::null_mut();
2001}
2002
2003pub unsafe extern "C" fn coex_schm_process_restart_wrapper() -> esp_wifi_sys::c_types::c_int {
2004    trace!("coex_schm_process_restart_wrapper");
2005
2006    #[cfg(not(coex))]
2007    return 0;
2008
2009    #[cfg(coex)]
2010    unsafe {
2011        crate::binary::include::coex_schm_process_restart()
2012    }
2013}
2014
2015#[allow(unused_variables)]
2016pub unsafe extern "C" fn coex_schm_register_cb_wrapper(
2017    arg1: esp_wifi_sys::c_types::c_int,
2018    cb: ::core::option::Option<
2019        unsafe extern "C" fn(arg1: esp_wifi_sys::c_types::c_int) -> esp_wifi_sys::c_types::c_int,
2020    >,
2021) -> esp_wifi_sys::c_types::c_int {
2022    trace!("coex_schm_register_cb_wrapper {} {:?}", arg1, cb);
2023
2024    #[cfg(not(coex))]
2025    return 0;
2026
2027    #[cfg(coex)]
2028    unsafe {
2029        crate::binary::include::coex_schm_register_callback(
2030            arg1 as u32,
2031            unwrap!(cb) as *const esp_wifi_sys::c_types::c_void
2032                as *mut esp_wifi_sys::c_types::c_void,
2033        )
2034    }
2035}
2036
2037pub unsafe extern "C" fn coex_schm_flexible_period_set(period: u8) -> i32 {
2038    trace!("coex_schm_flexible_period_set {}", period);
2039
2040    #[cfg(coex)]
2041    unsafe {
2042        unsafe extern "C" {
2043            fn coex_schm_flexible_period_set(period: u8) -> i32;
2044        }
2045
2046        coex_schm_flexible_period_set(period)
2047    }
2048
2049    #[cfg(not(coex))]
2050    0
2051}
2052
2053pub unsafe extern "C" fn coex_schm_flexible_period_get() -> u8 {
2054    trace!("coex_schm_flexible_period_get");
2055
2056    #[cfg(coex)]
2057    unsafe {
2058        unsafe extern "C" {
2059            fn coex_schm_flexible_period_get() -> u8;
2060        }
2061
2062        coex_schm_flexible_period_get()
2063    }
2064
2065    #[cfg(not(coex))]
2066    0
2067}
2068
2069pub unsafe extern "C" fn coex_register_start_cb(
2070    _cb: Option<unsafe extern "C" fn() -> esp_wifi_sys::c_types::c_int>,
2071) -> esp_wifi_sys::c_types::c_int {
2072    #[cfg(coex)]
2073    return unsafe { esp_wifi_sys::include::coex_register_start_cb(_cb) };
2074
2075    #[cfg(not(coex))]
2076    0
2077}
2078
2079/// **************************************************************************
2080/// Name: esp_clk_slowclk_cal_get_wrapper
2081///
2082/// Description:
2083///   Get the calibration value of RTC slow clock
2084///
2085/// Input Parameters:
2086///   None
2087///
2088/// Returned Value:
2089///   The calibration value obtained using rtc_clk_cal
2090///
2091/// *************************************************************************
2092#[allow(unused)]
2093pub unsafe extern "C" fn slowclk_cal_get() -> u32 {
2094    trace!("slowclk_cal_get");
2095
2096    // TODO not hardcode this
2097
2098    #[cfg(esp32s2)]
2099    return 44462;
2100
2101    #[cfg(esp32s3)]
2102    return 44462;
2103
2104    #[cfg(esp32c3)]
2105    return 28639;
2106
2107    #[cfg(esp32c2)]
2108    return 28639;
2109
2110    #[cfg(any(esp32c6, esp32h2))]
2111    return 0;
2112
2113    #[cfg(esp32)]
2114    return 28639;
2115}