Commit c04f2578 authored by HuangRui's avatar HuangRui
Browse files

Updated SDK to v0.9.5 and optimized memory.

parent 0420b6d7
......@@ -20,13 +20,13 @@
static int ICACHE_FLASH_ATTR db_getregistry (lua_State *L) {
static int db_getregistry (lua_State *L) {
lua_pushvalue(L, LUA_REGISTRYINDEX);
return 1;
}
static int ICACHE_FLASH_ATTR db_getmetatable (lua_State *L) {
static int db_getmetatable (lua_State *L) {
luaL_checkany(L, 1);
if (!lua_getmetatable(L, 1)) {
lua_pushnil(L); /* no metatable */
......@@ -35,7 +35,7 @@ static int ICACHE_FLASH_ATTR db_getmetatable (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_setmetatable (lua_State *L) {
static int db_setmetatable (lua_State *L) {
int t = lua_type(L, 2);
luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
"nil or table expected");
......@@ -45,14 +45,14 @@ static int ICACHE_FLASH_ATTR db_setmetatable (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_getfenv (lua_State *L) {
static int db_getfenv (lua_State *L) {
luaL_checkany(L, 1);
lua_getfenv(L, 1);
return 1;
}
static int ICACHE_FLASH_ATTR db_setfenv (lua_State *L) {
static int db_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE);
lua_settop(L, 2);
if (lua_setfenv(L, 1) == 0)
......@@ -62,19 +62,19 @@ static int ICACHE_FLASH_ATTR db_setfenv (lua_State *L) {
}
static void ICACHE_FLASH_ATTR settabss (lua_State *L, const char *i, const char *v) {
static void settabss (lua_State *L, const char *i, const char *v) {
lua_pushstring(L, v);
lua_setfield(L, -2, i);
}
static void ICACHE_FLASH_ATTR settabsi (lua_State *L, const char *i, int v) {
static void settabsi (lua_State *L, const char *i, int v) {
lua_pushinteger(L, v);
lua_setfield(L, -2, i);
}
static lua_State *ICACHE_FLASH_ATTR getthread (lua_State *L, int *arg) {
static lua_State *getthread (lua_State *L, int *arg) {
if (lua_isthread(L, 1)) {
*arg = 1;
return lua_tothread(L, 1);
......@@ -86,7 +86,7 @@ static lua_State *ICACHE_FLASH_ATTR getthread (lua_State *L, int *arg) {
}
static void ICACHE_FLASH_ATTR treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
if (L == L1) {
lua_pushvalue(L, -2);
lua_remove(L, -3);
......@@ -97,7 +97,7 @@ static void ICACHE_FLASH_ATTR treatstackoption (lua_State *L, lua_State *L1, con
}
static int ICACHE_FLASH_ATTR db_getinfo (lua_State *L) {
static int db_getinfo (lua_State *L) {
lua_Debug ar;
int arg;
lua_State *L1 = getthread(L, &arg);
......@@ -142,7 +142,7 @@ static int ICACHE_FLASH_ATTR db_getinfo (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_getlocal (lua_State *L) {
static int db_getlocal (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
......@@ -163,7 +163,7 @@ static int ICACHE_FLASH_ATTR db_getlocal (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_setlocal (lua_State *L) {
static int db_setlocal (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
......@@ -177,7 +177,7 @@ static int ICACHE_FLASH_ATTR db_setlocal (lua_State *L) {
}
static int ICACHE_FLASH_ATTR auxupvalue (lua_State *L, int get) {
static int auxupvalue (lua_State *L, int get) {
const char *name;
int n = luaL_checkint(L, 2);
luaL_checktype(L, 1, LUA_TFUNCTION);
......@@ -190,12 +190,12 @@ static int ICACHE_FLASH_ATTR auxupvalue (lua_State *L, int get) {
}
static int ICACHE_FLASH_ATTR db_getupvalue (lua_State *L) {
static int db_getupvalue (lua_State *L) {
return auxupvalue(L, 1);
}
static int ICACHE_FLASH_ATTR db_setupvalue (lua_State *L) {
static int db_setupvalue (lua_State *L) {
luaL_checkany(L, 3);
return auxupvalue(L, 0);
}
......@@ -205,7 +205,7 @@ static int ICACHE_FLASH_ATTR db_setupvalue (lua_State *L) {
static const char KEY_HOOK = 'h';
static void ICACHE_FLASH_ATTR hookf (lua_State *L, lua_Debug *ar) {
static void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] =
{"call", "return", "line", "count", "tail return"};
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
......@@ -223,7 +223,7 @@ static void ICACHE_FLASH_ATTR hookf (lua_State *L, lua_Debug *ar) {
}
static int ICACHE_FLASH_ATTR makemask (const char *smask, int count) {
static int makemask (const char *smask, int count) {
int mask = 0;
if (c_strchr(smask, 'c')) mask |= LUA_MASKCALL;
if (c_strchr(smask, 'r')) mask |= LUA_MASKRET;
......@@ -233,7 +233,7 @@ static int ICACHE_FLASH_ATTR makemask (const char *smask, int count) {
}
static char *ICACHE_FLASH_ATTR unmakemask (int mask, char *smask) {
static char *unmakemask (int mask, char *smask) {
int i = 0;
if (mask & LUA_MASKCALL) smask[i++] = 'c';
if (mask & LUA_MASKRET) smask[i++] = 'r';
......@@ -243,7 +243,7 @@ static char *ICACHE_FLASH_ATTR unmakemask (int mask, char *smask) {
}
static void ICACHE_FLASH_ATTR gethooktable (lua_State *L) {
static void gethooktable (lua_State *L) {
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_istable(L, -1)) {
......@@ -256,7 +256,7 @@ static void ICACHE_FLASH_ATTR gethooktable (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_sethook (lua_State *L) {
static int db_sethook (lua_State *L) {
int arg, mask, count;
lua_Hook func;
lua_State *L1 = getthread(L, &arg);
......@@ -280,7 +280,7 @@ static int ICACHE_FLASH_ATTR db_sethook (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_gethook (lua_State *L) {
static int db_gethook (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
char buff[5];
......@@ -300,7 +300,7 @@ static int ICACHE_FLASH_ATTR db_gethook (lua_State *L) {
}
static int ICACHE_FLASH_ATTR db_debug (lua_State *L) {
static int db_debug (lua_State *L) {
for (;;) {
char buffer[LUA_MAXINPUT];
#if defined(LUA_USE_STDIO)
......@@ -329,7 +329,7 @@ static int ICACHE_FLASH_ATTR db_debug (lua_State *L) {
#define LEVELS1 12 /* size of the first part of the stack */
#define LEVELS2 10 /* size of the second part of the stack */
static int ICACHE_FLASH_ATTR db_errorfb (lua_State *L) {
static int db_errorfb (lua_State *L) {
int level;
int firstpart = 1; /* still before eventual `...' */
int arg;
......@@ -401,6 +401,6 @@ const LUA_REG_TYPE dblib[] = {
{LNILKEY, LNILVAL}
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_debug (lua_State *L) {
LUALIB_API int luaopen_debug (lua_State *L) {
LREGISTER(L, LUA_DBLIBNAME, dblib);
}
......@@ -10,7 +10,7 @@
#include "c_types.h"
// Lua: read(id) , return system adc
static int ICACHE_FLASH_ATTR adc_sample( lua_State* L )
static int adc_sample( lua_State* L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( adc, id );
......@@ -31,7 +31,7 @@ const LUA_REG_TYPE adc_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_adc( lua_State *L )
LUALIB_API int luaopen_adc( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -34,13 +34,13 @@ typedef size_t lua_UInteger;
*/
#define MONADIC(name, op) \
static int ICACHE_FLASH_ATTR bit_ ## name(lua_State *L) { \
static int bit_ ## name(lua_State *L) { \
lua_pushinteger(L, op TOBIT(L, 1)); \
return 1; \
}
#define VARIADIC(name, op) \
static int ICACHE_FLASH_ATTR bit_ ## name(lua_State *L) { \
static int bit_ ## name(lua_State *L) { \
int n = lua_gettop(L), i; \
lua_Integer w = TOBIT(L, 1); \
for (i = 2; i <= n; i++) \
......@@ -50,14 +50,14 @@ typedef size_t lua_UInteger;
}
#define LOGICAL_SHIFT(name, op) \
static int ICACHE_FLASH_ATTR bit_ ## name(lua_State *L) { \
static int bit_ ## name(lua_State *L) { \
lua_pushinteger(L, (lua_UInteger)TOBIT(L, 1) op \
(unsigned)luaL_checknumber(L, 2)); \
return 1; \
}
#define ARITHMETIC_SHIFT(name, op) \
static int ICACHE_FLASH_ATTR bit_ ## name(lua_State *L) { \
static int bit_ ## name(lua_State *L) { \
lua_pushinteger(L, (lua_Integer)TOBIT(L, 1) op \
(unsigned)luaL_checknumber(L, 2)); \
return 1; \
......@@ -72,14 +72,14 @@ LOGICAL_SHIFT(rshift, >>)
ARITHMETIC_SHIFT(arshift, >>)
// Lua: res = bit( position )
static int ICACHE_FLASH_ATTR bit_bit( lua_State* L )
static int bit_bit( lua_State* L )
{
lua_pushinteger( L, ( lua_Integer )( 1 << luaL_checkinteger( L, 1 ) ) );
return 1;
}
// Lua: res = isset( value, position )
static int ICACHE_FLASH_ATTR bit_isset( lua_State* L )
static int bit_isset( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
......@@ -89,7 +89,7 @@ static int ICACHE_FLASH_ATTR bit_isset( lua_State* L )
}
// Lua: res = isclear( value, position )
static int ICACHE_FLASH_ATTR bit_isclear( lua_State* L )
static int bit_isclear( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
......@@ -99,7 +99,7 @@ static int ICACHE_FLASH_ATTR bit_isclear( lua_State* L )
}
// Lua: res = set( value, pos1, pos2, ... )
static int ICACHE_FLASH_ATTR bit_set( lua_State* L )
static int bit_set( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned total = lua_gettop( L ), i;
......@@ -111,7 +111,7 @@ static int ICACHE_FLASH_ATTR bit_set( lua_State* L )
}
// Lua: res = clear( value, pos1, pos2, ... )
static int ICACHE_FLASH_ATTR bit_clear( lua_State* L )
static int bit_clear( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned total = lua_gettop( L ), i;
......@@ -140,6 +140,6 @@ const LUA_REG_TYPE bit_map[] = {
{ LNILKEY, LNILVAL}
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_bit (lua_State *L) {
LUALIB_API int luaopen_bit (lua_State *L) {
LREGISTER( L, "bit", bit_map );
}
......@@ -14,7 +14,7 @@
static int file_fd = FS_OPEN_OK - 1;
// Lua: open(filename, mode)
static int ICACHE_FLASH_ATTR file_open( lua_State* L )
static int file_open( lua_State* L )
{
size_t len;
if((FS_OPEN_OK - 1)!=file_fd){
......@@ -39,7 +39,7 @@ static int ICACHE_FLASH_ATTR file_open( lua_State* L )
}
// Lua: close()
static int ICACHE_FLASH_ATTR file_close( lua_State* L )
static int file_close( lua_State* L )
{
if((FS_OPEN_OK - 1)!=file_fd){
fs_close(file_fd);
......@@ -50,7 +50,7 @@ static int ICACHE_FLASH_ATTR file_close( lua_State* L )
#if defined(BUILD_WOFS)
// Lua: list()
static int ICACHE_FLASH_ATTR file_list( lua_State* L )
static int file_list( lua_State* L )
{
uint32_t start = 0;
size_t act_len = 0;
......@@ -64,7 +64,7 @@ static int ICACHE_FLASH_ATTR file_list( lua_State* L )
}
// Lua: format()
static int ICACHE_FLASH_ATTR file_format( lua_State* L )
static int file_format( lua_State* L )
{
size_t len;
file_close(L);
......@@ -84,7 +84,7 @@ static int ICACHE_FLASH_ATTR file_format( lua_State* L )
extern spiffs fs;
// Lua: list()
static int ICACHE_FLASH_ATTR file_list( lua_State* L )
static int file_list( lua_State* L )
{
spiffs_DIR d;
struct spiffs_dirent e;
......@@ -101,7 +101,7 @@ static int ICACHE_FLASH_ATTR file_list( lua_State* L )
return 1;
}
static int ICACHE_FLASH_ATTR file_seek (lua_State *L)
static int file_seek (lua_State *L)
{
static const int mode[] = {FS_SEEK_SET, FS_SEEK_CUR, FS_SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL};
......@@ -118,7 +118,7 @@ static int ICACHE_FLASH_ATTR file_seek (lua_State *L)
}
// Lua: remove(filename)
static int ICACHE_FLASH_ATTR file_remove( lua_State* L )
static int file_remove( lua_State* L )
{
size_t len;
const char *fname = luaL_checklstring( L, 1, &len );
......@@ -130,7 +130,7 @@ static int ICACHE_FLASH_ATTR file_remove( lua_State* L )
}
// Lua: flush()
static int ICACHE_FLASH_ATTR file_flush( lua_State* L )
static int file_flush( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
return luaL_error(L, "open a file first");
......@@ -142,7 +142,7 @@ static int ICACHE_FLASH_ATTR file_flush( lua_State* L )
}
#if 0
// Lua: check()
static int ICACHE_FLASH_ATTR file_check( lua_State* L )
static int file_check( lua_State* L )
{
file_close(L);
lua_pushinteger(L, fs_check());
......@@ -153,7 +153,7 @@ static int ICACHE_FLASH_ATTR file_check( lua_State* L )
#endif
// g_read()
static int ICACHE_FLASH_ATTR file_g_read( lua_State* L, int n, int16_t end_char )
static int file_g_read( lua_State* L, int n, int16_t end_char )
{
if(n< 0 || n>LUAL_BUFFERSIZE)
n = LUAL_BUFFERSIZE;
......@@ -197,7 +197,7 @@ static int ICACHE_FLASH_ATTR file_g_read( lua_State* L, int n, int16_t end_char
// file.read() will read all byte in file
// file.read(10) will read 10 byte from file, or EOF is reached.
// file.read('q') will read until 'q' or EOF is reached.
static int ICACHE_FLASH_ATTR file_read( lua_State* L )
static int file_read( lua_State* L )
{
unsigned need_len = LUAL_BUFFERSIZE;
int16_t end_char = EOF;
......@@ -222,13 +222,13 @@ static int ICACHE_FLASH_ATTR file_read( lua_State* L )
}
// Lua: readline()
static int ICACHE_FLASH_ATTR file_readline( lua_State* L )
static int file_readline( lua_State* L )
{
return file_g_read(L, LUAL_BUFFERSIZE, '\n');
}
// Lua: write("string")
static int ICACHE_FLASH_ATTR file_write( lua_State* L )
static int file_write( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
return luaL_error(L, "open a file first");
......@@ -243,7 +243,7 @@ static int ICACHE_FLASH_ATTR file_write( lua_State* L )
}
// Lua: writeline("string")
static int ICACHE_FLASH_ATTR file_writeline( lua_State* L )
static int file_writeline( lua_State* L )
{
if((FS_OPEN_OK - 1)==file_fd)
return luaL_error(L, "open a file first");
......@@ -290,7 +290,7 @@ const LUA_REG_TYPE file_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_file( lua_State *L )
LUALIB_API int luaopen_file( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -23,7 +23,7 @@
static int gpio_cb_ref[GPIO_PIN_NUM];
static lua_State* gL = NULL;
void ICACHE_FLASH_ATTR lua_gpio_unref(unsigned pin){
void lua_gpio_unref(unsigned pin){
if(gpio_cb_ref[pin] != LUA_NOREF){
if(gL!=NULL)
luaL_unref(gL, LUA_REGISTRYINDEX, gpio_cb_ref[pin]);
......@@ -31,7 +31,7 @@ void ICACHE_FLASH_ATTR lua_gpio_unref(unsigned pin){
gpio_cb_ref[pin] = LUA_NOREF;
}
void ICACHE_FLASH_ATTR gpio_intr_callback( unsigned pin, unsigned level )
void gpio_intr_callback( unsigned pin, unsigned level )
{
NODE_DBG("pin:%d, level:%d \n", pin, level);
if(gpio_cb_ref[pin] == LUA_NOREF)
......@@ -44,7 +44,7 @@ void ICACHE_FLASH_ATTR gpio_intr_callback( unsigned pin, unsigned level )
}
// Lua: trig( pin, type, function )
static int ICACHE_FLASH_ATTR lgpio_trig( lua_State* L )
static int lgpio_trig( lua_State* L )
{
unsigned type;
unsigned pin;
......@@ -87,7 +87,7 @@ static int ICACHE_FLASH_ATTR lgpio_trig( lua_State* L )
#endif
// Lua: mode( pin, mode, pullup )
static int ICACHE_FLASH_ATTR lgpio_mode( lua_State* L )
static int lgpio_mode( lua_State* L )
{
unsigned mode, pullup = FLOAT;
unsigned pin;
......@@ -119,7 +119,7 @@ static int ICACHE_FLASH_ATTR lgpio_mode( lua_State* L )
}
// Lua: read( pin )
static int ICACHE_FLASH_ATTR lgpio_read( lua_State* L )
static int lgpio_read( lua_State* L )
{
unsigned pin;
......@@ -132,7 +132,7 @@ static int ICACHE_FLASH_ATTR lgpio_read( lua_State* L )
}
// Lua: write( pin, level )
static int ICACHE_FLASH_ATTR lgpio_write( lua_State* L )
static int lgpio_write( lua_State* L )
{
unsigned level;
unsigned pin;
......@@ -171,7 +171,7 @@ const LUA_REG_TYPE gpio_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_gpio( lua_State *L )
LUALIB_API int luaopen_gpio( lua_State *L )
{
#ifdef GPIO_INTERRUPT_ENABLE
int i;
......
......@@ -8,7 +8,7 @@
#include "lrotable.h"
// Lua: speed = i2c.setup( id, sda, scl, speed )
static int ICACHE_FLASH_ATTR i2c_setup( lua_State *L )
static int i2c_setup( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
unsigned sda = luaL_checkinteger( L, 2 );
......@@ -29,7 +29,7 @@ static int ICACHE_FLASH_ATTR i2c_setup( lua_State *L )
}
// Lua: i2c.start( id )
static int ICACHE_FLASH_ATTR i2c_start( lua_State *L )
static int i2c_start( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
......@@ -39,7 +39,7 @@ static int ICACHE_FLASH_ATTR i2c_start( lua_State *L )
}
// Lua: i2c.stop( id )
static int ICACHE_FLASH_ATTR i2c_stop( lua_State *L )
static int i2c_stop( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
......@@ -49,7 +49,7 @@ static int ICACHE_FLASH_ATTR i2c_stop( lua_State *L )
}
// Lua: status = i2c.address( id, address, direction )
static int ICACHE_FLASH_ATTR i2c_address( lua_State *L )
static int i2c_address( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
int address = luaL_checkinteger( L, 2 );
......@@ -64,7 +64,7 @@ static int ICACHE_FLASH_ATTR i2c_address( lua_State *L )
// Lua: wrote = i2c.write( id, data1, [data2], ..., [datan] )
// data can be either a string, a table or an 8-bit number
static int ICACHE_FLASH_ATTR i2c_write( lua_State *L )
static int i2c_write( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
const char *pdata;
......@@ -122,7 +122,7 @@ static int ICACHE_FLASH_ATTR i2c_write( lua_State *L )
}
// Lua: read = i2c.read( id, size )
static int ICACHE_FLASH_ATTR i2c_read( lua_State *L )
static int i2c_read( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
u32 size = ( u32 )luaL_checkinteger( L, 2 ), i;
......@@ -162,7 +162,7 @@ const LUA_REG_TYPE i2c_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_i2c( lua_State *L )
LUALIB_API int luaopen_i2c( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -55,8 +55,7 @@ typedef struct lnet_userdata
#endif
}lnet_userdata;
static void ICACHE_FLASH_ATTR
net_server_disconnected(void *arg) // for tcp server only
static void net_server_disconnected(void *arg) // for tcp server only
{
NODE_DBG("net_server_disconnected is called.\n");
struct espconn *pesp_conn = arg;
......@@ -99,8 +98,7 @@ net_server_disconnected(void *arg) // for tcp server only
lua_gc(gL, LUA_GCRESTART, 0);
}
static void ICACHE_FLASH_ATTR
net_socket_disconnected(void *arg) // tcp only
static void net_socket_disconnected(void *arg) // tcp only
{
NODE_DBG("net_socket_disconnected is called.\n");
struct espconn *pesp_conn = arg;
......@@ -130,22 +128,19 @@ net_socket_disconnected(void *arg) // tcp only
lua_gc(gL, LUA_GCRESTART, 0);
}
static void ICACHE_FLASH_ATTR
net_server_reconnected(void *arg, sint8_t err)
static void net_server_reconnected(void *arg, sint8_t err)
{
NODE_DBG("net_server_reconnected is called.\n");
net_server_disconnected(arg);
}
static void ICACHE_FLASH_ATTR
net_socket_reconnected(void *arg, sint8_t err)
static void net_socket_reconnected(void *arg, sint8_t err)
{
NODE_DBG("net_socket_reconnected is called.\n");
net_socket_disconnected(arg);
}
static void ICACHE_FLASH_ATTR
net_socket_received(void *arg, char *pdata, unsigned short len)
static void net_socket_received(void *arg, char *pdata, unsigned short len)
{
NODE_DBG("net_socket_received is called.\n");
struct espconn *pesp_conn = arg;
......@@ -169,8 +164,7 @@ net_socket_received(void *arg, char *pdata, unsigned short len)
lua_call(gL, 2, 0);
}
static void ICACHE_FLASH_ATTR
net_socket_sent(void *arg)
static void net_socket_sent(void *arg)
{
// NODE_DBG("net_socket_sent is called.\n");
struct espconn *pesp_conn = arg;
......@@ -188,8 +182,7 @@ net_socket_sent(void *arg)
lua_call(gL, 1, 0);
}
static void ICACHE_FLASH_ATTR
net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
NODE_DBG("net_dns_found is called.\n");
struct espconn *pesp_conn = arg;
......@@ -242,8 +235,7 @@ net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
}
}
static void ICACHE_FLASH_ATTR
net_server_connected(void *arg) // for tcp only
static void net_server_connected(void *arg) // for tcp only
{
NODE_DBG("net_server_connected is called.\n");
struct espconn *pesp_conn = arg;
......@@ -324,8 +316,7 @@ net_server_connected(void *arg) // for tcp only
lua_call(gL, 1, 0); // function(conn)
}
static void ICACHE_FLASH_ATTR
net_socket_connected(void *arg)
static void net_socket_connected(void *arg)
{
NODE_DBG("net_socket_connected is called.\n");
struct espconn *pesp_conn = arg;
......@@ -349,8 +340,7 @@ net_socket_connected(void *arg)
}
// Lua: s = net.create(type, secure/timeout, function(conn))
static int ICACHE_FLASH_ATTR
net_create( lua_State* L, const char* mt )
static int net_create( lua_State* L, const char* mt )
{
NODE_DBG("net_create is called.\n");
struct espconn *pesp_conn = NULL;
......@@ -496,8 +486,7 @@ net_create( lua_State* L, const char* mt )
// call close() first
// server: disconnect server, unref everything
// socket: unref everything
static int ICACHE_FLASH_ATTR
net_delete( lua_State* L, const char* mt )
static int net_delete( lua_State* L, const char* mt )
{
NODE_DBG("net_delete is called.\n");
bool isserver = false;
......@@ -571,7 +560,7 @@ net_delete( lua_State* L, const char* mt )
return 0;
}
static void ICACHE_FLASH_ATTR socket_connect(struct espconn *pesp_conn)
static void socket_connect(struct espconn *pesp_conn)
{
if(pesp_conn == NULL)
return;
......@@ -600,8 +589,7 @@ static void ICACHE_FLASH_ATTR socket_connect(struct espconn *pesp_conn)
static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg);
static dns_reconn_count = 0;
static void ICACHE_FLASH_ATTR
socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
NODE_DBG("socket_dns_found is called.\n");
struct espconn *pesp_conn = arg;
......@@ -647,8 +635,7 @@ socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
// Lua: server:listen( port, ip, function(con) )
// Lua: socket:connect( port, ip, function(con) )
static int ICACHE_FLASH_ATTR
net_start( lua_State* L, const char* mt )
static int net_start( lua_State* L, const char* mt )
{
NODE_DBG("net_start is called.\n");
struct espconn *pesp_conn = NULL;
......@@ -819,8 +806,7 @@ net_start( lua_State* L, const char* mt )
// Lua: server/socket:close()
// server disconnect everything, unref everything
// client disconnect and unref itself
static int ICACHE_FLASH_ATTR
net_close( lua_State* L, const char* mt )
static int net_close( lua_State* L, const char* mt )
{
NODE_DBG("net_close is called.\n");
bool isserver = false;
......@@ -929,8 +915,7 @@ net_close( lua_State* L, const char* mt )
}
// Lua: socket/udpserver:on( "method", function(s) )
static int ICACHE_FLASH_ATTR
net_on( lua_State* L, const char* mt )
static int net_on( lua_State* L, const char* mt )
{
NODE_DBG("net_on is called.\n");
bool isserver = false;
......@@ -994,8 +979,7 @@ net_on( lua_State* L, const char* mt )
}
// Lua: server/socket:send( string, function(sent) )
static int ICACHE_FLASH_ATTR
net_send( lua_State* L, const char* mt )
static int net_send( lua_State* L, const char* mt )
{
// NODE_DBG("net_send is called.\n");
bool isserver = false;
......@@ -1061,8 +1045,7 @@ net_send( lua_State* L, const char* mt )
}
// Lua: socket:dns( string, function(socket, ip) )
static int ICACHE_FLASH_ATTR
net_dns( lua_State* L, const char* mt )
static int net_dns( lua_State* L, const char* mt )
{
NODE_DBG("net_dns is called.\n");
bool isserver = false;
......@@ -1115,111 +1098,98 @@ net_dns( lua_State* L, const char* mt )
// Lua: s = net.createServer(type, function(server))
static int ICACHE_FLASH_ATTR net_createServer( lua_State* L )
static int net_createServer( lua_State* L )
{
const char *mt = "net.server";
return net_create(L, mt);
}
// Lua: server:delete()
static int ICACHE_FLASH_ATTR
net_server_delete( lua_State* L )
static int net_server_delete( lua_State* L )
{
const char *mt = "net.server";
return net_delete(L, mt);
}
// Lua: server:listen( port, ip )
static int ICACHE_FLASH_ATTR
net_server_listen( lua_State* L )
static int net_server_listen( lua_State* L )
{
const char *mt = "net.server";
return net_start(L, mt);
}
// Lua: server:close()
static int ICACHE_FLASH_ATTR
net_server_close( lua_State* L )
static int net_server_close( lua_State* L )
{
const char *mt = "net.server";
return net_close(L, mt);
}
// Lua: udpserver:on( "method", function(udpserver) )
static int ICACHE_FLASH_ATTR
net_udpserver_on( lua_State* L )
static int net_udpserver_on( lua_State* L )
{
const char *mt = "net.server";
return net_on(L, mt);
}
// Lua: udpserver:send(string, function() )
static int ICACHE_FLASH_ATTR
net_udpserver_send( lua_State* L )
static int net_udpserver_send( lua_State* L )
{
const char *mt = "net.server";
return net_send(L, mt);;
}
// Lua: s = net.createConnection(type, function(conn))
static int ICACHE_FLASH_ATTR
net_createConnection( lua_State* L )
static int net_createConnection( lua_State* L )
{
const char *mt = "net.socket";
return net_create(L, mt);
}
// Lua: socket:delete()
static int ICACHE_FLASH_ATTR
net_socket_delete( lua_State* L )
static int net_socket_delete( lua_State* L )
{
const char *mt = "net.socket";
return net_delete(L, mt);
}
// Lua: socket:connect( port, ip )
static int ICACHE_FLASH_ATTR
net_socket_connect( lua_State* L )
static int net_socket_connect( lua_State* L )
{
const char *mt = "net.socket";
return net_start(L, mt);
}
// Lua: socket:close()
static int ICACHE_FLASH_ATTR
net_socket_close( lua_State* L )
static int net_socket_close( lua_State* L )
{
const char *mt = "net.socket";
return net_close(L, mt);
}
// Lua: socket:on( "method", function(socket) )
static int ICACHE_FLASH_ATTR
net_socket_on( lua_State* L )
static int net_socket_on( lua_State* L )
{
const char *mt = "net.socket";
return net_on(L, mt);
}
// Lua: socket:send( string, function() )
static int ICACHE_FLASH_ATTR
net_socket_send( lua_State* L )
static int net_socket_send( lua_State* L )
{
const char *mt = "net.socket";
return net_send(L, mt);
}
// Lua: socket:dns( string, function(ip) )
static int ICACHE_FLASH_ATTR
net_socket_dns( lua_State* L )
static int net_socket_dns( lua_State* L )
{
const char *mt = "net.socket";
return net_dns(L, mt);
}
#if 0
static int ICACHE_FLASH_ATTR
net_array_index( lua_State* L )
static int net_array_index( lua_State* L )
{
char** parray = luaL_checkudata(L, 1, "net.array");
int index = luaL_checkint(L, 2);
......@@ -1227,8 +1197,7 @@ net_array_index( lua_State* L )
return 1;
}
static int ICACHE_FLASH_ATTR
net_array_newindex( lua_State* L )
static int net_array_newindex( lua_State* L )
{
char** parray = luaL_checkudata(L, 1, "net.array");
int index = luaL_checkint(L, 2);
......@@ -1238,8 +1207,7 @@ net_array_newindex( lua_State* L )
}
// expose an array to lua, by storing it in a userdata with the array metatable
static int ICACHE_FLASH_ATTR
expose_array(lua_State* L, char *array, unsigned short len) {
static int expose_array(lua_State* L, char *array, unsigned short len) {
char** parray = lua_newuserdata(L, len);
*parray = array;
luaL_getmetatable(L, "net.array");
......@@ -1300,7 +1268,7 @@ const LUA_REG_TYPE net_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_net( lua_State *L )
LUALIB_API int luaopen_net( lua_State *L )
{
int i;
for(i=0;i<MAX_SOCKET;i++)
......
......@@ -15,14 +15,14 @@
#include "flash_api.h"
// Lua: restart()
static int ICACHE_FLASH_ATTR node_restart( lua_State* L )
static int node_restart( lua_State* L )
{
system_restart();
return 0;
}
// Lua: dsleep( us )
static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L )
static int node_deepsleep( lua_State* L )
{
s32 us;
us = luaL_checkinteger( L, 1 );
......@@ -33,7 +33,7 @@ static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L )
}
// Lua: info()
static int ICACHE_FLASH_ATTR node_info( lua_State* L )
static int node_info( lua_State* L )
{
lua_pushinteger(L, NODE_VERSION_MAJOR);
lua_pushinteger(L, NODE_VERSION_MINOR);
......@@ -47,7 +47,7 @@ static int ICACHE_FLASH_ATTR node_info( lua_State* L )
}
// Lua: chipid()
static int ICACHE_FLASH_ATTR node_chipid( lua_State* L )
static int node_chipid( lua_State* L )
{
uint32_t id = system_get_chip_id();
lua_pushinteger(L, id);
......@@ -55,7 +55,7 @@ static int ICACHE_FLASH_ATTR node_chipid( lua_State* L )
}
// Lua: flashid()
static int ICACHE_FLASH_ATTR node_flashid( lua_State* L )
static int node_flashid( lua_State* L )
{
uint32_t id = spi_flash_get_id();
lua_pushinteger( L, id );
......@@ -63,7 +63,7 @@ static int ICACHE_FLASH_ATTR node_flashid( lua_State* L )
}
// Lua: flashsize()
static int ICACHE_FLASH_ATTR node_flashsize( lua_State* L )
static int node_flashsize( lua_State* L )
{
//uint32_t sz = 0;
//if(lua_type(L, 1) == LUA_TNUMBER)
......@@ -80,7 +80,7 @@ static int ICACHE_FLASH_ATTR node_flashsize( lua_State* L )
}
// Lua: heap()
static int ICACHE_FLASH_ATTR node_heap( lua_State* L )
static int node_heap( lua_State* L )
{
uint32_t sz = system_get_free_heap_size();
lua_pushinteger(L, sz);
......@@ -90,7 +90,7 @@ static int ICACHE_FLASH_ATTR node_heap( lua_State* L )
extern int led_high_count; // this is defined in lua.c
extern int led_low_count;
// Lua: led(low, high)
static int ICACHE_FLASH_ATTR node_led( lua_State* L )
static int node_led( lua_State* L )
{
int low, high;
if ( lua_isnumber(L, 1) )
......@@ -120,7 +120,7 @@ static int long_key_ref = LUA_NOREF;
static int short_key_ref = LUA_NOREF;
static lua_State *gL = NULL;
void ICACHE_FLASH_ATTR default_long_press(void *arg){
void default_long_press(void *arg){
if(led_high_count == 12 && led_low_count == 12){
led_low_count = led_high_count = 6;
} else {
......@@ -131,11 +131,11 @@ void ICACHE_FLASH_ATTR default_long_press(void *arg){
// NODE_DBG("default_long_press is called. hc: %d, lc: %d\n", led_high_count, led_low_count);
}
void ICACHE_FLASH_ATTR default_short_press(void *arg){
void default_short_press(void *arg){
system_restart();
}
void ICACHE_FLASH_ATTR key_long_press(void *arg){
void key_long_press(void *arg){
NODE_DBG("key_long_press is called.\n");
if(long_key_ref == LUA_NOREF){
default_long_press(arg);
......@@ -147,7 +147,7 @@ void ICACHE_FLASH_ATTR key_long_press(void *arg){
lua_call(gL, 0, 0);
}
void ICACHE_FLASH_ATTR key_short_press(void *arg){
void key_short_press(void *arg){
NODE_DBG("key_short_press is called.\n");
if(short_key_ref == LUA_NOREF){
default_short_press(arg);
......@@ -160,7 +160,7 @@ void ICACHE_FLASH_ATTR key_short_press(void *arg){
}
// Lua: key(type, function)
static int ICACHE_FLASH_ATTR node_key( lua_State* L )
static int node_key( lua_State* L )
{
int *ref = NULL;
size_t sl;
......@@ -196,7 +196,7 @@ extern lua_Load gLoad;
extern os_timer_t lua_timer;
extern void dojob(lua_Load *load);
// Lua: input("string")
static int ICACHE_FLASH_ATTR node_input( lua_State* L )
static int node_input( lua_State* L )
{
size_t l=0;
const char *s = luaL_checklstring(L, 1, &l);
......@@ -221,7 +221,7 @@ static int ICACHE_FLASH_ATTR node_input( lua_State* L )
static int output_redir_ref = LUA_NOREF;
static int serial_debug = 1;
void ICACHE_FLASH_ATTR output_redirect(const char *str){
void output_redirect(const char *str){
// if(c_strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n");
// return;
......@@ -242,7 +242,7 @@ void ICACHE_FLASH_ATTR output_redirect(const char *str){
}
// Lua: output(function(c), debug)
static int ICACHE_FLASH_ATTR node_output( lua_State* L )
static int node_output( lua_State* L )
{
gL = L;
// luaL_checkanyfunction(L, 1);
......@@ -293,7 +293,7 @@ const LUA_REG_TYPE node_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_node( lua_State *L )
LUALIB_API int luaopen_node( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -8,7 +8,7 @@
#include "driver/onewire.h"
// Lua: ow.setup( id )
static int ICACHE_FLASH_ATTR ow_setup( lua_State *L )
static int ow_setup( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
......@@ -22,7 +22,7 @@ static int ICACHE_FLASH_ATTR ow_setup( lua_State *L )
}
// Lua: r = ow.reset( id )
static int ICACHE_FLASH_ATTR ow_reset( lua_State *L )
static int ow_reset( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -31,7 +31,7 @@ static int ICACHE_FLASH_ATTR ow_reset( lua_State *L )
}
// Lua: ow.skip( id )
static int ICACHE_FLASH_ATTR ow_skip( lua_State *L )
static int ow_skip( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR ow_skip( lua_State *L )
}
// Lua: ow.select( id, buf[8])
static int ICACHE_FLASH_ATTR ow_select( lua_State *L )
static int ow_select( lua_State *L )
{
uint8_t rom[8];
size_t datalen;
......@@ -79,7 +79,7 @@ static int ICACHE_FLASH_ATTR ow_select( lua_State *L )
}
// Lua: ow.write( id, v, power)
static int ICACHE_FLASH_ATTR ow_write( lua_State *L )
static int ow_write( lua_State *L )
{
int power = 0;
unsigned id = luaL_checkinteger( L, 1 );
......@@ -99,7 +99,7 @@ static int ICACHE_FLASH_ATTR ow_write( lua_State *L )
}
// Lua: ow.write_bytes( id, buf, power)
static int ICACHE_FLASH_ATTR ow_write_bytes( lua_State *L )
static int ow_write_bytes( lua_State *L )
{
int power = 0;
size_t datalen;
......@@ -119,7 +119,7 @@ static int ICACHE_FLASH_ATTR ow_write_bytes( lua_State *L )
}
// Lua: r = ow.read( id )
static int ICACHE_FLASH_ATTR ow_read( lua_State *L )
static int ow_read( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -128,7 +128,7 @@ static int ICACHE_FLASH_ATTR ow_read( lua_State *L )
}
// Lua: r = ow.read_bytes( id, size )
static int ICACHE_FLASH_ATTR ow_read_bytes( lua_State *L )
static int ow_read_bytes( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -148,7 +148,7 @@ static int ICACHE_FLASH_ATTR ow_read_bytes( lua_State *L )
}
// Lua: ow.depower( id )
static int ICACHE_FLASH_ATTR ow_depower( lua_State *L )
static int ow_depower( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -159,7 +159,7 @@ static int ICACHE_FLASH_ATTR ow_depower( lua_State *L )
#if ONEWIRE_SEARCH
// Clear the search state so that if will start from the beginning again.
// Lua: ow.reset_search( id )
static int ICACHE_FLASH_ATTR ow_reset_search( lua_State *L )
static int ow_reset_search( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -171,7 +171,7 @@ static int ICACHE_FLASH_ATTR ow_reset_search( lua_State *L )
// Setup the search to find the device type 'family_code' on the next call
// to search(*newAddr) if it is present.
// Lua: ow.target_search( id, family_code)
static int ICACHE_FLASH_ATTR ow_target_search( lua_State *L )
static int ow_target_search( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -193,7 +193,7 @@ static int ICACHE_FLASH_ATTR ow_target_search( lua_State *L )
// the same devices in the same order.
// Lua: r = ow.search( id )
static int ICACHE_FLASH_ATTR ow_search( lua_State *L )
static int ow_search( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
......@@ -217,7 +217,7 @@ static int ICACHE_FLASH_ATTR ow_search( lua_State *L )
#if ONEWIRE_CRC
// uint8_t onewire_crc8(const uint8_t *addr, uint8_t len);
// Lua: r = ow.crc8( buf )
static int ICACHE_FLASH_ATTR ow_crc8( lua_State *L )
static int ow_crc8( lua_State *L )
{
size_t datalen;
const uint8_t *pdata = luaL_checklstring( L, 1, &datalen );
......@@ -230,7 +230,7 @@ static int ICACHE_FLASH_ATTR ow_crc8( lua_State *L )
#if ONEWIRE_CRC16
// bool onewire_check_crc16(const uint8_t* input, uint16_t len, const uint8_t* inverted_crc, uint16_t crc);
// Lua: b = ow.check_crc16( buf, inverted_crc0, inverted_crc1, crc )
static int ICACHE_FLASH_ATTR ow_check_crc16( lua_State *L )
static int ow_check_crc16( lua_State *L )
{
size_t datalen;
uint8_t inverted_crc[2];
......@@ -262,7 +262,7 @@ static int ICACHE_FLASH_ATTR ow_check_crc16( lua_State *L )
// uint16_t onewire_crc16(const uint8_t* input, uint16_t len, uint16_t crc);
// Lua: r = ow.crc16( buf, crc )
static int ICACHE_FLASH_ATTR ow_crc16( lua_State *L )
static int ow_crc16( lua_State *L )
{
size_t datalen;
const uint8_t *pdata = luaL_checklstring( L, 1, &datalen );
......@@ -313,7 +313,7 @@ const LUA_REG_TYPE ow_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_ow( lua_State *L )
LUALIB_API int luaopen_ow( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -10,7 +10,7 @@
#include "c_types.h"
// Lua: realfrequency = setup( id, frequency, duty )
static int ICACHE_FLASH_ATTR lpwm_setup( lua_State* L )
static int lpwm_setup( lua_State* L )
{
s32 freq; // signed, to error check for negative values
unsigned duty;
......@@ -35,7 +35,7 @@ static int ICACHE_FLASH_ATTR lpwm_setup( lua_State* L )
}
// Lua: close( id )
static int ICACHE_FLASH_ATTR lpwm_close( lua_State* L )
static int lpwm_close( lua_State* L )
{
unsigned id;
......@@ -46,7 +46,7 @@ static int ICACHE_FLASH_ATTR lpwm_close( lua_State* L )
}
// Lua: start( id )
static int ICACHE_FLASH_ATTR lpwm_start( lua_State* L )
static int lpwm_start( lua_State* L )
{
unsigned id;
id = luaL_checkinteger( L, 1 );
......@@ -56,7 +56,7 @@ static int ICACHE_FLASH_ATTR lpwm_start( lua_State* L )
}
// Lua: stop( id )
static int ICACHE_FLASH_ATTR lpwm_stop( lua_State* L )
static int lpwm_stop( lua_State* L )
{
unsigned id;
......@@ -67,7 +67,7 @@ static int ICACHE_FLASH_ATTR lpwm_stop( lua_State* L )
}
// Lua: realclock = setclock( id, clock )
static int ICACHE_FLASH_ATTR lpwm_setclock( lua_State* L )
static int lpwm_setclock( lua_State* L )
{
unsigned id;
s32 clk; // signed to error-check for negative values
......@@ -83,7 +83,7 @@ static int ICACHE_FLASH_ATTR lpwm_setclock( lua_State* L )
}
// Lua: clock = getclock( id )
static int ICACHE_FLASH_ATTR lpwm_getclock( lua_State* L )
static int lpwm_getclock( lua_State* L )
{
unsigned id;
u32 clk;
......@@ -96,7 +96,7 @@ static int ICACHE_FLASH_ATTR lpwm_getclock( lua_State* L )
}
// Lua: realduty = setduty( id, duty )
static int ICACHE_FLASH_ATTR lpwm_setduty( lua_State* L )
static int lpwm_setduty( lua_State* L )
{
unsigned id;
s32 duty; // signed to error-check for negative values
......@@ -112,7 +112,7 @@ static int ICACHE_FLASH_ATTR lpwm_setduty( lua_State* L )
}
// Lua: duty = getduty( id )
static int ICACHE_FLASH_ATTR lpwm_getduty( lua_State* L )
static int lpwm_getduty( lua_State* L )
{
unsigned id;
u32 duty;
......@@ -143,7 +143,7 @@ const LUA_REG_TYPE pwm_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_pwm( lua_State *L )
LUALIB_API int luaopen_pwm( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -12,57 +12,50 @@
static os_timer_t alarm_timer[NUM_TMR];
static int alarm_timer_cb_ref[NUM_TMR] = {LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF};
void ICACHE_FLASH_ATTR alarm_timer_common(lua_State* L, unsigned id){
void alarm_timer_common(lua_State* L, unsigned id){
if(alarm_timer_cb_ref[id] == LUA_NOREF)
return;
lua_rawgeti(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]);
lua_call(L, 0, 0);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb0(void *arg){
void alarm_timer_cb0(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 0);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb1(void *arg){
void alarm_timer_cb1(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 1);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb2(void *arg){
void alarm_timer_cb2(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 2);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb3(void *arg){
void alarm_timer_cb3(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 3);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb4(void *arg){
void alarm_timer_cb4(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 4);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb5(void *arg){
void alarm_timer_cb5(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 5);
}
void ICACHE_FLASH_ATTR
alarm_timer_cb6(void *arg){
void alarm_timer_cb6(void *arg){
if( !arg )
return;
alarm_timer_common((lua_State*)arg, 6);
......@@ -72,7 +65,7 @@ typedef void (*alarm_timer_callback)(void *arg);
static alarm_timer_callback alarm_timer_cb[NUM_TMR] = {alarm_timer_cb0,alarm_timer_cb1,alarm_timer_cb2,alarm_timer_cb3,alarm_timer_cb4,alarm_timer_cb5,alarm_timer_cb6};
// Lua: delay( us )
static int ICACHE_FLASH_ATTR tmr_delay( lua_State* L )
static int tmr_delay( lua_State* L )
{
s32 us;
us = luaL_checkinteger( L, 1 );
......@@ -91,7 +84,7 @@ static int ICACHE_FLASH_ATTR tmr_delay( lua_State* L )
}
// Lua: now() , return system timer in us
static int ICACHE_FLASH_ATTR tmr_now( lua_State* L )
static int tmr_now( lua_State* L )
{
unsigned now = 0x7FFFFFFF & system_get_time();
lua_pushinteger( L, now );
......@@ -99,7 +92,7 @@ static int ICACHE_FLASH_ATTR tmr_now( lua_State* L )
}
// Lua: alarm( id, interval, repeat, function )
static int ICACHE_FLASH_ATTR tmr_alarm( lua_State* L )
static int tmr_alarm( lua_State* L )
{
s32 interval;
unsigned repeat = 0;
......@@ -136,7 +129,7 @@ static int ICACHE_FLASH_ATTR tmr_alarm( lua_State* L )
}
// Lua: stop( id )
static int ICACHE_FLASH_ATTR tmr_stop( lua_State* L )
static int tmr_stop( lua_State* L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( tmr, id );
......@@ -147,7 +140,7 @@ static int ICACHE_FLASH_ATTR tmr_stop( lua_State* L )
// extern void update_key_led();
// Lua: wdclr()
static int ICACHE_FLASH_ATTR tmr_wdclr( lua_State* L )
static int tmr_wdclr( lua_State* L )
{
WRITE_PERI_REG(0x60000914, 0x73);
// update_key_led();
......@@ -155,7 +148,7 @@ static int ICACHE_FLASH_ATTR tmr_wdclr( lua_State* L )
}
// Lua: time() , return rtc time in us
static int ICACHE_FLASH_ATTR tmr_time( lua_State* L )
static int tmr_time( lua_State* L )
{
unsigned t = 0xFFFFFFFF & system_get_rtc_time();
unsigned c = 0xFFFFFFFF & system_rtc_clock_cali_proc();
......@@ -181,7 +174,7 @@ const LUA_REG_TYPE tmr_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_tmr( lua_State *L )
LUALIB_API int luaopen_tmr( lua_State *L )
{
int i = 0;
for(i=0;i<NUM_TMR;i++){
......
......@@ -13,7 +13,7 @@
static lua_State *gL = NULL;
static int uart_receive_rf = LUA_NOREF;
bool run_input = true;
bool ICACHE_FLASH_ATTR uart_on_data_cb(const char *buf, size_t len){
bool uart_on_data_cb(const char *buf, size_t len){
if(!buf || len==0)
return false;
if(uart_receive_rf == LUA_NOREF)
......@@ -29,7 +29,7 @@ bool ICACHE_FLASH_ATTR uart_on_data_cb(const char *buf, size_t len){
uint16_t need_len = 0;
int16_t end_char = -1;
// Lua: uart.on("method", [number/char], function, [run_input])
static int ICACHE_FLASH_ATTR uart_on( lua_State* L )
static int uart_on( lua_State* L )
{
size_t sl, el;
int32_t run = 1;
......@@ -160,7 +160,7 @@ const LUA_REG_TYPE uart_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_uart( lua_State *L )
LUALIB_API int luaopen_uart( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -15,7 +15,7 @@
static int wifi_smart_succeed = LUA_NOREF;
static void ICACHE_FLASH_ATTR wifi_smart_succeed_cb(void *arg){
static void wifi_smart_succeed_cb(void *arg){
NODE_DBG("wifi_smart_succeed_cb is called.\n");
if( !arg )
return;
......@@ -34,8 +34,7 @@ static lua_State* gL = NULL;
* @param status: scan over status
* @retval None
*/
static void ICACHE_FLASH_ATTR
wifi_scan_done(void *arg, STATUS status)
static void wifi_scan_done(void *arg, STATUS status)
{
uint8 ssid[33];
char temp[128];
......@@ -82,7 +81,7 @@ wifi_scan_done(void *arg, STATUS status)
}
// Lua: smart(channel, function succeed_cb)
static int ICACHE_FLASH_ATTR wifi_start_smart( lua_State* L )
static int wifi_start_smart( lua_State* L )
{
unsigned channel;
int stack = 1;
......@@ -114,7 +113,7 @@ static int ICACHE_FLASH_ATTR wifi_start_smart( lua_State* L )
}
// Lua: exit_smart(channel)
static int ICACHE_FLASH_ATTR wifi_exit_smart( lua_State* L )
static int wifi_exit_smart( lua_State* L )
{
smart_end();
if(wifi_smart_succeed != LUA_NOREF)
......@@ -124,7 +123,7 @@ static int ICACHE_FLASH_ATTR wifi_exit_smart( lua_State* L )
}
// Lua: realmode = setmode(mode)
static int ICACHE_FLASH_ATTR wifi_setmode( lua_State* L )
static int wifi_setmode( lua_State* L )
{
unsigned mode;
......@@ -139,7 +138,7 @@ static int ICACHE_FLASH_ATTR wifi_setmode( lua_State* L )
}
// Lua: realmode = getmode()
static int ICACHE_FLASH_ATTR wifi_getmode( lua_State* L )
static int wifi_getmode( lua_State* L )
{
unsigned mode;
mode = (unsigned)wifi_get_opmode();
......@@ -149,7 +148,7 @@ static int ICACHE_FLASH_ATTR wifi_getmode( lua_State* L )
// Lua: mac = wifi.xx.getmac()
static int ICACHE_FLASH_ATTR wifi_getmac( lua_State* L, uint8_t mode )
static int wifi_getmac( lua_State* L, uint8_t mode )
{
char temp[64];
uint8_t mac[6];
......@@ -160,7 +159,7 @@ static int ICACHE_FLASH_ATTR wifi_getmac( lua_State* L, uint8_t mode )
}
// Lua: mac = wifi.xx.setmac()
static int ICACHE_FLASH_ATTR wifi_setmac( lua_State* L, uint8_t mode )
static int wifi_setmac( lua_State* L, uint8_t mode )
{
unsigned len = 0;
const char *mac = luaL_checklstring( L, 1, &len );
......@@ -172,7 +171,7 @@ static int ICACHE_FLASH_ATTR wifi_setmac( lua_State* L, uint8_t mode )
}
// Lua: ip = wifi.xx.getip()
static int ICACHE_FLASH_ATTR wifi_getip( lua_State* L, uint8_t mode )
static int wifi_getip( lua_State* L, uint8_t mode )
{
struct ip_info pTempIp;
char temp[64];
......@@ -204,7 +203,7 @@ static uint32_t parse_key(lua_State* L, const char * key){
}
// Lua: ip = wifi.xx.setip()
static int ICACHE_FLASH_ATTR wifi_setip( lua_State* L, uint8_t mode )
static int wifi_setip( lua_State* L, uint8_t mode )
{
struct ip_info pTempIp;
wifi_get_ip_info(mode, &pTempIp);
......@@ -228,7 +227,7 @@ static int ICACHE_FLASH_ATTR wifi_setip( lua_State* L, uint8_t mode )
}
// Lua: realtype = sleeptype(type)
static int ICACHE_FLASH_ATTR wifi_sleeptype( lua_State* L )
static int wifi_sleeptype( lua_State* L )
{
unsigned type;
......@@ -248,27 +247,27 @@ static int ICACHE_FLASH_ATTR wifi_sleeptype( lua_State* L )
}
// Lua: wifi.sta.getmac()
static int ICACHE_FLASH_ATTR wifi_station_getmac( lua_State* L ){
static int wifi_station_getmac( lua_State* L ){
return wifi_getmac(L, STATION_IF);
}
// Lua: wifi.sta.setmac()
static int ICACHE_FLASH_ATTR wifi_station_setmac( lua_State* L ){
static int wifi_station_setmac( lua_State* L ){
return wifi_setmac(L, STATION_IF);
}
// Lua: wifi.sta.getip()
static int ICACHE_FLASH_ATTR wifi_station_getip( lua_State* L ){
static int wifi_station_getip( lua_State* L ){
return wifi_getip(L, STATION_IF);
}
// Lua: wifi.sta.setip()
static int ICACHE_FLASH_ATTR wifi_station_setip( lua_State* L ){
static int wifi_station_setip( lua_State* L ){
return wifi_setip(L, STATION_IF);
}
// Lua: wifi.sta.config(ssid, password)
static int ICACHE_FLASH_ATTR wifi_station_config( lua_State* L )
static int wifi_station_config( lua_State* L )
{
size_t sl, pl;
struct station_config sta_conf;
......@@ -301,21 +300,21 @@ static int ICACHE_FLASH_ATTR wifi_station_config( lua_State* L )
}
// Lua: wifi.sta.connect()
static int ICACHE_FLASH_ATTR wifi_station_connect4lua( lua_State* L )
static int wifi_station_connect4lua( lua_State* L )
{
wifi_station_connect();
return 0;
}
// Lua: wifi.sta.disconnect()
static int ICACHE_FLASH_ATTR wifi_station_disconnect4lua( lua_State* L )
static int wifi_station_disconnect4lua( lua_State* L )
{
wifi_station_disconnect();
return 0;
}
// Lua: wifi.sta.auto(true/false)
static int ICACHE_FLASH_ATTR wifi_station_setauto( lua_State* L )
static int wifi_station_setauto( lua_State* L )
{
unsigned a;
......@@ -330,7 +329,7 @@ static int ICACHE_FLASH_ATTR wifi_station_setauto( lua_State* L )
return 0;
}
static int ICACHE_FLASH_ATTR wifi_station_listap( lua_State* L )
static int wifi_station_listap( lua_State* L )
{
if(wifi_get_opmode() == SOFTAP_MODE)
{
......@@ -352,7 +351,7 @@ static int ICACHE_FLASH_ATTR wifi_station_listap( lua_State* L )
}
// Lua: wifi.sta.status()
static int ICACHE_FLASH_ATTR wifi_station_status( lua_State* L )
static int wifi_station_status( lua_State* L )
{
uint8_t status = wifi_station_get_connect_status();
lua_pushinteger( L, status );
......@@ -360,27 +359,27 @@ static int ICACHE_FLASH_ATTR wifi_station_status( lua_State* L )
}
// Lua: wifi.ap.getmac()
static int ICACHE_FLASH_ATTR wifi_ap_getmac( lua_State* L ){
static int wifi_ap_getmac( lua_State* L ){
return wifi_getmac(L, SOFTAP_IF);
}
// Lua: wifi.ap.setmac()
static int ICACHE_FLASH_ATTR wifi_ap_setmac( lua_State* L ){
static int wifi_ap_setmac( lua_State* L ){
return wifi_setmac(L, SOFTAP_IF);
}
// Lua: wifi.ap.getip()
static int ICACHE_FLASH_ATTR wifi_ap_getip( lua_State* L ){
static int wifi_ap_getip( lua_State* L ){
return wifi_getip(L, SOFTAP_IF);
}
// Lua: wifi.ap.setip()
static int ICACHE_FLASH_ATTR wifi_ap_setip( lua_State* L ){
static int wifi_ap_setip( lua_State* L ){
return wifi_setip(L, SOFTAP_IF);
}
// Lua: wifi.ap.config(table)
static int ICACHE_FLASH_ATTR wifi_ap_config( lua_State* L )
static int wifi_ap_config( lua_State* L )
{
struct softap_config config;
size_t len;
......@@ -495,7 +494,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_wifi( lua_State *L )
LUALIB_API int luaopen_wifi( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
......
......@@ -5,7 +5,7 @@
#include "c_string.h"
#include "c_stdio.h"
void ICACHE_FLASH_ATTR cmn_platform_init(void)
void cmn_platform_init(void)
{
}
......@@ -13,7 +13,7 @@ void ICACHE_FLASH_ATTR cmn_platform_init(void)
// ****************************************************************************
// GPIO functions
int ICACHE_FLASH_ATTR platform_gpio_exists( unsigned pin )
int platform_gpio_exists( unsigned pin )
{
return pin < NUM_GPIO;
}
......@@ -21,7 +21,7 @@ int ICACHE_FLASH_ATTR platform_gpio_exists( unsigned pin )
// ****************************************************************************
// CAN functions
int ICACHE_FLASH_ATTR platform_can_exists( unsigned id )
int platform_can_exists( unsigned id )
{
return id < NUM_CAN;
}
......@@ -30,7 +30,7 @@ int ICACHE_FLASH_ATTR platform_can_exists( unsigned id )
// SPI functions
int ICACHE_FLASH_ATTR platform_spi_exists( unsigned id )
int platform_spi_exists( unsigned id )
{
return id < NUM_SPI;
}
......@@ -38,7 +38,7 @@ int ICACHE_FLASH_ATTR platform_spi_exists( unsigned id )
// ****************************************************************************
// PWM functions
int ICACHE_FLASH_ATTR platform_pwm_exists( unsigned id )
int platform_pwm_exists( unsigned id )
{
return ((id < NUM_PWM) && (id > 0));
}
......@@ -46,7 +46,7 @@ int ICACHE_FLASH_ATTR platform_pwm_exists( unsigned id )
// ****************************************************************************
// ADC functions
int ICACHE_FLASH_ATTR platform_adc_exists( unsigned id )
int platform_adc_exists( unsigned id )
{
return id < NUM_ADC;
}
......@@ -54,7 +54,7 @@ int ICACHE_FLASH_ATTR platform_adc_exists( unsigned id )
// ****************************************************************************
// UART functions
int ICACHE_FLASH_ATTR platform_uart_exists( unsigned id )
int platform_uart_exists( unsigned id )
{
return id < NUM_UART;
}
......@@ -62,7 +62,7 @@ int ICACHE_FLASH_ATTR platform_uart_exists( unsigned id )
// ****************************************************************************
// OneWire functions
int ICACHE_FLASH_ATTR platform_ow_exists( unsigned id )
int platform_ow_exists( unsigned id )
{
return ((id < NUM_OW) && (id > 0));
}
......@@ -70,13 +70,13 @@ int ICACHE_FLASH_ATTR platform_ow_exists( unsigned id )
// ****************************************************************************
// Timer functions
int ICACHE_FLASH_ATTR platform_tmr_exists( unsigned id )
int platform_tmr_exists( unsigned id )
{
return id < NUM_TMR;
}
// I2C support
int ICACHE_FLASH_ATTR platform_i2c_exists( unsigned id )
int platform_i2c_exists( unsigned id )
{
#ifndef NUM_I2C
return 0;
......@@ -99,7 +99,7 @@ extern char _flash_used_end[];
// Helper function: find the flash sector in which an address resides
// Return the sector number, as well as the start and end address of the sector
static uint32_t ICACHE_FLASH_ATTR flashh_find_sector( uint32_t address, uint32_t *pstart, uint32_t *pend )
static uint32_t flashh_find_sector( uint32_t address, uint32_t *pstart, uint32_t *pend )
{
address -= INTERNAL_FLASH_START_ADDRESS;
#ifdef INTERNAL_FLASH_SECTOR_SIZE
......@@ -127,12 +127,12 @@ static uint32_t ICACHE_FLASH_ATTR flashh_find_sector( uint32_t address, uint32_t
#endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE
}
uint32_t ICACHE_FLASH_ATTR platform_flash_get_sector_of_address( uint32_t addr )
uint32_t platform_flash_get_sector_of_address( uint32_t addr )
{
return flashh_find_sector( addr, NULL, NULL );
}
uint32_t ICACHE_FLASH_ATTR platform_flash_get_num_sectors(void)
uint32_t platform_flash_get_num_sectors(void)
{
#ifdef INTERNAL_FLASH_SECTOR_SIZE
return INTERNAL_FLASH_SIZE / INTERNAL_FLASH_SECTOR_SIZE;
......@@ -143,7 +143,7 @@ uint32_t ICACHE_FLASH_ATTR platform_flash_get_num_sectors(void)
#endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE
}
uint32_t ICACHE_FLASH_ATTR platform_flash_get_first_free_block_address( uint32_t *psect )
uint32_t platform_flash_get_first_free_block_address( uint32_t *psect )
{
// Round the total used flash size to the closest flash block address
uint32_t start, end, sect;
......@@ -162,7 +162,7 @@ uint32_t ICACHE_FLASH_ATTR platform_flash_get_first_free_block_address( uint32_t
}
}
uint32_t ICACHE_FLASH_ATTR platform_flash_write( const void *from, uint32_t toaddr, uint32_t size )
uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size )
{
#ifndef INTERNAL_FLASH_WRITE_UNIT_SIZE
return platform_s_flash_write( from, toaddr, size );
......@@ -212,7 +212,7 @@ uint32_t ICACHE_FLASH_ATTR platform_flash_write( const void *from, uint32_t toad
#endif // #ifndef INTERNAL_FLASH_WRITE_UNIT_SIZE
}
uint32_t ICACHE_FLASH_ATTR platform_flash_read( void *to, uint32_t fromaddr, uint32_t size )
uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size )
{
#ifndef INTERNAL_FLASH_READ_UNIT_SIZE
return platform_s_flash_read( to, fromaddr, size );
......
......@@ -7,74 +7,69 @@
#include "flash_api.h"
#include "spi_flash.h"
SPIFlashInfo *ICACHE_FLASH_ATTR
flash_get_info(void)
{
static SPIFlashInfo spi_flash_info NODE_STORE_ATTR;
static bool is_spi_flash_info_initialized = false;
// Make the code more fast
if (!is_spi_flash_info_initialized)
{
SPIRead(0, &spi_flash_info, sizeof(spi_flash_info));
is_spi_flash_info_initialized = true;
}
// return (SPIFlashInfo *)(0x40200000);
return &spi_flash_info;
static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_FLASH_ATTR =
{
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
0x04, 0xFE, 0xFD, 0xFF, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE1, 0x0A, 0xFF, 0xFF, 0xF8, 0x00,
0xF8, 0xF8, 0x52, 0x4E, 0x4A, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE1, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
SPIFlashInfo flash_get_info(void)
{
volatile SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR;
spi_flash_info = *((SPIFlashInfo *)(FLASH_MAP_START_ADDRESS));
return spi_flash_info;
}
uint8_t ICACHE_FLASH_ATTR
flash_get_size(void)
uint8_t flash_get_size(void)
{
SPIFlashInfo *p_spi_flash_info = flash_get_info();
return p_spi_flash_info->size;
return flash_get_info().size;
}
uint32_t ICACHE_FLASH_ATTR
flash_get_size_byte(void)
uint32_t flash_get_size_byte(void)
{
static uint32_t flash_size = 0;
// Make the code more fast
if (flash_size == 0 )
uint32_t flash_size = 0;
switch (flash_get_info().size)
{
SPIFlashInfo *p_spi_flash_info = flash_get_info();
switch (p_spi_flash_info->size)
{
case SIZE_2MBIT:
// 2Mbit, 256kByte
flash_size = 256 * 1024;
break;
case SIZE_4MBIT:
// 4Mbit, 512kByte
flash_size = 512 * 1024;
break;
case SIZE_8MBIT:
// 8Mbit, 1MByte
flash_size = 1 * 1024 * 1024;
break;
case SIZE_16MBIT:
// 16Mbit, 2MByte
flash_size = 2 * 1024 * 1024;
break;
case SIZE_32MBIT:
// 32Mbit, 4MByte
flash_size = 4 * 1024 * 1024;
break;
default:
// Unknown flash size, fall back mode.
flash_size = 512 * 1024;
break;
}
case SIZE_2MBIT:
// 2Mbit, 256kByte
flash_size = 256 * 1024;
break;
case SIZE_4MBIT:
// 4Mbit, 512kByte
flash_size = 512 * 1024;
break;
case SIZE_8MBIT:
// 8Mbit, 1MByte
flash_size = 1 * 1024 * 1024;
break;
case SIZE_16MBIT:
// 16Mbit, 2MByte
flash_size = 2 * 1024 * 1024;
break;
case SIZE_32MBIT:
// 32Mbit, 4MByte
flash_size = 4 * 1024 * 1024;
break;
default:
// Unknown flash size, fall back mode.
flash_size = 512 * 1024;
break;
}
return flash_size;
}
bool ICACHE_FLASH_ATTR
flash_set_size(uint8_t size)
bool flash_set_size(uint8_t size)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
uint8_t data[SPI_FLASH_SEC_SIZE] NODE_STORE_ATTR;
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
SPIRead(0, data, sizeof(data));
SPIFlashInfo *p_spi_flash_info = (SPIFlashInfo *)(data);
p_spi_flash_info->size = size;
......@@ -85,8 +80,7 @@ flash_set_size(uint8_t size)
return true;
}
bool ICACHE_FLASH_ATTR
flash_set_size_byte(uint32_t size)
bool flash_set_size_byte(uint32_t size)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
......@@ -128,23 +122,15 @@ flash_set_size_byte(uint32_t size)
return result;
}
uint16_t ICACHE_FLASH_ATTR
flash_get_sec_num(void)
uint16_t flash_get_sec_num(void)
{
static uint16_t result = 0;
// Make the code more fast
if (result == 0 )
{
result = flash_get_size_byte() / SPI_FLASH_SEC_SIZE;
}
return result;
return flash_get_size_byte() / SPI_FLASH_SEC_SIZE;
}
uint8_t ICACHE_FLASH_ATTR
flash_get_mode(void)
uint8_t flash_get_mode(void)
{
SPIFlashInfo *p_spi_flash_info = flash_get_info();
switch (p_spi_flash_info->mode)
SPIFlashInfo spi_flash_info = flash_get_info();
switch (spi_flash_info.mode)
{
// Reserved for future use
case MODE_QIO:
......@@ -156,15 +142,14 @@ flash_get_mode(void)
case MODE_DOUT:
break;
}
return p_spi_flash_info->mode;
return spi_flash_info.mode;
}
uint32_t ICACHE_FLASH_ATTR
flash_get_speed(void)
uint32_t flash_get_speed(void)
{
uint32_t speed = 0;
SPIFlashInfo *p_spi_flash_info = flash_get_info();
switch (p_spi_flash_info->speed)
SPIFlashInfo spi_flash_info = flash_get_info();
switch (spi_flash_info.speed)
{
case SPEED_40MHZ:
// 40MHz
......@@ -186,8 +171,7 @@ flash_get_speed(void)
return speed;
}
bool ICACHE_FLASH_ATTR
flash_init_data_default(void)
bool flash_init_data_default(void)
{
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
......@@ -195,12 +179,11 @@ flash_init_data_default(void)
// It will init system data to default!
SPIEraseSector((flash_get_sec_num() - 4));
SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, 0x10000 - SPI_FLASH_SEC_SIZE + (0), 128);
SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32_t *)flash_init_data, 128);
return true;
}
bool ICACHE_FLASH_ATTR
flash_init_data_blank(void)
bool flash_init_data_blank(void)
{
// FLASH SEC - 2
// Dangerous, here are dinosaur infested!!!!!
......@@ -211,8 +194,7 @@ flash_init_data_blank(void)
return true;
}
bool ICACHE_FLASH_ATTR
flash_self_destruct(void)
bool flash_self_destruct(void)
{
// Erase your flash. Good bye!
SPIEraseChip();
......
......@@ -2,6 +2,8 @@
#define __FLASH_API_H__
#include "ets_sys.h"
#include "user_config.h"
#include "cpu_esp8266.h"
#define FLASH_MAP_START_ADDRESS (INTERNAL_FLASH_START_ADDRESS)
typedef struct
{
......@@ -29,9 +31,9 @@ typedef struct
SIZE_16MBIT = 3,
SIZE_32MBIT = 4,
} size : 4;
} NODE_STORE_TYPEDEF_ATTR SPIFlashInfo;
} ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo;
SPIFlashInfo *flash_get_info(void);
SPIFlashInfo flash_get_info(void);
uint8_t flash_get_size(void);
uint32_t flash_get_size_byte(void);
bool flash_set_size(uint8_t);
......
......@@ -7,7 +7,7 @@
#include "spiffs.h"
#endif
int ICACHE_FLASH_ATTR fs_mode2flag(const char *mode){
int fs_mode2flag(const char *mode){
if(c_strlen(mode)==1){
if(c_strcmp(mode,"w")==0)
return FS_WRONLY|FS_CREAT|FS_TRUNC;
......
......@@ -11,7 +11,7 @@
static void pwms_init();
int ICACHE_FLASH_ATTR platform_init()
int platform_init()
{
// Setup PWMs
pwms_init();
......@@ -23,7 +23,7 @@ int ICACHE_FLASH_ATTR platform_init()
// ****************************************************************************
// KEY_LED functions
uint8_t ICACHE_FLASH_ATTR platform_key_led( uint8_t level){
uint8_t platform_key_led( uint8_t level){
uint8_t temp;
gpio16_output_set(1); // set to high first, for reading key low level
gpio16_input_conf();
......@@ -38,7 +38,7 @@ uint8_t ICACHE_FLASH_ATTR platform_key_led( uint8_t level){
#ifdef GPIO_INTERRUPT_ENABLE
extern void lua_gpio_unref(unsigned pin);
#endif
int ICACHE_FLASH_ATTR platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
{
// NODE_DBG("Function platform_gpio_mode() is called. pin_mux:%d, func:%d\n",pin_mux[pin],pin_func[pin]);
if (pin >= NUM_GPIO)
......@@ -108,7 +108,7 @@ int ICACHE_FLASH_ATTR platform_gpio_mode( unsigned pin, unsigned mode, unsigned
return 1;
}
int ICACHE_FLASH_ATTR platform_gpio_write( unsigned pin, unsigned level )
int platform_gpio_write( unsigned pin, unsigned level )
{
// NODE_DBG("Function platform_gpio_write() is called. pin:%d, level:%d\n",GPIO_ID_PIN(pin_num[pin]),level);
if (pin >= NUM_GPIO)
......@@ -122,7 +122,7 @@ int ICACHE_FLASH_ATTR platform_gpio_write( unsigned pin, unsigned level )
GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), level);
}
int ICACHE_FLASH_ATTR platform_gpio_read( unsigned pin )
int platform_gpio_read( unsigned pin )
{
// NODE_DBG("Function platform_gpio_read() is called. pin:%d\n",GPIO_ID_PIN(pin_num[pin]));
if (pin >= NUM_GPIO)
......@@ -138,7 +138,7 @@ int ICACHE_FLASH_ATTR platform_gpio_read( unsigned pin )
}
#ifdef GPIO_INTERRUPT_ENABLE
static void ICACHE_FLASH_ATTR platform_gpio_intr_dispatcher( platform_gpio_intr_handler_fn_t cb){
static void platform_gpio_intr_dispatcher( platform_gpio_intr_handler_fn_t cb){
uint8 i, level;
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
for (i = 0; i < GPIO_PIN_NUM; i++) {
......@@ -156,12 +156,12 @@ static void ICACHE_FLASH_ATTR platform_gpio_intr_dispatcher( platform_gpio_intr_
}
}
void ICACHE_FLASH_ATTR platform_gpio_init( platform_gpio_intr_handler_fn_t cb )
void platform_gpio_init( platform_gpio_intr_handler_fn_t cb )
{
ETS_GPIO_INTR_ATTACH(platform_gpio_intr_dispatcher, cb);
}
int ICACHE_FLASH_ATTR platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type )
int platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type )
{
if (pin >= NUM_GPIO)
return -1;
......@@ -181,7 +181,7 @@ int ICACHE_FLASH_ATTR platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
uint32_t ICACHE_FLASH_ATTR platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
{
switch( baud )
{
......@@ -262,7 +262,7 @@ void platform_uart_send( unsigned id, u8 data )
static uint16_t pwms_duty[NUM_PWM] = {0};
static void ICACHE_FLASH_ATTR pwms_init()
static void pwms_init()
{
int i;
for(i=0;i<NUM_PWM;i++){
......@@ -276,7 +276,7 @@ static void ICACHE_FLASH_ATTR pwms_init()
// NOTE: Can't find a function to query for the period set for the timer,
// therefore using the struct.
// This may require adjustment if driver libraries are updated.
uint32_t ICACHE_FLASH_ATTR platform_pwm_get_clock( unsigned pin )
uint32_t platform_pwm_get_clock( unsigned pin )
{
// NODE_DBG("Function platform_pwm_get_clock() is called.\n");
if( pin >= NUM_PWM)
......@@ -288,7 +288,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_clock( unsigned pin )
}
// Set the PWM clock
uint32_t ICACHE_FLASH_ATTR platform_pwm_set_clock( unsigned pin, uint32_t clock )
uint32_t platform_pwm_set_clock( unsigned pin, uint32_t clock )
{
// NODE_DBG("Function platform_pwm_set_clock() is called.\n");
if( pin >= NUM_PWM)
......@@ -301,7 +301,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_set_clock( unsigned pin, uint32_t clock
return (uint32_t)pwm_get_freq( pin );
}
uint32_t ICACHE_FLASH_ATTR platform_pwm_get_duty( unsigned pin )
uint32_t platform_pwm_get_duty( unsigned pin )
{
// NODE_DBG("Function platform_pwm_get_duty() is called.\n");
if( pin < NUM_PWM){
......@@ -314,7 +314,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_duty( unsigned pin )
}
// Set the PWM duty
uint32_t ICACHE_FLASH_ATTR platform_pwm_set_duty( unsigned pin, uint32_t duty )
uint32_t platform_pwm_set_duty( unsigned pin, uint32_t duty )
{
// NODE_DBG("Function platform_pwm_set_duty() is called.\n");
if ( pin < NUM_PWM)
......@@ -330,7 +330,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_set_duty( unsigned pin, uint32_t duty )
return pwms_duty[pin];
}
uint32_t ICACHE_FLASH_ATTR platform_pwm_setup( unsigned pin, uint32_t frequency, unsigned duty )
uint32_t platform_pwm_setup( unsigned pin, uint32_t frequency, unsigned duty )
{
uint32_t clock;
if ( pin < NUM_PWM)
......@@ -350,7 +350,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_setup( unsigned pin, uint32_t frequency,
return clock;
}
void ICACHE_FLASH_ATTR platform_pwm_close( unsigned pin )
void platform_pwm_close( unsigned pin )
{
// NODE_DBG("Function platform_pwm_stop() is called.\n");
if ( pin < NUM_PWM)
......@@ -360,7 +360,7 @@ void ICACHE_FLASH_ATTR platform_pwm_close( unsigned pin )
}
}
void ICACHE_FLASH_ATTR platform_pwm_start( unsigned pin )
void platform_pwm_start( unsigned pin )
{
// NODE_DBG("Function platform_pwm_start() is called.\n");
if ( pin < NUM_PWM)
......@@ -372,7 +372,7 @@ void ICACHE_FLASH_ATTR platform_pwm_start( unsigned pin )
}
}
void ICACHE_FLASH_ATTR platform_pwm_stop( unsigned pin )
void platform_pwm_stop( unsigned pin )
{
// NODE_DBG("Function platform_pwm_stop() is called.\n");
if ( pin < NUM_PWM)
......@@ -387,7 +387,7 @@ void ICACHE_FLASH_ATTR platform_pwm_stop( unsigned pin )
// *****************************************************************************
// I2C platform interface
uint32_t ICACHE_FLASH_ATTR platform_i2c_setup( unsigned id, uint8_t sda, uint8_t scl, uint32_t speed ){
uint32_t platform_i2c_setup( unsigned id, uint8_t sda, uint8_t scl, uint32_t speed ){
if (sda >= NUM_GPIO || scl >= NUM_GPIO)
return 0;
......@@ -402,15 +402,15 @@ uint32_t ICACHE_FLASH_ATTR platform_i2c_setup( unsigned id, uint8_t sda, uint8_t
return PLATFORM_I2C_SPEED_SLOW;
}
void ICACHE_FLASH_ATTR platform_i2c_send_start( unsigned id ){
void platform_i2c_send_start( unsigned id ){
i2c_master_start();
}
void ICACHE_FLASH_ATTR platform_i2c_send_stop( unsigned id ){
void platform_i2c_send_stop( unsigned id ){
i2c_master_stop();
}
int ICACHE_FLASH_ATTR platform_i2c_send_address( unsigned id, uint16_t address, int direction ){
int platform_i2c_send_address( unsigned id, uint16_t address, int direction ){
// Convert enum codes to R/w bit value.
// If TX == 0 and RX == 1, this test will be removed by the compiler
if ( ! ( PLATFORM_I2C_DIRECTION_TRANSMITTER == 0 &&
......@@ -423,13 +423,13 @@ int ICACHE_FLASH_ATTR platform_i2c_send_address( unsigned id, uint16_t address,
return ! i2c_master_getAck();
}
int ICACHE_FLASH_ATTR platform_i2c_send_byte( unsigned id, uint8_t data ){
int platform_i2c_send_byte( unsigned id, uint8_t data ){
i2c_master_writeByte(data);
// Low-level returns nack (0=acked); we return ack (1=acked).
return ! i2c_master_getAck();
}
int ICACHE_FLASH_ATTR platform_i2c_recv_byte( unsigned id, int ack ){
int platform_i2c_recv_byte( unsigned id, int ack ){
uint8_t r = i2c_master_readByte();
i2c_master_setAck( !ack );
return r;
......@@ -438,7 +438,7 @@ int ICACHE_FLASH_ATTR platform_i2c_recv_byte( unsigned id, int ack ){
// ****************************************************************************
// Flash access functions
uint32_t ICACHE_FLASH_ATTR platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size )
uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size )
{
toaddr -= INTERNAL_FLASH_START_ADDRESS;
SpiFlashOpResult r;
......@@ -462,7 +462,7 @@ uint32_t ICACHE_FLASH_ATTR platform_s_flash_write( const void *from, uint32_t to
}
}
uint32_t ICACHE_FLASH_ATTR platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
{
fromaddr -= INTERNAL_FLASH_START_ADDRESS;
SpiFlashOpResult r;
......@@ -476,7 +476,7 @@ uint32_t ICACHE_FLASH_ATTR platform_s_flash_read( void *to, uint32_t fromaddr, u
}
}
int ICACHE_FLASH_ATTR platform_flash_erase_sector( uint32_t sector_id )
int platform_flash_erase_sector( uint32_t sector_id )
{
WRITE_PERI_REG(0x60000914, 0x73);
return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR;
......
......@@ -32,7 +32,7 @@ static smart_succeed succeed = NULL;
static void *smart_succeed_arg = NULL;
void smart_end();
int ICACHE_FLASH_ATTR smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, uint8_t *got){
int smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, uint8_t *got){
if(len == 0)
return 0;
uint16_t dst_len = len/NIBBLE_PER_BYTE;
......@@ -127,7 +127,7 @@ int ICACHE_FLASH_ATTR smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, u
return res;
}
void ICACHE_FLASH_ATTR detect(uint8 *buf, uint16 len){
void detect(uint8 *buf, uint16 len){
uint16_t seq;
int16_t seq_delta = 0;
uint16_t byte_num = 0, bit_num = 0;
......@@ -435,7 +435,7 @@ end:
return;
}
void ICACHE_FLASH_ATTR reset_map(smart_addr_map **am, size_t num){
void reset_map(smart_addr_map **am, size_t num){
int i;
for (i = 0; i < num; ++i)
{
......@@ -461,15 +461,15 @@ void ICACHE_FLASH_ATTR reset_map(smart_addr_map **am, size_t num){
}
}
void ICACHE_FLASH_ATTR smart_enable(void){
void smart_enable(void){
wifi_promiscuous_enable(1);
}
void ICACHE_FLASH_ATTR smart_disable(void){
void smart_disable(void){
wifi_promiscuous_enable(0);
}
void ICACHE_FLASH_ATTR smart_end(){
void smart_end(){
int i;
os_timer_disarm(&smart_timer);
smart_disable();
......@@ -532,7 +532,7 @@ void ICACHE_FLASH_ATTR smart_end(){
// system_restart(); // restart to enable the mode
}
void ICACHE_FLASH_ATTR smart_next_channel(){
void smart_next_channel(){
smart_disable();
switch(cur_channel){
case 1:
......@@ -586,7 +586,7 @@ void ICACHE_FLASH_ATTR smart_next_channel(){
smart_enable();
}
void ICACHE_FLASH_ATTR smart_begin(int chnl, smart_succeed s, void *arg){
void smart_begin(int chnl, smart_succeed s, void *arg){
int i;
alldone = 0;
for (i = 0; i < ADDR_MAP_NUM; ++i)
......@@ -674,7 +674,7 @@ void ICACHE_FLASH_ATTR smart_begin(int chnl, smart_succeed s, void *arg){
smart_enable();
}
void ICACHE_FLASH_ATTR station_check_connect(bool smart){
void station_check_connect(bool smart){
mode = wifi_get_opmode();
if( (STATION_MODE != mode) && (mode != STATIONAP_MODE) ){
return;
......
......@@ -10,17 +10,17 @@ static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
static u8_t spiffs_fds[32*4];
static u8_t spiffs_cache[(LOG_PAGE_SIZE+32)*4];
static s32_t ICACHE_FLASH_ATTR my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) {
static s32_t my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) {
platform_flash_read(dst, addr, size);
return SPIFFS_OK;
}
static s32_t ICACHE_FLASH_ATTR my_spiffs_write(u32_t addr, u32_t size, u8_t *src) {
static s32_t my_spiffs_write(u32_t addr, u32_t size, u8_t *src) {
platform_flash_write(src, addr, size);
return SPIFFS_OK;
}
static s32_t ICACHE_FLASH_ATTR my_spiffs_erase(u32_t addr, u32_t size) {
static s32_t my_spiffs_erase(u32_t addr, u32_t size) {
u32_t sect_first = platform_flash_get_sector_of_address(addr);
u32_t sect_last = sect_first;
while( sect_first <= sect_last )
......@@ -42,7 +42,7 @@ The small 4KB sectors allow for greater flexibility in applications th
********************/
void ICACHE_FLASH_ATTR spiffs_mount() {
void spiffs_mount() {
spiffs_config cfg;
cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL );
cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS );
......@@ -69,7 +69,7 @@ void ICACHE_FLASH_ATTR spiffs_mount() {
// FS formatting function
// Returns 1 if OK, 0 for error
int ICACHE_FLASH_ATTR myspiffs_format( void )
int myspiffs_format( void )
{
SPIFFS_unmount(&fs);
u32_t sect_first, sect_last;
......@@ -84,7 +84,7 @@ int ICACHE_FLASH_ATTR myspiffs_format( void )
return 1;
}
int ICACHE_FLASH_ATTR myspiffs_check( void )
int myspiffs_check( void )
{
// ets_wdt_disable();
// int res = (int)SPIFFS_check(&fs);
......@@ -92,15 +92,15 @@ int ICACHE_FLASH_ATTR myspiffs_check( void )
// return res;
}
int ICACHE_FLASH_ATTR myspiffs_open(const char *name, int flags){
int myspiffs_open(const char *name, int flags){
return (int)SPIFFS_open(&fs, name, (spiffs_flags)flags, 0);
}
int ICACHE_FLASH_ATTR myspiffs_close( int fd ){
int myspiffs_close( int fd ){
SPIFFS_close(&fs, (spiffs_file)fd);
return 0;
}
size_t ICACHE_FLASH_ATTR myspiffs_write( int fd, const void* ptr, size_t len ){
size_t myspiffs_write( int fd, const void* ptr, size_t len ){
#if 0
if(fd==c_stdout || fd==c_stderr){
uart0_tx_buffer((u8_t*)ptr, len);
......@@ -109,39 +109,39 @@ size_t ICACHE_FLASH_ATTR myspiffs_write( int fd, const void* ptr, size_t len ){
#endif
return SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
}
size_t ICACHE_FLASH_ATTR myspiffs_read( int fd, void* ptr, size_t len){
size_t myspiffs_read( int fd, void* ptr, size_t len){
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
}
int ICACHE_FLASH_ATTR myspiffs_lseek( int fd, int off, int whence ){
int myspiffs_lseek( int fd, int off, int whence ){
return SPIFFS_lseek(&fs, (spiffs_file)fd, off, whence);
}
int ICACHE_FLASH_ATTR myspiffs_eof( int fd ){
int myspiffs_eof( int fd ){
return SPIFFS_eof(&fs, (spiffs_file)fd);
}
int ICACHE_FLASH_ATTR myspiffs_tell( int fd ){
int myspiffs_tell( int fd ){
return SPIFFS_tell(&fs, (spiffs_file)fd);
}
int ICACHE_FLASH_ATTR myspiffs_getc( int fd ){
int myspiffs_getc( int fd ){
char c = EOF;
if(!myspiffs_eof(fd)){
SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
}
return (int)c;
}
int ICACHE_FLASH_ATTR myspiffs_ungetc( int c, int fd ){
int myspiffs_ungetc( int c, int fd ){
return SPIFFS_lseek(&fs, (spiffs_file)fd, -1, SEEK_CUR);
}
int ICACHE_FLASH_ATTR myspiffs_flush( int fd ){
int myspiffs_flush( int fd ){
return SPIFFS_fflush(&fs, (spiffs_file)fd);
}
int ICACHE_FLASH_ATTR myspiffs_error( int fd ){
int myspiffs_error( int fd ){
return SPIFFS_errno(&fs);
}
void ICACHE_FLASH_ATTR myspiffs_clearerr( int fd ){
void myspiffs_clearerr( int fd ){
fs.errno = SPIFFS_OK;
}
#if 0
void ICACHE_FLASH_ATTR test_spiffs() {
void test_spiffs() {
char buf[12];
// Surely, I've mounted spiffs before entering here
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment