Lely core libraries 2.3.4
can.h
Go to the documentation of this file.
1
21#ifndef LELY_IO2_INTERN_CAN_H_
22#define LELY_IO2_INTERN_CAN_H_
23
24#include "io2.h"
25#include <lely/ev/exec.h>
26#include <lely/io2/can.h>
27
28#include <stdint.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34static void io_can_chan_read_post(
35 struct io_can_chan_read *read, int result, int errc);
36static size_t io_can_chan_read_queue_post(
37 struct sllist *queue, int result, int errc);
38
39static void io_can_chan_write_post(struct io_can_chan_write *write, int errc);
40static size_t io_can_chan_write_queue_post(struct sllist *queue, int errc);
41
42static inline void
43io_can_chan_read_post(struct io_can_chan_read *read, int result, int errc)
44{
45 read->r.result = result;
46 read->r.errc = errc;
47
48 ev_exec_t *exec = read->task.exec;
49 ev_exec_post(exec, &read->task);
51}
52
53static inline size_t
54io_can_chan_read_queue_post(struct sllist *queue, int result, int errc)
55{
56 size_t n = 0;
57
58 struct slnode *node;
59 while ((node = sllist_pop_front(queue))) {
60 struct ev_task *task = ev_task_from_node(node);
61 struct io_can_chan_read *read =
63 io_can_chan_read_post(read, result, errc);
64 n += n < SIZE_MAX;
65 }
66
67 return n;
68}
69
70static inline void
71io_can_chan_write_post(struct io_can_chan_write *write, int errc)
72{
73 write->errc = errc;
74
75 ev_exec_t *exec = write->task.exec;
76 ev_exec_post(exec, &write->task);
78}
79
80static inline size_t
81io_can_chan_write_queue_post(struct sllist *queue, int errc)
82{
83 size_t n = 0;
84
85 struct slnode *node;
86 while ((node = sllist_pop_front(queue))) {
87 struct ev_task *task = ev_task_from_node(node);
88 struct io_can_chan_write *write =
90 io_can_chan_write_post(write, errc);
91 n += n < SIZE_MAX;
92 }
93
94 return n;
95}
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif // !LELY_IO2_INTERN_CAN_H_
This header file is part of the event library; it contains the abstract task executor interface.
void ev_exec_post(ev_exec_t *exec, struct ev_task *task)
Submits *task to *exec for execution.
Definition exec.h:124
void ev_exec_on_task_fini(ev_exec_t *exec)
Undoes the effect of a previous call to ev_exec_on_task_init().
Definition exec.h:112
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition ev.h:29
This header file is part of the I/O library; it contains the abstract CAN bus interface.
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.
Definition can.c:93
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.
Definition can.c:99
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
Definition sllist.h:243
This is the internal header file of the I/O library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
An executable task.
Definition task.h:41
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition task.h:43
int result
The result of the read operation: 1 if a CAN frame is received, 0 if an error frame is received,...
Definition can.h:68
int errc
The error number, obtained as if by get_errc(), if result is -1.
Definition can.h:70
A CAN channel read operation.
Definition can.h:74
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
Definition can.h:98
struct io_can_chan_read_result r
The result of the read operation.
Definition can.h:100
A CAN channel write operation.
Definition can.h:110
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the write operation.
Definition can.h:121
int errc
The error number, obtained as if by get_errc(), if an error occurred or the operation was canceled.
Definition can.h:126
A singly-linked list.
Definition sllist.h:52
A node in a singly-linked list.
Definition sllist.h:40
struct ev_task * ev_task_from_node(struct slnode *node)
Converts a pointer to a node in a queue to the address of the task containing the node.
Definition task.c:32