Microchip® Advanced Software Framework

sam_nvm.c File Reference

Non volatile memories management for SAM devices.

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

#include "common_nvm.h"
#include "conf_board.h"
#include "flash_efc.h"
#include "string.h"

Functions

status_code_t nvm_get_page_size (mem_type_t mem, uint32_t *size)
 Get the size of a page in the non volatile memory specified. More...
 
status_code_t nvm_get_pagenumber (mem_type_t mem, uint32_t address, uint32_t *num)
 Get the page number from the byte address address. More...
 
status_code_t nvm_get_size (mem_type_t mem, uint32_t *size)
 Get the size of whole non volatile memory specified. More...
 
status_code_t nvm_init (mem_type_t mem)
 Initialize the non volatile memory specified. More...
 
status_code_t nvm_page_erase (mem_type_t mem, uint32_t page_number)
 Erase a page in the non volatile memory. More...
 
status_code_t nvm_read (mem_type_t mem, uint32_t address, void *buffer, uint32_t len)
 Read len number of bytes from address address in non volatile memory mem and store it in the buffer buffer. More...
 
status_code_t nvm_read_char (mem_type_t mem, uint32_t address, uint8_t *data)
 Read single byte of data. More...
 
status_code_t nvm_set_security_bit (void)
 Enable security bit which blocks external read and write access to the device. More...
 
status_code_t nvm_write (mem_type_t mem, uint32_t address, void *buffer, uint32_t len)
 Write len number of bytes at address address in non volatile memory mem from the buffer buffer. More...
 
status_code_t nvm_write_char (mem_type_t mem, uint32_t address, uint8_t data)
 Write single byte of data. More...
 

status_code_t nvm_get_page_size ( mem_type_t  mem,
uint32_t *  size 
)

Get the size of a page in the non volatile memory specified.

Parameters
memType of non volatile memory
sizePointer to where to store the size

References ERR_INVALID_ARG, INT_FLASH, and STATUS_OK.

status_code_t nvm_get_pagenumber ( mem_type_t  mem,
uint32_t  address,
uint32_t *  num 
)

Get the page number from the byte address address.

Parameters
memType of non volatile memory
addressByte address of the non volatile memory
numPointer to where to store the page number

References ERR_INVALID_ARG, INT_FLASH, and STATUS_OK.

status_code_t nvm_get_size ( mem_type_t  mem,
uint32_t *  size 
)

Get the size of whole non volatile memory specified.

Parameters
memType of non volatile memory
sizePointer to where to store the size

References ERR_INVALID_ARG, INT_FLASH, and STATUS_OK.

status_code_t nvm_init ( mem_type_t  mem)

Initialize the non volatile memory specified.

Parameters
memType of non volatile memory to initialize

References at45dbx_init(), at45dbx_mem_check(), ERR_INVALID_ARG, ERR_NO_MEMORY, INT_FLASH, and STATUS_OK.

Referenced by pal_init(), run_memory_check_test(), and test_mem().

status_code_t nvm_page_erase ( mem_type_t  mem,
uint32_t  page_number 
)

Erase a page in the non volatile memory.

The function is only available for internal flash and/or userpage signature.

Note
For SAM4S internal flash erase, the minimum erase unit is 8 pages.
Parameters
memType of non volatile memory to erase
page_numberPage number to erase

References buffer, ERR_INVALID_ARG, flash_write(), IFLASH_ERASE_PAGES_8, INT_FLASH, and STATUS_OK.

Referenced by run_buffer_access_test(), run_byte_access_test(), and test_mem().

status_code_t nvm_read ( mem_type_t  mem,
uint32_t  address,
void *  buffer,
uint32_t  len 
)

Read len number of bytes from address address in non volatile memory mem and store it in the buffer buffer.

Parameters
memType of non volatile memory to read
addressAddress to read
bufferPointer to destination buffer
lenNumber of bytes to read

References at45dbx_read_byte(), at45dbx_read_byte_open(), at45dbx_read_close(), at45dbx_read_sector_open(), at45dbx_read_sector_to_ram(), AT45DBX_SECTOR_SIZE, buffer, ERR_BAD_ADDRESS, ERR_INVALID_ARG, INT_FLASH, and STATUS_OK.

Referenced by run_buffer_access_test(), and test_mem().

status_code_t nvm_read_char ( mem_type_t  mem,
uint32_t  address,
uint8_t *  data 
)

Read single byte of data.

Parameters
memType of non volatile memory to read
addressAddress to read
dataPointer to where to store the read data

References at45dbx_read_byte(), at45dbx_read_byte_open(), at45dbx_read_close(), buffer, ERR_BAD_ADDRESS, ERR_INVALID_ARG, INT_FLASH, and STATUS_OK.

Referenced by run_byte_access_test().

status_code_t nvm_set_security_bit ( void  )

Enable security bit which blocks external read and write access to the device.

References ERR_INVALID_ARG, flash_enable_security_bit(), and STATUS_OK.

status_code_t nvm_write ( mem_type_t  mem,
uint32_t  address,
void *  buffer,
uint32_t  len 
)

Write len number of bytes at address address in non volatile memory mem from the buffer buffer.

Note
For SAM4S internal flash, the page existed in the address must be erased first before written.
Parameters
memType of non volatile memory to write
addressAddress to write
bufferPointer to source buffer
lenNumber of bytes to write

References AT45DBX_SECTOR_SIZE, at45dbx_write_byte(), at45dbx_write_byte_open(), at45dbx_write_close(), at45dbx_write_sector_from_ram(), at45dbx_write_sector_open(), ERR_BAD_ADDRESS, ERR_INVALID_ARG, flash_write(), INT_FLASH, and STATUS_OK.

Referenced by run_buffer_access_test(), and test_mem().

status_code_t nvm_write_char ( mem_type_t  mem,
uint32_t  address,
uint8_t  data 
)

Write single byte of data.

Note
For SAM4S internal flash, the page existed in the address must be erased first before written, and the minimum write unit is a page,thus when writing a single byte, a whole page that contains the data is writen.
Parameters
memType of non volatile memory to write
addressAddress to write
dataData to be written

References at45dbx_write_byte(), at45dbx_write_byte_open(), at45dbx_write_close(), ERR_BAD_ADDRESS, ERR_INVALID_ARG, flash_write(), INT_FLASH, and STATUS_OK.

Referenced by run_byte_access_test().