Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
NVM driver example functions

Macros

#define FLASH_ERASED   0xffff
 

Functions

static void fill_flash_page_buffer (uint16_t *buffer, uint16_t seed)
 Fill page buffer with a sequence of numbers. More...
 
static bool is_flash_page_equal_to_buffer (flash_addr_t page_addr, uint16_t *buffer)
 Check if an flash page is equal to a flash page buffer in SRAM. More...
 
int main (void)
 
static void set_buffer (uint16_t *buffer, uint16_t value)
 Set all values of a flash page buffer in SRAM to a given value. More...
 
static status_code_t test_atomic_write_app_table (void)
 Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_app_page(). More...
 
static status_code_t test_atomic_write_boot (void)
 Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_boot_page(). More...
 
static status_code_t test_split_write_app_table (void)
 Test nvm_flash_load_word_to_buffer(), nvm_flash_erase_app_page() and nvm_flash_split_write_app_page(). More...
 
static status_code_t test_split_write_boot (void)
 Test nvm_flash_load_word_to_buffer(), nvm_flash_erase_boot_page() and nvm_flash_split_write_boot_page(). More...
 

Variables

uint16_t buffer [FLASH_PAGE_SIZE/2]
 Memory buffer to use during testing. More...
 

static void fill_flash_page_buffer ( uint16_t *  buffer,
uint16_t  seed 
)
static

Fill page buffer with a sequence of numbers.

The function fills the flash page buffer with a sequence of number, and stores the same numbers in a buffer in SRAM. The buffer is used to verify that the flash has been programmed correctly. A seed number is used to ensure that different pages always will be different.

Parameters
bufferSRAM buffer to store values written to the flash page buffer
seedOffset number to use on stored values.

References FLASH_PAGE_SIZE, and nvm_flash_load_word_to_buffer().

Referenced by test_atomic_write_app_table(), test_atomic_write_boot(), test_split_write_app_table(), and test_split_write_boot().

static bool is_flash_page_equal_to_buffer ( flash_addr_t  page_addr,
uint16_t *  buffer 
)
static

Check if an flash page is equal to a flash page buffer in SRAM.

References FLASH_PAGE_SIZE, and nvm_flash_read_word().

Referenced by test_atomic_write_app_table(), test_atomic_write_boot(), test_split_write_app_table(), and test_split_write_boot().

static void set_buffer ( uint16_t *  buffer,
uint16_t  value 
)
static

Set all values of a flash page buffer in SRAM to a given value.

References FLASH_PAGE_SIZE.

Referenced by test_atomic_write_app_table(), test_atomic_write_boot(), test_split_write_app_table(), and test_split_write_boot().

static status_code_t test_atomic_write_app_table ( void  )
static

Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_app_page().

Test procedure:

  • Fill page buffer.
  • Erase and write page to application table section
  • Verify each byte written correctly by comparing each word in flash
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, ERR_BAD_DATA, fill_flash_page_buffer(), FLASH_ERASED, FLASH_PAGE_SIZE, is_flash_page_equal_to_buffer(), nvm_flash_atomic_write_app_page(), set_buffer(), and STATUS_OK.

Referenced by main().

static status_code_t test_atomic_write_boot ( void  )
static

Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_boot_page().

Test procedure:

  • Fill page buffer.
  • Erase and write page to bootloader section
  • Verify each byte written correctly by comparing each word in flash
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, ERR_BAD_DATA, fill_flash_page_buffer(), FLASH_ERASED, FLASH_PAGE_SIZE, is_flash_page_equal_to_buffer(), nvm_flash_atomic_write_boot_page(), set_buffer(), and STATUS_OK.

Referenced by main().

static status_code_t test_split_write_app_table ( void  )
static

Test nvm_flash_load_word_to_buffer(), nvm_flash_erase_app_page() and nvm_flash_split_write_app_page().

Test procedure:

  • Erase page in application table section.
  • Verify the page is erased by comparing each word in flash.
  • Write page to application table section
  • Verify each byte written correctly by comparing each word in flash
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, ERR_BAD_DATA, fill_flash_page_buffer(), FLASH_ERASED, FLASH_PAGE_SIZE, is_flash_page_equal_to_buffer(), nvm_flash_erase_app_page(), nvm_flash_split_write_app_page(), set_buffer(), and STATUS_OK.

Referenced by main().

static status_code_t test_split_write_boot ( void  )
static

Test nvm_flash_load_word_to_buffer(), nvm_flash_erase_boot_page() and nvm_flash_split_write_boot_page().

Test procedure:

  • Erase page in boot section.
  • Verify the page is erased by comparing each word in flash.
  • Write page to boot section
  • Verify each byte written correctly by comparing each word in flash
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, ERR_BAD_DATA, fill_flash_page_buffer(), FLASH_ERASED, FLASH_PAGE_SIZE, is_flash_page_equal_to_buffer(), nvm_flash_erase_boot_page(), nvm_flash_split_write_boot_page(), set_buffer(), and STATUS_OK.

Referenced by main().

uint16_t buffer[FLASH_PAGE_SIZE/2]