NV component header.
The segment D_NV_MEMORY must be defined and reserved in the linker script (.xcl file), for example like this:
-D_D_NV_MEMORY_START=400 -D_D_NV_MEMORY_SIZE=4000
-Z(CODE)D_NV_MEMORY+_D_NV_MEMORY_SIZE=[_D_NV_MEMORY_START:+_D_NV_MEMORY_SIZE]
Note that nothing should actually be placed in the segment. These linker script commands will ensure that the entire range is reserved and not programmed (left as 0xff).
The segment should start on a flash page boundary, and the size should correspond to the define D_NV_MEMORY_SIZE.
Further, since the device can only erase a whole page and not arbitrary locations in flash, the sector size must be an integer multiple of the flash page size. Otherwise, erasing the first or last page of a sector will also erase content in flash locations neighbouring the sector.
Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.
#include <compiler.h>
Macros | |
#define | ADD_COMMA(value, n) value, |
#define | ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) |
#define | CEIL(a, b) (((a) - 1U)/(b) + 1U) |
#define | COMPARE_WITH_THRESHOLD(a, b, threshold) (abs((a) - (b)) < (threshold) ? ((a) > (b) ? 1 : 0) : ((a) > (b) ? 0 : 1)) |
#define | D_NV_FIRST_SECTOR 0 |
#define | D_NV_MEMORY_SIZE (D_NV_SECTOR_COUNT * D_NV_SECTOR_SIZE) |
#define | D_NV_SECTOR_COUNT 2 |
#define | D_NV_SECTOR_SIZE (8192U) |
#define | FIELD_OFFSET(struct_type, field_name) (((uint8_t*) &((struct_type *)(NULL))->field_name) - (uint8_t*)NULL) |
#define | FIRST_BIT_CLEARED(bitmask) (~(bitmask) & ((bitmask) + 1)) |
#define | FIRST_BIT_SET(bitmask) ((bitmask) & (~(bitmask) + 1)) |
#define | FLASH_PTR |
#define | GET_CONST_PARENT_BY_FIELD(TYPE, FIELD, FIELD_POINTER) ((const TYPE *)(((const uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD))) |
#define | GET_FIELD_PTR(structPtr, typeName, fieldName) ((uint8_t *)(structPtr) + offsetof(typeName, fieldName)) |
#define | GET_INDEX_FROM_OFFSET(PTR1, PTR2) (PTR1 - PTR2) |
#define | GET_PARENT_BY_FIELD(TYPE, FIELD, FIELD_POINTER) ((TYPE *)(((uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD))) |
#define | GET_STRUCT_BY_FIELD_POINTER(struct_type, field_name, field_pointer) ((struct_type *) (((uint8_t *) field_pointer) - FIELD_OFFSET(struct_type, field_name))) |
#define | INIT_ARRAY(initValue, size) {REPEAT_MACRO(ADD_COMMA, initValue, size)} |
#define | MAX(x, y) ((x)<(y)?(y):(x)) |
#define | MIN(x, y) ((x)<(y)?(x):(y)) |
#define | SLICE_SIZE(type, firstField, lastField) (offsetof(type, lastField) - offsetof(type, firstField) + sizeof(((type *)0)->lastField)) |
Typedefs | |
typedef uint16_t | D_Nv_Size_t |
Functions | |
void | D_Nv_EraseSector (uint8_t sector) |
bool | D_Nv_IsEmpty (uint8_t sector, uint16_t offset, D_Nv_Size_t numberOfBytes) |
bool | D_Nv_IsEqual (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes) |
void | D_Nv_Read (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes) |
void | D_Nv_SetSystemIntegrityCheckFunction (void(*pf)(void)) |
void | D_Nv_Write (uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes) |
#define ADD_COMMA | ( | value, | |
n | |||
) | value, |
#define ARRAY_SIZE | ( | a | ) | (sizeof(a)/sizeof(a[0])) |
#define CEIL | ( | a, | |
b | |||
) | (((a) - 1U)/(b) + 1U) |
#define COMPARE_WITH_THRESHOLD | ( | a, | |
b, | |||
threshold | |||
) | (abs((a) - (b)) < (threshold) ? ((a) > (b) ? 1 : 0) : ((a) > (b) ? 0 : 1)) |
#define D_NV_FIRST_SECTOR 0 |
#define D_NV_MEMORY_SIZE (D_NV_SECTOR_COUNT * D_NV_SECTOR_SIZE) |
#define D_NV_SECTOR_COUNT 2 |
#define D_NV_SECTOR_SIZE (8192U) |
#define FIELD_OFFSET | ( | struct_type, | |
field_name | |||
) | (((uint8_t*) &((struct_type *)(NULL))->field_name) - (uint8_t*)NULL) |
#define FIRST_BIT_CLEARED | ( | bitmask | ) | (~(bitmask) & ((bitmask) + 1)) |
#define FIRST_BIT_SET | ( | bitmask | ) | ((bitmask) & (~(bitmask) + 1)) |
#define FLASH_PTR |
Referenced by pdsInitItemMask().
#define GET_CONST_PARENT_BY_FIELD | ( | TYPE, | |
FIELD, | |||
FIELD_POINTER | |||
) | ((const TYPE *)(((const uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD))) |
#define GET_FIELD_PTR | ( | structPtr, | |
typeName, | |||
fieldName | |||
) | ((uint8_t *)(structPtr) + offsetof(typeName, fieldName)) |
#define GET_INDEX_FROM_OFFSET | ( | PTR1, | |
PTR2 | |||
) | (PTR1 - PTR2) |
#define GET_PARENT_BY_FIELD | ( | TYPE, | |
FIELD, | |||
FIELD_POINTER | |||
) | ((TYPE *)(((uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD))) |
#define GET_STRUCT_BY_FIELD_POINTER | ( | struct_type, | |
field_name, | |||
field_pointer | |||
) | ((struct_type *) (((uint8_t *) field_pointer) - FIELD_OFFSET(struct_type, field_name))) |
#define INIT_ARRAY | ( | initValue, | |
size | |||
) | {REPEAT_MACRO(ADD_COMMA, initValue, size)} |
#define MAX | ( | x, | |
y | |||
) | ((x)<(y)?(y):(x)) |
#define MIN | ( | x, | |
y | |||
) | ((x)<(y)?(x):(y)) |
#define SLICE_SIZE | ( | type, | |
firstField, | |||
lastField | |||
) | (offsetof(type, lastField) - offsetof(type, firstField) + sizeof(((type *)0)->lastField)) |
typedef uint16_t D_Nv_Size_t |
void D_Nv_EraseSector | ( | uint8_t | sector | ) |
bool D_Nv_IsEmpty | ( | uint8_t | sector, |
uint16_t | offset, | ||
D_Nv_Size_t | numberOfBytes | ||
) |
bool D_Nv_IsEqual | ( | uint8_t | sector, |
uint16_t | offset, | ||
uint8_t * | pBuffer, | ||
D_Nv_Size_t | numberOfBytes | ||
) |
void D_Nv_Read | ( | uint8_t | sector, |
uint16_t | offset, | ||
uint8_t * | pBuffer, | ||
D_Nv_Size_t | numberOfBytes | ||
) |
void D_Nv_SetSystemIntegrityCheckFunction | ( | void(*)(void) | pf | ) |
void D_Nv_Write | ( | uint8_t | sector, |
uint16_t | offset, | ||
uint8_t * | pBuffer, | ||
D_Nv_Size_t | numberOfBytes | ||
) |