Class to store microapps on flash.
More...
#include <cs_MicroappStorage.h>
Class to store microapps on flash.
◆ MicroappStorage() [1/2]
Singleton, constructor, also copy constructor, is private.
◆ MicroappStorage() [2/2]
◆ erase()
Erases storage space of given app.
First checks if storage is already erased.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
- Returns
- ERR_SUCCESS The storage is already erased.
-
ERR_WAIT_FOR_SUCCESS The storage will be written erased, wait for CMD_RESOLVE_ASYNC_CONTROL_COMMAND.
-
ERR_BUSY Retry again later.
◆ getAppHeader()
Get a copy of the microapp binary header.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
[out] | header | Header to read to. |
◆ getInstance()
◆ getStartInstructionAddress()
uint32_t MicroappStorage::getStartInstructionAddress |
( |
uint8_t |
appIndex | ) |
|
Get the address in flash, where the microapp program starts.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
◆ handleFileStorageEvent()
void MicroappStorage::handleFileStorageEvent |
( |
nrf_fstorage_evt_t * |
evt | ) |
|
Internal usage: when fstorage is done, this function will be called (indirectly through app_scheduler).
◆ init()
Initialize fstorage, allocate buffer.
◆ isErased() [1/2]
bool MicroappStorage::isErased |
( |
uint32_t |
flashAddress, |
|
|
uint16_t |
size |
|
) |
| |
|
private |
Reads flash, and checks if it's erased.
◆ isErased() [2/2]
bool MicroappStorage::isErased |
( |
uint8_t |
appIndex | ) |
|
Checks if storage space of this microapp is erased.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
- Returns
- true Storage space of this app is erased, and thus ready to be written.
◆ onFlashWritten()
Called when data has been written to flash.
◆ operator=()
◆ printHeader()
◆ resetChunkVars()
void MicroappStorage::resetChunkVars |
( |
| ) |
|
|
private |
To be called when a chunk has been written (or when it failed to write).
Resets all variables.
◆ validateApp()
Validate the overall binary, this goes through flash and checks it completely.
All flash write operations have to have finished before.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
- Returns
- ERR_SUCCESS The app binary header is valid, and the checksums match.
◆ write()
cs_ret_code_t MicroappStorage::write |
( |
uint32_t |
flashAddress, |
|
|
const uint8_t * |
data, |
|
|
uint16_t |
size |
|
) |
| |
|
private |
Write to flash.
- Returns
- ERR_SUCCESS The data will be written to flash.
◆ writeChunk()
cs_ret_code_t MicroappStorage::writeChunk |
( |
uint8_t |
appIndex, |
|
|
uint16_t |
offset, |
|
|
const uint8_t * |
data, |
|
|
uint16_t |
size |
|
) |
| |
Write a chunk to flash.
- Parameters
-
[in] | appIndex | Index of the microapp, validity is not checked. |
[in] | offset | Offset of the data in bytes from the start of the app storage space. |
[in] | data | Pointer to the data to be written. Must remain valid until the write is finished. |
[in] | size | Size of the data to be written, must be a multiple of 4. |
- Returns
- ERR_SUCCESS_NO_CHANGE The data is already on flash.
-
ERR_WAIT_FOR_SUCCESS The data will be written to flash, wait for CMD_RESOLVE_ASYNC_CONTROL_COMMAND.
-
ERR_NO_SPACE Data would go outside the app storage space.
-
ERR_WRONG_PAYLOAD_LENGTH Data size is not a multiple of 4.
-
ERR_WRITE_DISABLED App storage space is not erased.
-
ERR_BUSY Another chunk is being written already.
◆ writeNextChunkPart()
Write the next part of a chunk.
Called first time from command, and every time when a flash write is done.
- Returns
- ERR_SUCCESS Complete chunk has been written to flash.
-
ERR_WAIT_FOR_SUCCESS The data will be written to flash.
◆ _chunkData
const uint8_t* MicroappStorage::_chunkData = nullptr |
|
private |
When writing a chunk of data, it will be done in parts.
These variable are needed to know what to write where to.
◆ _chunkFlashAddress
uint32_t MicroappStorage::_chunkFlashAddress = 0 |
|
private |
◆ _chunkSize
uint16_t MicroappStorage::_chunkSize = 0 |
|
private |
◆ _chunkWritten
uint16_t MicroappStorage::_chunkWritten = 0 |
|
private |
◆ _writeBuffer
The buffer is required to perform writes to flash, as the data has to be aligned, and stay in memory until the write is done.
◆ _writing
bool MicroappStorage::_writing = false |
|
private |
Keep up whether or not we are currently writing to (or erasing) flash.
We tried using nrf_fstorage_is_busy() instead, but that seems to return busy when State is writing (because State uses FDS, which uses fstorage).
The documentation for this class was generated from the following file: