XilinxProcessorIPLib/drivers/can/examples/xcan_intr_example.c
static int XCanIntrExample(u16 DeviceId)
{
	int Status;

	/*
	 * Initialize the XCan driver.
	 */
	Status = XCan_Initialize(&Can, DeviceId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Run self-test on the device, which verifies basic sanity of the
	 * device and the driver.
	 */
	Status = XCan_SelfTest(&Can);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Configure the CAN device.
	 */
	Config(&Can);

	/*
	 * Set interrupt handlers.
	 */
	XCan_SetHandler(&Can, XCAN_HANDLER_SEND,
			(void *)SendHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_RECV,
			(void *)RecvHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_ERROR,
			(void *)ErrorHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_EVENT,
			(void *)EventHandler, (void *)&Can);

	/*
	 * Initialize flags.
	 */
	SendDone = FALSE;
	RecvDone = FALSE;
	LoopbackError = FALSE;

	/*
	 * Connect to the interrupt controller.
	 */
	Status = SetupInterruptSystem(&Can);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable all interrupts in CAN device.
	 */
	XCan_InterruptEnable(&Can, XCAN_IXR_ALL);

	/*
	 * Enter Loop Back Mode.
	 */
	XCan_EnterMode(&Can, XCAN_MODE_LOOPBACK);
	while(XCan_GetMode(&Can) != XCAN_MODE_LOOPBACK);

	/*
	 * Loop back a frame. The RecvHandler is expected to handle
	 * the frame reception.
	 */
	SendFrame(&Can); /* Send a frame */

	/*
	 * Wait here until both sending and reception have been completed.
	 */
	while ((SendDone != TRUE) || (RecvDone != TRUE));

	/*
	 * Check for errors found in the callbacks.
	 */
	if (LoopbackError == TRUE) {
		return XST_LOOPBACK_ERROR;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The main entry point for showing the XCan driver in interrupt mode.
* The example configures the device for internal loopback mode, then
* sends a CAN frame and receives the same CAN frame.
*
* @param	DeviceId contains the CAN device ID.
*
* @return	XST_SUCCESS if successful, otherwise driver-specific error code.
*
* @note 	If the device is not working correctly, this function may enter
*		an infinite loop and will never return to the caller.
*
******************************************************************************/
The main entry point for showing the XCan driver in interrupt mode.
The example configures the device for internal loopback mode, then
sends a CAN frame and receives the same CAN frame.
The main entry point for showing the XCan driver in interrupt mode . The example configures the device for internal loopback mode then sends a CAN frame and receives the same CAN frame .
static int XCanIntrExample(u16 DeviceId)
{
	int Status;
	Status = XCan_Initialize(&Can, DeviceId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XCan_SelfTest(&Can);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Config(&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_SEND,
			(void *)SendHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_RECV,
			(void *)RecvHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_ERROR,
			(void *)ErrorHandler, (void *)&Can);
	XCan_SetHandler(&Can, XCAN_HANDLER_EVENT,
			(void *)EventHandler, (void *)&Can);
	SendDone = FALSE;
	RecvDone = FALSE;
	LoopbackError = FALSE;
	Status = SetupInterruptSystem(&Can);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XCan_InterruptEnable(&Can, XCAN_IXR_ALL);
	XCan_EnterMode(&Can, XCAN_MODE_LOOPBACK);
	while(XCan_GetMode(&Can) != XCAN_MODE_LOOPBACK);
	SendFrame(&Can); 
	while ((SendDone != TRUE) || (RecvDone != TRUE));
	if (LoopbackError == TRUE) {
		return XST_LOOPBACK_ERROR;
	}
	return XST_SUCCESS;
}
static int XCanIntrExample ( u16 DeviceId ) { int Status ; Status = XCan_Initialize ( & Can , DeviceId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XCan_SelfTest ( & Can ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Config ( & Can ) ; XCan_SetHandler ( & Can , XCAN_HANDLER_SEND , ( void * ) SendHandler , ( void * ) & Can ) ; XCan_SetHandler ( & Can , XCAN_HANDLER_RECV , ( void * ) RecvHandler , ( void * ) & Can ) ; XCan_SetHandler ( & Can , XCAN_HANDLER_ERROR , ( void * ) ErrorHandler , ( void * ) & Can ) ; XCan_SetHandler ( & Can , XCAN_HANDLER_EVENT , ( void * ) EventHandler , ( void * ) & Can ) ; SendDone = FALSE ; RecvDone = FALSE ; LoopbackError = FALSE ; Status = SetupInterruptSystem ( & Can ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XCan_InterruptEnable ( & Can , XCAN_IXR_ALL ) ; XCan_EnterMode ( & Can , XCAN_MODE_LOOPBACK ) ; while ( XCan_GetMode ( & Can ) != XCAN_MODE_LOOPBACK ) ; SendFrame ( & Can ) ; while ( ( SendDone != TRUE ) || ( RecvDone != TRUE ) ) ; if ( LoopbackError == TRUE ) { return XST_LOOPBACK_ERROR ; } return XST_SUCCESS ; }
The main entry point for showing the XCan driver in interrupt mode.
The main entry point for showing the XCan driver in interrupt mode .
/*
	 * Initialize the XCan driver.
	 */ /*
	 * Run self-test on the device, which verifies basic sanity of the
	 * device and the driver.
	 */ /*
	 * Configure the CAN device.
	 */ /*
	 * Set interrupt handlers.
	 */ /*
	 * Initialize flags.
	 */ /*
	 * Connect to the interrupt controller.
	 */ /*
	 * Enable all interrupts in CAN device.
	 */ /*
	 * Enter Loop Back Mode.
	 */ /*
	 * Loop back a frame. The RecvHandler is expected to handle
	 * the frame reception.
	 */ /* Send a frame */ /*
	 * Wait here until both sending and reception have been completed.
	 */ /*
	 * Check for errors found in the callbacks.
	 */