Tiva Driver Lib
Macros | Functions
Eeprom_api

Macros

#define BLOCKS_FROM_EESIZE(x)
 
#define SIZE_FROM_EESIZE(x)
 
#define OFFSET_FROM_ADDR(x)   (((x) >> 2) & 0x0F)
 
#define EEPROM_MASS_ERASE_KEY   ((uint32_t)0xE37B << EEPROM_EEDBGME_KEY_S)
 
#define EEPROM_INIT_OK   0
 
#define EEPROM_INIT_RETRY   1
 
#define EEPROM_INIT_ERROR   2
 
#define EEPROM_RC_INVPL   0x00000100
 
#define EEPROM_RC_WRBUSY   0x00000020
 
#define EEPROM_RC_NOPERM   0x00000010
 
#define EEPROM_RC_WKCOPY   0x00000008
 
#define EEPROM_RC_WKERASE   0x00000004
 
#define EEPROM_RC_WORKING   0x00000001
 
#define EEPROM_PROT_SUPERVISOR_ONLY   0x00000008
 
#define EEPROM_PROT_RW_LRO_URW   0x00000000
 
#define EEPROM_PROT_NA_LNA_URW   0x00000001
 
#define EEPROM_PROT_RO_LNA_URO   0x00000002
 
#define EEPROM_INT_PROGRAM   0x00000004
 
#define EEPROMBlockFromAddr(ui32Addr)   ((ui32Addr) >> 6)
 
#define EEPROMAddrFromBlock(ui32Block)   ((ui32Block) << 6)
 

Functions

uint32_t EEPROMInit (void)
 
uint32_t EEPROMSizeGet (void)
 
uint32_t EEPROMBlockCountGet (void)
 
void EEPROMRead (uint32_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count)
 
uint32_t EEPROMProgram (uint32_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count)
 
uint32_t EEPROMProgramNonBlocking (uint32_t ui32Data, uint32_t ui32Address)
 
uint32_t EEPROMMassErase (void)
 
uint32_t EEPROMBlockProtectGet (uint32_t ui32Block)
 
uint32_t EEPROMBlockProtectSet (uint32_t ui32Block, uint32_t ui32Protect)
 
uint32_t EEPROMBlockPasswordSet (uint32_t ui32Block, uint32_t *pui32Password, uint32_t ui32Count)
 
uint32_t EEPROMBlockLock (uint32_t ui32Block)
 
uint32_t EEPROMBlockUnlock (uint32_t ui32Block, uint32_t *pui32Password, uint32_t ui32Count)
 
void EEPROMBlockHide (uint32_t ui32Block)
 
void EEPROMIntEnable (uint32_t ui32IntFlags)
 
void EEPROMIntDisable (uint32_t ui32IntFlags)
 
uint32_t EEPROMIntStatus (bool bMasked)
 
void EEPROMIntClear (uint32_t ui32IntFlags)
 
uint32_t EEPROMStatusGet (void)
 

Detailed Description

Macro Definition Documentation

#define BLOCKS_FROM_EESIZE (   x)
Value:
(((x) & EEPROM_EESIZE_BLKCNT_M) >> \
EEPROM_EESIZE_BLKCNT_S)
#define EEPROM_INIT_ERROR   2

This value may be returned from a call to EEPROMInit(). It indicates that a previous data or protection write operation was interrupted by a reset event and that the EEPROM peripheral was unable to clean up after the problem. This situation may be resolved with another reset or may be fatal depending upon the cause of the problem. For example, if the voltage to the part is unstable, retrying once the voltage has stabilized may clear the error.

#define EEPROM_INIT_OK   0

This value may be returned from a call to EEPROMInit(). It indicates that no previous write operations were interrupted by a reset event and that the EEPROM peripheral is ready for use.

#define EEPROM_INIT_RETRY   1

This value may be returned from a call to EEPROMInit(). It indicates that a previous data or protection write operation was interrupted by a reset event. The EEPROM peripheral has recovered its state but the last write operation may have been lost. The application must check the validity of data it has written and retry any writes as required.

#define EEPROM_INT_PROGRAM   0x00000004

