]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_data.h
b4c046327dc3e702c0b54b54a02dc8da4bbdd677
[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  * -----------------------------------------------------------------------
21  *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
22  *
23  *    Universidad de Cantabria,              SPAIN
24  *    University of York,                    UK
25  *    Scuola Superiore Sant'Anna,            ITALY
26  *    Kaiserslautern University,             GERMANY
27  *    Univ. Politécnica  Valencia,           SPAIN
28  *    Czech Technical University in Prague,  CZECH REPUBLIC
29  *    ENEA                                   SWEDEN
30  *    Thales Communication S.A.              FRANCE
31  *    Visual Tools S.A.                      SPAIN
32  *    Rapita Systems Ltd                     UK
33  *    Evidence                               ITALY
34  *
35  *    See http://www.frescor.org for a link to partners' websites
36  *
37  *           FRESCOR project (FP6/2005/IST/5-034026) is funded
38  *        in part by the European Union Sixth Framework Programme
39  *        The European Union is not liable of any use that may be
40  *        made of this code.
41  *
42  *  This file is part of FRESCAN
43  *
44  *  FRESCAN is free software; you can  redistribute it and/or  modify
45  *  it under the terms of  the GNU General Public License as published by
46  *  the Free Software Foundation;  either  version 2, or (at  your option)
47  *  any later version.
48  *
49  *  FRESCAN  is distributed  in  the hope  that  it  will  be useful,  but
50  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
51  *  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
52  *  General Public License for more details.
53  *
54  *  You should have  received a  copy of  the  GNU  General Public License
55  *  distributed  with  FRESCAN;  see file COPYING.   If not,  write to the
56  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
57  *  02111-1307, USA.
58  *
59  * As a special exception, including FRESCAN header files in a file,
60  * instantiating FRESCAN generics or templates, or linking other files
61  * with FRESCAN objects to produce an executable application, does not
62  * by itself cause the resulting executable application to be covered
63  * by the GNU General Public License. This exception does not
64  * however invalidate any other reasons why the executable file might be
65  * covered by the GNU Public License.
66  * -----------------------------------------------------------------------
67  *
68  */
69
70 #ifndef _MARTE_FRESCAN_DATA_H_
71 #define _MARTE_FRESCAN_DATA_H_
72
73 #include <stdint.h>    // uint32_t
74 #include <semaphore.h> // sem_t
75 #include <time.h>      // struct timespec, timer_t
76 #include "fosa_threads_and_signals.h"   // fosa_thread_id_t
77
78 #include <misc/linux_list.h> // struct list_head
79 #include <misc/freelist.h>   // freelist_t
80
81 #include "frescan.h"         // frescan_node_t, _prio_t, _budget_t
82 #include "frescan_config.h"  // FRESCAN_MLOCK_T, FRESCAN_MX_XXX
83 #include "frescan_packets.h" // frescan_packet_t
84
85 #include "frsh.h" // for frsh_contract_t
86 #include "fsa.h"  // for frsh_sa_scenario_t
87
88 /**
89  * frescan_repl_op_t - a replenishment operation
90  *
91  * @when: when the replenishment operation is programmed at
92  * @amount: number of frames to add to the available budget
93  * @repl_list: to chain the replenishments for a certain sporadic server
94  * @pool_pos: to know how to free it from the replenishment pool
95  */
96
97 typedef struct {
98         struct timespec when;
99         frescan_budget_t amount;
100         struct list_head repl_list;
101         int pool_pos;
102 } frescan_repl_op_t;
103
104 /**
105  * frescan_server_params_t - server parameters
106  *
107  * @budget: the budget in CAN 8-byte frames
108  * @period: the replenishment period for the server
109  * @prio: the priority of the server
110  */
111
112 typedef struct {
113         frescan_budget_t budget;
114         struct timespec  period;
115         frescan_prio_t prio;
116 } frescan_server_params_t;
117
118 /**
119  * frescan_server_data_t - server data
120  *
121  * @committed_params: the committed params (C,T,Prio) for the server
122  * @perceived_params: the params perceived by the user (we can lie to him)
123  * @current_priority: the current priority (0=background)
124  * @repl_list: the list of pending replenishment operations
125  * @repl_timer: the timer for the replenishments associated to this server
126  *     NOTE: we could use a single timer for all but for now this is simpler
127  * @act_time: the last activation time for the server
128  * @packet_list: the packets enqueued on this server
129  * @servers_list: the list of servers
130  */
131
132 typedef struct {
133         frescan_server_params_t committed_params;
134         frescan_server_params_t perceived_params;
135         frescan_network_t       net;
136         frescan_ss_t            id;
137         frescan_prio_t          current_priority;
138         frescan_budget_t        pending_packets;
139         frescan_repl_op_t       replenishments;
140         timer_t                 repl_timer;
141         struct timespec         act_time;
142         frescan_packet_t        packet_list;
143         struct list_head        servers_list;
144 } frescan_server_data_t;
145
146 /**
147  * the_servers_pool - pool of servers structure
148  */
149
150 extern frescan_server_data_t the_servers_pool[FRESCAN_MX_NETWORKS][FRESCAN_MX_IDS];
151 extern freelist_t the_servers_pool_freelist[FRESCAN_MX_NETWORKS];
152 extern frescan_server_data_t the_active_servers[FRESCAN_MX_NETWORKS];
153
154 /**
155  * frescan_sa_vres_t - a frescan vres
156  *
157  * @contract: the contract of the virtual resource
158  * @node: the node where the vres belongs to
159  * @ss: the sporadic server identifier
160  * @list: the list of vres. Note that this is the list of all the vres
161  *      in the network instace. As this is a master-slave protocol the master
162  *      knows everything about the contracts of the rest of nodes.
163  */
164
165 typedef enum {
166         FRESCAN_SA_PERIOD_DEC = 1<<5,
167         FRESCAN_SA_PERIOD_INC = 1<<4,
168         FRESCAN_SA_BUDGET_DEC = 1<<3,
169         FRESCAN_SA_BUDGET_INC = 1<<2,
170         FRESCAN_SA_PRIO_DEC   = 1<<1,
171         FRESCAN_SA_PRIO_INC   = 1
172 } frescan_sa_mode_change_type_t;
173
174 typedef struct {
175         frsh_contract_t    contract;
176         frescan_node_t     node;
177         frescan_ss_t       ss;
178         frsh_sa_vres_id_t  fsa_vres_global_id;
179         struct list_head   list;
180         // mode change variables
181         frsh_sa_time_t old_c;
182         frsh_sa_time_t old_t;
183         frsh_sa_prio_t old_p;
184         frescan_sa_mode_change_type_t mode_change_type;
185         struct list_head              mode_change_list;
186 } frescan_sa_vres_t;
187
188 /**
189  * frescan_sa_scenario_t - the scheduling analysis scenario
190  */
191
192 typedef struct {
193         frescan_prio_t    max_prio;
194         frescan_prio_t    min_prio;
195 } frescan_sa_init_params_t;
196
197 typedef struct {
198         frescan_sa_init_params_t init_params;
199         frescan_sa_vres_t vres_pool[FRESCAN_MX_NODES][FRESCAN_MX_IDS];
200         frescan_sa_vres_t vres_head;
201         freelist_t fsa_id_freelist;
202         frsh_sa_scenario_t fsa_scenario;
203 } frescan_sa_scenario_t;
204
205 /**
206  * frescan_prio_queue_t - priority queue
207  *
208  * FRESCAN priority queues are implemented as an array of one 'fifo_queue' for
209  * each priority. Where the 'fifo_queues' are implemented using the
210  * 'struct list_head fifo_list;' field of each packet structure (Linux lists).
211  *
212  * So far mutual exclusion is achieved by disabling interrupts and
213  * synchronization is done using a semaphore. This is because the queues
214  * are accesed concurrently from user threads and the IRQ handler.
215  *
216  * @net: the network this priority queue belongs to (mainly for locking)
217  * @fifo_queues: an array of packets for each priority where each packet
218  *               is just the head of a fifo_list. The array is allocated
219  *               from the heap, using malloc, at initialization with range
220  *               0..max_prio-1
221  * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
222  * @sem: semaphore used for synchronization
223  */
224
225 typedef struct {
226         frescan_network_t net;
227         frescan_packet_t *fifo_queues;
228         uint32_t max_prio;
229         sem_t sem;
230 } frescan_prio_queue_t;
231
232 /**
233  * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
234  *
235  * @tx_fp_queue: priority queue for the fixed priority packets
236  * @rx_channel_queues: a priority queue for each receiving channel
237  *
238  * TODO: add here the sporadic server queues...
239  */
240
241 typedef struct {
242         frescan_prio_queue_t *tx_fp_queue;
243         frescan_prio_queue_t **rx_channel_queues;
244         uint32_t num_rx_channels;
245 } frescan_queues_t;
246
247 /**
248  * frescan_network_data_t - data for each network instance
249  *
250  * @local_node: the local node id for that network. The implementation does not
251  * support several interfaces for the same network.
252  * @fd: file descriptor associated to /dev/canXX
253  * @repl_thread_id: replenishment thread id
254  * @manager_thread_id: manager thread id
255  * @acceptor_thread_id: acceptor thread id
256  * @neg_messages_ss_id: sporadic server for negotiation messages
257  * @queues: the queues of this network instance
258  * @last_packet: pointer to the last packet from which a frame was inserted
259  *               in the chip and its transmission is not complete.
260  * @last_packet_prio: prio of the packet in the buffer
261  * @id_queues: queues to store received packets while the whole message is
262  *             not complete (fragmentation). (id = 0 .. FRESCAN_MX_IDS - 1)
263  * @id_fp_queues: the same as id_queues but for fp messages, which have
264  *                id=FRESCAN_MX_IDS and are distinguised through their
265  *                priorities.
266  * @scenario: the scheduling analysis scenario for the network
267  *
268  * the implementation can handle several FRESCAN networks at the same time
269  * in the same node, so we need a place to store its internal data. The data
270  * is allocated as an array where the index is the MINOR number (which also
271  * identifies the /dev/canx device for that network)
272  */
273
274 typedef struct {
275         FRESCAN_MLOCK_T lock;
276         frescan_node_t local_node;
277         int fd;
278         fosa_thread_id_t repl_thread_id;
279         fosa_thread_id_t manager_thread_id;
280         fosa_thread_id_t acceptor_thread_id;
281         frescan_ss_t neg_messages_ss_id;
282         frescan_queues_t queues;
283         frescan_packet_t *last_packet;
284         frescan_prio_t last_packet_prio;
285         frescan_packet_t *id_queues[FRESCAN_MX_NODES][FRESCAN_MX_IDS];      // TODO: alloc at init
286         frescan_packet_t *id_fp_queues[FRESCAN_MX_NODES][FRESCAN_MX_PRIOS]; // TODO: alloc at init
287         frescan_sa_scenario_t scenario;
288         struct list_head mode_change_budget_inc_list_head[FRESCAN_MX_NODES];
289         struct list_head mode_change_budget_dec_list_head[FRESCAN_MX_NODES];
290 } frescan_network_data_t;
291
292 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
293
294 /**
295  * frescan_data_init() - init the data global variables
296  *
297  */
298
299 extern int frescan_data_init(int fd, frescan_init_params_t *params);
300
301 #endif // _MARTE_FRESCAN_DATA_H_