Lely core libraries 2.3.4
|
This file is part of the I/O library; it contains the CAN channel implementation for Linux. More...
#include "io.h"
#include "../can.h"
#include <lely/io2/ctx.h>
#include <lely/io2/linux/can.h>
#include <lely/io2/posix/poll.h>
#include <lely/util/diag.h>
#include <lely/util/spscring.h>
#include <lely/util/time.h>
#include <lely/util/util.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <linux/can/raw.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
#include "../posix/fd.h"
#include "can_attr.h"
#include "can_err.h"
#include "can_msg.h"
Go to the source code of this file.
Data Structures | |
struct | io_can_frame |
struct | io_can_chan_impl |
The implementation of a CAN channel. More... | |
Macros | |
#define | LELY_IO_CAN_RXLEN 1024 |
The default SocketCAN receive queue length (in number of CAN frames). | |
Functions | |
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 file is part of the I/O library; it contains the CAN channel implementation for Linux.
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_chan.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.