mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Update EEPROM.cpp (#6599)
use InterruptLock class for scoped interrupts instead of blindly disabling/enabling interrupts, which doesn't support nesting nor restore previous state. Add forgotten include Remove locks, simplify code Fix typo Drop needless include
This commit is contained in:
parent
08a0414ee0
commit
a00a4744d0
@ -71,11 +71,8 @@ void EEPROMClass::begin(size_t size) {
|
|||||||
|
|
||||||
_size = size;
|
_size = size;
|
||||||
|
|
||||||
noInterrupts();
|
if (!ESP.flashRead(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
|
||||||
auto ret = spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
|
DEBUGV("EEPROMClass::begin flash read failed\n");
|
||||||
interrupts();
|
|
||||||
if (ret != SPI_FLASH_RESULT_OK) {
|
|
||||||
DEBUGV("EEPROMClass::begin spi_flash_read failed, %d\n", (int)ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
|
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
|
||||||
@ -128,7 +125,6 @@ void EEPROMClass::write(int const address, uint8_t const value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool EEPROMClass::commit() {
|
bool EEPROMClass::commit() {
|
||||||
bool ret = false;
|
|
||||||
if (!_size)
|
if (!_size)
|
||||||
return false;
|
return false;
|
||||||
if(!_dirty)
|
if(!_dirty)
|
||||||
@ -136,22 +132,15 @@ bool EEPROMClass::commit() {
|
|||||||
if(!_data)
|
if(!_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
noInterrupts();
|
if (ESP.flashEraseSector(_sector)) {
|
||||||
auto flashret = spi_flash_erase_sector(_sector);
|
if (ESP.flashWrite(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
|
||||||
if (flashret == SPI_FLASH_RESULT_OK) {
|
|
||||||
flashret = spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
|
|
||||||
if (flashret == SPI_FLASH_RESULT_OK) {
|
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
ret = true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interrupts();
|
|
||||||
|
|
||||||
if (flashret != SPI_FLASH_RESULT_OK) {
|
|
||||||
DEBUGV("EEPROMClass::commit failed, %d\n", (int)flashret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
DEBUGV("EEPROMClass::commit failed\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * EEPROMClass::getDataPtr() {
|
uint8_t * EEPROMClass::getDataPtr() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user