static void initSettings(uint32_t aBase, uint32_t aFlag) { uint32_t address = aBase; uint32_t settingsSize = SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2; while (address < (aBase + settingsSize)) { utilsFlashErasePage(address); utilsFlashStatusWait(1000); address += SETTINGS_CONFIG_PAGE_SIZE; } setSettingsFlag(aBase, aFlag); }
otError utilsFlashInit(void) { otError error = OT_ERROR_NONE; char fileName[20]; struct stat st; bool create = false; memset(&st, 0, sizeof(st)); if (stat("tmp", &st) == -1) { mkdir("tmp", 0777); } snprintf(fileName, sizeof(fileName), "tmp/node.flash"); if (access(fileName, 0)) { create = true; } sFlashFd = open(fileName, O_RDWR | O_CREAT, 0666); lseek(sFlashFd, 0, SEEK_SET); otEXPECT_ACTION(sFlashFd >= 0, error = OT_ERROR_FAILED); if (create) { for (uint16_t index = 0; index < FLASH_PAGE_NUM; index++) { error = utilsFlashErasePage(index * FLASH_PAGE_SIZE); otEXPECT(error == OT_ERROR_NONE); } } exit: return error; }