22 #ifndef LELY_IO2_CAN_H_ 23 #define LELY_IO2_CAN_H_ 32 #ifndef LELY_IO_CAN_INLINE 33 #define LELY_IO_CAN_INLINE static inline 46 IO_CAN_BUS_FLAG_NONE = 0,
104 #define IO_CAN_CHAN_READ_INIT(msg, err, tp, exec, func) \ 106 (msg), (err), (tp), EV_TASK_INIT(exec, func), { 0, 0 } \ 130 #define IO_CAN_CHAN_WRITE_INIT(msg, exec, func) \ 132 (msg), EV_TASK_INIT(exec, func), 0 \ 140 int (*stop)(io_can_ctrl_t *ctrl);
141 int (*stopped)(
const io_can_ctrl_t *ctrl);
142 int (*restart)(io_can_ctrl_t *ctrl);
144 const io_can_ctrl_t *ctrl,
int *pnominal,
int *pdata);
145 int (*set_bitrate)(io_can_ctrl_t *ctrl,
int nominal,
int data);
146 int (*get_state)(
const io_can_ctrl_t *ctrl);
150 io_dev_t *(*get_dev)(
const io_can_chan_t *chan);
151 int (*get_flags)(
const io_can_chan_t *chan);
152 int (*read)(io_can_chan_t *chan,
struct can_msg *msg,
153 struct can_err *err,
struct timespec *tp,
int timeout);
155 int (*write)(io_can_chan_t *chan,
const struct can_msg *msg,
157 void (*submit_write)(
204 const io_can_ctrl_t *ctrl,
int *pnominal,
int *pdata);
221 io_can_ctrl_t *ctrl,
int nominal,
int data);
243 io_can_chan_t *chan,
struct ev_task *task);
283 io_can_chan_t *chan,
struct io_can_chan_read *read);
295 io_can_chan_t *chan,
struct io_can_chan_read *read);
306 io_can_chan_t *chan,
struct io_can_chan_read *read);
329 struct io_can_chan_read **pread);
345 io_can_chan_t *chan,
const struct can_msg *msg,
int timeout);
352 io_can_chan_t *chan,
struct io_can_chan_write *write);
364 io_can_chan_t *chan,
struct io_can_chan_write *write);
375 io_can_chan_t *chan,
struct io_can_chan_write *write);
394 const struct can_msg *msg,
struct io_can_chan_write **pwrite);
411 return (*ctrl)->stop(ctrl);
417 return (*ctrl)->stopped(ctrl);
423 return (*ctrl)->restart(ctrl);
429 return (*ctrl)->get_bitrate(ctrl, pnominal, pdata);
435 return (*ctrl)->set_bitrate(ctrl, nominal, data);
441 return (*ctrl)->get_state(ctrl);
471 return (*chan)->get_dev(chan);
477 return (*chan)->get_flags(chan);
482 struct timespec *tp,
int timeout)
484 return (*chan)->read(chan, msg, err, tp, timeout);
490 (*chan)->submit_read(chan, read);
508 return (*chan)->write(chan, msg, timeout);
514 (*chan)->submit_write(chan, write);
533 #endif // !LELY_IO2_CAN_H_ A CAN or CAN FD format frame.
static size_t io_can_chan_cancel(io_can_chan_t *chan, struct ev_task *task)
struct can_err * err
The address at which to store the CAN error frame.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
A CAN channel read operation.
ev_future_t * io_can_chan_async_write(io_can_chan_t *chan, ev_exec_t *exec, const struct can_msg *msg, struct io_can_chan_write **pwrite)
Submits an asynchronous write operation to a CAN channel and creates a future which becomes ready onc...
static ev_exec_t * io_can_chan_get_exec(const io_can_chan_t *chan)
int errc
The error number, obtained as if by get_errc(), if an error occurred or the operation was canceled...
static size_t io_can_chan_cancel_write(io_can_chan_t *chan, struct io_can_chan_write *write)
Cancels the specified CAN channel write operation if it is pending.
This header file is part of the I/O library; it contains CAN bus error definitions.
int io_can_chan_write(io_can_chan_t *chan, const struct can_msg *msg, int timeout)
Writes a CAN frame to a CAN channel.
ev_exec_t * io_dev_get_exec(const io_dev_t *dev)
Returns a pointer to the executor used by the I/O device to execute asynchronous tasks.
int io_can_ctrl_stop(io_can_ctrl_t *ctrl)
Stops a CAN controller.
This header file is part of the I/O library; it contains the CAN frame declarations.
int io_can_ctrl_stopped(const io_can_ctrl_t *ctrl)
Returns 1 in the CAN controller is stopped, 0 if not, and -1 on error.
FD Format (formerly Extended Data Length) support is enabled.
A CAN channel write operation.
Bit Rate Switch support is enabled.
const struct io_can_chan_vtbl *const io_can_chan_t
An abstract CAN channel.
void io_can_chan_submit_read(io_can_chan_t *chan, struct io_can_chan_read *read)
Submits a read operation to a CAN channel.
int io_can_chan_read(io_can_chan_t *chan, struct can_msg *msg, struct can_err *err, struct timespec *tp, int timeout)
Reads a CAN frame or CAN error frame from a CAN channel.
size_t io_dev_cancel(io_dev_t *dev, struct ev_task *task)
Cancels the asynchronous operation submitted to *dev, if its task has not yet been submitted to its e...
static size_t io_can_chan_cancel_read(io_can_chan_t *chan, struct io_can_chan_read *read)
Cancels the specified CAN channel read operation if it is pending.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
static size_t io_can_chan_abort(io_can_chan_t *chan, struct ev_task *task)
static size_t io_can_chan_abort_read(io_can_chan_t *chan, struct io_can_chan_read *read)
Aborts the specified CAN channel read operation if it is pending.
ev_future_t * io_can_chan_async_read(io_can_chan_t *chan, ev_exec_t *exec, struct can_msg *msg, struct can_err *err, struct timespec *tp, struct io_can_chan_read **pread)
Submits an asynchronous read operation to a CAN channel and creates a future which becomes ready once...
struct io_can_chan_read * io_can_chan_read_from_task(struct ev_task *task)
Obtains a pointer to a CAN channel read operation from a pointer to its completion task...
int result
The result of the read operation: 1 if a CAN frame is received, 0 if an error frame is received...
io_dev_t * io_can_chan_get_dev(const io_can_chan_t *chan)
Returns a pointer to the abstract I/O device representing the CAN channel.
int errc
The error number, obtained as if by get_errc(), if result is -1.
const struct can_msg * msg
A pointer to the CAN frame to be written.
This header file is part of the event library; it contains the futures and promises declarations...
size_t io_dev_abort(io_dev_t *dev, struct ev_task *task)
Aborts the asynchronous operation submitted to *dev, if its task has not yet been submitted to its ex...
Reception of error frames is enabled.
io_ctx_t * io_dev_get_ctx(const io_dev_t *dev)
Returns a pointer to the I/O context with which the I/O device is registered.
int io_can_ctrl_get_state(const io_can_ctrl_t *ctrl)
Returns the state of the CAN controller: one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF, CAN_STATE_SLEEPING or CAN_STATE_STOPPED, or -1 on error.
This header file is part of the event library; it contains the task declarations. ...
int io_can_ctrl_set_bitrate(io_can_ctrl_t *ctrl, int nominal, int data)
Configures the bitrate(s) of a CAN controller.
struct can_msg * msg
The address at which to store the CAN frame.
void io_can_chan_submit_write(io_can_chan_t *chan, struct io_can_chan_write *write)
Submits a write operation to a CAN channel.
const struct io_can_ctrl_vtbl *const io_can_ctrl_t
An abstract CAN controller.
static size_t io_can_chan_abort_write(io_can_chan_t *chan, struct io_can_chan_write *write)
Aborts the specified CAN channel write operation if it is pending.
static io_ctx_t * io_can_chan_get_ctx(const io_can_chan_t *chan)
int io_can_ctrl_restart(io_can_ctrl_t *ctrl)
(Re)starts a CAN contoller.
io_can_bus_flag
The CAN bus flags.
int io_can_ctrl_get_bitrate(const io_can_ctrl_t *ctrl, int *pnominal, int *pdata)
Obtains the bitrate(s) of a CAN controller.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the write operation.
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
struct io_can_chan_write * io_can_chan_write_from_task(struct ev_task *task)
Obtains a pointer to a CAN channel write operation from a pointer to its completion task...
This header file is part of the C11 and POSIX compatibility library; it includes <time.h> and defines any missing functionality.
struct timespec * tp
The address at which to store the system time at which the CAN frame or CAN error frame was received...
This header file is part of the I/O library; it contains the abstract I/O device interface.
The result of a CAN channel read operation.
int io_can_chan_get_flags(const io_can_chan_t *chan)
Returns the flafs of the CAN bus: any combination of IO_CAN_BUS_FLAG_ERR, IO_CAN_BUS_FLAG_FDF and IO_...