3.10.3 NVMCTRL with True Read-While-Write Support

Nonvolatile Memory Controller with True Read-While-Write Support

3.10.3.1 Introduction

This NVM Controller (NVMCTRL)Module is the interface between the CPU and Nonvolatile Memories (Flash, EEPROM, Signature Row, User Row, and fuses). These are reprogrammable memory blocks that retain their values when they are not powered. The Flash is mainly used for program storage and can also be used for data storage, while the EEPROM, Signature Row, User Row, and fuses are used for data storage. The “Read-While-Write section” refers to which section is being programmed (erased or written) and not the one read. Only the code located inside the NRWW Flash can be accessed by either executing a CPU instruction or reading data while the RWW Flash is being written or erased.

3.10.3.2 Supported Device Families

ATmega32xxAVR® EA

3.10.3.3 Required header files:

#include "mcc_generated_files/nvm/nvm.h"

3.10.3.4 Module Documentation

3.10.3.4.1 Non-Volatile Memory

This file contains API prototypes and other data types for the Non-Volatile Memory (NVM) driver.

Module description

This file contains API prototypes and other data types for the Non-Volatile Memory (NVM) driver.

Version: NVM Driver Version 2.1.2
Typedefs
Functions

Definition Documentation

SERIAL_NUMBER_SIZE

#define SERIAL_NUMBER_SIZE (16U)

Contains the serial number length in bytes.

Typedef Documentation

device_id_data_t

typedef uint32_t device_id_data_t

Data type for the Device ID data.

eeprom_address_t

typedef uint16_t eeprom_address_t

Data type for the EEPROM address.

eeprom_data_t

typedef uint8_t eeprom_data_t

Data type for the EEPROM data.

flash_address_t

typedef uint16_t flash_address_t

Data type for the Flash address.

flash_data_t

typedef uint8_t flash_data_t

Data types for the NVM address and data.

Data type for the Flash data.

fuse_address_t

typedef uint16_t fuse_address_t

Data type for the Fuse address.

fuse_data_t

typedef uint8_t fuse_data_t

Data type for the Fuse data.

sigrow_address_t

typedef uint16_t sigrow_address_t

Datatype for Signature Row address.

sigrow_data_t

typedef uint8_t sigrow_data_t

Data type for the Signature Row data.

Function Documentation

EEPROM_CallbackRegister()

void EEPROM_CallbackRegister (void(*)(void) CallbackHandler)

Setter function for the EEPROM Ready interrupt callback.

Parameters:
in CallbackHandler

- Pointer to a custom callback.

Returns:

None.

EEPROM_IsBusy()

bool EEPROM_IsBusy (void )

Checks if the EEPROM is busy.

Precondition:

NVM must be initialized with NVM_Initialize() before calling this API.

Parameters:
None.
Return values:
True

- The EEPROM operation is being performed.

False

- The EEPROM operation is not being performed.

EEPROM_Read()

eeprom_data_t EEPROM_Read (eeprom_address_t address)

Reads one byte from the given EEPROM address.

Precondition:

NVM must be initialized with NVM_Initialize() before calling this API.

Parameters:
in address

- Address of the EEPROM location to be read.

Returns:

Byte read from the given EEPROM address.

EEPROM_ReadyInterruptDisable()

void EEPROM_ReadyInterruptDisable (void )

Disables the EEREADY interrupt.

Precondition:

The interrupt can be disabled in the interrupt handler.

Parameters:
None.
Returns:

None.

EEPROM_ReadyInterruptEnable()

void EEPROM_ReadyInterruptEnable (void )

Enables the EEREADY interrupt.

Precondition:

The interrupt must be enabled only after triggering a NVM command. Global interrupt must be enabled for the EERADY interrupt to work.

Parameters:
None.
Returns:

None.

EEPROM_Write()

nvm_status_t EEPROM_Write (eeprom_address_t address, eeprom_data_t data)

Writes one byte to the given EEPROM address. The EEPROM busy status must be checked using the EEPROM_IsBusy() API to know if the Write operation is completed. Use the NVM_StatusGet() API to see the result of the Write operation.

Parameters:
in address

- Address of the EEPROM location to be written.

in data

- Byte to be written to the given EEPROM location.

Returns:

None.

Flash_CallbackRegister()

void Flash_CallbackRegister (void(*)(void) CallbackHandler)

Setter function for the Flash Ready interrupt callback.

Parameters:
in CallbackHandler

- Pointer to a custom callback.

Returns:

None.

FLASH_IsBusy()

bool FLASH_IsBusy (void )

Checks if the Flash is busy.

Precondition:

NVM must be initialized with NVM_Initialize() before calling this API.

Parameters:
None.
Return values:
True

- The Flash operation is being performed.

False

- The Flash operation is not being performed.

FLASH_PageAddressGet()

flash_address_t FLASH_PageAddressGet (flash_address_t address)

Returns the starting address of the page (the first byte location) containing the given Flash address.

Parameters:
in address

- Flash address for which the page starting address will be obtained.

Returns:

Starting address of the page containing the given Flash address.

FLASH_PageErase()