This value may be passed to EEPROMIntEnable() and EEPROMIntDisable() and is returned by EEPROMIntStatus() if an EEPROM interrupt is currently being signaled.

#define EEPROM_PROT_NA_LNA_URW   0x00000001

This value may be passed to EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet(). It indicates that the block should offer neither read nor write access unless it is protected by a password and unlocked.

#define EEPROM_PROT_RO_LNA_URO   0x00000002

This value may be passed to EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet(). It indicates that the block should offer read-only access when no password is set or when a password is set and the block is unlocked. When a password is set and the block is locked, neither read nor write access is permitted.

#define EEPROM_PROT_RW_LRO_URW   0x00000000

This value may be passed to EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet(). It indicates that the block should offer read/write access when no password is set or when a password is set and the block is unlocked, and read-only access when a password is set but the block is locked.

#define EEPROM_PROT_SUPERVISOR_ONLY   0x00000008

This bit may be ORed with the protection option passed to EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet(). It restricts EEPROM access to threads running in supervisor mode and prevents access to an EEPROM block when the CPU is in user mode.

#define EEPROM_RC_INVPL   0x00000100

This return code bit indicates that the EEPROM programming state machine failed to write a value due to the voltage level dropping below that required for EEPROM programming. The operation may be retried once the voltage stabilizes.

#define EEPROM_RC_NOPERM   0x00000010

This return code bit indicates that an attempt was made to write a value but the destination permissions disallow write operations. This may be due to the destination block being locked, access protection set to prohibit writes or an attempt to write a password when one is already written.

#define EEPROM_RC_WKCOPY   0x00000008

This return code bit indicates that the EEPROM programming state machine is currently copying to or from the internal copy buffer to make room for a newly written value. It is provided as a status indicator and does not indicate an error.

#define EEPROM_RC_WKERASE   0x00000004

This return code bit indicates that the EEPROM programming state machine is currently erasing the internal copy buffer. It is provided as a status indicator and does not indicate an error.

#define EEPROM_RC_WORKING   0x00000001

This return code bit indicates that the EEPROM programming state machine is currently working. No new write operations should be attempted until this bit is clear.

#define EEPROM_RC_WRBUSY   0x00000020

This return code bit indicates that an attempt was made to read from the EEPROM while a write operation was in progress.

#define EEPROMAddrFromBlock (   ui32Block)    ((ui32Block) << 6)

Returns the offset address of the first word in an EEPROM block.

Parameters
ui32Blockis the index of the EEPROM block whose first word address is to be returned.

This macro may be used to determine the address of the first word in a given EEPROM block. The address returned is expressed as a byte offset from the base of EEPROM storage.

Returns
Returns the address of the first word in the given EEPROM block.
#define EEPROMBlockFromAddr (   ui32Addr)    ((ui32Addr) >> 6)

Returns the EEPROM block number containing a given offset address.

Parameters
ui32Addris the linear, byte address of the EEPROM location whose block number is to be returned. This is a zero-based offset from the start of the EEPROM storage.

This macro may be used to translate an EEPROM address offset into a block number suitable for use in any of the driver's block protection functions. The address provided is expressed as a byte offset from the base of the EEPROM.

Returns
Returns the zero-based block number which contains the passed address.
#define SIZE_FROM_EESIZE (   x)
Value:
((((x) & EEPROM_EESIZE_WORDCNT_M) >> \
EEPROM_EESIZE_WORDCNT_S) * 4)

Function Documentation

uint32_t EEPROMBlockCountGet ( void  )

Determines the number of blocks in the EEPROM.

This function may be called to determine the number of blocks in the EEPROM. Each block is the same size and the number of bytes of storage contained in a block may be determined by dividing the size of the device, obtained via a call to the EEPROMSizeGet() function, by the number of blocks returned by this function.

Returns
Returns the total number of blocks in the device EEPROM.
void EEPROMBlockHide ( uint32_t  ui32Block)

Hides an EEPROM block until the next reset.

Parameters
ui32Blockis the EEPROM block number which is to be hidden.

