XilinxProcessorIPLib/drivers/can/src/xcan_selftest.c
int XCan_SelfTest(XCan *InstancePtr)
{
	u8 *FramePtr;
	u32 Result;
	u32 Index;

	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);

	/* Reset device first */
	XCan_Reset(InstancePtr);

	/*
	 * The device should enter Configuration Mode immediately after the
	 * reset above is finished. Now check the mode and return error code if
	 * it is not Configuration Mode.
	 */
	if (XCan_GetMode(InstancePtr) != XCAN_MODE_CONFIG) {
		return XST_FAILURE;
	}

	/*
	 * Setup Baud Rate Prescaler Register (BRPR) and Bit Timing Register
	 * (BTR) such that CAN baud rate equals 40Kbps, given the CAN clock
	 * equal to 24MHz.
	 */
	XCan_SetBaudRatePrescaler(InstancePtr, 29);
	XCan_SetBitTiming(InstancePtr, 3, 2, 15);

	/* Enter loopback mode  */
	XCan_EnterMode(InstancePtr, XCAN_MODE_LOOPBACK);
	while (XCan_GetMode(InstancePtr) != XCAN_MODE_LOOPBACK);

	/*
	 * Create a frame to send with known values so we can verify them
	 * on receive.
	 */
	TxFrame[0] = XCan_CreateIdValue(TEST_MESSAGE_ID, 0, 0, 0, 0);
	TxFrame[1] = XCan_CreateDlcValue(TEST_CAN_DLC);
	FramePtr = (u8 *) (&TxFrame[2]);
	for (Index = 0; Index < 8; Index++) {
		*FramePtr++ = (u8) Index;
	}

	/* Send the frame. */
	Result = XCan_Send(InstancePtr, TxFrame);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Wait until the frame arrives RX FIFO via internal loop back */
	while (XCan_IsRxEmpty(InstancePtr) == TRUE);

	/* Receive the frame */
	Result = XCan_Recv(InstancePtr, RxFrame);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Compare received frame with sent frame */
	for (Index = 0; Index < XCAN_MAX_FRAME_SIZE_IN_WORDS; Index++) {
		if (RxFrame[Index] != TxFrame[Index]) {
			return XST_FAILURE;
		}
	}

	/* Reset device again before return to the caller */
	XCan_Reset(InstancePtr);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function runs a self-test on the CAN driver/device. The test resets
* the device, sets up the Loop Back mode, sends a standard frame, receives the
* frame, verifies the contents, and resets the device again.
*
* Note that this is a destructive test in that resets of the device are
* performed. Refer to the device specification for the device status
* after the reset operation.
*
*
* @param	InstancePtr is a pointer to the XCan instance to be worked on.
*
* @return
*		- XST_SUCCESS   if the self-test passed. i.e., the frame
*		received via the internal loop back has the same contents as the
* 		sent frame.
* 		- XST_FAILURE   Otherwise.
*
* @note
*
* If the CAN device does not work properly, this function may enter an
* infinite loop and will never return to the caller.
* <br><br>
* If XST_FAILURE is returned, the device is not reset so that the caller could
* have a chance to check reason(s) causing the failure.
*
******************************************************************************/
This function runs a self-test on the CAN driver/device. The test resets
the device, sets up the Loop Back mode, sends a standard frame, receives the
frame, verifies the contents, and resets the device again.

