Skip to content

Commit 4378cb4

Browse files
Update README.md
1 parent f89e3cc commit 4378cb4

File tree

1 file changed

+55
-47
lines changed

1 file changed

+55
-47
lines changed

README.md

+55-47
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
The SPIFlashFileSystem (SFFS) library implements a basic [wear leveling](https://en.wikipedia.org/wiki/Wear_leveling) file system intended for use with SPI Flash devices, using either the built-in [hardware.spiflash](https://electricimp.com/docs/api/hardware/spiflash) object on imp003 and above, or an external SPI Flash plus the [SPIFlash library](https://github.com/electricimp/spiflash) on the imp001 and imp002.
7575

76-
**To add this library to your project, add `#require "SPIFlashFileSystem.device.lib.nut:2.0.0"` to the top of your device code.**
76+
**To add this library to your project, add** `#require "SPIFlashFileSystem.device.lib.nut:2.0.0"` **to the top of your device code.**
7777

7878
## Overview of the File System
7979

@@ -151,7 +151,7 @@ Because each sector contains a FileID and SpanID, the sectors can be anywhere in
151151

152152
When the SFFS deletes a file, it simply marks all of the pages the file was using as erased. In order to use those pages again in the future, we first need erase the sectors that the file used. This is done automatically through a process called garbage collection.
153153

154-
Each time a file is closed, or erased the SFFS determins whether or not it needs to run the garbage collector. It does this by comparing the number of free pages to the *autoGcThreshold*, which can be set with [setAutoGc](#setautogcnumpages) method.
154+
Each time a file is closed or erased, the SFFS determines whether or not it needs to run the garbage collector. It does this by comparing the number of free pages to the *autoGcThreshold*, which can be set with the [*setAutoGc()*](#setautogcnumpages) method.
155155

156156
## Library Classes
157157

@@ -216,7 +216,7 @@ If the *init()* method is called while the filesystem has files open, a `SPIFlas
216216

217217
### getFileList(*[orderByDate]*)
218218

219-
The *getFileList()* returns an array of file information identical to that passed into the *init()* callback. It takes an optional parameter: orderByData, a Boolean value that specifies whether the returned files should be sorted into date order for you. The default value is `false`.
219+
The *getFileList()* returns an array of file information identical to that passed into the *init()* callback. It takes an optional parameter: *orderByDate*, which is a Boolean value that specifies whether the returned files should be sorted into date order for you. The default value is `false`.
220220

221221
```squirrel
222222
local files = sffs.getFileList();
@@ -256,12 +256,12 @@ server.log(filename + " is " + sffs.fileSize(filename) + " bytes long");
256256

257257
This method returns information about the filesystem in the form of a table with the following keys:
258258

259-
| Key | Description |
260-
| ----------- | --------------- |
261-
| *size* | The filesystem size in bytes |
262-
| *len* | The number of files in the filesystem |
263-
| *start* | The address of the first byte of SPI flash assigned to the filesystem |
264-
| *end* | The address of the last byte of SPI flash assigned to the filesystem |
259+
| Key | Description |
260+
| --- | --- |
261+
| *size* | The filesystem size in bytes |
262+
| *len* | The number of files in the filesystem |
263+
| *start* | The address of the first byte of SPI flash assigned to the filesystem |
264+
| *end* | The address of the last byte of SPI flash assigned to the filesystem |
265265
| *pages* | The number of pages available in the filesystem |
266266

267267
```squirrel
@@ -270,26 +270,25 @@ local d = sffs.dimensions();
270270

271271
### created(*fileRef*)
272272

273-
Gets the creation timestamp for a specified file reference (id or file name).
273+
Gets the creation timestamp for a specified file reference (ID or file name).
274274

275275
```squirrel
276-
// get creation date by file name
276+
// Get creation date by file name
277277
sffs.created("file.txt");
278278
279-
// get creation date by id
279+
// Get creation date by ID
280280
sffs.created(5);
281281
```
282282

283283
### getFreeSpace()
284284

285285
This method returns an estimate of the free space available in the filesystem. Smaller files have more overhead than larger files so it is impossible to know exactly how much space is free. The information is returned as a table with two keys:
286286

287-
| Key | Description |
288-
| ------------- | --------------- |
289-
| *free* | The estimated free space in bytes |
287+
| Key | Description |
288+
| --- | --- |
289+
| *free* | The estimated free space in bytes |
290290
| *freeable* | The estimated space in bytes that may be freed through further garbage collection |
291291

292-
293292
### isFileOpen(*filename*)
294293

295294
Returns `true` or `false` according to whether or not the specified file is currently open.
@@ -352,7 +351,7 @@ This method erases all files within the filesystem. It will return with an error
352351

353352
### setAutoGc(*numPages*)
354353

355-
The *setAutoGc()* method sets the *autoGcThresgold* property. The default *autoGcThresgold* property is 4. The garbage collector will automatically run when the filesystem has fewer than *autoGcThreshold* pages.
354+
The *setAutoGc()* method sets the *autoGcThresgold* property. The garbage collector will automatically run when the filesystem has fewer than *autoGcThreshold* pages. The default *autoGcThresgold* value is 4.
356355

357356
Setting *numPages* to 0 will turn off automatic garbage collection.
358357

@@ -366,16 +365,15 @@ sffs.setAutoGc(10);
366365

367366
The *gc()* method manually starts the garbage collection process. The SPIFlashFileSystem is designed in such a way that the auto garbage collection *should* be sufficient, and you should never need to manually call the *gc()* method.
368367

369-
If the *numPages* parameter is specified, the garbage collector will free up to *numPages* pages and return when it completes (this is what happens when the garbage collector runs because the file system needs a page and none are free). If the *numPages* parameter is ommited, the garbage collector will run asynchronously in the background (this is what happens when the garbage collector runs because free pages drops below the value of *autoGcThreshold*).
370-
368+
If the *numPages* parameter is specified, the garbage collector will free up to *numPages* pages and return when it completes (this is what happens when the garbage collector runs because the file system needs a page and none are free). If the *numPages* parameter is omited, the garbage collector will run asynchronously in the background (this is what happens when the garbage collector runs because free pages drops below the value of *autoGcThreshold*).
371369

372370
## SPIFlashFileSystem.File
373371

374-
A *SPIFlashFileSystem.File* object is returned from the SPIFlashFileSystem each time a file is opened. The *SPIFlashFileSystem.File* object acts as a stream, with an internal pointer which can be manipulated with a variety of methods in the *SPIFlashFileSystem.File* class. Typically, you will not need to instantiate SPIFlashFileSystem.File objects yourself.
372+
A *SPIFlashFileSystem.File* object is returned from the SPIFlashFileSystem each time a file is opened. The *SPIFlashFileSystem.File* object acts as a stream, with an internal pointer which can be manipulated with a variety of methods in the *SPIFlashFileSystem.File* class. Typically, you will not need to instantiate *SPIFlashFileSystem.File* objects yourself.
375373

376-
## Constructor: SPIFlashFileSystem.File(*filesystem, fileId, fileIndex, filename, mode*)
374+
### Constructor: SPIFlashFileSystem.File(*filesystem, fileId, fileIndex, filename, mode*)
377375

378-
The constructor creates a file record. It takes the current SPIFlashFileSystem instance, the file’s unique integer ID, the index of the file in the internal record of open files, the current file’s filename, and its access mode: read or write, represented as the strings `"r"` and `"w"`, respectively.
376+
The constructor creates a file record. It takes the current *SPIFlashFileSystem* instance, the file’s unique integer ID, the index of the file in the internal record of open files, the current file’s filename, and its access mode: read or write, represented as the strings `"r"` and `"w"`, respectively.
379377

380378
## SPIFlashFileSystem.File Methods
381379

@@ -434,7 +432,7 @@ server.log(file.read().tostring());
434432

435433
Writes a string or blob to the end of a file's data opened with mode `"w"`. If you attempt to write to a file opened with mode `"r"` a `SPIFlashFileSystem.ERR_WRITE_R_FILE` error will be thrown.
436434

437-
**Note:** The page header is not written to the SPI Flash until the entire page is written, or the [close](#close) method is called.
435+
**Note** The page header is not written to the SPI Flash until the entire page is written, or the [close](#close) method is called.
438436

439437
In the following example, we download a file in chunks from the agent:
440438

@@ -459,7 +457,6 @@ The *close()* method closes a file, and writes data to the SPI Flash if required
459457

460458
*See [write()](#writedata) for sample usage.*
461459

462-
463460
## SPIFlashFileSystem.FAT
464461

465462
A SPIFlashFileSystem.FAT object is automatically generated when the filesystem is initialized. It records the file allocation table (FAT).
@@ -474,15 +471,15 @@ The constructor takes a master *SPIFlashFileSystem* object and, optionally, the
474471

475472
This method scans the filesystem for files and uses them to construct the file allocation table.
476473

477-
### get(*fileReference*)
474+
### get(*fileRef*)
478475

479-
This method retrieves information about a specific file from the file allocation table. The value passed into *fileReference* can be either a file’s name (a string) or its ID (an integer). The method returns a table of information containing the following keys:
476+
This method retrieves information about a specific file from the file allocation table. The value passed into *fileRef* can be either a file’s name (a string) or its ID (an integer). The method returns a table of information containing the following keys:
480477

481478
| Key | Description |
482-
| ----- | --------------- |
479+
| --- | --- |
483480
| *id* | The file’s ID (integer) |
484481
| *fname* | The file’s filename |
485-
| *spans* | ??? |
482+
| *spans* | The spans of the file |
486483
| *pages* | An array of pages in which the file is stored |
487484
| *pageCount* | The number of pages in which the file is stored |
488485
| *sizes* | An array of the size (in bytes) of the file chunks each page contains |
@@ -491,81 +488,92 @@ This method retrieves information about a specific file from the file allocation
491488

492489
### getFileList(*[orderByDate]*)
493490

494-
The *getFileList()* returns an array of file information, one entry per file in the FAT. It takes an optional parameter: *orderByData*, a Boolean value that specifies whether the returned files should be sorted into date order for you. The default value is `false`. The information for each file is a table with the following keys:
491+
The *getFileList()* returns an array of file information, one entry per file in the FAT. It takes an optional parameter: *orderByDate*, a Boolean value that specifies whether the returned files should be sorted into date order for you. The default value is `false`. The information for each file is a table with the following keys:
495492

496493
| Key | Description |
497-
| ----- | --------------- |
494+
| --- | --- |
498495
| *id* | The file’s ID (integer) |
499496
| *fname* | The file’s filename |
500497
| *size* | The total size of the file |
501498
| *created* | A timestamp indicating the date and time of the file’s creation |
502499

503500
### getFileId(*filename*)
501+
504502
This method takes a given file’s name and returns the unique integer by which it is referenced in the file allocation table.
505503

506-
### fileExists(*fileReference*)
507-
This method returns `true` or `false` according to whether or not the specified file exists in the file allocation table. The value passed into fileReference can be either a file’s name (a string) or its ID (an integer).
504+
### fileExists(*fileRef*)
505+
506+
This method returns `true` or `false` according to whether or not the specified file exists in the file allocation table. The value passed into *fileRef* can be either a file’s name (a string) or its ID (an integer).
508507

509508
### getFreePage()
510-
This method returns the address of a random free page in the filesystem. It will return an error, *SPIFlashFileSystem.ERR_NO_FREE_SPACE*, if it is unable to do so because there is no free space left.
509+
510+
This method returns the address of a random free page in the filesystem. It will return an error, `SPIFlashFileSystem.ERR_NO_FREE_SPACE`, if it is unable to do so because there is no free space left.
511511

512512
### markPage(*address, status*)
513-
This method sets the status of the page at address. Status values can be any of the constants: *SPIFLASHFILESYSTEM_STATUS_FREE, SPIFLASHFILESYSTEM_STATUS_USED*, *SPIFLASHFILESYSTEM_STATUS_ERASED or SPIFLASHFILESYSTEM_STATUS_BAD*.
513+
514+
This method sets the status of the page at address. Status values can be any of the constants: *SPIFLASHFILESYSTEM_STATUS_FREE*, *SPIFLASHFILESYSTEM_STATUS_USED*, *SPIFLASHFILESYSTEM_STATUS_ERASED* or *SPIFLASHFILESYSTEM_STATUS_BAD*.
514515

515516
### addPage(*fileId, page*)
517+
516518
This method adds the specified page to the file allocation table for the specified file.
517519

518-
### getPageCount(*fileReference*)
519-
This method returns the number of pages the files specified by the parameter fileReference comprises. The value passed into fileReference can be either a file’s name (a string) or its ID (an integer).
520+
### getPageCount(*fileRef*)
521+
522+
This method returns the number of pages the files specified by the parameter fileReference comprises. The value passed into *fileRef* can be either a file’s name (a string) or its ID (an integer).
520523

521-
### forEachPage(*fileReference, callback*)
522-
This method iterates over each page used to record the file specified by the parameter fileReference. For each page, the function passed into the parameter callback is called. This function takes a single parameter: the page it is passed.
524+
### forEachPage(*fileRef, callback*)
525+
526+
This method iterates over each page used to record the file specified by the parameter *fileRef*. For each page, the function passed into the parameter callback is called. This function takes a single parameter: the page it is passed.
523527

524528
### pagesOrderedBySpan(*pages*)
529+
525530
This method returns an array of pages ordered by the span.
526531

527532
### addSizeToLastSpan(*fileId, bytes*)
533+
528534
This method updates the size of the last span in a file.
529535

530536
### set(*fileId, file*)
537+
531538
This method sets the span for the file specified by its ID.
532539

533540
### removeFile(*filename*)
541+
534542
This method removes the named file from the file allocation table.
535543

536544
### getSectorMap()
545+
537546
This method returns the file allocation table’s sector map.
538547

539548
### getStats()
540-
This method returns a table of page usage information, specifically the number of pages in the filesystem in each of the four status categories. This information is returned as a table with the keys *free, used, erased and bad*. Each key’s value is an integer: the number of pages in the filesystem with that status.
549+
550+
This method returns a table of page usage information, specifically the number of pages in the filesystem in each of the four status categories. This information is returned as a table with the keys *free*, *used*, *erased* and *bad*. Each key’s value is an integer: the number of pages in the filesystem with that status.
541551

542552
### describe()
543-
This method is intended to assist with debugging: it provides a readout of the current number of files in the file allocation table, and lists each file by name, the number of pages it spans and its total size.
544553

554+
This method is intended to assist with debugging: it provides a readout of the current number of files in the file allocation table, and lists each file by name, the number of pages it spans and its total size.
545555

546556
## Testing
547557

548-
Repository contains [impUnit](https://github.com/electricimp/impUnit) tests and a configuration for [impTest](https://github.com/electricimp/impTest).
558+
The repository contains [impUnit](https://github.com/electricimp/impUnit) tests and a configuration for [impTest](https://github.com/electricimp/impTest).
549559

550-
Tests can be launched with:
560+
The tests can be launched with:
551561

552562
```bash
553563
imptest test
554564
```
555565

556-
By default configuration for the testing is read from [.imptest](https://github.com/electricimp/impTest/blob/develop/docs/imptest-spec.md).
557-
558-
To run test with your settings (for example while you are developing), create your copy of **.imptest** file and name it something like **.imptest.local**, then run tests with:
566+
By default, the configuration for the testing is read from the file [*.imptest*](https://github.com/electricimp/impTest/blob/develop/docs/imptest-spec.md). To run tests with your settings (for example while you are developing), create a copy of the *.imptest* file and rename it (for example, *.imptest.local*), then run the tests with:
559567

560568
```bash
561569
imptest test -c .imptest.local
562570
```
563571

564572
### Hardware
565573

566-
Tests require an [Amy](https://electricimp.com/docs/hardware/resources/reference-designs/amy/) board or [imp003 Evaluation Board](https://electricimp.com/docs/hardware/imp003evb/). Any other boards with imp003 and above containing SPI flash with available user space may work too.
574+
The provided tests require an [imp003 Breakout Board](https://electricimp.com/docs/hardware/resources/reference-designs/imp003breakout/) or [imp003 Evaluation Board](https://electricimp.com/docs/hardware/imp003evb/). Any other boards with imp003 and above containing SPI flash with available user space may work too.
567575

568-
imp001/002 support is planned.
576+
imp001 support is planned.
569577

570578
## To Do
571579

0 commit comments

Comments
 (0)