Unverified Commit 8b84445a authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2391 from nodemcu/dev

Next master snap
parents 67027c0d 2cc195d5
...@@ -46,8 +46,6 @@ SUBDIRS= \ ...@@ -46,8 +46,6 @@ SUBDIRS= \
fatfs \ fatfs \
esp-gdbstub \ esp-gdbstub \
websocket \ websocket \
swTimer \
misc \
pm \ pm \
sjson \ sjson \
sqlite3 \ sqlite3 \
...@@ -102,8 +100,6 @@ COMPONENTS_eagle.app.v6 = \ ...@@ -102,8 +100,6 @@ COMPONENTS_eagle.app.v6 = \
net/libnodemcu_net.a \ net/libnodemcu_net.a \
mbedtls/libmbedtls.a \ mbedtls/libmbedtls.a \
modules/libmodules.a \ modules/libmodules.a \
swTimer/libswtimer.a \
misc/libmisc.a \
sjson/libsjson.a \ sjson/libsjson.a \
sqlite3/libsqlite3.a \ sqlite3/libsqlite3.a \
......
#include "node.h" #include "node.h"
#include "coap_timer.h" #include "coap_timer.h"
#include "os_type.h" #include "os_type.h"
#include "pm/swtimer.h"
static os_timer_t coap_timer; static os_timer_t coap_timer;
static coap_tick_t basetime = 0; static coap_tick_t basetime = 0;
...@@ -48,6 +49,8 @@ void coap_timer_tick(void *arg){ ...@@ -48,6 +49,8 @@ void coap_timer_tick(void *arg){
void coap_timer_setup(coap_queue_t ** queue, coap_tick_t t){ void coap_timer_setup(coap_queue_t ** queue, coap_tick_t t){
os_timer_disarm(&coap_timer); os_timer_disarm(&coap_timer);
os_timer_setfn(&coap_timer, (os_timer_func_t *)coap_timer_tick, queue); os_timer_setfn(&coap_timer, (os_timer_func_t *)coap_timer_tick, queue);
SWTIMER_REG_CB(coap_timer_tick, SWTIMER_RESUME);
//coap_timer_tick processes a queue, my guess is that it is ok to resume the timer from where it left off
os_timer_arm(&coap_timer, t, 0); // no repeat os_timer_arm(&coap_timer, t, 0); // no repeat
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "mem.h" #include "mem.h"
#include "gpio.h" #include "gpio.h"
#include "user_interface.h" #include "user_interface.h"
#include "pm/swtimer.h"
#include "driver/key.h" #include "driver/key.h"
...@@ -148,6 +149,8 @@ key_intr_handler(void *arg) ...@@ -148,6 +149,8 @@ key_intr_handler(void *arg)
// 5s, restart & enter softap mode // 5s, restart & enter softap mode
os_timer_disarm(&keys->single_key[i]->key_5s); os_timer_disarm(&keys->single_key[i]->key_5s);
os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]); os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]);
SWTIMER_REG_CB(key_5s_cb, SWTIMER_DROP);
// key_5s_cb checks the state of a gpio. After resume, gpio state would be invalid
os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0); os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0);
keys->single_key[i]->key_level = 0; keys->single_key[i]->key_level = 0;
gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE); gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE);
...@@ -155,6 +158,8 @@ key_intr_handler(void *arg) ...@@ -155,6 +158,8 @@ key_intr_handler(void *arg)
// 50ms, check if this is a real key up // 50ms, check if this is a real key up
os_timer_disarm(&keys->single_key[i]->key_50ms); os_timer_disarm(&keys->single_key[i]->key_50ms);
os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]); os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]);
SWTIMER_REG_CB(key_50ms_cb, SWTIMER_DROP);
// key_50ms_cb checks the state of a gpio. After resume, gpio state would be invalid
os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0); os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0);
} }
} }
......
...@@ -527,6 +527,7 @@ void spi_slave_init(uint8 spi_no) ...@@ -527,6 +527,7 @@ void spi_slave_init(uint8 spi_no)
#ifdef SPI_SLAVE_DEBUG #ifdef SPI_SLAVE_DEBUG
#include "pm/swtimer.h"
/****************************************************************************** /******************************************************************************
* FunctionName : hspi_master_readwrite_repeat * FunctionName : hspi_master_readwrite_repeat
* Description : SPI master test function for reading and writing esp8266 slave buffer, * Description : SPI master test function for reading and writing esp8266 slave buffer,
...@@ -545,6 +546,8 @@ void hspi_master_readwrite_repeat(void) ...@@ -545,6 +546,8 @@ void hspi_master_readwrite_repeat(void)
temp++; temp++;
spi_byte_write_espslave(SPI_HSPI,temp); spi_byte_write_espslave(SPI_HSPI,temp);
os_timer_setfn(&timer2, (os_timer_func_t *)hspi_master_readwrite_repeat, NULL); os_timer_setfn(&timer2, (os_timer_func_t *)hspi_master_readwrite_repeat, NULL);
SWTIMER_REGISTER_CB_PTR(hspi_master_readwrite_repeat, SWTIMER_RESUME);
//hspi_master_readwrite_repeat timer will be resumed on wake up, maybe data will still be in buffer?
os_timer_arm(&timer2, 500, 0); os_timer_arm(&timer2, 500, 0);
} }
#endif #endif
......
...@@ -323,11 +323,14 @@ uart_autobaud_timeout(void *timer_arg) ...@@ -323,11 +323,14 @@ uart_autobaud_timeout(void *timer_arg)
uart_div_modify(uart_no, divisor); uart_div_modify(uart_no, divisor);
} }
} }
#include "pm/swtimer.h"
static void static void
uart_init_autobaud(uint32_t uart_no) uart_init_autobaud(uint32_t uart_no)
{ {
os_timer_setfn(&autobaud_timer, uart_autobaud_timeout, (void *) uart_no); os_timer_setfn(&autobaud_timer, uart_autobaud_timeout, (void *) uart_no);
SWTIMER_REG_CB(uart_autobaud_timeout, SWTIMER_DROP);
//if autobaud hasn't done it's thing by the time light sleep triggered, it probably isn't going to happen.
os_timer_arm(&autobaud_timer, 100, TRUE); os_timer_arm(&autobaud_timer, 100, TRUE);
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "limits.h" #include "limits.h"
#include "httpclient.h" #include "httpclient.h"
#include "stdlib.h" #include "stdlib.h"
#include "pm/swtimer.h"
#define REDIRECTION_FOLLOW_MAX 20 #define REDIRECTION_FOLLOW_MAX 20
...@@ -525,6 +526,8 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_ ...@@ -525,6 +526,8 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
/* Set connection timeout timer */ /* Set connection timeout timer */
os_timer_disarm( &(req->timeout_timer) ); os_timer_disarm( &(req->timeout_timer) );
os_timer_setfn( &(req->timeout_timer), (os_timer_func_t *) http_timeout_callback, conn ); os_timer_setfn( &(req->timeout_timer), (os_timer_func_t *) http_timeout_callback, conn );
SWTIMER_REG_CB(http_timeout_callback, SWTIMER_IMMEDIATE);
//http_timeout_callback frees memory used by this function and timer cannot be dropped
os_timer_arm( &(req->timeout_timer), req->timeout, false ); os_timer_arm( &(req->timeout_timer), req->timeout, false );
#ifdef CLIENT_SSL_ENABLE #ifdef CLIENT_SSL_ENABLE
......
#ifndef __DYNARR_H__
#define __DYNARR_H__
#include "user_interface.h"
#include "c_stdio.h"
#include "c_stdlib.h"
//#define DYNARR_DEBUG
//#define DYNARR_ERROR
typedef struct _dynarr{
void* data_ptr;
size_t used;
size_t array_size;
size_t data_size;
} dynarr_t;
bool dynarr_init(dynarr_t* array_ptr, size_t array_size, size_t data_size);
bool dynarr_resize(dynarr_t* array_ptr, size_t elements_to_add);
bool dynarr_remove(dynarr_t* array_ptr, void* element_ptr);
bool dynarr_add(dynarr_t* array_ptr, void* data_ptr, size_t data_size);
bool dynarr_boundaryCheck(dynarr_t* array_ptr, void* element_ptr);
bool dynarr_free(dynarr_t* array_ptr);
#if 0 || defined(DYNARR_DEBUG) || defined(NODE_DEBUG)
#define DYNARR_DBG(fmt, ...) c_printf("\n DYNARR_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__)
#else
#define DYNARR_DBG(...)
#endif
#if 0 || defined(DYNARR_ERROR) || defined(NODE_ERROR)
#define DYNARR_ERR(fmt, ...) c_printf("\n DYNARR: "fmt"\n", ##__VA_ARGS__)
#else
#define DYNARR_ERR(...)
#endif
#endif // __DYNARR_H__
/*
* swtimer.h
*
* Created on: Aug 4, 2017
* Author: anonymous
*/
#ifndef APP_INCLUDE_PM_SWTIMER_H_
#define APP_INCLUDE_PM_SWTIMER_H_
void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy);
#define SWTIMER_RESUME 0 //save remaining time
#define SWTIMER_RESTART 1 //use timer_period as remaining time
#define SWTIMER_IMMEDIATE 2 //fire timer immediately after resume
#define SWTIMER_DROP 3 //disarm timer, do not resume
#if defined(TIMER_SUSPEND_ENABLE)
#define SWTIMER_REG_CB(cb_ptr, suspend_policy) do{ \
static bool cb_ptr##_registered_flag;\
if(!cb_ptr##_registered_flag){ \
cb_ptr##_registered_flag = true; \
swtmr_cb_register(cb_ptr, suspend_policy);\
} \
}while(0);
#else
#define SWTIMER_REG_CB(...)
#endif
#endif /* APP_INCLUDE_PM_SWTIMER_H_ */
...@@ -689,11 +689,15 @@ static inline void rtc_time_switch_to_system_clock(void) ...@@ -689,11 +689,15 @@ static inline void rtc_time_switch_to_system_clock(void)
static inline void rtc_time_tmrfn(void* arg); static inline void rtc_time_tmrfn(void* arg);
#include "pm/swtimer.h"
static void rtc_time_install_timer(void) static void rtc_time_install_timer(void)
{ {
static ETSTimer tmr; static ETSTimer tmr;
os_timer_setfn(&tmr,rtc_time_tmrfn,NULL); os_timer_setfn(&tmr,rtc_time_tmrfn,NULL);
SWTIMER_REG_CB(rtc_time_tmrfn, SWTIMER_RESUME);
//I believe the function rtc_time_tmrfn compensates for drift in the clock and updates rtc time accordingly, This timer should probably be resumed
os_timer_arm(&tmr,10000,1); os_timer_arm(&tmr,10000,1);
} }
......
#ifndef __SW_TIMER_H__
#define __SW_TIMER_H__
#include "user_interface.h"
//#define SWTMR_DEBUG
#define USE_SWTMR_ERROR_STRINGS
#if defined(DEVELOP_VERSION)
#define SWTMR_DEBUG
#endif
#if defined(SWTMR_DEBUG)
#define SWTMR_DBG(fmt, ...) dbg_printf("\tSWTIMER(%s):"fmt"\n", __FUNCTION__, ##__VA_ARGS__)
#else
#define SWTMR_DBG(...)
#endif
#if defined(NODE_ERROR)
#define SWTMR_ERR(fmt, ...) NODE_ERR("%s"fmt"\n", "SWTIMER:", ##__VA_ARGS__)
#else
#define SWTMR_ERR(...)
#endif
enum SWTMR_STATUS{
SWTMR_FAIL = 0,
SWTMR_OK = 1,
SWTMR_MALLOC_FAIL = 10,
SWTMR_TIMER_NOT_ARMED,
// SWTMR_NULL_PTR,
SWTMR_REGISTRY_NO_REGISTERED_TIMERS,
// SWTMR_SUSPEND_ARRAY_INITIALIZATION_FAILED,
// SWTMR_SUSPEND_ARRAY_ADD_FAILED,
// SWTMR_SUSPEND_ARRAY_REMOVE_FAILED,
SWTMR_SUSPEND_TIMER_ALREADY_SUSPENDED,
SWTMR_SUSPEND_TIMER_ALREADY_REARMED,
SWTMR_SUSPEND_NO_SUSPENDED_TIMERS,
SWTMR_SUSPEND_TIMER_NOT_SUSPENDED,
};
/* Global Function Declarations */
void swtmr_register(void* timer_ptr);
void swtmr_unregister(void* timer_ptr);
int swtmr_suspend(os_timer_t* timer_ptr);
int swtmr_resume(os_timer_t* timer_ptr);
void swtmr_print_registry(void);
void swtmr_print_suspended(void);
void swtmr_print_timer_list(void);
const char* swtmr_errorcode2str(int error_value);
bool swtmr_suspended_test(os_timer_t* timer_ptr);
#endif // __SW_TIMER_H__
...@@ -52,7 +52,9 @@ extern void luaL_assertfail(const char *file, int line, const char *message); ...@@ -52,7 +52,9 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) #define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
#define ICACHE_STORE_ATTR __attribute__((aligned(4))) #define ICACHE_STORE_ATTR __attribute__((aligned(4)))
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text"))) #define ICACHE_RAM_STRING(x) ICACHE_RAM_STRING2(x)
#define ICACHE_RAM_STRING2(x) #x
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text." __FILE__ "." ICACHE_RAM_STRING(__LINE__))))
#ifdef GPIO_SAFE_NO_INTR_ENABLE #ifdef GPIO_SAFE_NO_INTR_ENABLE
#define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline)) #define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
#else #else
...@@ -114,8 +116,8 @@ extern void luaL_assertfail(const char *file, int line, const char *message); ...@@ -114,8 +116,8 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define WIFI_SDK_EVENT_MONITOR_ENABLE #define WIFI_SDK_EVENT_MONITOR_ENABLE
#define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
////#define ENABLE_TIMER_SUSPEND //#define PMSLEEP_ENABLE // Enable wifi.suspend() and node.sleep() (NOTE: node.sleep() is dependent on TIMER_SUSPEND_ENABLE)
//#define PMSLEEP_ENABLE //#define TIMER_SUSPEND_ENABLE //Required by node.sleep()
#define STRBUF_DEFAULT_INCREMENT 32 #define STRBUF_DEFAULT_INCREMENT 32
......
...@@ -86,5 +86,9 @@ ...@@ -86,5 +86,9 @@
//#define LUA_USE_MODULES_WS2812_EFFECTS //#define LUA_USE_MODULES_WS2812_EFFECTS
//#define LUA_USE_MODULES_XPT2046 //#define LUA_USE_MODULES_XPT2046
//debug modules
//#define LUA_USE_MODULES_SWTMR_DBG //SWTMR timer suspend Debug functions
#endif /* LUA_CROSS_COMPILER */ #endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */ #endif /* __USER_MODULES_H__ */
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include C_HEADER_STRING #include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
#include "vfs.h" #include "vfs.h"
#include "user_interface.h"
#else #else
#endif #endif
...@@ -791,6 +792,11 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { ...@@ -791,6 +792,11 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
} }
if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */ if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */
luaC_fullgc(L); luaC_fullgc(L);
#ifndef LUA_CROSS_COMPILER
if (L != NULL && (mode & EGC_ON_MEM_LIMIT) && G(L)->memlimit < 0 &&
(system_get_free_heap_size() < (-G(L)->memlimit)))
luaC_fullgc(L);
#endif
if(nsize > osize && L != NULL) { if(nsize > osize && L != NULL) {
#if defined(LUA_STRESS_EMERGENCY_GC) #if defined(LUA_STRESS_EMERGENCY_GC)
luaC_fullgc(L); luaC_fullgc(L);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "lstate.h" #include "lstate.h"
#include "c_types.h" #include "c_types.h"
void legc_set_mode(lua_State *L, int mode, unsigned limit) { void legc_set_mode(lua_State *L, int mode, int limit) {
global_State *g = G(L); global_State *g = G(L);
g->egcmode = mode; g->egcmode = mode;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit
#define EGC_ALWAYS 4 // always run EGC before an allocation #define EGC_ALWAYS 4 // always run EGC before an allocation
void legc_set_mode(lua_State *L, int mode, unsigned limit); void legc_set_mode(lua_State *L, int mode, int limit);
#endif #endif
...@@ -82,7 +82,7 @@ typedef struct global_State { ...@@ -82,7 +82,7 @@ typedef struct global_State {
Mbuffer buff; /* temporary buffer for string concatentation */ Mbuffer buff; /* temporary buffer for string concatentation */
lu_mem GCthreshold; lu_mem GCthreshold;
lu_mem totalbytes; /* number of bytes currently allocated */ lu_mem totalbytes; /* number of bytes currently allocated */
lu_mem memlimit; /* maximum number of bytes that can be allocated, 0 = no limit. */ l_mem memlimit; /* maximum number of bytes that can be allocated, 0 = no limit. <0 used with EGC_ON_MEM_LIMIT when free heap falls below -memlimit */
lu_mem estimate; /* an estimate of number of bytes actually in use */ lu_mem estimate; /* an estimate of number of bytes actually in use */
lu_mem gcdept; /* how much GC is `behind schedule' */ lu_mem gcdept; /* how much GC is `behind schedule' */
int gcpause; /* size of pause between successive GCs */ int gcpause; /* size of pause between successive GCs */
......
...@@ -434,9 +434,9 @@ espconn_Task(os_event_t *events) ...@@ -434,9 +434,9 @@ espconn_Task(os_event_t *events)
break; break;
case SIG_ESPCONN_ERRER: case SIG_ESPCONN_ERRER:
/*remove the node from the client's active connection list*/ /*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
if (espconn_manual_recv_enabled(task_msg)) if (espconn_manual_recv_enabled(task_msg))
espconn_list_delete(&plink_active, task_msg); espconn_list_delete(&plink_active, task_msg);
espconn_tcp_reconnect(task_msg);
break; break;
case SIG_ESPCONN_CLOSE: case SIG_ESPCONN_CLOSE:
/*remove the node from the client's active connection list*/ /*remove the node from the client's active connection list*/
......
...@@ -1039,6 +1039,7 @@ mdns_reg(struct mdns_info *info) { ...@@ -1039,6 +1039,7 @@ mdns_reg(struct mdns_info *info) {
os_timer_disarm(&mdns_timer); os_timer_disarm(&mdns_timer);
} }
} }
#include "pm/swtimer.h"
/** /**
* Initialize the resolver: set up the UDP pcb and configure the default server * Initialize the resolver: set up the UDP pcb and configure the default server
...@@ -1129,6 +1130,8 @@ mdns_init(struct mdns_info *info) { ...@@ -1129,6 +1130,8 @@ mdns_init(struct mdns_info *info) {
os_timer_disarm(&mdns_timer); os_timer_disarm(&mdns_timer);
os_timer_setfn(&mdns_timer, (os_timer_func_t *)mdns_reg,ms_info); os_timer_setfn(&mdns_timer, (os_timer_func_t *)mdns_reg,ms_info);
SWTIMER_REG_CB(mdns_reg, SWTIMER_RESTART);
//going on the above comment, it's probably a good idea to let mdns_reg run it's course. not sure if the 1 second timing is important, so lets restart it to be safe.
os_timer_arm(&mdns_timer, 1000, 1); os_timer_arm(&mdns_timer, 1000, 1);
} }
} }
......
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libmisc.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ./include
INCLUDES += -I ../include
INCLUDES += -I ../../include
INCLUDES += -I ../lua
INCLUDES += -I ../platform
INCLUDES += -I ../libc
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment