Index: App/Services/WatchdogMgmt.c =================================================================== diff -u -radd7eb956a7d2c124434541e1f06ca5ae158716f -r9ff8753b0d546369f99230b572454a8e38b0705a --- App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision add7eb956a7d2c124434541e1f06ca5ae158716f) +++ App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 9ff8753b0d546369f99230b572454a8e38b0705a) @@ -1,17 +1,17 @@ /************************************************************************* * - * Copyright Diality, Inc. 2019-2020. All Rights Reserved. - * 181 Technology, Ste. 150 - * Irvine, CA 92618 + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. * - * Project Denali + * 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 WatchdogMgmt.c * - * @brief Monitor for the off and stop buttons. - * * @date 20-Sep-2019 + * @author S. Nash * + * @brief Monitor for the off and stop buttons. + * *************************************************************************/ #include "Common.h" @@ -23,12 +23,25 @@ #define MIN_WATCHDOG_PET_INTERVAL_MS 45 +typedef enum Button_Self_Test_States +{ + WATCHDOG_SELF_TEST_STATE_START = 0, + WATCHDOG_SELF_TEST_STATE_IN_PROGRESS, + WATCHDOG_SELF_TEST_STATE_COMPLETE, + NUM_OF_WATCHDOG_SELF_TEST_STATES +} WATCHDOG_SELF_TEST_STATE_T; + +#define WATCHDOG_POST_TIMEOUT_MS 100 // ms + // ********** private data ********** static BOOL watchdogExpired = FALSE; -static BOOL lastWatchdogPetTime = 0; +static U32 lastWatchdogPetTime = 0; static BOOL watchdogTaskCheckedIn[NUM_OF_TASKS]; +static WATCHDOG_SELF_TEST_STATE_T watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; +static U32 watchdogSelfTestTimerCount = 0; + // ********** private function prototypes ********** static void resetWDTaskCheckIns( void ); @@ -48,6 +61,8 @@ { watchdogExpired = FALSE; lastWatchdogPetTime = getMSTimerCount(); + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; + watchdogSelfTestTimerCount = 0; resetWDTaskCheckIns(); } @@ -62,7 +77,7 @@ *************************************************************************/ void execWatchdogMgmt( void ) { - BOOL allTasksCheckedIn = TRUE; + BOOL allTasksCheckedIn; // called by background task, so give bg task credit for checking in checkInWithWatchdogMgmt( TASK_BG ); @@ -118,6 +133,59 @@ } /************************************************************************* + * @brief execWatchdogTest + * The execWatchdogTest function executes the watchdog test. \n + * This function should be called periodically until a pass or fail \n + * result is returned. + * @details + * Inputs : + * Outputs : + * @param none + * @return in progress, passed, or failed + *************************************************************************/ +SELF_TEST_STATUS_T execWatchdogTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( watchdogSelfTestState ) + { + case WATCHDOG_SELF_TEST_STATE_START: + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_IN_PROGRESS; + watchdogSelfTestTimerCount = getMSTimerCount(); + // no break here so we pass through directly to in progress processing + + case WATCHDOG_SELF_TEST_STATE_IN_PROGRESS: + while ( FALSE == didTimeout( watchdogSelfTestTimerCount, WATCHDOG_POST_TIMEOUT_MS ) ) + { + // waiting here for w.d. test period to prevent this task from checking in - watchdog should expire + } + if ( getCPLDWatchdogExpired() == PIN_SIGNAL_HIGH ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + // TODO - trigger watchdog POST failure + } + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_COMPLETE; + break; + + case WATCHDOG_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* * @brief resetWDTaskCheckIns * The resetWDTaskCheckIns function resets the task check-ins with the watchdog. * @details @@ -177,13 +245,8 @@ *************************************************************************/ static void petWatchdog( void ) { - U32 d; - // pulse the watchdog signal - setCPLDWatchdog( PIN_SIGNAL_HIGH ); - for ( d = 0; d < 1000; d++ ) - ; // ok to block briefly because we're in the background (idle) task - setCPLDWatchdog( PIN_SIGNAL_LOW ); + toggleCPLDWatchdog(); // remember when we last pet the watchdog lastWatchdogPetTime = getMSTimerCount();