diff --git a/components/esp8266/include/esp_wifi_os_adapter.h b/components/esp8266/include/esp_wifi_os_adapter.h new file mode 100644 index 00000000..a559de5d --- /dev/null +++ b/components/esp8266/include/esp_wifi_os_adapter.h @@ -0,0 +1,89 @@ +// Copyright 2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ESP_WIFI_OS_ADAPTER_H_ +#define ESP_WIFI_OS_ADAPTER_H_ + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +#define OSI_QUEUE_SEND_FRONT 0 +#define OSI_QUEUE_SEND_BACK 1 +#define OSI_QUEUE_SEND_OVERWRITE 2 + +typedef struct { + uint32_t (*enter_critical)(void); + void (*exit_critical)(uint32_t tmp); + + void *(*task_create)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio); + void (*task_delete)(void *task_handle); + void (*task_yield)(void); + void (*task_yield_from_isr)(void); + void (*task_delay)(uint32_t tick); + void *(*task_get_current_task)(void); + uint32_t (*task_get_max_priority)(void); + + uint32_t (*task_ms_to_tick)(uint32_t ms); + + void (*task_suspend_all)(void); + void (*task_resume_all)(void); + + void (*os_init)(void); + void (*os_start)(void); + + void *(*semphr_create)(uint32_t max, uint32_t init); + void (*semphr_delete)(void *semphr); + bool (*semphr_take_from_isr)(void *semphr, int *hptw); + bool (*semphr_give_from_isr)(void *semphr, int *hptw); + bool (*semphr_take)(void *semphr, uint32_t block_time_tick); + bool (*semphr_give)(void *semphr); + + void *(*mutex_create)(void); + void (*mutex_delete)(void *mutex); + bool (*mutex_lock)(void *mutex); + bool (*mutex_unlock)(void *mutex); + + void *(*queue_create)(uint32_t queue_len, uint32_t item_size); + void (*queue_delete)(void *queue); + bool (*queue_send)(void *queue, void *item, uint32_t block_time_tick, uint32_t pos); + bool (*queue_send_from_isr)(void *queue, void *item, int *hptw); + bool (*queue_recv)(void *queue, void *item, uint32_t block_time_tick); + bool (*queue_recv_from_isr)(void *queue, void *item, int *hptw); + uint32_t (*queue_msg_waiting)(void *queue); + + void *(*timer_create)(const char *name, uint32_t period_ticks, bool auto_load, void *arg, void (*cb)(void *timer)); + void *(*timer_get_arg)(void *timer); + bool (*timer_reset)(void *timer, uint32_t ticks); + bool (*timer_stop)(void *timer, uint32_t ticks); + bool (*timer_delete)(void *timer, uint32_t ticks); + + void *(*malloc)(uint32_t size); + void (*free)(void *p); + uint32_t (*get_free_heap_size)(void); + + void (*srand)(uint32_t seed); + int32_t (*rand)(void); +} wifi_osi_funcs_t; + +#ifdef __cplusplus +} +#endif + +#endif /* ESP_WIFI_OS_ADAPTER_H_ */ diff --git a/components/esp8266/include/esp_wifi_osi.h b/components/esp8266/include/esp_wifi_osi.h new file mode 100644 index 00000000..11228320 --- /dev/null +++ b/components/esp8266/include/esp_wifi_osi.h @@ -0,0 +1,153 @@ +// Copyright 2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ESP_WIFI_OSI_H_ +#define ESP_WIFI_OSI_H_ + +#include "esp_wifi_os_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern wifi_osi_funcs_t s_wifi_osi_funcs; + +#define wifi_enter_critical(t) \ + t = s_wifi_osi_funcs.enter_critical() + +#define wifi_exit_critical(t) \ + s_wifi_osi_funcs.exit_critical(t) + +#define wifi_task_create(func, name, depth, param, pri) \ + s_wifi_osi_funcs.task_create(func, name, depth, param, pri) + +#define wifi_task_delete(h) \ + s_wifi_osi_funcs.task_delete(h) + +#define wifi_task_yield() \ + s_wifi_osi_funcs.task_yield() + +#define wifi_task_yield_from_isr() \ + s_wifi_osi_funcs.task_yield_from_isr() + +#define wifi_task_delay(t) \ + s_wifi_osi_funcs.task_delay(t) + +#define wifi_task_get_current_task() \ + s_wifi_osi_funcs.task_get_current_task() + +#define wifi_task_get_max_priority() \ + s_wifi_osi_funcs.task_get_max_priority() + +#define wifi_task_ms_to_ticks(t) \ + s_wifi_osi_funcs.task_ms_to_tick(t) + +#define wifi_task_suspend_all() \ + s_wifi_osi_funcs.task_suspend_all() + +#define wifi_task_resume_all() \ + s_wifi_osi_funcs.task_resume_all() + +#define wifi_os_init() \ + s_wifi_osi_funcs.os_init() + +#define wifi_os_start() \ + s_wifi_osi_funcs.os_start() + +#define wifi_semphr_create(m, i) \ + s_wifi_osi_funcs.semphr_create(m, i) + +#define wifi_semphr_delete(s) \ + s_wifi_osi_funcs.semphr_delete(s) + +#define wifi_semphr_take_from_isr(s, r) \ + s_wifi_osi_funcs.semphr_take_from_isr(s, r) + +#define wifi_semphr_give_from_isr(s, r) \ + s_wifi_osi_funcs.semphr_give_from_isr(s, r) + +#define wifi_semphr_take(s, t) \ + s_wifi_osi_funcs.semphr_take(s, t) + +#define wifi_semphr_give(s) \ + s_wifi_osi_funcs.semphr_give(s) + +#define wifi_mutex_create() \ + s_wifi_osi_funcs.mutex_create() + +#define wifi_mutex_delete(m) \ + s_wifi_osi_funcs.mutex_delete(m) + +#define wifi_mutex_lock(m) \ + s_wifi_osi_funcs.mutex_lock(m) + +#define wifi_mutex_unlock(m) \ + s_wifi_osi_funcs.mutex_unlock(m) + +#define wifi_queue_create(ql, is) \ + s_wifi_osi_funcs.queue_create(ql, is) + +#define wifi_queue_delete(q) \ + s_wifi_osi_funcs.queue_delete(q) + +#define wifi_queue_send(q, i, t, p) \ + s_wifi_osi_funcs.queue_send(q, i, t, p) + +#define wifi_queue_send_from_isr(q, i, r) \ + s_wifi_osi_funcs.queue_send_from_isr(q, i, r) + +#define wifi_queue_recv(q, i, t) \ + s_wifi_osi_funcs.queue_recv(q, i, t) + +#define wifi_queue_recv_from_isr(q, i, r) \ + s_wifi_osi_funcs.queue_recv_from_isr(q, i, r) + +#define wifi_queue_msg_waiting(q) \ + s_wifi_osi_funcs.queue_msg_waiting(q) + +#define wifi_timer_create(n, p, al, ag, cb) \ + s_wifi_osi_funcs.timer_create(n, p, al, ag, cb) + +#define wifi_timer_get_arg(t) \ + s_wifi_osi_funcs.timer_get_arg(t) + +#define wifi_timer_reset(t, tk) \ + s_wifi_osi_funcs.timer_reset(t, tk) + +#define wifi_timer_stop(t, tk) \ + s_wifi_osi_funcs.timer_stop(t, tk) + +#define wifi_timer_delete(t, tk) \ + s_wifi_osi_funcs.timer_delete(t, tk) + +#define wifi_malloc(s) \ + s_wifi_osi_funcs.malloc(s) + +#define wifi_free(p) \ + s_wifi_osi_funcs.free(p) + +#define wifi_get_free_heap_size() \ + s_wifi_osi_funcs.get_free_heap_size() + +#define wifi_srand(s) \ + s_wifi_osi_funcs.srand(s) + +#define wifi_rand() \ + s_wifi_osi_funcs.rand() + +#ifdef __cplusplus +} +#endif + +#endif /* ESP_WIFI_OSI_H_ */ diff --git a/components/esp8266/lib/VERSION b/components/esp8266/lib/VERSION index e7ff495f..97af2bd4 100644 --- a/components/esp8266/lib/VERSION +++ b/components/esp8266/lib/VERSION @@ -1,11 +1,11 @@ gwen: - crypto: 21b4121 - espnow: 21b4121 - core: 0655d69 - minic: 21b4121 - net80211: 21b4121 - pp: 21b4121 - pwm: 21b4121 + crypto: 5fc5b4f + espnow: 5fc5b4f + core: 5fc5b4f + minic: 5fc5b4f + net80211: 5fc5b4f + pp: 5fc5b4f + pwm: 5fc5b4f smartconfig:9ec59b5 - wpa: 21b4121 - wps: 21b4121 \ No newline at end of file + wpa: 5fc5b4f + wps: 5fc5b4f \ No newline at end of file diff --git a/components/esp8266/lib/libcore.a b/components/esp8266/lib/libcore.a old mode 100644 new mode 100755 index 8eeb1a53..c18ba1ab Binary files a/components/esp8266/lib/libcore.a and b/components/esp8266/lib/libcore.a differ diff --git a/components/esp8266/lib/libcrypto.a b/components/esp8266/lib/libcrypto.a index 3478873a..c3aa0df5 100644 Binary files a/components/esp8266/lib/libcrypto.a and b/components/esp8266/lib/libcrypto.a differ diff --git a/components/esp8266/lib/libespnow.a b/components/esp8266/lib/libespnow.a index 9d56380e..063858f6 100644 Binary files a/components/esp8266/lib/libespnow.a and b/components/esp8266/lib/libespnow.a differ diff --git a/components/esp8266/lib/libminic.a b/components/esp8266/lib/libminic.a index 1a00eb6d..06525c88 100644 Binary files a/components/esp8266/lib/libminic.a and b/components/esp8266/lib/libminic.a differ diff --git a/components/esp8266/lib/libnet80211.a b/components/esp8266/lib/libnet80211.a index 8fa1ab86..c38eb684 100644 Binary files a/components/esp8266/lib/libnet80211.a and b/components/esp8266/lib/libnet80211.a differ diff --git a/components/esp8266/lib/libpp.a b/components/esp8266/lib/libpp.a index a8dd27d0..c587e38f 100644 Binary files a/components/esp8266/lib/libpp.a and b/components/esp8266/lib/libpp.a differ diff --git a/components/esp8266/lib/libpwm.a b/components/esp8266/lib/libpwm.a index 5e705533..8e8ada44 100644 Binary files a/components/esp8266/lib/libpwm.a and b/components/esp8266/lib/libpwm.a differ diff --git a/components/esp8266/lib/libwpa.a b/components/esp8266/lib/libwpa.a index d3376f42..adbc82fd 100644 Binary files a/components/esp8266/lib/libwpa.a and b/components/esp8266/lib/libwpa.a differ diff --git a/components/esp8266/lib/libwps.a b/components/esp8266/lib/libwps.a index 3ad3c698..029d515a 100644 Binary files a/components/esp8266/lib/libwps.a and b/components/esp8266/lib/libwps.a differ diff --git a/components/esp8266/source/esp_wifi_os_adapter.c b/components/esp8266/source/esp_wifi_os_adapter.c new file mode 100644 index 00000000..561b10f9 --- /dev/null +++ b/components/esp8266/source/esp_wifi_os_adapter.c @@ -0,0 +1,330 @@ +// Copyright 2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "esp_wifi_os_adapter.h" +#include "esp_system.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/timers.h" + +static uint32_t enter_critical_wrapper(void) +{ + taskENTER_CRITICAL(); + + return 0; +} + +static void exit_critical_wrapper(uint32_t tmp) +{ + taskEXIT_CRITICAL(); +} + +static void *task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio) +{ + portBASE_TYPE ret; + xTaskHandle handle; + + ret = xTaskCreate(task_func, (const signed char *)name, stack_depth, param, prio, &handle); + + return ret == pdPASS ? handle : NULL; +} + +static void task_delete_wrapper(void *task_handle) +{ + vTaskDelete(task_handle); +} + +static void task_yield_wrapper(void) +{ + portYIELD(); +} + +static void task_yield_from_isr_wrapper(void) +{ + portYIELD(); +} + +static void task_delay_wrapper(uint32_t tick) +{ + vTaskDelay(tick); +} + +static void* task_get_current_task_wrapper(void) +{ + return (void *)xTaskGetCurrentTaskHandle(); +} + +static uint32_t task_get_max_priority_wrapper(void) +{ + return (uint32_t)(configMAX_PRIORITIES); +} + +static uint32_t task_ms_to_tick_wrapper(uint32_t ms) +{ + return (uint32_t)(ms / portTICK_RATE_MS); +} + +static void task_suspend_all_wrapper(void) +{ + vTaskSuspendAll(); +} + +static void task_resume_all_wrapper(void) +{ + xTaskResumeAll(); +} + +static void os_init_wrapper(void) +{ + /* empty function */ +} + +static void os_start_wrapper(void) +{ + vTaskStartScheduler(); +} + +static void *semphr_create_wrapper(uint32_t max, uint32_t init) +{ + return (void *)xSemaphoreCreateCounting(max, init); +} + +static void semphr_delete_wrapper(void *semphr) +{ + vSemaphoreDelete(semphr); +} + +static bool semphr_take_from_isr_wrapper(void *semphr, int *hptw) +{ + signed portBASE_TYPE ret; + + ret = xSemaphoreTakeFromISR(semphr, (signed portBASE_TYPE *)hptw); + + return ret == pdPASS ? true : false; +} + +static bool semphr_give_from_isr_wrapper(void *semphr, int *hptw) +{ + signed portBASE_TYPE ret; + + ret = xSemaphoreGiveFromISR(semphr, (signed portBASE_TYPE *)hptw); + + return ret == pdPASS ? true : false; +} + +static bool semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + signed portBASE_TYPE ret; + + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + ret = xSemaphoreTake(semphr, portMAX_DELAY); + } else { + ret = xSemaphoreTake(semphr, block_time_tick); + } + + return ret == pdPASS ? true : false; +} + +static bool semphr_give_wrapper(void *semphr) +{ + signed portBASE_TYPE ret; + + ret = xSemaphoreGive(semphr); + + return ret == pdPASS ? true : false; +} + +static void *mutex_create_wrapper(void) +{ + return (void *)xSemaphoreCreateRecursiveMutex(); +} + +static void mutex_delete_wrapper(void *mutex) +{ + vSemaphoreDelete(mutex); +} + +static bool mutex_lock_wrapper(void *mutex) +{ + signed portBASE_TYPE ret; + + ret = xSemaphoreTakeRecursive(mutex, portMAX_DELAY); + + return ret == pdPASS ? true : false; +} + +static bool mutex_unlock_wrapper(void *mutex) +{ + signed portBASE_TYPE ret; + + ret = xSemaphoreGiveRecursive(mutex); + + return ret == pdPASS ? true : false; +} + +static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size) +{ + return (void *)xQueueCreate(queue_len, item_size); +} + +static void queue_delete_wrapper(void *queue) +{ + vQueueDelete(queue); +} + +static bool queue_send_wrapper(void *queue, void *item, uint32_t block_time_tick, uint32_t pos) +{ + signed portBASE_TYPE ret; + + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + ret = xQueueGenericSend(queue, item, portMAX_DELAY, pos); + } else { + ret = xQueueGenericSend(queue, item, block_time_tick, pos); + } + + return ret == pdPASS ? true : false; +} + +static bool queue_send_from_isr_wrapper(void *queue, void *item, int *hptw) +{ + signed portBASE_TYPE ret; + + ret = xQueueSendFromISR(queue, item, (signed portBASE_TYPE *)hptw); + + return ret == pdPASS ? true : false; +} + +static bool queue_recv_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + signed portBASE_TYPE ret; + + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + ret = xQueueReceive(queue, item, portMAX_DELAY); + } else { + ret = xQueueReceive(queue, item, block_time_tick); + } + + return ret == pdPASS ? true : false; +} + +static bool queue_recv_from_isr_wrapper(void *queue, void *item, int *hptw) +{ + signed portBASE_TYPE ret; + + ret = xQueueReceiveFromISR(queue, item, (signed portBASE_TYPE *)hptw); + + return ret == pdPASS ? true : false; +} + +static uint32_t queue_msg_waiting_wrapper(void *queue) +{ + return (uint32_t)uxQueueMessagesWaiting(queue); +} + +static uint32_t get_free_heap_size_wrapper(void) +{ + return (uint32_t)system_get_free_heap_size(); +} + +static void *timer_create_wrapper(const char *name, uint32_t period_ticks, bool auto_load, void *arg, void (*cb)(void *timer)) +{ + return xTimerCreate((const signed char *)name, period_ticks, auto_load, arg, (tmrTIMER_CALLBACK)cb); +} + +static void *timer_get_arg_wrapper(void *timer) +{ + return pvTimerGetTimerID(timer); +} + +static bool timer_reset_wrapper(void *timer, uint32_t ticks) +{ + return xTimerReset(timer, ticks); +} + +static bool timer_stop_wrapper(void *timer, uint32_t ticks) +{ + return xTimerStop(timer, ticks); +} + +static bool timer_delete_wrapper(void *timer, uint32_t ticks) +{ + return xTimerDelete(timer, ticks); +} + +static void srand_wrapper(uint32_t seed) +{ + /* empty function */ +} + +static int32_t rand_wrapper(void) +{ + return (int32_t)os_random(); +} + +wifi_osi_funcs_t s_wifi_osi_funcs = { + .enter_critical = enter_critical_wrapper, + .exit_critical = exit_critical_wrapper, + + .task_create = task_create_wrapper, + .task_delete = task_delete_wrapper, + .task_yield = task_yield_wrapper, + .task_yield_from_isr = task_yield_from_isr_wrapper, + .task_delay = task_delay_wrapper, + .task_get_current_task = task_get_current_task_wrapper, + .task_get_max_priority = task_get_max_priority_wrapper, + + .task_ms_to_tick = task_ms_to_tick_wrapper, + + .task_suspend_all = task_suspend_all_wrapper, + .task_resume_all = task_resume_all_wrapper, + + .os_init = os_init_wrapper, + .os_start = os_start_wrapper, + + .semphr_create = semphr_create_wrapper, + .semphr_delete = semphr_delete_wrapper, + .semphr_take_from_isr = semphr_take_from_isr_wrapper, + .semphr_give_from_isr = semphr_give_from_isr_wrapper, + .semphr_take = semphr_take_wrapper, + .semphr_give = semphr_give_wrapper, + + .mutex_create = mutex_create_wrapper, + .mutex_delete = mutex_delete_wrapper, + .mutex_lock = mutex_lock_wrapper, + .mutex_unlock = mutex_unlock_wrapper, + + .queue_create = queue_create_wrapper, + .queue_delete = queue_delete_wrapper, + .queue_send = queue_send_wrapper, + .queue_send_from_isr = queue_send_from_isr_wrapper, + .queue_recv = queue_recv_wrapper, + .queue_recv_from_isr = queue_recv_from_isr_wrapper, + .queue_msg_waiting = queue_msg_waiting_wrapper, + + .timer_create = timer_create_wrapper, + .timer_get_arg = timer_get_arg_wrapper, + .timer_reset = timer_reset_wrapper, + .timer_stop = timer_stop_wrapper, + .timer_delete = timer_delete_wrapper, + + .malloc = malloc, + .free = free, + .get_free_heap_size = get_free_heap_size_wrapper, + + .srand = srand_wrapper, + .rand = rand_wrapper, +}; diff --git a/components/freertos/include/freertos/portmacro.h b/components/freertos/include/freertos/portmacro.h index cf2f6e06..641c1081 100644 --- a/components/freertos/include/freertos/portmacro.h +++ b/components/freertos/include/freertos/portmacro.h @@ -117,8 +117,6 @@ extern void PendSV(char req); if(xSwitchRequired) PendSV(1) #endif -#define HDL_MAC_SIG_IN_LV1_ISR() PendSV(2) - /* Task utilities. */ #define portEND_SWITCHING_ISR( xSwitchRequired ) \ { \ diff --git a/components/freertos/library/port.c b/components/freertos/library/port.c index ab8472ed..49a25b9f 100644 --- a/components/freertos/library/port.c +++ b/components/freertos/library/port.c @@ -137,6 +137,11 @@ void PendSV(char req) } } +void HDL_MAC_SIG_IN_LV1_ISR(void) +{ + PendSV(2); +} + extern portBASE_TYPE MacIsrSigPostDefHdl(void); void SoftIsrHdl(void* arg) @@ -310,3 +315,18 @@ uint16 _xt_isr_handler(uint16 i) return i & ~(1 << index); } + +void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) +{ + os_printf("task [%s] stask overflow\n", pcTaskName); +} + +void __taskEXIT_CRITICAL(void) +{ + portEXIT_CRITICAL(); +} + +void __taskENTER_CRITICAL(void) +{ + portENTER_CRITICAL(); +}