Overview
MSPM0 support EEPROM emulation through its internal Flash. Compared to using an external serial EEPROM, EEPROM emulation using the internal Flash saves pin usage and cost. The EEPROM emulation Type A solution is suitable if the user application needs to store large "blocks" of data.
§ EEPROM_TypeA_writeData()
| uint32_t EEPROM_TypeA_writeData |
( |
uint32_t * |
data | ) |
|
Store provided data to the virtual EEPROM.
The function will store the data to the flash to be a new record. It will also add a header to the record to mark its state. When the flash sector is full, it will set the gEEPROMTypeAEraseFlag.
- Parameters
-
| [in] | data | Pointer to the buffer in RAM |
- Returns
- Whether or not the program succeeded
- Return values
-
| EEPROM_EMULATION_WRITE_OK | Program was successful |
| EEPROM_EMULATION_FORMAT_ERROR | Next address was not erased |
- Precondition
- The user must ensure that the length of the buffer in RAM is equal to the length of the data portion of the record.
- Postcondition
- When the sector is full, the function only set the gEEPROMTypeAEraseFlag. The user should erase the sector before all sectors are full. Refer to EEPROM_TypeA_eraseLastSector.
§ EEPROM_TypeA_init()
| uint32_t EEPROM_TypeA_init |
( |
uint32_t * |
data | ) |
|
Initialize the specified area in flash.
The function will first search the active record and check the format at the specified area. If active record exists, it will copy the data of active record to the buffer in RAM. If format is not correct, it will repair the format.
- Parameters
-
| [in] | data | Pointer to the buffer in RAM |
- Returns
- Whether or not the program succeeded
- Return values
-
| EEPROM_EMULATION_INIT_OK | Program was successful |
| EEPROM_EMULATION_INIT_ERROR | Next address was not erased |
- Precondition
- The user must ensure that the length of the buffer in RAM is equal to the length of the data portion of the record.
- Postcondition
- After EEPROM_TypeA_init, there will be a format-correct area in flash, a buffer in RAM copied the active record, and some global variables that have been written.
4 global variables about active record: gActiveRecordAddress gNextRecordAddress gActiveRecordNum gActiveSectorNum 3 global variables about format: gEEPROMTypeASearchFlag gEEPROMTypeAEraseFlag gEEPROMTypeAFormatErrorFlag
§ EEPROM_TypeA_readData()
| void EEPROM_TypeA_readData |
( |
uint32_t * |
data | ) |
|
Read the data from active record to the buffer in RAM.
- Parameters
-
| [in] | data | Pointer to the buffer in RAM |
- Precondition
- The user must ensure that the length of the buffer in RAM is equal to the length of the data portion of the record.
§ EEPROM_TypeA_repairFormat()
| bool EEPROM_TypeA_repairFormat |
( |
uint32_t * |
data | ) |
|
Repair the format.
The function will first erase sectors other than the active sector. Then it will copy the data from the buffer in RAM to the beginning of next sector, which is to be new active record. 4 global variables about active record are updated too. Finally, the function erase the last sector
- Parameters
-
| [in] | data | Pointer to the buffer in RAM |
- Returns
- Whether or not the program succeeded
- Return values
-
| false | Program didn't succeed |
| true | Program was successful |
- Precondition
- The user must firstly prepare the data in RAM before call the function. The user must ensure that the length of the buffer in RAM is equal to the length of the data portion of the record.
- Postcondition
- After EEPROM_TypeA_repairFormat, all sectors are erased and the active record is at the beginning of next sector
NOTE: The user must firstly prepare the data in RAM before call the function. It is recommended to read active record into RAM first, then call the function to repair the format and write active record back.
§ EEPROM_TypeA_searchCheck()
| void EEPROM_TypeA_searchCheck |
( |
void |
| ) |
|
Search the active record and check the format.
The function will traverse records� header. If the active record exists, gEEPROMTypeASearchFlag will be set, and 4 global variables about active record are updated. If the format is wrong, gEEPROMTypeAFormatErrorFlag is set
- Postcondition
- If the active record exists, gEEPROMTypeASearchFlag will be set, and 4 global variables about active record are updated. If the format is wrong, gEEPROMTypeAFormatErrorFlag is set
§ EEPROM_TypeA_eraseLastSector()
| bool EEPROM_TypeA_eraseLastSector |
( |
void |
| ) |
|
Erase the previous sector of the active sector.
- Returns
- Whether or not the program succeeded
- Return values
-
| false | Program didn't succeed |
| true | Program was successful |
According to gActiveSectorNum, the function can find the sector with active record. Then it will erase the previous sector
§ EEPROM_TypeA_eraseNonActiveSectors()
| bool EEPROM_TypeA_eraseNonActiveSectors |
( |
void |
| ) |
|
Erases sectors other than the active sector.
- Returns
- Whether or not the program succeeded
- Return values
-
| false | Program didn't succeed |
| true | Program was successful |
According to gActiveSectorNum, the function can find the sector with active record. Then it will erase sectors other than the active sector
§ EEPROM_TypeA_eraseAllSectors()
| bool EEPROM_TypeA_eraseAllSectors |
( |
void |
| ) |
|
Erase all sectors used by EEPROM emulation.
- Returns
- Whether or not the program succeeded
- Return values
-
| false | Program didn't succeed |
| true | Program was successful |