Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -rdc0d9b087c609e71cacdb7f0395cccf29d749c00 -r5a882c7292cea58e74b5a28d4e85dd60e741b834 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision dc0d9b087c609e71cacdb7f0395cccf29d749c00) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 5a882c7292cea58e74b5a28d4e85dd60e741b834) @@ -20,6 +20,7 @@ #include "etpwm.h" #include "mibspi.h" +#include "DrainPump.h" #include "FPGA.h" #include "OperationModes.h" #include "PIControllers.h" @@ -29,7 +30,6 @@ #include "TaskPriority.h" #include "Timers.h" #include "Valves.h" -#include "DrainPump.h" #ifdef EMC_TEST_BUILD #include "Heaters.h" #endif @@ -41,58 +41,56 @@ // ********** private definitions ********** -#define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the Drain Pump data is published on the CAN bus +#define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval at which the Drain Pump data is published on the CAN bus. +#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval at which the Drain pump is controlled. -#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the Drain pump is controlled +#define DRP_SPEED_ADC_TO_RPM_FACTOR 12.94 ///< conversion factor from ADC counts to RPM for Drain pump. +#define DRP_SPEED_RPM_TO_ADC_FACTOR ( 1.0 / DRP_SPEED_ADC_TO_RPM_FACTOR ) ///< conversion factor from RPM to ADC counts for Drain pump. -#define DRP_SPEED_ADC_TO_RPM_FACTOR 12.94 ///< conversion factor from ADC counts to RPM for Drain pump -#define DRP_SPEED_RPM_TO_ADC_FACTOR ( 1.0 / DRP_SPEED_ADC_TO_RPM_FACTOR ) ///< conversion factor from RPM to ADC counts for Drain pump - /// Enumeration of drain pump states. typedef enum DrainPump_States { - DRAIN_PUMP_OFF_STATE = 0, ///< Drain pump off state. - DRAIN_PUMP_CONTROL_TO_TARGET_STATE, ///< Drain pump control to target state. - NUM_OF_DRAIN_PUMP_STATES ///< Number of drain pump states. + DRAIN_PUMP_OFF_STATE = 0, ///< Drain pump off state + DRAIN_PUMP_CONTROL_TO_TARGET_STATE, ///< Drain pump control to target state + NUM_OF_DRAIN_PUMP_STATES ///< Number of drain pump states } DRAIN_PUMP_STATE_T; /// Enumeration of drain pump self test states. typedef enum DrainPump_Self_Test_States { - DRAIN_PUMP_SELF_TEST_STATE_START = 0, ///< Drain pump self test start state. - DRAIN_PUMP_TEST_STATE_IN_PROGRESS, ///< Drain pump self tests in progress state. - DRAIN_PUMP_TEST_STATE_COMPLETE, ///< Drain pump self tests completed state. - NUM_OF_DRAIN_PUMP_SELF_TEST_STATES ///< Number of drain pump self test states. + DRAIN_PUMP_SELF_TEST_STATE_START = 0, ///< Drain pump self test start state + DRAIN_PUMP_TEST_STATE_IN_PROGRESS, ///< Drain pump self tests in progress state + DRAIN_PUMP_TEST_STATE_COMPLETE, ///< Drain pump self tests completed state + NUM_OF_DRAIN_PUMP_SELF_TEST_STATES ///< Number of drain pump self test states } DRAIN_PUMP_SELF_TEST_STATE_T; -// pin assignment for pump enable -#define DRAIN_PUMP_ENABLE_SPI3_PORT_MASK 0x00000020 // (CS5 - re-purposed as output GPIO) -// drain pump enable macros -#define SET_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 |= DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} -#define CLR_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 &= ~DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} +#define DRAIN_PUMP_ENABLE_SPI3_PORT_MASK 0x00000020 ///< CS5 - Out put GPIO for pump enable. +#define SET_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 |= DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable set macro. +#define CLR_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 &= ~DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable clear macro. // TODO - test code - remove later #define DRAIN_PUMP_TEST2_SPI1_PORT_MASK 0x00000004 // (CS2 - re-purposed as input GPIO) #define GET_DIP_SW2_TEST() ( ( mibspiREG1->PC2 & DRAIN_PUMP_TEST2_SPI1_PORT_MASK ) != 0 ) // ********** private data ********** -static DRAIN_PUMP_STATE_T drainPumpState = DRAIN_PUMP_OFF_STATE; ///< current state of drain pump controller state machine -static U32 drainPumpDataPublicationTimerCounter = 0; ///< used to schedule drain pump data publication to CAN bus -static BOOL isDrainPumpOn = FALSE; ///< Drain pump is currently running -static U32 drainPumpDAC = 0; ///< initial drain pump DAC value -static U32 drainPumpDACSet = 0; ///< currently set drain pump DAC value -static PUMP_CONTROL_MODE_T drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested drain pump control mode. -static PUMP_CONTROL_MODE_T drainPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set drain pump control mode. +static DRAIN_PUMP_STATE_T drainPumpState = DRAIN_PUMP_OFF_STATE; ///< current state of drain pump controller state machine. +static U32 drainPumpDataPublicationTimerCounter = 0; ///< Drain pump data publish timer counter. +static BOOL isDrainPumpOn = FALSE; ///< Flag indicates drain pump is running or off. +static U32 drainPumpDAC = 0; ///< Initial drain pump DAC value. +static U32 drainPumpDACSet = 0; ///< Current set drain pump DAC value. +static PUMP_CONTROL_MODE_T drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested drain pump control mode. +static PUMP_CONTROL_MODE_T drainPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Current set drain pump control mode. -static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, DRAIN_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus. -static OVERRIDE_U32_T targetDrainPumpSpeed = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI). +static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, + DRAIN_PUMP_DATA_PUB_INTERVAL, + 0, 0 }; ///< Drain pump data publish interval. +static OVERRIDE_U32_T targetDrainPumpSpeed = { 0, 0, 0, 0 }; ///< Target drain pump speed. +static U32 drainControlTimerCounter = 0; ///< Timer counter for control drain pump. -static U32 drainControlTimerCounter = 0; ///< determines when to perform control on drain pump +static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState; ///< Current drain pump self test state. +static U32 drainPumpSelfTestTimerCount = 0; ///< Timer counter for drain pump self test. -static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState = DRAIN_PUMP_SELF_TEST_STATE_START; ///< current drain pump self test state -static U32 drainPumpSelfTestTimerCount = 0; ///< timer counter for drain pump self test - // ********** private function prototypes ********** static DRAIN_PUMP_STATE_T handleDrainPumpOffState( void ); @@ -110,14 +108,13 @@ * @return none *************************************************************************/ void initDrainPump( void ) -{ +{ stopDrainPump(); } /*********************************************************************//** * @brief - * The setDrainPumpTargetSpeed function sets a new target speed for the \n - * drain pump. + * The setDrainPumpTargetSpeed function sets a new target speed for the drain pump. * @details * Inputs : none * Outputs : targetDrainPumpPressure @@ -162,10 +159,10 @@ /*********************************************************************//** * @brief - * The execDrainPumpMonitor function executes the Drain Pump monitor. + * The execDrainPumpMonitor function executes the drain pump monitor. * @details * Inputs : none - * Outputs : none + * Outputs : publish drain pump data * @return none *************************************************************************/ void execDrainPumpMonitor( void ) @@ -182,7 +179,7 @@ /*********************************************************************//** * @brief - * The execDrainPumpController function executes the Drain Pump controller. + * The execDrainPumpController function executes the drain pump controller. * @details * Inputs : drainPumpState * Outputs : drainPumpState @@ -205,12 +202,14 @@ drainPumpState = DRAIN_PUMP_OFF_STATE; break; } -} +} +// ********** Private functions ********** + /*********************************************************************//** * @brief - * The handleDrainPumpOffState function handles the drain pump off state \n - * of the drain pump controller state machine. + * The handleDrainPumpOffState function handles the drain pump off state of + * the drain pump controller state machine. * @details * Inputs : targetDrainPumpSpeed * Outputs : drainPumpPWMDutyCyclePctSet, isDrainPumpOn @@ -257,7 +256,7 @@ /*********************************************************************//** * @brief - * The handleDrainPumpControlToTargetState function handles the "control to \n + * The handleDrainPumpControlToTargetState function handles the "control to * target" state of the drain pump controller state machine. * @details * Inputs : none @@ -308,10 +307,10 @@ /*********************************************************************//** * @brief - * The stopDrainPump function sets the Drain pump DAC to zero. + * The stopDrainPump function sets the drain pump DAC to zero. * @details * Inputs : none - * Outputs : isDrainPumpOn, DAC zeroed + * Outputs : isDrainPumpOn, DAC zeroed, clear drain pump enable * @return none *************************************************************************/ static void stopDrainPump( void ) @@ -325,12 +324,12 @@ /*********************************************************************//** * @brief - * The getPublishDrainPumpDataInterval function gets the Drain pump data \n + * The getPublishDrainPumpDataInterval function gets the drain pump data * publication interval. * @details * Inputs : drainPumpDataPublishInterval * Outputs : none - * @return the current Drain pump data publication interval (in ms). + * @return the current drain pump data publication interval (in ms). *************************************************************************/ U32 getPublishDrainPumpDataInterval( void ) { @@ -346,7 +345,7 @@ /*********************************************************************//** * @brief - * The getTargetDrainPumpSpeed function gets the current target Drain pump \n + * The getTargetDrainPumpSpeed function gets the current target drain pump * speed. * @details * Inputs : targetDrainPumpSpeed @@ -367,8 +366,7 @@ /*********************************************************************//** * @brief - * The publishDrainPumpData function publishes drain pump data at the set \n - * interval. + * The publishDrainPumpData function publishes drain pump data at the set interval. * @details * Inputs : target speed * Outputs : Drain pump data is published to CAN bus. @@ -379,21 +377,20 @@ // publish Drain pump data on interval if ( ++drainPumpDataPublicationTimerCounter >= getPublishDrainPumpDataInterval() ) { - U32 spdStPt = getTargetDrainPumpSpeed(); - + U32 const spdStPt = getTargetDrainPumpSpeed(); broadcastDrainPumpData( spdStPt, drainPumpDACSet ); drainPumpDataPublicationTimerCounter = 0; } } /*********************************************************************//** * @brief - * The execDrainPumpTest function executes the state machine for the Drain \n - * Pump self test. + * The execDrainPumpTest function executes the state machine for the drain + * pump self test. * @details * Inputs : none * Outputs : none - * @return the current state of the Drain Pump self test. + * @return the current state of the drain pump self test. *************************************************************************/ SELF_TEST_STATUS_T execDrainPumpTest( void ) { @@ -412,12 +409,12 @@ /*********************************************************************//** * @brief - * The testSetDrainPumpDataPublishIntervalOverride function overrides the \n + * The testSetDrainPumpDataPublishIntervalOverride function overrides the * drain pump data publish interval. * @details * Inputs : none * Outputs : drainPumpDataPublishInterval - * @param value override RO pump data publish interval with (in ms) + * @param value override drain pump data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetDrainPumpDataPublishIntervalOverride( U32 value ) @@ -438,8 +435,8 @@ /*********************************************************************//** * @brief - * The testResetDrainPumpDataPublishIntervalOverride function resets the override \n - * of the drain pump data publish interval. + * The testResetDrainPumpDataPublishIntervalOverride function resets the + * override of the drain pump data publish interval. * @details * Inputs : none * Outputs : drainPumpDataPublishInterval @@ -461,7 +458,7 @@ /*********************************************************************//** * @brief - * The testSetTargetDrainPumpSpeedOverride function overrides the target \n + * The testSetTargetDrainPumpSpeedOverride function overrides the target * drain pump speed (in RPM). * @details * Inputs : none @@ -486,7 +483,7 @@ /*********************************************************************//** * @brief - * The testResetTargetDrainPumpSpeedOverride function resets the override of the \n + * The testResetTargetDrainPumpSpeedOverride function resets the override of the * target drain pump speed (in RPM). * @details * Inputs : none