Skip to content

Commit

Permalink
update spiffs to v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
funshine committed Apr 5, 2015
1 parent 560ad8e commit ba836cf
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 107 deletions.
75 changes: 36 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **NodeMCU** #
version 0.9.5
version 0.9.6

[![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) [![Download](https://img.shields.io/badge/download-~400k-orange.svg)](https://github.com/nodemcu/nodemcu-firmware/releases/latest)
Expand Down Expand Up @@ -36,6 +36,39 @@ Tencent QQ group: 309957875<br />
- cross compiler (done)

# Change log
2015-04-06<br />
bump version to 0.9.6. not follow sdk version any more.<br />
fix mqtt module bugs. please see examples [mqtt](https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_examples/mqtt).<br />
fix dht lib.<br />
update spiffs to V0.3.0.<br />
enhancement for wifi.ap submodule.<br />
wifi.sta.config (wifi_station_config):
- range checking password length (8~64)

wifi.ap.config (wifi_ap_config):
- range checking ssid length (1~32)
- range checking pwd length (8~64)
- new params:
- auth: wifi.OPEN, wifi.WPA_PSK, wifi.WPA2_PSK, wifi.WPA_WPA2_PSK
- default WITH pwd: wifi.WPA_WPA2_PSK
- default WITHOUT pwd: wifi.OPEN
- channel: 1~13 (default: 6)
- hidden: 0/1 (default: 0)
- max: 1~4 (default: 4)
- beacon: 100~60000ms (default: 100)

wifi.ap.getclient (wifi_ap_listclient):
- returns table(mac,ip) of all connected clients

wifi.ap.dhcp:
- new submodule
- config (wifi_ap_dhcp_config), returns start/end ips
- params:
- start (e.g., "192.168.1.100")
- end ip calculated from wifi.ap.config.max
- start (wifi_ap_dhcp_start), returns boolean
- stop (wifi_ap_dhcp_stop), returns boolean

2015-03-31<br />
polish mqtt module, add queue for mqtt module.<br />
add reconnect option to mqtt.connect api, :connect( host, port, secure, auto_reconnect, function(client) )<br />
Expand Down Expand Up @@ -209,44 +242,8 @@ baudrate:9600
end)
```

####Connect to MQTT Broker

```lua
-- init mqtt client with keepalive timer 120sec
m = mqtt.Client("clientid", 120, "user", "password")

-- setup Last Will and Testament (optional)
-- Broker will publish a message with qos = 0, retain = 0, data = "offline"
-- to topic "/lwt" if client don't send keepalive packet
m:lwt("/lwt", "offline", 0, 0)

m:on("connect", function(con) print ("connected") end)
m:on("offline", function(con) print ("offline") end)

-- on publish message receive event
m:on("message", function(conn, topic, data)
print(topic .. ":" )
if data ~= nil then
print(data)
end
end)

-- m:connect( host, port, secure, auto_reconnect, function(client) )
-- for secure: m:connect("192.168.11.118", 1880, 1, 0)
-- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1)
m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end)

-- subscribe topic with qos = 0
m:subscribe("/topic",0, function(conn) print("subscribe success") end)
-- or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2 , qos = 2)
-- m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn) print("subscribe success") end)
-- publish a message with data = hello, QoS = 0, retain = 0
m:publish("/topic","hello",0,0, function(conn) print("sent") end)

m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disconnect from host.
-- you can call m:connect again

```
#### MQTT examples
please see [mqtt examples](https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_examples/mqtt)

#### UDP client and server
```lua
Expand Down
6 changes: 3 additions & 3 deletions app/include/user_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#define NODE_VERSION_MAJOR 0U
#define NODE_VERSION_MINOR 9U
#define NODE_VERSION_REVISION 5U
#define NODE_VERSION_REVISION 6U
#define NODE_VERSION_INTERNAL 0U

#define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 20150405"
#define NODE_VERSION "NodeMCU 0.9.6"
#define BUILD_DATE "build 20150406"

