Lely core libraries  2.2.5
can_net.h File Reference
#include <lely/io2/can.h>
#include <lely/io2/tqueue.h>
Include dependency graph for can_net.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct io_can_net io_can_net_t
 A CAN network interface.
 
typedef void io_can_net_on_error_func_t(int errc, size_t errcnt, void *arg)
 The type of function invoked when an error occurs during a CAN network interface operations, or when the operation completes successfully after one or more errors. More...
 
typedef void io_can_net_on_can_state_func_t(int new_state, int old_state, void *arg)
 The type of function invoked when a CAN bus state change is detected by a CAN network interface. More...
 
typedef void io_can_net_on_can_error_func_t(int error, void *arg)
 The type of function invoked when a CAN bus error is detected by an CAN network interface. More...
 

Functions

io_can_net_tio_can_net_create (ev_exec_t *exec, io_timer_t *timer, io_can_chan_t *chan, size_t txlen, int txtimeo)
 Creates a new CAN network interface. More...
 
void io_can_net_destroy (io_can_net_t *net)
 Destroys a CAN network interface.
 
void io_can_net_start (io_can_net_t *net)
 Starts a CAN network interface and begins processing CAN frames. More...
 
io_ctx_tio_can_net_get_ctx (const io_can_net_t *net)
 Returns a pointer to the I/O context with which the CAN network interface is registered.
 
ev_exec_tio_can_net_get_exec (const io_can_net_t *net)
 Returns a pointer to the executor used by the CAN network interface to execute asynchronous tasks.
 
io_clock_tio_can_net_get_clock (const io_can_net_t *net)
 Returns a pointer to the clock used by the CAN network interface.
 
io_tqueue_tio_can_net_get_tqueue (const io_can_net_t *net)
 Returns a pointer to the internal timer queue of a CAN network interface.
 
void io_can_net_get_on_read_error_func (const io_can_net_t *net, io_can_net_on_error_func_t **pfunc, void **parg)
 Retrieves the function invoked when a new CAN frame read error occurs, or when a read operation completes successfully after one or more errors. More...
 
void io_can_net_set_on_read_error_func (io_can_net_t *net, io_can_net_on_error_func_t *func, void *arg)
 Sets the function invoked when a new CAN frame read error occurs, or when a read operation completes successfully after one or more errors. More...
 
void io_can_net_get_on_queue_error_func (const io_can_net_t *net, io_can_net_on_error_func_t **pfunc, void **parg)
 Retrieves the function invoked when a CAN frame is dropped because the transmit queue is full, or when a frame is successfully queued after one or more errors. More...
 
void io_can_net_set_on_queue_error_func (io_can_net_t *net, io_can_net_on_error_func_t *func, void *arg)
 Sets the function invoked when a CAN frame is dropped because the transmit queue is full, or when a frame is successfully queued after one or more errors. More...
 
void io_can_net_get_on_write_error_func (const io_can_net_t *net, io_can_net_on_error_func_t **pfunc, void **parg)
 Retrieves the function invoked when a new CAN frame write error occurs, or when a write operation completes successfully after one or more errors. More...
 
void io_can_net_set_on_write_error_func (io_can_net_t *net, io_can_net_on_error_func_t *func, void *arg)
 Sets the function invoked when a new CAN frame write error occurs, or when a write operation completes successfully after one or more errors. More...
 
void io_can_net_get_on_can_state_func (const io_can_net_t *net, io_can_net_on_can_state_func_t **pfunc, void **parg)
 Retrieves the function invoked when a CAN bus state change is detected. More...
 
void io_can_net_set_on_can_state_func (io_can_net_t *net, io_can_net_on_can_state_func_t *func, void *arg)
 Sets the function to be invoked when a CAN bus state change is detected. More...
 
void io_can_net_get_on_can_error_func (const io_can_net_t *net, io_can_net_on_can_error_func_t **pfunc, void **parg)
 Retrieves the function invoked when a CAN bus error is detected. More...
 
void io_can_net_set_on_can_error_func (io_can_net_t *net, io_can_net_on_can_error_func_t *func, void *arg)
 Sets the function to be invoked when a CAN bus error is detected. More...
 
int io_can_net_lock (io_can_net_t *net)
 Locks the mutex protecting the CAN network interface. More...
 
int io_can_net_unlock (io_can_net_t *net)
 Unlocks the mutex protecting the CAN network interface. More...
 
struct __can_netio_can_net_get_net (const io_can_net_t *net)
 Returns a pointer to the internal interface of a CAN network interface. More...
 
int io_can_net_set_time (io_can_net_t *net)
 Updates the CAN network time. More...
 

Detailed Description

