1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/periph_eeprom: add clear and erase functions

This commit is contained in:
Alexandre Abadie 2018-09-27 13:22:49 +02:00
parent 90db0bf253
commit 50f19d1d1f
2 changed files with 34 additions and 0 deletions

View File

@ -79,6 +79,25 @@ void eeprom_write_byte(uint32_t pos, uint8_t data);
*/
size_t eeprom_write(uint32_t pos, const uint8_t *data, size_t len);
/**
* @brief Clear @p len bytes from the given position @p pos
*
* Clearing a byte in EEPROM simply consists in setting it to 0
*
* @param[in] pos start position in eeprom
* @param[in] len the number of bytes to clear
*
* @return the number of bytes cleared
*/
size_t eeprom_clear(uint32_t pos, size_t len);
/**
* @brief Erase the whole EEPROM content
*
* @return the EEPROM_SIZE
*/
size_t eeprom_erase(void);
#ifdef __cplusplus
}
#endif

View File

@ -40,4 +40,19 @@ void eeprom_write_byte(uint32_t pos, uint8_t byte)
eeprom_write(pos, &byte, 1);
}
size_t eeprom_clear(uint32_t pos, size_t len)
{
assert(pos + len <= EEPROM_SIZE);
for (size_t i = 0; i < len; i++) {
eeprom_write_byte(pos++, 0);
}
return len;
}
size_t eeprom_erase(void)
{
return eeprom_clear(0, EEPROM_SIZE);
}
#endif