From bf0b8c8bb647dc751c124f8666a8cc49af37e2e3 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Mon, 25 Jun 2018 16:30:38 +0800 Subject: [PATCH] feat(esp8266): Modify old system APIs to new ones --- components/esp8266/include/esp_libc.h | 2 -- components/esp8266/source/esp_wifi_os_adapter.c | 4 ++-- components/lwip/port/esp8266/include/lwipopts.h | 3 ++- components/newlib/newlib/port/time.c | 6 ++++-- components/spi_flash/src/spi_flash.c | 13 +++++++------ .../ssl/axtls/source/crypto/ssl_crypto_misc.c | 2 +- components/ssl/axtls/source/ssl/ssl_os_port.c | 12 +++++++----- components/ssl/axtls/source/ssl/ssl_tls1.c | 2 +- .../port/openssl/include/platform/ssl_port.h | 4 ++-- .../get-started/project_template/main/user_main.c | 2 +- examples/protocols/mqtt/main/MQTTEcho.c | 4 ++-- .../main/openssl_client_example_main.c | 4 ++-- .../openssl_demo/main/openssl_demo_example_main.c | 4 ++-- .../main/openssl_server_example_main.c | 4 ++-- examples/storage/spiffs_test/main/testrunner.h | 6 +++--- examples/wifi/smart_config/main/user_main.c | 2 +- .../wifi_station_machine/main/wifi_state_machine.c | 2 +- 17 files changed, 40 insertions(+), 36 deletions(-) diff --git a/components/esp8266/include/esp_libc.h b/components/esp8266/include/esp_libc.h index 66f2646e..ee6b17a7 100644 --- a/components/esp8266/include/esp_libc.h +++ b/components/esp8266/include/esp_libc.h @@ -34,8 +34,6 @@ extern "C" { #endif - -uint32_t os_random(void); int32_t os_get_random(unsigned char *buf, size_t len); /** diff --git a/components/esp8266/source/esp_wifi_os_adapter.c b/components/esp8266/source/esp_wifi_os_adapter.c index 28cc07d2..c090f149 100644 --- a/components/esp8266/source/esp_wifi_os_adapter.c +++ b/components/esp8266/source/esp_wifi_os_adapter.c @@ -245,7 +245,7 @@ static uint32_t queue_msg_waiting_wrapper(void *queue) static uint32_t get_free_heap_size_wrapper(void) { - return (uint32_t)system_get_free_heap_size(); + return (uint32_t)esp_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)) @@ -308,7 +308,7 @@ static void srand_wrapper(uint32_t seed) static int32_t rand_wrapper(void) { - return (int32_t)os_random(); + return (int32_t)esp_random(); } wifi_osi_funcs_t s_wifi_osi_funcs = { diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index 3a2af944..aad71b95 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -48,6 +48,7 @@ #include #include #include "esp_libc.h" +#include "esp_system.h" //#define SOCKETS_MT @@ -117,7 +118,7 @@ */ #define SMEMCPY(dst,src,len) memcpy(dst,src,len) -#define LWIP_RAND os_random +#define LWIP_RAND esp_random /** * @} diff --git a/components/newlib/newlib/port/time.c b/components/newlib/newlib/port/time.c index e18e3e3e..7a8169b7 100644 --- a/components/newlib/newlib/port/time.c +++ b/components/newlib/newlib/port/time.c @@ -21,6 +21,8 @@ #include "FreeRTOS.h" +extern uint32_t esp_get_time(); + static uint64_t s_boot_time; static os_timer_t microsecond_overflow_timer; @@ -31,7 +33,7 @@ static bool microsecond_overflow_timer_start_flag = false; static void microsecond_overflow_tick(void* arg) { - uint32_t m = system_get_time(); + uint32_t m = esp_get_time(); vPortEnterCritical(); @@ -84,7 +86,7 @@ static uint64_t get_time_since_boot() uint32_t c; uint64_t microseconds; - m = system_get_time(); + m = esp_get_time(); vPortEnterCritical(); diff --git a/components/spi_flash/src/spi_flash.c b/components/spi_flash/src/spi_flash.c index c2466dd0..cb630399 100644 --- a/components/spi_flash/src/spi_flash.c +++ b/components/spi_flash/src/spi_flash.c @@ -122,6 +122,7 @@ typedef struct { } spi_cmd_t; extern bool spi_flash_erase_sector_check(uint32_t); +extern uint32_t esp_get_time(); bool IRAM_ATTR spi_user_cmd(spi_cmd_dir_t mode, spi_cmd_t *p_cmd); bool special_flash_read_status(uint8_t command, uint32_t* status, int len); @@ -423,7 +424,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_sector(size_t sec) return ESP_ERR_FLASH_OP_FAIL; } - spi_debug("E[%x] %d-", sec, system_get_time()); + spi_debug("E[%x] %d-", sec, esp_get_time()); FLASH_INTR_LOCK(c_tmp); pp_soft_wdt_stop(); @@ -437,7 +438,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_sector(size_t sec) pp_soft_wdt_restart(); FLASH_INTR_UNLOCK(c_tmp); - spi_debug("%d\n", system_get_time()); + spi_debug("%d\n", esp_get_time()); return ret; } @@ -481,7 +482,7 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const void *src, size_t si } else tmp = (uint32_t *)src; - spi_debug("W[%x] %d-", dest_addr / 4096, system_get_time()); + spi_debug("W[%x] %d-", dest_addr / 4096, esp_get_time()); FLASH_INTR_LOCK(c_tmp); @@ -502,7 +503,7 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const void *src, size_t si if (IS_FLASH(src) || ((size_t)src) & 0x3) wifi_free(tmp); - spi_debug("%d\n", system_get_time()); + spi_debug("%d\n", esp_get_time()); return ret; } @@ -522,7 +523,7 @@ esp_err_t IRAM_ATTR spi_flash_read(size_t src_addr, void *dest, size_t size) return ESP_ERR_FLASH_OP_FAIL; } - spi_debug("R[%x] %d-", src_addr / 4096, system_get_time()); + spi_debug("R[%x] %d-", src_addr / 4096, esp_get_time()); FLASH_INTR_LOCK(c_tmp); @@ -537,7 +538,7 @@ esp_err_t IRAM_ATTR spi_flash_read(size_t src_addr, void *dest, size_t size) FlashIsOnGoing = 0; FLASH_INTR_UNLOCK(c_tmp); - spi_debug("%d\n", system_get_time()); + spi_debug("%d\n", esp_get_time()); return ret; } diff --git a/components/ssl/axtls/source/crypto/ssl_crypto_misc.c b/components/ssl/axtls/source/crypto/ssl_crypto_misc.c index c830e58b..1bcb1a1e 100644 --- a/components/ssl/axtls/source/crypto/ssl_crypto_misc.c +++ b/components/ssl/axtls/source/crypto/ssl_crypto_misc.c @@ -253,7 +253,7 @@ int get_random_NZ(int num_rand_bytes, uint8_t *rand_data) for (i = 0; i < num_rand_bytes; i++) { while (rand_data[i] == 0) /* can't be 0 */ - rand_data[i] = (uint8_t)(os_random()); + rand_data[i] = (uint8_t)(esp_random()); } return 0; diff --git a/components/ssl/axtls/source/ssl/ssl_os_port.c b/components/ssl/axtls/source/ssl/ssl_os_port.c index 594e23ce..352cee4c 100644 --- a/components/ssl/axtls/source/ssl/ssl_os_port.c +++ b/components/ssl/axtls/source/ssl/ssl_os_port.c @@ -213,7 +213,7 @@ EXP_FUNC void * ax_malloc(size_t s, const char* file, int line) if ((x = malloc(s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { - debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); + debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //add_mem_info(x, s, file, line); } @@ -226,7 +226,7 @@ EXP_FUNC void * ax_realloc(void *y, size_t s, const char* file, int line) if ((x = realloc(y, s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { - debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); + debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //add_mem_info(x, s, file, line); } @@ -239,7 +239,7 @@ EXP_FUNC void * ax_calloc(size_t n, size_t s, const char* file, int line) if ((x = calloc(n, s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { - debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); + debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //total_size = n * s; //add_mem_info (x, total_size, file, line); } @@ -253,7 +253,7 @@ EXP_FUNC void * ax_zalloc(size_t s, const char* file, int line) if ((x = (void*)zalloc(s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { - debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); + debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //add_mem_info(x, s, file, line); } @@ -262,7 +262,7 @@ EXP_FUNC void * ax_zalloc(size_t s, const char* file, int line) EXP_FUNC void ax_free(void *p, const char* file, int line) { if(p) { - debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, p,0, system_get_free_heap_size()); + debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, p,0, esp_get_free_heap_size()); free(p); p = NULL; } @@ -314,6 +314,7 @@ void exit_now(const char *format, ...) /** * gettimeofday() not in Win32 */ +#if 0 EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone) { #if defined(_WIN32_WCE) @@ -329,6 +330,7 @@ EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone) #endif } #endif +#endif unsigned int def_private_key_len = 0; unsigned char *def_private_key = NULL; diff --git a/components/ssl/axtls/source/ssl/ssl_tls1.c b/components/ssl/axtls/source/ssl/ssl_tls1.c index 291008d7..f2c7147d 100644 --- a/components/ssl/axtls/source/ssl/ssl_tls1.c +++ b/components/ssl/axtls/source/ssl/ssl_tls1.c @@ -243,7 +243,7 @@ EXP_FUNC void STDCALL ssl_ctx_free(SSL_CTX *ssl_ctx) EXP_FUNC void STDCALL ssl_free(SSL *ssl) { SSL_CTX *ssl_ctx; - printf("ssl_free:Aviable Memory|%d\n",system_get_free_heap_size()); + printf("ssl_free:Aviable Memory|%d\n",esp_get_free_heap_size()); if (ssl == NULL) /* just ignore null pointers */ return; diff --git a/components/ssl/mbedtls/port/openssl/include/platform/ssl_port.h b/components/ssl/mbedtls/port/openssl/include/platform/ssl_port.h index 63b22068..ad48854a 100644 --- a/components/ssl/mbedtls/port/openssl/include/platform/ssl_port.h +++ b/components/ssl/mbedtls/port/openssl/include/platform/ssl_port.h @@ -61,8 +61,8 @@ extern void vPortFree(void *pv); #define ssl_memcpy memcpy #define ssl_strlen strlen -#define ssl_speed_up_enter() system_update_cpu_freq(SYS_CPU_160MHZ) -#define ssl_speed_up_exit() system_update_cpu_freq(SYS_CPU_80MHZ) +#define ssl_speed_up_enter() rtc_clk_cpu_freq_set(RTC_CPU_FREQ_160M) +#define ssl_speed_up_exit() rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M) #define SSL_DEBUG_LOG printf diff --git a/examples/get-started/project_template/main/user_main.c b/examples/get-started/project_template/main/user_main.c index 7555f53c..32b348f8 100644 --- a/examples/get-started/project_template/main/user_main.c +++ b/examples/get-started/project_template/main/user_main.c @@ -71,5 +71,5 @@ uint32_t user_rf_cal_sector_set(void) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s\n", system_get_sdk_version()); + printf("SDK version:%s\n", esp_get_idf_version()); } diff --git a/examples/protocols/mqtt/main/MQTTEcho.c b/examples/protocols/mqtt/main/MQTTEcho.c index 796e0c8c..be815f6f 100644 --- a/examples/protocols/mqtt/main/MQTTEcho.c +++ b/examples/protocols/mqtt/main/MQTTEcho.c @@ -183,7 +183,7 @@ void wifi_event_handler_cb(System_Event_t* event) switch (event->event_id) { case EVENT_STAMODE_GOT_IP: - printf("sta got ip ,create task and free heap size is %d\n", system_get_free_heap_size()); + printf("sta got ip ,create task and free heap size is %d\n", esp_get_free_heap_size()); user_conn_init(); break; @@ -208,7 +208,7 @@ void wifi_event_handler_cb(System_Event_t* event) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size()); + printf("SDK version:%s %d\n", esp_get_idf_version(), esp_get_free_heap_size()); wifi_set_opmode(STATION_MODE); { diff --git a/examples/protocols/openssl_client/main/openssl_client_example_main.c b/examples/protocols/openssl_client/main/openssl_client_example_main.c index 4d216d8b..3f49b4a9 100644 --- a/examples/protocols/openssl_client/main/openssl_client_example_main.c +++ b/examples/protocols/openssl_client/main/openssl_client_example_main.c @@ -345,7 +345,7 @@ void wifi_event_handler_cb(System_Event_t* event) switch (event->event_id) { case EVENT_STAMODE_GOT_IP: - printf("sta got ip , creat task %d\n", system_get_free_heap_size()); + printf("sta got ip , creat task %d\n", esp_get_free_heap_size()); user_conn_init(); break; @@ -362,7 +362,7 @@ void wifi_event_handler_cb(System_Event_t* event) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size()); + printf("SDK version:%s %d\n", esp_get_idf_version(), esp_get_free_heap_size()); wifi_set_opmode(STATION_MODE); { diff --git a/examples/protocols/openssl_demo/main/openssl_demo_example_main.c b/examples/protocols/openssl_demo/main/openssl_demo_example_main.c index 1bc82209..37771ad7 100644 --- a/examples/protocols/openssl_demo/main/openssl_demo_example_main.c +++ b/examples/protocols/openssl_demo/main/openssl_demo_example_main.c @@ -263,7 +263,7 @@ void wifi_event_handler_cb(System_Event_t* event) switch (event->event_id) { case EVENT_STAMODE_GOT_IP: - printf("sta got ip , creat task %d\n", system_get_free_heap_size()); + printf("sta got ip , creat task %d\n", esp_get_free_heap_size()); user_conn_init(); break; @@ -280,7 +280,7 @@ void wifi_event_handler_cb(System_Event_t* event) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size()); + printf("SDK version:%s %d\n", esp_get_idf_version(), esp_get_free_heap_size()); wifi_set_opmode(STATION_MODE); { diff --git a/examples/protocols/openssl_server/main/openssl_server_example_main.c b/examples/protocols/openssl_server/main/openssl_server_example_main.c index 9e526592..9de6c3a2 100644 --- a/examples/protocols/openssl_server/main/openssl_server_example_main.c +++ b/examples/protocols/openssl_server/main/openssl_server_example_main.c @@ -347,7 +347,7 @@ void wifi_event_handler_cb(System_Event_t* event) switch (event->event_id) { case EVENT_STAMODE_GOT_IP: - printf("sta got ip , creat task %d\n", system_get_free_heap_size()); + printf("sta got ip , creat task %d\n", esp_get_free_heap_size()); user_conn_init(); break; @@ -364,7 +364,7 @@ void wifi_event_handler_cb(System_Event_t* event) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size()); + printf("SDK version:%s %d\n", esp_get_idf_version(), esp_get_free_heap_size()); wifi_set_opmode(STATION_MODE); { diff --git a/examples/storage/spiffs_test/main/testrunner.h b/examples/storage/spiffs_test/main/testrunner.h index ed965687..3361c735 100644 --- a/examples/storage/spiffs_test/main/testrunner.h +++ b/examples/storage/spiffs_test/main/testrunner.h @@ -75,17 +75,17 @@ typedef struct test_res_s { } test_res; #define MALLOC_CHECK(x, y) if (!(x)) { \ - printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, system_get_free_heap_size()); \ + printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, esp_get_free_heap_size()); \ goto __fail_stop; \ } #define MALLOC_CHECK_RETURN(x, y) if (!(x)) { \ - printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, system_get_free_heap_size()); \ + printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, esp_get_free_heap_size()); \ return; \ } #define MALLOC_CHECK_RETURN_1(x, y) if (!(x)) { \ - printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, system_get_free_heap_size()); \ + printf(" MALLOC %i FAIL %s:%i, FREE %i\n", y, __FILE__, __LINE__, esp_get_free_heap_size()); \ return -1; \ } diff --git a/examples/wifi/smart_config/main/user_main.c b/examples/wifi/smart_config/main/user_main.c index 8dfcbee3..1e854708 100644 --- a/examples/wifi/smart_config/main/user_main.c +++ b/examples/wifi/smart_config/main/user_main.c @@ -257,7 +257,7 @@ uint32_t user_rf_cal_sector_set(void) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s\n", system_get_sdk_version()); + printf("SDK version:%s\n", esp_get_idf_version()); /* need to set opmode before you set config */ wifi_set_opmode(STATION_MODE); diff --git a/examples/wifi/wifi_station_machine/main/wifi_state_machine.c b/examples/wifi/wifi_station_machine/main/wifi_state_machine.c index c82df024..fb87d91c 100644 --- a/examples/wifi/wifi_station_machine/main/wifi_state_machine.c +++ b/examples/wifi/wifi_station_machine/main/wifi_state_machine.c @@ -378,7 +378,7 @@ static void on_wifi_disconnect(uint8_t reason) *******************************************************************************/ void user_init(void) { - printf("SDK version:%s\n", system_get_sdk_version()); + printf("SDK version:%s\n", esp_get_idf_version()); set_on_station_connect(on_wifi_connect); set_on_station_disconnect(on_wifi_disconnect);