/************************************************************************** * * 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 "ModeFill.h" #include "OperationModes.h" #include "Timers.h" #ifdef RM46_EVAL_BOARD_TARGET #include "CPLD.h" #endif // ********** private data ********** static volatile enum FillModeSubModes { CHECK_INLET_WATER = 0, CREATE_PRODUCT_WATER, DIALYSATE_PRODUCTION, DELIVER_DIALYSATE } fillCurrentSubMode; static U32 timer; static U16 toggle_counter = 0; #define QUARTER_SECOND 250 #define HALF_SECOND 500 // ********** private function prototypes ********** /************************************************************************* * @brief initFillMode * The initFillMode function initializes the Fill Mode module. * @details * Inputs : none * Outputs : Fill Mode module initialized. * @param none * @return none *************************************************************************/ void initFillMode( void ) { fillCurrentSubMode = CHECK_INLET_WATER; timer = getMSTimerCount(); } /************************************************************************* * @brief transitionToFillMode * The transitionToFillMode function prepares for transition to \n * fill mode. * @details * Inputs : none * Outputs : * @param none * @return none *************************************************************************/ void transitionToFillMode( void ) { fillCurrentSubMode = CHECK_INLET_WATER; timer = getMSTimerCount(); toggle_counter = 0; } /************************************************************************* * @brief execFillMode * The execFillMode function executes the Fill Mode state machine. * @details * Inputs : none * Outputs : * @param none * @return none *************************************************************************/ void execFillMode( void ) { switch (fillCurrentSubMode){ case CHECK_INLET_WATER: // We check every half second to toggle LED if (TRUE == didTimeout(timer, QUARTER_SECOND)) { timer = getMSTimerCount(); // Reset timer #ifdef RM46_EVAL_BOARD_TARGET toggleUserLED(); #endif toggle_counter++; } if (toggle_counter == 8) { toggle_counter = 0; // switch to submode fillCurrentSubMode = CREATE_PRODUCT_WATER; } break; case CREATE_PRODUCT_WATER: // We check every half second to toggle LED if (TRUE == didTimeout(timer, HALF_SECOND)) { timer = getMSTimerCount(); // Reset timer #ifdef RM46_EVAL_BOARD_TARGET toggleUserLED(); #endif toggle_counter++; } if (toggle_counter == 4) { toggle_counter = 0; // switch to submode fillCurrentSubMode = DIALYSATE_PRODUCTION; } break; case DIALYSATE_PRODUCTION: // We check every half second to toggle LED if (TRUE == didTimeout(timer, HALF_SECOND + QUARTER_SECOND)) { timer = getMSTimerCount(); // Reset timer #ifdef RM46_EVAL_BOARD_TARGET toggleUserLED(); #endif toggle_counter++; } if (toggle_counter == 4) { toggle_counter = 0; // switch to submode fillCurrentSubMode = DELIVER_DIALYSATE; } break; case DELIVER_DIALYSATE: if(toggle_counter == 0) { #ifdef RM46_EVAL_BOARD_TARGET setUserLED(TRUE); #endif toggle_counter++; } break; } }