From dd02faef273a73f31fa172c266ab01b322e39f7e Mon Sep 17 00:00:00 2001 From: dnc40085 Date: Sun, 20 May 2018 00:38:33 -0700 Subject: [PATCH] Add function node.getcpufreq() (#2375) --- app/modules/node.c | 8 ++++++++ docs/en/modules/node.md | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/modules/node.c b/app/modules/node.c index a00bafd7..3df88b8c 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -386,6 +386,13 @@ static int node_setcpufreq(lua_State* L) return 1; } +// Lua: freq = node.getcpufreq() +static int node_getcpufreq(lua_State* L) +{ + lua_pushinteger(L, system_get_cpu_freq()); + return 1; +} + // Lua: code, reason [, exccause, epc1, epc2, epc3, excvaddr, depc ] = bootreason() static int node_bootreason (lua_State *L) { @@ -622,6 +629,7 @@ static const LUA_REG_TYPE node_map[] = { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) }, { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) }, { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) }, + { LSTRKEY( "getcpufreq" ), LFUNCVAL( node_getcpufreq) }, { LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) }, { LSTRKEY( "restore" ), LFUNCVAL( node_restore) }, { LSTRKEY( "random" ), LFUNCVAL( node_random) }, diff --git a/docs/en/modules/node.md b/docs/en/modules/node.md index d8176ff9..823e7650 100644 --- a/docs/en/modules/node.md +++ b/docs/en/modules/node.md @@ -185,6 +185,27 @@ none #### Returns flash size in bytes (integer) +## node.getcpufreq() + +Get the current CPU Frequency. + +#### Syntax +`node.getcpufreq()` + +#### Parameters +none + +#### Returns +Current CPU frequency (number) + +#### Example +```lua +do + local cpuFreq = node.getcpufreq() + print("The current CPU frequency is " .. cpuFreq .. " MHz") +end +``` + ## node.heap() Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible.