2 * @file frescan_queues.h
4 * @brief FRESCAN queues to manage the packets by prio and servers
15 * This file contains the FRESCAN queues where frescan packets are stored and
20 * See MaRTE OS license
24 #ifndef _MARTE_FRESCAN_QUEUES_H_
25 #define _MARTE_FRESCAN_QUEUES_H_
27 #include <stdint.h> // uint8_t
28 #include <stdbool.h> // bool
30 #include "frescan.h" // frescan_prio_t
31 #include "frescan_packets.h" // frescan_packet_t
32 #include "frescan_data.h"
35 * frescan_queues_init() - initialize the queues
37 * This function initializes the queue structures for an instance of frescan
38 * protocol. We provide different sizes and constants so, at initialization
39 * time, the structures are allocated from the heap. Note, that this approach
40 * is not conflicting with real-time systems where typically static allocation
41 * is used because we only do it at the initialization and also because we
42 * are using a real-time memory allocator. The advantage is that we have the
43 * flexibility of using different values for different instances of the
44 * protocol and that we can also supply the protocol compiled as a library.
46 * @queues: the queues structures
47 * @frescan_init_params_t: some init parameters for the queues
49 * TODO: add maximum number of packets per queue?? so far they are taken from
51 * TODO: add policy for overwritting
54 int frescan_queues_init(frescan_queues_t *queues,
55 frescan_init_params_t *params);
58 * frescan_pqueue_enqueue() - enqueue a packet
60 * this function enqueues a frescan_packet into the a priority queue. For the
61 * case of same priority packets they are stored at the tail, following a FIFO
64 * @pqueue: the priority queue
65 * @packet: the packet that we want to store
69 int frescan_pqueue_enqueue(frescan_prio_queue_t *pqueue,
70 frescan_packet_t *packet,
74 * frescan_pqueue_requeue() - requeue a packet
76 * this function requeues a previously extracted frescan_packet. It puts
77 * the packet at the head of the fifo queue. This is useful when you abort
78 * the transmission of the packet beacuse another one with highest priority
79 * has arrived, and you still want to preserve the order in which the packets
82 * @pqueue: the priority queue
83 * @packet: the packet that we want to store
87 int frescan_pqueue_requeue(frescan_prio_queue_t *pqueue,
88 frescan_packet_t *packet,
92 * frescan_pqueue_dequeue() - dequeue the packet with highest priority
94 * @pqueue: the priority queue
95 * @packet: the packet extracted
96 * @blocking: if there are no packets we can choose to block or not. In
97 * a non-blocking mode, if there are no packets 'packet' will be NULL
101 int frescan_pqueue_dequeue(frescan_prio_queue_t *pqueue,
102 frescan_packet_t **packet,
103 frescan_prio_t *packet_prio,
107 * frescan_pqueue_get_highest_prio() - returns the packet with highest prio
108 * but not extracting it from the queue.
110 * @pqueue: the priority queue
111 * @packet: the packet with highest prio (not extracted from the pqueue)
115 int frescan_pqueue_get_highest_prio(frescan_prio_queue_t *pqueue,
116 frescan_packet_t **packet,
117 frescan_prio_t *packet_prio);
120 * frescan_servers_enqueue() - enqueue a packet through a server
122 * @net: the network instance
123 * @id: the identificator for the server
124 * @packet: the packet being enqueued
128 int frescan_servers_enqueue(frescan_network_t net,
130 frescan_packet_t *packet);
133 * frescan_servers_requeue() - requeue a packet through a server
135 * @net: the network instance
136 * @id: the identificator for the server
137 * @packet: the packet being requeued
141 int frescan_servers_requeue(frescan_network_t net,
143 frescan_packet_t *packet);
146 * frescan_servers_dequeue() - dequeue a packet from a server
148 * @net: the network instance
149 * @id: the identificator for the server
150 * @packet: the packet dequeued
154 int frescan_servers_dequeue(frescan_network_t net,
156 frescan_packet_t **packet,
157 frescan_prio_t *packet_prio);
159 #endif // _MARTE_FRESCAN_QUEUES_H_