Data Storage Management API¶
SDK provide simple APIs to manage data storage. The storage APIs can be used to store data on storage media during unavailability of network or for logging purpose.
API Reference¶
Header File¶
Source: include/storage.h
#include <storage.h>
Functions¶
-
int storage_init(const struct storagecfg_t *cfg)¶
Initialize storage management library. This function must be called before calling any storage function.
- Parameters
cfg – [in] Storage configuration
- Returns
0 on success, negative value on error
-
int storage_save(int part, const void *buffer, int len)¶
Save data to storage partition
- Parameters
part – [in] Partition index, starting from 0
buffer – [in] Buffer to store
len – [in] Length of data in buffer
- Returns
0 on success, negative value on error
-
int storage_read(int part, void *buffer, int *len)¶
Read data from storage partition
- Parameters
part – [in] Partition index, starting from 0
buffer – [out] Pointer to buffer where data is stored
len – [out] Size of buffer, on return actual size read is updated
- Returns
0 on success, negative value on error. len is updated with actual data read from storage
-
int storage_read_indexed(int part, int index, void *buffer, int *len)¶
Red data from storage partition indexed. This function can be used to read multiple packets at once. The reading index is 0 based. In FIFO mode 0 points to first packet and in LIFO mode 0 points to last packet. e.g in FIFO mode reading an indexed packet of index 2 will return third packet stored in FIFO order.
- Parameters
part – [in] Partition index, starting from 0
index – [in] Index to read
buffer – [out] Pointer to buffer where data is stored
len – [out] Size of buffer, on return actual size read is updated
- Returns
0 on success, negative value on error. len is updated with actual data read from storage
-
int storage_delete(int part, int count)¶
Delete data from storage partition
- Parameters
part – [in] Partition index, starting from 0
count – [in] Number of packets to delete
- Returns
0 on success, negative value on error
-
int storage_available(int part)¶
Get storage status
- Parameters
part – [in] Partition index, starting from 0
- Returns
TRUE if offline is pending, FALSE if not data is available
-
int storage_getcount(int part)¶
Get storage data count available in partition
- Parameters
part – [in] Partition index, starting from 0
- Returns
available count
-
int storage_clear(int part)¶
Delete data in storage partion
- Parameters
part – [in] Partition index, starting from 0
- Returns
0 on success, negative on error
-
int storage_clear_all(void)¶
Delete all data
- Returns
int
Structures¶
-
struct storagecfg_t¶
Storage Configuration Structure
Public Members
-
uint8_t media¶
Storage Media storage_media_e
-
uint8_t parts¶
Number of Storage partition
-
uint8_t mode¶
Storage mode storage_mode_e
-
uint8_t on_full¶
Action to be taken when storage is full storage_action_e
-
uint8_t compression¶
1 to enable compression, 0 for no compression
-
uint8_t reserved¶
reserved for future use
-
uint16_t packet_sz¶
Approximate Average data packet size
-
uint32_t max_storage¶
Maximum number/count of data packets to store
-
uint32_t resvd_mem¶
Amount to reserved memory to keep in storage media, 16Kb minimum
-
uint8_t media¶
Enumerations¶
-
enum storage_media_e¶
Storage media
Values:
-
enumerator STORAGE_MEDIA_FS¶
Storage media internal flash memory
-
enumerator STORAGE_MEDIA_SPIFS¶
Storage media external SPI Flash
-
enumerator STORAGE_MEDIA_SD¶
Storage media SD card
-
enumerator STORAGE_MEDIA_FS¶
