can_loopback example

The example demonstrates use of the CAN (Controller Area Network) driver on the Radxa ROCK 3A hardware platform when there is no need to connect additional peripherals in the form of CAN transceivers.

Example directory in the SDK

The code of the example and build scripts are available at the following path:

/opt/KasperskyOS-Community-Edition-<platform>-<version>/examples/can_loopback

List of programs

When you build an example for the target hardware platform, platform-specific drivers are automatically included in the solution:

Initialization description

The solution initialization description file named init.yaml is generated during the solution build process based on the ./einit/src/init.yaml.in template. Macros in @INIT_*@‌ ‌format contained in the template are automatically expanded in the resulting init.yaml file. For more details, refer to init.yaml.in template.

Security policy description

The security.psl file contains a description of a security policy for a KasperskyOS-based solution and is located in the ./einit/src directory. The declarations in the PSL file are provided with comments that explain the purpose of these declarations.

The security.psl file is a top-level file that includes a part of the solution security policy description in the form of a PSL file dynld.psl via the use declaration. The dynld.psl file contains the security policy description that is used when dynamically linking the solution components. The declarations in the PSL files are provided with comments that explain the purpose of these declarations.

Resources

The ./resources/xdl/client directory contains the CanClient.edl file, which is the EDL description for the CanClient program.

Operating scenario

The CanClient program performs the following actions:

  1. Initializes the CAN driver.
  2. Opens the CAN interface can0 with the CAN_FLAGS_LOOPBACK internal cycle mode enabled and the baud rate specified by the CAN_BR_800KBS constant. (The CAN driver can also support the names can1 and can2.)

    The example uses the Classical CAN mode, which establish a baud rate limit of 1 MB/s. When setting the baud rate, the following constants are supported:

    • CAN_BR_1MBS
    • CAN_BR_800KBS
    • CAN_BR_500KBS
    • CAN_BR_250KBS
    • CAN_BR_125KBS
    • CAN_BR_62_5KBS

    In addition to the Classical CAN mode, the driver supports the CAN FD (Controller Area Network Flexible Data-Rate) mode. To enable CAN FD mode, the CAN_FLAGS_FD flag must be passed to the CAN port open function. 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
  3. Generates the test CAN packet that contains the packet 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 CAN FD.
  4. Transmits a prepared CAN packet via the same can0 interface and waits 5000 ms for it to be received via the can0 interface.
  5. Compares the received CAN packet with the sent packet to verify that the ID, length of the data field and all data bytes match.
  6. Closes the CAN interfaces and terminates with the EXIT_SUCCESS code upon successful completion of all operations, or shows the EXIT_FAILURE code if errors occurred.

Building and running the example

The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.

This example is intended to run only on Radxa ROCK 3A.

See Building and running examples section.

Page top