##// END OF EJS Templates
3.0.0.14
paul -
r255:8000c9c61c45 R3a
parent child
Show More
@@ -1,124 +1,124
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 # lpp_dpu_destid REMOVE BEFORE DELIVERY TO LESIA
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 12 # debug_watchdog
13 13 CONFIG += console verbose lpp_dpu_destid
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=0 # minor
22 22 DEFINES += SW_VERSION_N3=0 # patch
23 23 DEFINES += SW_VERSION_N4=14 # 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/TC_types.h \
120 120 ../header/lfr_common_headers/tm_byte_positions.h \
121 121 ../LFR_basic-parameters/basic_parameters.h \
122 122 ../LFR_basic-parameters/basic_parameters_params.h \
123 123 ../header/GscMemoryLPP.hpp
124 124
@@ -1,1606 +1,1606
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14 #include "math.h"
15 15
16 16 //***********
17 17 // RTEMS TASK
18 18
19 19 rtems_task actn_task( rtems_task_argument unused )
20 20 {
21 21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 22 *
23 23 * @param unused is the starting argument of the RTEMS task
24 24 *
25 25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 26 * on the incoming TeleCommand.
27 27 *
28 28 */
29 29
30 30 int result;
31 31 rtems_status_code status; // RTEMS status code
32 32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 33 size_t size; // size of the incoming TC packet
34 34 unsigned char subtype; // subtype of the current TC packet
35 35 unsigned char time[6];
36 36 rtems_id queue_rcv_id;
37 37 rtems_id queue_snd_id;
38 38
39 39 status = get_message_queue_id_recv( &queue_rcv_id );
40 40 if (status != RTEMS_SUCCESSFUL)
41 41 {
42 42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
43 43 }
44 44
45 45 status = get_message_queue_id_send( &queue_snd_id );
46 46 if (status != RTEMS_SUCCESSFUL)
47 47 {
48 48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
49 49 }
50 50
51 51 result = LFR_SUCCESSFUL;
52 52 subtype = 0; // subtype of the current TC packet
53 53
54 54 BOOT_PRINTF("in ACTN *** \n")
55 55
56 56 while(1)
57 57 {
58 58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 60 getTime( time ); // set time to the current time
61 61 if (status!=RTEMS_SUCCESSFUL)
62 62 {
63 63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
64 64 }
65 65 else
66 66 {
67 67 subtype = TC.serviceSubType;
68 68 switch(subtype)
69 69 {
70 70 case TC_SUBTYPE_RESET:
71 71 result = action_reset( &TC, queue_snd_id, time );
72 72 close_action( &TC, result, queue_snd_id );
73 73 break;
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id );
77 77 break;
78 78 case TC_SUBTYPE_LOAD_NORM:
79 79 result = action_load_normal_par( &TC, queue_snd_id, time );
80 80 close_action( &TC, result, queue_snd_id );
81 81 break;
82 82 case TC_SUBTYPE_LOAD_BURST:
83 83 result = action_load_burst_par( &TC, queue_snd_id, time );
84 84 close_action( &TC, result, queue_snd_id );
85 85 break;
86 86 case TC_SUBTYPE_LOAD_SBM1:
87 87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 88 close_action( &TC, result, queue_snd_id );
89 89 break;
90 90 case TC_SUBTYPE_LOAD_SBM2:
91 91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 92 close_action( &TC, result, queue_snd_id );
93 93 break;
94 94 case TC_SUBTYPE_DUMP:
95 95 result = action_dump_par( &TC, queue_snd_id );
96 96 close_action( &TC, result, queue_snd_id );
97 97 break;
98 98 case TC_SUBTYPE_ENTER:
99 99 result = action_enter_mode( &TC, queue_snd_id );
100 100 close_action( &TC, result, queue_snd_id );
101 101 break;
102 102 case TC_SUBTYPE_UPDT_INFO:
103 103 result = action_update_info( &TC, queue_snd_id );
104 104 close_action( &TC, result, queue_snd_id );
105 105 break;
106 106 case TC_SUBTYPE_EN_CAL:
107 107 result = action_enable_calibration( &TC, queue_snd_id, time );
108 108 close_action( &TC, result, queue_snd_id );
109 109 break;
110 110 case TC_SUBTYPE_DIS_CAL:
111 111 result = action_disable_calibration( &TC, queue_snd_id, time );
112 112 close_action( &TC, result, queue_snd_id );
113 113 break;
114 114 case TC_SUBTYPE_LOAD_K:
115 115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
116 116 close_action( &TC, result, queue_snd_id );
117 117 break;
118 118 case TC_SUBTYPE_DUMP_K:
119 119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
120 120 close_action( &TC, result, queue_snd_id );
121 121 break;
122 122 case TC_SUBTYPE_LOAD_FBINS:
123 123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
124 124 close_action( &TC, result, queue_snd_id );
125 125 break;
126 126 case TC_SUBTYPE_UPDT_TIME:
127 127 result = action_update_time( &TC );
128 128 close_action( &TC, result, queue_snd_id );
129 129 break;
130 130 default:
131 131 break;
132 132 }
133 133 }
134 134 }
135 135 }
136 136
137 137 //***********
138 138 // TC ACTIONS
139 139
140 140 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
141 141 {
142 142 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
143 143 *
144 144 * @param TC points to the TeleCommand packet that is being processed
145 145 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
146 146 *
147 147 */
148 148
149 149 PRINTF("this is the end!!!\n")
150 150 exit(0);
151 151 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
152 152 return LFR_DEFAULT;
153 153 }
154 154
155 155 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
156 156 {
157 157 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
158 158 *
159 159 * @param TC points to the TeleCommand packet that is being processed
160 160 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
161 161 *
162 162 */
163 163
164 164 rtems_status_code status;
165 165 unsigned char requestedMode;
166 166 unsigned int *transitionCoarseTime_ptr;
167 167 unsigned int transitionCoarseTime;
168 168 unsigned char * bytePosPtr;
169 169
170 170 bytePosPtr = (unsigned char *) &TC->packetID;
171 171
172 172 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
173 173 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
174 174 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
175 175
176 176 status = check_mode_value( requestedMode );
177 177
178 178 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
179 179 {
180 180 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
181 181 }
182 182
183 183 else // the mode value is valid, check the transition
184 184 {
185 185 status = check_mode_transition(requestedMode);
186 186 if (status != LFR_SUCCESSFUL)
187 187 {
188 188 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 189 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 190 }
191 191 }
192 192
193 193 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
194 194 {
195 195 status = check_transition_date( transitionCoarseTime );
196 196 if (status != LFR_SUCCESSFUL)
197 197 {
198 198 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
199 199 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
200 200 }
201 201 }
202 202
203 203 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
204 204 {
205 205 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
206 206
207 207 update_last_valid_transition_date( transitionCoarseTime );
208 208
209 209 switch(requestedMode)
210 210 {
211 211 case LFR_MODE_STANDBY:
212 212 status = enter_mode_standby();
213 213 break;
214 214 case LFR_MODE_NORMAL:
215 215 status = enter_mode_normal( transitionCoarseTime );
216 216 break;
217 217 case LFR_MODE_BURST:
218 218 status = enter_mode_burst( transitionCoarseTime );
219 219 break;
220 220 case LFR_MODE_SBM1:
221 221 status = enter_mode_sbm1( transitionCoarseTime );
222 222 break;
223 223 case LFR_MODE_SBM2:
224 224 status = enter_mode_sbm2( transitionCoarseTime );
225 225 break;
226 226 default:
227 227 break;
228 228 }
229 229 }
230 230
231 231 return status;
232 232 }
233 233
234 234 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
235 235 {
236 236 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
237 237 *
238 238 * @param TC points to the TeleCommand packet that is being processed
239 239 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
240 240 *
241 241 * @return LFR directive status code:
242 242 * - LFR_DEFAULT
243 243 * - LFR_SUCCESSFUL
244 244 *
245 245 */
246 246
247 247 unsigned int val;
248 248 int result;
249 249 unsigned int status;
250 250 unsigned char mode;
251 251 unsigned char * bytePosPtr;
252 252
253 253 bytePosPtr = (unsigned char *) &TC->packetID;
254 254
255 255 // check LFR mode
256 256 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
257 257 status = check_update_info_hk_lfr_mode( mode );
258 258 if (status == LFR_SUCCESSFUL) // check TDS mode
259 259 {
260 260 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
261 261 status = check_update_info_hk_tds_mode( mode );
262 262 }
263 263 if (status == LFR_SUCCESSFUL) // check THR mode
264 264 {
265 265 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
266 266 status = check_update_info_hk_thr_mode( mode );
267 267 }
268 268 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
269 269 {
270 270 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
271 271 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
272 272 val++;
273 273 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
274 274 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
275 275 }
276 276
277 277 // pa_bia_status_info
278 278 // => pa_bia_mode_mux_set 3 bits
279 279 // => pa_bia_mode_hv_enabled 1 bit
280 280 // => pa_bia_mode_bias1_enabled 1 bit
281 281 // => pa_bia_mode_bias2_enabled 1 bit
282 282 // => pa_bia_mode_bias3_enabled 1 bit
283 283 // => pa_bia_on_off (cp_dpu_bias_on_off)
284 284 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110]
285 285 pa_bia_status_info = pa_bia_status_info
286 286 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1);
287 287
288 288 result = status;
289 289
290 290 return result;
291 291 }
292 292
293 293 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
294 294 {
295 295 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
296 296 *
297 297 * @param TC points to the TeleCommand packet that is being processed
298 298 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
299 299 *
300 300 */
301 301
302 302 int result;
303 303
304 304 result = LFR_DEFAULT;
305 305
306 306 setCalibration( true );
307 307
308 308 result = LFR_SUCCESSFUL;
309 309
310 310 return result;
311 311 }
312 312
313 313 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 314 {
315 315 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
316 316 *
317 317 * @param TC points to the TeleCommand packet that is being processed
318 318 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
319 319 *
320 320 */
321 321
322 322 int result;
323 323
324 324 result = LFR_DEFAULT;
325 325
326 326 setCalibration( false );
327 327
328 328 result = LFR_SUCCESSFUL;
329 329
330 330 return result;
331 331 }
332 332
333 333 int action_update_time(ccsdsTelecommandPacket_t *TC)
334 334 {
335 335 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
336 336 *
337 337 * @param TC points to the TeleCommand packet that is being processed
338 338 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
339 339 *
340 340 * @return LFR_SUCCESSFUL
341 341 *
342 342 */
343 343
344 344 unsigned int val;
345 345
346 346 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
347 347 + (TC->dataAndCRC[1] << 16)
348 348 + (TC->dataAndCRC[2] << 8)
349 349 + TC->dataAndCRC[3];
350 350
351 351 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
352 352 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
353 353 val++;
354 354 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
355 355 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
356 356
357 357 return LFR_SUCCESSFUL;
358 358 }
359 359
360 360 //*******************
361 361 // ENTERING THE MODES
362 362 int check_mode_value( unsigned char requestedMode )
363 363 {
364 364 int status;
365 365
366 366 if ( (requestedMode != LFR_MODE_STANDBY)
367 367 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
368 368 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
369 369 {
370 370 status = LFR_DEFAULT;
371 371 }
372 372 else
373 373 {
374 374 status = LFR_SUCCESSFUL;
375 375 }
376 376
377 377 return status;
378 378 }
379 379
380 380 int check_mode_transition( unsigned char requestedMode )
381 381 {
382 382 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
383 383 *
384 384 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
385 385 *
386 386 * @return LFR directive status codes:
387 387 * - LFR_SUCCESSFUL - the transition is authorized
388 388 * - LFR_DEFAULT - the transition is not authorized
389 389 *
390 390 */
391 391
392 392 int status;
393 393
394 394 switch (requestedMode)
395 395 {
396 396 case LFR_MODE_STANDBY:
397 397 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
398 398 status = LFR_DEFAULT;
399 399 }
400 400 else
401 401 {
402 402 status = LFR_SUCCESSFUL;
403 403 }
404 404 break;
405 405 case LFR_MODE_NORMAL:
406 406 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
407 407 status = LFR_DEFAULT;
408 408 }
409 409 else {
410 410 status = LFR_SUCCESSFUL;
411 411 }
412 412 break;
413 413 case LFR_MODE_BURST:
414 414 if ( lfrCurrentMode == LFR_MODE_BURST ) {
415 415 status = LFR_DEFAULT;
416 416 }
417 417 else {
418 418 status = LFR_SUCCESSFUL;
419 419 }
420 420 break;
421 421 case LFR_MODE_SBM1:
422 422 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
423 423 status = LFR_DEFAULT;
424 424 }
425 425 else {
426 426 status = LFR_SUCCESSFUL;
427 427 }
428 428 break;
429 429 case LFR_MODE_SBM2:
430 430 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
431 431 status = LFR_DEFAULT;
432 432 }
433 433 else {
434 434 status = LFR_SUCCESSFUL;
435 435 }
436 436 break;
437 437 default:
438 438 status = LFR_DEFAULT;
439 439 break;
440 440 }
441 441
442 442 return status;
443 443 }
444 444
445 445 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
446 446 {
447 447 lastValidEnterModeTime = transitionCoarseTime;
448 PRINTF1("lastValidEnterModeTime = %x\n", transitionCoarseTime);
448 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
449 449 }
450 450
451 451 int check_transition_date( unsigned int transitionCoarseTime )
452 452 {
453 453 int status;
454 454 unsigned int localCoarseTime;
455 455 unsigned int deltaCoarseTime;
456 456
457 457 status = LFR_SUCCESSFUL;
458 458
459 459 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
460 460 {
461 461 status = LFR_SUCCESSFUL;
462 462 }
463 463 else
464 464 {
465 465 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
466 466
467 467 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
468 468
469 469 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
470 470 {
471 471 status = LFR_DEFAULT;
472 472 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
473 473 }
474 474
475 475 if (status == LFR_SUCCESSFUL)
476 476 {
477 477 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
478 478 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
479 479 {
480 480 status = LFR_DEFAULT;
481 481 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
482 482 }
483 483 }
484 484 }
485 485
486 486 return status;
487 487 }
488 488
489 489 int restart_asm_activities( unsigned char lfrRequestedMode )
490 490 {
491 491 rtems_status_code status;
492 492
493 493 status = stop_spectral_matrices();
494 494
495 495 status = restart_asm_tasks( lfrRequestedMode );
496 496
497 497 launch_spectral_matrix();
498 498
499 499 return status;
500 500 }
501 501
502 502 int stop_spectral_matrices( void )
503 503 {
504 504 /** This function stops and restarts the current mode average spectral matrices activities.
505 505 *
506 506 * @return RTEMS directive status codes:
507 507 * - RTEMS_SUCCESSFUL - task restarted successfully
508 508 * - RTEMS_INVALID_ID - task id invalid
509 509 * - RTEMS_ALREADY_SUSPENDED - task already suspended
510 510 *
511 511 */
512 512
513 513 rtems_status_code status;
514 514
515 515 status = RTEMS_SUCCESSFUL;
516 516
517 517 // (1) mask interruptions
518 518 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
519 519
520 520 // (2) reset spectral matrices registers
521 521 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
522 522 reset_sm_status();
523 523
524 524 // (3) clear interruptions
525 525 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
526 526
527 527 // suspend several tasks
528 528 if (lfrCurrentMode != LFR_MODE_STANDBY) {
529 529 status = suspend_asm_tasks();
530 530 }
531 531
532 532 if (status != RTEMS_SUCCESSFUL)
533 533 {
534 534 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
535 535 }
536 536
537 537 return status;
538 538 }
539 539
540 540 int stop_current_mode( void )
541 541 {
542 542 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
543 543 *
544 544 * @return RTEMS directive status codes:
545 545 * - RTEMS_SUCCESSFUL - task restarted successfully
546 546 * - RTEMS_INVALID_ID - task id invalid
547 547 * - RTEMS_ALREADY_SUSPENDED - task already suspended
548 548 *
549 549 */
550 550
551 551 rtems_status_code status;
552 552
553 553 status = RTEMS_SUCCESSFUL;
554 554
555 555 // (1) mask interruptions
556 556 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
557 557 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
558 558
559 559 // (2) reset waveform picker registers
560 560 reset_wfp_burst_enable(); // reset burst and enable bits
561 561 reset_wfp_status(); // reset all the status bits
562 562
563 563 // (3) reset spectral matrices registers
564 564 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
565 565 reset_sm_status();
566 566
567 567 // reset lfr VHDL module
568 568 reset_lfr();
569 569
570 570 reset_extractSWF(); // reset the extractSWF flag to false
571 571
572 572 // (4) clear interruptions
573 573 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
574 574 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
575 575
576 576 // suspend several tasks
577 577 if (lfrCurrentMode != LFR_MODE_STANDBY) {
578 578 status = suspend_science_tasks();
579 579 }
580 580
581 581 if (status != RTEMS_SUCCESSFUL)
582 582 {
583 583 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
584 584 }
585 585
586 586 return status;
587 587 }
588 588
589 589 int enter_mode_standby( void )
590 590 {
591 591 /** This function is used to put LFR in the STANDBY mode.
592 592 *
593 593 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
594 594 *
595 595 * @return RTEMS directive status codes:
596 596 * - RTEMS_SUCCESSFUL - task restarted successfully
597 597 * - RTEMS_INVALID_ID - task id invalid
598 598 * - RTEMS_INCORRECT_STATE - task never started
599 599 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
600 600 *
601 601 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
602 602 * is immediate.
603 603 *
604 604 */
605 605
606 606 int status;
607 607
608 608 status = stop_current_mode(); // STOP THE CURRENT MODE
609 609
610 610 #ifdef PRINT_TASK_STATISTICS
611 611 rtems_cpu_usage_report();
612 612 #endif
613 613
614 614 #ifdef PRINT_STACK_REPORT
615 615 PRINTF("stack report selected\n")
616 616 rtems_stack_checker_report_usage();
617 617 #endif
618 618
619 619 return status;
620 620 }
621 621
622 622 int enter_mode_normal( unsigned int transitionCoarseTime )
623 623 {
624 624 /** This function is used to start the NORMAL mode.
625 625 *
626 626 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
627 627 *
628 628 * @return RTEMS directive status codes:
629 629 * - RTEMS_SUCCESSFUL - task restarted successfully
630 630 * - RTEMS_INVALID_ID - task id invalid
631 631 * - RTEMS_INCORRECT_STATE - task never started
632 632 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
633 633 *
634 634 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
635 635 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
636 636 *
637 637 */
638 638
639 639 int status;
640 640
641 641 #ifdef PRINT_TASK_STATISTICS
642 642 rtems_cpu_usage_reset();
643 643 #endif
644 644
645 645 status = RTEMS_UNSATISFIED;
646 646
647 647 switch( lfrCurrentMode )
648 648 {
649 649 case LFR_MODE_STANDBY:
650 650 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
651 651 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
652 652 {
653 653 launch_spectral_matrix( );
654 654 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
655 655 }
656 656 break;
657 657 case LFR_MODE_BURST:
658 658 status = stop_current_mode(); // stop the current mode
659 659 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
660 660 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
661 661 {
662 662 launch_spectral_matrix( );
663 663 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
664 664 }
665 665 break;
666 666 case LFR_MODE_SBM1:
667 667 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
668 668 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
669 669 break;
670 670 case LFR_MODE_SBM2:
671 671 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
672 672 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
673 673 break;
674 674 default:
675 675 break;
676 676 }
677 677
678 678 if (status != RTEMS_SUCCESSFUL)
679 679 {
680 680 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
681 681 status = RTEMS_UNSATISFIED;
682 682 }
683 683
684 684 return status;
685 685 }
686 686
687 687 int enter_mode_burst( unsigned int transitionCoarseTime )
688 688 {
689 689 /** This function is used to start the BURST mode.
690 690 *
691 691 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
692 692 *
693 693 * @return RTEMS directive status codes:
694 694 * - RTEMS_SUCCESSFUL - task restarted successfully
695 695 * - RTEMS_INVALID_ID - task id invalid
696 696 * - RTEMS_INCORRECT_STATE - task never started
697 697 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
698 698 *
699 699 * The way the BURST mode is started does not depend on the LFR current mode.
700 700 *
701 701 */
702 702
703 703
704 704 int status;
705 705
706 706 #ifdef PRINT_TASK_STATISTICS
707 707 rtems_cpu_usage_reset();
708 708 #endif
709 709
710 710 status = stop_current_mode(); // stop the current mode
711 711 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
712 712 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
713 713 {
714 714 launch_spectral_matrix( );
715 715 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
716 716 }
717 717
718 718 if (status != RTEMS_SUCCESSFUL)
719 719 {
720 720 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
721 721 status = RTEMS_UNSATISFIED;
722 722 }
723 723
724 724 return status;
725 725 }
726 726
727 727 int enter_mode_sbm1( unsigned int transitionCoarseTime )
728 728 {
729 729 /** This function is used to start the SBM1 mode.
730 730 *
731 731 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
732 732 *
733 733 * @return RTEMS directive status codes:
734 734 * - RTEMS_SUCCESSFUL - task restarted successfully
735 735 * - RTEMS_INVALID_ID - task id invalid
736 736 * - RTEMS_INCORRECT_STATE - task never started
737 737 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
738 738 *
739 739 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
740 740 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
741 741 * cases, the acquisition is completely restarted.
742 742 *
743 743 */
744 744
745 745 int status;
746 746
747 747 #ifdef PRINT_TASK_STATISTICS
748 748 rtems_cpu_usage_reset();
749 749 #endif
750 750
751 751 status = RTEMS_UNSATISFIED;
752 752
753 753 switch( lfrCurrentMode )
754 754 {
755 755 case LFR_MODE_STANDBY:
756 756 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
757 757 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
758 758 {
759 759 launch_spectral_matrix( );
760 760 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
761 761 }
762 762 break;
763 763 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
764 764 restart_asm_activities( LFR_MODE_SBM1 );
765 765 status = LFR_SUCCESSFUL;
766 766 break;
767 767 case LFR_MODE_BURST:
768 768 status = stop_current_mode(); // stop the current mode
769 769 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
770 770 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
771 771 {
772 772 launch_spectral_matrix( );
773 773 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
774 774 }
775 775 break;
776 776 case LFR_MODE_SBM2:
777 777 restart_asm_activities( LFR_MODE_SBM1 );
778 778 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
779 779 break;
780 780 default:
781 781 break;
782 782 }
783 783
784 784 if (status != RTEMS_SUCCESSFUL)
785 785 {
786 786 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status)
787 787 status = RTEMS_UNSATISFIED;
788 788 }
789 789
790 790 return status;
791 791 }
792 792
793 793 int enter_mode_sbm2( unsigned int transitionCoarseTime )
794 794 {
795 795 /** This function is used to start the SBM2 mode.
796 796 *
797 797 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
798 798 *