##// END OF EJS Templates
1039 problème de centrage des snapshots avec FSW 3.2.0.12
paul -
r363:071a09d6f71c R3++ draft
parent child
Show More
@@ -1,1343 +1,1343
1 1 /** Functions and tasks related to waveform packet generation.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 7 *
8 8 */
9 9
10 10 #include "wf_handler.h"
11 11
12 12 //***************
13 13 // waveform rings
14 14 // F0
15 15 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
16 16 ring_node *current_ring_node_f0 = NULL;
17 17 ring_node *ring_node_to_send_swf_f0 = NULL;
18 18 // F1
19 19 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
20 20 ring_node *current_ring_node_f1 = NULL;
21 21 ring_node *ring_node_to_send_swf_f1 = NULL;
22 22 ring_node *ring_node_to_send_cwf_f1 = NULL;
23 23 // F2
24 24 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
25 25 ring_node *current_ring_node_f2 = NULL;
26 26 ring_node *ring_node_to_send_swf_f2 = NULL;
27 27 ring_node *ring_node_to_send_cwf_f2 = NULL;
28 28 // F3
29 29 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
30 30 ring_node *current_ring_node_f3 = NULL;
31 31 ring_node *ring_node_to_send_cwf_f3 = NULL;
32 32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
33 33
34 34 bool extractSWF1 = false;
35 35 bool extractSWF2 = false;
36 36 bool swf0_ready_flag_f1 = false;
37 37 bool swf0_ready_flag_f2 = false;
38 38 bool swf1_ready = false;
39 39 bool swf2_ready = false;
40 40
41 41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
42 42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
43 43 ring_node ring_node_swf1_extracted = {0};
44 44 ring_node ring_node_swf2_extracted = {0};
45 45
46 46 typedef enum resynchro_state_t
47 47 {
48 48 MEASURE,
49 49 CORRECTION
50 50 } resynchro_state;
51 51
52 52 //*********************
53 53 // Interrupt SubRoutine
54 54
55 55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 56 {
57 57 ring_node *node;
58 58
59 59 node = NULL;
60 60 switch ( frequencyChannel ) {
61 61 case CHANNELF1:
62 62 node = ring_node_to_send_cwf_f1;
63 63 break;
64 64 case CHANNELF2:
65 65 node = ring_node_to_send_cwf_f2;
66 66 break;
67 67 case CHANNELF3:
68 68 node = ring_node_to_send_cwf_f3;
69 69 break;
70 70 default:
71 71 break;
72 72 }
73 73
74 74 return node;
75 75 }
76 76
77 77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 78 {
79 79 ring_node *node;
80 80
81 81 node = NULL;
82 82 switch ( frequencyChannel ) {
83 83 case CHANNELF0:
84 84 node = ring_node_to_send_swf_f0;
85 85 break;
86 86 case CHANNELF1:
87 87 node = ring_node_to_send_swf_f1;
88 88 break;
89 89 case CHANNELF2:
90 90 node = ring_node_to_send_swf_f2;
91 91 break;
92 92 default:
93 93 break;
94 94 }
95 95
96 96 return node;
97 97 }
98 98
99 99 void reset_extractSWF( void )
100 100 {
101 101 extractSWF1 = false;
102 102 extractSWF2 = false;
103 103 swf0_ready_flag_f1 = false;
104 104 swf0_ready_flag_f2 = false;
105 105 swf1_ready = false;
106 106 swf2_ready = false;
107 107 }
108 108
109 109 inline void waveforms_isr_f3( void )
110 110 {
111 111 rtems_status_code spare_status;
112 112
113 113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 116 //***
117 117 // F3
118 118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 120 current_ring_node_f3 = current_ring_node_f3->next;
121 121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 126 }
127 127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 132 }
133 133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 135 }
136 136 }
137 137 }
138 138 }
139 139
140 140 inline void waveforms_isr_burst( void )
141 141 {
142 142 unsigned char status;
143 143 rtems_status_code spare_status;
144 144
145 145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146 146
147 147 switch(status)
148 148 {
149 149 case BIT_WFP_BUFFER_0:
150 150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
151 151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
152 152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
153 153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
154 154 current_ring_node_f2 = current_ring_node_f2->next;
155 155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
156 156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
157 157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 158 }
159 159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
160 160 break;
161 161 case BIT_WFP_BUFFER_1:
162 162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
163 163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
164 164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
165 165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
166 166 current_ring_node_f2 = current_ring_node_f2->next;
167 167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
168 168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
169 169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
170 170 }
171 171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
172 172 break;
173 173 default:
174 174 break;
175 175 }
176 176 }
177 177
178 178 inline void waveform_isr_normal_sbm1_sbm2( void )
179 179 {
180 180 rtems_status_code status;
181 181
182 182 //***
183 183 // F0
184 184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
185 185 {
186 186 swf0_ready_flag_f1 = true;
187 187 swf0_ready_flag_f2 = true;
188 188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
189 189 current_ring_node_f0 = current_ring_node_f0->next;
190 190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
191 191 {
192 192
193 193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
194 194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
195 195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
196 196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
197 197 }
198 198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
199 199 {
200 200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
201 201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
202 202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
203 203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
204 204 }
205 205 // send an event to the WFRM task for resynchro activities
206 206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
207 207 }
208 208
209 209 //***
210 210 // F1
211 211 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
212 212 // (1) change the receiving buffer for the waveform picker
213 213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
214 214 current_ring_node_f1 = current_ring_node_f1->next;
215 215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
216 216 {
217 217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
218 218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
219 219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
220 220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
221 221 }
222 222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
223 223 {
224 224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
225 225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
226 226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
227 227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
228 228 }
229 229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
230 230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
231 231 }
232 232
233 233 //***
234 234 // F2
235 235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
236 236 // (1) change the receiving buffer for the waveform picker
237 237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
238 238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
239 239 current_ring_node_f2 = current_ring_node_f2->next;
240 240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
241 241 {
242 242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
243 243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
244 244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
245 245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
246 246 }
247 247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
248 248 {
249 249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
250 250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
251 251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
252 252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
253 253 }
254 254 // (2) send an event for the waveforms transmission
255 255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
256 256 }
257 257 }
258 258
259 259 rtems_isr waveforms_isr( rtems_vector_number vector )
260 260 {
261 261 /** This is the interrupt sub routine called by the waveform picker core.
262 262 *
263 263 * This ISR launch different actions depending mainly on two pieces of information:
264 264 * 1. the values read in the registers of the waveform picker.
265 265 * 2. the current LFR mode.
266 266 *
267 267 */
268 268
269 269 // STATUS
270 270 // new error error buffer full
271 271 // 15 14 13 12 11 10 9 8
272 272 // f3 f2 f1 f0 f3 f2 f1 f0
273 273 //
274 274 // ready buffer
275 275 // 7 6 5 4 3 2 1 0
276 276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
277 277
278 278 rtems_status_code spare_status;
279 279
280 280 waveforms_isr_f3();
281 281
282 282 //*************************************************
283 283 // copy the status bits in the housekeeping packets
284 284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
285 285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
286 286
287 287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
288 288 {
289 289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
290 290 }
291 291
292 292 switch(lfrCurrentMode)
293 293 {
294 294 //********
295 295 // STANDBY
296 296 case LFR_MODE_STANDBY:
297 297 break;
298 298 //**************************
299 299 // LFR NORMAL, SBM1 and SBM2
300 300 case LFR_MODE_NORMAL:
301 301 case LFR_MODE_SBM1:
302 302 case LFR_MODE_SBM2:
303 303 waveform_isr_normal_sbm1_sbm2();
304 304 break;
305 305 //******
306 306 // BURST
307 307 case LFR_MODE_BURST:
308 308 waveforms_isr_burst();
309 309 break;
310 310 //********
311 311 // DEFAULT
312 312 default:
313 313 break;
314 314 }
315 315 }
316 316
317 317 //************
318 318 // RTEMS TASKS
319 319
320 320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
321 321 {
322 322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
323 323 *
324 324 * @param unused is the starting argument of the RTEMS task
325 325 *
326 326 * The following data packets are sent by this task:
327 327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
328 328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
329 329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
330 330 *
331 331 */
332 332
333 333 rtems_event_set event_out;
334 334 rtems_id queue_id;
335 335 rtems_status_code status;
336 336 ring_node *ring_node_swf1_extracted_ptr;
337 337 ring_node *ring_node_swf2_extracted_ptr;
338 338
339 339 event_out = EVENT_SETS_NONE_PENDING;
340 340 queue_id = RTEMS_ID_NONE;
341 341
342 342 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
343 343 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
344 344
345 345 status = get_message_queue_id_send( &queue_id );
346 346 if (status != RTEMS_SUCCESSFUL)
347 347 {
348 348 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
349 349 }
350 350
351 351 BOOT_PRINTF("in WFRM ***\n");
352 352
353 353 while(1){
354 354 // wait for an RTEMS_EVENT
355 355 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
356 356 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
357 357
358 358 if (event_out == RTEMS_EVENT_MODE_NORMAL)
359 359 {
360 360 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
361 361 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
362 362 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
363 363 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
364 364 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
365 365 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
366 366 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
367 367 }
368 368 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
369 369 {
370 370 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
371 371 }
372 372 }
373 373 }
374 374
375 375 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
376 376 {
377 377 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
378 378 *
379 379 * @param unused is the starting argument of the RTEMS task
380 380 *
381 381 * The following data packet is sent by this task:
382 382 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
383 383 *
384 384 */
385 385
386 386 rtems_event_set event_out;
387 387 rtems_id queue_id;
388 388 rtems_status_code status;
389 389 ring_node ring_node_cwf3_light;
390 390 ring_node *ring_node_to_send_cwf;
391 391
392 392 event_out = EVENT_SETS_NONE_PENDING;
393 393 queue_id = RTEMS_ID_NONE;
394 394
395 395 status = get_message_queue_id_send( &queue_id );
396 396 if (status != RTEMS_SUCCESSFUL)
397 397 {
398 398 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
399 399 }
400 400
401 401 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
402 402
403 403 // init the ring_node_cwf3_light structure
404 404 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
405 405 ring_node_cwf3_light.coarseTime = INIT_CHAR;
406 406 ring_node_cwf3_light.fineTime = INIT_CHAR;
407 407 ring_node_cwf3_light.next = NULL;
408 408 ring_node_cwf3_light.previous = NULL;
409 409 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
410 410 ring_node_cwf3_light.status = INIT_CHAR;
411 411
412 412 BOOT_PRINTF("in CWF3 ***\n");
413 413
414 414 while(1){
415 415 // wait for an RTEMS_EVENT
416 416 rtems_event_receive( RTEMS_EVENT_0,
417 417 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
418 418 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
419 419 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
420 420 {
421 421 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
422 422 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
423 423 {
424 424 PRINTF("send CWF_LONG_F3\n");
425 425 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
426 426 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
427 427 }
428 428 else
429 429 {
430 430 PRINTF("send CWF_F3 (light)\n");
431 431 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
432 432 }
433 433
434 434 }
435 435 else
436 436 {
437 437 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
438 438 }
439 439 }
440 440 }
441 441
442 442 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
443 443 {
444 444 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
445 445 *
446 446 * @param unused is the starting argument of the RTEMS task
447 447 *
448 448 * The following data packet is sent by this function:
449 449 * - TM_LFR_SCIENCE_BURST_CWF_F2
450 450 * - TM_LFR_SCIENCE_SBM2_CWF_F2
451 451 *
452 452 */
453 453
454 454 rtems_event_set event_out;
455 455 rtems_id queue_id;
456 456 rtems_status_code status;
457 457 ring_node *ring_node_to_send;
458 458 unsigned long long int acquisitionTimeF0_asLong;
459 459
460 460 event_out = EVENT_SETS_NONE_PENDING;
461 461 queue_id = RTEMS_ID_NONE;
462 462
463 463 acquisitionTimeF0_asLong = INIT_CHAR;
464 464
465 465 status = get_message_queue_id_send( &queue_id );
466 466 if (status != RTEMS_SUCCESSFUL)
467 467 {
468 468 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
469 469 }
470 470
471 471 BOOT_PRINTF("in CWF2 ***\n");
472 472
473 473 while(1){
474 474 // wait for an RTEMS_EVENT// send the snapshot when built
475 475 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
476 476 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
477 477 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
478 478 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
479 479 if (event_out == RTEMS_EVENT_MODE_BURST)
480 480 { // data are sent whatever the transition time
481 481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
482 482 }
483 483 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
484 484 {
485 485 if ( lfrCurrentMode == LFR_MODE_SBM2 )
486 486 {
487 487 // data are sent depending on the transition time
488 488 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
489 489 {
490 490 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
491 491 }
492 492 }
493 493 // launch snapshot extraction if needed
494 494 if (extractSWF2 == true)
495 495 {
496 496 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
497 497 // extract the snapshot
498 498 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
499 499 &ring_node_swf2_extracted, swf2_extracted );
500 500 extractSWF2 = false;
501 501 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
502 502 }
503 503 if (swf0_ready_flag_f2 == true)
504 504 {
505 505 extractSWF2 = true;
506 506 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
507 507 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
508 508 swf0_ready_flag_f2 = false;
509 509 }
510 510 }
511 511 }
512 512 }
513 513
514 514 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
515 515 {
516 516 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
517 517 *
518 518 * @param unused is the starting argument of the RTEMS task
519 519 *
520 520 * The following data packet is sent by this function:
521 521 * - TM_LFR_SCIENCE_SBM1_CWF_F1
522 522 *
523 523 */
524 524
525 525 rtems_event_set event_out;
526 526 rtems_id queue_id;
527 527 rtems_status_code status;
528 528
529 529 ring_node *ring_node_to_send_cwf;
530 530
531 531 event_out = EVENT_SETS_NONE_PENDING;
532 532 queue_id = RTEMS_ID_NONE;
533 533
534 534 status = get_message_queue_id_send( &queue_id );
535 535 if (status != RTEMS_SUCCESSFUL)
536 536 {
537 537 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
538 538 }
539 539
540 540 BOOT_PRINTF("in CWF1 ***\n");
541 541
542 542 while(1){
543 543 // wait for an RTEMS_EVENT
544 544 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
545 545 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
546 546 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
547 547 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
548 548 if (lfrCurrentMode == LFR_MODE_SBM1)
549 549 {
550 550 // data are sent depending on the transition time
551 551 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
552 552 {
553 553 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
554 554 }
555 555 }
556 556 // launch snapshot extraction if needed
557 557 if (extractSWF1 == true)
558 558 {
559 559 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
560 560 // launch the snapshot extraction
561 561 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
562 562 extractSWF1 = false;
563 563 }
564 564 if (swf0_ready_flag_f1 == true)
565 565 {
566 566 extractSWF1 = true;
567 567 swf0_ready_flag_f1 = false; // this step shall be executed only one time
568 568 }
569 569 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
570 570 {
571 571 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
572 572 swf1_ready = false;
573 573 swf2_ready = false;
574 574 }
575 575 }
576 576 }
577 577
578 578 rtems_task swbd_task(rtems_task_argument argument)
579 579 {
580 580 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
581 581 *
582 582 * @param unused is the starting argument of the RTEMS task
583 583 *
584 584 */
585 585
586 586 rtems_event_set event_out;
587 587 unsigned long long int acquisitionTimeF0_asLong;
588 588
589 589 event_out = EVENT_SETS_NONE_PENDING;
590 590 acquisitionTimeF0_asLong = INIT_CHAR;
591 591
592 592 BOOT_PRINTF("in SWBD ***\n")
593 593
594 594 while(1){
595 595 // wait for an RTEMS_EVENT
596 596 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
597 597 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
598 598 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
599 599 {
600 600 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
601 601 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
602 602 &ring_node_swf1_extracted, swf1_extracted );
603 603 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
604 604 }
605 605 else
606 606 {
607 607 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
608 608 }
609 609 }
610 610 }
611 611
612 612 //******************
613 613 // general functions
614 614
615 615 void WFP_init_rings( void )
616 616 {
617 617 // F0 RING
618 618 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
619 619 // F1 RING
620 620 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
621 621 // F2 RING
622 622 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
623 623 // F3 RING
624 624 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
625 625
626 626 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
627 627 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
628 628
629 629 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
630 630 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
631 631 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
632 632 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
633 633 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
634 634 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
635 635 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
636 636 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
637 637
638 638 }
639 639
640 640 void WFP_reset_current_ring_nodes( void )
641 641 {
642 642 current_ring_node_f0 = waveform_ring_f0[0].next;
643 643 current_ring_node_f1 = waveform_ring_f1[0].next;
644 644 current_ring_node_f2 = waveform_ring_f2[0].next;
645 645 current_ring_node_f3 = waveform_ring_f3[0].next;
646 646
647 647 ring_node_to_send_swf_f0 = waveform_ring_f0;
648 648 ring_node_to_send_swf_f1 = waveform_ring_f1;
649 649 ring_node_to_send_swf_f2 = waveform_ring_f2;
650 650
651 651 ring_node_to_send_cwf_f1 = waveform_ring_f1;
652 652 ring_node_to_send_cwf_f2 = waveform_ring_f2;
653 653 ring_node_to_send_cwf_f3 = waveform_ring_f3;
654 654 }
655 655
656 656 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
657 657 {
658 658 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
659 659 *
660 660 * @param waveform points to the buffer containing the data that will be send.
661 661 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
662 662 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
663 663 * contain information to setup the transmission of the data packets.
664 664 *
665 665 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
666 666 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
667 667 *
668 668 */
669 669
670 670 unsigned int i;
671 671 unsigned int j;
672 672 int ret;
673 673 rtems_status_code status;
674 674
675 675 char *sample;
676 676 int *dataPtr;
677 677
678 678 ret = LFR_DEFAULT;
679 679
680 680 dataPtr = (int*) ring_node_to_send->buffer_address;
681 681
682 682 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
683 683 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
684 684
685 685 //**********************
686 686 // BUILD CWF3_light DATA
687 687 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
688 688 {
689 689 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
690 690 for (j=0; j < CWF_BLK_SIZE; j++)
691 691 {
692 692 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
693 693 }
694 694 }
695 695
696 696 // SEND PACKET
697 697 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
698 698 if (status != RTEMS_SUCCESSFUL) {
699 699 ret = LFR_DEFAULT;
700 700 }
701 701
702 702 return ret;
703 703 }
704 704
705 705 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
706 706 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
707 707 {
708 708 unsigned long long int acquisitionTimeAsLong;
709 709 unsigned char localAcquisitionTime[BYTES_PER_TIME];
710 710 double deltaT;
711 711
712 712 deltaT = INIT_FLOAT;
713 713
714 714 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
715 715 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
716 716 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
717 717 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
718 718 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
719 719 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
720 720
721 721 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
722 722 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
723 723 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
724 724 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
725 725 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
726 726 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
727 727
728 728 switch( sid )
729 729 {
730 730 case SID_NORM_SWF_F0:
731 731 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
732 732 break;
733 733
734 734 case SID_NORM_SWF_F1:
735 735 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
736 736 break;
737 737
738 738 case SID_NORM_SWF_F2:
739 739 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
740 740 break;
741 741
742 742 case SID_SBM1_CWF_F1:
743 743 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
744 744 break;
745 745
746 746 case SID_SBM2_CWF_F2:
747 747 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
748 748 break;
749 749
750 750 case SID_BURST_CWF_F2:
751 751 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
752 752 break;
753 753
754 754 case SID_NORM_CWF_F3:
755 755 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
756 756 break;
757 757
758 758 case SID_NORM_CWF_LONG_F3:
759 759 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
760 760 break;
761 761
762 762 default:
763 763 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
764 764 deltaT = 0.;
765 765 break;
766 766 }
767 767
768 768 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
769 769 //
770 770 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
771 771 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
772 772 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
773 773 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
774 774 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
775 775 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
776 776
777 777 }
778 778
779 779 void build_snapshot_from_ring( ring_node *ring_node_to_send,
780 780 unsigned char frequencyChannel,
781 781 unsigned long long int acquisitionTimeF0_asLong,
782 782 ring_node *ring_node_swf_extracted,
783 783 int *swf_extracted)
784 784 {
785 785 unsigned int i;
786 786 unsigned int node;
787 787 unsigned long long int centerTime_asLong;
788 788 unsigned long long int acquisitionTime_asLong;
789 789 unsigned long long int bufferAcquisitionTime_asLong;
790 790 unsigned char *ptr1;
791 791 unsigned char *ptr2;
792 792 unsigned char *timeCharPtr;
793 793 unsigned char nb_ring_nodes;
794 794 unsigned long long int frequency_asLong;
795 795 unsigned long long int nbTicksPerSample_asLong;
796 796 unsigned long long int nbSamplesPart1_asLong;
797 797 unsigned long long int sampleOffset_asLong;
798 798
799 799 unsigned int deltaT_F0;
800 800 unsigned int deltaT_F1;
801 801 unsigned long long int deltaT_F2;
802 802
803 803 deltaT_F0 = DELTAT_F0;
804 deltaT_F1 = DELTAF_F1;
805 deltaT_F2 = DELTAF_F2;
804 deltaT_F1 = DELTAT_F1;
805 deltaT_F2 = DELTAT_F2;
806 806 sampleOffset_asLong = INIT_CHAR;
807 807
808 808 // (1) get the f0 acquisition time => the value is passed in argument
809 809
810 810 // (2) compute the central reference time
811 811 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
812 812 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
813 813 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
814 814 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
815 815
816 816 // (3) compute the acquisition time of the current snapshot
817 817 switch(frequencyChannel)
818 818 {
819 819 case CHANNELF1: // 1 is for F1 = 4096 Hz
820 820 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
821 821 nb_ring_nodes = NB_RING_NODES_F1;
822 822 frequency_asLong = FREQ_F1;
823 823 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
824 824 break;
825 825 case CHANNELF2: // 2 is for F2 = 256 Hz
826 826 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
827 827 nb_ring_nodes = NB_RING_NODES_F2;
828 828 frequency_asLong = FREQ_F2;
829 829 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
830 830 break;
831 831 default:
832 832 acquisitionTime_asLong = centerTime_asLong;
833 833 nb_ring_nodes = 0;
834 834 frequency_asLong = FREQ_F2;
835 835 nbTicksPerSample_asLong = TICKS_PER_T2;
836 836 break;
837 837 }
838 838
839 839 //*****************************************************************************
840 840 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
841 841 node = 0;
842 842 while ( node < nb_ring_nodes)
843 843 {
844 844 //PRINTF1("%d ... ", node);
845 845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
846 846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
847 847 {
848 848 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
849 849 node = nb_ring_nodes;
850 850 }
851 851 else
852 852 {
853 853 node = node + 1;
854 854 ring_node_to_send = ring_node_to_send->previous;
855 855 }
856 856 }
857 857
858 858 // (5) compute the number of samples to take in the current buffer
859 859 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
860 860 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
861 861 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
862 862
863 863 // (6) compute the final acquisition time
864 864 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
865 865 (sampleOffset_asLong * nbTicksPerSample_asLong);
866 866
867 867 // (7) copy the acquisition time at the beginning of the extrated snapshot
868 868 ptr1 = (unsigned char*) &acquisitionTime_asLong;
869 869 // fine time
870 870 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
871 871 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
872 872 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
873 873 // coarse time
874 874 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
875 875 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
876 876 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
877 877 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
878 878 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
879 879
880 880 // re set the synchronization bit
881 881 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
882 882 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
883 883
884 884 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
885 885 {
886 886 nbSamplesPart1_asLong = 0;
887 887 }
888 888 // copy the part 1 of the snapshot in the extracted buffer
889 889 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
890 890 {
891 891 swf_extracted[i] =
892 892 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SW