Line data Source code
1 : /*------------------------------------------------------------------------------
2 : -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 : -- This file is a part of the LFR FSW
4 : -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 : --
6 : -- This program is free software; you can redistribute it and/or modify
7 : -- it under the terms of the GNU General Public License as published by
8 : -- the Free Software Foundation; either version 2 of the License, or
9 : -- (at your option) any later version.
10 : --
11 : -- This program is distributed in the hope that it will be useful,
12 : -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : -- GNU General Public License for more details.
15 : --
16 : -- You should have received a copy of the GNU General Public License
17 : -- along with this program; if not, write to the Free Software
18 : -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 : -------------------------------------------------------------------------------*/
20 : /*-- Author : Paul Leroy
21 : -- Contact : Alexis Jeandet
22 : -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 : ----------------------------------------------------------------------------*/
24 :
25 : /** Functions related to data processing.
26 : *
27 : * @file
28 : * @author P. LEROY
29 : *
30 : * These function are related to data processing, i.e. spectral matrices averaging and basic
31 : * parameters computation.
32 : *
33 : */
34 :
35 : #include "avf2_prc2.h"
36 : #include "fsw_compile_warnings.h"
37 : #include "fsw_debug.h"
38 : #include "mitigations/PAS_filtering.h"
39 :
40 : typedef struct
41 : {
42 : unsigned int norm_bp1;
43 : unsigned int norm_bp2;
44 : unsigned int norm_asm;
45 : } nb_sm_before_bp_asm_f2;
46 :
47 : DISABLE_MISSING_FIELD_INITIALIZER_WARNING
48 : nb_sm_before_bp_asm_f2 nb_sm_before_f2 = { 0 };
49 :
50 : //***
51 : // F2
52 : ring_node_asm asm_ring_norm_f2[NB_RING_NODES_ASM_NORM_F2] = { { 0 } };
53 : ring_node ring_to_send_asm_f2[NB_RING_NODES_ASM_F2] = { { 0 } };
54 : ENABLE_MISSING_FIELD_INITIALIZER_WARNING
55 :
56 : int buffer_asm_f2[NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM] = { 0 };
57 :
58 : float asm_f2_patched_norm[TOTAL_SIZE_SM] = { 0 };
59 : float asm_f2_reorganized[TOTAL_SIZE_SM] = { 0 };
60 :
61 : float compressed_sm_norm_f2[TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = { 0 };
62 :
63 :
64 : //************
65 : // RTEMS TASKS
66 :
67 : //***
68 : // F2
69 4 : LFR_NO_RETURN rtems_task avf2_task(rtems_task_argument argument)
70 : {
71 : IGNORE_UNUSED_PARAMETER(argument);
72 : rtems_event_set event_out;
73 : rtems_id queue_id_prc2;
74 : asm_msg msgForPRC;
75 : ring_node* nodeForAveraging;
76 : ring_node_asm* current_ring_node_asm_norm_f2;
77 :
78 : unsigned int nb_norm_bp1;
79 : unsigned int nb_norm_bp2;
80 : unsigned int nb_norm_asm;
81 :
82 4 : event_out = EVENT_SETS_NONE_PENDING;
83 4 : queue_id_prc2 = RTEMS_ID_NONE;
84 4 : nb_norm_bp1 = 0;
85 4 : nb_norm_bp2 = 0;
86 4 : nb_norm_asm = 0;
87 :
88 : reset_nb_sm_f2(); // reset the sm counters that drive the BP and ASM computations /
89 : // transmissions
90 4 : ASM_generic_init_ring(asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2);
91 4 : current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
92 : DEBUG_CHECK_PTR(current_ring_node_asm_norm_f2);
93 :
94 : BOOT_PRINTF("in AVF2 ***\n");
95 :
96 4 : DEBUG_CHECK_STATUS(get_message_queue_id_prc2(&queue_id_prc2));
97 :
98 : while (1)
99 : {
100 : // wait for an RTEMS_EVENT0
101 44 : DEBUG_CHECK_STATUS(
102 : rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out));
103 :
104 : //****************************************
105 : // initialize the mesage for the MATR task
106 42 : msgForPRC.norm = current_ring_node_asm_norm_f2;
107 42 : msgForPRC.burst_sbm = NULL;
108 42 : msgForPRC.event
109 : = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
110 : //
111 : //****************************************
112 :
113 42 : nodeForAveraging = getRingNodeForAveraging(CHANNELF2);
114 :
115 : DEBUG_PRINTF("in AVF2 *** got new SM\n");
116 : // compute the average and store it in the averaged_sm_f2 buffer
117 42 : SM_average_f2(
118 : current_ring_node_asm_norm_f2->matrix, nodeForAveraging, nb_norm_bp1, &msgForPRC);
119 :
120 : // update nb_average
121 40 : nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
122 40 : nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
123 40 : nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
124 :
125 40 : if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
126 : {
127 8 : nb_norm_bp1 = 0;
128 : // set another ring for the ASM storage
129 8 : current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
130 : DEBUG_CHECK_PTR(current_ring_node_asm_norm_f2);
131 12 : if ((lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
132 12 : || (lfrCurrentMode == LFR_MODE_SBM2))
133 : {
134 6 : msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
135 : }
136 : }
137 :
138 40 : if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
139 : {
140 0 : nb_norm_bp2 = 0;
141 0 : if ((lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
142 0 : || (lfrCurrentMode == LFR_MODE_SBM2))
143 : {
144 0 : msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
145 : }
146 : }
147 :
148 40 : if (nb_norm_asm == nb_sm_before_f2.norm_asm)
149 : {
150 0 : nb_norm_asm = 0;
151 0 : if ((lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
152 0 : || (lfrCurrentMode == LFR_MODE_SBM2))
153 : {
154 0 : msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
155 : }
156 : }
157 :
158 : //*************************
159 : // send the message to PRC2
160 40 : if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
161 : {
162 6 : DEBUG_CHECK_STATUS(rtems_message_queue_send(queue_id_prc2, (char*)&msgForPRC, sizeof(asm_msg)));
163 : }
164 :
165 : }
166 : }
167 :
168 4 : LFR_NO_RETURN rtems_task prc2_task(rtems_task_argument argument)
169 : {
170 : IGNORE_UNUSED_PARAMETER(argument);
171 : char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
172 : size_t size; // size of the incoming TC packet
173 : asm_msg* incomingMsg;
174 : //
175 : rtems_id queue_id_send;
176 : rtems_id queue_id_q_p2;
177 : bp_packet __attribute__((aligned(4))) packet_norm_bp1;
178 : bp_packet __attribute__((aligned(4))) packet_norm_bp2;
179 : ring_node* current_ring_node_to_send_asm_f2;
180 : float nbSMInASMNORM;
181 :
182 4 : size = 0;
183 4 : queue_id_send = RTEMS_ID_NONE;
184 4 : queue_id_q_p2 = RTEMS_ID_NONE;
185 4 : memset(&packet_norm_bp1, 0, sizeof(bp_packet));
186 4 : memset(&packet_norm_bp2, 0, sizeof(bp_packet));
187 :
188 : // init the ring of the averaged spectral matrices which will be transmitted to the DPU
189 4 : init_ring(
190 : ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*)buffer_asm_f2, TOTAL_SIZE_SM);
191 4 : current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
192 : DEBUG_CHECK_PTR(current_ring_node_to_send_asm_f2);
193 :
194 : //*************
195 : // NORM headers
196 4 : BP_init_header(&packet_norm_bp1, APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
197 : PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2);
198 4 : BP_init_header(&packet_norm_bp2, APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
199 : PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2);
200 :
201 4 : DEBUG_CHECK_STATUS(get_message_queue_id_send(&queue_id_send));
202 4 : DEBUG_CHECK_STATUS(get_message_queue_id_prc2(&queue_id_q_p2));
203 :
204 : BOOT_PRINTF("in PRC2 ***\n");
205 :
206 : while (1)
207 : {
208 : // wait for a message coming from AVF2
209 10 : DEBUG_CHECK_STATUS(rtems_message_queue_receive(
210 : queue_id_q_p2, incomingData, &size, RTEMS_WAIT, RTEMS_NO_TIMEOUT));
211 :
212 6 : incomingMsg = (asm_msg*)incomingData;
213 : DEBUG_CHECK_PTR(incomingMsg);
214 :
215 : DEBUG_PRINTF("Before SM_calibrate_and_reorder_f2");
216 6 : SM_calibrate_and_reorder_f2(incomingMsg->norm->matrix, asm_f2_patched_norm);
217 : DEBUG_PRINTF("After SM_calibrate_and_reorder_f2");
218 :
219 6 : nbSMInASMNORM = (float)incomingMsg->numberOfSMInASMNORM;
220 :
221 : //*****
222 : //*****
223 : // NORM
224 : //*****
225 : //*****
226 : // 1) compress the matrix for Basic Parameters calculation
227 6 : ASM_compress_divide_and_mask(asm_f2_patched_norm, compressed_sm_norm_f2, nbSMInASMNORM,
228 : NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, ASM_F2_INDICE_START, CHANNELF2);
229 : // BP1_F2
230 6 : if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
231 : {
232 : // 1) compute the BP1 set
233 6 : compute_BP1(compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data);
234 :
235 : // 2) send the BP1 set
236 6 : set_time(packet_norm_bp1.time, (unsigned char*)&incomingMsg->coarseTimeNORM);
237 6 : set_time(packet_norm_bp1.acquisitionTime, (unsigned char*)&incomingMsg->coarseTimeNORM);
238 6 : packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
239 6 : packet_norm_bp1.sy_lfr_common_parameters
240 6 : = parameter_dump_packet.sy_lfr_common_parameters;
241 6 : BP_send((char*)&packet_norm_bp1, queue_id_send,
242 : PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA);
243 : }
244 : // BP2_F2
245 6 : if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
246 : {
247 : // 1) compute the BP2 set
248 0 : compute_BP2(compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data);
249 : // 2) send the BP2 set
250 0 : set_time(packet_norm_bp2.time, (unsigned char*)&incomingMsg->coarseTimeNORM);
251 0 : set_time(packet_norm_bp2.acquisitionTime, (unsigned char*)&incomingMsg->coarseTimeNORM);
252 0 : packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
253 0 : packet_norm_bp2.sy_lfr_common_parameters
254 0 : = parameter_dump_packet.sy_lfr_common_parameters;
255 0 : BP_send((char*)&packet_norm_bp2, queue_id_send,
256 : PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA);
257 : }
258 :
259 6 : if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
260 : {
261 : // 1) reorganize the ASM and divide
262 0 : ASM_divide(asm_f2_patched_norm,
263 0 : (float*)current_ring_node_to_send_asm_f2->buffer_address,
264 : (float)nb_sm_before_f2.norm_bp1, ASM_F2_INDICE_START,
265 : ASM_F2_INDICE_START + ASM_F2_KEEP_BINS);
266 0 : current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
267 0 : current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
268 0 : current_ring_node_to_send_asm_f2->packet_id = SID_NORM_ASM_F2;
269 :
270 : // 3) send the spectral matrix packets
271 0 : DEBUG_CHECK_STATUS(rtems_message_queue_send(
272 : queue_id_send, ¤t_ring_node_to_send_asm_f2, sizeof(ring_node*)));
273 :
274 : // change asm ring node
275 0 : current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
276 : DEBUG_CHECK_PTR(current_ring_node_to_send_asm_f2);
277 : }
278 :
279 6 : update_queue_max_count(queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max);
280 6 : }
281 : }
282 :
283 : //**********
284 : // FUNCTIONS
285 :
286 0 : void reset_nb_sm_f2(void)
287 : {
288 4 : nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
289 4 : nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
290 8 : nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256)
291 4 : + parameter_dump_packet.sy_lfr_n_asm_p[1];
292 0 : }
|