Index: firmware/App/Drivers/SafetyShutdown.c =================================================================== diff -u -rb64c49fdcf2b6d95e61e63f8e258c4e600935bbd -rc081112c61e0d85854e8f1e604ac7f1f37c2ec02 --- firmware/App/Drivers/SafetyShutdown.c (.../SafetyShutdown.c) (revision b64c49fdcf2b6d95e61e63f8e258c4e600935bbd) +++ firmware/App/Drivers/SafetyShutdown.c (.../SafetyShutdown.c) (revision c081112c61e0d85854e8f1e604ac7f1f37c2ec02) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -14,44 +14,130 @@ * **************************************************************************/ -#include "gio.h" +#include "mibspi.h" +#include "SystemCommMessages.h" #include "SafetyShutdown.h" +/** + * @addtogroup SafetyShutdown + * @{ + */ + // ********** private definitions ********** -// GIO port A pin assignments for pins connected to CPLD -#define SAFETY_GIO_PORT_PIN 3U +// pin I/O macros +#define SAFETY_SPI1_PORT_MASK 0x00000010 // (CS[4] - re-purposed as output GPIO) +#define SET_SAFETY_SHUTDOWN() {mibspiREG1->PC3 |= SAFETY_SPI1_PORT_MASK;} +#define CLR_SAFETY_SHUTDOWN() {mibspiREG1->PC3 &= ~SAFETY_SPI1_PORT_MASK;} -// CPLD pin I/O macros -#define SET_SAFETY_SHUTDOWN() gioSetBit( gioPORTB, SAFETY_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) -#define CLR_SAFETY_SHUTDOWN() gioSetBit( gioPORTB, SAFETY_GIO_PORT_PIN, PIN_SIGNAL_LOW ) +// ********** private definitions ********** -/************************************************************************* - * @brief initSafetyShutdown - * The initSafetyShutdown function initializes the Buttons module. +static BOOL safetyShutdownActivated = FALSE; ///< Status of safety shutdown signal. +static BOOL safetyShutdownOverrideResetState = FALSE; ///< Natural status of safety shutdown signal. Used to restore state on override reset. + +/*********************************************************************//** + * @brief + * The initSafetyShutdown function initializes the Safety Shutdown module. * @details * Inputs : none * Outputs : Safety Shutdown module signal output set to initial state. - * @param none * @return none *************************************************************************/ void initSafetyShutdown( void ) { CLR_SAFETY_SHUTDOWN(); } -/************************************************************************* - * @brief activateSafetyShutdown +/*********************************************************************//** + * @brief * The activateSafetyShutdown function activates the safety shutdown signal. * @details * Inputs : none * Outputs : Safety Shutdown signal output set to active state. - * @param none * @return none *************************************************************************/ void activateSafetyShutdown( void ) { SET_SAFETY_SHUTDOWN(); } +/*********************************************************************//** + * @brief + * The isSafetyShutdownActivated function returns whether the safety shutdown \n + * signal has been activated. + * @details + * Inputs : none + * Outputs : none + * @return safetyShutdownActivated + *************************************************************************/ +BOOL isSafetyShutdownActivated( void ) +{ + return safetyShutdownActivated; +} + +/*********************************************************************//** + * @brief + * The testSetSafetyShutdownOverride function overrides the HD safety \n + * shutdown. + * @details + * Inputs : none + * Outputs : HD safety shutdown overridden + * @param value : TRUE to activate safety shutdown, FALSE to de-activate it. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSafetyShutdownOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + // remember natural state before override so we can reset + safetyShutdownOverrideResetState = safetyShutdownActivated; + // override safety shutdown signal + if ( value > 0 ) + { + activateSafetyShutdown(); + } + else + { + safetyShutdownActivated = FALSE; + CLR_SAFETY_SHUTDOWN(); + } + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSafetyShutdownOverride function resets the override of the \n + * HD safety shutdown. + * @details + * Inputs : none + * Outputs : shutdown override reset + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetSafetyShutdownOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if ( TRUE == safetyShutdownOverrideResetState ) + { + activateSafetyShutdown(); + } + else + { + safetyShutdownActivated = FALSE; + CLR_SAFETY_SHUTDOWN(); + } + result = TRUE; + } + + return result; +} + +/**@}*/