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