Lely core libraries 2.3.4
can_rt.c File Reference

This file is part of the I/O library; it contains the implementation of the CAN frame router. More...

#include "io2.h"
#include <lely/libc/threads.h>
#include <lely/ev/exec.h>
#include <lely/ev/strand.h>
#include <lely/io2/can_rt.h>
#include <lely/io2/ctx.h>
#include <lely/util/errnum.h>
#include <lely/util/util.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for can_rt.c:

Go to the source code of this file.

Data Structures

struct  io_can_rt
 
struct  io_can_rt_async_read_msg
 
struct  io_can_rt_async_read_err
 
struct  io_can_rt_async_shutdown
 

Functions

io_can_rt_tio_can_rt_create (io_can_chan_t *chan, ev_exec_t *exec)
 Creates a new CAN frame router. More...
 
void io_can_rt_destroy (io_can_rt_t *rt)
 Destroys a CAN frame router. More...
 
io_dev_tio_can_rt_get_dev (const io_can_rt_t *rt)
 Returns a pointer to the abstract I/O device representing the CAN frame router.
 
io_can_chan_tio_can_rt_get_chan (const io_can_rt_t *rt)
 Returns a pointer to the CAN channel used by the CAN frame router.
 
void io_can_rt_submit_read_msg (io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
 Submits a CAN frame read operation to a CAN frame router. More...
 
size_t io_can_rt_cancel_read_msg (io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
 Cancels the specified CAN frame read operation if it is pending. More...
 
size_t io_can_rt_abort_read_msg (io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
 Aborts the specified CAN frame read operation if it is pending. More...
 
ev_future_tio_can_rt_async_read_msg (io_can_rt_t *rt, uint_least32_t id, uint_least8_t flags, struct io_can_rt_read_msg **pread_msg)
 Submits an asynchronous CAN frame read operation to a CAN frame router and creates a future which becomes ready once the read operation completes (or is canceled). More...
 
void io_can_rt_submit_read_err (io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
 Submits a CAN error frame read operation to a CAN frame router. More...
 
size_t io_can_rt_cancel_read_err (io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
 Cancels the specified CAN error frame read operation if it is pending. More...
 
size_t io_can_rt_abort_read_err (io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
 Aborts the specified CAN error frame read operation if it is pending. More...
 
ev_future_tio_can_rt_async_read_err (io_can_rt_t *rt, struct io_can_rt_read_err **pread_err)
 Submits an asynchronous CAN error frame read operation to a CAN frame router and creates a future which becomes ready once the read operation completes (or is canceled). More...
 
ev_future_tio_can_rt_async_shutdown (io_can_rt_t *rt)
 Shuts down a CAN frame router, cancels all pending operations and creates a (void) future which becomes ready once it is safe to invoke io_can_rt_destroy() (i.e., once the completion task of the last canceled reader has finished executing). More...
 
struct io_can_rt_read_msgio_can_rt_read_msg_from_task (struct ev_task *task)
 Obtains a pointer to a CAN frame read operation from a pointer to its completion task.
 
struct io_can_rt_read_errio_can_rt_read_err_from_task (struct ev_task *task)
 Obtains a pointer to a CAN error frame read operation from a pointer to its completion task.
 

Detailed Description

This file is part of the I/O library; it contains the implementation of the CAN frame router.

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

Definition in file can_rt.c.

Function Documentation

◆ io_can_rt_create()

io_can_rt_t * io_can_rt_create ( io_can_chan_t chan,
ev_exec_t exec 
)

Creates a new CAN frame router.

Parameters
chana pointer to the CAN channel to be used to read and write CAN frames. During the lifetime of the CAN frame router, no other read operations SHOULD be submitted to the CAN channel.
execa pointer to the executor used to execute asynchronous tasks.
Returns
a pointer to a new CAN frame router, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 225 of file can_rt.c.

◆ io_can_rt_destroy()

void io_can_rt_destroy ( io_can_rt_t rt)

Destroys a CAN frame router.

This function SHOULD NOT be called if there are pending read operations, since their completion tasks will never be executed. Use io_can_rt_async_shutdown() to cancel all operations and wait for the completion tasks to finish executing.

See also
io_can_rt_create()

Definition at line 252 of file can_rt.c.

◆ io_can_rt_submit_read_msg()

void io_can_rt_submit_read_msg ( io_can_rt_t rt,
struct io_can_rt_read_msg read_msg 
)

Submits a CAN frame read operation to a CAN frame router.

Once a matching CAN frame is received (or a read error occurs), the completion task is submitted for execution to the strand executor of the CAN frame router.

Definition at line 277 of file can_rt.c.

◆ io_can_rt_cancel_read_msg()

size_t io_can_rt_cancel_read_msg ( io_can_rt_t rt,
struct io_can_rt_read_msg read_msg 
)

Cancels the specified CAN frame read operation if it is pending.

The completion task is submitted for execution with errc = errnum2c(ERRNUM_CANCELED).

Returns
1 if the operation was canceled, and 0 if it was not pending.
See also
io_dev_cancel()

Definition at line 320 of file can_rt.c.

◆ io_can_rt_abort_read_msg()

size_t io_can_rt_abort_read_msg ( io_can_rt_t rt,
struct io_can_rt_read_msg read_msg 
)

Aborts the specified CAN frame read operation if it is pending.

If aborted, the completion task is not submitted for execution.

Returns
1 if the operation was aborted, and 0 if it was not pending.
See also
io_dev_abort()

Definition at line 343 of file can_rt.c.

◆ io_can_rt_async_read_msg()

ev_future_t * io_can_rt_async_read_msg ( io_can_rt_t rt,
uint_least32_t  id,
uint_least8_t  flags,
struct io_can_rt_read_msg **  pread_msg 
)

Submits an asynchronous CAN frame read operation to a CAN frame router and creates a future which becomes ready once the read operation completes (or is canceled).

The result of the future has type io_can_rt_read_msg_result.

Parameters
rta pointer to a CAN frame router.
idthe identifier of the CAN frame to be received.
flagsthe flags of the CAN frame to be received (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR, CAN_FLAG_FDF, CAN_FLAG_BRS and CAN_FLAG_ESI).
pread_msgthe address at which to store a pointer to the read operation (can be NULL).
Returns
a pointer to a future, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 365 of file can_rt.c.

◆ io_can_rt_submit_read_err()

void io_can_rt_submit_read_err ( io_can_rt_t rt,
struct io_can_rt_read_err read_err 
)

Submits a CAN error frame read operation to a CAN frame router.

Once a CAN error frame is received (or a read error occurs), the completion task is submitted for execution to the strand executor of the CAN frame router.

Definition at line 391 of file can_rt.c.

◆ io_can_rt_cancel_read_err()

size_t io_can_rt_cancel_read_err ( io_can_rt_t rt,
struct io_can_rt_read_err read_err 
)

Cancels the specified CAN error frame read operation if it is pending.

The completion task is submitted for execution with errc = errnum2c(ERRNUM_CANCELED).

Returns
1 if the operation was canceled, and 0 if it was not pending.
See also
io_dev_cancel()

Definition at line 425 of file can_rt.c.

◆ io_can_rt_abort_read_err()

size_t io_can_rt_abort_read_err ( io_can_rt_t rt,
struct io_can_rt_read_err read_err 
)

Aborts the specified CAN error frame read operation if it is pending.

If aborted, the completion task is not submitted for execution.

Returns
1 if the operation was aborted, and 0 if it was not pending.
See also
io_dev_abort()

Definition at line 448 of file can_rt.c.

◆ io_can_rt_async_read_err()

ev_future_t * io_can_rt_async_read_err ( io_can_rt_t rt,
struct io_can_rt_read_err **  pread_err 
)

Submits an asynchronous CAN error frame read operation to a CAN frame router and creates a future which becomes ready once the read operation completes (or is canceled).

The result of the future has type io_can_rt_read_err_result.

Parameters
rta pointer to a CAN frame router.
pread_errthe address at which to store a pointer to the read operation (can be NULL).
Returns
a pointer to a future, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 470 of file can_rt.c.

◆ io_can_rt_async_shutdown()

Shuts down a CAN frame router, cancels all pending operations and creates a (void) future which becomes ready once it is safe to invoke io_can_rt_destroy() (i.e., once the completion task of the last canceled reader has finished executing).

Returns
a pointer to a future, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 495 of file can_rt.c.