Note that this is a destructive test in that resets of the device are
performed. Refer to the device specification for the device status
after the reset operation.
This function runs a self - test on the CAN driver / device . The test resets the device sets up the Loop Back mode sends a standard frame receives the frame verifies the contents and resets the device again . Note that this is a destructive test in that resets of the device are performed . Refer to the device specification for the device status after the reset operation .
int XCan_SelfTest(XCan *InstancePtr)
{
	u8 *FramePtr;
	u32 Result;
	u32 Index;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	XCan_Reset(InstancePtr);
	if (XCan_GetMode(InstancePtr) != XCAN_MODE_CONFIG) {
		return XST_FAILURE;
	}
	XCan_SetBaudRatePrescaler(InstancePtr, 29);
	XCan_SetBitTiming(InstancePtr, 3, 2, 15);
	XCan_EnterMode(InstancePtr, XCAN_MODE_LOOPBACK);
	while (XCan_GetMode(InstancePtr) != XCAN_MODE_LOOPBACK);
	TxFrame[0] = XCan_CreateIdValue(TEST_MESSAGE_ID, 0, 0, 0, 0);
	TxFrame[1] = XCan_CreateDlcValue(TEST_CAN_DLC);
	FramePtr = (u8 *) (&TxFrame[2]);
	for (Index = 0; Index < 8; Index++) {
		*FramePtr++ = (u8) Index;
	}
	Result = XCan_Send(InstancePtr, TxFrame);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (XCan_IsRxEmpty(InstancePtr) == TRUE);
	Result = XCan_Recv(InstancePtr, RxFrame);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}
	for (Index = 0; Index < XCAN_MAX_FRAME_SIZE_IN_WORDS; Index++) {
		if (RxFrame[Index] != TxFrame[Index]) {
			return XST_FAILURE;
		}
	}
	XCan_Reset(InstancePtr);
	return XST_SUCCESS;
}
int XCan_SelfTest ( XCan * InstancePtr ) { u8 * FramePtr ; u32 Result ; u32 Index ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( InstancePtr -> IsReady == XIL_COMPONENT_IS_READY ) ; XCan_Reset ( InstancePtr ) ; if ( XCan_GetMode ( InstancePtr ) != XCAN_MODE_CONFIG ) { return XST_FAILURE ; } XCan_SetBaudRatePrescaler ( InstancePtr , 29 ) ; XCan_SetBitTiming ( InstancePtr , 3 , 2 , 15 ) ; XCan_EnterMode ( InstancePtr , XCAN_MODE_LOOPBACK ) ; while ( XCan_GetMode ( InstancePtr ) != XCAN_MODE_LOOPBACK ) ; TxFrame [ 0 ] = XCan_CreateIdValue ( TEST_MESSAGE_ID , 0 , 0 , 0 , 0 ) ; TxFrame [ 1 ] = XCan_CreateDlcValue ( TEST_CAN_DLC ) ; FramePtr = ( u8 * ) ( & TxFrame [ 2 ] ) ; for ( Index = 0 ; Index < 8 ; Index ++ ) { * FramePtr ++ = ( u8 ) Index ; } Result = XCan_Send ( InstancePtr , TxFrame ) ; if ( Result != XST_SUCCESS ) { return XST_FAILURE ; } while ( XCan_IsRxEmpty ( InstancePtr ) == TRUE ) ; Result = XCan_Recv ( InstancePtr , RxFrame ) ; if ( Result != XST_SUCCESS ) { return XST_FAILURE ; } for ( Index = 0 ; Index < XCAN_MAX_FRAME_SIZE_IN_WORDS ; Index ++ ) { if ( RxFrame [ Index ] != TxFrame [ Index ] ) { return XST_FAILURE ; } } XCan_Reset ( InstancePtr ) ; return XST_SUCCESS ; }
This function runs a self-test on the CAN driver/device.
This function runs a self - test on the CAN driver / device .
/* Reset device first */ /*
	 * The device should enter Configuration Mode immediately after the
	 * reset above is finished. Now check the mode and return error code if
	 * it is not Configuration Mode.
	 */ /*
	 * Setup Baud Rate Prescaler Register (BRPR) and Bit Timing Register
	 * (BTR) such that CAN baud rate equals 40Kbps, given the CAN clock
	 * equal to 24MHz.
	 */ /* Enter loopback mode  */ /*
	 * Create a frame to send with known values so we can verify them
	 * on receive.
	 */ /* Send the frame. */ /* Wait until the frame arrives RX FIFO via internal loop back */ /* Receive the frame */ /* Compare received frame with sent frame */ /* Reset device again before return to the caller */