##// END OF EJS Templates
3.0.0.15
paul -
r258:1259d1eafcaf 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 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 DEFINES += SW_VERSION_N4=14 # internal
23 DEFINES += SW_VERSION_N4=15 # 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,1617 +1,1624
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 PRINTF("this is the end!!!\n")
150 exit(0);
149 PRINTF("this is the end!!!\n");
150 exit(0);
151
151 152 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
153
152 154 return LFR_DEFAULT;
153 155 }
154 156
155 157 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
156 158 {
157 159 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
158 160 *
159 161 * @param TC points to the TeleCommand packet that is being processed
160 162 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
161 163 *
162 164 */
163 165
164 166 rtems_status_code status;
165 167 unsigned char requestedMode;
166 168 unsigned int *transitionCoarseTime_ptr;
167 169 unsigned int transitionCoarseTime;
168 170 unsigned char * bytePosPtr;
169 171
170 172 bytePosPtr = (unsigned char *) &TC->packetID;
171 173
172 174 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
173 175 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
174 176 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
175 177
176 178 status = check_mode_value( requestedMode );
177 179
178 180 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
179 181 {
180 182 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
181 183 }
182 184
183 185 else // the mode value is valid, check the transition
184 186 {
185 187 status = check_mode_transition(requestedMode);
186 188 if (status != LFR_SUCCESSFUL)
187 189 {
188 190 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 191 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 192 }
191 193 }
192 194
193 195 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
194 196 {
195 197 status = check_transition_date( transitionCoarseTime );
196 198 if (status != LFR_SUCCESSFUL)
197 199 {
198 200 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
199 201 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
200 202 }
201 203 }
202 204
203 205 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
204 206 {
205 207 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
206 208
207 209 update_last_valid_transition_date( transitionCoarseTime );
208 210
209 211 switch(requestedMode)
210 212 {
211 213 case LFR_MODE_STANDBY:
212 214 status = enter_mode_standby();
213 215 break;
214 216 case LFR_MODE_NORMAL:
215 217 status = enter_mode_normal( transitionCoarseTime );
216 218 break;
217 219 case LFR_MODE_BURST:
218 220 status = enter_mode_burst( transitionCoarseTime );
219 221 break;
220 222 case LFR_MODE_SBM1:
221 223 status = enter_mode_sbm1( transitionCoarseTime );
222 224 break;
223 225 case LFR_MODE_SBM2:
224 226 status = enter_mode_sbm2( transitionCoarseTime );
225 227 break;
226 228 default:
227 229 break;
228 230 }
229 231 }
230 232
233 if (status != RTEMS_SUCCESSFUL)
234 {
235 status = LFR_EXE_ERROR;
236 }
237
231 238 return status;
232 239 }
233 240
234 241 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
235 242 {
236 243 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
237 244 *
238 245 * @param TC points to the TeleCommand packet that is being processed
239 246 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
240 247 *
241 248 * @return LFR directive status code:
242 249 * - LFR_DEFAULT
243 250 * - LFR_SUCCESSFUL
244 251 *
245 252 */
246 253
247 254 unsigned int val;
248 255 int result;
249 256 unsigned int status;
250 257 unsigned char mode;
251 258 unsigned char * bytePosPtr;
252 259
253 260 bytePosPtr = (unsigned char *) &TC->packetID;
254 261
255 262 // check LFR mode
256 263 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
257 264 status = check_update_info_hk_lfr_mode( mode );
258 265 if (status == LFR_SUCCESSFUL) // check TDS mode
259 266 {
260 267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
261 268 status = check_update_info_hk_tds_mode( mode );
262 269 }
263 270 if (status == LFR_SUCCESSFUL) // check THR mode
264 271 {
265 272 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
266 273 status = check_update_info_hk_thr_mode( mode );
267 274 }
268 275 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
269 276 {
270 277 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
271 278 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
272 279 val++;
273 280 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
274 281 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
275 282 }
276 283
277 284 // pa_bia_status_info
278 285 // => pa_bia_mode_mux_set 3 bits
279 286 // => pa_bia_mode_hv_enabled 1 bit
280 287 // => pa_bia_mode_bias1_enabled 1 bit
281 288 // => pa_bia_mode_bias2_enabled 1 bit
282 289 // => pa_bia_mode_bias3_enabled 1 bit
283 290 // => pa_bia_on_off (cp_dpu_bias_on_off)
284 291 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110]
285 292 pa_bia_status_info = pa_bia_status_info
286 293 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1);
287 294
288 295 result = status;
289 296
290 297 return result;
291 298 }
292 299
293 300 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
294 301 {
295 302 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
296 303 *
297 304 * @param TC points to the TeleCommand packet that is being processed
298 305 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
299 306 *
300 307 */
301 308
302 309 int result;
303 310
304 311 result = LFR_DEFAULT;
305 312
306 313 setCalibration( true );
307 314
308 315 result = LFR_SUCCESSFUL;
309 316
310 317 return result;
311 318 }
312 319
313 320 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 321 {
315 322 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
316 323 *
317 324 * @param TC points to the TeleCommand packet that is being processed
318 325 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
319 326 *
320 327 */
321 328
322 329 int result;
323 330
324 331 result = LFR_DEFAULT;
325 332
326 333 setCalibration( false );
327 334
328 335 result = LFR_SUCCESSFUL;
329 336
330 337 return result;
331 338 }
332 339
333 340 int action_update_time(ccsdsTelecommandPacket_t *TC)
334 341 {
335 342 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
336 343 *
337 344 * @param TC points to the TeleCommand packet that is being processed
338 345 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
339 346 *
340 347 * @return LFR_SUCCESSFUL
341 348 *
342 349 */
343 350
344 351 unsigned int val;
345 352
346 353 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
347 354 + (TC->dataAndCRC[1] << 16)
348 355 + (TC->dataAndCRC[2] << 8)
349 356 + TC->dataAndCRC[3];
350 357
351 358 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
352 359 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
353 360 val++;
354 361 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
355 362 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
356 363
357 364 return LFR_SUCCESSFUL;
358 365 }
359 366
360 367 //*******************
361 368 // ENTERING THE MODES
362 369 int check_mode_value( unsigned char requestedMode )
363 370 {
364 371 int status;
365 372
366 373 if ( (requestedMode != LFR_MODE_STANDBY)
367 374 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
368 375 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
369 376 {
370 377 status = LFR_DEFAULT;
371 378 }
372 379 else
373 380 {
374 381 status = LFR_SUCCESSFUL;
375 382 }
376 383
377 384 return status;
378 385 }
379 386
380 387 int check_mode_transition( unsigned char requestedMode )
381 388 {
382 389 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
383 390 *
384 391 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
385 392 *
386 393 * @return LFR directive status codes:
387 394 * - LFR_SUCCESSFUL - the transition is authorized
388 395 * - LFR_DEFAULT - the transition is not authorized
389 396 *
390 397 */
391 398
392 399 int status;
393 400
394 401 switch (requestedMode)
395 402 {
396 403 case LFR_MODE_STANDBY:
397 404 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
398 405 status = LFR_DEFAULT;
399 406 }
400 407 else
401 408 {
402 409 status = LFR_SUCCESSFUL;
403 410 }
404 411 break;
405 412 case LFR_MODE_NORMAL:
406 413 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
407 414 status = LFR_DEFAULT;
408 415 }
409 416 else {
410 417 status = LFR_SUCCESSFUL;
411 418 }
412 419 break;
413 420 case LFR_MODE_BURST:
414 421 if ( lfrCurrentMode == LFR_MODE_BURST ) {
415 422 status = LFR_DEFAULT;
416 423 }
417 424 else {
418 425 status = LFR_SUCCESSFUL;
419 426 }
420 427 break;
421 428 case LFR_MODE_SBM1:
422 429 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
423 430 status = LFR_DEFAULT;
424 431 }
425 432 else {
426 433 status = LFR_SUCCESSFUL;
427 434 }
428 435 break;
429 436 case LFR_MODE_SBM2:
430 437 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
431 438 status = LFR_DEFAULT;
432 439 }
433 440 else {
434 441 status = LFR_SUCCESSFUL;
435 442 }
436 443 break;
437 444 default:
438 445 status = LFR_DEFAULT;
439 446 break;
440 447 }
441 448
442 449 return status;
443 450 }
444 451
445 452 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
446 453 {
447 454 if (transitionCoarseTime == 0)
448 455 {
449 456 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
450 457 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", transitionCoarseTime);
451 458 }
452 459 else
453 460 {
454 461 lastValidEnterModeTime = transitionCoarseTime;
455 462 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
456 463 }
457 464 }
458 465
459 466 int check_transition_date( unsigned int transitionCoarseTime )
460 467 {
461 468 int status;
462 469 unsigned int localCoarseTime;
463 470 unsigned int deltaCoarseTime;
464 471
465 472 status = LFR_SUCCESSFUL;
466 473
467 474 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
468 475 {
469 476 status = LFR_SUCCESSFUL;
470 477 }
471 478 else
472 479 {
473 480 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
474 481
475 482 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
476 483
477 484 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
478 485 {
479 486 status = LFR_DEFAULT;
480 487 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
481 488 }
482 489
483 490 if (status == LFR_SUCCESSFUL)
484 491 {
485 492 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
486 493 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
487 494 {
488 495 status = LFR_DEFAULT;
489 496 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
490 497 }
491 498 }
492 499 }
493 500
494 501 return status;
495 502 }
496 503
497 504 int restart_asm_activities( unsigned char lfrRequestedMode )
498 505 {
499 506 rtems_status_code status;
500 507
501 508 status = stop_spectral_matrices();
502 509
503 510 status = restart_asm_tasks( lfrRequestedMode );
504 511
505 512 launch_spectral_matrix();
506 513
507 514 return status;
508 515 }
509 516
510 517 int stop_spectral_matrices( void )
511 518 {
512 519 /** This function stops and restarts the current mode average spectral matrices activities.
513 520 *
514 521 * @return RTEMS directive status codes:
515 522 * - RTEMS_SUCCESSFUL - task restarted successfully
516 523 * - RTEMS_INVALID_ID - task id invalid
517 524 * - RTEMS_ALREADY_SUSPENDED - task already suspended
518 525 *
519 526 */
520 527
521 528 rtems_status_code status;
522 529
523 530 status = RTEMS_SUCCESSFUL;
524 531
525 532 // (1) mask interruptions
526 533 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
527 534
528 535 // (2) reset spectral matrices registers
529 536 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
530 537 reset_sm_status();
531 538
532 539 // (3) clear interruptions
533 540 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
534 541
535 542 // suspend several tasks
536 543 if (lfrCurrentMode != LFR_MODE_STANDBY) {
537 544 status = suspend_asm_tasks();
538 545 }
539 546
540 547 if (status != RTEMS_SUCCESSFUL)
541 548 {
542 549 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
543 550 }
544 551
545 552 return status;
546 553 }
547 554
548 555 int stop_current_mode( void )
549 556 {
550 557 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
551 558 *
552 559 * @return RTEMS directive status codes:
553 560 * - RTEMS_SUCCESSFUL - task restarted successfully
554 561 * - RTEMS_INVALID_ID - task id invalid
555 562 * - RTEMS_ALREADY_SUSPENDED - task already suspended
556 563 *
557 564 */
558 565
559 566 rtems_status_code status;
560 567
561 568 status = RTEMS_SUCCESSFUL;
562 569
563 570 // (1) mask interruptions
564 571 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
565 572 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
566 573
567 574 // (2) reset waveform picker registers
568 575 reset_wfp_burst_enable(); // reset burst and enable bits
569 576 reset_wfp_status(); // reset all the status bits
570 577
571 578 // (3) reset spectral matrices registers
572 579 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
573 580 reset_sm_status();
574 581
575 582 // reset lfr VHDL module
576 583 reset_lfr();
577 584
578 585 reset_extractSWF(); // reset the extractSWF flag to false
579 586
580 587 // (4) clear interruptions
581 588 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
582 589 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
583 590
584 591 // suspend several tasks
585 592 if (lfrCurrentMode != LFR_MODE_STANDBY) {
586 593 status = suspend_science_tasks();
587 594 }
588 595
589 596 if (status != RTEMS_SUCCESSFUL)
590 597 {
591 598 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
592 599 }
593 600
594 601 return status;
595 602 }
596 603
597 604 int enter_mode_standby( void )
598 605 {
599 606 /** This function is used to put LFR in the STANDBY mode.
600 607 *
601 608 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
602 609 *
603 610 * @return RTEMS directive status codes:
604 611 * - RTEMS_SUCCESSFUL - task restarted successfully
605 612 * - RTEMS_INVALID_ID - task id invalid
606 613 * - RTEMS_INCORRECT_STATE - task never started
607 614 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
608 615 *
609 616 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
610 617 * is immediate.
611 618 *
612 619 */
613 620
614 621 int status;
615 622
616 623 status = stop_current_mode(); // STOP THE CURRENT MODE
617 624
618 625 #ifdef PRINT_TASK_STATISTICS
619 626 rtems_cpu_usage_report();
620 627 #endif
621 628
622 629 #ifdef PRINT_STACK_REPORT
623 630 PRINTF("stack report selected\n")
624 631 rtems_stack_checker_report_usage();
625 632 #endif
626 633
627 634 return status;
628 635 }
629 636
630 637 int enter_mode_normal( unsigned int transitionCoarseTime )
631 638 {
632 639 /** This function is used to start the NORMAL mode.
633 640 *
634 641 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
635 642 *
636 643 * @return RTEMS directive status codes:
637 644 * - RTEMS_SUCCESSFUL - task restarted successfully
638 645 * - RTEMS_INVALID_ID - task id invalid
639 646 * - RTEMS_INCORRECT_STATE - task never started
640 647 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
641 648 *
642 649 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
643 650 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
644 651 *
645 652 */
646 653
647 654 int status;
648 655
649 656 #ifdef PRINT_TASK_STATISTICS
650 657 rtems_cpu_usage_reset();
651 658 #endif
652 659
653 660 status = RTEMS_UNSATISFIED;
654 661
655 662 switch( lfrCurrentMode )
656 663 {
657 664 case LFR_MODE_STANDBY:
658 665 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
659 666 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
660 667 {
661 668 launch_spectral_matrix( );
662 669 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
663 670 }
664 671 break;
665 672 case LFR_MODE_BURST:
666 673 status = stop_current_mode(); // stop the current mode
667 674 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
668 675 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
669 676 {
670 677 launch_spectral_matrix( );
671 678 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
672 679 }
673 680 break;
674 681 case LFR_MODE_SBM1:
675 682 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
676 683 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
677 684 break;
678 685 case LFR_MODE_SBM2:
679 686 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
680 687 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
681 688 break;
682 689 default:
683 690 break;
684 691 }
685 692
686 693 if (status != RTEMS_SUCCESSFUL)
687 694 {
688 695 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
689 696 status = RTEMS_UNSATISFIED;
690 697 }
691 698
692 699 return status;
693 700 }
694 701
695 702 int enter_mode_burst( unsigned int transitionCoarseTime )
696 703 {
697 704 /** This function is used to start the BURST mode.
698 705 *
699 706 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
700 707 *
701 708 * @return RTEMS directive status codes:
702 709 * - RTEMS_SUCCESSFUL - task restarted successfully
703 710 * - RTEMS_INVALID_ID - task id invalid
704 711 * - RTEMS_INCORRECT_STATE - task never started
705 712 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
706 713 *
707 714 * The way the BURST mode is started does not depend on the LFR current mode.
708 715 *
709 716 */
710 717
711 718
712 719 int status;
713 720
714 721 #ifdef PRINT_TASK_STATISTICS
715 722 rtems_cpu_usage_reset();
716 723 #endif
717 724
718 725 status = stop_current_mode(); // stop the current mode
719 726 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
720 727 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
721 728 {
722 729 launch_spectral_matrix( );
723 730 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
724 731 }
725 732
726 733 if (status != RTEMS_SUCCESSFUL)
727 734 {
728 735 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
729 736 status = RTEMS_UNSATISFIED;
730 737 }
731 738
732 739 return status;
733 740 }
734 741
735 742 int enter_mode_sbm1( unsigned int transitionCoarseTime )
736 743 {
737 744 /** This function is used to start the SBM1 mode.
738 745 *
739 746 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
740 747 *
741 748 * @return RTEMS directive status codes:
742 749 * - RTEMS_SUCCESSFUL - task restarted successfully
743 750 * - RTEMS_INVALID_ID - task id invalid
744 751 * - RTEMS_INCORRECT_STATE - task never started
745 752 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
746 753 *
747 754 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
748 755 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
749 756 * cases, the acquisition is completely restarted.
750 757 *
751 758 */
752 759
753 760 int status;
754 761
755 762 #ifdef PRINT_TASK_STATISTICS
756 763 rtems_cpu_usage_reset();
757 764 #endif
758 765
759 766 status = RTEMS_UNSATISFIED;
760 767
761 768 switch( lfrCurrentMode )
762 769 {
763 770 case LFR_MODE_STANDBY:
764 771 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
765 772 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
766 773 {
767 774 launch_spectral_matrix( );
768 775 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
769 776 }
770 777 break;
771 778 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
772 779 restart_asm_activities( LFR_MODE_SBM1 );
773 780 status = LFR_SUCCESSFUL;
774 781 break;
775 782 case LFR_MODE_BURST:
776 783 status = stop_current_mode(); // stop the current mode
777 784 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
778 785 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
779 786 {
780 787 launch_spectral_matrix( );
781 788 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
782 789 }
783 790 break;
784 791 case LFR_MODE_SBM2:
785 792 restart_asm_activities( LFR_MODE_SBM1 );
786 793 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
787 794 break;
788 795 default:
789 796 break;
790 797 }
791 798
792 799 if (status <