Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r499e5de29e706d09f79ba22511068990c4044e84 -r4fa5628781e2b420cad6afc42a4b754dd484b997 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 499e5de29e706d09f79ba22511068990c4044e84) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -14,151 +14,170 @@ * **************************************************************************/ -#include "ModeFill.h" #include "OperationModes.h" #include "Timers.h" +#include "ModeFill.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; +// ********** private definitions ********** -static U32 timer; -static U16 toggle_counter = 0; - #define QUARTER_SECOND 250 #define HALF_SECOND 500 +typedef enum Fill_Mode_States +{ + FILL_MODE_STATE_START = 0, + FILL_MODE_STATE_CHECK_INLET_WATER, + FILL_MODE_STATE_CREATE_PRODUCT_WATER, + FILL_MODE_STATE_DIALYSATE_PRODUCTION, + FILL_MODE_STATE_DELIVER_DIALYSATE, + NUM_OF_FILL_MODE_STATES +} FILL_MODE_STATE_T; +// ********** private data ********** + +static FILL_MODE_STATE_T fillState; + // ********** 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 ); + +/*********************************************************************//** * @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(); + fillState = FILL_MODE_STATE_START; } -/************************************************************************* +/*********************************************************************//** * @brief transitionToFillMode * The transitionToFillMode function prepares for transition to \n * fill mode. * @details * Inputs : none - * Outputs : - * @param none + * Outputs : fillState * @return none *************************************************************************/ void transitionToFillMode( void ) { - fillCurrentSubMode = CHECK_INLET_WATER; - timer = getMSTimerCount(); - toggle_counter = 0; + fillState = FILL_MODE_STATE_START; } -/************************************************************************* +/*********************************************************************//** * @brief execFillMode * The execFillMode function executes the Fill Mode state machine. * @details - * Inputs : none - * Outputs : - * @param none + * Inputs : fillState + * Outputs : fillState * @return none *************************************************************************/ void execFillMode( void ) { + // execute current Fill state + switch ( fillState ) + { + case FILL_MODE_STATE_START: + fillState = FILL_MODE_STATE_CHECK_INLET_WATER; + break; - switch (fillCurrentSubMode){ + case FILL_MODE_STATE_CHECK_INLET_WATER: + fillState = handleCheckInletWaterState(); + break; - case CHECK_INLET_WATER: + case FILL_MODE_STATE_CREATE_PRODUCT_WATER: + fillState = handleCreateProductWaterState(); + break; - // 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++; - } + case FILL_MODE_STATE_DIALYSATE_PRODUCTION: + fillState = handleDialysateProductionState(); + break; - if (toggle_counter == 8) - { - toggle_counter = 0; + case FILL_MODE_STATE_DELIVER_DIALYSATE: + fillState = handleDeliverDialysateState(); + break; - // switch to submode - fillCurrentSubMode = CREATE_PRODUCT_WATER; - } - + default: + // TODO - s/w fault break; + } +} - case CREATE_PRODUCT_WATER: +/*********************************************************************//** + * @brief + * The handleCheckInletWaterState function executes the Check Inlet Water \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 ) +{ + FILL_MODE_STATE_T result = FILL_MODE_STATE_CHECK_INLET_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++; - } + return result; +} - if (toggle_counter == 4) - { - toggle_counter = 0; +/*********************************************************************//** + * @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; - // switch to submode - fillCurrentSubMode = DIALYSATE_PRODUCTION; - } - break; + return result; +} - 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++; - } +/*********************************************************************//** + * @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; - if (toggle_counter == 4) - { - toggle_counter = 0; + return result; +} - // switch to submode - fillCurrentSubMode = DELIVER_DIALYSATE; - } - break; +/*********************************************************************//** + * @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; - case DELIVER_DIALYSATE: - - if(toggle_counter == 0) - { - #ifdef RM46_EVAL_BOARD_TARGET - setUserLED(TRUE); - #endif - toggle_counter++; - } - break; - } + return result; } - Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rf267c42c91fd6e22db80e19039b8993582de51e9 -r4fa5628781e2b420cad6afc42a4b754dd484b997 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision f267c42c91fd6e22db80e19039b8993582de51e9) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) @@ -107,10 +107,12 @@ STANDBY_MODE_STATE_T result = STANDBY_MODE_STATE_IDLE; // go to standby or standby solo mode depending on whether HD is connected -// if ( FALSE == isHDCommunicating() ) +// if ( FALSE == isHDCommunicating() ) // TODO - handle switching between standby and standby-solo modes // { // requestNewOperationMode( MODE_SOLO ); // } + // TODO - what is DG supposed to be doing while in standby mode? + return result; } Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r0774a37971585dacdc8398362393920c13d48426 -r4fa5628781e2b420cad6afc42a4b754dd484b997 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 0774a37971585dacdc8398362393920c13d48426) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) @@ -40,9 +40,9 @@ } FPGA_STATE_T; #define FPGA_PAGE_SIZE 256 -#define FPGA_EXPECTED_ID 0x59 +#define FPGA_EXPECTED_ID 0x60 -#define FPGA_HEADER_START_ADDR 256 // update these after re-arranging w/ Randy +#define FPGA_HEADER_START_ADDR 256 // TODO - update these after re-arranging w/ Randy #define FPGA_BULK_READ_START_ADDR 262 #define FPGA_BULK_WRITE_START_ADDR 2 @@ -74,44 +74,34 @@ { U08 fpgaId; U08 fpgaRev; - U16 fpgaControl; - U16 fpgaStatus; + U16 fpgaADC1Control; + U08 fpagDiag; + U08 reserved1; + U16 fpagADC2Control; + U16 fpagRTDControl; } FPGA_HEADER_T; // read only on FPGA typedef struct // TODO - add all sensor readings to this structure per FPGA register map { + U08 fpgaId; + U08 fpgaRev; + U16 fpgaADC1Control; + U16 fpgaStatus; + U08 fpgaIOErrorCntProcessor; + U08 fpgaIOErrorCntPC; + U32 reserved1; + U32 reserved2; + U32 reserved3; + U32 reserved4; + U32 reserved5; + U32 reserved6; + U32 reserved7; + U32 reserved8; + U32 reserved9; U32 LCA1; U32 LCA2; U32 LCB1; U32 LCB2; - - //U08 bloodFlowMeterDataPktCount; - //U08 bloodFlowMeterSlowPktCounts; - //U08 bloodFlowMeterDeviceStatus; - //U08 bloodFlowMeterResponse; - //F32 bloodFlowLast; - //U08 dialysateFlowMeterDataPktCount; - //U08 dialysateFlowMeterSlowPckCounts; - //U08 dialysateFlowMeterDeviceStatus; - //U08 dialysateFlowMeterResponse; - //F32 dialysateFlowLast; - - U08 bloodFlowMeterErrorCount; - U08 dialysateFlowMeterErrorCount; - U16 bloodOcclusionData; - U08 bloodOcclusionReadCount; - U08 bloodOcclusionErrorCount; - U16 dialysateInOcclusionData; - U08 dialysateInOcclusionReadCount; - U08 dialysateInOcclusionErrorCount; - U16 dialysateOutOcclusionData; - U08 dialysateOutOcclusionReadCount; - U08 dialysateOutOcclusionErrorCount; - U16 arterialPressureData; - U08 arterialPressureReadCount; - U08 arterialPressureErrorCount; - U16 dialysateTempPrimaryData; - U16 dialysateTempBackupData; } DG_FPGA_SENSORS_T; typedef struct // TODO - add all actuator set points to this structure per FPGA register map @@ -560,8 +550,7 @@ fpgaWriteCmdBuffer[ FPGA_WRITE_CMD_HDR_LEN + sizeof( FPGA_ACTUATORS_T ) + 1 ] = GET_LSB_OF_WORD( crc ); // construct bulk read command to read sensor data registers starting at address 8 fpgaReadCmdBuffer[ 0 ] = FPGA_READ_CMD_CODE; - //fpgaReadCmdBuffer[ 1 ] = 0x08; // start at FPGA address 0x108 (264) - fpgaReadCmdBuffer[ 1 ] = 0x2C; // start at FPGA address 0x108 (264) + fpgaReadCmdBuffer[ 1 ] = 0x00; // start at FPGA address 0x100 (256) fpgaReadCmdBuffer[ 2 ] = 0x01; fpgaReadCmdBuffer[ 3 ] = sizeof(DG_FPGA_SENSORS_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); @@ -875,24 +864,10 @@ *************************************************************************/ U16 getFPGAStatus( void ) { - return fpgaHeader.fpgaStatus; + return fpgaSensorReadings.fpgaStatus; } /************************************************************************* - * @brief getFPGADiag - * The getFPGADiag function sets the diagnostic register of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param ctrl : value to write to diagnostic register - * @return none - *************************************************************************/ -void setFPGAControl( U16 ctrl ) -{ - fpgaHeader.fpgaControl = ctrl; -} - -/************************************************************************* * @brief getFPGALoadCellA1 * The getFPGALoadCellA1 function gets the latest load cell A 1 reading. * @details @@ -948,92 +923,7 @@ return fpgaSensorReadings.LCB2; } - /************************************************************************* - * @brief getFPGABloodPumpOcclusion - * The getFPGABloodPumpOcclusion function gets the latest blood occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last blood occlusion reading - *************************************************************************/ -U16 getFPGABloodPumpOcclusion( void ) -{ - return fpgaSensorReadings.bloodOcclusionData; -} - -/************************************************************************* - * @brief getFPGADialInPumpOcclusion - * The getFPGADialInPumpOcclusion function gets the latest dialysate \n - * inlet occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last dialysate inlet occlusion reading - *************************************************************************/ -U16 getFPGADialInPumpOcclusion( void ) -{ -#ifdef DEBUG_ENABLED -// { -// // TODO - temporary debug code - remove later -// char debugOccStr[ 60 ]; -// S32 dat = fpgaSensorReadings.dialysateInOcclusionData; -// S32 rct = fpgaSensorReadings.dialysateInOcclusionReadCount; -// S32 ect = fpgaSensorReadings.dialysateInOcclusionErrorCount; -// -// sprintf( debugOccStr, "Data %5d Reads %5d Errors %5d\n", dat, rct, ect ); -// sendDebugData( (U08*)debugOccStr, strlen(debugOccStr) ); -// } -#endif - return fpgaSensorReadings.dialysateInOcclusionData; -} - -/************************************************************************* - * @brief getFPGADialOutPumpOcclusion - * The getFPGADialOutPumpOcclusion function gets the latest dialysate \n - * outlet occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last dialysate outlet occlusion reading - *************************************************************************/ -U16 getFPGADialOutPumpOcclusion( void ) -{ - return fpgaSensorReadings.dialysateOutOcclusionData; -} - -/************************************************************************* - * @brief getFPGAArterialPressure - * The getFPGAArterialPressure function gets the latest arterial pressure reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last arterial pressure reading - *************************************************************************/ -U16 getFPGAArterialPressure( void ) -{ - return fpgaSensorReadings.arterialPressureData; -} - -/************************************************************************* - * @brief getFPGAVenousPressure - * The getFPGAVenousPressure function gets the venous arterial pressure reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last venous pressure reading - *************************************************************************/ -U16 getFPGAVenousPressure( void ) -{ - return 0; // TODO - return reading when available -} - -/************************************************************************* * @brief consumeUnexpectedData * The consumeUnexpectedData function checks to see if a byte is sitting in \n * the SCI2 received data register. Index: firmware/App/Services/FPGA.h =================================================================== diff -u -rb64c49fdcf2b6d95e61e63f8e258c4e600935bbd -r4fa5628781e2b420cad6afc42a4b754dd484b997 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision b64c49fdcf2b6d95e61e63f8e258c4e600935bbd) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) @@ -33,17 +33,9 @@ void signalFPGATransmitCompleted( void ); U16 getFPGAStatus( void ); -void setFPGAControl( U16 ctrl ); U32 getFPGALoadCellA1( void ); U32 getFPGALoadCellA2( void ); U32 getFPGALoadCellB1( void ); U32 getFPGALoadCellB2( void ); -F32 getFPGABloodFlow( void ); -F32 getFPGADialysateFlow( void ); -U16 getFPGAArterialPressure( void ); -U16 getFPGAVenousPressure( void ); -U16 getFPGABloodPumpOcclusion( void ); -U16 getFPGADialInPumpOcclusion( void ); -U16 getFPGADialOutPumpOcclusion( void ); #endif