Microchip® Advanced Software Framework

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

Macros

#define BUFFER_SIZE   16
 
#define EEPROM_ERASED   0xff
 
#define FLASH_ERASED   0xff
 
#define FLASH_ERASED   0xffff
 
#define TEST_ADDR   0
 
#define TEST_ATOMIC_WRITE_PAGE   2
 
#define TEST_ERASE_BYTES_PAGE_1   4
 
#define TEST_ERASE_BYTES_PAGE_2   5
 
#define TEST_ERASE_PAGE   2
 
#define TEST_SPLIT_WRITE_PAGE   3
 
#define TEST_WRITE_PAGE   1
 

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_eeprom_page_equal_to_buffer (uint8_t page_addr, uint8_t *buffer)
 Check if an EEPROM page is equal to a memory buffer. 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...
 
static bool is_user_sig_equal_to_buffer (flash_addr_t address, uint8_t *buffer, uint8_t len)
 Check if an EEPROM page is equal to a memory buffer. More...
 
int main (void)
 
static void set_buffer (uint8_t *buffer, uint8_t value)
 Set all values of a memory buffer to a given value. More...
 
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 (void)
 Test nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_flush_buffer() and nvm_eeprom_atomic_write_page() 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_erase (void)
 Test nvm_eeprom_erase_all(). More...
 
static status_code_t test_erase_bytes (void)
 Test nvm_eeprom_erase_bytes_in_page() and nvm_eeprom_erase_bytes_in_all_pages() More...
 
static status_code_t test_read (void)
 Test nvm_user_sig_read_buffer(). More...
 
static status_code_t test_split_write (void)
 Test nvm_eeprom_split_write_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...
 
static status_code_t test_write (void)
 Test nvm_eeprom_erase_page() and nvm_eeprom_write_byte(). More...
 
static status_code_t test_write_and_erase (void)
 Test nvm_user_sig_write_buffer(). More...
 
static status_code_t test_write_no_erase (void)
 Test nvm_user_sig_write_buffer(). More...
 

Variables

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

#define BUFFER_SIZE   16
#define EEPROM_ERASED   0xff
#define FLASH_ERASED   0xff
#define TEST_ADDR   0
#define TEST_ATOMIC_WRITE_PAGE   2

Referenced by test_atomic_write().

#define TEST_ERASE_BYTES_PAGE_1   4

Referenced by test_erase_bytes().

#define TEST_ERASE_BYTES_PAGE_2   5

Referenced by test_erase_bytes().

#define TEST_ERASE_PAGE   2

Referenced by test_erase().

#define TEST_SPLIT_WRITE_PAGE   3

Referenced by test_split_write().

#define TEST_WRITE_PAGE   1

Referenced by test_write().

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_eeprom_page_equal_to_buffer ( uint8_t  page_addr,
uint8_t *  buffer 
)
static

Check if an EEPROM page is equal to a memory buffer.

References nvm_eeprom_read_byte().

Referenced by test_atomic_write(), test_erase(), test_erase_bytes(), test_split_write(), and test_write().

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 bool is_user_sig_equal_to_buffer ( flash_addr_t  address,
uint8_t *  buffer,
uint8_t  len 
)
static

Check if an EEPROM page is equal to a memory buffer.

References nvm_read_user_signature_row().

Referenced by test_write_and_erase(), and test_write_no_erase().

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

Set all values of a memory buffer to a given value.

References BUFFER_SIZE.

Referenced by test_read(), test_write_and_erase(), and test_write_no_erase().

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 ( void  )
static

Test nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_flush_buffer() and nvm_eeprom_atomic_write_page()

Test procedure:

  • Erase the TEST_ATOMIC_WRITE_PAGE page.
  • Load byte and then flush the buffer at one location.
  • Load two more bytes at a different location.
  • Write the page.
  • Verify that only two bytes are written and the rest of the page is erased.
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, EEPROM_ERASED, ERR_BAD_DATA, is_eeprom_page_equal_to_buffer(), nvm_eeprom_atomic_write_page(), nvm_eeprom_erase_page(), nvm_eeprom_flush_buffer(), nvm_eeprom_load_byte_to_buffer(), set_buffer(), STATUS_OK, and TEST_ATOMIC_WRITE_PAGE.

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.

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.

