node.setcpufreq, gpio speed, Os

add node.setcpufreq(80|160) copied from jrahlf
faster GPIO read/write
change optimization level to Os
fix chmod for fullmake.sh
This commit is contained in:
LaurynasL 2015-03-13 17:19:58 +02:00
parent 7dc36cea05
commit f8e8e5a198
3 changed files with 20 additions and 19 deletions

View File

@ -105,7 +105,7 @@ OBINS := $(GEN_BINS:%=$(BINODIR)/%)
CCFLAGS += \ CCFLAGS += \
-g \ -g \
-Ofast \ -Os \
-Wpointer-arith \ -Wpointer-arith \
-Wundef \ -Wundef \
-Werror \ -Werror \

View File

@ -121,28 +121,14 @@ static int lgpio_mode( lua_State* L )
// Lua: read( pin ) // Lua: read( pin )
static int lgpio_read( lua_State* L ) static int lgpio_read( lua_State* L )
{ {
unsigned pin; lua_pushinteger( L, platform_gpio_read( luaL_checkinteger( L, 1 ) ) );
pin = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( gpio, pin );
unsigned level = platform_gpio_read( pin );
lua_pushinteger( L, level );
return 1; return 1;
} }
// Lua: write( pin, level ) // Lua: write( pin, level )
static int lgpio_write( lua_State* L ) static int lgpio_write( lua_State* L )
{ {
unsigned level; platform_gpio_write(luaL_checkinteger( L, 1 ), luaL_checkinteger( L, 2 ) & 0x1);
unsigned pin;
pin = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( gpio, pin );
level = luaL_checkinteger( L, 2 );
if ( level!=HIGH && level!=LOW )
return luaL_error( L, "wrong arg type" );
platform_gpio_write(pin, level);
return 0; return 0;
} }

View File

@ -387,6 +387,22 @@ static int node_compile( lua_State* L )
return 0; return 0;
} }
// Lua: node.setcpufreq(int) -- change CPU frequency to 80 or 160 MHz, returns current frequency
static int node_set_cpu_freq( lua_State* L )
{
uint32_t new_freq = luaL_checkinteger( L, 1 );
if(new_freq == 160){
REG_SET_BIT(0x3ff00014, BIT(0));
os_update_cpu_frequency(160);
}else{
REG_CLR_BIT(0x3ff00014, BIT(0));
os_update_cpu_frequency(80);
}
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"
@ -407,8 +423,7 @@ 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) },
// Combined to dsleep(us, option) { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_set_cpu_freq ) },
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
#endif #endif