]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_data.h
update the names and add acceptor thread id to the general data
[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_budget_period_t;
68
69 typedef struct {
70         frescan_budget_period_t values;
71         frescan_prio_t prio;
72 } frescan_server_params_t;
73
74 /**
75  * frescan_server_data_t - server data
76  *
77  * @params: the fixed parameters (budget, period and priority)
78  * @current_budget: the current available capacity
79  * @current_priority: the current priority (0=background)
80  * @repl_list: the list of pending replenishment operations
81  * @repl_timer: the timer for the replenishments associated to this server
82  *     NOTE: we could use a single timer for all but for now this is simpler
83  * @packet_list: the packets enqueued on this server
84  */
85
86 typedef struct {
87         frescan_server_params_t params;
88         frescan_network_t net;
89         frescan_ss_t      id;
90         frescan_budget_t  current_budget;
91         frescan_prio_t    current_priority;
92         frescan_budget_t  pending_packets;
93         frescan_repl_op_t replenishments;
94         timer_t           repl_timer;
95         frescan_packet_t  packet_list;
96         struct list_head  servers_list;
97 } frescan_server_data_t;
98
99 /**
100  * the_servers_pool - pool of servers structure
101  */
102
103 extern frescan_server_data_t the_servers_pool[FRESCAN_MX_NETWORKS][FRESCAN_MX_IDS];
104 extern freelist_t the_servers_pool_freelist[FRESCAN_MX_NETWORKS];
105 extern frescan_server_data_t the_active_servers[FRESCAN_MX_NETWORKS];
106
107 /**
108  * frescan_contract_t
109  */
110
111 typedef struct {
112         frescan_budget_period_t min_values;
113         frescan_budget_period_t max_values;
114         frescan_prio_t prio;
115 } frescan_contract_t;
116
117 /**
118  * return info
119  */
120
121 typedef struct {
122         int error;
123         frescan_ss_t id;
124 } frescan_neg_return_info_t;
125
126 /**
127  * frescan_prio_queue_t - priority queue
128  *
129  * FRESCAN priority queues are implemented as an array of one 'fifo_queue' for
130  * each priority. Where the 'fifo_queues' are implemented using the
131  * 'struct list_head fifo_list;' field of each packet structure (Linux lists).
132  *
133  * So far mutual exclusion is achieved by disabling interrupts and
134  * synchronization is done using a semaphore. This is because the queues
135  * are accesed concurrently from user threads and the IRQ handler.
136  *
137  * @fifo_queues: an array of packets for each priority where each packet
138  *               is just the head of a fifo_list. The array is allocated
139  *               from the heap, using malloc, at initialization with range
140  *               0..max_prio-1
141  * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
142  * @sem: semaphore used for synchronization
143  */
144
145 typedef struct {
146         frescan_packet_t *fifo_queues;
147         uint32_t max_prio;
148         sem_t sem;
149 } frescan_prio_queue_t;
150
151 /**
152  * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
153  *
154  * @tx_fp_queue: priority queue for the fixed priority packets
155  * @rx_channel_queues: a priority queue for each receiving channel
156  *
157  * TODO: add here the sporadic server queues...
158  */
159
160 typedef struct {
161         frescan_prio_queue_t *tx_fp_queue;
162         frescan_prio_queue_t **rx_channel_queues;
163         uint32_t num_rx_channels;
164 } frescan_queues_t;
165
166 /**
167  * frescan_network_data_t - data for each network instance
168  *
169  * @local_node: the local node id for that network. The implementation does not
170  * support several interfaces for the same network.
171  * @fd: file descriptor associated to /dev/canXX
172  * @repl_thread_id: replenishment thread id
173  * @neg_thread_id: master local negotiator thread id (only master node has it)
174  * @acceptor_thread_id: acceptor negotiation thread id (all nodes have one)
175  * @neg_messages_ss_id: sporadic server for negotiation messages
176  * @queues: the queues of this network instance
177  * @last_packet: pointer to the last packet from which a frame was inserted
178  *               in the chip and its transmission is not complete.
179  * @last_packet_prio: prio of the packet in the buffer
180  * @id_queues: queues to store received packets while the whole message is
181  *             not complete (fragmentation). (id = 0 .. FRESCAN_MX_IDS - 1)
182  * @id_fp_queues: the same as id_queues but for fp messages, which have
183  *                id=FRESCAN_MX_IDS and are distinguised through their
184  *                priorities.
185  *
186  * the implementation can handle several FRESCAN networks at the same time
187  * in the same node, so we need a place to store its internal data. The data
188  * is allocated as an array where the index is the MINOR number (which also
189  * identifies the /dev/canx device for that network)
190  */
191
192 typedef struct {
193         FRESCAN_MLOCK_T lock;
194         frescan_node_t local_node;
195         int fd;
196         fosa_thread_id_t repl_thread_id;
197         fosa_thread_id_t neg_thread_id;
198         fosa_thread_id_t acceptor_thread_id;
199         frescan_ss_t neg_messages_ss_id;
200         frescan_queues_t queues;
201         frescan_packet_t *last_packet;
202         frescan_prio_t last_packet_prio;
203         frescan_packet_t *id_queues[FRESCAN_MX_IDS];      // TODO: alloc at init
204         frescan_packet_t *id_fp_queues[FRESCAN_MX_PRIOS]; // TODO: alloc at init
205 } frescan_network_data_t;
206
207 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
208
209 /**
210  * frescan_data_init() - init the data global variables
211  *
212  */
213
214 extern int frescan_data_init(int fd, frescan_init_params_t *params);
215
216
217
218 #endif // _MARTE_FRESCAN_DATA_H_