11/*
2- * Copyright (C) 2021 Texas Instruments Incorporated
2+ * Copyright (C) 2021-2025 Texas Instruments Incorporated
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
3737#include "ti_drivers_config.h"
3838#include "ti_drivers_open_close.h"
3939#include "ti_board_open_close.h"
40+ #include "stdbool.h"
4041
41- #define NUM_OF_ITERATIONS (3U)
42+ #define NUM_OF_ITERATIONS (3U)
43+ #define MILLISEC_PER_SEC (1000U)
44+ #define EXP_TIME_DIVIDER (2U)
45+ #define MILLISEC_TO_MICROSEC (msec ) ((msec)*1000U)
4246
4347/*
4448 * This example uses the WDT module in reset mode to trigger warm reset.
@@ -56,33 +60,40 @@ void watchdog_reset_mode_main(void *args)
5660 /* Watchdog timer expiry time in millisecond */
5761 uint32_t wdtExpiryTimeinMs = gWatchdogParams [CONFIG_WDT0 ].expirationTime ;
5862 uint32_t index = 0 ;
63+ uint32_t countdown = wdtExpiryTimeinMs /MILLISEC_PER_SEC ;
5964
6065 /* Open drivers to open the UART driver for console */
6166 Drivers_open ();
6267 Board_driversOpen ();
6368
6469 DebugP_log ("Watchdog reset Mode Test Started ...\r\n" );
6570
66- DebugP_log ("Servicing WDT for few iterations \r\n" );
71+ DebugP_log ("Servicing WDT for %d iterations \r\n" , NUM_OF_ITERATIONS );
6772
6873 /* Service the WDT for more than expiry time */
6974 for (index = 0 ; index < NUM_OF_ITERATIONS ; index ++ )
7075 {
7176 /* Need to service the WDT in open window */
7277 while (Watchdog_isClosedWindow (gWatchdogHandle [CONFIG_WDT0 ]) == true);
78+ /* wait for (expiry time/2 ) time */
79+ ClockP_usleep (MILLISEC_TO_MICROSEC (wdtExpiryTimeinMs )/EXP_TIME_DIVIDER );
80+ DebugP_log ("Servicing WDT !! \r\n" );
7381 /* Clear Watchdog timer */
7482 Watchdog_clear (gWatchdogHandle [CONFIG_WDT0 ]);
75- /* wait for (expiry time/2 ) time */
76- ClockP_usleep ((wdtExpiryTimeinMs * 100 )/2 );
7783 }
7884
79- DebugP_log ("Watchdog triggers warm reset in %d (ms)\r\n" , wdtExpiryTimeinMs );
85+ DebugP_log ("Watchdog triggers warm reset in %d (ms)\r\n" ,
86+ wdtExpiryTimeinMs );
8087 DebugP_log ("All tests have passed!!\r\n" );
88+ Watchdog_clear (gWatchdogHandle [CONFIG_WDT0 ]);
89+
90+ /* Wait for residual milli seconds */
91+ ClockP_usleep (MILLISEC_TO_MICROSEC (wdtExpiryTimeinMs %1000U ));
8192
8293 /* Wait till WDT triggers the reset */
83- while (1 )
94+ while (true )
8495 {
85- DebugP_log ("Prints will be stopped after reset \r\n" );
96+ DebugP_log ("%d\r\n" , countdown -- );
97+ ClockP_usleep ((MILLISEC_TO_MICROSEC (MILLISEC_PER_SEC )));
8698 }
87-
8899}
0 commit comments