1 /* 2 * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ESP_WIFI_OS_ADAPTER_H_ 8 #define ESP_WIFI_OS_ADAPTER_H_ 9 10 #include <stdarg.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define ESP_WIFI_OS_ADAPTER_VERSION 0x00000008 17 #define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF 18 19 #define OSI_FUNCS_TIME_BLOCKING 0xffffffff 20 21 #define OSI_QUEUE_SEND_FRONT 0 22 #define OSI_QUEUE_SEND_BACK 1 23 #define OSI_QUEUE_SEND_OVERWRITE 2 24 25 typedef struct { 26 int32_t _version; 27 bool (* _env_is_chip)(void); 28 void (*_set_intr)(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio); 29 void (*_clear_intr)(uint32_t intr_source, uint32_t intr_num); 30 void (*_set_isr)(int32_t n, void *f, void *arg); 31 void (*_ints_on)(uint32_t mask); 32 void (*_ints_off)(uint32_t mask); 33 bool (* _is_from_isr)(void); 34 void *(* _spin_lock_create)(void); 35 void (* _spin_lock_delete)(void *lock); 36 uint32_t (*_wifi_int_disable)(void *wifi_int_mux); 37 void (*_wifi_int_restore)(void *wifi_int_mux, uint32_t tmp); 38 void (*_task_yield_from_isr)(void); 39 void *(*_semphr_create)(uint32_t max, uint32_t init); 40 void (*_semphr_delete)(void *semphr); 41 int32_t (*_semphr_take)(void *semphr, uint32_t block_time_tick); 42 int32_t (*_semphr_give)(void *semphr); 43 void *(*_wifi_thread_semphr_get)(void); 44 void *(*_mutex_create)(void); 45 void *(*_recursive_mutex_create)(void); 46 void (*_mutex_delete)(void *mutex); 47 int32_t (*_mutex_lock)(void *mutex); 48 int32_t (*_mutex_unlock)(void *mutex); 49 void *(* _queue_create)(uint32_t queue_len, uint32_t item_size); 50 void (* _queue_delete)(void *queue); 51 int32_t (* _queue_send)(void *queue, void *item, uint32_t block_time_tick); 52 int32_t (* _queue_send_from_isr)(void *queue, void *item, void *hptw); 53 int32_t (* _queue_send_to_back)(void *queue, void *item, uint32_t block_time_tick); 54 int32_t (* _queue_send_to_front)(void *queue, void *item, uint32_t block_time_tick); 55 int32_t (* _queue_recv)(void *queue, void *item, uint32_t block_time_tick); 56 uint32_t (* _queue_msg_waiting)(void *queue); 57 void *(* _event_group_create)(void); 58 void (* _event_group_delete)(void *event); 59 uint32_t (* _event_group_set_bits)(void *event, uint32_t bits); 60 uint32_t (* _event_group_clear_bits)(void *event, uint32_t bits); 61 uint32_t (* _event_group_wait_bits)(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick); 62 int32_t (* _task_create_pinned_to_core)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id); 63 int32_t (* _task_create)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle); 64 void (* _task_delete)(void *task_handle); 65 void (* _task_delay)(uint32_t tick); 66 int32_t (* _task_ms_to_tick)(uint32_t ms); 67 void *(* _task_get_current_task)(void); 68 int32_t (* _task_get_max_priority)(void); 69 void *(* _malloc)(size_t size); 70 void (* _free)(void *p); 71 int32_t (* _event_post)(const char* event_base, int32_t event_id, void* event_data, size_t event_data_size, uint32_t ticks_to_wait); 72 uint32_t (* _get_free_heap_size)(void); 73 uint32_t (* _rand)(void); 74 void (* _dport_access_stall_other_cpu_start_wrap)(void); 75 void (* _dport_access_stall_other_cpu_end_wrap)(void); 76 void (* _wifi_apb80m_request)(void); 77 void (* _wifi_apb80m_release)(void); 78 void (* _phy_disable)(void); 79 void (* _phy_enable)(void); 80 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 81 void (* _phy_common_clock_enable)(void); 82 void (* _phy_common_clock_disable)(void); 83 #endif 84 int (* _phy_update_country_info)(const char* country); 85 int (* _read_mac)(uint8_t* mac, unsigned int type); 86 void (* _timer_arm)(void *timer, uint32_t tmout, bool repeat); 87 void (* _timer_disarm)(void *timer); 88 void (* _timer_done)(void *ptimer); 89 void (* _timer_setfn)(void *ptimer, void *pfunction, void *parg); 90 void (* _timer_arm_us)(void *ptimer, uint32_t us, bool repeat); 91 void (* _wifi_reset_mac)(void); 92 void (* _wifi_clock_enable)(void); 93 void (* _wifi_clock_disable)(void); 94 void (* _wifi_rtc_enable_iso)(void); 95 void (* _wifi_rtc_disable_iso)(void); 96 int64_t (* _esp_timer_get_time)(void); 97 int (* _nvs_set_i8)(uint32_t handle, const char* key, int8_t value); 98 int (* _nvs_get_i8)(uint32_t handle, const char* key, int8_t* out_value); 99 int (* _nvs_set_u8)(uint32_t handle, const char* key, uint8_t value); 100 int (* _nvs_get_u8)(uint32_t handle, const char* key, uint8_t* out_value); 101 int (* _nvs_set_u16)(uint32_t handle, const char* key, uint16_t value); 102 int (* _nvs_get_u16)(uint32_t handle, const char* key, uint16_t* out_value); 103 int (* _nvs_open)(const char* name, unsigned int open_mode, uint32_t *out_handle); 104 void (* _nvs_close)(uint32_t handle); 105 int (* _nvs_commit)(uint32_t handle); 106 int (* _nvs_set_blob)(uint32_t handle, const char* key, const void* value, size_t length); 107 int (* _nvs_get_blob)(uint32_t handle, const char* key, void* out_value, size_t* length); 108 int (* _nvs_erase_key)(uint32_t handle, const char* key); 109 int (* _get_random)(uint8_t *buf, size_t len); 110 int (* _get_time)(void *t); 111 unsigned long (* _random)(void); 112 #if !CONFIG_IDF_TARGET_ESP32 113 uint32_t (* _slowclk_cal_get)(void); 114 #endif 115 void (* _log_write)(unsigned int level, const char* tag, const char* format, ...); 116 void (* _log_writev)(unsigned int level, const char* tag, const char* format, va_list args); 117 uint32_t (* _log_timestamp)(void); 118 void * (* _malloc_internal)(size_t size); 119 void * (* _realloc_internal)(void *ptr, size_t size); 120 void * (* _calloc_internal)(size_t n, size_t size); 121 void * (* _zalloc_internal)(size_t size); 122 void * (* _wifi_malloc)(size_t size); 123 void * (* _wifi_realloc)(void *ptr, size_t size); 124 void * (* _wifi_calloc)(size_t n, size_t size); 125 void * (* _wifi_zalloc)(size_t size); 126 void * (* _wifi_create_queue)(int queue_len, int item_size); 127 void (* _wifi_delete_queue)(void * queue); 128 int (* _coex_init)(void); 129 void (* _coex_deinit)(void); 130 int (* _coex_enable)(void); 131 void (* _coex_disable)(void); 132 uint32_t (* _coex_status_get)(void); 133 void (* _coex_condition_set)(uint32_t type, bool dissatisfy); 134 int (* _coex_wifi_request)(uint32_t event, uint32_t latency, uint32_t duration); 135 int (* _coex_wifi_release)(uint32_t event); 136 int (* _coex_wifi_channel_set)(uint8_t primary, uint8_t secondary); 137 int (* _coex_event_duration_get)(uint32_t event, uint32_t *duration); 138 int (* _coex_pti_get)(uint32_t event, uint8_t *pti); 139 void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); 140 void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status); 141 int (* _coex_schm_interval_set)(uint32_t interval); 142 uint32_t (* _coex_schm_interval_get)(void); 143 uint8_t (* _coex_schm_curr_period_get)(void); 144 void * (* _coex_schm_curr_phase_get)(void); 145 int (* _coex_schm_process_restart)(void); 146 int (* _coex_schm_register_cb)(int, int (* cb)(int)); 147 int (* _coex_register_start_cb)(int (* cb)(void)); 148 #if CONFIG_IDF_TARGET_ESP32C6 149 void (* _regdma_link_set_write_wait_content)(void *, uint32_t, uint32_t); 150 void * (* _sleep_retention_find_link_by_id)(int); 151 int (* _sleep_retention_entries_create)(const void *, int, int, int); 152 void (* _sleep_retention_entries_destroy)(int); 153 #endif 154 int32_t _magic; 155 } wifi_osi_funcs_t; 156 157 extern wifi_osi_funcs_t g_wifi_osi_funcs; 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif /* ESP_WIFI_OS_ADAPTER_H_ */ 164