XilinxProcessorIPLib/drivers/canps/examples/xcanps_intr_example.c
int CanPsIntrExample(INTC *IntcInstPtr, XCanPs *CanInstPtr,
			u16 CanDeviceId, u16 CanIntrId)
{
	int Status;
	XCanPs_Config *ConfigPtr;

	/*
	 * Initialize the Can device.
	 */
	ConfigPtr = XCanPs_LookupConfig(CanDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XCanPs_CfgInitialize(CanInstPtr,
				ConfigPtr,
				ConfigPtr->BaseAddr);

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

	/*
	 * Configure CAN device.
	 */
	Config(CanInstPtr);

	/*
	 * Set interrupt handlers.
	 */
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_SEND,
			(void *)SendHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_RECV,
			(void *)RecvHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_ERROR,
			(void *)ErrorHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_EVENT,
			(void *)EventHandler, (void *)CanInstPtr);

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

	/*
	 * Connect to the interrupt controller.
	 */
	Status =  SetupInterruptSystem(IntcInstPtr,
					CanInstPtr,
					CanIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable all interrupts in CAN device.
	 */
	XCanPs_IntrEnable(CanInstPtr, XCANPS_IXR_ALL);

	/*
	 * Enter Loop Back Mode.
	 */
	XCanPs_EnterMode(CanInstPtr, XCANPS_MODE_LOOPBACK);
	while(XCanPs_GetMode(CanInstPtr) != XCANPS_MODE_LOOPBACK);

	/*
	 * Loop back a frame. The RecvHandler is expected to handle
	 * the frame reception.
	 */
	SendFrame(CanInstPtr); /* 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 XCanPs driver in interrupt mode.
* The example configures the device for internal loop back mode, then
* sends a CAN frame and receives the same CAN frame.
*
* @param	IntcInstPtr is a pointer to the instance of the INTC driver.
* @param	CanInstPtr is a pointer to the instance of the CAN driver which
*		is going to be connected to the interrupt controller.
* @param	CanDeviceId is the device Id of the CAN device and is typically
*		XPAR_<CANPS_instance>_DEVICE_ID value from xparameters.h.
* @param	CanIntrId is the interrupt Id and is typically
*		XPAR_<CANPS_instance>_INTR value from xparameters.h.
*
* @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 XCanPs driver in interrupt mode.
The example configures the device for internal loop back mode, then
sends a CAN frame and receives the same CAN frame.
The main entry point for showing the XCanPs driver in interrupt mode . The example configures the device for internal loop back mode then sends a CAN frame and receives the same CAN frame .
int CanPsIntrExample(INTC *IntcInstPtr, XCanPs *CanInstPtr,
			u16 CanDeviceId, u16 CanIntrId)
{
	int Status;
	XCanPs_Config *ConfigPtr;
	ConfigPtr = XCanPs_LookupConfig(CanDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XCanPs_CfgInitialize(CanInstPtr,
				ConfigPtr,
				ConfigPtr->BaseAddr);
	Status = XCanPs_SelfTest(CanInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Config(CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_SEND,
			(void *)SendHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_RECV,
			(void *)RecvHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_ERROR,
			(void *)ErrorHandler, (void *)CanInstPtr);
	XCanPs_SetHandler(CanInstPtr, XCANPS_HANDLER_EVENT,
			(void *)EventHandler, (void *)CanInstPtr);
	SendDone = FALSE;
	RecvDone = FALSE;
	LoopbackError = FALSE;
	Status =  SetupInterruptSystem(IntcInstPtr,
					CanInstPtr,
					CanIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XCanPs_IntrEnable(CanInstPtr, XCANPS_IXR_ALL);
	XCanPs_EnterMode(CanInstPtr, XCANPS_MODE_LOOPBACK);
	while(XCanPs_GetMode(CanInstPtr) != XCANPS_MODE_LOOPBACK);
	SendFrame(CanInstPtr); 
	while ((SendDone != TRUE) || (RecvDone != TRUE));
	if (LoopbackError == TRUE) {
		return XST_LOOPBACK_ERROR;
	}
	return XST_SUCCESS;
}
int CanPsIntrExample ( INTC * IntcInstPtr , XCanPs * CanInstPtr , u16 CanDeviceId , u16 CanIntrId ) { int Status ; XCanPs_Config * ConfigPtr ; ConfigPtr = XCanPs_LookupConfig ( CanDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } XCanPs_CfgInitialize ( CanInstPtr , ConfigPtr , ConfigPtr -> BaseAddr ) ; Status = XCanPs_SelfTest ( CanInstPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Config ( CanInstPtr ) ; XCanPs_SetHandler ( CanInstPtr , XCANPS_HANDLER_SEND , ( void * ) SendHandler , ( void * ) CanInstPtr ) ; XCanPs_SetHandler ( CanInstPtr , XCANPS_HANDLER_RECV , ( void * ) RecvHandler , ( void * ) CanInstPtr ) ; XCanPs_SetHandler ( CanInstPtr , XCANPS_HANDLER_ERROR , ( void * ) ErrorHandler , ( void * ) CanInstPtr ) ; XCanPs_SetHandler ( CanInstPtr , XCANPS_HANDLER_EVENT , ( void * ) EventHandler , ( void * ) CanInstPtr ) ; SendDone = FALSE ; RecvDone = FALSE ; LoopbackError = FALSE ; Status = SetupInterruptSystem ( IntcInstPtr , CanInstPtr , CanIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XCanPs_IntrEnable ( CanInstPtr , XCANPS_IXR_ALL ) ; XCanPs_EnterMode ( CanInstPtr , XCANPS_MODE_LOOPBACK ) ; while ( XCanPs_GetMode ( CanInstPtr ) != XCANPS_MODE_LOOPBACK ) ; SendFrame ( CanInstPtr ) ; while ( ( SendDone != TRUE ) || ( RecvDone != TRUE ) ) ; if ( LoopbackError == TRUE ) { return XST_LOOPBACK_ERROR ; } return XST_SUCCESS ; }
The main entry point for showing the XCanPs driver in interrupt mode.
The main entry point for showing the XCanPs driver in interrupt mode .
/*
	 * Initialize the Can device.
	 */ /*
	 * Run self-test on the device, which verifies basic sanity of the
	 * device and the driver.
	 */ /*
	 * Configure CAN device.
	 */ /*
	 * Set interrupt handlers.
	 */ /*
	 * Initialize the 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.
	 */