XilinxProcessorIPLib/drivers/scuwdt/examples/xscuwdt_intr_example.c
int ScuWdtIntrExample(XScuGic *IntcInstancePtr, XScuWdt * WdtInstancePtr,
		   u16 WdtDeviceId, u16 WdtIntrId)
{
	int Status;
	u32 Timebase = 0;
	u32 ExpiredTimeDelta = 0;
	XScuWdt_Config *ConfigPtr;

	/*
	 * Initialize the ScuWdt driver.
	 */
	ConfigPtr = XScuWdt_LookupConfig(WdtDeviceId);

	/*
	 * This is where the virtual address would be used, this example
	 * uses physical address.
	 */
	Status = XScuWdt_CfgInitialize(WdtInstancePtr, ConfigPtr,
				      ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XScuWdt_SelfTest(WdtInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Put the watchdog timer in timer mode.
	 */
	XScuWdt_SetTimerMode(WdtInstancePtr);

	/*
	 * Load the watchdog counter register.
	 */
	XScuWdt_LoadWdt(WdtInstancePtr, WDT_LOAD_VALUE);

	/*
	 * Start the ScuWdt device.
	 */
	XScuWdt_Start(WdtInstancePtr);

	/*
	 * Determine how long it takes for the watchdog timer to expire,
	 * for later processing.
	 */
	while (1) {
		if (!(XScuWdt_IsTimerExpired(WdtInstancePtr))) {
			ExpiredTimeDelta++;
		} else {
			break;
		}
	}

	/*
	 * Stop the timer to set up the device in interrupt mode.
	 */
	XScuWdt_Stop(WdtInstancePtr);

	/*
	 * Connect the device to interrupt subsystem so that interrupts
	 * can occur.
	 */
	Status = WdtSetupIntrSystem(IntcInstancePtr, WdtInstancePtr, WdtIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Reload the watchdog counter register.
	 */
	XScuWdt_RestartWdt(WdtInstancePtr);

	/*
	 * Start the ScuWdt device.
	 */
	HandlerCalled = 0;
	XScuWdt_Start(WdtInstancePtr);

	/*
	 * Verify that the watchdog timer does timeout when not restarted
	 * all the time, wait more than the amount of time it took for it
	 * to expire in the previous test.
	 */
	while (1) {
		/*
		 * If the handler is called, the test passed
		 */
		if ((HandlerCalled != 0)) {
			XScuWdt_WriteReg(WdtInstancePtr->Config.BaseAddr,
					 XSCUWDT_ISR_OFFSET,
					 XSCUWDT_ISR_EVENT_FLAG_MASK);
			break;
		}
	}

	/*
	 * Reload the watchdog counter to allow the next test to run normally.
	 */
	XScuWdt_RestartWdt(WdtInstancePtr);

	HandlerCalled = 0;

	/*
	 * Verify that the watchdog timer does not timeout when restarted
	 * all the time, wait more than the amount of time it took for it
	 * to expire in the previous test.
	 */
	while (1) {
		/*
		 * Reload the ScuWdt each pass through the loop.
		 */
		XScuWdt_RestartWdt(WdtInstancePtr);

		/*
		 * If more time has gone past than it took for it to expire
		 * when not restarted in the previous test, then stop as the
		 * restarting worked.
		 */
		Timebase++;
		if (Timebase > ExpiredTimeDelta + ExpiredTimeDelta) {
			break;
		}

		/*
		 * If the watchdog timer expired and/or handler called, then the
		 * test failed.
		 */
		if ((XScuWdt_IsTimerExpired(WdtInstancePtr)) ||
		    (HandlerCalled != 0)) {
			/*
			 * Disable and disconnect the interrupt system.
			 */
			WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId);
			return XST_FAILURE;
		}
	}

	/*
	 * Disable and disconnect the interrupt system.
	 */
	WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function tests the functioning of the Scu Private WDT driver and hardware
* in Timer mode using interrupts.
*
* After one expiration of the timeout interval, an interrupt is generated and
* the Event flag bit is set in the watchdog interrupt status register.
*
* @param	IntcInstancePtr is a pointer to the instance of the XScuGic
*		driver.
* @param	WdtInstancePtr is a pointer to the instance of XScuWdt driver.
* @param	WdtDeviceId is the Device ID of the XScuWdt device.
* @param	WdtIntrId is the Interrupt Id of the XScuWdt device.
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
This function tests the functioning of the Scu Private WDT driver and hardware
in Timer mode using interrupts.

After one expiration of the timeout interval, an interrupt is generated and
the Event flag bit is set in the watchdog interrupt status register.
This function tests the functioning of the Scu Private WDT driver and hardware in Timer mode using interrupts . After one expiration of the timeout interval an interrupt is generated and the Event flag bit is set in the watchdog interrupt status register .
int ScuWdtIntrExample(XScuGic *IntcInstancePtr, XScuWdt * WdtInstancePtr,
		   u16 WdtDeviceId, u16 WdtIntrId)
{
	int Status;
	u32 Timebase = 0;
	u32 ExpiredTimeDelta = 0;
	XScuWdt_Config *ConfigPtr;
	ConfigPtr = XScuWdt_LookupConfig(WdtDeviceId);
	Status = XScuWdt_CfgInitialize(WdtInstancePtr, ConfigPtr,
				      ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XScuWdt_SelfTest(WdtInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XScuWdt_SetTimerMode(WdtInstancePtr);
	XScuWdt_LoadWdt(WdtInstancePtr, WDT_LOAD_VALUE);
	XScuWdt_Start(WdtInstancePtr);
	while (1) {
		if (!(XScuWdt_IsTimerExpired(WdtInstancePtr))) {
			ExpiredTimeDelta++;
		} else {
			break;
		}
	}
	XScuWdt_Stop(WdtInstancePtr);
	Status = WdtSetupIntrSystem(IntcInstancePtr, WdtInstancePtr, WdtIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XScuWdt_RestartWdt(WdtInstancePtr);
	HandlerCalled = 0;
	XScuWdt_Start(WdtInstancePtr);
	while (1) {
		if ((HandlerCalled != 0)) {
			XScuWdt_WriteReg(WdtInstancePtr->Config.BaseAddr,
					 XSCUWDT_ISR_OFFSET,
					 XSCUWDT_ISR_EVENT_FLAG_MASK);
			break;
		}
	}
	XScuWdt_RestartWdt(WdtInstancePtr);
	HandlerCalled = 0;
	while (1) {
		XScuWdt_RestartWdt(WdtInstancePtr);
		Timebase++;
		if (Timebase > ExpiredTimeDelta + ExpiredTimeDelta) {
			break;
		}
		if ((XScuWdt_IsTimerExpired(WdtInstancePtr)) ||
		    (HandlerCalled != 0)) {
			WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId);
			return XST_FAILURE;
		}
	}
	WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId);
	return XST_SUCCESS;
}
int ScuWdtIntrExample ( XScuGic * IntcInstancePtr , XScuWdt * WdtInstancePtr , u16 WdtDeviceId , u16 WdtIntrId ) { int Status ; u32 Timebase = 0 ; u32 ExpiredTimeDelta = 0 ; XScuWdt_Config * ConfigPtr ; ConfigPtr = XScuWdt_LookupConfig ( WdtDeviceId ) ; Status = XScuWdt_CfgInitialize ( WdtInstancePtr , ConfigPtr , ConfigPtr -> BaseAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XScuWdt_SelfTest ( WdtInstancePtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XScuWdt_SetTimerMode ( WdtInstancePtr ) ; XScuWdt_LoadWdt ( WdtInstancePtr , WDT_LOAD_VALUE ) ; XScuWdt_Start ( WdtInstancePtr ) ; while ( 1 ) { if ( ! ( XScuWdt_IsTimerExpired ( WdtInstancePtr ) ) ) { ExpiredTimeDelta ++ ; } else { break ; } } XScuWdt_Stop ( WdtInstancePtr ) ; Status = WdtSetupIntrSystem ( IntcInstancePtr , WdtInstancePtr , WdtIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XScuWdt_RestartWdt ( WdtInstancePtr ) ; HandlerCalled = 0 ; XScuWdt_Start ( WdtInstancePtr ) ; while ( 1 ) { if ( ( HandlerCalled != 0 ) ) { XScuWdt_WriteReg ( WdtInstancePtr -> Config . BaseAddr , XSCUWDT_ISR_OFFSET , XSCUWDT_ISR_EVENT_FLAG_MASK ) ; break ; } } XScuWdt_RestartWdt ( WdtInstancePtr ) ; HandlerCalled = 0 ; while ( 1 ) { XScuWdt_RestartWdt ( WdtInstancePtr ) ; Timebase ++ ; if ( Timebase > ExpiredTimeDelta + ExpiredTimeDelta ) { break ; } if ( ( XScuWdt_IsTimerExpired ( WdtInstancePtr ) ) || ( HandlerCalled != 0 ) ) { WdtDisableIntrSystem ( IntcInstancePtr , WdtIntrId ) ; return XST_FAILURE ; } } WdtDisableIntrSystem ( IntcInstancePtr , WdtIntrId ) ; return XST_SUCCESS ; }
This function tests the functioning of the Scu Private WDT driver and hardware
in Timer mode using interrupts.
This function tests the functioning of the Scu Private WDT driver and hardware in Timer mode using interrupts .
/*
	 * Initialize the ScuWdt driver.
	 */ /*
	 * This is where the virtual address would be used, this example
	 * uses physical address.
	 */ /*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */ /*
	 * Put the watchdog timer in timer mode.
	 */ /*
	 * Load the watchdog counter register.
	 */ /*
	 * Start the ScuWdt device.
	 */ /*
	 * Determine how long it takes for the watchdog timer to expire,
	 * for later processing.
	 */ /*
	 * Stop the timer to set up the device in interrupt mode.
	 */ /*
	 * Connect the device to interrupt subsystem so that interrupts
	 * can occur.
	 */ /*
	 * Reload the watchdog counter register.
	 */ /*
	 * Start the ScuWdt device.
	 */ /*
	 * Verify that the watchdog timer does timeout when not restarted
	 * all the time, wait more than the amount of time it took for it
	 * to expire in the previous test.
	 */ /*
		 * If the handler is called, the test passed
		 */ /*
	 * Reload the watchdog counter to allow the next test to run normally.
	 */ /*
	 * Verify that the watchdog timer does not timeout when restarted
	 * all the time, wait more than the amount of time it took for it
	 * to expire in the previous test.
	 */ /*
		 * Reload the ScuWdt each pass through the loop.
		 */ /*
		 * If more time has gone past than it took for it to expire
		 * when not restarted in the previous test, then stop as the
		 * restarting worked.
		 */ /*
		 * If the watchdog timer expired and/or handler called, then the
		 * test failed.
		 */ /*
			 * Disable and disconnect the interrupt system.
			 */ /*
	 * Disable and disconnect the interrupt system.
	 */