This header file is part of the I/O library; it contains the CAN network interface declarations.

This interface couples a timer and CAN channel to the internal CAN network interface of the CAN library. It provides notifications of CAN bus state changes and I/O errors through user-defined callbacks. CAN frames sent through this interface are first put in a user-space transmit queue before being sent to the underlying CAN channel.

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_net.h.

Typedef Documentation

◆ io_can_net_on_error_func_t

typedef void io_can_net_on_error_func_t(int errc, size_t errcnt, void *arg)

The type of function invoked when an error occurs during a CAN network interface operations, or when the operation completes successfully after one or more errors.

The default implementation prints a warning or informational message with diag().

Parameters
errcthe error code (0 on success).
errcntthe number of errors since the last successful operation.
argthe user-specifed argument.

Definition at line 62 of file can_net.h.

◆ io_can_net_on_can_state_func_t

typedef void io_can_net_on_can_state_func_t(int new_state, int old_state, void *arg)

The type of function invoked when a CAN bus state change is detected by a CAN network interface.

The state is represented by one the CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, CAN_STATE_SLEEPING or CAN_STATE_STOPPED values. The default implementation prints a warning or informational message with diag().

The mutex protecting the CAN network interface will be locked when this function is called.

Parameters
new_statethe current state of the CAN bus (CAN_STATE_ACTIVE, CAN_STATE_PASSIVE or CAN_STATE_BUSOFF).
old_statethe previous state of the CAN bus (CAN_STATE_ACTIVE, CAN_STATE_PASSIVE or CAN_STATE_BUSOFF).
argthe user-specifed argument.

Definition at line 80 of file can_net.h.

◆ io_can_net_on_can_error_func_t

typedef void io_can_net_on_can_error_func_t(int error, void *arg)

The type of function invoked when a CAN bus error is detected by an CAN network interface.

The default implementation prints a warning with diag().

The mutex protecting the CAN network interface will be locked when this function is called.

Parameters
errorthe detected errors (any combination of CAN_ERROR_BIT, CAN_ERROR_STUFF, CAN_ERROR_CRC, CAN_ERROR_FORM, CAN_ERROR_ACK and CAN_ERROR_OTHER).
argthe user-specifed argument.

Definition at line 95 of file can_net.h.

Function Documentation

◆ io_can_net_create()

io_can_net_t* io_can_net_create ( ev_exec_t exec,
io_timer_t timer,
io_can_chan_t chan,
size_t  txlen,
int  txtimeo 
)

Creates a new CAN network interface.

Parameters
execa pointer to the executor used to execute asynchronous tasks. If exec is NULL, the CAN channel executor is used.
timera pointer to a timer. This timer MUST NOT be used for any other purpose.
chana pointer to a CAN channel. This channel MUST NOT be used for any other purpose.
txlenthe length (in number of frames) of the user-space transmit queue length. If txlen is 0, the default value LELY_IO_CAN_NET_TXLEN is used.
txtimeothe timeout (in milliseconds) when waiting for a CAN frame write confirmation. If txtimeo is 0, the default value #LELY_IO_CAN_CTX_TXTIMEO is used. If txtimeo is negative. the timeout is disabled.
Returns
a pointer to a new CAN network interface, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 377 of file can_net.c.

◆ io_can_net_start()

void io_can_net_start ( io_can_net_t net)

Starts a CAN network interface and begins processing CAN frames.

This function locks the mutex protecting the CAN network interface.

Definition at line 415 of file can_net.c.

◆ io_can_net_get_on_read_error_func()

void io_can_net_get_on_read_error_func ( const io_can_net_t net,
io_can_net_on_error_func_t **  pfunc,
void **  parg 
)

Retrieves the function invoked when a new CAN frame read error occurs, or when a read operation completes successfully after one or more errors.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the function (can be NULL).
pargthe address at which to store the user-specified argument (can be NULL).
See also
io_can_net_set_on_read_error_func()

Definition at line 472 of file can_net.c.

◆ io_can_net_set_on_read_error_func()

void io_can_net_set_on_read_error_func ( io_can_net_t net,
io_can_net_on_error_func_t func,
void *  arg 
)

Sets the function invoked when a new CAN frame read error occurs, or when a read operation completes successfully after one or more errors.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked. If func is NULL, the default implementation will be used.
argthe user-specified argument (can be NULL). arg is passed as the last argument to func.
See also
io_can_net_get_on_read_error_func()

Definition at line 490 of file can_net.c.

◆ io_can_net_get_on_queue_error_func()

void io_can_net_get_on_queue_error_func ( const io_can_net_t net,
io_can_net_on_error_func_t **  pfunc,
void **  parg 
)

