Example use of the CAN driver.
This example demonstrates use of the CAN driver when there is no need to connect an additional peripheral device for CAN transceivers. In the example, the CAN port is configured and then a CAN packet is sent. The received CAN packet is checked to make sure that it matches the sent packet.
The CAN interface named can0
is used to configure the port, and the pointer to the port name is assigned via the CanPortName
variable. The CAN driver also supports the names can1
and can2
, which can be used in the test application.
The CAN driver supports multiple operating modes and may work in Classical CAN mode or CANFD mode. CANFD mode is indicated by the CAN_FLAGS_FD
flag, which is passed to the function for opening the CAN port of the test example. If the CAN_FLAGS_FD
flag is absent from the settings for opening the port, Classical CAN mode will be used with the corresponding speed limitations.
In the example, the port is opened with a set transfer rate of 800 KBps. The constant CAN_BR_800KBS
is used for this purpose.
When using the CAN_FLAGS_FD
flag, the following data transfer rate constants are supported:
CANFD_BR_500KBS_D_2MBS
CANFD_BR_500KBS_D_2_5MBS
CANFD_BR_1MBS_D_2MBS
CAN_BR_1MBS
CAN_BR_800KBS
CAN_BR_500KBS
CAN_BR_250KBS
CAN_BR_125KBS
CAN_BR_62_5KBS
Classical CAN mode cannot use speeds higher than 1 MBps, therefore only the following constants can be used to configure the transfer rate if the CAN_FLAGS_FD
flag is absent:
CAN_BR_1MBS
CAN_BR_800KBS
CAN_BR_500KBS
CAN_BR_250KBS
CAN_BR_125KBS
CAN_BR_62_5KBS
The CAN test packet contains the ID, length of the data field, and the data. A description of the fields is provided in the CanFrame
structure. The length of the data field is limited to 8 bytes for Classical CAN, while the length is limited to 64 bytes for CANFD.
Example files
The code of the example and build scripts are available at the following path:
/opt/KasperskyOS-Community-Edition-<version>/examples/can_loopback
Building and running the example
This example is intended to run only on Radxa ROCK 3A.
If you build and run this example in QEMU, an error will occur. This is the expected behavior, because there is no CAN driver for QEMU.
See Building and running examples section.
Page top