Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_MicroappStorage.h
Go to the documentation of this file.
1#pragma once
2
3#include <ble/cs_Nordic.h> // TODO: don't use nrf_fstorage_evt_t in header.
6
7constexpr uint8_t MICROAPP_STORAGE_BUF_SIZE = 32;
8
13public:
15 static MicroappStorage instance;
16 return instance;
17 }
18
23
30 void getAppHeader(uint8_t appIndex, microapp_binary_header_t& header);
31
37 uint32_t getStartInstructionAddress(uint8_t appIndex);
38
45 bool isErased(uint8_t appIndex);
46
58 cs_ret_code_t erase(uint8_t appIndex);
59
76 cs_ret_code_t writeChunk(uint8_t appIndex, uint16_t offset, const uint8_t* data, uint16_t size);
77
85 cs_ret_code_t validateApp(uint8_t appIndex);
86
87 void printHeader(uint8_t logLevel, microapp_binary_header_t& header);
88
92 void handleFileStorageEvent(nrf_fstorage_evt_t* evt);
93
94private:
100 void operator=(MicroappStorage const&) = delete;
101
107 bool _writing = false;
108
113 __attribute__((aligned(4))) uint8_t _writeBuffer[MICROAPP_STORAGE_BUF_SIZE];
114
119 const uint8_t* _chunkData = nullptr;
120 uint16_t _chunkSize = 0;
121 uint16_t _chunkWritten = 0;
122 uint32_t _chunkFlashAddress = 0;
123
132
138 cs_ret_code_t write(uint32_t flashAddress, const uint8_t* data, uint16_t size);
139
144
150
154 bool isErased(uint32_t flashAddress, uint16_t size);
155};
Class to store microapps on flash.
Definition: cs_MicroappStorage.h:12
cs_ret_code_t write(uint32_t flashAddress, const uint8_t *data, uint16_t size)
Write to flash.
cs_ret_code_t validateApp(uint8_t appIndex)
Validate the overall binary, this goes through flash and checks it completely.
cs_ret_code_t init()
Initialize fstorage, allocate buffer.
cs_ret_code_t erase(uint8_t appIndex)
Erases storage space of given app.
bool _writing
Keep up whether or not we are currently writing to (or erasing) flash.
Definition: cs_MicroappStorage.h:107
void handleFileStorageEvent(nrf_fstorage_evt_t *evt)
Internal usage: when fstorage is done, this function will be called (indirectly through app_scheduler...
void printHeader(uint8_t logLevel, microapp_binary_header_t &header)
uint8_t _writeBuffer[MICROAPP_STORAGE_BUF_SIZE]
The buffer is required to perform writes to flash, as the data has to be aligned, and stay in memory ...
Definition: cs_MicroappStorage.h:113
uint16_t _chunkSize
Definition: cs_MicroappStorage.h:120
MicroappStorage(MicroappStorage const &)=delete
void onFlashWritten(cs_ret_code_t retCode)
Called when data has been written to flash.
const uint8_t * _chunkData
When writing a chunk of data, it will be done in parts.
Definition: cs_MicroappStorage.h:119
uint16_t _chunkWritten
Definition: cs_MicroappStorage.h:121
MicroappStorage()
Singleton, constructor, also copy constructor, is private.
static MicroappStorage & getInstance()
Definition: cs_MicroappStorage.h:14
uint32_t _chunkFlashAddress
Definition: cs_MicroappStorage.h:122
void resetChunkVars()
To be called when a chunk has been written (or when it failed to write).
cs_ret_code_t writeChunk(uint8_t appIndex, uint16_t offset, const uint8_t *data, uint16_t size)
Write a chunk to flash.
void getAppHeader(uint8_t appIndex, microapp_binary_header_t &header)
Get a copy of the microapp binary header.
bool isErased(uint8_t appIndex)
Checks if storage space of this microapp is erased.
cs_ret_code_t writeNextChunkPart()
Write the next part of a chunk.
void operator=(MicroappStorage const &)=delete
uint32_t getStartInstructionAddress(uint8_t appIndex)
Get the address in flash, where the microapp program starts.
constexpr uint8_t MICROAPP_STORAGE_BUF_SIZE
Definition: cs_MicroappStorage.h:7
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Header of a microapp binary.
Definition: cs_MicroappPackets.h:51