Microchip® Advanced Software Framework

pds_wl.c File Reference

This is the Pds wear levelling source file which contains Pds wear levelling implimentation.

Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include "pds_interface.h"
#include "pds_common.h"
#include "pds_task_handler.h"
#include "pds_wl.h"

Functions

bool isFileFound (PdsFileItemIdx_t pdsFileItemIdx)
 This function checks if a file is found in the file map. More...
 
static uint16_t pdsReturnFreeRowIdx (void)
 Finds free row index by scanning the row map. More...
 
static void pdsUpdateFileMap (UpdateFileMap_t *updateFileMap)
 Updates the file map so that it points to the latest row index for a file id. More...
 
static void pdsUpdateRowMap ()
 Updates the row map so that the old entries of the file are erased in the row map. More...
 
void pdsWlDeleteAll (void)
 This function Erases Filemap and Rowmap array in WL and Initiates NVM Erase all. More...
 
PdsStatus_t pdsWlInit (void)
 Initializes the WL PDS by updating the row and file map. More...
 
PdsStatus_t pdsWlRead (PdsFileItemIdx_t pdsFileItemIdx, PdsMem_t *buffer, uint16_t size)
 This function will find extract the row where the file is stored and read from NVM. More...
 
PdsStatus_t pdsWlWrite (PdsFileItemIdx_t pdsFileItemIdx, PdsMem_t *buffer, uint16_t size)
 This function will find the free row index to write to, updates the WL_Struct header and writes to NVM. More...
 

Variables

static FileMap_t fileMap [PDS_MAX_FILE_IDX]
 
static RowMap_t rowMap [EEPROM_NUM_ROWS]
 

bool isFileFound ( PdsFileItemIdx_t  pdsFileItemIdx)

This function checks if a file is found in the file map.

Parameters
[out]-return true or false

References _FileMap::maxCounterRowIdx.

Referenced by PDS_IsRestorable().

static uint16_t pdsReturnFreeRowIdx ( void  )
static

Finds free row index by scanning the row map.

Parameters
[out]-returns free row index

References EEPROM_NUM_ROWS, and pdsUpdateRowMap().

Referenced by pdsWlWrite().

static void pdsUpdateFileMap ( UpdateFileMap_t updateFileMap)
static

Updates the file map so that it points to the latest row index for a file id.

Parameters
[out]-returns none

References _RowMap::counter, _FileMap::maxCounterRowIdx, _UpdateFileMap::memId, _RowMap::previousIdx, and _UpdateFileMap::rowIdx.

Referenced by pdsWlInit(), and pdsWlWrite().

static void pdsUpdateRowMap ( )
static

Updates the row map so that the old entries of the file are erased in the row map.

Parameters
[in]-return none

References _RowMap::counter, _FileMap::maxCounterRowIdx, _RowMap::memId, PDS_MAX_FILE_IDX, and _RowMap::previousIdx.

Referenced by pdsReturnFreeRowIdx(), and pdsWlInit().

void pdsWlDeleteAll ( void  )

This function Erases Filemap and Rowmap array in WL and Initiates NVM Erase all.

Parameters
[out]-void

References EEPROM_NUM_ROWS, PDS_MAX_FILE_IDX, and pdsNvmEraseAll().

Referenced by PDS_DeleteAll().

PdsStatus_t pdsWlRead ( PdsFileItemIdx_t  pdsFileItemIdx,
PdsMem_t buffer,
uint16_t  size 
)

This function will find extract the row where the file is stored and read from NVM.

Parameters
[in]pdsFileItemIdx- The file id to be read from.
[in]buffer- The buffer containing data to be written.
[in]size- The size of the data in the buffer.
[out]status- The return status of the function's operation of type PdsStatus_t.

References _FileMap::maxCounterRowIdx, PDS_NOT_FOUND, PDS_OK, and pdsNvmRead().

Referenced by PDS_Restore(), PDS_RestoreAll(), and pdsStoreDelete().

PdsStatus_t pdsWlWrite ( PdsFileItemIdx_t  pdsFileItemIdx,
PdsMem_t buffer,
uint16_t  size 
)

This function will find the free row index to write to, updates the WL_Struct header and writes to NVM.

If the nvm write is successful it updates the row and file map.

Parameters
[in]pdsFileItemIdx- The file id to be written to.
[in]buffer- The buffer containing data to be written.
[in]size- The size of the data in the buffer.
[out]status- The return status of the function's operation of type PdsStatus_t.

References _RowMap::counter, _UpdateFileMap::counter, _PdsWlHeader_t::counter, _PdsWlHeader_t::magicNo, _RowMap::memId, _PdsWlHeader_t::memId, _UpdateFileMap::memId, _PdsNvm_t::NVM_Struct, PDS_MAGIC, PDS_OK, PDS_WL_VERSION, _PdsNvm_t::_NVM_Struct::pdsNvmData, pdsNvmWrite(), pdsReturnFreeRowIdx(), pdsUpdateFileMap(), _PdsWl_t::_WL_Struct::pdsWlHeader, _RowMap::previousIdx, _UpdateFileMap::rowIdx, _PdsWlHeader_t::size, _PdsWlHeader_t::version, and _PdsWl_t::WL_Struct.

Referenced by pdsStoreDelete().

FileMap_t fileMap[PDS_MAX_FILE_IDX]
static
RowMap_t rowMap[EEPROM_NUM_ROWS]
static