1 |
|
|
#ifndef FSW_PROCESSING_H_INCLUDED |
2 |
|
|
#define FSW_PROCESSING_H_INCLUDED |
3 |
|
|
|
4 |
|
|
#include <rtems.h> |
5 |
|
|
#include <grspw.h> |
6 |
|
|
#include <math.h> |
7 |
|
|
#include <stdlib.h> // abs() is in the stdlib |
8 |
|
|
#include <stdio.h> |
9 |
|
|
#include <math.h> |
10 |
|
|
#include <grlib_regs.h> |
11 |
|
|
|
12 |
|
|
#include "fsw_params.h" |
13 |
|
|
|
14 |
|
|
#define SBM_COEFF_PER_NORM_COEFF 2 |
15 |
|
|
#define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1] |
16 |
|
|
#define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes |
17 |
|
|
|
18 |
|
|
typedef struct ring_node_asm |
19 |
|
|
{ |
20 |
|
|
struct ring_node_asm *next; |
21 |
|
|
float matrix[ TOTAL_SIZE_SM ]; |
22 |
|
|
unsigned int status; |
23 |
|
|
} ring_node_asm; |
24 |
|
|
|
25 |
|
|
typedef struct |
26 |
|
|
{ |
27 |
|
|
unsigned char targetLogicalAddress; |
28 |
|
|
unsigned char protocolIdentifier; |
29 |
|
|
unsigned char reserved; |
30 |
|
|
unsigned char userApplication; |
31 |
|
|
unsigned char packetID[BYTES_PER_PACKETID]; |
32 |
|
|
unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL]; |
33 |
|
|
unsigned char packetLength[BYTES_PER_PKT_LEN]; |
34 |
|
|
// DATA FIELD HEADER |
35 |
|
|
unsigned char spare1_pusVersion_spare2; |
36 |
|
|
unsigned char serviceType; |
37 |
|
|
unsigned char serviceSubType; |
38 |
|
|
unsigned char destinationID; |
39 |
|
|
unsigned char time[BYTES_PER_TIME]; |
40 |
|
|
// AUXILIARY HEADER |
41 |
|
|
unsigned char sid; |
42 |
|
|
unsigned char pa_bia_status_info; |
43 |
|
|
unsigned char sy_lfr_common_parameters_spare; |
44 |
|
|
unsigned char sy_lfr_common_parameters; |
45 |
|
|
unsigned char acquisitionTime[BYTES_PER_TIME]; |
46 |
|
|
unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR]; |
47 |
|
|
// SOURCE DATA |
48 |
|
|
unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1] |
49 |
|
|
} bp_packet; |
50 |
|
|
|
51 |
|
|
typedef struct |
52 |
|
|
{ |
53 |
|
|
unsigned char targetLogicalAddress; |
54 |
|
|
unsigned char protocolIdentifier; |
55 |
|
|
unsigned char reserved; |
56 |
|
|
unsigned char userApplication; |
57 |
|
|
unsigned char packetID[BYTES_PER_PACKETID]; |
58 |
|
|
unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL]; |
59 |
|
|
unsigned char packetLength[BYTES_PER_PKT_LEN]; |
60 |
|
|
// DATA FIELD HEADER |
61 |
|
|
unsigned char spare1_pusVersion_spare2; |
62 |
|
|
unsigned char serviceType; |
63 |
|
|
unsigned char serviceSubType; |
64 |
|
|
unsigned char destinationID; |
65 |
|
|
unsigned char time[BYTES_PER_TIME]; |
66 |
|
|
// AUXILIARY HEADER |
67 |
|
|
unsigned char sid; |
68 |
|
|
unsigned char pa_bia_status_info; |
69 |
|
|
unsigned char sy_lfr_common_parameters_spare; |
70 |
|
|
unsigned char sy_lfr_common_parameters; |
71 |
|
|
unsigned char acquisitionTime[BYTES_PER_TIME]; |
72 |
|
|
unsigned char source_data_spare; |
73 |
|
|
unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR]; |
74 |
|
|
// SOURCE DATA |
75 |
|
|
unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes |
76 |
|
|
} bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1 |
77 |
|
|
|
78 |
|
|
typedef struct asm_msg |
79 |
|
|
{ |
80 |
|
|
ring_node_asm *norm; |
81 |
|
|
ring_node_asm *burst_sbm; |
82 |
|
|
rtems_event_set event; |
83 |
|
|
unsigned int coarseTimeNORM; |
84 |
|
|
unsigned int fineTimeNORM; |
85 |
|
|
unsigned int coarseTimeSBM; |
86 |
|
|
unsigned int fineTimeSBM; |
87 |
|
|
unsigned int numberOfSMInASMNORM; |
88 |
|
|
unsigned int numberOfSMInASMSBM; |
89 |
|
|
} asm_msg; |
90 |
|
|
|
91 |
|
|
extern unsigned char thisIsAnASMRestart; |
92 |
|
|
|
93 |
|
|
extern volatile int sm_f0[ ]; |
94 |
|
|
extern volatile int sm_f1[ ]; |
95 |
|
|
extern volatile int sm_f2[ ]; |
96 |
|
|
extern unsigned int acquisitionDurations[]; |
97 |
|
|
|
98 |
|
|
// parameters |
99 |
|
|
extern struct param_local_str param_local; |
100 |
|
|
extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; |
101 |
|
|
|
102 |
|
|
// registers |
103 |
|
|
extern time_management_regs_t *time_management_regs; |
104 |
|
|
extern volatile spectral_matrix_regs_t *spectral_matrix_regs; |
105 |
|
|
|
106 |
|
|
extern rtems_name misc_name[]; |
107 |
|
|
extern rtems_id Task_id[]; /* array of task ids */ |
108 |
|
|
|
109 |
|
|
ring_node * getRingNodeForAveraging( unsigned char frequencyChannel); |
110 |
|
|
// ISR |
111 |
|
|
rtems_isr spectral_matrices_isr( rtems_vector_number vector ); |
112 |
|
|
|
113 |
|
|
//****************** |
114 |
|
|
// Spectral Matrices |
115 |
|
|
void reset_nb_sm( void ); |
116 |
|
|
// SM |
117 |
|
|
void SM_init_rings( void ); |
118 |
|
|
void SM_reset_current_ring_nodes( void ); |
119 |
|
|
// ASM |
120 |
|
|
void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes ); |
121 |
|
|
|
122 |
|
|
//***************** |
123 |
|
|
// Basic Parameters |
124 |
|
|
|
125 |
|
|
void BP_reset_current_ring_nodes( void ); |
126 |
|
|
void BP_init_header(bp_packet *packet, |
127 |
|
|
unsigned int apid, unsigned char sid, |
128 |
|
|
unsigned int packetLength , unsigned char blkNr); |
129 |
|
|
void BP_init_header_with_spare(bp_packet_with_spare *packet, |
130 |
|
|
unsigned int apid, unsigned char sid, |
131 |
|
|
unsigned int packetLength, unsigned char blkNr ); |
132 |
|
|
void BP_send( char *data, |
133 |
|
|
rtems_id queue_id, |
134 |
|
|
unsigned int nbBytesToSend , unsigned int sid ); |
135 |
|
|
void BP_send_s1_s2(char *data, |
136 |
|
|
rtems_id queue_id, |
137 |
|
|
unsigned int nbBytesToSend, unsigned int sid ); |
138 |
|
|
|
139 |
|
|
//****************** |
140 |
|
|
// general functions |
141 |
|
|
void reset_sm_status( void ); |
142 |
|
|
void reset_spectral_matrix_regs( void ); |
143 |
|
|
void set_time(unsigned char *time, unsigned char *timeInBuffer ); |
144 |
|
|
unsigned long long int get_acquisition_time( unsigned char *timePtr ); |
145 |
|
|
unsigned char getSID( rtems_event_set event ); |
146 |
|
|
|
147 |
|
|
extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); |
148 |
|
|
extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); |
149 |
|
|
|
150 |
|
|
//*************************************** |
151 |
|
|
// DEFINITIONS OF STATIC INLINE FUNCTIONS |
152 |
|
|
static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, |
153 |
|
|
ring_node *ring_node_tab[], |
154 |
|
|
unsigned int nbAverageNORM, unsigned int nbAverageSBM, |
155 |
|
|
asm_msg *msgForMATR , unsigned char channel); |
156 |
|
|
|
157 |
|
|
void ASM_patch( float *inputASM, float *outputASM ); |
158 |
|
|
|
159 |
|
|
void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent ); |
160 |
|
|
|
161 |
|
|
static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized, |
162 |
|
|
float divider ); |
163 |
|
|
|
164 |
|
|
static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat, |
165 |
|
|
float divider, |
166 |
|
|
unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart); |
167 |
|
|
|
168 |
|
|
static inline void ASM_convert(volatile float *input_matrix, char *output_matrix); |
169 |
|
|
|
170 |
|
|
unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 ); |
171 |
|
|
|
172 |
|
|
unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel); |
173 |
|
|
|
174 |
|
|
void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, |
175 |
|
|
ring_node *ring_node_tab[], |
176 |
|
|
unsigned int nbAverageNORM, unsigned int nbAverageSBM, |
177 |
|
|
asm_msg *msgForMATR, unsigned char channel ) |
178 |
|
|
{ |
179 |
|
|
float sum; |
180 |
|
|
unsigned int i; |
181 |
|
|
unsigned int k; |
182 |
|
|
unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1]; |
183 |
|
|
unsigned int numberOfValidSM; |
184 |
|
|
unsigned char isValid; |
185 |
|
|
|
186 |
|
|
//************** |
187 |
|
|
// PAS FILTERING |
188 |
|
|
// check acquisitionTime of the incoming data |
189 |
|
|
numberOfValidSM = 0; |
190 |
|
|
for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++) |
191 |
|
|
{ |
192 |
|
|
isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel ); |
193 |
|
|
incomingSMIsValid[k] = isValid; |
194 |
|
|
numberOfValidSM = numberOfValidSM + isValid; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
//************************ |
198 |
|
|
// AVERAGE SPECTRAL MATRIX |
199 |
|
|
for(i=0; i<TOTAL_SIZE_SM; i++) |
200 |
|
|
{ |
201 |
|
|
sum = INIT_FLOAT; |
202 |
|
|
for ( k = 0; k < NB_SM_BEFORE_AVF0_F1; k++ ) |
203 |
|
|
{ |
204 |
|
|
if (incomingSMIsValid[k] == MATRIX_IS_NOT_POLLUTED) |
205 |
|
|
{ |
206 |
|
|
sum = sum + ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] ; |
207 |
|
|
} |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) ) |
211 |
|
|
{ |
212 |
|
|
averaged_spec_mat_NORM[ i ] = sum; |
213 |
|
|
averaged_spec_mat_SBM[ i ] = sum; |
214 |
|
|
msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime; |
215 |
|
|
msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime; |
216 |
|
|
msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime; |
217 |
|
|
msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime; |
218 |
|
|
} |
219 |
|
|
else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) ) |
220 |
|
|
{ |
221 |
|
|
averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); |
222 |
|
|
averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum ); |
223 |
|
|
} |
224 |
|
|
else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) ) |
225 |
|
|
{ |
226 |
|
|
averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); |
227 |
|
|
averaged_spec_mat_SBM[ i ] = sum; |
228 |
|
|
msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime; |
229 |
|
|
msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime; |
230 |
|
|
} |
231 |
|
|
else |
232 |
|
|
{ |
233 |
|
|
averaged_spec_mat_NORM[ i ] = sum; |
234 |
|
|
averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum ); |
235 |
|
|
msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime; |
236 |
|
|
msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime; |
237 |
|
|
// PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM) |
238 |
|
|
} |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
//******************* |
242 |
|
|
// UPDATE SM COUNTERS |
243 |
|
|
if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) ) |
244 |
|
|
{ |
245 |
|
|
msgForMATR->numberOfSMInASMNORM = numberOfValidSM; |
246 |
|
|
msgForMATR->numberOfSMInASMSBM = numberOfValidSM; |
247 |
|
|
} |
248 |
|
|
else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) ) |
249 |
|
|
{ |
250 |
|
|
msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM; |
251 |
|
|
msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM; |
252 |
|
|
} |
253 |
|
|
else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) ) |
254 |
|
|
{ |
255 |
|
|
msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM; |
256 |
|
|
msgForMATR->numberOfSMInASMSBM = numberOfValidSM; |
257 |
|
|
} |
258 |
|
|
else |
259 |
|
|
{ |
260 |
|
|
msgForMATR->numberOfSMInASMNORM = numberOfValidSM; |
261 |
|
|
msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM; |
262 |
|
|
} |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider ) |
266 |
|
|
{ |
267 |
|
|
int frequencyBin; |
268 |
|
|
int asmComponent; |
269 |
|
|
unsigned int offsetASM; |
270 |
|
|
unsigned int offsetASMReorganized; |
271 |
|
|
|
272 |
|
|
// BUILD DATA |
273 |
|
|
for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) |
274 |
|
|
{ |
275 |
|
|
for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ ) |
276 |
|
|
{ |
277 |
|
|
offsetASMReorganized = |
278 |
|
|
(frequencyBin * NB_VALUES_PER_SM) |
279 |
|
|
+ asmComponent; |
280 |
|
|
offsetASM = |
281 |
|
|
(asmComponent * NB_BINS_PER_SM) |
282 |
|
|
+ frequencyBin; |
283 |
|
|
if ( divider != INIT_FLOAT ) |
284 |
|
|
{ |
285 |
|
|
averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider; |
286 |
|
|
} |
287 |
|
|
else |
288 |
|
|
{ |
289 |
|
|
averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT; |
290 |
|
|
} |
291 |
|
|
} |
292 |
|
|
} |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider, |
296 |
|
|
unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart ) |
297 |
|
|
{ |
298 |
|
|
int frequencyBin; |
299 |
|
|
int asmComponent; |
300 |
|
|
int offsetASM; |
301 |
|
|
int offsetCompressed; |
302 |
|
|
int k; |
303 |
|
|
|
304 |
|
|
// BUILD DATA |
305 |
|
|
for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) |
306 |
|
|
{ |
307 |
|
|
for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ ) |
308 |
|
|
{ |
309 |
|
|
offsetCompressed = // NO TIME OFFSET |
310 |
|
|
(frequencyBin * NB_VALUES_PER_SM) |
311 |
|
|
+ asmComponent; |
312 |
|
|
offsetASM = // NO TIME OFFSET |
313 |
|
|
(asmComponent * NB_BINS_PER_SM) |
314 |
|
|
+ ASMIndexStart |
315 |
|
|
+ (frequencyBin * nbBinsToAverage); |
316 |
|
|
compressed_spec_mat[ offsetCompressed ] = 0; |
317 |
|
|
for ( k = 0; k < nbBinsToAverage; k++ ) |
318 |
|
|
{ |
319 |
|
|
compressed_spec_mat[offsetCompressed ] = |
320 |
|
|
( compressed_spec_mat[ offsetCompressed ] |
321 |
|
|
+ averaged_spec_mat[ offsetASM + k ] ); |
322 |
|
|
} |
323 |
|
|
compressed_spec_mat[ offsetCompressed ] = |
324 |
|
|
compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage); |
325 |
|
|
} |
326 |
|
|
} |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
void ASM_convert( volatile float *input_matrix, char *output_matrix) |
330 |
|
|
{ |
331 |
|
|
unsigned int frequencyBin; |
332 |
|
|
unsigned int asmComponent; |
333 |
|
|
char * pt_char_input; |
334 |
|
|
char * pt_char_output; |
335 |
|
|
unsigned int offsetInput; |
336 |
|
|
unsigned int offsetOutput; |
337 |
|
|
|
338 |
|
|
pt_char_input = (char*) &input_matrix; |
339 |
|
|
pt_char_output = (char*) &output_matrix; |
340 |
|
|
|
341 |
|
|
// convert all other data |
342 |
|
|
for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++) |
343 |
|
|
{ |
344 |
|
|
for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++) |
345 |
|
|
{ |
346 |
|
|
offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ; |
347 |
|
|
offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ; |
348 |
|
|
pt_char_input = (char*) &input_matrix [ offsetInput ]; |
349 |
|
|
pt_char_output = (char*) &output_matrix[ offsetOutput ]; |
350 |
|
|
pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float |
351 |
|
|
pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float |
352 |
|
|
} |
353 |
|
|
} |
354 |
|
|
} |
355 |
|
|
|
356 |
|
|
void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat, |
357 |
|
|
float divider, |
358 |
|
|
unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel); |
359 |
|
|
|
360 |
|
|
int getFBinMask(int k, unsigned char channel); |
361 |
|
|
|
362 |
|
|
void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm); |
363 |
|
|
|
364 |
|
|
#endif // FSW_PROCESSING_H_INCLUDED |