Implementing Watchdog Timer in FX3 – KBA223337

Version: **

 

Question:

How can a watchdog timer be implemented in FX3 firmware?

 

Answer:

Consider the following example:

#define CY_FX_WATCHDOG_PERIOD 5000 //Watchdog timer is set to 5 sec

#define CY_FX_WATCHDOG_CLEAR_PERIOD 3000 //Watchdog clear timer is set to 3 sec

 

CyU3PTimer WdClearTimer;

 

void TimerInit(void)

{

     CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;

     CyU3PSysWatchDogConfigure(CyTrue, (CY_FX_WATCHDOG_PERIOD); //Here CY_FX_WATCHDOG_PERIOD is in milliseconds

     CyU3PDebugPrint (4, "WatchDog Timer Created\r\n");

     apiRetStatus = CyU3PTimerCreate(&WdClearTimer, WatchDogTimerClearCb, 0, CY_FX_WATCHDOG_CLEAR_PERIOD, CY_FX_WATCHDOG_CLEAR_PERIOD, 1);                               //Here CY_FX_WATCHDOG_CLEAR_PERIOD is in milliseconds

     if (apiRetStatus != CY_U3P_SUCCESS)

     {

        CyU3PDebugPrint (4, "TimerCreate failed, Error Code = %d\r\n", apiRetStatus);

     }

}

Call the TimerInit() function before the infinite “for loop” ( for ( ;  ).

Note:

  1. In the example code snippet, CY_FX_WATCHDOG_PERIOD is the watchdog timer reset period, that is, if the watchdog timer is not cleared before this time period, FX3 would be reset. So, one more timer (WdClearTimer) is created to clear the watchdog timer before it expires.
  2. The value of CY_FX_WATCHDOG_CLEAR_PERIOD should be lesser than that of CY_FX_WATCHDOG_PERIOD.
  3. The WdClearTimer timer will generate a Callback WatchDogTimerClearCb, which is defined as:

 

void WatchDogTimerCb (uint32_t nParam)

{

                CyU3PSysWatchDogClear();

      }