/**********************************************************************//** * * 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 "ModeFill.h" /** * @addtogroup FillMode * @{ */ // ********** private definitions ********** #define QUARTER_SECOND 250 #define HALF_SECOND 500 /// Enumeration of fill mode states. typedef enum Fill_Mode_States { FILL_MODE_STATE_START = 0, ///< Start fill mode 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. // ********** private function prototypes ********** static FILL_MODE_STATE_T handleDialysateProductionState( void ); static 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 = 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 // Conc. pumps on } /*********************************************************************//** * @brief execFillMode * The execFillMode function executes the Fill Mode state machine. * @details * Inputs : fillState * Outputs : fillState * @return none *************************************************************************/ void execFillMode( void ) { // execute current Fill state switch ( fillState ) { case FILL_MODE_STATE_START: fillState = FILL_MODE_STATE_DIALYSATE_PRODUCTION; break; case FILL_MODE_STATE_DIALYSATE_PRODUCTION: fillState = handleDialysateProductionState(); break; case 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; break; } } /*********************************************************************//** * @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 FILL_MODE_STATE_T handleDialysateProductionState( void ) { FILL_MODE_STATE_T result = FILL_MODE_STATE_DIALYSATE_PRODUCTION; // TODO - transition when temperature and mix is in range if ( 1 ) { // TODO - VPo to reservoir setFPGAValveStates(0x015F); result = 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 FILL_MODE_STATE_T handleDeliverDialysateState( void ) { FILL_MODE_STATE_T result = FILL_MODE_STATE_DELIVER_DIALYSATE; // TODO - transition back when temperature or mix out of range if ( 0 ) { // TODO - VPo to drain setFPGAValveStates(0x014F); result = FILL_MODE_STATE_DIALYSATE_PRODUCTION; } return result; } /**@}*/