#endif /* __USER_VERSION_H__ */
26 changes: 15 additions & 11 deletions app/spiffs/spiffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ void myspiffs_unmount() {
int myspiffs_format( void )
{
SPIFFS_unmount(&fs);
u32_t sect_first, sect_last;
sect_first = ( u32_t )platform_flash_get_first_free_block_address( NULL );
sect_first += 0x3000;
sect_first &= 0xFFFFC000; // align to 4 sector.
sect_first = platform_flash_get_sector_of_address(sect_first);
sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4;
sect_last = platform_flash_get_sector_of_address(sect_last);
NODE_DBG("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
while( sect_first <= sect_last )
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
return 0;
// u32_t sect_first, sect_last;
// sect_first = ( u32_t )platform_flash_get_first_free_block_address( NULL );
// sect_first += 0x3000;
// sect_first &= 0xFFFFC000; // align to 4 sector.
// sect_first = platform_flash_get_sector_of_address(sect_first);
// sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4;
// sect_last = platform_flash_get_sector_of_address(sect_last);
// NODE_DBG("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
// while( sect_first <= sect_last )
// if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
// return 0;
int32_t res = SPIFFS_format(&fs);
if (res != SPIFFS_OK) {
return 0;
}
myspiffs_mount();
return 1;
}
Expand Down
35 changes: 34 additions & 1 deletion app/spiffs/spiffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ extern "C" {
#define SPIFFS_ERR_NOT_WRITABLE -10021
#define SPIFFS_ERR_NOT_READABLE -10022
#define SPIFFS_ERR_CONFLICTING_NAME -10023
#define SPIFFS_ERR_NOT_CONFIGURED -10024

#define SPIFFS_ERR_NOT_A_FS -10025
#define SPIFFS_ERR_MOUNTED -10026
#define SPIFFS_ERR_ERASE_FAIL -10027
#define SPIFFS_ERR_MAGIC_NOT_POSSIBLE -10028


#define SPIFFS_ERR_INTERNAL -10050

Expand Down Expand Up @@ -215,6 +222,11 @@ typedef struct {

// check callback function
spiffs_check_callback check_cb_f;

// mounted flag
u8_t mounted;
// config magic
u32_t config_magic;
} spiffs;

/* spiffs file status struct */
Expand Down Expand Up @@ -242,7 +254,10 @@ typedef struct {
// functions

/**
* Initializes the file system dynamic parameters and mounts the filesystem
* Initializes the file system dynamic parameters and mounts the filesystem.
* If SPIFFS_USE_MAGIC is enabled the mounting may fail with SPIFFS_ERR_NOT_A_FS
* if the flash does not contain a recognizable file system.
* In this case, SPIFFS_format must be called prior to remounting.
* @param fs the file system struct
* @param config the physical and logical configuration of the file system
* @param work a memory work buffer comprising 2*config->log_page_size
Expand Down Expand Up @@ -441,6 +456,24 @@ s32_t SPIFFS_check(spiffs *fs);
*/
s32_t SPIFFS_info(spiffs *fs, u32_t *total, u32_t *used);

/**
* Formats the entire file system. All data will be lost.
* The filesystem must not be mounted when calling this.
*
* NB: formatting is awkward. Due to backwards compatibility, SPIFFS_mount
* MUST be called prior to formatting in order to configure the filesystem.
* If SPIFFS_mount succeeds, SPIFFS_unmount must be called before calling
* SPIFFS_format.
* If SPIFFS_mount fails, SPIFFS_format can be called directly without calling
* SPIFFS_unmount first.
*/
s32_t SPIFFS_format(spiffs *fs);

/**
* Returns nonzero if spiffs is mounted, or zero if unmounted.
*/
u8_t SPIFFS_mounted(spiffs *fs);

/**
* Check if EOF reached.
* @param fs the file system struct
Expand Down
19 changes: 16 additions & 3 deletions app/spiffs/spiffs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,22 @@ typedef uint8_t u8_t;
#define SPIFFS_COPY_BUFFER_STACK (64)
#endif

// Enable this to have an identifiable spiffs filesystem. This will look for
// a magic in all sectors to determine if this is a valid spiffs system or
// not on mount point. If not, SPIFFS_format must be called prior to mounting
// again.
#ifndef SPIFFS_USE_MAGIC
#define SPIFFS_USE_MAGIC (0)
#endif

// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
// These should be defined on a multithreaded system

// define this to entering a mutex if you're running on a multithreaded system
// define this to enter a mutex if you're running on a multithreaded system
#ifndef SPIFFS_LOCK
#define SPIFFS_LOCK(fs)
#endif
// define this to exiting a mutex if you're running on a multithreaded system
// define this to exit a mutex if you're running on a multithreaded system
#ifndef SPIFFS_UNLOCK
#define SPIFFS_UNLOCK(fs)
#endif
Expand Down Expand Up @@ -159,7 +167,12 @@ typedef uint8_t u8_t;
#endif
#endif

// Set SPFIFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
// Enable this if your target needs aligned data for index tables
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
#endif

// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
// in the api. This function will visualize all filesystem using given printf
// function.
#ifndef SPIFFS_TEST_VISUALISATION
Expand Down
22 changes: 1 addition & 21 deletions app/spiffs/spiffs_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ static s32_t spiffs_gc_erase_block(
spiffs *fs,
spiffs_block_ix bix) {
s32_t res;
u32_t addr = SPIFFS_BLOCK_TO_PADDR(fs, bix);
s32_t size = SPIFFS_CFG_LOG_BLOCK_SZ(fs);

SPIFFS_GC_DBG("gc: erase block %i\n", bix);

// here we ignore res, just try erasing the block
while (size > 0) {
SPIFFS_GC_DBG("gc: erase %08x:%08x\n", addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
(void)fs->cfg.hal_erase_f(addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
addr += SPIFFS_CFG_PHYS_ERASE_SZ(fs);
size -= SPIFFS_CFG_PHYS_ERASE_SZ(fs);
}
fs->free_blocks++;

// register erase count for this block
res = _spiffs_wr(fs, SPIFFS_OP_C_WRTHRU | SPIFFS_OP_T_OBJ_LU2, 0,
SPIFFS_ERASE_COUNT_PADDR(fs, bix),
sizeof(spiffs_obj_id), (u8_t *)&fs->max_erase_count);
res = spiffs_erase_block(fs, bix);
SPIFFS_CHECK_RES(res);

fs->max_erase_count++;
if (fs->max_erase_count == SPIFFS_OBJ_ID_IX_FLAG) {
fs->max_erase_count = 0;
}

#if SPIFFS_CACHE
{
u32_t i;
Expand Down
Loading

0 comments on commit ba836cf

Please sign in to comment.