2014-12-22 12:35:05 +01:00
|
|
|
|
// Module for interfacing with system
|
|
|
|
|
|
2015-12-16 06:04:58 +01:00
|
|
|
|
#include "module.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
#include "lauxlib.h"
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
2015-11-09 00:46:08 +01:00
|
|
|
|
#include "ldebug.h"
|
2015-02-13 08:11:59 +01:00
|
|
|
|
#include "ldo.h"
|
|
|
|
|
#include "lfunc.h"
|
|
|
|
|
#include "lmem.h"
|
|
|
|
|
#include "lobject.h"
|
2015-11-09 00:46:08 +01:00
|
|
|
|
#include "lstate.h"
|
2016-02-20 19:54:09 +01:00
|
|
|
|
#include "legc.h"
|
2015-11-09 00:46:08 +01:00
|
|
|
|
|
2015-02-13 08:11:59 +01:00
|
|
|
|
#include "lopcodes.h"
|
|
|
|
|
#include "lstring.h"
|
|
|
|
|
#include "lundump.h"
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
#include "platform.h"
|
2015-12-12 04:27:31 +01:00
|
|
|
|
#include "lrodefs.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
|
|
#include "c_types.h"
|
|
|
|
|
#include "c_string.h"
|
|
|
|
|
#include "driver/uart.h"
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
#include "user_interface.h"
|
2014-12-31 01:08:31 +01:00
|
|
|
|
#include "flash_api.h"
|
2016-09-05 20:17:13 +02:00
|
|
|
|
#include "vfs.h"
|
2015-03-06 04:59:04 +01:00
|
|
|
|
#include "user_version.h"
|
2016-01-20 09:37:03 +01:00
|
|
|
|
#include "rom.h"
|
2016-03-02 00:37:41 +01:00
|
|
|
|
#include "task/task.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
2015-03-17 10:23:45 +01:00
|
|
|
|
#define CPU80MHZ 80
|
|
|
|
|
#define CPU160MHZ 160
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// Lua: restart()
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_restart( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
|
|
|
|
system_restart();
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 0;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
// Lua: dsleep( us, option )
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_deepsleep( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
2016-01-02 12:10:27 +01:00
|
|
|
|
uint32 us;
|
|
|
|
|
uint8 option;
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
//us = luaL_checkinteger( L, 1 );
|
|
|
|
|
// Set deleep option, skip if nil
|
|
|
|
|
if ( lua_isnumber(L, 2) )
|
|
|
|
|
{
|
|
|
|
|
option = lua_tointeger(L, 2);
|
|
|
|
|
if ( option < 0 || option > 4)
|
|
|
|
|
return luaL_error( L, "wrong arg range" );
|
|
|
|
|
else
|
2016-01-20 09:37:03 +01:00
|
|
|
|
system_deep_sleep_set_option( option );
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
}
|
2017-03-14 10:49:41 +01:00
|
|
|
|
bool instant = false;
|
|
|
|
|
if (lua_isnumber(L, 3))
|
|
|
|
|
instant = lua_tointeger(L, 3);
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
// Set deleep time, skip if nil
|
|
|
|
|
if ( lua_isnumber(L, 1) )
|
|
|
|
|
{
|
2016-01-02 12:10:27 +01:00
|
|
|
|
us = luaL_checknumber(L, 1);
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
// if ( us <= 0 )
|
|
|
|
|
if ( us < 0 )
|
|
|
|
|
return luaL_error( L, "wrong arg range" );
|
|
|
|
|
else
|
2017-03-14 10:49:41 +01:00
|
|
|
|
{
|
|
|
|
|
if (instant)
|
|
|
|
|
system_deep_sleep_instant(us);
|
|
|
|
|
else
|
|
|
|
|
system_deep_sleep( us );
|
|
|
|
|
}
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
}
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 0;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 21:31:06 +02:00
|
|
|
|
|
|
|
|
|
#ifdef PMSLEEP_ENABLE
|
|
|
|
|
#include "pmSleep.h"
|
|
|
|
|
|
|
|
|
|
int node_sleep_resume_cb_ref= LUA_NOREF;
|
|
|
|
|
void node_sleep_resume_cb(void)
|
|
|
|
|
{
|
|
|
|
|
PMSLEEP_DBG("START");
|
|
|
|
|
pmSleep_execute_lua_cb(&node_sleep_resume_cb_ref);
|
|
|
|
|
PMSLEEP_DBG("END");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lua: node.sleep(table)
|
|
|
|
|
static int node_sleep( lua_State* L )
|
|
|
|
|
{
|
|
|
|
|
pmSleep_INIT_CFG(cfg);
|
|
|
|
|
cfg.sleep_mode=LIGHT_SLEEP_T;
|
|
|
|
|
|
|
|
|
|
if(lua_istable(L, 1)){
|
|
|
|
|
pmSleep_parse_table_lua(L, 1, &cfg, NULL, &node_sleep_resume_cb_ref);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return luaL_argerror(L, 1, "must be table");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg.resume_cb_ptr = &node_sleep_resume_cb;
|
|
|
|
|
pmSleep_suspend(&cfg);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif //PMSLEEP_ENABLE
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_info( lua_State* L )
|
2014-12-31 07:26:51 +01:00
|
|
|
|
{
|
|
|
|
|
lua_pushinteger(L, NODE_VERSION_MAJOR);
|
|
|
|
|
lua_pushinteger(L, NODE_VERSION_MINOR);
|
|
|
|
|
lua_pushinteger(L, NODE_VERSION_REVISION);
|
|
|
|
|
lua_pushinteger(L, system_get_chip_id()); // chip id
|
|
|
|
|
lua_pushinteger(L, spi_flash_get_id()); // flash id
|
2015-03-15 22:40:43 +01:00
|
|
|
|
#if defined(FLASH_SAFE_API)
|
2015-03-15 17:51:47 +01:00
|
|
|
|
lua_pushinteger(L, flash_safe_get_size_byte() / 1024); // flash size in KB
|
2015-03-15 22:40:43 +01:00
|
|
|
|
#else
|
2015-03-15 17:51:47 +01:00
|
|
|
|
lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB
|
2015-03-15 22:40:43 +01:00
|
|
|
|
#endif // defined(FLASH_SAFE_API)
|
2015-03-15 17:48:28 +01:00
|
|
|
|
lua_pushinteger(L, flash_rom_get_mode());
|
|
|
|
|
lua_pushinteger(L, flash_rom_get_speed());
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 8;
|
2014-12-31 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// Lua: chipid()
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_chipid( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
|
|
|
|
uint32_t id = system_get_chip_id();
|
|
|
|
|
lua_pushinteger(L, id);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 1;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
2015-03-26 17:52:55 +01:00
|
|
|
|
|
|
|
|
|
// deprecated, moved to adc module
|
2015-01-26 11:17:15 +01:00
|
|
|
|
// Lua: readvdd33()
|
2015-03-26 17:52:55 +01:00
|
|
|
|
// static int node_readvdd33( lua_State* L )
|
|
|
|
|
// {
|
|
|
|
|
// uint32_t vdd33 = readvdd33();
|
|
|
|
|
// lua_pushinteger(L, vdd33);
|
|
|
|
|
// return 1;
|
|
|
|
|
// }
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
2014-12-31 01:08:31 +01:00
|
|
|
|
// Lua: flashid()
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_flashid( lua_State* L )
|
2014-12-31 01:08:31 +01:00
|
|
|
|
{
|
|
|
|
|
uint32_t id = spi_flash_get_id();
|
|
|
|
|
lua_pushinteger( L, id );
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 1;
|
2014-12-31 01:08:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lua: flashsize()
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_flashsize( lua_State* L )
|
2014-12-31 01:08:31 +01:00
|
|
|
|
{
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (lua_type(L, 1) == LUA_TNUMBER)
|
|
|
|
|
{
|
|
|
|
|
flash_rom_set_size_byte(luaL_checkinteger(L, 1));
|
|
|
|
|
}
|
2015-03-15 17:51:47 +01:00
|
|
|
|
#if defined(FLASH_SAFE_API)
|
|
|
|
|
uint32_t sz = flash_safe_get_size_byte();
|
|
|
|
|
#else
|
|
|
|
|
uint32_t sz = flash_rom_get_size_byte();
|
|
|
|
|
#endif // defined(FLASH_SAFE_API)
|
2014-12-31 01:08:31 +01:00
|
|
|
|
lua_pushinteger( L, sz );
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 1;
|
2014-12-31 01:08:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// Lua: heap()
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_heap( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
|
|
|
|
uint32_t sz = system_get_free_heap_size();
|
|
|
|
|
lua_pushinteger(L, sz);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 1;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern lua_Load gLoad;
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
|
extern bool user_process_input(bool force);
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// Lua: input("string")
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_input( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
2015-03-15 22:40:43 +01:00
|
|
|
|
size_t l = 0;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
const char *s = luaL_checklstring(L, 1, &l);
|
|
|
|
|
if (s != NULL && l > 0 && l < LUA_MAXINPUT - 1)
|
|
|
|
|
{
|
|
|
|
|
lua_Load *load = &gLoad;
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (load->line_position == 0) {
|
2014-12-22 12:35:05 +01:00
|
|
|
|
c_memcpy(load->line, s, l);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
load->line[l + 1] = '\0';
|
|
|
|
|
load->line_position = c_strlen(load->line) + 1;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
load->done = 1;
|
|
|
|
|
NODE_DBG("Get command:\n");
|
|
|
|
|
NODE_DBG(load->line); // buggy here
|
|
|
|
|
NODE_DBG("\nResult(if any):\n");
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
|
user_process_input(true);
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int output_redir_ref = LUA_NOREF;
|
|
|
|
|
static int serial_debug = 1;
|
2015-03-15 22:40:43 +01:00
|
|
|
|
void output_redirect(const char *str) {
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
|
lua_State *L = lua_getstate();
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// if(c_strlen(str)>=TX_BUFF_SIZE){
|
|
|
|
|
// NODE_ERR("output too long.\n");
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
2016-08-02 22:33:05 +02:00
|
|
|
|
if (output_redir_ref == LUA_NOREF) {
|
2014-12-22 12:35:05 +01:00
|
|
|
|
uart0_sendStr(str);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (serial_debug != 0) {
|
2014-12-22 12:35:05 +01:00
|
|
|
|
uart0_sendStr(str);
|
|
|
|
|
}
|
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, output_redir_ref);
|
|
|
|
|
lua_pushstring(L, str);
|
|
|
|
|
lua_call(L, 1, 0); // this call back function should never user output.
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lua: output(function(c), debug)
|
2015-01-05 03:09:51 +01:00
|
|
|
|
static int node_output( lua_State* L )
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
|
|
|
|
// luaL_checkanyfunction(L, 1);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) {
|
2014-12-22 12:35:05 +01:00
|
|
|
|
lua_pushvalue(L, 1); // copy argument (func) to the top of stack
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (output_redir_ref != LUA_NOREF)
|
2014-12-22 12:35:05 +01:00
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, output_redir_ref);
|
|
|
|
|
output_redir_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
|
} else { // unref the key press function
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (output_redir_ref != LUA_NOREF)
|
2014-12-22 12:35:05 +01:00
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, output_redir_ref);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
output_redir_ref = LUA_NOREF;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
serial_debug = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( lua_isnumber(L, 2) )
|
|
|
|
|
{
|
|
|
|
|
serial_debug = lua_tointeger(L, 2);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (serial_debug != 0)
|
2014-12-22 12:35:05 +01:00
|
|
|
|
serial_debug = 1;
|
|
|
|
|
} else {
|
|
|
|
|
serial_debug = 1; // default to 1
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return 0;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 08:11:59 +01:00
|
|
|
|
static int writer(lua_State* L, const void* p, size_t size, void* u)
|
|
|
|
|
{
|
|
|
|
|
UNUSED(L);
|
|
|
|
|
int file_fd = *( (int *)u );
|
2016-09-05 20:17:13 +02:00
|
|
|
|
if (!file_fd)
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return 1;
|
2015-03-15 22:40:43 +01:00
|
|
|
|
NODE_DBG("get fd:%d,size:%d\n", file_fd, size);
|
|
|
|
|
|
2016-09-05 20:17:13 +02:00
|
|
|
|
if (size != 0 && (size != vfs_write(file_fd, (const char *)p, size)) )
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return 1;
|
2015-03-15 22:40:43 +01:00
|
|
|
|
NODE_DBG("write fd:%d,size:%d\n", file_fd, size);
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define toproto(L,i) (clvalue(L->top+(i))->l.p)
|
|
|
|
|
// Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc
|
|
|
|
|
static int node_compile( lua_State* L )
|
|
|
|
|
{
|
|
|
|
|
Proto* f;
|
2016-09-05 20:17:13 +02:00
|
|
|
|
int file_fd = 0;
|
2015-02-13 08:11:59 +01:00
|
|
|
|
size_t len;
|
|
|
|
|
const char *fname = luaL_checklstring( L, 1, &len );
|
2016-09-05 20:17:13 +02:00
|
|
|
|
const char *basename = vfs_basename( fname );
|
|
|
|
|
luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid");
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
2016-09-05 20:17:13 +02:00
|
|
|
|
char *output = luaM_malloc( L, len+1 );
|
2015-02-13 08:11:59 +01:00
|
|
|
|
c_strcpy(output, fname);
|
|
|
|
|
// check here that filename end with ".lua".
|
2016-09-05 20:17:13 +02:00
|
|
|
|
if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) {
|
|
|
|
|
luaM_free( L, output );
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return luaL_error(L, "not a .lua file");
|
2016-09-05 20:17:13 +02:00
|
|
|
|
}
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
output[c_strlen(output) - 2] = 'c';
|
|
|
|
|
output[c_strlen(output) - 1] = '\0';
|
2015-02-13 08:11:59 +01:00
|
|
|
|
NODE_DBG(output);
|
|
|
|
|
NODE_DBG("\n");
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (luaL_loadfsfile(L, fname) != 0) {
|
2016-09-05 20:17:13 +02:00
|
|
|
|
luaM_free( L, output );
|
2015-03-15 22:40:43 +01:00
|
|
|
|
return luaL_error(L, lua_tostring(L, -1));
|
2015-02-13 08:11:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
f = toproto(L, -1);
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
|
|
|
|
int stripping = 1; /* strip debug information? */
|
|
|
|
|
|
2016-09-05 20:17:13 +02:00
|
|
|
|
file_fd = vfs_open(output, "w+");
|
|
|
|
|
if (!file_fd)
|
2015-02-13 08:11:59 +01:00
|
|
|
|
{
|
2016-09-05 20:17:13 +02:00
|
|
|
|
luaM_free( L, output );
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return luaL_error(L, "cannot open/write to file");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua_lock(L);
|
2015-03-15 22:40:43 +01:00
|
|
|
|
int result = luaU_dump(L, f, writer, &file_fd, stripping);
|
2015-02-13 08:11:59 +01:00
|
|
|
|
lua_unlock(L);
|
|
|
|
|
|
2016-09-05 20:17:13 +02:00
|
|
|
|
if (vfs_flush(file_fd) != VFS_RES_OK) {
|
2015-08-11 00:08:49 +02:00
|
|
|
|
// overwrite Lua error, like writer() does in case of a file io error
|
|
|
|
|
result = 1;
|
|
|
|
|
}
|
2016-09-05 20:17:13 +02:00
|
|
|
|
vfs_close(file_fd);
|
|
|
|
|
file_fd = 0;
|
|
|
|
|
luaM_free( L, output );
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (result == LUA_ERR_CC_INTOVERFLOW) {
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return luaL_error(L, "value too big or small for target integer type");
|
|
|
|
|
}
|
2015-03-15 22:40:43 +01:00
|
|
|
|
if (result == LUA_ERR_CC_NOTINTEGER) {
|
2015-02-13 08:11:59 +01:00
|
|
|
|
return luaL_error(L, "target lua_Number is integral but fractional value found");
|
|
|
|
|
}
|
2015-08-11 00:08:49 +02:00
|
|
|
|
if (result == 1) { // result status generated by writer() or fs_flush() fail
|
|
|
|
|
return luaL_error(L, "writing to file failed");
|
|
|
|
|
}
|
2015-02-13 08:11:59 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 16:28:34 +01:00
|
|
|
|
// Task callback handler for node.task.post()
|
2016-03-02 00:37:41 +01:00
|
|
|
|
static task_handle_t do_node_task_handle;
|
|
|
|
|
static void do_node_task (task_param_t task_fn_ref, uint8_t prio)
|
|
|
|
|
{
|
|
|
|
|
lua_State* L = lua_getstate();
|
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
2016-03-03 16:28:34 +01:00
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
2016-03-02 00:37:41 +01:00
|
|
|
|
lua_pushinteger(L, prio);
|
2016-03-03 16:28:34 +01:00
|
|
|
|
lua_call(L, 1, 0);
|
2016-03-02 00:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 16:28:34 +01:00
|
|
|
|
// Lua: node.task.post([priority],task_cb) -- schedule a task for execution next
|
2016-03-02 00:37:41 +01:00
|
|
|
|
static int node_task_post( lua_State* L )
|
|
|
|
|
{
|
|
|
|
|
int n = 1, Ltype = lua_type(L, 1);
|
|
|
|
|
unsigned priority = TASK_PRIORITY_MEDIUM;
|
|
|
|
|
if (Ltype == LUA_TNUMBER) {
|
|
|
|
|
priority = (unsigned) luaL_checkint(L, 1);
|
|
|
|
|
luaL_argcheck(L, priority <= TASK_PRIORITY_HIGH, 1, "invalid priority");
|
|
|
|
|
Ltype = lua_type(L, ++n);
|
|
|
|
|
}
|
|
|
|
|
luaL_argcheck(L, Ltype == LUA_TFUNCTION || Ltype == LUA_TLIGHTFUNCTION, n, "invalid function");
|
2016-03-04 13:26:10 +01:00
|
|
|
|
lua_pushvalue(L, n);
|
2016-03-02 00:37:41 +01:00
|
|
|
|
|
2016-03-03 16:28:34 +01:00
|
|
|
|
int task_fn_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
2016-03-02 00:37:41 +01:00
|
|
|
|
|
|
|
|
|
if (!do_node_task_handle) // bind the task handle to do_node_task on 1st call
|
|
|
|
|
do_node_task_handle = task_get_id(do_node_task);
|
|
|
|
|
|
2016-03-03 16:28:34 +01:00
|
|
|
|
if(!task_post(priority, do_node_task_handle, (task_param_t)task_fn_ref)) {
|
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, task_fn_ref);
|
|
|
|
|
luaL_error(L, "Task queue overflow. Task not posted");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2016-03-02 00:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 10:23:45 +01:00
|
|
|
|
// Lua: setcpufreq(mhz)
|
|
|
|
|
// mhz is either CPU80MHZ od CPU160MHZ
|
|
|
|
|
static int node_setcpufreq(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
// http://www.esp8266.com/viewtopic.php?f=21&t=1369
|
|
|
|
|
uint32_t new_freq = luaL_checkinteger(L, 1);
|
|
|
|
|
if (new_freq == CPU160MHZ){
|
|
|
|
|
REG_SET_BIT(0x3ff00014, BIT(0));
|
2015-10-01 07:20:53 +02:00
|
|
|
|
ets_update_cpu_frequency(CPU160MHZ);
|
2015-03-17 10:23:45 +01:00
|
|
|
|
} else {
|
|
|
|
|
REG_CLR_BIT(0x3ff00014, BIT(0));
|
2015-10-01 07:20:53 +02:00
|
|
|
|
ets_update_cpu_frequency(CPU80MHZ);
|
2015-03-17 10:23:45 +01:00
|
|
|
|
}
|
|
|
|
|
new_freq = ets_get_cpu_frequency();
|
|
|
|
|
lua_pushinteger(L, new_freq);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 01:42:20 +01:00
|
|
|
|
// Lua: code, reason [, exccause, epc1, epc2, epc3, excvaddr, depc ] = bootreason()
|
2015-06-27 04:34:03 +02:00
|
|
|
|
static int node_bootreason (lua_State *L)
|
|
|
|
|
{
|
2016-01-15 01:42:20 +01:00
|
|
|
|
const struct rst_info *ri = system_get_rst_info ();
|
|
|
|
|
uint32_t arr[8] = {
|
|
|
|
|
rtc_get_reset_reason(),
|
|
|
|
|
ri->reason,
|
|
|
|
|
ri->exccause, ri->epc1, ri->epc2, ri->epc3, ri->excvaddr, ri->depc
|
|
|
|
|
};
|
|
|
|
|
int i, n = ((ri->reason != REASON_EXCEPTION_RST) ? 2 : 8);
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
lua_pushinteger (L, arr[i]);
|
|
|
|
|
return n;
|
2015-06-27 04:34:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 21:54:22 +02:00
|
|
|
|
// Lua: restore()
|
|
|
|
|
static int node_restore (lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
system_restore();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 00:46:08 +01:00
|
|
|
|
#ifdef LUA_OPTIMIZE_DEBUG
|
|
|
|
|
/* node.stripdebug([level[, function]]).
|
|
|
|
|
* level: 1 don't discard debug
|
|
|
|
|
* 2 discard Local and Upvalue debug info
|
|
|
|
|
* 3 discard Local, Upvalue and lineno debug info.
|
|
|
|
|
* function: Function to be stripped as per setfenv except 0 not permitted.
|
|
|
|
|
* If no arguments then the current default setting is returned.
|
|
|
|
|
* If function is omitted, this is the default setting for future compiles
|
|
|
|
|
* The function returns an estimated integer count of the bytes stripped.
|
|
|
|
|
*/
|
|
|
|
|
static int node_stripdebug (lua_State *L) {
|
|
|
|
|
int level;
|
|
|
|
|
|
|
|
|
|
if (L->top == L->base) {
|
|
|
|
|
lua_pushlightuserdata(L, &luaG_stripdebug );
|
|
|
|
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
|
|
|
|
if (lua_isnil(L, -1)) {
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
lua_pushinteger(L, LUA_OPTIMIZE_DEBUG);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
level = luaL_checkint(L, 1);
|
|
|
|
|
if ((level <= 0) || (level > 3)) luaL_argerror(L, 1, "must in range 1-3");
|
|
|
|
|
|
|
|
|
|
if (L->top == L->base + 1) {
|
|
|
|
|
/* Store the default level in the registry if no function parameter */
|
|
|
|
|
lua_pushlightuserdata(L, &luaG_stripdebug);
|
|
|
|
|
lua_pushinteger(L, level);
|
|
|
|
|
lua_settable(L, LUA_REGISTRYINDEX);
|
|
|
|
|
lua_settop(L,0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (level == 1) {
|
|
|
|
|
lua_settop(L,0);
|
|
|
|
|
lua_pushinteger(L, 0);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lua_isfunction(L, 2)) {
|
|
|
|
|
int scope = luaL_checkint(L, 2);
|
|
|
|
|
if (scope > 0) {
|
|
|
|
|
/* if the function parameter is a +ve integer then climb to find function */
|
|
|
|
|
lua_Debug ar;
|
|
|
|
|
lua_pop(L, 1); /* pop level as getinfo will replace it by the function */
|
|
|
|
|
if (lua_getstack(L, scope, &ar)) {
|
|
|
|
|
lua_getinfo(L, "f", &ar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!lua_isfunction(L, 2) || lua_iscfunction(L, -1)) luaL_argerror(L, 2, "must be a Lua Function");
|
|
|
|
|
// lua_lock(L);
|
|
|
|
|
Proto *f = clvalue(L->base + 1)->l.p;
|
|
|
|
|
// lua_unlock(L);
|
|
|
|
|
lua_settop(L,0);
|
|
|
|
|
lua_pushinteger(L, luaG_stripdebug(L, f, level, 1));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-20 19:54:09 +01:00
|
|
|
|
// Lua: node.egc.setmode( mode, [param])
|
2016-03-02 00:37:41 +01:00
|
|
|
|
// where the mode is one of the node.egc constants NOT_ACTIVE , ON_ALLOC_FAILURE,
|
2016-02-20 19:54:09 +01:00
|
|
|
|
// ON_MEM_LIMIT, ALWAYS. In the case of ON_MEM_LIMIT an integer parameter is reqired
|
|
|
|
|
// See legc.h and lecg.c.
|
|
|
|
|
static int node_egc_setmode(lua_State* L) {
|
|
|
|
|
unsigned mode = luaL_checkinteger(L, 1);
|
|
|
|
|
unsigned limit = luaL_optinteger (L, 2, 0);
|
2016-03-02 00:37:41 +01:00
|
|
|
|
|
2016-02-20 19:54:09 +01:00
|
|
|
|
luaL_argcheck(L, mode <= (EGC_ON_ALLOC_FAILURE | EGC_ON_MEM_LIMIT | EGC_ALWAYS), 1, "invalid mode");
|
|
|
|
|
luaL_argcheck(L, !(mode & EGC_ON_MEM_LIMIT) || limit>0, 1, "limit must be non-zero");
|
2016-03-02 00:37:41 +01:00
|
|
|
|
|
2016-02-20 19:54:09 +01:00
|
|
|
|
legc_set_mode( L, mode, limit );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-03-20 17:54:16 +01:00
|
|
|
|
//
|
|
|
|
|
// Lua: osprint(true/false)
|
|
|
|
|
// Allows you to turn on the native Espressif SDK printing
|
|
|
|
|
static int node_osprint( lua_State* L )
|
|
|
|
|
{
|
|
|
|
|
if (lua_toboolean(L, 1)) {
|
|
|
|
|
system_set_os_print(1);
|
|
|
|
|
} else {
|
|
|
|
|
system_set_os_print(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-26 14:14:49 +01:00
|
|
|
|
int node_random_range(int l, int u) {
|
|
|
|
|
// The range is the number of different values to return
|
|
|
|
|
unsigned int range = u + 1 - l;
|
|
|
|
|
|
|
|
|
|
// If this is very large then use simpler code
|
|
|
|
|
if (range >= 0x7fffffff) {
|
|
|
|
|
unsigned int v;
|
|
|
|
|
|
|
|
|
|
// This cannot loop more than half the time
|
|
|
|
|
while ((v = os_random()) >= range) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now v is in the range [0, range)
|
|
|
|
|
return v + l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Easy case, with only one value, we know the result
|
|
|
|
|
if (range == 1) {
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Another easy case -- uniform 32-bit
|
|
|
|
|
if (range == 0) {
|
|
|
|
|
return os_random();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now we have to figure out what a large multiple of range is
|
|
|
|
|
// that just fits into 32 bits.
|
|
|
|
|
// The limit will be less than 1 << 32 by some amount (not much)
|
|
|
|
|
uint32_t limit = ((0x80000000 / ((range + 1) >> 1)) - 1) * range;
|
|
|
|
|
|
|
|
|
|
uint32_t v;
|
|
|
|
|
|
|
|
|
|
while ((v = os_random()) >= limit) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now v is uniformly distributed in [0, limit) and limit is a multiple of range
|
|
|
|
|
|
|
|
|
|
return (v % range) + l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_random (lua_State *L) {
|
|
|
|
|
int u;
|
|
|
|
|
int l;
|
|
|
|
|
|
|
|
|
|
switch (lua_gettop(L)) { /* check number of arguments */
|
|
|
|
|
case 0: { /* no arguments */
|
|
|
|
|
#ifdef LUA_NUMBER_INTEGRAL
|
|
|
|
|
lua_pushnumber(L, 0); /* Number between 0 and 1 - always 0 with ints */
|
|
|
|
|
#else
|
|
|
|
|
lua_pushnumber(L, (lua_Number)os_random() / (lua_Number)(1LL << 32));
|
|
|
|
|
#endif
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
case 1: { /* only upper limit */
|
|
|
|
|
l = 1;
|
|
|
|
|
u = luaL_checkint(L, 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2: { /* lower and upper limits */
|
|
|
|
|
l = luaL_checkint(L, 1);
|
|
|
|
|
u = luaL_checkint(L, 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return luaL_error(L, "wrong number of arguments");
|
|
|
|
|
}
|
|
|
|
|
luaL_argcheck(L, l<=u, 2, "interval is empty");
|
|
|
|
|
lua_pushnumber(L, node_random_range(l, u)); /* int between `l' and `u' */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
// Module function map
|
2016-02-20 19:54:09 +01:00
|
|
|
|
|
|
|
|
|
static const LUA_REG_TYPE node_egc_map[] = {
|
2016-03-02 00:37:41 +01:00
|
|
|
|
{ LSTRKEY( "setmode" ), LFUNCVAL( node_egc_setmode ) },
|
2016-02-20 19:54:09 +01:00
|
|
|
|
{ LSTRKEY( "NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) },
|
|
|
|
|
{ LSTRKEY( "ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
|
|
|
|
|
{ LSTRKEY( "ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) },
|
|
|
|
|
{ LSTRKEY( "ALWAYS" ), LNUMVAL( EGC_ALWAYS ) },
|
|
|
|
|
{ LNILKEY, LNILVAL }
|
|
|
|
|
};
|
2016-03-02 00:37:41 +01:00
|
|
|
|
static const LUA_REG_TYPE node_task_map[] = {
|
|
|
|
|
{ LSTRKEY( "post" ), LFUNCVAL( node_task_post ) },
|
|
|
|
|
{ LSTRKEY( "LOW_PRIORITY" ), LNUMVAL( TASK_PRIORITY_LOW ) },
|
|
|
|
|
{ LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) },
|
|
|
|
|
{ LSTRKEY( "HIGH_PRIORITY" ), LNUMVAL( TASK_PRIORITY_HIGH ) },
|
|
|
|
|
{ LNILKEY, LNILVAL }
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-16 06:04:58 +01:00
|
|
|
|
static const LUA_REG_TYPE node_map[] =
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{
|
|
|
|
|
{ LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
|
|
|
|
|
{ LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
|
2017-04-04 21:31:06 +02:00
|
|
|
|
#ifdef PMSLEEP_ENABLE
|
|
|
|
|
{ LSTRKEY( "sleep" ), LFUNCVAL( node_sleep ) },
|
|
|
|
|
PMSLEEP_INT_MAP,
|
|
|
|
|
#endif
|
2014-12-31 07:26:51 +01:00
|
|
|
|
{ LSTRKEY( "info" ), LFUNCVAL( node_info ) },
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{ LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) },
|
2014-12-31 01:08:31 +01:00
|
|
|
|
{ LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) },
|
|
|
|
|
{ LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{ LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
|
|
|
|
|
{ LSTRKEY( "input" ), LFUNCVAL( node_input ) },
|
|
|
|
|
{ LSTRKEY( "output" ), LFUNCVAL( node_output ) },
|
2015-11-09 00:46:08 +01:00
|
|
|
|
// Moved to adc module, use adc.readvdd33()
|
2015-03-26 17:52:55 +01:00
|
|
|
|
// { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
|
2015-02-13 08:11:59 +01:00
|
|
|
|
{ LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
|
2015-03-17 10:23:45 +01:00
|
|
|
|
{ LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) },
|
|
|
|
|
{ LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) },
|
|
|
|
|
{ LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) },
|
2015-06-27 04:34:03 +02:00
|
|
|
|
{ LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) },
|
2015-07-03 21:54:22 +02:00
|
|
|
|
{ LSTRKEY( "restore" ), LFUNCVAL( node_restore) },
|
2016-12-26 14:14:49 +01:00
|
|
|
|
{ LSTRKEY( "random" ), LFUNCVAL( node_random) },
|
2015-11-09 00:46:08 +01:00
|
|
|
|
#ifdef LUA_OPTIMIZE_DEBUG
|
|
|
|
|
{ LSTRKEY( "stripdebug" ), LFUNCVAL( node_stripdebug ) },
|
|
|
|
|
#endif
|
2016-03-02 00:37:41 +01:00
|
|
|
|
{ LSTRKEY( "egc" ), LROVAL( node_egc_map ) },
|
|
|
|
|
{ LSTRKEY( "task" ), LROVAL( node_task_map ) },
|
2016-03-20 17:54:16 +01:00
|
|
|
|
#ifdef DEVELOPMENT_TOOLS
|
|
|
|
|
{ LSTRKEY( "osprint" ), LFUNCVAL( node_osprint ) },
|
|
|
|
|
#endif
|
2015-11-09 00:46:08 +01:00
|
|
|
|
|
2015-03-15 22:40:43 +01:00
|
|
|
|
// Combined to dsleep(us, option)
|
Combined dsleep_set_options(option) to dsleep( us, option )
* dsleep( us, option )
Hardware has to support deep-sleep wake up (XPD_DCDC connects to EXT_RSTB with 0R). system_deep_sleep(0) ,set no wake up timer,connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
** us: Integer
time to sleep.
if us = 0, it will sleep forever.
** option: Integer
option=0, init data byte 108 is valuable;
option>0, init data byte 108 is valueless.
More details as follows:
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
1, RF_CAL after deep-sleep wake up, there will belarge current.
2, no RF_CAL after deep-sleep wake up, there will only be small current.
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
2015-01-29 07:21:38 +01:00
|
|
|
|
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
|
2014-12-22 12:35:05 +01:00
|
|
|
|
{ LNILKEY, LNILVAL }
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-16 06:04:58 +01:00
|
|
|
|
NODEMCU_MODULE(NODE, "node", node_map, NULL);
|