Xmega Application Note


NVM driver EEPROM handling
[NVM driver]

Functions for handling internal EEPROM memory. More...

Collaboration diagram for NVM driver EEPROM handling:

Functions

void nvm_eeprom_atomic_write_page (uint8_t page_addr)
 Erase and write bytes from page buffer into EEPROM.
void nvm_eeprom_erase_all (void)
 Erase entire EEPROM memory.
void nvm_eeprom_erase_bytes_in_all_pages (void)
 Erase bytes from all EEPROM pages.
void nvm_eeprom_erase_bytes_in_page (uint8_t page_addr)
 Erase bytes from EEPROM page.
void nvm_eeprom_erase_page (uint8_t page_addr)
 Erase EEPROM page.
void nvm_eeprom_fill_buffer_with_value (uint8_t value)
 Fill temporary EEPROM page buffer with value.
void nvm_eeprom_flush_buffer (void)
 Flush temporary EEPROM page buffer.
void nvm_eeprom_load_byte_to_buffer (uint8_t byte_addr, uint8_t value)
 Load single byte into temporary page buffer.
void nvm_eeprom_load_page_to_buffer (const uint8_t *values)
 Load entire page into temporary EEPROM page buffer.
uint8_t nvm_eeprom_read_byte (uint8_t page_addr, uint8_t byte_addr)
 Read one byte from EEPROM using IO mapping.
void nvm_eeprom_split_write_page (uint8_t page_addr)
 Write (without erasing) EEPROM page.
void nvm_eeprom_write_byte (uint8_t page_addr, uint8_t byte_addr, uint8_t value)
 Write one byte to EEPROM using IO mapping.

Detailed Description

Functions for handling internal EEPROM memory.

The internal EEPROM can be used to store data that will persist after power is removed. This can typically be used to store calibration data, application state, encryption keys or other data that need to be preserved when power is removed.

The functions in this module uses IO register access to manipulate the EEPROM.

Note:
The functions in this module are modifying the NVM.CMD register. If the application are using program space access in interrupts (__flash pointers in IAR EW or pgm_read_byte in GCC) interrupts needs to be disabled when running EEPROM access functions. If not the program space reads will be corrupted.

Function Documentation

void nvm_eeprom_atomic_write_page ( uint8_t  page_addr  ) 

Erase and write bytes from page buffer into EEPROM.

This function writes the contents of an already loaded EEPROM page buffer into EEPROM memory.

As this is an atomic write, the page in EEPROM will be erased automatically before writing. Note that only the page buffer locations that have been loaded will be used when writing to EEPROM. Page buffer locations that have not been loaded will be left untouched in EEPROM.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
void nvm_eeprom_erase_all ( void   ) 

Erase entire EEPROM memory.

This function erases the entire EEPROM memory block to 0xFF.

void nvm_eeprom_erase_bytes_in_all_pages ( void   ) 

Erase bytes from all EEPROM pages.

This function erases bytes from all EEPROM pages, so that every location written to in the page buffer reads 0xFF.

void nvm_eeprom_erase_bytes_in_page ( uint8_t  page_addr  ) 

Erase bytes from EEPROM page.

This function erases bytes from one EEPROM page, so that every location written to in the page buffer reads 0xFF.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
void nvm_eeprom_erase_page ( uint8_t  page_addr  ) 

Erase EEPROM page.

This function erases one EEPROM page, so that every location reads 0xFF.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
void nvm_eeprom_fill_buffer_with_value ( uint8_t  value  ) 

Fill temporary EEPROM page buffer with value.

This fills the the EEPROM page buffers with a given value. If memory mapped EEPROM is enabled, this function will not work.

Note:
Only the lower part of the address is used to address the buffer. Therefore, no address parameter is needed. In the end, the data is written to the EEPROM page given by the address parameter to the EEPROM write page operation.
Parameters:
value Value to copy to the page buffer.
void nvm_eeprom_flush_buffer ( void   ) 

Flush temporary EEPROM page buffer.

This function flushes the EEPROM page buffers. This function will cancel any ongoing EEPROM page buffer loading operations, if any. This function also works for memory mapped EEPROM access.

Note:
An EEPROM write operations will automatically flush the buffer for you.
The function does not preserve the value of the NVM.CMD register
void nvm_eeprom_load_byte_to_buffer ( uint8_t  byte_addr,
uint8_t  value 
)

Load single byte into temporary page buffer.

This function loads one byte into the temporary EEPROM page buffers. If memory mapped EEPROM is enabled, this function will not work. Make sure that the buffer is flushed before starting to load bytes. Also, if multiple bytes are loaded into the same location, they will be ANDed together, thus 0x55 and 0xAA will result in 0x00 in the buffer.

Note:
Only one page buffer exist, thus only one page can be loaded with data and programmed into one page. If data needs to be written to different pages, the loading and writing needs to be repeated.
Parameters:
byte_addr EEPROM Byte address, between 0 and EEPROM_PAGE_SIZE.
value Byte value to write to buffer.
void nvm_eeprom_load_page_to_buffer ( const uint8_t *  values  ) 

Load entire page into temporary EEPROM page buffer.

This function loads an entire EEPROM page from an SRAM buffer to the EEPROM page buffers. If memory mapped EEPROM is enabled, this function will not work. Make sure that the buffer is flushed before starting to load bytes.

Note:
Only the lower part of the address is used to address the buffer. Therefore, no address parameter is needed. In the end, the data is written to the EEPROM page given by the address parameter to the EEPROM write page operation.
Parameters:
values Pointer to SRAM buffer containing an entire page.
uint8_t nvm_eeprom_read_byte ( uint8_t  page_addr,
uint8_t  byte_addr 
)

Read one byte from EEPROM using IO mapping.

This function reads one byte from EEPROM using IO-mapped access. If memory mapped EEPROM is enabled, this function will not work.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
byte_addr EEPROM Byte address, between 0 and EEPROM_PAGE_SIZE.
Returns:
Byte value read from EEPROM.
void nvm_eeprom_split_write_page ( uint8_t  page_addr  ) 

Write (without erasing) EEPROM page.

This function writes the contents of an already loaded EEPROM page buffer into EEPROM memory.

As this is a split write, the page in EEPROM will _not_ be erased before writing.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
void nvm_eeprom_write_byte ( uint8_t  page_addr,
uint8_t  byte_addr,
uint8_t  value 
)

Write one byte to EEPROM using IO mapping.

This function writes one byte to EEPROM using IO-mapped access. If memory mapped EEPROM is enabled, this function will not work. This functiom will cancel all ongoing EEPROM page buffer loading operations, if any.

Parameters:
page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE
byte_addr EEPROM Byte address, between 0 and EEPROM_PAGE_SIZE.
value Byte value to write to EEPROM.
@DOC_TITLE@
Generated on Fri Oct 22 12:15:26 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3