XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_selftest.c
s32 XWdtPs_SelfTest(XWdtPs *InstancePtr)
{
	u32 ZmrOrig;
	u32 ZmrValue1;
	u32 ZmrValue2;
	s32 Status;

	/*
	 * Assert to ensure the inputs are valid and the instance has been
	 * initialized.
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);

	/*
	 * Read the ZMR register at start the test.
	 */
	ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
				 XWDTPS_ZMR_OFFSET);

	/*
	 * EX-OR in the length of the interrupt pulse,
	 * do not set the key value.
	 */
	ZmrValue1 = ZmrOrig ^ (u32)XWDTPS_ZMR_RSTLN_MASK;


	/*
	 * Try to write to register w/o key value then read back.
	 */
	XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
			  ZmrValue1);

	ZmrValue2 =	XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
				 XWDTPS_ZMR_OFFSET);

	if (ZmrValue1 == ZmrValue2) {
		/*
		 * If the values match, the hw failed the test,
		 * return orig register value.
		 */
		XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
				  XWDTPS_ZMR_OFFSET,
				  (ZmrOrig | (u32)XWDTPS_ZMR_ZKEY_VAL));
		Status = (s32)XST_FAILURE;
	} else {


		/*
		 * Try to write to register with key value then read back.
		 */
		XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
				  (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL));

		ZmrValue2 =	XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
					 XWDTPS_ZMR_OFFSET);

		if (ZmrValue1 != ZmrValue2) {
			/*
			 * If the values do not match, the hw failed the test,
			 * return orig register value.
			 */
			XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
					  XWDTPS_ZMR_OFFSET,
					  ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
			Status = (s32)XST_FAILURE;

		} else {

			/*
			 * The hardware locking feature is functional, return the original value
			 * and return success.
			 */
			XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
					  ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);

			Status = (s32)XST_SUCCESS;
		}
	}
	return Status;
}
/****************************************************************************/
/**
*
* Run a self-test on the timebase. This test verifies that the register access
* locking functions. This is tested by trying to alter a register without
* setting the key value and verifying that the register contents did not
* change.
*
* @param	InstancePtr is a pointer to the XWdtPs instance.
*
* @return
*		- XST_SUCCESS if self-test was successful.
*		- XST_FAILURE if self-test was not successful.
*
* @note		None.
*
******************************************************************************/
Run a self-test on the timebase. This test verifies that the register access
locking functions. This is tested by trying to alter a register without
setting the key value and verifying that the register contents did not
change.
Run a self - test on the timebase . This test verifies that the register access locking functions . This is tested by trying to alter a register without setting the key value and verifying that the register contents did not change .
s32 XWdtPs_SelfTest(XWdtPs *InstancePtr)
{
	u32 ZmrOrig;
	u32 ZmrValue1;
	u32 ZmrValue2;
	s32 Status;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
				 XWDTPS_ZMR_OFFSET);
	ZmrValue1 = ZmrOrig ^ (u32)XWDTPS_ZMR_RSTLN_MASK;
	XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
			  ZmrValue1);
	ZmrValue2 =	XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
				 XWDTPS_ZMR_OFFSET);
	if (ZmrValue1 == ZmrValue2) {
		XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
				  XWDTPS_ZMR_OFFSET,
				  (ZmrOrig | (u32)XWDTPS_ZMR_ZKEY_VAL));
		Status = (s32)XST_FAILURE;
	} else {
		XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
				  (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL));
		ZmrValue2 =	XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
					 XWDTPS_ZMR_OFFSET);
		if (ZmrValue1 != ZmrValue2) {
			XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
					  XWDTPS_ZMR_OFFSET,
					  ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
			Status = (s32)XST_FAILURE;
		} else {
			XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
					  ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
			Status = (s32)XST_SUCCESS;
		}
	}
	return Status;
}
s32 XWdtPs_SelfTest ( XWdtPs * InstancePtr ) { u32 ZmrOrig ; u32 ZmrValue1 ; u32 ZmrValue2 ; s32 Status ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( InstancePtr -> IsReady == XIL_COMPONENT_IS_READY ) ; ZmrOrig = XWdtPs_ReadReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET ) ; ZmrValue1 = ZmrOrig ^ ( u32 ) XWDTPS_ZMR_RSTLN_MASK ; XWdtPs_WriteReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET , ZmrValue1 ) ; ZmrValue2 = XWdtPs_ReadReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET ) ; if ( ZmrValue1 == ZmrValue2 ) { XWdtPs_WriteReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET , ( ZmrOrig | ( u32 ) XWDTPS_ZMR_ZKEY_VAL ) ) ; Status = ( s32 ) XST_FAILURE ; } else { XWdtPs_WriteReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET , ( ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL ) ) ; ZmrValue2 = XWdtPs_ReadReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET ) ; if ( ZmrValue1 != ZmrValue2 ) { XWdtPs_WriteReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET , ZmrOrig | XWDTPS_ZMR_ZKEY_VAL ) ; Status = ( s32 ) XST_FAILURE ; } else { XWdtPs_WriteReg ( InstancePtr -> Config . BaseAddress , XWDTPS_ZMR_OFFSET , ZmrOrig | XWDTPS_ZMR_ZKEY_VAL ) ; Status = ( s32 ) XST_SUCCESS ; } } return Status ; }
Run a self-test on the timebase.
Run a self - test on the timebase .
/*
	 * Assert to ensure the inputs are valid and the instance has been
	 * initialized.
	 */ /*
	 * Read the ZMR register at start the test.
	 */ /*
	 * EX-OR in the length of the interrupt pulse,
	 * do not set the key value.
	 */ /*
	 * Try to write to register w/o key value then read back.
	 */ /*
		 * If the values match, the hw failed the test,
		 * return orig register value.
		 */ /*
		 * Try to write to register with key value then read back.
		 */ /*
			 * If the values do not match, the hw failed the test,
			 * return orig register value.
			 */ /*
			 * The hardware locking feature is functional, return the original value
			 * and return success.
			 */