Lely core libraries
2.2.5
|
This header file is part of the I/O library; it contains the virtual CAN bus declarations. More...
Go to the source code of this file.
Functions | |
io_can_ctrl_t * | io_vcan_ctrl_create (io_clock_t *clock, int flags, int nominal, int data, int state) |
Creates a new virtual CAN controller. More... | |
void | io_vcan_ctrl_destroy (io_can_ctrl_t *ctrl) |
Destroys a virtual CAN controller. More... | |
void | io_vcan_ctrl_set_state (io_can_ctrl_t *ctrl, int state) |
Sets the state of a virtual CAN bus: one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, CAN_STATE_SLEEPING or CAN_STATE_STOPPED. More... | |
int | io_vcan_ctrl_write_msg (io_can_ctrl_t *ctrl, const struct can_msg *msg, int timeout) |
Writes a CAN frame to a all virtual CAN channels registered with a virtual CAN controller. More... | |
int | io_vcan_ctrl_write_err (io_can_ctrl_t *ctrl, const struct can_err *err, int timeout) |
Writes a CAN error frame to a all virtual CAN channels registered with a virtual CAN controller. More... | |
io_can_chan_t * | io_vcan_chan_create (io_ctx_t *ctx, ev_exec_t *exec, size_t rxlen) |
Creates a new virtual CAN channel. More... | |
void | io_vcan_chan_destroy (io_can_chan_t *chan) |
Destroys a virtual CAN channel. More... | |
io_can_ctrl_t * | io_vcan_chan_get_ctrl (const io_can_chan_t *chan) |
Returns a pointer to the virtual CAN controller with which a virtual CAN channel is registered, or NULL if the channel is closed. | |
void | io_vcan_chan_open (io_can_chan_t *chan, io_can_ctrl_t *ctrl) |
Opens a virtual CAN channel by registering it with the specified virtual CAN controller. More... | |
int | io_vcan_chan_is_open (const io_can_chan_t *chan) |
Returns 1 if the CAN channel is open and 0 if not. More... | |
void | io_vcan_chan_close (io_can_chan_t *chan) |
Closes a virtual CAN channel. More... | |
This header file is part of the I/O library; it contains the virtual CAN bus declarations.
A virtual CAN bus makes it possible to write platform-independent tests for CAN applications and to create controlled error conditions. It consists of a virtual CAN controller with which one or more virtual CAN channels are registered. When a virtual channel sends a message, it is placed into the receive queue of all other channels. Each channel only as a receive queue. Send operations succeed if every (other) channel has a slot available in their receive queue; otherwise they block or time out.
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 vcan.h.
io_can_ctrl_t* io_vcan_ctrl_create | ( | io_clock_t * | clock, |
int | flags, | ||
int | nominal, | ||
int | data, | ||
int | state | ||
) |
Creates a new virtual CAN controller.
clock | a pointer to the clock used to obtain the timestamp when sending CAN frames. |
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). |
nominal | the nominal bitrate. For the CAN FD protocol, this is the bit rate of the arbitration phase. If nominal is 0, the default value LELY_IO_VCAN_BITRATE is used. |
data | the data bitrate. This bit rate is only defined for the CAN FD protocol; the value is ignored otherwise. If data is 0, the data bitrate equals the nominal bitrate. |
state | the initial state of the virtual CAN bus (one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, CAN_STATE_SLEEPING or CAN_STATE_STOPPED). If state is CAN_STATE_STOPPED, the controller is stopped. |
void io_vcan_ctrl_destroy | ( | io_can_ctrl_t * | ctrl | ) |
Destroys a virtual CAN controller.
void io_vcan_ctrl_set_state | ( | io_can_ctrl_t * | ctrl, |
int | state | ||
) |
Sets the state of a virtual CAN bus: one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, CAN_STATE_SLEEPING or CAN_STATE_STOPPED.
If the requested state is CAN_STATE_STOPPED, the controller will be stopped as if by io_can_ctrl_stop() and all pending and future I/O operations will fail with error number ERRNUM_NETDOWN. Subsequent calls to this function have no effect until the controller is restarted with io_can_ctrl_restart().
If the requested state differs from the current state and is not CAN_STATE_STOPPED, and the controller supports error frames (IO_CAN_BUS_FLAG_ERR), an error frame with the new state is sent to all registered virtual CAN channels.
int io_vcan_ctrl_write_msg | ( | io_can_ctrl_t * | ctrl, |
const struct can_msg * | msg, | ||
int | timeout | ||
) |
Writes a CAN frame to a all virtual CAN channels registered with a virtual CAN controller.
This function blocks until the frame is written or an error occurs.
ctrl | a pointer to a virtual CAN controller. |
msg | a pointer to the CAN frame to be written. |
timeout | the maximum number of milliseconds this function will block. If timeout is negative, this function will block indefinitely. |
int io_vcan_ctrl_write_err | ( | io_can_ctrl_t * | ctrl, |
const struct can_err * | err, | ||
int | timeout | ||
) |
Writes a CAN error frame to a all virtual CAN channels registered with a virtual CAN controller.
This function blocks until the error frame is written or an error occurs. If the IO_CAN_BUS_FLAG_ERR flag was not specified when the controller was created with io_vcan_ctrl_create(), the controller does not support error frames and this function will fail.
ctrl | a pointer to a virtual CAN controller. |
err | a pointer to the CAN error frame to be written. |
timeout | the maximum number of milliseconds this function will block. If timeout is negative, this function will block indefinitely. |
io_can_chan_t* io_vcan_chan_create | ( | io_ctx_t * | ctx, |
ev_exec_t * | exec, | ||
size_t | rxlen | ||
) |
Creates a new virtual CAN channel.
ctx | a pointer to the I/O context with which the channel should be registered. |
exec | a pointer to the executor used to execute asynchronous tasks. |
rxlen | the receive queue length (in number of frames) of the channel. If rxlen is 0, the default value LELY_IO_VCAN_RXLEN is used. |
void io_vcan_chan_destroy | ( | io_can_chan_t * | chan | ) |
Destroys a virtual CAN channel.
void io_vcan_chan_open | ( | io_can_chan_t * | chan, |
io_can_ctrl_t * | ctrl | ||
) |
Opens a virtual CAN channel by registering it with the specified virtual CAN controller.
If the channel was already open, it is first closed as if by io_vcan_chan_close().
int io_vcan_chan_is_open | ( | const io_can_chan_t * | chan | ) |
void io_vcan_chan_close | ( | io_can_chan_t * | chan | ) |
Closes a virtual CAN channel.
Any pending read or write operations are canceled as if by io_can_chan_cancel_read() and io_can_chan_cancel_write().