4 * @brief global data used from different modules in frescan
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.
20 * -----------------------------------------------------------------------
21 * Copyright (C) 2006 - 2008 FRESCOR consortium partners:
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
30 * Thales Communication S.A. FRANCE
31 * Visual Tools S.A. SPAIN
32 * Rapita Systems Ltd UK
35 * See http://www.frescor.org for a link to partners' websites
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
42 * This file is part of FRESCAN
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)
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.
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
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 * -----------------------------------------------------------------------
70 #ifndef _MARTE_FRESCAN_DATA_H_
71 #define _MARTE_FRESCAN_DATA_H_
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
78 #include <misc/linux_list.h> // struct list_head
79 #include <misc/freelist.h> // freelist_t
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
85 #include "frsh.h" // for frsh_contract_t
86 #include "fsa.h" // for frsh_sa_scenario_t
89 * frescan_repl_op_t - a replenishment operation
91 * @when: when the replenishment operation is programmed at
92 * @amount: number of frames to add to the current_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
99 frescan_budget_t amount;
100 struct list_head repl_list;
105 * frescan_server_params_t - server parameters
107 * @budget: the budget in CAN 8-byte frames
108 * @period: the replenishment period for the server
109 * @prio: the priority of the server
113 frescan_budget_t budget;
114 struct timespec period;
116 } frescan_server_params_t;
119 * frescan_server_data_t - server data
121 * @params: the fixed parameters (budget, period and priority)
122 * @current_budget: the current available capacity
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
133 frescan_server_params_t params;
134 frescan_network_t net;
136 frescan_budget_t current_budget;
137 frescan_prio_t current_priority;
138 frescan_budget_t pending_packets;
139 frescan_repl_op_t replenishments;
141 struct timespec act_time;
142 frescan_packet_t packet_list;
143 struct list_head servers_list;
144 } frescan_server_data_t;
147 * the_servers_pool - pool of servers structure
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];
155 * frescan_sa_vres_t - a frescan vres
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.
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;
175 frsh_contract_t contract;
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;
189 * frescan_sa_scenario_t - the scheduling analysis scenario
193 frescan_prio_t max_prio;
194 frescan_prio_t min_prio;
195 } frescan_sa_init_params_t;
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;
206 * frescan_prio_queue_t - priority queue
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).
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.
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
221 * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
222 * @sem: semaphore used for synchronization
226 frescan_network_t net;
227 frescan_packet_t *fifo_queues;
230 } frescan_prio_queue_t;
233 * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
235 * @tx_fp_queue: priority queue for the fixed priority packets
236 * @rx_channel_queues: a priority queue for each receiving channel
238 * TODO: add here the sporadic server queues...
242 frescan_prio_queue_t *tx_fp_queue;
243 frescan_prio_queue_t **rx_channel_queues;
244 uint32_t num_rx_channels;
248 * frescan_network_data_t - data for each network instance
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
266 * @scenario: the scheduling analysis scenario for the network
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)
275 FRESCAN_MLOCK_T lock;
276 frescan_node_t local_node;
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;
292 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
295 * frescan_data_init() - init the data global variables
299 extern int frescan_data_init(int fd, frescan_init_params_t *params);
301 #endif // _MARTE_FRESCAN_DATA_H_