/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ModeFill.c * * @date 19-Nov-2019 * @author L. Baloa * * @brief Top-level state machine for the fill mode. * **************************************************************************/ #include "FPGA.h" #include "OperationModes.h" #include "Timers.h" #include "Valves.h" #include "ModeFill.h" /** * @addtogroup FillMode * @{ */ // ********** private definitions ********** #define QUARTER_SECOND 250 #define HALF_SECOND 500 // ********** private data ********** static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. // ********** private function prototypes ********** static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ); static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ); /*********************************************************************//** * @brief initFillMode * The initFillMode function initializes the Fill Mode module. * @details * Inputs : none * Outputs : Fill Mode module initialized. * @return none *************************************************************************/ void initFillMode( void ) { fillState = DG_FILL_MODE_STATE_START; } /*********************************************************************//** * @brief transitionToFillMode * The transitionToFillMode function prepares for transition to \n * fill mode. * @details * Inputs : none * Outputs : fillState * @return none *************************************************************************/ void transitionToFillMode( void ) { // re-initialize fill mode each time we transition to fill mode initFillMode(); // TODO - set initial actuator states setFPGAValveStates(0x014F); // VDr, VPo to drain setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); // Conc. pumps on } /*********************************************************************//** * @brief execFillMode * The execFillMode function executes the Fill Mode state machine. * @details * Inputs : fillState * Outputs : fillState * @return current state. *************************************************************************/ U32 execFillMode( void ) { // execute current Fill state switch ( fillState ) { case DG_FILL_MODE_STATE_START: fillState = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; break; case DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION: fillState = handleDialysateProductionState(); break; 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 = DG_FILL_MODE_STATE_START; break; } return fillState; } /*********************************************************************//** * @brief * 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 DG_FILL_MODE_STATE_T handleDialysateProductionState( void ) { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; // 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; } return result; } /*********************************************************************//** * @brief * 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 DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ) { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; // 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; } return result; } /*********************************************************************//** * @brief * The getCurrentFillState function returns the current state of the \n * fill mode. * @details * Inputs : fillState * Outputs : none * @return the current state of fill mode. *************************************************************************/ DG_FILL_MODE_STATE_T getCurrentFillState( void ) { return fillState; } /**@}*/