diff options
Diffstat (limited to 'Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c')
| -rw-r--r-- | Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c | 208 |
1 files changed, 124 insertions, 84 deletions
diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c index 0c007f755..d5e125337 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c @@ -83,6 +83,7 @@ uint32_t InitSequenceMachineReadyToDye(void); uint32_t InitSequenceStateMachine( INIT_SEQUENCE_STAGES_ENUM ReadValue); uint32_t PowerUpUpdate(MACHINE_STATE_STAGES_ENUM stage); int InitFailures = 0; +extern uint32_t PressureSensorV0[2]; MACHINE_STATE_STAGES_ENUM GetMachineState(void) { @@ -90,8 +91,11 @@ MACHINE_STATE_STAGES_ENUM GetMachineState(void) } void SetMachineState(MACHINE_STATE_STAGES_ENUM NewState) { - MachineStateDetail = NewState; - PowerUpUpdate(NewState); + if (MachineStateDetail != NewState) + { + MachineStateDetail = NewState; + PowerUpUpdate(NewState); + } } void StopInitSequence(void) { @@ -145,7 +149,7 @@ uint32_t InitScheduler(uint32_t IfIndex, uint32_t BusyFlag) StoredInitStages = InitStages; InitSequenceStateMachine(InitStages); } - PowerUpUpdate(MachineStateDetail); + //PowerUpUpdate(MachineStateDetail); return OK; } /*******************************************************************************************************/ @@ -230,12 +234,13 @@ uint32_t InitSequenceMidTankCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag } uint32_t InitSequenceBlowerCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { - double V0[2] = {0.0, 0.0}; if (SafeRemoveControlCallback(HWControlId, InitSequenceBlowerCallBackFunction )==OK) HWControlId = 0xFF; else Report("Remove control callback failed",__FILE__,__LINE__,(int)HWControlId,RpWarning,(int)InitSequenceBlowerCallBackFunction,0); + + Turn_the_Blower_On();//Turn on with the Default_Voltage if (BlowerCfg.heatingvoltage) Control_Voltage_To_Blower(BlowerCfg.heatingvoltage); @@ -244,35 +249,10 @@ uint32_t InitSequenceBlowerCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) WHS_enable_control_loop(true); WHS_Set_SetPoint_Q_value(headairflow); - AlarmHandlingSetAlarm (EVENT_TYPE__MACHINE_STATE_INITIAL_BLOWER_FAILED,OFF); //handle alarm detection and operation + //AlarmHandlingSetAlarm (EVENT_TYPE__MACHINE_STATE_INITIAL_BLOWER_FAILED,OFF); //handle alarm detection and operation waste_seq_step1();// include 1Sec delay <- to open !!!! - if (Head_Type == HEAD_TYPE_ARC) { - if (ResetReason & SYSCTL_CAUSE_POR) { - V0[0] = PressureSensorInit(0); - V0[1] = PressureSensorInit(1); - ReportWithPackageFilter(InitFilter,"read pressure sensor v0[0],v0[1]", __FILE__,__LINE__, (int)V0[0], RpMessage, (int)V0[1], 0); - if (V0[0] > 1000) { - MCU_E2PromProgram(EEPROM_ORIFICE1_ZERO_VALUE, V0[0]); - ReportWithPackageFilter(InitFilter,"store pressure sensor v0[0]", __FILE__,__LINE__, (int)V0[0], RpMessage, 0, 0); - } else { - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE, &V0[0]); - ReportWithPackageFilter(InitFilter,"load from EEPROM", __FILE__,__LINE__, (int)V0[0], RpMessage, 0, 0); - } - if (V0[1] > 1000) { - MCU_E2PromProgram(EEPROM_ORIFICE1_ZERO_VALUE, V0[1]); - ReportWithPackageFilter(InitFilter,"store pressure sensor v0[1]", __FILE__,__LINE__, (int)V0[1], RpMessage, 0, 0); - } else { - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE, &V0[1]); - ReportWithPackageFilter(InitFilter,"load from EEPROM", __FILE__,__LINE__, (int)V0[1], RpMessage, 0, 0); - } - } else { - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE, &V0[0]); - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE, &V0[1]); - ReportWithPackageFilter(InitFilter,"load initial values from EEPROM", __FILE__,__LINE__, (int)V0[0], RpMessage, (int)V0[1], 0); - } - } Safety_Init(); InitStages++; @@ -433,70 +413,109 @@ uint32_t InitSequencePowerManagementInit(void) // InitStages++; return OK; } -uint32_t InitSequenceInitialBlowerActivation(void) +uint32_t InitSequenceWHSAirFlowCalibration(void) { - SetMachineState(MACHINE_STATE_INITIAL_BLOWER_ACTIVATION); int i,total1=0,total2=0,total3=0; uint32_t ZeroValue; uint16_t value = 0; - //WHS_Start_Blower_Control_Closed_Loop(0.0); - WHS_enable_control_loop(false); - if (WHS_Type == WHS_TYPE_NEW) + + if (ResetReason & SYSCTL_CAUSE_POR) { - if (ResetReason & SYSCTL_CAUSE_POR) + for (i=0;i<8;i++) { - Control_Voltage_To_Blower(1); //stop the blower - Task_sleep (1000); - for (i=0;i<8;i++) - { - Trigger_WHS_MAX11614_Read_allADC(); - Task_sleep (100); - get_orf_1(&value); - total1+=value; - get_orf_2(&value); - total2+=value; - get_orf_3(&value); - total3+=value; - ReportWithPackageFilter(InitFilter,"load initial orifice value", __FILE__,total1,total2, RpMessage, total3, 0); - Task_sleep(100); - } - total1/=8; - total2/=8; - total3/=8; - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE,&ZeroValue); - if ((total1>800)&&(total1<2000)) - { - MCU_E2PromProgram(EEPROM_ORIFICE1_ZERO_VALUE,total1); - } - else - total1 = ZeroValue; - ReportWithPackageFilter(InitFilter,"store initial orifice 1 value", __FILE__,EEPROM_ORIFICE1_ZERO_VALUE,total1, RpMessage, ZeroValue, 0); - MCU_E2PromRead(EEPROM_ORIFICE3_ZERO_VALUE,&ZeroValue); - if ((total3>1000)&&(total3<1500)) - { - MCU_E2PromProgram(EEPROM_ORIFICE3_ZERO_VALUE,total3); - } - else - total3 = ZeroValue; - ReportWithPackageFilter(InitFilter,"store initial orifice 3 value", __FILE__,EEPROM_ORIFICE3_ZERO_VALUE,total3, RpMessage, ZeroValue, 0); - WHS_MAX11614_Load_OrificeZeroValue(total1,total2,total3); + Trigger_WHS_MAX11614_Read_allADC(); + Task_sleep (100); + get_orf_1(&value); + total1+=value; + get_orf_2(&value); + total2+=value; + get_orf_3(&value); + total3+=value; + ReportWithPackageFilter(InitFilter,"load initial orifice value", __FILE__,total1,total2, RpMessage, total3, 0); + Task_sleep(100); + } + total1/=8; + total2/=8; + total3/=8; + MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE,&ZeroValue); + if ((total1>800)&&(total1<2000)) + { + MCU_E2PromProgram(EEPROM_ORIFICE1_ZERO_VALUE,total1); } else + total1 = ZeroValue; + ReportWithPackageFilter(InitFilter,"store initial orifice 1 value", __FILE__,EEPROM_ORIFICE1_ZERO_VALUE,total1, RpMessage, ZeroValue, 0); + MCU_E2PromRead(EEPROM_ORIFICE3_ZERO_VALUE,&ZeroValue); + if ((total3>1000)&&(total3<1500)) { - MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE,&total1); - MCU_E2PromRead(EEPROM_ORIFICE3_ZERO_VALUE,&total3); - ReportWithPackageFilter(InitFilter,"load initial values from EEPROM", __FILE__,0,total3, RpMessage, total1, 0); - WHS_MAX11614_Load_OrificeZeroValue(total1,total1,total3); + MCU_E2PromProgram(EEPROM_ORIFICE3_ZERO_VALUE,total3); } + else + total3 = ZeroValue; + ReportWithPackageFilter(InitFilter,"store initial orifice 3 value", __FILE__,EEPROM_ORIFICE3_ZERO_VALUE,total3, RpMessage, ZeroValue, 0); + WHS_MAX11614_Load_OrificeZeroValue(total1,total2,total3); + } + else + { + MCU_E2PromRead(EEPROM_ORIFICE1_ZERO_VALUE,&total1); + MCU_E2PromRead(EEPROM_ORIFICE3_ZERO_VALUE,&total3); + ReportWithPackageFilter(InitFilter,"load initial values from EEPROM", __FILE__,0,total3, RpMessage, total1, 0); + WHS_MAX11614_Load_OrificeZeroValue(total1,total1,total3); } + return OK; + +} +uint32_t InitSequenceArcAirflowCalibration(void) +{ + uint32_t V0[2] = {0, 0}; + if (ResetReason & SYSCTL_CAUSE_POR) { + V0[0] = PressureSensorInit(0); + V0[1] = PressureSensorInit(1); + ReportWithPackageFilter(InitFilter,"read pressure sensor v0[0],v0[1]", __FILE__,__LINE__, (int)V0[0], RpMessage, (int)V0[1], 0); + if (V0[0] > 1000) { + MCU_E2PromProgram(EEPROM_PRESSURE_SENSOR_V0_0, V0[0]); + ReportWithPackageFilter(InitFilter,"store pressure sensor v0[0]", __FILE__,__LINE__, (int)V0[0], RpMessage, 0, 0); + } else { + MCU_E2PromRead(EEPROM_PRESSURE_SENSOR_V0_0, &V0[0]); + ReportWithPackageFilter(InitFilter,"load from EEPROM", __FILE__,__LINE__, (int)V0[0], RpMessage, 0, 0); + } + if (V0[1] > 1000) { + MCU_E2PromProgram(EEPROM_PRESSURE_SENSOR_V0_1, V0[1]); + ReportWithPackageFilter(InitFilter,"store pressure sensor v0[1]", __FILE__,__LINE__, (int)V0[1], RpMessage, 0, 0); + } else { + MCU_E2PromRead(EEPROM_PRESSURE_SENSOR_V0_1, &V0[1]); + ReportWithPackageFilter(InitFilter,"load from EEPROM", __FILE__,__LINE__, (int)V0[1], RpMessage, 0, 0); + } + } else { + MCU_E2PromRead(EEPROM_PRESSURE_SENSOR_V0_0, &V0[0]); + MCU_E2PromRead(EEPROM_PRESSURE_SENSOR_V0_1, &V0[1]); + ReportWithPackageFilter(InitFilter,"load initial values from EEPROM", __FILE__,__LINE__, (int)V0[0], RpMessage, (int)V0[1], 0); + } + PressureSensorV0[0] = V0[0]; + PressureSensorV0[1] = V0[1]; + return OK; +} +uint32_t InitSequenceInitialBlowerActivation(void) +{ + WHS_enable_control_loop(false); + Turn_the_Blower_On();//Turn on with the Default_Voltage + Control_Voltage_To_Blower(1); //stop the blower HeadBlowersInit(); + Task_sleep (1000); + + if (WHS_Type == WHS_TYPE_NEW) + { + InitSequenceWHSAirFlowCalibration(); + } + if (Head_Type == HEAD_TYPE_ARC) + { + InitSequenceArcAirflowCalibration(); + } + Voc_Sensor_Zero_Calibration(); + SetMachineState(MACHINE_STATE_INITIAL_BLOWER_ACTIVATION); - Turn_the_Blower_On();//Turn on with the Default_Voltage -// if (BlowerCfg.voltage) -// Control_Voltage_To_Blower(BlowerCfg.voltage); -// else - Control_Voltage_To_Blower(4200); + Control_Voltage_To_Blower(4200); Set_All_WHS_Fans(200); Report("AddControlCallback INIT",__FILE__,__LINE__,(int)HWControlId,RpWarning,(int)InitStages,0); HWControlId = AddControlCallback("Init Blower", InitSequenceBlowerCallBackFunction, 10* eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); @@ -732,6 +751,14 @@ uint32_t InitSequenceStateMachine( INIT_SEQUENCE_STAGES_ENUM ReadValue) return OK; } char PowerUpToken[36+1] = {0}; +//char init_string[100]; +uint32_t PowerUpLoadControlId = 0xFF; +uint32_t PowerUpUpdateCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) +{ + + PowerUpUpdate(MachineStateDetail); + return OK; +} uint32_t PowerUpUpdate(MACHINE_STATE_STAGES_ENUM stage) { uint32_t status = NOT_SUPPORTED; @@ -746,7 +773,7 @@ uint32_t PowerUpUpdate(MACHINE_STATE_STAGES_ENUM stage) if (PowerUpToken[0] == 0) return OK; - Report("PowerUpUpdate",__FILE__,last,InitStages,RpWarning,(int)stage,0); + //Report("PowerUpUpdate",__FILE__,last,InitStages,RpWarning,(int)stage,0); response.has_state = true; response.has_progresspercentage = true; @@ -858,7 +885,8 @@ uint32_t PowerUpUpdate(MACHINE_STATE_STAGES_ENUM stage) Error = ERROR_CODE__POWER_UP_NO_CFG_FILE; break; } - //Report("PowerUpUpdate",__FILE__,last,(int)response.progresspercentage,RpWarning,(int)stage,0); + //usnprintf(init_string, 80, "PowerUpUpdate token %s",PowerUpToken); + Report("PowerUpUpdate",__FILE__,InitStages,(int)response.progresspercentage,RpWarning,(int)stage,0); responseContainer = createContainer(MESSAGE_TYPE__StartPowerUpResponse, PowerUpToken, last, &response, &start_power_up_response__pack, &start_power_up_response__get_packed_size); responseContainer.has_continuous = true; responseContainer.continuous = true; @@ -875,8 +903,18 @@ uint32_t PowerUpUpdate(MACHINE_STATE_STAGES_ENUM stage) SendChars((char*)container_buffer, container_size); //MessageContainer responseContainer; + if (last == true) + { + if (PowerUpLoadControlId!= 0xFF) + { + RemoveControlCallback(PowerUpLoadControlId, PowerUpUpdateCallBackFunction); + PowerUpLoadControlId = 0xFF; + } + } return status; } + + uint32_t PowerUpUpdateFunc(MessageContainer* requestContainer) { uint32_t status = NOT_SUPPORTED; @@ -884,11 +922,13 @@ uint32_t PowerUpUpdateFunc(MessageContainer* requestContainer) // MachineUpdateInitParams InitParams; - Report("PowerUpUpdateFunc",__FILE__,__LINE__,(int)0,RpWarning,(int)0,0); StartPowerUpRequest* request = start_power_up_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); ustrncpy (PowerUpToken, requestContainer->token,36); + //usnprintf(init_string, 80, "PowerUpUpdateFunc token %s",PowerUpToken); + Report("PowerUpUpdateFunc",__FILE__,__LINE__,(int)0,RpWarning,(int)0,0); + PowerUpLoadControlId = AddControlCallback("PowerUpLoad", PowerUpUpdateCallBackFunction, 2* eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); - PowerUpUpdate(MachineStateDetail); + //PowerUpUpdate(MachineStateDetail); start_power_up_request__free_unpacked(request,NULL); return status; } |