nvm_status_t FLASH_PageErase (flash_address_t address)

Erases one Flash page containing the given address.

Precondition:

NVM must be initialized with NVM_Initialize() before calling this API.

Parameters:
in address

- Starting address of the Flash page to be erased.

Returns:

Status of the Flash Page Erase operation as described in the nvm_status_t.

FLASH_PageOffsetGet()

flash_address_t FLASH_PageOffsetGet (flash_address_t address)

Returns the offset from the starting address of the page (the first byte location).

Parameters:
in address

- Flash address for which the offset from the starting address of the page will be obtained.

Returns:

Offset of the given address from the starting address of the page.

FLASH_Read()

flash_data_t FLASH_Read (flash_address_t address)

Reads a byte from the given Flash address.

Precondition:

NVM must be initialized with NVM_Initialize() before calling this API.

Parameters:
in address

- Address of the Flash location where data read from.

Returns:

Byte read from the given Flash address.

Flash_ReadyInterruptDisable()

void Flash_ReadyInterruptDisable (void )

Disables the FLREADY interrupt.

Precondition:

The interrupt can be disabled in the interrupt handler.

Parameters:
None.
Returns:

None.

Flash_ReadyInterruptEnable()

void Flash_ReadyInterruptEnable (void )

Enables the FLREADY interrupt.

Precondition:

The interrupt must be enabled only after triggering a NVM command. Global interrupt must be enabled for the FLREADY interrupt to work.

Parameters:
None.
Returns:

None.

FLASH_RowWrite()

nvm_status_t FLASH_RowWrite (flash_address_t address, flash_data_t * dataBuffer)

Writes one entire Flash row/page from the given starting address of the row (the first byte location). The size of the input buffer must be one Flash row and the address must be aligned with the row boundary. Use FLASH_PageAddressGet() to obtain the starting address of the row.

Precondition:

Erase Flash row before calling this function.

Parameters:
in address

- Starting address of the Flash row to be written.

in *dataBuffer

- Pointer to a buffer which holds the data to be written.

Returns:

Status of the Flash row Write operation as described in nvm_status_t.

FUSE_Read()

fuse_data_t FUSE_Read (fuse_address_t address)

Reads a fuse.

Parameters:
in address

- Fuse address to be read.

Returns:

Fuse data.

NVM_Initialize()

void NVM_Initialize (void )

Initializes the NVM driver.

Parameters:
None.
Returns:

None.

NVM_StatusClear()

void NVM_StatusClear (void )

Clears the status of the last NVM operation.

Parameters:
None.
Return values:
None.
NVM_StatusGet()

nvm_status_t NVM_StatusGet (void )

Returns the status of the last NVM operation.

Parameters:
None.
Return values:
NVM_OK

- The NVM operation succeeded

NVM_ERROR

- The NVM operation failed

SIGROW_DeviceIDRead()

device_id_data_t SIGROW_DeviceIDRead (sigrow_address_t address)

Reads the Device ID.

Parameters:
in address

- Starting address of the Device ID.

Returns:

Device ID.  

SIGROW_Read()

sigrow_data_t SIGROW_Read (sigrow_address_t address)

Reads one Signature Row byte.

Parameters:
in address

- Address of the Signature Row byte to be read.

Returns:

Signature Row data.

SIGROW_SerialNumberRead()

void SIGROW_SerialNumberRead (sigrow_address_t address, sigrow_data_t * serialNumber)

Reads the serial number. The size of the buffer must be equal to the size of the serial number.

Parameters:
in address

- Starting address of the serial number.

out *serialNumber

- Buffer to hold the serial number.

Returns:

None.

Enumeration Type Documentation

nvm_status_t

enum nvm_status_t

Contains the return codes for the NVM driver APIs.

NVM_OK

0 - The NVM operation succeeded

NVM_ERROR

1 - The NVM operation failed

NVM_BUSY

2 - The NVM Write operation is ongoing

3.10.3.5 File Documentation

3.10.3.5.1 source/source-files/nvm.c File Reference

This file contains the implementation for the NVM driver.

#include <avr/pgmspace.h>
#include "../../system/ccp.h"
#include "../nvm.h"

Functions

Detailed Description

This file contains the implementation for the NVM driver.

Version: NVM Driver Version 2.1.2

Function Documentation

FLASH_SpmWriteWord()

inline static void FLASH_SpmWriteWord (flash_address_t address, uint16_t data)

ISR()

ISR (NVMCTRL_NVMREADY_vect )

NVM_NoOperation_Command()

inline static void NVM_NoOperation_Command (void )

Variable Documentation

EEPROM_Callback

void(* EEPROM_Callback) (void) = NULL[static]

Flash_Callback

void(* Flash_Callback) (void) = NULL[static]

3.10.3.5.2 source/source-files/nvm.h File Reference

#include <string.h>
#include "../system/utils/compiler.h"

Functions

Typedefs

Macro Definition Documentation

FLASH_ErasePageAddressGet

#define FLASH_ErasePageAddressGet FLASH_PageAddressGet

FLASH_ErasePageOffsetGet

#define FLASH_ErasePageOffsetGet FLASH_PageOffsetGet