asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
chann.h
1
11#ifndef ASRT_CHANN_H
12#define ASRT_CHANN_H
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "./asrt_assert.h"
19#include "./cobs.h"
20#include "./log.h"
21#include "./span.h"
22#include "./status.h"
23#include "./status_to_str.h"
24
25#include <stddef.h>
26#include <stdint.h>
27
29enum asrt_chann_id_e
30{
31 ASRT_META = 1,
32 ASRT_CORE = 2,
33 ASRT_DIAG = 3,
34 ASRT_PARA = 4,
35 ASRT_COLL = 5,
36 ASRT_STRM = 6,
37};
38
39typedef uint16_t asrt_chann_id;
40
42enum asrt_event_e
43{
44 ASRT_EVENT_TICK = 1,
45 ASRT_EVENT_RECV = 2,
46};
47
48static inline char const* asrt_event_to_str( enum asrt_event_e event )
49{
50 switch ( event ) {
51 case ASRT_EVENT_TICK:
52 return "tick";
53 case ASRT_EVENT_RECV:
54 return "recv";
55 }
56 return "unknown";
57}
58
60typedef void ( *asrt_send_done_cb )( void* ptr, enum asrt_status status );
61
64{
66 asrt_chann_id chid;
67 asrt_send_done_cb done_cb;
68 void* done_ptr;
69
71};
72
76{
79};
80
81static inline void asrt_send_req_list_init( struct asrt_send_req_list* list )
82{
83 list->head = NULL;
84 list->tail = NULL;
85}
86
87static inline int32_t asrt_send_is_req_used(
88 struct asrt_send_req_list const* list,
89 struct asrt_send_req const* req )
90{
91 return req->next != NULL || list->tail == req;
92}
93
94typedef enum asrt_status ( *asrt_event_callback )( void* ptr, enum asrt_event_e event, void* arg );
95
122{
123 asrt_chann_id chid;
124 void* e_cb_ptr;
125 asrt_event_callback e_cb;
126 struct asrt_node* next;
127 struct asrt_node* prev;
128 struct asrt_send_req_list* send_queue;
129};
130
132void asrt_node_link( struct asrt_node* after, struct asrt_node* node );
133
135void asrt_node_unlink( struct asrt_node* node );
136
137static inline enum asrt_status asrt_chann_recv( struct asrt_node* node, struct asrt_span buff )
138{
139 ASRT_ASSERT( node );
140 ASRT_ASSERT( node->e_cb );
141 return node->e_cb( node->e_cb_ptr, ASRT_EVENT_RECV, &buff );
142}
143
144static inline enum asrt_status asrt_chann_tick( struct asrt_node* node, uint32_t now )
145{
146 ASRT_ASSERT( node );
147 ASRT_ASSERT( node->e_cb );
148 return node->e_cb( node->e_cb_ptr, ASRT_EVENT_TICK, &now );
149}
150
153void asrt_chann_tick_successors( struct asrt_node* node, uint32_t now );
154
156struct asrt_node* asrt_chann_find( struct asrt_node* head, asrt_chann_id id );
157
159enum asrt_status asrt_chann_dispatch( struct asrt_node* head, struct asrt_span buff );
160
164enum asrt_status asrt_chann_cobs_dispatch(
165 struct asrt_cobs_ibuffer* ibuff,
166 struct asrt_node* head,
167 struct asrt_span in_buff );
168
172void asrt_send_enque(
173 struct asrt_node* node,
174 struct asrt_send_req* req,
175 asrt_send_done_cb done_cb,
176 void* done_ptr );
177
180static inline struct asrt_send_req* asrt_send_req_list_next( struct asrt_send_req_list* list )
181{
182 return list->head;
183}
184
188void asrt_send_req_list_done( struct asrt_send_req_list* list, enum asrt_status status );
189
191{
192 uint8_t buff[1];
193 struct asrt_send_req req;
194};
196{
197 uint8_t buff[2];
198 struct asrt_send_req req;
199};
201{
202 uint8_t buff[4];
203 struct asrt_send_req req;
204};
206{
207 uint8_t buff[5];
208 struct asrt_send_req req;
209};
211{
212 uint8_t buff[6];
213 struct asrt_send_req req;
214};
216{
217 uint8_t buff[8];
218 struct asrt_send_req req;
219};
221{
222 uint8_t buff[9];
223 struct asrt_send_req req;
224};
225
226#ifdef __cplusplus
227}
228#endif
229
230#endif
Input buffer for COBS-encoded data. buff is total capacity, used is occupied region.
Definition: cobs.h:69
A node in a doubly-linked channel chain.
Definition: chann.h:122
Intrusive FIFO of outgoing send requests.
Definition: chann.h:76
struct asrt_send_req * head
Oldest pending request (next to transmit).
Definition: chann.h:77
struct asrt_send_req * tail
Newest pending request.
Definition: chann.h:78
An outgoing message request placed in a module's send queue.
Definition: chann.h:64
asrt_send_done_cb done_cb
Completion callback, may be NULL.
Definition: chann.h:67
struct asrt_span_span buff
Message payload (scatter-gather).
Definition: chann.h:65
void * done_ptr
Opaque context forwarded to done_cb.
Definition: chann.h:68
asrt_chann_id chid
Target channel ID, set by asrt_send_enque().
Definition: chann.h:66
struct asrt_send_req * next
Intrusive linked-list link.
Definition: chann.h:70
Scatter-gather buffer: a primary byte range [b, e) followed by rest_count additional spans.
Definition: span.h:37
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: span.h:23
Definition: chann.h:191
Definition: chann.h:196
Definition: chann.h:201
Definition: chann.h:206
Definition: chann.h:211
Definition: chann.h:216
Definition: chann.h:221