node.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. // Module for interfacing with system
  2. #include "module.h"
  3. #include "lauxlib.h"
  4. #include "ldebug.h"
  5. #include "ldo.h"
  6. #include "lfunc.h"
  7. #include "lmem.h"
  8. #include "lobject.h"
  9. #include "lstate.h"
  10. #include "legc.h"
  11. #include "lopcodes.h"
  12. #include "lstring.h"
  13. #include "lundump.h"
  14. #include "platform.h"
  15. #include "lrodefs.h"
  16. #include "c_types.h"
  17. #include "c_string.h"
  18. #include "driver/uart.h"
  19. #include "user_interface.h"
  20. #include "flash_api.h"
  21. #include "vfs.h"
  22. #include "user_version.h"
  23. #include "rom.h"
  24. #include "task/task.h"
  25. #define CPU80MHZ 80
  26. #define CPU160MHZ 160
  27. // Lua: restart()
  28. static int node_restart( lua_State* L )
  29. {
  30. system_restart();
  31. return 0;
  32. }
  33. // Lua: dsleep( us, option )
  34. static int node_deepsleep( lua_State* L )
  35. {
  36. uint32 us;
  37. uint8 option;
  38. //us = luaL_checkinteger( L, 1 );
  39. // Set deleep option, skip if nil
  40. if ( lua_isnumber(L, 2) )
  41. {
  42. option = lua_tointeger(L, 2);
  43. if ( option < 0 || option > 4)
  44. return luaL_error( L, "wrong arg range" );
  45. else
  46. system_deep_sleep_set_option( option );
  47. }
  48. bool instant = false;
  49. if (lua_isnumber(L, 3))
  50. instant = lua_tointeger(L, 3);
  51. // Set deleep time, skip if nil
  52. if ( lua_isnumber(L, 1) )
  53. {
  54. us = luaL_checknumber(L, 1);
  55. // if ( us <= 0 )
  56. if ( us < 0 )
  57. return luaL_error( L, "wrong arg range" );
  58. else
  59. {
  60. if (instant)
  61. system_deep_sleep_instant(us);
  62. else
  63. system_deep_sleep( us );
  64. }
  65. }
  66. return 0;
  67. }
  68. #ifdef PMSLEEP_ENABLE
  69. #include "pmSleep.h"
  70. int node_sleep_resume_cb_ref= LUA_NOREF;
  71. void node_sleep_resume_cb(void)
  72. {
  73. PMSLEEP_DBG("START");
  74. pmSleep_execute_lua_cb(&node_sleep_resume_cb_ref);
  75. PMSLEEP_DBG("END");
  76. }
  77. // Lua: node.sleep(table)
  78. static int node_sleep( lua_State* L )
  79. {
  80. pmSleep_INIT_CFG(cfg);
  81. cfg.sleep_mode=LIGHT_SLEEP_T;
  82. if(lua_istable(L, 1)){
  83. pmSleep_parse_table_lua(L, 1, &cfg, NULL, &node_sleep_resume_cb_ref);
  84. }
  85. else{
  86. return luaL_argerror(L, 1, "must be table");
  87. }
  88. cfg.resume_cb_ptr = &node_sleep_resume_cb;
  89. pmSleep_suspend(&cfg);
  90. return 0;
  91. }
  92. #endif //PMSLEEP_ENABLE
  93. static int node_info( lua_State* L )
  94. {
  95. lua_pushinteger(L, NODE_VERSION_MAJOR);
  96. lua_pushinteger(L, NODE_VERSION_MINOR);
  97. lua_pushinteger(L, NODE_VERSION_REVISION);
  98. lua_pushinteger(L, system_get_chip_id()); // chip id
  99. lua_pushinteger(L, spi_flash_get_id()); // flash id
  100. lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB
  101. lua_pushinteger(L, flash_rom_get_mode());
  102. lua_pushinteger(L, flash_rom_get_speed());
  103. return 8;
  104. }
  105. // Lua: chipid()
  106. static int node_chipid( lua_State* L )
  107. {
  108. uint32_t id = system_get_chip_id();
  109. lua_pushinteger(L, id);
  110. return 1;
  111. }
  112. // deprecated, moved to adc module
  113. // Lua: readvdd33()
  114. // static int node_readvdd33( lua_State* L )
  115. // {
  116. // uint32_t vdd33 = readvdd33();
  117. // lua_pushinteger(L, vdd33);
  118. // return 1;
  119. // }
  120. // Lua: flashid()
  121. static int node_flashid( lua_State* L )
  122. {
  123. uint32_t id = spi_flash_get_id();
  124. lua_pushinteger( L, id );
  125. return 1;
  126. }
  127. // Lua: flashsize()
  128. static int node_flashsize( lua_State* L )
  129. {
  130. if (lua_type(L, 1) == LUA_TNUMBER)
  131. {
  132. flash_rom_set_size_byte(luaL_checkinteger(L, 1));
  133. }
  134. uint32_t sz = flash_rom_get_size_byte();
  135. lua_pushinteger( L, sz );
  136. return 1;
  137. }
  138. // Lua: heap()
  139. static int node_heap( lua_State* L )
  140. {
  141. uint32_t sz = system_get_free_heap_size();
  142. lua_pushinteger(L, sz);
  143. return 1;
  144. }
  145. extern lua_Load gLoad;
  146. extern bool user_process_input(bool force);
  147. // Lua: input("string")
  148. static int node_input( lua_State* L )
  149. {
  150. size_t l = 0;
  151. const char *s = luaL_checklstring(L, 1, &l);
  152. if (s != NULL && l > 0 && l < LUA_MAXINPUT - 1)
  153. {
  154. lua_Load *load = &gLoad;
  155. if (load->line_position == 0) {
  156. c_memcpy(load->line, s, l);
  157. load->line[l + 1] = '\0';
  158. load->line_position = c_strlen(load->line) + 1;
  159. load->done = 1;
  160. NODE_DBG("Get command:\n");
  161. NODE_DBG(load->line); // buggy here
  162. NODE_DBG("\nResult(if any):\n");
  163. user_process_input(true);
  164. }
  165. }
  166. return 0;
  167. }
  168. static int output_redir_ref = LUA_NOREF;
  169. static int serial_debug = 1;
  170. void output_redirect(const char *str) {
  171. lua_State *L = lua_getstate();
  172. // if(c_strlen(str)>=TX_BUFF_SIZE){
  173. // NODE_ERR("output too long.\n");
  174. // return;
  175. // }
  176. if (output_redir_ref == LUA_NOREF) {
  177. uart0_sendStr(str);
  178. return;
  179. }
  180. if (serial_debug != 0) {
  181. uart0_sendStr(str);
  182. }
  183. lua_rawgeti(L, LUA_REGISTRYINDEX, output_redir_ref);
  184. lua_pushstring(L, str);
  185. lua_call(L, 1, 0); // this call back function should never user output.
  186. }
  187. // Lua: output(function(c), debug)
  188. static int node_output( lua_State* L )
  189. {
  190. // luaL_checkanyfunction(L, 1);
  191. if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) {
  192. lua_pushvalue(L, 1); // copy argument (func) to the top of stack
  193. if (output_redir_ref != LUA_NOREF)
  194. luaL_unref(L, LUA_REGISTRYINDEX, output_redir_ref);
  195. output_redir_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  196. } else { // unref the key press function
  197. if (output_redir_ref != LUA_NOREF)
  198. luaL_unref(L, LUA_REGISTRYINDEX, output_redir_ref);
  199. output_redir_ref = LUA_NOREF;
  200. serial_debug = 1;
  201. return 0;
  202. }
  203. if ( lua_isnumber(L, 2) )
  204. {
  205. serial_debug = lua_tointeger(L, 2);
  206. if (serial_debug != 0)
  207. serial_debug = 1;
  208. } else {
  209. serial_debug = 1; // default to 1
  210. }
  211. return 0;
  212. }
  213. static int writer(lua_State* L, const void* p, size_t size, void* u)
  214. {
  215. UNUSED(L);
  216. int file_fd = *( (int *)u );
  217. if (!file_fd)
  218. return 1;
  219. NODE_DBG("get fd:%d,size:%d\n", file_fd, size);
  220. if (size != 0 && (size != vfs_write(file_fd, (const char *)p, size)) )
  221. return 1;
  222. NODE_DBG("write fd:%d,size:%d\n", file_fd, size);
  223. return 0;
  224. }
  225. #define toproto(L,i) (clvalue(L->top+(i))->l.p)
  226. // Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc
  227. static int node_compile( lua_State* L )
  228. {
  229. Proto* f;
  230. int file_fd = 0;
  231. size_t len;
  232. const char *fname = luaL_checklstring( L, 1, &len );
  233. const char *basename = vfs_basename( fname );
  234. luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid");
  235. char *output = luaM_malloc( L, len+1 );
  236. c_strcpy(output, fname);
  237. // check here that filename end with ".lua".
  238. if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) {
  239. luaM_free( L, output );
  240. return luaL_error(L, "not a .lua file");
  241. }
  242. output[c_strlen(output) - 2] = 'c';
  243. output[c_strlen(output) - 1] = '\0';
  244. NODE_DBG(output);
  245. NODE_DBG("\n");
  246. if (luaL_loadfsfile(L, fname) != 0) {
  247. luaM_free( L, output );
  248. return luaL_error(L, lua_tostring(L, -1));
  249. }
  250. f = toproto(L, -1);
  251. int stripping = 1; /* strip debug information? */
  252. file_fd = vfs_open(output, "w+");
  253. if (!file_fd)
  254. {
  255. luaM_free( L, output );
  256. return luaL_error(L, "cannot open/write to file");
  257. }
  258. lua_lock(L);
  259. int result = luaU_dump(L, f, writer, &file_fd, stripping);
  260. lua_unlock(L);
  261. if (vfs_flush(file_fd) != VFS_RES_OK) {
  262. // overwrite Lua error, like writer() does in case of a file io error
  263. result = 1;
  264. }
  265. vfs_close(file_fd);
  266. file_fd = 0;
  267. luaM_free( L, output );
  268. if (result == LUA_ERR_CC_INTOVERFLOW) {
  269. return luaL_error(L, "value too big or small for target integer type");
  270. }
  271. if (result == LUA_ERR_CC_NOTINTEGER) {
  272. return luaL_error(L, "target lua_Number is integral but fractional value found");
  273. }
  274. if (result == 1) { // result status generated by writer() or fs_flush() fail
  275. return luaL_error(L, "writing to file failed");
  276. }
  277. return 0;
  278. }
  279. // Task callback handler for node.task.post()
  280. static task_handle_t do_node_task_handle;
  281. static void do_node_task (task_param_t task_fn_ref, uint8_t prio)
  282. {
  283. lua_State* L = lua_getstate();
  284. lua_rawgeti(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
  285. luaL_unref(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
  286. lua_pushinteger(L, prio);
  287. lua_call(L, 1, 0);
  288. }
  289. // Lua: node.task.post([priority],task_cb) -- schedule a task for execution next
  290. static int node_task_post( lua_State* L )
  291. {
  292. int n = 1, Ltype = lua_type(L, 1);
  293. unsigned priority = TASK_PRIORITY_MEDIUM;
  294. if (Ltype == LUA_TNUMBER) {
  295. priority = (unsigned) luaL_checkint(L, 1);
  296. luaL_argcheck(L, priority <= TASK_PRIORITY_HIGH, 1, "invalid priority");
  297. Ltype = lua_type(L, ++n);
  298. }
  299. luaL_argcheck(L, Ltype == LUA_TFUNCTION || Ltype == LUA_TLIGHTFUNCTION, n, "invalid function");
  300. lua_pushvalue(L, n);
  301. int task_fn_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  302. if (!do_node_task_handle) // bind the task handle to do_node_task on 1st call
  303. do_node_task_handle = task_get_id(do_node_task);
  304. if(!task_post(priority, do_node_task_handle, (task_param_t)task_fn_ref)) {
  305. luaL_unref(L, LUA_REGISTRYINDEX, task_fn_ref);
  306. luaL_error(L, "Task queue overflow. Task not posted");
  307. }
  308. return 0;
  309. }
  310. // Lua: setcpufreq(mhz)
  311. // mhz is either CPU80MHZ od CPU160MHZ
  312. static int node_setcpufreq(lua_State* L)
  313. {
  314. // http://www.esp8266.com/viewtopic.php?f=21&t=1369
  315. uint32_t new_freq = luaL_checkinteger(L, 1);
  316. if (new_freq == CPU160MHZ){
  317. REG_SET_BIT(0x3ff00014, BIT(0));
  318. ets_update_cpu_frequency(CPU160MHZ);
  319. } else {
  320. REG_CLR_BIT(0x3ff00014, BIT(0));
  321. ets_update_cpu_frequency(CPU80MHZ);
  322. }
  323. new_freq = ets_get_cpu_frequency();
  324. lua_pushinteger(L, new_freq);
  325. return 1;
  326. }
  327. // Lua: code, reason [, exccause, epc1, epc2, epc3, excvaddr, depc ] = bootreason()
  328. static int node_bootreason (lua_State *L)
  329. {
  330. const struct rst_info *ri = system_get_rst_info ();
  331. uint32_t arr[8] = {
  332. rtc_get_reset_reason(),
  333. ri->reason,
  334. ri->exccause, ri->epc1, ri->epc2, ri->epc3, ri->excvaddr, ri->depc
  335. };
  336. int i, n = ((ri->reason != REASON_EXCEPTION_RST) ? 2 : 8);
  337. for (i = 0; i < n; ++i)
  338. lua_pushinteger (L, arr[i]);
  339. return n;
  340. }
  341. // Lua: restore()
  342. static int node_restore (lua_State *L)
  343. {
  344. system_restore();
  345. return 0;
  346. }
  347. #ifdef LUA_OPTIMIZE_DEBUG
  348. /* node.stripdebug([level[, function]]). 
  349. * level: 1 don't discard debug
  350. * 2 discard Local and Upvalue debug info
  351. * 3 discard Local, Upvalue and lineno debug info.
  352. * function: Function to be stripped as per setfenv except 0 not permitted.
  353. * If no arguments then the current default setting is returned.
  354. * If function is omitted, this is the default setting for future compiles
  355. * The function returns an estimated integer count of the bytes stripped.
  356. */
  357. static int node_stripdebug (lua_State *L) {
  358. int level;
  359. if (L->top == L->base) {
  360. lua_pushlightuserdata(L, &luaG_stripdebug );
  361. lua_gettable(L, LUA_REGISTRYINDEX);
  362. if (lua_isnil(L, -1)) {
  363. lua_pop(L, 1);
  364. lua_pushinteger(L, LUA_OPTIMIZE_DEBUG);
  365. }
  366. return 1;
  367. }
  368. level = luaL_checkint(L, 1);
  369. if ((level <= 0) || (level > 3)) luaL_argerror(L, 1, "must in range 1-3");
  370. if (L->top == L->base + 1) {
  371. /* Store the default level in the registry if no function parameter */
  372. lua_pushlightuserdata(L, &luaG_stripdebug);
  373. lua_pushinteger(L, level);
  374. lua_settable(L, LUA_REGISTRYINDEX);
  375. lua_settop(L,0);
  376. return 0;
  377. }
  378. if (level == 1) {
  379. lua_settop(L,0);
  380. lua_pushinteger(L, 0);
  381. return 1;
  382. }
  383. if (!lua_isfunction(L, 2)) {
  384. int scope = luaL_checkint(L, 2);
  385. if (scope > 0) {
  386. /* if the function parameter is a +ve integer then climb to find function */
  387. lua_Debug ar;
  388. lua_pop(L, 1); /* pop level as getinfo will replace it by the function */
  389. if (lua_getstack(L, scope, &ar)) {
  390. lua_getinfo(L, "f", &ar);
  391. }
  392. }
  393. }
  394. if(!lua_isfunction(L, 2) || lua_iscfunction(L, -1)) luaL_argerror(L, 2, "must be a Lua Function");
  395. // lua_lock(L);
  396. Proto *f = clvalue(L->base + 1)->l.p;
  397. // lua_unlock(L);
  398. lua_settop(L,0);
  399. lua_pushinteger(L, luaG_stripdebug(L, f, level, 1));
  400. return 1;
  401. }
  402. #endif
  403. // Lua: node.egc.setmode( mode, [param])
  404. // where the mode is one of the node.egc constants NOT_ACTIVE , ON_ALLOC_FAILURE,
  405. // ON_MEM_LIMIT, ALWAYS. In the case of ON_MEM_LIMIT an integer parameter is reqired
  406. // See legc.h and lecg.c.
  407. static int node_egc_setmode(lua_State* L) {
  408. unsigned mode = luaL_checkinteger(L, 1);
  409. unsigned limit = luaL_optinteger (L, 2, 0);
  410. luaL_argcheck(L, mode <= (EGC_ON_ALLOC_FAILURE | EGC_ON_MEM_LIMIT | EGC_ALWAYS), 1, "invalid mode");
  411. luaL_argcheck(L, !(mode & EGC_ON_MEM_LIMIT) || limit>0, 1, "limit must be non-zero");
  412. legc_set_mode( L, mode, limit );
  413. return 0;
  414. }
  415. //
  416. // Lua: osprint(true/false)
  417. // Allows you to turn on the native Espressif SDK printing
  418. static int node_osprint( lua_State* L )
  419. {
  420. if (lua_toboolean(L, 1)) {
  421. system_set_os_print(1);
  422. } else {
  423. system_set_os_print(0);
  424. }
  425. return 0;
  426. }
  427. int node_random_range(int l, int u) {
  428. // The range is the number of different values to return
  429. unsigned int range = u + 1 - l;
  430. // If this is very large then use simpler code
  431. if (range >= 0x7fffffff) {
  432. unsigned int v;
  433. // This cannot loop more than half the time
  434. while ((v = os_random()) >= range) {
  435. }
  436. // Now v is in the range [0, range)
  437. return v + l;
  438. }
  439. // Easy case, with only one value, we know the result
  440. if (range == 1) {
  441. return l;
  442. }
  443. // Another easy case -- uniform 32-bit
  444. if (range == 0) {
  445. return os_random();
  446. }
  447. // Now we have to figure out what a large multiple of range is
  448. // that just fits into 32 bits.
  449. // The limit will be less than 1 << 32 by some amount (not much)
  450. uint32_t limit = ((0x80000000 / ((range + 1) >> 1)) - 1) * range;
  451. uint32_t v;
  452. while ((v = os_random()) >= limit) {
  453. }
  454. // Now v is uniformly distributed in [0, limit) and limit is a multiple of range
  455. return (v % range) + l;
  456. }
  457. static int node_random (lua_State *L) {
  458. int u;
  459. int l;
  460. switch (lua_gettop(L)) { /* check number of arguments */
  461. case 0: { /* no arguments */
  462. #ifdef LUA_NUMBER_INTEGRAL
  463. lua_pushnumber(L, 0); /* Number between 0 and 1 - always 0 with ints */
  464. #else
  465. lua_pushnumber(L, (lua_Number)os_random() / (lua_Number)(1LL << 32));
  466. #endif
  467. return 1;
  468. }
  469. case 1: { /* only upper limit */
  470. l = 1;
  471. u = luaL_checkint(L, 1);
  472. break;
  473. }
  474. case 2: { /* lower and upper limits */
  475. l = luaL_checkint(L, 1);
  476. u = luaL_checkint(L, 2);
  477. break;
  478. }
  479. default:
  480. return luaL_error(L, "wrong number of arguments");
  481. }
  482. luaL_argcheck(L, l<=u, 2, "interval is empty");
  483. lua_pushnumber(L, node_random_range(l, u)); /* int between `l' and `u' */
  484. return 1;
  485. }
  486. // Module function map
  487. static const LUA_REG_TYPE node_egc_map[] = {
  488. { LSTRKEY( "setmode" ), LFUNCVAL( node_egc_setmode ) },
  489. { LSTRKEY( "NOT_ACTIVE" ), LNUMVAL( EGC_NOT_ACTIVE ) },
  490. { LSTRKEY( "ON_ALLOC_FAILURE" ), LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
  491. { LSTRKEY( "ON_MEM_LIMIT" ), LNUMVAL( EGC_ON_MEM_LIMIT ) },
  492. { LSTRKEY( "ALWAYS" ), LNUMVAL( EGC_ALWAYS ) },
  493. { LNILKEY, LNILVAL }
  494. };
  495. static const LUA_REG_TYPE node_task_map[] = {
  496. { LSTRKEY( "post" ), LFUNCVAL( node_task_post ) },
  497. { LSTRKEY( "LOW_PRIORITY" ), LNUMVAL( TASK_PRIORITY_LOW ) },
  498. { LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) },
  499. { LSTRKEY( "HIGH_PRIORITY" ), LNUMVAL( TASK_PRIORITY_HIGH ) },
  500. { LNILKEY, LNILVAL }
  501. };
  502. static const LUA_REG_TYPE node_map[] =
  503. {
  504. { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
  505. { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
  506. #ifdef PMSLEEP_ENABLE
  507. { LSTRKEY( "sleep" ), LFUNCVAL( node_sleep ) },
  508. PMSLEEP_INT_MAP,
  509. #endif
  510. { LSTRKEY( "info" ), LFUNCVAL( node_info ) },
  511. { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) },
  512. { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) },
  513. { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },
  514. { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
  515. { LSTRKEY( "input" ), LFUNCVAL( node_input ) },
  516. { LSTRKEY( "output" ), LFUNCVAL( node_output ) },
  517. // Moved to adc module, use adc.readvdd33()
  518. // { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
  519. { LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
  520. { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) },
  521. { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) },
  522. { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) },
  523. { LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) },
  524. { LSTRKEY( "restore" ), LFUNCVAL( node_restore) },
  525. { LSTRKEY( "random" ), LFUNCVAL( node_random) },
  526. #ifdef LUA_OPTIMIZE_DEBUG
  527. { LSTRKEY( "stripdebug" ), LFUNCVAL( node_stripdebug ) },
  528. #endif
  529. { LSTRKEY( "egc" ), LROVAL( node_egc_map ) },
  530. { LSTRKEY( "task" ), LROVAL( node_task_map ) },
  531. #ifdef DEVELOPMENT_TOOLS
  532. { LSTRKEY( "osprint" ), LFUNCVAL( node_osprint ) },
  533. #endif
  534. // Combined to dsleep(us, option)
  535. // { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
  536. { LNILKEY, LNILVAL }
  537. };
  538. NODEMCU_MODULE(NODE, "node", node_map, NULL);