node.c 17 KB

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