static void FirmwareIAPCallback(UAVObjEvent* ev) { static uint32_t last_time = 0; uint32_t this_time; uint32_t delta; if(iap_state == IAP_STATE_RESETTING) return; if ( ev->obj == FirmwareIAPObjHandle() ) { // Get the input object data FirmwareIAPObjGet(&data); this_time = get_time(); delta = this_time - last_time; last_time = this_time; if((data.BoardType==BOARD_TYPE)&&(data.crc != iap_calc_crc())) { read_description(data.Description); data.BoardRevision=BOARD_REVISION; data.crc = iap_calc_crc(); FirmwareIAPObjSet( &data ); } if((data.ArmReset==1)&&(iap_state!=IAP_STATE_RESETTING)) { data.ArmReset=0; FirmwareIAPObjSet( &data ); } switch(iap_state) { case IAP_STATE_READY: if( data.Command == IAP_CMD_STEP_1 ) { iap_state = IAP_STATE_STEP_1; } break; case IAP_STATE_STEP_1: if( data.Command == IAP_CMD_STEP_2 ) { if( delta > iap_time_2_low_end && delta < iap_time_2_high_end ) { iap_state = IAP_STATE_STEP_2; } else { iap_state = IAP_STATE_READY; } } else { iap_state = IAP_STATE_READY; } break; case IAP_STATE_STEP_2: if( data.Command == IAP_CMD_STEP_3 ) { if( delta > iap_time_3_low_end && delta < iap_time_3_high_end ) { // we've met the three sequence of command numbers // we've met the time requirements. PIOS_IAP_SetRequest1(); PIOS_IAP_SetRequest2(); /* Note: Cant just wait timeout value, because first time is randomized */ reset_count = 0; lastResetSysTime = xTaskGetTickCount(); UAVObjEvent * ev = pvPortMalloc(sizeof(UAVObjEvent)); memset(ev,0,sizeof(UAVObjEvent)); EventPeriodicCallbackCreate(ev, resetTask, 100); iap_state = IAP_STATE_RESETTING; } else { iap_state = IAP_STATE_READY; } } else { iap_state = IAP_STATE_READY; } break; case IAP_STATE_RESETTING: // stay here permanentally, should reboot break; default: iap_state = IAP_STATE_READY; break; } } }
static void FirmwareIAPCallback(UAVObjEvent* ev) { const struct pios_board_info * bdinfo = &pios_board_info_blob; static uint32_t last_time = 0; uint32_t this_time; uint32_t delta; if(iap_state == IAP_STATE_RESETTING) return; if ( ev->obj == FirmwareIAPObjHandle() ) { // Get the input object data FirmwareIAPObjGet(&data); this_time = get_time(); delta = this_time - last_time; last_time = this_time; if((data.BoardType==bdinfo->board_type)&&(data.crc != PIOS_BL_HELPER_CRC_Memory_Calc())) { PIOS_BL_HELPER_FLASH_Read_Description(data.Description,FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM); PIOS_SYS_SerialNumberGetBinary(data.CPUSerial); data.BoardRevision=bdinfo->board_rev; data.crc = PIOS_BL_HELPER_CRC_Memory_Calc(); FirmwareIAPObjSet( &data ); } if((data.ArmReset==1)&&(iap_state!=IAP_STATE_RESETTING)) { data.ArmReset=0; FirmwareIAPObjSet( &data ); } switch(iap_state) { case IAP_STATE_READY: if( data.Command == IAP_CMD_STEP_1 ) { iap_state = IAP_STATE_STEP_1; } break; case IAP_STATE_STEP_1: if( data.Command == IAP_CMD_STEP_2 ) { if( delta > iap_time_2_low_end && delta < iap_time_2_high_end ) { iap_state = IAP_STATE_STEP_2; } else { iap_state = IAP_STATE_READY; } } else { iap_state = IAP_STATE_READY; } break; case IAP_STATE_STEP_2: if( data.Command == IAP_CMD_STEP_3 ) { if( delta > iap_time_3_low_end && delta < iap_time_3_high_end ) { FlightStatusData flightStatus; FlightStatusGet(&flightStatus); if(flightStatus.Armed != FLIGHTSTATUS_ARMED_DISARMED) { // Abort any attempts if not disarmed iap_state = IAP_STATE_READY; break; } // we've met the three sequence of command numbers // we've met the time requirements. PIOS_IAP_SetRequest1(); PIOS_IAP_SetRequest2(); /* Note: Cant just wait timeout value, because first time is randomized */ reset_count = 0; lastResetSysTime = xTaskGetTickCount(); UAVObjEvent * ev = pvPortMalloc(sizeof(UAVObjEvent)); memset(ev,0,sizeof(UAVObjEvent)); EventPeriodicCallbackCreate(ev, resetTask, 100); iap_state = IAP_STATE_RESETTING; } else { iap_state = IAP_STATE_READY; } } else { iap_state = IAP_STATE_READY; } break; case IAP_STATE_RESETTING: // stay here permanentally, should reboot break; default: iap_state = IAP_STATE_READY; last_time = 0; // Reset the time counter, as we are not doing a IAP reset break; } } }