##// END OF EJS Templates
sync
paul -
r183:a41da50c1d4b VHDL_0_1_28
parent child
Show More
@@ -1,2 +1,2
1 0f2eb26d750be2b6d8a3f5dee479b4575d3b93be LFR_basic-parameters
1 cc82265fd480dbd0344bbf888476c76602b3e9c0 LFR_basic-parameters
2 2 95a8d83f1d0c59f28a679e66e23464f21c12dd8a header/lfr_common_headers
@@ -1,397 +1,397
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf0_prc0.h"
11 11 #include "fsw_processing.h"
12 12
13 13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14 14
15 15 //***
16 16 // F0
17 17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19 19
20 20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
22 22
23 23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
24 24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
26 26
27 27 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
28 28 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
29 29 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
30 30
31 31 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
32 32 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
33 33
34 34 //************
35 35 // RTEMS TASKS
36 36
37 37 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
38 38 {
39 39 int i;
40 40
41 41 rtems_event_set event_out;
42 42 rtems_status_code status;
43 43 rtems_id queue_id_prc0;
44 44 asm_msg msgForMATR;
45 45 ring_node *nodeForAveraging;
46 46 ring_node *ring_node_tab[8];
47 47 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
48 48 ring_node_asm *current_ring_node_asm_norm_f0;
49 49
50 50 unsigned int nb_norm_bp1;
51 51 unsigned int nb_norm_bp2;
52 52 unsigned int nb_norm_asm;
53 53 unsigned int nb_sbm_bp1;
54 54 unsigned int nb_sbm_bp2;
55 55
56 56 nb_norm_bp1 = 0;
57 57 nb_norm_bp2 = 0;
58 58 nb_norm_asm = 0;
59 59 nb_sbm_bp1 = 0;
60 60 nb_sbm_bp2 = 0;
61 61
62 62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67 67
68 68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69 69
70 70 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 71 if (status != RTEMS_SUCCESSFUL)
72 72 {
73 73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 74 }
75 75
76 76 while(1){
77 77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78 78
79 79 //****************************************
80 80 // initialize the mesage for the MATR task
81 81 msgForMATR.norm = current_ring_node_asm_norm_f0;
82 82 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 83 msgForMATR.event = 0x00; // this composite event will be sent to the PRC0 task
84 84 //
85 85 //****************************************
86 86
87 87 nodeForAveraging = getRingNodeForAveraging( 0 );
88 88
89 89 ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging;
90 90 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
91 91 {
92 92 nodeForAveraging = nodeForAveraging->previous;
93 93 ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging;
94 94 }
95 95
96 96 // compute the average and store it in the averaged_sm_f1 buffer
97 97 SM_average( current_ring_node_asm_norm_f0->matrix,
98 98 current_ring_node_asm_burst_sbm_f0->matrix,
99 99 ring_node_tab,
100 100 nb_norm_bp1, nb_sbm_bp1,
101 101 &msgForMATR );
102 102
103 103 // update nb_average
104 104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
105 105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
106 106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
107 107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
108 108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
109 109
110 110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 111 {
112 112 nb_sbm_bp1 = 0;
113 113 // set another ring for the ASM storage
114 114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 115 if ( lfrCurrentMode == LFR_MODE_BURST )
116 116 {
117 117 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0;
118 118 }
119 119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 120 {
121 121 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0;
122 122 }
123 123 }
124 124
125 125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 126 {
127 127 nb_sbm_bp2 = 0;
128 128 if ( lfrCurrentMode == LFR_MODE_BURST )
129 129 {
130 130 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0;
131 131 }
132 132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 133 {
134 134 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0;
135 135 }
136 136 }
137 137
138 138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 139 {
140 140 nb_norm_bp1 = 0;
141 141 // set another ring for the ASM storage
142 142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 145 {
146 146 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0;
147 147 }
148 148 }
149 149
150 150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 151 {
152 152 nb_norm_bp2 = 0;
153 153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 155 {
156 156 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0;
157 157 }
158 158 }
159 159
160 160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 161 {
162 162 nb_norm_asm = 0;
163 163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 165 {
166 166 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0;
167 167 }
168 168 }
169 169
170 170 //*************************
171 171 // send the message to MATR
172 172 if (msgForMATR.event != 0x00)
173 173 {
174 174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0);
175 175 }
176 176
177 177 if (status != RTEMS_SUCCESSFUL) {
178 178 printf("in AVF0 *** Error sending message to MATR, code %d\n", status);
179 179 }
180 180 }
181 181 }
182 182
183 183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 184 {
185 185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 186 size_t size; // size of the incoming TC packet
187 187 asm_msg *incomingMsg;
188 188 //
189 189 unsigned char sid;
190 190 rtems_status_code status;
191 191 rtems_id queue_id;
192 192 rtems_id queue_id_q_p0;
193 193 bp_packet_with_spare packet_norm_bp1;
194 194 bp_packet packet_norm_bp2;
195 195 bp_packet packet_sbm_bp1;
196 196 bp_packet packet_sbm_bp2;
197 197 ring_node *current_ring_node_to_send_asm_f0;
198 198
199 199 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 200 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
201 201 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
202 202
203 203 //*************
204 204 // NORM headers
205 205 BP_init_header_with_spare( &packet_norm_bp1,
206 206 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
207 207 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
208 208 BP_init_header( &packet_norm_bp2,
209 209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
210 210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
211 211
212 212 //****************************
213 213 // BURST SBM1 and SBM2 headers
214 214 if ( lfrRequestedMode == LFR_MODE_BURST )
215 215 {
216 216 BP_init_header( &packet_sbm_bp1,
217 217 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
218 218 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
219 219 BP_init_header( &packet_sbm_bp2,
220 220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
221 221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
222 222 }
223 223 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
224 224 {
225 225 BP_init_header( &packet_sbm_bp1,
226 226 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
227 227 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
228 228 BP_init_header( &packet_sbm_bp2,
229 229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
230 230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
231 231 }
232 232 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
233 233 {
234 234 BP_init_header( &packet_sbm_bp1,
235 235 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
236 236 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
237 237 BP_init_header( &packet_sbm_bp2,
238 238 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
239 239 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
240 240 }
241 241 else
242 242 {
243 243 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
244 244 }
245 245
246 246 status = get_message_queue_id_send( &queue_id );
247 247 if (status != RTEMS_SUCCESSFUL)
248 248 {
249 249 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
250 250 }
251 251 status = get_message_queue_id_prc0( &queue_id_q_p0);
252 252 if (status != RTEMS_SUCCESSFUL)
253 253 {
254 254 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
255 255 }
256 256
257 257 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
258 258
259 259 while(1){
260 260 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
261 261 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
262 262
263 263 incomingMsg = (asm_msg*) incomingData;
264 264
265 265 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
266 266 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
267 267
268 268 //****************
269 269 //****************
270 270 // BURST SBM1 SBM2
271 271 //****************
272 272 //****************
273 273 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
274 274 {
275 275 sid = getSID( incomingMsg->event );
276 276 // 1) compress the matrix for Basic Parameters calculation
277 277 ASM_compress_reorganize_and_divide( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
278 278 nb_sm_before_f0.burst_sbm_bp1,
279 279 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
280 280 ASM_F0_INDICE_START);
281 281 // 2) compute the BP1 set
282 // BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
282 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
283 283 // 3) send the BP1 set
284 284 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
285 285 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
286 286 BP_send( (char *) &packet_sbm_bp1, queue_id,
287 287 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
288 288 sid);
289 289 // 4) compute the BP2 set if needed
290 290 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
291 291 {
292 292 // 1) compute the BP2 set
293 293 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
294 294 // 2) send the BP2 set
295 295 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
296 296 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
297 297 BP_send( (char *) &packet_sbm_bp2, queue_id,
298 298 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
299 299 sid);
300 300 }
301 301 }
302 302
303 303 //*****
304 304 //*****
305 305 // NORM
306 306 //*****
307 307 //*****
308 308 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
309 309 {
310 310 // 1) compress the matrix for Basic Parameters calculation
311 311 ASM_compress_reorganize_and_divide( asm_f0_patched_norm, compressed_sm_norm_f0,
312 312 nb_sm_before_f0.norm_bp1,
313 313 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
314 314 ASM_F0_INDICE_START );
315 315 // 2) compute the BP1 set
316 // BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
316 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
317 317 // 3) send the BP1 set
318 318 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 319 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
320 320 BP_send( (char *) &packet_norm_bp1, queue_id,
321 321 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
322 322 SID_NORM_BP1_F0 );
323 323 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
324 324 {
325 325 // 1) compute the BP2 set using the same ASM as the one used for BP1
326 326 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
327 327 // 2) send the BP2 set
328 328 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 329 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
330 330 BP_send( (char *) &packet_norm_bp2, queue_id,
331 331 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
332 332 SID_NORM_BP2_F0);
333 333 }
334 334 }
335 335
336 336 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
337 337 {
338 338 // 1) reorganize the ASM and divide
339 339 ASM_reorganize_and_divide( asm_f0_patched_norm,
340 340 asm_f0_reorganized,
341 341 nb_sm_before_f0.norm_bp1 );
342 342 // 2) convert the float array in a char array
343 343 ASM_convert( asm_f0_reorganized, (char*) current_ring_node_to_send_asm_f0->buffer_address );
344 344 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
345 345 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
346 346 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
347 347
348 348 // 3) send the spectral matrix packets
349 349 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
350 350 // change asm ring node
351 351 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
352 352 }
353 353 }
354 354 }
355 355
356 356 //**********
357 357 // FUNCTIONS
358 358
359 359 void reset_nb_sm_f0( unsigned char lfrMode )
360 360 {
361 361 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
362 362 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
363 363 nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96;
364 364 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
365 365 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
366 366 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
367 367 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
368 368 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
369 369 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
370 370
371 371 if (lfrMode == LFR_MODE_SBM1)
372 372 {
373 373 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
374 374 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
375 375 }
376 376 else if (lfrMode == LFR_MODE_SBM2)
377 377 {
378 378 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
379 379 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
380 380 }
381 381 else if (lfrMode == LFR_MODE_BURST)
382 382 {
383 383 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
384 384 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
385 385 }
386 386 else
387 387 {
388 388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
389 389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
390 390 }
391 391 }
392 392
393 393 void init_k_coefficients_f0( void )
394 394 {
395 395 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
396 396 init_k_coefficients( k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0);
397 397 }
@@ -1,379 +1,385
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf1_prc1.h"
11 11
12 12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13 13
14 14 extern ring_node sm_ring_f1[ ];
15 15
16 16 //***
17 17 // F1
18 18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
19 19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
20 20
21 21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
22 22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
23 23
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
24 26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
27
25 28 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
26 29 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
27 30 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
28 31
29 32 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
30 33 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
31 34
32 35 //************
33 36 // RTEMS TASKS
34 37
35 38 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 39 {
37 40 int i;
38 41
39 42 rtems_event_set event_out;
40 43 rtems_status_code status;
41 44 rtems_id queue_id_prc1;
42 45 asm_msg msgForMATR;
43 46 ring_node *nodeForAveraging;
44 47 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
45 48 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 49 ring_node_asm *current_ring_node_asm_norm_f1;
47 50
48 51 unsigned int nb_norm_bp1;
49 52 unsigned int nb_norm_bp2;
50 53 unsigned int nb_norm_asm;
51 54 unsigned int nb_sbm_bp1;
52 55 unsigned int nb_sbm_bp2;
53 56
54 57 nb_norm_bp1 = 0;
55 58 nb_norm_bp2 = 0;
56 59 nb_norm_asm = 0;
57 60 nb_sbm_bp1 = 0;
58 61 nb_sbm_bp2 = 0;
59 62
60 63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
61 64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
62 65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
63 66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
64 67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
65 68
66 69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
67 70
68 71 status = get_message_queue_id_prc1( &queue_id_prc1 );
69 72 if (status != RTEMS_SUCCESSFUL)
70 73 {
71 74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
72 75 }
73 76
74 77 while(1){
75 78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
76 79
77 80 //****************************************
78 81 // initialize the mesage for the MATR task
79 82 msgForMATR.norm = current_ring_node_asm_norm_f1;
80 83 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1;
81 84 msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task
82 85 //
83 86 //****************************************
84 87
85 88 nodeForAveraging = getRingNodeForAveraging( 1 );
86 89
87 90 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
88 91 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
89 92 {
90 93 nodeForAveraging = nodeForAveraging->previous;
91 94 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
92 95 }
93 96
94 97 // compute the average and store it in the averaged_sm_f1 buffer
95 98 SM_average( current_ring_node_asm_norm_f1->matrix,
96 99 current_ring_node_asm_burst_sbm_f1->matrix,
97 100 ring_node_tab,
98 101 nb_norm_bp1, nb_sbm_bp1,
99 102 &msgForMATR );
100 103
101 104 // update nb_average
102 105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
103 106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
104 107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
105 108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
106 109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
107 110
108 111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
109 112 {
110 113 nb_sbm_bp1 = 0;
111 114 // set another ring for the ASM storage
112 115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
113 116 if ( lfrCurrentMode == LFR_MODE_BURST )
114 117 {
115 118 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1;
116 119 }
117 120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
118 121 {
119 122 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1;
120 123 }
121 124 }
122 125
123 126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
124 127 {
125 128 nb_sbm_bp2 = 0;
126 129 if ( lfrCurrentMode == LFR_MODE_BURST )
127 130 {
128 131 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1;
129 132 }
130 133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
131 134 {
132 135 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1;
133 136 }
134 137 }
135 138
136 139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
137 140 {
138 141 nb_norm_bp1 = 0;
139 142 // set another ring for the ASM storage
140 143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
141 144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
142 145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 146 {
144 147 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1;
145 148 }
146 149 }
147 150
148 151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
149 152 {
150 153 nb_norm_bp2 = 0;
151 154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
152 155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
153 156 {
154 157 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1;
155 158 }
156 159 }
157 160
158 161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
159 162 {
160 163 nb_norm_asm = 0;
161 164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
162 165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
163 166 {
164 167 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1;
165 168 }
166 169 }
167 170
168 171 //*************************
169 172 // send the message to MATR
170 173 if (msgForMATR.event != 0x00)
171 174 {
172 175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1);
173 176 }
174 177
175 178 if (status != RTEMS_SUCCESSFUL) {
176 179 printf("in AVF1 *** Error sending message to PRC1, code %d\n", status);
177 180 }
178 181 }
179 182 }
180 183
181 184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
182 185 {
183 186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
184 187 size_t size; // size of the incoming TC packet
185 188 asm_msg *incomingMsg;
186 189 //
187 190 unsigned char sid;
188 191 rtems_status_code status;
189 192 rtems_id queue_id_send;
190 193 rtems_id queue_id_q_p1;
191 194 bp_packet_with_spare packet_norm_bp1;
192 195 bp_packet packet_norm_bp2;
193 196 bp_packet packet_sbm_bp1;
194 197 bp_packet packet_sbm_bp2;
195 198 ring_node *current_ring_node_to_send_asm_f1;
196 199
197 200 unsigned long long int localTime;
198 201
199 202 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 203 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
201 204 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
202 205
203 206 //*************
204 207 // NORM headers
205 208 BP_init_header_with_spare( &packet_norm_bp1,
206 209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
207 210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
208 211 BP_init_header( &packet_norm_bp2,
209 212 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
210 213 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
211 214
212 215 //***********************
213 216 // BURST and SBM2 headers
214 217 if ( lfrRequestedMode == LFR_MODE_BURST )
215 218 {
216 219 BP_init_header( &packet_sbm_bp1,
217 220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
218 221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
219 222 BP_init_header( &packet_sbm_bp2,
220 223 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
221 224 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
222 225 }
223 226 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
224 227 {
225 228 BP_init_header( &packet_sbm_bp1,
226 229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
227 230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
228 231 BP_init_header( &packet_sbm_bp2,
229 232 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
230 233 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 234 }
232 235 else
233 236 {
234 237 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
235 238 }
236 239
237 240 status = get_message_queue_id_send( &queue_id_send );
238 241 if (status != RTEMS_SUCCESSFUL)
239 242 {
240 243 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
241 244 }
242 245 status = get_message_queue_id_prc1( &queue_id_q_p1);
243 246 if (status != RTEMS_SUCCESSFUL)
244 247 {
245 248 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
246 249 }
247 250
248 251 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
249 252
250 253 while(1){
251 254 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
252 255 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
253 256
254 257 incomingMsg = (asm_msg*) incomingData;
255 258
259 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
260 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
261
256 262 localTime = getTimeAsUnsignedLongLongInt( );
257 263 //***********
258 264 //***********
259 265 // BURST SBM2
260 266 //***********
261 267 //***********
262 268 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
263 269 {
264 270 sid = getSID( incomingMsg->event );
265 271 // 1) compress the matrix for Basic Parameters calculation
266 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f1,
272 ASM_compress_reorganize_and_divide( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
267 273 nb_sm_before_f1.burst_sbm_bp1,
268 274 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
269 275 ASM_F1_INDICE_START);
270 276 // 2) compute the BP1 set
271 277 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
272 278 // 3) send the BP1 set
273 279 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
274 280 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
275 281 BP_send( (char *) &packet_sbm_bp1, queue_id_send,
276 282 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
277 283 sid );
278 284 // 4) compute the BP2 set if needed
279 285 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
280 286 {
281 287 // 1) compute the BP2 set
282 288 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_norm_bp2.data );
283 289 // 2) send the BP2 set
284 290 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
285 291 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
286 292 BP_send( (char *) &packet_sbm_bp2, queue_id_send,
287 293 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
288 294 sid );
289 295 }
290 296 }
291 297
292 298 //*****
293 299 //*****
294 300 // NORM
295 301 //*****
296 302 //*****
297 303 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
298 304 {
299 305 // 1) compress the matrix for Basic Parameters calculation
300 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f1,
306 ASM_compress_reorganize_and_divide( asm_f1_patched_norm, compressed_sm_norm_f1,
301 307 nb_sm_before_f1.norm_bp1,
302 308 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
303 309 ASM_F1_INDICE_START );
304 310 // 2) compute the BP1 set
305 // BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
311 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
306 312 // 3) send the BP1 set
307 313 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
308 314 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
309 315 BP_send( (char *) &packet_norm_bp1, queue_id_send,
310 316 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
311 317 SID_NORM_BP1_F1 );
312 318 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
313 319 {
314 320 // 1) compute the BP2 set
315 321 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
316 322 // 2) send the BP2 set
317 323 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
318 324 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 325 BP_send( (char *) &packet_norm_bp2, queue_id_send,
320 326 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
321 327 SID_NORM_BP2_F1 );
322 328 }
323 329 }
324 330
325 331 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
326 332 {
327 333 // 1) reorganize the ASM and divide
328 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
334 ASM_reorganize_and_divide( asm_f1_patched_norm,
329 335 asm_f1_reorganized,
330 336 nb_sm_before_f1.norm_bp1 );
331 337 // 2) convert the float array in a char array
332 338 ASM_convert( asm_f1_reorganized, (char*) current_ring_node_to_send_asm_f1->buffer_address );
333 339 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
334 340 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
335 341 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
336 342 // 3) send the spectral matrix packets
337 343 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
338 344 // change asm ring node
339 345 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
340 346 }
341 347
342 348 }
343 349 }
344 350
345 351 //**********
346 352 // FUNCTIONS
347 353
348 354 void reset_nb_sm_f1( unsigned char lfrMode )
349 355 {
350 356 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
351 357 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
352 358 nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16;
353 359 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
354 360 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
355 361 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
356 362 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
357 363
358 364 if (lfrMode == LFR_MODE_SBM2)
359 365 {
360 366 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
361 367 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
362 368 }
363 369 else if (lfrMode == LFR_MODE_BURST)
364 370 {
365 371 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
366 372 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
367 373 }
368 374 else
369 375 {
370 376 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
371 377 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
372 378 }
373 379 }
374 380
375 381 void init_k_coefficients_f1( void )
376 382 {
377 383 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
378 384 init_k_coefficients( k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1);
379 385 }
@@ -1,285 +1,289
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf2_prc2.h"
11 11
12 12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13 13
14 14 extern ring_node sm_ring_f2[ ];
15 15
16 16 //***
17 17 // F2
18 18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
19 19
20 20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
21 21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
22 22
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
23 24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
25
24 26 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
25 27 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
26 28
27 29 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
28 30
29 31 //************
30 32 // RTEMS TASKS
31 33
32 34 //***
33 35 // F2
34 36 rtems_task avf2_task( rtems_task_argument argument )
35 37 {
36 38 rtems_event_set event_out;
37 39 rtems_status_code status;
38 40 rtems_id queue_id_prc2;
39 41 asm_msg msgForMATR;
40 42 ring_node *nodeForAveraging;
41 43 ring_node_asm *current_ring_node_asm_norm_f2;
42 44
43 45 unsigned int nb_norm_bp1;
44 46 unsigned int nb_norm_bp2;
45 47 unsigned int nb_norm_asm;
46 48
47 49 nb_norm_bp1 = 0;
48 50 nb_norm_bp2 = 0;
49 51 nb_norm_asm = 0;
50 52
51 53 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
52 54 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
53 55 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
54 56
55 57 BOOT_PRINTF("in AVF2 ***\n")
56 58
57 59 status = get_message_queue_id_prc2( &queue_id_prc2 );
58 60 if (status != RTEMS_SUCCESSFUL)
59 61 {
60 62 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
61 63 }
62 64
63 65 while(1){
64 66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
65 67
66 68 //****************************************
67 69 // initialize the mesage for the MATR task
68 70 msgForMATR.norm = current_ring_node_asm_norm_f2;
69 71 msgForMATR.burst_sbm = NULL;
70 72 msgForMATR.event = 0x00; // this composite event will be sent to the PRC2 task
71 73 //
72 74 //****************************************
73 75
74 76 nodeForAveraging = getRingNodeForAveraging( 2 );
75 77
76 78 // printf(" **0** %x . %x", sm_ring_f2[0].coarseTime, sm_ring_f2[0].fineTime);
77 79 // printf(" **1** %x . %x", sm_ring_f2[1].coarseTime, sm_ring_f2[1].fineTime);
78 80 // printf(" **2** %x . %x", sm_ring_f2[2].coarseTime, sm_ring_f2[2].fineTime);
79 81 // printf(" **3** %x . %x", sm_ring_f2[3].coarseTime, sm_ring_f2[3].fineTime);
80 82 // printf(" **4** %x . %x", sm_ring_f2[4].coarseTime, sm_ring_f2[4].fineTime);
81 83 // printf(" **5** %x . %x", sm_ring_f2[5].coarseTime, sm_ring_f2[5].fineTime);
82 84 // printf(" **6** %x . %x", sm_ring_f2[6].coarseTime, sm_ring_f2[6].fineTime);
83 85 // printf(" **7** %x . %x", sm_ring_f2[7].coarseTime, sm_ring_f2[7].fineTime);
84 86 // printf(" **8** %x . %x", sm_ring_f2[8].coarseTime, sm_ring_f2[8].fineTime);
85 87 // printf(" **9** %x . %x", sm_ring_f2[9].coarseTime, sm_ring_f2[9].fineTime);
86 88 // printf(" **10** %x . %x\n", sm_ring_f2[10].coarseTime, sm_ring_f2[10].fineTime);
87 89
88 90 // compute the average and store it in the averaged_sm_f2 buffer
89 91 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
90 92 nodeForAveraging,
91 93 nb_norm_bp1,
92 94 &msgForMATR );
93 95
94 96 // update nb_average
95 97 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
96 98 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
97 99 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
98 100
99 101 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
100 102 {
101 103 nb_norm_bp1 = 0;
102 104 // set another ring for the ASM storage
103 105 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
104 106 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 107 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 108 {
107 109 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2;
108 110 }
109 111 }
110 112
111 113 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
112 114 {
113 115 nb_norm_bp2 = 0;
114 116 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 117 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 118 {
117 119 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2;
118 120 }
119 121 }
120 122
121 123 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
122 124 {
123 125 nb_norm_asm = 0;
124 126 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
125 127 || (lfrCurrentMode == LFR_MODE_SBM2) )
126 128 {
127 129 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2;
128 130 }
129 131 }
130 132
131 133 //*************************
132 134 // send the message to MATR
133 135 if (msgForMATR.event != 0x00)
134 136 {
135 137 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC2);
136 138 }
137 139
138 140 if (status != RTEMS_SUCCESSFUL) {
139 141 printf("in AVF2 *** Error sending message to MATR, code %d\n", status);
140 142 }
141 143 }
142 144 }
143 145
144 146 rtems_task prc2_task( rtems_task_argument argument )
145 147 {
146 148 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
147 149 size_t size; // size of the incoming TC packet
148 150 asm_msg *incomingMsg;
149 151 //
150 152 rtems_status_code status;
151 153 rtems_id queue_id_send;
152 154 rtems_id queue_id_q_p2;
153 155 bp_packet packet_norm_bp1;
154 156 bp_packet packet_norm_bp2;
155 157 ring_node *current_ring_node_to_send_asm_f2;
156 158
157 159 unsigned long long int localTime;
158 160
159 161 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
160 162 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
161 163 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
162 164
163 165 //*************
164 166 // NORM headers
165 167 BP_init_header( &packet_norm_bp1,
166 168 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
167 169 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
168 170 BP_init_header( &packet_norm_bp2,
169 171 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
170 172 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
171 173
172 174 status = get_message_queue_id_send( &queue_id_send );
173 175 if (status != RTEMS_SUCCESSFUL)
174 176 {
175 177 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
176 178 }
177 179 status = get_message_queue_id_prc2( &queue_id_q_p2);
178 180 if (status != RTEMS_SUCCESSFUL)
179 181 {
180 182 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
181 183 }
182 184
183 185 BOOT_PRINTF("in PRC2 ***\n")
184 186
185 187 while(1){
186 188 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
187 189 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
188 190
189 191 incomingMsg = (asm_msg*) incomingData;
190 192
193 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
194
191 195 localTime = getTimeAsUnsignedLongLongInt( );
192 196
193 197 //*****
194 198 //*****
195 199 // NORM
196 200 //*****
197 201 //*****
198 202 // 1) compress the matrix for Basic Parameters calculation
199 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2,
203 ASM_compress_reorganize_and_divide( asm_f2_patched_norm, compressed_sm_norm_f2,
200 204 nb_sm_before_f2.norm_bp1,
201 205 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 206 ASM_F2_INDICE_START );
203 207 // BP1_F2
204 208 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
205 209 {
206 210 // 1) compute the BP1 set
207 // BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
211 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 212 // 2) send the BP1 set
209 213 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 214 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 215 BP_send( (char *) &packet_norm_bp1, queue_id_send,
212 216 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
213 217 SID_NORM_BP1_F2 );
214 218 }
215 219 // BP2_F2
216 220 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
217 221 {
218 222 // 1) compute the BP2 set
219 223 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
220 224 // 2) send the BP2 set
221 225 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
222 226 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
223 227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
224 228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
225 229 SID_NORM_BP2_F2 );
226 230 }
227 231
228 232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
229 233 {
230 234 // 1) reorganize the ASM and divide
231 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
235 ASM_reorganize_and_divide( asm_f2_patched_norm,
232 236 asm_f2_reorganized,
233 237 nb_sm_before_f2.norm_bp1 );
234 238 // 2) convert the float array in a char array
235 239 ASM_convert( asm_f2_reorganized, (char*) current_ring_node_to_send_asm_f2->buffer_address );
236 240 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
237 241 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
238 242 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
239 243 // 3) send the spectral matrix packets
240 244 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
241 245 // change asm ring node
242 246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
243 247 }
244 248
245 249 }
246 250 }
247 251
248 252 //**********
249 253 // FUNCTIONS
250 254
251 255 void reset_nb_sm_f2( void )
252 256 {
253 257 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
254 258 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
255 259 nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1];
256 260 }
257 261
258 262 void SM_average_f2( float *averaged_spec_mat_f2,
259 263 ring_node *ring_node,
260 264 unsigned int nbAverageNormF2,
261 265 asm_msg *msgForMATR )
262 266 {
263 267 float sum;
264 268 unsigned int i;
265 269
266 270 for(i=0; i<TOTAL_SIZE_SM; i++)
267 271 {
268 272 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
269 273 if ( (nbAverageNormF2 == 0) )
270 274 {
271 275 averaged_spec_mat_f2[ i ] = sum;
272 276 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
273 277 msgForMATR->fineTimeNORM = ring_node->fineTime;
274 278 }
275 279 else
276 280 {
277 281 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
278 282 }
279 283 }
280 284 }
281 285
282 286 void init_k_coefficients_f2( void )
283 287 {
284 288 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
285 289 }
General Comments 0
You need to be logged in to leave comments. Login now