This function hides an EEPROM block other than block 0. Once hidden, a block is completely inaccessible until the next reset. This mechanism allows initialization code to have access to data which is to be hidden from the rest of the application. Unlike applications using passwords, an application making using of block hiding need not contain any embedded passwords which could be found through disassembly.

Returns
None.
uint32_t EEPROMBlockLock ( uint32_t  ui32Block)

Locks a password-protected EEPROM block.

Parameters
ui32Blockis the EEPROM block number which is to be locked.

This function locks an EEPROM block that has previously been protected by writing a password. Access to the block once it is locked is determined by the protection settings applied via a previous call to the EEPROMBlockProtectSet() function. If no password has previously been set for the block, this function has no effect.

Locking block 0 has the effect of making all other blocks in the EEPROM inaccessible.

Returns
Returns the lock state for the block on exit, 1 if unlocked (as would be the case if no password was set) or 0 if locked.
uint32_t EEPROMBlockPasswordSet ( uint32_t  ui32Block,
uint32_t *  pui32Password,
uint32_t  ui32Count 
)

Sets the password used to protect an EEPROM block.

Parameters
ui32Blockis the EEPROM block number for which the password is to be set.
pui32Passwordpoints to an array of uint32_t values comprising the password to set. Each element may be any 32-bit value other than 0xFFFFFFFF. This array must contain the number of elements given by the ui32Count parameter.
ui32Countprovides the number of uint32_ts in the ui32Password. Valid values are 1, 2 and 3.

This function allows the password used to unlock an EEPROM block to be set. Valid passwords may be either 32, 64 or 96 bits comprising words with any value other than 0xFFFFFFFF. The password may only be set once. Any further attempts to set the password result in an error. Once the password is set, the block remains unlocked until EEPROMBlockLock() is called for that block or block 0, or a reset occurs.

If a password is set on block 0, this affects locking of the peripheral as a whole. When block 0 is locked, all other EEPROM blocks are inaccessible until block 0 is unlocked. Once block 0 is unlocked, other blocks become accessible according to any passwords set on those blocks and the protection set for that block via a call to EEPROMBlockProtectSet().

Returns
Returns a logical OR combination of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING to indicate status and error conditions.
uint32_t EEPROMBlockProtectGet ( uint32_t  ui32Block)

Returns the current protection level for an EEPROM block.

Parameters
ui32Blockis the block number for which the protection level is to be queried.

This function returns the current protection settings for a given EEPROM block. If block 0 is currently locked, it must be unlocked prior to calling this function to query the protection setting for other blocks.

Returns
Returns one of EEPROM_PROT_RW_LRO_URW, EEPROM_PROT_NA_LNA_URW or EEPROM_PROT_RO_LNA_URO optionally OR-ed with EEPROM_PROT_SUPERVISOR_ONLY.
uint32_t EEPROMBlockProtectSet ( uint32_t  ui32Block,
uint32_t  ui32Protect 
)

Set the current protection options for an EEPROM block.

Parameters
ui32Blockis the block number for which the protection options are to be set.
ui32Protectconsists of one of the values EEPROM_PROT_RW_LRO_URW, EEPROM_PROT_NA_LNA_URW or EEPROM_PROT_RO_LNA_URO optionally ORed with EEPROM_PROT_SUPERVISOR_ONLY.

This function sets the protection settings for a given EEPROM block assuming no protection settings have previously been written. Note that protection settings applied to block 0 have special meaning and control access to the EEPROM peripheral as a whole. Protection settings applied to blocks numbered 1 and above are layered above any protection set on block 0 such that the effective protection on each block is the logical OR of the protection flags set for block 0 and for the target block. This protocol allows global protection options to be set for the whole device via block 0 and more restrictive protection settings to be set on a block-by-block basis.

The protection flags indicate access permissions as follow:

EEPROM_PROT_SUPERVISOR_ONLY restricts access to the block to threads running in supervisor mode. If clear, both user and supervisor threads can access the block.

EEPROM_PROT_RW_LRO_URW provides read/write access to the block if no password is set or if a password is set and the block is unlocked. If the block is locked, only read access is permitted.

EEPROM_PROT_NA_LNA_URW provides neither read nor write access unless a password is set and the block is unlocked. If the block is unlocked, both read and write access are permitted.

