diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-03 15:49:54 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-03 15:49:54 +0300 |
| commit | 2bab30adc68e3166ca2ce613ba63224d909c84d9 (patch) | |
| tree | e76b419f574bd7ce2040f6513225f556c81a057b /Software/Embedded_SW | |
| parent | 1638e0bd64156c28a72f2e01a9f93e1cb0683714 (diff) | |
| download | Tango-2bab30adc68e3166ca2ce613ba63224d909c84d9.tar.gz Tango-2bab30adc68e3166ca2ce613ba63224d909c84d9.zip | |
version 1.3.8.3 Power down scenario, Idle handling, some thread load improvements
Diffstat (limited to 'Software/Embedded_SW')
22 files changed, 623 insertions, 34 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c index a31f4bef8..d54280fee 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c @@ -36,10 +36,20 @@ char activateString[100]; char ActivateToken[36+1]={0}; bool Reboot = false; + +bool SwUpgradeActive(void) +{ + if (ActivateVersionControlId != 0xFF) + { + Reboot = false; + return true; + } + return false; +} uint32_t ActivateVersionCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { - ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT; - MessageContainer responseContainer; + //ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT; + //MessageContainer responseContainer; usnprintf(activateString, 1000, "file %d of %d bytes %d of %d",CurrentRunningFile,NumberOfFiles,vme_index,CurrentFileSize); diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h index 9af76f96f..6f817fe90 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h @@ -11,6 +11,7 @@ uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer); uint32_t ValidateVersionRequestFunc(MessageContainer* requestContainer); +bool SwUpgradeActive(void); diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index 7f22a613a..030c4229e 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -20,7 +20,7 @@ typedef struct } TangoVersion_t; -TangoVersion_t _gTangoVersion = {1,3,8,2}; +TangoVersion_t _gTangoVersion = {1,3,8,3}; #define BUILD_DATE __DATE__ char Dat[50] = BUILD_DATE; char _gTangoName [MAX_STRING_LEN] = "Tango01 ";//d diff --git a/Software/Embedded_SW/Embedded/Communication/Container.c b/Software/Embedded_SW/Embedded/Communication/Container.c index ad57c36ab..b0c063a5e 100644 --- a/Software/Embedded_SW/Embedded/Communication/Container.c +++ b/Software/Embedded_SW/Embedded/Communication/Container.c @@ -43,6 +43,7 @@ #include "Communication/CommunicationTask.h" #include "StateMachines/Printing/PrintingSTM.h" +#include "StateMachines/Initialization/PowerIdle.h" #include "Common/report/report.h" #include "Connection.h" @@ -130,6 +131,8 @@ void receive_callback(char* buffer, size_t length) if (requestContainer == NULL) return; // HeatingTestSendResonse(0, false,true,true, /*OriginalMotorSpd_2PPS[index]*/length,requestContainer->type,0,0, "Container"); + if (requestContainer->type != MESSAGE_TYPE__KeepAliveRequest) //user action resets the idle counter + resetIdleCounter(); msgId[index] = requestContainer->type; Length[index] = length; diff --git a/Software/Embedded_SW/Embedded/Main.c b/Software/Embedded_SW/Embedded/Main.c index 2147652e2..046f8291e 100644 --- a/Software/Embedded_SW/Embedded/Main.c +++ b/Software/Embedded_SW/Embedded/Main.c @@ -46,7 +46,7 @@ #include "StateMachines/Printing/PrintingSTM.h" #include "StateMachines/Initialization/InitSequence.h" - +#include "StateMachines/Initialization/PowerIdle.h" #include <Drivers/SSI_Comm/SSI_Comm.h> #include "drivers/SPI/SPI_Comm.h" #include "drivers/Uart_Comm/Uart.h" @@ -245,7 +245,7 @@ int main(void) // HWControlId = AddControlCallback( MainHWInitCallBackFunction, 2* eOneSecond/*eHundredMillisecond*/, MainDummyFunction,0,0, 0 ); Start_InitSequence(); - + PowerIdleInit(); BIOS_start(); diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c index 8e76badfe..81c4a230b 100644 --- a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c +++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c @@ -1042,7 +1042,7 @@ void SendEventNotifications(void) else { LOG_ERROR(response.n_events,"events malloc error"); - return ERROR; + return; } } else diff --git a/Software/Embedded_SW/Embedded/Modules/General/buttons.c b/Software/Embedded_SW/Embedded/Modules/General/buttons.c index 4befb83ea..ee6204060 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/buttons.c +++ b/Software/Embedded_SW/Embedded/Modules/General/buttons.c @@ -22,6 +22,7 @@ #include "Modules/Thread/Thread_ex.h" #include "Modules/General/buttons.h" +#include "StateMachines/Initialization/PowerOffSequence.h" //int MachineOnOff(); int PowerDown(); @@ -86,6 +87,7 @@ bool Read_PWR_Button();//TODO move to GPIO folder int PowerDown() { bool ret = OK; + PowerOffInit(); return ret; } diff --git a/Software/Embedded_SW/Embedded/Modules/General/process.c b/Software/Embedded_SW/Embedded/Modules/General/process.c index 458bb35f2..277891861 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/process.c +++ b/Software/Embedded_SW/Embedded/Modules/General/process.c @@ -20,6 +20,7 @@ #include "modules/ids/ids_ex.h" #include "third_party/fatfs/src/ffconf.h" #include "Common/SWUpdate/FileSystem.h" +#include "StateMachines/Initialization/PowerIdle.h" @@ -210,6 +211,7 @@ void ProcessRequestFunc(MessageContainer* requestContainer) //REPORT_MSG (ProcessParams->dryerzone1temp,"Process Params Dryer"); + PowerIdleOutOfIdleState(); if (status == 0) status = HandleProcessParameters(ProcessParams); diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_dispenser.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_dispenser.c index 492dce2cc..b33b531a3 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_dispenser.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_dispenser.c @@ -245,6 +245,24 @@ void IDS_Dispenser_Content_Init (void) //================================== } uint16_t seconds_counter = 0; +uint32_t IDS_Dispenser_Store_Data (void) +{ + FRESULT Status = FR_OK; + IDSDispenserData.n_dispenserinfo = MAX_SYSTEM_DISPENSERS; + IDSDispenserData.dispenserinfo = dispenserdata; + uint8_t* response_buffer = my_malloc(dispenser_data__get_packed_size(&IDSDispenserData)); + size_t response_size = 0; + if (response_buffer) + { + response_size = dispenser_data__pack(&IDSDispenserData, response_buffer); + Status = FileWrite(response_buffer,response_size,DispenserStorePath); + my_free(response_buffer); + } + else + return ERROR; + + return Status; +} void IDS_Dispenser_Content_Calculation (char DispenserId) { assert (DispenserId<MAX_SYSTEM_DISPENSERS); @@ -258,24 +276,12 @@ void IDS_Dispenser_Content_Calculation (char DispenserId) { if (seconds_counter++>=600)//3600) { + seconds_counter = 0; if (IDS_Dispenser_Data[DispenserId].consumedinnanolitter) { REPORT_MSG(IDS_Dispenser_Data[DispenserId].consumedinnanolitter,"Saving Dispenser Data" ); } - seconds_counter = 0; - IDSDispenserData.n_dispenserinfo = MAX_SYSTEM_DISPENSERS; - IDSDispenserData.dispenserinfo = dispenserdata; - uint8_t* response_buffer = my_malloc(dispenser_data__get_packed_size(&IDSDispenserData)); - size_t response_size = 0; - if (response_buffer) - { - response_size = dispenser_data__pack(&IDSDispenserData, response_buffer); - } - - FileWrite(response_buffer,response_size,DispenserStorePath); - my_free(response_buffer); - //dispenser_data__free_unpacked(response_size,NULL); - + IDS_Dispenser_Store_Data(); } } } diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h index 2e8d33e1a..9b2442698 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h @@ -69,6 +69,7 @@ uint32_t IDS_Dispenser_Close_Valve_And_Stop_Motor(int DispenserId, callback_fptr uint32_t IDS_Dispenser_Start_Motor_and_Open_Valve(int DispenserId, int MotorSpeed, callback_fptr callback); void IDS_Dispenser_Content_Calculation (char DispenserId); +uint32_t IDS_Dispenser_Store_Data (void); uint32_t IDS_MapDispenserUsedinFileJob(void *JobDetails); diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c index 919e84582..d041b648e 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c @@ -7,6 +7,7 @@ #include "driverlib/gpio.h" #include "Drivers/USB_Communication/USBCDCD.h" +#include "StateMachines/Initialization/PowerOffSequence.h" //#include "graphics_adapter.h" @@ -20,7 +21,7 @@ void Stub_ProgressRequest(MessageContainer* requestContainer) ProgressResponse response = PROGRESS_RESPONSE__INIT; response.has_progress = true; - + PowerOffInit(); int i = 0; for (i = 0; i < request->amount; i++) { diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index 3ee248fba..ab5075ab9 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -78,6 +78,13 @@ //RUN MOTOR A FULL CYCLE //RUN A MOTOR NUMBER OF STEPS //RUN CONTROL FOR A SINGLE DANCER + bool ThreadLoadingActive(void) + { + if ((LoadStages > THREAD_LOAD_INIT)&&(LoadStages < THREAD_LOAD_END)) + return true; + else + return false; + } uint32_t Thread_Load_Init(void) { void* buffer = NULL; @@ -245,9 +252,9 @@ { REPORT_MSG(LoadStages, "Thread Load State Machine step"); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD].directionthreadwize, 200, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD], Thread_Load_HomingCallback,10000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD].directionthreadwize, 80, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANHEAD], Thread_Load_HomingCallback,10000); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH].directionthreadwize, 200, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH], Thread_Load_HomingCallback,10000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH].directionthreadwize, 80, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_DH_CLEANMECH], Thread_Load_HomingCallback,10000); return OK; } uint32_t Thread_Load_Open_Covers(void) diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h index 69ac4b6ad..d7ce917c0 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h @@ -67,9 +67,11 @@ typedef enum THREAD_LOAD_END }THREAD_LOAD_STAGES_ENUM; uint32_t ThreadLoadStateMachine( THREAD_LOAD_STAGES_ENUM ReadValue); +bool ThreadLoadingActive(void); void ThreadLoadPollRequest(MessageContainer* requestContainer); void ThreadLoadRequest(MessageContainer* requestContainer); + #endif diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 07a32b2a6..a4208ad25 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -717,7 +717,7 @@ void SetOriginMotorSpeed(float process_speed) uint32_t ThreadPreSegmentState(void *SegmentDetails, uint32_t SegmentId) { //set the speed only before the first segment, speed is constant across all job segments and intersegments - JobSegment* Segment = SegmentDetails; + //JobSegment* Segment = SegmentDetails; float process_speed = dyeingspeed; if (dyeingspeed == 0) diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste.h b/Software/Embedded_SW/Embedded/Modules/Waste/Waste.h index 66428039f..f6b7d760a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Waste/Waste.h +++ b/Software/Embedded_SW/Embedded/Modules/Waste/Waste.h @@ -97,6 +97,7 @@ typedef enum U8 WHS_init(void); U8 WHS_HW_test(void); +bool WHS_IsEmptying(); diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c index 689a2bc95..447e954d4 100644 --- a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c @@ -52,7 +52,6 @@ bool SetActiveWastCartridge(); - struct waste_cartridge_params { uint32_t serial_number; @@ -99,6 +98,15 @@ struct WHS_information struct WHS_information WHS_info; +bool WHS_IsEmptying() +{ + bool ret = false; + if ( WHS_info.sttMachine == WHS_emptying ) + { + ret = true; + } + return ret; +} /* -------- cartridge function ----*/ diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c index 017eb2126..64cb99918 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c @@ -23,6 +23,8 @@ #include "InitSequence.h" #include "drivers/I2C_Communication/DAC/Blower.h" +#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h" +#include "drivers/Valves/Valve.h" #include "heaters/heaters_ex.h" @@ -38,7 +40,7 @@ INIT_SEQUENCE_MACHINE_READY_TO_DYE, INIT_SEQUENCE_END, }INIT_SEQUENCE_STAGES_ENUM; - INIT_SEQUENCE_STAGES_ENUM InitStages = INIT_SEQUENCE_INIT; + INIT_SEQUENCE_STAGES_ENUM InitStages = INIT_SEQUENCE_INIT, StoredInitStages = INIT_SEQUENCE_INIT; MACHINE_STATE_STAGES_ENUM MachineState = MACHINE_STATE_INIT; MACHINE_STATE_STAGES_ENUM GetMachineState(void) @@ -49,7 +51,9 @@ void SetMachineState(MACHINE_STATE_STAGES_ENUM NewState) { MachineState = NewState; } -uint32_t HWControlId; +uint32_t HWControlId,InitSchedulerControlId; +uint32_t MidTankControlId; + uint32_t RESET_Cause = 0; void InitSequenceResetReason(void); @@ -72,7 +76,7 @@ uint32_t InitSequenceCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { ActivateHeadMagnet(); InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); } else { @@ -81,11 +85,23 @@ uint32_t InitSequenceCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) } return OK; } +/*******************************************************************************************************/ +uint32_t InitScheduler(uint32_t IfIndex, uint32_t BusyFlag) +{ + if (InitStages > StoredInitStages) + { + StoredInitStages = InitStages; + InitSequenceStateMachine(InitStages); + } + return OK; +} +/*******************************************************************************************************/ uint32_t Start_InitSequence(void) { MachineState = MACHINE_STATE_HW_CONFIG; HWControlId = AddControlCallback( InitSequenceCallBackFunction, 4* eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); + InitSchedulerControlId = AddControlCallback( InitScheduler, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); return OK; } void InitSequenceResetReason(void) @@ -104,7 +120,7 @@ void InitSequenceResetReason(void) LOG_ERROR(RESET_Cause,"Reset Reason Register"); SysCtlResetCauseClear(RESET_Cause); InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); //return OK; } @@ -113,7 +129,7 @@ void InitSequenceBuiltInTestCallBack(uint32_t IfIndex, uint32_t BusyFlag) if (1)//BIT OK { InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); } else { @@ -127,6 +143,44 @@ uint32_t InitSequenceBuiltInTest(void) InitSequenceBuiltInTestCallBack(0,0); return OK; } +int MidTankOperationCounter = 0; +uint32_t InitSequenceMidTankCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) +{ + int MidTankOpenAir = 8; + int MidTankReadPressure = 16; + int MidTankCloseAir = 24; + int MidTankEnd = 32; + int portId; + + if (MidTankOperationCounter >= MidTankEnd) + { + SafeRemoveControlCallback(MidTankControlId, InitSequenceMidTankCallBackFunction); + } + else if (MidTankOperationCounter >= MidTankCloseAir) + { + //close air valve for midtank (MidTankOperationCounter-MidTankCloseAir) + portId = (MidTankOperationCounter - MidTankCloseAir) ; //0-7 + Disable_MidTank_Pressure_Reading(portId); + Valve_Set(IDS_Id_to_AirValve[portId], Atm_MidTank_OFF ); //Atm_MidTank_OFF/ON + } + else if (MidTankOperationCounter >= MidTankReadPressure) + { + //read pressure for midtank (MidTankOperationCounter-MidTankCloseAir) + for (portId = 0;portId < MAX_SYSTEM_DISPENSERS;portId++) + { + Read_MidTank_Pressure_Sensor(portId); + } + } + else if (MidTankOperationCounter >= MidTankOpenAir) + { + //open air valve for midtank (MidTankOperationCounter-MidTankOpenAir) + portId = (MidTankOperationCounter - MidTankOpenAir) ; //0-7 + Enable_MidTank_Pressure_Reading(portId); + Valve_Set(IDS_Id_to_AirValve[portId], Atm_MidTank_ON ); //Atm_MidTank_OFF/ON + } + MidTankOperationCounter++; + return OK; +} uint32_t InitSequenceBlowerCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { if (SafeRemoveControlCallback(HWControlId, InitSequenceBlowerCallBackFunction )==OK) @@ -137,7 +191,7 @@ uint32_t InitSequenceBlowerCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) Control_Voltage_To_Blower(BlowerCfg.heatingvoltage); Safety_Init(); InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); return OK; } uint32_t InitSequenceInitialBlowerActivation(void) @@ -150,6 +204,8 @@ uint32_t InitSequenceInitialBlowerActivation(void) Control_Voltage_To_Blower(BlowerCfg.voltage); HWControlId = AddControlCallback( InitSequenceBlowerCallBackFunction, 10* eOneSecond/*eHundredMillisecond*/, TemplateDataReadCBFunction,0,0, 0 ); } + MidTankControlId = AddControlCallback( InitSequenceMidTankCallBackFunction, 300/*eHundredMillisecond*/, TemplateDataReadCBFunction,0,0, 0 ); + return OK; } int NumOfCheckedDispnsers = 0; @@ -159,7 +215,7 @@ uint32_t InitSequenceDispenserPressureBuildUpTestCallBackFunction(uint32_t IfInd if(NumOfCheckedDispnsers==0) { InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); MachineState = MACHINE_STATE_DISPENSER_PRESSURE_BUILDUP_TEST; } @@ -187,7 +243,7 @@ uint32_t InitSequenceThreadDetection(void) { InitStages++; MachineState = MACHINE_STATE_THREAD_DETECTION; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); return OK; } @@ -201,7 +257,7 @@ uint32_t InitSequenceStartHeatingCallBackFunction(uint32_t IfIndex, uint32_t Bus else Report("Remove control callback failed",__FILE__,__LINE__,(int)HWControlId,RpWarning,(int)InitSequenceStartHeatingCallBackFunction,0); InitStages++; - InitSequenceStateMachine(InitStages); + //InitSequenceStateMachine(InitStages); } return OK; } @@ -267,6 +323,7 @@ uint32_t InitSequenceStateMachine( INIT_SEQUENCE_STAGES_ENUM ReadValue) break; default: LOG_ERROR(ReadValue,"ERROR IN INIT STATE MACHINE"); + RemoveControlCallback( InitSchedulerControlId,InitScheduler); break; } return OK; diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.c b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.c new file mode 100644 index 000000000..c6136fc62 --- /dev/null +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.c @@ -0,0 +1,99 @@ +/* + * PowerIdle.c + * + * Created on: Apr 3, 2019 + * Author: shlomo + */ +#include "modules/General/GeneralHardware.h" +#include "modules/General/Safety.h" +#include "modules/thread/thread.h" +#include "modules/ids/ids.h" +#include "modules/control/control.h" +#include "modules/AlarmHandling/AlarmHandling.h" +#include "modules/heaters/heaters_ex.h" +#include "modules/Diagnostics/Diagnostics.h" +#include "Modules/General/process.h" + +#include "StateMachines/Printing/PrintingSTM.h" +#include "InitSequence.h" + +#include "drivers/I2C_Communication/DAC/Blower.h" +#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h" +#include "drivers/Valves/Valve.h" + +#include "heaters/heaters_ex.h" + +#define DEFAULT_IDLE_TIME_LIMIT 3600 +int powerIdleSecondsCounter = 0; +int powerIdleSecondsLimit = DEFAULT_IDLE_TIME_LIMIT; +bool powerIdleState = false; +bool machineActive = false; +uint32_t IdleControlId = 0xFF; +void PowerIdleSetIdle(void) +{ + ProcessParameters ProcessParametersClear; + ProcessParametersClear.dryerzone1temp = 80; + ProcessParametersClear.dryerzone2temp = 80; + ProcessParametersClear.dryerzone3temp = 80; + ProcessParametersClear.mixertemp = 0; + ProcessParametersClear.headzone1temp = 80; + ProcessParametersClear.headzone2temp = 80; + ProcessParametersClear.headzone3temp = 80; + ProcessParametersClear.headzone4temp = 80; + ProcessParametersClear.headzone5temp = 80; + ProcessParametersClear.headzone6temp = 80; + ProcessParametersClear.dyeingspeed = 40; + if (HandleProcessParameters(&ProcessParametersClear)!= OK) + { + LOG_ERROR (1, "Turn Heaters idle failed"); + return ERROR; + } + if (BlowerCfg.enabled == true) + { + Turn_the_Blower_On();//Turn on with the Default_Voltage + if (BlowerCfg.heatingvoltage) + Control_Voltage_To_Blower(BlowerCfg.heatingvoltage); + else + Control_Voltage_To_Blower(BlowerCfg.voltage-500); + } +} + +uint32_t PowerIdleCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) +{ + if (machineActive == true) + return OK; + if (++powerIdleSecondsCounter>=powerIdleSecondsLimit) + { + if (powerIdleState == false) + { + Report("PowerIdle Idle activated ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0); + powerIdleState = true; + //move to idle state + } + } + return OK; +} +void PowerIdleInit(void) +{ + IdleControlId = AddControlCallback( PowerIdleCallBackFunction, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); + if (IdleControlId == 0xFF) + Report("AddControlCallback failed",__FILE__,__LINE__,(int)IdleControlId,RpWarning,(int)0,0); + Report("PowerIdleInit ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)0,0); + +} +int getIdleCounter (void) {return powerIdleSecondsCounter;} +void setIdleLimit (int Limit) {powerIdleSecondsLimit = Limit;} +void setmachineActive(bool Active){machineActive = Active;} +void resetIdleCounter (void) {powerIdleSecondsCounter = 0;} +bool getIdleState (void) {return powerIdleState;} +void PowerIdleOutOfIdleState(void) +{ + Report("PowerIdle Out of Idle ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0); + powerIdleSecondsCounter = 0; + if (powerIdleState == true) + { + powerIdleState = false; + //move to idle state + } + +} diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.h b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.h new file mode 100644 index 000000000..71edf8885 --- /dev/null +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerIdle.h @@ -0,0 +1,22 @@ +/* + * PowerIdle.h + * + * Created on: Apr 3, 2019 + * Author: shlomo + */ + +#ifndef STATEMACHINES_INITIALIZATION_POWERIDLE_H_ +#define STATEMACHINES_INITIALIZATION_POWERIDLE_H_ + +int getIdleCounter (void); +void setIdleLimit (int Limit); +void resetIdleCounter (void); +bool getIdleState (void); +void PowerIdleOutOfIdleState(void); +void setmachineActive(bool Active); +void PowerIdleInit(void); + + + + +#endif /* STATEMACHINES_INITIALIZATION_POWERIDLE_H_ */ diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.c b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.c new file mode 100644 index 000000000..f0cf641ae --- /dev/null +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.c @@ -0,0 +1,327 @@ +/* + * PowerOffSequence.c + * + * Created on: Apr 2, 2019 + * Author: shlomo + */ + + +#include "modules/General/GeneralHardware.h" +#include "modules/General/Safety.h" +#include "modules/thread/thread.h" +#include "modules/waste/waste.h" +#include "modules/ids/ids.h" +#include "modules/control/control.h" +#include "modules/AlarmHandling/AlarmHandling.h" +#include "modules/heaters/heaters_ex.h" +#include "modules/Diagnostics/Diagnostics.h" +#include "Modules/General/process.h" + +#include "Modules/Thread/Thread_ex.h" +#include "Common/SWUpdate/FirmwareUpgrade.h" + +#include "StateMachines/Printing/PrintingSTM.h" +#include "InitSequence.h" + +#include "drivers/I2C_Communication/DAC/Blower.h" +#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h" +#include "drivers/Heater/TemperatureSensor.h" +#include "drivers/Valves/Valve.h" + +#include "heaters/heaters_ex.h" + +#include "PowerOffSequence.h" +/* + typedef enum + { + POWER_OFF_INIT, + POWER_OFF_HEAD_CLEAN, + POWER_OFF_MIXER_FLUSH, + POWER_OFF_HEATERS_OFF, + POWER_OFF_STORE_DATA, + POWER_OFF_WAIT_FOR_PROCESSES,//wait for waste emptying, ink filling, thread loading + POWER_OFF_STOP_RUNNING_JOB, + POWER_OFF_SET_VALVE_POSITION, + POWER_OFF_WAIT_FOR_TEMPERATURE, + POWER_OFF_TURN_OFF_DRYER_FAN, + POWER_OFF_TURN_OFF_COOLER, + POWER_OFF_TURN_OFF_BLOWER, + POWER_OFF_POWER_OFF, + POWER_OFF_MAX, + }POWER_OFF_STAGES_ENUM; +*/ +POWER_OFF_STAGES_ENUM PowerOffMachineState = POWER_OFF_INIT,StoredMachineState = POWER_OFF_INIT; +uint32_t PowerOffControlId = 0xFF; +uint32_t WaitForProcessControlId = 0xFF; +uint32_t PowerOffSequenceStateMachine( POWER_OFF_STAGES_ENUM ReadValue); + +/*******************************************************************************************************/ +uint32_t PowerOffScheduler(uint32_t IfIndex, uint32_t BusyFlag) +{ + if (PowerOffMachineState > StoredMachineState) + { + StoredMachineState = PowerOffMachineState; + PowerOffSequenceStateMachine (PowerOffMachineState); + } + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffInit(void) +{ + LOG_ERROR(0,"Power Off Init"); + PowerOffMachineState = POWER_OFF_HEAD_CLEAN; + PowerOffControlId = AddControlCallback( PowerOffScheduler, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffHeadClean(void) +{ + //TBD + PowerOffMachineState = POWER_OFF_MIXER_FLUSH; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffMixerFlush(void) +{ + //TBD + PowerOffMachineState = POWER_OFF_HEATERS_OFF; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffHeatersOff(void) +{ + ProcessParameters ProcessParametersClear; + ProcessParametersClear.dryerzone1temp = 0; + ProcessParametersClear.dryerzone2temp = 0; + ProcessParametersClear.dryerzone3temp = 0; + ProcessParametersClear.mixertemp = 0; + ProcessParametersClear.headzone1temp = 0; + ProcessParametersClear.headzone2temp = 0; + ProcessParametersClear.headzone3temp = 0; + ProcessParametersClear.headzone4temp = 0; + ProcessParametersClear.headzone5temp = 0; + ProcessParametersClear.headzone6temp = 0; + ProcessParametersClear.dyeingspeed = 40; + if (HandleProcessParameters(&ProcessParametersClear)!= OK) + { + LOG_ERROR (PowerOffMachineState, "Turn Off Heaters failed"); + return ERROR; + } + + PowerOffMachineState = POWER_OFF_STORE_DATA; + + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffStoreData(void) +{ + //TBD + REPORT_MSG (PowerOffMachineState, "Store Data"); + IDS_Dispenser_Store_Data(); + PowerOffMachineState = POWER_OFF_WAIT_FOR_PROCESSES; + return OK; +} +/*******************************************************************************************************/ +int WaitForProcessCounter = 0; +uint32_t PowerOffWaitForProcessesCallback(uint32_t IfIndex, uint32_t BusyFlag) +{ + if ((WHS_IsEmptying()|| + //MidTankFillingActive()|| + ThreadLoadingActive()|| + SwUpgradeActive())&& + (WaitForProcessCounter++<900)) + { + REPORT_MSG (PowerOffMachineState, "On going processes, wait for end of process"); + } + else + { + PowerOffMachineState = POWER_OFF_SET_VALVE_POSITION; + SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForProcessesCallback); + WaitForProcessControlId = 0xFF; + } + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffWaitForProcesses(void) +{ + int i; + REPORT_MSG (PowerOffMachineState, "Stop dispensers homing"); + for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) + IDS_StopHomeDispenser(i); + if (WHS_IsEmptying()|| + //MidTankFillingActive()|| + ThreadLoadingActive()|| + SwUpgradeActive()) + { + WaitForProcessCounter = 0; //15 minutes wait + REPORT_MSG (PowerOffMachineState, "On going processes, wait for end of process"); + WaitForProcessControlId = AddControlCallback( PowerOffWaitForProcessesCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); + } + else + { + PowerOffMachineState = POWER_OFF_STOP_RUNNING_JOB; + } + //TBD + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffStopRunningJob(void) +{ + if (JobIsActive()) + { + REPORT_MSG (PowerOffMachineState, "Stop running job"); + AbortJob("Power off pressed"); + } + PowerOffMachineState = POWER_OFF_SET_VALVE_POSITION; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffSetValvePosition(void) +{ + //TBD + PowerOffMachineState = POWER_OFF_WAIT_FOR_TEMPERATURE; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffWaitForTemperatureCallback(uint32_t IfIndex, uint32_t BusyFlag) +{ + uint32_t MaxTemp = 0,readTemp; + readTemp = TemperatureSensorRead( MIXER_PT100); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP1); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP2); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP3); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP4); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP5); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( HEAD6_PT100); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DRYER_TEMP1); + if ((readTemp>= MaxTemp)&&(readTemp < 28000)) + MaxTemp = readTemp; + +#define POWER_OFF_TEMP_THRESHOLD 10000 + + if ((MaxTemp>POWER_OFF_TEMP_THRESHOLD)&&(WaitForProcessCounter++<1800)) + { + Report("On going cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0); + } + else + { + Report("ended cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0); + PowerOffMachineState = POWER_OFF_TURN_OFF_DRYER_FAN; + SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForTemperatureCallback); + WaitForProcessControlId = 0xFF; + } + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffWaitForTemperature(void) +{ + if (WaitForProcessControlId == 0xFF) + { + WaitForProcessCounter = 0; + WaitForProcessControlId = AddControlCallback( PowerOffWaitForTemperatureCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); + } + //TBD + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffTurnOffDryerFan(void) +{ + Control_Dryer_Fan(STOP,75);//use START or STOP, 0 - 100% + PowerOffMachineState = POWER_OFF_TURN_OFF_COOLER; + + //TBD + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffTurnOffCooler(void) +{ + uint32_t DeActivateChiller(); + PowerOffMachineState = POWER_OFF_TURN_OFF_BLOWER; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffTurnOffBlower(void) +{ + Turn_the_Blower_Off();//Turn off + PowerOffMachineState = POWER_OFF_POWER_OFF; + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffPowerOff(void) +{ + int i; + for (i = 0;i<10;i++) + { + REPORT_MSG (10-i, "Power off in x seconds"); + Task_sleep (1000); + } + Power_Off(); + return OK; +} +/*******************************************************************************************************/ +uint32_t PowerOffSequenceStateMachine( POWER_OFF_STAGES_ENUM ReadValue) +{ + uint32_t status = OK; + + REPORT_MSG(ReadValue,"PowerOffSequenceStateMachine"); + switch (ReadValue) + { + case POWER_OFF_INIT: + break; + case POWER_OFF_HEAD_CLEAN: + status = PowerOffHeadClean(); + break; + case POWER_OFF_MIXER_FLUSH: + status = PowerOffMixerFlush(); + break; + case POWER_OFF_HEATERS_OFF: + status = PowerOffHeatersOff(); + break; + case POWER_OFF_STORE_DATA: + status = PowerOffStoreData(); + break; + case POWER_OFF_WAIT_FOR_PROCESSES: //wait for waste emptying: ink filling: thread loading + status = PowerOffWaitForProcesses(); + break; + case POWER_OFF_STOP_RUNNING_JOB: + status = PowerOffStopRunningJob(); + break; + case POWER_OFF_SET_VALVE_POSITION: + status = PowerOffSetValvePosition(); + break; + case POWER_OFF_WAIT_FOR_TEMPERATURE: + status = PowerOffWaitForTemperature(); + break; + case POWER_OFF_TURN_OFF_DRYER_FAN: + status = PowerOffTurnOffDryerFan(); + break; + case POWER_OFF_TURN_OFF_COOLER: + status = PowerOffTurnOffCooler(); + break; + case POWER_OFF_TURN_OFF_BLOWER: + status = PowerOffTurnOffBlower(); + break; + case POWER_OFF_POWER_OFF: + status = PowerOffPowerOff(); + break; + default: + LOG_ERROR(ReadValue,"ERROR IN POWER OFF STATE MACHINE"); + break; + } +return OK; +} + diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.h b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.h new file mode 100644 index 000000000..fa1e123bd --- /dev/null +++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/PowerOffSequence.h @@ -0,0 +1,34 @@ +/* + * PowerOffSequence.h + * + * Created on: Apr 2, 2019 + * Author: shlomo + */ + +#ifndef STATEMACHINES_INITIALIZATION_POWEROFFSEQUENCE_H_ +#define STATEMACHINES_INITIALIZATION_POWEROFFSEQUENCE_H_ + + typedef enum + { + POWER_OFF_INIT, + POWER_OFF_HEAD_CLEAN, + POWER_OFF_MIXER_FLUSH, + POWER_OFF_HEATERS_OFF, + POWER_OFF_STORE_DATA, + POWER_OFF_WAIT_FOR_PROCESSES,//wait for waste emptying, ink filling, thread loading + POWER_OFF_STOP_RUNNING_JOB, + POWER_OFF_SET_VALVE_POSITION, + POWER_OFF_WAIT_FOR_TEMPERATURE, + POWER_OFF_TURN_OFF_DRYER_FAN, + POWER_OFF_TURN_OFF_COOLER, + POWER_OFF_TURN_OFF_BLOWER, + POWER_OFF_POWER_OFF, + POWER_OFF_ERROR, + POWER_OFF_MAX, + }POWER_OFF_STAGES_ENUM; + + +uint32_t PowerOffInit(void); + + +#endif /* STATEMACHINES_INITIALIZATION_POWEROFFSEQUENCE_H_ */ diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index 972f79939..b5034a11c 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -59,6 +59,7 @@ #include "PMR/Diagnostics/ThreadAbortJoggingRequest.pb-c.h" #include "PMR/Diagnostics/ThreadAbortJoggingResponse.pb-c.h" +#include "StateMachines/Initialization/PowerIdle.h" #include "./printingSTM.h" #include "modules/thread/thread_ex.h" @@ -954,6 +955,7 @@ Void jobTask(UArg arg0, UArg arg1) case JobRequestMsg: JobEndReason = JOB_OK; JobActive = true; + setmachineActive(true); /*ValidateState (CurrentJob); break; case ValidationResultsOk:*/ @@ -977,6 +979,8 @@ Void jobTask(UArg arg0, UArg arg1) break; case PrintingResultsOk: JobActive = false; + setmachineActive(false); + resetIdleCounter(); CurrentJob = NULL; //if (CurrentRequest!= NULL) // job_request__free_unpacked(CurrentRequest,NULL); @@ -988,6 +992,8 @@ Void jobTask(UArg arg0, UArg arg1) break; case PrintingResultsFail: JobActive = false; + setmachineActive(false); + resetIdleCounter(); CurrentJob = NULL; //if (CurrentRequest!= NULL) // job_request__free_unpacked(CurrentRequest,NULL); |
