Commit bf3463d0 authored by zeroday's avatar zeroday
Browse files

Merge pull request #75 from nodemcu/dev095

Dev095
parents 0a3702f8 729603fa
......@@ -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 );
......
......@@ -6,38 +6,36 @@
#include "user_config.h"
#include "flash_api.h"
#include "spi_flash.h"
#include "c_stdio.h"
SPIFlashInfo *ICACHE_FLASH_ATTR
flash_get_info(void)
static volatile const uint8_t flash_init_data[128] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
{
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;
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 )
{
SPIFlashInfo *p_spi_flash_info = flash_get_info();
switch (p_spi_flash_info->size)
uint32_t flash_size = 0;
switch (flash_get_info().size)
{
case SIZE_2MBIT:
// 2Mbit, 256kByte
......@@ -64,29 +62,26 @@ flash_get_size_byte(void)
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;
SPIEraseSector(0);
SPIWrite(data, 0, sizeof(data));
spi_flash_write(0, (uint32 *)data, sizeof(data));
//p_spi_flash_info = flash_get_info();
//p_spi_flash_info->size = 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 +123,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 +143,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 +172,21 @@ flash_get_speed(void)
return speed;
}
bool ICACHE_FLASH_ATTR
flash_init_data_default(void)
bool flash_init_data_written(void)
{
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// It will init system data to default!
uint32_t data[2] ICACHE_STORE_ATTR;
SPIRead((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, data, sizeof(data));
if(data[0] == 0xFFFFFFFF && data[1] == 0xFFFFFFFF) {
return false;
}
return true;
}
bool flash_init_data_default(void)
{
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
......@@ -195,12 +194,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);
spi_flash_write((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)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 +209,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);
......@@ -39,6 +41,7 @@ bool flash_set_size_byte(uint32_t);
uint16_t flash_get_sec_num(void);
uint8_t flash_get_mode(void);
uint32_t flash_get_speed(void);
bool flash_init_data_written(void);
bool flash_init_data_default(void);
bool flash_init_data_blank(void);
bool flash_self_destruct(void);
......
......@@ -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
......
......@@ -11,7 +11,7 @@
#if SPIFFS_CACHE
// returns cached page for give page index, or null if no such cached page
static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) {
static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) {
spiffs_cache *cache = spiffs_get_cache(fs);
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) return 0;
int i;
......@@ -30,7 +30,7 @@ static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get(spiffs *fs, sp
}
// frees cached page
static s32_t ICACHE_FLASH_ATTR spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) {
static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) {
s32_t res = SPIFFS_OK;
spiffs_cache *cache = spiffs_get_cache(fs);
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix);
......@@ -56,7 +56,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_cache_page_free(spiffs *fs, int ix, u8_t w
}
// removes the oldest accessed cached page
static s32_t ICACHE_FLASH_ATTR spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) {
static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) {
s32_t res = SPIFFS_OK;
spiffs_cache *cache = spiffs_get_cache(fs);
......@@ -86,7 +86,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_cache_page_remove_oldest(spiffs *fs, u8_t
}
// allocates a new cached page and returns it, or null if all cache pages are busy
static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_allocate(spiffs *fs) {
static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) {
spiffs_cache *cache = spiffs_get_cache(fs);
if (cache->cpage_use_map == 0xffffffff) {
// out of cache memory
......@@ -107,7 +107,7 @@ static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_allocate(spiffs *f
}
// drops the cache page for give page index
void ICACHE_FLASH_ATTR spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {
void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {
spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix);
if (cp) {
spiffs_cache_page_free(fs, cp->ix, 0);
......@@ -117,7 +117,7 @@ void ICACHE_FLASH_ATTR spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {
// ------------------------------
// reads from spi flash or the cache
s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
s32_t spiffs_phys_rd(
spiffs *fs,
u8_t op,
spiffs_file fh,
......@@ -165,7 +165,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
}
// writes to spi flash and/or the cache
s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
s32_t spiffs_phys_wr(
spiffs *fs,
u8_t op,
spiffs_file fh,
......@@ -207,7 +207,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
#if SPIFFS_CACHE_WR
// returns the cache page that this fd refers, or null if no cache page
spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) {
spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) {
spiffs_cache *cache = spiffs_get_cache(fs);
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) {
......@@ -230,7 +230,7 @@ spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get_by_fd(spiffs *fs, spi
// allocates a new cache page and refers this to given fd - flushes an old cache
// page if all cache is busy
spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) {
spiffs_cache_page *spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) {
// before this function is called, it is ensured that there is no already existing
// cache page with same object id
spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
......@@ -247,7 +247,7 @@ spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_allocate_by_fd(spiffs *fs
}
// unrefers all fds that this cache page refers to and releases the cache page
void ICACHE_FLASH_ATTR spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) {
void spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) {
if (cp == 0) return;
int i;
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
......@@ -265,7 +265,7 @@ void ICACHE_FLASH_ATTR spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp
#endif
// initializes the cache
void ICACHE_FLASH_ATTR spiffs_cache_init(spiffs *fs) {
void spiffs_cache_init(spiffs *fs) {
if (fs->cache == 0) return;
u32_t sz = fs->cache_size;
u32_t cache_mask = 0;
......
......@@ -28,7 +28,7 @@
// searches in the object indices and returns the referenced page index given
// the object id and the data span index
// destroys fs->lu_work
static s32_t ICACHE_FLASH_ATTR spiffs_object_get_data_page_index_reference(
static s32_t spiffs_object_get_data_page_index_reference(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_span_ix data_spix,
......@@ -59,7 +59,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_object_get_data_page_index_reference(
}
// copies page contents to a new page
static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_page(spiffs *fs, spiffs_page_ix cur_pix, spiffs_page_header *p_hdr, spiffs_page_ix *new_pix) {
static s32_t spiffs_rewrite_page(spiffs *fs, spiffs_page_ix cur_pix, spiffs_page_header *p_hdr, spiffs_page_ix *new_pix) {
s32_t res;
res = spiffs_page_allocate_data(fs, p_hdr->obj_id, p_hdr, 0,0,0,0, new_pix);
SPIFFS_CHECK_RES(res);
......@@ -73,7 +73,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_page(spiffs *fs, spiffs_page_ix cu
// rewrites the object index for given object id and replaces the
// data page index to a new page index
static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_index(spiffs *fs, spiffs_obj_id obj_id, spiffs_span_ix data_spix, spiffs_page_ix new_data_pix, spiffs_page_ix objix_pix) {
static s32_t spiffs_rewrite_index(spiffs *fs, spiffs_obj_id obj_id, spiffs_span_ix data_spix, spiffs_page_ix new_data_pix, spiffs_page_ix objix_pix) {
s32_t res;
spiffs_block_ix bix;
int entry;
......@@ -137,7 +137,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_index(spiffs *fs, spiffs_obj_id ob
}
// deletes an object just by marking object index header as deleted
static s32_t ICACHE_FLASH_ATTR spiffs_delete_obj_lazy(spiffs *fs, spiffs_obj_id obj_id) {
static s32_t spiffs_delete_obj_lazy(spiffs *fs, spiffs_obj_id obj_id) {
spiffs_page_ix objix_hdr_pix;
s32_t res;
res = spiffs_obj_lu_find_id_and_span(fs, obj_id, 0, 0, &objix_hdr_pix);
......@@ -154,7 +154,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_delete_obj_lazy(spiffs *fs, spiffs_obj_id
}
// validates the given look up entry
static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, spiffs_page_header *p_hdr,
static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, spiffs_page_header *p_hdr,
spiffs_page_ix cur_pix, spiffs_block_ix cur_block, int cur_entry, int *reload_lu) {
u8_t delete_page = 0;
s32_t res = SPIFFS_OK;
......@@ -424,7 +424,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_validate(spiffs *fs, spiffs_o
return res;
}
static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block, int cur_entry,
static s32_t spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block, int cur_entry,
u32_t user_data, void *user_p) {
s32_t res = SPIFFS_OK;
spiffs_page_header p_hdr;
......@@ -452,7 +452,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id o
// Scans all object look up. For each entry, corresponding page header is checked for validity.
// If an object index header page is found, this is also checked
s32_t ICACHE_FLASH_ATTR spiffs_lookup_consistency_check(spiffs *fs, u8_t check_all_objects) {
s32_t spiffs_lookup_consistency_check(spiffs *fs, u8_t check_all_objects) {
s32_t res = SPIFFS_OK;
if (fs->check_cb_f) fs->check_cb_f(SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_PROGRESS, 0, 0);
......@@ -485,7 +485,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_lookup_consistency_check(spiffs *fs, u8_t check_a
// * x011 used, referenced only once, not index
// * x101 used, unreferenced, index
// The working memory might not fit all pages so several scans might be needed
static s32_t ICACHE_FLASH_ATTR spiffs_page_consistency_check_i(spiffs *fs) {
static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
const u32_t bits = 4;
const spiffs_page_ix pages_per_scan = SPIFFS_CFG_LOG_PAGE_SZ(fs) * 8 / bits;
......@@ -822,7 +822,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_page_consistency_check_i(spiffs *fs) {
}
// Checks consistency amongst all pages and fixes irregularities
s32_t ICACHE_FLASH_ATTR spiffs_page_consistency_check(spiffs *fs) {
s32_t spiffs_page_consistency_check(spiffs *fs) {
if (fs->check_cb_f) fs->check_cb_f(SPIFFS_CHECK_PAGE, SPIFFS_CHECK_PROGRESS, 0, 0);
s32_t res = spiffs_page_consistency_check_i(fs);
if (res != SPIFFS_OK) {
......@@ -837,7 +837,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_consistency_check(spiffs *fs) {
// searches for given object id in temporary object id index,
// returns the index or -1
static int ICACHE_FLASH_ATTR spiffs_object_index_search(spiffs *fs, spiffs_obj_id obj_id) {
static int spiffs_object_index_search(spiffs *fs, spiffs_obj_id obj_id) {
int i;
spiffs_obj_id *obj_table = (spiffs_obj_id *)fs->work;
obj_id &= ~SPIFFS_OBJ_ID_IX_FLAG;
......@@ -849,7 +849,7 @@ static int ICACHE_FLASH_ATTR spiffs_object_index_search(spiffs *fs, spiffs_obj_i
return -1;
}
s32_t ICACHE_FLASH_ATTR spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block,
s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block,
int cur_entry, u32_t user_data, void *user_p) {
s32_t res_c = SPIFFS_VIS_COUNTINUE;
s32_t res = SPIFFS_OK;
......@@ -943,7 +943,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_index_consistency_check_v(spiffs *fs, spif
// Scans for index pages. When an index page is found, corresponding index header is searched for.
// If no such page exists, the index page cannot be reached as no index header exists and must be
// deleted.
s32_t ICACHE_FLASH_ATTR spiffs_object_index_consistency_check(spiffs *fs) {
s32_t spiffs_object_index_consistency_check(spiffs *fs) {
s32_t res = SPIFFS_OK;
// impl note:
// fs->work is used for a temporary object index memory, listing found object ids and
......
......@@ -4,7 +4,7 @@
// Erases a logical block and updates the erase counter.
// If cache is enabled, all pages that might be cached in this block
// is dropped.
static s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_block(
static s32_t spiffs_gc_erase_block(
spiffs *fs,
spiffs_block_ix bix) {
s32_t res;
......@@ -47,7 +47,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_block(
// Searches for blocks where all entries are deleted - if one is found,
// the block is erased. Compared to the non-quick gc, the quick one ensures
// that no updates are needed on existing objects on pages that are erased.
s32_t ICACHE_FLASH_ATTR spiffs_gc_quick(
s32_t spiffs_gc_quick(
spiffs *fs) {
s32_t res = SPIFFS_OK;
u32_t blocks = fs->block_count;
......@@ -111,7 +111,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_quick(
// Checks if garbaga collecting is necessary. If so a candidate block is found,
// cleansed and erased
s32_t ICACHE_FLASH_ATTR spiffs_gc_check(
s32_t spiffs_gc_check(
spiffs *fs,
u32_t len) {
s32_t res;
......@@ -179,7 +179,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_check(
}
// Updates page statistics for a block that is about to be erased
s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_page_stats(
s32_t spiffs_gc_erase_page_stats(
spiffs *fs,
spiffs_block_ix bix) {
s32_t res = SPIFFS_OK;
......@@ -216,7 +216,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_page_stats(
}
// Finds block candidates to erase
s32_t ICACHE_FLASH_ATTR spiffs_gc_find_candidate(
s32_t spiffs_gc_find_candidate(
spiffs *fs,
spiffs_block_ix **block_candidates,
int *candidate_count) {
......@@ -350,7 +350,7 @@ typedef struct {
// repeat loop until end of object lookup
// scan object lookup again for remaining object index pages, move to new page in other block
//
s32_t ICACHE_FLASH_ATTR spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
s32_t res = SPIFFS_OK;
u32_t entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(spiffs_obj_id));
int cur_entry = 0;
......
......@@ -11,17 +11,17 @@
static s32_t spiffs_fflush_cache(spiffs *fs, spiffs_file fh);
#if SPIFFS_BUFFER_HELP
u32_t ICACHE_FLASH_ATTR SPIFFS_buffer_bytes_for_filedescs(spiffs *fs, u32_t num_descs) {
u32_t SPIFFS_buffer_bytes_for_filedescs(spiffs *fs, u32_t num_descs) {
return num_descs * sizeof(spiffs_fd);
}
#if SPIFFS_CACHE
u32_t ICACHE_FLASH_ATTR SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages) {
u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages) {
return sizeof(spiffs_cache) + num_pages * (sizeof(spiffs_cache_page) + SPIFFS_CFG_LOG_PAGE_SZ(fs));
}
#endif
#endif
s32_t ICACHE_FLASH_ATTR SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
u8_t *fd_space, u32_t fd_space_size,
void *cache, u32_t cache_size,
spiffs_check_callback check_cb_f) {
......@@ -82,7 +82,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *wo
return 0;
}
void ICACHE_FLASH_ATTR SPIFFS_unmount(spiffs *fs) {
void SPIFFS_unmount(spiffs *fs) {
if (!SPIFFS_CHECK_MOUNT(fs)) return;
SPIFFS_LOCK(fs);
int i;
......@@ -100,11 +100,11 @@ void ICACHE_FLASH_ATTR SPIFFS_unmount(spiffs *fs) {
SPIFFS_UNLOCK(fs);
}
s32_t ICACHE_FLASH_ATTR SPIFFS_errno(spiffs *fs) {
s32_t SPIFFS_errno(spiffs *fs) {
return fs->errno;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
spiffs_obj_id obj_id;
......@@ -118,7 +118,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode m
return 0;
}
spiffs_file ICACHE_FLASH_ATTR SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode) {
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -175,7 +175,7 @@ spiffs_file ICACHE_FLASH_ATTR SPIFFS_open(spiffs *fs, const char *path, spiffs_f
return fd->file_nbr;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, u32_t len) {
s32_t SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, u32_t len) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -220,7 +220,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, u32_t
return len;
}
static s32_t ICACHE_FLASH_ATTR spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, void *buf, u32_t offset, s32_t len) {
static s32_t spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, void *buf, u32_t offset, s32_t len) {
s32_t res = SPIFFS_OK;
s32_t remaining = len;
if (fd->size != SPIFFS_UNDEFINED_LEN && offset < fd->size) {
......@@ -239,7 +239,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, voi
}
s32_t ICACHE_FLASH_ATTR SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, u32_t len) {
s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, u32_t len) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -357,7 +357,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, u32_
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -401,7 +401,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int
return 0;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_remove(spiffs *fs, const char *path) {
s32_t SPIFFS_remove(spiffs *fs, const char *path) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -434,7 +434,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_remove(spiffs *fs, const char *path) {
return 0;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -461,7 +461,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
return 0;
}
static s32_t ICACHE_FLASH_ATTR spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, spiffs_file fh, spiffs_stat *s) {
static s32_t spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, spiffs_file fh, spiffs_stat *s) {
spiffs_page_object_ix_header objix_hdr;
spiffs_obj_id obj_id;
s32_t res =_spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ, fh,
......@@ -482,7 +482,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, s
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s) {
s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -499,7 +499,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_fstat(spiffs *fs, spiffs_file fh, spiffs_stat *s) {
s32_t SPIFFS_fstat(spiffs *fs, spiffs_file fh, spiffs_stat *s) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -522,7 +522,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fstat(spiffs *fs, spiffs_file fh, spiffs_stat *s)
// Checks if there are any cached writes for the object id associated with
// given filehandle. If so, these writes are flushed.
static s32_t ICACHE_FLASH_ATTR spiffs_fflush_cache(spiffs *fs, spiffs_file fh) {
static s32_t spiffs_fflush_cache(spiffs *fs, spiffs_file fh) {
s32_t res = SPIFFS_OK;
#if SPIFFS_CACHE_WR
......@@ -552,7 +552,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_fflush_cache(spiffs *fs, spiffs_file fh) {
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
s32_t SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
SPIFFS_API_CHECK_MOUNT(fs);
s32_t res = SPIFFS_OK;
#if SPIFFS_CACHE_WR
......@@ -565,7 +565,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
return res;
}
void ICACHE_FLASH_ATTR SPIFFS_close(spiffs *fs, spiffs_file fh) {
void SPIFFS_close(spiffs *fs, spiffs_file fh) {
if (!SPIFFS_CHECK_MOUNT(fs)) {
fs->errno = SPIFFS_ERR_NOT_MOUNTED;
return;
......@@ -580,7 +580,7 @@ void ICACHE_FLASH_ATTR SPIFFS_close(spiffs *fs, spiffs_file fh) {
SPIFFS_UNLOCK(fs);
}
spiffs_DIR *ICACHE_FLASH_ATTR SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d) {
spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d) {
if (!SPIFFS_CHECK_MOUNT(fs)) {
fs->errno = SPIFFS_ERR_NOT_MOUNTED;
return 0;
......@@ -591,7 +591,7 @@ spiffs_DIR *ICACHE_FLASH_ATTR SPIFFS_opendir(spiffs *fs, const char *name, spiff
return d;
}
static s32_t ICACHE_FLASH_ATTR spiffs_read_dir_v(
static s32_t spiffs_read_dir_v(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_block_ix bix,
......@@ -624,7 +624,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_read_dir_v(
return SPIFFS_VIS_COUNTINUE;
}
struct spiffs_dirent *ICACHE_FLASH_ATTR SPIFFS_readdir(spiffs_DIR *d, struct spiffs_dirent *e) {
struct spiffs_dirent *SPIFFS_readdir(spiffs_DIR *d, struct spiffs_dirent *e) {
if (!SPIFFS_CHECK_MOUNT(d->fs)) {
d->fs->errno = SPIFFS_ERR_NOT_MOUNTED;
return 0;
......@@ -657,12 +657,12 @@ struct spiffs_dirent *ICACHE_FLASH_ATTR SPIFFS_readdir(spiffs_DIR *d, struct spi
return ret;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_closedir(spiffs_DIR *d) {
s32_t SPIFFS_closedir(spiffs_DIR *d) {
SPIFFS_API_CHECK_MOUNT(d->fs);
return 0;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_check(spiffs *fs) {
s32_t SPIFFS_check(spiffs *fs) {
s32_t res;
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -679,7 +679,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_check(spiffs *fs) {
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_eof(spiffs *fs, spiffs_file fh) {
s32_t SPIFFS_eof(spiffs *fs, spiffs_file fh) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -698,7 +698,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_eof(spiffs *fs, spiffs_file fh) {
return res;
}
s32_t ICACHE_FLASH_ATTR SPIFFS_tell(spiffs *fs, spiffs_file fh) {
s32_t SPIFFS_tell(spiffs *fs, spiffs_file fh) {
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......@@ -718,7 +718,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_tell(spiffs *fs, spiffs_file fh) {
}
#if SPIFFS_TEST_VISUALISATION
s32_t ICACHE_FLASH_ATTR SPIFFS_vis(spiffs *fs) {
s32_t SPIFFS_vis(spiffs *fs) {
s32_t res = SPIFFS_OK;
SPIFFS_API_CHECK_MOUNT(fs);
SPIFFS_LOCK(fs);
......
#include "spiffs.h"
#include "spiffs_nucleus.h"
static s32_t ICACHE_FLASH_ATTR spiffs_page_data_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
static s32_t spiffs_page_data_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
s32_t res = SPIFFS_OK;
if (pix == (spiffs_page_ix)-1) {
// referring to page 0xffff...., bad object index
......@@ -29,7 +29,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_page_data_check(spiffs *fs, spiffs_fd *fd,
return res;
}
static s32_t ICACHE_FLASH_ATTR spiffs_page_index_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
static s32_t spiffs_page_index_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
s32_t res = SPIFFS_OK;
if (pix == (spiffs_page_ix)-1) {
// referring to page 0xffff...., bad object index
......@@ -59,7 +59,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_page_index_check(spiffs *fs, spiffs_fd *fd
#if !SPIFFS_CACHE
s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
s32_t spiffs_phys_rd(
spiffs *fs,
u32_t addr,
u32_t len,
......@@ -67,7 +67,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
return fs->cfg.hal_read_f(addr, len, dst);
}
s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
s32_t spiffs_phys_wr(
spiffs *fs,
u32_t addr,
u32_t len,
......@@ -77,7 +77,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
#endif
s32_t ICACHE_FLASH_ATTR spiffs_phys_cpy(
s32_t spiffs_phys_cpy(
spiffs *fs,
spiffs_file fh,
u32_t dst,
......@@ -116,7 +116,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_cpy(
// @param user_p any pointer, passed to the callback visitor function
// @param block_ix reported block index where match was found
// @param lu_entry reported look up index where match was found
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_entry_visitor(
s32_t spiffs_obj_lu_find_entry_visitor(
spiffs *fs,
spiffs_block_ix starting_block,
int starting_lu_entry,
......@@ -214,7 +214,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_entry_visitor(
}
static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan_v(
static s32_t spiffs_obj_lu_scan_v(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_block_ix bix,
......@@ -237,7 +237,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan_v(
// Scans thru all obj lu and counts free, deleted and used pages
// Find the maximum block erase count
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan(
s32_t spiffs_obj_lu_scan(
spiffs *fs) {
s32_t res;
spiffs_block_ix bix;
......@@ -299,7 +299,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan(
// Find free object lookup entry
// Iterate over object lookup pages in each block until a free object id entry is found
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free(
s32_t spiffs_obj_lu_find_free(
spiffs *fs,
spiffs_block_ix starting_block,
int starting_lu_entry,
......@@ -331,7 +331,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free(
// Find object lookup entry containing given id
// Iterate over object lookup pages in each block until a given object id entry is found
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id(
s32_t spiffs_obj_lu_find_id(
spiffs *fs,
spiffs_block_ix starting_block,
int starting_lu_entry,
......@@ -347,7 +347,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id(
}
static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_v(
static s32_t spiffs_obj_lu_find_id_and_span_v(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_block_ix bix,
......@@ -373,7 +373,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_v(
// Find object lookup entry containing given id and span index
// Iterate over object lookup pages in each block until a given object id entry is found
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span(
s32_t spiffs_obj_lu_find_id_and_span(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_span_ix spix,
......@@ -412,7 +412,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span(
// Find object lookup entry containing given id and span index in page headers only
// Iterate over object lookup pages in each block until a given object id entry is found
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_by_phdr(
s32_t spiffs_obj_lu_find_id_and_span_by_phdr(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_span_ix spix,
......@@ -452,7 +452,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_by_phdr(
// Allocates a free defined page with given obj_id
// Occupies object lookup entry and page
// data may be NULL; where only page header is stored, len and page_offs is ignored
s32_t ICACHE_FLASH_ATTR spiffs_page_allocate_data(
s32_t spiffs_page_allocate_data(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_page_header *ph,
......@@ -509,7 +509,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_allocate_data(
// Moves a page from src to a free page and finalizes it. Updates page index. Page data is given in param page.
// If page data is null, provided header is used for metainfo and page data is physically copied.
s32_t ICACHE_FLASH_ATTR spiffs_page_move(
s32_t spiffs_page_move(
spiffs *fs,
spiffs_file fh,
u8_t *page_data,
......@@ -571,7 +571,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_move(
}
// Deletes a page and removes it from object lookup.
s32_t ICACHE_FLASH_ATTR spiffs_page_delete(
s32_t spiffs_page_delete(
spiffs *fs,
spiffs_page_ix pix) {
s32_t res;
......@@ -600,7 +600,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_delete(
}
// Create an object index header page with empty index and undefined length
s32_t ICACHE_FLASH_ATTR spiffs_object_create(
s32_t spiffs_object_create(
spiffs *fs,
spiffs_obj_id obj_id,
u8_t name[SPIFFS_OBJ_NAME_LEN],
......@@ -655,7 +655,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_create(
// new_objix_hdr_data may be null, if so the object index header page is loaded
// name may be null, if so name is not changed
// size may be null, if so size is not changed
s32_t ICACHE_FLASH_ATTR spiffs_object_update_index_hdr(
s32_t spiffs_object_update_index_hdr(
spiffs *fs,
spiffs_fd *fd,
spiffs_obj_id obj_id,
......@@ -706,7 +706,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_update_index_hdr(
return res;
}
void ICACHE_FLASH_ATTR spiffs_cb_object_event(
void spiffs_cb_object_event(
spiffs *fs,
spiffs_fd *fd,
int ev,
......@@ -745,7 +745,7 @@ void ICACHE_FLASH_ATTR spiffs_cb_object_event(
}
// Open object by id
s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_id(
s32_t spiffs_object_open_by_id(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_fd *fd,
......@@ -763,7 +763,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_id(
}
// Open object by page index
s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_page(
s32_t spiffs_object_open_by_page(
spiffs *fs,
spiffs_page_ix pix,
spiffs_fd *fd,
......@@ -801,7 +801,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_page(
// Append to object
// keep current object index (header) page in fs->work buffer
s32_t ICACHE_FLASH_ATTR spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
spiffs *fs = fd->fs;
s32_t res = SPIFFS_OK;
u32_t written = 0;
......@@ -1032,7 +1032,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *
// Modify object
// keep current object index (header) page in fs->work buffer
s32_t ICACHE_FLASH_ATTR spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
spiffs *fs = fd->fs;
s32_t res = SPIFFS_OK;
u32_t written = 0;
......@@ -1231,7 +1231,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *
return res;
}
static s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name_v(
static s32_t spiffs_object_find_object_index_header_by_name_v(
spiffs *fs,
spiffs_obj_id obj_id,
spiffs_block_ix bix,
......@@ -1260,7 +1260,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name_v(
}
// Finds object index header page by name
s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name(
s32_t spiffs_object_find_object_index_header_by_name(
spiffs *fs,
u8_t name[SPIFFS_OBJ_NAME_LEN],
spiffs_page_ix *pix) {
......@@ -1295,7 +1295,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name(
}
// Truncates object to new size. If new size is null, object may be removed totally
s32_t ICACHE_FLASH_ATTR spiffs_object_truncate(
s32_t spiffs_object_truncate(
spiffs_fd *fd,
u32_t new_size,
u8_t remove) {
......@@ -1502,7 +1502,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_truncate(
return res;
}
s32_t ICACHE_FLASH_ATTR spiffs_object_read(
s32_t spiffs_object_read(
spiffs_fd *fd,
u32_t offset,
u32_t len,
......@@ -1586,7 +1586,7 @@ typedef struct {
u32_t compaction;
} spiffs_free_obj_id_state;
static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
u32_t user_data, void *user_p) {
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED) {
spiffs_obj_id min_obj_id = user_data;
......@@ -1600,7 +1600,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *f
return SPIFFS_VIS_COUNTINUE;
}
static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
u32_t user_data, void *user_p) {
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED && (id & SPIFFS_OBJ_ID_IX_FLAG)) {
s32_t res;
......@@ -1629,7 +1629,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *
// object ids cannot fit into a work buffer, these are grouped. When a group containing free
// object ids is found, the object lu is again scanned for object ids within group and bitmasked.
// Finally, the bitmasked is searched for a free id
s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id) {
s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id) {
s32_t res = SPIFFS_OK;
u32_t max_objects = (SPIFFS_CFG_PHYS_SZ(fs) / (u32_t)SPIFFS_CFG_LOG_PAGE_SZ(fs)) / 2;
spiffs_free_obj_id_state state;
......@@ -1720,7 +1720,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id
return res;
}
s32_t ICACHE_FLASH_ATTR spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
int i;
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
for (i = 0; i < fs->fd_count; i++) {
......@@ -1734,7 +1734,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
return SPIFFS_ERR_OUT_OF_FILE_DESCS;
}
s32_t ICACHE_FLASH_ATTR spiffs_fd_return(spiffs *fs, spiffs_file f) {
s32_t spiffs_fd_return(spiffs *fs, spiffs_file f) {
if (f <= 0 || f > fs->fd_count) {
return SPIFFS_ERR_BAD_DESCRIPTOR;
}
......@@ -1747,7 +1747,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_fd_return(spiffs *fs, spiffs_file f) {
return SPIFFS_OK;
}
s32_t ICACHE_FLASH_ATTR spiffs_fd_get(spiffs *fs, spiffs_file f, spiffs_fd **fd) {
s32_t spiffs_fd_get(spiffs *fs, spiffs_file f, spiffs_fd **fd) {
if (f <= 0 || f > fs->fd_count) {
return SPIFFS_ERR_BAD_DESCRIPTOR;
}
......
......@@ -82,6 +82,12 @@ void user_init(void)
NODE_DBG("Can not init platform for modules.\n");
return;
}
if(!flash_init_data_written()){
NODE_ERR("Restore init data.\n");
flash_init_data_default();
}
#if defined( BUILD_WOFS )
romfs_init();
......
......@@ -28,7 +28,7 @@ static int romfs_num_fd;
// Length of the 'file size' field for both ROMFS/WOFS
#define ROMFS_SIZE_LEN 4
static int ICACHE_FLASH_ATTR romfs_find_empty_fd(void)
static int romfs_find_empty_fd(void)
{
int i;
......@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR romfs_find_empty_fd(void)
return -1;
}
static void ICACHE_FLASH_ATTR romfs_close_fd( int fd )
static void romfs_close_fd( int fd )
{
if(fd<0 || fd>=TOTAL_MAX_FDS)
return;
......@@ -49,7 +49,7 @@ static void ICACHE_FLASH_ATTR romfs_close_fd( int fd )
}
// Helper function: read a byte from the FS
static uint8_t ICACHE_FLASH_ATTR romfsh_read8( uint32_t addr, const FSDATA *pfs )
static uint8_t romfsh_read8( uint32_t addr, const FSDATA *pfs )
{
uint8_t temp;
if( pfs->flags & ROMFS_FS_FLAG_DIRECT )
......@@ -59,13 +59,13 @@ static uint8_t ICACHE_FLASH_ATTR romfsh_read8( uint32_t addr, const FSDATA *pfs
}
// Helper function: return 1 if PFS reffers to a WOFS, 0 otherwise
static int ICACHE_FLASH_ATTR romfsh_is_wofs( const FSDATA* pfs )
static int romfsh_is_wofs( const FSDATA* pfs )
{
return ( pfs->flags & ROMFS_FS_FLAG_WO ) != 0;
}
// Find the next file, returning FS_FILE_OK or FS_FILE_NOT_FOUND if there no file left.
static uint8_t ICACHE_FLASH_ATTR romfs_next_file( uint32_t *start, char* fname, size_t len, size_t *act_len, FSDATA *pfs )
static uint8_t romfs_next_file( uint32_t *start, char* fname, size_t len, size_t *act_len, FSDATA *pfs )
{
uint32_t i, j, n;
uint32_t fsize;
......@@ -120,7 +120,7 @@ static uint8_t ICACHE_FLASH_ATTR romfs_next_file( uint32_t *start, char* fname,
// Open the given file, returning one of FS_FILE_NOT_FOUND, FS_FILE_ALREADY_OPENED
// or FS_FILE_OK
static uint8_t ICACHE_FLASH_ATTR romfs_open_file( const char* fname, FD* pfd, FSDATA *pfs, uint32_t *plast, uint32_t *pnameaddr )
static uint8_t romfs_open_file( const char* fname, FD* pfd, FSDATA *pfs, uint32_t *plast, uint32_t *pnameaddr )
{
uint32_t i, j, n;
char fsname[ MAX_FNAME_LENGTH + 1 ];
......@@ -184,7 +184,7 @@ static uint8_t ICACHE_FLASH_ATTR romfs_open_file( const char* fname, FD* pfd, FS
return FS_FILE_NOT_FOUND;
}
static int ICACHE_FLASH_ATTR romfs_open( const char *path, int flags, int mode, void *pdata )
static int romfs_open( const char *path, int flags, int mode, void *pdata )
{
FD tempfs;
int i;
......@@ -295,7 +295,7 @@ static int ICACHE_FLASH_ATTR romfs_open( const char *path, int flags, int mode,
return i;
}
static int ICACHE_FLASH_ATTR romfs_close( int fd, void *pdata )
static int romfs_close( int fd, void *pdata )
{
if(fd<0 || fd>=TOTAL_MAX_FDS)
return 0;
......@@ -320,7 +320,7 @@ static int ICACHE_FLASH_ATTR romfs_close( int fd, void *pdata )
return 0;
}
static _ssize_t ICACHE_FLASH_ATTR romfs_write( int fd, const void* ptr, size_t len, void *pdata )
static _ssize_t romfs_write( int fd, const void* ptr, size_t len, void *pdata )
{
if(fd<0 || fd>=TOTAL_MAX_FDS)
return -1;
......@@ -350,7 +350,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_write( int fd, const void* ptr, size_t l
return len;
}
static _ssize_t ICACHE_FLASH_ATTR romfs_read( int fd, void* ptr, size_t len, void *pdata )
static _ssize_t romfs_read( int fd, void* ptr, size_t len, void *pdata )
{
if(fd<0 || fd>=TOTAL_MAX_FDS)
return -1;
......@@ -374,7 +374,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_read( int fd, void* ptr, size_t len, voi
}
// lseek
static int ICACHE_FLASH_ATTR romfs_lseek( int fd, int off, int whence, void *pdata )
static int romfs_lseek( int fd, int off, int whence, void *pdata )
{
if(fd<0 || fd>=TOTAL_MAX_FDS)
return -1;
......@@ -409,7 +409,7 @@ static int ICACHE_FLASH_ATTR romfs_lseek( int fd, int off, int whence, void *pda
// WOFS functions and instance descriptor for real hardware
#if defined( BUILD_WOFS )
static uint32_t ICACHE_FLASH_ATTR sim_wofs_write( const void *from, uint32_t toaddr, uint32_t size, const void *pdata )
static uint32_t sim_wofs_write( const void *from, uint32_t toaddr, uint32_t size, const void *pdata )
{
const FSDATA *pfsdata = ( const FSDATA* )pdata;
if(toaddr>=INTERNAL_FLASH_SIZE)
......@@ -421,7 +421,7 @@ static uint32_t ICACHE_FLASH_ATTR sim_wofs_write( const void *from, uint32_t toa
return platform_flash_write( from, toaddr, size );
}
static uint32_t ICACHE_FLASH_ATTR sim_wofs_read( void *to, uint32_t fromaddr, uint32_t size, const void *pdata )
static uint32_t sim_wofs_read( void *to, uint32_t fromaddr, uint32_t size, const void *pdata )
{
const FSDATA *pfsdata = ( const FSDATA* )pdata;
if(fromaddr>=INTERNAL_FLASH_SIZE)
......@@ -445,7 +445,7 @@ static FSDATA wofs_fsdata =
// WOFS formatting function
// Returns 1 if OK, 0 for error
int ICACHE_FLASH_ATTR wofs_format( void )
int wofs_format( void )
{
uint32_t sect_first, sect_last;
FD tempfd;
......@@ -460,27 +460,27 @@ int ICACHE_FLASH_ATTR wofs_format( void )
return 1;
}
int ICACHE_FLASH_ATTR wofs_open(const char *_name, int flags){
int wofs_open(const char *_name, int flags){
return romfs_open( _name, flags, 0, &wofs_fsdata );
}
int ICACHE_FLASH_ATTR wofs_close( int fd ){
int wofs_close( int fd ){
return romfs_close( fd, &wofs_fsdata );
}
size_t ICACHE_FLASH_ATTR wofs_write( int fd, const void* ptr, size_t len ){
size_t wofs_write( int fd, const void* ptr, size_t len ){
return romfs_write( fd, ptr, len, &wofs_fsdata );
}
size_t ICACHE_FLASH_ATTR wofs_read( int fd, void* ptr, size_t len){
size_t wofs_read( int fd, void* ptr, size_t len){
return romfs_read( fd, ptr, len, &wofs_fsdata );
}
int ICACHE_FLASH_ATTR wofs_lseek( int fd, int off, int whence ){
int wofs_lseek( int fd, int off, int whence ){
return romfs_lseek( fd, off, whence, &wofs_fsdata );
}
int ICACHE_FLASH_ATTR wofs_eof( int fd ){
int wofs_eof( int fd ){
if(fd<0 || fd>=TOTAL_MAX_FDS)
return -1;
FD* pfd = fd_table + fd;
......@@ -488,7 +488,7 @@ int ICACHE_FLASH_ATTR wofs_eof( int fd ){
return pfd->offset == pfd->size;
}
int ICACHE_FLASH_ATTR wofs_getc( int fd ){
int wofs_getc( int fd ){
char c = EOF;
if(!wofs_eof(fd)){
romfs_read( fd, &c, 1, &wofs_fsdata );
......@@ -497,19 +497,19 @@ int ICACHE_FLASH_ATTR wofs_getc( int fd ){
return (int)c;
}
int ICACHE_FLASH_ATTR wofs_ungetc( int c, int fd ){
int wofs_ungetc( int c, int fd ){
return romfs_lseek( fd, -1, SEEK_CUR, &wofs_fsdata );
}
// Find the next file, returning FS_FILE_OK or FS_FILE_NOT_FOUND if there no file left.
uint8_t ICACHE_FLASH_ATTR wofs_next( uint32_t *start, char* fname, size_t len, size_t *act_len ){
uint8_t wofs_next( uint32_t *start, char* fname, size_t len, size_t *act_len ){
return romfs_next_file( start, fname, len, act_len, &wofs_fsdata );
}
#endif // #ifdef BUILD_WOFS
// Initialize both ROMFS and WOFS as needed
int ICACHE_FLASH_ATTR romfs_init( void )
int romfs_init( void )
{
unsigned i;
......@@ -529,13 +529,13 @@ int ICACHE_FLASH_ATTR romfs_init( void )
#else // #if defined( BUILD_ROMFS ) || defined( BUILD_WOFS )
int ICACHE_FLASH_ATTR romfs_init( void )
int romfs_init( void )
{
}
#endif // #if defined( BUILD_ROMFS ) || defined( BUILD_WOFS )
int ICACHE_FLASH_ATTR test_romfs()
int test_romfs()
{
int fd;
int i, size;
......
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