Lely core libraries
2.3.4
|
Go to the source code of this file.
Functions | |
io_can_ctrl_t * | io_can_ctrl_create_from_name (const char *name, size_t txlen) |
Creates a new CAN controller from an interface name. More... | |
io_can_ctrl_t * | io_can_ctrl_create_from_index (unsigned int index, size_t txlen) |
Creates a new CAN controller from an interface index. More... | |
void | io_can_ctrl_destroy (io_can_ctrl_t *ctrl) |
Destroys a CAN controller. More... | |
const char * | io_can_ctrl_get_name (const io_can_ctrl_t *ctrl) |
Returns the interface name of a CAN controller. | |
unsigned int | io_can_ctrl_get_index (const io_can_ctrl_t *ctrl) |
Returns the interface index of a CAN controller. | |
int | io_can_ctrl_get_flags (const io_can_ctrl_t *ctrl) |
Returns the flags specifying which CAN bus features are enabled. More... | |
io_can_chan_t * | io_can_chan_create (io_poll_t *poll, ev_exec_t *exec, size_t rxlen) |
Creates a new CAN channel. More... | |
void | io_can_chan_destroy (io_can_chan_t *chan) |
Destroys a CAN channel. More... | |
int | io_can_chan_get_handle (const io_can_chan_t *chan) |
Returns the SocketCAN file descriptor associated with a CAN channel, or -1 if the channel is closed. | |
int | io_can_chan_open (io_can_chan_t *chan, const io_can_ctrl_t *ctrl, int flags) |
Opens a CAN channel. More... | |
int | io_can_chan_assign (io_can_chan_t *chan, int fd) |
Assigns an existing SocketCAN file descriptor to a CAN channel. More... | |
int | io_can_chan_release (io_can_chan_t *chan) |
Dissociates and returns the SocketCAN file descriptor from a CAN channel. More... | |
int | io_can_chan_is_open (const io_can_chan_t *chan) |
Returns 1 if the CAN channel is open and 0 if not. More... | |
int | io_can_chan_close (io_can_chan_t *chan) |
Closes the SocketCAN file descriptor associated with a CAN channel. More... | |
This header file is part of the I/O library; it contains the CAN bus declarations for Linux.
This implementation uses the SocketCAN interface.
When the transmit queue of a SocketCAN network interface is full, write()
and send()
operations return ENOBUFS
instead of blocking or returning EAGAIN
. Those operations only block if the per-socket SO_SNDBUF
limit is reached. In order to achieve the expected blocking behavior, this implementation sets the SO_SNDBUF
limit to its minimal value. It is the responsibility of the user to ensure the transmit queue is large enough to prevent ENOBUFS
errors (typically at least 15 times the number of open file descriptors referring to the same network interface, see section 3.4 in https://rtime.felk.cvut.cz/can/socketcan-qdisc-final.pdf).
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file can.h.
io_can_ctrl_t* io_can_ctrl_create_from_name | ( | const char * | name, |
size_t | txlen | ||
) |
Creates a new CAN controller from an interface name.
This function MAY need the CAP_NET_ADMIN capability to set the transmit queue length of the specified SocketCAN interface to at least txlen.
name | the name of a SocketCAN network interface. |
txlen | the transmission queue length (in number of frames) of the network interface. If txlen is 0, the default value LELY_IO_CAN_TXLEN is used. |
Definition at line 138 of file can_ctrl.c.
io_can_ctrl_t* io_can_ctrl_create_from_index | ( | unsigned int | index, |
size_t | txlen | ||
) |
Creates a new CAN controller from an interface index.
This function MAY need the CAP_NET_ADMIN capability to set the transmit queue length of the specified SocketCAN interface to at least txlen.
index | the index of a SocketCAN network interface. |
txlen | the transmission queue length (in number of frames) of the network interface. If txlen is 0, the default value LELY_IO_CAN_TXLEN is used. |
Definition at line 147 of file can_ctrl.c.
void io_can_ctrl_destroy | ( | io_can_ctrl_t * | ctrl | ) |
Destroys a CAN controller.
Definition at line 174 of file can_ctrl.c.
int io_can_ctrl_get_flags | ( | const io_can_ctrl_t * | ctrl | ) |
Returns the flags specifying which CAN bus features are enabled.
Definition at line 199 of file can_ctrl.c.
io_can_chan_t* io_can_chan_create | ( | io_poll_t * | poll, |
ev_exec_t * | exec, | ||
size_t | rxlen | ||
) |
Creates a new CAN channel.
poll | a pointer to the I/O polling instance used to monitor CAN bus events. If NULL, I/O operations MAY cause the event loop to block. |
exec | a pointer to the executor used to execute asynchronous tasks. |
rxlen | the receive queue length (in number of frames) of the CAN channel. If rxlen is 0, the default value LELY_IO_CAN_RXLEN is used. |
Definition at line 382 of file can_chan.c.
void io_can_chan_destroy | ( | io_can_chan_t * | chan | ) |
int io_can_chan_open | ( | io_can_chan_t * | chan, |
const io_can_ctrl_t * | ctrl, | ||
int | flags | ||
) |
Opens a CAN channel.
If the channel was already open, it is first closed as if by io_can_chan_close().
chan | a pointer to a CAN channel. |
ctrl | a pointer to the a controller representing a SocketCAN network interface. |
flags | the flags specifying which CAN bus features MUST be enabled (any combination of IO_CAN_BUS_FLAG_ERR, IO_CAN_BUS_FLAG_FDF and IO_CAN_BUS_FLAG_BRS). |
Definition at line 433 of file can_chan.c.
int io_can_chan_assign | ( | io_can_chan_t * | chan, |
int | fd | ||
) |
Assigns an existing SocketCAN file descriptor to a CAN channel.
Before being assigned, the file descriptor will be modified in the following way:
CAN_RAW_LOOPBACK
and CAN_RAW_RECV_OWN_MSGS
socket options, andIf the channel was already open, it is first closed as if by io_can_chan_close().
Definition at line 503 of file can_chan.c.
int io_can_chan_release | ( | io_can_chan_t * | chan | ) |
Dissociates and returns the SocketCAN file descriptor from a CAN channel.
Any pending read or write operations are canceled as if by io_can_chan_cancel_read() and io_can_chan_cancel_write().
Definition at line 561 of file can_chan.c.
int io_can_chan_is_open | ( | const io_can_chan_t * | chan | ) |
Returns 1 if the CAN channel is open and 0 if not.
This function is equivalent to io_can_chan_get_handle(chan) != -1
.
Definition at line 569 of file can_chan.c.
int io_can_chan_close | ( | io_can_chan_t * | chan | ) |
Closes the SocketCAN file descriptor associated with a CAN channel.
Any pending read or write operations are canceled as if by io_can_chan_cancel_read() and io_can_chan_cancel_write().
Definition at line 575 of file can_chan.c.