/************************************************************************** * * Copyright (c) 2024-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file GPIO.c * * @author (last) Vinayakam Mani * @date (last) 29-Aug-2024 * * @author (original) Vinayakam Mani * @date (original) 29-Aug-2024 * ***************************************************************************/ #include "gio.h" #include "mibspi.h" #include "FpgaDD.h" #include "GPIO.h" /** * @addtogroup GPIO * @{ */ // ********** private definitions ********** #define WD_PET_GIO_PORT_PIN 1U ///< Watchdog pet GPIO pin number. #define WD_EXP_GIO_PORT_PIN 0U ///< Watchdog expired GPIO pin number. #define GPIO_AC_SWITCH_MASK 0x10U ///< AC switch status bit mask (concentrate cap switch per HDD). #define GPIO_LEAK_SENSOR_MASK 0x04U ///< Leak sensor status bit mask (per HDD - update if different). #define GET_WD_EXP() ( PIN_SIGNAL_STATE_T )( gioGetBit( gioPORTB, WD_EXP_GIO_PORT_PIN ) ) ///< Get watchdog expired pin state macro. #define TGL_WD_PET() gioToggleBit( gioPORTB, WD_PET_GIO_PORT_PIN ) ///< Macro to toggle watchdog pet signal state. #define SET_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) ///< Macro to set watchdog pet signal state high. #define CLR_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_LOW ) ///< Macro to set watchdog pet signal state low. /*********************************************************************//** * @brief * The toggleWatchdogPetSignal function toggles the watchdog pet output * signal on its GPIO pin. * @details \b Inputs: none * @details \b Outputs: Watchdog pet output signal toggled * @return none *************************************************************************/ void toggleWatchdogPetSignal( void ) { TGL_WD_PET(); } /*********************************************************************//** * @brief * The setWatchdogPetSignal function sets the watchdog pet output * signal on its GPIO pin to HIGH. * @details \b Inputs: none * @details \b Outputs: Watchdog pet output signal set high * @return none *************************************************************************/ void setWatchdogPetSignal( void ) { SET_WD_PET(); } /*********************************************************************//** * @brief * The clrWatchdogPetSignal function sets the watchdog pet output * signal on its GPIO pin to LOW. * @details \b Inputs: none * @details \b Outputs: Watchdog pet output signal set low * @return none *************************************************************************/ void clrWatchdogPetSignal( void ) { CLR_WD_PET(); } /*********************************************************************//** * @brief * The getWatchdogExpired function determines the current signal level * on the watchdog expired pin. * @details \b Inputs: Signal on watchdog expired pin. * @details \b Outputs: none * @return level (LOW or HIGH) *************************************************************************/ PIN_SIGNAL_STATE_T getWatchdogExpired( void ) { PIN_SIGNAL_STATE_T level = GET_WD_EXP(); return level; } /*********************************************************************//** * @brief * The getGPIOStatusFromFPGA function returns the latest GPIO status register * value reported by the DD FPGA. * @details \b Inputs: fpgaSensorReadings.fpgaGPIOStatus (via FpgaDD service) * @details \b Outputs: none * @return GPIO status register value (bit-mapped per HDD definition) *************************************************************************/ U08 getGPIOStatusFromFPGA( void ) { return getFPGAGPIOStatus(); } /*********************************************************************//** * @brief * The getACSwitchStatus function returns the AC switch (concentrate cap * switch) status from the FPGA GPIO register. * @details \b Inputs: fpgaSensorReadings.fpgaGPIOStatus (via getGPIOStatusFromFPGA) * @details \b Outputs: none * @return TRUE if AC switch is asserted, FALSE otherwise *************************************************************************/ BOOL getACSwitchStatus( void ) { U08 gpioStatus = getGPIOStatusFromFPGA(); BOOL isAsserted = ( ( gpioStatus & GPIO_AC_SWITCH_MASK ) != 0U ) ? TRUE : FALSE; return isAsserted; } /*********************************************************************//** * @brief * The getLeakSensorStatus function returns the leak sensor status from the * FPGA GPIO register. Application code should trigger an alarm when * LEAK_SENSOR_DETECTED is returned (e.g. in a monitor task). * @details \b Inputs: fpgaSensorReadings.fpgaGPIOStatus (via getGPIOStatusFromFPGA) * @details \b Outputs: none * @return LEAK_SENSOR_NOT_DETECTED or LEAK_SENSOR_DETECTED *************************************************************************/ LEAK_SENSOR_STATUS_T getLeakSensorStatus( void ) { U08 gpioStatus = getGPIOStatusFromFPGA(); LEAK_SENSOR_STATUS_T status = ( ( gpioStatus & GPIO_LEAK_SENSOR_MASK ) != 0U ) ? LEAK_SENSOR_DETECTED : LEAK_SENSOR_NOT_DETECTED; return status; } /**@}*/