XilinxProcessorIPLib/drivers/canps/examples/xcanps_watermark_intr_example.c
int CanPsWatermarkIntrExample(XScuGic *IntcInstPtr, XCanPs *CanInstPtr,
				u16 CanDeviceId, u16 CanIntrId)
{
	int Status;
	XCanPs_Config *ConfigPtr;
	u32 Index;

	/*
	 * Initialize the Can device.
	 */
	ConfigPtr = XCanPs_LookupConfig(CanDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XCanPs_CfgInitialize(CanInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * 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 the CAN device.
	 */
	Config(CanInstPtr);

	/*
	 * Set the 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 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);
	XCanPs_IntrEnable(CanInstPtr, XCANPS_IXR_TXFWMEMP_MASK);

	/*
	 * Disable the Receive FIFO Not Empty Interrupt and the
	 * New Message Received Interrupt.
	 */
	XCanPs_IntrDisable(CanInstPtr,
				XCANPS_IXR_RXNEMP_MASK |
				XCANPS_IXR_RXOK_MASK | XCANPS_IXR_TXOK_MASK);

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

	/*
	 * Send a number of frames.
	 */
	TestDataOffset = 1;
	for (Index = 0; Index < TEST_THRESHOLD; Index++) {

		SendFrame(CanInstPtr); /* Send a frame */
		TestDataOffset++;
	}

	/*
	 * 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_FAILURE;
	}

	/*
	 * Read the Received Frames from the FIFO.
	 */
	TestDataOffset = 1;
	Status = ReceiveData(CanInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

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

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The main entry point for showing the usage of XCanPs driver in interrupt
* mode. The example configures the device for internal loop back mode, then
* sends multiple CAN frames and receives the same number of CAN frame's
* using the Rx Watermark Interrupt.
*
* @param	IntcInstPtr is a pointer to the instance of the ScuGic 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 usage of XCanPs driver in interrupt
mode. The example configures the device for internal loop back mode, then
sends multiple CAN frames and receives the same number of CAN frame's
using the Rx Watermark Interrupt.
The main entry point for showing the usage of XCanPs driver in interrupt mode . The example configures the device for internal loop back mode then sends multiple CAN frames and receives the same number of CAN frame ' s using the Rx Watermark Interrupt .
int CanPsWatermarkIntrExample(XScuGic *IntcInstPtr, XCanPs *CanInstPtr,
				u16 CanDeviceId, u16 CanIntrId)
{
	int Status;
	XCanPs_Config *ConfigPtr;
	u32 Index;
	ConfigPtr = XCanPs_LookupConfig(CanDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XCanPs_CfgInitialize(CanInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	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_IntrEnable(CanInstPtr, XCANPS_IXR_TXFWMEMP_MASK);
	XCanPs_IntrDisable(CanInstPtr,
				XCANPS_IXR_RXNEMP_MASK |
				XCANPS_IXR_RXOK_MASK | XCANPS_IXR_TXOK_MASK);
	XCanPs_EnterMode(CanInstPtr, XCANPS_MODE_LOOPBACK);
	while(XCanPs_GetMode(CanInstPtr) != XCANPS_MODE_LOOPBACK);
	TestDataOffset = 1;
	for (Index = 0; Index < TEST_THRESHOLD; Index++) {
		SendFrame(CanInstPtr); 
		TestDataOffset++;
	}
	while ((SendDone != TRUE) || (RecvDone != TRUE));
	if (LoopbackError == TRUE) {
		return XST_FAILURE;
	}
	TestDataOffset = 1;
	Status = ReceiveData(CanInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if (LoopbackError == TRUE) {
		return XST_LOOPBACK_ERROR;
	}
	return XST_SUCCESS;
}
int CanPsWatermarkIntrExample ( XScuGic * IntcInstPtr , XCanPs * CanInstPtr , u16 CanDeviceId , u16 CanIntrId ) { int Status ; XCanPs_Config * ConfigPtr ; u32 Index ; ConfigPtr = XCanPs_LookupConfig ( CanDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XCanPs_CfgInitialize ( CanInstPtr , ConfigPtr , ConfigPtr -> BaseAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } 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_IntrEnable ( CanInstPtr , XCANPS_IXR_TXFWMEMP_MASK ) ; XCanPs_IntrDisable ( CanInstPtr , XCANPS_IXR_RXNEMP_MASK | XCANPS_IXR_RXOK_MASK | XCANPS_IXR_TXOK_MASK ) ; XCanPs_EnterMode ( CanInstPtr , XCANPS_MODE_LOOPBACK ) ; while ( XCanPs_GetMode ( CanInstPtr ) != XCANPS_MODE_LOOPBACK ) ; TestDataOffset = 1 ; for ( Index = 0 ; Index < TEST_THRESHOLD ; Index ++ ) { SendFrame ( CanInstPtr ) ; TestDataOffset ++ ; } while ( ( SendDone != TRUE ) || ( RecvDone != TRUE ) ) ; if ( LoopbackError == TRUE ) { return XST_FAILURE ; } TestDataOffset = 1 ; Status = ReceiveData ( CanInstPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( LoopbackError == TRUE ) { return XST_LOOPBACK_ERROR ; } return XST_SUCCESS ; }
The main entry point for showing the usage of XCanPs driver in interrupt
mode.
The main entry point for showing the usage of 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 the CAN device.
	 */ /*
	 * Set the interrupt handlers.
	 */ /*
	 * Initialize flags.
	 */ /*
	 * Connect to the interrupt controller.
	 */ /*
	 * Enable all interrupts in CAN device.
	 */ /*
	 * Disable the Receive FIFO Not Empty Interrupt and the
	 * New Message Received Interrupt.
	 */ /*
	 * Enter Loop Back Mode.
	 */ /*
	 * Send a number of frames.
	 */ /* Send a frame */ /*
	 * Wait here until both sending and reception have been completed.
	 */ /*
	 * Check for errors found in the callbacks.
	 */ /*
	 * Read the Received Frames from the FIFO.
	 */ /*
	 * Check for errors found in the callbacks.
	 */