tinyproto
tiny_fd_i_queue_control_int.h
1 /*
2  Copyright 2019-2025 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  GNU General Public License Usage
7 
8  Protocol Library is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Protocol Library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
20 
21  Commercial License Usage
22 
23  Licensees holding valid commercial Tiny Protocol licenses may use this file in
24  accordance with the commercial license agreement provided in accordance with
25  the terms contained in a written agreement between you and Alexey Dynda.
26  For further information contact via email on github account.
27 */
28 
29 #pragma once
30 
31 #include "tiny_fd.h"
32 #include "tiny_fd_defines_int.h"
33 
34 #include <stdbool.h>
35 
36 typedef struct i_queue_control_send_t
37 {
38  uint8_t last_ns; // next free frame to send in cycle buffer
39  uint8_t confirm_ns; // next sent frame to be confirmed
40  uint8_t next_ns; // next frame to be sent
42 
43 typedef struct i_queue_control_recv_t
44 {
45  uint8_t next_nr; // next expected frame number
47 
48 typedef struct i_queue_control_t
49 {
50  struct i_queue_control_send_t tx_state;
51  struct i_queue_control_recv_t rx_state;
53 
54 typedef bool (*on_i_frame_to_process_cb_t)(void *ctx, uint8_t nr);
55 
57 
58 static inline uint8_t __i_queue_control_get_next_frame_to_confirm(i_queue_control_t *control)
59 {
60  return control->tx_state.confirm_ns;
61 }
62 
64 
65 bool __i_queue_control_confirm_sent_frames(i_queue_control_t *control, uint8_t nr, on_i_frame_to_process_cb_t cb, void *ctx);
66 
68 
69 bool __i_queue_control_restransmit_frame(i_queue_control_t *control, uint8_t nr, on_i_frame_to_process_cb_t cb, void *ctx);
70 
72 
73 uint8_t __i_queue_control_get_next_frame_to_send(i_queue_control_t *control);
74 
76 
77 uint8_t __i_queue_control_get_next_frame_to_receive(i_queue_control_t *control);
78 
80 
81 void __i_queue_control_move_to_next_frame_to_receive(i_queue_control_t *control);
82 
84 
85 void __i_queue_control_move_to_previous_ns(i_queue_control_t *control);
86 
88 
89 void __i_queue_control_move_to_next_ns(i_queue_control_t *control);
90 
92 
93 bool __i_queue_control_has_unconfirmed_frames(i_queue_control_t *control);
94 
96 
97 bool __all_frames_are_sent(i_queue_control_t *control);
98 
100 
101 bool __i_queue_control_tx_full(i_queue_control_t *control);
102 
104 
105 bool __put_i_frame_to_tx_queue(tiny_fd_handle_t handle, uint8_t peer, const void *data, int len);
106 
108 
109 void __reset_i_queue_control(i_queue_control_t *control);
110 
112 
113 void __i_queue_control_log_statistics(i_queue_control_t *control, uint8_t is_full);
114 
Definition: tiny_fd_int.h:103
Definition: tiny_fd_i_queue_control_int.h:36
Definition: tiny_fd_i_queue_control_int.h:48
Definition: tiny_fd_i_queue_control_int.h:43
This is Tiny Full-Duplex protocol implementation for microcontrollers.