Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r384157184f801e501c61bdf675d7d8b727b5ab9d -r0e809b89fe509c2968c3445898466dd8dd9411a9 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 384157184f801e501c61bdf675d7d8b727b5ab9d) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 0e809b89fe509c2968c3445898466dd8dd9411a9) @@ -426,7 +426,7 @@ currentValveStates[ valve ].hasValveBeenHomed = FALSE; currentValveStates[ valve ].homingOperationActive = TRUE; currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); } } else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && @@ -452,7 +452,6 @@ ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && ( TRUE != getCPLDACPowerLossDetected() ) ) { - currentValveStates[ valve ].homingOperationActive = FALSE; currentValveStates[ valve ].hasValveBeenHomed = FALSE; currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; Index: firmware/App/Drivers/PinchValve.c =================================================================== diff -u -r24527f0e57b90bbb12116e625ae2b7efa347920c -r0e809b89fe509c2968c3445898466dd8dd9411a9 --- firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 24527f0e57b90bbb12116e625ae2b7efa347920c) +++ firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 0e809b89fe509c2968c3445898466dd8dd9411a9) @@ -31,12 +31,12 @@ #define PINCH_VALVE_COMMAND_TIMEOUT_MS 1000 ///< Maximum FPGA command execution time in milliseconds. #define PINCH_VALVE_MOTION_TIMEOUT_MS 10000 ///< Maximum allowed valve motion time in milliseconds -#define PINCH_VALVE_HOME_OFFSET 20 ///< Offset (in encoder counts) from end of travel edge to set position B and C. +#define PINCH_VALVE_HOME_OFFSET 20 ///< Offset (in encoder counts) from end of travel edge to set position B and C. -#define H1_VALVE_POSITION_B_OFFSET_COUNTS 500 -#define H1_VALVE_POSITION_C_OFFSET_COUNTS 600 -#define H19_VALVE_POSITION_B_OFFSET_COUNTS 700 -#define H19_VALVE_POSITION_C_OFFSET_COUNTS 900 +#define H1_VALVE_POSITION_B_OFFSET_COUNTS 450 ///< H1 encoder count offset applied from the Position B end of travel edge. +#define H1_VALVE_POSITION_C_OFFSET_COUNTS 900 ///< H1 encoder count offset applied from the Position C end of travel edge. +#define H19_VALVE_POSITION_B_OFFSET_COUNTS 720 ///< H19 encoder count offset applied from the Position B end of travel edge. +#define H19_VALVE_POSITION_C_OFFSET_COUNTS 800 ///< H19 encoder count offset applied from the Position C end of travel edge. #define PINCH_VALVE_FPGA_CMD_START_BIT_MASK 0x01 ///< FPGA command register bit 0 used to start a command transaction #define PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT_MASK 0x02 ///< FPGA command register bit 1 indicating a write only command. @@ -47,7 +47,7 @@ #define PINCH_VALVE_SPI_DONE_BIT_MASK 0x01 ///< SPI status bit 0 indicating command completion #define PINCH_VALVE_SPI_TX_COUNT_MASK 0x0E ///< SPI status mask for the transmitted word count #define PINCH_VALVE_SPI_TX_COUNT_SHIFT 1 ///< Bit shift for the SPI transmitted word count -#define PINCH_VALVE_SPI_RX_COUNT_MASK 0x30 ///< SPI status mask for the received-word count. +#define PINCH_VALVE_SPI_RX_COUNT_MASK 0x30 ///< SPI status mask for the received word count. #define PINCH_VALVE_SPI_RX_COUNT_SHIFT 4 ///< Bit shift for the SPI received word count #define PINCH_VALVE_SPI_CONTROLLER_FAULT_BIT_MASK 0x40 ///< SPI status bit 6 indicating a controller fault. @@ -62,7 +62,7 @@ #define PINCH_VALVE_PMD_CMD_SET_VELOCITY 0x0011 ///< Command used to set the requested movement velocity #define PINCH_VALVE_PMD_CMD_UPDATE 0x001A ///< Command used to apply previous written motion parameters #define PINCH_VALVE_PMD_CMD_GET_EVENT_STATUS 0x0031 ///< Command used to read the event status register -#define PINCH_VALVE_PMD_CMD_RESET_EVENT_STATUS 0x0034 ///< Command used to clear selected event-status bits. +#define PINCH_VALVE_PMD_CMD_RESET_EVENT_STATUS 0x0034 ///< Command used to clear selected event status bits. #define PINCH_VALVE_PMD_CMD_GET_ACTUAL_POSITION 0x0037 ///< Command used to read the current encoder position. #define PINCH_VALVE_PMD_CMD_SET_ACTUAL_POSITION 0x004D ///< Command used to assign the current encoder position #define PINCH_VALVE_PMD_CMD_SET_PROFILE_MODE 0x00A0 ///< Command used to select the motion profile mode @@ -76,7 +76,7 @@ static const S32 H1_HOMING_VELOCITY_SECOND = 3342; ///< Second H1 homing movement velocity ( Forward Direction ) static const S32 H19_HOMING_VELOCITY_FIRST = 3342; ///< First H19 homing movement velocity ( Forward Direction ) static const S32 H19_HOMING_VELOCITY_SECOND = -3342; ///< Second H19 homing movement velocity ( Reverse Direction ) -static const S32 POSITION_VELOCITY = 100000; ///< Velocity used for normal stored position movement +static const S32 POSITION_VELOCITY = 100000; ///< Velocity used for normal stored position movement #define PINCH_VALVE_EVENT_MOTION_COMPLETE_MASK 0x0001 ///< Event Status bit 0: motion complete. #define PINCH_VALVE_EVENT_MOTION_ERROR_MASK 0x0010 ///< Event Status bit 4: motion error. @@ -89,7 +89,7 @@ PINCH_VALVE_FUNCTION_WAIT_STATE ///< Waits for the current command to finish } PINCH_VALVE_FUNCTION_STATE_T; -/// Pinch Valve FPGA command state machine. +/// Pinch Valve command state machine. typedef enum pinchValveCommandStates { PINCH_VALVE_CMD_IDLE_STATE = 0, ///< Waits for a new command. @@ -109,7 +109,7 @@ U16 inputWord3; ///< Input word 3. U08 inputWordCount; ///< Number of valid input words, excluding the command header. U08 outputWordCount; ///< Number of output words expected. - BOOL writeOnly; ///< TRUE for a write-only command. + BOOL writeOnly; ///< TRUE for a write only command. } PINCH_VALVE_COMMAND_T; /// Pinch Valve Command for Homing sequence @@ -248,6 +248,17 @@ // ********** private function prototypes ********** +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdIdleState( VALVE_T valve ); +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdSetCmdState( VALVE_T valve ); +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdXmitCmdState( VALVE_T valve ); +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdWaitDoneState( VALVE_T valve ); +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdReadWordsState( VALVE_T valve ); +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdErrorState( VALVE_T valve ); + +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionIdleState( VALVE_T valve ); +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionSendState( VALVE_T valve ); +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionWaitState( VALVE_T valve ); + static BOOL setPinchValveCommand( VALVE_T valve, PINCH_VALVE_COMMAND_T command ); static BOOL writePinchValveCommandRegisters( VALVE_T valve ); @@ -335,22 +346,14 @@ fpgaCommandValue[ valve ] = 0; executeStartTime[ valve ] = 0; -// activeCommand[ valve ].cmdHeader = 0; -// activeCommand[ valve ].inputWord1 = 0; -// activeCommand[ valve ].inputWord2 = 0; -// activeCommand[ valve ].inputWord3 = 0; -// activeCommand[ valve ].inputWordCount = 0; -// activeCommand[ valve ].outputWordCount = 0; -// activeCommand[ valve ].writeOnly = FALSE; + motionStartTime[ valve ] = 0; - motionStartTime[ valve ] = 0; - clearActivePinchValveCommand( valve ); clearPinchValveCommandRegisters( valve ); setPinchValveEnableReset( valve, TRUE, FALSE ); - homingInProgress[ valve ] = FALSE; - positionInProgress[ valve ] = FALSE; + homingInProgress[ valve ] = FALSE; + positionInProgress[ valve ] = FALSE; } } @@ -359,14 +362,9 @@ * @brief * The execPinchValveCommand function executes the low level FPGA command * state machine. -* @details \b Inputs: commandState[], activeCommand[], commandSpiStatus[], -* commandErrorCount[], errorCountAtCommandStart[], executeStartTime[], -* fpgaCommandValue[] -* @details \b Outputs: commandState[], commandFailed[], -* commandOutputWord1[], commandOutputWord2[], commandOutputWord3[], -* commandSpiStatus[], commandErrorCount[], errorCountAtCommandStart[], -* executeStartTime[], fpgaCommandValue[], activeCommand[] -* @return none +* @details \b Inputs: commandState[] +* @details \b Outputs: commandState[] +* @return current state (sub-mode) *************************************************************************/ void execPinchValveCommand( void ) { @@ -377,121 +375,395 @@ switch ( commandState[ valve ] ) { case PINCH_VALVE_CMD_IDLE_STATE: + commandState[ valve ] = handlePinchValveCmdIdleState( valve ); break; case PINCH_VALVE_CMD_SET_CMD_STATE: - if ( TRUE == writePinchValveCommandRegisters( valve ) ) - { - errorCountAtCommandStart[ valve ] = readPinchValveErrorCount( valve ); - commandState[ valve ] = PINCH_VALVE_CMD_XMIT_CMD_STATE; - } - else - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } + commandState[ valve ] = handlePinchValveCmdSetCmdState( valve ); break; - case PINCH_VALVE_CMD_XMIT_CMD_STATE: - if ( TRUE == transmitPinchValveCommand( valve ) ) - { - executeStartTime[ valve ] = getMSTimerCount(); - commandState[ valve ] = PINCH_VALVE_CMD_WAIT_DONE_STATE; - } - else - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } + commandState[ valve ] = handlePinchValveCmdXmitCmdState( valve ); break; - case PINCH_VALVE_CMD_WAIT_DONE_STATE: - if ( TRUE == didTimeout( executeStartTime[ valve ], PINCH_VALVE_COMMAND_TIMEOUT_MS ) ) - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } - else - { - if ( H1_VALV == valve ) - { - commandSpiStatus[ valve ] = getH1SPICmdStatus(); - commandErrorCount[ valve ] = getH1ErrorCount(); - } - else - { - commandSpiStatus[ valve ] = getH19SPICmdStatus(); - commandErrorCount[ valve ] = getH19ErrorCount(); - } - if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || - ( TRUE == isPinchValveControllerFaultActive( valve ) ) ) - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } - else if ( TRUE == isPinchValveCommandResponseReady( valve ) ) - { - readPinchValveCommandResponse( valve ); - commandState[ valve ] = PINCH_VALVE_CMD_READ_WORDS_STATE; - } - } + commandState[ valve ] = handlePinchValveCmdWaitDoneState( valve ); break; case PINCH_VALVE_CMD_READ_WORDS_STATE: - - if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || - ( TRUE == isPinchValveControllerFaultActive( valve ) ) || - ( FALSE == arePinchValveWordCountsValid( valve ) ) ) - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } - else - { - PINCH_VALVE_CMD_STATE_T nextState; - - nextState = processPinchValveCommandOutput( valve ); - clearPinchValveFpgaCommand( valve ); - - if ( PINCH_VALVE_CMD_IDLE_STATE == nextState ) - { - clearActivePinchValveCommand( valve ); - commandFailed[ valve ] = FALSE; - commandState[ valve ] = PINCH_VALVE_CMD_IDLE_STATE; - } - else if ( PINCH_VALVE_CMD_SET_CMD_STATE == nextState ) - { - commandOutputWord1[ valve ] = 0; - commandOutputWord2[ valve ] = 0; - commandOutputWord3[ valve ] = 0; - commandSpiStatus[ valve ] = 0; - commandFailed[ valve ] = FALSE; - commandState[ valve ] = PINCH_VALVE_CMD_SET_CMD_STATE; - } - else - { - commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; - } - } + commandState[ valve ] = handlePinchValveCmdReadWordsState( valve ); break; - case PINCH_VALVE_CMD_ERROR_STATE: + commandState[ valve ] = handlePinchValveCmdErrorState( valve ); + break; + + default: + // Recover from an invalid command state. clearPinchValveCommandRegisters( valve ); clearActivePinchValveCommand( valve ); commandFailed[ valve ] = TRUE; commandState[ valve ] = PINCH_VALVE_CMD_IDLE_STATE; break; + } + } +} +/*********************************************************************//** +* @brief +* The handlePinchValveCmdIdleState function handles the command +* IDLE state. +* @details \b Inputs: valve +* @details \b Outputs: none +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdIdleState( VALVE_T valve ) +{ + ( void )valve; + + return PINCH_VALVE_CMD_IDLE_STATE; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveCmdSetCmdState function writes the active command +* registers and captures the FPGA error count before transmission. +* @details \b Inputs: valve +* @details \b Outputs: errorCountAtCommandStart[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdSetCmdState( VALVE_T valve ) +{ + PINCH_VALVE_CMD_STATE_T nextState = PINCH_VALVE_CMD_ERROR_STATE; + + if ( TRUE == writePinchValveCommandRegisters( valve ) ) + { + errorCountAtCommandStart[ valve ] = readPinchValveErrorCount( valve ); + nextState = PINCH_VALVE_CMD_XMIT_CMD_STATE; + } + + return nextState; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveCmdXmitCmdState function starts the FPGA command +* transaction and starts the command timeout timer. +* @details \b Inputs: valve +* @details \b Outputs: executeStartTime[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdXmitCmdState( VALVE_T valve ) +{ + PINCH_VALVE_CMD_STATE_T nextState = PINCH_VALVE_CMD_ERROR_STATE; + + if ( TRUE == transmitPinchValveCommand( valve ) ) + { + executeStartTime[ valve ] = getMSTimerCount(); + nextState = PINCH_VALVE_CMD_WAIT_DONE_STATE; + } + + return nextState; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveCmdWaitDoneState function waits for the FPGA command +* transaction to complete and validates command status. +* @details \b Inputs: valve, executeStartTime[] +* @details \b Outputs: commandSpiStatus[], commandErrorCount[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdWaitDoneState( VALVE_T valve ) +{ + PINCH_VALVE_CMD_STATE_T nextState = PINCH_VALVE_CMD_WAIT_DONE_STATE; + + if ( TRUE == didTimeout( executeStartTime[ valve ], PINCH_VALVE_COMMAND_TIMEOUT_MS ) ) + { + nextState = PINCH_VALVE_CMD_ERROR_STATE; + } + else + { + if ( H1_VALV == valve ) + { + commandSpiStatus[ valve ] = getH1SPICmdStatus(); + commandErrorCount[ valve ] = getH1ErrorCount(); + } + else if ( H19_VALV == valve ) + { + commandSpiStatus[ valve ] = getH19SPICmdStatus(); + commandErrorCount[ valve ] = getH19ErrorCount(); + } + + if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || + ( TRUE == isPinchValveControllerFaultActive( valve ) ) ) + { + nextState = PINCH_VALVE_CMD_ERROR_STATE; + } + else if ( TRUE == isPinchValveCommandResponseReady( valve ) ) + { + readPinchValveCommandResponse( valve ); + nextState = PINCH_VALVE_CMD_READ_WORDS_STATE; + } + } + + return nextState; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveCmdReadWordsState function validates and processes the +* completed command response. +* @details \b Inputs: valve +* @details \b Outputs: commandOutputWord1[], commandOutputWord2[], +* commandOutputWord3[], commandSpiStatus[], commandFailed[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdReadWordsState( VALVE_T valve ) +{ + PINCH_VALVE_CMD_STATE_T nextState; + + if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || + ( TRUE == isPinchValveControllerFaultActive( valve ) ) || + ( FALSE == arePinchValveWordCountsValid( valve ) ) ) + { + nextState = PINCH_VALVE_CMD_ERROR_STATE; + } + else + { + nextState = processPinchValveCommandOutput( valve ); + clearPinchValveFpgaCommand( valve ); + + if ( PINCH_VALVE_CMD_IDLE_STATE == nextState ) + { + clearActivePinchValveCommand( valve ); + commandFailed[ valve ] = FALSE; + } + else if ( PINCH_VALVE_CMD_SET_CMD_STATE == nextState ) + { + // This is to clear the previous response before repeating the command. + commandOutputWord1[ valve ] = 0; + commandOutputWord2[ valve ] = 0; + commandOutputWord3[ valve ] = 0; + commandSpiStatus[ valve ] = 0; + commandFailed[ valve ] = FALSE; + } + else + { + nextState = PINCH_VALVE_CMD_ERROR_STATE; + } + } + + return nextState; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveCmdErrorState function clears the failed FPGA command +* transaction and reports the command failure. +* @details \b Inputs: valve +* @details \b Outputs: commandFailed[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve command state machine. +*************************************************************************/ +static PINCH_VALVE_CMD_STATE_T handlePinchValveCmdErrorState( VALVE_T valve ) +{ + PINCH_VALVE_CMD_STATE_T nextState = PINCH_VALVE_CMD_IDLE_STATE; + + clearPinchValveCommandRegisters( valve ); + clearActivePinchValveCommand( valve ); + commandFailed[ valve ] = TRUE; + + return nextState; +} + +/*********************************************************************//** +* @brief +* The execPinchValveFunction function executes the pinch valve +* homing and position command sequence state machine. +* @details \b Inputs: functionState[] +* @details \b Outputs: functionState[] +* @return current state (sub-mode) +*************************************************************************/ +void execPinchValveFunction( void ) +{ + VALVE_T valve; + + for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) + { + switch ( functionState[ valve ] ) + { + case PINCH_VALVE_FUNCTION_IDLE_STATE: + functionState[ valve ] = handlePinchValveFunctionIdleState( valve ); + break; + + case PINCH_VALVE_FUNCTION_SEND_STATE: + functionState[ valve ] = handlePinchValveFunctionSendState( valve ); + break; + + case PINCH_VALVE_FUNCTION_WAIT_STATE: + functionState[ valve ] = handlePinchValveFunctionWaitState( valve ); + break; + default: - clearPinchValveCommandRegisters( valve ); - clearActivePinchValveCommand( valve ); commandFailed[ valve ] = TRUE; - commandState[ valve ] = PINCH_VALVE_CMD_IDLE_STATE; + resetPinchValveFunctionSequence( valve ); break; } } } /*********************************************************************//** * @brief +* The handlePinchValveFunctionIdleState function starts a pending homing or +* stored position command sequence. +* @details \b Inputs: valve, pendingValveHomeRequest[], +* pendingValvePositionRequest[], pendingValvePosition[], h1HomingCommands[], +* h19HomingCommands[], positionCommands[] +* @details \b Outputs: pendingValvePositionRequest[], homingInProgress[], positionInProgress[], +* activeCommandArray[], activeCommandCount[], activeCommandIndex[], +* commandFailed[], positionCommands[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve function state machine +*************************************************************************/ +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionIdleState( VALVE_T valve ) +{ + PINCH_VALVE_FUNCTION_STATE_T nextState = PINCH_VALVE_FUNCTION_IDLE_STATE; + + if ( TRUE == pendingValveHomeRequest[ valve ] ) + { + pendingValveHomeRequest[ valve ] = FALSE; + homingInProgress[ valve ] = TRUE; + + if ( H1_VALV == valve ) + { + activeCommandArray[ valve ] = h1HomingCommands; + } + else if ( H19_VALV == valve ) + { + activeCommandArray[ valve ] = h19HomingCommands; + } + else + { + activeCommandArray[ valve ] = 0; + } + + if ( 0 != activeCommandArray[ valve ] ) + { + activeCommandCount[ valve ] = NUM_OF_PINCH_VALVE_HOMING_COMMANDS; + activeCommandIndex[ valve ] = 0; + commandFailed[ valve ] = FALSE; + nextState = PINCH_VALVE_FUNCTION_SEND_STATE; + } + else + { + commandFailed[ valve ] = TRUE; + resetPinchValveFunctionSequence( valve ); + } + } + else if ( TRUE == pendingValvePositionRequest[ valve ] ) + { + pendingValvePositionRequest[ valve ] = FALSE; + positionInProgress[ valve ] = TRUE; + setSigned32CommandWords( &positionCommands[ PINCH_VALVE_POSITION_CMD_SET_POSITION ], pendingValvePosition[ valve ] ); + activeCommandArray[ valve ] = positionCommands; + activeCommandCount[ valve ] = NUM_OF_PINCH_VALVE_POSITION_COMMANDS; + activeCommandIndex[ valve ] = 0; + commandFailed[ valve ] = FALSE; + nextState = PINCH_VALVE_FUNCTION_SEND_STATE; + } + + return nextState; +} + + +/*********************************************************************//** +* @brief +* The handlePinchValveFunctionSendState function submits the next command +* in the active homing or position sequence. +* @details \b Inputs: valve, activeCommandArray[], activeCommandCount[], +* activeCommandIndex[], commandState[] +* @details \b Outputs: commandFailed[], activeCommand[], commandState[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve function state machine. +*************************************************************************/ +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionSendState( VALVE_T valve ) +{ + PINCH_VALVE_FUNCTION_STATE_T nextState = PINCH_VALVE_FUNCTION_SEND_STATE; + + if ( activeCommandIndex[ valve ] < activeCommandCount[ valve ] ) + { + if ( PINCH_VALVE_CMD_IDLE_STATE == commandState[ valve ] ) + { + if ( TRUE == setPinchValveCommand( valve, activeCommandArray[ valve ] [ activeCommandIndex[ valve ] ] ) ) + { + nextState = PINCH_VALVE_FUNCTION_WAIT_STATE; + } + else + { + commandFailed[ valve ] = TRUE; + resetPinchValveFunctionSequence( valve ); + nextState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + } + } + else + { + resetPinchValveFunctionSequence( valve ); + nextState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + + return nextState; +} + +/*********************************************************************//** +* @brief +* The handlePinchValveFunctionWaitState function waits for the active +* command to finish and advances to the next command in sequence. +* @details \b Inputs: valve, commandState[], commandFailed[], +* activeCommandIndex[], activeCommandCount[] +* @details \b Outputs: activeCommandIndex[] +* @param valve H1_VALV or H19_VALV. +* @return next Pinch Valve function state machine. +*************************************************************************/ +static PINCH_VALVE_FUNCTION_STATE_T handlePinchValveFunctionWaitState( VALVE_T valve ) +{ + PINCH_VALVE_FUNCTION_STATE_T nextState = PINCH_VALVE_FUNCTION_WAIT_STATE; + + if ( PINCH_VALVE_CMD_IDLE_STATE == commandState[ valve ] ) + { + if ( TRUE == commandFailed[ valve ] ) + { + // TODO: Later for s/w fault. + resetPinchValveFunctionSequence( valve ); + nextState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + else + { + activeCommandIndex[ valve ]++; + + if ( activeCommandIndex[ valve ] >= activeCommandCount[ valve ] ) + { + resetPinchValveFunctionSequence( valve ); + nextState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + else + { + nextState = PINCH_VALVE_FUNCTION_SEND_STATE; + } + } + } + + return nextState; +} + +/*********************************************************************//** +* @brief * The homePinchValve function requests the homing command sequence for the * selected pinch valve. * @details \b Inputs: valve, pendingValveHomeRequest[], @@ -539,7 +811,7 @@ pendingValvePositionRequest[ valve ] = TRUE; pendingValveHomeRequest[ valve ] = FALSE; commandFailed[ valve ] = FALSE; - result = TRUE; + result = TRUE; } return result; @@ -661,128 +933,6 @@ /*********************************************************************//** * @brief -* The execPinchValveFunction function executes the homing and -* position sequence state machine. -* @details \b Inputs: functionState[], commandState[], -* pendingValveHomeRequest[], pendingValvePositionRequest[], -* pendingValvePosition[], commandFailed[], activeCommandArray[], -* activeCommandCount[], activeCommandIndex[] -* @details \b Outputs: functionState[],pendingValveHomeRequest[], -* pendingValvePositionRequest[],commandFailed[], homingInProgress[], -* positionInProgress[], -* activeCommandArray[], activeCommandCount[], activeCommandIndex[], -* positionCommands[] -* @return none -*************************************************************************/ -void execPinchValveFunction( void ) -{ - VALVE_T valve; - - for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) - { - switch ( functionState[ valve ] ) - { - case PINCH_VALVE_FUNCTION_IDLE_STATE: - if ( TRUE == pendingValveHomeRequest[ valve ] ) - { - pendingValveHomeRequest[ valve ] = FALSE; - homingInProgress[ valve ] = TRUE; - if ( H1_VALV == valve ) - { - activeCommandArray[ valve ] = h1HomingCommands; - } - else if ( H19_VALV == valve ) - { - activeCommandArray[ valve ] = h19HomingCommands; - } - else - { - activeCommandArray[ valve ] = 0; - - } - // Then only continue when the array is valid: - if ( 0 != activeCommandArray[ valve ] ) - { - activeCommandCount[ valve ] = NUM_OF_PINCH_VALVE_HOMING_COMMANDS; - activeCommandIndex[ valve ] = 0; - commandFailed[ valve ] = FALSE; - functionState[ valve ] = PINCH_VALVE_FUNCTION_SEND_STATE; - } - else - { - commandFailed[ valve ] = TRUE; - resetPinchValveFunctionSequence( valve ); - } - } - else if ( TRUE == pendingValvePositionRequest[ valve ] ) - { - pendingValvePositionRequest[ valve ] = FALSE; - positionInProgress[ valve ] = TRUE; - setSigned32CommandWords( &positionCommands[ PINCH_VALVE_POSITION_CMD_SET_POSITION ], pendingValvePosition[ valve ] ); - activeCommandArray[ valve ] = positionCommands; - activeCommandCount[ valve ] = NUM_OF_PINCH_VALVE_POSITION_COMMANDS; - activeCommandIndex[ valve ] = 0; - commandFailed[ valve ] = FALSE; - functionState[ valve ] = PINCH_VALVE_FUNCTION_SEND_STATE; - } - break; - - case PINCH_VALVE_FUNCTION_SEND_STATE: - - if ( activeCommandIndex[ valve ] < activeCommandCount[ valve ] ) - { - if ( PINCH_VALVE_CMD_IDLE_STATE == commandState[ valve ] ) - { - if ( TRUE == setPinchValveCommand( valve, activeCommandArray[ valve ] [ activeCommandIndex[ valve ] ] ) ) - { - functionState[ valve ] = PINCH_VALVE_FUNCTION_WAIT_STATE; - } - else - { - commandFailed[ valve ] = TRUE; - resetPinchValveFunctionSequence( valve ); - } - } - } - else - { - resetPinchValveFunctionSequence( valve ); - } - break; - - case PINCH_VALVE_FUNCTION_WAIT_STATE: - if ( PINCH_VALVE_CMD_IDLE_STATE == commandState[ valve ] ) - { - if ( TRUE == commandFailed[ valve ] ) - { - resetPinchValveFunctionSequence( valve ); - // TODO: Connect this failure to the required valve fault or software fault handling after the alarm behavior is defined. - } - else - { - activeCommandIndex[ valve ]++; - if ( activeCommandIndex[ valve ] >= activeCommandCount[ valve ] ) - { - resetPinchValveFunctionSequence( valve ); - } - else - { - functionState[ valve ] = PINCH_VALVE_FUNCTION_SEND_STATE; - } - } - } - break; - - default: - commandFailed[ valve ] = TRUE; - resetPinchValveFunctionSequence( valve ); - break; - } - } -} - -/*********************************************************************//** -* @brief * The setPinchValveCommand function loads the selected command into the * command state machine. * @details \b Inputs: valve, command, commandState[] Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r61a682bdc061446828bdc1d868791422242b0ab7 -r0e809b89fe509c2968c3445898466dd8dd9411a9 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 61a682bdc061446828bdc1d868791422242b0ab7) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 0e809b89fe509c2968c3445898466dd8dd9411a9) @@ -212,21 +212,21 @@ U32 h10Speed; ///< Reg 34. H10 Syringe pump time between step toggle (1/2 step period). U16 h10DACData; ///< Reg 38. H10 Syringe pump DAC data (12 bits). U08 h10DACControl; ///< Reg 40. H10 Syringe pump ADC and DAC control register. - U16 nibpCtl; ///< Reg 41. NIBP control register. + U08 nibpCtl; ///< Reg 41. NIBP control register. U16 nibpInflate; ///< Reg 42. NIBP inflate pressure register. U32 h5SetSpeed; ///< Reg 44. H5 ejector motor set speed. - U16 h1CmdHeader; ///< Reg 48. H1 Magellan command header. - U16 h1InputWord1; ///< Reg 50. H1 Magellan input word 1. - U16 h1InputWord2; ///< Reg 52. H1 Magellan input word 2. - U16 h1InputWord3; ///< Reg 54. H1 Magellan input word 3. - U08 h1FPGACmd; ///< Reg 56. H1 Magellan FPGA command register. - U08 h1EnableReset; ///< Reg 57. H1 Magellan enable and reset register. - U16 h19CmdHeader; ///< Reg 58. H19 Magellan command header. - U16 h19InputWord1; ///< Reg 60. H19 Magellan input word 1. - U16 h19InputWord2; ///< Reg 62. H19 Magellan input word 2. - U16 h19InputWord3; ///< Reg 64. H19 Magellan input word 3. - U08 h19FPGACmd; ///< Reg 66. H19 Magellan FPGA command register. - U08 h19EnableReset; ///< Reg 67. H19 Magellan enable and reset register. + U16 h1CmdHeader; ///< Reg 48. H1 command header. + U16 h1InputWord1; ///< Reg 50. H1 input word 1. + U16 h1InputWord2; ///< Reg 52. H1 input word 2. + U16 h1InputWord3; ///< Reg 54. H1 input word 3. + U08 h1FPGACmd; ///< Reg 56. H1 FPGA command register. + U08 h1EnableReset; ///< Reg 57. H1 enable and reset register. + U16 h19CmdHeader; ///< Reg 58. H19 command header. + U16 h19InputWord1; ///< Reg 60. H19 input word 1. + U16 h19InputWord2; ///< Reg 62. H19 input word 2. + U16 h19InputWord3; ///< Reg 64. H19 input word 3. + U08 h19FPGACmd; ///< Reg 66. H19 FPGA command register. + U08 h19EnableReset; ///< Reg 67. H19 enable and reset register. } FPGA_ACTUATORS_T; #pragma pack(pop) @@ -1731,7 +1731,7 @@ /*********************************************************************//** * @brief - * The setH1InputWord2 function sets H1 Magellan input word 2. + * The setH1InputWord2 function sets H1 Magellan input word 2.hh * @details \b Inputs: fpgaActuatorSetPoints * @details \b Outputs: none * @param inputWord Input word 2 value.