PEController BSP v4
Board Support Package for PEController from Taraz Technologies
 
Loading...
Searching...
No Matches

Functions

void StateStorage_Init (state_storage_config_t *_config)
 This function initializes the state storage according to the application requirements.
 
void StateStorage_Refresh (void)
 Refreshes the storage state if required.
 

Detailed Description

Function Documentation

◆ StateStorage_Init()

void StateStorage_Init ( state_storage_config_t _config)
extern

This function utilizes two distinct sectors to retrieve the states of all system components. By using a ping-pong approach, only one sector is active at a time for updating the states. The first packet within each sector either remains empty or contains the states of all system components. If the first packet is not present, the sector is considered empty and will be promptly erased if it hasn't been already. Following the initial packet, subsequent partial data packets are used to update the system states.

static state_storage_config_t storageConfig = {0};
// Initialize both sectors
storageConfig.sectors[0].sectorNo = FLASH_SECTOR_TOTAL - 2;
storageConfig.sectors[1].sectorNo = FLASH_SECTOR_TOTAL - 1;
for (int i = 0; i < 2; i++)
{
storageConfig.sectors[i].bank = FLASH_BANK_1;
storageConfig.sectors[i].byteCount = FLASH_SECTOR_SIZE;
storageConfig.sectors[i].addr = (uint32_t*)(FLASH_BANK1_BASE + (storageConfig.sectors[i].sectorNo * FLASH_SECTOR_SIZE));
}
// Initialize the clients
static state_storage_client_t storageClients[2];
storageConfig.clientCount = 3;
storageConfig.clients = storageClients;
storageClients[0].arg = (void*)&CLIENT_DATA;
//Following are sample definitions for the functions to be defined in the client.
static void InitStatesFromStorage(uint32_t* data, bool isDataValid)
{
// @note Make sure to only save/load controllable variables here
dest_data_t* src = (dest_data_t*)data;
src_data_t* dest = (src_data_t*)&srcData;
// Put elements here which will always be default values here, such as enable etc which can't be 1 when the control starts
if (isDataValid)
src->value = dest->value;
// Set default values because the loaded values are invalid
// @note Make sure to only save/load controllable variables here
else
src->value = 0;
}
static uint32_t RefreshStates(uint32_t* data, uint32_t* indexPtr)
{
uint32_t len = 0;
dest_data_t* dest = (dest_data_t*)data;
src_data_t* src = (src_data_t*)&srcData;
// @note Only update values and signal to update if values have been changed
if (dest->value != src->value)
{
dest->value = src->value;
len = storageWordLen;
}
*indexPtr = 0;
return len;
}
Client1_ConfigStorage(state_storage_client_t* _config)
{
_config->InitStatesFromStorage = InitStatesFromStorage;
_config->RefreshStates = RefreshStates;
_config->dataWordLen = STORAGE_WORD_LEN;
}
Client1_ConfigStorage(&storageClients[0]);
Client2_ConfigStorage(&storageClients[1]);
StateStorage_Init(&storageConfig);
void StateStorage_Init(state_storage_config_t *_config)
This function initializes the state storage according to the application requirements.
Definition state_storage_lib.c:283
Contains the entities to be defined by each storage client. The storage module uses these members to ...
Definition state_storage_lib.h:78
uint32_t dataWordLen
No of 32-bit words required for the client storage.
Definition state_storage_lib.h:80
void(* InitStatesFromStorage)(uint32_t *data, bool isDataValid)
This callback initiates the storage for the relevant client.
Definition state_storage_lib.h:81
uint32_t(* RefreshStates)(uint32_t *data, uint32_t *indexPtr)
This callback is used to refresh the states in the data buffer for the client.
Definition state_storage_lib.h:100
void * arg
Custom arguments used by the relevant client.
Definition state_storage_lib.h:79
uint32_t bank
Definition state_storage_lib.h:141
uint32_t * addr
Definition state_storage_lib.h:142
uint32_t byteCount
Definition state_storage_lib.h:140
uint32_t sectorNo
Definition state_storage_lib.h:138
Defines the state storage configuration.
Definition state_storage_lib.h:148
state_storage_client_t * clients
Definition state_storage_lib.h:151
flash_sector_config_t sectors[2]
Definition state_storage_lib.h:149
int clientCount
Definition state_storage_lib.h:150
Parameters
_configSystem configuration for the storage.

This function utilizes two distinct sectors to retrieve the states of all system components. By using a ping-pong approach, only one sector is active at a time for updating the states. The first packet within each sector either remains empty or contains the states of all system components. If the first packet is not present, the sector is considered empty and will be promptly erased if it hasn't been already. Following the initial packet, subsequent partial data packets are used to update the system states.

static state_storage_config_t storageConfig = {0};
// Initialize both sectors
storageConfig.sectors[0].sectorNo = FLASH_SECTOR_TOTAL - 2;
storageConfig.sectors[1].sectorNo = FLASH_SECTOR_TOTAL - 1;
for (int i = 0; i < 2; i++)
{
storageConfig.sectors[i].bank = FLASH_BANK_1;
storageConfig.sectors[i].byteCount = FLASH_SECTOR_SIZE;
storageConfig.sectors[i].addr = (uint32_t*)(FLASH_BANK1_BASE + (storageConfig.sectors[i].sectorNo * FLASH_SECTOR_SIZE));
}
// Initialize the clients
static state_storage_client_t storageClients[2];
storageConfig.clientCount = 3;
storageConfig.clients = storageClients;
storageClients[0].arg = (void*)&CLIENT_DATA;
//Following are sample definitions for the functions to be defined in the client.
//static void InitStatesFromStorage(uint32_t* data, bool isDataValid)
//{
// // @note Make sure to only save/load controllable variables here
// dest_data_t* src = (dest_data_t*)data;
// src_data_t* dest = (src_data_t*)&srcData;
// // Put elements here which will always be default values here, such as enable etc which can't be 1 when the control starts
// if (isDataValid)
// src->value = dest->value;
// // Set default values because the loaded values are invalid
// // @note Make sure to only save/load controllable variables here
// else
// src->value = 0;
//}
//static uint32_t RefreshStates(uint32_t* data, uint32_t* indexPtr)
//{
// uint32_t len = 0;
// dest_data_t* dest = (dest_data_t*)data;
// src_data_t* src = (src_data_t*)&srcData;
// // @note Only update values and signal to update if values have been changed
// if (dest->value != src->value)
// {
// dest->value = src->value;
// len = storageWordLen;
// }
// *indexPtr = 0;
// return len;
//}
//Client1_ConfigStorage(state_storage_client_t* _config)
//{
// _config->InitStatesFromStorage = InitStatesFromStorage;
// _config->RefreshStates = RefreshStates;
// _config->dataWordLen = STORAGE_WORD_LEN;
//}
Client1_ConfigStorage(&storageClients[0]);
Client2_ConfigStorage(&storageClients[1]);
StateStorage_Init(&storageConfig);
Parameters
_configSystem configuration for the storage.

◆ StateStorage_Refresh()

void StateStorage_Refresh ( void  )
extern

Poll this function periodically to refresh the stored states for all parameters. If the index in the sector is 0 or the packet cannot fit within the remaining space in the sector, the "isFirstSectorPacket" flag is set. This flag ensures that all parameters are completely flushed to the beginning of the sector. To obtain the necessary data, each client is prompted to refresh their states using the state_storage_client_t::RefreshStates() function. It is the responsibility of the client to provide the refreshed data, if necessary, and return the size of the updated data. Finally, the partial data will be flushed to the storage flash.