##// END OF EJS Templates
PAS filtering implemented
paul -
r289:a907a62ed869 R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 dad8371a5549f3395f975fddc33098b05fd829f4 header/lfr_common_headers
2 2450d4935652a4d0370245cc7fc60a4c51e6fc9b header/lfr_common_headers
@@ -1,123 +1,123
1 TEMPLATE = app
1 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options =
3 # CONFIG options =
4 # verbose
4 # verbose
5 # boot_messages
5 # boot_messages
6 # debug_messages
6 # debug_messages
7 # cpu_usage_report
7 # cpu_usage_report
8 # stack_report
8 # stack_report
9 # vhdl_dev
9 # vhdl_dev
10 # debug_tch
10 # debug_tch
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 # debug_watchdog
12 # debug_watchdog
13 CONFIG += console verbose lpp_dpu_destid
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 CONFIG -= qt
14 CONFIG -= qt
15
15
16 include(./sparc.pri)
16 include(./sparc.pri)
17
17
18 # flight software version
18 # flight software version
19 SWVERSION=-1-0
19 SWVERSION=-1-0
20 DEFINES += SW_VERSION_N1=3 # major
20 DEFINES += SW_VERSION_N1=3 # major
21 DEFINES += SW_VERSION_N2=1 # minor
21 DEFINES += SW_VERSION_N2=1 # minor
22 DEFINES += SW_VERSION_N3=0 # patch
22 DEFINES += SW_VERSION_N3=0 # patch
23 DEFINES += SW_VERSION_N4=0 # internal
23 DEFINES += SW_VERSION_N4=0 # internal
24
24
25 # <GCOV>
25 # <GCOV>
26 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
26 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
27 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
27 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
28 # </GCOV>
28 # </GCOV>
29
29
30 # <CHANGE BEFORE FLIGHT>
30 # <CHANGE BEFORE FLIGHT>
31 contains( CONFIG, lpp_dpu_destid ) {
31 contains( CONFIG, lpp_dpu_destid ) {
32 DEFINES += LPP_DPU_DESTID
32 DEFINES += LPP_DPU_DESTID
33 }
33 }
34 # </CHANGE BEFORE FLIGHT>
34 # </CHANGE BEFORE FLIGHT>
35
35
36 contains( CONFIG, debug_tch ) {
36 contains( CONFIG, debug_tch ) {
37 DEFINES += DEBUG_TCH
37 DEFINES += DEBUG_TCH
38 }
38 }
39 DEFINES += MSB_FIRST_TCH
39 DEFINES += MSB_FIRST_TCH
40
40
41 contains( CONFIG, vhdl_dev ) {
41 contains( CONFIG, vhdl_dev ) {
42 DEFINES += VHDL_DEV
42 DEFINES += VHDL_DEV
43 }
43 }
44
44
45 contains( CONFIG, verbose ) {
45 contains( CONFIG, verbose ) {
46 DEFINES += PRINT_MESSAGES_ON_CONSOLE
46 DEFINES += PRINT_MESSAGES_ON_CONSOLE
47 }
47 }
48
48
49 contains( CONFIG, debug_messages ) {
49 contains( CONFIG, debug_messages ) {
50 DEFINES += DEBUG_MESSAGES
50 DEFINES += DEBUG_MESSAGES
51 }
51 }
52
52
53 contains( CONFIG, cpu_usage_report ) {
53 contains( CONFIG, cpu_usage_report ) {
54 DEFINES += PRINT_TASK_STATISTICS
54 DEFINES += PRINT_TASK_STATISTICS
55 }
55 }
56
56
57 contains( CONFIG, stack_report ) {
57 contains( CONFIG, stack_report ) {
58 DEFINES += PRINT_STACK_REPORT
58 DEFINES += PRINT_STACK_REPORT
59 }
59 }
60
60
61 contains( CONFIG, boot_messages ) {
61 contains( CONFIG, boot_messages ) {
62 DEFINES += BOOT_MESSAGES
62 DEFINES += BOOT_MESSAGES
63 }
63 }
64
64
65 contains( CONFIG, debug_watchdog ) {
65 contains( CONFIG, debug_watchdog ) {
66 DEFINES += DEBUG_WATCHDOG
66 DEFINES += DEBUG_WATCHDOG
67 }
67 }
68
68
69 #doxygen.target = doxygen
69 #doxygen.target = doxygen
70 #doxygen.commands = doxygen ../doc/Doxyfile
70 #doxygen.commands = doxygen ../doc/Doxyfile
71 #QMAKE_EXTRA_TARGETS += doxygen
71 #QMAKE_EXTRA_TARGETS += doxygen
72
72
73 TARGET = fsw
73 TARGET = fsw
74
74
75 INCLUDEPATH += \
75 INCLUDEPATH += \
76 $${PWD}/../src \
76 $${PWD}/../src \
77 $${PWD}/../header \
77 $${PWD}/../header \
78 $${PWD}/../header/lfr_common_headers \
78 $${PWD}/../header/lfr_common_headers \
79 $${PWD}/../header/processing \
79 $${PWD}/../header/processing \
80 $${PWD}/../LFR_basic-parameters
80 $${PWD}/../LFR_basic-parameters
81
81
82 SOURCES += \
82 SOURCES += \
83 ../src/wf_handler.c \
83 ../src/wf_handler.c \
84 ../src/tc_handler.c \
84 ../src/tc_handler.c \
85 ../src/fsw_misc.c \
85 ../src/fsw_misc.c \
86 ../src/fsw_init.c \
86 ../src/fsw_init.c \
87 ../src/fsw_globals.c \
87 ../src/fsw_globals.c \
88 ../src/fsw_spacewire.c \
88 ../src/fsw_spacewire.c \
89 ../src/tc_load_dump_parameters.c \
89 ../src/tc_load_dump_parameters.c \
90 ../src/tm_lfr_tc_exe.c \
90 ../src/tm_lfr_tc_exe.c \
91 ../src/tc_acceptance.c \
91 ../src/tc_acceptance.c \
92 ../src/processing/fsw_processing.c \
92 ../src/processing/fsw_processing.c \
93 ../src/processing/avf0_prc0.c \
93 ../src/processing/avf0_prc0.c \
94 ../src/processing/avf1_prc1.c \
94 ../src/processing/avf1_prc1.c \
95 ../src/processing/avf2_prc2.c \
95 ../src/processing/avf2_prc2.c \
96 ../src/lfr_cpu_usage_report.c \
96 ../src/lfr_cpu_usage_report.c \
97 ../LFR_basic-parameters/basic_parameters.c
97 ../LFR_basic-parameters/basic_parameters.c
98
98
99 HEADERS += \
99 HEADERS += \
100 ../header/wf_handler.h \
100 ../header/wf_handler.h \
101 ../header/tc_handler.h \
101 ../header/tc_handler.h \
102 ../header/grlib_regs.h \
102 ../header/grlib_regs.h \
103 ../header/fsw_misc.h \
103 ../header/fsw_misc.h \
104 ../header/fsw_init.h \
104 ../header/fsw_init.h \
105 ../header/fsw_spacewire.h \
105 ../header/fsw_spacewire.h \
106 ../header/tc_load_dump_parameters.h \
106 ../header/tc_load_dump_parameters.h \
107 ../header/tm_lfr_tc_exe.h \
107 ../header/tm_lfr_tc_exe.h \
108 ../header/tc_acceptance.h \
108 ../header/tc_acceptance.h \
109 ../header/processing/fsw_processing.h \
109 ../header/processing/fsw_processing.h \
110 ../header/processing/avf0_prc0.h \
110 ../header/processing/avf0_prc0.h \
111 ../header/processing/avf1_prc1.h \
111 ../header/processing/avf1_prc1.h \
112 ../header/processing/avf2_prc2.h \
112 ../header/processing/avf2_prc2.h \
113 ../header/fsw_params_wf_handler.h \
113 ../header/fsw_params_wf_handler.h \
114 ../header/lfr_cpu_usage_report.h \
114 ../header/lfr_cpu_usage_report.h \
115 ../header/lfr_common_headers/ccsds_types.h \
115 ../header/lfr_common_headers/ccsds_types.h \
116 ../header/lfr_common_headers/fsw_params.h \
116 ../header/lfr_common_headers/fsw_params.h \
117 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
117 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
118 ../header/lfr_common_headers/fsw_params_processing.h \
118 ../header/lfr_common_headers/fsw_params_processing.h \
119 ../header/lfr_common_headers/tm_byte_positions.h \
119 ../header/lfr_common_headers/tm_byte_positions.h \
120 ../LFR_basic-parameters/basic_parameters.h \
120 ../LFR_basic-parameters/basic_parameters.h \
121 ../LFR_basic-parameters/basic_parameters_params.h \
121 ../LFR_basic-parameters/basic_parameters_params.h \
122 ../header/GscMemoryLPP.hpp
122 ../header/GscMemoryLPP.hpp
123
123
@@ -1,332 +1,361
1 #ifndef FSW_PROCESSING_H_INCLUDED
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <math.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h>
8 #include <stdio.h>
9 #include <math.h>
9 #include <math.h>
10 #include <grlib_regs.h>
10 #include <grlib_regs.h>
11
11
12 #include "fsw_params.h"
12 #include "fsw_params.h"
13
13
14 typedef struct ring_node_asm
14 typedef struct ring_node_asm
15 {
15 {
16 struct ring_node_asm *next;
16 struct ring_node_asm *next;
17 float matrix[ TOTAL_SIZE_SM ];
17 float matrix[ TOTAL_SIZE_SM ];
18 unsigned int status;
18 unsigned int status;
19 } ring_node_asm;
19 } ring_node_asm;
20
20
21 typedef struct
21 typedef struct
22 {
22 {
23 unsigned char targetLogicalAddress;
23 unsigned char targetLogicalAddress;
24 unsigned char protocolIdentifier;
24 unsigned char protocolIdentifier;
25 unsigned char reserved;
25 unsigned char reserved;
26 unsigned char userApplication;
26 unsigned char userApplication;
27 unsigned char packetID[2];
27 unsigned char packetID[2];
28 unsigned char packetSequenceControl[2];
28 unsigned char packetSequenceControl[2];
29 unsigned char packetLength[2];
29 unsigned char packetLength[2];
30 // DATA FIELD HEADER
30 // DATA FIELD HEADER
31 unsigned char spare1_pusVersion_spare2;
31 unsigned char spare1_pusVersion_spare2;
32 unsigned char serviceType;
32 unsigned char serviceType;
33 unsigned char serviceSubType;
33 unsigned char serviceSubType;
34 unsigned char destinationID;
34 unsigned char destinationID;
35 unsigned char time[6];
35 unsigned char time[6];
36 // AUXILIARY HEADER
36 // AUXILIARY HEADER
37 unsigned char sid;
37 unsigned char sid;
38 unsigned char pa_bia_status_info;
38 unsigned char pa_bia_status_info;
39 unsigned char sy_lfr_common_parameters_spare;
39 unsigned char sy_lfr_common_parameters_spare;
40 unsigned char sy_lfr_common_parameters;
40 unsigned char sy_lfr_common_parameters;
41 unsigned char acquisitionTime[6];
41 unsigned char acquisitionTime[6];
42 unsigned char pa_lfr_bp_blk_nr[2];
42 unsigned char pa_lfr_bp_blk_nr[2];
43 // SOURCE DATA
43 // SOURCE DATA
44 unsigned char data[ 780 ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
44 unsigned char data[ 780 ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
45 } bp_packet;
45 } bp_packet;
46
46
47 typedef struct
47 typedef struct
48 {
48 {
49 unsigned char targetLogicalAddress;
49 unsigned char targetLogicalAddress;
50 unsigned char protocolIdentifier;
50 unsigned char protocolIdentifier;
51 unsigned char reserved;
51 unsigned char reserved;
52 unsigned char userApplication;
52 unsigned char userApplication;
53 unsigned char packetID[2];
53 unsigned char packetID[2];
54 unsigned char packetSequenceControl[2];
54 unsigned char packetSequenceControl[2];
55 unsigned char packetLength[2];
55 unsigned char packetLength[2];
56 // DATA FIELD HEADER
56 // DATA FIELD HEADER
57 unsigned char spare1_pusVersion_spare2;
57 unsigned char spare1_pusVersion_spare2;
58 unsigned char serviceType;
58 unsigned char serviceType;
59 unsigned char serviceSubType;
59 unsigned char serviceSubType;
60 unsigned char destinationID;
60 unsigned char destinationID;
61 unsigned char time[6];
61 unsigned char time[6];
62 // AUXILIARY HEADER
62 // AUXILIARY HEADER
63 unsigned char sid;
63 unsigned char sid;
64 unsigned char pa_bia_status_info;
64 unsigned char pa_bia_status_info;
65 unsigned char sy_lfr_common_parameters_spare;
65 unsigned char sy_lfr_common_parameters_spare;
66 unsigned char sy_lfr_common_parameters;
66 unsigned char sy_lfr_common_parameters;
67 unsigned char acquisitionTime[6];
67 unsigned char acquisitionTime[6];
68 unsigned char source_data_spare;
68 unsigned char source_data_spare;
69 unsigned char pa_lfr_bp_blk_nr[2];
69 unsigned char pa_lfr_bp_blk_nr[2];
70 // SOURCE DATA
70 // SOURCE DATA
71 unsigned char data[ 143 ]; // 13 bins * 11 Bytes
71 unsigned char data[ 143 ]; // 13 bins * 11 Bytes
72 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
72 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
73
73
74 typedef struct asm_msg
74 typedef struct asm_msg
75 {
75 {
76 ring_node_asm *norm;
76 ring_node_asm *norm;
77 ring_node_asm *burst_sbm;
77 ring_node_asm *burst_sbm;
78 rtems_event_set event;
78 rtems_event_set event;
79 unsigned int coarseTimeNORM;
79 unsigned int coarseTimeNORM;
80 unsigned int fineTimeNORM;
80 unsigned int fineTimeNORM;
81 unsigned int coarseTimeSBM;
81 unsigned int coarseTimeSBM;
82 unsigned int fineTimeSBM;
82 unsigned int fineTimeSBM;
83 unsigned int numberOfSMInASMNORM;
84 unsigned int numberOfSMInASMSBM;
83 } asm_msg;
85 } asm_msg;
84
86
85 extern unsigned char thisIsAnASMRestart;
87 extern unsigned char thisIsAnASMRestart;
86
88
87 extern volatile int sm_f0[ ];
89 extern volatile int sm_f0[ ];
88 extern volatile int sm_f1[ ];
90 extern volatile int sm_f1[ ];
89 extern volatile int sm_f2[ ];
91 extern volatile int sm_f2[ ];
92 extern unsigned int acquisitionDurations[];
90
93
91 // parameters
94 // parameters
92 extern struct param_local_str param_local;
95 extern struct param_local_str param_local;
93 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
96 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
94
97
95 // registers
98 // registers
96 extern time_management_regs_t *time_management_regs;
99 extern time_management_regs_t *time_management_regs;
97 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
100 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
98
101
99 extern rtems_name misc_name[5];
102 extern rtems_name misc_name[5];
100 extern rtems_id Task_id[20]; /* array of task ids */
103 extern rtems_id Task_id[20]; /* array of task ids */
101
104
102 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
105 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
103 // ISR
106 // ISR
104 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
107 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
105
108
106 //******************
109 //******************
107 // Spectral Matrices
110 // Spectral Matrices
108 void reset_nb_sm( void );
111 void reset_nb_sm( void );
109 // SM
112 // SM
110 void SM_init_rings( void );
113 void SM_init_rings( void );
111 void SM_reset_current_ring_nodes( void );
114 void SM_reset_current_ring_nodes( void );
112 // ASM
115 // ASM
113 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
116 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
114
117
115 //*****************
118 //*****************
116 // Basic Parameters
119 // Basic Parameters
117
120
118 void BP_reset_current_ring_nodes( void );
121 void BP_reset_current_ring_nodes( void );
119 void BP_init_header(bp_packet *packet,
122 void BP_init_header(bp_packet *packet,
120 unsigned int apid, unsigned char sid,
123 unsigned int apid, unsigned char sid,
121 unsigned int packetLength , unsigned char blkNr);
124 unsigned int packetLength , unsigned char blkNr);
122 void BP_init_header_with_spare(bp_packet_with_spare *packet,
125 void BP_init_header_with_spare(bp_packet_with_spare *packet,
123 unsigned int apid, unsigned char sid,
126 unsigned int apid, unsigned char sid,
124 unsigned int packetLength, unsigned char blkNr );
127 unsigned int packetLength, unsigned char blkNr );
125 void BP_send( char *data,
128 void BP_send( char *data,
126 rtems_id queue_id,
129 rtems_id queue_id,
127 unsigned int nbBytesToSend , unsigned int sid );
130 unsigned int nbBytesToSend , unsigned int sid );
128 void BP_send_s1_s2(char *data,
131 void BP_send_s1_s2(char *data,
129 rtems_id queue_id,
132 rtems_id queue_id,
130 unsigned int nbBytesToSend, unsigned int sid );
133 unsigned int nbBytesToSend, unsigned int sid );
131
134
132 //******************
135 //******************
133 // general functions
136 // general functions
134 void reset_sm_status( void );
137 void reset_sm_status( void );
135 void reset_spectral_matrix_regs( void );
138 void reset_spectral_matrix_regs( void );
136 void set_time(unsigned char *time, unsigned char *timeInBuffer );
139 void set_time(unsigned char *time, unsigned char *timeInBuffer );
137 unsigned long long int get_acquisition_time( unsigned char *timePtr );
140 unsigned long long int get_acquisition_time( unsigned char *timePtr );
138 unsigned char getSID( rtems_event_set event );
141 unsigned char getSID( rtems_event_set event );
139
142
140 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
143 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
141 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
144 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
142
145
143 //***************************************
146 //***************************************
144 // DEFINITIONS OF STATIC INLINE FUNCTIONS
147 // DEFINITIONS OF STATIC INLINE FUNCTIONS
145 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
148 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
146 ring_node *ring_node_tab[],
149 ring_node *ring_node_tab[],
147 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
150 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
148 asm_msg *msgForMATR );
151 asm_msg *msgForMATR , unsigned char channel);
149
150 static inline void SM_average_debug(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
151 ring_node *ring_node_tab[],
152 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
153 asm_msg *msgForMATR );
154
152
155 void ASM_patch( float *inputASM, float *outputASM );
153 void ASM_patch( float *inputASM, float *outputASM );
156
154
157 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
155 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
158
156
159 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
157 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
160 float divider );
158 float divider );
161
159
162 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
160 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
163 float divider,
161 float divider,
164 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
162 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
165
163
166 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
164 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
167
165
166 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
167
168 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
168 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
169 ring_node *ring_node_tab[],
169 ring_node *ring_node_tab[],
170 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
170 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
171 asm_msg *msgForMATR )
171 asm_msg *msgForMATR, unsigned char channel )
172 {
172 {
173 float sum;
173 float sum;
174 unsigned int i;
174 unsigned int i;
175 unsigned int k;
176 unsigned char incomingSMIsValid[8];
177 unsigned int numberOfValidSM;
178 unsigned char isValid;
175
179
180 //**************
181 // PAS FILTERING
182 // check acquisitionTime of the incoming data
183 numberOfValidSM = 0;
184 for (k=0; k<8; k++)
185 {
186 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
187 incomingSMIsValid[k] = isValid;
188 numberOfValidSM = numberOfValidSM + isValid;
189 }
190
191 //************************
192 // AVERAGE SPECTRAL MATRIX
176 for(i=0; i<TOTAL_SIZE_SM; i++)
193 for(i=0; i<TOTAL_SIZE_SM; i++)
177 {
194 {
178 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
195 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
179 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
196 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
180 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
197 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
181 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
198 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
182 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
199 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
183 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
200 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
184 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
201 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
185 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
202 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
203
204 sum = ( (incomingSMIsValid[0] == 1) ? ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] : 0.0 )
205 + ( (incomingSMIsValid[1] == 1) ? ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] : 0.0 )
206 + ( (incomingSMIsValid[2] == 1) ? ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] : 0.0 )
207 + ( (incomingSMIsValid[3] == 1) ? ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] : 0.0 )
208 + ( (incomingSMIsValid[4] == 1) ? ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] : 0.0 )
209 + ( (incomingSMIsValid[5] == 1) ? ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] : 0.0 )
210 + ( (incomingSMIsValid[6] == 1) ? ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] : 0.0 )
211 + ( (incomingSMIsValid[7] == 1) ? ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ] : 0.0 );
186
212
187 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
213 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
188 {
214 {
189 averaged_spec_mat_NORM[ i ] = sum;
215 averaged_spec_mat_NORM[ i ] = sum;
190 averaged_spec_mat_SBM[ i ] = sum;
216 averaged_spec_mat_SBM[ i ] = sum;
191 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
217 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
192 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
218 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
193 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
219 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
194 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
220 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
195 }
221 }
196 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
222 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
197 {
223 {
198 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
224 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
199 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
225 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
200 }
226 }
201 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
227 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
202 {
228 {
203 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
229 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
204 averaged_spec_mat_SBM[ i ] = sum;
230 averaged_spec_mat_SBM[ i ] = sum;
205 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
231 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
206 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
232 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
207 }
233 }
208 else
234 else
209 {
235 {
210 averaged_spec_mat_NORM[ i ] = sum;
236 averaged_spec_mat_NORM[ i ] = sum;
211 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
237 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
212 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
238 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
213 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
239 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
214 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
240 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
215 }
241 }
216 }
242 }
217 }
218
243
219 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
244 //*******************
220 ring_node *ring_node_tab[],
245 // UPDATE SM COUNTERS
221 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
246 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
222 asm_msg *msgForMATR )
247 {
223 {
248 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
224 float sum;
249 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
225 unsigned int i;
250 }
226
251 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
227 for(i=0; i<TOTAL_SIZE_SM; i++)
228 {
252 {
229 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
253 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
230 averaged_spec_mat_NORM[ i ] = sum;
254 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
231 averaged_spec_mat_SBM[ i ] = sum;
255 }
232 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
256 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
233 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
257 {
234 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
258 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
235 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
259 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
260 }
261 else
262 {
263 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
264 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
236 }
265 }
237 }
266 }
238
267
239 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
268 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
240 {
269 {
241 int frequencyBin;
270 int frequencyBin;
242 int asmComponent;
271 int asmComponent;
243 unsigned int offsetASM;
272 unsigned int offsetASM;
244 unsigned int offsetASMReorganized;
273 unsigned int offsetASMReorganized;
245
274
246 // BUILD DATA
275 // BUILD DATA
247 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
276 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
248 {
277 {
249 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
278 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
250 {
279 {
251 offsetASMReorganized =
280 offsetASMReorganized =
252 frequencyBin * NB_VALUES_PER_SM
281 frequencyBin * NB_VALUES_PER_SM
253 + asmComponent;
282 + asmComponent;
254 offsetASM =
283 offsetASM =
255 asmComponent * NB_BINS_PER_SM
284 asmComponent * NB_BINS_PER_SM
256 + frequencyBin;
285 + frequencyBin;
257 averaged_spec_mat_reorganized[offsetASMReorganized ] =
286 averaged_spec_mat_reorganized[offsetASMReorganized ] =
258 averaged_spec_mat[ offsetASM ] / divider;
287 (divider != 0.0) ? averaged_spec_mat[ offsetASM ] / divider : 0.0;
259 }
288 }
260 }
289 }
261 }
290 }
262
291
263 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
292 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
264 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
293 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
265 {
294 {
266 int frequencyBin;
295 int frequencyBin;
267 int asmComponent;
296 int asmComponent;
268 int offsetASM;
297 int offsetASM;
269 int offsetCompressed;
298 int offsetCompressed;
270 int k;
299 int k;
271
300
272 // BUILD DATA
301 // BUILD DATA
273 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
302 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
274 {
303 {
275 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
304 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
276 {
305 {
277 offsetCompressed = // NO TIME OFFSET
306 offsetCompressed = // NO TIME OFFSET
278 frequencyBin * NB_VALUES_PER_SM
307 frequencyBin * NB_VALUES_PER_SM
279 + asmComponent;
308 + asmComponent;
280 offsetASM = // NO TIME OFFSET
309 offsetASM = // NO TIME OFFSET
281 asmComponent * NB_BINS_PER_SM
310 asmComponent * NB_BINS_PER_SM
282 + ASMIndexStart
311 + ASMIndexStart
283 + frequencyBin * nbBinsToAverage;
312 + frequencyBin * nbBinsToAverage;
284 compressed_spec_mat[ offsetCompressed ] = 0;
313 compressed_spec_mat[ offsetCompressed ] = 0;
285 for ( k = 0; k < nbBinsToAverage; k++ )
314 for ( k = 0; k < nbBinsToAverage; k++ )
286 {
315 {
287 compressed_spec_mat[offsetCompressed ] =
316 compressed_spec_mat[offsetCompressed ] =
288 ( compressed_spec_mat[ offsetCompressed ]
317 ( compressed_spec_mat[ offsetCompressed ]
289 + averaged_spec_mat[ offsetASM + k ] );
318 + averaged_spec_mat[ offsetASM + k ] );
290 }
319 }
291 compressed_spec_mat[ offsetCompressed ] =
320 compressed_spec_mat[ offsetCompressed ] =
292 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
321 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
293 }
322 }
294 }
323 }
295 }
324 }
296
325
297 void ASM_convert( volatile float *input_matrix, char *output_matrix)
326 void ASM_convert( volatile float *input_matrix, char *output_matrix)
298 {
327 {
299 unsigned int frequencyBin;
328 unsigned int frequencyBin;
300 unsigned int asmComponent;
329 unsigned int asmComponent;
301 char * pt_char_input;
330 char * pt_char_input;
302 char * pt_char_output;
331 char * pt_char_output;
303 unsigned int offsetInput;
332 unsigned int offsetInput;
304 unsigned int offsetOutput;
333 unsigned int offsetOutput;
305
334
306 pt_char_input = (char*) &input_matrix;
335 pt_char_input = (char*) &input_matrix;
307 pt_char_output = (char*) &output_matrix;
336 pt_char_output = (char*) &output_matrix;
308
337
309 // convert all other data
338 // convert all other data
310 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
339 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
311 {
340 {
312 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
341 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
313 {
342 {
314 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
343 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
315 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
344 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
316 pt_char_input = (char*) &input_matrix [ offsetInput ];
345 pt_char_input = (char*) &input_matrix [ offsetInput ];
317 pt_char_output = (char*) &output_matrix[ offsetOutput ];
346 pt_char_output = (char*) &output_matrix[ offsetOutput ];
318 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
347 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
319 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
348 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
320 }
349 }
321 }
350 }
322 }
351 }
323
352
324 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
353 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
325 float divider,
354 float divider,
326 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
355 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
327
356
328 int getFBinMask(int k, unsigned char channel);
357 int getFBinMask(int k, unsigned char channel);
329
358
330 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
359 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
331
360
332 #endif // FSW_PROCESSING_H_INCLUDED
361 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,95 +1,96
1 /** Global variables of the LFR flight software.
1 /** Global variables of the LFR flight software.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * Among global variables, there are:
6 * Among global variables, there are:
7 * - RTEMS names and id.
7 * - RTEMS names and id.
8 * - APB configuration registers.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
13 * - the global dump parameter buffer.
14 *
14 *
15 */
15 */
16
16
17 #include <rtems.h>
17 #include <rtems.h>
18 #include <grspw.h>
18 #include <grspw.h>
19
19
20 #include "ccsds_types.h"
20 #include "ccsds_types.h"
21 #include "grlib_regs.h"
21 #include "grlib_regs.h"
22 #include "fsw_params.h"
22 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
23 #include "fsw_params_wf_handler.h"
24
24
25 // RTEMS GLOBAL VARIABLES
25 // RTEMS GLOBAL VARIABLES
26 rtems_name misc_name[5];
26 rtems_name misc_name[5];
27 rtems_name Task_name[20]; /* array of task names */
27 rtems_name Task_name[20]; /* array of task names */
28 rtems_id Task_id[20]; /* array of task ids */
28 rtems_id Task_id[20]; /* array of task ids */
29 rtems_name timecode_timer_name;
29 rtems_name timecode_timer_name;
30 rtems_id timecode_timer_id;
30 rtems_id timecode_timer_id;
31 int fdSPW = 0;
31 int fdSPW = 0;
32 int fdUART = 0;
32 int fdUART = 0;
33 unsigned char lfrCurrentMode;
33 unsigned char lfrCurrentMode;
34 unsigned char pa_bia_status_info;
34 unsigned char pa_bia_status_info;
35 unsigned char thisIsAnASMRestart = 0;
35 unsigned char thisIsAnASMRestart = 0;
36 unsigned char oneTcLfrUpdateTimeReceived = 0;
36 unsigned char oneTcLfrUpdateTimeReceived = 0;
37
37
38 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
38 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
39 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
39 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
40 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
40 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
41 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
41 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
42 // F0 F1 F2 F3
42 // F0 F1 F2 F3
43 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
45 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
45 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
46 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
46 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
47
47
48 //***********************************
48 //***********************************
49 // SPECTRAL MATRICES GLOBAL VARIABLES
49 // SPECTRAL MATRICES GLOBAL VARIABLES
50
50
51 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
51 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
52 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
52 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
53 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
53 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
54 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
54 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
55
55
56 // APB CONFIGURATION REGISTERS
56 // APB CONFIGURATION REGISTERS
57 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
57 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
58 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
58 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
59 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
59 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
60 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
60 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
61
61
62 // MODE PARAMETERS
62 // MODE PARAMETERS
63 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
63 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
64 struct param_local_str param_local;
64 struct param_local_str param_local;
65 unsigned int lastValidEnterModeTime;
65 unsigned int lastValidEnterModeTime;
66
66
67 // HK PACKETS
67 // HK PACKETS
68 Packet_TM_LFR_HK_t housekeeping_packet;
68 Packet_TM_LFR_HK_t housekeeping_packet;
69 unsigned char cp_rpw_sc_rw_f_flags;
69 unsigned char cp_rpw_sc_rw_f_flags;
70 // message queues occupancy
70 // message queues occupancy
71 unsigned char hk_lfr_q_sd_fifo_size_max;
71 unsigned char hk_lfr_q_sd_fifo_size_max;
72 unsigned char hk_lfr_q_rv_fifo_size_max;
72 unsigned char hk_lfr_q_rv_fifo_size_max;
73 unsigned char hk_lfr_q_p0_fifo_size_max;
73 unsigned char hk_lfr_q_p0_fifo_size_max;
74 unsigned char hk_lfr_q_p1_fifo_size_max;
74 unsigned char hk_lfr_q_p1_fifo_size_max;
75 unsigned char hk_lfr_q_p2_fifo_size_max;
75 unsigned char hk_lfr_q_p2_fifo_size_max;
76 // sequence counters are incremented by APID (PID + CAT) and destination ID
76 // sequence counters are incremented by APID (PID + CAT) and destination ID
77 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
77 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
78 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
78 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
79 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
79 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
80 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
80 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
81 unsigned short sequenceCounterHK;
81 unsigned short sequenceCounterHK;
82 spw_stats grspw_stats;
82 spw_stats grspw_stats;
83
83
84 // TC_LFR_UPDATE_INFO
84 // TC_LFR_UPDATE_INFO
85 float cp_rpw_sc_rw1_f1;
85 float cp_rpw_sc_rw1_f1;
86 float cp_rpw_sc_rw1_f2;
86 float cp_rpw_sc_rw1_f2;
87 float cp_rpw_sc_rw2_f1;
87 float cp_rpw_sc_rw2_f1;
88 float cp_rpw_sc_rw2_f2;
88 float cp_rpw_sc_rw2_f2;
89 float cp_rpw_sc_rw3_f1;
89 float cp_rpw_sc_rw3_f1;
90 float cp_rpw_sc_rw3_f2;
90 float cp_rpw_sc_rw3_f2;
91 float cp_rpw_sc_rw4_f1;
91 float cp_rpw_sc_rw4_f1;
92 float cp_rpw_sc_rw4_f2;
92 float cp_rpw_sc_rw4_f2;
93 float sy_lfr_sc_rw_delta_f;
93 float sy_lfr_sc_rw_delta_f;
94
94
95 fbins_masks_t fbins_masks;
95 fbins_masks_t fbins_masks;
96 unsigned int acquisitionDurations[3] = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
@@ -1,408 +1,413
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf0_prc0.h"
10 #include "avf0_prc0.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14
14
15 //***
15 //***
16 // F0
16 // F0
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19
19
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
22
22
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
26
26
27 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
27 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
28 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
28 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
29 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
29 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
30
30
31 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
31 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
32 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
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 // RTEMS TASKS
35 // RTEMS TASKS
36
36
37 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
37 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
38 {
38 {
39 int i;
39 int i;
40
40
41 rtems_event_set event_out;
41 rtems_event_set event_out;
42 rtems_status_code status;
42 rtems_status_code status;
43 rtems_id queue_id_prc0;
43 rtems_id queue_id_prc0;
44 asm_msg msgForPRC;
44 asm_msg msgForPRC;
45 ring_node *nodeForAveraging;
45 ring_node *nodeForAveraging;
46 ring_node *ring_node_tab[8];
46 ring_node *ring_node_tab[8];
47 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
47 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
48 ring_node_asm *current_ring_node_asm_norm_f0;
48 ring_node_asm *current_ring_node_asm_norm_f0;
49
49
50 unsigned int nb_norm_bp1;
50 unsigned int nb_norm_bp1;
51 unsigned int nb_norm_bp2;
51 unsigned int nb_norm_bp2;
52 unsigned int nb_norm_asm;
52 unsigned int nb_norm_asm;
53 unsigned int nb_sbm_bp1;
53 unsigned int nb_sbm_bp1;
54 unsigned int nb_sbm_bp2;
54 unsigned int nb_sbm_bp2;
55
55
56 nb_norm_bp1 = 0;
56 nb_norm_bp1 = 0;
57 nb_norm_bp2 = 0;
57 nb_norm_bp2 = 0;
58 nb_norm_asm = 0;
58 nb_norm_asm = 0;
59 nb_sbm_bp1 = 0;
59 nb_sbm_bp1 = 0;
60 nb_sbm_bp2 = 0;
60 nb_sbm_bp2 = 0;
61
61
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67
67
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69
69
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 if (status != RTEMS_SUCCESSFUL)
71 if (status != RTEMS_SUCCESSFUL)
72 {
72 {
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 }
74 }
75
75
76 while(1){
76 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
78
79 //****************************************
79 //****************************************
80 // initialize the mesage for the MATR task
80 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.event = 0x00; // this composite event will be sent to the PRC0 task
83 msgForPRC.event = 0x00; // this composite event will be sent to the PRC0 task
84 //
84 //
85 //****************************************
85 //****************************************
86
86
87 nodeForAveraging = getRingNodeForAveraging( 0 );
87 nodeForAveraging = getRingNodeForAveraging( 0 );
88
88
89 ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging;
89 ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging;
90 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
90 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
91 {
91 {
92 nodeForAveraging = nodeForAveraging->previous;
92 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging;
93 ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging;
94 }
94 }
95
95
96 // compute the average and store it in the averaged_sm_f1 buffer
96 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f0->matrix,
97 SM_average( current_ring_node_asm_norm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
99 ring_node_tab,
99 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
100 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC );
101 &msgForPRC, 0 ); // 0 => frequency channel 0
102
102
103 // update nb_average
103 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
109
109
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 {
111 {
112 nb_sbm_bp1 = 0;
112 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
113 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
115 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
116 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 }
118 }
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 {
120 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 }
122 }
123 }
123 }
124
124
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 {
126 {
127 nb_sbm_bp2 = 0;
127 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
128 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
129 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 }
131 }
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
133 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 }
135 }
136 }
136 }
137
137
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 {
139 {
140 nb_norm_bp1 = 0;
140 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
141 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
145 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 }
147 }
148 }
148 }
149
149
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 {
151 {
152 nb_norm_bp2 = 0;
152 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
155 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 }
157 }
158 }
158 }
159
159
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 {
161 {
162 nb_norm_asm = 0;
162 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
165 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 }
167 }
168 }
168 }
169
169
170 //*************************
170 //*************************
171 // send the message to PRC
171 // send the message to PRC
172 if (msgForPRC.event != 0x00)
172 if (msgForPRC.event != 0x00)
173 {
173 {
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 }
175 }
176
176
177 if (status != RTEMS_SUCCESSFUL) {
177 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 }
179 }
180 }
180 }
181 }
181 }
182
182
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 {
184 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
186 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
187 asm_msg *incomingMsg;
188 //
188 //
189 unsigned char sid;
189 unsigned char sid;
190 rtems_status_code status;
190 rtems_status_code status;
191 rtems_id queue_id;
191 rtems_id queue_id;
192 rtems_id queue_id_q_p0;
192 rtems_id queue_id_q_p0;
193 bp_packet_with_spare packet_norm_bp1;
193 bp_packet_with_spare packet_norm_bp1;
194 bp_packet packet_norm_bp2;
194 bp_packet packet_norm_bp2;
195 bp_packet packet_sbm_bp1;
195 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp2;
196 bp_packet packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f0;
197 ring_node *current_ring_node_to_send_asm_f0;
198 float nbSMInASMNORM;
199 float nbSMInASMSBM;
198
200
199 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
201 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
202 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
201 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
203 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
202
204
203 //*************
205 //*************
204 // NORM headers
206 // NORM headers
205 BP_init_header_with_spare( &packet_norm_bp1,
207 BP_init_header_with_spare( &packet_norm_bp1,
206 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
208 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
207 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
208 BP_init_header( &packet_norm_bp2,
210 BP_init_header( &packet_norm_bp2,
209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
211 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
212 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
211
213
212 //****************************
214 //****************************
213 // BURST SBM1 and SBM2 headers
215 // BURST SBM1 and SBM2 headers
214 if ( lfrRequestedMode == LFR_MODE_BURST )
216 if ( lfrRequestedMode == LFR_MODE_BURST )
215 {
217 {
216 BP_init_header( &packet_sbm_bp1,
218 BP_init_header( &packet_sbm_bp1,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
218 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
220 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
219 BP_init_header( &packet_sbm_bp2,
221 BP_init_header( &packet_sbm_bp2,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
222 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
223 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
222 }
224 }
223 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
225 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
224 {
226 {
225 BP_init_header( &packet_sbm_bp1,
227 BP_init_header( &packet_sbm_bp1,
226 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
228 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
227 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
228 BP_init_header( &packet_sbm_bp2,
230 BP_init_header( &packet_sbm_bp2,
229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
231 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
231 }
233 }
232 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
233 {
235 {
234 BP_init_header( &packet_sbm_bp1,
236 BP_init_header( &packet_sbm_bp1,
235 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
236 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
237 BP_init_header( &packet_sbm_bp2,
239 BP_init_header( &packet_sbm_bp2,
238 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
239 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
240 }
242 }
241 else
243 else
242 {
244 {
243 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
245 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
244 }
246 }
245
247
246 status = get_message_queue_id_send( &queue_id );
248 status = get_message_queue_id_send( &queue_id );
247 if (status != RTEMS_SUCCESSFUL)
249 if (status != RTEMS_SUCCESSFUL)
248 {
250 {
249 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
251 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
250 }
252 }
251 status = get_message_queue_id_prc0( &queue_id_q_p0);
253 status = get_message_queue_id_prc0( &queue_id_q_p0);
252 if (status != RTEMS_SUCCESSFUL)
254 if (status != RTEMS_SUCCESSFUL)
253 {
255 {
254 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
256 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
255 }
257 }
256
258
257 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
259 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
258
260
259 while(1){
261 while(1){
260 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
262 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
262
264
263 incomingMsg = (asm_msg*) incomingData;
265 incomingMsg = (asm_msg*) incomingData;
264
266
265 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
267 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
266 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
267
269
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
268 //****************
273 //****************
269 //****************
274 //****************
270 // BURST SBM1 SBM2
275 // BURST SBM1 SBM2
271 //****************
276 //****************
272 //****************
277 //****************
273 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
274 {
279 {
275 sid = getSID( incomingMsg->event );
280 sid = getSID( incomingMsg->event );
276 // 1) compress the matrix for Basic Parameters calculation
281 // 1) compress the matrix for Basic Parameters calculation
277 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
282 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
278 nb_sm_before_f0.burst_sbm_bp1,
283 nbSMInASMSBM,
279 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
284 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
280 ASM_F0_INDICE_START, CHANNELF0);
285 ASM_F0_INDICE_START, CHANNELF0);
281 // 2) compute the BP1 set
286 // 2) compute the BP1 set
282 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
287 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
283 // 3) send the BP1 set
288 // 3) send the BP1 set
284 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
285 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
286 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
287 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
288 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
289 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
290 sid);
295 sid);
291 // 4) compute the BP2 set if needed
296 // 4) compute the BP2 set if needed
292 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
293 {
298 {
294 // 1) compute the BP2 set
299 // 1) compute the BP2 set
295 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
300 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
296 // 2) send the BP2 set
301 // 2) send the BP2 set
297 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
300 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
303 sid);
308 sid);
304 }
309 }
305 }
310 }
306
311
307 //*****
312 //*****
308 //*****
313 //*****
309 // NORM
314 // NORM
310 //*****
315 //*****
311 //*****
316 //*****
312 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
313 {
318 {
314 // 1) compress the matrix for Basic Parameters calculation
319 // 1) compress the matrix for Basic Parameters calculation
315 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
320 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
316 nb_sm_before_f0.norm_bp1,
321 nbSMInASMNORM,
317 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
322 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
318 ASM_F0_INDICE_START, CHANNELF0 );
323 ASM_F0_INDICE_START, CHANNELF0 );
319 // 2) compute the BP1 set
324 // 2) compute the BP1 set
320 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
325 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
321 // 3) send the BP1 set
326 // 3) send the BP1 set
322 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
323 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
324 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
325 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
326 BP_send( (char *) &packet_norm_bp1, queue_id,
331 BP_send( (char *) &packet_norm_bp1, queue_id,
327 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
328 SID_NORM_BP1_F0 );
333 SID_NORM_BP1_F0 );
329 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
330 {
335 {
331 // 1) compute the BP2 set using the same ASM as the one used for BP1
336 // 1) compute the BP2 set using the same ASM as the one used for BP1
332 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
337 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
333 // 2) send the BP2 set
338 // 2) send the BP2 set
334 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
335 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
337 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
338 BP_send( (char *) &packet_norm_bp2, queue_id,
343 BP_send( (char *) &packet_norm_bp2, queue_id,
339 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
340 SID_NORM_BP2_F0);
345 SID_NORM_BP2_F0);
341 }
346 }
342 }
347 }
343
348
344 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
345 {
350 {
346 // 1) reorganize the ASM and divide
351 // 1) reorganize the ASM and divide
347 ASM_reorganize_and_divide( asm_f0_patched_norm,
352 ASM_reorganize_and_divide( asm_f0_patched_norm,
348 (float*) current_ring_node_to_send_asm_f0->buffer_address,
353 (float*) current_ring_node_to_send_asm_f0->buffer_address,
349 nb_sm_before_f0.norm_bp1 );
354 nbSMInASMNORM );
350 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
355 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
351 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
356 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
352 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
357 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
353
358
354 // 3) send the spectral matrix packets
359 // 3) send the spectral matrix packets
355 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
360 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
356 // change asm ring node
361 // change asm ring node
357 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
362 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
358 }
363 }
359
364
360 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
365 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
361
366
362 }
367 }
363 }
368 }
364
369
365 //**********
370 //**********
366 // FUNCTIONS
371 // FUNCTIONS
367
372
368 void reset_nb_sm_f0( unsigned char lfrMode )
373 void reset_nb_sm_f0( unsigned char lfrMode )
369 {
374 {
370 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
375 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
371 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
376 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
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;
377 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 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
378 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
374 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
379 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
375 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
380 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
376 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
381 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
377 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
382 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
378 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
383 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
379
384
380 if (lfrMode == LFR_MODE_SBM1)
385 if (lfrMode == LFR_MODE_SBM1)
381 {
386 {
382 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
387 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
383 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
388 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
384 }
389 }
385 else if (lfrMode == LFR_MODE_SBM2)
390 else if (lfrMode == LFR_MODE_SBM2)
386 {
391 {
387 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
392 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
388 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
393 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
389 }
394 }
390 else if (lfrMode == LFR_MODE_BURST)
395 else if (lfrMode == LFR_MODE_BURST)
391 {
396 {
392 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
393 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
394 }
399 }
395 else
400 else
396 {
401 {
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
399 }
404 }
400 }
405 }
401
406
402 void init_k_coefficients_prc0( void )
407 void init_k_coefficients_prc0( void )
403 {
408 {
404 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
409 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
405
410
406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
411 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
407 }
412 }
408
413
@@ -1,394 +1,396
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf1_prc1.h"
10 #include "avf1_prc1.h"
11
11
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13
13
14 extern ring_node sm_ring_f1[ ];
14 extern ring_node sm_ring_f1[ ];
15
15
16 //***
16 //***
17 // F1
17 // F1
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
20
20
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
23
23
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
27
27
28 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
28 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
29 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
29 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
30 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
30 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
31
31
32 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
32 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
33 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
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 // RTEMS TASKS
36 // RTEMS TASKS
37
37
38 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
38 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
39 {
39 {
40 int i;
40 int i;
41
41
42 rtems_event_set event_out;
42 rtems_event_set event_out;
43 rtems_status_code status;
43 rtems_status_code status;
44 rtems_id queue_id_prc1;
44 rtems_id queue_id_prc1;
45 asm_msg msgForPRC;
45 asm_msg msgForPRC;
46 ring_node *nodeForAveraging;
46 ring_node *nodeForAveraging;
47 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
47 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
48 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
48 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
49 ring_node_asm *current_ring_node_asm_norm_f1;
49 ring_node_asm *current_ring_node_asm_norm_f1;
50
50
51 unsigned int nb_norm_bp1;
51 unsigned int nb_norm_bp1;
52 unsigned int nb_norm_bp2;
52 unsigned int nb_norm_bp2;
53 unsigned int nb_norm_asm;
53 unsigned int nb_norm_asm;
54 unsigned int nb_sbm_bp1;
54 unsigned int nb_sbm_bp1;
55 unsigned int nb_sbm_bp2;
55 unsigned int nb_sbm_bp2;
56
56
57 nb_norm_bp1 = 0;
57 nb_norm_bp1 = 0;
58 nb_norm_bp2 = 0;
58 nb_norm_bp2 = 0;
59 nb_norm_asm = 0;
59 nb_norm_asm = 0;
60 nb_sbm_bp1 = 0;
60 nb_sbm_bp1 = 0;
61 nb_sbm_bp2 = 0;
61 nb_sbm_bp2 = 0;
62
62
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68
68
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70
70
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 if (status != RTEMS_SUCCESSFUL)
72 if (status != RTEMS_SUCCESSFUL)
73 {
73 {
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 }
75 }
76
76
77 while(1){
77 while(1){
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79
79
80 //****************************************
80 //****************************************
81 // initialize the mesage for the MATR task
81 // initialize the mesage for the MATR task
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 msgForPRC.event = 0x00; // this composite event will be sent to the PRC1 task
84 msgForPRC.event = 0x00; // this composite event will be sent to the PRC1 task
85 //
85 //
86 //****************************************
86 //****************************************
87
87
88 nodeForAveraging = getRingNodeForAveraging( 1 );
88 nodeForAveraging = getRingNodeForAveraging( 1 );
89
89
90 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
90 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
91 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
91 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
92 {
92 {
93 nodeForAveraging = nodeForAveraging->previous;
93 nodeForAveraging = nodeForAveraging->previous;
94 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
94 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
95 }
95 }
96
96
97 // compute the average and store it in the averaged_sm_f1 buffer
97 // compute the average and store it in the averaged_sm_f1 buffer
98 SM_average( current_ring_node_asm_norm_f1->matrix,
98 SM_average( current_ring_node_asm_norm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
100 ring_node_tab,
100 ring_node_tab,
101 nb_norm_bp1, nb_sbm_bp1,
101 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC );
102 &msgForPRC, 1 ); // 1 => frequency channel 1
103
103
104 // update nb_average
104 // update nb_average
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
110
110
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 {
112 {
113 nb_sbm_bp1 = 0;
113 nb_sbm_bp1 = 0;
114 // set another ring for the ASM storage
114 // set another ring for the ASM storage
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
116 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
117 {
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 }
119 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
121 {
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 }
123 }
124 }
124 }
125
125
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 {
127 {
128 nb_sbm_bp2 = 0;
128 nb_sbm_bp2 = 0;
129 if ( lfrCurrentMode == LFR_MODE_BURST )
129 if ( lfrCurrentMode == LFR_MODE_BURST )
130 {
130 {
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 }
132 }
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 {
134 {
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 }
136 }
137 }
137 }
138
138
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 {
140 {
141 nb_norm_bp1 = 0;
141 nb_norm_bp1 = 0;
142 // set another ring for the ASM storage
142 // set another ring for the ASM storage
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
146 {
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 }
148 }
149 }
149 }
150
150
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 {
152 {
153 nb_norm_bp2 = 0;
153 nb_norm_bp2 = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
156 {
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 }
158 }
159 }
159 }
160
160
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 {
162 {
163 nb_norm_asm = 0;
163 nb_norm_asm = 0;
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 {
166 {
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 }
168 }
169 }
169 }
170
170
171 //*************************
171 //*************************
172 // send the message to PRC
172 // send the message to PRC
173 if (msgForPRC.event != 0x00)
173 if (msgForPRC.event != 0x00)
174 {
174 {
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 }
176 }
177
177
178 if (status != RTEMS_SUCCESSFUL) {
178 if (status != RTEMS_SUCCESSFUL) {
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 }
180 }
181 }
181 }
182 }
182 }
183
183
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 {
185 {
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 size_t size; // size of the incoming TC packet
187 size_t size; // size of the incoming TC packet
188 asm_msg *incomingMsg;
188 asm_msg *incomingMsg;
189 //
189 //
190 unsigned char sid;
190 unsigned char sid;
191 rtems_status_code status;
191 rtems_status_code status;
192 rtems_id queue_id_send;
192 rtems_id queue_id_send;
193 rtems_id queue_id_q_p1;
193 rtems_id queue_id_q_p1;
194 bp_packet_with_spare packet_norm_bp1;
194 bp_packet_with_spare packet_norm_bp1;
195 bp_packet packet_norm_bp2;
195 bp_packet packet_norm_bp2;
196 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp1;
197 bp_packet packet_sbm_bp2;
197 bp_packet packet_sbm_bp2;
198 ring_node *current_ring_node_to_send_asm_f1;
198 ring_node *current_ring_node_to_send_asm_f1;
199
199 float nbSMInASMNORM;
200 unsigned long long int localTime;
200 float nbSMInASMSBM;
201
201
202 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
202 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
203 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
203 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
204 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
204 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
205
205
206 //*************
206 //*************
207 // NORM headers
207 // NORM headers
208 BP_init_header_with_spare( &packet_norm_bp1,
208 BP_init_header_with_spare( &packet_norm_bp1,
209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
211 BP_init_header( &packet_norm_bp2,
211 BP_init_header( &packet_norm_bp2,
212 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
212 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
213 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
213 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
214
214
215 //***********************
215 //***********************
216 // BURST and SBM2 headers
216 // BURST and SBM2 headers
217 if ( lfrRequestedMode == LFR_MODE_BURST )
217 if ( lfrRequestedMode == LFR_MODE_BURST )
218 {
218 {
219 BP_init_header( &packet_sbm_bp1,
219 BP_init_header( &packet_sbm_bp1,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
222 BP_init_header( &packet_sbm_bp2,
222 BP_init_header( &packet_sbm_bp2,
223 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
223 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
224 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
224 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
225 }
225 }
226 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
226 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
227 {
227 {
228 BP_init_header( &packet_sbm_bp1,
228 BP_init_header( &packet_sbm_bp1,
229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 BP_init_header( &packet_sbm_bp2,
231 BP_init_header( &packet_sbm_bp2,
232 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
232 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
233 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
234 }
234 }
235 else
235 else
236 {
236 {
237 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
237 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
238 }
238 }
239
239
240 status = get_message_queue_id_send( &queue_id_send );
240 status = get_message_queue_id_send( &queue_id_send );
241 if (status != RTEMS_SUCCESSFUL)
241 if (status != RTEMS_SUCCESSFUL)
242 {
242 {
243 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
243 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
244 }
244 }
245 status = get_message_queue_id_prc1( &queue_id_q_p1);
245 status = get_message_queue_id_prc1( &queue_id_q_p1);
246 if (status != RTEMS_SUCCESSFUL)
246 if (status != RTEMS_SUCCESSFUL)
247 {
247 {
248 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
248 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
249 }
249 }
250
250
251 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
251 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
252
252
253 while(1){
253 while(1){
254 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
254 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
255 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
255 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
256
256
257 incomingMsg = (asm_msg*) incomingData;
257 incomingMsg = (asm_msg*) incomingData;
258
258
259 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
259 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
260 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
260 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
261
261
262 localTime = getTimeAsUnsignedLongLongInt( );
262 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
263 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
264
263 //***********
265 //***********
264 //***********
266 //***********
265 // BURST SBM2
267 // BURST SBM2
266 //***********
268 //***********
267 //***********
269 //***********
268 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
270 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
269 {
271 {
270 sid = getSID( incomingMsg->event );
272 sid = getSID( incomingMsg->event );
271 // 1) compress the matrix for Basic Parameters calculation
273 // 1) compress the matrix for Basic Parameters calculation
272 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
274 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
273 nb_sm_before_f1.burst_sbm_bp1,
275 nbSMInASMSBM,
274 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
276 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
275 ASM_F1_INDICE_START, CHANNELF1);
277 ASM_F1_INDICE_START, CHANNELF1);
276 // 2) compute the BP1 set
278 // 2) compute the BP1 set
277 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
279 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
278 // 3) send the BP1 set
280 // 3) send the BP1 set
279 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
281 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
280 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
282 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
281 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
283 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
282 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
284 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
283 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
285 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
284 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
286 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
285 sid );
287 sid );
286 // 4) compute the BP2 set if needed
288 // 4) compute the BP2 set if needed
287 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
289 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
288 {
290 {
289 // 1) compute the BP2 set
291 // 1) compute the BP2 set
290 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
292 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
291 // 2) send the BP2 set
293 // 2) send the BP2 set
292 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
294 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
293 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
295 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
294 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
296 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
295 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
297 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
296 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
298 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
297 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
299 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
298 sid );
300 sid );
299 }
301 }
300 }
302 }
301
303
302 //*****
304 //*****
303 //*****
305 //*****
304 // NORM
306 // NORM
305 //*****
307 //*****
306 //*****
308 //*****
307 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
309 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
308 {
310 {
309 // 1) compress the matrix for Basic Parameters calculation
311 // 1) compress the matrix for Basic Parameters calculation
310 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
312 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
311 nb_sm_before_f1.norm_bp1,
313 nbSMInASMNORM,
312 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
314 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
313 ASM_F1_INDICE_START, CHANNELF1 );
315 ASM_F1_INDICE_START, CHANNELF1 );
314 // 2) compute the BP1 set
316 // 2) compute the BP1 set
315 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
317 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
316 // 3) send the BP1 set
318 // 3) send the BP1 set
317 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
318 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
320 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
321 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
320 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
322 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
321 BP_send( (char *) &packet_norm_bp1, queue_id_send,
323 BP_send( (char *) &packet_norm_bp1, queue_id_send,
322 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
324 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
323 SID_NORM_BP1_F1 );
325 SID_NORM_BP1_F1 );
324 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
326 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
325 {
327 {
326 // 1) compute the BP2 set
328 // 1) compute the BP2 set
327 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
329 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
328 // 2) send the BP2 set
330 // 2) send the BP2 set
329 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
331 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
330 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
332 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
331 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
333 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
332 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
334 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
333 BP_send( (char *) &packet_norm_bp2, queue_id_send,
335 BP_send( (char *) &packet_norm_bp2, queue_id_send,
334 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
336 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
335 SID_NORM_BP2_F1 );
337 SID_NORM_BP2_F1 );
336 }
338 }
337 }
339 }
338
340
339 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
341 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
340 {
342 {
341 // 1) reorganize the ASM and divide
343 // 1) reorganize the ASM and divide
342 ASM_reorganize_and_divide( asm_f1_patched_norm,
344 ASM_reorganize_and_divide( asm_f1_patched_norm,
343 (float*) current_ring_node_to_send_asm_f1->buffer_address,
345 (float*) current_ring_node_to_send_asm_f1->buffer_address,
344 nb_sm_before_f1.norm_bp1 );
346 nbSMInASMNORM );
345 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
347 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
346 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
348 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
347 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
349 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
348 // 3) send the spectral matrix packets
350 // 3) send the spectral matrix packets
349 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
351 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
350 // change asm ring node
352 // change asm ring node
351 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
353 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
352 }
354 }
353
355
354 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
356 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
355
357
356 }
358 }
357 }
359 }
358
360
359 //**********
361 //**********
360 // FUNCTIONS
362 // FUNCTIONS
361
363
362 void reset_nb_sm_f1( unsigned char lfrMode )
364 void reset_nb_sm_f1( unsigned char lfrMode )
363 {
365 {
364 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
366 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
365 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
367 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
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;
368 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 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
369 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
368 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
370 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
369 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
371 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
370 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
372 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
371
373
372 if (lfrMode == LFR_MODE_SBM2)
374 if (lfrMode == LFR_MODE_SBM2)
373 {
375 {
374 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
376 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
375 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
377 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
376 }
378 }
377 else if (lfrMode == LFR_MODE_BURST)
379 else if (lfrMode == LFR_MODE_BURST)
378 {
380 {
379 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
381 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
380 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
382 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
381 }
383 }
382 else
384 else
383 {
385 {
384 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
386 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
385 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
387 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
386 }
388 }
387 }
389 }
388
390
389 void init_k_coefficients_prc1( void )
391 void init_k_coefficients_prc1( void )
390 {
392 {
391 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
393 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
392
394
393 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
395 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
394 }
396 }
@@ -1,281 +1,325
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf2_prc2.h"
10 #include "avf2_prc2.h"
11
11
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13
13
14 extern ring_node sm_ring_f2[ ];
14 extern ring_node sm_ring_f2[ ];
15
15
16 //***
16 //***
17 // F2
17 // F2
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
19
19
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
22
22
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
25
25
26 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
26 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
27 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
27 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
28
28
29 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
29 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
30
30
31 //************
31 //************
32 // RTEMS TASKS
32 // RTEMS TASKS
33
33
34 //***
34 //***
35 // F2
35 // F2
36 rtems_task avf2_task( rtems_task_argument argument )
36 rtems_task avf2_task( rtems_task_argument argument )
37 {
37 {
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 rtems_id queue_id_prc2;
40 rtems_id queue_id_prc2;
41 asm_msg msgForPRC;
41 asm_msg msgForPRC;
42 ring_node *nodeForAveraging;
42 ring_node *nodeForAveraging;
43 ring_node_asm *current_ring_node_asm_norm_f2;
43 ring_node_asm *current_ring_node_asm_norm_f2;
44
44
45 unsigned int nb_norm_bp1;
45 unsigned int nb_norm_bp1;
46 unsigned int nb_norm_bp2;
46 unsigned int nb_norm_bp2;
47 unsigned int nb_norm_asm;
47 unsigned int nb_norm_asm;
48
48
49 nb_norm_bp1 = 0;
49 nb_norm_bp1 = 0;
50 nb_norm_bp2 = 0;
50 nb_norm_bp2 = 0;
51 nb_norm_asm = 0;
51 nb_norm_asm = 0;
52
52
53 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
54 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
55 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
56
56
57 BOOT_PRINTF("in AVF2 ***\n")
57 BOOT_PRINTF("in AVF2 ***\n")
58
58
59 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 status = get_message_queue_id_prc2( &queue_id_prc2 );
60 if (status != RTEMS_SUCCESSFUL)
60 if (status != RTEMS_SUCCESSFUL)
61 {
61 {
62 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
63 }
63 }
64
64
65 while(1){
65 while(1){
66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
67
67
68 //****************************************
68 //****************************************
69 // initialize the mesage for the MATR task
69 // initialize the mesage for the MATR task
70 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 msgForPRC.norm = current_ring_node_asm_norm_f2;
71 msgForPRC.burst_sbm = NULL;
71 msgForPRC.burst_sbm = NULL;
72 msgForPRC.event = 0x00; // this composite event will be sent to the PRC2 task
72 msgForPRC.event = 0x00; // this composite event will be sent to the PRC2 task
73 //
73 //
74 //****************************************
74 //****************************************
75
75
76 nodeForAveraging = getRingNodeForAveraging( 2 );
76 nodeForAveraging = getRingNodeForAveraging( 2 );
77
77
78 // compute the average and store it in the averaged_sm_f2 buffer
78 // compute the average and store it in the averaged_sm_f2 buffer
79 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
80 nodeForAveraging,
80 nodeForAveraging,
81 nb_norm_bp1,
81 nb_norm_bp1,
82 &msgForPRC );
82 &msgForPRC );
83
83
84 // update nb_average
84 // update nb_average
85 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
86 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
87 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
88
88
89 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
90 {
90 {
91 nb_norm_bp1 = 0;
91 nb_norm_bp1 = 0;
92 // set another ring for the ASM storage
92 // set another ring for the ASM storage
93 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
94 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
95 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 || (lfrCurrentMode == LFR_MODE_SBM2) )
96 {
96 {
97 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
98 }
98 }
99 }
99 }
100
100
101 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
102 {
102 {
103 nb_norm_bp2 = 0;
103 nb_norm_bp2 = 0;
104 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 {
106 {
107 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
108 }
108 }
109 }
109 }
110
110
111 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
112 {
112 {
113 nb_norm_asm = 0;
113 nb_norm_asm = 0;
114 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 {
116 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
118 }
118 }
119 }
119 }
120
120
121 //*************************
121 //*************************
122 // send the message to PRC2
122 // send the message to PRC2
123 if (msgForPRC.event != 0x00)
123 if (msgForPRC.event != 0x00)
124 {
124 {
125 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
126 }
126 }
127
127
128 if (status != RTEMS_SUCCESSFUL) {
128 if (status != RTEMS_SUCCESSFUL) {
129 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
130 }
130 }
131 }
131 }
132 }
132 }
133
133
134 rtems_task prc2_task( rtems_task_argument argument )
134 rtems_task prc2_task( rtems_task_argument argument )
135 {
135 {
136 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
137 size_t size; // size of the incoming TC packet
137 size_t size; // size of the incoming TC packet
138 asm_msg *incomingMsg;
138 asm_msg *incomingMsg;
139 //
139 //
140 rtems_status_code status;
140 rtems_status_code status;
141 rtems_id queue_id_send;
141 rtems_id queue_id_send;
142 rtems_id queue_id_q_p2;
142 rtems_id queue_id_q_p2;
143 bp_packet packet_norm_bp1;
143 bp_packet packet_norm_bp1;
144 bp_packet packet_norm_bp2;
144 bp_packet packet_norm_bp2;
145 ring_node *current_ring_node_to_send_asm_f2;
145 ring_node *current_ring_node_to_send_asm_f2;
146 float nbSMInASMNORM;
146
147
147 unsigned long long int localTime;
148 unsigned long long int localTime;
148
149
149 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
150 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
150 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
151 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
151 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
152 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
152
153
153 //*************
154 //*************
154 // NORM headers
155 // NORM headers
155 BP_init_header( &packet_norm_bp1,
156 BP_init_header( &packet_norm_bp1,
156 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
157 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
157 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
158 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
158 BP_init_header( &packet_norm_bp2,
159 BP_init_header( &packet_norm_bp2,
159 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
160 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
160 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
161 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
161
162
162 status = get_message_queue_id_send( &queue_id_send );
163 status = get_message_queue_id_send( &queue_id_send );
163 if (status != RTEMS_SUCCESSFUL)
164 if (status != RTEMS_SUCCESSFUL)
164 {
165 {
165 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
166 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
166 }
167 }
167 status = get_message_queue_id_prc2( &queue_id_q_p2);
168 status = get_message_queue_id_prc2( &queue_id_q_p2);
168 if (status != RTEMS_SUCCESSFUL)
169 if (status != RTEMS_SUCCESSFUL)
169 {
170 {
170 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
171 }
172 }
172
173
173 BOOT_PRINTF("in PRC2 ***\n")
174 BOOT_PRINTF("in PRC2 ***\n")
174
175
175 while(1){
176 while(1){
176 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
177 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
177 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
178 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
178
179
179 incomingMsg = (asm_msg*) incomingData;
180 incomingMsg = (asm_msg*) incomingData;
180
181
181 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
182 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
182
183
183 localTime = getTimeAsUnsignedLongLongInt( );
184 localTime = getTimeAsUnsignedLongLongInt( );
184
185
186 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
187
185 //*****
188 //*****
186 //*****
189 //*****
187 // NORM
190 // NORM
188 //*****
191 //*****
189 //*****
192 //*****
190 // 1) compress the matrix for Basic Parameters calculation
193 // 1) compress the matrix for Basic Parameters calculation
191 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
194 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
192 nb_sm_before_f2.norm_bp1,
195 nbSMInASMNORM,
193 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
196 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
194 ASM_F2_INDICE_START, CHANNELF2 );
197 ASM_F2_INDICE_START, CHANNELF2 );
195 // BP1_F2
198 // BP1_F2
196 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
199 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
197 {
200 {
198 // 1) compute the BP1 set
201 // 1) compute the BP1 set
199 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
202 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
200 // 2) send the BP1 set
203 // 2) send the BP1 set
201 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
204 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
202 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
205 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
203 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
206 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
204 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
207 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
205 BP_send( (char *) &packet_norm_bp1, queue_id_send,
208 BP_send( (char *) &packet_norm_bp1, queue_id_send,
206 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
207 SID_NORM_BP1_F2 );
210 SID_NORM_BP1_F2 );
208 }
211 }
209 // BP2_F2
212 // BP2_F2
210 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
213 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
211 {
214 {
212 // 1) compute the BP2 set
215 // 1) compute the BP2 set
213 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
216 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
214 // 2) send the BP2 set
217 // 2) send the BP2 set
215 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
218 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
216 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
219 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
217 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
220 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
218 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
221 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
219 BP_send( (char *) &packet_norm_bp2, queue_id_send,
222 BP_send( (char *) &packet_norm_bp2, queue_id_send,
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
223 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
221 SID_NORM_BP2_F2 );
224 SID_NORM_BP2_F2 );
222 }
225 }
223
226
224 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
227 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
225 {
228 {
226 // 1) reorganize the ASM and divide
229 // 1) reorganize the ASM and divide
227 ASM_reorganize_and_divide( asm_f2_patched_norm,
230 ASM_reorganize_and_divide( asm_f2_patched_norm,
228 (float*) current_ring_node_to_send_asm_f2->buffer_address,
231 (float*) current_ring_node_to_send_asm_f2->buffer_address,
229 nb_sm_before_f2.norm_bp1 );
232 nb_sm_before_f2.norm_bp1 );
230 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
233 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
231 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
234 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
232 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
235 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
233 // 3) send the spectral matrix packets
236 // 3) send the spectral matrix packets
234 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
237 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
235 // change asm ring node
238 // change asm ring node
236 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
239 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
237 }
240 }
238
241
239 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
242 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
240
243
241 }
244 }
242 }
245 }
243
246
244 //**********
247 //**********
245 // FUNCTIONS
248 // FUNCTIONS
246
249
247 void reset_nb_sm_f2( void )
250 void reset_nb_sm_f2( void )
248 {
251 {
249 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
252 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
250 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
253 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
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];
254 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 }
255 }
253
256
254 void SM_average_f2( float *averaged_spec_mat_f2,
257 void SM_average_f2( float *averaged_spec_mat_f2,
255 ring_node *ring_node,
258 ring_node *ring_node,
256 unsigned int nbAverageNormF2,
259 unsigned int nbAverageNormF2,
257 asm_msg *msgForMATR )
260 asm_msg *msgForMATR )
258 {
261 {
259 float sum;
262 float sum;
260 unsigned int i;
263 unsigned int i;
264 unsigned char keepMatrix;
265
266 // test acquisitionTime validity
267 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, 2 );
261
268
262 for(i=0; i<TOTAL_SIZE_SM; i++)
269 for(i=0; i<TOTAL_SIZE_SM; i++)
263 {
270 {
264 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
271 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
265 if ( (nbAverageNormF2 == 0) )
272 if ( (nbAverageNormF2 == 0) ) // average initialization
266 {
273 {
267 averaged_spec_mat_f2[ i ] = sum;
274 if (keepMatrix == 1) // keep the matrix and add it to the average
275 {
276 averaged_spec_mat_f2[ i ] = sum;
277 }
278 else // drop the matrix and initialize the average
279 {
280 averaged_spec_mat_f2[ i ] = 0.;
281 }
268 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
282 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
269 msgForMATR->fineTimeNORM = ring_node->fineTime;
283 msgForMATR->fineTimeNORM = ring_node->fineTime;
270 }
284 }
271 else
285 else
272 {
286 {
273 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
287 if (keepMatrix == 1) // keep the matrix and add it to the average
288 {
289 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
290 }
291 else
292 {
293 // nothing to do, the matrix is not valid
294 }
295 }
296 }
297
298 if (keepMatrix == 1)
299 {
300 if ( (nbAverageNormF2 == 0) )
301 {
302 msgForMATR->numberOfSMInASMNORM = 1;
303 }
304 else
305 {
306 msgForMATR->numberOfSMInASMNORM++;
307 }
308 }
309 else
310 {
311 if ( (nbAverageNormF2 == 0) )
312 {
313 msgForMATR->numberOfSMInASMNORM = 0;
314 }
315 else
316 {
317 // nothing to do
274 }
318 }
275 }
319 }
276 }
320 }
277
321
278 void init_k_coefficients_prc2( void )
322 void init_k_coefficients_prc2( void )
279 {
323 {
280 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
324 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
281 }
325 }
@@ -1,720 +1,795
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "fsw_processing.h"
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
11 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
12 #include "fsw_init.h"
13
13
14 unsigned int nb_sm_f0;
14 unsigned int nb_sm_f0;
15 unsigned int nb_sm_f0_aux_f1;
15 unsigned int nb_sm_f0_aux_f1;
16 unsigned int nb_sm_f1;
16 unsigned int nb_sm_f1;
17 unsigned int nb_sm_f0_aux_f2;
17 unsigned int nb_sm_f0_aux_f2;
18
18
19 typedef enum restartState_t
19 typedef enum restartState_t
20 {
20 {
21 WAIT_FOR_F2,
21 WAIT_FOR_F2,
22 WAIT_FOR_F1,
22 WAIT_FOR_F1,
23 WAIT_FOR_F0
23 WAIT_FOR_F0
24 } restartState;
24 } restartState;
25
25
26 //************************
26 //************************
27 // spectral matrices rings
27 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
31 ring_node *current_ring_node_sm_f0;
31 ring_node *current_ring_node_sm_f0;
32 ring_node *current_ring_node_sm_f1;
32 ring_node *current_ring_node_sm_f1;
33 ring_node *current_ring_node_sm_f2;
33 ring_node *current_ring_node_sm_f2;
34 ring_node *ring_node_for_averaging_sm_f0;
34 ring_node *ring_node_for_averaging_sm_f0;
35 ring_node *ring_node_for_averaging_sm_f1;
35 ring_node *ring_node_for_averaging_sm_f1;
36 ring_node *ring_node_for_averaging_sm_f2;
36 ring_node *ring_node_for_averaging_sm_f2;
37
37
38 //
38 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
40 {
41 ring_node *node;
41 ring_node *node;
42
42
43 node = NULL;
43 node = NULL;
44 switch ( frequencyChannel ) {
44 switch ( frequencyChannel ) {
45 case 0:
45 case 0:
46 node = ring_node_for_averaging_sm_f0;
46 node = ring_node_for_averaging_sm_f0;
47 break;
47 break;
48 case 1:
48 case 1:
49 node = ring_node_for_averaging_sm_f1;
49 node = ring_node_for_averaging_sm_f1;
50 break;
50 break;
51 case 2:
51 case 2:
52 node = ring_node_for_averaging_sm_f2;
52 node = ring_node_for_averaging_sm_f2;
53 break;
53 break;
54 default:
54 default:
55 break;
55 break;
56 }
56 }
57
57
58 return node;
58 return node;
59 }
59 }
60
60
61 //***********************************************************
61 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
62 // Interrupt Service Routine for spectral matrices processing
63
63
64 void spectral_matrices_isr_f0( int statusReg )
64 void spectral_matrices_isr_f0( int statusReg )
65 {
65 {
66 unsigned char status;
66 unsigned char status;
67 rtems_status_code status_code;
67 rtems_status_code status_code;
68 ring_node *full_ring_node;
68 ring_node *full_ring_node;
69
69
70 status = (unsigned char) (statusReg & 0x03); // [0011] get the status_ready_matrix_f0_x bits
70 status = (unsigned char) (statusReg & 0x03); // [0011] get the status_ready_matrix_f0_x bits
71
71
72 switch(status)
72 switch(status)
73 {
73 {
74 case 0:
74 case 0:
75 break;
75 break;
76 case 3:
76 case 3:
77 // UNEXPECTED VALUE
77 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = 0x03; // [0011]
78 spectral_matrix_regs->status = 0x03; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
80 break;
81 case 1:
81 case 1:
82 full_ring_node = current_ring_node_sm_f0->previous;
82 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
87 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
88 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
90 {
90 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
91 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
93 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
95 }
96 nb_sm_f0 = 0;
96 nb_sm_f0 = 0;
97 }
97 }
98 spectral_matrix_regs->status = 0x01; // [0000 0001]
98 spectral_matrix_regs->status = 0x01; // [0000 0001]
99 break;
99 break;
100 case 2:
100 case 2:
101 full_ring_node = current_ring_node_sm_f0->previous;
101 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
106 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
107 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
109 {
109 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
110 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
112 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
114 }
115 nb_sm_f0 = 0;
115 nb_sm_f0 = 0;
116 }
116 }
117 spectral_matrix_regs->status = 0x02; // [0000 0010]
117 spectral_matrix_regs->status = 0x02; // [0000 0010]
118 break;
118 break;
119 }
119 }
120 }
120 }
121
121
122 void spectral_matrices_isr_f1( int statusReg )
122 void spectral_matrices_isr_f1( int statusReg )
123 {
123 {
124 rtems_status_code status_code;
124 rtems_status_code status_code;
125 unsigned char status;
125 unsigned char status;
126 ring_node *full_ring_node;
126 ring_node *full_ring_node;
127
127
128 status = (unsigned char) ((statusReg & 0x0c) >> 2); // [1100] get the status_ready_matrix_f1_x bits
128 status = (unsigned char) ((statusReg & 0x0c) >> 2); // [1100] get the status_ready_matrix_f1_x bits
129
129
130 switch(status)
130 switch(status)
131 {
131 {
132 case 0:
132 case 0:
133 break;
133 break;
134 case 3:
134 case 3:
135 // UNEXPECTED VALUE
135 // UNEXPECTED VALUE
136 spectral_matrix_regs->status = 0xc0; // [1100]
136 spectral_matrix_regs->status = 0xc0; // [1100]
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
138 break;
138 break;
139 case 1:
139 case 1:
140 full_ring_node = current_ring_node_sm_f1->previous;
140 full_ring_node = current_ring_node_sm_f1->previous;
141 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
141 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
142 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
142 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
143 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
143 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
144 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
144 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
145 // if there are enough ring nodes ready, wake up an AVFx task
145 // if there are enough ring nodes ready, wake up an AVFx task
146 nb_sm_f1 = nb_sm_f1 + 1;
146 nb_sm_f1 = nb_sm_f1 + 1;
147 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
147 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
148 {
148 {
149 ring_node_for_averaging_sm_f1 = full_ring_node;
149 ring_node_for_averaging_sm_f1 = full_ring_node;
150 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
150 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
151 {
151 {
152 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
152 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
153 }
153 }
154 nb_sm_f1 = 0;
154 nb_sm_f1 = 0;
155 }
155 }
156 spectral_matrix_regs->status = 0x04; // [0000 0100]
156 spectral_matrix_regs->status = 0x04; // [0000 0100]
157 break;
157 break;
158 case 2:
158 case 2:
159 full_ring_node = current_ring_node_sm_f1->previous;
159 full_ring_node = current_ring_node_sm_f1->previous;
160 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
160 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
161 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
161 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
162 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
162 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
163 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
163 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
164 // if there are enough ring nodes ready, wake up an AVFx task
164 // if there are enough ring nodes ready, wake up an AVFx task
165 nb_sm_f1 = nb_sm_f1 + 1;
165 nb_sm_f1 = nb_sm_f1 + 1;
166 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
166 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
167 {
167 {
168 ring_node_for_averaging_sm_f1 = full_ring_node;
168 ring_node_for_averaging_sm_f1 = full_ring_node;
169 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
169 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
170 {
170 {
171 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
171 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
172 }
172 }
173 nb_sm_f1 = 0;
173 nb_sm_f1 = 0;
174 }
174 }
175 spectral_matrix_regs->status = 0x08; // [1000 0000]
175 spectral_matrix_regs->status = 0x08; // [1000 0000]
176 break;
176 break;
177 }
177 }
178 }
178 }
179
179
180 void spectral_matrices_isr_f2( int statusReg )
180 void spectral_matrices_isr_f2( int statusReg )
181 {
181 {
182 unsigned char status;
182 unsigned char status;
183 rtems_status_code status_code;
183 rtems_status_code status_code;
184
184
185 status = (unsigned char) ((statusReg & 0x30) >> 4); // [0011 0000] get the status_ready_matrix_f2_x bits
185 status = (unsigned char) ((statusReg & 0x30) >> 4); // [0011 0000] get the status_ready_matrix_f2_x bits
186
186
187 switch(status)
187 switch(status)
188 {
188 {
189 case 0:
189 case 0:
190 break;
190 break;
191 case 3:
191 case 3:
192 // UNEXPECTED VALUE
192 // UNEXPECTED VALUE
193 spectral_matrix_regs->status = 0x30; // [0011 0000]
193 spectral_matrix_regs->status = 0x30; // [0011 0000]
194 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
194 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
195 break;
195 break;
196 case 1:
196 case 1:
197 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
197 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
198 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
198 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
199 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
199 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
200 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
200 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
201 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
201 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
202 spectral_matrix_regs->status = 0x10; // [0001 0000]
202 spectral_matrix_regs->status = 0x10; // [0001 0000]
203 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
203 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
204 {
204 {
205 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
205 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
206 }
206 }
207 break;
207 break;
208 case 2:
208 case 2:
209 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
209 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
210 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
210 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
211 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
211 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
212 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
212 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
213 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
213 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
214 spectral_matrix_regs->status = 0x20; // [0010 0000]
214 spectral_matrix_regs->status = 0x20; // [0010 0000]
215 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
215 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
216 {
216 {
217 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
217 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
218 }
218 }
219 break;
219 break;
220 }
220 }
221 }
221 }
222
222
223 void spectral_matrix_isr_error_handler( int statusReg )
223 void spectral_matrix_isr_error_handler( int statusReg )
224 {
224 {
225 // STATUS REGISTER
225 // STATUS REGISTER
226 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
226 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
227 // 10 9 8
227 // 10 9 8
228 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
228 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
229 // 7 6 5 4 3 2 1 0
229 // 7 6 5 4 3 2 1 0
230 // [bad_component_err] not defined in the last version of the VHDL code
230 // [bad_component_err] not defined in the last version of the VHDL code
231
231
232 rtems_status_code status_code;
232 rtems_status_code status_code;
233
233
234 //***************************************************
234 //***************************************************
235 // the ASM status register is copied in the HK packet
235 // the ASM status register is copied in the HK packet
236 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) (statusReg & 0x780 >> 7); // [0111 1000 0000]
236 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) (statusReg & 0x780 >> 7); // [0111 1000 0000]
237
237
238 if (statusReg & 0x7c0) // [0111 1100 0000]
238 if (statusReg & 0x7c0) // [0111 1100 0000]
239 {
239 {
240 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
240 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
241 }
241 }
242
242
243 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
243 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
244
244
245 }
245 }
246
246
247 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
247 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
248 {
248 {
249 // STATUS REGISTER
249 // STATUS REGISTER
250 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
250 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
251 // 10 9 8
251 // 10 9 8
252 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
252 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
253 // 7 6 5 4 3 2 1 0
253 // 7 6 5 4 3 2 1 0
254
254
255 int statusReg;
255 int statusReg;
256
256
257 static restartState state = WAIT_FOR_F2;
257 static restartState state = WAIT_FOR_F2;
258
258
259 statusReg = spectral_matrix_regs->status;
259 statusReg = spectral_matrix_regs->status;
260
260
261 if (thisIsAnASMRestart == 0)
261 if (thisIsAnASMRestart == 0)
262 { // this is not a restart sequence, process incoming matrices normally
262 { // this is not a restart sequence, process incoming matrices normally
263 spectral_matrices_isr_f0( statusReg );
263 spectral_matrices_isr_f0( statusReg );
264
264
265 spectral_matrices_isr_f1( statusReg );
265 spectral_matrices_isr_f1( statusReg );
266
266
267 spectral_matrices_isr_f2( statusReg );
267 spectral_matrices_isr_f2( statusReg );
268 }
268 }
269 else
269 else
270 { // a restart sequence has to be launched
270 { // a restart sequence has to be launched
271 switch (state) {
271 switch (state) {
272 case WAIT_FOR_F2:
272 case WAIT_FOR_F2:
273 if ((statusReg & 0x30) != 0x00) // [0011 0000] check the status_ready_matrix_f2_x bits
273 if ((statusReg & 0x30) != 0x00) // [0011 0000] check the status_ready_matrix_f2_x bits
274 {
274 {
275 state = WAIT_FOR_F1;
275 state = WAIT_FOR_F1;
276 }
276 }
277 break;
277 break;
278 case WAIT_FOR_F1:
278 case WAIT_FOR_F1:
279 if ((statusReg & 0x0c) != 0x00) // [0000 1100] check the status_ready_matrix_f1_x bits
279 if ((statusReg & 0x0c) != 0x00) // [0000 1100] check the status_ready_matrix_f1_x bits
280 {
280 {
281 state = WAIT_FOR_F0;
281 state = WAIT_FOR_F0;
282 }
282 }
283 break;
283 break;
284 case WAIT_FOR_F0:
284 case WAIT_FOR_F0:
285 if ((statusReg & 0x03) != 0x00) // [0000 0011] check the status_ready_matrix_f0_x bits
285 if ((statusReg & 0x03) != 0x00) // [0000 0011] check the status_ready_matrix_f0_x bits
286 {
286 {
287 state = WAIT_FOR_F2;
287 state = WAIT_FOR_F2;
288 thisIsAnASMRestart = 0;
288 thisIsAnASMRestart = 0;
289 }
289 }
290 break;
290 break;
291 default:
291 default:
292 break;
292 break;
293 }
293 }
294 reset_sm_status();
294 reset_sm_status();
295 }
295 }
296
296
297 spectral_matrix_isr_error_handler( statusReg );
297 spectral_matrix_isr_error_handler( statusReg );
298
298
299 }
299 }
300
300
301 //******************
301 //******************
302 // Spectral Matrices
302 // Spectral Matrices
303
303
304 void reset_nb_sm( void )
304 void reset_nb_sm( void )
305 {
305 {
306 nb_sm_f0 = 0;
306 nb_sm_f0 = 0;
307 nb_sm_f0_aux_f1 = 0;
307 nb_sm_f0_aux_f1 = 0;
308 nb_sm_f0_aux_f2 = 0;
308 nb_sm_f0_aux_f2 = 0;
309
309
310 nb_sm_f1 = 0;
310 nb_sm_f1 = 0;
311 }
311 }
312
312
313 void SM_init_rings( void )
313 void SM_init_rings( void )
314 {
314 {
315 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
315 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
316 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
316 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
317 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
317 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
318
318
319 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
319 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
320 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
320 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
321 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
321 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
322 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
322 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
323 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
323 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
324 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
324 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
325 }
325 }
326
326
327 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
327 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
328 {
328 {
329 unsigned char i;
329 unsigned char i;
330
330
331 ring[ nbNodes - 1 ].next
331 ring[ nbNodes - 1 ].next
332 = (ring_node_asm*) &ring[ 0 ];
332 = (ring_node_asm*) &ring[ 0 ];
333
333
334 for(i=0; i<nbNodes-1; i++)
334 for(i=0; i<nbNodes-1; i++)
335 {
335 {
336 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
336 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
337 }
337 }
338 }
338 }
339
339
340 void SM_reset_current_ring_nodes( void )
340 void SM_reset_current_ring_nodes( void )
341 {
341 {
342 current_ring_node_sm_f0 = sm_ring_f0[0].next;
342 current_ring_node_sm_f0 = sm_ring_f0[0].next;
343 current_ring_node_sm_f1 = sm_ring_f1[0].next;
343 current_ring_node_sm_f1 = sm_ring_f1[0].next;
344 current_ring_node_sm_f2 = sm_ring_f2[0].next;
344 current_ring_node_sm_f2 = sm_ring_f2[0].next;
345
345
346 ring_node_for_averaging_sm_f0 = NULL;
346 ring_node_for_averaging_sm_f0 = NULL;
347 ring_node_for_averaging_sm_f1 = NULL;
347 ring_node_for_averaging_sm_f1 = NULL;
348 ring_node_for_averaging_sm_f2 = NULL;
348 ring_node_for_averaging_sm_f2 = NULL;
349 }
349 }
350
350
351 //*****************
351 //*****************
352 // Basic Parameters
352 // Basic Parameters
353
353
354 void BP_init_header( bp_packet *packet,
354 void BP_init_header( bp_packet *packet,
355 unsigned int apid, unsigned char sid,
355 unsigned int apid, unsigned char sid,
356 unsigned int packetLength, unsigned char blkNr )
356 unsigned int packetLength, unsigned char blkNr )
357 {
357 {
358 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
358 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
359 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
359 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
360 packet->reserved = 0x00;
360 packet->reserved = 0x00;
361 packet->userApplication = CCSDS_USER_APP;
361 packet->userApplication = CCSDS_USER_APP;
362 packet->packetID[0] = (unsigned char) (apid >> 8);
362 packet->packetID[0] = (unsigned char) (apid >> 8);
363 packet->packetID[1] = (unsigned char) (apid);
363 packet->packetID[1] = (unsigned char) (apid);
364 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
364 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
365 packet->packetSequenceControl[1] = 0x00;
365 packet->packetSequenceControl[1] = 0x00;
366 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
366 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
367 packet->packetLength[1] = (unsigned char) (packetLength);
367 packet->packetLength[1] = (unsigned char) (packetLength);
368 // DATA FIELD HEADER
368 // DATA FIELD HEADER
369 packet->spare1_pusVersion_spare2 = 0x10;
369 packet->spare1_pusVersion_spare2 = 0x10;
370 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
370 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
371 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
371 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
372 packet->destinationID = TM_DESTINATION_ID_GROUND;
372 packet->destinationID = TM_DESTINATION_ID_GROUND;
373 packet->time[0] = 0x00;
373 packet->time[0] = 0x00;
374 packet->time[1] = 0x00;
374 packet->time[1] = 0x00;
375 packet->time[2] = 0x00;
375 packet->time[2] = 0x00;
376 packet->time[3] = 0x00;
376 packet->time[3] = 0x00;
377 packet->time[4] = 0x00;
377 packet->time[4] = 0x00;
378 packet->time[5] = 0x00;
378 packet->time[5] = 0x00;
379 // AUXILIARY DATA HEADER
379 // AUXILIARY DATA HEADER
380 packet->sid = sid;
380 packet->sid = sid;
381 packet->pa_bia_status_info = 0x00;
381 packet->pa_bia_status_info = 0x00;
382 packet->sy_lfr_common_parameters_spare = 0x00;
382 packet->sy_lfr_common_parameters_spare = 0x00;
383 packet->sy_lfr_common_parameters = 0x00;
383 packet->sy_lfr_common_parameters = 0x00;
384 packet->acquisitionTime[0] = 0x00;
384 packet->acquisitionTime[0] = 0x00;
385 packet->acquisitionTime[1] = 0x00;
385 packet->acquisitionTime[1] = 0x00;
386 packet->acquisitionTime[2] = 0x00;
386 packet->acquisitionTime[2] = 0x00;
387 packet->acquisitionTime[3] = 0x00;
387 packet->acquisitionTime[3] = 0x00;
388 packet->acquisitionTime[4] = 0x00;
388 packet->acquisitionTime[4] = 0x00;
389 packet->acquisitionTime[5] = 0x00;
389 packet->acquisitionTime[5] = 0x00;
390 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
390 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
391 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
391 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
392 }
392 }
393
393
394 void BP_init_header_with_spare( bp_packet_with_spare *packet,
394 void BP_init_header_with_spare( bp_packet_with_spare *packet,
395 unsigned int apid, unsigned char sid,
395 unsigned int apid, unsigned char sid,
396 unsigned int packetLength , unsigned char blkNr)
396 unsigned int packetLength , unsigned char blkNr)
397 {
397 {
398 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
398 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
399 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
399 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
400 packet->reserved = 0x00;
400 packet->reserved = 0x00;
401 packet->userApplication = CCSDS_USER_APP;
401 packet->userApplication = CCSDS_USER_APP;
402 packet->packetID[0] = (unsigned char) (apid >> 8);
402 packet->packetID[0] = (unsigned char) (apid >> 8);
403 packet->packetID[1] = (unsigned char) (apid);
403 packet->packetID[1] = (unsigned char) (apid);
404 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
404 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
405 packet->packetSequenceControl[1] = 0x00;
405 packet->packetSequenceControl[1] = 0x00;
406 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
406 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
407 packet->packetLength[1] = (unsigned char) (packetLength);
407 packet->packetLength[1] = (unsigned char) (packetLength);
408 // DATA FIELD HEADER
408 // DATA FIELD HEADER
409 packet->spare1_pusVersion_spare2 = 0x10;
409 packet->spare1_pusVersion_spare2 = 0x10;
410 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
410 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
411 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
411 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
412 packet->destinationID = TM_DESTINATION_ID_GROUND;
412 packet->destinationID = TM_DESTINATION_ID_GROUND;
413 // AUXILIARY DATA HEADER
413 // AUXILIARY DATA HEADER
414 packet->sid = sid;
414 packet->sid = sid;
415 packet->pa_bia_status_info = 0x00;
415 packet->pa_bia_status_info = 0x00;
416 packet->sy_lfr_common_parameters_spare = 0x00;
416 packet->sy_lfr_common_parameters_spare = 0x00;
417 packet->sy_lfr_common_parameters = 0x00;
417 packet->sy_lfr_common_parameters = 0x00;
418 packet->time[0] = 0x00;
418 packet->time[0] = 0x00;
419 packet->time[0] = 0x00;
419 packet->time[0] = 0x00;
420 packet->time[0] = 0x00;
420 packet->time[0] = 0x00;
421 packet->time[0] = 0x00;
421 packet->time[0] = 0x00;
422 packet->time[0] = 0x00;
422 packet->time[0] = 0x00;
423 packet->time[0] = 0x00;
423 packet->time[0] = 0x00;
424 packet->source_data_spare = 0x00;
424 packet->source_data_spare = 0x00;
425 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
425 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
426 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
426 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
427 }
427 }
428
428
429 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
429 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
430 {
430 {
431 rtems_status_code status;
431 rtems_status_code status;
432
432
433 // SEND PACKET
433 // SEND PACKET
434 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
434 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
435 if (status != RTEMS_SUCCESSFUL)
435 if (status != RTEMS_SUCCESSFUL)
436 {
436 {
437 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
437 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
438 }
438 }
439 }
439 }
440
440
441 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
441 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
442 {
442 {
443 /** This function is used to send the BP paquets when needed.
443 /** This function is used to send the BP paquets when needed.
444 *
444 *
445 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
445 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
446 *
446 *
447 * @return void
447 * @return void
448 *
448 *
449 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
449 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
450 * BURST paquets are sent everytime.
450 * BURST paquets are sent everytime.
451 *
451 *
452 */
452 */
453
453
454 rtems_status_code status;
454 rtems_status_code status;
455
455
456 // SEND PACKET
456 // SEND PACKET
457 // before lastValidTransitionDate, the data are drops even if they are ready
457 // before lastValidTransitionDate, the data are drops even if they are ready
458 // this guarantees that no SBM packets will be received before the requested enter mode time
458 // this guarantees that no SBM packets will be received before the requested enter mode time
459 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
459 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
460 {
460 {
461 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
461 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
462 if (status != RTEMS_SUCCESSFUL)
462 if (status != RTEMS_SUCCESSFUL)
463 {
463 {
464 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
464 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
465 }
465 }
466 }
466 }
467 }
467 }
468
468
469 //******************
469 //******************
470 // general functions
470 // general functions
471
471
472 void reset_sm_status( void )
472 void reset_sm_status( void )
473 {
473 {
474 // error
474 // error
475 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
475 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
476 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
476 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
477 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
477 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
478 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
478 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
479
479
480 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
480 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
481 }
481 }
482
482
483 void reset_spectral_matrix_regs( void )
483 void reset_spectral_matrix_regs( void )
484 {
484 {
485 /** This function resets the spectral matrices module registers.
485 /** This function resets the spectral matrices module registers.
486 *
486 *
487 * The registers affected by this function are located at the following offset addresses:
487 * The registers affected by this function are located at the following offset addresses:
488 *
488 *
489 * - 0x00 config
489 * - 0x00 config
490 * - 0x04 status
490 * - 0x04 status
491 * - 0x08 matrixF0_Address0
491 * - 0x08 matrixF0_Address0
492 * - 0x10 matrixFO_Address1
492 * - 0x10 matrixFO_Address1
493 * - 0x14 matrixF1_Address
493 * - 0x14 matrixF1_Address
494 * - 0x18 matrixF2_Address
494 * - 0x18 matrixF2_Address
495 *
495 *
496 */
496 */
497
497
498 set_sm_irq_onError( 0 );
498 set_sm_irq_onError( 0 );
499
499
500 set_sm_irq_onNewMatrix( 0 );
500 set_sm_irq_onNewMatrix( 0 );
501
501
502 reset_sm_status();
502 reset_sm_status();
503
503
504 // F1
504 // F1
505 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
505 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
506 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
506 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
507 // F2
507 // F2
508 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
508 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
509 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
509 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
510 // F3
510 // F3
511 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
511 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
512 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
512 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
513
513
514 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
514 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
515 }
515 }
516
516
517 void set_time( unsigned char *time, unsigned char * timeInBuffer )
517 void set_time( unsigned char *time, unsigned char * timeInBuffer )
518 {
518 {
519 time[0] = timeInBuffer[0];
519 time[0] = timeInBuffer[0];
520 time[1] = timeInBuffer[1];
520 time[1] = timeInBuffer[1];
521 time[2] = timeInBuffer[2];
521 time[2] = timeInBuffer[2];
522 time[3] = timeInBuffer[3];
522 time[3] = timeInBuffer[3];
523 time[4] = timeInBuffer[6];
523 time[4] = timeInBuffer[6];
524 time[5] = timeInBuffer[7];
524 time[5] = timeInBuffer[7];
525 }
525 }
526
526
527 unsigned long long int get_acquisition_time( unsigned char *timePtr )
527 unsigned long long int get_acquisition_time( unsigned char *timePtr )
528 {
528 {
529 unsigned long long int acquisitionTimeAslong;
529 unsigned long long int acquisitionTimeAslong;
530 acquisitionTimeAslong = 0x00;
530 acquisitionTimeAslong = 0x00;
531 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
531 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
532 + ( (unsigned long long int) timePtr[1] << 32 )
532 + ( (unsigned long long int) timePtr[1] << 32 )
533 + ( (unsigned long long int) timePtr[2] << 24 )
533 + ( (unsigned long long int) timePtr[2] << 24 )
534 + ( (unsigned long long int) timePtr[3] << 16 )
534 + ( (unsigned long long int) timePtr[3] << 16 )
535 + ( (unsigned long long int) timePtr[6] << 8 )
535 + ( (unsigned long long int) timePtr[6] << 8 )
536 + ( (unsigned long long int) timePtr[7] );
536 + ( (unsigned long long int) timePtr[7] );
537 return acquisitionTimeAslong;
537 return acquisitionTimeAslong;
538 }
538 }
539
539
540 unsigned char getSID( rtems_event_set event )
540 unsigned char getSID( rtems_event_set event )
541 {
541 {
542 unsigned char sid;
542 unsigned char sid;
543
543
544 rtems_event_set eventSetBURST;
544 rtems_event_set eventSetBURST;
545 rtems_event_set eventSetSBM;
545 rtems_event_set eventSetSBM;
546
546
547 //******
547 //******
548 // BURST
548 // BURST
549 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
549 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
550 | RTEMS_EVENT_BURST_BP1_F1
550 | RTEMS_EVENT_BURST_BP1_F1
551 | RTEMS_EVENT_BURST_BP2_F0
551 | RTEMS_EVENT_BURST_BP2_F0
552 | RTEMS_EVENT_BURST_BP2_F1;
552 | RTEMS_EVENT_BURST_BP2_F1;
553
553
554 //****
554 //****
555 // SBM
555 // SBM
556 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
556 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
557 | RTEMS_EVENT_SBM_BP1_F1
557 | RTEMS_EVENT_SBM_BP1_F1
558 | RTEMS_EVENT_SBM_BP2_F0
558 | RTEMS_EVENT_SBM_BP2_F0
559 | RTEMS_EVENT_SBM_BP2_F1;
559 | RTEMS_EVENT_SBM_BP2_F1;
560
560
561 if (event & eventSetBURST)
561 if (event & eventSetBURST)
562 {
562 {
563 sid = SID_BURST_BP1_F0;
563 sid = SID_BURST_BP1_F0;
564 }
564 }
565 else if (event & eventSetSBM)
565 else if (event & eventSetSBM)
566 {
566 {
567 sid = SID_SBM1_BP1_F0;
567 sid = SID_SBM1_BP1_F0;
568 }
568 }
569 else
569 else
570 {
570 {
571 sid = 0;
571 sid = 0;
572 }
572 }
573
573
574 return sid;
574 return sid;
575 }
575 }
576
576
577 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
577 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
578 {
578 {
579 unsigned int i;
579 unsigned int i;
580 float re;
580 float re;
581 float im;
581 float im;
582
582
583 for (i=0; i<NB_BINS_PER_SM; i++){
583 for (i=0; i<NB_BINS_PER_SM; i++){
584 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
584 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
585 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
585 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
586 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
586 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
587 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
587 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
588 }
588 }
589 }
589 }
590
590
591 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
591 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
592 {
592 {
593 unsigned int i;
593 unsigned int i;
594 float re;
594 float re;
595
595
596 for (i=0; i<NB_BINS_PER_SM; i++){
596 for (i=0; i<NB_BINS_PER_SM; i++){
597 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
597 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
598 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
598 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
599 }
599 }
600 }
600 }
601
601
602 void ASM_patch( float *inputASM, float *outputASM )
602 void ASM_patch( float *inputASM, float *outputASM )
603 {
603 {
604 extractReImVectors( inputASM, outputASM, 1); // b1b2
604 extractReImVectors( inputASM, outputASM, 1); // b1b2
605 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
605 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
606 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
606 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
607 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
607 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
608 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
608 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
609 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
609 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
610 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
610 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
611 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
611 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
612 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
612 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
613 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
613 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
614
614
615 copyReVectors(inputASM, outputASM, 0 ); // b1b1
615 copyReVectors(inputASM, outputASM, 0 ); // b1b1
616 copyReVectors(inputASM, outputASM, 9 ); // b2b2
616 copyReVectors(inputASM, outputASM, 9 ); // b2b2
617 copyReVectors(inputASM, outputASM, 16); // b3b3
617 copyReVectors(inputASM, outputASM, 16); // b3b3
618 copyReVectors(inputASM, outputASM, 21); // e1e1
618 copyReVectors(inputASM, outputASM, 21); // e1e1
619 copyReVectors(inputASM, outputASM, 24); // e2e2
619 copyReVectors(inputASM, outputASM, 24); // e2e2
620 }
620 }
621
621
622 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
622 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
623 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
623 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
624 unsigned char ASMIndexStart,
624 unsigned char ASMIndexStart,
625 unsigned char channel )
625 unsigned char channel )
626 {
626 {
627 //*************
627 //*************
628 // input format
628 // input format
629 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
629 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
630 //**************
630 //**************
631 // output format
631 // output format
632 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
632 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
633 //************
633 //************
634 // compression
634 // compression
635 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
635 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
636 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
636 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
637
637
638 int frequencyBin;
638 int frequencyBin;
639 int asmComponent;
639 int asmComponent;
640 int offsetASM;
640 int offsetASM;
641 int offsetCompressed;
641 int offsetCompressed;
642 int offsetFBin;
642 int offsetFBin;
643 int fBinMask;
643 int fBinMask;
644 int k;
644 int k;
645
645
646 // BUILD DATA
646 // BUILD DATA
647 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
647 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
648 {
648 {
649 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
649 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
650 {
650 {
651 offsetCompressed = // NO TIME OFFSET
651 offsetCompressed = // NO TIME OFFSET
652 frequencyBin * NB_VALUES_PER_SM
652 frequencyBin * NB_VALUES_PER_SM
653 + asmComponent;
653 + asmComponent;
654 offsetASM = // NO TIME OFFSET
654 offsetASM = // NO TIME OFFSET
655 asmComponent * NB_BINS_PER_SM
655 asmComponent * NB_BINS_PER_SM
656 + ASMIndexStart
656 + ASMIndexStart
657 + frequencyBin * nbBinsToAverage;
657 + frequencyBin * nbBinsToAverage;
658 offsetFBin = ASMIndexStart
658 offsetFBin = ASMIndexStart
659 + frequencyBin * nbBinsToAverage;
659 + frequencyBin * nbBinsToAverage;
660 compressed_spec_mat[ offsetCompressed ] = 0;
660 compressed_spec_mat[ offsetCompressed ] = 0;
661 for ( k = 0; k < nbBinsToAverage; k++ )
661 for ( k = 0; k < nbBinsToAverage; k++ )
662 {
662 {
663 fBinMask = getFBinMask( offsetFBin + k, channel );
663 fBinMask = getFBinMask( offsetFBin + k, channel );
664 compressed_spec_mat[offsetCompressed ] =
664 compressed_spec_mat[offsetCompressed ] =
665 ( compressed_spec_mat[ offsetCompressed ]
665 ( compressed_spec_mat[ offsetCompressed ]
666 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
666 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
667 }
667 }
668 compressed_spec_mat[ offsetCompressed ] =
668 compressed_spec_mat[ offsetCompressed ] =
669 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
669 (divider != 0.) ? compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage) : 0.0;
670 }
670 }
671 }
671 }
672
672
673 }
673 }
674
674
675 int getFBinMask( int index, unsigned char channel )
675 int getFBinMask( int index, unsigned char channel )
676 {
676 {
677 unsigned int indexInChar;
677 unsigned int indexInChar;
678 unsigned int indexInTheChar;
678 unsigned int indexInTheChar;
679 int fbin;
679 int fbin;
680 unsigned char *sy_lfr_fbins_fx_word1;
680 unsigned char *sy_lfr_fbins_fx_word1;
681
681
682 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
682 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
683
683
684 switch(channel)
684 switch(channel)
685 {
685 {
686 case 0:
686 case 0:
687 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
687 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
688 break;
688 break;
689 case 1:
689 case 1:
690 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
690 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
691 break;
691 break;
692 case 2:
692 case 2:
693 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
693 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
694 break;
694 break;
695 default:
695 default:
696 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
696 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
697 }
697 }
698
698
699 indexInChar = index >> 3;
699 indexInChar = index >> 3;
700 indexInTheChar = index - indexInChar * 8;
700 indexInTheChar = index - indexInChar * 8;
701
701
702 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
702 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
703
703
704 return fbin;
704 return fbin;
705 }
705 }
706
706
707 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
708 {
709 u_int64_t acquisitionTime;
710 u_int64_t timecodeReference;
711 u_int64_t offsetInFineTime;
712 u_int64_t shiftInFineTime;
713 u_int64_t tBadInFineTime;
714 u_int64_t acquisitionTimeRangeMin;
715 u_int64_t acquisitionTimeRangeMax;
716 unsigned char pasFilteringIsEnabled;
717 unsigned char ret;
718
719 pasFilteringIsEnabled = (parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01); // [0000 0001]
720 ret = 1;
721
722 //***************************
723 // <FOR TESTING PURPOSE ONLY>
724 unsigned char sy_lfr_pas_filter_modulus = 4;
725 unsigned char sy_lfr_pas_filter_offset = 1;
726 float sy_lfr_pas_filter_shift = 0.5;
727 float sy_lfr_pas_filter_tbad = 1.0;
728 // </FOR TESTING PURPOSE ONLY>
729 //****************************
730
731 // compute acquisition time from caoarseTime and fineTime
732 acquisitionTime = ( ((u_int64_t)coarseTime) << 16 )
733 + (u_int64_t) fineTime;
734
735 // compute the timecode reference
736 timecodeReference = (u_int64_t) (floor( ((double) coarseTime) / ((double) sy_lfr_pas_filter_modulus) )
737 * ((double) sy_lfr_pas_filter_modulus)) * 65536;
738
739 // compute the acquitionTime range
740 offsetInFineTime = ((double) sy_lfr_pas_filter_offset) * 65536;
741 shiftInFineTime = ((double) sy_lfr_pas_filter_shift) * 65536;
742 tBadInFineTime = ((double) sy_lfr_pas_filter_tbad) * 65536;
743
744 acquisitionTimeRangeMin =
745 timecodeReference
746 + offsetInFineTime
747 + shiftInFineTime
748 - acquisitionDurations[channel];
749 acquisitionTimeRangeMax =
750 timecodeReference
751 + offsetInFineTime
752 + shiftInFineTime
753 + tBadInFineTime;
754
755 if ( (acquisitionTime >= acquisitionTimeRangeMin)
756 && (acquisitionTime <= acquisitionTimeRangeMax)
757 && (pasFilteringIsEnabled == 1) )
758 {
759 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
760 }
761 else
762 {
763 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
764 }
765
766 // printf("coarseTime = %x, fineTime = %x\n",
767 // coarseTime,
768 // fineTime);
769
770 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
771 // ret,
772 // acquisitionTime / 65536.,
773 // timecodeReference / 65536.);
774
775 // printf(", Min = %f, Max = %f\n",
776 // acquisitionTimeRangeMin / 65536.,
777 // acquisitionTimeRangeMax / 65536.);
778
779 return ret;
780 }
781
707 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
782 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
708 {
783 {
709 unsigned char bin;
784 unsigned char bin;
710 unsigned char kcoeff;
785 unsigned char kcoeff;
711
786
712 for (bin=0; bin<nb_bins_norm; bin++)
787 for (bin=0; bin<nb_bins_norm; bin++)
713 {
788 {
714 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
789 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
715 {
790 {
716 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
791 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
717 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
792 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
718 }
793 }
719 }
794 }
720 }
795 }
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now