From cd18fb27a2499072f18cb0320ddeb85a0500a93e Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 31 Oct 2019 10:16:10 +0200 Subject: version 1.4.6.0 - going forward --- .../Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c | 11 +-- .../Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c | 22 +++++- .../Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h | 6 +- .../Drivers/I2C_Communication/DAC/Blower.c | 2 +- .../Dispenser_Card/IO_Ports/Dispenser_IO.c | 4 + .../Dispenser_Card/IO_Ports/Dispenser_IO.h | 1 + .../Embedded/Drivers/I2C_Communication/I2C.h | 2 + .../Embedded/Drivers/I2C_Communication/I2C_Task.c | 85 ++++++++++++++++++++++ .../Embedded_SW/Embedded/Drivers/Motors/Motor.c | 14 +++- .../Embedded_SW/Embedded/Drivers/Motors/Motor.h | 1 + .../Embedded/Drivers/Motors/MotorActions.c | 30 ++++---- .../Embedded_SW/Embedded/Drivers/Valves/Valve.c | 2 +- 12 files changed, 153 insertions(+), 27 deletions(-) create mode 100644 Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C_Task.c (limited to 'Software/Embedded_SW/Embedded/Drivers') diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c index 26996ad48..1f871a4cc 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c @@ -547,17 +547,18 @@ bool Is_FPGA_WD_Occurred() LOG_ERROR (FPGA_WD_Counter, "FPGA WD Occurred"); FPGA_WD_Counter = FPGA_WD_Counter+1; FPGA_WD_Occurred = true; -/* + //To recover: //1. Disable all FPGA's WD: Control_WD(DISABLE,0); //2. Enqable all FPGA's WD: Control_WD(ENABLE,250); //3. Call FPGA_SetMotorsInit: - FPGA_SetMotorsInit(); + //FPGA_SetMotorsInit(); //4. Init Motor's Drivers: - Init_Motors_Drivers_After_FPGA_WD(); - + //Init_Motors_Drivers_After_FPGA_WD(); + Motor_ReconfigAllMotors(); +/* //OR //Reset MCU (will reset also the FPGA): //Power_Reset(); @@ -789,7 +790,7 @@ uint32_t SecondaryPumpCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) void PumpActivation(uint32_t seconds) { Pumps_Control(WASTECH_PUMP2, OPEN); - SecondaryPumpControlId = AddControlCallback( SecondaryPumpCallBackFunction, seconds*1000/*eHundredMillisecond*/, TemplateDataReadCBFunction,0,0, 0 ); + SecondaryPumpControlId = AddControlCallback(NULL, SecondaryPumpCallBackFunction, seconds*1000/*eHundredMillisecond*/, TemplateDataReadCBFunction,0,0, 0 ); } /* uint8_t Buttons_LEDS(BUTTON Button, OPERATION_MODE LED_Mode) diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c index 331913816..fe8a96b32 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c @@ -26,6 +26,7 @@ #include "ADC_MUX.h" #include "Modules/AlarmHandling/AlarmHandling.h" +#include "modules/ids/ids_ex.h" bool MidTank_Pressure_Read_Enable[NUM_OF_MIDTANKS] = {true,true,true,true,true,true,true,true}; double MidTank_Pressure[NUM_OF_MIDTANKS] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; @@ -388,10 +389,10 @@ double Get_MidTank_Pressure_Sensor(MidTank_t MidTank_ID) //0-7 assert (MidTank_ID +#include +#include "include.h" +#include "inc/hw_memmap.h" + +#include "drivers/ADC_Sampling/adc.h" + +#include "ADC_MUX/ADC_MUX.h" +#include "modules/ids/ids_ex.h" + +Mailbox_Handle I2C_ReadingMsgQ = NULL; +typedef enum +{ + Midtank_Pressure_Reading, + Heater_Current_Reading +}I2C_ReadingMessages; + +typedef struct I2C_ReadingMessage{ + uint16_t messageId; + uint16_t parameter; +}I2C_ReadingMessageStruc; + +void Trigger_Heater_Current_Read(void) +{ + I2C_ReadingMessageStruc I2C_ReadingMessage; + uint8_t Heater_i; + + for (Heater_i = 0;Heater_i < NUM_OF_CURRENT_HEATERS;Heater_i++) + { + I2C_ReadingMessage.messageId = Heater_Current_Reading; + I2C_ReadingMessage.parameter = Heater_i; + if (I2C_ReadingMsgQ != NULL) + Mailbox_post(I2C_ReadingMsgQ , &I2C_ReadingMessage, BIOS_NO_WAIT); + } + return; + +} + +void Trigger_MidTank_Pressure_Read(void) +{ + I2C_ReadingMessageStruc I2C_ReadingMessage; + uint8_t Midtank_i; + + for (Midtank_i = 0;Midtank_i < MAX_SYSTEM_DISPENSERS;Midtank_i++) + { + I2C_ReadingMessage.messageId = Midtank_Pressure_Reading; + I2C_ReadingMessage.parameter = Midtank_i; + if (I2C_ReadingMsgQ != NULL) + Mailbox_post(I2C_ReadingMsgQ , &I2C_ReadingMessage, BIOS_NO_WAIT); + } + return; + +} +void I2C_ReadingTask(UArg arg0, UArg arg1) +{ + I2C_ReadingMessageStruc I2C_ReadingMessage; + Error_Block eb; + Error_init(&eb); + I2C_ReadingMsgQ = Mailbox_create(sizeof(I2C_ReadingMessageStruc), 40, NULL,&eb); + + while(1) + { + Mailbox_pend(I2C_ReadingMsgQ , &I2C_ReadingMessage, BIOS_WAIT_FOREVER); + switch (I2C_ReadingMessage.messageId) + { + case Midtank_Pressure_Reading: + //Report("Read_MidTank_Pressure_Sensor",__FILE__,__LINE__,255,RpWarning,0,0); + Read_MidTank_Pressure_Sensor(I2C_ReadingMessage.parameter); + break; + case Heater_Current_Reading: + //Report("Read_Heaters_Current",__FILE__,__LINE__,255,RpWarning,0,0); + Read_Heaters_Current(I2C_ReadingMessage.parameter); + break; + default: + break; + } + } +} diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c index 7ea2ea79a..4a5a48f04 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c @@ -86,7 +86,19 @@ uint32_t MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorConfig return FPGA_MotorConfig( _motorId, MotorConfig); #endif } - +uint32_t Motor_ReconfigAllMotors(void) +{ + TimerMotors_t Motor_i; + uint32_t status = PASSED; + for (Motor_i = 0; Motor_i < NUM_OF_MOTORS ; Motor_i++) + { + if (isMotorConfigured(Motor_i)) + { + status |= MotorConfig( Motor_i, &MotorsCfg[Motor_i]); + } + } + return status; +} bool isMotorConfigured(TimerMotors_t _motorId) { return MotorConfigState[_motorId]; diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index afacb50c3..59a8726f3 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -131,6 +131,7 @@ extern MotorDriverConfigStruc MotorsCfg[NUM_OF_MOTORS]; uint32_t MotorsInit(void); //set the motor configuration uint32_t MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorConfig); +uint32_t Motor_ReconfigAllMotors(void); bool isMotorConfigured(TimerMotors_t _motorId); diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index 5c25a87ca..b39b9f325 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -147,7 +147,7 @@ uint32_t MotorGotoWithCallback (TimerMotors_t MotorId, uint32_t Steps, uint32_t MotorStop(MotorId,Hard_Hiz ); Task_sleep(100); MotorGoTo(MotorId,Steps ); - MotorControlId[MotorId] = AddControlCallback( MotorMoveToLimitSwitchCallBackFunction, eTenMillisecond, FPGA_Read_limit_Switches,(IfTypeMotors*0x100+MotorId), LimitSwitchId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToLimitSwitchCallBackFunction, eTenMillisecond, FPGA_Read_limit_Switches,(IfTypeMotors*0x100+MotorId), LimitSwitchId, 0 ); MotorControlCallback[MotorId] = MotorMoveToLimitSwitchCallBackFunction; return MotorControlId[MotorId]; } @@ -163,7 +163,7 @@ uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32 //MotorStop(MotorId,Hard_Hiz ); int sign = direction?1:-1; MotorGoTo(MotorId,Steps*sign ); - MotorControlId[MotorId] = AddControlCallback( MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; } @@ -184,7 +184,7 @@ uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t S //MotorStop(MotorId,Hard_Hiz ); MotorMove(MotorId,direction,Steps ); - MotorControlId[MotorId] = AddControlCallback( MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; } @@ -284,7 +284,7 @@ uint32_t MotorMoveToStopper (TimerMotors_t MotorId,bool direction, uint32_t Spee StoredMotorPosition[MotorId] = MotorGetPosition(MotorId); REPORT_MSG(StoredMotorPosition[MotorId],"MotorMoveToStopper initial position"); MotorSetSpeed (MotorId, Speed); - MotorControlId[MotorId] = AddControlCallback( MotorVerifiedCallBackFunction, 20,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorVerifiedCallBackFunction, 10,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorVerifiedCallBackFunction; return MotorControlId[MotorId]; } @@ -321,7 +321,7 @@ uint32_t MotorMoveToDrierPositionCallBackFunction(uint32_t IfIndex, uint32_t Rea MotorStop(MotorId,Hard_Stop ); //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); //call the module callback if (MotorCallback[MotorId]) @@ -359,7 +359,7 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb //MotorSetDirection( MotorId, direction); MotorSetSpeed (MotorId, 50); - MotorControlId[MotorId] = AddControlCallback( MotorMoveToDrierPositionCallBackFunction, 2,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToDrierPositionCallBackFunction, 2,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveToDrierPositionCallBackFunction; return MotorControlId[MotorId]; @@ -370,7 +370,7 @@ uint32_t MotorSetSpeedWithCallback (TimerMotors_t MotorId, uint32_t _freq, callb //assert (callback); MotorCallback[MotorId] = callback; - MotorControlId[MotorId] = AddControlCallback( MotorSetSpeedCallBackFunction, eTenMillisecond, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorSetSpeedCallBackFunction, eTenMillisecond, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorSetSpeedCallBackFunction; MotorSetSpeed(MotorId, _freq); @@ -409,7 +409,7 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO MotorControlCallback[MotorId] = 0; MotorControlId[MotorId] = 0xFF; //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); //call the module callback if (MotorCallback[MotorId]) @@ -436,7 +436,7 @@ uint32_t MotorSetSpeedCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TO MotorControlCallback[MotorId] = 0; MotorControlId[MotorId] = 0xFF; //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); //call the module callback if (MotorCallback[MotorId]) @@ -483,7 +483,7 @@ uint32_t MotorMoveToLimitSwitchCallBackFunction(uint32_t IfIndex, uint32_t Limit } //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DH_LID) { if (CloseMagnet == true) @@ -542,7 +542,7 @@ uint32_t MotorMovetoLimitSwitch (TimerMotors_t MotorId,bool direction, uint32_t MotorSetDirection( MotorId, direction); MotorSetSpeed(MotorId, Freq); - MotorControlId[MotorId] = AddControlCallback( MotorMoveToLimitSwitchCallBackFunction, MotorTimeLag[MotorId] , FPGA_Read_limit_Switches,(IfTypeMotors*0x100+MotorId), LimitSwitchId, 0 ); + MotorControlId[MotorId] = AddControlCallback("MoveToLimitSwitch", MotorMoveToLimitSwitchCallBackFunction, MotorTimeLag[MotorId] , FPGA_Read_limit_Switches,(IfTypeMotors*0x100+MotorId), LimitSwitchId, 0 ); if ( MotorControlId[MotorId] == 0xFF) return ERROR; MotorCallback[MotorId] = callback; @@ -575,7 +575,7 @@ uint32_t MotorMoveToBreakSensorCallBackFunction(uint32_t IfIndex, uint32_t Limit MotorStop(MotorId,Hard_Hiz); //TODO in run time limit switch just reverse direction //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); //call the module callback if (MotorCallback[MotorId]) @@ -601,7 +601,7 @@ uint32_t MotorMovetoBreakSensor (TimerMotors_t MotorId,bool direction, uint32_t MotorSetDirection( MotorId, direction); MotorSetSpeed(MotorId, Freq); - MotorControlId[MotorId] = AddControlCallback( MotorMoveToBreakSensorCallBackFunction, eOneMillisecond , ReadBreakSensor,(IfTypeMotors*0x100+MotorId), 0, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToBreakSensorCallBackFunction, eOneMillisecond , ReadBreakSensor,(IfTypeMotors*0x100+MotorId), 0, 0 ); if ( MotorControlId[MotorId] == 0xFF) return ERROR; MotorCallback[MotorId] = callback; @@ -646,7 +646,7 @@ uint32_t MotorMoveToDancerPositionCallBackFunction(uint32_t IfIndex, uint32_t Re MotorStop(MotorId,Hard_Hiz); //TODO in run time limit switch just reverse direction //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); //call the module callback if (MotorCallback[MotorId]) @@ -669,7 +669,7 @@ uint32_t MotorMovetoDancerPosition (TimerMotors_t MotorId,bool direction, uint32 DancerId = dancerid; MotorSetDirection( MotorId, direction); MotorSetSpeed(MotorId, Freq); - MotorControlId[MotorId] = AddControlCallback( MotorMoveToDancerPositionCallBackFunction, eTenMillisecond , Control_Read_Dancer_Position,(IfTypeMotors*0x100+MotorId), DancerId, 0 ); + MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToDancerPositionCallBackFunction, eTenMillisecond , Control_Read_Dancer_Position,(IfTypeMotors*0x100+MotorId), DancerId, 0 ); if ( MotorControlId[MotorId] == 0xFF) return ERROR; MotorCallback[MotorId] = callback; diff --git a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c index 66be6a21a..06e5b4b0d 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c +++ b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c @@ -371,7 +371,7 @@ uint32_t Control3WayValvesWithCallback (Valves_t _ValveId, bool direction, callb Valve3WayModuleCallback[_ValveId] = callback; - Valve3WayControlId[_ValveId] = AddControlCallback( Valve3WayCallBackFunction, eOneSecond/*eHundredMillisecond*/, FPGA_GetDispenserValveBusyOCD,(IfTypeDisopenser*0x100+_ValveId), _ValveId, 0 ); + Valve3WayControlId[_ValveId] = AddControlCallback("Valve3WayControlId", Valve3WayCallBackFunction, eOneSecond/*eHundredMillisecond*/, FPGA_GetDispenserValveBusyOCD,(IfTypeDisopenser*0x100+_ValveId), _ValveId, 0 ); if (Valve3WayControlId[_ValveId] == 0xFF) Report("Add control callback failed",__FILE__,__LINE__,(int)_ValveId,RpWarning,(int)Valve3WayControlId[_ValveId],0); //else -- cgit v1.3.1