Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
dbc8d791
Commit
dbc8d791
authored
Mar 02, 2017
by
Johny Mattsson
Browse files
Added node.chipid() based on esptool's formula.
parent
602979bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
components/modules/node.c
View file @
dbc8d791
...
@@ -7,14 +7,33 @@
...
@@ -7,14 +7,33 @@
#include "vfs.h"
#include "vfs.h"
#include "esp_system.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_log.h"
#include "soc/efuse_reg.h"
#include "ldebug.h"
#include "ldebug.h"
// Lua: heap()
// Lua: node.chipid()
static
int
node_chipid
(
lua_State
*
L
)
{
// This matches the way esptool.py generates a chipid for the ESP32 as of
// esptool commit e9e9179f6fc3f2ecfc568987d3224b5e53a05f06
// Oddly, this drops the lowest byte what's effectively the MAC address, so
// it would seem plausible to encounter up to 256 chips with the same chipid
uint64_t
word16
=
REG_READ
(
EFUSE_BLK0_RDATA1_REG
);
uint64_t
word17
=
REG_READ
(
EFUSE_BLK0_RDATA2_REG
);
const
uint64_t
MAX_UINT24
=
0xffffff
;
uint64_t
cid
=
((
word17
&
MAX_UINT24
)
<<
24
)
|
((
word16
>>
8
)
&
MAX_UINT24
);
char
chipid
[
17
]
=
{
0
};
sprintf
(
chipid
,
"0x%llx"
,
cid
);
lua_pushstring
(
L
,
chipid
);
return
1
;
}
// Lua: node.heap()
static
int
node_heap
(
lua_State
*
L
)
static
int
node_heap
(
lua_State
*
L
)
{
{
uint32_t
sz
=
esp_get_free_heap_size
();
uint32_t
sz
=
esp_get_free_heap_size
();
lua_pushinteger
(
L
,
sz
);
lua_pushinteger
(
L
,
sz
);
return
1
;
return
1
;
}
}
static
int
node_restart
(
lua_State
*
L
)
static
int
node_restart
(
lua_State
*
L
)
...
@@ -147,6 +166,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u)
...
@@ -147,6 +166,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u)
return
0
;
return
0
;
}
}
#define toproto(L,i) (clvalue(L->top+(i))->l.p)
#define toproto(L,i) (clvalue(L->top+(i))->l.p)
// Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc
// Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc
static
int
node_compile
(
lua_State
*
L
)
static
int
node_compile
(
lua_State
*
L
)
...
@@ -280,6 +300,7 @@ static const LUA_REG_TYPE node_task_map[] = {
...
@@ -280,6 +300,7 @@ static const LUA_REG_TYPE node_task_map[] = {
static
const
LUA_REG_TYPE
node_map
[]
=
static
const
LUA_REG_TYPE
node_map
[]
=
{
{
{
LSTRKEY
(
"chipid"
),
LFUNCVAL
(
node_chipid
)
},
{
LSTRKEY
(
"compile"
),
LFUNCVAL
(
node_compile
)
},
{
LSTRKEY
(
"compile"
),
LFUNCVAL
(
node_compile
)
},
{
LSTRKEY
(
"dsleep"
),
LFUNCVAL
(
node_dsleep
)
},
{
LSTRKEY
(
"dsleep"
),
LFUNCVAL
(
node_dsleep
)
},
{
LSTRKEY
(
"egc"
),
LROVAL
(
node_egc_map
)
},
{
LSTRKEY
(
"egc"
),
LROVAL
(
node_egc_map
)
},
...
...
docs/en/modules/node.md
View file @
dbc8d791
...
@@ -56,7 +56,10 @@ Returns the ESP chip ID.
...
@@ -56,7 +56,10 @@ Returns the ESP chip ID.
none
none
#### Returns
#### Returns
chip ID (number)
chip ID (string)
Note that due to the chip id being a much larger value on the ESP32, it is
reported as a string now. E.g.
`"0x1818fe346a88"`
.
## node.compile()
## node.compile()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment