void eepromWaitSpiComplete() { while (!Spi_complete) { SIMU_SLEEP(5/*ms*/); } Spi_complete = false; }
void backupEeprom() { char filename[60]; uint8_t buffer[1024]; FIL file; lcd_clear(); displayProgressBar(STR_WRITING); // reset unexpectedShutdown to prevent warning when user restores EEPROM backup g_eeGeneral.unexpectedShutdown = 0; eeDirty(EE_GENERAL); eeCheck(true); // create the directory if needed... DIR folder; FRESULT result = f_opendir(&folder, EEPROMS_PATH); if (result != FR_OK) { if (result == FR_NO_PATH) result = f_mkdir(EEPROMS_PATH); if (result != FR_OK) { POPUP_WARNING(SDCARD_ERROR(result)); return; } } // prepare the filename... char * tmp = strAppend(filename, EEPROMS_PATH "/eeprom"); tmp = strAppendDate(tmp, true); strAppend(tmp, EEPROM_EXT); // open the file for writing... f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS); for (int i=0; i<EESIZE; i+=1024) { UINT count; eepromReadBlock(buffer, i, 1024); f_write(&file, buffer, 1024, &count); updateProgressBar(i, EESIZE); SIMU_SLEEP(100/*ms*/); } f_close(&file); //set back unexpectedShutdown g_eeGeneral.unexpectedShutdown = 1; eeDirty(EE_GENERAL); eeCheck(true); }
void flashBootloader(const char * filename) { FIL file; f_open(&file, filename, FA_READ); uint8_t buffer[1024]; UINT count; lcd_clear(); displayProgressBar(STR_WRITING); static uint8_t unlocked = 0; if (!unlocked) { unlocked = 1; unlockFlash(); } for (int i=0; i<BOOTLOADER_SIZE; i+=1024) { watchdogSetTimeout(100/*1s*/); if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) { POPUP_WARNING(STR_SDCARD_ERROR); break; } if (i==0 && !isBootloaderStart((uint32_t *)buffer)) { POPUP_WARNING(STR_INCOMPATIBLE); break; } for (int j=0; j<1024; j+=FLASH_PAGESIZE) { writeFlash(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j)); } updateProgressBar(i, BOOTLOADER_SIZE); SIMU_SLEEP(30/*ms*/); } if (unlocked) { lockFlash(); unlocked = 0; } f_close(&file); }
void eepromWaitReadStatus() { while ((eepromReadStatus() & 1) != 0) { SIMU_SLEEP(5/*ms*/); } }