Index: App/Drivers/CPLD.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -r29f1ba03faefd982327916590818a260a3e4aa48 --- App/Drivers/CPLD.c (.../CPLD.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ App/Drivers/CPLD.c (.../CPLD.c) (revision 29f1ba03faefd982327916590818a260a3e4aa48) @@ -1,23 +1,22 @@ -/************************************************************************* -* -* Copyright Diality, Inc. 2019-2020. All Rights Reserved. -* 181 Technology, Ste. 150 -* Irvine, CA 92618 -* -* Project Denali -* -* @file CPLD.c -* -* @brief Monitor/Controller for the CPLD. -* -* @date 20-Sep-2019 -* -*************************************************************************/ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 "lin.h" +#include "mibspi.h" -#include "Common.h" #include "AlarmLamp.h" #include "Buttons.h" #include "WatchdogMgmt.h" @@ -26,36 +25,62 @@ // ********** private definitions ********** // GIO port A pin assignments for pins connected to CPLD -#define GREEN_GIO_PORT_PIN 6U -#define RED_GIO_PORT_PIN 7U +#define OFF_BUTTON_GIO_PORT_PIN 0U +#define STOP_BUTTON_GIO_PORT_PIN 1U // 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 OFF_BUTTON_GIO_PORT_PIN 2U -#define STOP_BUTTON_GIO_PORT_PIN 3U +#define WD_EXP_GIO_PORT_PIN 2U -// LIN port pin assignments for pins connected to CPLD -#define WD_EXP_LIN_PORT_MASK 2U // (Rx - re-purposed as input GPIO) -#define YELLOW_LIN_PORT_MASK 4U // (Tx - re-purposed as output GPIO) +// MIBSPI5 port pin assignments for pins connected to CPLD +#define GREEN_SPI5_PORT_MASK 0x00000200 // (CLK - re-purposed as output GPIO) +#define BLUE_SPI5_PORT_MASK 0x00000400 // (SIMO[0] - re-purposed as output GPIO) +#define RED_SPI5_PORT_MASK 0x00000800 // (SOMI[0] - re-purposed as output GPIO) // CPLD pin I/O macros -#define GET_OFF() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTB, OFF_BUTTON_GIO_PORT_PIN)) -#define GET_STOP() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTB, STOP_BUTTON_GIO_PORT_PIN)) -#define GET_WD_EXP() (PIN_SIGNAL_STATE_T)(((linREG->PIO2 | WD_EXP_LIN_PORT_MASK) == 0 ? PIN_SIGNAL_LOW : PIN_SIGNAL_HIGH)) +#define GET_OFF() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTA, OFF_BUTTON_GIO_PORT_PIN)) +#define GET_STOP() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTA, STOP_BUTTON_GIO_PORT_PIN)) +#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 TGL_OFF_REQ() gioToggleBit( gioPORTB, OFF_REQUEST_GIO_PORT_PIN) #define SET_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) #define SET_OFF_REQ() gioSetBit( gioPORTB, OFF_REQUEST_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) -#define SET_GREEN() gioSetBit( gioPORTA, GREEN_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) -#define SET_RED() gioSetBit( gioPORTA, RED_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) -#define SET_YELLOW() linREG->PIO3 |= YELLOW_LIN_PORT_MASK +#define SET_GREEN() {mibspiREG5->PC3 |= GREEN_SPI5_PORT_MASK;} +#define SET_BLUE() {mibspiREG5->PC3 |= BLUE_SPI5_PORT_MASK;} +#define SET_RED() {mibspiREG5->PC3 |= RED_SPI5_PORT_MASK;} #define CLR_WD_PET() gioSetBit( gioPORTB, WD_PET_GIO_PORT_PIN, PIN_SIGNAL_LOW ) #define CLR_OFF_REQ() gioSetBit( gioPORTB, OFF_REQUEST_GIO_PORT_PIN, PIN_SIGNAL_LOW ) -#define CLR_GREEN() gioSetBit( gioPORTA, GREEN_GIO_PORT_PIN, PIN_SIGNAL_LOW ) -#define CLR_RED() gioSetBit( gioPORTA, RED_GIO_PORT_PIN, PIN_SIGNAL_LOW ) -#define CLR_YELLOW() linREG->PIO3 &= ~YELLOW_LIN_PORT_MASK +#define CLR_GREEN() {mibspiREG5->PC3 &= ~GREEN_SPI5_PORT_MASK;} +#define CLR_BLUE() {mibspiREG5->PC3 &= ~BLUE_SPI5_PORT_MASK;} +#define CLR_RED() {mibspiREG5->PC3 &= ~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(); + } + } +#endif + /************************************************************************* * @brief initCPLD * The initCPLD function initializes the CPLD module. @@ -64,46 +89,38 @@ * 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 watchdog pet output low (inactive) + CLR_WD_PET(); - // initialize power off request output low (inactive) - CLR_OFF_REQ(); + // initialize power off request output low (inactive) + CLR_OFF_REQ(); - // initialize alarm lamp color LED outputs low (off) - CLR_GREEN(); - CLR_RED(); - CLR_YELLOW(); + // initialize alarm lamp color LED outputs low (off) + CLR_GREEN(); + CLR_RED(); + CLR_BLUE(); - // initialize the associated s/w modules - initAlarmLamp(); - initButtons(); - initWatchdogMgmt(); + // initialize the associated s/w modules + initAlarmLamp(); + initButtons(); + initWatchdogMgmt(); } /************************************************************************* - * @brief setCPLDWatchdog - * The setCPLDWatchdog function sets the watchdog pet signal to CPLD to \n - * given level. + * @brief toggleCPLDWatchdog + * The toggleCPLDWatchdog function toggles the watchdog pet signal to CPLD. * @details * Inputs : none - * Outputs : watchdog pet signal set to given level. - * @param level : LOW or HIGH + * Outputs : watchdog pet signal toggled. + * @param level : none * @return none -*************************************************************************/ -void setCPLDWatchdog( PIN_SIGNAL_STATE_T level ) + *************************************************************************/ +void toggleCPLDWatchdog( void ) { - if ( level == PIN_SIGNAL_HIGH ) - { - SET_WD_PET(); - } - else - { - CLR_WD_PET(); - } + TGL_WD_PET(); } /************************************************************************* @@ -115,12 +132,12 @@ * Outputs : none * @param none * @return level : (LOW or HIGH) -*************************************************************************/ + *************************************************************************/ PIN_SIGNAL_STATE_T getCPLDWatchdogExpired( void ) { - PIN_SIGNAL_STATE_T level = GET_WD_EXP(); + PIN_SIGNAL_STATE_T level = GET_WD_EXP(); - return level; + return level; } /************************************************************************* @@ -132,39 +149,39 @@ * 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(); - } + if ( level == PIN_SIGNAL_HIGH ) + { + SET_GREEN(); + } + else + { + CLR_GREEN(); + } } /************************************************************************* - * @brief setCPLDLampYellow - * The setCPLDLampYellow function sets the alarm lamp yellow signal to CPLD \n + * @brief setCPLDLampBlue + * The setCPLDLampBlue function sets the alarm lamp blue signal to CPLD \n * to given level. * @details * Inputs : none - * Outputs : alarm lamp yellow signal set to given level. + * Outputs : alarm lamp blue signal set to given level. * @param level : LOW or HIGH * @return none -*************************************************************************/ -void setCPLDLampYellow( PIN_SIGNAL_STATE_T level ) + *************************************************************************/ +void setCPLDLampBlue( PIN_SIGNAL_STATE_T level ) { - if ( level == PIN_SIGNAL_HIGH ) - { - SET_YELLOW(); - } - else - { - CLR_YELLOW(); - } + if ( level == PIN_SIGNAL_HIGH ) + { + SET_BLUE(); + } + else + { + CLR_BLUE(); + } } /************************************************************************* @@ -176,39 +193,30 @@ * 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(); - } + if ( level == PIN_SIGNAL_HIGH ) + { + SET_RED(); + } + else + { + CLR_RED(); + } } /************************************************************************* - * @brief setCPLDOffRequest - * The setCPLDOffRequest function sets the off request signal to CPLD to \n - * given level. + * @brief toggleCPLDOffRequest + * The toggleCPLDOffRequest function toggles the off request signal to CPLD. * @details * Inputs : none - * Outputs : off request signal set to given level. - * @param level : LOW or HIGH + * Outputs : off request signal toggled. * @return none -*************************************************************************/ -void setCPLDOffRequest( PIN_SIGNAL_STATE_T level ) + *************************************************************************/ +void toggleCPLDOffRequest( void ) { - if ( level == PIN_SIGNAL_HIGH ) - { - SET_OFF_REQ(); - } - else - { - CLR_OFF_REQ(); - } + TGL_OFF_REQ(); } /************************************************************************* @@ -220,12 +228,12 @@ * Outputs : none * @param none * @return level : (LOW or HIGH) -*************************************************************************/ + *************************************************************************/ PIN_SIGNAL_STATE_T getCPLDOffButton( void ) { - PIN_SIGNAL_STATE_T level = GET_OFF(); + PIN_SIGNAL_STATE_T level = GET_OFF(); - return level; + return level; } /************************************************************************* @@ -237,11 +245,11 @@ * Outputs : none * @param none * @return level : (LOW or HIGH) -*************************************************************************/ + *************************************************************************/ PIN_SIGNAL_STATE_T getCPLDStopButton( void ) { - PIN_SIGNAL_STATE_T level = GET_STOP(); + PIN_SIGNAL_STATE_T level = GET_STOP(); - return level; + return level; }