#include <SlotNVM.h>
|
bool | begin () |
| Initialize SlotNVM. More...
|
|
bool | isValid () const |
| Check if begin is called before and returns true. More...
|
|
bool | isSlotAvailable (uint8_t slot) const |
| Check if data is stored for a given slot. More...
|
|
bool | writeSlot (uint8_t slot, const uint8_t *data, nvm_size_t len) |
| Write data. More...
|
|
template<class T > |
bool | writeSlot (uint8_t slot, T &data) |
| Write data. More...
|
|
bool | readSlot (uint8_t slot, uint8_t *data, nvm_size_t &len) const |
| Read data If buffer is to small, nothing is read but len is set to needed size and false is returned. More...
|
|
template<class T > |
bool | readSlot (uint8_t slot, T &data) const |
| Read data If slot stores more or less byte than size of data false is returned and data untouched. More...
|
|
bool | eraseSlot (uint8_t slot) |
| Delete slot data. More...
|
|
nvm_size_t | getSize () const |
| Get amount of total available user data. More...
|
|
nvm_size_t | getUsableSize () const |
| Get amount of total usable user data. More...
|
|
nvm_size_t | getFree () const |
| Get amount of still writable user data. More...
|
|
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
class SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >
- Template Parameters
-
BASE | Base class handling NVM read and write, see NVMBase as example. This class also specifies the size of the NVM via member S_SIZE. |
CLUSTER_SIZE | Size of a cluster in byte. This should not be lower than 7. Typical values are 16, 32, 64, 128, 256. |
PROVISION | Bytes that must always be free to ensure that data can safely be rewritten. If your slot data do not exceed this limit is can always be rewritten without deleting other data before. This value is rounded to next multiple of user data of a cluster. |
LAST_SLOT | Number of last usable slot. Maximum value is 250. 0 mean number is equal to count of available cluster. The result is stored in S_LAST_SLOT |
CRC_FUNC | Function to calculate a 8 bit CRC. Prototype must be: uint8_t CRC8_function(uint8_t crc, uint8_t data). NULL means not CRC is stored in NVM and therefore one extra data byte per cluster is available. |
RND_TYPE | Return type of RND_FUNC. |
RND_FUNC | Random function for wear leveling. Default is rand() from stdlib.h. Please do not forget to call srand(). |
◆ begin()
template<class BASE , nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION, uint8_t LAST_SLOT, uint8_t(*)(uint8_t, uint8_t) CRC_FUNC, typename RND_TYPE , RND_TYPE(*)() RND_FUNC>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::begin |
( |
| ) |
|
Initialize SlotNVM.
Call this once before every other call to SlotNVM. This will check current data of NVM and fix wrong data if found some.
- Returns
- true if NVM data is readable and data structure is OK or fixed.
false if NVM data is not readable or data structure is corrupt and can not be fixed or begin() is called twice.
◆ eraseSlot()
template<class BASE , nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION, uint8_t LAST_SLOT, uint8_t(*)(uint8_t, uint8_t) CRC_FUNC, typename RND_TYPE , RND_TYPE(*)() RND_FUNC>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::eraseSlot |
( |
uint8_t |
slot | ) |
|
Delete slot data.
- Parameters
-
- Returns
- true on success else false
◆ getFree()
template<class BASE , nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION, uint8_t LAST_SLOT, uint8_t(*)(uint8_t, uint8_t) CRC_FUNC, typename RND_TYPE , RND_TYPE(*)() RND_FUNC>
nvm_size_t SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::getFree |
( |
| ) |
const |
Get amount of still writable user data.
- Returns
- Free bytes
◆ getSize()
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
nvm_size_t SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::getSize |
( |
| ) |
const |
|
inline |
Get amount of total available user data.
Some of this might be reserved as provision for safe overwriting.
- Returns
- Total size in bytes
◆ getUsableSize()
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
nvm_size_t SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::getUsableSize |
( |
| ) |
const |
|
inline |
Get amount of total usable user data.
- Returns
- Usable data size in bytes
◆ isSlotAvailable()
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::isSlotAvailable |
( |
uint8_t |
slot | ) |
const |
|
inline |
Check if data is stored for a given slot.
- Parameters
-
slot | Slot number to check, |
- Returns
- true if there is data for this slot.
◆ isValid()
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::isValid |
( |
| ) |
const |
|
inline |
Check if begin is called before and returns true.
- Returns
- true if SlotNVM is ready for use.
◆ readSlot() [1/2]
template<class BASE , nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION, uint8_t LAST_SLOT, uint8_t(*)(uint8_t, uint8_t) CRC_FUNC, typename RND_TYPE , RND_TYPE(*)() RND_FUNC>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::readSlot |
( |
uint8_t |
slot, |
|
|
uint8_t * |
data, |
|
|
nvm_size_t & |
len |
|
) |
| const |
Read data If buffer is to small, nothing is read but len is set to needed size and false is returned.
So you can set data to NULL and len to 0 to read data length of a slot.
- Parameters
-
| slot | Slot number |
| data | Buffer to read in |
[in,out] | len | in: Size of data buffer
out: On success count of bytes copied to data. If data buffer was to small the size of slot else value is not changed. |
- Returns
- true on success else false
◆ readSlot() [2/2]
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
template<class T >
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::readSlot |
( |
uint8_t |
slot, |
|
|
T & |
data |
|
) |
| const |
|
inline |
Read data If slot stores more or less byte than size of data false is returned and data untouched.
- Parameters
-
slot | Slot number |
data | Data to read in |
- Returns
- true on success else false
◆ writeSlot() [1/2]
template<class BASE , nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION, uint8_t LAST_SLOT, uint8_t(*)(uint8_t, uint8_t) CRC_FUNC, typename RND_TYPE , RND_TYPE(*)() RND_FUNC>
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::writeSlot |
( |
uint8_t |
slot, |
|
|
const uint8_t * |
data, |
|
|
nvm_size_t |
len |
|
) |
| |
Write data.
- Parameters
-
slot | Slot number |
data | Data to write |
len | Lenght of data to write |
- Returns
- true on success else false
◆ writeSlot() [2/2]
template<class BASE, nvm_size_t CLUSTER_SIZE, nvm_size_t PROVISION = 0, uint8_t LAST_SLOT = 0, uint8_t(*)(uint8_t crc, uint8_t data) CRC_FUNC = (uint8_t (*)(uint8_t, uint8_t))NULL, typename RND_TYPE = int, RND_TYPE(*)() RND_FUNC = &rand>
template<class T >
bool SlotNVM< BASE, CLUSTER_SIZE, PROVISION, LAST_SLOT, CRC_FUNC, RND_TYPE, RND_FUNC >::writeSlot |
( |
uint8_t |
slot, |
|
|
T & |
data |
|
) |
| |
|
inline |
Write data.
- Parameters
-
slot | Slot number |
data | Data to write |
- Returns
- true on success else false
The documentation for this class was generated from the following file: