Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) @@ -1,6 +1,5 @@ // Includes - #include "Valves.h" #include "FPGA.h" #include "Timers.h" @@ -95,15 +94,16 @@ VALVE_POSITION_T commandedPosition; VALVE_POSITION_T currentPosition; S16 currentPositionInCounts; - S16 previousPositionInCounts; BOOL hasTransitionBeenRequested; VALVE_STATE_T execState; U32 transitionStartTime; S16 positions[ NUM_OF_VALVE_POSITIONS ]; F32 valveCurrent; U32 valveOverCurrentCounter; U32 valvePositionOutOfRangeCounter; + U32 valvesDataPublishCounter; // Homing variables + S16 previousPositionInCounts; U32 numberOfFailedHomings; U32 homingEdgeDetectionCounter; BOOL hasHomingBeenRequested; @@ -117,7 +117,6 @@ static VALVE_STATUS_T valvesStatus[ NUM_OF_VALVES ]; static OVERRIDE_U32_T valvesDataPublishInterval = { VALVES_DATA_PUB_INTERVAL, VALVES_DATA_PUB_INTERVAL, 0, 0 }; -static U32 valvesDataPublishCounter = 0; // Self test function prototypes static VALVE_SELF_TEST_STATE_T handleValveSelfTestEnableValves( void ); @@ -138,11 +137,11 @@ static void convertAndMonitorValvesCurrent( void ); static void getAndMonitorValvesCurrentPosition( void ); static DATA_GET_PROTOTYPE( U32, getPublishValvesDataInterval ); -static void publishValvesData( void ); +static void publishValvesData( VALVE_T valve ); /*********************************************************************//** * @brief - * The initValves function initializes the valves driver + * The initValves function initializes the valves driver. * @details * Inputs: valveSelfTestState, valvesSelfTestResult, valvesStatus * Outputs: valveSelfTestState, valvesSelfTestResult, valvesStatus @@ -164,7 +163,7 @@ /*********************************************************************//** * @brief - * The homeValve function sets the homing request flag of a valve to TRUE + * The homeValve function sets the homing request flag of a valve to TRUE. * @details * Inputs: valvesStatus * Outputs: valvesStatus (The flag that sets the homing request) @@ -181,7 +180,7 @@ /*********************************************************************//** * @brief - * The setValvePosition function sets the requested position of a valve + * The setValvePosition function sets the requested position of a valve. * @details * Inputs: valvesStatus * Outputs: valvesStatus (commanded position) @@ -206,7 +205,7 @@ /*********************************************************************//** * @brief - * The getValvePosition function returns the current position of a valve + * The getValvePosition function returns the current position of a valve. * @details * Inputs: none * Outputs: valvesStatus (current position) @@ -222,7 +221,7 @@ /*********************************************************************//** * @brief * The setValveBloodTrap function set the blood trap valve to open or close - * position + * position. * @details * Inputs: TODO * Outputs: TODO @@ -231,12 +230,13 @@ *************************************************************************/ BOOL setValveBloodTrap( OPN_CLS_STATE_T state ) { + //TODO fill up the function return TRUE; } /*********************************************************************//** * @brief - * The execValvesSelfTest function executes the valves self test + * The execValvesSelfTest function executes the valves self test. * @details * Inputs: valveSelfTestState * Outputs: valveSelfTestState @@ -268,7 +268,7 @@ /*********************************************************************//** * @brief - * The execValves function executes the valves exec state machine + * The execValves function executes the valves exec state machine. * @details * Inputs: none * Outputs: none (All the values are stored in the structure of each valve) @@ -329,14 +329,14 @@ default: break; } - } - publishValvesData(); + publishValvesData( valve ); + } } /*********************************************************************//** * @brief - * The handleValveSelfTestEnableValves function starts the valves self test + * The handleValveSelfTestEnableValves function starts the valves self test. * @details * Inputs: valvesSelfTestResult * Outputs: nvalvesSelfTestResult @@ -360,7 +360,7 @@ /*********************************************************************//** * @brief * The handleValveSelfTestConfirmEnable function checks to make sure the - * valves are enabled properly + * valves are enabled properly. * @details * Inputs: valvesSelfTestResult * Outputs: valvesSelfTestResult @@ -383,8 +383,7 @@ /*********************************************************************//** * @brief * The handleValveStateWaitForPost function handles the wait for POST \n - * state - * valves are enabled properly + * state. * @details * Inputs: valveSelfTestState, valveSelfTestState * Outputs: valveSelfTestState (the next exec state of a valve) @@ -405,8 +404,7 @@ /*********************************************************************//** * @brief * The handleValveStateIdle function handles the idle state of the valves \n - * state machine - * valves are enabled properly + * state machine. * @details * Inputs: valveSelfTestState, valveSelfTestState * Outputs: valveSelfTestState (the next exec state of a valve) @@ -441,7 +439,7 @@ /*********************************************************************//** * @brief * The handleValveStateInTransition function handles the in transition \n - * state of the state machine + * state of the state machine. * @details * Inputs: valvesStatus (commanded position, current position, current position \n * in counts, has transition been requested flag) @@ -516,7 +514,7 @@ /*********************************************************************//** * @brief * The handleValveStateHomingNotStarted function handles homing not started \n - * state of the state machine + * state of the state machine. * @details * Inputs: valvesStatus, valveSelfTestState * Outputs: valvesStatus @@ -548,7 +546,7 @@ /*********************************************************************//** * @brief * The handleValveStateHomingFindEnergizedEdge function handles find \n - * energized state of the state machine + * energized state of the state machine. * @details * Inputs: valvesStatus, valveSelfTestState * Outputs: valvesStatus @@ -607,8 +605,8 @@ /*********************************************************************//** * @brief * The handleValveStateHomingFindDeenergizedEdge function handles find \n - * de-energized state of the state machine - * @details + * de-energized state of the state machine. + * @details. * Inputs: valvesStatus, valveSelfTestState * Outputs: valvesStatus * @return: none @@ -681,7 +679,7 @@ /*********************************************************************//** * @brief * The execMonitorValves function handles monitoring of the valves. The \n - * function calls other functions to monitor the values + * function calls other functions to monitor the values. * @details * Inputs: none * Outputs: none @@ -703,7 +701,7 @@ * @brief * The areValvesEnabled function checks the current valves status from FPGA \n * to the enable bit mask of each valve. If any of the valves is not enabled \n - * the function raises an alarm + * the function raises an alarm. * @details * Inputs: none * Outputs: none @@ -777,7 +775,7 @@ /*********************************************************************//** * @brief - * The setFPGAValue function sets the position of a valve to FPGA + * The setFPGAValue function sets the position of a valve to FPGA. * @details * Inputs: none * Outputs: none @@ -818,7 +816,7 @@ * @brief * The convertAndMonitorValvesCurrent function gets the current values \n * in counts from FPGA and converts them to current. If any of the values \n - * is above the threshold, the function will raise an alarm + * is above the threshold, the function will raise an alarm. * @details * Inputs: valvesStatus * Outputs: valvesStatus @@ -831,7 +829,8 @@ F32 ADC2Voltage = 0; F32 voltage2Current = 0; - // Get the current from FPGA in ADC + // Get the current from FPGA in ADC and use the macros to convert + // the ADC count into voltage, and convert voltage to current currentInADC = getFPGAValveDialyzerInletCurrentCounts(); ADC2Voltage = ADC_TO_VOLTAGE_CONVERSION( currentInADC ); voltage2Current = ADC_TO_VOLTAGE_CONVERSION( ADC2Voltage ); @@ -877,7 +876,7 @@ * of the valves and stores them into the structure of each valve. The function \n * checks whether any of the valves have deviated from their current position \n * if they are in idle state. If any of the valves have deviated, the function \n - * raises an alarm + * raises an alarm. * @details * Inputs: valvesStatus * Outputs: valvesStatus @@ -927,7 +926,7 @@ /*********************************************************************//** * @brief * The getPublishValvesDataInterval function gets the valves data publish \n - * interval + * interval. * @details * Inputs: valvesDataPublishInterval * Outputs: none @@ -948,22 +947,82 @@ /*********************************************************************//** * @brief * The publishValvesData function publishes the data of the valves at the \n - * specified time interval + * specified time interval. * @details - * Inputs: valvesDataPublishCounter - * Outputs: valvesDataPublishCounter + * Inputs: valvesStatus + * Outputs: valvesStatus * @return: none *************************************************************************/ -static void publishValvesData( void ) +static void publishValvesData( VALVE_T valve ) { - if ( ++valvesDataPublishCounter > getPublishValvesDataInterval() ) + // Check the counter + if ( ++valvesStatus[ valve ].valvesDataPublishCounter > getPublishValvesDataInterval() ) { - broadcastHDValves(); + U32 currentPos = (U32)valvesStatus[ valve ].currentPosition; + S16 currentPosCount = valvesStatus[ valve ].currentPositionInCounts; + F32 current = valvesStatus[ valve ].valveCurrent; - valvesDataPublishCounter = 0; + broadcastHDValves( (U32)valve, currentPos, currentPosCount, current ); + + valvesStatus[ valve ].valvesDataPublishCounter = 0; } } /**@}*/ +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ +/*********************************************************************//** + * @brief + * The testSetValvesDataPublishInterval function overrides the valves \n + * data publish interval. + * @details + * Inputs: valvesDataPublishInterval + * Outputs: valvesDataPublishInterval + * @param: value : override valve data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetValvesDataPublishInterval( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_PRIORITY_INTERVAL; + + result = TRUE; + valvesDataPublishInterval.ovData = intvl; + valvesDataPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetValvesDataPublishInterval function resets the override \n + * of the valves publish interval. + * @details + * Inputs: valvesDataPublishInterval + * Outputs: valvesDataPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetValvesDataPublishInterval( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + valvesDataPublishInterval.override = OVERRIDE_RESET; + valvesDataPublishInterval.ovData = valvesDataPublishInterval.ovInitData; + } + + return result; +} + + + + Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) @@ -52,6 +52,10 @@ BOOL setValveBloodTrap( OPN_CLS_STATE_T state ); +BOOL testSetValvesDataPublishInterval( U32 value ); + +BOOL testResetValvesDataPublishInterval( void ); + /**@}*/ #endif Index: firmware/App/Services/MessagePayloads.h =================================================================== diff -u -rc84daa1f07003427fc5cdde8f5651434478f7313 -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 --- firmware/App/Services/MessagePayloads.h (.../MessagePayloads.h) (revision c84daa1f07003427fc5cdde8f5651434478f7313) +++ firmware/App/Services/MessagePayloads.h (.../MessagePayloads.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) @@ -173,6 +173,14 @@ U32 ctrlMode; } OVERRIDE_PUMP_SET_PT_PAYLOAD_T; +typedef struct +{ + U32 valveID; + U32 currentPosID; + S16 currentPos; + F32 current; +} HD_VALVES_T; + #pragma pack(pop) #endif Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) @@ -31,7 +31,8 @@ #include "SafetyShutdown.h" #include "SystemComm.h" #include "SystemCommMessages.h" -#include "Utilities.h" +#include "Utilities.h" +#include "Valves.h" #include "WatchdogMgmt.h" #include "RTC.h" @@ -1119,9 +1120,42 @@ return result; } -BOOL broadcastHDValves( void ) +/***********************************************************************//** + * @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 + * Outputs : HD valves msg constructed and queued + * @param valve : HD valve ID + * @param currentPosEnum : Current position ID + * @param currentPosCount : Current position count + * @param current : Current of the valve + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastHDValves( U32 valve, U32 currentPosEnum, S16 currentPosCount, F32 current ) { + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + HD_VALVES_T payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_VALVES_DATA; + msg.hdr.payloadLen = sizeof( HD_VALVES_T ); + + payload.valveID = valve; + payload.currentPosID = currentPosEnum; + payload.currentPos = currentPosCount; + payload.current = current; + + memcpy( payloadPtr, &payload, sizeof( HD_VALVES_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 @@ -2365,3 +2399,15 @@ // respond to request sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } + +/*********************************************************************//** + * @brief + * The handleTestHDValvesBroadcastIntervalOverrideRequest function handles \n + * a request to override the broadcast interval for HD valves data. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_OVERRIDE_HANDLER_FUNC_U32( U32, handleTestHDValvesBroadcastIntervalOverrideRequest, testSetValvesDataPublishInterval, testResetValvesDataPublishInterval ) Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) @@ -161,7 +161,7 @@ BOOL broadcastHDOperationMode( U32 mode, U32 subMode ); //MSG_ID_HD_VALVES_DATA -BOOL broadcastHDValves( void ); +BOOL broadcastHDValves( U32 valve, U32 currentPosEnum, S16 currentPosCount, F32 current ); #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT @@ -313,6 +313,9 @@ // MSG_ID_HD_DIALYSATE_FLOW_SET_CALIBRATION: void handleSetDialysateFlowCalibration( MESSAGE_T *message ); + +//MSG_ID_HD_VALVES_SEND_INTERVAL_OVERRIDE +void handleTestHDValvesBroadcastIntervalOverrideRequest( MESSAGE_T *message ); #endif