CANDEV

Generic CAN device structure

Synopsis:

#include <hw/libcan.h>
#include <sys/can_dcmd.h>
#include <sys/iofunc.h>
#include <sys/siginfo.h>

typedef struct can_dev_entry
{
    iofunc_attr_t   attr;
    iofunc_mount_t  mount;
    CANDEV_TYPE     devtype;
    int             can_unit;
    int             dev_unit;
    CANDEV_MODE     mode;
    canmsg_list_t   *free_queue;
    canmsg_list_t   *msg_queue;
    int             rsmid;
    uint32_t        cflags;
    struct sigevent event;
    CLIENTWAITQ     *wait_free_queue;
    CLIENTWAITQ     *wait_client_queue;
} CANDEV;

Description:

The CANDEV structure represents an initialized CAN device. The CAN resource manager uses this information to facilitate communication with clients.

The members include:

attr

The data and state associated with the individual CAN service offered by the CAN resource manager.

Initialized by libcan during RX/TX device creation; based on devtype.

mount

Data managed by libcan.

devtype

The CAN device type; CANDEV_TYPE_RX (receiver) or CANDEV_TYPE_TX (transmitter).

Initialized by libcan during RX/TX device initialization; copied from the CANDEV_INIT structure.

can_unit

The CAN unit number. Corresponds to the X in the /dev/canX/rxY path.

Initialized by libcan during RX/TX device initialization; copied from the CANDEV_INIT structure.

dev_unit

The device unit number. Corresponds to the Y in the /dev/canX/rxY path.

Initialized by libcan during RX/TX device initialization; copied from the CANDEV_INIT structure.

mode

The CAN driver mode; CANDEV_MODE_IO (I/O) or CANDEV_MODE_RAW_FRAME (raw frames).

Initialized by libcan during RX/TX device initialization; copied from CANDEV_INIT structure.

free_queue

The free element queue; a pointer to the canmsg_list_t instance.

When receiving messages, event_handler() must dequeue an entry from this queue, fill it with data, and add it to the msg_queue queue. If the queue is empty, the driver can drop the oldest message in the msg_queue by removing it, filling it with new data, and adding it back to the msg_queue queue.

After a message is transmitted, you must add the entry back to the free_queue.

Allocated by libcan during device initialization, with the number of elements specified in the CANDEV_INIT structure.

msg_queue

The active TX or RX queue; a pointer to the canmsg_list_t instance. When transmitting, dequeue messages from this queue. When receiving, add messages to this queue.

Allocated by libcan during device initialization with no elements.

This member uses elements originally allocated for free_queue.

rsmid

The resource manager link ID.

Initialized by libcan during device initialization and creation and used during device clean up.

cflags

CAN device flags. Setting bit 31 to:

  • 0 — indicates a standard CAN message.
  • 1 — indicates a CAN FD message.

The resource manager uses this member when reading and writing data using the read() and write() functions.

The cflags member can be set by the driver implementation at any time.

event

Data that libcan manages.

wait_free_queue

Free elements in the client wait queue; a pointer to the CLIENTWAITQ instance.

Allocated by libcan during device initialization, with the number of elements specified in CANDEV_INIT structure.

wait_client_queue

Queue of blocked clients waiting for a response from the driver; a pointer to the CLIENTWAITQ instance.

Allocated by libcan during device initialization with no elements.

This member uses elements originally allocated for wait_free_queue.

The only member that should be directly modified by the implementation is cflags to control the read/write message size; specify 8 bytes for standard CAN and 64 bytes for CAN FD.

The free_queue and msg_queue instances must be manipulated using the cansmsg_dequeue_element() and canmsg_queue_element() functions when receiving and transmitting CAN messages.

The devtype, mode, can_unit, and dev_unit members are copied from the CANDEV_INIT instance passed to the can_resmgr_init_device() function and shouldn't be modified.

All other members are initialized and managed by libcan and must not be modified by the implementation.

Page updated: