RT-Thread RTOS
An open source embedded real-time operating system
rt_can_ops Struct Reference

#include <dev_can.h>

Data Fields

rt_err_t(* configure )(struct rt_can_device *can, struct can_configure *cfg)
 
rt_err_t(* control )(struct rt_can_device *can, int cmd, void *arg)
 
rt_ssize_t(* sendmsg )(struct rt_can_device *can, const void *buf, rt_uint32_t boxno)
 
rt_ssize_t(* recvmsg )(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
 
rt_ssize_t(* sendmsg_nonblocking )(struct rt_can_device *can, const void *buf)
 

Detailed Description

The CAN device driver operations structure.

This structure contains pointers to the low-level functions that implement the CAN functionality. It must be provided when registering a CAN device.

Field Documentation

◆ configure

rt_err_t(* rt_can_ops::configure) (struct rt_can_device *can, struct can_configure *cfg)

Configures the CAN controller with the specified settings.

Parameters
[in]canA pointer to the CAN device structure.
[in]cfgA pointer to the configuration structure.
Returns
RT_EOK on success, or a negative error code on failure.

◆ control

rt_err_t(* rt_can_ops::control) (struct rt_can_device *can, int cmd, void *arg)

Sends control commands to the CAN device.

Parameters
[in]canA pointer to the CAN device structure.
[in]cmdThe control command (e.g., RT_CAN_CMD_SET_FILTER).
[in]argA pointer to the arguments for the command.
Returns
RT_EOK on success, or a negative error code on failure.

◆ sendmsg

rt_ssize_t(* rt_can_ops::sendmsg) (struct rt_can_device *can, const void *buf, rt_uint32_t boxno)

Low-level blocking function to send a CAN message.

Parameters
[in]canA pointer to the CAN device structure.
[in]bufA pointer to the rt_can_msg to be sent.
[in]boxnoThe hardware mailbox number to use for transmission.
Returns
The number of bytes sent on success, or a negative error code on failure.

◆ recvmsg

rt_ssize_t(* rt_can_ops::recvmsg) (struct rt_can_device *can, void *buf, rt_uint32_t fifo)

Low-level function to receive a CAN message.

Parameters
[in,out]canA pointer to the CAN device structure.
[out]bufA pointer to the buffer to store the received rt_can_msg.
[in]fifoThe hardware FIFO number to read from.
Returns
The number of bytes received on success, or a negative error code on failure.

◆ sendmsg_nonblocking

rt_ssize_t(* rt_can_ops::sendmsg_nonblocking) (struct rt_can_device *can, const void *buf)

Low-level, hardware-specific function to send a CAN message non-blockingly.

This function attempts to place a message into a hardware transmission mailbox and returns immediately without waiting for the transmission to complete.

Parameters
[in]canA pointer to the CAN device structure.
[in]bufA pointer to the rt_can_msg to be sent.
Returns
  • RT_EOK if the message was successfully accepted by the hardware.
  • -RT_EBUSY if all hardware mailboxes are currently full.
  • Other negative error codes for different failures.