1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-26 15:03:53 +01:00
Gilles DOFFE ae51a22fbb can: use frame len instead of can_dlc
RIOT implementation of CAN bus relies on SocketCAN model.
Since commit c398e56 (can: add optional DLC element to Classical CAN
frame structure), '__u8 can_dlc' attribute of struct can_frame is
considered as deprecated in SocketCAN and kept for legacy support.
Attribute '__u8 len' should be used instead.

	union {
		/* CAN frame payload length in byte (0 .. CAN_MAX_DLEN)
		 * was previously named can_dlc so we need to carry that
		 * name for legacy support
		 */
		__u8 len;
		__u8 can_dlc; /* deprecated */
	};

Moreover, CAN FD frame structure does not support legacy attribute
'can_dlc', making 'len' mandatory for incoming CAN FD support in RIOT.

	struct canfd_frame {
		canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
		__u8    len;     /* frame payload length in byte */
		__u8    flags;   /* additional flags for CAN FD */
		__u8    __res0;  /* reserved / padding */
		__u8    __res1;  /* reserved / padding */
		__u8    data[CANFD_MAX_DLEN]
__attribute__((aligned(8)));
	};

Signed-off-by: Gilles DOFFE <gilles.doffe@rtone.fr>
2025-01-29 20:51:22 +01:00
..
2025-01-29 20:51:22 +01:00
2023-05-12 14:24:40 +02:00

candev test application

About

This application is a test for using the candev abstraction directly. Use this if you want to use a single CAN driver and thus don't need the CAN-DLL layer.

The CAN_DRIVER variable is used to select the default CAN_DRIVER, supported alternatives are:

  • MCP2515 to use mcp2515 stand-alone CAN controller
  • PERIPH_CAN to use periph_can controller, usually requires a CAN transceiver as well: e.g. tja1042 or ncv7356 (except for native)

Usage

Sending

Messages can be sent over the CAN-bus through the send command. Optionally, up to 8 bytes can be passed as arguments (in decimal form). If no arguments are passed it will default to sending AB CD EF (hex).

> send <bytes>
# e.g.: send AA BB CC
> send 170 187 204
send 170 187 204

Receiving

The test-app is always listening for incoming CAN messages. They will be stored asynchronously in a buffer and can be requested by means of the receive command. Optionally, an argument n can be passed to receive n messages in a row.

> receive <n>
# e.g.:
> receive 2
Reading from Rxbuf...
id: 1 dlc: 3 Data:
0xAA 0xBB 0xCC
Reading from Rxbuf...
id: 1 dlc: 3 Data:
0xAA 0xBB 0xCC

Native Setup

Refer to README.native.can.md.