Lely core libraries  2.3.4
can.c File Reference
#include "../can.h"
#include <lely/libc/threads.h>
#include <lely/io2/ctx.h>
#include <lely/io2/user/can.h>
#include <lely/util/diag.h>
#include <lely/util/errnum.h>
#include <lely/util/spscring.h>
#include <lely/util/time.h>
#include <lely/util/util.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for can.c:

Go to the source code of this file.

Data Structures

struct  io_user_can_frame
 
struct  io_user_can_chan
 The implementation of a user-defined CAN channel. More...
 

Macros

#define LELY_IO_USER_CAN_RXLEN   1024
 The default receive queue length (in number of CAN frames) of the user-defined CAN channel.
 

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 file is part of the I/O library; it contains the implementation of the user-defined CAN channel.

See also
lely/io2/user/can.h
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 useried. See the License for the specific language governing permissions and limitations under the License.

Definition in file can.c.

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.