| 10 | volatile static spin_lock_t *flashLock = nullptr; |
| 11 | |
| 12 | int64_t writeToFlash(alarm_id_t id, void *flashCache) |
| 13 | { |
| 14 | while (is_spin_locked(flashLock)); |
| 15 | |
| 16 | multicore_lockout_start_blocking(); |
| 17 | uint32_t interrupts = spin_lock_blocking(flashLock); |
| 18 | |
| 19 | flash_range_erase((intptr_t)EEPROM_ADDRESS_START - (intptr_t)XIP_BASE, EEPROM_SIZE_BYTES); |
| 20 | flash_range_program((intptr_t)EEPROM_ADDRESS_START - (intptr_t)XIP_BASE, reinterpret_cast<uint8_t *>(flashCache), EEPROM_SIZE_BYTES); |
| 21 | |
| 22 | flashWriteAlarm = 0; |
| 23 | |
| 24 | multicore_lockout_end_blocking(); |
| 25 | spin_unlock(flashLock, interrupts); |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | void FlashPROM::start() |
| 31 | { |