@@ -1,123 +1,123 | |||
|
1 | 1 | TEMPLATE = app |
|
2 | 2 | # CONFIG += console v8 sim |
|
3 | 3 | # CONFIG options = |
|
4 | 4 | # verbose |
|
5 | 5 | # boot_messages |
|
6 | 6 | # debug_messages |
|
7 | 7 | # cpu_usage_report |
|
8 | 8 | # stack_report |
|
9 | 9 | # vhdl_dev |
|
10 | 10 | # debug_tch |
|
11 | 11 | # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\ |
|
12 | 12 | # debug_watchdog |
|
13 | 13 | CONFIG += console verbose lpp_dpu_destid cpu_usage_report |
|
14 | 14 | CONFIG -= qt |
|
15 | 15 | |
|
16 | 16 | include(./sparc.pri) |
|
17 | 17 | |
|
18 | 18 | # flight software version |
|
19 | 19 | SWVERSION=-1-0 |
|
20 | 20 | DEFINES += SW_VERSION_N1=3 # major |
|
21 | 21 | DEFINES += SW_VERSION_N2=1 # minor |
|
22 | 22 | DEFINES += SW_VERSION_N3=0 # patch |
|
23 |
DEFINES += SW_VERSION_N4= |
|
|
23 | DEFINES += SW_VERSION_N4=1 # internal | |
|
24 | 24 | |
|
25 | 25 | # <GCOV> |
|
26 | 26 | #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage |
|
27 | 27 | #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc |
|
28 | 28 | # </GCOV> |
|
29 | 29 | |
|
30 | 30 | # <CHANGE BEFORE FLIGHT> |
|
31 | 31 | contains( CONFIG, lpp_dpu_destid ) { |
|
32 | 32 | DEFINES += LPP_DPU_DESTID |
|
33 | 33 | } |
|
34 | 34 | # </CHANGE BEFORE FLIGHT> |
|
35 | 35 | |
|
36 | 36 | contains( CONFIG, debug_tch ) { |
|
37 | 37 | DEFINES += DEBUG_TCH |
|
38 | 38 | } |
|
39 | 39 | DEFINES += MSB_FIRST_TCH |
|
40 | 40 | |
|
41 | 41 | contains( CONFIG, vhdl_dev ) { |
|
42 | 42 | DEFINES += VHDL_DEV |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | contains( CONFIG, verbose ) { |
|
46 | 46 | DEFINES += PRINT_MESSAGES_ON_CONSOLE |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | contains( CONFIG, debug_messages ) { |
|
50 | 50 | DEFINES += DEBUG_MESSAGES |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | contains( CONFIG, cpu_usage_report ) { |
|
54 | 54 | DEFINES += PRINT_TASK_STATISTICS |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | contains( CONFIG, stack_report ) { |
|
58 | 58 | DEFINES += PRINT_STACK_REPORT |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | contains( CONFIG, boot_messages ) { |
|
62 | 62 | DEFINES += BOOT_MESSAGES |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | contains( CONFIG, debug_watchdog ) { |
|
66 | 66 | DEFINES += DEBUG_WATCHDOG |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | #doxygen.target = doxygen |
|
70 | 70 | #doxygen.commands = doxygen ../doc/Doxyfile |
|
71 | 71 | #QMAKE_EXTRA_TARGETS += doxygen |
|
72 | 72 | |
|
73 | 73 | TARGET = fsw |
|
74 | 74 | |
|
75 | 75 | INCLUDEPATH += \ |
|
76 | 76 | $${PWD}/../src \ |
|
77 | 77 | $${PWD}/../header \ |
|
78 | 78 | $${PWD}/../header/lfr_common_headers \ |
|
79 | 79 | $${PWD}/../header/processing \ |
|
80 | 80 | $${PWD}/../LFR_basic-parameters |
|
81 | 81 | |
|
82 | 82 | SOURCES += \ |
|
83 | 83 | ../src/wf_handler.c \ |
|
84 | 84 | ../src/tc_handler.c \ |
|
85 | 85 | ../src/fsw_misc.c \ |
|
86 | 86 | ../src/fsw_init.c \ |
|
87 | 87 | ../src/fsw_globals.c \ |
|
88 | 88 | ../src/fsw_spacewire.c \ |
|
89 | 89 | ../src/tc_load_dump_parameters.c \ |
|
90 | 90 | ../src/tm_lfr_tc_exe.c \ |
|
91 | 91 | ../src/tc_acceptance.c \ |
|
92 | 92 | ../src/processing/fsw_processing.c \ |
|
93 | 93 | ../src/processing/avf0_prc0.c \ |
|
94 | 94 | ../src/processing/avf1_prc1.c \ |
|
95 | 95 | ../src/processing/avf2_prc2.c \ |
|
96 | 96 | ../src/lfr_cpu_usage_report.c \ |
|
97 | 97 | ../LFR_basic-parameters/basic_parameters.c |
|
98 | 98 | |
|
99 | 99 | HEADERS += \ |
|
100 | 100 | ../header/wf_handler.h \ |
|
101 | 101 | ../header/tc_handler.h \ |
|
102 | 102 | ../header/grlib_regs.h \ |
|
103 | 103 | ../header/fsw_misc.h \ |
|
104 | 104 | ../header/fsw_init.h \ |
|
105 | 105 | ../header/fsw_spacewire.h \ |
|
106 | 106 | ../header/tc_load_dump_parameters.h \ |
|
107 | 107 | ../header/tm_lfr_tc_exe.h \ |
|
108 | 108 | ../header/tc_acceptance.h \ |
|
109 | 109 | ../header/processing/fsw_processing.h \ |
|
110 | 110 | ../header/processing/avf0_prc0.h \ |
|
111 | 111 | ../header/processing/avf1_prc1.h \ |
|
112 | 112 | ../header/processing/avf2_prc2.h \ |
|
113 | 113 | ../header/fsw_params_wf_handler.h \ |
|
114 | 114 | ../header/lfr_cpu_usage_report.h \ |
|
115 | 115 | ../header/lfr_common_headers/ccsds_types.h \ |
|
116 | 116 | ../header/lfr_common_headers/fsw_params.h \ |
|
117 | 117 | ../header/lfr_common_headers/fsw_params_nb_bytes.h \ |
|
118 | 118 | ../header/lfr_common_headers/fsw_params_processing.h \ |
|
119 | 119 | ../header/lfr_common_headers/tm_byte_positions.h \ |
|
120 | 120 | ../LFR_basic-parameters/basic_parameters.h \ |
|
121 | 121 | ../LFR_basic-parameters/basic_parameters_params.h \ |
|
122 | 122 | ../header/GscMemoryLPP.hpp |
|
123 | 123 |
@@ -1,413 +1,414 | |||
|
1 | 1 | /** Functions related to data processing. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "avf0_prc0.h" |
|
11 | 11 | #include "fsw_processing.h" |
|
12 | 12 | |
|
13 | 13 | nb_sm_before_bp_asm_f0 nb_sm_before_f0; |
|
14 | 14 | |
|
15 | 15 | //*** |
|
16 | 16 | // F0 |
|
17 | 17 | ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ]; |
|
18 | 18 | ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ]; |
|
19 | 19 | |
|
20 | 20 | ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ]; |
|
21 | 21 | int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ]; |
|
22 | 22 | |
|
23 | 23 | float asm_f0_patched_norm [ TOTAL_SIZE_SM ]; |
|
24 | 24 | float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ]; |
|
25 | 25 | float asm_f0_reorganized [ TOTAL_SIZE_SM ]; |
|
26 | 26 | |
|
27 | 27 | char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; |
|
28 | 28 | float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0]; |
|
29 | 29 | float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ]; |
|
30 | 30 | |
|
31 | 31 | float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352 |
|
32 | 32 | float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704 |
|
33 | 33 | |
|
34 | 34 | //************ |
|
35 | 35 | // RTEMS TASKS |
|
36 | 36 | |
|
37 | 37 | rtems_task avf0_task( rtems_task_argument lfrRequestedMode ) |
|
38 | 38 | { |
|
39 | 39 | int i; |
|
40 | 40 | |
|
41 | 41 | rtems_event_set event_out; |
|
42 | 42 | rtems_status_code status; |
|
43 | 43 | rtems_id queue_id_prc0; |
|
44 | 44 | asm_msg msgForPRC; |
|
45 | 45 | ring_node *nodeForAveraging; |
|
46 | 46 | ring_node *ring_node_tab[8]; |
|
47 | 47 | ring_node_asm *current_ring_node_asm_burst_sbm_f0; |
|
48 | 48 | ring_node_asm *current_ring_node_asm_norm_f0; |
|
49 | 49 | |
|
50 | 50 | unsigned int nb_norm_bp1; |
|
51 | 51 | unsigned int nb_norm_bp2; |
|
52 | 52 | unsigned int nb_norm_asm; |
|
53 | 53 | unsigned int nb_sbm_bp1; |
|
54 | 54 | unsigned int nb_sbm_bp2; |
|
55 | 55 | |
|
56 | 56 | nb_norm_bp1 = 0; |
|
57 | 57 | nb_norm_bp2 = 0; |
|
58 | 58 | nb_norm_asm = 0; |
|
59 | 59 | nb_sbm_bp1 = 0; |
|
60 | 60 | nb_sbm_bp2 = 0; |
|
61 | 61 | |
|
62 | 62 | reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions |
|
63 | 63 | ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 ); |
|
64 | 64 | ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 ); |
|
65 | 65 | current_ring_node_asm_norm_f0 = asm_ring_norm_f0; |
|
66 | 66 | current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0; |
|
67 | 67 | |
|
68 | 68 | BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) |
|
69 | 69 | |
|
70 | 70 | status = get_message_queue_id_prc0( &queue_id_prc0 ); |
|
71 | 71 | if (status != RTEMS_SUCCESSFUL) |
|
72 | 72 | { |
|
73 | 73 | PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status) |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | while(1){ |
|
77 | 77 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
78 | 78 | |
|
79 | 79 | //**************************************** |
|
80 | 80 | // initialize the mesage for the MATR task |
|
81 | 81 | msgForPRC.norm = current_ring_node_asm_norm_f0; |
|
82 | 82 | msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0; |
|
83 | 83 | msgForPRC.event = 0x00; // this composite event will be sent to the PRC0 task |
|
84 | 84 | // |
|
85 | 85 | //**************************************** |
|
86 | 86 | |
|
87 | 87 | nodeForAveraging = getRingNodeForAveraging( 0 ); |
|
88 | 88 | |
|
89 | 89 | ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging; |
|
90 | 90 | for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ ) |
|
91 | 91 | { |
|
92 | 92 | nodeForAveraging = nodeForAveraging->previous; |
|
93 | 93 | ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | // compute the average and store it in the averaged_sm_f1 buffer |
|
97 | 97 | SM_average( current_ring_node_asm_norm_f0->matrix, |
|
98 | 98 | current_ring_node_asm_burst_sbm_f0->matrix, |
|
99 | 99 | ring_node_tab, |
|
100 | 100 | nb_norm_bp1, nb_sbm_bp1, |
|
101 | 101 | &msgForPRC, 0 ); // 0 => frequency channel 0 |
|
102 | 102 | |
|
103 | 103 | // update nb_average |
|
104 | 104 | nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0; |
|
105 | 105 | nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0; |
|
106 | 106 | nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0; |
|
107 | 107 | nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0; |
|
108 | 108 | nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0; |
|
109 | 109 | |
|
110 | 110 | if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1) |
|
111 | 111 | { |
|
112 | 112 | nb_sbm_bp1 = 0; |
|
113 | 113 | // set another ring for the ASM storage |
|
114 | 114 | current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next; |
|
115 | 115 | if ( lfrCurrentMode == LFR_MODE_BURST ) |
|
116 | 116 | { |
|
117 | 117 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0; |
|
118 | 118 | } |
|
119 | 119 | else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
120 | 120 | { |
|
121 | 121 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0; |
|
122 | 122 | } |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2) |
|
126 | 126 | { |
|
127 | 127 | nb_sbm_bp2 = 0; |
|
128 | 128 | if ( lfrCurrentMode == LFR_MODE_BURST ) |
|
129 | 129 | { |
|
130 | 130 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0; |
|
131 | 131 | } |
|
132 | 132 | else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
133 | 133 | { |
|
134 | 134 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0; |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1) |
|
139 | 139 | { |
|
140 | 140 | nb_norm_bp1 = 0; |
|
141 | 141 | // set another ring for the ASM storage |
|
142 | 142 | current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next; |
|
143 | 143 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
144 | 144 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
145 | 145 | { |
|
146 | 146 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0; |
|
147 | 147 | } |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2) |
|
151 | 151 | { |
|
152 | 152 | nb_norm_bp2 = 0; |
|
153 | 153 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
154 | 154 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
155 | 155 | { |
|
156 | 156 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0; |
|
157 | 157 | } |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | if (nb_norm_asm == nb_sm_before_f0.norm_asm) |
|
161 | 161 | { |
|
162 | 162 | nb_norm_asm = 0; |
|
163 | 163 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
164 | 164 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
165 | 165 | { |
|
166 | 166 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0; |
|
167 | 167 | } |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | //************************* |
|
171 | 171 | // send the message to PRC |
|
172 | 172 | if (msgForPRC.event != 0x00) |
|
173 | 173 | { |
|
174 | 174 | status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0); |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | if (status != RTEMS_SUCCESSFUL) { |
|
178 | 178 | PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status) |
|
179 | 179 | } |
|
180 | 180 | } |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | rtems_task prc0_task( rtems_task_argument lfrRequestedMode ) |
|
184 | 184 | { |
|
185 | 185 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
186 | 186 | size_t size; // size of the incoming TC packet |
|
187 | 187 | asm_msg *incomingMsg; |
|
188 | 188 | // |
|
189 | 189 | unsigned char sid; |
|
190 | 190 | rtems_status_code status; |
|
191 | 191 | rtems_id queue_id; |
|
192 | 192 | rtems_id queue_id_q_p0; |
|
193 | 193 | bp_packet_with_spare packet_norm_bp1; |
|
194 | 194 | bp_packet packet_norm_bp2; |
|
195 | 195 | bp_packet packet_sbm_bp1; |
|
196 | 196 | bp_packet packet_sbm_bp2; |
|
197 | 197 | ring_node *current_ring_node_to_send_asm_f0; |
|
198 | 198 | float nbSMInASMNORM; |
|
199 | 199 | float nbSMInASMSBM; |
|
200 | 200 | |
|
201 | 201 | // init the ring of the averaged spectral matrices which will be transmitted to the DPU |
|
202 | 202 | init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM ); |
|
203 | 203 | current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0; |
|
204 | 204 | |
|
205 | 205 | //************* |
|
206 | 206 | // NORM headers |
|
207 | 207 | BP_init_header_with_spare( &packet_norm_bp1, |
|
208 | 208 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0, |
|
209 | 209 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 ); |
|
210 | 210 | BP_init_header( &packet_norm_bp2, |
|
211 | 211 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0, |
|
212 | 212 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0); |
|
213 | 213 | |
|
214 | 214 | //**************************** |
|
215 | 215 | // BURST SBM1 and SBM2 headers |
|
216 | 216 | if ( lfrRequestedMode == LFR_MODE_BURST ) |
|
217 | 217 | { |
|
218 | 218 | BP_init_header( &packet_sbm_bp1, |
|
219 | 219 | APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0, |
|
220 | 220 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
221 | 221 | BP_init_header( &packet_sbm_bp2, |
|
222 | 222 | APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0, |
|
223 | 223 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
224 | 224 | } |
|
225 | 225 | else if ( lfrRequestedMode == LFR_MODE_SBM1 ) |
|
226 | 226 | { |
|
227 | 227 | BP_init_header( &packet_sbm_bp1, |
|
228 | 228 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0, |
|
229 | 229 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
230 | 230 | BP_init_header( &packet_sbm_bp2, |
|
231 | 231 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0, |
|
232 | 232 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
233 | 233 | } |
|
234 | 234 | else if ( lfrRequestedMode == LFR_MODE_SBM2 ) |
|
235 | 235 | { |
|
236 | 236 | BP_init_header( &packet_sbm_bp1, |
|
237 | 237 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0, |
|
238 | 238 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
239 | 239 | BP_init_header( &packet_sbm_bp2, |
|
240 | 240 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0, |
|
241 | 241 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); |
|
242 | 242 | } |
|
243 | 243 | else |
|
244 | 244 | { |
|
245 | 245 | PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | status = get_message_queue_id_send( &queue_id ); |
|
249 | 249 | if (status != RTEMS_SUCCESSFUL) |
|
250 | 250 | { |
|
251 | 251 | PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status) |
|
252 | 252 | } |
|
253 | 253 | status = get_message_queue_id_prc0( &queue_id_q_p0); |
|
254 | 254 | if (status != RTEMS_SUCCESSFUL) |
|
255 | 255 | { |
|
256 | 256 | PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status) |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) |
|
260 | 260 | |
|
261 | 261 | while(1){ |
|
262 | 262 | status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************ |
|
263 | 263 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 |
|
264 | 264 | |
|
265 | 265 | incomingMsg = (asm_msg*) incomingData; |
|
266 | 266 | |
|
267 | 267 | ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm ); |
|
268 | 268 | ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm ); |
|
269 | 269 | |
|
270 | 270 | nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; |
|
271 | 271 | nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM; |
|
272 | 272 | |
|
273 | 273 | //**************** |
|
274 | 274 | //**************** |
|
275 | 275 | // BURST SBM1 SBM2 |
|
276 | 276 | //**************** |
|
277 | 277 | //**************** |
|
278 | 278 | if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) ) |
|
279 | 279 | { |
|
280 | 280 | sid = getSID( incomingMsg->event ); |
|
281 | 281 | // 1) compress the matrix for Basic Parameters calculation |
|
282 | 282 | ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0, |
|
283 | 283 | nbSMInASMSBM, |
|
284 | 284 | NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0, |
|
285 | 285 | ASM_F0_INDICE_START, CHANNELF0); |
|
286 | 286 | // 2) compute the BP1 set |
|
287 | 287 | BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data ); |
|
288 | 288 | // 3) send the BP1 set |
|
289 | 289 | set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
290 | 290 | set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
291 | 291 | packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info; |
|
292 | 292 | packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
293 | 293 | BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id, |
|
294 | 294 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA, |
|
295 | 295 | sid); |
|
296 | 296 | // 4) compute the BP2 set if needed |
|
297 | 297 | if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) ) |
|
298 | 298 | { |
|
299 | 299 | // 1) compute the BP2 set |
|
300 | 300 | BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data ); |
|
301 | 301 | // 2) send the BP2 set |
|
302 | 302 | set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
303 | 303 | set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
304 | 304 | packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info; |
|
305 | 305 | packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
306 | 306 | BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id, |
|
307 | 307 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA, |
|
308 | 308 | sid); |
|
309 | 309 | } |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | //***** |
|
313 | 313 | //***** |
|
314 | 314 | // NORM |
|
315 | 315 | //***** |
|
316 | 316 | //***** |
|
317 | 317 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0) |
|
318 | 318 | { |
|
319 | 319 | // 1) compress the matrix for Basic Parameters calculation |
|
320 | 320 | ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0, |
|
321 | 321 | nbSMInASMNORM, |
|
322 | 322 | NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, |
|
323 | 323 | ASM_F0_INDICE_START, CHANNELF0 ); |
|
324 | 324 | // 2) compute the BP1 set |
|
325 | 325 | BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data ); |
|
326 | 326 | // 3) send the BP1 set |
|
327 | 327 | set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
328 | 328 | set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
329 | 329 | packet_norm_bp1.pa_bia_status_info = pa_bia_status_info; |
|
330 | 330 | packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
331 | 331 | BP_send( (char *) &packet_norm_bp1, queue_id, |
|
332 | 332 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA, |
|
333 | 333 | SID_NORM_BP1_F0 ); |
|
334 | 334 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0) |
|
335 | 335 | { |
|
336 | 336 | // 1) compute the BP2 set using the same ASM as the one used for BP1 |
|
337 | 337 | BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data ); |
|
338 | 338 | // 2) send the BP2 set |
|
339 | 339 | set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
340 | 340 | set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
341 | 341 | packet_norm_bp2.pa_bia_status_info = pa_bia_status_info; |
|
342 | 342 | packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
343 | 343 | BP_send( (char *) &packet_norm_bp2, queue_id, |
|
344 | 344 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA, |
|
345 | 345 | SID_NORM_BP2_F0); |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0) |
|
350 | 350 | { |
|
351 | 351 | // 1) reorganize the ASM and divide |
|
352 | 352 | ASM_reorganize_and_divide( asm_f0_patched_norm, |
|
353 | 353 | (float*) current_ring_node_to_send_asm_f0->buffer_address, |
|
354 | 354 | nbSMInASMNORM ); |
|
355 | 355 | current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM; |
|
356 | 356 | current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM; |
|
357 | 357 | current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0; |
|
358 | 358 | |
|
359 | 359 | // 3) send the spectral matrix packets |
|
360 | 360 | status = rtems_message_queue_send( queue_id, ¤t_ring_node_to_send_asm_f0, sizeof( ring_node* ) ); |
|
361 | ||
|
361 | 362 | // change asm ring node |
|
362 | 363 | current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next; |
|
363 | 364 | } |
|
364 | 365 | |
|
365 | 366 | update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max ); |
|
366 | 367 | |
|
367 | 368 | } |
|
368 | 369 | } |
|
369 | 370 | |
|
370 | 371 | //********** |
|
371 | 372 | // FUNCTIONS |
|
372 | 373 | |
|
373 | 374 | void reset_nb_sm_f0( unsigned char lfrMode ) |
|
374 | 375 | { |
|
375 | 376 | nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96; |
|
376 | 377 | nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96; |
|
377 | 378 | 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; |
|
378 | 379 | nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit |
|
379 | 380 | nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96; |
|
380 | 381 | nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96; |
|
381 | 382 | nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96; |
|
382 | 383 | nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96; |
|
383 | 384 | nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96; |
|
384 | 385 | |
|
385 | 386 | if (lfrMode == LFR_MODE_SBM1) |
|
386 | 387 | { |
|
387 | 388 | nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1; |
|
388 | 389 | nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2; |
|
389 | 390 | } |
|
390 | 391 | else if (lfrMode == LFR_MODE_SBM2) |
|
391 | 392 | { |
|
392 | 393 | nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1; |
|
393 | 394 | nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2; |
|
394 | 395 | } |
|
395 | 396 | else if (lfrMode == LFR_MODE_BURST) |
|
396 | 397 | { |
|
397 | 398 | nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; |
|
398 | 399 | nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; |
|
399 | 400 | } |
|
400 | 401 | else |
|
401 | 402 | { |
|
402 | 403 | nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; |
|
403 | 404 | nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; |
|
404 | 405 | } |
|
405 | 406 | } |
|
406 | 407 | |
|
407 | 408 | void init_k_coefficients_prc0( void ) |
|
408 | 409 | { |
|
409 | 410 | init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 ); |
|
410 | 411 | |
|
411 | 412 | init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0); |
|
412 | 413 | } |
|
413 | 414 |
@@ -1,396 +1,398 | |||
|
1 | 1 | /** Functions related to data processing. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "avf1_prc1.h" |
|
11 | 11 | |
|
12 | 12 | nb_sm_before_bp_asm_f1 nb_sm_before_f1; |
|
13 | 13 | |
|
14 | 14 | extern ring_node sm_ring_f1[ ]; |
|
15 | 15 | |
|
16 | 16 | //*** |
|
17 | 17 | // F1 |
|
18 | 18 | ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ]; |
|
19 | 19 | ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ]; |
|
20 | 20 | |
|
21 | 21 | ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ]; |
|
22 | 22 | int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ]; |
|
23 | 23 | |
|
24 | 24 | float asm_f1_patched_norm [ TOTAL_SIZE_SM ]; |
|
25 | 25 | float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ]; |
|
26 | 26 | float asm_f1_reorganized [ TOTAL_SIZE_SM ]; |
|
27 | 27 | |
|
28 | 28 | char asm_f1_char [ TOTAL_SIZE_SM * 2 ]; |
|
29 | 29 | float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1]; |
|
30 | 30 | float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ]; |
|
31 | 31 | |
|
32 | 32 | float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416 |
|
33 | 33 | float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832 |
|
34 | 34 | |
|
35 | 35 | //************ |
|
36 | 36 | // RTEMS TASKS |
|
37 | 37 | |
|
38 | 38 | rtems_task avf1_task( rtems_task_argument lfrRequestedMode ) |
|
39 | 39 | { |
|
40 | 40 | int i; |
|
41 | 41 | |
|
42 | 42 | rtems_event_set event_out; |
|
43 | 43 | rtems_status_code status; |
|
44 | 44 | rtems_id queue_id_prc1; |
|
45 | 45 | asm_msg msgForPRC; |
|
46 | 46 | ring_node *nodeForAveraging; |
|
47 | 47 | ring_node *ring_node_tab[NB_SM_BEFORE_AVF0]; |
|
48 | 48 | ring_node_asm *current_ring_node_asm_burst_sbm_f1; |
|
49 | 49 | ring_node_asm *current_ring_node_asm_norm_f1; |
|
50 | 50 | |
|
51 | 51 | unsigned int nb_norm_bp1; |
|
52 | 52 | unsigned int nb_norm_bp2; |
|
53 | 53 | unsigned int nb_norm_asm; |
|
54 | 54 | unsigned int nb_sbm_bp1; |
|
55 | 55 | unsigned int nb_sbm_bp2; |
|
56 | 56 | |
|
57 | 57 | nb_norm_bp1 = 0; |
|
58 | 58 | nb_norm_bp2 = 0; |
|
59 | 59 | nb_norm_asm = 0; |
|
60 | 60 | nb_sbm_bp1 = 0; |
|
61 | 61 | nb_sbm_bp2 = 0; |
|
62 | 62 | |
|
63 | 63 | reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions |
|
64 | 64 | ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 ); |
|
65 | 65 | ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 ); |
|
66 | 66 | current_ring_node_asm_norm_f1 = asm_ring_norm_f1; |
|
67 | 67 | current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1; |
|
68 | 68 | |
|
69 | 69 | BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) |
|
70 | 70 | |
|
71 | 71 | status = get_message_queue_id_prc1( &queue_id_prc1 ); |
|
72 | 72 | if (status != RTEMS_SUCCESSFUL) |
|
73 | 73 | { |
|
74 | 74 | PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status) |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | while(1){ |
|
78 | 78 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
79 | 79 | |
|
80 | 80 | //**************************************** |
|
81 | 81 | // initialize the mesage for the MATR task |
|
82 | 82 | msgForPRC.norm = current_ring_node_asm_norm_f1; |
|
83 | 83 | msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1; |
|
84 | 84 | msgForPRC.event = 0x00; // this composite event will be sent to the PRC1 task |
|
85 | 85 | // |
|
86 | 86 | //**************************************** |
|
87 | 87 | |
|
88 | 88 | nodeForAveraging = getRingNodeForAveraging( 1 ); |
|
89 | 89 | |
|
90 | 90 | ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging; |
|
91 | 91 | for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ ) |
|
92 | 92 | { |
|
93 | 93 | nodeForAveraging = nodeForAveraging->previous; |
|
94 | 94 | ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging; |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | // compute the average and store it in the averaged_sm_f1 buffer |
|
98 | 98 | SM_average( current_ring_node_asm_norm_f1->matrix, |
|
99 | 99 | current_ring_node_asm_burst_sbm_f1->matrix, |
|
100 | 100 | ring_node_tab, |
|
101 | 101 | nb_norm_bp1, nb_sbm_bp1, |
|
102 | 102 | &msgForPRC, 1 ); // 1 => frequency channel 1 |
|
103 | 103 | |
|
104 | 104 | // update nb_average |
|
105 | 105 | nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1; |
|
106 | 106 | nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1; |
|
107 | 107 | nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1; |
|
108 | 108 | nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1; |
|
109 | 109 | nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1; |
|
110 | 110 | |
|
111 | 111 | if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1) |
|
112 | 112 | { |
|
113 | 113 | nb_sbm_bp1 = 0; |
|
114 | 114 | // set another ring for the ASM storage |
|
115 | 115 | current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next; |
|
116 | 116 | if ( lfrCurrentMode == LFR_MODE_BURST ) |
|
117 | 117 | { |
|
118 | 118 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1; |
|
119 | 119 | } |
|
120 | 120 | else if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
121 | 121 | { |
|
122 | 122 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1; |
|
123 | 123 | } |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2) |
|
127 | 127 | { |
|
128 | 128 | nb_sbm_bp2 = 0; |
|
129 | 129 | if ( lfrCurrentMode == LFR_MODE_BURST ) |
|
130 | 130 | { |
|
131 | 131 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1; |
|
132 | 132 | } |
|
133 | 133 | else if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
134 | 134 | { |
|
135 | 135 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1; |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1) |
|
140 | 140 | { |
|
141 | 141 | nb_norm_bp1 = 0; |
|
142 | 142 | // set another ring for the ASM storage |
|
143 | 143 | current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next; |
|
144 | 144 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
145 | 145 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
146 | 146 | { |
|
147 | 147 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1; |
|
148 | 148 | } |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2) |
|
152 | 152 | { |
|
153 | 153 | nb_norm_bp2 = 0; |
|
154 | 154 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
155 | 155 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
156 | 156 | { |
|
157 | 157 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1; |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | if (nb_norm_asm == nb_sm_before_f1.norm_asm) |
|
162 | 162 | { |
|
163 | 163 | nb_norm_asm = 0; |
|
164 | 164 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
165 | 165 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
166 | 166 | { |
|
167 | 167 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1; |
|
168 | 168 | } |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | //************************* |
|
172 | 172 | // send the message to PRC |
|
173 | 173 | if (msgForPRC.event != 0x00) |
|
174 | 174 | { |
|
175 | 175 | status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | if (status != RTEMS_SUCCESSFUL) { |
|
179 | 179 | PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status) |
|
180 | 180 | } |
|
181 | 181 | } |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | rtems_task prc1_task( rtems_task_argument lfrRequestedMode ) |
|
185 | 185 | { |
|
186 | 186 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
187 | 187 | size_t size; // size of the incoming TC packet |
|
188 | 188 | asm_msg *incomingMsg; |
|
189 | 189 | // |
|
190 | 190 | unsigned char sid; |
|
191 | 191 | rtems_status_code status; |
|
192 | 192 | rtems_id queue_id_send; |
|
193 | 193 | rtems_id queue_id_q_p1; |
|
194 | 194 | bp_packet_with_spare packet_norm_bp1; |
|
195 | 195 | bp_packet packet_norm_bp2; |
|
196 | 196 | bp_packet packet_sbm_bp1; |
|
197 | 197 | bp_packet packet_sbm_bp2; |
|
198 | 198 | ring_node *current_ring_node_to_send_asm_f1; |
|
199 | 199 | float nbSMInASMNORM; |
|
200 | 200 | float nbSMInASMSBM; |
|
201 | 201 | |
|
202 | 202 | // init the ring of the averaged spectral matrices which will be transmitted to the DPU |
|
203 | 203 | init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM ); |
|
204 | 204 | current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1; |
|
205 | 205 | |
|
206 | 206 | //************* |
|
207 | 207 | // NORM headers |
|
208 | 208 | BP_init_header_with_spare( &packet_norm_bp1, |
|
209 | 209 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1, |
|
210 | 210 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 ); |
|
211 | 211 | BP_init_header( &packet_norm_bp2, |
|
212 | 212 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1, |
|
213 | 213 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1); |
|
214 | 214 | |
|
215 | 215 | //*********************** |
|
216 | 216 | // BURST and SBM2 headers |
|
217 | 217 | if ( lfrRequestedMode == LFR_MODE_BURST ) |
|
218 | 218 | { |
|
219 | 219 | BP_init_header( &packet_sbm_bp1, |
|
220 | 220 | APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1, |
|
221 | 221 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); |
|
222 | 222 | BP_init_header( &packet_sbm_bp2, |
|
223 | 223 | APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1, |
|
224 | 224 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); |
|
225 | 225 | } |
|
226 | 226 | else if ( lfrRequestedMode == LFR_MODE_SBM2 ) |
|
227 | 227 | { |
|
228 | 228 | BP_init_header( &packet_sbm_bp1, |
|
229 | 229 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1, |
|
230 | 230 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); |
|
231 | 231 | BP_init_header( &packet_sbm_bp2, |
|
232 | 232 | APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1, |
|
233 | 233 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); |
|
234 | 234 | } |
|
235 | 235 | else |
|
236 | 236 | { |
|
237 | 237 | PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | status = get_message_queue_id_send( &queue_id_send ); |
|
241 | 241 | if (status != RTEMS_SUCCESSFUL) |
|
242 | 242 | { |
|
243 | 243 | PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status) |
|
244 | 244 | } |
|
245 | 245 | status = get_message_queue_id_prc1( &queue_id_q_p1); |
|
246 | 246 | if (status != RTEMS_SUCCESSFUL) |
|
247 | 247 | { |
|
248 | 248 | PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status) |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) |
|
252 | 252 | |
|
253 | 253 | while(1){ |
|
254 | 254 | status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************ |
|
255 | 255 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 |
|
256 | 256 | |
|
257 | 257 | incomingMsg = (asm_msg*) incomingData; |
|
258 | 258 | |
|
259 | 259 | ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm ); |
|
260 | 260 | ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm ); |
|
261 | 261 | |
|
262 | 262 | nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; |
|
263 | 263 | nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM; |
|
264 | 264 | |
|
265 | 265 | //*********** |
|
266 | 266 | //*********** |
|
267 | 267 | // BURST SBM2 |
|
268 | 268 | //*********** |
|
269 | 269 | //*********** |
|
270 | 270 | if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) ) |
|
271 | 271 | { |
|
272 | 272 | sid = getSID( incomingMsg->event ); |
|
273 | 273 | // 1) compress the matrix for Basic Parameters calculation |
|
274 | 274 | ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1, |
|
275 | 275 | nbSMInASMSBM, |
|
276 | 276 | NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1, |
|
277 | 277 | ASM_F1_INDICE_START, CHANNELF1); |
|
278 | 278 | // 2) compute the BP1 set |
|
279 | 279 | BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data ); |
|
280 | 280 | // 3) send the BP1 set |
|
281 | 281 | set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
282 | 282 | set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
283 | 283 | packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info; |
|
284 | 284 | packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
285 | 285 | BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send, |
|
286 | 286 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA, |
|
287 | 287 | sid ); |
|
288 | 288 | // 4) compute the BP2 set if needed |
|
289 | 289 | if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) ) |
|
290 | 290 | { |
|
291 | 291 | // 1) compute the BP2 set |
|
292 | 292 | BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data ); |
|
293 | 293 | // 2) send the BP2 set |
|
294 | 294 | set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
295 | 295 | set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM ); |
|
296 | 296 | packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info; |
|
297 | 297 | packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
298 | 298 | BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send, |
|
299 | 299 | PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA, |
|
300 | 300 | sid ); |
|
301 | 301 | } |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | //***** |
|
305 | 305 | //***** |
|
306 | 306 | // NORM |
|
307 | 307 | //***** |
|
308 | 308 | //***** |
|
309 | 309 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1) |
|
310 | 310 | { |
|
311 | 311 | // 1) compress the matrix for Basic Parameters calculation |
|
312 | 312 | ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1, |
|
313 | 313 | nbSMInASMNORM, |
|
314 | 314 | NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1, |
|
315 | 315 | ASM_F1_INDICE_START, CHANNELF1 ); |
|
316 | 316 | // 2) compute the BP1 set |
|
317 | 317 | BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data ); |
|
318 | 318 | // 3) send the BP1 set |
|
319 | 319 | set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
320 | 320 | set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
321 | 321 | packet_norm_bp1.pa_bia_status_info = pa_bia_status_info; |
|
322 | 322 | packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
323 | 323 | BP_send( (char *) &packet_norm_bp1, queue_id_send, |
|
324 | 324 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA, |
|
325 | 325 | SID_NORM_BP1_F1 ); |
|
326 | 326 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1) |
|
327 | 327 | { |
|
328 | 328 | // 1) compute the BP2 set |
|
329 | 329 | BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data ); |
|
330 | 330 | // 2) send the BP2 set |
|
331 | 331 | set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
332 | 332 | set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
333 | 333 | packet_norm_bp2.pa_bia_status_info = pa_bia_status_info; |
|
334 | 334 | packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
335 | 335 | BP_send( (char *) &packet_norm_bp2, queue_id_send, |
|
336 | 336 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA, |
|
337 | 337 | SID_NORM_BP2_F1 ); |
|
338 | 338 | } |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1) |
|
342 | 342 | { |
|
343 | 343 | // 1) reorganize the ASM and divide |
|
344 | 344 | ASM_reorganize_and_divide( asm_f1_patched_norm, |
|
345 | 345 | (float*) current_ring_node_to_send_asm_f1->buffer_address, |
|
346 | 346 | nbSMInASMNORM ); |
|
347 | 347 | current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM; |
|
348 | 348 | current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM; |
|
349 | 349 | current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1; |
|
350 | ||
|
350 | 351 | // 3) send the spectral matrix packets |
|
351 | 352 | status = rtems_message_queue_send( queue_id_send, ¤t_ring_node_to_send_asm_f1, sizeof( ring_node* ) ); |
|
353 | ||
|
352 | 354 | // change asm ring node |
|
353 | 355 | current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next; |
|
354 | 356 | } |
|
355 | 357 | |
|
356 | 358 | update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max ); |
|
357 | 359 | |
|
358 | 360 | } |
|
359 | 361 | } |
|
360 | 362 | |
|
361 | 363 | //********** |
|
362 | 364 | // FUNCTIONS |
|
363 | 365 | |
|
364 | 366 | void reset_nb_sm_f1( unsigned char lfrMode ) |
|
365 | 367 | { |
|
366 | 368 | nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16; |
|
367 | 369 | nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16; |
|
368 | 370 | 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; |
|
369 | 371 | nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16; |
|
370 | 372 | nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16; |
|
371 | 373 | nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16; |
|
372 | 374 | nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16; |
|
373 | 375 | |
|
374 | 376 | if (lfrMode == LFR_MODE_SBM2) |
|
375 | 377 | { |
|
376 | 378 | nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1; |
|
377 | 379 | nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2; |
|
378 | 380 | } |
|
379 | 381 | else if (lfrMode == LFR_MODE_BURST) |
|
380 | 382 | { |
|
381 | 383 | nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; |
|
382 | 384 | nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; |
|
383 | 385 | } |
|
384 | 386 | else |
|
385 | 387 | { |
|
386 | 388 | nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; |
|
387 | 389 | nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; |
|
388 | 390 | } |
|
389 | 391 | } |
|
390 | 392 | |
|
391 | 393 | void init_k_coefficients_prc1( void ) |
|
392 | 394 | { |
|
393 | 395 | init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 ); |
|
394 | 396 | |
|
395 | 397 | init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1); |
|
396 | 398 | } |
@@ -1,325 +1,327 | |||
|
1 | 1 | /** Functions related to data processing. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "avf2_prc2.h" |
|
11 | 11 | |
|
12 | 12 | nb_sm_before_bp_asm_f2 nb_sm_before_f2; |
|
13 | 13 | |
|
14 | 14 | extern ring_node sm_ring_f2[ ]; |
|
15 | 15 | |
|
16 | 16 | //*** |
|
17 | 17 | // F2 |
|
18 | 18 | ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ]; |
|
19 | 19 | |
|
20 | 20 | ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ]; |
|
21 | 21 | int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ]; |
|
22 | 22 | |
|
23 | 23 | float asm_f2_patched_norm [ TOTAL_SIZE_SM ]; |
|
24 | 24 | float asm_f2_reorganized [ TOTAL_SIZE_SM ]; |
|
25 | 25 | |
|
26 | 26 | char asm_f2_char [ TOTAL_SIZE_SM * 2 ]; |
|
27 | 27 | float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2]; |
|
28 | 28 | |
|
29 | 29 | float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384 |
|
30 | 30 | |
|
31 | 31 | //************ |
|
32 | 32 | // RTEMS TASKS |
|
33 | 33 | |
|
34 | 34 | //*** |
|
35 | 35 | // F2 |
|
36 | 36 | rtems_task avf2_task( rtems_task_argument argument ) |
|
37 | 37 | { |
|
38 | 38 | rtems_event_set event_out; |
|
39 | 39 | rtems_status_code status; |
|
40 | 40 | rtems_id queue_id_prc2; |
|
41 | 41 | asm_msg msgForPRC; |
|
42 | 42 | ring_node *nodeForAveraging; |
|
43 | 43 | ring_node_asm *current_ring_node_asm_norm_f2; |
|
44 | 44 | |
|
45 | 45 | unsigned int nb_norm_bp1; |
|
46 | 46 | unsigned int nb_norm_bp2; |
|
47 | 47 | unsigned int nb_norm_asm; |
|
48 | 48 | |
|
49 | 49 | nb_norm_bp1 = 0; |
|
50 | 50 | nb_norm_bp2 = 0; |
|
51 | 51 | nb_norm_asm = 0; |
|
52 | 52 | |
|
53 | 53 | reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions |
|
54 | 54 | ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 ); |
|
55 | 55 | current_ring_node_asm_norm_f2 = asm_ring_norm_f2; |
|
56 | 56 | |
|
57 | 57 | BOOT_PRINTF("in AVF2 ***\n") |
|
58 | 58 | |
|
59 | 59 | status = get_message_queue_id_prc2( &queue_id_prc2 ); |
|
60 | 60 | if (status != RTEMS_SUCCESSFUL) |
|
61 | 61 | { |
|
62 | 62 | PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status) |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | while(1){ |
|
66 | 66 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
67 | 67 | |
|
68 | 68 | //**************************************** |
|
69 | 69 | // initialize the mesage for the MATR task |
|
70 | 70 | msgForPRC.norm = current_ring_node_asm_norm_f2; |
|
71 | 71 | msgForPRC.burst_sbm = NULL; |
|
72 | 72 | msgForPRC.event = 0x00; // this composite event will be sent to the PRC2 task |
|
73 | 73 | // |
|
74 | 74 | //**************************************** |
|
75 | 75 | |
|
76 | 76 | nodeForAveraging = getRingNodeForAveraging( 2 ); |
|
77 | 77 | |
|
78 | 78 | // compute the average and store it in the averaged_sm_f2 buffer |
|
79 | 79 | SM_average_f2( current_ring_node_asm_norm_f2->matrix, |
|
80 | 80 | nodeForAveraging, |
|
81 | 81 | nb_norm_bp1, |
|
82 | 82 | &msgForPRC ); |
|
83 | 83 | |
|
84 | 84 | // update nb_average |
|
85 | 85 | nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2; |
|
86 | 86 | nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2; |
|
87 | 87 | nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2; |
|
88 | 88 | |
|
89 | 89 | if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1) |
|
90 | 90 | { |
|
91 | 91 | nb_norm_bp1 = 0; |
|
92 | 92 | // set another ring for the ASM storage |
|
93 | 93 | current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next; |
|
94 | 94 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) |
|
95 | 95 | || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
96 | 96 | { |
|
97 | 97 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2; |
|
98 | 98 | } |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2) |
|
102 | 102 | { |
|
103 | 103 | nb_norm_bp2 = 0; |
|
104 | 104 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) |
|
105 | 105 | || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
106 | 106 | { |
|
107 | 107 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2; |
|
108 | 108 | } |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | if (nb_norm_asm == nb_sm_before_f2.norm_asm) |
|
112 | 112 | { |
|
113 | 113 | nb_norm_asm = 0; |
|
114 | 114 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) |
|
115 | 115 | || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
116 | 116 | { |
|
117 | 117 | msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2; |
|
118 | 118 | } |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | //************************* |
|
122 | 122 | // send the message to PRC2 |
|
123 | 123 | if (msgForPRC.event != 0x00) |
|
124 | 124 | { |
|
125 | 125 | status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2); |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | if (status != RTEMS_SUCCESSFUL) { |
|
129 | 129 | PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status) |
|
130 | 130 | } |
|
131 | 131 | } |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | rtems_task prc2_task( rtems_task_argument argument ) |
|
135 | 135 | { |
|
136 | 136 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
137 | 137 | size_t size; // size of the incoming TC packet |
|
138 | 138 | asm_msg *incomingMsg; |
|
139 | 139 | // |
|
140 | 140 | rtems_status_code status; |
|
141 | 141 | rtems_id queue_id_send; |
|
142 | 142 | rtems_id queue_id_q_p2; |
|
143 | 143 | bp_packet packet_norm_bp1; |
|
144 | 144 | bp_packet packet_norm_bp2; |
|
145 | 145 | ring_node *current_ring_node_to_send_asm_f2; |
|
146 | 146 | float nbSMInASMNORM; |
|
147 | 147 | |
|
148 | 148 | unsigned long long int localTime; |
|
149 | 149 | |
|
150 | 150 | // init the ring of the averaged spectral matrices which will be transmitted to the DPU |
|
151 | 151 | init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM ); |
|
152 | 152 | current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2; |
|
153 | 153 | |
|
154 | 154 | //************* |
|
155 | 155 | // NORM headers |
|
156 | 156 | BP_init_header( &packet_norm_bp1, |
|
157 | 157 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2, |
|
158 | 158 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 ); |
|
159 | 159 | BP_init_header( &packet_norm_bp2, |
|
160 | 160 | APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2, |
|
161 | 161 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 ); |
|
162 | 162 | |
|
163 | 163 | status = get_message_queue_id_send( &queue_id_send ); |
|
164 | 164 | if (status != RTEMS_SUCCESSFUL) |
|
165 | 165 | { |
|
166 | 166 | PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status) |
|
167 | 167 | } |
|
168 | 168 | status = get_message_queue_id_prc2( &queue_id_q_p2); |
|
169 | 169 | if (status != RTEMS_SUCCESSFUL) |
|
170 | 170 | { |
|
171 | 171 | PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status) |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | BOOT_PRINTF("in PRC2 ***\n") |
|
175 | 175 | |
|
176 | 176 | while(1){ |
|
177 | 177 | status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************ |
|
178 | 178 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2 |
|
179 | 179 | |
|
180 | 180 | incomingMsg = (asm_msg*) incomingData; |
|
181 | 181 | |
|
182 | 182 | ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm ); |
|
183 | 183 | |
|
184 | 184 | localTime = getTimeAsUnsignedLongLongInt( ); |
|
185 | 185 | |
|
186 | 186 | nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; |
|
187 | 187 | |
|
188 | 188 | //***** |
|
189 | 189 | //***** |
|
190 | 190 | // NORM |
|
191 | 191 | //***** |
|
192 | 192 | //***** |
|
193 | 193 | // 1) compress the matrix for Basic Parameters calculation |
|
194 | 194 | ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2, |
|
195 | 195 | nbSMInASMNORM, |
|
196 | 196 | NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, |
|
197 | 197 | ASM_F2_INDICE_START, CHANNELF2 ); |
|
198 | 198 | // BP1_F2 |
|
199 | 199 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2) |
|
200 | 200 | { |
|
201 | 201 | // 1) compute the BP1 set |
|
202 | 202 | BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data ); |
|
203 | 203 | // 2) send the BP1 set |
|
204 | 204 | set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
205 | 205 | set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
206 | 206 | packet_norm_bp1.pa_bia_status_info = pa_bia_status_info; |
|
207 | 207 | packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
208 | 208 | BP_send( (char *) &packet_norm_bp1, queue_id_send, |
|
209 | 209 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA, |
|
210 | 210 | SID_NORM_BP1_F2 ); |
|
211 | 211 | } |
|
212 | 212 | // BP2_F2 |
|
213 | 213 | if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2) |
|
214 | 214 | { |
|
215 | 215 | // 1) compute the BP2 set |
|
216 | 216 | BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data ); |
|
217 | 217 | // 2) send the BP2 set |
|
218 | 218 | set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
219 | 219 | set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM ); |
|
220 | 220 | packet_norm_bp2.pa_bia_status_info = pa_bia_status_info; |
|
221 | 221 | packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
222 | 222 | BP_send( (char *) &packet_norm_bp2, queue_id_send, |
|
223 | 223 | PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA, |
|
224 | 224 | SID_NORM_BP2_F2 ); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2) |
|
228 | 228 | { |
|
229 | 229 | // 1) reorganize the ASM and divide |
|
230 | 230 | ASM_reorganize_and_divide( asm_f2_patched_norm, |
|
231 | 231 | (float*) current_ring_node_to_send_asm_f2->buffer_address, |
|
232 | 232 | nb_sm_before_f2.norm_bp1 ); |
|
233 | 233 | current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM; |
|
234 | 234 | current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM; |
|
235 | 235 | current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2; |
|
236 | ||
|
236 | 237 | // 3) send the spectral matrix packets |
|
237 | 238 | status = rtems_message_queue_send( queue_id_send, ¤t_ring_node_to_send_asm_f2, sizeof( ring_node* ) ); |
|
239 | ||
|
238 | 240 | // change asm ring node |
|
239 | 241 | current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next; |
|
240 | 242 | } |
|
241 | 243 | |
|
242 | 244 | update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max ); |
|
243 | 245 | |
|
244 | 246 | } |
|
245 | 247 | } |
|
246 | 248 | |
|
247 | 249 | //********** |
|
248 | 250 | // FUNCTIONS |
|
249 | 251 | |
|
250 | 252 | void reset_nb_sm_f2( void ) |
|
251 | 253 | { |
|
252 | 254 | nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0; |
|
253 | 255 | nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1; |
|
254 | 256 | 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]; |
|
255 | 257 | } |
|
256 | 258 | |
|
257 | 259 | void SM_average_f2( float *averaged_spec_mat_f2, |
|
258 | 260 | ring_node *ring_node, |
|
259 | 261 | unsigned int nbAverageNormF2, |
|
260 | 262 | asm_msg *msgForMATR ) |
|
261 | 263 | { |
|
262 | 264 | float sum; |
|
263 | 265 | unsigned int i; |
|
264 | 266 | unsigned char keepMatrix; |
|
265 | 267 | |
|
266 | 268 | // test acquisitionTime validity |
|
267 | 269 | keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, 2 ); |
|
268 | 270 | |
|
269 | 271 | for(i=0; i<TOTAL_SIZE_SM; i++) |
|
270 | 272 | { |
|
271 | 273 | sum = ( (int *) (ring_node->buffer_address) ) [ i ]; |
|
272 | 274 | if ( (nbAverageNormF2 == 0) ) // average initialization |
|
273 | 275 | { |
|
274 | 276 | if (keepMatrix == 1) // keep the matrix and add it to the average |
|
275 | 277 | { |
|
276 | 278 | averaged_spec_mat_f2[ i ] = sum; |
|
277 | 279 | } |
|
278 | 280 | else // drop the matrix and initialize the average |
|
279 | 281 | { |
|
280 | 282 | averaged_spec_mat_f2[ i ] = 0.; |
|
281 | 283 | } |
|
282 | 284 | msgForMATR->coarseTimeNORM = ring_node->coarseTime; |
|
283 | 285 | msgForMATR->fineTimeNORM = ring_node->fineTime; |
|
284 | 286 | } |
|
285 | 287 | else |
|
286 | 288 | { |
|
287 | 289 | if (keepMatrix == 1) // keep the matrix and add it to the average |
|
288 | 290 | { |
|
289 | 291 | averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); |
|
290 | 292 | } |
|
291 | 293 | else |
|
292 | 294 | { |
|
293 | 295 | // nothing to do, the matrix is not valid |
|
294 | 296 | } |
|
295 | 297 | } |
|
296 | 298 | } |
|
297 | 299 | |
|
298 | 300 | if (keepMatrix == 1) |
|
299 | 301 | { |
|
300 | 302 | if ( (nbAverageNormF2 == 0) ) |
|
301 | 303 | { |
|
302 | 304 | msgForMATR->numberOfSMInASMNORM = 1; |
|
303 | 305 | } |
|
304 | 306 | else |
|
305 | 307 | { |
|
306 | 308 | msgForMATR->numberOfSMInASMNORM++; |
|
307 | 309 | } |
|
308 | 310 | } |
|
309 | 311 | else |
|
310 | 312 | { |
|
311 | 313 | if ( (nbAverageNormF2 == 0) ) |
|
312 | 314 | { |
|
313 | 315 | msgForMATR->numberOfSMInASMNORM = 0; |
|
314 | 316 | } |
|
315 | 317 | else |
|
316 | 318 | { |
|
317 | 319 | // nothing to do |
|
318 | 320 | } |
|
319 | 321 | } |
|
320 | 322 | } |
|
321 | 323 | |
|
322 | 324 | void init_k_coefficients_prc2( void ) |
|
323 | 325 | { |
|
324 | 326 | init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2); |
|
325 | 327 | } |
@@ -1,1310 +1,1314 | |||
|
1 | 1 | /** Functions and tasks related to waveform packet generation. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle waveforms, in snapshot or continuous format.\n |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "wf_handler.h" |
|
11 | 11 | |
|
12 | 12 | //*************** |
|
13 | 13 | // waveform rings |
|
14 | 14 | // F0 |
|
15 | 15 | ring_node waveform_ring_f0[NB_RING_NODES_F0]; |
|
16 | 16 | ring_node *current_ring_node_f0; |
|
17 | 17 | ring_node *ring_node_to_send_swf_f0; |
|
18 | 18 | // F1 |
|
19 | 19 | ring_node waveform_ring_f1[NB_RING_NODES_F1]; |
|
20 | 20 | ring_node *current_ring_node_f1; |
|
21 | 21 | ring_node *ring_node_to_send_swf_f1; |
|
22 | 22 | ring_node *ring_node_to_send_cwf_f1; |
|
23 | 23 | // F2 |
|
24 | 24 | ring_node waveform_ring_f2[NB_RING_NODES_F2]; |
|
25 | 25 | ring_node *current_ring_node_f2; |
|
26 | 26 | ring_node *ring_node_to_send_swf_f2; |
|
27 | 27 | ring_node *ring_node_to_send_cwf_f2; |
|
28 | 28 | // F3 |
|
29 | 29 | ring_node waveform_ring_f3[NB_RING_NODES_F3]; |
|
30 | 30 | ring_node *current_ring_node_f3; |
|
31 | 31 | ring_node *ring_node_to_send_cwf_f3; |
|
32 | 32 | char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ]; |
|
33 | 33 | |
|
34 | 34 | bool extractSWF1 = false; |
|
35 | 35 | bool extractSWF2 = false; |
|
36 | 36 | bool swf0_ready_flag_f1 = false; |
|
37 | 37 | bool swf0_ready_flag_f2 = false; |
|
38 | 38 | bool swf1_ready = false; |
|
39 | 39 | bool swf2_ready = false; |
|
40 | 40 | |
|
41 | 41 | int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ]; |
|
42 | 42 | int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ]; |
|
43 | 43 | ring_node ring_node_swf1_extracted; |
|
44 | 44 | ring_node ring_node_swf2_extracted; |
|
45 | 45 | |
|
46 | 46 | typedef enum resynchro_state_t |
|
47 | 47 | { |
|
48 | 48 | MEASURE, |
|
49 | 49 | CORRECTION |
|
50 | 50 | } resynchro_state; |
|
51 | 51 | |
|
52 | 52 | //********************* |
|
53 | 53 | // Interrupt SubRoutine |
|
54 | 54 | |
|
55 | 55 | ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel) |
|
56 | 56 | { |
|
57 | 57 | ring_node *node; |
|
58 | 58 | |
|
59 | 59 | node = NULL; |
|
60 | 60 | switch ( frequencyChannel ) { |
|
61 | 61 | case 1: |
|
62 | 62 | node = ring_node_to_send_cwf_f1; |
|
63 | 63 | break; |
|
64 | 64 | case 2: |
|
65 | 65 | node = ring_node_to_send_cwf_f2; |
|
66 | 66 | break; |
|
67 | 67 | case 3: |
|
68 | 68 | node = ring_node_to_send_cwf_f3; |
|
69 | 69 | break; |
|
70 | 70 | default: |
|
71 | 71 | break; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | return node; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel) |
|
78 | 78 | { |
|
79 | 79 | ring_node *node; |
|
80 | 80 | |
|
81 | 81 | node = NULL; |
|
82 | 82 | switch ( frequencyChannel ) { |
|
83 | 83 | case 0: |
|
84 | 84 | node = ring_node_to_send_swf_f0; |
|
85 | 85 | break; |
|
86 | 86 | case 1: |
|
87 | 87 | node = ring_node_to_send_swf_f1; |
|
88 | 88 | break; |
|
89 | 89 | case 2: |
|
90 | 90 | node = ring_node_to_send_swf_f2; |
|
91 | 91 | break; |
|
92 | 92 | default: |
|
93 | 93 | break; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | return node; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void reset_extractSWF( void ) |
|
100 | 100 | { |
|
101 | 101 | extractSWF1 = false; |
|
102 | 102 | extractSWF2 = false; |
|
103 | 103 | swf0_ready_flag_f1 = false; |
|
104 | 104 | swf0_ready_flag_f2 = false; |
|
105 | 105 | swf1_ready = false; |
|
106 | 106 | swf2_ready = false; |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | inline void waveforms_isr_f3( void ) |
|
110 | 110 | { |
|
111 | 111 | rtems_status_code spare_status; |
|
112 | 112 | |
|
113 | 113 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet |
|
114 | 114 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
115 | 115 | { // in modes other than STANDBY and BURST, send the CWF_F3 data |
|
116 | 116 | //*** |
|
117 | 117 | // F3 |
|
118 | 118 | if ( (waveform_picker_regs->status & 0xc0) != 0x00 ) { // [1100 0000] check the f3 full bits |
|
119 | 119 | ring_node_to_send_cwf_f3 = current_ring_node_f3->previous; |
|
120 | 120 | current_ring_node_f3 = current_ring_node_f3->next; |
|
121 | 121 | if ((waveform_picker_regs->status & 0x40) == 0x40){ // [0100 0000] f3 buffer 0 is full |
|
122 | 122 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time; |
|
123 | 123 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time; |
|
124 | 124 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address; |
|
125 | 125 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00008840; // [1000 1000 0100 0000] |
|
126 | 126 | } |
|
127 | 127 | else if ((waveform_picker_regs->status & 0x80) == 0x80){ // [1000 0000] f3 buffer 1 is full |
|
128 | 128 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time; |
|
129 | 129 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time; |
|
130 | 130 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; |
|
131 | 131 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00008880; // [1000 1000 1000 0000] |
|
132 | 132 | } |
|
133 | 133 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
134 | 134 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | inline void waveforms_isr_burst( void ) |
|
141 | 141 | { |
|
142 | 142 | unsigned char status; |
|
143 | 143 | rtems_status_code spare_status; |
|
144 | 144 | |
|
145 | 145 | status = (waveform_picker_regs->status & 0x30) >> 4; // [0011 0000] get the status bits for f2 |
|
146 | 146 | |
|
147 | 147 | |
|
148 | 148 | switch(status) |
|
149 | 149 | { |
|
150 | 150 | case 1: |
|
151 | 151 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
152 | 152 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
153 | 153 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
154 | 154 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
155 | 155 | current_ring_node_f2 = current_ring_node_f2->next; |
|
156 | 156 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
157 | 157 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
158 | 158 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
159 | 159 | } |
|
160 | 160 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000] |
|
161 | 161 | break; |
|
162 | 162 | case 2: |
|
163 | 163 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
164 | 164 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
165 | 165 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
166 | 166 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
167 | 167 | current_ring_node_f2 = current_ring_node_f2->next; |
|
168 | 168 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
169 | 169 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
170 | 170 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
171 | 171 | } |
|
172 | 172 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000] |
|
173 | 173 | break; |
|
174 | 174 | default: |
|
175 | 175 | break; |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | inline void waveform_isr_normal_sbm1_sbm2( void ) |
|
180 | 180 | { |
|
181 | 181 | rtems_status_code status; |
|
182 | 182 | |
|
183 | 183 | //*** |
|
184 | 184 | // F0 |
|
185 | 185 | if ( (waveform_picker_regs->status & 0x03) != 0x00 ) // [0000 0011] check the f0 full bits |
|
186 | 186 | { |
|
187 | 187 | swf0_ready_flag_f1 = true; |
|
188 | 188 | swf0_ready_flag_f2 = true; |
|
189 | 189 | ring_node_to_send_swf_f0 = current_ring_node_f0->previous; |
|
190 | 190 | current_ring_node_f0 = current_ring_node_f0->next; |
|
191 | 191 | if ( (waveform_picker_regs->status & 0x01) == 0x01) |
|
192 | 192 | { |
|
193 | 193 | |
|
194 | 194 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time; |
|
195 | 195 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time; |
|
196 | 196 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address; |
|
197 | 197 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001] |
|
198 | 198 | } |
|
199 | 199 | else if ( (waveform_picker_regs->status & 0x02) == 0x02) |
|
200 | 200 | { |
|
201 | 201 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time; |
|
202 | 202 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time; |
|
203 | 203 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; |
|
204 | 204 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010] |
|
205 | 205 | } |
|
206 | 206 | // send an event to the WFRM task for resynchro activities |
|
207 | 207 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH ); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | //*** |
|
211 | 211 | // F1 |
|
212 | 212 | if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bits |
|
213 | 213 | // (1) change the receiving buffer for the waveform picker |
|
214 | 214 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; |
|
215 | 215 | current_ring_node_f1 = current_ring_node_f1->next; |
|
216 | 216 | if ( (waveform_picker_regs->status & 0x04) == 0x04) |
|
217 | 217 | { |
|
218 | 218 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time; |
|
219 | 219 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time; |
|
220 | 220 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address; |
|
221 | 221 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0 |
|
222 | 222 | } |
|
223 | 223 | else if ( (waveform_picker_regs->status & 0x08) == 0x08) |
|
224 | 224 | { |
|
225 | 225 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time; |
|
226 | 226 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time; |
|
227 | 227 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; |
|
228 | 228 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0 |
|
229 | 229 | } |
|
230 | 230 | // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) |
|
231 | 231 | status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | //*** |
|
235 | 235 | // F2 |
|
236 | 236 | if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bit |
|
237 | 237 | // (1) change the receiving buffer for the waveform picker |
|
238 | 238 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
239 | 239 | ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; |
|
240 | 240 | current_ring_node_f2 = current_ring_node_f2->next; |
|
241 | 241 | if ( (waveform_picker_regs->status & 0x10) == 0x10) |
|
242 | 242 | { |
|
243 | 243 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
244 | 244 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
245 | 245 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
246 | 246 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000] |
|
247 | 247 | } |
|
248 | 248 | else if ( (waveform_picker_regs->status & 0x20) == 0x20) |
|
249 | 249 | { |
|
250 | 250 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
251 | 251 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
252 | 252 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
253 | 253 | waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000] |
|
254 | 254 | } |
|
255 | 255 | // (2) send an event for the waveforms transmission |
|
256 | 256 | status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
257 | 257 | } |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | rtems_isr waveforms_isr( rtems_vector_number vector ) |
|
261 | 261 | { |
|
262 | 262 | /** This is the interrupt sub routine called by the waveform picker core. |
|
263 | 263 | * |
|
264 | 264 | * This ISR launch different actions depending mainly on two pieces of information: |
|
265 | 265 | * 1. the values read in the registers of the waveform picker. |
|
266 | 266 | * 2. the current LFR mode. |
|
267 | 267 | * |
|
268 | 268 | */ |
|
269 | 269 | |
|
270 | 270 | // STATUS |
|
271 | 271 | // new error error buffer full |
|
272 | 272 | // 15 14 13 12 11 10 9 8 |
|
273 | 273 | // f3 f2 f1 f0 f3 f2 f1 f0 |
|
274 | 274 | // |
|
275 | 275 | // ready buffer |
|
276 | 276 | // 7 6 5 4 3 2 1 0 |
|
277 | 277 | // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0 |
|
278 | 278 | |
|
279 | 279 | rtems_status_code spare_status; |
|
280 | 280 | |
|
281 | 281 | waveforms_isr_f3(); |
|
282 | 282 | |
|
283 | 283 | //************************************************* |
|
284 | 284 | // copy the status bits in the housekeeping packets |
|
285 | 285 | housekeeping_packet.hk_lfr_vhdl_iir_cal = |
|
286 | 286 | (unsigned char) ((waveform_picker_regs->status & 0xff00) >> 8); |
|
287 | 287 | |
|
288 | 288 | if ( (waveform_picker_regs->status & 0xff00) != 0x00) // [1111 1111 0000 0000] check the error bits |
|
289 | 289 | { |
|
290 | 290 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 ); |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | switch(lfrCurrentMode) |
|
294 | 294 | { |
|
295 | 295 | //******** |
|
296 | 296 | // STANDBY |
|
297 | 297 | case LFR_MODE_STANDBY: |
|
298 | 298 | break; |
|
299 | 299 | //************************** |
|
300 | 300 | // LFR NORMAL, SBM1 and SBM2 |
|
301 | 301 | case LFR_MODE_NORMAL: |
|
302 | 302 | case LFR_MODE_SBM1: |
|
303 | 303 | case LFR_MODE_SBM2: |
|
304 | 304 | waveform_isr_normal_sbm1_sbm2(); |
|
305 | 305 | break; |
|
306 | 306 | //****** |
|
307 | 307 | // BURST |
|
308 | 308 | case LFR_MODE_BURST: |
|
309 | 309 | waveforms_isr_burst(); |
|
310 | 310 | break; |
|
311 | 311 | //******** |
|
312 | 312 | // DEFAULT |
|
313 | 313 | default: |
|
314 | 314 | break; |
|
315 | 315 | } |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | //************ |
|
319 | 319 | // RTEMS TASKS |
|
320 | 320 | |
|
321 | 321 | rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
322 | 322 | { |
|
323 | 323 | /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. |
|
324 | 324 | * |
|
325 | 325 | * @param unused is the starting argument of the RTEMS task |
|
326 | 326 | * |
|
327 | 327 | * The following data packets are sent by this task: |
|
328 | 328 | * - TM_LFR_SCIENCE_NORMAL_SWF_F0 |
|
329 | 329 | * - TM_LFR_SCIENCE_NORMAL_SWF_F1 |
|
330 | 330 | * - TM_LFR_SCIENCE_NORMAL_SWF_F2 |
|
331 | 331 | * |
|
332 | 332 | */ |
|
333 | 333 | |
|
334 | 334 | rtems_event_set event_out; |
|
335 | 335 | rtems_id queue_id; |
|
336 | 336 | rtems_status_code status; |
|
337 | 337 | ring_node *ring_node_swf1_extracted_ptr; |
|
338 | 338 | ring_node *ring_node_swf2_extracted_ptr; |
|
339 | 339 | |
|
340 | 340 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; |
|
341 | 341 | ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; |
|
342 | 342 | |
|
343 | 343 | status = get_message_queue_id_send( &queue_id ); |
|
344 | 344 | if (status != RTEMS_SUCCESSFUL) |
|
345 | 345 | { |
|
346 | 346 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | BOOT_PRINTF("in WFRM ***\n"); |
|
350 | 350 | |
|
351 | 351 | while(1){ |
|
352 | 352 | // wait for an RTEMS_EVENT |
|
353 | 353 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, |
|
354 | 354 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
355 | 355 | |
|
356 | 356 | if (event_out == RTEMS_EVENT_MODE_NORMAL) |
|
357 | 357 | { |
|
358 | 358 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); |
|
359 | 359 | ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; |
|
360 | 360 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; |
|
361 | 361 | ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; |
|
362 | 362 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); |
|
363 | 363 | status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); |
|
364 | 364 | status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); |
|
365 | 365 | } |
|
366 | 366 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) |
|
367 | 367 | { |
|
368 | 368 | snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
369 | 369 | } |
|
370 | 370 | } |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
374 | 374 | { |
|
375 | 375 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. |
|
376 | 376 | * |
|
377 | 377 | * @param unused is the starting argument of the RTEMS task |
|
378 | 378 | * |
|
379 | 379 | * The following data packet is sent by this task: |
|
380 | 380 | * - TM_LFR_SCIENCE_NORMAL_CWF_F3 |
|
381 | 381 | * |
|
382 | 382 | */ |
|
383 | 383 | |
|
384 | 384 | rtems_event_set event_out; |
|
385 | 385 | rtems_id queue_id; |
|
386 | 386 | rtems_status_code status; |
|
387 | 387 | ring_node ring_node_cwf3_light; |
|
388 | 388 | ring_node *ring_node_to_send_cwf; |
|
389 | 389 | |
|
390 | 390 | status = get_message_queue_id_send( &queue_id ); |
|
391 | 391 | if (status != RTEMS_SUCCESSFUL) |
|
392 | 392 | { |
|
393 | 393 | PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
397 | 397 | |
|
398 | 398 | // init the ring_node_cwf3_light structure |
|
399 | 399 | ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; |
|
400 | 400 | ring_node_cwf3_light.coarseTime = 0x00; |
|
401 | 401 | ring_node_cwf3_light.fineTime = 0x00; |
|
402 | 402 | ring_node_cwf3_light.next = NULL; |
|
403 | 403 | ring_node_cwf3_light.previous = NULL; |
|
404 | 404 | ring_node_cwf3_light.sid = SID_NORM_CWF_F3; |
|
405 | 405 | ring_node_cwf3_light.status = 0x00; |
|
406 | 406 | |
|
407 | BOOT_PRINTF("in CWF3 ***\n") | |
|
407 | BOOT_PRINTF("in CWF3 ***\n"); | |
|
408 | 408 | |
|
409 |
|
|
|
409 | while(1){ | |
|
410 | 410 | // wait for an RTEMS_EVENT |
|
411 | 411 | rtems_event_receive( RTEMS_EVENT_0, |
|
412 | 412 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
413 | 413 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
414 | 414 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) |
|
415 | 415 | { |
|
416 | 416 | ring_node_to_send_cwf = getRingNodeToSendCWF( 3 ); |
|
417 | 417 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01) |
|
418 | 418 | { |
|
419 | PRINTF("send CWF_LONG_F3\n") | |
|
420 |
|
|
|
419 | PRINTF("send CWF_LONG_F3\n"); | |
|
420 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; | |
|
421 | 421 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
422 | 422 | } |
|
423 | 423 | else |
|
424 | 424 | { |
|
425 | PRINTF("send CWF_F3 (light)\n") | |
|
426 |
|
|
|
425 | PRINTF("send CWF_F3 (light)\n"); | |
|
426 | send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); | |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | } |
|
430 | 430 | else |
|
431 | 431 | { |
|
432 | 432 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) |
|
433 | 433 | } |
|
434 | 434 | } |
|
435 | 435 | } |
|
436 | 436 | |
|
437 | 437 | rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 |
|
438 | 438 | { |
|
439 | 439 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. |
|
440 | 440 | * |
|
441 | 441 | * @param unused is the starting argument of the RTEMS task |
|
442 | 442 | * |
|
443 | 443 | * The following data packet is sent by this function: |
|
444 | 444 | * - TM_LFR_SCIENCE_BURST_CWF_F2 |
|
445 | 445 | * - TM_LFR_SCIENCE_SBM2_CWF_F2 |
|
446 | 446 | * |
|
447 | 447 | */ |
|
448 | 448 | |
|
449 | 449 | rtems_event_set event_out; |
|
450 | 450 | rtems_id queue_id; |
|
451 | 451 | rtems_status_code status; |
|
452 | 452 | ring_node *ring_node_to_send; |
|
453 | 453 | unsigned long long int acquisitionTimeF0_asLong; |
|
454 | 454 | |
|
455 | 455 | acquisitionTimeF0_asLong = 0x00; |
|
456 | 456 | |
|
457 | 457 | status = get_message_queue_id_send( &queue_id ); |
|
458 | 458 | if (status != RTEMS_SUCCESSFUL) |
|
459 | 459 | { |
|
460 | 460 | PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | BOOT_PRINTF("in CWF2 ***\n") | |
|
463 | BOOT_PRINTF("in CWF2 ***\n"); | |
|
464 | 464 | |
|
465 |
|
|
|
465 | while(1){ | |
|
466 | 466 | // wait for an RTEMS_EVENT// send the snapshot when built |
|
467 | 467 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); |
|
468 | 468 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, |
|
469 | 469 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
470 | 470 | ring_node_to_send = getRingNodeToSendCWF( 2 ); |
|
471 | 471 | if (event_out == RTEMS_EVENT_MODE_BURST) |
|
472 | { | |
|
472 | { // data are sent whatever the transition time | |
|
473 | 473 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
474 | 474 | } |
|
475 | 475 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
476 | 476 | { |
|
477 | 477 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
478 | 478 | { |
|
479 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); | |
|
479 | // data are sent depending on the transition time | |
|
480 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime) | |
|
481 | { | |
|
482 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); | |
|
483 | } | |
|
480 | 484 | } |
|
481 | 485 | // launch snapshot extraction if needed |
|
482 | 486 | if (extractSWF2 == true) |
|
483 | 487 | { |
|
484 | 488 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; |
|
485 | 489 | // extract the snapshot |
|
486 | 490 | build_snapshot_from_ring( ring_node_to_send_swf_f2, 2, acquisitionTimeF0_asLong, |
|
487 | 491 | &ring_node_swf2_extracted, swf2_extracted ); |
|
488 | 492 | extractSWF2 = false; |
|
489 | 493 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM |
|
490 | 494 | } |
|
491 | 495 | if (swf0_ready_flag_f2 == true) |
|
492 | 496 | { |
|
493 | 497 | extractSWF2 = true; |
|
494 | 498 | // record the acquition time of the f0 snapshot to use to build the snapshot at f2 |
|
495 | 499 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
496 | 500 | swf0_ready_flag_f2 = false; |
|
497 | 501 | } |
|
498 | 502 | } |
|
499 | 503 | } |
|
500 | 504 | } |
|
501 | 505 | |
|
502 | 506 | rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 |
|
503 | 507 | { |
|
504 | 508 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. |
|
505 | 509 | * |
|
506 | 510 | * @param unused is the starting argument of the RTEMS task |
|
507 | 511 | * |
|
508 | 512 | * The following data packet is sent by this function: |
|
509 | 513 | * - TM_LFR_SCIENCE_SBM1_CWF_F1 |
|
510 | 514 | * |
|
511 | 515 | */ |
|
512 | 516 | |
|
513 | 517 | rtems_event_set event_out; |
|
514 | 518 | rtems_id queue_id; |
|
515 | 519 | rtems_status_code status; |
|
516 | 520 | |
|
517 | 521 | ring_node *ring_node_to_send_cwf; |
|
518 | 522 | |
|
519 | 523 | status = get_message_queue_id_send( &queue_id ); |
|
520 | 524 | if (status != RTEMS_SUCCESSFUL) |
|
521 | 525 | { |
|
522 | 526 | PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) |
|
523 | 527 | } |
|
524 | 528 | |
|
525 | 529 | BOOT_PRINTF("in CWF1 ***\n"); |
|
526 | 530 | |
|
527 | 531 | while(1){ |
|
528 | 532 | // wait for an RTEMS_EVENT |
|
529 | 533 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
530 | 534 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
531 | 535 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); |
|
532 | 536 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; |
|
533 | 537 | if (lfrCurrentMode == LFR_MODE_SBM1) |
|
534 | 538 | { |
|
535 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | |
|
536 | if (status != 0) | |
|
539 | // data are sent depending on the transition time | |
|
540 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) | |
|
537 | 541 | { |
|
538 | PRINTF("cwf sending failed\n") | |
|
542 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | |
|
539 | 543 | } |
|
540 | 544 | } |
|
541 | 545 | // launch snapshot extraction if needed |
|
542 | 546 | if (extractSWF1 == true) |
|
543 | 547 | { |
|
544 | 548 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; |
|
545 | 549 | // launch the snapshot extraction |
|
546 | 550 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
547 | 551 | extractSWF1 = false; |
|
548 | 552 | } |
|
549 | 553 | if (swf0_ready_flag_f1 == true) |
|
550 | 554 | { |
|
551 | 555 | extractSWF1 = true; |
|
552 | 556 | swf0_ready_flag_f1 = false; // this step shall be executed only one time |
|
553 | 557 | } |
|
554 | 558 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction |
|
555 | 559 | { |
|
556 | 560 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); |
|
557 | 561 | swf1_ready = false; |
|
558 | 562 | swf2_ready = false; |
|
559 | 563 | } |
|
560 | 564 | } |
|
561 | 565 | } |
|
562 | 566 | |
|
563 | 567 | rtems_task swbd_task(rtems_task_argument argument) |
|
564 | 568 | { |
|
565 | 569 | /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. |
|
566 | 570 | * |
|
567 | 571 | * @param unused is the starting argument of the RTEMS task |
|
568 | 572 | * |
|
569 | 573 | */ |
|
570 | 574 | |
|
571 | 575 | rtems_event_set event_out; |
|
572 | 576 | unsigned long long int acquisitionTimeF0_asLong; |
|
573 | 577 | |
|
574 | 578 | acquisitionTimeF0_asLong = 0x00; |
|
575 | 579 | |
|
576 | 580 | BOOT_PRINTF("in SWBD ***\n") |
|
577 | 581 | |
|
578 | 582 | while(1){ |
|
579 | 583 | // wait for an RTEMS_EVENT |
|
580 | 584 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
581 | 585 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
582 | 586 | if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
583 | 587 | { |
|
584 | 588 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
585 | 589 | build_snapshot_from_ring( ring_node_to_send_swf_f1, 1, acquisitionTimeF0_asLong, |
|
586 | 590 | &ring_node_swf1_extracted, swf1_extracted ); |
|
587 | 591 | swf1_ready = true; // the snapshot has been extracted and is ready to be sent |
|
588 | 592 | } |
|
589 | 593 | else |
|
590 | 594 | { |
|
591 | 595 | PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) |
|
592 | 596 | } |
|
593 | 597 | } |
|
594 | 598 | } |
|
595 | 599 | |
|
596 | 600 | //****************** |
|
597 | 601 | // general functions |
|
598 | 602 | |
|
599 | 603 | void WFP_init_rings( void ) |
|
600 | 604 | { |
|
601 | 605 | // F0 RING |
|
602 | 606 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); |
|
603 | 607 | // F1 RING |
|
604 | 608 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); |
|
605 | 609 | // F2 RING |
|
606 | 610 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); |
|
607 | 611 | // F3 RING |
|
608 | 612 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); |
|
609 | 613 | |
|
610 | 614 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; |
|
611 | 615 | ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; |
|
612 | 616 | |
|
613 | 617 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) |
|
614 | 618 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) |
|
615 | 619 | DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) |
|
616 | 620 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) |
|
617 | 621 | DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) |
|
618 | 622 | DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) |
|
619 | 623 | DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) |
|
620 | 624 | DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) |
|
621 | 625 | |
|
622 | 626 | } |
|
623 | 627 | |
|
624 | 628 | void WFP_reset_current_ring_nodes( void ) |
|
625 | 629 | { |
|
626 | 630 | current_ring_node_f0 = waveform_ring_f0[0].next; |
|
627 | 631 | current_ring_node_f1 = waveform_ring_f1[0].next; |
|
628 | 632 | current_ring_node_f2 = waveform_ring_f2[0].next; |
|
629 | 633 | current_ring_node_f3 = waveform_ring_f3[0].next; |
|
630 | 634 | |
|
631 | 635 | ring_node_to_send_swf_f0 = waveform_ring_f0; |
|
632 | 636 | ring_node_to_send_swf_f1 = waveform_ring_f1; |
|
633 | 637 | ring_node_to_send_swf_f2 = waveform_ring_f2; |
|
634 | 638 | |
|
635 | 639 | ring_node_to_send_cwf_f1 = waveform_ring_f1; |
|
636 | 640 | ring_node_to_send_cwf_f2 = waveform_ring_f2; |
|
637 | 641 | ring_node_to_send_cwf_f3 = waveform_ring_f3; |
|
638 | 642 | } |
|
639 | 643 | |
|
640 | 644 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) |
|
641 | 645 | { |
|
642 | 646 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
643 | 647 | * |
|
644 | 648 | * @param waveform points to the buffer containing the data that will be send. |
|
645 | 649 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
646 | 650 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
647 | 651 | * contain information to setup the transmission of the data packets. |
|
648 | 652 | * |
|
649 | 653 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
650 | 654 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
651 | 655 | * |
|
652 | 656 | */ |
|
653 | 657 | |
|
654 | 658 | unsigned int i; |
|
655 | 659 | int ret; |
|
656 | 660 | rtems_status_code status; |
|
657 | 661 | |
|
658 | 662 | char *sample; |
|
659 | 663 | int *dataPtr; |
|
660 | 664 | |
|
661 | 665 | ret = LFR_DEFAULT; |
|
662 | 666 | |
|
663 | 667 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
664 | 668 | |
|
665 | 669 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; |
|
666 | 670 | ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; |
|
667 | 671 | |
|
668 | 672 | //********************** |
|
669 | 673 | // BUILD CWF3_light DATA |
|
670 | 674 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) |
|
671 | 675 | { |
|
672 | 676 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; |
|
673 | 677 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ]; |
|
674 | 678 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ]; |
|
675 | 679 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ]; |
|
676 | 680 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ]; |
|
677 | 681 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ]; |
|
678 | 682 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ]; |
|
679 | 683 | } |
|
680 | 684 | |
|
681 | 685 | // SEND PACKET |
|
682 | 686 | status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); |
|
683 | 687 | if (status != RTEMS_SUCCESSFUL) { |
|
684 | 688 | ret = LFR_DEFAULT; |
|
685 | 689 | } |
|
686 | 690 | |
|
687 | 691 | return ret; |
|
688 | 692 | } |
|
689 | 693 | |
|
690 | 694 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, |
|
691 | 695 | unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) |
|
692 | 696 | { |
|
693 | 697 | unsigned long long int acquisitionTimeAsLong; |
|
694 | 698 | unsigned char localAcquisitionTime[6]; |
|
695 | 699 | double deltaT; |
|
696 | 700 | |
|
697 | 701 | deltaT = 0.; |
|
698 | 702 | |
|
699 | 703 | localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 ); |
|
700 | 704 | localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 ); |
|
701 | 705 | localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 ); |
|
702 | 706 | localAcquisitionTime[3] = (unsigned char) ( coarseTime ); |
|
703 | 707 | localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 ); |
|
704 | 708 | localAcquisitionTime[5] = (unsigned char) ( fineTime ); |
|
705 | 709 | |
|
706 | 710 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 ) |
|
707 | 711 | + ( (unsigned long long int) localAcquisitionTime[1] << 32 ) |
|
708 | 712 | + ( (unsigned long long int) localAcquisitionTime[2] << 24 ) |
|
709 | 713 | + ( (unsigned long long int) localAcquisitionTime[3] << 16 ) |
|
710 | 714 | + ( (unsigned long long int) localAcquisitionTime[4] << 8 ) |
|
711 | 715 | + ( (unsigned long long int) localAcquisitionTime[5] ); |
|
712 | 716 | |
|
713 | 717 | switch( sid ) |
|
714 | 718 | { |
|
715 | 719 | case SID_NORM_SWF_F0: |
|
716 | 720 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ; |
|
717 | 721 | break; |
|
718 | 722 | |
|
719 | 723 | case SID_NORM_SWF_F1: |
|
720 | 724 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ; |
|
721 | 725 | break; |
|
722 | 726 | |
|
723 | 727 | case SID_NORM_SWF_F2: |
|
724 | 728 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ; |
|
725 | 729 | break; |
|
726 | 730 | |
|
727 | 731 | case SID_SBM1_CWF_F1: |
|
728 | 732 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ; |
|
729 | 733 | break; |
|
730 | 734 | |
|
731 | 735 | case SID_SBM2_CWF_F2: |
|
732 | 736 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; |
|
733 | 737 | break; |
|
734 | 738 | |
|
735 | 739 | case SID_BURST_CWF_F2: |
|
736 | 740 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; |
|
737 | 741 | break; |
|
738 | 742 | |
|
739 | 743 | case SID_NORM_CWF_F3: |
|
740 | 744 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ; |
|
741 | 745 | break; |
|
742 | 746 | |
|
743 | 747 | case SID_NORM_CWF_LONG_F3: |
|
744 | 748 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ; |
|
745 | 749 | break; |
|
746 | 750 | |
|
747 | 751 | default: |
|
748 | 752 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) |
|
749 | 753 | deltaT = 0.; |
|
750 | 754 | break; |
|
751 | 755 | } |
|
752 | 756 | |
|
753 | 757 | acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; |
|
754 | 758 | // |
|
755 | 759 | acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40); |
|
756 | 760 | acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32); |
|
757 | 761 | acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24); |
|
758 | 762 | acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16); |
|
759 | 763 | acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 ); |
|
760 | 764 | acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong ); |
|
761 | 765 | |
|
762 | 766 | } |
|
763 | 767 | |
|
764 | 768 | void build_snapshot_from_ring( ring_node *ring_node_to_send, |
|
765 | 769 | unsigned char frequencyChannel, |
|
766 | 770 | unsigned long long int acquisitionTimeF0_asLong, |
|
767 | 771 | ring_node *ring_node_swf_extracted, |
|
768 | 772 | int *swf_extracted) |
|
769 | 773 | { |
|
770 | 774 | unsigned int i; |
|
771 | 775 | unsigned long long int centerTime_asLong; |
|
772 | 776 | unsigned long long int acquisitionTime_asLong; |
|
773 | 777 | unsigned long long int bufferAcquisitionTime_asLong; |
|
774 | 778 | unsigned char *ptr1; |
|
775 | 779 | unsigned char *ptr2; |
|
776 | 780 | unsigned char *timeCharPtr; |
|
777 | 781 | unsigned char nb_ring_nodes; |
|
778 | 782 | unsigned long long int frequency_asLong; |
|
779 | 783 | unsigned long long int nbTicksPerSample_asLong; |
|
780 | 784 | unsigned long long int nbSamplesPart1_asLong; |
|
781 | 785 | unsigned long long int sampleOffset_asLong; |
|
782 | 786 | |
|
783 | 787 | unsigned int deltaT_F0; |
|
784 | 788 | unsigned int deltaT_F1; |
|
785 | 789 | unsigned long long int deltaT_F2; |
|
786 | 790 | |
|
787 | 791 | deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; |
|
788 | 792 | deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384; |
|
789 | 793 | deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144; |
|
790 | 794 | sampleOffset_asLong = 0x00; |
|
791 | 795 | |
|
792 | 796 | // (1) get the f0 acquisition time => the value is passed in argument |
|
793 | 797 | |
|
794 | 798 | // (2) compute the central reference time |
|
795 | 799 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; |
|
796 | 800 | |
|
797 | 801 | // (3) compute the acquisition time of the current snapshot |
|
798 | 802 | switch(frequencyChannel) |
|
799 | 803 | { |
|
800 | 804 | case 1: // 1 is for F1 = 4096 Hz |
|
801 | 805 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; |
|
802 | 806 | nb_ring_nodes = NB_RING_NODES_F1; |
|
803 | 807 | frequency_asLong = 4096; |
|
804 | 808 | nbTicksPerSample_asLong = 16; // 65536 / 4096; |
|
805 | 809 | break; |
|
806 | 810 | case 2: // 2 is for F2 = 256 Hz |
|
807 | 811 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; |
|
808 | 812 | nb_ring_nodes = NB_RING_NODES_F2; |
|
809 | 813 | frequency_asLong = 256; |
|
810 | 814 | nbTicksPerSample_asLong = 256; // 65536 / 256; |
|
811 | 815 | break; |
|
812 | 816 | default: |
|
813 | 817 | acquisitionTime_asLong = centerTime_asLong; |
|
814 | 818 | frequency_asLong = 256; |
|
815 | 819 | nbTicksPerSample_asLong = 256; |
|
816 | 820 | break; |
|
817 | 821 | } |
|
818 | 822 | |
|
819 | 823 | //**************************************************************************** |
|
820 | 824 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong |
|
821 | 825 | for (i=0; i<nb_ring_nodes; i++) |
|
822 | 826 | { |
|
823 | 827 | //PRINTF1("%d ... ", i); |
|
824 | 828 | bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); |
|
825 | 829 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) |
|
826 | 830 | { |
|
827 | 831 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); |
|
828 | 832 | break; |
|
829 | 833 | } |
|
830 | 834 | ring_node_to_send = ring_node_to_send->previous; |
|
831 | 835 | } |
|
832 | 836 | |
|
833 | 837 | // (5) compute the number of samples to take in the current buffer |
|
834 | 838 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16; |
|
835 | 839 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; |
|
836 | 840 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); |
|
837 | 841 | |
|
838 | 842 | // (6) compute the final acquisition time |
|
839 | 843 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + |
|
840 | 844 | sampleOffset_asLong * nbTicksPerSample_asLong; |
|
841 | 845 | |
|
842 | 846 | // (7) copy the acquisition time at the beginning of the extrated snapshot |
|
843 | 847 | ptr1 = (unsigned char*) &acquisitionTime_asLong; |
|
844 | 848 | // fine time |
|
845 | 849 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; |
|
846 | 850 | ptr2[2] = ptr1[ 4 + 2 ]; |
|
847 | 851 | ptr2[3] = ptr1[ 5 + 2 ]; |
|
848 | 852 | // coarse time |
|
849 | 853 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; |
|
850 | 854 | ptr2[0] = ptr1[ 0 + 2 ]; |
|
851 | 855 | ptr2[1] = ptr1[ 1 + 2 ]; |
|
852 | 856 | ptr2[2] = ptr1[ 2 + 2 ]; |
|
853 | 857 | ptr2[3] = ptr1[ 3 + 2 ]; |
|
854 | 858 | |
|
855 | 859 | // re set the synchronization bit |
|
856 | 860 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; |
|
857 | 861 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000] |
|
858 | 862 | |
|
859 | 863 | if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) |
|
860 | 864 | { |
|
861 | 865 | nbSamplesPart1_asLong = 0; |
|
862 | 866 | } |
|
863 | 867 | // copy the part 1 of the snapshot in the extracted buffer |
|
864 | 868 | for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) |
|
865 | 869 | { |
|
866 | 870 | swf_extracted[i] = |
|
867 | 871 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; |
|
868 | 872 | } |
|
869 | 873 | // copy the part 2 of the snapshot in the extracted buffer |
|
870 | 874 | ring_node_to_send = ring_node_to_send->next; |
|
871 | 875 | for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) |
|
872 | 876 | { |
|
873 | 877 | swf_extracted[i] = |
|
874 | 878 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; |
|
875 | 879 | } |
|
876 | 880 | } |
|
877 | 881 | |
|
878 | 882 | double computeCorrection( unsigned char *timePtr ) |
|
879 | 883 | { |
|
880 | 884 | unsigned long long int acquisitionTime; |
|
881 | 885 | unsigned long long int centerTime; |
|
882 | 886 | unsigned long long int previousTick; |
|
883 | 887 | unsigned long long int nextTick; |
|
884 | 888 | unsigned long long int deltaPreviousTick; |
|
885 | 889 | unsigned long long int deltaNextTick; |
|
886 | 890 | double deltaPrevious_ms; |
|
887 | 891 | double deltaNext_ms; |
|
888 | 892 | double correctionInF2; |
|
889 | 893 | |
|
890 | 894 | // get acquisition time in fine time ticks |
|
891 | 895 | acquisitionTime = get_acquisition_time( timePtr ); |
|
892 | 896 | |
|
893 | 897 | // compute center time |
|
894 | 898 | centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; |
|
895 | 899 | previousTick = centerTime - (centerTime & 0xffff); |
|
896 | 900 | nextTick = previousTick + 65536; |
|
897 | 901 | |
|
898 | 902 | deltaPreviousTick = centerTime - previousTick; |
|
899 | 903 | deltaNextTick = nextTick - centerTime; |
|
900 | 904 | |
|
901 | 905 | deltaPrevious_ms = ((double) deltaPreviousTick) / 65536. * 1000.; |
|
902 | 906 | deltaNext_ms = ((double) deltaNextTick) / 65536. * 1000.; |
|
903 | 907 | |
|
904 | 908 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); |
|
905 | 909 | |
|
906 | 910 | // which tick is the closest? |
|
907 | 911 | if (deltaPreviousTick > deltaNextTick) |
|
908 | 912 | { |
|
909 | 913 | // the snapshot center is just before the second => increase delta_snapshot |
|
910 | 914 | correctionInF2 = + (deltaNext_ms * 256. / 1000. ); |
|
911 | 915 | } |
|
912 | 916 | else |
|
913 | 917 | { |
|
914 | 918 | // the snapshot center is just after the second => decrease delta_snapshot |
|
915 | 919 | correctionInF2 = - (deltaPrevious_ms * 256. / 1000. ); |
|
916 | 920 | } |
|
917 | 921 | |
|
918 | 922 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); |
|
919 | 923 | |
|
920 | 924 | return correctionInF2; |
|
921 | 925 | } |
|
922 | 926 | |
|
923 | 927 | void applyCorrection( double correction ) |
|
924 | 928 | { |
|
925 | 929 | int correctionInt; |
|
926 | 930 | |
|
927 | 931 | if (correction >= 0.) |
|
928 | 932 | { |
|
929 | 933 | if ( (1. > correction) && (correction > 0.5) ) |
|
930 | 934 | { |
|
931 | 935 | correctionInt = 1; |
|
932 | 936 | } |
|
933 | 937 | else |
|
934 | 938 | { |
|
935 | 939 | correctionInt = 2 * floor(correction); |
|
936 | 940 | } |
|
937 | 941 | } |
|
938 | 942 | else |
|
939 | 943 | { |
|
940 | 944 | if ( (-1. < correction) && (correction < -0.5) ) |
|
941 | 945 | { |
|
942 | 946 | correctionInt = -1; |
|
943 | 947 | } |
|
944 | 948 | else |
|
945 | 949 | { |
|
946 | 950 | correctionInt = 2 * ceil(correction); |
|
947 | 951 | } |
|
948 | 952 | } |
|
949 | 953 | waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; |
|
950 | 954 | } |
|
951 | 955 | |
|
952 | 956 | void snapshot_resynchronization( unsigned char *timePtr ) |
|
953 | 957 | { |
|
954 | 958 | /** This function compute a correction to apply on delta_snapshot. |
|
955 | 959 | * |
|
956 | 960 | * |
|
957 | 961 | * @param timePtr is a pointer to the acquisition time of the snapshot being considered. |
|
958 | 962 | * |
|
959 | 963 | * @return void |
|
960 | 964 | * |
|
961 | 965 | */ |
|
962 | 966 | |
|
963 | 967 | static double correction = 0.; |
|
964 | 968 | static resynchro_state state = MEASURE; |
|
965 | 969 | static unsigned int nbSnapshots = 0; |
|
966 | 970 | |
|
967 | 971 | int correctionInt; |
|
968 | 972 | |
|
969 | 973 | correctionInt = 0; |
|
970 | 974 | |
|
971 | 975 | switch (state) |
|
972 | 976 | { |
|
973 | 977 | |
|
974 | 978 | case MEASURE: |
|
975 | 979 | // ******** |
|
976 | 980 | PRINTF1("MEASURE === %d\n", nbSnapshots); |
|
977 | 981 | state = CORRECTION; |
|
978 | 982 | correction = computeCorrection( timePtr ); |
|
979 | 983 | PRINTF1("MEASURE === correction = %.2f\n", correction ); |
|
980 | 984 | applyCorrection( correction ); |
|
981 | 985 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
982 | 986 | //**** |
|
983 | 987 | break; |
|
984 | 988 | |
|
985 | 989 | case CORRECTION: |
|
986 | 990 | //************ |
|
987 | 991 | PRINTF1("CORRECTION === %d\n", nbSnapshots); |
|
988 | 992 | state = MEASURE; |
|
989 | 993 | computeCorrection( timePtr ); |
|
990 | 994 | set_wfp_delta_snapshot(); |
|
991 | 995 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
992 | 996 | //**** |
|
993 | 997 | break; |
|
994 | 998 | |
|
995 | 999 | default: |
|
996 | 1000 | break; |
|
997 | 1001 | |
|
998 | 1002 | } |
|
999 | 1003 | |
|
1000 | 1004 | nbSnapshots++; |
|
1001 | 1005 | } |
|
1002 | 1006 | |
|
1003 | 1007 | //************** |
|
1004 | 1008 | // wfp registers |
|
1005 | 1009 | void reset_wfp_burst_enable( void ) |
|
1006 | 1010 | { |
|
1007 | 1011 | /** This function resets the waveform picker burst_enable register. |
|
1008 | 1012 | * |
|
1009 | 1013 | * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. |
|
1010 | 1014 | * |
|
1011 | 1015 | */ |
|
1012 | 1016 | |
|
1013 | 1017 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 |
|
1014 | 1018 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & 0x80; |
|
1015 | 1019 | } |
|
1016 | 1020 | |
|
1017 | 1021 | void reset_wfp_status( void ) |
|
1018 | 1022 | { |
|
1019 | 1023 | /** This function resets the waveform picker status register. |
|
1020 | 1024 | * |
|
1021 | 1025 | * All status bits are set to 0 [new_err full_err full]. |
|
1022 | 1026 | * |
|
1023 | 1027 | */ |
|
1024 | 1028 | |
|
1025 | 1029 | waveform_picker_regs->status = 0xffff; |
|
1026 | 1030 | } |
|
1027 | 1031 | |
|
1028 | 1032 | void reset_wfp_buffer_addresses( void ) |
|
1029 | 1033 | { |
|
1030 | 1034 | // F0 |
|
1031 | 1035 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 |
|
1032 | 1036 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c |
|
1033 | 1037 | // F1 |
|
1034 | 1038 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 |
|
1035 | 1039 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 |
|
1036 | 1040 | // F2 |
|
1037 | 1041 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 |
|
1038 | 1042 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c |
|
1039 | 1043 | // F3 |
|
1040 | 1044 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 |
|
1041 | 1045 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 |
|
1042 | 1046 | } |
|
1043 | 1047 | |
|
1044 | 1048 | void reset_waveform_picker_regs( void ) |
|
1045 | 1049 | { |
|
1046 | 1050 | /** This function resets the waveform picker module registers. |
|
1047 | 1051 | * |
|
1048 | 1052 | * The registers affected by this function are located at the following offset addresses: |
|
1049 | 1053 | * - 0x00 data_shaping |
|
1050 | 1054 | * - 0x04 run_burst_enable |
|
1051 | 1055 | * - 0x08 addr_data_f0 |
|
1052 | 1056 | * - 0x0C addr_data_f1 |
|
1053 | 1057 | * - 0x10 addr_data_f2 |
|
1054 | 1058 | * - 0x14 addr_data_f3 |
|
1055 | 1059 | * - 0x18 status |
|
1056 | 1060 | * - 0x1C delta_snapshot |
|
1057 | 1061 | * - 0x20 delta_f0 |
|
1058 | 1062 | * - 0x24 delta_f0_2 |
|
1059 | 1063 | * - 0x28 delta_f1 (obsolet parameter) |
|
1060 | 1064 | * - 0x2c delta_f2 |
|
1061 | 1065 | * - 0x30 nb_data_by_buffer |
|
1062 | 1066 | * - 0x34 nb_snapshot_param |
|
1063 | 1067 | * - 0x38 start_date |
|
1064 | 1068 | * - 0x3c nb_word_in_buffer |
|
1065 | 1069 | * |
|
1066 | 1070 | */ |
|
1067 | 1071 | |
|
1068 | 1072 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW |
|
1069 | 1073 | |
|
1070 | 1074 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] |
|
1071 | 1075 | |
|
1072 | 1076 | reset_wfp_buffer_addresses(); |
|
1073 | 1077 | |
|
1074 | 1078 | reset_wfp_status(); // 0x18 |
|
1075 | 1079 | |
|
1076 | 1080 | set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff |
|
1077 | 1081 | |
|
1078 | 1082 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 |
|
1079 | 1083 | |
|
1080 | 1084 | //the parameter delta_f1 [0x28] is not used anymore |
|
1081 | 1085 | |
|
1082 | 1086 | set_wfp_delta_f2(); // 0x2c |
|
1083 | 1087 | |
|
1084 | 1088 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); |
|
1085 | 1089 | DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); |
|
1086 | 1090 | DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); |
|
1087 | 1091 | DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); |
|
1088 | 1092 | DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); |
|
1089 | 1093 | // 2688 = 8 * 336 |
|
1090 | 1094 | waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1 |
|
1091 | 1095 | waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples |
|
1092 | 1096 | waveform_picker_regs->start_date = 0x7fffffff; // 0x38 |
|
1093 | 1097 | // |
|
1094 | 1098 | // coarse time and fine time registers are not initialized, they are volatile |
|
1095 | 1099 | // |
|
1096 | 1100 | waveform_picker_regs->buffer_length = 0x1f8;// buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 |
|
1097 | 1101 | } |
|
1098 | 1102 | |
|
1099 | 1103 | void set_wfp_data_shaping( void ) |
|
1100 | 1104 | { |
|
1101 | 1105 | /** This function sets the data_shaping register of the waveform picker module. |
|
1102 | 1106 | * |
|
1103 | 1107 | * The value is read from one field of the parameter_dump_packet structure:\n |
|
1104 | 1108 | * bw_sp0_sp1_r0_r1 |
|
1105 | 1109 | * |
|
1106 | 1110 | */ |
|
1107 | 1111 | |
|
1108 | 1112 | unsigned char data_shaping; |
|
1109 | 1113 | |
|
1110 | 1114 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register |
|
1111 | 1115 | // waveform picker : [R1 R0 SP1 SP0 BW] |
|
1112 | 1116 | |
|
1113 | 1117 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; |
|
1114 | 1118 | |
|
1115 | 1119 | waveform_picker_regs->data_shaping = |
|
1116 | 1120 | ( (data_shaping & 0x20) >> 5 ) // BW |
|
1117 | 1121 | + ( (data_shaping & 0x10) >> 3 ) // SP0 |
|
1118 | 1122 | + ( (data_shaping & 0x08) >> 1 ) // SP1 |
|
1119 | 1123 | + ( (data_shaping & 0x04) << 1 ) // R0 |
|
1120 | 1124 | + ( (data_shaping & 0x02) << 3 ) // R1 |
|
1121 | 1125 | + ( (data_shaping & 0x01) << 5 ); // R2 |
|
1122 | 1126 | } |
|
1123 | 1127 | |
|
1124 | 1128 | void set_wfp_burst_enable_register( unsigned char mode ) |
|
1125 | 1129 | { |
|
1126 | 1130 | /** This function sets the waveform picker burst_enable register depending on the mode. |
|
1127 | 1131 | * |
|
1128 | 1132 | * @param mode is the LFR mode to launch. |
|
1129 | 1133 | * |
|
1130 | 1134 | * The burst bits shall be before the enable bits. |
|
1131 | 1135 | * |
|
1132 | 1136 | */ |
|
1133 | 1137 | |
|
1134 | 1138 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 |
|
1135 | 1139 | // the burst bits shall be set first, before the enable bits |
|
1136 | 1140 | switch(mode) { |
|
1137 | 1141 | case LFR_MODE_NORMAL: |
|
1138 | 1142 | case LFR_MODE_SBM1: |
|
1139 | 1143 | case LFR_MODE_SBM2: |
|
1140 | 1144 | waveform_picker_regs->run_burst_enable = 0x60; // [0110 0000] enable f2 and f1 burst |
|
1141 | 1145 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 |
|
1142 | 1146 | break; |
|
1143 | 1147 | case LFR_MODE_BURST: |
|
1144 | 1148 | waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled |
|
1145 | 1149 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2 |
|
1146 | 1150 | break; |
|
1147 | 1151 | default: |
|
1148 | 1152 | waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled |
|
1149 | 1153 | break; |
|
1150 | 1154 | } |
|
1151 | 1155 | } |
|
1152 | 1156 | |
|
1153 | 1157 | void set_wfp_delta_snapshot( void ) |
|
1154 | 1158 | { |
|
1155 | 1159 | /** This function sets the delta_snapshot register of the waveform picker module. |
|
1156 | 1160 | * |
|
1157 | 1161 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: |
|
1158 | 1162 | * - sy_lfr_n_swf_p[0] |
|
1159 | 1163 | * - sy_lfr_n_swf_p[1] |
|
1160 | 1164 | * |
|
1161 | 1165 | */ |
|
1162 | 1166 | |
|
1163 | 1167 | unsigned int delta_snapshot; |
|
1164 | 1168 | unsigned int delta_snapshot_in_T2; |
|
1165 | 1169 | |
|
1166 | 1170 | delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256 |
|
1167 | 1171 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; |
|
1168 | 1172 | |
|
1169 | 1173 | delta_snapshot_in_T2 = delta_snapshot * 256; |
|
1170 | 1174 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes |
|
1171 | 1175 | } |
|
1172 | 1176 | |
|
1173 | 1177 | void set_wfp_delta_f0_f0_2( void ) |
|
1174 | 1178 | { |
|
1175 | 1179 | unsigned int delta_snapshot; |
|
1176 | 1180 | unsigned int nb_samples_per_snapshot; |
|
1177 | 1181 | float delta_f0_in_float; |
|
1178 | 1182 | |
|
1179 | 1183 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1180 | 1184 | nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1181 | 1185 | delta_f0_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.; |
|
1182 | 1186 | |
|
1183 | 1187 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); |
|
1184 | 1188 | waveform_picker_regs->delta_f0_2 = 0x30; // 48 = 11 0000, max 7 bits |
|
1185 | 1189 | } |
|
1186 | 1190 | |
|
1187 | 1191 | void set_wfp_delta_f1( void ) |
|
1188 | 1192 | { |
|
1189 | 1193 | /** Sets the value of the delta_f1 parameter |
|
1190 | 1194 | * |
|
1191 | 1195 | * @param void |
|
1192 | 1196 | * |
|
1193 | 1197 | * @return void |
|
1194 | 1198 | * |
|
1195 | 1199 | * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. |
|
1196 | 1200 | * |
|
1197 | 1201 | */ |
|
1198 | 1202 | |
|
1199 | 1203 | unsigned int delta_snapshot; |
|
1200 | 1204 | unsigned int nb_samples_per_snapshot; |
|
1201 | 1205 | float delta_f1_in_float; |
|
1202 | 1206 | |
|
1203 | 1207 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1204 | 1208 | nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1205 | 1209 | delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.; |
|
1206 | 1210 | |
|
1207 | 1211 | waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); |
|
1208 | 1212 | } |
|
1209 | 1213 | |
|
1210 | 1214 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used |
|
1211 | 1215 | { |
|
1212 | 1216 | /** Sets the value of the delta_f2 parameter |
|
1213 | 1217 | * |
|
1214 | 1218 | * @param void |
|
1215 | 1219 | * |
|
1216 | 1220 | * @return void |
|
1217 | 1221 | * |
|
1218 | 1222 | * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 |
|
1219 | 1223 | * waveforms (see lpp_waveform_snapshot_controler.vhd for details). |
|
1220 | 1224 | * |
|
1221 | 1225 | */ |
|
1222 | 1226 | |
|
1223 | 1227 | unsigned int delta_snapshot; |
|
1224 | 1228 | unsigned int nb_samples_per_snapshot; |
|
1225 | 1229 | |
|
1226 | 1230 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1227 | 1231 | nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1228 | 1232 | |
|
1229 | 1233 | waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2 - 1; |
|
1230 | 1234 | } |
|
1231 | 1235 | |
|
1232 | 1236 | //***************** |
|
1233 | 1237 | // local parameters |
|
1234 | 1238 | |
|
1235 | 1239 | void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) |
|
1236 | 1240 | { |
|
1237 | 1241 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. |
|
1238 | 1242 | * |
|
1239 | 1243 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. |
|
1240 | 1244 | * @param sid is the source identifier of the packet being updated. |
|
1241 | 1245 | * |
|
1242 | 1246 | * REQ-LFR-SRS-5240 / SSS-CP-FS-590 |
|
1243 | 1247 | * The sequence counters shall wrap around from 2^14 to zero. |
|
1244 | 1248 | * The sequence counter shall start at zero at startup. |
|
1245 | 1249 | * |
|
1246 | 1250 | * REQ-LFR-SRS-5239 / SSS-CP-FS-580 |
|
1247 | 1251 | * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 |
|
1248 | 1252 | * |
|
1249 | 1253 | */ |
|
1250 | 1254 | |
|
1251 | 1255 | unsigned short *sequence_cnt; |
|
1252 | 1256 | unsigned short segmentation_grouping_flag; |
|
1253 | 1257 | unsigned short new_packet_sequence_control; |
|
1254 | 1258 | rtems_mode initial_mode_set; |
|
1255 | 1259 | rtems_mode current_mode_set; |
|
1256 | 1260 | rtems_status_code status; |
|
1257 | 1261 | |
|
1258 | 1262 | //****************************************** |
|
1259 | 1263 | // CHANGE THE MODE OF THE CALLING RTEMS TASK |
|
1260 | 1264 | status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); |
|
1261 | 1265 | |
|
1262 | 1266 | if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) |
|
1263 | 1267 | || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) |
|
1264 | 1268 | || (sid == SID_BURST_CWF_F2) |
|
1265 | 1269 | || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) |
|
1266 | 1270 | || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) |
|
1267 | 1271 | || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) |
|
1268 | 1272 | || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) |
|
1269 | 1273 | || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) |
|
1270 | 1274 | { |
|
1271 | 1275 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; |
|
1272 | 1276 | } |
|
1273 | 1277 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) |
|
1274 | 1278 | || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) |
|
1275 | 1279 | || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) |
|
1276 | 1280 | || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) |
|
1277 | 1281 | { |
|
1278 | 1282 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; |
|
1279 | 1283 | } |
|
1280 | 1284 | else |
|
1281 | 1285 | { |
|
1282 | 1286 | sequence_cnt = (unsigned short *) NULL; |
|
1283 | 1287 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) |
|
1284 | 1288 | } |
|
1285 | 1289 | |
|
1286 | 1290 | if (sequence_cnt != NULL) |
|
1287 | 1291 | { |
|
1288 | 1292 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; |
|
1289 | 1293 | *sequence_cnt = (*sequence_cnt) & 0x3fff; |
|
1290 | 1294 | |
|
1291 | 1295 | new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; |
|
1292 | 1296 | |
|
1293 | 1297 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); |
|
1294 | 1298 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1295 | 1299 | |
|
1296 | 1300 | // increment the sequence counter |
|
1297 | 1301 | if ( *sequence_cnt < SEQ_CNT_MAX) |
|
1298 | 1302 | { |
|
1299 | 1303 | *sequence_cnt = *sequence_cnt + 1; |
|
1300 | 1304 | } |
|
1301 | 1305 | else |
|
1302 | 1306 | { |
|
1303 | 1307 | *sequence_cnt = 0; |
|
1304 | 1308 | } |
|
1305 | 1309 | } |
|
1306 | 1310 | |
|
1307 | 1311 | //************************************* |
|
1308 | 1312 | // RESTORE THE MODE OF THE CALLING TASK |
|
1309 | 1313 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); |
|
1310 | 1314 | } |
General Comments 0
You need to be logged in to leave comments.
Login now