Microchip® Advanced Software Framework

D_Nv.c File Reference

NV component implementation.

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

#include <D_Nv_Bindings.h>
#include <D_Nv.h>
#include <D_Nv_Init.h>
#include "nvm.h"
#include "common_nvm.h"
#include "compiler.h"
#include "system_interrupt.h"
#include "string.h"
#include "assert.h"

Macros

#define COMPID   "D_Nv"
 
#define D_NV_MEMORY_END   (((uint32_t)&__d_nv_mem_end) - 1U)
 
#define D_NV_MEMORY_START   (uint32_t)&__d_nv_mem_start
 

Functions

static bool CompareData (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
 Compare bytes with contents of the internal NV. More...
 
void D_Nv_EraseSector (uint8_t sector)
 Erases a sector of the internal NV. More...
 
void D_Nv_Init (void)
 Initializes the component – checks that parameters are correct. More...
 
bool D_Nv_IsEmpty (uint8_t sector, uint16_t offset, D_Nv_Size_t numberOfBytes)
 Checks if the requested range is empty (containing all 0xFF). More...
 
bool D_Nv_IsEqual (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
 Compare bytes with contents of the internal NV. More...
 
void D_Nv_Read (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
 Read bytes from the internal NV. More...
 
void D_Nv_SetSystemIntegrityCheckFunction (void(*pf)(void))
 The function to set system integrity check callback function. More...
 
void D_Nv_Write (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
 Write bytes to the internal NV. More...
 

Variables

uint32_t __d_nv_mem_end
 
uint32_t __d_nv_mem_start
 
static void(* s_pfSystemCheckCallback )(void) = NULL
 

#define COMPID   "D_Nv"
#define D_NV_MEMORY_END   (((uint32_t)&__d_nv_mem_end) - 1U)
#define D_NV_MEMORY_START   (uint32_t)&__d_nv_mem_start

static bool CompareData ( uint8_t  sector,
uint16_t  offset,
uint8_t *  pBuffer,
D_Nv_Size_t  numberOfBytes 
)
static

Compare bytes with contents of the internal NV.

Parameters
sectorThe sector to use (0..D_NV_SECTOR_COUNT)
offsetThe offset to start comparing with
[in]pBufferIf NULL then read buffer will be compared with 0xFF Otherwise it is the start address of the buffer that contains the data to compare with
numberOfBytesThe number of bytes to compare
Note
offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)

References D_NV_FIRST_SECTOR, D_NV_MEMORY_END, D_NV_MEMORY_START, D_NV_SECTOR_SIZE, FLASH_PTR, and MIN.

Referenced by D_Nv_IsEmpty(), and D_Nv_IsEqual().

void D_Nv_EraseSector ( uint8_t  sector)

Erases a sector of the internal NV.

Parameters
sectorThe sector to erase (0..D_NV_SECTOR_COUNT)

References D_NV_FIRST_SECTOR, D_NV_MEMORY_END, D_NV_MEMORY_START, D_NV_SECTOR_SIZE, and nvm_erase_row().

void D_Nv_Init ( void  )

Initializes the component – checks that parameters are correct.

References D_NV_MEMORY_END, D_NV_MEMORY_SIZE, D_NV_MEMORY_START, and D_NV_SECTOR_SIZE.

Referenced by PDS_Init().

bool D_Nv_IsEmpty ( uint8_t  sector,
uint16_t  offset,
D_Nv_Size_t  numberOfBytes 
)

Checks if the requested range is empty (containing all 0xFF).

Parameters
sectorThe sector to use (0..D_NV_SECTOR_COUNT)
offsetThe start offset to check
numberOfBytesThe number of bytes to check
Returns
true if the range is empty, FALSE otherwise.
Note
Sector crossing is not permitted

References CompareData().

bool D_Nv_IsEqual ( uint8_t  sector,
uint16_t  offset,
uint8_t *  pBuffer,
D_Nv_Size_t  numberOfBytes 
)

Compare bytes with contents of the internal NV.

Parameters
sectorThe sector to use (0..D_NV_SECTOR_COUNT)
offsetThe offset to start comparing with
[in]pBufferThe start address of the buffer that contains the data to compare with
numberOfBytesThe number of bytes to compare
Note
offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)

References CompareData().

void D_Nv_Read ( uint8_t  sector,
uint16_t  offset,
uint8_t *  pBuffer,
D_Nv_Size_t  numberOfBytes 
)

Read bytes from the internal NV.

Parameters
sectorThe sector to use (0..D_NV_SECTOR_COUNT)
offsetThe offset to start reading at
[out]pBufferThe start address of the buffer to store the read data to
numberOfBytesThe number of bytes to read
Note
offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)

References D_NV_FIRST_SECTOR, D_NV_MEMORY_END, D_NV_MEMORY_START, D_NV_SECTOR_SIZE, and FLASH_PTR.

void D_Nv_SetSystemIntegrityCheckFunction ( void(*)(void)  pf)

The function to set system integrity check callback function.

References s_pfSystemCheckCallback.

void D_Nv_Write ( uint8_t  sector,
uint16_t  offset,
uint8_t *  pBuffer,
D_Nv_Size_t  numberOfBytes 
)

Write bytes to the internal NV.

Parameters
sectorThe sector to use (0..D_NV_SECTOR_COUNT)
offsetThe offset to start writing to
[in]pBufferThe start address of the buffer that contains the data to write
numberOfBytesThe number of bytes to write
Note
offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)
pBuffer cannot be const because it is passed to HAL_FillFlashPageBuffer()

References D_NV_FIRST_SECTOR, D_NV_MEMORY_END, D_NV_MEMORY_START, D_NV_SECTOR_SIZE, MIN, nvm_write_buffer(), s_pfSystemCheckCallback, STATUS_BUSY, STATUS_OK, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

uint32_t __d_nv_mem_end
uint32_t __d_nv_mem_start
void(* s_pfSystemCheckCallback)(void) = NULL
static