Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor timer suspend portion of node.sleep (pmsleep) #2287

Merged
merged 5 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions app/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,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__ */
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
52 changes: 0 additions & 52 deletions app/misc/Makefile

This file was deleted.

Loading