EEPROM_PROT_RO_LNA_URO provides read access to the block if no password is set or if a password is set and the block is unlocked. If the block is password protected and locked, neither read nor write access is permitted.

Returns
Returns a logical OR combination of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING to indicate status and error conditions.
uint32_t EEPROMBlockUnlock ( uint32_t  ui32Block,
uint32_t *  pui32Password,
uint32_t  ui32Count 
)

Unlocks a password-protected EEPROM block.

Parameters
ui32Blockis the EEPROM block number which is to be unlocked.
pui32Passwordpoints to an array of uint32_t values containing the password for the block. Each element must match the password originally set via a call to EEPROMBlockPasswordSet().
ui32Countprovides the number of elements in the pui32Password array and must match the value originally passed to EEPROMBlockPasswordSet(). Valid values are 1, 2 and 3.

This function unlocks an EEPROM block that has previously been protected by writing a password. Access to the block once it is unlocked is determined by the protection settings applied via a previous call to the EEPROMBlockProtectSet() function.

To successfully unlock an EEPROM block, the password provided must match the password provided on the original call to EEPROMBlockPasswordSet(). If an incorrect password is provided, the block remains locked.

Unlocking block 0 has the effect of making all other blocks in the device accessible according to their own access protection settings. When block 0 is locked, all other EEPROM blocks are inaccessible.

Returns
Returns the lock state for the block on exit, 1 if unlocked or 0 if locked.
uint32_t EEPROMInit ( void  )

Performs any necessary recovery in case of power failures during write.

This function must be called after SysCtlPeripheralEnable() and before the EEPROM is accessed. It is used to check for errors in the EEPROM state such as from power fail during a previous write operation. The function detects these errors and performs as much recovery as possible before returning information to the caller on whether or not a previous data write was lost and must be retried.

In cases where EEPROM_INIT_RETRY is returned, the application is responsible for determining which data write may have been lost and rewriting this data. If EEPROM_INIT_ERROR is returned, the EEPROM was unable to recover its state. This condition may or may not be resolved on future resets depending upon the cause of the fault. For example, if the supply voltage is unstable, retrying the operation once the voltage is stabilized may clear the error.

Failure to call this function after a reset may lead to incorrect operation or permanent data loss if the EEPROM is later written.

Returns
Returns EEPROM_INIT_OK if no errors were detected, EEPROM_INIT_RETRY if a previous write operation may have been interrupted by a power or reset event or EEPROM_INIT_ERROR if the EEPROM peripheral cannot currently recover from an interrupted write or erase operation.
void EEPROMIntClear ( uint32_t  ui32IntFlags)

Clears the EEPROM interrupt.

Parameters
ui32IntFlagsindicates which interrupt sources to clear. Currently, the only valid value is EEPROM_INT_PROGRAM.

This function allows an application to clear the EEPROM interrupt.

Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler (as opposed to the very last action) to avoid returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
Returns
None.
void EEPROMIntDisable ( uint32_t  ui32IntFlags)

Disables the EEPROM interrupt.

Parameters
ui32IntFlagsindicates which EEPROM interrupt source to disable. This must be EEPROM_INT_PROGRAM currently.

This function disables the EEPROM interrupt and prevents calls to the interrupt vector when any EEPROM write or erase operation completes. The EEPROM peripheral shares a single interrupt vector with the flash memory subsystem, INT_FLASH. This function is provided as a convenience but the EEPROM interrupt can also be disabled using a call to FlashIntDisable() passing FLASH_INT_EEPROM in the ui32IntFlags parameter.

Returns
None.
void EEPROMIntEnable ( uint32_t  ui32IntFlags)

Enables the EEPROM interrupt.

Parameters
ui32IntFlagsindicates which EEPROM interrupt source to enable. This must be EEPROM_INT_PROGRAM currently.

This function enables the EEPROM interrupt. When enabled, an interrupt is generated when any EEPROM write or erase operation completes. The EEPROM peripheral shares a single interrupt vector with the flash memory subsystem, INT_FLASH. This function is provided as a convenience but the EEPROM interrupt can also be enabled using a call to FlashIntEnable() passing FLASH_INT_EEPROM in the ui32IntFlags parameter.

