Lely core libraries  2.3.4
can.h File Reference

This header file is part of the I/O library; it contains the Controller Area Network (CAN) declarations. More...

#include <lely/io/io.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.

Functions

io_handle_t io_open_can (const char *path)
 Opens a CAN device. More...
 
int io_can_read (io_handle_t handle, struct can_msg *msg)
 Reads a single CAN or CAN FD frame. More...
 
int io_can_write (io_handle_t handle, const struct can_msg *msg)
 Writes a single CAN or CAN FD frame. More...
 
int io_can_start (io_handle_t handle)
 Starts transmission and reception on a CAN device. More...
 
int io_can_stop (io_handle_t handle)
 Stops transmission and reception on a CAN device. More...
 
int io_can_get_state (io_handle_t handle)
 Obtains the state of a CAN device. More...
 
int io_can_get_error (io_handle_t handle, int *perror)
 Obtains and clears the current error number of a CAN device, and stores the value (any combination of CAN_ERROR_BIT, CAN_ERROR_STUFF, CAN_ERROR_CRC, CAN_ERROR_FORM and CAN_ERROR_ACK) in *perror. More...
 
int io_can_get_ec (io_handle_t handle, uint16_t *ptxec, uint16_t *prxec)
 Obtains the transmit and/or receive error count of a CAN device and stores the value in *ptxec and/or *prxec. More...
 
int io_can_get_bitrate (io_handle_t handle, uint32_t *pbitrate)
 Obtains the bitrate (in bit/s) of a CAN device and stores the value in *pbitrate. More...
 
int io_can_set_bitrate (io_handle_t handle, uint32_t bitrate)
 Sets the bitrate (in bit/s) of a CAN device. More...
 
int io_can_get_txqlen (io_handle_t handle, size_t *ptxqlen)
 Obtains the length of the transmission queue (in number of CAN frames) of a CAN device and stores the value in *ptxqlen. More...
 
int io_can_set_txqlen (io_handle_t handle, size_t txqlen)
 Sets the length of the transmission queue (in number of CAN frames) of a CAN device. More...
 

Detailed Description

This header file is part of the I/O library; it contains the Controller Area Network (CAN) declarations.

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.

Function Documentation

◆ io_open_can()

io_handle_t io_open_can ( const char *  path)

Opens a CAN device.

Parameters
paththe (platform dependent) path (or interface) name of the device.
Returns
a new I/O device handle, or IO_HANDLE_ERROR on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 111 of file can.c.

◆ io_can_read()

int io_can_read ( io_handle_t  handle,
struct can_msg msg 
)

Reads a single CAN or CAN FD frame.

Parameters
handlea valid CAN device handle.
msgthe address at which to store the received frame.
Returns
the number of frames received (at most 1), or -1 on error. In the latter case, the error number can be obtained with get_errc(). In case of an I/O error (ERRNUM_IO), the CAN device state and error can be obtained with io_can_get_state() and io_can_get_error(), respectively.

Definition at line 218 of file can.c.

◆ io_can_write()

int io_can_write ( io_handle_t  handle,
const struct can_msg msg 
)

Writes a single CAN or CAN FD frame.

Parameters
handlea valid CAN device handle.
msga pointer to the frame to be written.
Returns
the number of frames sent (at most 1), or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 276 of file can.c.

◆ io_can_start()

int io_can_start ( io_handle_t  handle)

Starts transmission and reception on a CAN device.

On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.

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_stop()

Definition at line 322 of file can.c.

◆ io_can_stop()

int io_can_stop ( io_handle_t  handle)

Stops transmission and reception on a CAN device.

On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.

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_start()

Definition at line 354 of file can.c.

◆ io_can_get_state()

int io_can_get_state ( io_handle_t  handle)

Obtains the state of a CAN device.

Returns
CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 388 of file can.c.

◆ io_can_get_error()

int io_can_get_error ( io_handle_t  handle,
int *  perror 
)

Obtains and clears the current error number of a CAN device, and stores the value (any combination of CAN_ERROR_BIT, CAN_ERROR_STUFF, CAN_ERROR_CRC, CAN_ERROR_FORM and CAN_ERROR_ACK) in *perror.

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

Definition at line 436 of file can.c.

◆ io_can_get_ec()

int io_can_get_ec ( io_handle_t  handle,
uint16_t *  ptxec,
uint16_t *  prxec 
)

Obtains the transmit and/or receive error count of a CAN device and stores the value in *ptxec and/or *prxec.

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

Definition at line 458 of file can.c.

◆ io_can_get_bitrate()

int io_can_get_bitrate ( io_handle_t  handle,
uint32_t *  pbitrate 
)

Obtains the bitrate (in bit/s) of a CAN device and stores the value in *pbitrate.

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_set_bitrate()

Definition at line 498 of file can.c.

◆ io_can_set_bitrate()

int io_can_set_bitrate ( io_handle_t  handle,
uint32_t  bitrate 
)

Sets the bitrate (in bit/s) of a CAN device.

Note that not all bitrates are supported on every CAN controller. Standard bitrates are 10 kbit/s, 20 kbit/s, 50 kbit/s, 125 kbit/s, 250 kbit/s, 500 kbit/s, 800 kbit/s and 1 Mbit/s. On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.

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_get_bitrate()

Definition at line 536 of file can.c.

◆ io_can_get_txqlen()

int io_can_get_txqlen ( io_handle_t  handle,
size_t *  ptxqlen 
)

Obtains the length of the transmission queue (in number of CAN frames) of a CAN device and stores the value in *ptxqlen.

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_set_txqlen()

Definition at line 589 of file can.c.

◆ io_can_set_txqlen()

int io_can_set_txqlen ( io_handle_t  handle,
size_t  txqlen 
)

Sets the length of the transmission queue (in number of CAN frames) of a CAN device.

On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.

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_get_txqlen()

Definition at line 626 of file can.c.