Atmel Software Framework

common_nvm.h File Reference

Non volatile memories management.

Copyright (c) 2012-2015 Atmel Corporation. All rights reserved.

#include "compiler.h"
#include "conf_board.h"
#include "parts.h"
#include "status_codes.h"

Enumerations

enum  mem_type_t { INT_FLASH }
 

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...
 

enum mem_type_t
Enumerator
INT_FLASH 

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, FLASH_PAGE_SIZE, 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, FLASH_PAGE_SIZE, 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, FLASH_PAGE_SIZE, FLASH_SIZE, 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 ERR_INVALID_ARG, FLASH_PAGE_SIZE, INT_FLASH, nvm_eeprom_erase_page(), nvm_flash_erase_app_page(), nvm_flash_erase_boot_page(), nvm_flash_erase_user_section(), 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, ERR_BAD_ADDRESS, ERR_INVALID_ARG, INT_FLASH, nvm_eeprom_read_buffer(), nvm_flash_read_buffer(), nvm_user_sig_read_buffer(), and STATUS_OK.

Referenced by pal_ps_get(), 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(), ERR_BAD_ADDRESS, ERR_INVALID_ARG, INT_FLASH, nvm_eeprom_read_byte(), nvm_flash_read_byte(), nvm_user_sig_read_buffer(), 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 nvm_lb_lock_bits_write(), 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, INT_FLASH, nvm_eeprom_erase_and_write_buffer(), nvm_flash_erase_and_write_buffer(), nvm_user_sig_write_buffer(), and STATUS_OK.

Referenced by pal_ps_set(), 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, INT_FLASH, nvm_eeprom_write_byte(), nvm_flash_erase_and_write_buffer(), nvm_user_sig_write_buffer(), and STATUS_OK.

Referenced by run_byte_access_test().