Index: firmware/App/Drivers/PinchValve.c =================================================================== diff -u -rb9d2f7eb5f099009b6c8979f6d8b59001c065711 -r6ad57767b87b8e691c6cbb728b56efabe8a28e8e --- firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision b9d2f7eb5f099009b6c8979f6d8b59001c065711) +++ firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 6ad57767b87b8e691c6cbb728b56efabe8a28e8e) @@ -31,7 +31,7 @@ #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 55 ///< Offset (in encoder counts) from end of travel edge to set position B and C. +#define PINCH_VALVE_HOME_OFFSET 1300 ///< Offset (in encoder counts) from end of travel edge to set position B and C. #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. @@ -46,8 +46,8 @@ #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. -#define PINCH_VALVE_ENABLE_BIT_MASK 0x00 ///< Value used to enable normal pinch valve controller -#define PINCH_VALVE_RESET_BIT_MASK 0x01 ///< Bit mask used to reset the pinch valve controller. +#define PINCH_VALVE_ENABLE_BIT_MASK 0x01 ///< Value used to enable normal pinch valve controller +#define PINCH_VALVE_RESET_BIT_MASK 0x02 ///< Bit mask used to reset the pinch valve controller. #define PINCH_VALVE_MAX_INPUT_WORDS 3 ///< Maximum number of command input words, excluding the command header. #define PINCH_VALVE_MAX_OUTPUT_WORDS 3 ///< Maximum number of command output words. @@ -71,7 +71,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 = 50000; ///< 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. @@ -233,7 +233,6 @@ static U08 commandSpiStatus[ NUM_OF_VALVES ]; ///< Current FPGA SPI command status value for each valve. static U08 commandErrorCount[ NUM_OF_VALVES ]; ///< Current FPGA command error count for each valve. static U08 errorCountAtCommandStart[ NUM_OF_VALVES ]; ///< Error count captured before starting the current command. -static U08 enableResetValue[ NUM_OF_VALVES ]; ///< Last enable/reset value written for each valve. static U08 fpgaCommandValue[ NUM_OF_VALVES ]; ///< FPGA command byte given for each valve. static U32 executeStartTime[ NUM_OF_VALVES ]; ///< Command execution start time used for transaction timeout detection @@ -309,6 +308,7 @@ pendingValvePosition[ valve ] = 0; currentValvePosition[ valve ] = 0; + for ( pos = 0; pos < NUM_OF_VALVE_POSITIONS; pos++ ) { valvePositions[ valve ][ pos ] = 0; @@ -325,7 +325,6 @@ commandErrorCount[ valve ] = 0; errorCountAtCommandStart[ valve ] = 0; - enableResetValue[ valve ] = 0; fpgaCommandValue[ valve ] = 0; executeStartTime[ valve ] = 0; @@ -337,7 +336,7 @@ // activeCommand[ valve ].outputWordCount = 0; // activeCommand[ valve ].writeOnly = FALSE; - motionStartTime[ valve ] = 0; + motionStartTime[ valve ] = 0; clearActivePinchValveCommand( valve ); clearPinchValveCommandRegisters( valve ); @@ -373,7 +372,7 @@ if ( TRUE == writePinchValveCommandRegisters( valve ) ) { errorCountAtCommandStart[ valve ] = readPinchValveErrorCount( valve ); - commandState[ valve ] = PINCH_VALVE_CMD_XMIT_CMD_STATE; + commandState[ valve ] = PINCH_VALVE_CMD_XMIT_CMD_STATE; } else { @@ -386,7 +385,7 @@ if ( TRUE == transmitPinchValveCommand( valve ) ) { executeStartTime[ valve ] = getMSTimerCount(); - commandState[ valve ] = PINCH_VALVE_CMD_WAIT_DONE_STATE; + commandState[ valve ] = PINCH_VALVE_CMD_WAIT_DONE_STATE; } else { @@ -412,7 +411,8 @@ commandSpiStatus[ valve ] = getH19SPICmdStatus(); commandErrorCount[ valve ] = getH19ErrorCount(); } - if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || ( TRUE == isPinchValveControllerFaultActive( valve ) ) ) + if ( ( TRUE == didPinchValveErrorCountChange( valve ) ) || + ( TRUE == isPinchValveControllerFaultActive( valve ) ) ) { commandState[ valve ] = PINCH_VALVE_CMD_ERROR_STATE; } @@ -567,47 +567,37 @@ { U08 value = 0; - if ( TRUE == enable ) + if ( H1_VALV == valve ) { - value &= ~PINCH_VALVE_RESET_BIT_MASK; - } + value = geth1ReadEnableRest(); - if ( TRUE == reset ) - { - value |= PINCH_VALVE_RESET_BIT_MASK; - } + if ( TRUE == enable ) + { + value &= ~PINCH_VALVE_ENABLE_BIT_MASK; + } - if ( H1_VALV == valve ) - { - enableResetValue[ valve ] = value; + if ( TRUE == reset ) + { + value |= PINCH_VALVE_RESET_BIT_MASK; + } + setH1EnableReset( value ); } else if ( H19_VALV == valve ) { - enableResetValue[ valve ] = value; - setH19EnableReset( value ); - } -} + value = geth19ReadEnableRest(); -/*********************************************************************//** -* @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 ) -{ - U08 result = 0; + if ( TRUE == enable ) + { + value &= ~PINCH_VALVE_ENABLE_BIT_MASK; + } - if ( TRUE == isValidPinchValve( valve ) ) - { - result = enableResetValue[ valve ]; + if ( TRUE == reset ) + { + value |= PINCH_VALVE_RESET_BIT_MASK; + } + setH19EnableReset( value ); } - - return result; } /*********************************************************************//** @@ -692,8 +682,8 @@ { activeCommandCount[ valve ] = NUM_OF_PINCH_VALVE_HOMING_COMMANDS; activeCommandIndex[ valve ] = 0; - commandFailed[ valve ] = FALSE; - functionState[ valve ] = PINCH_VALVE_FUNCTION_SEND_STATE; + commandFailed[ valve ] = FALSE; + functionState[ valve ] = PINCH_VALVE_FUNCTION_SEND_STATE; } else { @@ -704,13 +694,13 @@ else if ( TRUE == pendingValvePositionRequest[ valve ] ) { pendingValvePositionRequest[ valve ] = FALSE; - positionInProgress[ valve ] = TRUE; + 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; + 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; @@ -763,7 +753,6 @@ default: commandFailed[ valve ] = TRUE; resetPinchValveFunctionSequence( valve ); - // TODO: software fault for an invalid pinch-valve function state. break; } } @@ -1087,7 +1076,7 @@ { U08 transmitWordCount = (U08)( command->inputWordCount + 1 ); - if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && + if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && ( transmitWordCount <= PINCH_VALVE_MAX_TRANSMIT_WORDS ) ) { result = TRUE; @@ -1234,7 +1223,6 @@ break; default: - // Check with Sean TODO later break; } } @@ -1247,7 +1235,6 @@ break; default: - // Check with Sean TODO later break; } } @@ -1339,7 +1326,7 @@ activeCommandArray[ valve ] = 0; activeCommandCount[ valve ] = 0; activeCommandIndex[ valve ] = 0; - homingInProgress[ valve ] = FALSE; + homingInProgress[ valve ] = FALSE; positionInProgress[ valve ] = FALSE; functionState[ valve ] = PINCH_VALVE_FUNCTION_IDLE_STATE; }