static status_code_t test_erase ( void  )
static

Test nvm_eeprom_erase_all().

Test procedure:

  • Write one byte to the TEST_ERASE_PAGE page.
  • Erase all memory locations
  • Verify that the EEPROM is erased by a spot test on the TEST_ERASE_PAGE page.
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, EEPROM_ERASED, ERR_BAD_DATA, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_all(), nvm_eeprom_write_byte(), set_buffer(), STATUS_OK, and TEST_ERASE_PAGE.

static status_code_t test_erase_bytes ( void  )
static

Test nvm_eeprom_erase_bytes_in_page() and nvm_eeprom_erase_bytes_in_all_pages()

Test procedure:

  • Write two bytes into page TEST_ERASE_BYTES_PAGE_1 and TEST_ERASE_BYTES_PAGE_2
  • Load value to page buffer in the address of the first byte
  • Erase first byte of TEST_ERASE_BYTES_PAGE_1
  • Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_1
  • Load value to page buffer in the address of the first byte
  • Erase first byte of all pages
  • Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_2
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, EEPROM_ERASED, ERR_BAD_DATA, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_bytes_in_all_pages(), nvm_eeprom_erase_bytes_in_page(), nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_write_byte(), set_buffer(), STATUS_OK, TEST_ERASE_BYTES_PAGE_1, and TEST_ERASE_BYTES_PAGE_2.

static status_code_t test_read ( void  )
static

Test nvm_user_sig_read_buffer().

Test procedure:

Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, BUFFER_SIZE, ERR_BAD_DATA, FLASH_ERASED, nvm_user_sig_read_buffer(), nvm_user_sig_write_buffer(), set_buffer(), STATUS_OK, and TEST_ADDR.

Referenced by main().

static status_code_t test_split_write ( void  )
static

Test nvm_eeprom_split_write_page()

Test procedure:

  • Erase TEST_SPLIT_WRITE_PAGE page and then write 2 bytes to TEST_SPLIT_WRITE_PAGE by using an atomic write
  • Write 1 additional byte at another location using a split write
  • Verify that all 3 bytes written correctly and that the rest of the page is erased.
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, EEPROM_ERASED, ERR_BAD_DATA, is_eeprom_page_equal_to_buffer(), nvm_eeprom_atomic_write_page(), nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_split_write_page(), set_buffer(), STATUS_OK, and TEST_SPLIT_WRITE_PAGE.

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.

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.

static status_code_t test_write ( void  )
static

Test nvm_eeprom_erase_page() and nvm_eeprom_write_byte().

Test procedure:

  • Erase TEST_WRITE_PAGE
  • Write one byte
  • Verify that the byte is written and that all other bytes are erased.
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, EEPROM_ERASED, ERR_BAD_DATA, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_page(), nvm_eeprom_write_byte(), set_buffer(), STATUS_OK, and TEST_WRITE_PAGE.

static status_code_t test_write_and_erase ( void  )
static

Test nvm_user_sig_write_buffer().

Test procedure:

  • Write to user signature row with automatic erasing enabled
  • Verify contents is equal to buffer
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, BUFFER_SIZE, ERR_BAD_DATA, FLASH_ERASED, is_user_sig_equal_to_buffer(), nvm_user_sig_write_buffer(), set_buffer(), STATUS_OK, and TEST_ADDR.

Referenced by main().

static status_code_t test_write_no_erase ( void  )
static

Test nvm_user_sig_write_buffer().

Test procedure:

  • Erase and write to user signature row with some known values
  • Write other values to user signature row with automatic erasing disabled
  • Verify contents is NOT equal to buffer
Returns
STATUS_OK if test succeeded, otherwise ERR_BAD_DATA

References buffer, BUFFER_SIZE, ERR_BAD_DATA, FLASH_ERASED, is_user_sig_equal_to_buffer(), nvm_user_sig_write_buffer(), set_buffer(), STATUS_OK, and TEST_ADDR.

Referenced by main().

uint8_t buffer[EEPROM_PAGE_SIZE]

Memory buffer to use during testing.

uint16_t buffer[FLASH_PAGE_SIZE/2]

Memory buffer to use during testing.