diff --git a/app/coap/coap.h b/app/coap/coap.h index f47123f2..dc4bb6d9 100644 --- a/app/coap/coap.h +++ b/app/coap/coap.h @@ -192,6 +192,11 @@ void coap_setup(void); void endpoint_setup(void); int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_t buflen); +int check_token(coap_packet_t *pkt); + +#include "uri.h" +int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtype_t t, coap_method_t m, coap_uri_t *uri, const uint8_t *payload, size_t payload_len); + #ifdef __cplusplus } diff --git a/app/driver/key.c b/app/driver/key.c index d05c4aca..afd7b142 100644 --- a/app/driver/key.c +++ b/app/driver/key.c @@ -17,7 +17,7 @@ #include "driver/key.h" -LOCAL void key_intr_handler(struct keys_param *keys); +LOCAL void ICACHE_RAM_ATTR key_intr_handler(void *arg); /****************************************************************************** * FunctionName : key_init_single @@ -130,8 +130,9 @@ key_50ms_cb(struct single_key_param *single_key) * Returns : none *******************************************************************************/ LOCAL void -key_intr_handler(struct keys_param *keys) +key_intr_handler(void *arg) { + struct keys_param *keys = arg; uint8 i; uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); diff --git a/app/driver/pwm.c b/app/driver/pwm.c index c34f1437..07469dd9 100644 --- a/app/driver/pwm.c +++ b/app/driver/pwm.c @@ -306,8 +306,9 @@ pwm_get_freq(uint8 channel) * Returns : NONE *******************************************************************************/ LOCAL void ICACHE_RAM_ATTR -pwm_tim1_intr_handler(void) +pwm_tim1_intr_handler(void *p) { + (void)p; uint8 local_toggle = pwm_toggle; // pwm_toggle may change outside RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK); diff --git a/app/include/driver/spi.h b/app/include/driver/spi.h index bb8e0314..04ae1fe6 100644 --- a/app/include/driver/spi.h +++ b/app/include/driver/spi.h @@ -2,7 +2,7 @@ #define SPI_APP_H #include "spi_register.h" -#include "ets_sys.h" +#include "rom.h" #include "osapi.h" #include "uart.h" #include "os_type.h" diff --git a/app/include/rom.h b/app/include/rom.h index ba48fcb7..5b8641dd 100644 --- a/app/include/rom.h +++ b/app/include/rom.h @@ -4,6 +4,7 @@ #define _ROM_H_ #include "c_types.h" +#include "ets_sys.h" // SHA1 is assumed to match the netbsd sha1.h headers #define SHA1_DIGEST_LENGTH 20 @@ -44,7 +45,7 @@ extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_ extern void mem_init(void * start_addr); // Interrupt Service Routine functions -typedef void (*ets_isr_fn) (void *arg, uint32_t sp); +typedef void (*ets_isr_fn) (void *arg); extern int ets_isr_attach (unsigned int interrupt, ets_isr_fn, void *arg); extern void ets_isr_mask (unsigned intr); extern void ets_isr_unmask (unsigned intr); @@ -108,4 +109,35 @@ typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause */ exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler); + +void ets_update_cpu_frequency (uint32_t mhz); +uint32_t ets_get_cpu_frequency (void); + +void *ets_memcpy (void *dst, const void *src, size_t n); +void *ets_memmove (void *dst, const void *src, size_t n); +void *ets_memset (void *dst, int c, size_t n); +int ets_memcmp (const void *s1, const void *s2, size_t n); + +char *ets_strcpy (char *dst, const char *src); +size_t ets_strlen (const char *s); +int ets_strcmp (const char *s1, const char *s2); +int ets_strncmp (const char *s1, const char *s2, size_t n); + +void ets_delay_us (uint32_t us); + +int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); + +int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); + +void ets_str2macaddr (uint8_t *dst, const char *str); + +void ets_timer_disarm (ETSTimer *a); +void ets_timer_setfn (ETSTimer *t, ETSTimerFunc *fn, void *parg); + +void Cache_Read_Enable(uint32_t b0, uint32_t b1, uint32_t use_40108000); +void Cache_Read_Disable(void); + +void ets_intr_lock(void); +void ets_intr_unlock(void); + #endif diff --git a/app/include/rtc/rtctime_internal.h b/app/include/rtc/rtctime_internal.h index 0c9a3a5a..c8b2ce90 100644 --- a/app/include/rtc/rtctime_internal.h +++ b/app/include/rtc/rtctime_internal.h @@ -126,6 +126,7 @@ #include #include "rom.h" #include "rtcaccess.h" +#include "user_interface.h" // Layout of the RTC storage space: // diff --git a/app/libc/c_stdio.c b/app/libc/c_stdio.c index a8e0956f..e52f2ffc 100644 --- a/app/libc/c_stdio.c +++ b/app/libc/c_stdio.c @@ -272,7 +272,6 @@ strtoupper(char *p) //#include //#include #include "c_string.h" -typedef int int32_t; typedef unsigned int u_int32_t; typedef unsigned int u_int; typedef unsigned long u_long; diff --git a/app/modules/Makefile b/app/modules/Makefile index 48b26103..848c3834 100644 --- a/app/modules/Makefile +++ b/app/modules/Makefile @@ -15,6 +15,8 @@ ifndef PDIR GEN_LIBS = libmodules.a endif +EXTRA_CCFLAGS+=-std=gnu11 + ############################################################# # Configuration i.e. compile options etc. # Target specific stuff (defines etc.) goes in here! diff --git a/app/modules/cjson.c b/app/modules/cjson.c index b611c05f..ec769e04 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -43,6 +43,7 @@ #include "c_limits.h" #include "lauxlib.h" #include "flash_api.h" +#include "ctype.h" #include "strbuf.h" #include "cjson_mem.h" diff --git a/app/modules/coap.c b/app/modules/coap.c index 2b6efb9e..cac6268e 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -372,7 +372,7 @@ static int coap_request( lua_State* L, coap_method_t m ) if(!pdu){ if(uri) c_free(uri); - return; + return luaL_error (L, "alloc fail"); } const char *payload = NULL; diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index 067c9535..84a84009 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -36,11 +36,11 @@ #include "platform.h" #include "c_stdlib.h" #include "c_string.h" +#include "ctype.h" #include "user_interface.h" #include "espconn.h" #include "flash_fs.h" - #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define ENDUSER_SETUP_ERR_FATAL (1 << 0) @@ -96,7 +96,7 @@ static void enduser_setup_station_start(void); static void enduser_setup_station_start(void); static void enduser_setup_ap_start(void); static void enduser_setup_ap_stop(void); -static void enduser_setup_check_station(void); +static void enduser_setup_check_station(void *p); static void enduser_setup_debug(lua_State *L, const char *str); @@ -177,8 +177,9 @@ static void enduser_setup_check_station_stop(void) * * Check that we've successfully entered station mode. */ -static void enduser_setup_check_station(void) +static void enduser_setup_check_station(void *p) { + (void)p; struct ip_info ip; c_memset(&ip, 0, sizeof(struct ip_info)); @@ -391,7 +392,7 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data err = wifi_station_disconnect(); if (err == FALSE) { - ENDUSER_SETUP_ERROR_VOID("enduser_setup_station_start failed. wifi_station_disconnect failed.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); + ENDUSER_SETUP_ERROR("enduser_setup_station_start failed. wifi_station_disconnect failed.", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_NONFATAL); } err = wifi_station_connect(); if (err == FALSE) diff --git a/app/modules/gpio.c b/app/modules/gpio.c index d779a903..d4c189ed 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -3,6 +3,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" +#include "rom.h" #include "c_types.h" #include "c_string.h" diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 2dde4de6..78a41f18 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -15,6 +15,8 @@ #include "mqtt_msg.h" #include "msg_queue.h" +#include "user_interface.h" + #define MQTT_BUF_SIZE 1024 #define MQTT_DEFAULT_KEEPALIVE 60 #define MQTT_MAX_CLIENT_LEN 64 @@ -831,7 +833,7 @@ static void socket_connect(struct espconn *pesp_conn) } static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg); -static dns_reconn_count = 0; +static int dns_reconn_count = 0; static ip_addr_t host_ip; // for dns static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { diff --git a/app/modules/net.c b/app/modules/net.c index f0eee3b6..516ccab9 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -610,7 +610,7 @@ static void socket_connect(struct espconn *pesp_conn) } static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg); -static dns_reconn_count = 0; +static int dns_reconn_count = 0; static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { NODE_DBG("socket_dns_found is called.\n"); diff --git a/app/modules/node.c b/app/modules/node.c index 26b63760..bfdf0a37 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -25,6 +25,7 @@ #include "flash_api.h" #include "flash_fs.h" #include "user_version.h" +#include "rom.h" #define CPU80MHZ 80 #define CPU160MHZ 160 @@ -49,7 +50,7 @@ static int node_deepsleep( lua_State* L ) if ( option < 0 || option > 4) return luaL_error( L, "wrong arg range" ); else - deep_sleep_set_option( option ); + system_deep_sleep_set_option( option ); } // Set deleep time, skip if nil if ( lua_isnumber(L, 1) ) diff --git a/app/modules/rc.c b/app/modules/rc.c index d8301743..72c0dff4 100644 --- a/app/modules/rc.c +++ b/app/modules/rc.c @@ -1,6 +1,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" +#include "rom.h" //#include "driver/easygpio.h" //static Ping_Data pingA; #define defPulseLen 185 diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index 76ca4392..9d3d0a6e 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -87,7 +87,7 @@ static void do_sleep_opt (lua_State *L, int idx) uint32_t opt = lua_tonumber (L, idx); if (opt < 0 || opt > 4) luaL_error (L, "unknown sleep option"); - deep_sleep_set_option (opt); + system_deep_sleep_set_option (opt); } } diff --git a/app/modules/tmr.c b/app/modules/tmr.c index 2a3dc724..c88af871 100755 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -59,20 +59,6 @@ tmr.softwd(int) #define TIMER_MODE_AUTO 1 #define TIMER_IDLE_FLAG (1<<7) -//well, the following are my assumptions -//why, oh why is there no good documentation -//chinese companies should learn from Atmel -extern void ets_timer_arm_new(os_timer_t* t, uint32_t milliseconds, uint32_t repeat_flag, uint32_t isMstimer); -extern void ets_timer_disarm(os_timer_t* t); -extern void ets_timer_setfn(os_timer_t* t, os_timer_func_t *f, void *arg); -extern void ets_delay_us(uint32_t us); -extern uint32_t system_get_time(); -extern uint32_t platform_tmr_exists(uint32_t t); -extern uint32_t system_rtc_clock_cali_proc(); -extern uint32_t system_get_rtc_time(); -extern void system_restart(); -extern void system_soft_wdt_feed(); - //in fact lua_State is constant, it's pointless to pass it around //but hey, whatever, I'll just pass it, still we waste 28B here typedef struct{ diff --git a/app/modules/uart.c b/app/modules/uart.c index 406737db..857d7137 100755 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -6,6 +6,7 @@ #include "c_types.h" #include "c_string.h" +#include "rom.h" static lua_State *gL = NULL; static int uart_receive_rf = LUA_NOREF; diff --git a/app/modules/wifi.c b/app/modules/wifi.c index af8c5bfd..e0c99857 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -6,6 +6,7 @@ #include "c_string.h" #include "c_stdlib.h" +#include "ctype.h" #include "c_types.h" #include "user_interface.h" @@ -22,7 +23,7 @@ static bool FLAG_wifi_force_sleep_enabled=0; //variables for wifi event monitor static sint32_t wifi_status_cb_ref[6] = {LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF}; -static volatile os_timer_t wifi_sta_status_timer; +static os_timer_t wifi_sta_status_timer; static uint8 prev_wifi_status=0; diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index 26b56211..e135c195 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -43,7 +43,7 @@ static void ws2801_strip(uint8_t const * data, uint16_t len) { GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, ws2801_bit_data); } -static void enable_pin_mux(pin) { +static void enable_pin_mux(int pin) { // The API only supports setting PERIPHS_IO_MUX on GPIO 0, 2, 4, 5 switch (pin) { case 0: diff --git a/app/platform/platform.c b/app/platform/platform.c index 35f30318..5a3eed7d 100755 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -131,7 +131,8 @@ int platform_gpio_read( unsigned pin ) } #ifdef GPIO_INTERRUPT_ENABLE -static void platform_gpio_intr_dispatcher( platform_gpio_intr_handler_fn_t cb){ +static void platform_gpio_intr_dispatcher( void *arg) { + platform_gpio_intr_handler_fn_t cb = arg; uint8 i, level; uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); for (i = 0; i < GPIO_PIN_NUM; i++) { diff --git a/app/platform/platform.h b/app/platform/platform.h index 24cb3317..0669ff9d 100644 --- a/app/platform/platform.h +++ b/app/platform/platform.h @@ -149,6 +149,7 @@ int platform_uart_recv( unsigned id, unsigned timer_id, timer_data_type timeout int platform_s_uart_recv( unsigned id, timer_data_type timeout ); int platform_uart_set_flow_control( unsigned id, int type ); int platform_s_uart_set_flow_control( unsigned id, int type ); +void platform_uart_alt( int set ); // ***************************************************************************** // PWM subsection @@ -253,6 +254,13 @@ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr); void* platform_get_first_free_ram( unsigned id ); void* platform_get_last_free_ram( unsigned id ); + +// ***************************************************************************** +// Other glue + +int platform_ow_exists( unsigned id ); +int platform_gpio_exists( unsigned id ); + // ***************************************************************************** // Helper macros #define MOD_CHECK_ID( mod, id )\ diff --git a/app/smart/smart.c b/app/smart/smart.c index c362191a..2b7a906c 100644 --- a/app/smart/smart.c +++ b/app/smart/smart.c @@ -499,7 +499,7 @@ void smart_end(){ wifi_station_connect(); os_timer_disarm(&smart_timer); - os_timer_setfn(&smart_timer, (os_timer_func_t *)station_check_connect, 1); + os_timer_setfn(&smart_timer, (os_timer_func_t *)station_check_connect, (void *)1); os_timer_arm(&smart_timer, STATION_CHECK_TIME, 0); // no repeat } } @@ -716,6 +716,6 @@ void station_check_connect(bool smart){ break; } os_timer_disarm(&smart_timer); - os_timer_setfn(&smart_timer, (os_timer_func_t *)station_check_connect, smart); + os_timer_setfn(&smart_timer, (os_timer_func_t *)station_check_connect, (void *)(int)smart); os_timer_arm(&smart_timer, STATION_CHECK_TIME, 0); // no repeat } diff --git a/app/spiffs/spiffs.h b/app/spiffs/spiffs.h index e1e76d81..eecb8139 100644 --- a/app/spiffs/spiffs.h +++ b/app/spiffs/spiffs.h @@ -571,6 +571,7 @@ void myspiffs_clearerr( int fd ); int myspiffs_check( void ); int myspiffs_rename( const char *old, const char *newname ); size_t myspiffs_size( int fd ); +int myspiffs_format (void); s32_t SPIFFS_eof(spiffs *fs, spiffs_file fh); s32_t SPIFFS_tell(spiffs *fs, spiffs_file fh); diff --git a/sdk-overrides/include/mem.h b/sdk-overrides/include/mem.h new file mode 100644 index 00000000..1a2f91ec --- /dev/null +++ b/sdk-overrides/include/mem.h @@ -0,0 +1,11 @@ +#ifndef _SDK_OVERRIDE_MEM_H_ +#define _SDK_OVERRIDE_MEM_H_ + +void *pvPortMalloc (size_t sz, const char *, unsigned); +void vPortFree (void *p, const char *, unsigned); +void *pvPortZalloc (size_t sz, const char *, unsigned); +void *pvPortRealloc (void *p, size_t n, const char *, unsigned); + +#include_next "mem.h" + +#endif diff --git a/sdk-overrides/include/osapi.h b/sdk-overrides/include/osapi.h new file mode 100644 index 00000000..96b836cc --- /dev/null +++ b/sdk-overrides/include/osapi.h @@ -0,0 +1,9 @@ +#ifndef _SDK_OVERRIDE_OSAPI_H_ +#define _SDK_OVERRIDE_OSAPI_H_ + +#include "rom.h" +void ets_timer_arm_new (ETSTimer *a, int b, int c, int isMstimer); + +#include_next "osapi.h" + +#endif