1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #ifndef _ESP32_COMPAT_H_ 15 #define _ESP32_COMPAT_H_ 16 17 // Skip these include files 18 #define ESP_MDNS_NETWORKING_H_ 19 #define _TCPIP_ADAPTER_H_ 20 #define _ESP_TASK_H_ 21 22 #ifdef USE_BSD_STRING 23 #include <bsd/string.h> 24 #endif 25 #include <stdint.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <stdbool.h> 29 #include <unistd.h> 30 #include <signal.h> 31 #include <sys/time.h> 32 #include "esp_timer.h" 33 34 #define ESP_FAIL -1 35 36 #define ESP_ERR_NO_MEM 0x101 37 #define ESP_ERR_INVALID_ARG 0x102 38 #define ESP_ERR_INVALID_STATE 0x103 39 #define ESP_ERR_INVALID_SIZE 0x104 40 #define ESP_ERR_NOT_FOUND 0x105 41 #define ESP_ERR_NOT_SUPPORTED 0x106 42 #define ESP_ERR_TIMEOUT 0x107 43 #define ESP_ERR_INVALID_RESPONSE 0x108 44 #define ESP_ERR_INVALID_CRC 0x109 45 46 #define pdTRUE true 47 #define pdFALSE false 48 #define pdPASS ( pdTRUE ) 49 #define pdFAIL ( pdFALSE ) 50 51 #define portMAX_DELAY 0xFFFFFFFF 52 #define portTICK_PERIOD_MS 1 53 #define ESP_LOGW(a,b) 54 #define ESP_LOGD(a,b) 55 #define ESP_LOGE(a,b,c) 56 #define ESP_LOGV(a,b,c,d) 57 58 #define LWIP_HDR_PBUF_H 59 #define __ESP_SYSTEM_H__ 60 #define INC_TASK_H 61 62 #define pdMS_TO_TICKS(a) a 63 #define portTICK_RATE_MS 10 64 #define xSemaphoreTake(s,d) true 65 #define xTaskDelete(a) 66 #define vTaskDelete(a) free(a) 67 #define xSemaphoreGive(s) 68 #define xQueueCreateMutex(s) 69 #define _mdns_pcb_init(a,b) true 70 #define _mdns_pcb_deinit(a,b) true 71 #define xSemaphoreCreateMutex() malloc(1) 72 #define xSemaphoreCreateBinary() malloc(1) 73 #define vSemaphoreDelete(s) free(s) 74 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U 75 #define xTaskCreatePinnedToCore(a,b,c,d,e,f,g) *(f) = malloc(1) 76 #define vTaskDelay(m) usleep((m)*0) 77 #define esp_random() (rand()%UINT32_MAX) 78 79 80 #define ESP_TASK_PRIO_MAX 25 81 #define ESP_TASKD_EVENT_PRIO 5 82 #define _mdns_udp_pcb_write(tcpip_if, ip_protocol, ip, port, data, len) len 83 #define xTaskHandle TaskHandle_t 84 85 86 typedef int32_t esp_err_t; 87 88 typedef void * xSemaphoreHandle; 89 typedef void * SemaphoreHandle_t; 90 typedef void * xQueueHandle; 91 typedef void * QueueHandle_t; 92 typedef void * TaskHandle_t; 93 typedef int BaseType_t; 94 typedef uint32_t TickType_t; 95 typedef uint32_t portTickType; 96 97 98 extern const char * WIFI_EVENT; 99 extern const char * IP_EVENT; 100 extern const char * ETH_EVENT; 101 102 /* status of DHCP client or DHCP server */ 103 typedef enum { 104 TCPIP_ADAPTER_DHCP_INIT = 0, /**< DHCP client/server in initial state */ 105 TCPIP_ADAPTER_DHCP_STARTED, /**< DHCP client/server already been started */ 106 TCPIP_ADAPTER_DHCP_STOPPED, /**< DHCP client/server already been stopped */ 107 TCPIP_ADAPTER_DHCP_STATUS_MAX 108 } tcpip_adapter_dhcp_status_t; 109 110 struct udp_pcb { 111 uint8_t dummy; 112 }; 113 114 struct ip4_addr { 115 uint32_t addr; 116 }; 117 typedef struct ip4_addr ip4_addr_t; 118 119 struct ip6_addr { 120 uint32_t addr[4]; 121 }; 122 typedef struct ip6_addr ip6_addr_t; 123 124 typedef struct { 125 ip4_addr_t ip; 126 ip4_addr_t netmask; 127 ip4_addr_t gw; 128 } tcpip_adapter_ip_info_t; 129 130 typedef enum { 131 TCPIP_ADAPTER_IF_STA = 0, /**< ESP32 station interface */ 132 TCPIP_ADAPTER_IF_AP, /**< ESP32 soft-AP interface */ 133 TCPIP_ADAPTER_IF_ETH, /**< ESP32 ethernet interface */ 134 TCPIP_ADAPTER_IF_MAX 135 } tcpip_adapter_if_t; 136 137 typedef struct { 138 ip6_addr_t ip; 139 } tcpip_adapter_ip6_info_t; 140 141 typedef void* system_event_t; 142 143 struct pbuf { 144 struct pbuf *next; 145 void *payload; 146 uint16_t tot_len; 147 uint16_t len; 148 uint8_t /*pbuf_type*/ type; 149 uint8_t flags; 150 uint16_t ref; 151 }; 152 153 uint32_t xTaskGetTickCount(void); 154 typedef void (*esp_timer_cb_t)(void* arg); 155 156 // Queue mock 157 QueueHandle_t xQueueCreate( uint32_t uxQueueLength, 158 uint32_t uxItemSize ); 159 160 void vQueueDelete( QueueHandle_t xQueue ); 161 162 uint32_t xQueueSend(QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait); 163 164 uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait); 165 166 void GetLastItem(void *pvBuffer); 167 168 void ForceTaskDelete(void); 169 170 esp_err_t esp_event_handler_register(const char * event_base, int32_t event_id, void* event_handler, void* event_handler_arg); 171 172 esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler); 173 174 175 TaskHandle_t xTaskGetCurrentTaskHandle(void); 176 void xTaskNotifyGive(TaskHandle_t task); 177 BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time ); 178 179 #endif //_ESP32_COMPAT_H_ 180