Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
bf3463d0
Commit
bf3463d0
authored
Jan 06, 2015
by
zeroday
Browse files
Merge pull request #75 from nodemcu/dev095
Dev095
parents
0a3702f8
729603fa
Changes
97
Hide whitespace changes
Inline
Side-by-side
app/modules/node.c
View file @
bf3463d0
...
@@ -15,14 +15,14 @@
...
@@ -15,14 +15,14 @@
#include "flash_api.h"
#include "flash_api.h"
// Lua: restart()
// Lua: restart()
static
int
ICACHE_FLASH_ATTR
node_restart
(
lua_State
*
L
)
static
int
node_restart
(
lua_State
*
L
)
{
{
system_restart
();
system_restart
();
return
0
;
return
0
;
}
}
// Lua: dsleep( us )
// Lua: dsleep( us )
static
int
ICACHE_FLASH_ATTR
node_deepsleep
(
lua_State
*
L
)
static
int
node_deepsleep
(
lua_State
*
L
)
{
{
s32
us
;
s32
us
;
us
=
luaL_checkinteger
(
L
,
1
);
us
=
luaL_checkinteger
(
L
,
1
);
...
@@ -33,7 +33,7 @@ static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L )
...
@@ -33,7 +33,7 @@ static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L )
}
}
// Lua: info()
// 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_MAJOR
);
lua_pushinteger
(
L
,
NODE_VERSION_MINOR
);
lua_pushinteger
(
L
,
NODE_VERSION_MINOR
);
...
@@ -47,7 +47,7 @@ static int ICACHE_FLASH_ATTR node_info( lua_State* L )
...
@@ -47,7 +47,7 @@ static int ICACHE_FLASH_ATTR node_info( lua_State* L )
}
}
// Lua: chipid()
// 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
();
uint32_t
id
=
system_get_chip_id
();
lua_pushinteger
(
L
,
id
);
lua_pushinteger
(
L
,
id
);
...
@@ -55,7 +55,7 @@ static int ICACHE_FLASH_ATTR node_chipid( lua_State* L )
...
@@ -55,7 +55,7 @@ static int ICACHE_FLASH_ATTR node_chipid( lua_State* L )
}
}
// Lua: flashid()
// 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
();
uint32_t
id
=
spi_flash_get_id
();
lua_pushinteger
(
L
,
id
);
lua_pushinteger
(
L
,
id
);
...
@@ -63,7 +63,7 @@ static int ICACHE_FLASH_ATTR node_flashid( lua_State* L )
...
@@ -63,7 +63,7 @@ static int ICACHE_FLASH_ATTR node_flashid( lua_State* L )
}
}
// Lua: flashsize()
// Lua: flashsize()
static
int
ICACHE_FLASH_ATTR
node_flashsize
(
lua_State
*
L
)
static
int
node_flashsize
(
lua_State
*
L
)
{
{
//uint32_t sz = 0;
//uint32_t sz = 0;
//if(lua_type(L, 1) == LUA_TNUMBER)
//if(lua_type(L, 1) == LUA_TNUMBER)
...
@@ -80,7 +80,7 @@ static int ICACHE_FLASH_ATTR node_flashsize( lua_State* L )
...
@@ -80,7 +80,7 @@ static int ICACHE_FLASH_ATTR node_flashsize( lua_State* L )
}
}
// Lua: heap()
// 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
();
uint32_t
sz
=
system_get_free_heap_size
();
lua_pushinteger
(
L
,
sz
);
lua_pushinteger
(
L
,
sz
);
...
@@ -90,7 +90,7 @@ static int ICACHE_FLASH_ATTR node_heap( lua_State* L )
...
@@ -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_high_count
;
// this is defined in lua.c
extern
int
led_low_count
;
extern
int
led_low_count
;
// Lua: led(low, high)
// Lua: led(low, high)
static
int
ICACHE_FLASH_ATTR
node_led
(
lua_State
*
L
)
static
int
node_led
(
lua_State
*
L
)
{
{
int
low
,
high
;
int
low
,
high
;
if
(
lua_isnumber
(
L
,
1
)
)
if
(
lua_isnumber
(
L
,
1
)
)
...
@@ -120,7 +120,7 @@ static int long_key_ref = LUA_NOREF;
...
@@ -120,7 +120,7 @@ static int long_key_ref = LUA_NOREF;
static
int
short_key_ref
=
LUA_NOREF
;
static
int
short_key_ref
=
LUA_NOREF
;
static
lua_State
*
gL
=
NULL
;
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
){
if
(
led_high_count
==
12
&&
led_low_count
==
12
){
led_low_count
=
led_high_count
=
6
;
led_low_count
=
led_high_count
=
6
;
}
else
{
}
else
{
...
@@ -131,11 +131,11 @@ void ICACHE_FLASH_ATTR default_long_press(void *arg){
...
@@ -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);
// 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
();
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
"
);
NODE_DBG
(
"key_long_press is called.
\n
"
);
if
(
long_key_ref
==
LUA_NOREF
){
if
(
long_key_ref
==
LUA_NOREF
){
default_long_press
(
arg
);
default_long_press
(
arg
);
...
@@ -147,7 +147,7 @@ void ICACHE_FLASH_ATTR key_long_press(void *arg){
...
@@ -147,7 +147,7 @@ void ICACHE_FLASH_ATTR key_long_press(void *arg){
lua_call
(
gL
,
0
,
0
);
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
"
);
NODE_DBG
(
"key_short_press is called.
\n
"
);
if
(
short_key_ref
==
LUA_NOREF
){
if
(
short_key_ref
==
LUA_NOREF
){
default_short_press
(
arg
);
default_short_press
(
arg
);
...
@@ -160,7 +160,7 @@ void ICACHE_FLASH_ATTR key_short_press(void *arg){
...
@@ -160,7 +160,7 @@ void ICACHE_FLASH_ATTR key_short_press(void *arg){
}
}
// Lua: key(type, function)
// Lua: key(type, function)
static
int
ICACHE_FLASH_ATTR
node_key
(
lua_State
*
L
)
static
int
node_key
(
lua_State
*
L
)
{
{
int
*
ref
=
NULL
;
int
*
ref
=
NULL
;
size_t
sl
;
size_t
sl
;
...
@@ -196,7 +196,7 @@ extern lua_Load gLoad;
...
@@ -196,7 +196,7 @@ extern lua_Load gLoad;
extern
os_timer_t
lua_timer
;
extern
os_timer_t
lua_timer
;
extern
void
dojob
(
lua_Load
*
load
);
extern
void
dojob
(
lua_Load
*
load
);
// Lua: input("string")
// Lua: input("string")
static
int
ICACHE_FLASH_ATTR
node_input
(
lua_State
*
L
)
static
int
node_input
(
lua_State
*
L
)
{
{
size_t
l
=
0
;
size_t
l
=
0
;
const
char
*
s
=
luaL_checklstring
(
L
,
1
,
&
l
);
const
char
*
s
=
luaL_checklstring
(
L
,
1
,
&
l
);
...
@@ -221,7 +221,7 @@ static int ICACHE_FLASH_ATTR node_input( lua_State* L )
...
@@ -221,7 +221,7 @@ static int ICACHE_FLASH_ATTR node_input( lua_State* L )
static
int
output_redir_ref
=
LUA_NOREF
;
static
int
output_redir_ref
=
LUA_NOREF
;
static
int
serial_debug
=
1
;
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){
// if(c_strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n");
// NODE_ERR("output too long.\n");
// return;
// return;
...
@@ -242,7 +242,7 @@ void ICACHE_FLASH_ATTR output_redirect(const char *str){
...
@@ -242,7 +242,7 @@ void ICACHE_FLASH_ATTR output_redirect(const char *str){
}
}
// Lua: output(function(c), debug)
// Lua: output(function(c), debug)
static
int
ICACHE_FLASH_ATTR
node_output
(
lua_State
*
L
)
static
int
node_output
(
lua_State
*
L
)
{
{
gL
=
L
;
gL
=
L
;
// luaL_checkanyfunction(L, 1);
// luaL_checkanyfunction(L, 1);
...
@@ -293,7 +293,7 @@ const LUA_REG_TYPE node_map[] =
...
@@ -293,7 +293,7 @@ const LUA_REG_TYPE node_map[] =
{
LNILKEY
,
LNILVAL
}
{
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
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
return
0
;
...
...
app/modules/ow.c
View file @
bf3463d0
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include "driver/onewire.h"
#include "driver/onewire.h"
// Lua: ow.setup( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
...
@@ -22,7 +22,7 @@ static int ICACHE_FLASH_ATTR ow_setup( lua_State *L )
...
@@ -22,7 +22,7 @@ static int ICACHE_FLASH_ATTR ow_setup( lua_State *L )
}
}
// Lua: r = ow.reset( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -31,7 +31,7 @@ static int ICACHE_FLASH_ATTR ow_reset( lua_State *L )
...
@@ -31,7 +31,7 @@ static int ICACHE_FLASH_ATTR ow_reset( lua_State *L )
}
}
// Lua: ow.skip( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR ow_skip( lua_State *L )
...
@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR ow_skip( lua_State *L )
}
}
// Lua: ow.select( id, buf[8])
// 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
];
uint8_t
rom
[
8
];
size_t
datalen
;
size_t
datalen
;
...
@@ -79,7 +79,7 @@ static int ICACHE_FLASH_ATTR ow_select( lua_State *L )
...
@@ -79,7 +79,7 @@ static int ICACHE_FLASH_ATTR ow_select( lua_State *L )
}
}
// Lua: ow.write( id, v, power)
// 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
;
int
power
=
0
;
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
...
@@ -99,7 +99,7 @@ static int ICACHE_FLASH_ATTR ow_write( lua_State *L )
...
@@ -99,7 +99,7 @@ static int ICACHE_FLASH_ATTR ow_write( lua_State *L )
}
}
// Lua: ow.write_bytes( id, buf, power)
// 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
;
int
power
=
0
;
size_t
datalen
;
size_t
datalen
;
...
@@ -119,7 +119,7 @@ static int ICACHE_FLASH_ATTR ow_write_bytes( lua_State *L )
...
@@ -119,7 +119,7 @@ static int ICACHE_FLASH_ATTR ow_write_bytes( lua_State *L )
}
}
// Lua: r = ow.read( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -128,7 +128,7 @@ static int ICACHE_FLASH_ATTR ow_read( lua_State *L )
...
@@ -128,7 +128,7 @@ static int ICACHE_FLASH_ATTR ow_read( lua_State *L )
}
}
// Lua: r = ow.read_bytes( id, size )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -148,7 +148,7 @@ static int ICACHE_FLASH_ATTR ow_read_bytes( lua_State *L )
...
@@ -148,7 +148,7 @@ static int ICACHE_FLASH_ATTR ow_read_bytes( lua_State *L )
}
}
// Lua: ow.depower( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -159,7 +159,7 @@ static int ICACHE_FLASH_ATTR ow_depower( lua_State *L )
...
@@ -159,7 +159,7 @@ static int ICACHE_FLASH_ATTR ow_depower( lua_State *L )
#if ONEWIRE_SEARCH
#if ONEWIRE_SEARCH
// Clear the search state so that if will start from the beginning again.
// Clear the search state so that if will start from the beginning again.
// Lua: ow.reset_search( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -171,7 +171,7 @@ static int ICACHE_FLASH_ATTR ow_reset_search( lua_State *L )
...
@@ -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
// Setup the search to find the device type 'family_code' on the next call
// to search(*newAddr) if it is present.
// to search(*newAddr) if it is present.
// Lua: ow.target_search( id, family_code)
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -193,7 +193,7 @@ static int ICACHE_FLASH_ATTR ow_target_search( lua_State *L )
...
@@ -193,7 +193,7 @@ static int ICACHE_FLASH_ATTR ow_target_search( lua_State *L )
// the same devices in the same order.
// the same devices in the same order.
// Lua: r = ow.search( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
ow
,
id
);
MOD_CHECK_ID
(
ow
,
id
);
...
@@ -217,7 +217,7 @@ static int ICACHE_FLASH_ATTR ow_search( lua_State *L )
...
@@ -217,7 +217,7 @@ static int ICACHE_FLASH_ATTR ow_search( lua_State *L )
#if ONEWIRE_CRC
#if ONEWIRE_CRC
// uint8_t onewire_crc8(const uint8_t *addr, uint8_t len);
// uint8_t onewire_crc8(const uint8_t *addr, uint8_t len);
// Lua: r = ow.crc8( buf )
// 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
;
size_t
datalen
;
const
uint8_t
*
pdata
=
luaL_checklstring
(
L
,
1
,
&
datalen
);
const
uint8_t
*
pdata
=
luaL_checklstring
(
L
,
1
,
&
datalen
);
...
@@ -230,7 +230,7 @@ static int ICACHE_FLASH_ATTR ow_crc8( lua_State *L )
...
@@ -230,7 +230,7 @@ static int ICACHE_FLASH_ATTR ow_crc8( lua_State *L )
#if ONEWIRE_CRC16
#if ONEWIRE_CRC16
// bool onewire_check_crc16(const uint8_t* input, uint16_t len, const uint8_t* inverted_crc, uint16_t crc);
// 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 )
// 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
;
size_t
datalen
;
uint8_t
inverted_crc
[
2
];
uint8_t
inverted_crc
[
2
];
...
@@ -262,7 +262,7 @@ static int ICACHE_FLASH_ATTR ow_check_crc16( lua_State *L )
...
@@ -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);
// uint16_t onewire_crc16(const uint8_t* input, uint16_t len, uint16_t crc);
// Lua: r = ow.crc16( buf, 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
;
size_t
datalen
;
const
uint8_t
*
pdata
=
luaL_checklstring
(
L
,
1
,
&
datalen
);
const
uint8_t
*
pdata
=
luaL_checklstring
(
L
,
1
,
&
datalen
);
...
@@ -313,7 +313,7 @@ const LUA_REG_TYPE ow_map[] =
...
@@ -313,7 +313,7 @@ const LUA_REG_TYPE ow_map[] =
{
LNILKEY
,
LNILVAL
}
{
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
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
return
0
;
...
...
app/modules/pwm.c
View file @
bf3463d0
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include "c_types.h"
#include "c_types.h"
// Lua: realfrequency = setup( id, frequency, duty )
// 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
s32
freq
;
// signed, to error check for negative values
unsigned
duty
;
unsigned
duty
;
...
@@ -35,7 +35,7 @@ static int ICACHE_FLASH_ATTR lpwm_setup( lua_State* L )
...
@@ -35,7 +35,7 @@ static int ICACHE_FLASH_ATTR lpwm_setup( lua_State* L )
}
}
// Lua: close( id )
// Lua: close( id )
static
int
ICACHE_FLASH_ATTR
lpwm_close
(
lua_State
*
L
)
static
int
lpwm_close
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
...
@@ -46,7 +46,7 @@ static int ICACHE_FLASH_ATTR lpwm_close( lua_State* L )
...
@@ -46,7 +46,7 @@ static int ICACHE_FLASH_ATTR lpwm_close( lua_State* L )
}
}
// Lua: start( id )
// Lua: start( id )
static
int
ICACHE_FLASH_ATTR
lpwm_start
(
lua_State
*
L
)
static
int
lpwm_start
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
id
=
luaL_checkinteger
(
L
,
1
);
id
=
luaL_checkinteger
(
L
,
1
);
...
@@ -56,7 +56,7 @@ static int ICACHE_FLASH_ATTR lpwm_start( lua_State* L )
...
@@ -56,7 +56,7 @@ static int ICACHE_FLASH_ATTR lpwm_start( lua_State* L )
}
}
// Lua: stop( id )
// Lua: stop( id )
static
int
ICACHE_FLASH_ATTR
lpwm_stop
(
lua_State
*
L
)
static
int
lpwm_stop
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
...
@@ -67,7 +67,7 @@ static int ICACHE_FLASH_ATTR lpwm_stop( lua_State* L )
...
@@ -67,7 +67,7 @@ static int ICACHE_FLASH_ATTR lpwm_stop( lua_State* L )
}
}
// Lua: realclock = setclock( id, clock )
// Lua: realclock = setclock( id, clock )
static
int
ICACHE_FLASH_ATTR
lpwm_setclock
(
lua_State
*
L
)
static
int
lpwm_setclock
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
s32
clk
;
// signed to error-check for negative values
s32
clk
;
// signed to error-check for negative values
...
@@ -83,7 +83,7 @@ static int ICACHE_FLASH_ATTR lpwm_setclock( lua_State* L )
...
@@ -83,7 +83,7 @@ static int ICACHE_FLASH_ATTR lpwm_setclock( lua_State* L )
}
}
// Lua: clock = getclock( id )
// Lua: clock = getclock( id )
static
int
ICACHE_FLASH_ATTR
lpwm_getclock
(
lua_State
*
L
)
static
int
lpwm_getclock
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
u32
clk
;
u32
clk
;
...
@@ -96,7 +96,7 @@ static int ICACHE_FLASH_ATTR lpwm_getclock( lua_State* L )
...
@@ -96,7 +96,7 @@ static int ICACHE_FLASH_ATTR lpwm_getclock( lua_State* L )
}
}
// Lua: realduty = setduty( id, duty )
// Lua: realduty = setduty( id, duty )
static
int
ICACHE_FLASH_ATTR
lpwm_setduty
(
lua_State
*
L
)
static
int
lpwm_setduty
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
s32
duty
;
// signed to error-check for negative values
s32
duty
;
// signed to error-check for negative values
...
@@ -112,7 +112,7 @@ static int ICACHE_FLASH_ATTR lpwm_setduty( lua_State* L )
...
@@ -112,7 +112,7 @@ static int ICACHE_FLASH_ATTR lpwm_setduty( lua_State* L )
}
}
// Lua: duty = getduty( id )
// Lua: duty = getduty( id )
static
int
ICACHE_FLASH_ATTR
lpwm_getduty
(
lua_State
*
L
)
static
int
lpwm_getduty
(
lua_State
*
L
)
{
{
unsigned
id
;
unsigned
id
;
u32
duty
;
u32
duty
;
...
@@ -143,7 +143,7 @@ const LUA_REG_TYPE pwm_map[] =
...
@@ -143,7 +143,7 @@ const LUA_REG_TYPE pwm_map[] =
{
LNILKEY
,
LNILVAL
}
{
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
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
return
0
;
...
...
app/modules/tmr.c
View file @
bf3463d0
...
@@ -12,57 +12,50 @@
...
@@ -12,57 +12,50 @@
static
os_timer_t
alarm_timer
[
NUM_TMR
];
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
};
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
)
if
(
alarm_timer_cb_ref
[
id
]
==
LUA_NOREF
)
return
;
return
;
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
alarm_timer_cb_ref
[
id
]);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
alarm_timer_cb_ref
[
id
]);
lua_call
(
L
,
0
,
0
);
lua_call
(
L
,
0
,
0
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb0
(
void
*
arg
){
alarm_timer_cb0
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
0
);
alarm_timer_common
((
lua_State
*
)
arg
,
0
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb1
(
void
*
arg
){
alarm_timer_cb1
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
1
);
alarm_timer_common
((
lua_State
*
)
arg
,
1
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb2
(
void
*
arg
){
alarm_timer_cb2
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
2
);
alarm_timer_common
((
lua_State
*
)
arg
,
2
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb3
(
void
*
arg
){
alarm_timer_cb3
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
3
);
alarm_timer_common
((
lua_State
*
)
arg
,
3
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb4
(
void
*
arg
){
alarm_timer_cb4
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
4
);
alarm_timer_common
((
lua_State
*
)
arg
,
4
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb5
(
void
*
arg
){
alarm_timer_cb5
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
5
);
alarm_timer_common
((
lua_State
*
)
arg
,
5
);
}
}
void
ICACHE_FLASH_ATTR
void
alarm_timer_cb6
(
void
*
arg
){
alarm_timer_cb6
(
void
*
arg
){
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
alarm_timer_common
((
lua_State
*
)
arg
,
6
);
alarm_timer_common
((
lua_State
*
)
arg
,
6
);
...
@@ -72,7 +65,7 @@ typedef void (*alarm_timer_callback)(void *arg);
...
@@ -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
};
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 )
// Lua: delay( us )
static
int
ICACHE_FLASH_ATTR
tmr_delay
(
lua_State
*
L
)
static
int
tmr_delay
(
lua_State
*
L
)
{
{
s32
us
;
s32
us
;
us
=
luaL_checkinteger
(
L
,
1
);
us
=
luaL_checkinteger
(
L
,
1
);
...
@@ -91,7 +84,7 @@ static int ICACHE_FLASH_ATTR tmr_delay( lua_State* L )
...
@@ -91,7 +84,7 @@ static int ICACHE_FLASH_ATTR tmr_delay( lua_State* L )
}
}
// Lua: now() , return system timer in us
// 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
();
unsigned
now
=
0x7FFFFFFF
&
system_get_time
();
lua_pushinteger
(
L
,
now
);
lua_pushinteger
(
L
,
now
);
...
@@ -99,7 +92,7 @@ static int ICACHE_FLASH_ATTR tmr_now( lua_State* L )
...
@@ -99,7 +92,7 @@ static int ICACHE_FLASH_ATTR tmr_now( lua_State* L )
}
}
// Lua: alarm( id, interval, repeat, function )
// 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
;
s32
interval
;
unsigned
repeat
=
0
;
unsigned
repeat
=
0
;
...
@@ -136,7 +129,7 @@ static int ICACHE_FLASH_ATTR tmr_alarm( lua_State* L )
...
@@ -136,7 +129,7 @@ static int ICACHE_FLASH_ATTR tmr_alarm( lua_State* L )
}
}
// Lua: stop( id )
// 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
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
tmr
,
id
);
MOD_CHECK_ID
(
tmr
,
id
);
...
@@ -147,7 +140,7 @@ static int ICACHE_FLASH_ATTR tmr_stop( lua_State* L )
...
@@ -147,7 +140,7 @@ static int ICACHE_FLASH_ATTR tmr_stop( lua_State* L )
// extern void update_key_led();
// extern void update_key_led();
// Lua: wdclr()
// Lua: wdclr()
static
int
ICACHE_FLASH_ATTR
tmr_wdclr
(
lua_State
*
L
)
static
int
tmr_wdclr
(
lua_State
*
L
)
{
{
WRITE_PERI_REG
(
0x60000914
,
0x73
);
WRITE_PERI_REG
(
0x60000914
,
0x73
);
// update_key_led();
// update_key_led();
...
@@ -155,7 +148,7 @@ static int ICACHE_FLASH_ATTR tmr_wdclr( lua_State* L )
...
@@ -155,7 +148,7 @@ static int ICACHE_FLASH_ATTR tmr_wdclr( lua_State* L )
}
}
// Lua: time() , return rtc time in us
// 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
t
=
0xFFFFFFFF
&
system_get_rtc_time
();
unsigned
c
=
0xFFFFFFFF
&
system_rtc_clock_cali_proc
();
unsigned
c
=
0xFFFFFFFF
&
system_rtc_clock_cali_proc
();
...
@@ -181,7 +174,7 @@ const LUA_REG_TYPE tmr_map[] =
...
@@ -181,7 +174,7 @@ const LUA_REG_TYPE tmr_map[] =
{
LNILKEY
,
LNILVAL
}
{
LNILKEY
,
LNILVAL
}
};
};
LUALIB_API
int
ICACHE_FLASH_ATTR
luaopen_tmr
(
lua_State
*
L
)
LUALIB_API
int
luaopen_tmr
(
lua_State
*
L
)
{
{
int
i
=
0
;
int
i
=
0
;
for
(
i
=
0
;
i
<
NUM_TMR
;
i
++
){
for
(
i
=
0
;
i
<
NUM_TMR
;
i
++
){
...
...
app/modules/uart.c
View file @
bf3463d0
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
static
lua_State
*
gL
=
NULL
;
static
lua_State
*
gL
=
NULL
;
static
int
uart_receive_rf
=
LUA_NOREF
;
static
int
uart_receive_rf
=
LUA_NOREF
;
bool
run_input
=
true
;
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
)
if
(
!
buf
||
len
==
0
)
return
false
;
return
false
;
if
(
uart_receive_rf
==
LUA_NOREF
)
if
(
uart_receive_rf
==
LUA_NOREF
)
...
@@ -29,7 +29,7 @@ bool ICACHE_FLASH_ATTR uart_on_data_cb(const char *buf, size_t len){
...
@@ -29,7 +29,7 @@ bool ICACHE_FLASH_ATTR uart_on_data_cb(const char *buf, size_t len){
uint16_t
need_len
=
0
;
uint16_t
need_len
=
0
;
int16_t
end_char
=
-
1
;
int16_t
end_char
=
-
1
;
// Lua: uart.on("method", [number/char], function, [run_input])
// 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
;
size_t
sl
,
el
;
int32_t
run
=
1
;
int32_t
run
=
1
;
...
@@ -160,7 +160,7 @@ const LUA_REG_TYPE uart_map[] =
...
@@ -160,7 +160,7 @@ const LUA_REG_TYPE uart_map[] =
{
LNILKEY
,
LNILVAL
}
{
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
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
return
0
;
...
...
app/modules/wifi.c
View file @
bf3463d0
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
static
int
wifi_smart_succeed
=
LUA_NOREF
;
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
"
);
NODE_DBG
(
"wifi_smart_succeed_cb is called.
\n
"
);
if
(
!
arg
)
if
(
!
arg
)
return
;
return
;
...
@@ -34,8 +34,7 @@ static lua_State* gL = NULL;
...
@@ -34,8 +34,7 @@ static lua_State* gL = NULL;
* @param status: scan over status
* @param status: scan over status
* @retval None
* @retval None
*/
*/
static
void
ICACHE_FLASH_ATTR
static
void
wifi_scan_done
(
void
*
arg
,
STATUS
status
)
wifi_scan_done
(
void
*
arg
,
STATUS
status
)
{
{
uint8
ssid
[
33
];
uint8
ssid
[
33
];
char
temp
[
128
];
char
temp
[
128
];
...
@@ -82,7 +81,7 @@ wifi_scan_done(void *arg, STATUS status)
...
@@ -82,7 +81,7 @@ wifi_scan_done(void *arg, STATUS status)
}
}
// Lua: smart(channel, function succeed_cb)
// 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
;
unsigned
channel
;
int
stack
=
1
;
int
stack
=
1
;
...
@@ -114,7 +113,7 @@ static int ICACHE_FLASH_ATTR wifi_start_smart( lua_State* L )
...
@@ -114,7 +113,7 @@ static int ICACHE_FLASH_ATTR wifi_start_smart( lua_State* L )
}
}
// Lua: exit_smart(channel)
// 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
();
smart_end
();
if
(
wifi_smart_succeed
!=
LUA_NOREF
)
if
(
wifi_smart_succeed
!=
LUA_NOREF
)
...
@@ -124,7 +123,7 @@ static int ICACHE_FLASH_ATTR wifi_exit_smart( lua_State* L )
...
@@ -124,7 +123,7 @@ static int ICACHE_FLASH_ATTR wifi_exit_smart( lua_State* L )
}
}
// Lua: realmode = setmode(mode)
// Lua: realmode = setmode(mode)
static
int
ICACHE_FLASH_ATTR
wifi_setmode
(
lua_State
*
L
)
static
int
wifi_setmode
(
lua_State
*
L
)
{
{
unsigned
mode
;
unsigned
mode
;
...
@@ -139,7 +138,7 @@ static int ICACHE_FLASH_ATTR wifi_setmode( lua_State* L )
...
@@ -139,7 +138,7 @@ static int ICACHE_FLASH_ATTR wifi_setmode( lua_State* L )
}
}
// Lua: realmode = getmode()
// Lua: realmode = getmode()
static
int
ICACHE_FLASH_ATTR
wifi_getmode
(
lua_State
*
L
)
static
int
wifi_getmode
(
lua_State
*
L
)
{
{
unsigned
mode
;
unsigned
mode
;
mode
=
(
unsigned
)
wifi_get_opmode
();
mode
=
(
unsigned
)
wifi_get_opmode
();
...
@@ -149,7 +148,7 @@ static int ICACHE_FLASH_ATTR wifi_getmode( lua_State* L )
...
@@ -149,7 +148,7 @@ static int ICACHE_FLASH_ATTR wifi_getmode( lua_State* L )
// Lua: mac = wifi.xx.getmac()
// 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
];
char
temp
[
64
];
uint8_t
mac
[
6
];
uint8_t
mac
[
6
];
...
@@ -160,7 +159,7 @@ static int ICACHE_FLASH_ATTR wifi_getmac( lua_State* L, uint8_t mode )
...
@@ -160,7 +159,7 @@ static int ICACHE_FLASH_ATTR wifi_getmac( lua_State* L, uint8_t mode )
}
}
// Lua: mac = wifi.xx.setmac()
// 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
;
unsigned
len
=
0
;
const
char
*
mac
=
luaL_checklstring
(
L
,
1
,
&
len
);
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 )
...
@@ -172,7 +171,7 @@ static int ICACHE_FLASH_ATTR wifi_setmac( lua_State* L, uint8_t mode )
}
}
// Lua: ip = wifi.xx.getip()
// 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
;
struct
ip_info
pTempIp
;
char
temp
[
64
];
char
temp
[
64
];
...
@@ -204,7 +203,7 @@ static uint32_t parse_key(lua_State* L, const char * key){
...
@@ -204,7 +203,7 @@ static uint32_t parse_key(lua_State* L, const char * key){
}
}
// Lua: ip = wifi.xx.setip()
// 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
;
struct
ip_info
pTempIp
;
wifi_get_ip_info
(
mode
,
&
pTempIp
);
wifi_get_ip_info
(
mode
,
&
pTempIp
);
...
@@ -228,7 +227,7 @@ static int ICACHE_FLASH_ATTR wifi_setip( lua_State* L, uint8_t mode )
...
@@ -228,7 +227,7 @@ static int ICACHE_FLASH_ATTR wifi_setip( lua_State* L, uint8_t mode )
}
}
// Lua: realtype = sleeptype(type)
// Lua: realtype = sleeptype(type)
static
int
ICACHE_FLASH_ATTR
wifi_sleeptype
(
lua_State
*
L
)
static
int
wifi_sleeptype
(
lua_State
*
L
)
{
{
unsigned
type
;
unsigned
type
;
...
@@ -248,27 +247,27 @@ static int ICACHE_FLASH_ATTR wifi_sleeptype( lua_State* L )
...
@@ -248,27 +247,27 @@ static int ICACHE_FLASH_ATTR wifi_sleeptype( lua_State* L )
}
}
// Lua: wifi.sta.getmac()
// 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
);
return
wifi_getmac
(
L
,
STATION_IF
);
}
}
// Lua: wifi.sta.setmac()
// 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
);
return
wifi_setmac
(
L
,
STATION_IF
);
}
}
// Lua: wifi.sta.getip()
// 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
);
return
wifi_getip
(
L
,
STATION_IF
);
}
}
// Lua: wifi.sta.setip()
// 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
);
return
wifi_setip
(
L
,
STATION_IF
);
}
}
// Lua: wifi.sta.config(ssid, password)
// 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
;
size_t
sl
,
pl
;
struct
station_config
sta_conf
;
struct
station_config
sta_conf
;
...
@@ -301,21 +300,21 @@ static int ICACHE_FLASH_ATTR wifi_station_config( lua_State* L )
...
@@ -301,21 +300,21 @@ static int ICACHE_FLASH_ATTR wifi_station_config( lua_State* L )
}
}
// Lua: wifi.sta.connect()
// 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
();
wifi_station_connect
();
return
0
;
return
0
;
}
}
// Lua: wifi.sta.disconnect()
// 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
();
wifi_station_disconnect
();
return
0
;
return
0
;
}
}
// Lua: wifi.sta.auto(true/false)
// 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
;
unsigned
a
;
...
@@ -330,7 +329,7 @@ static int ICACHE_FLASH_ATTR wifi_station_setauto( lua_State* L )
...
@@ -330,7 +329,7 @@ static int ICACHE_FLASH_ATTR wifi_station_setauto( lua_State* L )
return
0
;
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
)
if
(
wifi_get_opmode
()
==
SOFTAP_MODE
)
{
{
...
@@ -352,7 +351,7 @@ static int ICACHE_FLASH_ATTR wifi_station_listap( lua_State* L )
...
@@ -352,7 +351,7 @@ static int ICACHE_FLASH_ATTR wifi_station_listap( lua_State* L )
}
}
// Lua: wifi.sta.status()
// 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
();
uint8_t
status
=
wifi_station_get_connect_status
();
lua_pushinteger
(
L
,
status
);
lua_pushinteger
(
L
,
status
);
...
@@ -360,27 +359,27 @@ static int ICACHE_FLASH_ATTR wifi_station_status( lua_State* L )
...
@@ -360,27 +359,27 @@ static int ICACHE_FLASH_ATTR wifi_station_status( lua_State* L )
}
}
// Lua: wifi.ap.getmac()
// 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
);
return
wifi_getmac
(
L
,
SOFTAP_IF
);
}
}
// Lua: wifi.ap.setmac()
// 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
);
return
wifi_setmac
(
L
,
SOFTAP_IF
);
}
}
// Lua: wifi.ap.getip()
// 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
);
return
wifi_getip
(
L
,
SOFTAP_IF
);
}
}
// Lua: wifi.ap.setip()
// 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
);
return
wifi_setip
(
L
,
SOFTAP_IF
);
}
}
// Lua: wifi.ap.config(table)
// 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
;
struct
softap_config
config
;
size_t
len
;
size_t
len
;
...
@@ -495,7 +494,7 @@ const LUA_REG_TYPE wifi_map[] =
...
@@ -495,7 +494,7 @@ const LUA_REG_TYPE wifi_map[] =
{
LNILKEY
,
LNILVAL
}
{
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
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
return
0
;
...
...
app/platform/common.c
View file @
bf3463d0
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#include "c_string.h"
#include "c_string.h"
#include "c_stdio.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)
...
@@ -13,7 +13,7 @@ void ICACHE_FLASH_ATTR cmn_platform_init(void)
// ****************************************************************************
// ****************************************************************************
// GPIO functions
// GPIO functions
int
ICACHE_FLASH_ATTR
platform_gpio_exists
(
unsigned
pin
)
int
platform_gpio_exists
(
unsigned
pin
)
{
{
return
pin
<
NUM_GPIO
;
return
pin
<
NUM_GPIO
;
}
}
...
@@ -21,7 +21,7 @@ int ICACHE_FLASH_ATTR platform_gpio_exists( unsigned pin )
...
@@ -21,7 +21,7 @@ int ICACHE_FLASH_ATTR platform_gpio_exists( unsigned pin )
// ****************************************************************************
// ****************************************************************************
// CAN functions
// CAN functions
int
ICACHE_FLASH_ATTR
platform_can_exists
(
unsigned
id
)
int
platform_can_exists
(
unsigned
id
)
{
{
return
id
<
NUM_CAN
;
return
id
<
NUM_CAN
;
}
}
...
@@ -30,7 +30,7 @@ int ICACHE_FLASH_ATTR platform_can_exists( unsigned id )
...
@@ -30,7 +30,7 @@ int ICACHE_FLASH_ATTR platform_can_exists( unsigned id )
// SPI functions
// SPI functions
int
ICACHE_FLASH_ATTR
platform_spi_exists
(
unsigned
id
)
int
platform_spi_exists
(
unsigned
id
)
{
{
return
id
<
NUM_SPI
;
return
id
<
NUM_SPI
;
}
}
...
@@ -38,7 +38,7 @@ int ICACHE_FLASH_ATTR platform_spi_exists( unsigned id )
...
@@ -38,7 +38,7 @@ int ICACHE_FLASH_ATTR platform_spi_exists( unsigned id )
// ****************************************************************************
// ****************************************************************************
// PWM functions
// PWM functions
int
ICACHE_FLASH_ATTR
platform_pwm_exists
(
unsigned
id
)
int
platform_pwm_exists
(
unsigned
id
)
{
{
return
((
id
<
NUM_PWM
)
&&
(
id
>
0
));
return
((
id
<
NUM_PWM
)
&&
(
id
>
0
));
}
}
...
@@ -46,7 +46,7 @@ int ICACHE_FLASH_ATTR platform_pwm_exists( unsigned id )
...
@@ -46,7 +46,7 @@ int ICACHE_FLASH_ATTR platform_pwm_exists( unsigned id )
// ****************************************************************************
// ****************************************************************************
// ADC functions
// ADC functions
int
ICACHE_FLASH_ATTR
platform_adc_exists
(
unsigned
id
)
int
platform_adc_exists
(
unsigned
id
)
{
{
return
id
<
NUM_ADC
;
return
id
<
NUM_ADC
;
}
}
...
@@ -54,7 +54,7 @@ int ICACHE_FLASH_ATTR platform_adc_exists( unsigned id )
...
@@ -54,7 +54,7 @@ int ICACHE_FLASH_ATTR platform_adc_exists( unsigned id )
// ****************************************************************************
// ****************************************************************************
// UART functions
// UART functions
int
ICACHE_FLASH_ATTR
platform_uart_exists
(
unsigned
id
)
int
platform_uart_exists
(
unsigned
id
)
{
{
return
id
<
NUM_UART
;
return
id
<
NUM_UART
;
}
}
...
@@ -62,7 +62,7 @@ int ICACHE_FLASH_ATTR platform_uart_exists( unsigned id )
...
@@ -62,7 +62,7 @@ int ICACHE_FLASH_ATTR platform_uart_exists( unsigned id )
// ****************************************************************************
// ****************************************************************************
// OneWire functions
// OneWire functions
int
ICACHE_FLASH_ATTR
platform_ow_exists
(
unsigned
id
)
int
platform_ow_exists
(
unsigned
id
)
{
{
return
((
id
<
NUM_OW
)
&&
(
id
>
0
));
return
((
id
<
NUM_OW
)
&&
(
id
>
0
));
}
}
...
@@ -70,13 +70,13 @@ int ICACHE_FLASH_ATTR platform_ow_exists( unsigned id )
...
@@ -70,13 +70,13 @@ int ICACHE_FLASH_ATTR platform_ow_exists( unsigned id )
// ****************************************************************************
// ****************************************************************************
// Timer functions
// Timer functions
int
ICACHE_FLASH_ATTR
platform_tmr_exists
(
unsigned
id
)
int
platform_tmr_exists
(
unsigned
id
)
{
{
return
id
<
NUM_TMR
;
return
id
<
NUM_TMR
;
}
}
// I2C support
// I2C support
int
ICACHE_FLASH_ATTR
platform_i2c_exists
(
unsigned
id
)
int
platform_i2c_exists
(
unsigned
id
)
{
{
#ifndef NUM_I2C
#ifndef NUM_I2C
return
0
;
return
0
;
...
@@ -99,7 +99,7 @@ extern char _flash_used_end[];
...
@@ -99,7 +99,7 @@ extern char _flash_used_end[];
// Helper function: find the flash sector in which an address resides
// 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
// 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
;
address
-=
INTERNAL_FLASH_START_ADDRESS
;
#ifdef INTERNAL_FLASH_SECTOR_SIZE
#ifdef INTERNAL_FLASH_SECTOR_SIZE
...
@@ -127,12 +127,12 @@ static uint32_t ICACHE_FLASH_ATTR flashh_find_sector( uint32_t address, uint32_t
...
@@ -127,12 +127,12 @@ static uint32_t ICACHE_FLASH_ATTR flashh_find_sector( uint32_t address, uint32_t
#endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE
#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
);
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
#ifdef INTERNAL_FLASH_SECTOR_SIZE
return
INTERNAL_FLASH_SIZE
/
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)
...
@@ -143,7 +143,7 @@ uint32_t ICACHE_FLASH_ATTR platform_flash_get_num_sectors(void)
#endif // #ifdef INTERNAL_FLASH_SECTOR_SIZE
#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
// Round the total used flash size to the closest flash block address
uint32_t
start
,
end
,
sect
;
uint32_t
start
,
end
,
sect
;
...
@@ -162,7 +162,7 @@ uint32_t ICACHE_FLASH_ATTR platform_flash_get_first_free_block_address( uint32_t
...
@@ -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
#ifndef INTERNAL_FLASH_WRITE_UNIT_SIZE
return
platform_s_flash_write
(
from
,
toaddr
,
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
...
@@ -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
#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
#ifndef INTERNAL_FLASH_READ_UNIT_SIZE
return
platform_s_flash_read
(
to
,
fromaddr
,
size
);
return
platform_s_flash_read
(
to
,
fromaddr
,
size
);
...
...
app/platform/flash_api.c
View file @
bf3463d0
...
@@ -6,87 +6,82 @@
...
@@ -6,87 +6,82 @@
#include "user_config.h"
#include "user_config.h"
#include "flash_api.h"
#include "flash_api.h"
#include "spi_flash.h"
#include "spi_flash.h"
#include "c_stdio.h"
SPIFlashInfo
*
ICACHE_FLASH_ATTR
static
volatile
const
uint8_t
flash_init_data
[
128
]
ICACHE_STORE_ATTR
ICACHE_RODATA_ATTR
=
flash_get_info
(
void
)
{
{
0x05
,
0x00
,
0x04
,
0x02
,
0x05
,
0x05
,
0x05
,
0x02
,
0x05
,
0x00
,
0x04
,
0x05
,
0x05
,
0x04
,
0x05
,
0x05
,
static
SPIFlashInfo
spi_flash_info
NODE_STORE_ATTR
;
0x04
,
0xFE
,
0xFD
,
0xFF
,
0xF0
,
0xF0
,
0xF0
,
0xE0
,
0xE0
,
0xE0
,
0xE1
,
0x0A
,
0xFF
,
0xFF
,
0xF8
,
0x00
,
static
bool
is_spi_flash_info_initialized
=
false
;
0xF8
,
0xF8
,
0x52
,
0x4E
,
0x4A
,
0x44
,
0x40
,
0x38
,
0x00
,
0x00
,
0x01
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
// Make the code more fast
0x01
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
if
(
!
is_spi_flash_info_initialized
)
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
,
SPIRead
(
0
,
&
spi_flash_info
,
sizeof
(
spi_flash_info
));
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
is_spi_flash_info_initialized
=
true
;
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
}
};
// return (SPIFlashInfo *)(0x40200000);
return
&
spi_flash_info
;
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
uint8_t
flash_get_size
(
void
)
flash_get_size
(
void
)
{
{
SPIFlashInfo
*
p_spi_flash_info
=
flash_get_info
();
return
flash_get_info
().
size
;
return
p_spi_flash_info
->
size
;
}
}
uint32_t
ICACHE_FLASH_ATTR
uint32_t
flash_get_size_byte
(
void
)
flash_get_size_byte
(
void
)
{
{
static
uint32_t
flash_size
=
0
;
uint32_t
flash_size
=
0
;
// Make the code more fast
switch
(
flash_get_info
().
size
)
if
(
flash_size
==
0
)
{
{
SPIFlashInfo
*
p_spi_flash_info
=
flash_get_info
();
case
SIZE_2MBIT
:
switch
(
p_spi_flash_info
->
size
)
// 2Mbit, 256kByte
{
flash_size
=
256
*
1024
;
case
SIZE_2MBIT
:
break
;
// 2Mbit, 256kByte
case
SIZE_4MBIT
:
flash_size
=
256
*
1024
;
// 4Mbit, 512kByte
break
;
flash_size
=
512
*
1024
;
case
SIZE_4MBIT
:
break
;
// 4Mbit, 512kByte
case
SIZE_8MBIT
:
flash_size
=
512
*
1024
;
// 8Mbit, 1MByte
break
;
flash_size
=
1
*
1024
*
1024
;
case
SIZE_8MBIT
:
break
;
// 8Mbit, 1MByte
case
SIZE_16MBIT
:
flash_size
=
1
*
1024
*
1024
;
// 16Mbit, 2MByte
break
;
flash_size
=
2
*
1024
*
1024
;
case
SIZE_16MBIT
:
break
;
// 16Mbit, 2MByte
case
SIZE_32MBIT
:
flash_size
=
2
*
1024
*
1024
;
// 32Mbit, 4MByte
break
;
flash_size
=
4
*
1024
*
1024
;
case
SIZE_32MBIT
:
break
;
// 32Mbit, 4MByte
default:
flash_size
=
4
*
1024
*
1024
;
// Unknown flash size, fall back mode.
break
;
flash_size
=
512
*
1024
;
default:
break
;
// Unknown flash size, fall back mode.
flash_size
=
512
*
1024
;
break
;
}
}
}
return
flash_size
;
return
flash_size
;
}
}
bool
ICACHE_FLASH_ATTR
bool
flash_set_size
(
uint8_t
size
)
flash_set_size
(
uint8_t
size
)
{
{
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
// If you don't know what you're doing, your nodemcu may turn into stone ...
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
NOD
E_STORE_ATTR
;
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACH
E_STORE_ATTR
;
SPIRead
(
0
,
data
,
sizeof
(
data
));
SPIRead
(
0
,
data
,
sizeof
(
data
));
SPIFlashInfo
*
p_spi_flash_info
=
(
SPIFlashInfo
*
)(
data
);
SPIFlashInfo
*
p_spi_flash_info
=
(
SPIFlashInfo
*
)(
data
);
p_spi_flash_info
->
size
=
size
;
p_spi_flash_info
->
size
=
size
;
SPIEraseSector
(
0
);
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 = flash_get_info();
//p_spi_flash_info->size = size;
//p_spi_flash_info->size = size;
return
true
;
return
true
;
}
}
bool
ICACHE_FLASH_ATTR
bool
flash_set_size_byte
(
uint32_t
size
)
flash_set_size_byte
(
uint32_t
size
)
{
{
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
...
@@ -128,23 +123,15 @@ flash_set_size_byte(uint32_t size)
...
@@ -128,23 +123,15 @@ flash_set_size_byte(uint32_t size)
return
result
;
return
result
;
}
}
uint16_t
ICACHE_FLASH_ATTR
uint16_t
flash_get_sec_num
(
void
)
flash_get_sec_num
(
void
)
{
{
static
uint16_t
result
=
0
;
return
flash_get_size_byte
()
/
SPI_FLASH_SEC_SIZE
;
// Make the code more fast
if
(
result
==
0
)
{
result
=
flash_get_size_byte
()
/
SPI_FLASH_SEC_SIZE
;
}
return
result
;
}
}
uint8_t
ICACHE_FLASH_ATTR
uint8_t
flash_get_mode
(
void
)
flash_get_mode
(
void
)
{
{
SPIFlashInfo
*
p_
spi_flash_info
=
flash_get_info
();
SPIFlashInfo
spi_flash_info
=
flash_get_info
();
switch
(
p_
spi_flash_info
->
mode
)
switch
(
spi_flash_info
.
mode
)
{
{
// Reserved for future use
// Reserved for future use
case
MODE_QIO
:
case
MODE_QIO
:
...
@@ -156,15 +143,14 @@ flash_get_mode(void)
...
@@ -156,15 +143,14 @@ flash_get_mode(void)
case
MODE_DOUT
:
case
MODE_DOUT
:
break
;
break
;
}
}
return
p_
spi_flash_info
->
mode
;
return
spi_flash_info
.
mode
;
}
}
uint32_t
ICACHE_FLASH_ATTR
uint32_t
flash_get_speed
(
void
)
flash_get_speed
(
void
)
{
{
uint32_t
speed
=
0
;
uint32_t
speed
=
0
;
SPIFlashInfo
*
p_
spi_flash_info
=
flash_get_info
();
SPIFlashInfo
spi_flash_info
=
flash_get_info
();
switch
(
p_
spi_flash_info
->
speed
)
switch
(
spi_flash_info
.
speed
)
{
{
case
SPEED_40MHZ
:
case
SPEED_40MHZ
:
// 40MHz
// 40MHz
...
@@ -186,8 +172,21 @@ flash_get_speed(void)
...
@@ -186,8 +172,21 @@ flash_get_speed(void)
return
speed
;
return
speed
;
}
}
bool
ICACHE_FLASH_ATTR
bool
flash_init_data_written
(
void
)
flash_init_data_default
(
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
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
...
@@ -195,12 +194,11 @@ flash_init_data_default(void)
...
@@ -195,12 +194,11 @@ flash_init_data_default(void)
// It will init system data to default!
// It will init system data to default!
SPIEraseSector
((
flash_get_sec_num
()
-
4
));
SPIEraseSector
((
flash_get_sec_num
()
-
4
));
SPIW
rite
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
0x10000
-
SPI_FLASH_SEC_SIZE
+
(
0
)
,
128
);
spi_flash_w
rite
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
flash_init_data
,
128
);
return
true
;
return
true
;
}
}
bool
ICACHE_FLASH_ATTR
bool
flash_init_data_blank
(
void
)
flash_init_data_blank
(
void
)
{
{
// FLASH SEC - 2
// FLASH SEC - 2
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
...
@@ -211,8 +209,7 @@ flash_init_data_blank(void)
...
@@ -211,8 +209,7 @@ flash_init_data_blank(void)
return
true
;
return
true
;
}
}
bool
ICACHE_FLASH_ATTR
bool
flash_self_destruct
(
void
)
flash_self_destruct
(
void
)
{
{
// Erase your flash. Good bye!
// Erase your flash. Good bye!
SPIEraseChip
();
SPIEraseChip
();
...
...
app/platform/flash_api.h
View file @
bf3463d0
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#define __FLASH_API_H__
#define __FLASH_API_H__
#include "ets_sys.h"
#include "ets_sys.h"
#include "user_config.h"
#include "user_config.h"
#include "cpu_esp8266.h"
#define FLASH_MAP_START_ADDRESS (INTERNAL_FLASH_START_ADDRESS)
typedef
struct
typedef
struct
{
{
...
@@ -29,9 +31,9 @@ typedef struct
...
@@ -29,9 +31,9 @@ typedef struct
SIZE_16MBIT
=
3
,
SIZE_16MBIT
=
3
,
SIZE_32MBIT
=
4
,
SIZE_32MBIT
=
4
,
}
size
:
4
;
}
size
:
4
;
}
NOD
E_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
}
ICACH
E_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
SPIFlashInfo
*
flash_get_info
(
void
);
SPIFlashInfo
flash_get_info
(
void
);
uint8_t
flash_get_size
(
void
);
uint8_t
flash_get_size
(
void
);
uint32_t
flash_get_size_byte
(
void
);
uint32_t
flash_get_size_byte
(
void
);
bool
flash_set_size
(
uint8_t
);
bool
flash_set_size
(
uint8_t
);
...
@@ -39,6 +41,7 @@ bool flash_set_size_byte(uint32_t);
...
@@ -39,6 +41,7 @@ bool flash_set_size_byte(uint32_t);
uint16_t
flash_get_sec_num
(
void
);
uint16_t
flash_get_sec_num
(
void
);
uint8_t
flash_get_mode
(
void
);
uint8_t
flash_get_mode
(
void
);
uint32_t
flash_get_speed
(
void
);
uint32_t
flash_get_speed
(
void
);
bool
flash_init_data_written
(
void
);
bool
flash_init_data_default
(
void
);
bool
flash_init_data_default
(
void
);
bool
flash_init_data_blank
(
void
);
bool
flash_init_data_blank
(
void
);
bool
flash_self_destruct
(
void
);
bool
flash_self_destruct
(
void
);
...
...
app/platform/flash_fs.c
View file @
bf3463d0
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "spiffs.h"
#include "spiffs.h"
#endif
#endif
int
ICACHE_FLASH_ATTR
fs_mode2flag
(
const
char
*
mode
){
int
fs_mode2flag
(
const
char
*
mode
){
if
(
c_strlen
(
mode
)
==
1
){
if
(
c_strlen
(
mode
)
==
1
){
if
(
c_strcmp
(
mode
,
"w"
)
==
0
)
if
(
c_strcmp
(
mode
,
"w"
)
==
0
)
return
FS_WRONLY
|
FS_CREAT
|
FS_TRUNC
;
return
FS_WRONLY
|
FS_CREAT
|
FS_TRUNC
;
...
...
app/platform/platform.c
View file @
bf3463d0
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
static
void
pwms_init
();
static
void
pwms_init
();
int
ICACHE_FLASH_ATTR
platform_init
()
int
platform_init
()
{
{
// Setup PWMs
// Setup PWMs
pwms_init
();
pwms_init
();
...
@@ -23,7 +23,7 @@ int ICACHE_FLASH_ATTR platform_init()
...
@@ -23,7 +23,7 @@ int ICACHE_FLASH_ATTR platform_init()
// ****************************************************************************
// ****************************************************************************
// KEY_LED functions
// 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
;
uint8_t
temp
;
gpio16_output_set
(
1
);
// set to high first, for reading key low level
gpio16_output_set
(
1
);
// set to high first, for reading key low level
gpio16_input_conf
();
gpio16_input_conf
();
...
@@ -38,7 +38,7 @@ uint8_t ICACHE_FLASH_ATTR platform_key_led( uint8_t level){
...
@@ -38,7 +38,7 @@ uint8_t ICACHE_FLASH_ATTR platform_key_led( uint8_t level){
#ifdef GPIO_INTERRUPT_ENABLE
#ifdef GPIO_INTERRUPT_ENABLE
extern
void
lua_gpio_unref
(
unsigned
pin
);
extern
void
lua_gpio_unref
(
unsigned
pin
);
#endif
#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]);
// NODE_DBG("Function platform_gpio_mode() is called. pin_mux:%d, func:%d\n",pin_mux[pin],pin_func[pin]);
if
(
pin
>=
NUM_GPIO
)
if
(
pin
>=
NUM_GPIO
)
...
@@ -108,7 +108,7 @@ int ICACHE_FLASH_ATTR platform_gpio_mode( unsigned pin, unsigned mode, unsigned
...
@@ -108,7 +108,7 @@ int ICACHE_FLASH_ATTR platform_gpio_mode( unsigned pin, unsigned mode, unsigned
return
1
;
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);
// NODE_DBG("Function platform_gpio_write() is called. pin:%d, level:%d\n",GPIO_ID_PIN(pin_num[pin]),level);
if
(
pin
>=
NUM_GPIO
)
if
(
pin
>=
NUM_GPIO
)
...
@@ -122,7 +122,7 @@ int ICACHE_FLASH_ATTR platform_gpio_write( unsigned pin, unsigned level )
...
@@ -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
);
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]));
// NODE_DBG("Function platform_gpio_read() is called. pin:%d\n",GPIO_ID_PIN(pin_num[pin]));
if
(
pin
>=
NUM_GPIO
)
if
(
pin
>=
NUM_GPIO
)
...
@@ -138,7 +138,7 @@ int ICACHE_FLASH_ATTR platform_gpio_read( unsigned pin )
...
@@ -138,7 +138,7 @@ int ICACHE_FLASH_ATTR platform_gpio_read( unsigned pin )
}
}
#ifdef GPIO_INTERRUPT_ENABLE
#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
;
uint8
i
,
level
;
uint32
gpio_status
=
GPIO_REG_READ
(
GPIO_STATUS_ADDRESS
);
uint32
gpio_status
=
GPIO_REG_READ
(
GPIO_STATUS_ADDRESS
);
for
(
i
=
0
;
i
<
GPIO_PIN_NUM
;
i
++
)
{
for
(
i
=
0
;
i
<
GPIO_PIN_NUM
;
i
++
)
{
...
@@ -156,12 +156,12 @@ static void ICACHE_FLASH_ATTR platform_gpio_intr_dispatcher( platform_gpio_intr_
...
@@ -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
);
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
)
if
(
pin
>=
NUM_GPIO
)
return
-
1
;
return
-
1
;
...
@@ -181,7 +181,7 @@ int ICACHE_FLASH_ATTR platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type
...
@@ -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.
// UartDev is defined and initialized in rom code.
extern
UartDevice
UartDev
;
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
)
switch
(
baud
)
{
{
...
@@ -262,7 +262,7 @@ void platform_uart_send( unsigned id, u8 data )
...
@@ -262,7 +262,7 @@ void platform_uart_send( unsigned id, u8 data )
static
uint16_t
pwms_duty
[
NUM_PWM
]
=
{
0
};
static
uint16_t
pwms_duty
[
NUM_PWM
]
=
{
0
};
static
void
ICACHE_FLASH_ATTR
pwms_init
()
static
void
pwms_init
()
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
NUM_PWM
;
i
++
){
for
(
i
=
0
;
i
<
NUM_PWM
;
i
++
){
...
@@ -276,7 +276,7 @@ static void ICACHE_FLASH_ATTR pwms_init()
...
@@ -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,
// NOTE: Can't find a function to query for the period set for the timer,
// therefore using the struct.
// therefore using the struct.
// This may require adjustment if driver libraries are updated.
// 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");
// NODE_DBG("Function platform_pwm_get_clock() is called.\n");
if
(
pin
>=
NUM_PWM
)
if
(
pin
>=
NUM_PWM
)
...
@@ -288,7 +288,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_clock( unsigned pin )
...
@@ -288,7 +288,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_clock( unsigned pin )
}
}
// Set the PWM clock
// 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");
// NODE_DBG("Function platform_pwm_set_clock() is called.\n");
if
(
pin
>=
NUM_PWM
)
if
(
pin
>=
NUM_PWM
)
...
@@ -301,7 +301,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_set_clock( unsigned pin, uint32_t clock
...
@@ -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
);
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");
// NODE_DBG("Function platform_pwm_get_duty() is called.\n");
if
(
pin
<
NUM_PWM
){
if
(
pin
<
NUM_PWM
){
...
@@ -314,7 +314,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_duty( unsigned pin )
...
@@ -314,7 +314,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_get_duty( unsigned pin )
}
}
// Set the PWM duty
// 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");
// NODE_DBG("Function platform_pwm_set_duty() is called.\n");
if
(
pin
<
NUM_PWM
)
if
(
pin
<
NUM_PWM
)
...
@@ -330,7 +330,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_set_duty( unsigned pin, uint32_t duty )
...
@@ -330,7 +330,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_set_duty( unsigned pin, uint32_t duty )
return
pwms_duty
[
pin
];
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
;
uint32_t
clock
;
if
(
pin
<
NUM_PWM
)
if
(
pin
<
NUM_PWM
)
...
@@ -350,7 +350,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_setup( unsigned pin, uint32_t frequency,
...
@@ -350,7 +350,7 @@ uint32_t ICACHE_FLASH_ATTR platform_pwm_setup( unsigned pin, uint32_t frequency,
return
clock
;
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");
// NODE_DBG("Function platform_pwm_stop() is called.\n");
if
(
pin
<
NUM_PWM
)
if
(
pin
<
NUM_PWM
)
...
@@ -360,7 +360,7 @@ void ICACHE_FLASH_ATTR platform_pwm_close( unsigned pin )
...
@@ -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");
// NODE_DBG("Function platform_pwm_start() is called.\n");
if
(
pin
<
NUM_PWM
)
if
(
pin
<
NUM_PWM
)
...
@@ -372,7 +372,7 @@ void ICACHE_FLASH_ATTR platform_pwm_start( unsigned pin )
...
@@ -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");
// NODE_DBG("Function platform_pwm_stop() is called.\n");
if
(
pin
<
NUM_PWM
)
if
(
pin
<
NUM_PWM
)
...
@@ -387,7 +387,7 @@ void ICACHE_FLASH_ATTR platform_pwm_stop( unsigned pin )
...
@@ -387,7 +387,7 @@ void ICACHE_FLASH_ATTR platform_pwm_stop( unsigned pin )
// *****************************************************************************
// *****************************************************************************
// I2C platform interface
// 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
)
if
(
sda
>=
NUM_GPIO
||
scl
>=
NUM_GPIO
)
return
0
;
return
0
;
...
@@ -402,15 +402,15 @@ uint32_t ICACHE_FLASH_ATTR platform_i2c_setup( unsigned id, uint8_t sda, uint8_t
...
@@ -402,15 +402,15 @@ uint32_t ICACHE_FLASH_ATTR platform_i2c_setup( unsigned id, uint8_t sda, uint8_t
return
PLATFORM_I2C_SPEED_SLOW
;
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
();
i2c_master_start
();
}
}
void
ICACHE_FLASH_ATTR
platform_i2c_send_stop
(
unsigned
id
){
void
platform_i2c_send_stop
(
unsigned
id
){
i2c_master_stop
();
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.
// Convert enum codes to R/w bit value.
// If TX == 0 and RX == 1, this test will be removed by the compiler
// If TX == 0 and RX == 1, this test will be removed by the compiler
if
(
!
(
PLATFORM_I2C_DIRECTION_TRANSMITTER
==
0
&&
if
(
!
(
PLATFORM_I2C_DIRECTION_TRANSMITTER
==
0
&&
...
@@ -423,13 +423,13 @@ int ICACHE_FLASH_ATTR platform_i2c_send_address( unsigned id, uint16_t address,
...
@@ -423,13 +423,13 @@ int ICACHE_FLASH_ATTR platform_i2c_send_address( unsigned id, uint16_t address,
return
!
i2c_master_getAck
();
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
);
i2c_master_writeByte
(
data
);
// Low-level returns nack (0=acked); we return ack (1=acked).
// Low-level returns nack (0=acked); we return ack (1=acked).
return
!
i2c_master_getAck
();
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
();
uint8_t
r
=
i2c_master_readByte
();
i2c_master_setAck
(
!
ack
);
i2c_master_setAck
(
!
ack
);
return
r
;
return
r
;
...
@@ -438,7 +438,7 @@ int ICACHE_FLASH_ATTR platform_i2c_recv_byte( unsigned id, int ack ){
...
@@ -438,7 +438,7 @@ int ICACHE_FLASH_ATTR platform_i2c_recv_byte( unsigned id, int ack ){
// ****************************************************************************
// ****************************************************************************
// Flash access functions
// 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
;
toaddr
-=
INTERNAL_FLASH_START_ADDRESS
;
SpiFlashOpResult
r
;
SpiFlashOpResult
r
;
...
@@ -462,7 +462,7 @@ uint32_t ICACHE_FLASH_ATTR platform_s_flash_write( const void *from, uint32_t to
...
@@ -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
;
fromaddr
-=
INTERNAL_FLASH_START_ADDRESS
;
SpiFlashOpResult
r
;
SpiFlashOpResult
r
;
...
@@ -476,7 +476,7 @@ uint32_t ICACHE_FLASH_ATTR platform_s_flash_read( void *to, uint32_t fromaddr, u
...
@@ -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
);
WRITE_PERI_REG
(
0x60000914
,
0x73
);
return
flash_erase
(
sector_id
)
==
SPI_FLASH_RESULT_OK
?
PLATFORM_OK
:
PLATFORM_ERR
;
return
flash_erase
(
sector_id
)
==
SPI_FLASH_RESULT_OK
?
PLATFORM_OK
:
PLATFORM_ERR
;
...
...
app/smart/smart.c
View file @
bf3463d0
...
@@ -32,7 +32,7 @@ static smart_succeed succeed = NULL;
...
@@ -32,7 +32,7 @@ static smart_succeed succeed = NULL;
static
void
*
smart_succeed_arg
=
NULL
;
static
void
*
smart_succeed_arg
=
NULL
;
void
smart_end
();
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
)
if
(
len
==
0
)
return
0
;
return
0
;
uint16_t
dst_len
=
len
/
NIBBLE_PER_BYTE
;
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
...
@@ -127,7 +127,7 @@ int ICACHE_FLASH_ATTR smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, u
return
res
;
return
res
;
}
}
void
ICACHE_FLASH_ATTR
detect
(
uint8
*
buf
,
uint16
len
){
void
detect
(
uint8
*
buf
,
uint16
len
){
uint16_t
seq
;
uint16_t
seq
;
int16_t
seq_delta
=
0
;
int16_t
seq_delta
=
0
;
uint16_t
byte_num
=
0
,
bit_num
=
0
;
uint16_t
byte_num
=
0
,
bit_num
=
0
;
...
@@ -435,7 +435,7 @@ end:
...
@@ -435,7 +435,7 @@ end:
return
;
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
;
int
i
;
for
(
i
=
0
;
i
<
num
;
++
i
)
for
(
i
=
0
;
i
<
num
;
++
i
)
{
{
...
@@ -461,15 +461,15 @@ void ICACHE_FLASH_ATTR reset_map(smart_addr_map **am, size_t num){
...
@@ -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
);
wifi_promiscuous_enable
(
1
);
}
}
void
ICACHE_FLASH_ATTR
smart_disable
(
void
){
void
smart_disable
(
void
){
wifi_promiscuous_enable
(
0
);
wifi_promiscuous_enable
(
0
);
}
}
void
ICACHE_FLASH_ATTR
smart_end
(){
void
smart_end
(){
int
i
;
int
i
;
os_timer_disarm
(
&
smart_timer
);
os_timer_disarm
(
&
smart_timer
);
smart_disable
();
smart_disable
();
...
@@ -532,7 +532,7 @@ void ICACHE_FLASH_ATTR smart_end(){
...
@@ -532,7 +532,7 @@ void ICACHE_FLASH_ATTR smart_end(){
// system_restart(); // restart to enable the mode
// system_restart(); // restart to enable the mode
}
}
void
ICACHE_FLASH_ATTR
smart_next_channel
(){
void
smart_next_channel
(){
smart_disable
();
smart_disable
();
switch
(
cur_channel
){
switch
(
cur_channel
){
case
1
:
case
1
:
...
@@ -586,7 +586,7 @@ void ICACHE_FLASH_ATTR smart_next_channel(){
...
@@ -586,7 +586,7 @@ void ICACHE_FLASH_ATTR smart_next_channel(){
smart_enable
();
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
;
int
i
;
alldone
=
0
;
alldone
=
0
;
for
(
i
=
0
;
i
<
ADDR_MAP_NUM
;
++
i
)
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){
...
@@ -674,7 +674,7 @@ void ICACHE_FLASH_ATTR smart_begin(int chnl, smart_succeed s, void *arg){
smart_enable
();
smart_enable
();
}
}
void
ICACHE_FLASH_ATTR
station_check_connect
(
bool
smart
){
void
station_check_connect
(
bool
smart
){
mode
=
wifi_get_opmode
();
mode
=
wifi_get_opmode
();
if
(
(
STATION_MODE
!=
mode
)
&&
(
mode
!=
STATIONAP_MODE
)
){
if
(
(
STATION_MODE
!=
mode
)
&&
(
mode
!=
STATIONAP_MODE
)
){
return
;
return
;
...
...
app/spiffs/spiffs.c
View file @
bf3463d0
...
@@ -10,17 +10,17 @@ static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
...
@@ -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_fds
[
32
*
4
];
static
u8_t
spiffs_cache
[(
LOG_PAGE_SIZE
+
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
);
platform_flash_read
(
dst
,
addr
,
size
);
return
SPIFFS_OK
;
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
);
platform_flash_write
(
src
,
addr
,
size
);
return
SPIFFS_OK
;
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_first
=
platform_flash_get_sector_of_address
(
addr
);
u32_t
sect_last
=
sect_first
;
u32_t
sect_last
=
sect_first
;
while
(
sect_first
<=
sect_last
)
while
(
sect_first
<=
sect_last
)
...
@@ -42,7 +42,7 @@ The small 4KB sectors allow for greater flexibility in applications th
...
@@ -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
;
spiffs_config
cfg
;
cfg
.
phys_addr
=
(
u32_t
)
platform_flash_get_first_free_block_address
(
NULL
);
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
);
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() {
...
@@ -69,7 +69,7 @@ void ICACHE_FLASH_ATTR spiffs_mount() {
// FS formatting function
// FS formatting function
// Returns 1 if OK, 0 for error
// Returns 1 if OK, 0 for error
int
ICACHE_FLASH_ATTR
myspiffs_format
(
void
)
int
myspiffs_format
(
void
)
{
{
SPIFFS_unmount
(
&
fs
);
SPIFFS_unmount
(
&
fs
);
u32_t
sect_first
,
sect_last
;
u32_t
sect_first
,
sect_last
;
...
@@ -84,7 +84,7 @@ int ICACHE_FLASH_ATTR myspiffs_format( void )
...
@@ -84,7 +84,7 @@ int ICACHE_FLASH_ATTR myspiffs_format( void )
return
1
;
return
1
;
}
}
int
ICACHE_FLASH_ATTR
myspiffs_check
(
void
)
int
myspiffs_check
(
void
)
{
{
// ets_wdt_disable();
// ets_wdt_disable();
// int res = (int)SPIFFS_check(&fs);
// int res = (int)SPIFFS_check(&fs);
...
@@ -92,15 +92,15 @@ int ICACHE_FLASH_ATTR myspiffs_check( void )
...
@@ -92,15 +92,15 @@ int ICACHE_FLASH_ATTR myspiffs_check( void )
// return res;
// 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
);
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
);
SPIFFS_close
(
&
fs
,
(
spiffs_file
)
fd
);
return
0
;
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 0
if(fd==c_stdout || fd==c_stderr){
if(fd==c_stdout || fd==c_stderr){
uart0_tx_buffer((u8_t*)ptr, len);
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 ){
...
@@ -109,39 +109,39 @@ size_t ICACHE_FLASH_ATTR myspiffs_write( int fd, const void* ptr, size_t len ){
#endif
#endif
return
SPIFFS_write
(
&
fs
,
(
spiffs_file
)
fd
,
(
void
*
)
ptr
,
len
);
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
);
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
);
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
);
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
);
return
SPIFFS_tell
(
&
fs
,
(
spiffs_file
)
fd
);
}
}
int
ICACHE_FLASH_ATTR
myspiffs_getc
(
int
fd
){
int
myspiffs_getc
(
int
fd
){
char
c
=
EOF
;
char
c
=
EOF
;
if
(
!
myspiffs_eof
(
fd
)){
if
(
!
myspiffs_eof
(
fd
)){
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
&
c
,
1
);
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
&
c
,
1
);
}
}
return
(
int
)
c
;
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
);
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
);
return
SPIFFS_fflush
(
&
fs
,
(
spiffs_file
)
fd
);
}
}
int
ICACHE_FLASH_ATTR
myspiffs_error
(
int
fd
){
int
myspiffs_error
(
int
fd
){
return
SPIFFS_errno
(
&
fs
);
return
SPIFFS_errno
(
&
fs
);
}
}
void
ICACHE_FLASH_ATTR
myspiffs_clearerr
(
int
fd
){
void
myspiffs_clearerr
(
int
fd
){
fs
.
errno
=
SPIFFS_OK
;
fs
.
errno
=
SPIFFS_OK
;
}
}
#if 0
#if 0
void
ICACHE_FLASH_ATTR
test_spiffs() {
void test_spiffs() {
char buf[12];
char buf[12];
// Surely, I've mounted spiffs before entering here
// Surely, I've mounted spiffs before entering here
...
...
app/spiffs/spiffs_cache.c
View file @
bf3463d0
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#if SPIFFS_CACHE
#if SPIFFS_CACHE
// returns cached page for give page index, or null if no such cached page
// 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
);
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
if
((
cache
->
cpage_use_map
&
cache
->
cpage_use_mask
)
==
0
)
return
0
;
if
((
cache
->
cpage_use_map
&
cache
->
cpage_use_mask
)
==
0
)
return
0
;
int
i
;
int
i
;
...
@@ -30,7 +30,7 @@ static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get(spiffs *fs, sp
...
@@ -30,7 +30,7 @@ static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_get(spiffs *fs, sp
}
}
// frees cached page
// 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
;
s32_t
res
=
SPIFFS_OK
;
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
spiffs_cache_page
*
cp
=
spiffs_get_cache_page_hdr
(
fs
,
cache
,
ix
);
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
...
@@ -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
// 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
;
s32_t
res
=
SPIFFS_OK
;
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
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
...
@@ -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
// 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
);
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
if
(
cache
->
cpage_use_map
==
0xffffffff
)
{
if
(
cache
->
cpage_use_map
==
0xffffffff
)
{
// out of cache memory
// out of cache memory
...
@@ -107,7 +107,7 @@ static spiffs_cache_page *ICACHE_FLASH_ATTR spiffs_cache_page_allocate(spiffs *f
...
@@ -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
// 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
);
spiffs_cache_page
*
cp
=
spiffs_cache_page_get
(
fs
,
pix
);
if
(
cp
)
{
if
(
cp
)
{
spiffs_cache_page_free
(
fs
,
cp
->
ix
,
0
);
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) {
...
@@ -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
// reads from spi flash or the cache
s32_t
ICACHE_FLASH_ATTR
spiffs_phys_rd
(
s32_t
spiffs_phys_rd
(
spiffs
*
fs
,
spiffs
*
fs
,
u8_t
op
,
u8_t
op
,
spiffs_file
fh
,
spiffs_file
fh
,
...
@@ -165,7 +165,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
...
@@ -165,7 +165,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
}
}
// writes to spi flash and/or the cache
// writes to spi flash and/or the cache
s32_t
ICACHE_FLASH_ATTR
spiffs_phys_wr
(
s32_t
spiffs_phys_wr
(
spiffs
*
fs
,
spiffs
*
fs
,
u8_t
op
,
u8_t
op
,
spiffs_file
fh
,
spiffs_file
fh
,
...
@@ -207,7 +207,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
...
@@ -207,7 +207,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
#if SPIFFS_CACHE_WR
#if SPIFFS_CACHE_WR
// returns the cache page that this fd refers, or null if no cache page
// 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
);
spiffs_cache
*
cache
=
spiffs_get_cache
(
fs
);
if
((
cache
->
cpage_use_map
&
cache
->
cpage_use_mask
)
==
0
)
{
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
...
@@ -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
// allocates a new cache page and refers this to given fd - flushes an old cache
// page if all cache is busy
// 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
// before this function is called, it is ensured that there is no already existing
// cache page with same object id
// cache page with same object id
spiffs_cache_page_remove_oldest
(
fs
,
SPIFFS_CACHE_FLAG_TYPE_WR
,
0
);
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
...
@@ -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
// 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
;
if
(
cp
==
0
)
return
;
int
i
;
int
i
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
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
...
@@ -265,7 +265,7 @@ void ICACHE_FLASH_ATTR spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp
#endif
#endif
// initializes the cache
// initializes the cache
void
ICACHE_FLASH_ATTR
spiffs_cache_init
(
spiffs
*
fs
)
{
void
spiffs_cache_init
(
spiffs
*
fs
)
{
if
(
fs
->
cache
==
0
)
return
;
if
(
fs
->
cache
==
0
)
return
;
u32_t
sz
=
fs
->
cache_size
;
u32_t
sz
=
fs
->
cache_size
;
u32_t
cache_mask
=
0
;
u32_t
cache_mask
=
0
;
...
...
app/spiffs/spiffs_check.c
View file @
bf3463d0
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
// searches in the object indices and returns the referenced page index given
// searches in the object indices and returns the referenced page index given
// the object id and the data span index
// the object id and the data span index
// destroys fs->lu_work
// 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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_span_ix
data_spix
,
spiffs_span_ix
data_spix
,
...
@@ -59,7 +59,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_object_get_data_page_index_reference(
...
@@ -59,7 +59,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_object_get_data_page_index_reference(
}
}
// copies page contents to a new page
// 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
;
s32_t
res
;
res
=
spiffs_page_allocate_data
(
fs
,
p_hdr
->
obj_id
,
p_hdr
,
0
,
0
,
0
,
0
,
new_pix
);
res
=
spiffs_page_allocate_data
(
fs
,
p_hdr
->
obj_id
,
p_hdr
,
0
,
0
,
0
,
0
,
new_pix
);
SPIFFS_CHECK_RES
(
res
);
SPIFFS_CHECK_RES
(
res
);
...
@@ -73,7 +73,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_page(spiffs *fs, spiffs_page_ix cu
...
@@ -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
// rewrites the object index for given object id and replaces the
// data page index to a new page index
// 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
;
s32_t
res
;
spiffs_block_ix
bix
;
spiffs_block_ix
bix
;
int
entry
;
int
entry
;
...
@@ -137,7 +137,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_rewrite_index(spiffs *fs, spiffs_obj_id ob
...
@@ -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
// 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
;
spiffs_page_ix
objix_hdr_pix
;
s32_t
res
;
s32_t
res
;
res
=
spiffs_obj_lu_find_id_and_span
(
fs
,
obj_id
,
0
,
0
,
&
objix_hdr_pix
);
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
...
@@ -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
// 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
)
{
spiffs_page_ix
cur_pix
,
spiffs_block_ix
cur_block
,
int
cur_entry
,
int
*
reload_lu
)
{
u8_t
delete_page
=
0
;
u8_t
delete_page
=
0
;
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
...
@@ -424,7 +424,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_validate(spiffs *fs, spiffs_o
...
@@ -424,7 +424,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_lookup_check_validate(spiffs *fs, spiffs_o
return
res
;
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
)
{
u32_t
user_data
,
void
*
user_p
)
{
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
spiffs_page_header
p_hdr
;
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
...
@@ -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.
// 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
// 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
;
s32_t
res
=
SPIFFS_OK
;
if
(
fs
->
check_cb_f
)
fs
->
check_cb_f
(
SPIFFS_CHECK_LOOKUP
,
SPIFFS_CHECK_PROGRESS
,
0
,
0
);
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
...
@@ -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
// * x011 used, referenced only once, not index
// * x101 used, unreferenced, index
// * x101 used, unreferenced, index
// The working memory might not fit all pages so several scans might be needed
// 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
u32_t
bits
=
4
;
const
spiffs_page_ix
pages_per_scan
=
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
*
8
/
bits
;
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) {
...
@@ -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
// 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
);
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
);
s32_t
res
=
spiffs_page_consistency_check_i
(
fs
);
if
(
res
!=
SPIFFS_OK
)
{
if
(
res
!=
SPIFFS_OK
)
{
...
@@ -837,7 +837,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_consistency_check(spiffs *fs) {
...
@@ -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,
// searches for given object id in temporary object id index,
// returns the index or -1
// 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
;
int
i
;
spiffs_obj_id
*
obj_table
=
(
spiffs_obj_id
*
)
fs
->
work
;
spiffs_obj_id
*
obj_table
=
(
spiffs_obj_id
*
)
fs
->
work
;
obj_id
&=
~
SPIFFS_OBJ_ID_IX_FLAG
;
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
...
@@ -849,7 +849,7 @@ static int ICACHE_FLASH_ATTR spiffs_object_index_search(spiffs *fs, spiffs_obj_i
return
-
1
;
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
)
{
int
cur_entry
,
u32_t
user_data
,
void
*
user_p
)
{
s32_t
res_c
=
SPIFFS_VIS_COUNTINUE
;
s32_t
res_c
=
SPIFFS_VIS_COUNTINUE
;
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
...
@@ -943,7 +943,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_index_consistency_check_v(spiffs *fs, spif
...
@@ -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.
// 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
// If no such page exists, the index page cannot be reached as no index header exists and must be
// deleted.
// 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
;
s32_t
res
=
SPIFFS_OK
;
// impl note:
// impl note:
// fs->work is used for a temporary object index memory, listing found object ids and
// fs->work is used for a temporary object index memory, listing found object ids and
...
...
app/spiffs/spiffs_gc.c
View file @
bf3463d0
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
// Erases a logical block and updates the erase counter.
// Erases a logical block and updates the erase counter.
// If cache is enabled, all pages that might be cached in this block
// If cache is enabled, all pages that might be cached in this block
// is dropped.
// is dropped.
static
s32_t
ICACHE_FLASH_ATTR
spiffs_gc_erase_block
(
static
s32_t
spiffs_gc_erase_block
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_block_ix
bix
)
{
spiffs_block_ix
bix
)
{
s32_t
res
;
s32_t
res
;
...
@@ -47,7 +47,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_block(
...
@@ -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,
// 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
// 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.
// 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
)
{
spiffs
*
fs
)
{
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
u32_t
blocks
=
fs
->
block_count
;
u32_t
blocks
=
fs
->
block_count
;
...
@@ -111,7 +111,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_quick(
...
@@ -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,
// Checks if garbaga collecting is necessary. If so a candidate block is found,
// cleansed and erased
// cleansed and erased
s32_t
ICACHE_FLASH_ATTR
spiffs_gc_check
(
s32_t
spiffs_gc_check
(
spiffs
*
fs
,
spiffs
*
fs
,
u32_t
len
)
{
u32_t
len
)
{
s32_t
res
;
s32_t
res
;
...
@@ -179,7 +179,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_check(
...
@@ -179,7 +179,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_check(
}
}
// Updates page statistics for a block that is about to be erased
// 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
*
fs
,
spiffs_block_ix
bix
)
{
spiffs_block_ix
bix
)
{
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
...
@@ -216,7 +216,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_page_stats(
...
@@ -216,7 +216,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_gc_erase_page_stats(
}
}
// Finds block candidates to erase
// Finds block candidates to erase
s32_t
ICACHE_FLASH_ATTR
spiffs_gc_find_candidate
(
s32_t
spiffs_gc_find_candidate
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_block_ix
**
block_candidates
,
spiffs_block_ix
**
block_candidates
,
int
*
candidate_count
)
{
int
*
candidate_count
)
{
...
@@ -350,7 +350,7 @@ typedef struct {
...
@@ -350,7 +350,7 @@ typedef struct {
// repeat loop until end of object lookup
// repeat loop until end of object lookup
// scan object lookup again for remaining object index pages, move to new page in other block
// 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
;
s32_t
res
=
SPIFFS_OK
;
u32_t
entries_per_page
=
(
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
/
sizeof
(
spiffs_obj_id
));
u32_t
entries_per_page
=
(
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
/
sizeof
(
spiffs_obj_id
));
int
cur_entry
=
0
;
int
cur_entry
=
0
;
...
...
app/spiffs/spiffs_hydrogen.c
View file @
bf3463d0
...
@@ -11,17 +11,17 @@
...
@@ -11,17 +11,17 @@
static
s32_t
spiffs_fflush_cache
(
spiffs
*
fs
,
spiffs_file
fh
);
static
s32_t
spiffs_fflush_cache
(
spiffs
*
fs
,
spiffs_file
fh
);
#if SPIFFS_BUFFER_HELP
#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
);
return
num_descs
*
sizeof
(
spiffs_fd
);
}
}
#if SPIFFS_CACHE
#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
));
return
sizeof
(
spiffs_cache
)
+
num_pages
*
(
sizeof
(
spiffs_cache_page
)
+
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
));
}
}
#endif
#endif
#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
,
u8_t
*
fd_space
,
u32_t
fd_space_size
,
void
*
cache
,
u32_t
cache_size
,
void
*
cache
,
u32_t
cache_size
,
spiffs_check_callback
check_cb_f
)
{
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
...
@@ -82,7 +82,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *wo
return
0
;
return
0
;
}
}
void
ICACHE_FLASH_ATTR
SPIFFS_unmount
(
spiffs
*
fs
)
{
void
SPIFFS_unmount
(
spiffs
*
fs
)
{
if
(
!
SPIFFS_CHECK_MOUNT
(
fs
))
return
;
if
(
!
SPIFFS_CHECK_MOUNT
(
fs
))
return
;
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
int
i
;
int
i
;
...
@@ -100,11 +100,11 @@ void ICACHE_FLASH_ATTR SPIFFS_unmount(spiffs *fs) {
...
@@ -100,11 +100,11 @@ void ICACHE_FLASH_ATTR SPIFFS_unmount(spiffs *fs) {
SPIFFS_UNLOCK
(
fs
);
SPIFFS_UNLOCK
(
fs
);
}
}
s32_t
ICACHE_FLASH_ATTR
SPIFFS_errno
(
spiffs
*
fs
)
{
s32_t
SPIFFS_errno
(
spiffs
*
fs
)
{
return
fs
->
errno
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
spiffs_obj_id
obj_id
;
spiffs_obj_id
obj_id
;
...
@@ -118,7 +118,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode m
...
@@ -118,7 +118,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode m
return
0
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -175,7 +175,7 @@ spiffs_file ICACHE_FLASH_ATTR SPIFFS_open(spiffs *fs, const char *path, spiffs_f
...
@@ -175,7 +175,7 @@ spiffs_file ICACHE_FLASH_ATTR SPIFFS_open(spiffs *fs, const char *path, spiffs_f
return
fd
->
file_nbr
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -220,7 +220,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, u32_t
...
@@ -220,7 +220,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, u32_t
return
len
;
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
res
=
SPIFFS_OK
;
s32_t
remaining
=
len
;
s32_t
remaining
=
len
;
if
(
fd
->
size
!=
SPIFFS_UNDEFINED_LEN
&&
offset
<
fd
->
size
)
{
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
...
@@ -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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -357,7 +357,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, u32_
...
@@ -357,7 +357,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, u32_
return
res
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -401,7 +401,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int
...
@@ -401,7 +401,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int
return
0
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -434,7 +434,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_remove(spiffs *fs, const char *path) {
...
@@ -434,7 +434,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_remove(spiffs *fs, const char *path) {
return
0
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -461,7 +461,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
...
@@ -461,7 +461,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fremove(spiffs *fs, spiffs_file fh) {
return
0
;
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_page_object_ix_header
objix_hdr
;
spiffs_obj_id
obj_id
;
spiffs_obj_id
obj_id
;
s32_t
res
=
_spiffs_rd
(
fs
,
SPIFFS_OP_T_OBJ_IX
|
SPIFFS_OP_C_READ
,
fh
,
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
...
@@ -482,7 +482,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, s
return
res
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -499,7 +499,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s
...
@@ -499,7 +499,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s
return
res
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -522,7 +522,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fstat(spiffs *fs, spiffs_file fh, spiffs_stat *s)
...
@@ -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
// Checks if there are any cached writes for the object id associated with
// given filehandle. If so, these writes are flushed.
// 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
;
s32_t
res
=
SPIFFS_OK
;
#if SPIFFS_CACHE_WR
#if SPIFFS_CACHE_WR
...
@@ -552,7 +552,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_fflush_cache(spiffs *fs, spiffs_file fh) {
...
@@ -552,7 +552,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_fflush_cache(spiffs *fs, spiffs_file fh) {
return
res
;
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
);
SPIFFS_API_CHECK_MOUNT
(
fs
);
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
#if SPIFFS_CACHE_WR
#if SPIFFS_CACHE_WR
...
@@ -565,7 +565,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
...
@@ -565,7 +565,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_fflush(spiffs *fs, spiffs_file fh) {
return
res
;
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
))
{
if
(
!
SPIFFS_CHECK_MOUNT
(
fs
))
{
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
return
;
return
;
...
@@ -580,7 +580,7 @@ void ICACHE_FLASH_ATTR SPIFFS_close(spiffs *fs, spiffs_file fh) {
...
@@ -580,7 +580,7 @@ void ICACHE_FLASH_ATTR SPIFFS_close(spiffs *fs, spiffs_file fh) {
SPIFFS_UNLOCK
(
fs
);
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
))
{
if
(
!
SPIFFS_CHECK_MOUNT
(
fs
))
{
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
return
0
;
return
0
;
...
@@ -591,7 +591,7 @@ spiffs_DIR *ICACHE_FLASH_ATTR SPIFFS_opendir(spiffs *fs, const char *name, spiff
...
@@ -591,7 +591,7 @@ spiffs_DIR *ICACHE_FLASH_ATTR SPIFFS_opendir(spiffs *fs, const char *name, spiff
return
d
;
return
d
;
}
}
static
s32_t
ICACHE_FLASH_ATTR
spiffs_read_dir_v
(
static
s32_t
spiffs_read_dir_v
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_block_ix
bix
,
spiffs_block_ix
bix
,
...
@@ -624,7 +624,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_read_dir_v(
...
@@ -624,7 +624,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_read_dir_v(
return
SPIFFS_VIS_COUNTINUE
;
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
))
{
if
(
!
SPIFFS_CHECK_MOUNT
(
d
->
fs
))
{
d
->
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
d
->
fs
->
errno
=
SPIFFS_ERR_NOT_MOUNTED
;
return
0
;
return
0
;
...
@@ -657,12 +657,12 @@ struct spiffs_dirent *ICACHE_FLASH_ATTR SPIFFS_readdir(spiffs_DIR *d, struct spi
...
@@ -657,12 +657,12 @@ struct spiffs_dirent *ICACHE_FLASH_ATTR SPIFFS_readdir(spiffs_DIR *d, struct spi
return
ret
;
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
);
SPIFFS_API_CHECK_MOUNT
(
d
->
fs
);
return
0
;
return
0
;
}
}
s32_t
ICACHE_FLASH_ATTR
SPIFFS_check
(
spiffs
*
fs
)
{
s32_t
SPIFFS_check
(
spiffs
*
fs
)
{
s32_t
res
;
s32_t
res
;
SPIFFS_API_CHECK_MOUNT
(
fs
);
SPIFFS_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -679,7 +679,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_check(spiffs *fs) {
...
@@ -679,7 +679,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_check(spiffs *fs) {
return
res
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -698,7 +698,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_eof(spiffs *fs, spiffs_file fh) {
...
@@ -698,7 +698,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_eof(spiffs *fs, spiffs_file fh) {
return
res
;
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_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
@@ -718,7 +718,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_tell(spiffs *fs, spiffs_file fh) {
...
@@ -718,7 +718,7 @@ s32_t ICACHE_FLASH_ATTR SPIFFS_tell(spiffs *fs, spiffs_file fh) {
}
}
#if SPIFFS_TEST_VISUALISATION
#if SPIFFS_TEST_VISUALISATION
s32_t
ICACHE_FLASH_ATTR
SPIFFS_vis
(
spiffs
*
fs
)
{
s32_t
SPIFFS_vis
(
spiffs
*
fs
)
{
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
SPIFFS_API_CHECK_MOUNT
(
fs
);
SPIFFS_API_CHECK_MOUNT
(
fs
);
SPIFFS_LOCK
(
fs
);
SPIFFS_LOCK
(
fs
);
...
...
app/spiffs/spiffs_nucleus.c
View file @
bf3463d0
#include "spiffs.h"
#include "spiffs.h"
#include "spiffs_nucleus.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
;
s32_t
res
=
SPIFFS_OK
;
if
(
pix
==
(
spiffs_page_ix
)
-
1
)
{
if
(
pix
==
(
spiffs_page_ix
)
-
1
)
{
// referring to page 0xffff...., bad object index
// 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,
...
@@ -29,7 +29,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_page_data_check(spiffs *fs, spiffs_fd *fd,
return
res
;
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
;
s32_t
res
=
SPIFFS_OK
;
if
(
pix
==
(
spiffs_page_ix
)
-
1
)
{
if
(
pix
==
(
spiffs_page_ix
)
-
1
)
{
// referring to page 0xffff...., bad object index
// 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
...
@@ -59,7 +59,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_page_index_check(spiffs *fs, spiffs_fd *fd
#if !SPIFFS_CACHE
#if !SPIFFS_CACHE
s32_t
ICACHE_FLASH_ATTR
spiffs_phys_rd
(
s32_t
spiffs_phys_rd
(
spiffs
*
fs
,
spiffs
*
fs
,
u32_t
addr
,
u32_t
addr
,
u32_t
len
,
u32_t
len
,
...
@@ -67,7 +67,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
...
@@ -67,7 +67,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_rd(
return
fs
->
cfg
.
hal_read_f
(
addr
,
len
,
dst
);
return
fs
->
cfg
.
hal_read_f
(
addr
,
len
,
dst
);
}
}
s32_t
ICACHE_FLASH_ATTR
spiffs_phys_wr
(
s32_t
spiffs_phys_wr
(
spiffs
*
fs
,
spiffs
*
fs
,
u32_t
addr
,
u32_t
addr
,
u32_t
len
,
u32_t
len
,
...
@@ -77,7 +77,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
...
@@ -77,7 +77,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_wr(
#endif
#endif
s32_t
ICACHE_FLASH_ATTR
spiffs_phys_cpy
(
s32_t
spiffs_phys_cpy
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_file
fh
,
spiffs_file
fh
,
u32_t
dst
,
u32_t
dst
,
...
@@ -116,7 +116,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_cpy(
...
@@ -116,7 +116,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_phys_cpy(
// @param user_p any pointer, passed to the callback visitor function
// @param user_p any pointer, passed to the callback visitor function
// @param block_ix reported block index where match was found
// @param block_ix reported block index where match was found
// @param lu_entry reported look up 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
*
fs
,
spiffs_block_ix
starting_block
,
spiffs_block_ix
starting_block
,
int
starting_lu_entry
,
int
starting_lu_entry
,
...
@@ -214,7 +214,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_entry_visitor(
...
@@ -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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_block_ix
bix
,
spiffs_block_ix
bix
,
...
@@ -237,7 +237,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan_v(
...
@@ -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
// Scans thru all obj lu and counts free, deleted and used pages
// Find the maximum block erase count
// Find the maximum block erase count
s32_t
ICACHE_FLASH_ATTR
spiffs_obj_lu_scan
(
s32_t
spiffs_obj_lu_scan
(
spiffs
*
fs
)
{
spiffs
*
fs
)
{
s32_t
res
;
s32_t
res
;
spiffs_block_ix
bix
;
spiffs_block_ix
bix
;
...
@@ -299,7 +299,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan(
...
@@ -299,7 +299,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_scan(
// Find free object lookup entry
// Find free object lookup entry
// Iterate over object lookup pages in each block until a free object id entry is found
// 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
*
fs
,
spiffs_block_ix
starting_block
,
spiffs_block_ix
starting_block
,
int
starting_lu_entry
,
int
starting_lu_entry
,
...
@@ -331,7 +331,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free(
...
@@ -331,7 +331,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free(
// Find object lookup entry containing given id
// Find object lookup entry containing given id
// Iterate over object lookup pages in each block until a given object id entry is found
// 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
*
fs
,
spiffs_block_ix
starting_block
,
spiffs_block_ix
starting_block
,
int
starting_lu_entry
,
int
starting_lu_entry
,
...
@@ -347,7 +347,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id(
...
@@ -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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_block_ix
bix
,
spiffs_block_ix
bix
,
...
@@ -373,7 +373,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_v(
...
@@ -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
// 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
// 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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_span_ix
spix
,
spiffs_span_ix
spix
,
...
@@ -412,7 +412,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span(
...
@@ -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
// 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
// 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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_span_ix
spix
,
spiffs_span_ix
spix
,
...
@@ -452,7 +452,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_id_and_span_by_phdr(
...
@@ -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
// Allocates a free defined page with given obj_id
// Occupies object lookup entry and page
// Occupies object lookup entry and page
// data may be NULL; where only page header is stored, len and page_offs is ignored
// 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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_page_header
*
ph
,
spiffs_page_header
*
ph
,
...
@@ -509,7 +509,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_allocate_data(
...
@@ -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.
// 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.
// 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
*
fs
,
spiffs_file
fh
,
spiffs_file
fh
,
u8_t
*
page_data
,
u8_t
*
page_data
,
...
@@ -571,7 +571,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_move(
...
@@ -571,7 +571,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_move(
}
}
// Deletes a page and removes it from object lookup.
// 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
*
fs
,
spiffs_page_ix
pix
)
{
spiffs_page_ix
pix
)
{
s32_t
res
;
s32_t
res
;
...
@@ -600,7 +600,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_delete(
...
@@ -600,7 +600,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_page_delete(
}
}
// Create an object index header page with empty index and undefined length
// 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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
u8_t
name
[
SPIFFS_OBJ_NAME_LEN
],
u8_t
name
[
SPIFFS_OBJ_NAME_LEN
],
...
@@ -655,7 +655,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_create(
...
@@ -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
// 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
// name may be null, if so name is not changed
// size may be null, if so size 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
*
fs
,
spiffs_fd
*
fd
,
spiffs_fd
*
fd
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
...
@@ -706,7 +706,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_update_index_hdr(
...
@@ -706,7 +706,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_update_index_hdr(
return
res
;
return
res
;
}
}
void
ICACHE_FLASH_ATTR
spiffs_cb_object_event
(
void
spiffs_cb_object_event
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_fd
*
fd
,
spiffs_fd
*
fd
,
int
ev
,
int
ev
,
...
@@ -745,7 +745,7 @@ void ICACHE_FLASH_ATTR spiffs_cb_object_event(
...
@@ -745,7 +745,7 @@ void ICACHE_FLASH_ATTR spiffs_cb_object_event(
}
}
// Open object by id
// Open object by id
s32_t
ICACHE_FLASH_ATTR
spiffs_object_open_by_id
(
s32_t
spiffs_object_open_by_id
(
spiffs
*
fs
,
spiffs
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_fd
*
fd
,
spiffs_fd
*
fd
,
...
@@ -763,7 +763,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_id(
...
@@ -763,7 +763,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_id(
}
}
// Open object by page index
// 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
*
fs
,
spiffs_page_ix
pix
,
spiffs_page_ix
pix
,
spiffs_fd
*
fd
,
spiffs_fd
*
fd
,
...
@@ -801,7 +801,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_page(
...
@@ -801,7 +801,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_open_by_page(
// Append to object
// Append to object
// keep current object index (header) page in fs->work buffer
// 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
;
spiffs
*
fs
=
fd
->
fs
;
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
u32_t
written
=
0
;
u32_t
written
=
0
;
...
@@ -1032,7 +1032,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *
...
@@ -1032,7 +1032,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *
// Modify object
// Modify object
// keep current object index (header) page in fs->work buffer
// 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
;
spiffs
*
fs
=
fd
->
fs
;
s32_t
res
=
SPIFFS_OK
;
s32_t
res
=
SPIFFS_OK
;
u32_t
written
=
0
;
u32_t
written
=
0
;
...
@@ -1231,7 +1231,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *
...
@@ -1231,7 +1231,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *
return
res
;
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
*
fs
,
spiffs_obj_id
obj_id
,
spiffs_obj_id
obj_id
,
spiffs_block_ix
bix
,
spiffs_block_ix
bix
,
...
@@ -1260,7 +1260,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name_v(
...
@@ -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
// 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
,
spiffs
*
fs
,
u8_t
name
[
SPIFFS_OBJ_NAME_LEN
],
u8_t
name
[
SPIFFS_OBJ_NAME_LEN
],
spiffs_page_ix
*
pix
)
{
spiffs_page_ix
*
pix
)
{
...
@@ -1295,7 +1295,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_find_object_index_header_by_name(
...
@@ -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
// 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
,
spiffs_fd
*
fd
,
u32_t
new_size
,
u32_t
new_size
,
u8_t
remove
)
{
u8_t
remove
)
{
...
@@ -1502,7 +1502,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_truncate(
...
@@ -1502,7 +1502,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_object_truncate(
return
res
;
return
res
;
}
}
s32_t
ICACHE_FLASH_ATTR
spiffs_object_read
(
s32_t
spiffs_object_read
(
spiffs_fd
*
fd
,
spiffs_fd
*
fd
,
u32_t
offset
,
u32_t
offset
,
u32_t
len
,
u32_t
len
,
...
@@ -1586,7 +1586,7 @@ typedef struct {
...
@@ -1586,7 +1586,7 @@ typedef struct {
u32_t
compaction
;
u32_t
compaction
;
}
spiffs_free_obj_id_state
;
}
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
)
{
u32_t
user_data
,
void
*
user_p
)
{
if
(
id
!=
SPIFFS_OBJ_ID_FREE
&&
id
!=
SPIFFS_OBJ_ID_DELETED
)
{
if
(
id
!=
SPIFFS_OBJ_ID_FREE
&&
id
!=
SPIFFS_OBJ_ID_DELETED
)
{
spiffs_obj_id
min_obj_id
=
user_data
;
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
...
@@ -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
;
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
)
{
u32_t
user_data
,
void
*
user_p
)
{
if
(
id
!=
SPIFFS_OBJ_ID_FREE
&&
id
!=
SPIFFS_OBJ_ID_DELETED
&&
(
id
&
SPIFFS_OBJ_ID_IX_FLAG
))
{
if
(
id
!=
SPIFFS_OBJ_ID_FREE
&&
id
!=
SPIFFS_OBJ_ID_DELETED
&&
(
id
&
SPIFFS_OBJ_ID_IX_FLAG
))
{
s32_t
res
;
s32_t
res
;
...
@@ -1629,7 +1629,7 @@ static s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *
...
@@ -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 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.
// 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
// 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
;
s32_t
res
=
SPIFFS_OK
;
u32_t
max_objects
=
(
SPIFFS_CFG_PHYS_SZ
(
fs
)
/
(
u32_t
)
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
))
/
2
;
u32_t
max_objects
=
(
SPIFFS_CFG_PHYS_SZ
(
fs
)
/
(
u32_t
)
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
))
/
2
;
spiffs_free_obj_id_state
state
;
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
...
@@ -1720,7 +1720,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id
return
res
;
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
;
int
i
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
for
(
i
=
0
;
i
<
fs
->
fd_count
;
i
++
)
{
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) {
...
@@ -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
;
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
)
{
if
(
f
<=
0
||
f
>
fs
->
fd_count
)
{
return
SPIFFS_ERR_BAD_DESCRIPTOR
;
return
SPIFFS_ERR_BAD_DESCRIPTOR
;
}
}
...
@@ -1747,7 +1747,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_fd_return(spiffs *fs, spiffs_file f) {
...
@@ -1747,7 +1747,7 @@ s32_t ICACHE_FLASH_ATTR spiffs_fd_return(spiffs *fs, spiffs_file f) {
return
SPIFFS_OK
;
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
)
{
if
(
f
<=
0
||
f
>
fs
->
fd_count
)
{
return
SPIFFS_ERR_BAD_DESCRIPTOR
;
return
SPIFFS_ERR_BAD_DESCRIPTOR
;
}
}
...
...
app/user/user_main.c
View file @
bf3463d0
...
@@ -82,6 +82,12 @@ void user_init(void)
...
@@ -82,6 +82,12 @@ void user_init(void)
NODE_DBG
(
"Can not init platform for modules.
\n
"
);
NODE_DBG
(
"Can not init platform for modules.
\n
"
);
return
;
return
;
}
}
if
(
!
flash_init_data_written
()){
NODE_ERR
(
"Restore init data.
\n
"
);
flash_init_data_default
();
}
#if defined( BUILD_WOFS )
#if defined( BUILD_WOFS )
romfs_init
();
romfs_init
();
...
...
app/wofs/romfs.c
View file @
bf3463d0
...
@@ -28,7 +28,7 @@ static int romfs_num_fd;
...
@@ -28,7 +28,7 @@ static int romfs_num_fd;
// Length of the 'file size' field for both ROMFS/WOFS
// Length of the 'file size' field for both ROMFS/WOFS
#define ROMFS_SIZE_LEN 4
#define ROMFS_SIZE_LEN 4
static
int
ICACHE_FLASH_ATTR
romfs_find_empty_fd
(
void
)
static
int
romfs_find_empty_fd
(
void
)
{
{
int
i
;
int
i
;
...
@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR romfs_find_empty_fd(void)
...
@@ -40,7 +40,7 @@ static int ICACHE_FLASH_ATTR romfs_find_empty_fd(void)
return
-
1
;
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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
;
return
;
...
@@ -49,7 +49,7 @@ static void ICACHE_FLASH_ATTR romfs_close_fd( int fd )
...
@@ -49,7 +49,7 @@ static void ICACHE_FLASH_ATTR romfs_close_fd( int fd )
}
}
// Helper function: read a byte from the FS
// 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
;
uint8_t
temp
;
if
(
pfs
->
flags
&
ROMFS_FS_FLAG_DIRECT
)
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
...
@@ -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
// 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
;
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.
// 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
i
,
j
,
n
;
uint32_t
fsize
;
uint32_t
fsize
;
...
@@ -120,7 +120,7 @@ static uint8_t ICACHE_FLASH_ATTR romfs_next_file( uint32_t *start, char* fname,
...
@@ -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
// Open the given file, returning one of FS_FILE_NOT_FOUND, FS_FILE_ALREADY_OPENED
// or FS_FILE_OK
// 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
;
uint32_t
i
,
j
,
n
;
char
fsname
[
MAX_FNAME_LENGTH
+
1
];
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
...
@@ -184,7 +184,7 @@ static uint8_t ICACHE_FLASH_ATTR romfs_open_file( const char* fname, FD* pfd, FS
return
FS_FILE_NOT_FOUND
;
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
;
FD
tempfs
;
int
i
;
int
i
;
...
@@ -295,7 +295,7 @@ static int ICACHE_FLASH_ATTR romfs_open( const char *path, int flags, int mode,
...
@@ -295,7 +295,7 @@ static int ICACHE_FLASH_ATTR romfs_open( const char *path, int flags, int mode,
return
i
;
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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
0
;
return
0
;
...
@@ -320,7 +320,7 @@ static int ICACHE_FLASH_ATTR romfs_close( int fd, void *pdata )
...
@@ -320,7 +320,7 @@ static int ICACHE_FLASH_ATTR romfs_close( int fd, void *pdata )
return
0
;
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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
-
1
;
return
-
1
;
...
@@ -350,7 +350,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_write( int fd, const void* ptr, size_t l
...
@@ -350,7 +350,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_write( int fd, const void* ptr, size_t l
return
len
;
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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
-
1
;
return
-
1
;
...
@@ -374,7 +374,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_read( int fd, void* ptr, size_t len, voi
...
@@ -374,7 +374,7 @@ static _ssize_t ICACHE_FLASH_ATTR romfs_read( int fd, void* ptr, size_t len, voi
}
}
// lseek
// 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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
-
1
;
return
-
1
;
...
@@ -409,7 +409,7 @@ static int ICACHE_FLASH_ATTR romfs_lseek( int fd, int off, int whence, void *pda
...
@@ -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
// WOFS functions and instance descriptor for real hardware
#if defined( BUILD_WOFS )
#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
;
const
FSDATA
*
pfsdata
=
(
const
FSDATA
*
)
pdata
;
if
(
toaddr
>=
INTERNAL_FLASH_SIZE
)
if
(
toaddr
>=
INTERNAL_FLASH_SIZE
)
...
@@ -421,7 +421,7 @@ static uint32_t ICACHE_FLASH_ATTR sim_wofs_write( const void *from, uint32_t toa
...
@@ -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
);
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
;
const
FSDATA
*
pfsdata
=
(
const
FSDATA
*
)
pdata
;
if
(
fromaddr
>=
INTERNAL_FLASH_SIZE
)
if
(
fromaddr
>=
INTERNAL_FLASH_SIZE
)
...
@@ -445,7 +445,7 @@ static FSDATA wofs_fsdata =
...
@@ -445,7 +445,7 @@ static FSDATA wofs_fsdata =
// WOFS formatting function
// WOFS formatting function
// Returns 1 if OK, 0 for error
// Returns 1 if OK, 0 for error
int
ICACHE_FLASH_ATTR
wofs_format
(
void
)
int
wofs_format
(
void
)
{
{
uint32_t
sect_first
,
sect_last
;
uint32_t
sect_first
,
sect_last
;
FD
tempfd
;
FD
tempfd
;
...
@@ -460,27 +460,27 @@ int ICACHE_FLASH_ATTR wofs_format( void )
...
@@ -460,27 +460,27 @@ int ICACHE_FLASH_ATTR wofs_format( void )
return
1
;
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
);
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
);
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
);
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
);
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
);
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
)
if
(
fd
<
0
||
fd
>=
TOTAL_MAX_FDS
)
return
-
1
;
return
-
1
;
FD
*
pfd
=
fd_table
+
fd
;
FD
*
pfd
=
fd_table
+
fd
;
...
@@ -488,7 +488,7 @@ int ICACHE_FLASH_ATTR wofs_eof( int fd ){
...
@@ -488,7 +488,7 @@ int ICACHE_FLASH_ATTR wofs_eof( int fd ){
return
pfd
->
offset
==
pfd
->
size
;
return
pfd
->
offset
==
pfd
->
size
;
}
}
int
ICACHE_FLASH_ATTR
wofs_getc
(
int
fd
){
int
wofs_getc
(
int
fd
){
char
c
=
EOF
;
char
c
=
EOF
;
if
(
!
wofs_eof
(
fd
)){
if
(
!
wofs_eof
(
fd
)){
romfs_read
(
fd
,
&
c
,
1
,
&
wofs_fsdata
);
romfs_read
(
fd
,
&
c
,
1
,
&
wofs_fsdata
);
...
@@ -497,19 +497,19 @@ int ICACHE_FLASH_ATTR wofs_getc( int fd ){
...
@@ -497,19 +497,19 @@ int ICACHE_FLASH_ATTR wofs_getc( int fd ){
return
(
int
)
c
;
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
);
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.
// 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
);
return
romfs_next_file
(
start
,
fname
,
len
,
act_len
,
&
wofs_fsdata
);
}
}
#endif // #ifdef BUILD_WOFS
#endif // #ifdef BUILD_WOFS
// Initialize both ROMFS and WOFS as needed
// Initialize both ROMFS and WOFS as needed
int
ICACHE_FLASH_ATTR
romfs_init
(
void
)
int
romfs_init
(
void
)
{
{
unsigned
i
;
unsigned
i
;
...
@@ -529,13 +529,13 @@ int ICACHE_FLASH_ATTR romfs_init( void )
...
@@ -529,13 +529,13 @@ int ICACHE_FLASH_ATTR romfs_init( void )
#else // #if defined( BUILD_ROMFS ) || defined( BUILD_WOFS )
#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 )
#endif // #if defined( BUILD_ROMFS ) || defined( BUILD_WOFS )
int
ICACHE_FLASH_ATTR
test_romfs
()
int
test_romfs
()
{
{
int
fd
;
int
fd
;
int
i
,
size
;
int
i
,
size
;
...
...
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment