Fisheye: Tag 078ab958e0cac18c5b8a5cc2f9d22710ac52aa1e refers to a dead (removed) revision in file `eback'. Fisheye: No comparison available. Pass `N' to diff? Index: firmware/App/Drivers/PinchValve.c =================================================================== diff -u -r7c5d664608c68233915578a07ec713f434d5407f -r078ab958e0cac18c5b8a5cc2f9d22710ac52aa1e --- firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 7c5d664608c68233915578a07ec713f434d5407f) +++ firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 078ab958e0cac18c5b8a5cc2f9d22710ac52aa1e) @@ -15,594 +15,774 @@ * ***************************************************************************/ - +#include "FpgaTD.h" #include "PinchValve.h" #include "RotaryValve.h" -#include "FpgaTD.h" #include "Timers.h" #include "Utilities.h" + /** - * @addtogroup PinchValve - * @{ - */ +* @addtogroup PinchValve +* @{ +*/ // ********** private definitions ********** -#define PINCH_VALVE_FPGA_CMD_START_BIT 0x01 -#define PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT 0x02 -#define PINCH_VALVE_FPGA_CMD_TX_WORDS_SHIFT 2 -#define PINCH_VALVE_FPGA_CMD_RX_WORDS_SHIFT 5 -#define PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK 0x03 +#define PINCH_VALVE_STATUS_POLL_INTERVAL_MS 10 ///< FPGA status polling interval in (ms). +#define PINCH_VALVE_COMMAND_TIMEOUT_MS 1000 ///< Maximum FPGA command execution time. -#define PINCH_VALVE_SPI_CMD_DONE_MASK 0x01 +#define PINCH_VALVE_FPGA_CMD_START_BIT_MASK 0x01 ///< Bit 0 starts a command transaction. (TODO: To change the comments later) +#define PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT_MASK 0x02 ///< Bit 1 selects a write-only command. +#define PINCH_VALVE_FPGA_CMD_TX_COUNT_SHIFT 2 ///< Bits 4-2 contain transmit word count. +#define PINCH_VALVE_FPGA_CMD_RX_COUNT_SHIFT 5 ///< Bits 7-5 contain receive word count. +#define PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK 0x07 ///< Three-bit FPGA word-count mask. -#define PINCH_VALVE_ENABLE_BIT 0x01 -#define PINCH_VALVE_RESET_BIT 0x02 +#define PINCH_VALVE_SPI_DONE_BIT_MASK 0x01 ///< SPI command completed. +#define PINCH_VALVE_SPI_TX_COUNT_MASK 0x0E ///< SPI status bits 3-1: transmitted words. +#define PINCH_VALVE_SPI_TX_COUNT_SHIFT 1 +#define PINCH_VALVE_SPI_RX_COUNT_MASK 0x30 ///< SPI status bits 5-4: received words. +#define PINCH_VALVE_SPI_RX_COUNT_SHIFT 4 +#define PINCH_VALVE_SPI_CONTROLLER_FAULT_BIT_MASK 0x40 ///< SPI status bit 6: controller fault. -#define PINCH_VALVE_EXECUTE_DELAY_MS 10 +#define PINCH_VALVE_ENABLE_BIT_MASK 0x01 ///< Enable controller. +#define PINCH_VALVE_RESET_BIT_MASK 0x02 ///< Reset controller. -#define PINCH_VALVE_NO_WORDS 0 -#define PINCH_VALVE_ONE_WORD 1 -#define PINCH_VALVE_TWO_WORDS 2 -#define PINCH_VALVE_THREE_WORDS 3 - -#define PINCH_VALVE_WRITE_READ_CMD FALSE -#define PINCH_VALVE_WRITE_ONLY_CMD TRUE - -/// Pinch valve driver state machine states. -typedef enum +/// Pinch Valve driver function state machine. +typedef enum pinchValveFunctionStates { - PINCH_VALVE_IDLE_STATE = 0, ///< Waiting for a new pinch valve command. - PINCH_VALVE_EXECUTE_STATE ///< Executing the active pinch valve command. -} PINCH_VALVE_STATE_T; + PINCH_VALVE_FUNCTION_IDLE_STATE = 0, ///< Waiting for a new command request. + PINCH_VALVE_FUNCTION_SEND_STATE, ///< Starts the low level command state machine. + PINCH_VALVE_FUNCTION_WAIT_STATE ///< Waits for command completion or error. +} PINCH_VALVE_FUNCTION_STATE_T; -/// Pinch valve execute state machine steps. -typedef enum +/// Low level FPGA command state machine. +typedef enum pinchValveCommandStates { - PINCH_VALVE_EXECUTE_STEP_WRITE_COMMAND = 0, ///< Write the PMD command to the FPGA. - PINCH_VALVE_EXECUTE_STEP_WAIT_FOR_FPGA, ///< Wait for the FPGA to complete the command transaction. - PINCH_VALVE_EXECUTE_STEP_READ_OUTPUT, ///< Read the command response from the FPGA. - PINCH_VALVE_EXECUTE_STEP_GET_EVENT_STATUS, ///< Read the PMD event status. - PINCH_VALVE_EXECUTE_STEP_GET_ACTIVITY_STATUS, ///< Read the PMD activity status. - PINCH_VALVE_EXECUTE_STEP_GET_ACTUAL_POSITION, ///< Read the PMD actual position. - PINCH_VALVE_EXECUTE_STEP_COMPLETE ///< Complete the current command and return to idle. -} PINCH_VALVE_EXECUTE_STEP_T; + PINCH_VALVE_CMD_IDLE_STATE = 0, ///< No FPGA command is active. + PINCH_VALVE_CMD_SET_CMD_STATE, ///< Writes header and input words. + PINCH_VALVE_CMD_XMIT_CMD_STATE, ///< Writes FPGA command byte. + PINCH_VALVE_CMD_WAIT_DONE_STATE, ///< Polls command-done status. + PINCH_VALVE_CMD_READ_WORDS_STATE, ///< Reads response words and counters. + PINCH_VALVE_CMD_ERROR_STATE, ///< Command failed. + PINCH_VALVE_CMD_READY_STATE ///< Command completed successfully. +} PINCH_VALVE_CMD_STATE_T; -/// Supported pinch valve command types. -typedef enum -{ - PINCH_VALVE_CMD_TYPE_NONE = 0, ///< No active command. - PINCH_VALVE_CMD_TYPE_HOME, ///< Home the pinch valve. - PINCH_VALVE_CMD_TYPE_POSITION, ///< Move the pinch valve to the requested position. - PINCH_VALVE_CMD_TYPE_READ_STATUS ///< Read the pinch valve status. -} PINCH_VALVE_CMD_TYPE_T; +// ********** private data ********** -/// Pinch valve command execution results. -typedef enum -{ - PINCH_VALVE_CMD_RESULT_IDLE = 0, ///< No command is active. - PINCH_VALVE_CMD_RESULT_BUSY, ///< Command is currently executing. - PINCH_VALVE_CMD_RESULT_COMPLETE, ///< Command completed successfully. - PINCH_VALVE_CMD_RESULT_ERROR ///< Command completed with an error. -} PINCH_VALVE_CMD_RESULT_T; +static PINCH_VALVE_FUNCTION_STATE_T functionState; ///< Current function state. +static PINCH_VALVE_CMD_STATE_T commandState; ///< Current command state. -/// Pinch valve command information. -typedef struct -{ - VALVE_T valve; ///< Target rotary pinch valve (H1 or H19). - PINCH_VALVE_CMD_TYPE_T cmdType; ///< Command type. - U16 cmdHeader; ///< PMD command header. - U16 inputWord1; ///< PMD command input word 1. - U16 inputWord2; ///< PMD command input word 2. - U16 inputWord3; ///< PMD command input word 3. - U08 txWordCount; ///< Number of words transmitted to the PMD controller. - U08 rxWordCount; ///< Number of words expected from the PMD controller. - BOOL writeOnly; ///< TRUE if the command is write only. - S32 targetPosition; ///< Requested target position. -} PINCH_VALVE_COMMAND_T; +static VALVE_T activeValve; ///< Valve executing the current command. +static PINCH_VALVE_COMMAND_T pendingCommand; ///< Command waiting to be started. +static PINCH_VALVE_COMMAND_T activeCommand; ///< Command currently being executed. -/// Pinch valve command response. -typedef struct -{ - U16 outputWord1; ///< PMD output word 1. - U16 outputWord2; ///< PMD output word 2. - U16 outputWord3; ///< PMD output word 3. - U08 spiCmdStatus; ///< FPGA SPI command status. - U08 readCount; ///< FPGA read counter. - U08 errorCount; ///< FPGA communication error counter. -} PINCH_VALVE_RESPONSE_T; +static PINCH_VALVE_RESPONSE_T currentResponse; ///< Response for the active command. +static PINCH_VALVE_RESPONSE_T lastResponse[ NUM_OF_VALVES ]; ///< Last response for each valve. +static PINCH_VALVE_CMD_RESULT_T commandResult; ///< Latest driver result. +static U08 enableResetValue[ NUM_OF_VALVES ]; ///< Last enable/reset value written per valve. +static U08 errorCountAtCommandStart; ///< Error counter captured before command start. -// ********** private data ********** +static U32 executeStartTime; ///< Execute transaction start time. +static U32 statusPollStartMSCount; ///< Status polling interval start time. -static PINCH_VALVE_STATE_T pinchValveState; -static PINCH_VALVE_EXECUTE_STEP_T executeStep;firmware -static PINCH_VALVE_COMMAND_T activeCommand; -static PINCH_VALVE_RESPONSE_T lastResponse; -static PINCH_VALVE_CMD_RESULT_T commandResult; -static BOOL commandPending; -static U32 executeStartTime; - // ********** private function prototypes ********** -static BOOL startPinchValveCommand( PINCH_VALVE_COMMAND_T command ); -static void execIdleState( void ); -static void execExecuteState( void ); +static void handlePinchValveFunction( void ); +static void handlePinchValveCommand( void ); -static void writeCommandToFpga( const PINCH_VALVE_COMMAND_T *command ); -static void readFpgaResponse( VALVE_T valve, PINCH_VALVE_RESPONSE_T *response ); -static void sendStatusReadCommand( VALVE_T valve, U16 commandHeader ); +static void writePinchValveCommandRegisters( void ); +static BOOL transmitPinchValveCommand( void ); +static void readPinchValveCommandResponse( void ); +static void clearPinchValveFpgaCommand( void ); -static BOOL isFpgaCommandDone( VALVE_T valve ); -static U08 buildFpgaCommandByte( U08 txWordCount, U08 rxWordCount, BOOL writeOnly ); -static void setValveEnableReset( VALVE_T valve, U08 enableReset ); -static void transitionToIdle( PINCH_VALVE_CMD_RESULT_T result ); +static BOOL buildPinchValveFpgaCommandByte( const PINCH_VALVE_COMMAND_T *command, U08 *fpgaCommand ); +static BOOL isPinchValveCommandDone( void ); +static BOOL isPinchValveControllerFaultActive( void ); +static BOOL didPinchValveErrorCountChange( void ); +static BOOL arePinchValveWordCountsValid( void ); +static U08 readPinchValveErrorCount( VALVE_T valve ); +static BOOL isValidPinchValve( VALVE_T valve ); +static BOOL isValidPinchValveCommand( const PINCH_VALVE_COMMAND_T *command ); +static void clearPinchValveResponse( PINCH_VALVE_RESPONSE_T *response ); /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -void initPinchValve( void ) +* @brief +* The initPinchValveDriver function initializes the pinch valve +* communication driver. +* @details \b Inputs: none +* @details \b Outputs: PinchValve driver unit is initialized +* @return none +*************************************************************************/ +void initPinchValveDriver( void ) { - pinchValveState = PINCH_VALVE_IDLE_STATE; - executeStep = PINCH_VALVE_EXECUTE_STEP_WRITE_COMMAND; + U32 valve; + + functionState = PINCH_VALVE_FUNCTION_IDLE_STATE; + commandState = PINCH_VALVE_CMD_IDLE_STATE; + activeValve = H1_VALV; commandResult = PINCH_VALVE_CMD_RESULT_IDLE; - commandPending = FALSE; - activeCommand.valve = H1_VALV; - activeCommand.cmdType = PINCH_VALVE_CMD_TYPE_NONE; - activeCommand.cmdHeader = 0; - activeCommand.inputWord1 = 0U; - activeCommand.inputWord2 = 0U; - activeCommand.inputWord3 = 0U; - activeCommand.txWordCount = 0U; - activeCommand.rxWordCount = 0U; - activeCommand.writeOnly = FALSE; - activeCommand.targetPosition = 0; + pendingCommand.cmdHeader = 0; + pendingCommand.inputWord1 = 0; + pendingCommand.inputWord2 = 0; + pendingCommand.inputWord3 = 0; + pendingCommand.inputWordCount = 0; + pendingCommand.outputWordCount = 0; + pendingCommand.writeOnly = FALSE; - lastResponse.outputWord1 = 0U; - lastResponse.outputWord2 = 0U; - lastResponse.outputWord3 = 0U; - lastResponse.spiCmdStatus = 0U; - lastResponse.readCount = 0U; - lastResponse.errorCount = 0U; + activeCommand = pendingCommand; - setValveEnableReset( H1_VALV, 0U ); - setValveEnableReset( H19_VALV, 0U ); -} + clearPinchValveResponse( ¤tResponse ); -/*********************************************************************//** - * @brief Executes the Magellan pinch valve state machine. - * @details \b Inputs: commandPending, pinchValveState - * @details \b Outputs: active command processing and response data - * @return none - *************************************************************************/ -void execPinchValve( void ) -{ - switch ( pinchValveState ) + for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { - case PINCH_VALVE_IDLE_STATE: - execIdleState(); - break; + clearPinchValveResponse( &lastResponse[ valve ] ); + enableResetValue[ valve ] = 0; + } - case PINCH_VALVE_EXECUTE_STATE: - execExecuteState(); - break; + errorCountAtCommandStart = 0; + executeStartTime = 0; + statusPollStartMSCount = 0; - default: - transitionToIdle( PINCH_VALVE_CMD_RESULT_ERROR ); - break; - } + clearPinchValveFpgaCommand(); } /*********************************************************************//** - * @brief Starts a pinch valve home command. - * @param valve Pinch valve identifier. - * @return TRUE when command was accepted, otherwise FALSE. - *************************************************************************/ -BOOL startPinchValveHome( VALVE_T valve ) +* @brief +* The execPinchValveDriver function executes the function and command state +* machines. +* TODO: All Inputs and Outputs will be changed later +* @details \b Inputs: PinchValve private data and FPGA response data +* @details \b Outputs: PinchValve private data and FPGA command data +* @return none +*************************************************************************/ +void execPinchValveDriver( void ) { - PINCH_VALVE_COMMAND_T command; + //TODO: Need to fix this + handlePinchValveCommand(); + handlePinchValveFunction(); +} - command.valve = valve; - command.cmdType = PINCH_VALVE_CMD_TYPE_HOME; - command.cmdHeader = PINCH_VALVE_PMD_CMD_SET_OPERATING_MODE; - command.inputWord1 = 0x0037U; - command.inputWord2 = 0; - command.inputWord3 = 0; - command.txWordCount = PINCH_VALVE_ONE_WORD; - command.rxWordCount = PINCH_VALVE_NO_WORDS; - command.writeOnly = PINCH_VALVE_WRITE_ONLY_CMD; - command.targetPosition = 0; +/*********************************************************************//** +* @brief +* The setPinchValveCommand function requests execution of one generic +* Magellan command. +* @details \b Inputs: valve, command +* @details \b Outputs: pendingCommand, functionState, commandResult +* @param valve H1_VALV or H19_VALV. +* @param command Command header, input words, word counts, and transaction type. +* @return TRUE if the request was accepted, FALSE otherwise. +*************************************************************************/ +BOOL setPinchValveCommand( VALVE_T valve, const PINCH_VALVE_COMMAND_T *command ) +{ + BOOL result = FALSE; - return startPinchValveCommand( command ); + if ( ( TRUE == isValidPinchValve( valve ) ) && ( TRUE == isValidPinchValveCommand( command ) ) && + ( PINCH_VALVE_FUNCTION_IDLE_STATE == functionState ) && ( PINCH_VALVE_CMD_IDLE_STATE == commandState ) ) + { + activeValve = valve; + pendingCommand = *command; + commandResult = PINCH_VALVE_CMD_RESULT_BUSY; + functionState = PINCH_VALVE_FUNCTION_SEND_STATE; + result = TRUE; + } + + return result; } /*********************************************************************//** - * @brief Starts a pinch valve move command. - * @param valve Pinch valve identifier. - * @param targetPosition Target motor position in counts. - * @return TRUE when command was accepted, otherwise FALSE. - *************************************************************************/ -BOOL startPinchValveMove( VALVE_T valve, S32 targetPosition ) +* @brief +* The setPinchValveEnableReset function sets the enable and reset +* register for the selected valve. +* @details \b Inputs: valve, enable, reset +* @details \b Outputs: FPGA enable/reset register, enableResetValue[] +* @param valve H1_VALV or H19_VALV. +* @param enable TRUE to enable the controller. +* @param reset TRUE to assert the reset bit. +* @return none +*************************************************************************/ +void setPinchValveEnableReset( VALVE_T valve, BOOL enable, BOOL reset ) { - PINCH_VALVE_COMMAND_T command; + U08 value = 0; - command.valve = valve; - command.cmdType = PINCH_VALVE_CMD_TYPE_POSITION; - command.cmdHeader = PINCH_VALVE_PMD_CMD_SET_POSITION; - command.inputWord1 = (U16)( targetPosition & 0x0000FFFFL ); - command.inputWord2 = (U16)( ( targetPosition >> 16 ) & 0x0000FFFFL ); - command.inputWord3 = 0; - command.txWordCount = PINCH_VALVE_TWO_WORDS; - command.rxWordCount = PINCH_VALVE_NO_WORDS; - command.writeOnly = PINCH_VALVE_WRITE_ONLY_CMD; - command.targetPosition = targetPosition; + if ( TRUE == enable ) + { + value |= PINCH_VALVE_ENABLE_BIT_MASK; + } - return startPinchValveCommand( command ); + if ( TRUE == reset ) + { + value |= PINCH_VALVE_RESET_BIT_MASK; + } + + if ( H1_VALV == valve ) + { + enableResetValue[ H1_VALV ] = value; + setH1EnableReset( value ); + } + else if ( H19_VALV == valve ) + { + enableResetValue[ H19_VALV ] = value; + setH19EnableReset( value ); + } + else + { + // TODO: Check with Sean and update later (Invalid valve. The caller can verify the valve before calling) + } } /*********************************************************************//** - * @brief Starts a status read command for the selected pinch valve. - * @param valve Pinch valve identifier. - * @return TRUE when command was accepted, otherwise FALSE. - *************************************************************************/ -BOOL startPinchValveReadStatus( VALVE_T valve ) +* @brief +* The getPinchValveEnableReset function returns the last enable/reset value +* written for the selected valve. +* @details \b Inputs: enableResetValue[] +* @details \b Outputs: none +* @param valve H1_VALV or H19_VALV. +* @return Last enable/reset value, or 0 for an invalid valve. +*************************************************************************/ +U08 getPinchValveEnableReset( VALVE_T valve ) { - PINCH_VALVE_COMMAND_T command; + U08 result = 0; - command.valve = valve; - command.cmdType = PINCH_VALVE_CMD_TYPE_READ_STATUS; - command.cmdHeader = PINCH_VALVE_PMD_CMD_GET_EVENT_STATUS; - command.inputWord1 = 0U; - command.inputWord2 = 0U; - command.inputWord3 = 0U; - command.txWordCount = PINCH_VALVE_NO_WORDS; - command.rxWordCount = PINCH_VALVE_ONE_WORD; - command.writeOnly = PINCH_VALVE_WRITE_READ_CMD; - command.targetPosition = 0; + if ( TRUE == isValidPinchValve( valve ) ) + { + result = enableResetValue[ valve ]; + } - return startPinchValveCommand( command ); + return result; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -PINCH_VALVE_STATE_T getPinchValveState( void ) +* @brief +* The isPinchValveBusy function indicates whether a command is active. +* @details \b Inputs: functionState, commandState +* @details \b Outputs: none +* @return TRUE if the driver is busy, FALSE otherwise. +*************************************************************************/ +BOOL isPinchValveBusy( void ) { - return pinchValveState; + return ( ( PINCH_VALVE_FUNCTION_IDLE_STATE != functionState ) || + ( PINCH_VALVE_CMD_IDLE_STATE != commandState ) ); } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ +* @brief +* The getPinchValveCommandResult function returns the latest command result. +* @details \b Inputs: commandResult +* @details \b Outputs: none +* @return Latest driver command result. +*************************************************************************/ PINCH_VALVE_CMD_RESULT_T getPinchValveCommandResult( void ) { return commandResult; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -void getPinchValveResponse( PINCH_VALVE_RESPONSE_T *response ) +* @brief +* The getPinchValveResponse function returns the last response for a valve. +* @details \b Inputs: lastResponse[] +* @details \b Outputs: response +* @param valve H1_VALV or H19_VALV. +* @param response Destination for the response data. +* @return TRUE if the response was returned, FALSE otherwise. +*************************************************************************/ +BOOL getPinchValveResponse( VALVE_T valve, PINCH_VALVE_RESPONSE_T *response ) { - if ( response != NULL ) - { - *response = lastResponse; - } -} + BOOL result = FALSE; -/*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static BOOL startPinchValveCommand( PINCH_VALVE_COMMAND_T command ) -{ - BOOL accepted = FALSE; - - if ( ( pinchValveState == PINCH_VALVE_IDLE_STATE ) && ( commandPending == FALSE ) ) + if ( ( TRUE == isValidPinchValve( valve ) ) && ( response != 0 ) ) { - activeCommand = command; - commandPending = TRUE; - commandResult = PINCH_VALVE_CMD_RESULT_BUSY; - accepted = TRUE; + *response = lastResponse[ valve ]; + result = TRUE; } - return accepted; + return result; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void execIdleState( void ) +* @brief +* The handlePinchValveFunction function executes the high level +* IDLE, SEND, and WAIT state machine. +* @details \b Inputs: functionState, commandState +* @details \b Outputs: functionState, commandState, commandResult +* @return none +*************************************************************************/ +static void handlePinchValveFunction( void ) { - if ( commandPending == TRUE ) + switch ( functionState ) { - executeStep = PINCH_VALVE_EXECUTE_STEP_WRITE_COMMAND; - pinchValveState = PINCH_VALVE_EXECUTE_STATE; + case PINCH_VALVE_FUNCTION_IDLE_STATE: + { + // TODO: Check with Sean and update later + break; + } + + case PINCH_VALVE_FUNCTION_SEND_STATE: + { + activeCommand = pendingCommand; + clearPinchValveResponse( ¤tResponse ); + commandState = PINCH_VALVE_CMD_SET_CMD_STATE; + functionState = PINCH_VALVE_FUNCTION_WAIT_STATE; + break; + } + + case PINCH_VALVE_FUNCTION_WAIT_STATE: + { + if ( PINCH_VALVE_CMD_READY_STATE == commandState ) + { + clearPinchValveFpgaCommand(); + lastResponse[ activeValve ] = currentResponse; + commandResult = PINCH_VALVE_CMD_RESULT_COMPLETE; + commandState = PINCH_VALVE_CMD_IDLE_STATE; + functionState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + else if ( PINCH_VALVE_CMD_ERROR_STATE == commandState ) + { + clearPinchValveFpgaCommand(); + lastResponse[ activeValve ] = currentResponse; + commandResult = PINCH_VALVE_CMD_RESULT_ERROR; + commandState = PINCH_VALVE_CMD_IDLE_STATE; + functionState = PINCH_VALVE_FUNCTION_IDLE_STATE; + } + else + { + //TODO: Check with Sean and update later (The command state machine is still executing) + } + + break; + } + + default: + { + clearPinchValveFpgaCommand(); + commandResult = PINCH_VALVE_CMD_RESULT_ERROR; + commandState = PINCH_VALVE_CMD_IDLE_STATE; + functionState = PINCH_VALVE_FUNCTION_IDLE_STATE; + break; + } } } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void execExecuteState( void ) +* @brief +* The handlePinchValveCommand function executes one FPGA command +* transaction. +* @details \b Inputs: activeCommand, activeValve, FPGA response data +* @details \b Outputs: FPGA command data, currentResponse, commandState +* @return none +*************************************************************************/ +static void handlePinchValveCommand( void ) { - switch ( executeStep ) + switch ( commandState ) { - case PINCH_VALVE_EXECUTE_STEP_WRITE_COMMAND: + case PINCH_VALVE_CMD_IDLE_STATE: { - // Step 1: write command header, input words, and FPGA command. - writeCommandToFpga( &activeCommand ); - executeStartTime = getMSTimerCount(); - executeStep = PINCH_VALVE_EXECUTE_STEP_WAIT_FOR_FPGA; break; } - case PINCH_VALVE_EXECUTE_STEP_WAIT_FOR_FPGA: + case PINCH_VALVE_CMD_SET_CMD_STATE: { - // Step 2: wait 10 ms before reading FPGA response. - if ( didTimeout( executeStartTime, PINCH_VALVE_EXECUTE_DELAY_MS ) == TRUE ) + writePinchValveCommandRegisters(); + + if ( PINCH_VALVE_CMD_ERROR_STATE != commandState ) { - executeStep = PINCH_VALVE_EXECUTE_STEP_READ_OUTPUT; + errorCountAtCommandStart = readPinchValveErrorCount( activeValve ); + commandState = PINCH_VALVE_CMD_XMIT_CMD_STATE; } + break; } - case PINCH_VALVE_EXECUTE_STEP_READ_OUTPUT: + case PINCH_VALVE_CMD_XMIT_CMD_STATE: { - //Step 3: read SPI status and output words. - readFpgaResponse( activeCommand.valve, &lastResponse ); - - if ( isFpgaCommandDone( activeCommand.valve ) == TRUE ) + if ( TRUE == transmitPinchValveCommand() ) { - executeStep = PINCH_VALVE_EXECUTE_STEP_GET_EVENT_STATUS; + executeStartTime = getMSTimerCount(); + statusPollStartMSCount = executeStartTime; + commandState = PINCH_VALVE_CMD_WAIT_DONE_STATE; } else { - // FPGA is still busy. Wait before checking again. - executeStartTime = getMSTimerCount(); - executeStep = PINCH_VALVE_EXECUTE_STEP_WAIT_FOR_FPGA; + commandState = PINCH_VALVE_CMD_ERROR_STATE; } + break; } - case PINCH_VALVE_EXECUTE_STEP_GET_EVENT_STATUS: + case PINCH_VALVE_CMD_WAIT_DONE_STATE: { - // Step 4: request PMD event status. - sendStatusReadCommand( activeCommand.valve, PINCH_VALVE_PMD_CMD_GET_EVENT_STATUS ); - executeStartTime = getMSTimerCount(); - executeStep = PINCH_VALVE_EXECUTE_STEP_GET_ACTIVITY_STATUS; + if ( TRUE == didTimeout( executeStartTime, PINCH_VALVE_COMMAND_TIMEOUT_MS ) ) + { + readPinchValveCommandResponse(); + commandState = PINCH_VALVE_CMD_ERROR_STATE; + } + else if ( TRUE == didTimeout( statusPollStartMSCount, PINCH_VALVE_STATUS_POLL_INTERVAL_MS ) ) + { + readPinchValveCommandResponse(); + statusPollStartMSCount = getMSTimerCount(); + + if ( ( TRUE == didPinchValveErrorCountChange() ) || ( TRUE == isPinchValveControllerFaultActive() ) ) + { + commandState = PINCH_VALVE_CMD_ERROR_STATE; + } + else if ( TRUE == isPinchValveCommandDone() ) + { + commandState = PINCH_VALVE_CMD_READ_WORDS_STATE; + } + else + { + // TODO: Remove later (FPGA command is still executing) + } + } + else + { + // TODO: Remove later (Wait for the next polling interval) + } + break; } - case PINCH_VALVE_EXECUTE_STEP_GET_ACTIVITY_STATUS: + case PINCH_VALVE_CMD_READ_WORDS_STATE: { - // Step 5: request PMD activity status. - if ( didTimeout( executeStartTime, PINCH_VALVE_EXECUTE_DELAY_MS ) == TRUE ) + readPinchValveCommandResponse(); + + if ( ( TRUE == didPinchValveErrorCountChange() ) || ( TRUE == isPinchValveControllerFaultActive() ) || ( FALSE == arePinchValveWordCountsValid() ) ) { - readFpgaResponse( activeCommand.valve, &lastResponse ); - sendStatusReadCommand( activeCommand.valve, PINCH_VALVE_PMD_CMD_GET_ACTIVITY_STATUS ); - executeStartTime = getMSTimerCount(); - executeStep = PINCH_VALVE_EXECUTE_STEP_GET_ACTUAL_POSITION; + commandState = PINCH_VALVE_CMD_ERROR_STATE; } + else + { + commandState = PINCH_VALVE_CMD_READY_STATE; + } + break; } - case PINCH_VALVE_EXECUTE_STEP_GET_ACTUAL_POSITION: + case PINCH_VALVE_CMD_ERROR_STATE: { - // Step 6: request actual position and read final output. - if ( didTimeout( executeStartTime, PINCH_VALVE_EXECUTE_DELAY_MS ) == TRUE ) - { - readFpgaResponse( activeCommand.valve, &lastResponse ); - sendStatusReadCommand( activeCommand.valve, PINCH_VALVE_PMD_CMD_GET_ACTUAL_POSITION ); - executeStartTime = getMSTimerCount(); - executeStep = PINCH_VALVE_EXECUTE_STEP_COMPLETE; - } + // TODO: Check with Sean and update later break; } - case PINCH_VALVE_EXECUTE_STEP_COMPLETE: + case PINCH_VALVE_CMD_READY_STATE: { - // Step 7: read final response and return to Idle. - if ( didTimeout( executeStartTime, PINCH_VALVE_EXECUTE_DELAY_MS ) == TRUE ) - { - readFpgaResponse( activeCommand.valve, &lastResponse ); - transitionToIdle( PINCH_VALVE_CMD_RESULT_COMPLETE ); - } + // TODO: Check with Sean and update later break; } default: { - transitionToIdle( PINCH_VALVE_CMD_RESULT_ERROR ); + commandState = PINCH_VALVE_CMD_ERROR_STATE; break; } } } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void writeCommandToFpga( const PINCH_VALVE_COMMAND_T *command ) +* @brief +* The writePinchValveCommandRegisters function writes the command header and +* input words through the FpgaTD interface. +* @details \b Inputs: activeValve, activeCommand +* @details \b Outputs: FPGA command header and input registers +* @return none +*************************************************************************/ +static void writePinchValveCommandRegisters( void ) { - U08 fpgaCmd; + if ( H1_VALV == activeValve ) + { + setH1CmdHeader( activeCommand.cmdHeader ); + setH1InputWord1( activeCommand.inputWord1 ); + setH1InputWord2( activeCommand.inputWord2 ); + setH1InputWord3( activeCommand.inputWord3 ); + } + else if ( H19_VALV == activeValve ) + { + setH19CmdHeader( activeCommand.cmdHeader ); + setH19InputWord1( activeCommand.inputWord1 ); + setH19InputWord2( activeCommand.inputWord2 ); + setH19InputWord3( activeCommand.inputWord3 ); + } + else + { + commandState = PINCH_VALVE_CMD_ERROR_STATE; + } +} - fpgaCmd = buildFpgaCommandByte( command->txWordCount, - command->rxWordCount, - command->writeOnly ); +/*********************************************************************//** +* @brief +* The transmitPinchValveCommand function builds and writes the FPGA command +* byte. +* @details \b Inputs: activeValve, activeCommand +* @details \b Outputs: FPGA command register +* @return TRUE if the command byte was valid and written. +*************************************************************************/ +static BOOL transmitPinchValveCommand( void ) +{ + BOOL result = FALSE; + U08 fpgaCommand; - if ( command->valve == H1_VALV ) + if ( TRUE == buildPinchValveFpgaCommandByte( &activeCommand, &fpgaCommand ) ) { - setH1CmdHeader( command->cmdHeader ); - setH1InputWord1( command->inputWord1 ); - setH1InputWord2( command->inputWord2 ); - setH1InputWord3( command->inputWord3 ); - setH1FPGACmd( fpgaCmd ); + if ( H1_VALV == activeValve ) + { + setH1FPGACmd( fpgaCommand ); + result = TRUE; + } + else if ( H19_VALV == activeValve ) + { + setH19FPGACmd( fpgaCommand ); + result = TRUE; + } + else + { + //TODO: Check with Sean and remove later + } } + + return result; +} + +/*********************************************************************//** +* @brief +* The readPinchValveCommandResponse function reads the active valve response +* through the FpgaTD interface. +* @details \b Inputs: activeValve, FPGA response registers +* @details \b Outputs: currentResponse +* @return none +*************************************************************************/ +static void readPinchValveCommandResponse( void ) +{ + if ( H1_VALV == activeValve ) + { + currentResponse.spiCmdStatus = getH1SPICmdStatus(); + currentResponse.readCount = getH1ReadCount(); + currentResponse.errorCount = getH1ErrorCount(); + currentResponse.outputWord1 = getH1OutputWord1(); + currentResponse.outputWord2 = getH1OutputWord2(); + currentResponse.outputWord3 = getH1OutputWord3(); + } + else if ( H19_VALV == activeValve ) + { + currentResponse.spiCmdStatus = getH19SPICmdStatus(); + currentResponse.readCount = getH19ReadCount(); + currentResponse.errorCount = getH19ErrorCount(); + currentResponse.outputWord1 = getH19OutputWord1(); + currentResponse.outputWord2 = getH19OutputWord2(); + currentResponse.outputWord3 = getH19OutputWord3(); + } else { - setH19CmdHeader( command->cmdHeader ); - setH19InputWord1( command->inputWord1 ); - setH19InputWord2( command->inputWord2 ); - setH19InputWord3( command->inputWord3 ); - setH19FPGACmd( fpgaCmd ); + clearPinchValveResponse( ¤tResponse ); } } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void readFpgaResponse( VALVE_T valve, PINCH_VALVE_RESPONSE_T *response ) +* @brief +* The clearPinchValveFpgaCommand function clears the active valve FPGA command +* register. +* @details \b Inputs: activeValve +* @details \b Outputs: FPGA command register +* @return none +*************************************************************************/ +static void clearPinchValveFpgaCommand( void ) { - if ( valve == H1_VALV ) + if ( H1_VALV == activeValve ) { - response->spiCmdStatus = getH1SPICmdStatus(); - response->readCount = getH1ReadCount(); - response->errorCount = getH1ErrorCount(); - response->outputWord1 = getH1OutputWord1(); - response->outputWord2 = getH1OutputWord2(); - response->outputWord3 = getH1OutputWord3(); + setH1FPGACmd( 0 ); } + else if ( H19_VALV == activeValve ) + { + setH19FPGACmd( 0 ); + } else { - response->spiCmdStatus = getH19SPICmdStatus(); - response->readCount = getH19ReadCount(); - response->errorCount = getH19ErrorCount(); - response->outputWord1 = getH19OutputWord1(); - response->outputWord2 = getH19OutputWord2(); - response->outputWord3 = getH19OutputWord3(); + //TODO: Check with Sean and Update } } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void sendStatusReadCommand( VALVE_T valve, U16 commandHeader ) +* @brief +* The buildPinchValveFpgaCommandByte function builds the FPGA command byte. +* @details The transmit count includes the command header, so one is added to +* the number of input words. +* @details \b Inputs: command +* @details \b Outputs: fpgaCommand +* @param command Pinch valve command request. +* @param fpgaCommand Destination for the built FPGA command byte. +* @return TRUE if the word counts are valid. +*************************************************************************/ +static BOOL buildPinchValveFpgaCommandByte( const PINCH_VALVE_COMMAND_T *command, U08 *fpgaCommand ) { - PINCH_VALVE_COMMAND_T statusCommand; + BOOL result = FALSE; - statusCommand.valve = valve; - statusCommand.cmdType = PINCH_VALVE_CMD_TYPE_READ_STATUS; - statusCommand.cmdHeader = commandHeader; - statusCommand.inputWord1 = 0U; - statusCommand.inputWord2 = 0U; - statusCommand.inputWord3 = 0U; - statusCommand.txWordCount = PINCH_VALVE_NO_WORDS; - statusCommand.rxWordCount = PINCH_VALVE_ONE_WORD; - statusCommand.writeOnly = PINCH_VALVE_WRITE_READ_CMD; - statusCommand.targetPosition = 0; + if ( ( command != 0 ) && ( fpgaCommand != 0 ) ) + { + U08 transmitWordCount = (U08)( command->inputWordCount + 1 ); - writeCommandToFpga( &statusCommand ); + if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && + ( transmitWordCount <= 4 ) ) + { + *fpgaCommand = PINCH_VALVE_FPGA_CMD_START_BIT_MASK; + + if ( TRUE == command->writeOnly ) + { + *fpgaCommand |= PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT_MASK; + } + + *fpgaCommand |= (U08)( ( transmitWordCount & PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK ) << PINCH_VALVE_FPGA_CMD_TX_COUNT_SHIFT ); + + *fpgaCommand |= (U08)( ( command->outputWordCount & PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK ) << PINCH_VALVE_FPGA_CMD_RX_COUNT_SHIFT ); + + result = TRUE; + } + } + + return result; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static BOOL isFpgaCommandDone( VALVE_T valve ) +* @brief +* The isPinchValveCommandDone function checks the SPI command-done bit. +* @details \b Inputs: currentResponse +* @details \b Outputs: none +* @return TRUE if the FPGA transaction is complete. +*************************************************************************/ +static BOOL isPinchValveCommandDone( void ) { - U08 status; + return ( ( currentResponse.spiCmdStatus & PINCH_VALVE_SPI_DONE_BIT_MASK ) != 0 ); +} - if ( valve == H1_VALV ) +/*********************************************************************//** +* @brief +* The isPinchValveControllerFaultActive function checks the controller fault +* status bit. +* @details \b Inputs: currentResponse +* @details \b Outputs: none +* @return TRUE if the controller fault bit is active. +*************************************************************************/ +static BOOL isPinchValveControllerFaultActive( void ) +{ + return ( ( currentResponse.spiCmdStatus & PINCH_VALVE_SPI_CONTROLLER_FAULT_BIT_MASK ) != 0 ); +} + +/*********************************************************************//** +* @brief +* The didPinchValveErrorCountChange function checks whether the active +* transaction incremented the invalid-command counter. +* @details \b Inputs: errorCountAtCommandStart, currentResponse.errorCount +* @details \b Outputs: none +* @return TRUE if the error count changed. +*************************************************************************/ +static BOOL didPinchValveErrorCountChange( void ) +{ + return ( currentResponse.errorCount != errorCountAtCommandStart ); +} + +/*********************************************************************//** +* @brief +* The arePinchValveWordCountsValid function verifies the FPGA-reported +* transmitted and received word counts. +* @details \b Inputs: currentResponse.spiCmdStatus, activeCommand +* @details \b Outputs: none +* @return TRUE if reported counts match the command. +*************************************************************************/ +static BOOL arePinchValveWordCountsValid( void ) +{ + U08 expectedTransmitCount = (U08)( activeCommand.inputWordCount + 1 ); + U08 transmittedCount = (U08)( ( currentResponse.spiCmdStatus & PINCH_VALVE_SPI_TX_COUNT_MASK ) >> PINCH_VALVE_SPI_TX_COUNT_SHIFT ); + U08 receivedCount = (U08)( ( currentResponse.spiCmdStatus & PINCH_VALVE_SPI_RX_COUNT_MASK ) >> PINCH_VALVE_SPI_RX_COUNT_SHIFT ); + + return ( ( transmittedCount == expectedTransmitCount ) && ( receivedCount == activeCommand.outputWordCount ) ); +} + +/*********************************************************************//** +* @brief +* The readPinchValveErrorCount function returns the current error count for +* the selected valve. +* @details \b Inputs: FPGA response registers +* @details \b Outputs: none +* @param valve H1_VALV or H19_VALV. +* @return Current error count, or 0 for an invalid valve. +*************************************************************************/ +static U08 readPinchValveErrorCount( VALVE_T valve ) +{ + U08 result = 0; + + if ( H1_VALV == valve ) { - status = getH1SPICmdStatus(); + result = getH1ErrorCount(); } + else if ( H19_VALV == valve ) + { + result = getH19ErrorCount(); + } else { - status = getH19SPICmdStatus(); + // TODO: Check with Sean and Remove later ( Invalid valve ) } - return ( ( status & PINCH_VALVE_SPI_CMD_DONE_MASK ) != 0U ); + return result; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static U08 buildFpgaCommandByte( U08 txWordCount, U08 rxWordCount, BOOL writeOnly ) +* @brief +* The isValidPinchValve function validates a valve ID. +* @details \b Inputs: valve +* @details \b Outputs: none +* @param valve Valve to validate. +* @return TRUE if the valve is H1 or H19. +*************************************************************************/ +static BOOL isValidPinchValve( VALVE_T valve ) { - U08 fpgaCmd = PINCH_VALVE_FPGA_CMD_START_BIT; + return ( ( H1_VALV == valve ) || ( H19_VALV == valve ) ); +} - txWordCount &= PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK; - rxWordCount &= PINCH_VALVE_FPGA_CMD_WORD_COUNT_MASK; +/*********************************************************************//** +* @brief +* The isValidPinchValveCommand function validates a generic command request. +* @details \b Inputs: command +* @details \b Outputs: none +* @param command Command to validate. +* @return TRUE if the request is valid. +*************************************************************************/ +static BOOL isValidPinchValveCommand( const PINCH_VALVE_COMMAND_T *command ) +{ + BOOL result = FALSE; - if ( writeOnly == TRUE ) + if ( command != 0 ) { - fpgaCmd |= PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT; + if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && + ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) ) + { + result = TRUE; + } } - fpgaCmd |= (U08)( txWordCount << PINCH_VALVE_FPGA_CMD_TX_WORDS_SHIFT ); - fpgaCmd |= (U08)( rxWordCount << PINCH_VALVE_FPGA_CMD_RX_WORDS_SHIFT ); - - return fpgaCmd; + return result; } /*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void setValveEnableReset( VALVE_T valve, U08 enableReset ) +* @brief +* The clearPinchValveResponse function clears a response structure. +* @details \b Inputs: response +* @details \b Outputs: response +* @param response Response structure to clear. +* @return none +*************************************************************************/ +static void clearPinchValveResponse( PINCH_VALVE_RESPONSE_T *response ) { - if ( valve == H1_VALV ) + if ( response != 0 ) { - setH1EnableReset( enableReset ); + response->outputWord1 = 0; + response->outputWord2 = 0; + response->outputWord3 = 0; + response->spiCmdStatus = 0; + response->readCount = 0; + response->errorCount = 0; } - else - { - setH19EnableReset( enableReset ); - } } -/*********************************************************************//** - * @brief Initializes the Magellan pinch valve driver. - * @details \b Inputs: none - * @details \b Outputs: Pinch valve private state data initialized. - * @return none - *************************************************************************/ -static void transitionToIdle( PINCH_VALVE_CMD_RESULT_T result ) -{ - commandPending = FALSE; - commandResult = result; - executeStep = PINCH_VALVE_EXECUTE_STEP_WRITE_COMMAND; - activeCommand.cmdType = PINCH_VALVE_CMD_TYPE_NONE; - pinchValveState = PINCH_VALVE_IDLE_STATE; -} - -/** @} */ +/**@}*/ Index: firmware/App/Drivers/PinchValve.h =================================================================== diff -u -r9565d9627edc032a2c6414a38f38f14c62e3ec87 -r078ab958e0cac18c5b8a5cc2f9d22710ac52aa1e --- firmware/App/Drivers/PinchValve.h (.../PinchValve.h) (revision 9565d9627edc032a2c6414a38f38f14c62e3ec87) +++ firmware/App/Drivers/PinchValve.h (.../PinchValve.h) (revision 078ab958e0cac18c5b8a5cc2f9d22710ac52aa1e) @@ -18,52 +18,71 @@ #ifndef __PINCHVALVE_H__ #define __PINCHVALVE_H__ -#ifndef __PINCH_VALVE_H__ -#define __PINCH_VALVE_H__ - #include "TDCommon.h" +#include "RotaryValve.h" /** - * @defgroup PinchValve PinchValve - * @brief Magellan pinch valve driver for H1 and H19. + * @defgroup PinchValve PinchValve + * @brief pinch valve communication driver. + * This driver sends one generic command at a time through the FPGA + * interface. High level functions such as homing and movement to positions + * A, B, and C belong in the controller layer. * - * The PinchValve unit provides a command execution state machine for the - * Magellan based pinch valve interface. FPGA register access is handled by - * FpgaTD. - * - * @addtogroup PinchValve - * @{ + * @addtogroup PinchValve + * @{ */ // ********** public definitions ********** +#define PINCH_VALVE_MAX_INPUT_WORDS 3U ///< Maximum number of command input words. +#define PINCH_VALVE_MAX_OUTPUT_WORDS 3U ///< Maximum number of command output words. +/// Pinch valve command request. +typedef struct +{ + U16 cmdHeader; ///< Command header. + U16 inputWord1; ///< Input word 1. + U16 inputWord2; ///< Input word 2. + 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. +} PINCH_VALVE_COMMAND_T; -// PMD IC command codes. -#define PINCH_VALVE_PMD_CMD_SET_PROFILE_MODE 0x00A0 -#define PINCH_VALVE_PMD_CMD_RESET_EVENT_STATUS 0x0034 -#define PINCH_VALVE_PMD_CMD_SET_VELOCITY 0x0011 -#define PINCH_VALVE_PMD_CMD_SET_POSITION 0x0010 -#define PINCH_VALVE_PMD_CMD_UPDATE 0x001A -#define PINCH_VALVE_PMD_CMD_GET_ACTIVITY_STATUS 0x00A6 -#define PINCH_VALVE_PMD_CMD_GET_EVENT_STATUS 0x0031 -#define PINCH_VALVE_PMD_CMD_GET_ACTUAL_POSITION 0x0037 -#define PINCH_VALVE_PMD_CMD_SET_ACTUAL_POSITION 0x004D -#define PINCH_VALVE_PMD_CMD_SET_OPERATING_MODE 0x0065 +/// Pinch valve command response. +typedef struct +{ + U16 outputWord1; ///< Output word 1. + U16 outputWord2; ///< Output word 2. + U16 outputWord3; ///< Output word 3. + U08 spiCmdStatus; ///< FPGA SPI command status. + U08 readCount; ///< FPGA read count. + U08 errorCount; ///< FPGA invalid command error count. +} PINCH_VALVE_RESPONSE_T; +/// Pinch valve driver command result. +typedef enum pinchValveCommandResults +{ + PINCH_VALVE_CMD_RESULT_IDLE = 0, ///< No command has been requested. + PINCH_VALVE_CMD_RESULT_BUSY, ///< Command is executing. + PINCH_VALVE_CMD_RESULT_COMPLETE, ///< Command completed successfully. + PINCH_VALVE_CMD_RESULT_ERROR ///< Command failed. +} PINCH_VALVE_CMD_RESULT_T; + // ********** public function prototypes ********** -void initPinchValve( void ); -void execPinchValve( void ); +void initPinchValveDriver( void ); +void execPinchValveDriver( void ); -BOOL startPinchValveHome( PINCH_VALVE_ID_T valve ); -BOOL startPinchValveMove( PINCH_VALVE_ID_T valve, S32 targetPosition ); -BOOL startPinchValveReadStatus( PINCH_VALVE_ID_T valve ); +BOOL setPinchValveCommand( VALVE_T valve, const PINCH_VALVE_COMMAND_T *command ); -PINCH_VALVE_STATE_T getPinchValveState( void ); +void setPinchValveEnableReset( VALVE_T valve, BOOL enable, BOOL reset ); +U08 getPinchValveEnableReset( VALVE_T valve ); + +BOOL isPinchValveBusy( void ); PINCH_VALVE_CMD_RESULT_T getPinchValveCommandResult( void ); -void getPinchValveResponse( PINCH_VALVE_RESPONSE_T *response ); +BOOL getPinchValveResponse( VALVE_T valve, PINCH_VALVE_RESPONSE_T *response ); -U16 getPinchValveLastOutputWord3( void ); +/**@}*/ #endif