Created
July 1, 2016 09:54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Storageを読み込む。もしCRCが不一致なら初期化 | |
// | |
bool readStorageAndInitIfNeeded() { | |
bool ok = system_rtc_mem_read(kOffset_CRC, &storage, sizeof(storage)); | |
if (!ok) { | |
Serial.println("readStorageAndInitIfNeeded : mem_read fail"); | |
return ok; | |
} | |
int crc = calcCRC(); | |
Serial.print("crc = "); | |
Serial.print(crc, HEX); | |
Serial.print(", stored crc = "); | |
Serial.println(storage.crc, HEX); | |
if (crc != storage.crc) { | |
Serial.println("crc mismatch"); | |
memset(storage.uni.buffer, 0, sizeof(storage.uni.buffer)); | |
storage.uni.datas.counter = 0; | |
storage.uni.datas.nextAdjust = 0; | |
crc = calcCRC(); | |
Serial.print("new crc = "); | |
Serial.println(crc, HEX); | |
storage.crc = crc; | |
ok = system_rtc_mem_write(kOffset_CRC, &storage, sizeof(storage)); | |
if (!ok) { | |
Serial.println("readStorageAndInitIfNeeded : write fail"); | |
} | |
} | |
Serial.print("read counter = "); | |
Serial.println(storage.uni.datas.counter); | |
return ok; | |
} | |
bool writeStorage() { | |
storage.crc = calcCRC(); | |
bool ok = system_rtc_mem_write(kOffset_CRC, &storage, sizeof(storage)); | |
if (!ok) { | |
Serial.println("Error : writeStorage : system_rtc_mem_write fail"); | |
} | |
return ok; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment