/************************************************************************** * * Copyright (c) 2019-2020 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 CPLD.c * * @date 20-Sep-2019 * @author S. Nash * * @brief Monitor/Controller for the CPLD (Complex Programmable Logic Device). * **************************************************************************/ #include "gio.h" #include "mibspi.h" #include "WatchdogMgmt.h" #include "CPLD.h" // ********** private definitions ********** // GIO port B pin assignments for pins connected to CPLD #define OFF_REQUEST_GIO_PORT_PIN 0U #define WD_PET_GIO_PORT_PIN 1U #define WD_EXP_GIO_PORT_PIN 2U #define LAMP_GRN_SPI5_PORT_MASK 0x00000200 // (CLK(100) - re-purposed as output GPIO) #define LAMP_BLU_SPI5_PORT_MASK 0x00010000 // (SIMO[0](99) - re-purposed as output GPIO) #define LAMP_RED_SPI5_PORT_MASK 0x01000000 // (SOMI[0](98) - re-purposed as output GPIO) // CPLD pin I/O macros #define GET_WD_EXP() ( PIN_SIGNAL_STATE_T )( gioGetBit( gioPORTB, WD_EXP_GIO_PORT_PIN ) ) #define TGL_WD_PET() gioToggleBit( gioPORTB, WD_PET_GIO_PORT_PIN ) #define SET_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) #define CLR_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_LOW ) #define SET_GREEN() {mibspiREG5->PC3 |= LAMP_GRN_SPI5_PORT_MASK;} #define CLR_GREEN() {mibspiREG5->PC3 &= ~LAMP_GRN_SPI5_PORT_MASK;} #define SET_BLUE() {mibspiREG5->PC3 |= LAMP_BLU_SPI5_PORT_MASK;} #define CLR_BLUE() {mibspiREG5->PC3 &= ~LAMP_BLU_SPI5_PORT_MASK;} #define SET_RED() {mibspiREG5->PC3 |= LAMP_RED_SPI5_PORT_MASK;} #define CLR_RED() {mibspiREG5->PC3 &= ~LAMP_RED_SPI5_PORT_MASK;} #ifdef RM46_EVAL_BOARD_TARGET // for RM46 eval board, user button B uses the MIBSPI1_nCS[4] pin, so need to re-purpose that pin as GPIO to see the button #define USER_BUTTON_MASK 0x00000010 // (nCS[4] #define GET_USER_BUTTON() ( PIN_SIGNAL_STATE_T )( ( ( mibspiREG1->PC2 & USER_BUTTON_MASK ) == 0 ? PIN_SIGNAL_LOW : PIN_SIGNAL_HIGH ) ) PIN_SIGNAL_STATE_T getUserButtonState( void ) { PIN_SIGNAL_STATE_T result = GET_USER_BUTTON(); return result; } // for RM46 eval board, user LED A uses the same GPIO pin that CPLD uses for watchdog pet. Had to disable watchdog pet to use as LED. void setUserLED( BOOL on ) { if ( on == TRUE ) { SET_WD_PET(); } else { CLR_WD_PET(); } } void toggleUserLED() { TGL_WD_PET(); } #endif /************************************************************************* * @brief initCPLD * The initCPLD function initializes the CPLD module. * @details * Inputs : none * Outputs : CPLD module signal outputs set to initial states. * @param none * @return none *************************************************************************/ void initCPLD( void ) { // initialize watchdog pet output low (inactive) CLR_WD_PET(); // initialize alarm lamp color LED outputs low (off) CLR_GREEN(); CLR_RED(); CLR_BLUE(); } /************************************************************************* * @brief toggleCPLDWatchdog * The toggleCPLDWatchdog function toggles the watchdog pet signal to CPLD. * @details * Inputs : none * Outputs : watchdog pet signal toggled. * @param level : none * @return none *************************************************************************/ void toggleCPLDWatchdog( void ) { TGL_WD_PET(); } /************************************************************************* * @brief getCPLDWatchdogExpired * The getCPLDWatchdogExpired function determines the current signal level \n * on the watchdog expired pin from the CPLD. * @details * Inputs : Signal from CPLD on watchdog expired pin. * Outputs : none * @param none * @return level : (LOW or HIGH) *************************************************************************/ PIN_SIGNAL_STATE_T getCPLDWatchdogExpired( void ) { PIN_SIGNAL_STATE_T level = GET_WD_EXP(); return level; } /************************************************************************* * @brief setCPLDLampGreen * The setCPLDLampGreen function sets the alarm lamp green signal to CPLD \n * to given level. * @details * Inputs : none * Outputs : alarm lamp green signal set to given level. * @param level : LOW or HIGH * @return none *************************************************************************/ void setCPLDLampGreen( PIN_SIGNAL_STATE_T level ) { if ( level == PIN_SIGNAL_HIGH ) { SET_GREEN(); } else { CLR_GREEN(); } } /************************************************************************* * @brief setCPLDLampBlue * The setCPLDLampBlue function sets the alarm lamp blue signal to CPLD \n * to given level. * @details * Inputs : none * Outputs : alarm lamp blue signal set to given level. * @param level : LOW or HIGH * @return none *************************************************************************/ void setCPLDLampBlue( PIN_SIGNAL_STATE_T level ) { if ( level == PIN_SIGNAL_HIGH ) { SET_BLUE(); } else { CLR_BLUE(); } } /************************************************************************* * @brief setCPLDLampRed * The setCPLDLampRed function sets the alarm lamp red signal to CPLD \n * to given level. * @details * Inputs : none * Outputs : alarm lamp red signal set to given level. * @param level : LOW or HIGH * @return none *************************************************************************/ void setCPLDLampRed( PIN_SIGNAL_STATE_T level ) { if ( level == PIN_SIGNAL_HIGH ) { SET_RED(); } else { CLR_RED(); } }