Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -rdbcbd145954ef52510ac929a412e0dba42f0941b -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision dbcbd145954ef52510ac929a412e0dba42f0941b) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -50,7 +50,6 @@ S16 posA; ///< Calculated Position A S16 posB; ///< Calculated Position B U32 pwm; ///< Valve PWM in the bypass mode - U32 airTrapValve ///< Air trap valve status } HD_VALVE_DATA_T; @@ -71,6 +70,7 @@ S16 cmdPosition; } HD_VALVE_FAST_DATA_T; #pragma pack(pop) +HD_VALVE_FAST_DATA_T fastDataRemoveLater; // TODO REMOVE THE struct // ********** public function prototypes ********* @@ -81,16 +81,14 @@ void execValves( void ); -BOOL homeValve( VALVE_T valve ); +void homeValve( VALVE_T valve ); BOOL setValvePosition( VALVE_T valve, VALVE_POSITION_T position ); VALVE_POSITION_T getValvePosition( VALVE_T valve ); void setValveAirTrap( OPN_CLS_STATE_T state ); -OPN_CLS_STATE_T getValveAirTrapStatus( void ); - BOOL testSetValvesDataPublishInterval( U32 value ); BOOL testResetValvesDataPublishInterval( void ); Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -23,7 +23,9 @@ #include "Dialysis.h" #include "DialInFlow.h" #include "DialOutFlow.h" +#include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Timers.h" #include "ModeTreatment.h" @@ -39,8 +41,12 @@ #define MAX_UF_RATE_ACCURACY_ERROR_ML_HR 100.0 ///< Maximum ultrafiltration rate accuracy error in mL/hr over each hour of treatment. #define MAX_UF_RATE_ACCURACY_ERROR_PCT 0.05 ///< Minimum ultrafilteration rate accuracy in percentage of set point (5%) over each hour of treatment. #define MAX_UF_ACCURACY_ERROR_ML 250.0 ///< Maximum ultrafiltration accuracy error in mL over the entire treatment. -#define UF_ACCURACY_CHECK_INTERVAL ((1 * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND) / TASK_GENERAL_INTERVAL) ///< Ultrafiltration rate accuracy check interval count +/// Ultrafiltration rate accuracy check interval count +#define UF_ACCURACY_CHECK_INTERVAL ((1 * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND) / TASK_GENERAL_INTERVAL) +#define MAX_SALINE_VOLUME_DELIVERED 800.0 ///< Maximum saline volume delivered for a treatment. +#define SALINE_BOLUS_RATE_ML_MIN 150 ///< Fixed rate for saline bolus delivery. + // ********** private data ********** static DIALYSIS_STATE_T currentDialysisState; ///< Current state of the dialysis sub-mode state machine. @@ -60,8 +66,15 @@ static U32 setDialysateFlowRate; ///< Currently set dialysate flow rate (from prescription). static F32 maxUFVolumeML; ///< Currently set total ultrafiltration volume for treatment (from prescription). static F32 setUFRate; ///< Currently set ultrafiltration rate (from prescription). -static F32 maxUFRateAccuracyError_Ml_hr; ///< Minimum ultrafiltration rate accuracy over 1 hour duration (5% or 100 mL, whichever is greater). +static F32 maxUFRateAccuracyError_Ml_hr; ///< Minimum ultrafiltration rate accuracy over 1 hour duration (5% or 100 mL, whichever is greater). +static BOOL salineBolusStartRequested; ///< Flag indicates a saline bolus start has been requested by user. +static BOOL salineBolusAbortRequested; ///< Flag indicates a salien bolus abort has been requested by user. +static BOOL salineBolusAutoResumeUF; ///< Flag indicates UF should be auto-resumed after saline bolus completes. +static F32 totalSalineVolumeDelivered; ///< Volume (mL) in total of saline delivered so far (cumulative for all boluses including current one). +static F32 bolusSalineVolumeDelivered; ///< Volume (mL) of current bolus delivered so far. +static F32 bolusSalineVolumeDelivered_Safety; ///< Volume (mL) of current bolus delivered so far according to safety monitor. + static U32 uFAccuracyCheckTimerCtr; ///< Timer counter to determine when next to check ultrafiltration accuracy. static F32 lastUFVolumeChecked; ///< Starting ultrafiltration volume for accuracy check. @@ -70,12 +83,16 @@ static DIALYSIS_STATE_T handleDialysisUltrafiltrationState( void ); static DIALYSIS_STATE_T handleDialysisSalineBolusState( void ); -static UF_STATE_T handleUFStartState( void ); -static UF_STATE_T handleUFPausedState( void ); -static UF_STATE_T handleUFRunningState( void ); -static UF_STATE_T handleUFOffState( void ); -static UF_STATE_T handleUFCompletedState( void ); +static UF_STATE_T handleUFStartState( DIALYSIS_STATE_T *dialysisState ); +static UF_STATE_T handleUFPausedState( DIALYSIS_STATE_T *dialysisState ); +static UF_STATE_T handleUFRunningState( DIALYSIS_STATE_T *dialysisState ); +static UF_STATE_T handleUFOffState( DIALYSIS_STATE_T *dialysisState ); +static UF_STATE_T handleUFCompletedState( DIALYSIS_STATE_T *dialysisState ); +static SALINE_BOLUS_STATE_T handleSalineBolusIdleState( DIALYSIS_STATE_T *dialysisState ); +static SALINE_BOLUS_STATE_T handleSalineBolusInProgressState( DIALYSIS_STATE_T *dialysisState ); +static SALINE_BOLUS_STATE_T handleSalineBolusMaxDeliveredState( DIALYSIS_STATE_T *dialysisState ); + static void checkUFAccuracyAndVolume( void ); static void updateUFVolumes( void ); @@ -112,6 +129,10 @@ setUFRate = 0.0; maxUFRateAccuracyError_Ml_hr = MAX_UF_RATE_ACCURACY_ERROR_ML_HR; + salineBolusStartRequested = FALSE; + salineBolusAbortRequested = FALSE; + salineBolusAutoResumeUF = FALSE; + uFAccuracyCheckTimerCtr = 0; lastUFVolumeChecked = 0.0; } @@ -222,6 +243,90 @@ /*********************************************************************//** * @brief + * The signalStartSalineBolus function handles user request to initiate a + * saline bolus. + * @details Inputs: TBD + * @details Outputs: TBD + * @return none + *************************************************************************/ +void signalStartSalineBolus( void ) +{ + BOOL accept = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + U32 salineBolusVolume = getTreatmentParameterU32( TREATMENT_PARAM_SALINE_BOLUS_VOLUME ); + HD_OP_MODE_T currOpMode = getCurrentOperationMode(); + TREATMENT_STATE_T currTreatSubMode = getTreatmentState(); + SALINE_BOLUS_STATE_T currSalineBolusState = getSalineBolusState(); + + // must be in treatment mode, dialysis sub-mode, saline bolus in idle state in order to start a saline bolus + if ( currOpMode != MODE_TREA ) + { + rejReason = REQUEST_REJECT_REASON_NOT_IN_TREATMENT_MODE; + } + else if ( currTreatSubMode != TREATMENT_DIALYSIS_STATE ) + { + rejReason = REQUEST_REJECT_REASON_INVALID_TREATMENT_STATE; + } + else if ( currSalineBolusState != SALINE_BOLUS_STATE_IDLE ) + { + rejReason = REQUEST_REJECT_REASON_SALINE_BOLUS_IN_PROGRESS; + } + else if ( totalSalineVolumeDelivered >= MAX_SALINE_VOLUME_DELIVERED ) + { + rejReason = REQUEST_REJECT_REASON_SALINE_MAX_VOLUME_REACHED; + } + else + { + accept = TRUE; + salineBolusStartRequested = TRUE; + } + + // send response + sendSalineBolusResponse( accept, rejReason, salineBolusVolume ); +} + +/*********************************************************************//** + * @brief + * The signalAbortSalineBolus function handles user request to abort a + * saline bolus. + * @details Inputs: TBD + * @details Outputs: TBD + * @return none + *************************************************************************/ +void signalAbortSalineBolus( void ) +{ + BOOL accept = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + U32 salineBolusVolume = getTreatmentParameterU32( TREATMENT_PARAM_SALINE_BOLUS_VOLUME ); + HD_OP_MODE_T currOpMode = getCurrentOperationMode(); + TREATMENT_STATE_T currTreatSubMode = getTreatmentState(); + SALINE_BOLUS_STATE_T currSalineBolusState = getSalineBolusState(); + + // must be in treatment mode, dialysis sub-mode, saline bolus in delivery state in order to abort a saline bolus + if ( currOpMode != MODE_TREA ) + { + rejReason = REQUEST_REJECT_REASON_NOT_IN_TREATMENT_MODE; + } + else if ( currTreatSubMode != TREATMENT_DIALYSIS_STATE ) + { + rejReason = REQUEST_REJECT_REASON_INVALID_TREATMENT_STATE; + } + else if ( currSalineBolusState != SALINE_BOLUS_STATE_IN_PROGRESS ) + { + rejReason = REQUEST_REJECT_REASON_SALINE_BOLUS_NOT_IN_PROGRESS; + } + else + { + accept = TRUE; + salineBolusAbortRequested = TRUE; + } + + // send response + sendSalineBolusResponse( accept, rejReason, salineBolusVolume ); +} + +/*********************************************************************//** + * @brief * The getDialysisState function gets the current dialysis state (sub-mode). * @details * Inputs : currentDialysisState @@ -425,27 +530,28 @@ switch ( currentUFState ) { case UF_START_STATE: - currentUFState = handleUFStartState(); + currentUFState = handleUFStartState( &result ); break; case UF_PAUSED_STATE: - currentUFState = handleUFPausedState(); + currentUFState = handleUFPausedState( &result ); break; case UF_RUNNING_STATE: - currentUFState = handleUFRunningState(); + currentUFState = handleUFRunningState( &result ); break; case UF_OFF_STATE: - currentUFState = handleUFOffState(); + currentUFState = handleUFOffState( &result ); break; case UF_COMPLETED_STATE: - currentUFState = handleUFCompletedState(); + currentUFState = handleUFCompletedState( &result ); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYSIS_INVALID_UF_STATE, currentUFState ) + currentUFState = UF_COMPLETED_STATE; break; } @@ -465,8 +571,26 @@ { DIALYSIS_STATE_T result = DIALYSIS_SALINE_BOLUS_STATE; - // TODO - + switch ( currentSalineBolusState ) + { + case SALINE_BOLUS_STATE_IDLE: + currentSalineBolusState = handleSalineBolusIdleState( &result ); + break; + case SALINE_BOLUS_STATE_IN_PROGRESS: + currentSalineBolusState = handleSalineBolusInProgressState( &result ); + break; + + case SALINE_BOLUS_STATE_MAX_DELIVERED: + currentSalineBolusState = handleSalineBolusMaxDeliveredState( &result ); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYSIS_INVALID_SALINE_BOLUS_STATE, currentSalineBolusState ) + currentSalineBolusState = SALINE_BOLUS_STATE_MAX_DELIVERED; + break; + } + return result; } @@ -478,9 +602,10 @@ * Inputs : maxUFVolumeML * Outputs : if ultrafiltration prescribed, ultrafiltration time is * initialized. + * @param dialysisState next dialysis state * @return next ultrafiltration state. *************************************************************************/ -static UF_STATE_T handleUFStartState( void ) +static UF_STATE_T handleUFStartState( DIALYSIS_STATE_T *dialysisState ) { UF_STATE_T result; @@ -505,15 +630,38 @@ * @details * Inputs : none * Outputs : if ultrafiltration resumption requested, UF time is set to resume. + * @param dialysisState next dialysis state * @return next ultrafiltration state. *************************************************************************/ -static UF_STATE_T handleUFPausedState( void ) +static UF_STATE_T handleUFPausedState( DIALYSIS_STATE_T *dialysisState ) { UF_STATE_T result = UF_PAUSED_STATE; // calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); + // handle saline bolus start request from user + if ( TRUE == salineBolusStartRequested ) + { + salineBolusAutoResumeUF = FALSE; + // go to saline bolus state + if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) + { + *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; + } + } + // handle auto-resume after saline bolus + else if ( TRUE == salineBolusAutoResumeUF ) + { + salineBolusAutoResumeUF = FALSE; + // set outlet pump to dialysate rate + set UF rate + setDialOutPumpTargetRate( setDialysateFlowRate + FLOAT_TO_INT_WITH_ROUND( setUFRate ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // restart UF time accumulation for reference volume calculation + lastUFTimeStamp = getMSTimerCount(); + // resume UF + result = UF_RUNNING_STATE; + } + // TODO - test code - remove later if ( TRUE == isStopButtonPressed() ) { @@ -532,9 +680,10 @@ * Inputs : ms timer, lastUFTimeStamp * Outputs : UF timer incremented, UF volumes updated and provided to DPo * pump controller. + * @param dialysisState next dialysis state * @return next ultrafiltration state. *************************************************************************/ -static UF_STATE_T handleUFRunningState( void ) +static UF_STATE_T handleUFRunningState( DIALYSIS_STATE_T *dialysisState ) { UF_STATE_T result = UF_RUNNING_STATE; U32 newTime = getMSTimerCount(); @@ -555,6 +704,21 @@ { result = UF_COMPLETED_STATE; } + // handle saline bolus start request from user + else if ( TRUE == salineBolusStartRequested ) + { + if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) + { + // set outlet pump to dialysate rate + setDialOutPumpTargetRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // since we were doing UF prior to saline bolus, we want to auto-resume when done + salineBolusAutoResumeUF = TRUE; + // go to UF paused state + result = UF_PAUSED_STATE; + // go to saline bolus state + *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; + } + } // TODO - test code - remove later if ( TRUE == isStopButtonPressed() ) @@ -573,15 +737,27 @@ * @details * Inputs : none * Outputs : UF volumes updated and provided to DPo pump controller. + * @param dialysisState next dialysis state * @return next ultrafiltration state *************************************************************************/ -static UF_STATE_T handleUFOffState( void ) +static UF_STATE_T handleUFOffState( DIALYSIS_STATE_T *dialysisState ) { UF_STATE_T result = UF_OFF_STATE; // calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); + // handle saline bolus start request from user + if ( TRUE == salineBolusStartRequested ) + { + salineBolusAutoResumeUF = FALSE; + // go to saline bolus state + if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) + { + *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; + } + } + return result; } @@ -592,20 +768,86 @@ * @details * Inputs : none * Outputs : UF volumes updated and provided to DPo pump controller. + * @param dialysisState next dialysis state * @return next ultrafiltration state *************************************************************************/ -static UF_STATE_T handleUFCompletedState( void ) +static UF_STATE_T handleUFCompletedState( DIALYSIS_STATE_T *dialysisState ) { UF_STATE_T result = UF_COMPLETED_STATE; // calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); + // handle saline bolus start request from user + if ( TRUE == salineBolusStartRequested ) + { + salineBolusAutoResumeUF = FALSE; + // go to saline bolus state + if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) + { + *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; + } + } + return result; } /*********************************************************************//** * @brief + * The handleSalineBolusIdleState function handles the idle state of the + * saline bolus state machine. + * @details Inputs: none + * @details Outputs: + * @param dialysisState next dialysis state + * @return next saline bolus state + *************************************************************************/ +static SALINE_BOLUS_STATE_T handleSalineBolusIdleState( DIALYSIS_STATE_T *dialysisState ) +{ + SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_IDLE; + + // handle saline bolus start request from user + if ( TRUE == salineBolusStartRequested ) + { + salineBolusStartRequested = FALSE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleSalineBolusInProgressState function handles the in-progress state of the + * saline bolus state machine. + * @details Inputs: none + * @details Outputs: + * @param dialysisState next dialysis state + * @return next saline bolus state + *************************************************************************/ +static SALINE_BOLUS_STATE_T handleSalineBolusInProgressState( DIALYSIS_STATE_T *dialysisState ) +{ + SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_IN_PROGRESS; + + return result; +} + +/*********************************************************************//** + * @brief + * The handleSalineBolusMaxDeliveredState function handles the max saline delivered + * state of the saline bolus state machine. This is a terminal state. + * @details Inputs: none + * @details Outputs: + * @param dialysisState next dialysis state + * @return next saline bolus state + *************************************************************************/ +static SALINE_BOLUS_STATE_T handleSalineBolusMaxDeliveredState( DIALYSIS_STATE_T *dialysisState ) +{ + SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_MAX_DELIVERED; + + return result; +} + +/*********************************************************************//** + * @brief * The checkUF function checks ultrafiltration accuracy for the last * hour and checks total UF volume. Triggers an alarm if out of spec. * @details Index: firmware/App/Modes/Dialysis.h =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Modes/Dialysis.h (.../Dialysis.h) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Modes/Dialysis.h (.../Dialysis.h) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -41,6 +41,9 @@ void startDialysis( void ); void stopDialysis( void ); +void signalStartSalineBolus( void ); +void signalAbortSalineBolus( void ); + DIALYSIS_STATE_T getDialysisState( void ); UF_STATE_T getUltrafiltrationState( void ); SALINE_BOLUS_STATE_T getSalineBolusState( void ); Index: firmware/App/Services/AlarmMgmt.h =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -193,6 +193,11 @@ SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_S32_PARAM, // 80 SW_FAULT_ID_MODE_TREATMENT_PARAMS_INVALID_GET_F32_PARAM, SW_FAULT_ID_PERSISTENT_ALARM_INVALID_INDEX, + SW_FAULT_ID_HD_VALVES_INVALID_SELF_TEST_STATE, + SW_FAULT_ID_HD_VALVES_INVALID_EXEC_STATE, + SW_FAULT_ID_AIR_TRAP_INVALID_STATE, // 85 + SW_FAULT_ID_AIR_TRAP_INVALID_LEVEL_SENSOR, + SW_FAULT_ID_DIALYSIS_INVALID_SALINE_BOLUS_STATE, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -78,6 +78,9 @@ #define FPGA_ADC1_AUTO_READ_ENABLE 0x01 ///< Auto-read enable bit for ADC1 control register. +#define FPGA_AIRTRAP_LEVEL_LOW_MASK 0x0008 ///< Bit mask for air trap lower level sensor. +#define FPGA_AIRTRAP_LEVEL_HIGH_MASK 0x0004 ///< Bit mask for air trap upper level sensor. + // FPGA Sensors Record #pragma pack(push,1) /// Record structure for FPGA header read. @@ -164,6 +167,23 @@ U16 VDiPWMTarget; ///< Reg 374. PWM target duty cycle for VDi pinch valve. U16 VDoPWMTarget; ///< Reg 376. PWM target duty cycle for VDo pinch valve. U16 VSparePWMTarget; ///< Reg 378. PWM target duty cycle for Vspare pinch valve. + U16 SyringePumpStatus; ///< Reg 380. Syringe pump status register + U16 SyringePumpEncStatus; ///< Reg 382. Syringe pump encoder status + U32 SyringePumpEncPosition; ///< Reg 384. Syringe pump encoder position + U16 sPumpAdcDataReadChannel0; ///< Reg 388. + U16 sPumpAdcDataReadCh1; ///< Reg 390. + U16 sPumpAdcDataReadCh2; ///< Reg 392. + U16 sPumpAdcDataReadCh3; ///< Reg 394. + U16 VBASpeed; ///< Reg 396. VBA pinch valve speed (Register VAUX0) + U16 VBVSpeed; ///< Reg 398. VBV pinch valve speed (Register VAUX1) + U16 VBVCurrent; ///< Reg 400. VBV pinch valve current (Register VAUX2) + U16 VDoCurrent; ///< Reg 402. VDo pinch valve current (Register VAUX3) + U16 VBACurrent; ///< Reg 404. VBA pinch valve current (Register VAUX8) + U16 VDiSpeed; ///< Reg 406. VDi pinch valve current (Register VAUX9) + U16 VDoSpeed; ///< Reg 408. VDo pinch valve speed (Register VAUX10) + U16 VDiCurrent; ///< Reg 410. VDi pinch valve current (Register VAUX11) + U16 VSpareSpeed; ///< Reg 412. VSpare speed (Register VAUX5) + U16 VSpareCurrent; ///< Reg 414. VSpare current (Register VAUX13) } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -268,9 +288,8 @@ /*********************************************************************//** * @brief * The initFPGA function initializes the FPGA module. - * @details - * Inputs : none - * Outputs : FPGA module initialized. + * @details Inputs: none + * @details Outputs: FPGA module initialized. * @return none *************************************************************************/ void initFPGA( void ) @@ -379,9 +398,8 @@ * @brief * The resetFPGACommFlags function resets the various fpga comm flags and * counters. - * @details - * Inputs : none - * Outputs : fpga comm flags & counters reset + * @details Inputs: none + * @details Outputs: fpga comm flags & counters reset * @return none *************************************************************************/ static void resetFPGACommFlags( void ) @@ -399,9 +417,8 @@ * @brief * The signalFPGAReceiptCompleted function increments a counter to indicate * that another DMA receipt from the FPGA has completed. - * @details - * Inputs : none - * Outputs : fpgaReceiptCounter + * @details Inputs: none + * @details Outputs: fpgaReceiptCounter * @return none *************************************************************************/ void signalFPGAReceiptCompleted( void ) @@ -434,9 +451,8 @@ * @brief * The signalFPGATransmitCompleted function increments a counter to indicate * that another DMA transmit to the FPGA has completed. - * @details - * Inputs : none - * Outputs : fpgaReceiptCounter + * @details Inputs: none + * @details Outputs: fpgaReceiptCounter * @return none *************************************************************************/ void signalFPGATransmitCompleted( void ) @@ -447,9 +463,8 @@ /*********************************************************************//** * @brief * The execFPGA function manages incoming data exchanges with the FPGA. - * @details - * Inputs : fpgaState - * Outputs : fpgaState + * @details Inputs: fpgaState + * @details Outputs: fpgaState * @return none *************************************************************************/ void execFPGAIn( void ) @@ -506,9 +521,8 @@ /*********************************************************************//** * @brief * The execFPGAOut function manages outgoing data exchanges with the FPGA. - * @details - * Inputs : fpgaState - * Outputs : fpgaState + * @details Inputs: fpgaState + * @details Outputs: fpgaState * @return none *************************************************************************/ void execFPGAOut( void ) @@ -553,9 +567,8 @@ * @brief * The handleFPGAReadHeaderState function handles the FPGA state where * the read header registers command is sent to the FPGA. - * @details - * Inputs : none - * Outputs : read command sent to FPGA + * @details Inputs: none + * @details Outputs: read command sent to FPGA * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAReadHeaderState( void ) @@ -585,9 +598,8 @@ * @brief * The handleFPGAReceiveHeaderState function handles the FPGA state * where the header registers read response should be ready to take in. - * @details - * Inputs : none - * Outputs : header register values updated + * @details Inputs: none + * @details Outputs: header register values updated * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAReceiveHeaderState( void ) @@ -637,9 +649,8 @@ * @brief * The handleFPGAWriteAllActuatorsState function handles the FPGA state * where the bulk write command is sent to the FPGA. - * @details - * Inputs : actuator set points - * Outputs : actuator set points sent to FPGA + * @details Inputs: actuator set points + * @details Outputs: actuator set points sent to FPGA * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAWriteAllActuatorsState( void ) @@ -686,9 +697,8 @@ * @brief * The handleFPGAReceiveAllSensorsState function handles the FPGA state * where the bulk read response should be ready to parse. - * @details - * Inputs : none - * Outputs : sensor values updated + * @details Inputs: none + * @details Outputs: sensor values updated * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ) @@ -749,9 +759,8 @@ * @brief * The handleFPGAReadAllSensorsAsyncState function handles the FPGA state where * the read async sensors command is sent to the FPGA. - * @details - * Inputs : none - * Outputs : read async sensors command sent to FPGA + * @details Inputs: none + * @details Outputs: read async sensors command sent to FPGA * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAReadAllSensorsAsyncState( void ) @@ -781,9 +790,8 @@ * @brief * The handleFPGAReceiveAllSensorsAsyncState function handles the FPGA state * where the bulk async read response should be ready to parse. - * @details - * Inputs : none - * Outputs : async sensor values updated + * @details Inputs: none + * @details Outputs: async sensor values updated * @return next FPGA state *************************************************************************/ static FPGA_STATE_T handleFPGAReceiveAllSensorsAsyncState( void ) @@ -833,9 +841,8 @@ /*********************************************************************//** * @brief * The execFPGATest function executes the FPGA self-test. - * @details - * Inputs : fpgaHeader - * Outputs : none + * @details Inputs: fpgaHeader + * @details Outputs: none * @return passed, or failed *************************************************************************/ SELF_TEST_STATUS_T execFPGATest( void ) @@ -862,11 +869,29 @@ /*********************************************************************//** * @brief + * The consumeUnexpectedData function checks to see if a byte is sitting in + * the SCI2 received data register. + * @details Inputs: fpgaHeader + * @details Outputs: none + * @return fpgaDiag + *************************************************************************/ +static void consumeUnexpectedData( void ) +{ + // clear any errors + sciRxError( scilinREG ); + // if a byte is pending read, read it + if ( sciIsRxReady( scilinREG ) != 0 ) + { + sciReceiveByte( scilinREG ); + } +} + +/*********************************************************************//** + * @brief * The setupDMAForWriteCmd function sets the byte count for the next DMA * write command to the FPGA. - * @details - * Inputs : none - * Outputs : number of bytes for next FPGA write command is set + * @details Inputs: none + * @details Outputs: number of bytes for next FPGA write command is set * @param bytes2Transmit number of bytes to be transmitted via DMA to the FPGA * @return none *************************************************************************/ @@ -887,9 +912,8 @@ * @brief * The startDMAWriteCmd function initiates the DMA transmit for the next * DMA write command to the FPGA. - * @details - * Inputs : none - * Outputs : DMA write command to FPGA is initiated + * @details Inputs: none + * @details Outputs: DMA write command to FPGA is initiated * @return none *************************************************************************/ static void startDMAWriteCmd( void ) @@ -903,9 +927,8 @@ * @brief * The setupDMAForWriteResp function sets the expected byte count for the * next DMA write command response from the FPGA. - * @details - * Inputs : none - * Outputs : number of expected bytes for next FPGA write command response is set + * @details Inputs: none + * @details Outputs: number of expected bytes for next FPGA write command response is set * @param bytes2Receive number of bytes expected to be transmitted via DMA from the FPGA * @return none *************************************************************************/ @@ -926,9 +949,8 @@ * @brief * The startDMAReceiptOfWriteResp function initiates readiness of the DMA * receiver for the next DMA write command response from the FPGA. - * @details - * Inputs : none - * Outputs : DMA write command response is ready to be received from the FPGA + * @details Inputs: none + * @details Outputs: DMA write command response is ready to be received from the FPGA * @return none *************************************************************************/ static void startDMAReceiptOfWriteResp( void ) @@ -942,9 +964,8 @@ * @brief * The setupDMAForReadCmd function sets the byte count for the next DMA * read command to the FPGA. - * @details - * Inputs : none - * Outputs : number of bytes for next FPGA read command is set + * @details Inputs: none + * @details Outputs: number of bytes for next FPGA read command is set * @param bytes2Transmit number of bytes to be transmitted via DMA to the FPGA * @return none *************************************************************************/ @@ -965,9 +986,8 @@ * @brief * The startDMAReadCmd function initiates the DMA transmit for the next * DMA read command to the FPGA. - * @details - * Inputs : none - * Outputs : DMA read command to FPGA is initiated + * @details Inputs: none + * @details Outputs: DMA read command to FPGA is initiated * @return none *************************************************************************/ static void startDMAReadCmd( void ) @@ -981,9 +1001,8 @@ * @brief * The setupDMAForReadResp function sets the expected byte count for the * next DMA read command response from the FPGA. - * @details - * Inputs : none - * Outputs : number of expected bytes for next FPGA read command response is set + * @details Inputs: none + * @details Outputs: number of expected bytes for next FPGA read command response is set * @param bytes2Receive number of expected bytes to be transmitted via DMA from the FPGA * @return none *************************************************************************/ @@ -1004,9 +1023,8 @@ * @brief * The startDMAReceiptOfReadResp function initiates readiness of the DMA * receiver for the next DMA read command response from the FPGA. - * @details - * Inputs : none - * Outputs : DMA read command response is ready to be received from the FPGA + * @details Inputs: none + * @details Outputs: DMA read command response is ready to be received from the FPGA * @return none *************************************************************************/ static void startDMAReceiptOfReadResp( void ) @@ -1019,9 +1037,8 @@ /*********************************************************************//** * @brief * The getFPGAVersions function gets the fpga version numbers. - * @details - * Inputs : fpgaHeader - * Outputs : none + * @details Inputs: fpgaHeader + * @details Outputs: none * @return none *************************************************************************/ void getFPGAVersions( U08 *Id, U08 *Maj, U08 *Min, U08 *Lab ) @@ -1036,9 +1053,8 @@ * @brief * The getFPGABloodFlowSignalStrength function gets the latest blood flow * signal strength reading. - * @details - * Inputs : fpgaSensorReadings2 - * Outputs : none + * @details Inputs: fpgaSensorReadings2 + * @details Outputs: none * @return last blood flow signal strength reading *************************************************************************/ F32 getFPGABloodFlowSignalStrength( void ) @@ -1050,9 +1066,8 @@ * @brief * The getFPGADialysateFlowSignalStrength function gets the latest dialysate * flow signal strength reading. - * @details - * Inputs : fpgaSensorReadings2 - * Outputs : none + * @details Inputs: fpgaSensorReadings2 + * @details Outputs: none * @return last dialysate flow signal strength reading *************************************************************************/ F32 getFPGADialysateFlowSignalStrength( void ) @@ -1063,9 +1078,8 @@ /*********************************************************************//** * @brief * The getFPGABloodFlow function gets the latest blood flow reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last blood flow reading *************************************************************************/ F32 getFPGABloodFlow( void ) @@ -1076,9 +1090,8 @@ /*********************************************************************//** * @brief * The getFPGADialysateFlow function gets the latest dialysate flow reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate flow reading *************************************************************************/ F32 getFPGADialysateFlow( void ) @@ -1093,9 +1106,8 @@ * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last blood pump hall sensor count reading. *************************************************************************/ U16 getFPGABloodPumpHallSensorCount( void ) @@ -1110,9 +1122,8 @@ * Bit 0 - Derived direction of the blood pump motor (0=Fwd, 1=Rev) * Bit 1 - A direction error was detected in the current hall sensor phase * Bit 2 - A direction error was detected since the last read of this register - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last blood pump hall sensor status reading. *************************************************************************/ U08 getFPGABloodPumpHallSensorStatus( void ) @@ -1127,9 +1138,8 @@ * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate inlet pump hall sensor count reading. *************************************************************************/ U16 getFPGADialInPumpHallSensorCount( void ) @@ -1144,9 +1154,8 @@ * Bit 0 - Derived direction of the dialyste inlet pump motor (0=Fwd, 1=Rev) * Bit 1 - A direction error was detected in the current hall sensor phase * Bit 2 - A direction error was detected since the last read of this register - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate inlet pump hall sensor status reading. *************************************************************************/ U08 getFPGADialInPumpHallSensorStatus( void ) @@ -1161,9 +1170,8 @@ * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate outlet pump hall sensor count reading. *************************************************************************/ U16 getFPGADialOutPumpHallSensorCount( void ) @@ -1178,9 +1186,8 @@ * Bit 0 - Derived direction of the dialysate outlet pump motor (0=Fwd, 1=Rev) * Bit 1 - A direction error was detected in the current hall sensor phase * Bit 2 - A direction error was detected since the last read of this register - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate outlet pump hall sensor status reading. *************************************************************************/ U08 getFPGADialOutPumpHallSensorStatus( void ) @@ -1191,9 +1198,8 @@ /*********************************************************************//** * @brief * The getFPGABloodPumpOcclusion function gets the latest blood occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last blood occlusion reading *************************************************************************/ U16 getFPGABloodPumpOcclusion( void ) @@ -1205,9 +1211,8 @@ * @brief * The getFPGADialInPumpOcclusion function gets the latest dialysate * inlet occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate inlet occlusion reading *************************************************************************/ U16 getFPGADialInPumpOcclusion( void ) @@ -1219,9 +1224,8 @@ * @brief * The getFPGADialOutPumpOcclusion function gets the latest dialysate * outlet occlusion reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last dialysate outlet occlusion reading *************************************************************************/ U16 getFPGADialOutPumpOcclusion( void ) @@ -1232,9 +1236,8 @@ /*********************************************************************//** * @brief * The getFPGAArterialPressure function gets the latest arterial pressure reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last arterial pressure reading *************************************************************************/ S32 getFPGAArterialPressure( void ) @@ -1245,9 +1248,8 @@ /*********************************************************************//** * @brief * The getFPGAVenousPressure function gets the venous arterial pressure reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @return last venous pressure reading *************************************************************************/ U16 getFPGAVenousPressure( void ) @@ -1260,9 +1262,8 @@ * @brief * The getFPGAAccelAxes function gets the accelerometer axis readings. * Axis readings are in ADC counts. 0.004 g per LSB. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @param x Populate this param with X axis reading * @param y Populate this param with Y axis reading * @param z Populate this param with Z axis reading @@ -1280,9 +1281,8 @@ * The getFPGAAccelMaxes function gets the maximum accelerometer axis readings. * from last FPGA read (every 10ms). * Axis readings are in ADC counts. 0.004 g per LSB. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @param x Populate this param with maximum X axis reading * @param y Populate this param with maximum Y axis reading * @param z Populate this param with maximum Z axis reading @@ -1299,9 +1299,8 @@ * @brief * The getFPGAAccelStatus function gets the accelerometer reading count * and error register values. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none + * @details Inputs: fpgaSensorReadings + * @details Outputs: none * @param cnt Populate this param with latest sample counter value * @param err Populate this param with latest error * @return none @@ -1316,20 +1315,314 @@ * @brief * The consumeUnexpectedData function checks to see if a byte is sitting in * the SCI2 received data register. - * @details - * Inputs : fpgaHeader - * Outputs : none + * @details Inputs: fpgaHeader + * @details Outputs: none * @return fpgaDiag *************************************************************************/ -static void consumeUnexpectedData( void ) +void getFPGAAirTrapLevels( BOOL *airAtLower, BOOL *airAtUpper ) { - // clear any errors - sciRxError( scilinREG ); - // if a byte is pending read, read it - if ( sciIsRxReady( scilinREG ) != 0 ) - { - sciReceiveByte( scilinREG ); - } + U16 fpgaGPIO = fpgaSensorReadings.fpgaGPIO; + U16 lower = fpgaGPIO & FPGA_AIRTRAP_LEVEL_LOW_MASK; + U16 upper = fpgaGPIO & FPGA_AIRTRAP_LEVEL_HIGH_MASK; + + *airAtLower = ( 0 == lower ? FALSE : TRUE ); + *airAtUpper = ( 0 == upper ? FALSE : TRUE ); } +/*********************************************************************//** + * @brief + * The setFPGAValvesControlMode function sets the valves control mode. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param bits : The bits to enable the PID controller of a valve + * @return none + *************************************************************************/ +void setFPGAValvesControlMode( U16 bits ) +{ + fpgaActuatorSetPoints.fpgaPIDControl = bits; +} + +/*********************************************************************//** + * @brief + * The getValvesStatus function reads the status of the valves + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return The status of the valves + *************************************************************************/ +U16 getFPGAValvesStatus( void ) +{ + return fpgaSensorReadings.valveStatus; +} + +/*********************************************************************//** + * @brief + * The setValveDialyzerInletPosition function sets the position of VDi \n + * in counts + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param setPoint : Next position of the valve in counts + * @return none + *************************************************************************/ +void setFPGAValveDialyzerInletPosition( S16 setPoint ) +{ + fpgaActuatorSetPoints.VDiSetPoint = setPoint; +} + +/*********************************************************************//** + * @brief + * The getValveDialyzerInletPosition function reads the current position \n + * of VDi in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current position of VDi + *************************************************************************/ +S16 getFPGAValveDialyzerInletPosition( void ) +{ + return fpgaSensorReadings.VDiPosition; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveDialyzerInletCurrentCounts function reads the current \n + * of VDi in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current of VDi + *************************************************************************/ +U16 getFPGAValveDialyzerInletCurrentCounts( void ) +{ + return fpgaSensorReadings.VDiCurrent; +} + +#ifdef DEBUG_ENABLED +/*********************************************************************//** + * @brief + * The setFPGAValveDialyzerInletPWM function sets the PWM of VDI in counts. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param count which is the PWM of VDI in counts + * @return none + *************************************************************************/ +void setFPGAValveDialyzerInletPWM( U16 count ) +{ + fpgaActuatorSetPoints.VDiPWMFixed = count; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveDialyzerInletPWM function reads the current PWM target + * of VDI. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return current PWM of VDI + *************************************************************************/ +U16 getFPGAValveDialyzerInletPWM( void ) +{ + return fpgaSensorReadings.VDiPWMTarget; +} +#endif + +/*********************************************************************//** + * @brief + * The setValveDialyzerOutletPosition function sets the position of VDo \n + * in counts + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param setPoint : Next position of the valve in counts + * @return none + *************************************************************************/ +void setFPGAValveDialyzerOutletPosition( S16 setPoint ) +{ + fpgaActuatorSetPoints.VDoSetPoint = setPoint; +} + +/*********************************************************************//** + * @brief + * The getDialyzerOutletValvePosition function reads the current position \n + * of VDo in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current position of VDo + *************************************************************************/ +S16 getFPGAValveDialyzerOutletPosition( void ) +{ + return fpgaSensorReadings.VDoPosition; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveDialyzerOutletCurrentCounts function reads the current \n + * of VDo in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current of VDo + *************************************************************************/ +U16 getFPGAValveDialyzerOutletCurrentCounts( void ) +{ + return fpgaSensorReadings.VDoCurrent; +} + +#ifdef DEBUG_ENABLED +/*********************************************************************//** + * @brief + * The setFPGAValveDialyzerOutletPWM function sets the PWM of VDO in counts. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param count which is the PWM of VDO in counts + * @return none + *************************************************************************/ +void setFPGAValveDialyzerOutletPWM( U16 count ) +{ + fpgaActuatorSetPoints.VDoPWMFixed = count; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveDialyzerOutletPWM function reads the current PWM target + * of VDO. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return current PWM of VDO + *************************************************************************/ +U16 getFPGAValveDialyzerOutletPWM( void ) +{ + return fpgaSensorReadings.VDoPWMTarget; +} +#endif + +/*********************************************************************//** + * @brief + * The setValveBloodVenousPosition function sets the position of VBV \n + * in counts + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param setPoint : Next position of the valve in counts + * @return none + *************************************************************************/ +void setFPGAValveBloodVenousPosition( S16 setPoint ) +{ + fpgaActuatorSetPoints.VBVSetPoint = setPoint; +} + +/*********************************************************************//** + * @brief + * The getValveBloodVenousPosition function reads the current position \n + * of VBV in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current position of VBV + *************************************************************************/ +S16 getFPGAValveBloodVenousPosition( void ) +{ + return fpgaSensorReadings.VBVPosition; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveBloodVenousCurrentCounts function reads the current \n + * of VBV in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current of VBV + *************************************************************************/ +U16 getFPGAValveBloodVenousCurrentCounts( void ) +{ + return fpgaSensorReadings.VBVCurrent; +} + +#ifdef DEBUG_ENABLED +/*********************************************************************//** + * @brief + * The setFPGAValveBloodVenousPWM function sets the PWM of VBV in counts. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param count which is the PWM of VBV in counts + * @return none + *************************************************************************/ +void setFPGAValveBloodVenousPWM( U16 count ) +{ + fpgaActuatorSetPoints.VBVPWMFixed = count; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveBloodVenousPWM function returns the PWM of VBV in counts. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: none + * @return returns the PWM of VBV in counts + *************************************************************************/ +U16 getFPGAValveBloodVenousPWM( void ) +{ + return fpgaSensorReadings.VBVPWMTarget; +} +#endif + +/*********************************************************************//** + * @brief + * The setValveBloodArterialPosition function sets the position of VBA \n + * in counts + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param setPoint : Next position of the valve in counts + * @return none + *************************************************************************/ +void setFPGAValveBloodArterialPosition( S16 setPoint ) +{ + fpgaActuatorSetPoints.VBASetPoint = setPoint; +} + +/*********************************************************************//** + * @brief + * The getValveBloodArterialPosition function reads the current position \n + * of VBA in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current position of VBA + *************************************************************************/ +S16 getFPGAValveBloodArterialPosition( void ) +{ + return fpgaSensorReadings.VBAPosition; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveBloodArterialCurrentCounts function reads the current \n + * of VBA in counts + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current of VBA + *************************************************************************/ +U16 getFPGAValveBloodArterialCurrentCounts( void ) +{ + return fpgaSensorReadings.VBACurrent; +} + +#ifdef DEBUG_ENABLED +/*********************************************************************//** + * @brief + * The setFPGAValveBloodArterialPWM function sets a PWM for VBA in counts. + * @details Inputs: fpgaActuatorSetPoints + * @details Outputs: fpgaActuatorSetPoints + * @param count which is the PWM of VBA in counts + * @return none + *************************************************************************/ +void setFPGAValveBloodArterialPWM( U16 count ) +{ + fpgaActuatorSetPoints.VBAPWMFixed = count; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveBloodArterialPWM function returns the current PWM of + * VBA in counts. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return current PWM of VBA in counts + *************************************************************************/ +U16 getFPGAValveBloodArterialPWM( void ) +{ + return fpgaSensorReadings.VBAPWMTarget; +} +#endif + /**@}*/ Index: firmware/App/Services/FPGA.h =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -68,6 +68,39 @@ void getFPGAAccelMaxes( S16 *xm, S16*ym, S16*zm ); void getFPGAAccelStatus( U16 *cnt, U16 *accelFPGAFaultReg ); +void getFPGAAirTrapLevels( BOOL *airAtLower, BOOL *airAtUpper ); + +void setFPGAValvesControlMode( U16 bits ); +U16 getFPGAValvesStatus( void ); + +void setFPGAValveDialyzerInletPosition( S16 setPoint ); +S16 getFPGAValveDialyzerInletPosition( void ); +U16 getFPGAValveDialyzerInletCurrentCounts( void ); + +void setFPGAValveDialyzerOutletPosition( S16 setPoint ); +S16 getFPGAValveDialyzerOutletPosition( void ); +U16 getFPGAValveDialyzerOutletCurrentCounts( void ); + +void setFPGAValveBloodVenousPosition( S16 setPoint ); +S16 getFPGAValveBloodVenousPosition( void ); +U16 getFPGAValveBloodVenousCurrentCounts( void ); + +void setFPGAValveBloodArterialPosition( S16 setPoint ); +S16 getFPGAValveBloodArterialPosition( void ); +U16 getFPGAValveBloodArterialCurrentCounts( void ); + +// The PWM functions only used during debugging +#ifdef DEBUG_ENABLED + void setFPGAValveDialyzerInletPWM( U16 count ); + U16 getFPGAValveDialyzerInletPWM( void ); + void setFPGAValveDialyzerOutletPWM( U16 count ); + U16 getFPGAValveDialyzerOutletPWM( void ); + void setFPGAValveBloodVenousPWM( U16 count ); + U16 getFPGAValveBloodVenousPWM( void ); + void setFPGAValveBloodArterialPWM( U16 count ); + U16 getFPGAValveBloodArterialPWM( void ); +#endif + /**@}*/ #endif Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -1158,6 +1158,10 @@ case MSG_ID_USER_UF_SETTINGS_CHANGE_REQUEST: handleChangeUFSettingsRequest( message ); + break; + + case MSG_ID_USER_SALINE_BOLUS_REQUEST: + handleSalineBolusRequest( message ); break; case MSG_ID_USER_CONFIRM_UF_SETTINGS_CHANGE: Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -30,12 +30,12 @@ #include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "PresOccl.h" +#include "RTC.h" #include "SafetyShutdown.h" #include "SystemComm.h" #include "SystemCommMessages.h" -#include "Utilities.h" +#include "Utilities.h" #include "WatchdogMgmt.h" -#include "RTC.h" /** * @addtogroup SystemCommMessages @@ -1129,6 +1129,33 @@ return result; } +/***********************************************************************//** + * @brief + * The broadcastHDValves function constructs an HD valves msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: HD valves msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastHDValves( HD_VALVE_DATA_T *valveData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_VALVES_DATA; + msg.hdr.payloadLen = sizeof( HD_VALVE_DATA_T ); + + memcpy( payloadPtr, valveData, sizeof( HD_VALVE_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + #ifdef EMC_TEST_BUILD BOOL broadcastCANErrorCount( U32 count ) { @@ -1739,6 +1766,72 @@ { sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); } +} + +/*********************************************************************//** + * @brief + * The handleSalineBolusRequest function handles a saline bolus request + * message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSalineBolusRequest( MESSAGE_T *message ) +{ + if ( sizeof(BOOL) == message->hdr.payloadLen ) + { + BOOL start; + + memcpy( &start, &message->payload[0], sizeof(BOOL) ); + + if ( TRUE == start ) + { + signalStartSalineBolus(); + } + else + { + signalAbortSalineBolus(); + } + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/*********************************************************************//** + * @brief + * The sendSalineBolusResponse function constructs a saline bolus start/abort + * response to the UI and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: Treatment parameters response msg constructed and queued. + * @param accepted T/F - was saline bolus request accepted? + * @param rejReason reason why request was rejected (or zero if accepted) + * @param bolusVol volume (in mL) currently set for saline bolus + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendSalineBolusResponse( BOOL accepted, U32 rejReason, U32 bolusVol ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_USER_SALINE_BOLUS_RESPONSE; + msg.hdr.payloadLen = sizeof( BOOL ) + sizeof( U32 ) + sizeof( U32 ); + + memcpy( payloadPtr, &accepted, sizeof( BOOL ) ); + payloadPtr += sizeof( BOOL ); + memcpy( payloadPtr, &rejReason, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &bolusVol, sizeof( U32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; } /*********************************************************************//** @@ -1752,7 +1845,7 @@ *************************************************************************/ void handleDGOpMode( MESSAGE_T *message ) { - U32 payloadSize = sizeof(U32) + sizeof(U32); + U32 payloadSize = sizeof(U32) + sizeof(U32); if ( message->hdr.payloadLen == payloadSize ) { Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -ra4f5ed3748870d287a4c2c6fcc003fc4d3b9233f --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision a4f5ed3748870d287a4c2c6fcc003fc4d3b9233f) @@ -22,6 +22,7 @@ #include "MsgQueues.h" #include "DialOutFlow.h" #include "DGInterface.h" +#include "Valves.h" /** * @defgroup SystemCommMessages SystemCommMessages @@ -124,6 +125,12 @@ // MSG_ID_USER_BLOOD_DIAL_RATE_CHANGE_REQUEST void handleChangeBloodDialysateRateChangeRequest( MESSAGE_T *message ); +// MSG_ID_USER_SALINE_BOLUS_REQUEST +void handleSalineBolusRequest( MESSAGE_T *message ); + +// MSG_ID_USER_SALINE_BOLUS_RESPONSE +BOOL sendSalineBolusResponse( BOOL accepted, U32 rejReason, U32 bolusVol ); + // MSG_ID_USER_BLOOD_DIAL_RATE_CHANGE_RESPONSE BOOL sendChangeBloodDialysateRateChangeResponse( BOOL accepted, U32 reason, U32 bloodRate, U32 dialRate ); @@ -188,8 +195,11 @@ BOOL broadcastPowerOffWarning( void ); // MSG_ID_HD_OP_MODE -BOOL broadcastHDOperationMode( U32 mode, U32 subMode ); +BOOL broadcastHDOperationMode( U32 mode, U32 subMode ); +// MSG_ID_HD_VALVES_DATA +BOOL broadcastHDValves( HD_VALVE_DATA_T *valveData ); + #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT BOOL broadcastCANErrorCount( U32 count );