Returns
None.
uint32_t EEPROMIntStatus ( bool  bMasked)

Reports the state of the EEPROM interrupt.

Parameters
bMaskeddetermines whether the masked or unmasked state of the interrupt is to be returned. If bMasked is true, the masked state is returned, otherwise the unmasked state is returned.

This function allows an application to query the state of the EEPROM interrupt. If active, the interrupt may be cleared by calling EEPROMIntClear().

Returns
Returns EEPROM_INT_PROGRAM if an interrupt is being signaled or 0 otherwise.
uint32_t EEPROMMassErase ( void  )

Erases the EEPROM and returns it to the factory default condition.

This function completely erases the EEPROM and removes any and all access protection on its blocks, leaving the device in the factory default condition. After this operation, all EEPROM words contain the value 0xFFFFFFFF and all blocks are accessible for both read and write operations in all CPU modes. No passwords are active.

The function is synchronous and does not return until the erase operation has completed.

Returns
Returns 0 on success or non-zero values on failure. Failure codes are logical OR combinations of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING.
uint32_t EEPROMProgram ( uint32_t *  pui32Data,
uint32_t  ui32Address,
uint32_t  ui32Count 
)

Writes data to the EEPROM.

Parameters
pui32Datapoints to the first word of data to write to the EEPROM.
ui32Addressdefines the byte address within the EEPROM that the data is to be written to. This value must be a multiple of 4.
ui32Countdefines the number of bytes of data that is to be written. This value must be a multiple of 4.

This function may be called to write data into the EEPROM at a given word-aligned address. The call is synchronous and returns only after all data has been written or an error occurs.

Returns
Returns 0 on success or non-zero values on failure. Failure codes are logical OR combinations of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING.
uint32_t EEPROMProgramNonBlocking ( uint32_t  ui32Data,
uint32_t  ui32Address 
)

Writes a word to the EEPROM.

Parameters
ui32Datais the word to write to the EEPROM.
ui32Addressdefines the byte address within the EEPROM to which the data is to be written. This value must be a multiple of 4.

This function is intended to allow EEPROM programming under interrupt control. It may be called to start the process of writing a single word of data into the EEPROM at a given word-aligned address. The call is asynchronous and returns immediately without waiting for the write to complete. Completion of the operation is signaled by means of an interrupt from the EEPROM module. The EEPROM peripheral shares a single interrupt vector with the flash memory subsystem, INT_FLASH.

Returns
Returns status and error information in the form of a logical OR combinations of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE and EEPROM_RC_WORKING. Flags EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING are expected in normal operation and do not indicate an error.
void EEPROMRead ( uint32_t *  pui32Data,
uint32_t  ui32Address,
uint32_t  ui32Count 
)

Reads data from the EEPROM.

Parameters
pui32Datais a pointer to storage for the data read from the EEPROM. This pointer must point to at least ui32Count bytes of available memory.
ui32Addressis the byte address within the EEPROM from which data is to be read. This value must be a multiple of 4.
ui32Countis the number of bytes of data to read from the EEPROM. This value must be a multiple of 4.

This function may be called to read a number of words of data from a word-aligned address within the EEPROM. Data read is copied into the buffer pointed to by the pui32Data parameter.

Returns
None.
uint32_t EEPROMSizeGet ( void  )

Determines the size of the EEPROM.

This function returns the size of the EEPROM in bytes.

Returns
Returns the total number of bytes in the EEPROM.
uint32_t EEPROMStatusGet ( void  )

Returns status on the last EEPROM program or erase operation.

This function returns the current status of the last program or erase operation performed by the EEPROM. It is intended to provide error information to applications programming or setting EEPROM protection options under interrupt control.

Returns
Returns 0 if the last program or erase operation completed without any errors. If an operation is ongoing or an error occurred, the return value is a logical OR combination of EEPROM_RC_INVPL, EEPROM_RC_WRBUSY, EEPROM_RC_NOPERM, EEPROM_RC_WKCOPY, EEPROM_RC_WKERASE, and EEPROM_RC_WORKING.