##// END OF EJS Templates
PAS filtering implemented
paul -
r289:a907a62ed869 R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 dad8371a5549f3395f975fddc33098b05fd829f4 header/lfr_common_headers
2 2450d4935652a4d0370245cc7fc60a4c51e6fc9b header/lfr_common_headers
@@ -10,7 +10,7 TEMPLATE = app
10 10 # debug_tch
11 11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 12 # debug_watchdog
13 CONFIG += console verbose lpp_dpu_destid
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 14 CONFIG -= qt
15 15
16 16 include(./sparc.pri)
@@ -80,6 +80,8 typedef struct asm_msg
80 80 unsigned int fineTimeNORM;
81 81 unsigned int coarseTimeSBM;
82 82 unsigned int fineTimeSBM;
83 unsigned int numberOfSMInASMNORM;
84 unsigned int numberOfSMInASMSBM;
83 85 } asm_msg;
84 86
85 87 extern unsigned char thisIsAnASMRestart;
@@ -87,6 +89,7 extern unsigned char thisIsAnASMRestart;
87 89 extern volatile int sm_f0[ ];
88 90 extern volatile int sm_f1[ ];
89 91 extern volatile int sm_f2[ ];
92 extern unsigned int acquisitionDurations[];
90 93
91 94 // parameters
92 95 extern struct param_local_str param_local;
@@ -145,12 +148,7 extern rtems_status_code get_message_que
145 148 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
146 149 ring_node *ring_node_tab[],
147 150 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
148 asm_msg *msgForMATR );
149
150 static inline void SM_average_debug(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
151 ring_node *ring_node_tab[],
152 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
153 asm_msg *msgForMATR );
151 asm_msg *msgForMATR , unsigned char channel);
154 152
155 153 void ASM_patch( float *inputASM, float *outputASM );
156 154
@@ -165,24 +163,52 static inline void ASM_compress_reorgani
165 163
166 164 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
167 165
166 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
167
168 168 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
169 169 ring_node *ring_node_tab[],
170 170 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
171 asm_msg *msgForMATR )
171 asm_msg *msgForMATR, unsigned char channel )
172 172 {
173 173 float sum;
174 174 unsigned int i;
175 unsigned int k;
176 unsigned char incomingSMIsValid[8];
177 unsigned int numberOfValidSM;
178 unsigned char isValid;
175 179
180 //**************
181 // PAS FILTERING
182 // check acquisitionTime of the incoming data
183 numberOfValidSM = 0;
184 for (k=0; k<8; k++)
185 {
186 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
187 incomingSMIsValid[k] = isValid;
188 numberOfValidSM = numberOfValidSM + isValid;
189 }
190
191 //************************
192 // AVERAGE SPECTRAL MATRIX
176 193 for(i=0; i<TOTAL_SIZE_SM; i++)
177 194 {
178 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
179 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
180 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
181 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
182 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
183 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
184 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
185 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
195 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
196 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
197 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
198 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
199 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
200 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
201 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
202 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
203
204 sum = ( (incomingSMIsValid[0] == 1) ? ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] : 0.0 )
205 + ( (incomingSMIsValid[1] == 1) ? ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] : 0.0 )
206 + ( (incomingSMIsValid[2] == 1) ? ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] : 0.0 )
207 + ( (incomingSMIsValid[3] == 1) ? ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] : 0.0 )
208 + ( (incomingSMIsValid[4] == 1) ? ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] : 0.0 )
209 + ( (incomingSMIsValid[5] == 1) ? ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] : 0.0 )
210 + ( (incomingSMIsValid[6] == 1) ? ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] : 0.0 )
211 + ( (incomingSMIsValid[7] == 1) ? ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ] : 0.0 );
186 212
187 213 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
188 214 {
@@ -214,25 +240,28 void SM_average( float *averaged_spec_ma
214 240 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
215 241 }
216 242 }
243
244 //*******************
245 // UPDATE SM COUNTERS
246 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
247 {
248 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
249 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
217 250 }
218
219 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
220 ring_node *ring_node_tab[],
221 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
222 asm_msg *msgForMATR )
251 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
223 252 {
224 float sum;
225 unsigned int i;
226
227 for(i=0; i<TOTAL_SIZE_SM; i++)
253 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
254 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
255 }
256 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
228 257 {
229 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
230 averaged_spec_mat_NORM[ i ] = sum;
231 averaged_spec_mat_SBM[ i ] = sum;
232 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
233 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
234 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
235 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
258 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
259 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
260 }
261 else
262 {
263 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
264 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
236 265 }
237 266 }
238 267
@@ -255,7 +284,7 void ASM_reorganize_and_divide( float *a
255 284 asmComponent * NB_BINS_PER_SM
256 285 + frequencyBin;
257 286 averaged_spec_mat_reorganized[offsetASMReorganized ] =
258 averaged_spec_mat[ offsetASM ] / divider;
287 (divider != 0.0) ? averaged_spec_mat[ offsetASM ] / divider : 0.0;
259 288 }
260 289 }
261 290 }
@@ -93,3 +93,4 float cp_rpw_sc_rw4_f2;
93 93 float sy_lfr_sc_rw_delta_f;
94 94
95 95 fbins_masks_t fbins_masks;
96 unsigned int acquisitionDurations[3] = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
@@ -98,7 +98,7 rtems_task avf0_task( rtems_task_argumen
98 98 current_ring_node_asm_burst_sbm_f0->matrix,
99 99 ring_node_tab,
100 100 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC );
101 &msgForPRC, 0 ); // 0 => frequency channel 0
102 102
103 103 // update nb_average
104 104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
@@ -195,6 +195,8 rtems_task prc0_task( rtems_task_argumen
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 float nbSMInASMNORM;
199 float nbSMInASMSBM;
198 200
199 201 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 202 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
@@ -265,6 +267,9 rtems_task prc0_task( rtems_task_argumen
265 267 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
266 268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
267 269
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
268 273 //****************
269 274 //****************
270 275 // BURST SBM1 SBM2
@@ -275,7 +280,7 rtems_task prc0_task( rtems_task_argumen
275 280 sid = getSID( incomingMsg->event );
276 281 // 1) compress the matrix for Basic Parameters calculation
277 282 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
278 nb_sm_before_f0.burst_sbm_bp1,
283 nbSMInASMSBM,
279 284 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
280 285 ASM_F0_INDICE_START, CHANNELF0);
281 286 // 2) compute the BP1 set
@@ -313,7 +318,7 rtems_task prc0_task( rtems_task_argumen
313 318 {
314 319 // 1) compress the matrix for Basic Parameters calculation
315 320 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
316 nb_sm_before_f0.norm_bp1,
321 nbSMInASMNORM,
317 322 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
318 323 ASM_F0_INDICE_START, CHANNELF0 );
319 324 // 2) compute the BP1 set
@@ -346,7 +351,7 rtems_task prc0_task( rtems_task_argumen
346 351 // 1) reorganize the ASM and divide
347 352 ASM_reorganize_and_divide( asm_f0_patched_norm,
348 353 (float*) current_ring_node_to_send_asm_f0->buffer_address,
349 nb_sm_before_f0.norm_bp1 );
354 nbSMInASMNORM );
350 355 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
351 356 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
352 357 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
@@ -99,7 +99,7 rtems_task avf1_task( rtems_task_argumen
99 99 current_ring_node_asm_burst_sbm_f1->matrix,
100 100 ring_node_tab,
101 101 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC );
102 &msgForPRC, 1 ); // 1 => frequency channel 1
103 103
104 104 // update nb_average
105 105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
@@ -196,8 +196,8 rtems_task prc1_task( rtems_task_argumen
196 196 bp_packet packet_sbm_bp1;
197 197 bp_packet packet_sbm_bp2;
198 198 ring_node *current_ring_node_to_send_asm_f1;
199
200 unsigned long long int localTime;
199 float nbSMInASMNORM;
200 float nbSMInASMSBM;
201 201
202 202 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
203 203 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
@@ -259,7 +259,9 rtems_task prc1_task( rtems_task_argumen
259 259 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
260 260 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
261 261
262 localTime = getTimeAsUnsignedLongLongInt( );
262 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
263 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
264
263 265 //***********
264 266 //***********
265 267 // BURST SBM2
@@ -270,7 +272,7 rtems_task prc1_task( rtems_task_argumen
270 272 sid = getSID( incomingMsg->event );
271 273 // 1) compress the matrix for Basic Parameters calculation
272 274 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
273 nb_sm_before_f1.burst_sbm_bp1,
275 nbSMInASMSBM,
274 276 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
275 277 ASM_F1_INDICE_START, CHANNELF1);
276 278 // 2) compute the BP1 set
@@ -308,7 +310,7 rtems_task prc1_task( rtems_task_argumen
308 310 {
309 311 // 1) compress the matrix for Basic Parameters calculation
310 312 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
311 nb_sm_before_f1.norm_bp1,
313 nbSMInASMNORM,
312 314 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
313 315 ASM_F1_INDICE_START, CHANNELF1 );
314 316 // 2) compute the BP1 set
@@ -341,7 +343,7 rtems_task prc1_task( rtems_task_argumen
341 343 // 1) reorganize the ASM and divide
342 344 ASM_reorganize_and_divide( asm_f1_patched_norm,
343 345 (float*) current_ring_node_to_send_asm_f1->buffer_address,
344 nb_sm_before_f1.norm_bp1 );
346 nbSMInASMNORM );
345 347 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
346 348 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
347 349 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
@@ -143,6 +143,7 rtems_task prc2_task( rtems_task_argumen
143 143 bp_packet packet_norm_bp1;
144 144 bp_packet packet_norm_bp2;
145 145 ring_node *current_ring_node_to_send_asm_f2;
146 float nbSMInASMNORM;
146 147
147 148 unsigned long long int localTime;
148 149
@@ -182,6 +183,8 rtems_task prc2_task( rtems_task_argumen
182 183
183 184 localTime = getTimeAsUnsignedLongLongInt( );
184 185
186 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
187
185 188 //*****
186 189 //*****
187 190 // NORM
@@ -189,7 +192,7 rtems_task prc2_task( rtems_task_argumen
189 192 //*****
190 193 // 1) compress the matrix for Basic Parameters calculation
191 194 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
192 nb_sm_before_f2.norm_bp1,
195 nbSMInASMNORM,
193 196 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
194 197 ASM_F2_INDICE_START, CHANNELF2 );
195 198 // BP1_F2
@@ -258,20 +261,61 void SM_average_f2( float *averaged_spec
258 261 {
259 262 float sum;
260 263 unsigned int i;
264 unsigned char keepMatrix;
265
266 // test acquisitionTime validity
267 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, 2 );
261 268
262 269 for(i=0; i<TOTAL_SIZE_SM; i++)
263 270 {
264 271 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
265 if ( (nbAverageNormF2 == 0) )
272 if ( (nbAverageNormF2 == 0) ) // average initialization
273 {
274 if (keepMatrix == 1) // keep the matrix and add it to the average
266 275 {
267 276 averaged_spec_mat_f2[ i ] = sum;
277 }
278 else // drop the matrix and initialize the average
279 {
280 averaged_spec_mat_f2[ i ] = 0.;
281 }
268 282 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
269 283 msgForMATR->fineTimeNORM = ring_node->fineTime;
270 284 }
271 285 else
272 286 {
287 if (keepMatrix == 1) // keep the matrix and add it to the average
288 {
273 289 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
274 290 }
291 else
292 {
293 // nothing to do, the matrix is not valid
294 }
295 }
296 }
297
298 if (keepMatrix == 1)
299 {
300 if ( (nbAverageNormF2 == 0) )
301 {
302 msgForMATR->numberOfSMInASMNORM = 1;
303 }
304 else
305 {
306 msgForMATR->numberOfSMInASMNORM++;
307 }
308 }
309 else
310 {
311 if ( (nbAverageNormF2 == 0) )
312 {
313 msgForMATR->numberOfSMInASMNORM = 0;
314 }
315 else
316 {
317 // nothing to do
318 }
275 319 }
276 320 }
277 321
@@ -666,7 +666,7 void ASM_compress_reorganize_and_divide_
666 666 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
667 667 }
668 668 compressed_spec_mat[ offsetCompressed ] =
669 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
669 (divider != 0.) ? compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage) : 0.0;
670 670 }
671 671 }
672 672
@@ -704,6 +704,81 int getFBinMask( int index, unsigned cha
704 704 return fbin;
705 705 }
706 706
707 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
708 {
709 u_int64_t acquisitionTime;
710 u_int64_t timecodeReference;
711 u_int64_t offsetInFineTime;
712 u_int64_t shiftInFineTime;
713 u_int64_t tBadInFineTime;
714 u_int64_t acquisitionTimeRangeMin;
715 u_int64_t acquisitionTimeRangeMax;
716 unsigned char pasFilteringIsEnabled;
717 unsigned char ret;
718
719 pasFilteringIsEnabled = (parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01); // [0000 0001]
720 ret = 1;
721
722 //***************************
723 // <FOR TESTING PURPOSE ONLY>
724 unsigned char sy_lfr_pas_filter_modulus = 4;
725 unsigned char sy_lfr_pas_filter_offset = 1;
726 float sy_lfr_pas_filter_shift = 0.5;
727 float sy_lfr_pas_filter_tbad = 1.0;
728 // </FOR TESTING PURPOSE ONLY>
729 //****************************
730
731 // compute acquisition time from caoarseTime and fineTime
732 acquisitionTime = ( ((u_int64_t)coarseTime) << 16 )
733 + (u_int64_t) fineTime;
734
735 // compute the timecode reference
736 timecodeReference = (u_int64_t) (floor( ((double) coarseTime) / ((double) sy_lfr_pas_filter_modulus) )
737 * ((double) sy_lfr_pas_filter_modulus)) * 65536;
738
739 // compute the acquitionTime range
740 offsetInFineTime = ((double) sy_lfr_pas_filter_offset) * 65536;
741 shiftInFineTime = ((double) sy_lfr_pas_filter_shift) * 65536;
742 tBadInFineTime = ((double) sy_lfr_pas_filter_tbad) * 65536;
743
744 acquisitionTimeRangeMin =
745 timecodeReference
746 + offsetInFineTime
747 + shiftInFineTime
748 - acquisitionDurations[channel];
749 acquisitionTimeRangeMax =
750 timecodeReference
751 + offsetInFineTime
752 + shiftInFineTime
753 + tBadInFineTime;
754
755 if ( (acquisitionTime >= acquisitionTimeRangeMin)
756 && (acquisitionTime <= acquisitionTimeRangeMax)
757 && (pasFilteringIsEnabled == 1) )
758 {
759 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
760 }
761 else
762 {
763 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
764 }
765
766 // printf("coarseTime = %x, fineTime = %x\n",
767 // coarseTime,
768 // fineTime);
769
770 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
771 // ret,
772 // acquisitionTime / 65536.,
773 // timecodeReference / 65536.);
774
775 // printf(", Min = %f, Max = %f\n",
776 // acquisitionTimeRangeMin / 65536.,
777 // acquisitionTimeRangeMax / 65536.);
778
779 return ret;
780 }
781
707 782 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
708 783 {
709 784 unsigned char bin;
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now