can: xcan_polled_example.c File Reference

| can Xilinx SDK Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Functions
xcan_polled_example.c File Reference

## Overview

Contains an example of how to use the XCan driver directly.

The example here shows using the driver/device in polled mode.

Note

The Baud Rate Prescaler Register (BRPR) and Bit Timing Register (BTR) are setup such that CAN baud rate equals 40Kbps, assuming that the the CAN clock frequency is 24MHz. The user needs to modify these values based on the desired baud rate and the CAN clock frequency. For more information see the CAN 2.0A, CAN 2.0B, ISO 11898-1 specifications.

    MODIFICATION HISTORY:

    Ver   Who    Date       Changes

    1.00a xd     04/12/05 First release
    2.00a ktn    10/22/09 Updated driver to use the HAL APIs/macros.
                    The macros have been renamed to remove _m from the name.
    3.2   ms     01/23/17 Added xil_printf statement in main function to
                  ensure that "Successfully ran" and "Failed" strings are
                  available in all examples. This is a fix for CR-965028.
    3.3   ask  08/01/18 Fixed Cppcheck and GCC warnings in can driver

## Functions
int | XCanPolledExample (u16 DeviceId)
| The entry point for showing the XCan driver in polled mode. More...
int | main (void)
| Main function to call the example. More...

## Function Documentation

int main | ( | void |  | ) |

Main function to call the example.

This function is not included if the example is generated from the TestAppGen test tool.

Parameters

  None |

Returns
  - XST_SUCCESS if the example has completed successfully.
  - XST_FAILURE if the example has failed.

Note
  None

References XCanPolledExample().

int XCanPolledExample | ( | u16 | DeviceId | ) |

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.

Parameters

  DeviceId | is the XPAR_CAN_<instance_num>_DEVICE_ID value from xparameters.h.

Returns

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.

References XCan_EnterMode(), XCan_GetMode(), XCan_Initialize(), XCAN_MODE_CONFIG, XCAN_MODE_LOOPBACK, XCan_SelfTest(), XCan_SetBaudRatePrescaler(), and XCan_SetBitTiming().

Referenced by main().