feat(esp8266): Modify old system APIs to new ones

This commit is contained in:
Dong Heng
2018-06-25 16:30:38 +08:00
parent c5b9f8ed9d
commit bf0b8c8bb6
17 changed files with 40 additions and 36 deletions

View File

@ -34,8 +34,6 @@
extern "C" { extern "C" {
#endif #endif
uint32_t os_random(void);
int32_t os_get_random(unsigned char *buf, size_t len); int32_t os_get_random(unsigned char *buf, size_t len);
/** /**

View File

@ -245,7 +245,7 @@ static uint32_t queue_msg_waiting_wrapper(void *queue)
static uint32_t get_free_heap_size_wrapper(void) 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)) 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) static int32_t rand_wrapper(void)
{ {
return (int32_t)os_random(); return (int32_t)esp_random();
} }
wifi_osi_funcs_t s_wifi_osi_funcs = { wifi_osi_funcs_t s_wifi_osi_funcs = {

View File

@ -48,6 +48,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include "esp_libc.h" #include "esp_libc.h"
#include "esp_system.h"
//#define SOCKETS_MT //#define SOCKETS_MT
@ -117,7 +118,7 @@
*/ */
#define SMEMCPY(dst,src,len) memcpy(dst,src,len) #define SMEMCPY(dst,src,len) memcpy(dst,src,len)
#define LWIP_RAND os_random #define LWIP_RAND esp_random
/** /**
* @} * @}

View File

@ -21,6 +21,8 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
extern uint32_t esp_get_time();
static uint64_t s_boot_time; static uint64_t s_boot_time;
static os_timer_t microsecond_overflow_timer; 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) static void microsecond_overflow_tick(void* arg)
{ {
uint32_t m = system_get_time(); uint32_t m = esp_get_time();
vPortEnterCritical(); vPortEnterCritical();
@ -84,7 +86,7 @@ static uint64_t get_time_since_boot()
uint32_t c; uint32_t c;
uint64_t microseconds; uint64_t microseconds;
m = system_get_time(); m = esp_get_time();
vPortEnterCritical(); vPortEnterCritical();

View File

@ -122,6 +122,7 @@ typedef struct {
} spi_cmd_t; } spi_cmd_t;
extern bool spi_flash_erase_sector_check(uint32_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 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); 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; 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); FLASH_INTR_LOCK(c_tmp);
pp_soft_wdt_stop(); pp_soft_wdt_stop();
@ -437,7 +438,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_sector(size_t sec)
pp_soft_wdt_restart(); pp_soft_wdt_restart();
FLASH_INTR_UNLOCK(c_tmp); FLASH_INTR_UNLOCK(c_tmp);
spi_debug("%d\n", system_get_time()); spi_debug("%d\n", esp_get_time());
return ret; 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 } else
tmp = (uint32_t *)src; 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); 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) if (IS_FLASH(src) || ((size_t)src) & 0x3)
wifi_free(tmp); wifi_free(tmp);
spi_debug("%d\n", system_get_time()); spi_debug("%d\n", esp_get_time());
return ret; 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; 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); 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; FlashIsOnGoing = 0;
FLASH_INTR_UNLOCK(c_tmp); FLASH_INTR_UNLOCK(c_tmp);
spi_debug("%d\n", system_get_time()); spi_debug("%d\n", esp_get_time());
return ret; return ret;
} }

View File

@ -253,7 +253,7 @@ int get_random_NZ(int num_rand_bytes, uint8_t *rand_data)
for (i = 0; i < num_rand_bytes; i++) for (i = 0; i < num_rand_bytes; i++)
{ {
while (rand_data[i] == 0) /* can't be 0 */ 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; return 0;

View File

@ -213,7 +213,7 @@ EXP_FUNC void * ax_malloc(size_t s, const char* file, int line)
if ((x = malloc(s)) == NULL) if ((x = malloc(s)) == NULL)
exit_now("out of memory %s %d\n", file, line); exit_now("out of memory %s %d\n", file, line);
else { 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); //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) if ((x = realloc(y, s)) == NULL)
exit_now("out of memory %s %d\n", file, line); exit_now("out of memory %s %d\n", file, line);
else { 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); //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) if ((x = calloc(n, s)) == NULL)
exit_now("out of memory %s %d\n", file, line); exit_now("out of memory %s %d\n", file, line);
else { 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; //total_size = n * s;
//add_mem_info (x, total_size, file, line); //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) if ((x = (void*)zalloc(s)) == NULL)
exit_now("out of memory %s %d\n", file, line); exit_now("out of memory %s %d\n", file, line);
else { 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); //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) EXP_FUNC void ax_free(void *p, const char* file, int line)
{ {
if(p) { 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); free(p);
p = NULL; p = NULL;
} }
@ -314,6 +314,7 @@ void exit_now(const char *format, ...)
/** /**
* gettimeofday() not in Win32 * gettimeofday() not in Win32
*/ */
#if 0
EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone) EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone)
{ {
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
@ -329,6 +330,7 @@ EXP_FUNC void STDCALL gettimeofday(struct timeval* t, void* timezone)
#endif #endif
} }
#endif #endif
#endif
unsigned int def_private_key_len = 0; unsigned int def_private_key_len = 0;
unsigned char *def_private_key = NULL; unsigned char *def_private_key = NULL;

View File

@ -243,7 +243,7 @@ EXP_FUNC void STDCALL ssl_ctx_free(SSL_CTX *ssl_ctx)
EXP_FUNC void STDCALL ssl_free(SSL *ssl) EXP_FUNC void STDCALL ssl_free(SSL *ssl)
{ {
SSL_CTX *ssl_ctx; 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 */ if (ssl == NULL) /* just ignore null pointers */
return; return;

View File

@ -61,8 +61,8 @@ extern void vPortFree(void *pv);
#define ssl_memcpy memcpy #define ssl_memcpy memcpy
#define ssl_strlen strlen #define ssl_strlen strlen
#define ssl_speed_up_enter() system_update_cpu_freq(SYS_CPU_160MHZ) #define ssl_speed_up_enter() rtc_clk_cpu_freq_set(RTC_CPU_FREQ_160M)
#define ssl_speed_up_exit() system_update_cpu_freq(SYS_CPU_80MHZ) #define ssl_speed_up_exit() rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M)
#define SSL_DEBUG_LOG printf #define SSL_DEBUG_LOG printf

View File

@ -71,5 +71,5 @@ uint32_t user_rf_cal_sector_set(void)
*******************************************************************************/ *******************************************************************************/
void user_init(void) void user_init(void)
{ {
printf("SDK version:%s\n", system_get_sdk_version()); printf("SDK version:%s\n", esp_get_idf_version());
} }

View File

@ -183,7 +183,7 @@ void wifi_event_handler_cb(System_Event_t* event)
switch (event->event_id) { switch (event->event_id) {
case EVENT_STAMODE_GOT_IP: 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(); user_conn_init();
break; break;
@ -208,7 +208,7 @@ void wifi_event_handler_cb(System_Event_t* event)
*******************************************************************************/ *******************************************************************************/
void user_init(void) 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); wifi_set_opmode(STATION_MODE);
{ {

View File

@ -345,7 +345,7 @@ void wifi_event_handler_cb(System_Event_t* event)
switch (event->event_id) { switch (event->event_id) {
case EVENT_STAMODE_GOT_IP: 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(); user_conn_init();
break; break;
@ -362,7 +362,7 @@ void wifi_event_handler_cb(System_Event_t* event)
*******************************************************************************/ *******************************************************************************/
void user_init(void) 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); wifi_set_opmode(STATION_MODE);
{ {

View File

@ -263,7 +263,7 @@ void wifi_event_handler_cb(System_Event_t* event)
switch (event->event_id) { switch (event->event_id) {
case EVENT_STAMODE_GOT_IP: 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(); user_conn_init();
break; break;
@ -280,7 +280,7 @@ void wifi_event_handler_cb(System_Event_t* event)
*******************************************************************************/ *******************************************************************************/
void user_init(void) 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); wifi_set_opmode(STATION_MODE);
{ {

View File

@ -347,7 +347,7 @@ void wifi_event_handler_cb(System_Event_t* event)
switch (event->event_id) { switch (event->event_id) {
case EVENT_STAMODE_GOT_IP: 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(); user_conn_init();
break; break;
@ -364,7 +364,7 @@ void wifi_event_handler_cb(System_Event_t* event)
*******************************************************************************/ *******************************************************************************/
void user_init(void) 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); wifi_set_opmode(STATION_MODE);
{ {

View File

@ -75,17 +75,17 @@ typedef struct test_res_s {
} test_res; } test_res;
#define MALLOC_CHECK(x, y) if (!(x)) { \ #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; \ goto __fail_stop; \
} }
#define MALLOC_CHECK_RETURN(x, y) if (!(x)) { \ #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; \ return; \
} }
#define MALLOC_CHECK_RETURN_1(x, y) if (!(x)) { \ #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; \ return -1; \
} }

View File

@ -257,7 +257,7 @@ uint32_t user_rf_cal_sector_set(void)
*******************************************************************************/ *******************************************************************************/
void user_init(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 */ /* need to set opmode before you set config */
wifi_set_opmode(STATION_MODE); wifi_set_opmode(STATION_MODE);

View File

@ -378,7 +378,7 @@ static void on_wifi_disconnect(uint8_t reason)
*******************************************************************************/ *******************************************************************************/
void user_init(void) 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_connect(on_wifi_connect);
set_on_station_disconnect(on_wifi_disconnect); set_on_station_disconnect(on_wifi_disconnect);