canmsg_list_t

Message list

Synopsis:

#include <hw/libcan.h>

typedef struct _canmsg_list {
    size_t      len;
    unsigned    nmsg;
    unsigned    msgcnt;
    canmsg_t    *msgs;
    canmsg_t    *head;
    canmsg_t    *tail;
} canmsg_list_t;

Description:

The canmsg_list_t structure lists canmsg_t elements. The libcan resource manager uses it to hold active RX and TX messages, as well as current unused messages. Every time you remove a message from a list, you must re-add it to the same list or add it to a different list. Otherwise, the element becomes unavailable to the driver resulting in a memory leak.

There are separate active messages and free messages lists for each device serviced by the driver.

When receiving messages from hardware, the event_handler() function must either get a message element from the free messages queue or get a message element from the active messages queue to drop the message. Then, the function must populate the fields of the message and enqueue it on the active messages queue for the driver to service the waiting clients. Alternatively, the function can drop the incoming message if no free elements are available.

When transmitting messages to hardware, the transmit() function must get a message from the active message list (if available), forward it to the hardware, and add it back to the free message queue.

The members include:

len

The length of each msg in bytes.

nmsg

The number of message elements pre-allocated in the list.

msgcnt

The number of messages in use. This number wraps to zero after UINT_MAX + 1 messages are added.

msgs

A pointer to the pre-allocated array of canmsg_t instances.

head

A pointer to the first message element.

tail

A pointer to the last message element.

When created, the list preallocates a number of elements. Pointers to these elements can be removed from the list and added to other lists; however, the memory locations remain the same. It's possible to add elements to the list that are dynamically allocated or preallocated in another list.

Page updated: