##// END OF EJS Templates
3.0.0.12...
paul -
r236:5379af5b0bd4 R3
parent child
Show More
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 82603593a3f6185e68418200fe1fee7d81fe6e3d header/lfr_common_headers
2 07e22c5c44daa84954a10db557a74b8c8dd2d014 header/lfr_common_headers
@@ -1,112 +1,112
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 4 # lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
6 6 CONFIG -= qt
7 7
8 8 include(./sparc.pri)
9 9
10 10 # flight software version
11 11 SWVERSION=-1-0
12 12 DEFINES += SW_VERSION_N1=3 # major
13 13 DEFINES += SW_VERSION_N2=0 # minor
14 14 DEFINES += SW_VERSION_N3=0 # patch
15 DEFINES += SW_VERSION_N4=11 # internal
15 DEFINES += SW_VERSION_N4=12 # internal
16 16
17 17 # <GCOV>
18 QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
20 20 # </GCOV>
21 21
22 22 # <CHANGE BEFORE FLIGHT>
23 23 contains( CONFIG, lpp_dpu_destid ) {
24 24 DEFINES += LPP_DPU_DESTID
25 25 }
26 26 # </CHANGE BEFORE FLIGHT>
27 27
28 28 contains( CONFIG, debug_tch ) {
29 29 DEFINES += DEBUG_TCH
30 30 }
31 31 DEFINES += MSB_FIRST_TCH
32 32
33 33 contains( CONFIG, vhdl_dev ) {
34 34 DEFINES += VHDL_DEV
35 35 }
36 36
37 37 contains( CONFIG, verbose ) {
38 38 DEFINES += PRINT_MESSAGES_ON_CONSOLE
39 39 }
40 40
41 41 contains( CONFIG, debug_messages ) {
42 42 DEFINES += DEBUG_MESSAGES
43 43 }
44 44
45 45 contains( CONFIG, cpu_usage_report ) {
46 46 DEFINES += PRINT_TASK_STATISTICS
47 47 }
48 48
49 49 contains( CONFIG, stack_report ) {
50 50 DEFINES += PRINT_STACK_REPORT
51 51 }
52 52
53 53 contains( CONFIG, boot_messages ) {
54 54 DEFINES += BOOT_MESSAGES
55 55 }
56 56
57 57 #doxygen.target = doxygen
58 58 #doxygen.commands = doxygen ../doc/Doxyfile
59 59 #QMAKE_EXTRA_TARGETS += doxygen
60 60
61 61 TARGET = fsw
62 62
63 63 INCLUDEPATH += \
64 64 $${PWD}/../src \
65 65 $${PWD}/../header \
66 66 $${PWD}/../header/lfr_common_headers \
67 67 $${PWD}/../header/processing \
68 68 $${PWD}/../LFR_basic-parameters
69 69
70 70 SOURCES += \
71 71 ../src/wf_handler.c \
72 72 ../src/tc_handler.c \
73 73 ../src/fsw_misc.c \
74 74 ../src/fsw_init.c \
75 75 ../src/fsw_globals.c \
76 76 ../src/fsw_spacewire.c \
77 77 ../src/tc_load_dump_parameters.c \
78 78 ../src/tm_lfr_tc_exe.c \
79 79 ../src/tc_acceptance.c \
80 80 ../src/processing/fsw_processing.c \
81 81 ../src/processing/avf0_prc0.c \
82 82 ../src/processing/avf1_prc1.c \
83 83 ../src/processing/avf2_prc2.c \
84 84 ../src/lfr_cpu_usage_report.c \
85 85 ../LFR_basic-parameters/basic_parameters.c
86 86
87 87 HEADERS += \
88 88 ../header/wf_handler.h \
89 89 ../header/tc_handler.h \
90 90 ../header/grlib_regs.h \
91 91 ../header/fsw_misc.h \
92 92 ../header/fsw_init.h \
93 93 ../header/fsw_spacewire.h \
94 94 ../header/tc_load_dump_parameters.h \
95 95 ../header/tm_lfr_tc_exe.h \
96 96 ../header/tc_acceptance.h \
97 97 ../header/processing/fsw_processing.h \
98 98 ../header/processing/avf0_prc0.h \
99 99 ../header/processing/avf1_prc1.h \
100 100 ../header/processing/avf2_prc2.h \
101 101 ../header/fsw_params_wf_handler.h \
102 102 ../header/lfr_cpu_usage_report.h \
103 103 ../header/lfr_common_headers/ccsds_types.h \
104 104 ../header/lfr_common_headers/fsw_params.h \
105 105 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
106 106 ../header/lfr_common_headers/fsw_params_processing.h \
107 107 ../header/lfr_common_headers/TC_types.h \
108 108 ../header/lfr_common_headers/tm_byte_positions.h \
109 109 ../LFR_basic-parameters/basic_parameters.h \
110 110 ../LFR_basic-parameters/basic_parameters_params.h \
111 111 ../header/GscMemoryLPP.hpp
112 112
@@ -1,329 +1,329
1 1 #ifndef FSW_PROCESSING_H_INCLUDED
2 2 #define FSW_PROCESSING_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <math.h>
7 7 #include <stdlib.h> // abs() is in the stdlib
8 8 #include <stdio.h>
9 9 #include <math.h>
10 10 #include <grlib_regs.h>
11 11
12 12 #include "fsw_params.h"
13 13
14 14 typedef struct ring_node_asm
15 15 {
16 16 struct ring_node_asm *next;
17 17 float matrix[ TOTAL_SIZE_SM ];
18 18 unsigned int status;
19 19 } ring_node_asm;
20 20
21 21 typedef struct
22 22 {
23 23 unsigned char targetLogicalAddress;
24 24 unsigned char protocolIdentifier;
25 25 unsigned char reserved;
26 26 unsigned char userApplication;
27 27 unsigned char packetID[2];
28 28 unsigned char packetSequenceControl[2];
29 29 unsigned char packetLength[2];
30 30 // DATA FIELD HEADER
31 31 unsigned char spare1_pusVersion_spare2;
32 32 unsigned char serviceType;
33 33 unsigned char serviceSubType;
34 34 unsigned char destinationID;
35 35 unsigned char time[6];
36 36 // AUXILIARY HEADER
37 37 unsigned char sid;
38 38 unsigned char biaStatusInfo;
39 39 unsigned char sy_lfr_common_parameters_spare;
40 40 unsigned char sy_lfr_common_parameters;
41 41 unsigned char acquisitionTime[6];
42 42 unsigned char pa_lfr_bp_blk_nr[2];
43 43 // SOURCE DATA
44 44 unsigned char data[ 780 ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
45 45 } bp_packet;
46 46
47 47 typedef struct
48 48 {
49 49 unsigned char targetLogicalAddress;
50 50 unsigned char protocolIdentifier;
51 51 unsigned char reserved;
52 52 unsigned char userApplication;
53 53 unsigned char packetID[2];
54 54 unsigned char packetSequenceControl[2];
55 55 unsigned char packetLength[2];
56 56 // DATA FIELD HEADER
57 57 unsigned char spare1_pusVersion_spare2;
58 58 unsigned char serviceType;
59 59 unsigned char serviceSubType;
60 60 unsigned char destinationID;
61 61 unsigned char time[6];
62 62 // AUXILIARY HEADER
63 63 unsigned char sid;
64 64 unsigned char biaStatusInfo;
65 65 unsigned char sy_lfr_common_parameters_spare;
66 66 unsigned char sy_lfr_common_parameters;
67 67 unsigned char acquisitionTime[6];
68 68 unsigned char source_data_spare;
69 69 unsigned char pa_lfr_bp_blk_nr[2];
70 70 // SOURCE DATA
71 71 unsigned char data[ 143 ]; // 13 bins * 11 Bytes
72 72 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
73 73
74 74 typedef struct asm_msg
75 75 {
76 76 ring_node_asm *norm;
77 77 ring_node_asm *burst_sbm;
78 78 rtems_event_set event;
79 79 unsigned int coarseTimeNORM;
80 80 unsigned int fineTimeNORM;
81 81 unsigned int coarseTimeSBM;
82 82 unsigned int fineTimeSBM;
83 83 } asm_msg;
84 84
85 85 extern volatile int sm_f0[ ];
86 86 extern volatile int sm_f1[ ];
87 87 extern volatile int sm_f2[ ];
88 88
89 89 // parameters
90 90 extern struct param_local_str param_local;
91 91 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
92 92
93 93 // registers
94 94 extern time_management_regs_t *time_management_regs;
95 95 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
96 96
97 97 extern rtems_name misc_name[5];
98 98 extern rtems_id Task_id[20]; /* array of task ids */
99 99
100 100 //
101 101 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
102 102 // ISR
103 103 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
104 104 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
105 105
106 106 //******************
107 107 // Spectral Matrices
108 108 void reset_nb_sm( void );
109 109 // SM
110 110 void SM_init_rings( void );
111 111 void SM_reset_current_ring_nodes( void );
112 112 // ASM
113 113 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
114 114
115 115 //*****************
116 116 // Basic Parameters
117 117
118 118 void BP_reset_current_ring_nodes( void );
119 119 void BP_init_header(bp_packet *packet,
120 120 unsigned int apid, unsigned char sid,
121 121 unsigned int packetLength , unsigned char blkNr);
122 122 void BP_init_header_with_spare(bp_packet_with_spare *packet,
123 123 unsigned int apid, unsigned char sid,
124 124 unsigned int packetLength, unsigned char blkNr );
125 125 void BP_send( char *data,
126 126 rtems_id queue_id ,
127 127 unsigned int nbBytesToSend , unsigned int sid );
128 128
129 129 //******************
130 130 // general functions
131 131 void reset_sm_status( void );
132 132 void reset_spectral_matrix_regs( void );
133 133 void set_time(unsigned char *time, unsigned char *timeInBuffer );
134 134 unsigned long long int get_acquisition_time( unsigned char *timePtr );
135 135 unsigned char getSID( rtems_event_set event );
136 136
137 137 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
138 138 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
139 139
140 140 //***************************************
141 141 // DEFINITIONS OF STATIC INLINE FUNCTIONS
142 142 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
143 143 ring_node *ring_node_tab[],
144 144 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
145 145 asm_msg *msgForMATR );
146 146
147 147 static inline void SM_average_debug(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
148 148 ring_node *ring_node_tab[],
149 149 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
150 150 asm_msg *msgForMATR );
151 151
152 152 void ASM_patch( float *inputASM, float *outputASM );
153 153
154 154 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
155 155
156 156 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
157 157 float divider );
158 158
159 159 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
160 160 float divider,
161 161 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
162 162
163 163 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
164 164
165 165 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
166 166 ring_node *ring_node_tab[],
167 167 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
168 168 asm_msg *msgForMATR )
169 169 {
170 170 float sum;
171 171 unsigned int i;
172 172
173 173 for(i=0; i<TOTAL_SIZE_SM; i++)
174 174 {
175 175 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
176 176 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
177 177 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
178 178 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
179 179 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
180 180 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
181 181 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
182 182 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
183 183
184 184 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
185 185 {
186 186 averaged_spec_mat_NORM[ i ] = sum;
187 187 averaged_spec_mat_SBM[ i ] = sum;
188 188 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
189 189 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
190 190 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
191 191 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
192 192 }
193 193 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
194 194 {
195 195 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
196 196 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
197 197 }
198 198 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
199 199 {
200 200 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
201 201 averaged_spec_mat_SBM[ i ] = sum;
202 202 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
203 203 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
204 204 }
205 205 else
206 206 {
207 207 averaged_spec_mat_NORM[ i ] = sum;
208 208 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
209 209 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
210 210 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
211 211 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
212 212 }
213 213 }
214 214 }
215 215
216 216 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
217 217 ring_node *ring_node_tab[],
218 218 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
219 219 asm_msg *msgForMATR )
220 220 {
221 221 float sum;
222 222 unsigned int i;
223 223
224 224 for(i=0; i<TOTAL_SIZE_SM; i++)
225 225 {
226 226 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
227 227 averaged_spec_mat_NORM[ i ] = sum;
228 228 averaged_spec_mat_SBM[ i ] = sum;
229 229 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
230 230 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
231 231 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
232 232 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
233 233 }
234 234 }
235 235
236 236 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
237 237 {
238 238 int frequencyBin;
239 239 int asmComponent;
240 240 unsigned int offsetASM;
241 241 unsigned int offsetASMReorganized;
242 242
243 243 // BUILD DATA
244 244 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
245 245 {
246 246 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
247 247 {
248 248 offsetASMReorganized =
249 249 frequencyBin * NB_VALUES_PER_SM
250 250 + asmComponent;
251 251 offsetASM =
252 252 asmComponent * NB_BINS_PER_SM
253 253 + frequencyBin;
254 254 averaged_spec_mat_reorganized[offsetASMReorganized ] =
255 255 averaged_spec_mat[ offsetASM ] / divider;
256 256 }
257 257 }
258 258 }
259 259
260 260 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
261 261 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
262 262 {
263 263 int frequencyBin;
264 264 int asmComponent;
265 265 int offsetASM;
266 266 int offsetCompressed;
267 267 int k;
268 268
269 269 // BUILD DATA
270 270 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
271 271 {
272 272 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
273 273 {
274 274 offsetCompressed = // NO TIME OFFSET
275 275 frequencyBin * NB_VALUES_PER_SM
276 276 + asmComponent;
277 277 offsetASM = // NO TIME OFFSET
278 278 asmComponent * NB_BINS_PER_SM
279 279 + ASMIndexStart
280 280 + frequencyBin * nbBinsToAverage;
281 281 compressed_spec_mat[ offsetCompressed ] = 0;
282 282 for ( k = 0; k < nbBinsToAverage; k++ )
283 283 {
284 284 compressed_spec_mat[offsetCompressed ] =
285 285 ( compressed_spec_mat[ offsetCompressed ]
286 286 + averaged_spec_mat[ offsetASM + k ] );
287 287 }
288 288 compressed_spec_mat[ offsetCompressed ] =
289 289 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
290 290 }
291 291 }
292 292 }
293 293
294 294 void ASM_convert( volatile float *input_matrix, char *output_matrix)
295 295 {
296 296 unsigned int frequencyBin;
297 297 unsigned int asmComponent;
298 298 char * pt_char_input;
299 299 char * pt_char_output;
300 300 unsigned int offsetInput;
301 301 unsigned int offsetOutput;
302 302
303 303 pt_char_input = (char*) &input_matrix;
304 304 pt_char_output = (char*) &output_matrix;
305 305
306 306 // convert all other data
307 307 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
308 308 {
309 309 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
310 310 {
311 311 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
312 312 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
313 313 pt_char_input = (char*) &input_matrix [ offsetInput ];
314 314 pt_char_output = (char*) &output_matrix[ offsetOutput ];
315 315 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
316 316 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
317 317 }
318 318 }
319 319 }
320 320
321 321 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
322 322 float divider,
323 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
323 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
324 324
325 int getFBinMask(int k);
325 int getFBinMask(int k, unsigned char channel);
326 326
327 327 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
328 328
329 329 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,408 +1,408
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 PRINTF1("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 ASM_compress_reorganize_and_divide( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
277 ASM_compress_reorganize_and_divide_mask( 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 ASM_F0_INDICE_START);
280 ASM_F0_INDICE_START, CHANNELF0);
281 281 // 2) compute the BP1 set
282 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 packet_sbm_bp1.biaStatusInfo = pa_bia_status_info;
287 287 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
288 288 BP_send( (char *) &packet_sbm_bp1, queue_id,
289 289 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
290 290 sid);
291 291 // 4) compute the BP2 set if needed
292 292 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
293 293 {
294 294 // 1) compute the BP2 set
295 295 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
296 296 // 2) send the BP2 set
297 297 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 298 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 299 packet_sbm_bp2.biaStatusInfo = pa_bia_status_info;
300 300 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 301 BP_send( (char *) &packet_sbm_bp2, queue_id,
302 302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
303 303 sid);
304 304 }
305 305 }
306 306
307 307 //*****
308 308 //*****
309 309 // NORM
310 310 //*****
311 311 //*****
312 312 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
313 313 {
314 314 // 1) compress the matrix for Basic Parameters calculation
315 ASM_compress_reorganize_and_divide( asm_f0_patched_norm, compressed_sm_norm_f0,
315 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
316 316 nb_sm_before_f0.norm_bp1,
317 317 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
318 ASM_F0_INDICE_START );
318 ASM_F0_INDICE_START, CHANNELF0 );
319 319 // 2) compute the BP1 set
320 320 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
321 321 // 3) send the BP1 set
322 322 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
323 323 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
324 324 packet_norm_bp1.biaStatusInfo = pa_bia_status_info;
325 325 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
326 326 BP_send( (char *) &packet_norm_bp1, queue_id,
327 327 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
328 328 SID_NORM_BP1_F0 );
329 329 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
330 330 {
331 331 // 1) compute the BP2 set using the same ASM as the one used for BP1
332 332 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
333 333 // 2) send the BP2 set
334 334 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
335 335 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 336 packet_norm_bp2.biaStatusInfo = pa_bia_status_info;
337 337 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
338 338 BP_send( (char *) &packet_norm_bp2, queue_id,
339 339 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
340 340 SID_NORM_BP2_F0);
341 341 }
342 342 }
343 343
344 344 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
345 345 {
346 346 // 1) reorganize the ASM and divide
347 347 ASM_reorganize_and_divide( asm_f0_patched_norm,
348 348 (float*) current_ring_node_to_send_asm_f0->buffer_address,
349 349 nb_sm_before_f0.norm_bp1 );
350 350 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
351 351 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
352 352 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
353 353
354 354 // 3) send the spectral matrix packets
355 355 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
356 356 // change asm ring node
357 357 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
358 358 }
359 359
360 360 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
361 361
362 362 }
363 363 }
364 364
365 365 //**********
366 366 // FUNCTIONS
367 367
368 368 void reset_nb_sm_f0( unsigned char lfrMode )
369 369 {
370 370 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
371 371 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
372 372 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;
373 373 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
374 374 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
375 375 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
376 376 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
377 377 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
378 378 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
379 379
380 380 if (lfrMode == LFR_MODE_SBM1)
381 381 {
382 382 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
383 383 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
384 384 }
385 385 else if (lfrMode == LFR_MODE_SBM2)
386 386 {
387 387 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
388 388 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
389 389 }
390 390 else if (lfrMode == LFR_MODE_BURST)
391 391 {
392 392 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
393 393 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
394 394 }
395 395 else
396 396 {
397 397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
398 398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
399 399 }
400 400 }
401 401
402 402 void init_k_coefficients_prc0( void )
403 403 {
404 404 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
405 405
406 406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
407 407 }
408 408
@@ -1,394 +1,394
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 24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
25 25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
26 26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
27 27
28 28 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
29 29 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
30 30 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
31 31
32 32 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
33 33 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
34 34
35 35 //************
36 36 // RTEMS TASKS
37 37
38 38 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
39 39 {
40 40 int i;
41 41
42 42 rtems_event_set event_out;
43 43 rtems_status_code status;
44 44 rtems_id queue_id_prc1;
45 45 asm_msg msgForMATR;
46 46 ring_node *nodeForAveraging;
47 47 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
48 48 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
49 49 ring_node_asm *current_ring_node_asm_norm_f1;
50 50
51 51 unsigned int nb_norm_bp1;
52 52 unsigned int nb_norm_bp2;
53 53 unsigned int nb_norm_asm;
54 54 unsigned int nb_sbm_bp1;
55 55 unsigned int nb_sbm_bp2;
56 56
57 57 nb_norm_bp1 = 0;
58 58 nb_norm_bp2 = 0;
59 59 nb_norm_asm = 0;
60 60 nb_sbm_bp1 = 0;
61 61 nb_sbm_bp2 = 0;
62 62
63 63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68 68
69 69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70 70
71 71 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 72 if (status != RTEMS_SUCCESSFUL)
73 73 {
74 74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 75 }
76 76
77 77 while(1){
78 78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79 79
80 80 //****************************************
81 81 // initialize the mesage for the MATR task
82 82 msgForMATR.norm = current_ring_node_asm_norm_f1;
83 83 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 84 msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task
85 85 //
86 86 //****************************************
87 87
88 88 nodeForAveraging = getRingNodeForAveraging( 1 );
89 89
90 90 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
91 91 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
92 92 {
93 93 nodeForAveraging = nodeForAveraging->previous;
94 94 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
95 95 }
96 96
97 97 // compute the average and store it in the averaged_sm_f1 buffer
98 98 SM_average( current_ring_node_asm_norm_f1->matrix,
99 99 current_ring_node_asm_burst_sbm_f1->matrix,
100 100 ring_node_tab,
101 101 nb_norm_bp1, nb_sbm_bp1,
102 102 &msgForMATR );
103 103
104 104 // update nb_average
105 105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
106 106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
107 107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
108 108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
109 109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
110 110
111 111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 112 {
113 113 nb_sbm_bp1 = 0;
114 114 // set another ring for the ASM storage
115 115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 116 if ( lfrCurrentMode == LFR_MODE_BURST )
117 117 {
118 118 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1;
119 119 }
120 120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 121 {
122 122 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1;
123 123 }
124 124 }
125 125
126 126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 127 {
128 128 nb_sbm_bp2 = 0;
129 129 if ( lfrCurrentMode == LFR_MODE_BURST )
130 130 {
131 131 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1;
132 132 }
133 133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 134 {
135 135 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1;
136 136 }
137 137 }
138 138
139 139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 140 {
141 141 nb_norm_bp1 = 0;
142 142 // set another ring for the ASM storage
143 143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 146 {
147 147 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1;
148 148 }
149 149 }
150 150
151 151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 152 {
153 153 nb_norm_bp2 = 0;
154 154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 156 {
157 157 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1;
158 158 }
159 159 }
160 160
161 161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 162 {
163 163 nb_norm_asm = 0;
164 164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 166 {
167 167 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1;
168 168 }
169 169 }
170 170
171 171 //*************************
172 172 // send the message to MATR
173 173 if (msgForMATR.event != 0x00)
174 174 {
175 175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1);
176 176 }
177 177
178 178 if (status != RTEMS_SUCCESSFUL) {
179 179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 180 }
181 181 }
182 182 }
183 183
184 184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 185 {
186 186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 187 size_t size; // size of the incoming TC packet
188 188 asm_msg *incomingMsg;
189 189 //
190 190 unsigned char sid;
191 191 rtems_status_code status;
192 192 rtems_id queue_id_send;
193 193 rtems_id queue_id_q_p1;
194 194 bp_packet_with_spare packet_norm_bp1;
195 195 bp_packet packet_norm_bp2;
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 199
200 200 unsigned long long int localTime;
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 );
204 204 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
205 205
206 206 //*************
207 207 // NORM headers
208 208 BP_init_header_with_spare( &packet_norm_bp1,
209 209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
210 210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
211 211 BP_init_header( &packet_norm_bp2,
212 212 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
213 213 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
214 214
215 215 //***********************
216 216 // BURST and SBM2 headers
217 217 if ( lfrRequestedMode == LFR_MODE_BURST )
218 218 {
219 219 BP_init_header( &packet_sbm_bp1,
220 220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
221 221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
222 222 BP_init_header( &packet_sbm_bp2,
223 223 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
224 224 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
225 225 }
226 226 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
227 227 {
228 228 BP_init_header( &packet_sbm_bp1,
229 229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
230 230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 231 BP_init_header( &packet_sbm_bp2,
232 232 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
233 233 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
234 234 }
235 235 else
236 236 {
237 237 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
238 238 }
239 239
240 240 status = get_message_queue_id_send( &queue_id_send );
241 241 if (status != RTEMS_SUCCESSFUL)
242 242 {
243 243 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
244 244 }
245 245 status = get_message_queue_id_prc1( &queue_id_q_p1);
246 246 if (status != RTEMS_SUCCESSFUL)
247 247 {
248 248 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
249 249 }
250 250
251 251 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
252 252
253 253 while(1){
254 254 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
255 255 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
256 256
257 257 incomingMsg = (asm_msg*) incomingData;
258 258
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 262 localTime = getTimeAsUnsignedLongLongInt( );
263 263 //***********
264 264 //***********
265 265 // BURST SBM2
266 266 //***********
267 267 //***********
268 268 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
269 269 {
270 270 sid = getSID( incomingMsg->event );
271 271 // 1) compress the matrix for Basic Parameters calculation
272 ASM_compress_reorganize_and_divide( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
272 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
273 273 nb_sm_before_f1.burst_sbm_bp1,
274 274 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
275 ASM_F1_INDICE_START);
275 ASM_F1_INDICE_START, CHANNELF1);
276 276 // 2) compute the BP1 set
277 277 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
278 278 // 3) send the BP1 set
279 279 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
280 280 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
281 281 packet_sbm_bp1.biaStatusInfo = pa_bia_status_info;
282 282 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
283 283 BP_send( (char *) &packet_sbm_bp1, queue_id_send,
284 284 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
285 285 sid );
286 286 // 4) compute the BP2 set if needed
287 287 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
288 288 {
289 289 // 1) compute the BP2 set
290 290 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
291 291 // 2) send the BP2 set
292 292 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
293 293 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
294 294 packet_sbm_bp2.biaStatusInfo = pa_bia_status_info;
295 295 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
296 296 BP_send( (char *) &packet_sbm_bp2, queue_id_send,
297 297 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
298 298 sid );
299 299 }
300 300 }
301 301
302 302 //*****
303 303 //*****
304 304 // NORM
305 305 //*****
306 306 //*****
307 307 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
308 308 {
309 309 // 1) compress the matrix for Basic Parameters calculation
310 ASM_compress_reorganize_and_divide( asm_f1_patched_norm, compressed_sm_norm_f1,
310 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
311 311 nb_sm_before_f1.norm_bp1,
312 312 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
313 ASM_F1_INDICE_START );
313 ASM_F1_INDICE_START, CHANNELF1 );
314 314 // 2) compute the BP1 set
315 315 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
316 316 // 3) send the BP1 set
317 317 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
318 318 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 319 packet_norm_bp1.biaStatusInfo = pa_bia_status_info;
320 320 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
321 321 BP_send( (char *) &packet_norm_bp1, queue_id_send,
322 322 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
323 323 SID_NORM_BP1_F1 );
324 324 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
325 325 {
326 326 // 1) compute the BP2 set
327 327 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
328 328 // 2) send the BP2 set
329 329 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
330 330 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
331 331 packet_norm_bp2.biaStatusInfo = pa_bia_status_info;
332 332 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
333 333 BP_send( (char *) &packet_norm_bp2, queue_id_send,
334 334 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
335 335 SID_NORM_BP2_F1 );
336 336 }
337 337 }
338 338
339 339 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
340 340 {
341 341 // 1) reorganize the ASM and divide
342 342 ASM_reorganize_and_divide( asm_f1_patched_norm,
343 343 (float*) current_ring_node_to_send_asm_f1->buffer_address,
344 344 nb_sm_before_f1.norm_bp1 );
345 345 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
346 346 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
347 347 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
348 348 // 3) send the spectral matrix packets
349 349 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
350 350 // change asm ring node
351 351 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
352 352 }
353 353
354 354 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
355 355
356 356 }
357 357 }
358 358
359 359 //**********
360 360 // FUNCTIONS
361 361
362 362 void reset_nb_sm_f1( unsigned char lfrMode )
363 363 {
364 364 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
365 365 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
366 366 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;
367 367 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
368 368 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
369 369 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
370 370 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
371 371
372 372 if (lfrMode == LFR_MODE_SBM2)
373 373 {
374 374 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
375 375 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
376 376 }
377 377 else if (lfrMode == LFR_MODE_BURST)
378 378 {
379 379 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
380 380 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
381 381 }
382 382 else
383 383 {
384 384 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
385 385 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
386 386 }
387 387 }
388 388
389 389 void init_k_coefficients_prc1( void )
390 390 {
391 391 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
392 392
393 393 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
394 394 }
@@ -1,281 +1,281
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 23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
24 24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
25 25
26 26 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
27 27 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
28 28
29 29 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
30 30
31 31 //************
32 32 // RTEMS TASKS
33 33
34 34 //***
35 35 // F2
36 36 rtems_task avf2_task( rtems_task_argument argument )
37 37 {
38 38 rtems_event_set event_out;
39 39 rtems_status_code status;
40 40 rtems_id queue_id_prc2;
41 41 asm_msg msgForMATR;
42 42 ring_node *nodeForAveraging;
43 43 ring_node_asm *current_ring_node_asm_norm_f2;
44 44
45 45 unsigned int nb_norm_bp1;
46 46 unsigned int nb_norm_bp2;
47 47 unsigned int nb_norm_asm;
48 48
49 49 nb_norm_bp1 = 0;
50 50 nb_norm_bp2 = 0;
51 51 nb_norm_asm = 0;
52 52
53 53 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
54 54 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
55 55 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
56 56
57 57 BOOT_PRINTF("in AVF2 ***\n")
58 58
59 59 status = get_message_queue_id_prc2( &queue_id_prc2 );
60 60 if (status != RTEMS_SUCCESSFUL)
61 61 {
62 62 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
63 63 }
64 64
65 65 while(1){
66 66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
67 67
68 68 //****************************************
69 69 // initialize the mesage for the MATR task
70 70 msgForMATR.norm = current_ring_node_asm_norm_f2;
71 71 msgForMATR.burst_sbm = NULL;
72 72 msgForMATR.event = 0x00; // this composite event will be sent to the PRC2 task
73 73 //
74 74 //****************************************
75 75
76 76 nodeForAveraging = getRingNodeForAveraging( 2 );
77 77
78 78 // compute the average and store it in the averaged_sm_f2 buffer
79 79 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
80 80 nodeForAveraging,
81 81 nb_norm_bp1,
82 82 &msgForMATR );
83 83
84 84 // update nb_average
85 85 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
86 86 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
87 87 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
88 88
89 89 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
90 90 {
91 91 nb_norm_bp1 = 0;
92 92 // set another ring for the ASM storage
93 93 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
94 94 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
95 95 || (lfrCurrentMode == LFR_MODE_SBM2) )
96 96 {
97 97 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2;
98 98 }
99 99 }
100 100
101 101 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
102 102 {
103 103 nb_norm_bp2 = 0;
104 104 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 105 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 106 {
107 107 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2;
108 108 }
109 109 }
110 110
111 111 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
112 112 {
113 113 nb_norm_asm = 0;
114 114 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 115 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 116 {
117 117 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2;
118 118 }
119 119 }
120 120
121 121 //*************************
122 122 // send the message to MATR
123 123 if (msgForMATR.event != 0x00)
124 124 {
125 125 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC2);
126 126 }
127 127
128 128 if (status != RTEMS_SUCCESSFUL) {
129 129 PRINTF1("in AVF2 *** Error sending message to MATR, code %d\n", status)
130 130 }
131 131 }
132 132 }
133 133
134 134 rtems_task prc2_task( rtems_task_argument argument )
135 135 {
136 136 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
137 137 size_t size; // size of the incoming TC packet
138 138 asm_msg *incomingMsg;
139 139 //
140 140 rtems_status_code status;
141 141 rtems_id queue_id_send;
142 142 rtems_id queue_id_q_p2;
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 146
147 147 unsigned long long int localTime;
148 148
149 149 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
150 150 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
151 151 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
152 152
153 153 //*************
154 154 // NORM headers
155 155 BP_init_header( &packet_norm_bp1,
156 156 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
157 157 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
158 158 BP_init_header( &packet_norm_bp2,
159 159 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
160 160 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
161 161
162 162 status = get_message_queue_id_send( &queue_id_send );
163 163 if (status != RTEMS_SUCCESSFUL)
164 164 {
165 165 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
166 166 }
167 167 status = get_message_queue_id_prc2( &queue_id_q_p2);
168 168 if (status != RTEMS_SUCCESSFUL)
169 169 {
170 170 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
171 171 }
172 172
173 173 BOOT_PRINTF("in PRC2 ***\n")
174 174
175 175 while(1){
176 176 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
177 177 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
178 178
179 179 incomingMsg = (asm_msg*) incomingData;
180 180
181 181 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
182 182
183 183 localTime = getTimeAsUnsignedLongLongInt( );
184 184
185 185 //*****
186 186 //*****
187 187 // NORM
188 188 //*****
189 189 //*****
190 190 // 1) compress the matrix for Basic Parameters calculation
191 ASM_compress_reorganize_and_divide( asm_f2_patched_norm, compressed_sm_norm_f2,
191 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
192 192 nb_sm_before_f2.norm_bp1,
193 193 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
194 ASM_F2_INDICE_START );
194 ASM_F2_INDICE_START, CHANNELF2 );
195 195 // BP1_F2
196 196 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
197 197 {
198 198 // 1) compute the BP1 set
199 199 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
200 200 // 2) send the BP1 set
201 201 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
202 202 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
203 203 packet_norm_bp1.biaStatusInfo = pa_bia_status_info;
204 204 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
205 205 BP_send( (char *) &packet_norm_bp1, queue_id_send,
206 206 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
207 207 SID_NORM_BP1_F2 );
208 208 }
209 209 // BP2_F2
210 210 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
211 211 {
212 212 // 1) compute the BP2 set
213 213 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
214 214 // 2) send the BP2 set
215 215 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
216 216 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
217 217 packet_norm_bp2.biaStatusInfo = pa_bia_status_info;
218 218 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
219 219 BP_send( (char *) &packet_norm_bp2, queue_id_send,
220 220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
221 221 SID_NORM_BP2_F2 );
222 222 }
223 223
224 224 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
225 225 {
226 226 // 1) reorganize the ASM and divide
227 227 ASM_reorganize_and_divide( asm_f2_patched_norm,
228 228 (float*) current_ring_node_to_send_asm_f2->buffer_address,
229 229 nb_sm_before_f2.norm_bp1 );
230 230 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
231 231 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
232 232 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
233 233 // 3) send the spectral matrix packets
234 234 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
235 235 // change asm ring node
236 236 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
237 237 }
238 238
239 239 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
240 240
241 241 }
242 242 }
243 243
244 244 //**********
245 245 // FUNCTIONS
246 246
247 247 void reset_nb_sm_f2( void )
248 248 {
249 249 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
250 250 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
251 251 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];
252 252 }
253 253
254 254 void SM_average_f2( float *averaged_spec_mat_f2,
255 255 ring_node *ring_node,
256 256 unsigned int nbAverageNormF2,
257 257 asm_msg *msgForMATR )
258 258 {
259 259 float sum;
260 260 unsigned int i;
261 261
262 262 for(i=0; i<TOTAL_SIZE_SM; i++)
263 263 {
264 264 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
265 265 if ( (nbAverageNormF2 == 0) )
266 266 {
267 267 averaged_spec_mat_f2[ i ] = sum;
268 268 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
269 269 msgForMATR->fineTimeNORM = ring_node->fineTime;
270 270 }
271 271 else
272 272 {
273 273 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
274 274 }
275 275 }
276 276 }
277 277
278 278 void init_k_coefficients_prc2( void )
279 279 {
280 280 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
281 281 }
@@ -1,669 +1,689
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 "fsw_processing.h"
11 11 #include "fsw_processing_globals.c"
12 12 #include "fsw_init.h"
13 13
14 14 unsigned int nb_sm_f0;
15 15 unsigned int nb_sm_f0_aux_f1;
16 16 unsigned int nb_sm_f1;
17 17 unsigned int nb_sm_f0_aux_f2;
18 18
19 19 //************************
20 20 // spectral matrices rings
21 21 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
22 22 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
23 23 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
24 24 ring_node *current_ring_node_sm_f0;
25 25 ring_node *current_ring_node_sm_f1;
26 26 ring_node *current_ring_node_sm_f2;
27 27 ring_node *ring_node_for_averaging_sm_f0;
28 28 ring_node *ring_node_for_averaging_sm_f1;
29 29 ring_node *ring_node_for_averaging_sm_f2;
30 30
31 31 //
32 32 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
33 33 {
34 34 ring_node *node;
35 35
36 36 node = NULL;
37 37 switch ( frequencyChannel ) {
38 38 case 0:
39 39 node = ring_node_for_averaging_sm_f0;
40 40 break;
41 41 case 1:
42 42 node = ring_node_for_averaging_sm_f1;
43 43 break;
44 44 case 2:
45 45 node = ring_node_for_averaging_sm_f2;
46 46 break;
47 47 default:
48 48 break;
49 49 }
50 50
51 51 return node;
52 52 }
53 53
54 54 //***********************************************************
55 55 // Interrupt Service Routine for spectral matrices processing
56 56
57 57 void spectral_matrices_isr_f0( unsigned char statusReg )
58 58 {
59 59 unsigned char status;
60 60 rtems_status_code status_code;
61 61 ring_node *full_ring_node;
62 62
63 63 status = statusReg & 0x03; // [0011] get the status_ready_matrix_f0_x bits
64 64
65 65 switch(status)
66 66 {
67 67 case 0:
68 68 break;
69 69 case 3:
70 70 // UNEXPECTED VALUE
71 71 spectral_matrix_regs->status = 0x03; // [0011]
72 72 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
73 73 break;
74 74 case 1:
75 75 full_ring_node = current_ring_node_sm_f0->previous;
76 76 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
77 77 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
78 78 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
79 79 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
80 80 // if there are enough ring nodes ready, wake up an AVFx task
81 81 nb_sm_f0 = nb_sm_f0 + 1;
82 82 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
83 83 {
84 84 ring_node_for_averaging_sm_f0 = full_ring_node;
85 85 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
86 86 {
87 87 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
88 88 }
89 89 nb_sm_f0 = 0;
90 90 }
91 91 spectral_matrix_regs->status = 0x01; // [0000 0001]
92 92 break;
93 93 case 2:
94 94 full_ring_node = current_ring_node_sm_f0->previous;
95 95 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
96 96 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
97 97 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
98 98 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
99 99 // if there are enough ring nodes ready, wake up an AVFx task
100 100 nb_sm_f0 = nb_sm_f0 + 1;
101 101 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
102 102 {
103 103 ring_node_for_averaging_sm_f0 = full_ring_node;
104 104 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
105 105 {
106 106 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
107 107 }
108 108 nb_sm_f0 = 0;
109 109 }
110 110 spectral_matrix_regs->status = 0x02; // [0000 0010]
111 111 break;
112 112 }
113 113 }
114 114
115 115 void spectral_matrices_isr_f1( unsigned char statusReg )
116 116 {
117 117 rtems_status_code status_code;
118 118 unsigned char status;
119 119 ring_node *full_ring_node;
120 120
121 121 status = (statusReg & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
122 122
123 123 switch(status)
124 124 {
125 125 case 0:
126 126 break;
127 127 case 3:
128 128 // UNEXPECTED VALUE
129 129 spectral_matrix_regs->status = 0xc0; // [1100]
130 130 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
131 131 break;
132 132 case 1:
133 133 full_ring_node = current_ring_node_sm_f1->previous;
134 134 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
135 135 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
136 136 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
137 137 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
138 138 // if there are enough ring nodes ready, wake up an AVFx task
139 139 nb_sm_f1 = nb_sm_f1 + 1;
140 140 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
141 141 {
142 142 ring_node_for_averaging_sm_f1 = full_ring_node;
143 143 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
144 144 {
145 145 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
146 146 }
147 147 nb_sm_f1 = 0;
148 148 }
149 149 spectral_matrix_regs->status = 0x04; // [0000 0100]
150 150 break;
151 151 case 2:
152 152 full_ring_node = current_ring_node_sm_f1->previous;
153 153 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
154 154 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
155 155 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
156 156 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
157 157 // if there are enough ring nodes ready, wake up an AVFx task
158 158 nb_sm_f1 = nb_sm_f1 + 1;
159 159 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
160 160 {
161 161 ring_node_for_averaging_sm_f1 = full_ring_node;
162 162 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
163 163 {
164 164 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
165 165 }
166 166 nb_sm_f1 = 0;
167 167 }
168 168 spectral_matrix_regs->status = 0x08; // [1000 0000]
169 169 break;
170 170 }
171 171 }
172 172
173 173 void spectral_matrices_isr_f2( unsigned char statusReg )
174 174 {
175 175 unsigned char status;
176 176 rtems_status_code status_code;
177 177
178 178 status = (statusReg & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
179 179
180 180 switch(status)
181 181 {
182 182 case 0:
183 183 break;
184 184 case 3:
185 185 // UNEXPECTED VALUE
186 186 spectral_matrix_regs->status = 0x30; // [0011 0000]
187 187 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
188 188 break;
189 189 case 1:
190 190 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
191 191 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
192 192 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
193 193 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
194 194 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
195 195 spectral_matrix_regs->status = 0x10; // [0001 0000]
196 196 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
197 197 {
198 198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
199 199 }
200 200 break;
201 201 case 2:
202 202 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
203 203 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
204 204 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
205 205 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
206 206 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
207 207 spectral_matrix_regs->status = 0x20; // [0010 0000]
208 208 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
209 209 {
210 210 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
211 211 }
212 212 break;
213 213 }
214 214 }
215 215
216 216 void spectral_matrix_isr_error_handler( unsigned char statusReg )
217 217 {
218 218 rtems_status_code status_code;
219 219
220 220 if (statusReg & 0x7c0) // [0111 1100 0000]
221 221 {
222 222 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
223 223 }
224 224
225 225 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
226 226 }
227 227
228 228 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
229 229 {
230 230 // STATUS REGISTER
231 231 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
232 232 // 10 9 8
233 233 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
234 234 // 7 6 5 4 3 2 1 0
235 235
236 236 unsigned char statusReg;
237 237
238 238 statusReg = spectral_matrix_regs->status;
239 239
240 240 spectral_matrices_isr_f0( statusReg );
241 241
242 242 spectral_matrices_isr_f1( statusReg );
243 243
244 244 spectral_matrices_isr_f2( statusReg );
245 245
246 246 spectral_matrix_isr_error_handler( statusReg );
247 247 }
248 248
249 249 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
250 250 {
251 251 rtems_status_code status_code;
252 252
253 253 //***
254 254 // F0
255 255 nb_sm_f0 = nb_sm_f0 + 1;
256 256 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
257 257 {
258 258 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
259 259 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
260 260 {
261 261 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
262 262 }
263 263 nb_sm_f0 = 0;
264 264 }
265 265
266 266 //***
267 267 // F1
268 268 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
269 269 if (nb_sm_f0_aux_f1 == 6)
270 270 {
271 271 nb_sm_f0_aux_f1 = 0;
272 272 nb_sm_f1 = nb_sm_f1 + 1;
273 273 }
274 274 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
275 275 {
276 276 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
277 277 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
278 278 {
279 279 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
280 280 }
281 281 nb_sm_f1 = 0;
282 282 }
283 283
284 284 //***
285 285 // F2
286 286 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
287 287 if (nb_sm_f0_aux_f2 == 96)
288 288 {
289 289 nb_sm_f0_aux_f2 = 0;
290 290 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
291 291 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
292 292 {
293 293 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
294 294 }
295 295 }
296 296 }
297 297
298 298 //******************
299 299 // Spectral Matrices
300 300
301 301 void reset_nb_sm( void )
302 302 {
303 303 nb_sm_f0 = 0;
304 304 nb_sm_f0_aux_f1 = 0;
305 305 nb_sm_f0_aux_f2 = 0;
306 306
307 307 nb_sm_f1 = 0;
308 308 }
309 309
310 310 void SM_init_rings( void )
311 311 {
312 312 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
313 313 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
314 314 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
315 315
316 316 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
317 317 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
318 318 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
319 319 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
320 320 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
321 321 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
322 322 }
323 323
324 324 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
325 325 {
326 326 unsigned char i;
327 327
328 328 ring[ nbNodes - 1 ].next
329 329 = (ring_node_asm*) &ring[ 0 ];
330 330
331 331 for(i=0; i<nbNodes-1; i++)
332 332 {
333 333 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
334 334 }
335 335 }
336 336
337 337 void SM_reset_current_ring_nodes( void )
338 338 {
339 339 current_ring_node_sm_f0 = sm_ring_f0[0].next;
340 340 current_ring_node_sm_f1 = sm_ring_f1[0].next;
341 341 current_ring_node_sm_f2 = sm_ring_f2[0].next;
342 342
343 343 ring_node_for_averaging_sm_f0 = NULL;
344 344 ring_node_for_averaging_sm_f1 = NULL;
345 345 ring_node_for_averaging_sm_f2 = NULL;
346 346 }
347 347
348 348 //*****************
349 349 // Basic Parameters
350 350
351 351 void BP_init_header( bp_packet *packet,
352 352 unsigned int apid, unsigned char sid,
353 353 unsigned int packetLength, unsigned char blkNr )
354 354 {
355 355 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
356 356 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
357 357 packet->reserved = 0x00;
358 358 packet->userApplication = CCSDS_USER_APP;
359 359 packet->packetID[0] = (unsigned char) (apid >> 8);
360 360 packet->packetID[1] = (unsigned char) (apid);
361 361 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
362 362 packet->packetSequenceControl[1] = 0x00;
363 363 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
364 364 packet->packetLength[1] = (unsigned char) (packetLength);
365 365 // DATA FIELD HEADER
366 366 packet->spare1_pusVersion_spare2 = 0x10;
367 367 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
368 368 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
369 369 packet->destinationID = TM_DESTINATION_ID_GROUND;
370 370 packet->time[0] = 0x00;
371 371 packet->time[1] = 0x00;
372 372 packet->time[2] = 0x00;
373 373 packet->time[3] = 0x00;
374 374 packet->time[4] = 0x00;
375 375 packet->time[5] = 0x00;
376 376 // AUXILIARY DATA HEADER
377 377 packet->sid = sid;
378 378 packet->biaStatusInfo = 0x00;
379 379 packet->sy_lfr_common_parameters_spare = 0x00;
380 380 packet->sy_lfr_common_parameters = 0x00;
381 381 packet->acquisitionTime[0] = 0x00;
382 382 packet->acquisitionTime[1] = 0x00;
383 383 packet->acquisitionTime[2] = 0x00;
384 384 packet->acquisitionTime[3] = 0x00;
385 385 packet->acquisitionTime[4] = 0x00;
386 386 packet->acquisitionTime[5] = 0x00;
387 387 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
388 388 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
389 389 }
390 390
391 391 void BP_init_header_with_spare( bp_packet_with_spare *packet,
392 392 unsigned int apid, unsigned char sid,
393 393 unsigned int packetLength , unsigned char blkNr)
394 394 {
395 395 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
396 396 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
397 397 packet->reserved = 0x00;
398 398 packet->userApplication = CCSDS_USER_APP;
399 399 packet->packetID[0] = (unsigned char) (apid >> 8);
400 400 packet->packetID[1] = (unsigned char) (apid);
401 401 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
402 402 packet->packetSequenceControl[1] = 0x00;
403 403 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
404 404 packet->packetLength[1] = (unsigned char) (packetLength);
405 405 // DATA FIELD HEADER
406 406 packet->spare1_pusVersion_spare2 = 0x10;
407 407 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
408 408 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
409 409 packet->destinationID = TM_DESTINATION_ID_GROUND;
410 410 // AUXILIARY DATA HEADER
411 411 packet->sid = sid;
412 412 packet->biaStatusInfo = 0x00;
413 413 packet->sy_lfr_common_parameters_spare = 0x00;
414 414 packet->sy_lfr_common_parameters = 0x00;
415 415 packet->time[0] = 0x00;
416 416 packet->time[0] = 0x00;
417 417 packet->time[0] = 0x00;
418 418 packet->time[0] = 0x00;
419 419 packet->time[0] = 0x00;
420 420 packet->time[0] = 0x00;
421 421 packet->source_data_spare = 0x00;
422 422 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
423 423 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
424 424 }
425 425
426 426 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
427 427 {
428 428 rtems_status_code status;
429 429
430 430 // SEND PACKET
431 431 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
432 432 if (status != RTEMS_SUCCESSFUL)
433 433 {
434 434 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
435 435 }
436 436 }
437 437
438 438 //******************
439 439 // general functions
440 440
441 441 void reset_sm_status( void )
442 442 {
443 443 // error
444 444 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
445 445 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
446 446 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
447 447 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
448 448
449 449 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
450 450 }
451 451
452 452 void reset_spectral_matrix_regs( void )
453 453 {
454 454 /** This function resets the spectral matrices module registers.
455 455 *
456 456 * The registers affected by this function are located at the following offset addresses:
457 457 *
458 458 * - 0x00 config
459 459 * - 0x04 status
460 460 * - 0x08 matrixF0_Address0
461 461 * - 0x10 matrixFO_Address1
462 462 * - 0x14 matrixF1_Address
463 463 * - 0x18 matrixF2_Address
464 464 *
465 465 */
466 466
467 467 set_sm_irq_onError( 0 );
468 468
469 469 set_sm_irq_onNewMatrix( 0 );
470 470
471 471 reset_sm_status();
472 472
473 473 // F1
474 474 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
475 475 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
476 476 // F2
477 477 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
478 478 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
479 479 // F3
480 480 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
481 481 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
482 482
483 483 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
484 484 }
485 485
486 486 void set_time( unsigned char *time, unsigned char * timeInBuffer )
487 487 {
488 488 time[0] = timeInBuffer[0];
489 489 time[1] = timeInBuffer[1];
490 490 time[2] = timeInBuffer[2];
491 491 time[3] = timeInBuffer[3];
492 492 time[4] = timeInBuffer[6];
493 493 time[5] = timeInBuffer[7];
494 494 }
495 495
496 496 unsigned long long int get_acquisition_time( unsigned char *timePtr )
497 497 {
498 498 unsigned long long int acquisitionTimeAslong;
499 499 acquisitionTimeAslong = 0x00;
500 500 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
501 501 + ( (unsigned long long int) timePtr[1] << 32 )
502 502 + ( (unsigned long long int) timePtr[2] << 24 )
503 503 + ( (unsigned long long int) timePtr[3] << 16 )
504 504 + ( (unsigned long long int) timePtr[6] << 8 )
505 505 + ( (unsigned long long int) timePtr[7] );
506 506 return acquisitionTimeAslong;
507 507 }
508 508
509 509 unsigned char getSID( rtems_event_set event )
510 510 {
511 511 unsigned char sid;
512 512
513 513 rtems_event_set eventSetBURST;
514 514 rtems_event_set eventSetSBM;
515 515
516 516 //******
517 517 // BURST
518 518 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
519 519 | RTEMS_EVENT_BURST_BP1_F1
520 520 | RTEMS_EVENT_BURST_BP2_F0
521 521 | RTEMS_EVENT_BURST_BP2_F1;
522 522
523 523 //****
524 524 // SBM
525 525 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
526 526 | RTEMS_EVENT_SBM_BP1_F1
527 527 | RTEMS_EVENT_SBM_BP2_F0
528 528 | RTEMS_EVENT_SBM_BP2_F1;
529 529
530 530 if (event & eventSetBURST)
531 531 {
532 532 sid = SID_BURST_BP1_F0;
533 533 }
534 534 else if (event & eventSetSBM)
535 535 {
536 536 sid = SID_SBM1_BP1_F0;
537 537 }
538 538 else
539 539 {
540 540 sid = 0;
541 541 }
542 542
543 543 return sid;
544 544 }
545 545
546 546 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
547 547 {
548 548 unsigned int i;
549 549 float re;
550 550 float im;
551 551
552 552 for (i=0; i<NB_BINS_PER_SM; i++){
553 553 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
554 554 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
555 555 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
556 556 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
557 557 }
558 558 }
559 559
560 560 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
561 561 {
562 562 unsigned int i;
563 563 float re;
564 564
565 565 for (i=0; i<NB_BINS_PER_SM; i++){
566 566 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
567 567 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
568 568 }
569 569 }
570 570
571 571 void ASM_patch( float *inputASM, float *outputASM )
572 572 {
573 573 extractReImVectors( inputASM, outputASM, 1); // b1b2
574 574 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
575 575 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
576 576 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
577 577 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
578 578 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
579 579 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
580 580 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
581 581 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
582 582 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
583 583
584 584 copyReVectors(inputASM, outputASM, 0 ); // b1b1
585 585 copyReVectors(inputASM, outputASM, 9 ); // b2b2
586 586 copyReVectors(inputASM, outputASM, 16); // b3b3
587 587 copyReVectors(inputASM, outputASM, 21); // e1e1
588 588 copyReVectors(inputASM, outputASM, 24); // e2e2
589 589 }
590 590
591 591 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
592 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
592 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
593 unsigned char ASMIndexStart,
594 unsigned char channel )
593 595 {
594 596 //*************
595 597 // input format
596 598 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
597 599 //**************
598 600 // output format
599 601 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
600 602 //************
601 603 // compression
602 604 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
603 605 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
604 606
605 607 int frequencyBin;
606 608 int asmComponent;
607 609 int offsetASM;
608 610 int offsetCompressed;
609 611 int offsetFBin;
610 612 int fBinMask;
611 613 int k;
612 614
613 615 // BUILD DATA
614 616 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
615 617 {
616 618 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
617 619 {
618 620 offsetCompressed = // NO TIME OFFSET
619 621 frequencyBin * NB_VALUES_PER_SM
620 622 + asmComponent;
621 623 offsetASM = // NO TIME OFFSET
622 624 asmComponent * NB_BINS_PER_SM
623 625 + ASMIndexStart
624 626 + frequencyBin * nbBinsToAverage;
625 627 offsetFBin = ASMIndexStart
626 628 + frequencyBin * nbBinsToAverage;
627 629 compressed_spec_mat[ offsetCompressed ] = 0;
628 630 for ( k = 0; k < nbBinsToAverage; k++ )
629 631 {
630 fBinMask = getFBinMask( offsetFBin + k );
632 fBinMask = getFBinMask( offsetFBin + k, channel );
631 633 compressed_spec_mat[offsetCompressed ] =
632 634 ( compressed_spec_mat[ offsetCompressed ]
633 635 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
634 636 }
635 637 compressed_spec_mat[ offsetCompressed ] =
636 638 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
637 639 }
638 640 }
639 641
640 642 }
641 643
642 int getFBinMask( int index )
644 int getFBinMask( int index, unsigned char channel )
643 645 {
644 646 unsigned int indexInChar;
645 647 unsigned int indexInTheChar;
646 648 int fbin;
649 unsigned char *sy_lfr_fbins_fx_word1;
650
651 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
652
653 switch(channel)
654 {
655 case 0:
656 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
657 break;
658 case 1:
659 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
660 break;
661 case 2:
662 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
663 break;
664 default:
665 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
666 }
647 667
648 668 indexInChar = index >> 3;
649 669 indexInTheChar = index - indexInChar * 8;
650 670
651 fbin = (int) ((parameter_dump_packet.sy_lfr_fbins_f0_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
671 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
652 672
653 673 return fbin;
654 674 }
655 675
656 676 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
657 677 {
658 678 unsigned char bin;
659 679 unsigned char kcoeff;
660 680
661 681 for (bin=0; bin<nb_bins_norm; bin++)
662 682 {
663 683 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
664 684 {
665 685 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
666 686 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
667 687 }
668 688 }
669 689 }
General Comments 0
You need to be logged in to leave comments. Login now