XilinxProcessorIPLib/drivers/canfd/examples/xcanfd_polled_example.c
int XCanFdPolledExample(u16 DeviceId)
{
	int Status;
	XCanFd *CanFdInstPtr = &CanFd;
	XCanFd_Config *ConfigPtr;
	u32 IdValue;
	u32 BuffNr;
	u8 RxBuffers;

	/* Initialize the Can device */
	ConfigPtr = XCanFd_LookupConfig(DeviceId);
	if (CanFdInstPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XCanFd_CfgInitialize(CanFdInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/*
	 * Run self-test on the device, which verifies basic sanity of the
	 * device and the driver.
	 */
	Status = XCanFd_SelfTest(CanFdInstPtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	/*
	 * Enter Configuration Mode so we can setup Baud Rate Prescaler
	 * Register (BRPR) and Bit Timing Register (BTR)
	 */
	XCanFd_EnterMode(CanFdInstPtr, XCANFD_MODE_CONFIG);
	while (XCanFd_GetMode(CanFdInstPtr) != XCANFD_MODE_CONFIG);

	/*
	 * Configure the Baud Rate Prescalar in
	 * Arbitration Phase
	 */
	XCanFd_SetBaudRatePrescaler(CanFdInstPtr, TEST_BRPR_BAUD_PRESCALAR);

	/*
	 * Configure the Bit Timing Values in
	 * Arbitration Phase.
	 */
	XCanFd_SetBitTiming(CanFdInstPtr, TEST_BTR_SYNCJUMPWIDTH,
		TEST_BTR_SECOND_TIMESEGMENT,TEST_BTR_FIRST_TIMESEGMENT);

	 /* Configure the Baud Rate Prescalar in Data Phase */
	XCanFd_SetFBaudRatePrescaler(CanFdInstPtr, TEST_FBRPR_BAUD_PRESCALAR);

	/* Configure the Bit Timing Values in Data Phase */
	XCanFd_SetFBitTiming(CanFdInstPtr,TEST_FBTR_SYNCJUMPWIDTH,
		TEST_FBTR_SECOND_TIMESEGMENT,TEST_FBTR_FIRST_TIMESEGMENT);

	/*
	 * Disable the Global BRS Disable so that
	 * at the time of sending the can frame
	 * we will choose whether we need Bit
	 * Rate Switch or not.
	 */
	XCanFd_SetBitRateSwitch_DisableNominal(CanFdInstPtr);
	/*
	 * Check for the design
	 * 0 - Sequential Mode
	 * 1 - MailBox Mode.
	 */
	if (XCANFD_GET_RX_MODE(CanFdInstPtr) == 0) {
		XCanFd_AcceptFilterDisable(CanFdInstPtr,
			XCANFD_AFR_UAF_ALL_MASK);
		XCanFd_AcceptFilterEnable(CanFdInstPtr,
			XCANFD_AFR_UAF_ALL_MASK);
	}
	else {
		RxBuffers = XCanFd_Get_RxBuffers(CanFdInstPtr);
		IdValue = XCanFd_CreateIdValue(TEST_MESSAGE_ID, 0, 0, 0, 0);
		for (BuffNr = 0;BuffNr < RxBuffers;BuffNr++) {
			XCanFd_RxBuff_MailBox_DeActive(CanFdInstPtr,BuffNr);
			XCanFd_Set_MailBox_IdMask(CanFdInstPtr,BuffNr,
				TEST_MAILBOX_MASK,IdValue);
			XCanFd_RxBuff_MailBox_Active(CanFdInstPtr,BuffNr);
		}
	}

	/* Configure CAN Device to enter to Loop Back Mode */
	XCanFd_EnterMode(CanFdInstPtr, XCANFD_MODE_LOOPBACK);
	while (XCanFd_GetMode(CanFdInstPtr) != XCANFD_MODE_LOOPBACK);

	/* Send Frame */
	Status = SendFrame(CanFdInstPtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}

	/* Receive The Frame */
	Status = RecvFrame(CanFdInstPtr);

	return Status;

}
/*****************************************************************************/
/**
*
* The entry point for showing the XCan driver in polled mode. The example
* configures the device for internal loopback mode, then sends a Can
* frame, receives the same Can frame, and verifies the frame contents.
*
* @param	DeviceId is the XPAR_CAN_<instance_num>_DEVICE_ID 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 entry point for showing the XCan driver in polled mode. The example
configures the device for internal loopback mode, then sends a Can
frame, receives the same Can frame, and verifies the frame contents.
The entry point for showing the XCan driver in polled mode . The example configures the device for internal loopback mode then sends a Can frame receives the same Can frame and verifies the frame contents .
int XCanFdPolledExample(u16 DeviceId)
{
	int Status;
	XCanFd *CanFdInstPtr = &CanFd;
	XCanFd_Config *ConfigPtr;
	u32 IdValue;
	u32 BuffNr;
	u8 RxBuffers;
	ConfigPtr = XCanFd_LookupConfig(DeviceId);
	if (CanFdInstPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XCanFd_CfgInitialize(CanFdInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XCanFd_SelfTest(CanFdInstPtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	XCanFd_EnterMode(CanFdInstPtr, XCANFD_MODE_CONFIG);
	while (XCanFd_GetMode(CanFdInstPtr) != XCANFD_MODE_CONFIG);
	XCanFd_SetBaudRatePrescaler(CanFdInstPtr, TEST_BRPR_BAUD_PRESCALAR);
	XCanFd_SetBitTiming(CanFdInstPtr, TEST_BTR_SYNCJUMPWIDTH,
		TEST_BTR_SECOND_TIMESEGMENT,TEST_BTR_FIRST_TIMESEGMENT);
	XCanFd_SetFBaudRatePrescaler(CanFdInstPtr, TEST_FBRPR_BAUD_PRESCALAR);
	XCanFd_SetFBitTiming(CanFdInstPtr,TEST_FBTR_SYNCJUMPWIDTH,
		TEST_FBTR_SECOND_TIMESEGMENT,TEST_FBTR_FIRST_TIMESEGMENT);
	XCanFd_SetBitRateSwitch_DisableNominal(CanFdInstPtr);
	if (XCANFD_GET_RX_MODE(CanFdInstPtr) == 0) {
		XCanFd_AcceptFilterDisable(CanFdInstPtr,
			XCANFD_AFR_UAF_ALL_MASK);
		XCanFd_AcceptFilterEnable(CanFdInstPtr,
			XCANFD_AFR_UAF_ALL_MASK);
	}
	else {
		RxBuffers = XCanFd_Get_RxBuffers(CanFdInstPtr);
		IdValue = XCanFd_CreateIdValue(TEST_MESSAGE_ID, 0, 0, 0, 0);
		for (BuffNr = 0;BuffNr < RxBuffers;BuffNr++) {
			XCanFd_RxBuff_MailBox_DeActive(CanFdInstPtr,BuffNr);
			XCanFd_Set_MailBox_IdMask(CanFdInstPtr,BuffNr,
				TEST_MAILBOX_MASK,IdValue);
			XCanFd_RxBuff_MailBox_Active(CanFdInstPtr,BuffNr);
		}
	}
	XCanFd_EnterMode(CanFdInstPtr, XCANFD_MODE_LOOPBACK);
	while (XCanFd_GetMode(CanFdInstPtr) != XCANFD_MODE_LOOPBACK);
	Status = SendFrame(CanFdInstPtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	Status = RecvFrame(CanFdInstPtr);
	return Status;
}
int XCanFdPolledExample ( u16 DeviceId ) { int Status ; XCanFd * CanFdInstPtr = & CanFd ; XCanFd_Config * ConfigPtr ; u32 IdValue ; u32 BuffNr ; u8 RxBuffers ; ConfigPtr = XCanFd_LookupConfig ( DeviceId ) ; if ( CanFdInstPtr == NULL ) { return XST_FAILURE ; } Status = XCanFd_CfgInitialize ( CanFdInstPtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XCanFd_SelfTest ( CanFdInstPtr ) ; if ( Status != XST_SUCCESS ) { return Status ; } XCanFd_EnterMode ( CanFdInstPtr , XCANFD_MODE_CONFIG ) ; while ( XCanFd_GetMode ( CanFdInstPtr ) != XCANFD_MODE_CONFIG ) ; XCanFd_SetBaudRatePrescaler ( CanFdInstPtr , TEST_BRPR_BAUD_PRESCALAR ) ; XCanFd_SetBitTiming ( CanFdInstPtr , TEST_BTR_SYNCJUMPWIDTH , TEST_BTR_SECOND_TIMESEGMENT , TEST_BTR_FIRST_TIMESEGMENT ) ; XCanFd_SetFBaudRatePrescaler ( CanFdInstPtr , TEST_FBRPR_BAUD_PRESCALAR ) ; XCanFd_SetFBitTiming ( CanFdInstPtr , TEST_FBTR_SYNCJUMPWIDTH , TEST_FBTR_SECOND_TIMESEGMENT , TEST_FBTR_FIRST_TIMESEGMENT ) ; XCanFd_SetBitRateSwitch_DisableNominal ( CanFdInstPtr ) ; if ( XCANFD_GET_RX_MODE ( CanFdInstPtr ) == 0 ) { XCanFd_AcceptFilterDisable ( CanFdInstPtr , XCANFD_AFR_UAF_ALL_MASK ) ; XCanFd_AcceptFilterEnable ( CanFdInstPtr , XCANFD_AFR_UAF_ALL_MASK ) ; } else { RxBuffers = XCanFd_Get_RxBuffers ( CanFdInstPtr ) ; IdValue = XCanFd_CreateIdValue ( TEST_MESSAGE_ID , 0 , 0 , 0 , 0 ) ; for ( BuffNr = 0 ; BuffNr < RxBuffers ; BuffNr ++ ) { XCanFd_RxBuff_MailBox_DeActive ( CanFdInstPtr , BuffNr ) ; XCanFd_Set_MailBox_IdMask ( CanFdInstPtr , BuffNr , TEST_MAILBOX_MASK , IdValue ) ; XCanFd_RxBuff_MailBox_Active ( CanFdInstPtr , BuffNr ) ; } } XCanFd_EnterMode ( CanFdInstPtr , XCANFD_MODE_LOOPBACK ) ; while ( XCanFd_GetMode ( CanFdInstPtr ) != XCANFD_MODE_LOOPBACK ) ; Status = SendFrame ( CanFdInstPtr ) ; if ( Status != XST_SUCCESS ) { return Status ; } Status = RecvFrame ( CanFdInstPtr ) ; return Status ; }
The entry point for showing the XCan driver in polled mode.
The entry point for showing the XCan driver in polled mode .
/* Initialize the Can device */ /*
	 * Run self-test on the device, which verifies basic sanity of the
	 * device and the driver.
	 */ /*
	 * Enter Configuration Mode so we can setup Baud Rate Prescaler
	 * Register (BRPR) and Bit Timing Register (BTR)
	 */ /*
	 * Configure the Baud Rate Prescalar in
	 * Arbitration Phase
	 */ /*
	 * Configure the Bit Timing Values in
	 * Arbitration Phase.
	 */ /* Configure the Baud Rate Prescalar in Data Phase */ /* Configure the Bit Timing Values in Data Phase */ /*
	 * Disable the Global BRS Disable so that
	 * at the time of sending the can frame
	 * we will choose whether we need Bit
	 * Rate Switch or not.
	 */ /*
	 * Check for the design
	 * 0 - Sequential Mode
	 * 1 - MailBox Mode.
	 */ /* Configure CAN Device to enter to Loop Back Mode */ /* Send Frame */ /* Receive The Frame */