Microchip® Advanced Software Framework

lorawan/services/pds/src/pds_nvm.c File Reference
#include "pds_interface.h"
#include "pds_common.h"
#include "pds_task_handler.h"
#include "pds_wl.h"

Macros

#define PDS_FLASH_START_ADDRESS   NVMCTRL_RWW_EEPROM_ADDR
 

Functions

static uint16_t calculate_crc (uint16_t length, uint8_t *data)
 Calculates the CRC. More...
 
static uint16_t Crc16Ccitt (uint16_t initValue, uint8_t byte)
 Calculates the CRC in CCITT polynome. More...
 
static uint32_t nvmLogicalRowToPhysicalAddr (uint16_t logicalRow)
 Converts logical rows to physical address. More...
 
PdsStatus_t pdsNvmErase (uint16_t rowId)
 Will erase the contents of a row. More...
 
PdsStatus_t pdsNvmEraseAll (void)
 Erases all the contents of NVM of all rows. More...
 
PdsStatus_t pdsNvmInit (void)
 Initializes the NVM by checking the EEPROM size and calling nvm init. More...
 
PdsStatus_t pdsNvmRead (uint16_t rowId, PdsMem_t *buffer, uint16_t size)
 This function will read the contents of NVM and verify the crc. More...
 
PdsStatus_t pdsNvmWrite (uint16_t rowId, PdsMem_t *buffer, uint16_t size)
 This function will calculate the crc of the buffer contents and writes the buffer contents to nvm. More...
 

#define PDS_FLASH_START_ADDRESS   NVMCTRL_RWW_EEPROM_ADDR

static uint16_t calculate_crc ( uint16_t  length,
uint8_t *  data 
)
static

Calculates the CRC.

Parameters
[in]length- The amount of data for which CRC is to be calculated.
[in]data- The data.
[out]uint16_t- The calculated 16 bit CRC.

References Crc16Ccitt(), i, and length.

Referenced by pdsNvmRead(), and pdsNvmWrite().

uint16_t Crc16Ccitt ( uint16_t  initValue,
uint8_t  byte 
)
static

Calculates the CRC in CCITT polynome.

Parameters
[in]initValue- The rowId to be erased.
[in]byte- The rowId to be erased.
[out]uint16_t- The calculated 16 bit CRC.

Referenced by calculate_crc().

static uint32_t nvmLogicalRowToPhysicalAddr ( uint16_t  logicalRow)
static

Converts logical rows to physical address.

Parameters
[in]logicalRow- The logical row.
[out]uint16_t- The calculated 16 bit CRC.

References PDS_FLASH_START_ADDRESS.

Referenced by pdsNvmErase(), pdsNvmRead(), and pdsNvmWrite().

PdsStatus_t pdsNvmErase ( uint16_t  rowId)

Will erase the contents of a row.

Parameters
[in]rowId- The rowId to be erased.
[out]status- The return status of the function's operation of type PdsStatus_t.

References ERR_BUSY, nvm_erase_row(), nvmLogicalRowToPhysicalAddr(), PDS_ERROR, PDS_OK, and STATUS_OK.

Referenced by pdsNvmEraseAll().

PdsStatus_t pdsNvmEraseAll ( void  )

Erases all the contents of NVM of all rows.

Parameters
[in]none
[out]status- The return status of the function's operation of type PdsStatus_t.

References EEPROM_NUM_ROWS, PDS_OK, and pdsNvmErase().

Referenced by pdsWlDeleteAll().

PdsStatus_t pdsNvmInit ( void  )

Initializes the NVM by checking the EEPROM size and calling nvm init.

Parameters
[in]none
[out]status- The return status of the function's operation of type PdsStatus_t.

References EEPROM_SIZE, nvm_get_parameters(), nvm_init(), PDS_ERROR, PDS_NOT_ENOUGH_MEMORY, PDS_OK, nvm_parameters::rww_eeprom_number_of_pages, and STATUS_OK.

Referenced by pdsWlInit().

PdsStatus_t pdsNvmRead ( uint16_t  rowId,
PdsMem_t buffer,
uint16_t  size 
)

This function will read the contents of NVM and verify the crc.

Parameters
[in]pdsFileItemIdx- The file id to be read.
[in]buffer- The buffer containing data to be read.
[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 calculate_crc(), _PdsNvmHeader_t::crc, EEPROM_ROW_SIZE, _PdsNvm_t::NVM_Struct, nvmLogicalRowToPhysicalAddr(), PDS_CRC_ERROR, PDS_ERROR, PDS_OK, _PdsNvm_t::_NVM_Struct::pdsNvmData, _PdsNvm_t::_NVM_Struct::pdsNvmHeader, _PdsNvmHeader_t::size, STATUS_BUSY, and STATUS_OK.

Referenced by pdsNvmWrite(), pdsWlInit(), and pdsWlRead().

PdsStatus_t pdsNvmWrite ( uint16_t  rowId,
PdsMem_t buffer,
uint16_t  size 
)

This function will calculate the crc of the buffer contents and writes the buffer contents to nvm.

It will also read the same content to verify if its written properly.

Parameters
[in]pdsFileItemIdx- The file id to be written.
[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 calculate_crc(), _PdsNvmHeader_t::crc, _PdsNvm_t::NVM_Struct, nvmLogicalRowToPhysicalAddr(), PDS_ERROR, PDS_NVM_VERSION, PDS_OK, _PdsNvm_t::_NVM_Struct::pdsNvmData, _PdsNvm_t::_NVM_Struct::pdsNvmHeader, pdsNvmRead(), _PdsNvmHeader_t::size, STATUS_OK, and _PdsNvmHeader_t::version.

Referenced by pdsWlWrite().