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
b648e9a8
Commit
b648e9a8
authored
Mar 17, 2015
by
Markus Gritsch
Browse files
Added node.setcpufreq(mhz) function.
This function allows setting the CPU frequency to node.CPU80MHZ or node.CPU160MHZ.
parent
abfdb58d
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/node.c
View file @
b648e9a8
...
@@ -25,6 +25,9 @@
...
@@ -25,6 +25,9 @@
#include "flash_fs.h"
#include "flash_fs.h"
#include "user_version.h"
#include "user_version.h"
#define CPU80MHZ 80
#define CPU160MHZ 160
// Lua: restart()
// Lua: restart()
static
int
node_restart
(
lua_State
*
L
)
static
int
node_restart
(
lua_State
*
L
)
{
{
...
@@ -391,6 +394,24 @@ static int node_compile( lua_State* L )
...
@@ -391,6 +394,24 @@ static int node_compile( lua_State* L )
return
0
;
return
0
;
}
}
// 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
));
os_update_cpu_frequency
(
CPU160MHZ
);
}
else
{
REG_CLR_BIT
(
0x3ff00014
,
BIT
(
0
));
os_update_cpu_frequency
(
CPU80MHZ
);
}
new_freq
=
ets_get_cpu_frequency
();
lua_pushinteger
(
L
,
new_freq
);
return
1
;
}
// Module function map
// Module function map
#define MIN_OPT_LEVEL 2
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
#include "lrodefs.h"
...
@@ -411,6 +432,9 @@ const LUA_REG_TYPE node_map[] =
...
@@ -411,6 +432,9 @@ const LUA_REG_TYPE node_map[] =
{
LSTRKEY
(
"output"
),
LFUNCVAL
(
node_output
)
},
{
LSTRKEY
(
"output"
),
LFUNCVAL
(
node_output
)
},
{
LSTRKEY
(
"readvdd33"
),
LFUNCVAL
(
node_readvdd33
)
},
{
LSTRKEY
(
"readvdd33"
),
LFUNCVAL
(
node_readvdd33
)
},
{
LSTRKEY
(
"compile"
),
LFUNCVAL
(
node_compile
)
},
{
LSTRKEY
(
"compile"
),
LFUNCVAL
(
node_compile
)
},
{
LSTRKEY
(
"CPU80MHZ"
),
LNUMVAL
(
CPU80MHZ
)
},
{
LSTRKEY
(
"CPU160MHZ"
),
LNUMVAL
(
CPU160MHZ
)
},
{
LSTRKEY
(
"setcpufreq"
),
LFUNCVAL
(
node_setcpufreq
)
},
// Combined to dsleep(us, option)
// Combined to dsleep(us, option)
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
#if LUA_OPTIMIZE_MEMORY > 0
#if LUA_OPTIMIZE_MEMORY > 0
...
@@ -428,5 +452,5 @@ LUALIB_API int luaopen_node( lua_State *L )
...
@@ -428,5 +452,5 @@ LUALIB_API int luaopen_node( lua_State *L )
// Add constants
// Add constants
return
1
;
return
1
;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
}
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