]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_data.h
negotiator thread and bwres layer
[frescor/fna.git] / src_frescan / frescan_data.h
1 /*!
2  * @file frescan_data.h
3  *
4  * @brief global data used from different modules in frescan
5  *
6  * @version 0.01
7  *
8  * @date 12-Mar-2008
9  *
10  * @author
11  *      Daniel Sangorrin
12  *
13  * @comments
14  *
15  * In order to simplify we have a single module, frescan_data, to store the
16  * main internal structures and global data of the FRESCAN protocol.
17  *
18  * @license
19  *
20  * See MaRTE OS license
21  *
22  */
23
24 #ifndef _MARTE_FRESCAN_DATA_H_
25 #define _MARTE_FRESCAN_DATA_H_
26
27 #include <stdint.h>    // uint32_t
28 #include <semaphore.h> // sem_t
29 #include <time.h>      // struct timespec, timer_t
30 #include "fosa_threads_and_signals.h"   // fosa_thread_id_t
31
32 #include <misc/linux_list.h> // struct list_head
33 #include <misc/freelist.h>   // freelist_t
34
35 #include "frescan.h"         // frescan_node_t, _prio_t, _budget_t
36 #include "frescan_config.h"  // FRESCAN_MLOCK_T, FRESCAN_MX_XXX
37 #include "frescan_packets.h" // frescan_packet_t
38 #include "frescan_servers_replenishments.h" // frescan_repl_op_t
39
40 /**
41  * frescan_repl_op_t - a replenishment operation
42  *
43  * @when: when the replenishment operation is programmed at
44  * @amount: number of frames to add to the current_budget
45  * @repl_list: to chain the replenishments for a certain sporadic server
46  * @pool_pos: to know how to free it from the replenishment pool
47  */
48
49 typedef struct {
50         struct timespec when;
51         frescan_budget_t amount;
52         struct list_head repl_list;
53         int pool_pos;
54 } frescan_repl_op_t;
55
56 /**
57  * frescan_server_params_t - server parameters
58  *
59  * @budget: the budget in CAN 8-byte frames
60  * @period: the replenishment period for the server
61  * @prio: the priority for the server TODO: this should be a return value
62  */
63
64 typedef struct {
65         frescan_budget_t budget;
66         struct timespec period;
67         frescan_prio_t prio;
68 } frescan_server_params_t;
69
70 /**
71  * frescan_server_data_t - server data
72  *
73  * @params: the fixed parameters (budget, period and priority)
74  * @current_budget: the current available capacity
75  * @current_priority: the current priority (0=background)
76  * @repl_list: the list of pending replenishment operations
77  * @repl_timer: the timer for the replenishments associated to this server
78  *     NOTE: we could use a single timer for all but for now this is simpler
79  * @packet_list: the packets enqueued on this server
80  */
81
82 typedef struct {
83         frescan_server_params_t params;
84         frescan_network_t net;
85         frescan_ss_t      id;
86         frescan_budget_t  current_budget;
87         frescan_prio_t    current_priority;
88         frescan_budget_t  pending_packets;
89         frescan_repl_op_t replenishments;
90         timer_t           repl_timer;
91         frescan_packet_t  packet_list;
92         struct list_head  servers_list;
93 } frescan_server_data_t;
94
95 /**
96  * the_servers_pool - pool of servers structure
97  */
98
99 extern frescan_server_data_t the_servers_pool[FRESCAN_MX_NETWORKS][FRESCAN_MX_IDS];
100 extern freelist_t the_servers_pool_freelist[FRESCAN_MX_NETWORKS];
101 extern frescan_server_data_t the_active_servers[FRESCAN_MX_NETWORKS];
102
103 /**
104  * frescan_contract_t
105  */
106
107 typedef struct {
108         frescan_budget_t max_budget;
109         struct timespec  min_period;
110         frescan_budget_t min_budget;
111         struct timespec  max_period;
112         frescan_prio_t prio;
113 } frescan_contract_t;
114
115 /**
116  * frescan_prio_queue_t - priority queue
117  *
118  * FRESCAN priority queues are implemented as an array of one 'fifo_queue' for
119  * each priority. Where the 'fifo_queues' are implemented using the
120  * 'struct list_head fifo_list;' field of each packet structure (Linux lists).
121  *
122  * So far mutual exclusion is achieved by disabling interrupts and
123  * synchronization is done using a semaphore. This is because the queues
124  * are accesed concurrently from user threads and the IRQ handler.
125  *
126  * @fifo_queues: an array of packets for each priority where each packet
127  *               is just the head of a fifo_list. The array is allocated
128  *               from the heap, using malloc, at initialization with range
129  *               0..max_prio-1
130  * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
131  * @sem: semaphore used for synchronization
132  */
133
134 typedef struct {
135         frescan_packet_t *fifo_queues;
136         uint32_t max_prio;
137         sem_t sem;
138 } frescan_prio_queue_t;
139
140 /**
141  * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
142  *
143  * @tx_fp_queue: priority queue for the fixed priority packets
144  * @rx_channel_queues: a priority queue for each receiving channel
145  *
146  * TODO: add here the sporadic server queues...
147  */
148
149 typedef struct {
150         frescan_prio_queue_t *tx_fp_queue;
151         frescan_prio_queue_t **rx_channel_queues;
152         uint32_t num_rx_channels;
153 } frescan_queues_t;
154
155 /**
156  * frescan_network_data_t - data for each network instance
157  *
158  * @local_node: the local node id for that network. The implementation does not
159  * support several interfaces for the same network.
160  * @fd: file descriptor associated to /dev/canXX
161  * @queues: the queues of this network instance
162  * @last_packet: pointer to the last packet from which a frame was inserted
163  *               in the chip and its transmission is not complete.
164  * @last_packet_prio: prio of the packet in the buffer
165  * @id_queues: queues to store received packets while the whole message is
166  *             not complete (fragmentation). (id = 0 .. FRESCAN_MX_IDS - 1)
167  * @id_fp_queues: the same as id_queues but for fp messages, which have
168  *                id=FRESCAN_MX_IDS and are distinguised through their
169  *                priorities.
170  *
171  * the implementation can handle several FRESCAN networks at the same time
172  * in the same node, so we need a place to store its internal data. The data
173  * is allocated as an array where the index is the MINOR number (which also
174  * identifies the /dev/canx device for that network)
175  */
176
177 typedef struct {
178         FRESCAN_MLOCK_T lock;
179         frescan_node_t local_node;
180         int fd;
181         fosa_thread_id_t repl_thread_id;
182         fosa_thread_id_t neg_thread_id;
183         frescan_queues_t queues;
184         frescan_packet_t *last_packet;
185         frescan_prio_t last_packet_prio;
186         frescan_packet_t *id_queues[FRESCAN_MX_IDS];      // TODO: alloc at init
187         frescan_packet_t *id_fp_queues[FRESCAN_MX_PRIOS]; // TODO: alloc at init
188 } frescan_network_data_t;
189
190 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
191
192 /**
193  * frescan_data_init() - init the data global variables
194  *
195  */
196
197 extern int frescan_data_init(int fd, frescan_init_params_t *params);
198
199
200
201 #endif // _MARTE_FRESCAN_DATA_H_