Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -rf43eb1e9e0803776ec7420b16e1db8760b020bd9 -r4c20f6a3d8c8ff33d2dff4ba27e0732c7614378b --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision f43eb1e9e0803776ec7420b16e1db8760b020bd9) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 4c20f6a3d8c8ff33d2dff4ba27e0732c7614378b) @@ -14,16 +14,16 @@ * **************************************************************************/ +#include "FPGA.h" +#include "LoadCell.h" #include "OperationModes.h" +#include "Reservoirs.h" #include "Timers.h" +#include "Valves.h" #include "ModeFill.h" -#ifdef RM46_EVAL_BOARD_TARGET - #include "CPLD.h" -#endif - /** - * @addtogroup FillMode + * @addtogroup DGFillMode * @{ */ @@ -32,27 +32,14 @@ #define QUARTER_SECOND 250 #define HALF_SECOND 500 -/// Enumberation of fill mode states. -typedef enum Fill_Mode_States -{ - FILL_MODE_STATE_START = 0, ///< Start fill mode state. - FILL_MODE_STATE_CHECK_INLET_WATER, ///< Check inlet water state. - FILL_MODE_STATE_CREATE_PRODUCT_WATER, ///< Create product water state. - FILL_MODE_STATE_DIALYSATE_PRODUCTION, ///< Dialysate production state. - FILL_MODE_STATE_DELIVER_DIALYSATE, ///< Deliver dialysate state. - NUM_OF_FILL_MODE_STATES ///< Number of fill mode states. -} FILL_MODE_STATE_T; - // ********** private data ********** -static FILL_MODE_STATE_T fillState; ///< Currently active fill state. +static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. // ********** private function prototypes ********** -static FILL_MODE_STATE_T handleCheckInletWaterState( void ); -static FILL_MODE_STATE_T handleCreateProductWaterState( void ); -static FILL_MODE_STATE_T handleDialysateProductionState( void ); -static FILL_MODE_STATE_T handleDeliverDialysateState( void ); +static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ); +static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ); /*********************************************************************//** * @brief initFillMode @@ -64,7 +51,7 @@ *************************************************************************/ void initFillMode( void ) { - fillState = FILL_MODE_STATE_START; + fillState = DG_FILL_MODE_STATE_START; } /*********************************************************************//** @@ -78,7 +65,13 @@ *************************************************************************/ void transitionToFillMode( void ) { - fillState = FILL_MODE_STATE_START; + // re-initialize fill mode each time we transition to fill mode + initFillMode(); + + // set initial actuator states + setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); + // Conc. pumps on } /*********************************************************************//** @@ -87,106 +80,112 @@ * @details * Inputs : fillState * Outputs : fillState - * @return none + * @return current state. *************************************************************************/ -void execFillMode( void ) +U32 execFillMode( void ) { // execute current Fill state switch ( fillState ) { - case FILL_MODE_STATE_START: - fillState = FILL_MODE_STATE_CHECK_INLET_WATER; + case DG_FILL_MODE_STATE_START: + fillState = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; break; - case FILL_MODE_STATE_CHECK_INLET_WATER: - fillState = handleCheckInletWaterState(); - break; - - case FILL_MODE_STATE_CREATE_PRODUCT_WATER: - fillState = handleCreateProductWaterState(); - break; - - case FILL_MODE_STATE_DIALYSATE_PRODUCTION: + case DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION: fillState = handleDialysateProductionState(); break; - case FILL_MODE_STATE_DELIVER_DIALYSATE: + case DG_FILL_MODE_STATE_DELIVER_DIALYSATE: fillState = handleDeliverDialysateState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, 0, fillState ) // TODO - add s/w fault enum to 1st data param - fillState = FILL_MODE_STATE_START; + fillState = DG_FILL_MODE_STATE_START; break; } + + return fillState; } /*********************************************************************//** * @brief - * The handleCheckInletWaterState function executes the Check Inlet Water \n + * The handleDialysateProductionState function executes the Dialysate Production \n * state of the Fill Mode state machine. * @details * Inputs : none * Outputs : * @param none * @return the next state *************************************************************************/ -static FILL_MODE_STATE_T handleCheckInletWaterState( void ) +static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ) { - FILL_MODE_STATE_T result = FILL_MODE_STATE_CHECK_INLET_WATER; + DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; - return result; -} + // TODO - transition when temperature and mix is in range + if ( 1 ) + { + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); + result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; + } -/*********************************************************************//** - * @brief - * The handleCreateProductWaterState function executes the Create Product \n - * Water state of the Fill Mode state machine. - * @details - * Inputs : none - * Outputs : - * @param none - * @return the next state - *************************************************************************/ -static FILL_MODE_STATE_T handleCreateProductWaterState( void ) -{ - FILL_MODE_STATE_T result = FILL_MODE_STATE_CREATE_PRODUCT_WATER; - return result; } /*********************************************************************//** * @brief - * The handleDialysateProductionState function executes the Dialysate Production \n + * The handleDeliverDialysateState function executes the Deliver Dialysate \n * state of the Fill Mode state machine. * @details * Inputs : none * Outputs : * @param none * @return the next state *************************************************************************/ -static FILL_MODE_STATE_T handleDialysateProductionState( void ) +static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ) { - FILL_MODE_STATE_T result = FILL_MODE_STATE_DIALYSATE_PRODUCTION; + DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; + LOAD_CELL_ID_T fillWeightLoadCell = LOAD_CELL_A1; + // TODO - transition back when temperature or mix out of range + if ( 0 ) + { + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); + result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + } + + + // determine which load cell to use for fill volume - we want weight of inactive reservoir +#ifndef BETA_V1_BUILD + if ( RESERVOIR_1 == getActiveReservoir() ) +#else + if ( RESERVOIR_2 == getActiveReservoir() ) +#endif + { + fillWeightLoadCell = LOAD_CELL_B1; + } + + // if we've reached our target fill to volume (by weight), we're done filling - go back to re-circ mode + if ( getReservoirFillVolumeTargetMl() <= getLoadCellFilteredWeight( fillWeightLoadCell ) ) + { + requestNewOperationMode( DG_MODE_CIRC ); + } + return result; } /*********************************************************************//** * @brief - * The handleDeliverDialysateState function executes the Deliver Dialysate \n - * state of the Fill Mode state machine. + * The getCurrentFillState function returns the current state of the \n + * fill mode. * @details - * Inputs : none - * Outputs : - * @param none - * @return the next state + * Inputs : fillState + * Outputs : none + * @return the current state of fill mode. *************************************************************************/ -static FILL_MODE_STATE_T handleDeliverDialysateState( void ) +DG_FILL_MODE_STATE_T getCurrentFillState( void ) { - FILL_MODE_STATE_T result = FILL_MODE_STATE_DELIVER_DIALYSATE; - - return result; + return fillState; } /**@}*/