Lely core libraries 2.3.4
can.h File Reference

This header file is part of the I/O library; it contains the user-defined CAN channel declarations. More...

#include <lely/io2/can.h>
Include dependency graph for can.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef int io_user_can_chan_write_t(const struct can_msg *msg, int timeout, void *arg)
 The type of function invoked by a user-defined CAN channel when a CAN frame needs to be written. More...
 

Functions

io_can_chan_tio_user_can_chan_create (io_ctx_t *ctx, ev_exec_t *exec, int flags, size_t rxlen, int txtimeo, io_user_can_chan_write_t *func, void *arg)
 Creates a new user-defined CAN channel. More...
 
void io_user_can_chan_destroy (io_can_chan_t *chan)
 Destroys a user-defined CAN channel. More...
 
int io_user_can_chan_on_msg (io_can_chan_t *chan, const struct can_msg *msg, const struct timespec *tp, int timeout)
 Processes an incoming CAN frame. More...
 
int io_user_can_chan_on_err (io_can_chan_t *chan, const struct can_err *err, const struct timespec *tp, int timeout)
 Processes an incoming CAN error frame. More...
 

Detailed Description

This header file is part of the I/O library; it contains the user-defined CAN channel declarations.

The user-defined CAN channel is a passive channel; it does not actively read CAN frames, but requires the user to notify it of incoming (error) frames with io_user_can_chan_on_msg() and io_user_can_chan_on_err(). A user-defined callback function is invoked when a CAN frame needs to be written.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

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.

Typedef Documentation

◆ io_user_can_chan_write_t

typedef int io_user_can_chan_write_t(const struct can_msg *msg, int timeout, void *arg)

The type of function invoked by a user-defined CAN channel when a CAN frame needs to be written.

Parameters
msga pointer to the CAN frame to be written.
argthe user-specific value submitted to io_user_can_chan_create().
timeoutthe maximum number of milliseconds this function SHOULD block. If timeout is negative, this function SHOULD block indefinitely.
Returns
0 on success, or -1 on error. In the latter case, implementations SHOULD set the error number with set_errc() or set_errnum().

Definition at line 50 of file can.h.

Function Documentation

◆ io_user_can_chan_create()

io_can_chan_t * io_user_can_chan_create ( io_ctx_t ctx,
ev_exec_t exec,
int  flags,
size_t  rxlen,
int  txtimeo,
io_user_can_chan_write_t func,
void *  arg 
)

Creates a new user-defined CAN channel.

Parameters
ctxa pointer to the I/O context with which the channel should be registered.
execa pointer to the executor used to execute asynchronous tasks.
flagsthe 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).
rxlenthe receive queue length (in number of frames) of the channel. If rxlen is 0, the default value LELY_IO_USER_CAN_RXLEN is used.
txtimeothe timeout (in milliseconds) passed to func when writing a CAN frame asynchronously. If txtimeo is 0, the default value LELY_IO_TX_TIMEOUT is used. If txtimeo is negative, the write function will wait indefinitely.
funca pointer to the function to be invoked when a CAN frame needs to be written (can be NULL).
argthe user-specific value to be passed as the second argument to func.
Returns
a pointer to a new channel, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 378 of file can.c.

◆ io_user_can_chan_destroy()

void io_user_can_chan_destroy ( io_can_chan_t chan)

Destroys a user-defined CAN channel.

See also
io_user_can_chan_create()

Definition at line 407 of file can.c.

◆ io_user_can_chan_on_msg()

int io_user_can_chan_on_msg ( io_can_chan_t chan,
const struct can_msg msg,
const struct timespec *  tp,
int  timeout 
)

Processes an incoming CAN frame.

Parameters
chana pointer to a user-defined CAN channel.
msga pointer to the incoming CAN frame.
tpa pointer to the system time at which the CAN frame was received (can be NULL).
timeoutthe maximum number of milliseconds this function will block when the receive queue is full. If timeout is negative, this function will block indefinitely.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 416 of file can.c.

◆ io_user_can_chan_on_err()

int io_user_can_chan_on_err ( io_can_chan_t chan,
const struct can_err err,
const struct timespec *  tp,
int  timeout 
)

Processes an incoming CAN error frame.

Parameters
chana pointer to a user-defined CAN channel.
erra pointer to the incoming CAN error frame.
tpa pointer to the system time at which the CAN error frame was received (can be NULL).
timeoutthe maximum number of milliseconds this function will block when the receive queue is full. If timeout is negative, this function will block indefinitely.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 441 of file can.c.