Index: App/Contollers/Buttons.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -r894b734327eb6e7cfa6bf651623576bc10214195 --- App/Contollers/Buttons.c (.../Buttons.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ App/Contollers/Buttons.c (.../Buttons.c) (revision 894b734327eb6e7cfa6bf651623576bc10214195) @@ -1,18 +1,18 @@ /************************************************************************* -* -* Copyright Diality, Inc. 2019-2020. All Rights Reserved. -* 181 Technology, Ste. 150 -* Irvine, CA 92618 -* -* Project Denali -* -* @file Buttons.c -* -* @brief Monitor/Controller for the off and stop buttons. -* -* @date 20-Sep-2019 -* -*************************************************************************/ + * + * Copyright Diality, Inc. 2019-2020. All Rights Reserved. + * 181 Technology, Ste. 150 + * Irvine, CA 92618 + * + * Project Denali + * + * @file Buttons.c + * + * @brief Monitor/Controller for the off and stop buttons. + * + * @date 20-Sep-2019 + * + *************************************************************************/ #include "Common.h" #include "CPLD.h" @@ -24,9 +24,9 @@ typedef enum Button_States { - BUTTON_STATE_RELEASED = 0, // Fault - BUTTON_STATE_PRESSED, // Service - NUM_OF_BUTTON_STATES + BUTTON_STATE_RELEASED = 0, // Fault + BUTTON_STATE_PRESSED, // Service + NUM_OF_BUTTON_STATES } BUTTON_STATE_T; #define OFF_REQUEST_PULSE_COUNT 4 @@ -36,14 +36,14 @@ static BUTTON_STATE_T offButtonState = BUTTON_STATE_RELEASED; static BUTTON_STATE_T prevOffButtonState = BUTTON_STATE_RELEASED; -static BOOL offButtonPressPending = FALSE; +static BOOL offButtonPressPending = FALSE; static BUTTON_STATE_T stopButtonState = BUTTON_STATE_RELEASED; static BUTTON_STATE_T prevStopButtonState = BUTTON_STATE_RELEASED; -static BOOL stopButtonPressPending = FALSE; +static BOOL stopButtonPressPending = FALSE; -static U32 offRequestPulseCount = 0; -static U32 offRequestPulseTimer = 0; +static U32 offRequestPulseCount = 0; +static U32 offRequestPulseTimer = 0; // ********** private function prototypes ********** @@ -59,19 +59,19 @@ * Outputs : Buttons module initialized. * @param none * @return none -*************************************************************************/ + *************************************************************************/ void initButtons( void ) { - offButtonState = BUTTON_STATE_RELEASED; - prevOffButtonState = BUTTON_STATE_RELEASED; - offButtonPressPending = FALSE; + offButtonState = BUTTON_STATE_RELEASED; + prevOffButtonState = BUTTON_STATE_RELEASED; + offButtonPressPending = FALSE; - stopButtonState = BUTTON_STATE_RELEASED; - prevStopButtonState = BUTTON_STATE_RELEASED; - stopButtonPressPending = FALSE; + stopButtonState = BUTTON_STATE_RELEASED; + prevStopButtonState = BUTTON_STATE_RELEASED; + stopButtonPressPending = FALSE; - offRequestPulseCount = 0; - offRequestPulseTimer = 0; + offRequestPulseCount = 0; + offRequestPulseTimer = 0; } /************************************************************************* @@ -82,21 +82,21 @@ * Outputs : offButtonState, stopButtonState, prevOffButtonState, prevStopButtonState * @param none * @return none -*************************************************************************/ + *************************************************************************/ void execButtons( void ) { - PIN_SIGNAL_STATE_T off = getCPLDOffButton(); - PIN_SIGNAL_STATE_T stop = getCPLDStopButton(); + PIN_SIGNAL_STATE_T off = getCPLDOffButton(); + PIN_SIGNAL_STATE_T stop = getCPLDStopButton(); - // set current button states read from CPLD - offButtonState = ( off == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); - stopButtonState = ( stop == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + // set current button states read from CPLD + offButtonState = ( off == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + stopButtonState = ( stop == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); - // handle button state transitions for stop button - handleStopButtonProcessing(); + // handle button state transitions for stop button + handleStopButtonProcessing(); - // handle button state transitions for off button - handleOffButtonProcessing(); + // handle button state transitions for off button + handleOffButtonProcessing(); } /************************************************************************* @@ -109,15 +109,15 @@ * Outputs : stopButtonPressPending * @param button * @return true if the stop button is pressed, false if not -*************************************************************************/ + *************************************************************************/ BOOL isStopButtonPressed( void ) { - BOOL result = FALSE; + BOOL result = FALSE; - result = stopButtonPressPending; - stopButtonPressPending = FALSE; + result = stopButtonPressPending; + stopButtonPressPending = FALSE; - return result; + return result; } /************************************************************************* @@ -129,31 +129,31 @@ * Outputs : none * @param button * @return true if given button is pressed, false if not -*************************************************************************/ + *************************************************************************/ BOOL isButtonPressedRaw( BUTTON_T button ) { - BOOL result = FALSE; + BOOL result = FALSE; - switch (button) - { - case BUTTON_OFF: - if ( offButtonState == BUTTON_STATE_PRESSED ) - { - result = TRUE; - } - break; - case BUTTON_STOP: - if ( stopButtonState == BUTTON_STATE_PRESSED ) - { - result = TRUE; - } - break; - default: - // TODO - s/w fault - break; - } + switch ( button ) + { + case BUTTON_OFF: + if ( offButtonState == BUTTON_STATE_PRESSED ) + { + result = TRUE; + } + break; + case BUTTON_STOP: + if ( stopButtonState == BUTTON_STATE_PRESSED ) + { + result = TRUE; + } + break; + default: + // TODO - s/w fault + break; + } - return result; + return result; } /************************************************************************* @@ -165,17 +165,17 @@ * Outputs : stopButtonPressPending * @param none * @return none -*************************************************************************/ + *************************************************************************/ void userConfirmOffButton( void ) { - OP_MODE opMode = getCurrentOperationMode(); + OP_MODE opMode = getCurrentOperationMode(); - if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) - { - offButtonPressPending = TRUE; - offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; - offRequestPulseTimer = 0; - } + if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) + { + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } } /************************************************************************* @@ -187,41 +187,41 @@ * Outputs : offButtonPressPending, offRequestPulseCount, offRequestPulseTimer * @param none * @return none -*************************************************************************/ + *************************************************************************/ static void handleOffButtonProcessing( void ) { - // handle button state transitions for off button - if ( offButtonState != prevOffButtonState ) - { - if ( offButtonState == BUTTON_STATE_PRESSED ) - { - OP_MODE opMode = getCurrentOperationMode(); + // handle button state transitions for off button + if ( offButtonState != prevOffButtonState ) + { + if ( offButtonState == BUTTON_STATE_PRESSED ) + { + OP_MODE opMode = getCurrentOperationMode(); - // if off request in a valid mode, send to UI for user confirmation - if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) - { - // TODO - send off button to UI for user confirmation - // temporary - just pretend user confirmed for now - userConfirmOffButton(); - } - } - prevOffButtonState = offButtonState; - } + // if off request in a valid mode, send to UI for user confirmation + if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) + { + // TODO - send off button to UI for user confirmation + // temporary - just pretend user confirmed for now + userConfirmOffButton(); + } + } + prevOffButtonState = offButtonState; + } - if ( TRUE == offButtonPressPending ) - { - offRequestPulseTimer += TASK_PRIORITY_INTERVAL; - if ( offRequestPulseTimer >= OFF_REQUEST_PULSE_INTVL ) - { - offRequestPulseTimer = 0; - offRequestPulseCount--; - if ( offRequestPulseCount == 0 ) - { - offButtonPressPending = false; - } - pulseOffRequestSignal(); - } - } + if ( TRUE == offButtonPressPending ) + { + offRequestPulseTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestPulseTimer >= OFF_REQUEST_PULSE_INTVL ) + { + offRequestPulseTimer = 0; + offRequestPulseCount--; + if ( offRequestPulseCount == 0 ) + { + offButtonPressPending = false; + } + pulseOffRequestSignal(); + } + } } /************************************************************************* @@ -232,14 +232,15 @@ * Outputs : off request signal pulsed * @param none * @return none -*************************************************************************/ + *************************************************************************/ static void pulseOffRequestSignal( void ) { - U32 d; + U32 d; - setCPLDOffRequest( PIN_SIGNAL_HIGH ); - for ( d = 0; d < 1000; d++ ); // ok to block briefly because we're shutting down anyway - setCPLDOffRequest( PIN_SIGNAL_LOW ); + setCPLDOffRequest( PIN_SIGNAL_HIGH ); + for ( d = 0; d < 1000; d++ ) + ; // ok to block briefly because we're shutting down anyway + setCPLDOffRequest( PIN_SIGNAL_LOW ); } /************************************************************************* @@ -251,18 +252,17 @@ * Outputs : stopButtonPressPending * @param none * @return none -*************************************************************************/ + *************************************************************************/ static void handleStopButtonProcessing( void ) { - // handle button state transitions for stop button if ( stopButtonState != prevStopButtonState ) - if ( stopButtonState != prevStopButtonState ) - { - if ( stopButtonState == BUTTON_STATE_PRESSED ) - { - stopButtonPressPending = TRUE; - } - prevStopButtonState = stopButtonState; - } + // handle button state transitions for stop button if ( stopButtonState != prevStopButtonState ) + if ( stopButtonState != prevStopButtonState ) + { + if ( stopButtonState == BUTTON_STATE_PRESSED ) + { + stopButtonPressPending = TRUE; + } + prevStopButtonState = stopButtonState; + } } -