Skip to content

Commit

Permalink
Merge pull request nodemcu#2391 from nodemcu/dev
Browse files Browse the repository at this point in the history
Next master snap
  • Loading branch information
TerryE authored Jun 8, 2018
2 parents 67027c0 + 2cc195d commit 8b84445
Show file tree
Hide file tree
Showing 49 changed files with 1,097 additions and 1,451 deletions.
4 changes: 0 additions & 4 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ SUBDIRS= \
fatfs \
esp-gdbstub \
websocket \
swTimer \
misc \
pm \
sjson \
sqlite3 \
Expand Down Expand Up @@ -102,8 +100,6 @@ COMPONENTS_eagle.app.v6 = \
net/libnodemcu_net.a \
mbedtls/libmbedtls.a \
modules/libmodules.a \
swTimer/libswtimer.a \
misc/libmisc.a \
sjson/libsjson.a \
sqlite3/libsqlite3.a \

Expand Down
3 changes: 3 additions & 0 deletions app/coap/coap_timer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "node.h"
#include "coap_timer.h"
#include "os_type.h"
#include "pm/swtimer.h"

static os_timer_t coap_timer;
static coap_tick_t basetime = 0;
Expand Down Expand Up @@ -48,6 +49,8 @@ void coap_timer_tick(void *arg){
void coap_timer_setup(coap_queue_t ** queue, coap_tick_t t){
os_timer_disarm(&coap_timer);
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
}

Expand Down
5 changes: 5 additions & 0 deletions app/driver/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "mem.h"
#include "gpio.h"
#include "user_interface.h"
#include "pm/swtimer.h"

#include "driver/key.h"

Expand Down Expand Up @@ -148,13 +149,17 @@ key_intr_handler(void *arg)
// 5s, restart & enter softap mode
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]);
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);
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);
} else {
// 50ms, check if this is a real key up
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]);
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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/driver/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ void spi_slave_init(uint8 spi_no)


#ifdef SPI_SLAVE_DEBUG
#include "pm/swtimer.h"
/******************************************************************************
* FunctionName : hspi_master_readwrite_repeat
* Description : SPI master test function for reading and writing esp8266 slave buffer,
Expand All @@ -545,6 +546,8 @@ void hspi_master_readwrite_repeat(void)
temp++;
spi_byte_write_espslave(SPI_HSPI,temp);
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);
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions app/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,14 @@ uart_autobaud_timeout(void *timer_arg)
uart_div_modify(uart_no, divisor);
}
}
#include "pm/swtimer.h"

static void
uart_init_autobaud(uint32_t 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);
}

Expand Down
3 changes: 3 additions & 0 deletions app/http/httpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "limits.h"
#include "httpclient.h"
#include "stdlib.h"
#include "pm/swtimer.h"

#define REDIRECTION_FOLLOW_MAX 20

Expand Down Expand Up @@ -525,6 +526,8 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
/* Set connection timeout timer */
os_timer_disarm( &(req->timeout_timer) );
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 );

#ifdef CLIENT_SSL_ENABLE
Expand Down
40 changes: 0 additions & 40 deletions app/include/misc/dynarr.h

This file was deleted.

File renamed without changes.
30 changes: 30 additions & 0 deletions app/include/pm/swtimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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_ */
4 changes: 4 additions & 0 deletions app/include/rtc/rtctime_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,15 @@ static inline void rtc_time_switch_to_system_clock(void)

static inline void rtc_time_tmrfn(void* arg);

#include "pm/swtimer.h"

static void rtc_time_install_timer(void)
{
static ETSTimer tmr;

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);
}

Expand Down
53 changes: 0 additions & 53 deletions app/include/swTimer/swTimer.h

This file was deleted.

8 changes: 5 additions & 3 deletions app/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
#define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
#else
Expand Down Expand Up @@ -114,8 +116,8 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define WIFI_SDK_EVENT_MONITOR_ENABLE
#define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE

////#define ENABLE_TIMER_SUSPEND
//#define PMSLEEP_ENABLE
//#define PMSLEEP_ENABLE // Enable wifi.suspend() and node.sleep() (NOTE: node.sleep() is dependent on TIMER_SUSPEND_ENABLE)
//#define TIMER_SUSPEND_ENABLE //Required by node.sleep()


#define STRBUF_DEFAULT_INCREMENT 32
Expand Down
4 changes: 4 additions & 0 deletions app/include/user_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@
//#define LUA_USE_MODULES_WS2812_EFFECTS
//#define LUA_USE_MODULES_XPT2046

//debug modules
//#define LUA_USE_MODULES_SWTMR_DBG //SWTMR timer suspend Debug functions


#endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */
6 changes: 6 additions & 0 deletions app/lua/lauxlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER
#include "vfs.h"
#include "user_interface.h"
#else
#endif

Expand Down Expand Up @@ -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 */
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 defined(LUA_STRESS_EMERGENCY_GC)
luaC_fullgc(L);
Expand Down
2 changes: 1 addition & 1 deletion app/lua/legc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "lstate.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);

g->egcmode = mode;
Expand Down
2 changes: 1 addition & 1 deletion app/lua/legc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#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

void legc_set_mode(lua_State *L, int mode, unsigned limit);
void legc_set_mode(lua_State *L, int mode, int limit);

#endif

2 changes: 1 addition & 1 deletion app/lua/lstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct global_State {
Mbuffer buff; /* temporary buffer for string concatentation */
lu_mem GCthreshold;
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 gcdept; /* how much GC is `behind schedule' */
int gcpause; /* size of pause between successive GCs */
Expand Down
2 changes: 1 addition & 1 deletion app/lwip/app/espconn_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ espconn_Task(os_event_t *events)
break;
case SIG_ESPCONN_ERRER:
/*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
if (espconn_manual_recv_enabled(task_msg))
espconn_list_delete(&plink_active, task_msg);
espconn_tcp_reconnect(task_msg);
break;
case SIG_ESPCONN_CLOSE:
/*remove the node from the client's active connection list*/
Expand Down
3 changes: 3 additions & 0 deletions app/lwip/core/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ mdns_reg(struct mdns_info *info) {
os_timer_disarm(&mdns_timer);
}
}
#include "pm/swtimer.h"

/**
* Initialize the resolver: set up the UDP pcb and configure the default server
Expand Down Expand Up @@ -1129,6 +1130,8 @@ mdns_init(struct mdns_info *info) {

os_timer_disarm(&mdns_timer);
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);
}
}
Expand Down
Loading

0 comments on commit 8b84445

Please sign in to comment.