Lely core libraries  2.2.5
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
31 extern "C" {
32 #endif
33 
34 static void io_can_chan_read_post(
35  struct io_can_chan_read *read, int result, int errc);
36 static size_t io_can_chan_read_queue_post(
37  struct sllist *queue, int result, int errc);
38 
39 static void io_can_chan_write_post(struct io_can_chan_write *write, int errc);
40 static size_t io_can_chan_write_queue_post(struct sllist *queue, int errc);
41 
42 static inline void
43 io_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 
53 static inline size_t
54 io_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 
70 static inline void
71 io_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 
80 static inline size_t
81 io_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_
void ev_exec_post(ev_exec_t *exec, struct ev_task *task)
Submits *task to *exec for execution.
Definition: exec.h:126
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
A CAN channel read operation.
Definition: can.h:74
int errc
The error number, obtained as if by get_errc(), if an error occurred or the operation was canceled...
Definition: can.h:126
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:114
A node in a singly-linked list.
Definition: sllist.h:39
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
Definition: sllist.h:221
A CAN channel write operation.
Definition: can.h:110
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
Definition: can.h:98
A singly-linked list.
Definition: sllist.h:51
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:91
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
This header file is part of the I/O library; it contains the abstract CAN bus interface.
struct io_can_chan_read_result r
The result of the read operation.
Definition: can.h:100
This header file is part of the C11 and POSIX compatibility library; it includes <stdint.h> and defines any missing functionality.
An executable task.
Definition: task.h:41
This header file is part of the event library; it contains the abstract task executor interface...
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
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the write operation.
Definition: can.h:121
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:97
This is the internal header file of the I/O library.