Retrieves the function invoked when a CAN frame is dropped because the transmit queue is full, or when a frame is successfully queued after one or more errors.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the function (can be NULL).
pargthe address at which to store the user-specified argument (can be NULL).
See also
io_can_net_set_on_queue_error_func()

Definition at line 506 of file can_net.c.

◆ io_can_net_set_on_queue_error_func()

void io_can_net_set_on_queue_error_func ( io_can_net_t net,
io_can_net_on_error_func_t func,
void *  arg 
)

Sets the function invoked when a CAN frame is dropped because the transmit queue is full, or when a frame is successfully queued after one or more errors.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked. If func is NULL, the default implementation will be used.
argthe user-specified argument (can be NULL). arg is passed as the last argument to func.
See also
io_can_net_get_on_queue_error_func()

Definition at line 524 of file can_net.c.

◆ io_can_net_get_on_write_error_func()

void io_can_net_get_on_write_error_func ( const io_can_net_t net,
io_can_net_on_error_func_t **  pfunc,
void **  parg 
)

Retrieves the function invoked when a new CAN frame write error occurs, or when a write operation completes successfully after one or more errors.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the function (can be NULL).
pargthe address at which to store the user-specified argument (can be NULL).
See also
io_can_net_set_on_write_error_func()

Definition at line 540 of file can_net.c.

◆ io_can_net_set_on_write_error_func()

void io_can_net_set_on_write_error_func ( io_can_net_t net,
io_can_net_on_error_func_t func,
void *  arg 
)

Sets the function invoked when a new CAN frame write error occurs, or when a write operation completes successfully after one or more errors.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked. If func is NULL, the default implementation will be used.
argthe user-specified argument (can be NULL). arg is passed as the last argument to func.
See also
io_can_net_get_on_write_error_func()

Definition at line 558 of file can_net.c.

◆ io_can_net_get_on_can_state_func()

void io_can_net_get_on_can_state_func ( const io_can_net_t net,
io_can_net_on_can_state_func_t **  pfunc,
void **  parg 
)

Retrieves the function invoked when a CAN bus state change is detected.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the function (can be NULL).
pargthe address at which to store the user-specified argument (can be NULL).
See also
io_can_net_set_on_can_state_func()

Definition at line 574 of file can_net.c.

◆ io_can_net_set_on_can_state_func()

void io_can_net_set_on_can_state_func ( io_can_net_t net,
io_can_net_on_can_state_func_t func,
void *  arg 
)

Sets the function to be invoked when a CAN bus state change is detected.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked. If func is NULL, the default implementation will be used.
argthe user-specified argument (can be NULL). arg is passed as the last argument to func.
See also
io_can_net_get_on_can_state_func()

Definition at line 592 of file can_net.c.

◆ io_can_net_get_on_can_error_func()

void io_can_net_get_on_can_error_func ( const io_can_net_t net,
io_can_net_on_can_error_func_t **  pfunc,
void **  parg 
)

Retrieves the function invoked when a CAN bus error is detected.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the function (can be NULL).
pargthe address at which to store the user-specified argument (can be NULL).
See also
io_can_net_set_on_can_error_func()

Definition at line 608 of file can_net.c.

◆ io_can_net_set_on_can_error_func()

void io_can_net_set_on_can_error_func ( io_can_net_t net,
io_can_net_on_can_error_func_t func,
void *  arg 
)

Sets the function to be invoked when a CAN bus error is detected.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked. If func is NULL, the default implementation will be used.
argthe user-specified argument (can be NULL). arg is passed as the last argument to func.
See also
io_can_net_get_on_can_error_func()

Definition at line 626 of file can_net.c.

◆ io_can_net_lock()

int io_can_net_lock ( io_can_net_t net)

Locks the mutex protecting the CAN network interface.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc();
See also
io_can_net_unlock()

Definition at line 642 of file can_net.c.

◆ io_can_net_unlock()

int io_can_net_unlock ( io_can_net_t net)

Unlocks the mutex protecting the CAN network interface.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc();
See also
io_can_net_lock()

Definition at line 656 of file can_net.c.

◆ io_can_net_get_net()

struct __can_net* io_can_net_get_net ( const io_can_net_t net)

Returns a pointer to the internal interface of a CAN network interface.

The mutex protecting the CAN network interface MUST be locked when using the internal interface.

See also
io_can_net_lock(), io_can_net_unlock()

Definition at line 671 of file can_net.c.

◆ io_can_net_set_time()

int io_can_net_set_time ( io_can_net_t net)

Updates the CAN network time.

The mutex protecting the CAN network interface MUST be locked for the duration of this call.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
io_can_net_lock(), io_can_net_unlock()

Definition at line 679 of file can_net.c.