int Spark_Prepare_For_Firmware_Update(FileTransfer::Descriptor& file, uint32_t flags, void* reserved) { if (file.store==FileTransfer::Store::FIRMWARE) { // address is relative to the OTA region. Normally will be 0. file.file_address = HAL_OTA_FlashAddress() + file.chunk_address; // chunk_size 0 indicates defaults. if (file.chunk_size==0) { file.chunk_size = HAL_OTA_ChunkSize(); file.file_length = HAL_OTA_FlashLength(); } } int result = 0; if (flags & 1) { // only check address } else { RGB.control(true); RGB.color(RGB_COLOR_MAGENTA); SPARK_FLASH_UPDATE = 1; TimingFlashUpdateTimeout = 0; system_notify_event(firmware_update, firmware_update_begin, &file); HAL_FLASH_Begin(file.file_address, file.file_length, NULL); } return result; }
int Spark_Prepare_For_Firmware_Update(FileTransfer::Descriptor& file, uint32_t flags, void* reserved) { if (file.store==FileTransfer::Store::FIRMWARE) { // address is relative to the OTA region. Normally will be 0. file.file_address = HAL_OTA_FlashAddress() + file.chunk_address; // chunk_size 0 indicates defaults. if (file.chunk_size==0) { file.chunk_size = HAL_OTA_ChunkSize(); file.file_length = HAL_OTA_FlashLength(); } } int result = 0; if (flags & 1) { // only check address } else { uint32_t start = HAL_Timer_Milliseconds(); system_set_flag(SYSTEM_FLAG_OTA_UPDATE_PENDING, 1, nullptr); volatile bool flag = false; system_notify_event(firmware_update_pending, 0, nullptr, set_flag, (void*)&flag); System.waitCondition([&flag]{return flag;}, timeRemaining(start, 30000)); system_set_flag(SYSTEM_FLAG_OTA_UPDATE_PENDING, 0, nullptr); if (System.updatesEnabled()) // application event is handled asynchronously { RGB.control(true); RGB.color(RGB_COLOR_MAGENTA); SPARK_FLASH_UPDATE = 1; TimingFlashUpdateTimeout = 0; system_notify_event(firmware_update, firmware_update_begin, &file); HAL_FLASH_Begin(file.file_address, file.file_length, NULL); } else { result = 1; // updates disabled } } return result; }