XilinxProcessorIPLib/drivers/wdttb/examples/xwdttb_example.c
int WdtTbExample(u16 DeviceId)
{
	int Status;
	int Count = 0;
	XWdtTb_Config *Config;

	/*
	 * Initialize the WDTTB driver so that it's ready to use look up
	 * configuration in the config table, then initialize it.
	 */
	Config = XWdtTb_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}

	/*
	 * Initialize the watchdog timer and timebase driver so that
	 * it is ready to use.
	 */
	Status = XWdtTb_CfgInitialize(&WatchdogTimebase, Config,
			Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XWdtTb_SelfTest(&WatchdogTimebase);
	if (Status != XST_SUCCESS) {
		xil_printf("Example:Self test failed\n\r");
		return XST_FAILURE;
	}

	/*
	 * Start the watchdog timer, the timebase is automatically reset
	 * when this occurs.
	 */
	XWdtTb_Start(&WatchdogTimebase);

	/*
	 * Verify Whether the WatchDog Reset Status has been set in the next two
	 * expiry state.
	 */
	while (1) {
		xil_printf(".");

		/*
		 * If the watchdog timer expired, then restart it.
		 */
		if (XWdtTb_IsWdtExpired(&WatchdogTimebase)) {

			/*
			 * Restart the watchdog timer as a normal application
			 * would
			 */
			XWdtTb_RestartWdt(&WatchdogTimebase);
			Count++;
			xil_printf("\n\rRestart kick %d\n\r", Count);
		}

		/*
		 * Check whether the WatchDog Reset Status has been set.
		 * If this is set means then the test has failed
		 */
		if (XWdtTb_ReadReg(WatchdogTimebase.Config.BaseAddr,
				XWT_TWCSR0_OFFSET) & XWT_CSR0_WRS_MASK) {

			/*
			 * Stop the watchdog timer
			 */
			XWdtTb_Stop(&WatchdogTimebase);
			return XST_FAILURE;
		}

		/*
		 * Check whether the WatchDog timer expires two times.
		 * If the timer expires two times then the test is passed.
		 */
		if(Count == 2) {
			break;
		}
	}
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function tests the functioning of the TimeBase WatchDog Timer module
* in the polled mode.
*
* After one expiration of the WDT timeout interval, the WDT state bit is set to
* one in the status register. If the state bit is not cleared (by writing a 1 to
* the state bit) before the next expiration of the timeout interval, a WDT reset
* is generated.
*
* This function checks for Watchdog timer reset condition in two timer expiry
* state.
*
* This function may require some time (seconds or even minutes) to execute
* because it waits for the watchdog timer to expire.
*
* @param	DeviceId is the XPAR_<WDTB_instance>_DEVICE_ID value from
*		xparameters.h.
*
* @return
*		- XST_SUCCESS if WRS bit is not set in next two subsequent
*		timer expiry state.
*		- XST_FAILURE otherwise.
*
* @note		None.
*
****************************************************************************/
This function tests the functioning of the TimeBase WatchDog Timer module
in the polled mode.

After one expiration of the WDT timeout interval, the WDT state bit is set to
one in the status register. If the state bit is not cleared (by writing a 1 to
the state bit) before the next expiration of the timeout interval, a WDT reset
is generated.

This function checks for Watchdog timer reset condition in two timer expiry
state.

This function may require some time (seconds or even minutes) to execute
because it waits for the watchdog timer to expire.
This function tests the functioning of the TimeBase WatchDog Timer module in the polled mode . After one expiration of the WDT timeout interval the WDT state bit is set to one in the status register . If the state bit is not cleared ( by writing a 1 to the state bit ) before the next expiration of the timeout interval a WDT reset is generated . This function checks for Watchdog timer reset condition in two timer expiry state . This function may require some time ( seconds or even minutes ) to execute because it waits for the watchdog timer to expire .
int WdtTbExample(u16 DeviceId)
{
	int Status;
	int Count = 0;
	XWdtTb_Config *Config;
	Config = XWdtTb_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}
	Status = XWdtTb_CfgInitialize(&WatchdogTimebase, Config,
			Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XWdtTb_SelfTest(&WatchdogTimebase);
	if (Status != XST_SUCCESS) {
		xil_printf("Example:Self test failed\n\r");
		return XST_FAILURE;
	}
	XWdtTb_Start(&WatchdogTimebase);
	while (1) {
		xil_printf(".");
		if (XWdtTb_IsWdtExpired(&WatchdogTimebase)) {
			XWdtTb_RestartWdt(&WatchdogTimebase);
			Count++;
			xil_printf("\n\rRestart kick %d\n\r", Count);
		}
		if (XWdtTb_ReadReg(WatchdogTimebase.Config.BaseAddr,
				XWT_TWCSR0_OFFSET) & XWT_CSR0_WRS_MASK) {
			XWdtTb_Stop(&WatchdogTimebase);
			return XST_FAILURE;
		}
		if(Count == 2) {
			break;
		}
	}
	return XST_SUCCESS;
}
int WdtTbExample ( u16 DeviceId ) { int Status ; int Count = 0 ; XWdtTb_Config * Config ; Config = XWdtTb_LookupConfig ( DeviceId ) ; if ( NULL == Config ) { return XST_FAILURE ; } Status = XWdtTb_CfgInitialize ( & WatchdogTimebase , Config , Config -> BaseAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XWdtTb_SelfTest ( & WatchdogTimebase ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " ) ; return XST_FAILURE ; } XWdtTb_Start ( & WatchdogTimebase ) ; while ( 1 ) { xil_printf ( " " ) ; if ( XWdtTb_IsWdtExpired ( & WatchdogTimebase ) ) { XWdtTb_RestartWdt ( & WatchdogTimebase ) ; Count ++ ; xil_printf ( " \n \r \n \r " , Count ) ; } if ( XWdtTb_ReadReg ( WatchdogTimebase . Config . BaseAddr , XWT_TWCSR0_OFFSET ) & XWT_CSR0_WRS_MASK ) { XWdtTb_Stop ( & WatchdogTimebase ) ; return XST_FAILURE ; } if ( Count == 2 ) { break ; } } return XST_SUCCESS ; }
This function tests the functioning of the TimeBase WatchDog Timer module
in the polled mode.
This function tests the functioning of the TimeBase WatchDog Timer module in the polled mode .
/*
	 * Initialize the WDTTB driver so that it's ready to use look up
	 * configuration in the config table, then initialize it.
	 */ /*
	 * Initialize the watchdog timer and timebase driver so that
	 * it is ready to use.
	 */ /*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */ /*
	 * Start the watchdog timer, the timebase is automatically reset
	 * when this occurs.
	 */ /*
	 * Verify Whether the WatchDog Reset Status has been set in the next two
	 * expiry state.
	 */ /*
		 * If the watchdog timer expired, then restart it.
		 */ /*
			 * Restart the watchdog timer as a normal application
			 * would
			 */ /*
		 * Check whether the WatchDog Reset Status has been set.
		 * If this is set means then the test has failed
		 */ /*
			 * Stop the watchdog timer
			 */ /*
		 * Check whether the WatchDog timer expires two times.
		 * If the timer expires two times then the test is passed.
		 */