Index: firmware/App/Monitors/Buttons.c =================================================================== diff -u -r395522dffef1348e176564925656012f529c1910 -rf99f8b365af2274d68d7f424cc9be9815b4db19c --- firmware/App/Monitors/Buttons.c (.../Buttons.c) (revision 395522dffef1348e176564925656012f529c1910) +++ firmware/App/Monitors/Buttons.c (.../Buttons.c) (revision f99f8b365af2274d68d7f424cc9be9815b4db19c) @@ -21,6 +21,7 @@ //#include "NVDataMgmt.h" #include "OperationModes.h" #include "TaskPriority.h" +#include "TDDefs.h" #include "Timers.h" /** @@ -47,24 +48,6 @@ NUM_OF_BUTTONS ///< Number of hardware buttons } BUTTON_T; -/// Enumeration of off button commands to UI. -typedef enum OffButtonCmdsToUI -{ - OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM = 0, ///< Prompt user to confirm power off command - OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT, ///< Cancel user confirm prompt command - OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST, ///< Reject user off request command - NUM_OF_OFF_BUTTON_CMDS ///< Number of off button commands to UI -} OFF_BUTTON_CMD_T; - -/// Enumeration of off button responses from UI. -typedef enum OffButtonRspsFromUI -{ - OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF = 0, ///< User requests power off response - OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF, ///< User confirms power off response - OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF, ///< User rejects power off response - NUM_OF_OFF_BUTTON_RSPS ///< Number of off button responses from UI -} OFF_BUTTON_RSP_T; - #define OFF_REQUEST_PULSE_COUNT 4 ///< Number of edges for power off sequence on power off output signal. #define OFF_REQUEST_PULSE_INTVL_MS 50 ///< Duration (in ms) of power off sequence steps. #define OFF_REQUEST_DELAY_TIME_MS 2000 ///< Duration (in ms) of delay before power off sequence is initiated to provide sub-systems time to wrap things up. @@ -80,11 +63,11 @@ static OVERRIDE_U32_T dataOffButtonState; ///< Current off button state (overrideable). static BUTTON_STATE_T prevOffButtonState; ///< Previous state of off button. static BOOL offRequestAwaitingUserConfirmation = FALSE; ///< Flag indicates whether a power off request is pending user confirmation. -static U32 offRequestPendingTimer; ///< Timer counter for pending power off request. -static BOOL offButtonPressPending; ///< Flag indicates whether a confirmed power off request is pending execution. -static U32 offRequestPulseCount; ///< Power off sequence step counter. -static U32 offRequestPulseTimer; ///< Power off sequence step timer counter. -static U32 offRequestDelayTimer; ///< Power off sequence delay timer counter. +static volatile U32 offRequestPendingTimer; ///< Timer counter for pending power off request. +static volatile BOOL offButtonPressPending; ///< Flag indicates whether a confirmed power off request is pending execution. +static volatile U32 offRequestPulseCount; ///< Power off sequence step counter. +static volatile U32 offRequestPulseTimer; ///< Power off sequence step timer counter. +static volatile U32 offRequestDelayTimer; ///< Power off sequence delay timer counter. static OVERRIDE_U32_T dataStopButtonState; ///< Current stop button state (overrideable). static BUTTON_STATE_T prevStopButtonState; ///< Previous state of stop button. @@ -280,81 +263,6 @@ /*********************************************************************//** * @brief - * The userConfirmOffButton function handles user confirmation of the off - * button. The off request will be initiated here if confirmed or cancelled - * if rejected by user. - * @details \b Inputs: current operation mode - * @details \b Outputs: stopButtonPressPending - * @param response 1 = confirmed, 0 = rejected - * @return none - *************************************************************************/ -void userConfirmOffButton( U08 response ) -{ - switch ( response ) - { - case OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF: - // If we are in a mode that allows power off, set off pending flag and request user confirmation - if ( TRUE == isCurrentOpModeOkToTurnOff() ) - { - offRequestAwaitingUserConfirmation = TRUE; - offRequestPendingTimer = 0; -#ifndef SIMULATE_UI - sendOffButtonMsgToUI( OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM ); -#endif - } - else - { // Send rejection response to power off request - sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); - } - break; - - case OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF: - // Is an off request pending user confirmation? - if ( TRUE == offRequestAwaitingUserConfirmation ) - { - // Reset off request pending flag - offRequestAwaitingUserConfirmation = FALSE; - // If we are in a mode that allows power off, initiate power off sequence - if ( TRUE == isCurrentOpModeOkToTurnOff() ) - { - POWER_OFF_WARNING_DATA_T data; - - data.powerOffWarning = 0; - - broadcastData( MSG_ID_POWER_OFF_WARNING, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( POWER_OFF_WARNING_DATA_T ) ); - //signalPowerOffWarning(); // warn nvdata unit that power is going down - offButtonPressPending = TRUE; - offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; - offRequestPulseTimer = 0; - } - else - { - sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); - } - } - else - { - sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); - } - break; - - case OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF: - // Is an off request pending user confirmation? - if ( TRUE == offRequestAwaitingUserConfirmation ) - { - // Reset off request pending flag - offRequestAwaitingUserConfirmation = FALSE; - } - break; - - default: - // Ok - do nothing - break; - } // End switch -} - -/*********************************************************************//** - * @brief * The isCurrentOpModeOkToTurnOff function determines whether the system can * be turned off in current operation mode. * @details \b Inputs: Current operation mode. @@ -403,58 +311,122 @@ * @details \b Outputs: offButtonPressPending, offRequestPulseCount, offRequestPulseTimer * @return none *************************************************************************/ -static void handleOffButtonProcessing( void ) -{ - // Handle button state transitions for off button - if ( getOffButtonState() != prevOffButtonState ) - { - if ( getOffButtonState() == BUTTON_STATE_PRESSED ) - { - // If off request in a valid mode, send to UI for user confirmation - userConfirmOffButton( OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF ); +static void handleOffButtonProcessing( void ) +{ + static U08 shutdownFlag = FALSE; + CONFIRMATION_REQUEST_STATUS_T responceStatus = CONFIRMATION_REQUEST_STATUS_UNUSED; + + // Handle button state transitions for off button + if ( getOffButtonState() != prevOffButtonState ) + { + if ( getOffButtonState() == BUTTON_STATE_PRESSED ) + { // Log off button press - SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_OFF, BUTTON_STATE_PRESSED ) + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + offRequestAwaitingUserConfirmation = TRUE; + offRequestPendingTimer = getMSTimerCount(); + +#ifndef SIMULATE_UI + addConfirmationRequest( GENERIC_CONFIRM_ID_POWER_OFF, GENERIC_CONFIRM_CMD_REQUEST_OPEN, 0 ); +#endif + } + else + { + ;// do nothing if required will add, as per the requirement. + } + + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_OFF, BUTTON_STATE_PRESSED ) } else { SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_OFF, BUTTON_STATE_RELEASED ) - } - prevOffButtonState = getOffButtonState(); - } - - // If off request has not been confirmed by user before it expires, cancel it - if ( TRUE == offRequestAwaitingUserConfirmation ) - { - offRequestPendingTimer += TASK_PRIORITY_INTERVAL; - if ( offRequestPendingTimer >= OFF_REQUEST_EXPIRATION_TIME_MS ) - { - offRequestAwaitingUserConfirmation = FALSE; - sendOffButtonMsgToUI( OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT ); - } - } - - // If user confirmed off button press, manage off request sequence - if ( TRUE == offButtonPressPending ) + } + + prevOffButtonState = getOffButtonState(); + } + + if ( TRUE == offRequestAwaitingUserConfirmation ) { - // Delay power off to provide sub-systems time to prepare for shutdown + if ( TRUE == didTimeout( offRequestPendingTimer, OFF_REQUEST_EXPIRATION_TIME_MS ) ) + { + setConfirmationRequestStatus( GENERIC_CONFIRM_ID_POWER_OFF, + CONFIRMATION_REQUEST_STATUS_TIMEOUT ); + } + + responceStatus = getConfirmationRequestStatus( GENERIC_CONFIRM_ID_POWER_OFF ); + + if ( CONFIRMATION_REQUEST_STATUS_REJECTED == responceStatus ) + { + offRequestAwaitingUserConfirmation = FALSE; + } + else if ( CONFIRMATION_REQUEST_STATUS_TIMEOUT == responceStatus ) + { + offRequestAwaitingUserConfirmation = FALSE; + } + else if ( CONFIRMATION_REQUEST_STATUS_ACCEPTED == responceStatus ) + { + offRequestAwaitingUserConfirmation = FALSE; + + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + POWER_OFF_WARNING_DATA_T data; + + data.powerOffWarning = 0; + + broadcastData( MSG_ID_POWER_OFF_WARNING, + COMM_BUFFER_OUT_CAN_TD_BROADCAST, + (U08 *)&data, + sizeof( POWER_OFF_WARNING_DATA_T ) ); + + //signalPowerOffWarning(); // warn nvdata unit that power is going down + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } + else + { + addConfirmationRequest( GENERIC_CONFIRM_ID_POWER_OFF, GENERIC_CONFIRM_CMD_REJECT, REQUEST_REJECT_REASON_SYSTEM_IN_OPERATIONMODE ); + } + } + else + { + ; // do nothing + } + } + + // If user confirmed off button press, manage off request sequence + if ( TRUE == offButtonPressPending ) + { + if ( !shutdownFlag ) + { + addConfirmationRequest( GENERIC_CONFIRM_ID_POWER_OFF, GENERIC_CONFIRM_CMD_REQUEST_INPROGRESS, 0 ); + shutdownFlag = TRUE; + } + offRequestDelayTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestDelayTimer >= OFF_REQUEST_DELAY_TIME_MS ) { - // Power off sequence is 4 50 ms toggles of the off request output signal offRequestPulseTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestPulseTimer >= OFF_REQUEST_PULSE_INTVL_MS ) { offRequestPulseTimer = 0; offRequestPulseCount--; + if ( offRequestPulseCount == 0 ) { - offButtonPressPending = false; + offButtonPressPending = FALSE; + offRequestDelayTimer = 0; + shutdownFlag = FALSE; } + toggleCPLDOffRequest(); } - } - } -} + } + } +} /*********************************************************************//** * @brief