##// END OF EJS Templates
bug corrected TC_LFR_LOAD_KCOEFFICIENTS with sy_lfr_kcoeff_frequency >= 24
paul -
r207:8a50b41b6c0c R3
parent child
Show More
@@ -1,1175 +1,1174
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( 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 printf("TC_SUBTYPE_LOAD_K\n");
116 115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
117 116 close_action( &TC, result, queue_snd_id );
118 117 break;
119 118 case TC_SUBTYPE_DUMP_K:
120 119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
121 120 close_action( &TC, result, queue_snd_id );
122 121 break;
123 122 case TC_SUBTYPE_LOAD_FBINS:
124 123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
125 124 close_action( &TC, result, queue_snd_id );
126 125 break;
127 126 case TC_SUBTYPE_UPDT_TIME:
128 127 result = action_update_time( &TC );
129 128 close_action( &TC, result, queue_snd_id );
130 129 break;
131 130 default:
132 131 break;
133 132 }
134 133 }
135 134 }
136 135 }
137 136
138 137 //***********
139 138 // TC ACTIONS
140 139
141 140 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
142 141 {
143 142 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
144 143 *
145 144 * @param TC points to the TeleCommand packet that is being processed
146 145 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
147 146 *
148 147 */
149 148
150 149 printf("this is the end!!!\n");
151 150 exit(0);
152 151 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
153 152 return LFR_DEFAULT;
154 153 }
155 154
156 155 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
157 156 {
158 157 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
159 158 *
160 159 * @param TC points to the TeleCommand packet that is being processed
161 160 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
162 161 *
163 162 */
164 163
165 164 rtems_status_code status;
166 165 unsigned char requestedMode;
167 166 unsigned int *transitionCoarseTime_ptr;
168 167 unsigned int transitionCoarseTime;
169 168 unsigned char * bytePosPtr;
170 169
171 170 bytePosPtr = (unsigned char *) &TC->packetID;
172 171
173 172 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
174 173 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
175 174 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
176 175
177 176 status = check_mode_value( requestedMode );
178 177
179 178 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
180 179 {
181 180 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
182 181 }
183 182 else // the mode value is consistent, check the transition
184 183 {
185 184 status = check_mode_transition(requestedMode);
186 185 if (status != LFR_SUCCESSFUL)
187 186 {
188 187 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 188 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 189 }
191 190 }
192 191
193 192 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
194 193 {
195 194 status = check_transition_date( transitionCoarseTime );
196 195 if (status != LFR_SUCCESSFUL)
197 196 {
198 197 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
199 198 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
200 199 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
201 200 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
202 201 }
203 202 }
204 203
205 204 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
206 205 {
207 206 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
208 207 status = enter_mode( requestedMode, transitionCoarseTime );
209 208 }
210 209
211 210 return status;
212 211 }
213 212
214 213 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
215 214 {
216 215 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
217 216 *
218 217 * @param TC points to the TeleCommand packet that is being processed
219 218 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
220 219 *
221 220 * @return LFR directive status code:
222 221 * - LFR_DEFAULT
223 222 * - LFR_SUCCESSFUL
224 223 *
225 224 */
226 225
227 226 unsigned int val;
228 227 int result;
229 228 unsigned int status;
230 229 unsigned char mode;
231 230 unsigned char * bytePosPtr;
232 231
233 232 bytePosPtr = (unsigned char *) &TC->packetID;
234 233
235 234 // check LFR mode
236 235 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
237 236 status = check_update_info_hk_lfr_mode( mode );
238 237 if (status == LFR_SUCCESSFUL) // check TDS mode
239 238 {
240 239 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
241 240 status = check_update_info_hk_tds_mode( mode );
242 241 }
243 242 if (status == LFR_SUCCESSFUL) // check THR mode
244 243 {
245 244 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
246 245 status = check_update_info_hk_thr_mode( mode );
247 246 }
248 247 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
249 248 {
250 249 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
251 250 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
252 251 val++;
253 252 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
254 253 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
255 254 }
256 255
257 256 result = status;
258 257
259 258 return result;
260 259 }
261 260
262 261 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
263 262 {
264 263 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
265 264 *
266 265 * @param TC points to the TeleCommand packet that is being processed
267 266 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
268 267 *
269 268 */
270 269
271 270 int result;
272 271
273 272 result = LFR_DEFAULT;
274 273
275 274 setCalibration( true );
276 275
277 276 result = LFR_SUCCESSFUL;
278 277
279 278 return result;
280 279 }
281 280
282 281 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
283 282 {
284 283 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
285 284 *
286 285 * @param TC points to the TeleCommand packet that is being processed
287 286 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
288 287 *
289 288 */
290 289
291 290 int result;
292 291
293 292 result = LFR_DEFAULT;
294 293
295 294 setCalibration( false );
296 295
297 296 result = LFR_SUCCESSFUL;
298 297
299 298 return result;
300 299 }
301 300
302 301 int action_update_time(ccsdsTelecommandPacket_t *TC)
303 302 {
304 303 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
305 304 *
306 305 * @param TC points to the TeleCommand packet that is being processed
307 306 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
308 307 *
309 308 * @return LFR_SUCCESSFUL
310 309 *
311 310 */
312 311
313 312 unsigned int val;
314 313
315 314 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
316 315 + (TC->dataAndCRC[1] << 16)
317 316 + (TC->dataAndCRC[2] << 8)
318 317 + TC->dataAndCRC[3];
319 318
320 319 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 320 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 321 val++;
323 322 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
324 323 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325 324
326 325 return LFR_SUCCESSFUL;
327 326 }
328 327
329 328 //*******************
330 329 // ENTERING THE MODES
331 330 int check_mode_value( unsigned char requestedMode )
332 331 {
333 332 int status;
334 333
335 334 if ( (requestedMode != LFR_MODE_STANDBY)
336 335 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
337 336 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
338 337 {
339 338 status = LFR_DEFAULT;
340 339 }
341 340 else
342 341 {
343 342 status = LFR_SUCCESSFUL;
344 343 }
345 344
346 345 return status;
347 346 }
348 347
349 348 int check_mode_transition( unsigned char requestedMode )
350 349 {
351 350 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
352 351 *
353 352 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
354 353 *
355 354 * @return LFR directive status codes:
356 355 * - LFR_SUCCESSFUL - the transition is authorized
357 356 * - LFR_DEFAULT - the transition is not authorized
358 357 *
359 358 */
360 359
361 360 int status;
362 361
363 362 switch (requestedMode)
364 363 {
365 364 case LFR_MODE_STANDBY:
366 365 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
367 366 status = LFR_DEFAULT;
368 367 }
369 368 else
370 369 {
371 370 status = LFR_SUCCESSFUL;
372 371 }
373 372 break;
374 373 case LFR_MODE_NORMAL:
375 374 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
376 375 status = LFR_DEFAULT;
377 376 }
378 377 else {
379 378 status = LFR_SUCCESSFUL;
380 379 }
381 380 break;
382 381 case LFR_MODE_BURST:
383 382 if ( lfrCurrentMode == LFR_MODE_BURST ) {
384 383 status = LFR_DEFAULT;
385 384 }
386 385 else {
387 386 status = LFR_SUCCESSFUL;
388 387 }
389 388 break;
390 389 case LFR_MODE_SBM1:
391 390 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
392 391 status = LFR_DEFAULT;
393 392 }
394 393 else {
395 394 status = LFR_SUCCESSFUL;
396 395 }
397 396 break;
398 397 case LFR_MODE_SBM2:
399 398 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
400 399 status = LFR_DEFAULT;
401 400 }
402 401 else {
403 402 status = LFR_SUCCESSFUL;
404 403 }
405 404 break;
406 405 default:
407 406 status = LFR_DEFAULT;
408 407 break;
409 408 }
410 409
411 410 return status;
412 411 }
413 412
414 413 int check_transition_date( unsigned int transitionCoarseTime )
415 414 {
416 415 int status;
417 416 unsigned int localCoarseTime;
418 417 unsigned int deltaCoarseTime;
419 418
420 419 status = LFR_SUCCESSFUL;
421 420
422 421 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
423 422 {
424 423 status = LFR_SUCCESSFUL;
425 424 }
426 425 else
427 426 {
428 427 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
429 428
430 429 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime)
431 430
432 431 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
433 432 {
434 433 status = LFR_DEFAULT;
435 434 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n")
436 435 }
437 436
438 437 if (status == LFR_SUCCESSFUL)
439 438 {
440 439 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
441 440 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
442 441 {
443 442 status = LFR_DEFAULT;
444 443 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
445 444 }
446 445 }
447 446 }
448 447
449 448 return status;
450 449 }
451 450
452 451 int stop_current_mode( void )
453 452 {
454 453 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
455 454 *
456 455 * @return RTEMS directive status codes:
457 456 * - RTEMS_SUCCESSFUL - task restarted successfully
458 457 * - RTEMS_INVALID_ID - task id invalid
459 458 * - RTEMS_ALREADY_SUSPENDED - task already suspended
460 459 *
461 460 */
462 461
463 462 rtems_status_code status;
464 463
465 464 status = RTEMS_SUCCESSFUL;
466 465
467 466 // (1) mask interruptions
468 467 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
469 468 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
470 469
471 470 // (2) reset waveform picker registers
472 471 reset_wfp_burst_enable(); // reset burst and enable bits
473 472 reset_wfp_status(); // reset all the status bits
474 473
475 474 // (3) reset spectral matrices registers
476 475 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
477 476 reset_sm_status();
478 477
479 478 // reset lfr VHDL module
480 479 reset_lfr();
481 480
482 481 reset_extractSWF(); // reset the extractSWF flag to false
483 482
484 483 // (4) clear interruptions
485 484 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
486 485 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
487 486
488 487 // <Spectral Matrices simulator>
489 488 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
490 489 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
491 490 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
492 491 // </Spectral Matrices simulator>
493 492
494 493 // suspend several tasks
495 494 if (lfrCurrentMode != LFR_MODE_STANDBY) {
496 495 status = suspend_science_tasks();
497 496 }
498 497
499 498 if (status != RTEMS_SUCCESSFUL)
500 499 {
501 500 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
502 501 }
503 502
504 503 return status;
505 504 }
506 505
507 506 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
508 507 {
509 508 /** This function is launched after a mode transition validation.
510 509 *
511 510 * @param mode is the mode in which LFR will be put.
512 511 *
513 512 * @return RTEMS directive status codes:
514 513 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
515 514 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
516 515 *
517 516 */
518 517
519 518 rtems_status_code status;
520 519
521 520 //**********************
522 521 // STOP THE CURRENT MODE
523 522 status = stop_current_mode();
524 523 if (status != RTEMS_SUCCESSFUL)
525 524 {
526 525 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
527 526 }
528 527
529 528 //*************************
530 529 // ENTER THE REQUESTED MODE
531 530 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
532 531 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
533 532 {
534 533 #ifdef PRINT_TASK_STATISTICS
535 534 rtems_cpu_usage_reset();
536 535 #endif
537 536 status = restart_science_tasks( mode );
538 537 launch_spectral_matrix( );
539 538 launch_waveform_picker( mode, transitionCoarseTime );
540 539 // launch_spectral_matrix_simu( );
541 540 }
542 541 else if ( mode == LFR_MODE_STANDBY )
543 542 {
544 543 #ifdef PRINT_TASK_STATISTICS
545 544 rtems_cpu_usage_report();
546 545 #endif
547 546
548 547 #ifdef PRINT_STACK_REPORT
549 548 PRINTF("stack report selected\n")
550 549 rtems_stack_checker_report_usage();
551 550 #endif
552 551 }
553 552 else
554 553 {
555 554 status = RTEMS_UNSATISFIED;
556 555 }
557 556
558 557 if (status != RTEMS_SUCCESSFUL)
559 558 {
560 559 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
561 560 status = RTEMS_UNSATISFIED;
562 561 }
563 562
564 563 return status;
565 564 }
566 565
567 566 int restart_science_tasks(unsigned char lfrRequestedMode )
568 567 {
569 568 /** This function is used to restart all science tasks.
570 569 *
571 570 * @return RTEMS directive status codes:
572 571 * - RTEMS_SUCCESSFUL - task restarted successfully
573 572 * - RTEMS_INVALID_ID - task id invalid
574 573 * - RTEMS_INCORRECT_STATE - task never started
575 574 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 575 *
577 576 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
578 577 *
579 578 */
580 579
581 580 rtems_status_code status[10];
582 581 rtems_status_code ret;
583 582
584 583 ret = RTEMS_SUCCESSFUL;
585 584
586 585 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
587 586 if (status[0] != RTEMS_SUCCESSFUL)
588 587 {
589 588 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
590 589 }
591 590
592 591 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
593 592 if (status[1] != RTEMS_SUCCESSFUL)
594 593 {
595 594 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
596 595 }
597 596
598 597 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 598 if (status[2] != RTEMS_SUCCESSFUL)
600 599 {
601 600 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
602 601 }
603 602
604 603 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 604 if (status[3] != RTEMS_SUCCESSFUL)
606 605 {
607 606 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
608 607 }
609 608
610 609 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 610 if (status[4] != RTEMS_SUCCESSFUL)
612 611 {
613 612 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
614 613 }
615 614
616 615 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 616 if (status[5] != RTEMS_SUCCESSFUL)
618 617 {
619 618 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
620 619 }
621 620
622 621 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
623 622 if (status[6] != RTEMS_SUCCESSFUL)
624 623 {
625 624 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
626 625 }
627 626
628 627 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
629 628 if (status[7] != RTEMS_SUCCESSFUL)
630 629 {
631 630 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
632 631 }
633 632
634 633 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
635 634 if (status[8] != RTEMS_SUCCESSFUL)
636 635 {
637 636 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
638 637 }
639 638
640 639 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
641 640 if (status[9] != RTEMS_SUCCESSFUL)
642 641 {
643 642 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
644 643 }
645 644
646 645 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
647 646 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
648 647 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
649 648 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
650 649 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
651 650 {
652 651 ret = RTEMS_UNSATISFIED;
653 652 }
654 653
655 654 return ret;
656 655 }
657 656
658 657 int suspend_science_tasks()
659 658 {
660 659 /** This function suspends the science tasks.
661 660 *
662 661 * @return RTEMS directive status codes:
663 662 * - RTEMS_SUCCESSFUL - task restarted successfully
664 663 * - RTEMS_INVALID_ID - task id invalid
665 664 * - RTEMS_ALREADY_SUSPENDED - task already suspended
666 665 *
667 666 */
668 667
669 668 rtems_status_code status;
670 669
671 670 printf("in suspend_science_tasks\n");
672 671
673 672 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
674 673 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
675 674 {
676 675 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
677 676 }
678 677 else
679 678 {
680 679 status = RTEMS_SUCCESSFUL;
681 680 }
682 681 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
683 682 {
684 683 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
685 684 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
686 685 {
687 686 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
688 687 }
689 688 else
690 689 {
691 690 status = RTEMS_SUCCESSFUL;
692 691 }
693 692 }
694 693 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
695 694 {
696 695 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
697 696 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
698 697 {
699 698 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
700 699 }
701 700 else
702 701 {
703 702 status = RTEMS_SUCCESSFUL;
704 703 }
705 704 }
706 705 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
707 706 {
708 707 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
709 708 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
710 709 {
711 710 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
712 711 }
713 712 else
714 713 {
715 714 status = RTEMS_SUCCESSFUL;
716 715 }
717 716 }
718 717 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
719 718 {
720 719 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
721 720 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
722 721 {
723 722 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
724 723 }
725 724 else
726 725 {
727 726 status = RTEMS_SUCCESSFUL;
728 727 }
729 728 }
730 729 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
731 730 {
732 731 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
733 732 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
734 733 {
735 734 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
736 735 }
737 736 else
738 737 {
739 738 status = RTEMS_SUCCESSFUL;
740 739 }
741 740 }
742 741 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
743 742 {
744 743 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
745 744 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
746 745 {
747 746 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
748 747 }
749 748 else
750 749 {
751 750 status = RTEMS_SUCCESSFUL;
752 751 }
753 752 }
754 753 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
755 754 {
756 755 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
757 756 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
758 757 {
759 758 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
760 759 }
761 760 else
762 761 {
763 762 status = RTEMS_SUCCESSFUL;
764 763 }
765 764 }
766 765 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
767 766 {
768 767 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
769 768 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
770 769 {
771 770 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
772 771 }
773 772 else
774 773 {
775 774 status = RTEMS_SUCCESSFUL;
776 775 }
777 776 }
778 777 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
779 778 {
780 779 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
781 780 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
782 781 {
783 782 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
784 783 }
785 784 else
786 785 {
787 786 status = RTEMS_SUCCESSFUL;
788 787 }
789 788 }
790 789
791 790 return status;
792 791 }
793 792
794 793 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
795 794 {
796 795 WFP_reset_current_ring_nodes();
797 796
798 797 reset_waveform_picker_regs();
799 798
800 799 set_wfp_burst_enable_register( mode );
801 800
802 801 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
803 802 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
804 803
805 804 if (transitionCoarseTime == 0)
806 805 {
807 806 waveform_picker_regs->start_date = time_management_regs->coarse_time;
808 807 }
809 808 else
810 809 {
811 810 waveform_picker_regs->start_date = transitionCoarseTime;
812 811 }
813 812
814 813 }
815 814
816 815 void launch_spectral_matrix( void )
817 816 {
818 817 SM_reset_current_ring_nodes();
819 818
820 819 reset_spectral_matrix_regs();
821 820
822 821 reset_nb_sm();
823 822
824 823 set_sm_irq_onNewMatrix( 1 );
825 824
826 825 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
827 826 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
828 827
829 828 }
830 829
831 830 void launch_spectral_matrix_simu( void )
832 831 {
833 832 SM_reset_current_ring_nodes();
834 833 reset_spectral_matrix_regs();
835 834 reset_nb_sm();
836 835
837 836 // Spectral Matrices simulator
838 837 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
839 838 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
840 839 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
841 840 }
842 841
843 842 void set_sm_irq_onNewMatrix( unsigned char value )
844 843 {
845 844 if (value == 1)
846 845 {
847 846 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
848 847 }
849 848 else
850 849 {
851 850 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
852 851 }
853 852 }
854 853
855 854 void set_sm_irq_onError( unsigned char value )
856 855 {
857 856 if (value == 1)
858 857 {
859 858 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
860 859 }
861 860 else
862 861 {
863 862 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
864 863 }
865 864 }
866 865
867 866 //*****************************
868 867 // CONFIGURE CALIBRATION SIGNAL
869 868 void setCalibrationPrescaler( unsigned int prescaler )
870 869 {
871 870 // prescaling of the master clock (25 MHz)
872 871 // master clock is divided by 2^prescaler
873 872 time_management_regs->calPrescaler = prescaler;
874 873 }
875 874
876 875 void setCalibrationDivisor( unsigned int divisionFactor )
877 876 {
878 877 // division of the prescaled clock by the division factor
879 878 time_management_regs->calDivisor = divisionFactor;
880 879 }
881 880
882 881 void setCalibrationData( void ){
883 882 unsigned int k;
884 883 unsigned short data;
885 884 float val;
886 885 float f0;
887 886 float f1;
888 887 float fs;
889 888 float Ts;
890 889 float scaleFactor;
891 890
892 891 f0 = 625;
893 892 f1 = 10000;
894 893 fs = 160256.410;
895 894 Ts = 1. / fs;
896 895 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
897 896
898 897 time_management_regs->calDataPtr = 0x00;
899 898
900 899 // build the signal for the SCM calibration
901 900 for (k=0; k<256; k++)
902 901 {
903 902 val = sin( 2 * pi * f0 * k * Ts )
904 903 + sin( 2 * pi * f1 * k * Ts );
905 904 data = (unsigned short) ((val * scaleFactor) + 2048);
906 905 time_management_regs->calData = data & 0xfff;
907 906 }
908 907 }
909 908
910 909 void setCalibrationDataInterleaved( void ){
911 910 unsigned int k;
912 911 float val;
913 912 float f0;
914 913 float f1;
915 914 float fs;
916 915 float Ts;
917 916 unsigned short data[384];
918 917 unsigned char *dataPtr;
919 918
920 919 f0 = 625;
921 920 f1 = 10000;
922 921 fs = 240384.615;
923 922 Ts = 1. / fs;
924 923
925 924 time_management_regs->calDataPtr = 0x00;
926 925
927 926 // build the signal for the SCM calibration
928 927 for (k=0; k<384; k++)
929 928 {
930 929 val = sin( 2 * pi * f0 * k * Ts )
931 930 + sin( 2 * pi * f1 * k * Ts );
932 931 data[k] = (unsigned short) (val * 512 + 2048);
933 932 }
934 933
935 934 // write the signal in interleaved mode
936 935 for (k=0; k<128; k++)
937 936 {
938 937 dataPtr = (unsigned char*) &data[k*3 + 2];
939 938 time_management_regs->calData = (data[k*3] & 0xfff)
940 939 + ( (dataPtr[0] & 0x3f) << 12);
941 940 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
942 941 + ( (dataPtr[1] & 0x3f) << 12);
943 942 }
944 943 }
945 944
946 945 void setCalibrationReload( bool state)
947 946 {
948 947 if (state == true)
949 948 {
950 949 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
951 950 }
952 951 else
953 952 {
954 953 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
955 954 }
956 955 }
957 956
958 957 void setCalibrationEnable( bool state )
959 958 {
960 959 // this bit drives the multiplexer
961 960 if (state == true)
962 961 {
963 962 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
964 963 }
965 964 else
966 965 {
967 966 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
968 967 }
969 968 }
970 969
971 970 void setCalibrationInterleaved( bool state )
972 971 {
973 972 // this bit drives the multiplexer
974 973 if (state == true)
975 974 {
976 975 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
977 976 }
978 977 else
979 978 {
980 979 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
981 980 }
982 981 }
983 982
984 983 void setCalibration( bool state )
985 984 {
986 985 if (state == true)
987 986 {
988 987 setCalibrationEnable( true );
989 988 setCalibrationReload( false );
990 989 set_hk_lfr_calib_enable( true );
991 990 }
992 991 else
993 992 {
994 993 setCalibrationEnable( false );
995 994 setCalibrationReload( true );
996 995 set_hk_lfr_calib_enable( false );
997 996 }
998 997 }
999 998
1000 999 void set_hk_lfr_calib_enable( bool state )
1001 1000 {
1002 1001 if (state == true)
1003 1002 {
1004 1003 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
1005 1004 }
1006 1005 else
1007 1006 {
1008 1007 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
1009 1008 }
1010 1009 }
1011 1010
1012 1011 void configureCalibration( bool interleaved )
1013 1012 {
1014 1013 setCalibration( false );
1015 1014 if ( interleaved == true )
1016 1015 {
1017 1016 setCalibrationInterleaved( true );
1018 1017 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1019 1018 setCalibrationDivisor( 26 ); // => 240 384
1020 1019 setCalibrationDataInterleaved();
1021 1020 }
1022 1021 else
1023 1022 {
1024 1023 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1025 1024 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1026 1025 setCalibrationData();
1027 1026 }
1028 1027 }
1029 1028
1030 1029 //****************
1031 1030 // CLOSING ACTIONS
1032 1031 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1033 1032 {
1034 1033 /** This function is used to update the HK packets statistics after a successful TC execution.
1035 1034 *
1036 1035 * @param TC points to the TC being processed
1037 1036 * @param time is the time used to date the TC execution
1038 1037 *
1039 1038 */
1040 1039
1041 1040 unsigned int val;
1042 1041
1043 1042 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1044 1043 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1045 1044 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1046 1045 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1047 1046 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1048 1047 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1049 1048 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1050 1049 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1051 1050 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1052 1051 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1053 1052 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1054 1053 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1055 1054
1056 1055 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1057 1056 val++;
1058 1057 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1059 1058 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1060 1059 }
1061 1060
1062 1061 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1063 1062 {
1064 1063 /** This function is used to update the HK packets statistics after a TC rejection.
1065 1064 *
1066 1065 * @param TC points to the TC being processed
1067 1066 * @param time is the time used to date the TC rejection
1068 1067 *
1069 1068 */
1070 1069
1071 1070 unsigned int val;
1072 1071
1073 1072 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1074 1073 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1075 1074 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1076 1075 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1077 1076 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1078 1077 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1079 1078 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1080 1079 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1081 1080 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1082 1081 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1083 1082 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1084 1083 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1085 1084
1086 1085 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1087 1086 val++;
1088 1087 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1089 1088 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1090 1089 }
1091 1090
1092 1091 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1093 1092 {
1094 1093 /** This function is the last step of the TC execution workflow.
1095 1094 *
1096 1095 * @param TC points to the TC being processed
1097 1096 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1098 1097 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1099 1098 * @param time is the time used to date the TC execution
1100 1099 *
1101 1100 */
1102 1101
1103 1102 unsigned char requestedMode;
1104 1103
1105 1104 if (result == LFR_SUCCESSFUL)
1106 1105 {
1107 1106 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1108 1107 &
1109 1108 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1110 1109 )
1111 1110 {
1112 1111 send_tm_lfr_tc_exe_success( TC, queue_id );
1113 1112 }
1114 1113 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1115 1114 {
1116 1115 //**********************************
1117 1116 // UPDATE THE LFRMODE LOCAL VARIABLE
1118 1117 requestedMode = TC->dataAndCRC[1];
1119 1118 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1120 1119 updateLFRCurrentMode();
1121 1120 }
1122 1121 }
1123 1122 else if (result == LFR_EXE_ERROR)
1124 1123 {
1125 1124 send_tm_lfr_tc_exe_error( TC, queue_id );
1126 1125 }
1127 1126 }
1128 1127
1129 1128 //***************************
1130 1129 // Interrupt Service Routines
1131 1130 rtems_isr commutation_isr1( rtems_vector_number vector )
1132 1131 {
1133 1132 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1134 1133 printf("In commutation_isr1 *** Error sending event to DUMB\n");
1135 1134 }
1136 1135 }
1137 1136
1138 1137 rtems_isr commutation_isr2( rtems_vector_number vector )
1139 1138 {
1140 1139 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1141 1140 printf("In commutation_isr2 *** Error sending event to DUMB\n");
1142 1141 }
1143 1142 }
1144 1143
1145 1144 //****************
1146 1145 // OTHER FUNCTIONS
1147 1146 void updateLFRCurrentMode()
1148 1147 {
1149 1148 /** This function updates the value of the global variable lfrCurrentMode.
1150 1149 *
1151 1150 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1152 1151 *
1153 1152 */
1154 1153 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1155 1154 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1156 1155 }
1157 1156
1158 1157 void set_lfr_soft_reset( unsigned char value )
1159 1158 {
1160 1159 if (value == 1)
1161 1160 {
1162 1161 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1163 1162 }
1164 1163 else
1165 1164 {
1166 1165 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1167 1166 }
1168 1167 }
1169 1168
1170 1169 void reset_lfr( void )
1171 1170 {
1172 1171 set_lfr_soft_reset( 1 );
1173 1172
1174 1173 set_lfr_soft_reset( 0 );
1175 1174 }
@@ -1,1127 +1,1139
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 19 ring_node kcoefficient_node_1;
20 20 ring_node kcoefficient_node_2;
21 21
22 22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 23 {
24 24 /** This function updates the LFR registers with the incoming common parameters.
25 25 *
26 26 * @param TC points to the TeleCommand packet that is being processed
27 27 *
28 28 *
29 29 */
30 30
31 31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 33 set_wfp_data_shaping( );
34 34 return LFR_SUCCESSFUL;
35 35 }
36 36
37 37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 38 {
39 39 /** This function updates the LFR registers with the incoming normal parameters.
40 40 *
41 41 * @param TC points to the TeleCommand packet that is being processed
42 42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 43 *
44 44 */
45 45
46 46 int result;
47 47 int flag;
48 48 rtems_status_code status;
49 49
50 50 flag = LFR_SUCCESSFUL;
51 51
52 52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 55 flag = LFR_DEFAULT;
56 56 }
57 57
58 58 // CHECK THE PARAMETERS SET CONSISTENCY
59 59 if (flag == LFR_SUCCESSFUL)
60 60 {
61 61 flag = check_common_par_consistency( TC, queue_id );
62 62 }
63 63
64 64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_l( TC );
68 68 result = set_sy_lfr_n_swf_p( TC );
69 69 result = set_sy_lfr_n_bp_p0( TC );
70 70 result = set_sy_lfr_n_bp_p1( TC );
71 71 result = set_sy_lfr_n_asm_p( TC );
72 72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 73 }
74 74
75 75 return flag;
76 76 }
77 77
78 78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 79 {
80 80 /** This function updates the LFR registers with the incoming burst parameters.
81 81 *
82 82 * @param TC points to the TeleCommand packet that is being processed
83 83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 84 *
85 85 */
86 86
87 87 int flag;
88 88 rtems_status_code status;
89 89 unsigned char sy_lfr_b_bp_p0;
90 90 unsigned char sy_lfr_b_bp_p1;
91 91 float aux;
92 92
93 93 flag = LFR_SUCCESSFUL;
94 94
95 95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 97 flag = LFR_DEFAULT;
98 98 }
99 99
100 100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102 102
103 103 // sy_lfr_b_bp_p0
104 104 if (flag == LFR_SUCCESSFUL)
105 105 {
106 106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 107 {
108 108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1
113 113 if (flag == LFR_SUCCESSFUL)
114 114 {
115 115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 116 {
117 117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
118 118 flag = WRONG_APP_DATA;
119 119 }
120 120 }
121 121 //****************************************************************
122 122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 123 if (flag == LFR_SUCCESSFUL)
124 124 {
125 125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 128 if (aux > FLOAT_EQUAL_ZERO)
129 129 {
130 130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET HTE PARAMETERS
136 136 if (flag == LFR_SUCCESSFUL)
137 137 {
138 138 flag = set_sy_lfr_b_bp_p0( TC );
139 139 flag = set_sy_lfr_b_bp_p1( TC );
140 140 }
141 141
142 142 return flag;
143 143 }
144 144
145 145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 146 {
147 147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 148 *
149 149 * @param TC points to the TeleCommand packet that is being processed
150 150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 151 *
152 152 */
153 153
154 154 int flag;
155 155 rtems_status_code status;
156 156 unsigned char sy_lfr_s1_bp_p0;
157 157 unsigned char sy_lfr_s1_bp_p1;
158 158 float aux;
159 159
160 160 flag = LFR_SUCCESSFUL;
161 161
162 162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 164 flag = LFR_DEFAULT;
165 165 }
166 166
167 167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169 169
170 170 // sy_lfr_s1_bp_p0
171 171 if (flag == LFR_SUCCESSFUL)
172 172 {
173 173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 174 {
175 175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
176 176 flag = WRONG_APP_DATA;
177 177 }
178 178 }
179 179 // sy_lfr_s1_bp_p1
180 180 if (flag == LFR_SUCCESSFUL)
181 181 {
182 182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 183 {
184 184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
185 185 flag = WRONG_APP_DATA;
186 186 }
187 187 }
188 188 //******************************************************************
189 189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 190 if (flag == LFR_SUCCESSFUL)
191 191 {
192 192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
193 193 if (aux > FLOAT_EQUAL_ZERO)
194 194 {
195 195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 196 flag = LFR_DEFAULT;
197 197 }
198 198 }
199 199
200 200 // SET THE PARAMETERS
201 201 if (flag == LFR_SUCCESSFUL)
202 202 {
203 203 flag = set_sy_lfr_s1_bp_p0( TC );
204 204 flag = set_sy_lfr_s1_bp_p1( TC );
205 205 }
206 206
207 207 return flag;
208 208 }
209 209
210 210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 211 {
212 212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 213 *
214 214 * @param TC points to the TeleCommand packet that is being processed
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 216 *
217 217 */
218 218
219 219 int flag;
220 220 rtems_status_code status;
221 221 unsigned char sy_lfr_s2_bp_p0;
222 222 unsigned char sy_lfr_s2_bp_p1;
223 223 float aux;
224 224
225 225 flag = LFR_SUCCESSFUL;
226 226
227 227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 229 flag = LFR_DEFAULT;
230 230 }
231 231
232 232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 234
235 235 // sy_lfr_s2_bp_p0
236 236 if (flag == LFR_SUCCESSFUL)
237 237 {
238 238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 239 {
240 240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 241 flag = WRONG_APP_DATA;
242 242 }
243 243 }
244 244 // sy_lfr_s2_bp_p1
245 245 if (flag == LFR_SUCCESSFUL)
246 246 {
247 247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 248 {
249 249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 250 flag = WRONG_APP_DATA;
251 251 }
252 252 }
253 253 //******************************************************************
254 254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 255 if (flag == LFR_SUCCESSFUL)
256 256 {
257 257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 260 if (aux > FLOAT_EQUAL_ZERO)
261 261 {
262 262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 263 flag = LFR_DEFAULT;
264 264 }
265 265 }
266 266
267 267 // SET THE PARAMETERS
268 268 if (flag == LFR_SUCCESSFUL)
269 269 {
270 270 flag = set_sy_lfr_s2_bp_p0( TC );
271 271 flag = set_sy_lfr_s2_bp_p1( TC );
272 272 }
273 273
274 274 return flag;
275 275 }
276 276
277 277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 278 {
279 279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 280 *
281 281 * @param TC points to the TeleCommand packet that is being processed
282 282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 283 *
284 284 */
285 285
286 286 int flag;
287 287
288 288 flag = LFR_DEFAULT;
289 289
290 290 flag = set_sy_lfr_kcoeff( TC );
291 291
292 292 return flag;
293 293 }
294 294
295 295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 296 {
297 297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 298 *
299 299 * @param TC points to the TeleCommand packet that is being processed
300 300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 301 *
302 302 */
303 303
304 304 int flag;
305 305
306 306 flag = LFR_DEFAULT;
307 307
308 308 flag = set_sy_lfr_fbins( TC );
309 309
310 310 return flag;
311 311 }
312 312
313 313 void printKCoefficients(unsigned int freq, unsigned int bin, float *k_coeff)
314 314 {
315 315 printf("freq = %d *** bin = %d *** (0) %f *** (1) %f *** (2) %f *** (3) %f *** (4) %f\n",
316 316 freq,
317 317 bin,
318 318 k_coeff[ (bin*NB_K_COEFF_PER_BIN) + 0 ],
319 319 k_coeff[ (bin*NB_K_COEFF_PER_BIN) + 1 ],
320 320 k_coeff[ (bin*NB_K_COEFF_PER_BIN) + 2 ],
321 321 k_coeff[ (bin*NB_K_COEFF_PER_BIN) + 3 ],
322 322 k_coeff[ (bin*NB_K_COEFF_PER_BIN) + 4 ]);
323 323 }
324 324
325 325 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
326 326 {
327 327 /** This function updates the LFR registers with the incoming sbm2 parameters.
328 328 *
329 329 * @param TC points to the TeleCommand packet that is being processed
330 330 * @param queue_id is the id of the queue which handles TM related to this execution step
331 331 *
332 332 */
333 333
334 334 unsigned int address;
335 335 rtems_status_code status;
336 336 unsigned int freq;
337 337 unsigned int bin;
338 338 unsigned int coeff;
339 339 unsigned char *kCoeffPtr;
340 340 unsigned char *kCoeffDumpPtr;
341 341
342 342 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
343 343 // F0 => 11 bins
344 344 // F1 => 13 bins
345 345 // F2 => 12 bins
346 346 // 36 bins to dump in two packets (30 bins max per packet)
347 347
348 348 //*********
349 349 // PACKET 1
350 350 // 11 F0 bins, 13 F1 bins and 6 F2 bins
351 351 kcoefficients_dump_1.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8);
352 352 kcoefficients_dump_1.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump );
353 353 increment_seq_counter( &sequenceCounterParameterDump );
354 354 for( freq=0;
355 355 freq<NB_BINS_COMPRESSED_SM_F0;
356 356 freq++ )
357 357 {
358 358 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
359 359 bin = freq;
360 360 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
361 361 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
362 362 {
363 363 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
364 364 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
365 365 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
366 366 }
367 367 }
368 368 for( freq=NB_BINS_COMPRESSED_SM_F0;
369 369 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
370 370 freq++ )
371 371 {
372 372 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
373 373 bin = freq - NB_BINS_COMPRESSED_SM_F0;
374 374 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
375 375 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
376 376 {
377 377 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
378 378 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
379 379 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
380 380 }
381 381 }
382 382 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
383 383 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
384 384 freq++ )
385 385 {
386 386 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
387 387 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
388 388 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
389 389 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
390 390 {
391 391 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
392 392 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
393 393 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
394 394 }
395 395 }
396 396 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
397 397 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
398 398 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
399 399 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
400 400 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
401 401 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
402 402 // SEND DATA
403 403 kcoefficient_node_1.status = 1;
404 404 address = (unsigned int) &kcoefficient_node_1;
405 405 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
406 406 if (status != RTEMS_SUCCESSFUL) {
407 407 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
408 408 }
409 409
410 410 //********
411 411 // PACKET 2
412 412 // 6 F2 bins
413 413 kcoefficients_dump_2.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8);
414 414 kcoefficients_dump_2.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump );
415 415 increment_seq_counter( &sequenceCounterParameterDump );
416 416 for( freq=0; freq<6; freq++ )
417 417 {
418 418 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
419 419 bin = freq + 6;
420 420 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
421 421 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
422 422 {
423 423 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
424 424 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
425 425 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
426 426 }
427 427 }
428 428 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
429 429 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
430 430 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
431 431 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
432 432 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
433 433 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
434 434 // SEND DATA
435 435 kcoefficient_node_2.status = 1;
436 436 address = (unsigned int) &kcoefficient_node_2;
437 437 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
438 438 if (status != RTEMS_SUCCESSFUL) {
439 439 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
440 440 }
441 441
442 442 return status;
443 443 }
444 444
445 445 int action_dump_par( rtems_id queue_id )
446 446 {
447 447 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
448 448 *
449 449 * @param queue_id is the id of the queue which handles TM related to this execution step.
450 450 *
451 451 * @return RTEMS directive status codes:
452 452 * - RTEMS_SUCCESSFUL - message sent successfully
453 453 * - RTEMS_INVALID_ID - invalid queue id
454 454 * - RTEMS_INVALID_SIZE - invalid message size
455 455 * - RTEMS_INVALID_ADDRESS - buffer is NULL
456 456 * - RTEMS_UNSATISFIED - out of message buffers
457 457 * - RTEMS_TOO_MANY - queue s limit has been reached
458 458 *
459 459 */
460 460
461 461 int status;
462 462
463 463 // UPDATE TIME
464 464 parameter_dump_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8);
465 465 parameter_dump_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump );
466 466 increment_seq_counter( &sequenceCounterParameterDump );
467 467
468 468 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
469 469 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
470 470 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
471 471 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
472 472 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
473 473 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
474 474 // SEND DATA
475 475 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
476 476 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
477 477 if (status != RTEMS_SUCCESSFUL) {
478 478 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
479 479 }
480 480
481 481 return status;
482 482 }
483 483
484 484 //***********************
485 485 // NORMAL MODE PARAMETERS
486 486
487 487 int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
488 488 {
489 489 unsigned char msb;
490 490 unsigned char lsb;
491 491 int flag;
492 492 float aux;
493 493 rtems_status_code status;
494 494
495 495 unsigned int sy_lfr_n_swf_l;
496 496 unsigned int sy_lfr_n_swf_p;
497 497 unsigned int sy_lfr_n_asm_p;
498 498 unsigned char sy_lfr_n_bp_p0;
499 499 unsigned char sy_lfr_n_bp_p1;
500 500 unsigned char sy_lfr_n_cwf_long_f3;
501 501
502 502 flag = LFR_SUCCESSFUL;
503 503
504 504 //***************
505 505 // get parameters
506 506 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
507 507 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
508 508 sy_lfr_n_swf_l = msb * 256 + lsb;
509 509
510 510 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
511 511 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
512 512 sy_lfr_n_swf_p = msb * 256 + lsb;
513 513
514 514 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
515 515 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
516 516 sy_lfr_n_asm_p = msb * 256 + lsb;
517 517
518 518 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
519 519
520 520 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
521 521
522 522 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
523 523
524 524 //******************
525 525 // check consistency
526 526 // sy_lfr_n_swf_l
527 527 if (sy_lfr_n_swf_l != 2048)
528 528 {
529 529 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
530 530 flag = WRONG_APP_DATA;
531 531 }
532 532 // sy_lfr_n_swf_p
533 533 if (flag == LFR_SUCCESSFUL)
534 534 {
535 535 if ( sy_lfr_n_swf_p < 16 )
536 536 {
537 537 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
538 538 flag = WRONG_APP_DATA;
539 539 }
540 540 }
541 541 // sy_lfr_n_bp_p0
542 542 if (flag == LFR_SUCCESSFUL)
543 543 {
544 544 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
545 545 {
546 546 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
547 547 flag = WRONG_APP_DATA;
548 548 }
549 549 }
550 550 // sy_lfr_n_asm_p
551 551 if (flag == LFR_SUCCESSFUL)
552 552 {
553 553 if (sy_lfr_n_asm_p == 0)
554 554 {
555 555 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
556 556 flag = WRONG_APP_DATA;
557 557 }
558 558 }
559 559 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
560 560 if (flag == LFR_SUCCESSFUL)
561 561 {
562 562 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
563 563 if (aux > FLOAT_EQUAL_ZERO)
564 564 {
565 565 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
566 566 flag = WRONG_APP_DATA;
567 567 }
568 568 }
569 569 // sy_lfr_n_bp_p1
570 570 if (flag == LFR_SUCCESSFUL)
571 571 {
572 572 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
573 573 {
574 574 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
575 575 flag = WRONG_APP_DATA;
576 576 }
577 577 }
578 578 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
579 579 if (flag == LFR_SUCCESSFUL)
580 580 {
581 581 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
582 582 if (aux > FLOAT_EQUAL_ZERO)
583 583 {
584 584 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
585 585 flag = LFR_DEFAULT;
586 586 }
587 587 }
588 588 // sy_lfr_n_cwf_long_f3
589 589
590 590 return flag;
591 591 }
592 592
593 593 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
594 594 {
595 595 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
596 596 *
597 597 * @param TC points to the TeleCommand packet that is being processed
598 598 * @param queue_id is the id of the queue which handles TM related to this execution step
599 599 *
600 600 */
601 601
602 602 int result;
603 603
604 604 result = LFR_SUCCESSFUL;
605 605
606 606 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
607 607 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
608 608
609 609 return result;
610 610 }
611 611
612 612 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
613 613 {
614 614 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
615 615 *
616 616 * @param TC points to the TeleCommand packet that is being processed
617 617 * @param queue_id is the id of the queue which handles TM related to this execution step
618 618 *
619 619 */
620 620
621 621 int result;
622 622
623 623 result = LFR_SUCCESSFUL;
624 624
625 625 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
626 626 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
627 627
628 628 return result;
629 629 }
630 630
631 631 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
632 632 {
633 633 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
634 634 *
635 635 * @param TC points to the TeleCommand packet that is being processed
636 636 * @param queue_id is the id of the queue which handles TM related to this execution step
637 637 *
638 638 */
639 639
640 640 int result;
641 641
642 642 result = LFR_SUCCESSFUL;
643 643
644 644 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
645 645 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
646 646
647 647 return result;
648 648 }
649 649
650 650 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
651 651 {
652 652 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
653 653 *
654 654 * @param TC points to the TeleCommand packet that is being processed
655 655 * @param queue_id is the id of the queue which handles TM related to this execution step
656 656 *
657 657 */
658 658
659 659 int status;
660 660
661 661 status = LFR_SUCCESSFUL;
662 662
663 663 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
664 664
665 665 return status;
666 666 }
667 667
668 668 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
669 669 {
670 670 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
671 671 *
672 672 * @param TC points to the TeleCommand packet that is being processed
673 673 * @param queue_id is the id of the queue which handles TM related to this execution step
674 674 *
675 675 */
676 676
677 677 int status;
678 678
679 679 status = LFR_SUCCESSFUL;
680 680
681 681 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
682 682
683 683 return status;
684 684 }
685 685
686 686 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
687 687 {
688 688 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
689 689 *
690 690 * @param TC points to the TeleCommand packet that is being processed
691 691 * @param queue_id is the id of the queue which handles TM related to this execution step
692 692 *
693 693 */
694 694
695 695 int status;
696 696
697 697 status = LFR_SUCCESSFUL;
698 698
699 699 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
700 700
701 701 return status;
702 702 }
703 703
704 704 //**********************
705 705 // BURST MODE PARAMETERS
706 706 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
707 707 {
708 708 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
709 709 *
710 710 * @param TC points to the TeleCommand packet that is being processed
711 711 * @param queue_id is the id of the queue which handles TM related to this execution step
712 712 *
713 713 */
714 714
715 715 int status;
716 716
717 717 status = LFR_SUCCESSFUL;
718 718
719 719 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
720 720
721 721 return status;
722 722 }
723 723
724 724 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
725 725 {
726 726 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
727 727 *
728 728 * @param TC points to the TeleCommand packet that is being processed
729 729 * @param queue_id is the id of the queue which handles TM related to this execution step
730 730 *
731 731 */
732 732
733 733 int status;
734 734
735 735 status = LFR_SUCCESSFUL;
736 736
737 737 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
738 738
739 739 return status;
740 740 }
741 741
742 742 //*********************
743 743 // SBM1 MODE PARAMETERS
744 744 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
745 745 {
746 746 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
747 747 *
748 748 * @param TC points to the TeleCommand packet that is being processed
749 749 * @param queue_id is the id of the queue which handles TM related to this execution step
750 750 *
751 751 */
752 752
753 753 int status;
754 754
755 755 status = LFR_SUCCESSFUL;
756 756
757 757 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
758 758
759 759 return status;
760 760 }
761 761
762 762 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
763 763 {
764 764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
765 765 *
766 766 * @param TC points to the TeleCommand packet that is being processed
767 767 * @param queue_id is the id of the queue which handles TM related to this execution step
768 768 *
769 769 */
770 770
771 771 int status;
772 772
773 773 status = LFR_SUCCESSFUL;
774 774
775 775 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
776 776
777 777 return status;
778 778 }
779 779
780 780 //*********************
781 781 // SBM2 MODE PARAMETERS
782 782 int set_sy_lfr_s2_bp_p0(ccsdsTelecommandPacket_t *TC)
783 783 {
784 784 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
785 785 *
786 786 * @param TC points to the TeleCommand packet that is being processed
787 787 * @param queue_id is the id of the queue which handles TM related to this execution step
788 788 *
789 789 */
790 790
791 791 int status;
792 792
793 793 status = LFR_SUCCESSFUL;
794 794
795 795 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
796 796
797 797 return status;
798 798 }
799 799
800 800 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
801 801 {
802 802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
803 803 *
804 804 * @param TC points to the TeleCommand packet that is being processed
805 805 * @param queue_id is the id of the queue which handles TM related to this execution step
806 806 *
807 807 */
808 808
809 809 int status;
810 810
811 811 status = LFR_SUCCESSFUL;
812 812
813 813 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
814 814
815 815 return status;
816 816 }
817 817
818 818 //*******************
819 819 // TC_LFR_UPDATE_INFO
820 820 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
821 821 {
822 822 unsigned int status;
823 823
824 824 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
825 825 || (mode == LFR_MODE_BURST)
826 826 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
827 827 {
828 828 status = LFR_SUCCESSFUL;
829 829 }
830 830 else
831 831 {
832 832 status = LFR_DEFAULT;
833 833 }
834 834
835 835 return status;
836 836 }
837 837
838 838 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
839 839 {
840 840 unsigned int status;
841 841
842 842 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
843 843 || (mode == TDS_MODE_BURST)
844 844 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
845 845 || (mode == TDS_MODE_LFM))
846 846 {
847 847 status = LFR_SUCCESSFUL;
848 848 }
849 849 else
850 850 {
851 851 status = LFR_DEFAULT;
852 852 }
853 853
854 854 return status;
855 855 }
856 856
857 857 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
858 858 {
859 859 unsigned int status;
860 860
861 861 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
862 862 || (mode == THR_MODE_BURST))
863 863 {
864 864 status = LFR_SUCCESSFUL;
865 865 }
866 866 else
867 867 {
868 868 status = LFR_DEFAULT;
869 869 }
870 870
871 871 return status;
872 872 }
873 873
874 874 //***********
875 875 // FBINS MASK
876 876
877 877 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
878 878 {
879 879 int status;
880 880 unsigned int k;
881 881 unsigned char *fbins_mask_dump;
882 882 unsigned char *fbins_mask_TC;
883 883
884 884 status = LFR_SUCCESSFUL;
885 885
886 886 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
887 887 fbins_mask_TC = TC->dataAndCRC;
888 888
889 889 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
890 890 {
891 891 fbins_mask_dump[k] = fbins_mask_TC[k];
892 892 }
893 893 for (k=0; k < NB_FBINS_MASKS; k++)
894 894 {
895 895 unsigned char *auxPtr;
896 896 auxPtr = &parameter_dump_packet.sy_lfr_fbins_f0_word1[k*NB_BYTES_PER_FBINS_MASK];
897 897 printf("%x %x %x %x\n", auxPtr[0], auxPtr[1], auxPtr[2], auxPtr[3]);
898 898 }
899 899
900 900
901 901 return status;
902 902 }
903 903
904 904 //**************
905 905 // KCOEFFICIENTS
906 906 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC )
907 907 {
908 908 unsigned int i;
909 909 unsigned short sy_lfr_kcoeff_frequency;
910 910 unsigned short bin;
911 911 unsigned short *freqPtr;
912 912 float *kcoeffPtr_norm;
913 913 float *kcoeffPtr_sbm;
914 914 int status;
915 915 unsigned char *kcoeffLoadPtr;
916 916 unsigned char *kcoeffNormPtr;
917 917 unsigned char *kcoeffSbmPtr_a;
918 918 unsigned char *kcoeffSbmPtr_b;
919 919
920 920 status = LFR_SUCCESSFUL;
921 921
922 922 kcoeffPtr_norm = NULL;
923 923 kcoeffPtr_sbm = NULL;
924 924 bin = 0;
925 925
926 926 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
927 927 sy_lfr_kcoeff_frequency = *freqPtr;
928 928
929 929 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
930 930 {
931 931 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
932 932 }
933 933 else
934 934 {
935 935 if ( ( sy_lfr_kcoeff_frequency >= 0 )
936 936 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
937 937 {
938 938 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
939 939 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
940 940 bin = sy_lfr_kcoeff_frequency;
941 941 }
942 942 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
943 943 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
944 944 {
945 945 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
946 946 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
947 947 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
948 948 }
949 949 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
950 950 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
951 951 {
952 952 kcoeffPtr_norm = k_coeff_intercalib_f2;
953 953 kcoeffPtr_sbm = NULL;
954 954 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
955 955 }
956 956 }
957 957
958 if (kcoeffPtr_norm != NULL )
958 printf("in set_sy_lfr_kcoeff *** freq = %d, bin = %d\n", sy_lfr_kcoeff_frequency, bin);
959
960 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
959 961 {
960 printf("freq = %d, bin = %d\n", sy_lfr_kcoeff_frequency, bin);
961 962 for (i=0; i<NB_K_COEFF_PER_BIN; i++)
962 963 {
963 964 // destination
964 965 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + i ];
966 // source
967 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * i];
968 // copy source to destination
969 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
970 }
971 }
972
973 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
974 {
975 for (i=0; i<NB_K_COEFF_PER_BIN; i++)
976 {
977 // destination
965 978 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + i) * 2 ];
966 979 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + i) * 2 + 1 ];
967 980 // source
968 981 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * i];
969 982 // copy source to destination
970 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
971 983 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
972 984 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
973 985 }
974 986 }
975 987
976 988 return status;
977 989 }
978 990
979 991 void copyFloatByChar( unsigned char *destination, unsigned char *source )
980 992 {
981 993 destination[0] = source[0];
982 994 destination[1] = source[1];
983 995 destination[2] = source[2];
984 996 destination[3] = source[3];
985 997 }
986 998
987 999 //**********
988 1000 // init dump
989 1001
990 1002 void init_parameter_dump( void )
991 1003 {
992 1004 /** This function initialize the parameter_dump_packet global variable with default values.
993 1005 *
994 1006 */
995 1007
996 1008 unsigned int k;
997 1009
998 1010 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
999 1011 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1000 1012 parameter_dump_packet.reserved = CCSDS_RESERVED;
1001 1013 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1002 1014 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1003 1015 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1004 1016 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1005 1017 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1006 1018 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1007 1019 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1008 1020 // DATA FIELD HEADER
1009 1021 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1010 1022 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1011 1023 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1012 1024 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1013 1025 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1014 1026 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1015 1027 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1016 1028 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1017 1029 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1018 1030 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1019 1031 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1020 1032
1021 1033 //******************
1022 1034 // COMMON PARAMETERS
1023 1035 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1024 1036 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1025 1037
1026 1038 //******************
1027 1039 // NORMAL PARAMETERS
1028 1040 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1029 1041 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1030 1042 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1031 1043 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1032 1044 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1033 1045 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1034 1046 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1035 1047 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1036 1048 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1037 1049
1038 1050 //*****************
1039 1051 // BURST PARAMETERS
1040 1052 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1041 1053 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1042 1054
1043 1055 //****************
1044 1056 // SBM1 PARAMETERS
1045 1057 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1046 1058 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1047 1059
1048 1060 //****************
1049 1061 // SBM2 PARAMETERS
1050 1062 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1051 1063 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1052 1064
1053 1065 //************
1054 1066 // FBINS MASKS
1055 1067 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1056 1068 {
1057 1069 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1058 1070 }
1059 1071 }
1060 1072
1061 1073 void init_kcoefficients_dump( void )
1062 1074 {
1063 1075 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1064 1076 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1065 1077
1066 1078 kcoefficient_node_1.previous = NULL;
1067 1079 kcoefficient_node_1.next = NULL;
1068 1080 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1069 1081 kcoefficient_node_1.coarseTime = 0x00;
1070 1082 kcoefficient_node_1.fineTime = 0x00;
1071 1083 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1072 1084 kcoefficient_node_1.status = 0x00;
1073 1085
1074 1086 kcoefficient_node_2.previous = NULL;
1075 1087 kcoefficient_node_2.next = NULL;
1076 1088 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1077 1089 kcoefficient_node_2.coarseTime = 0x00;
1078 1090 kcoefficient_node_2.fineTime = 0x00;
1079 1091 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1080 1092 kcoefficient_node_2.status = 0x00;
1081 1093 }
1082 1094
1083 1095 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1084 1096 {
1085 1097 unsigned int k;
1086 1098 unsigned int packetLength;
1087 1099
1088 1100 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1089 1101
1090 1102 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1091 1103 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1092 1104 kcoefficients_dump->reserved = CCSDS_RESERVED;
1093 1105 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1094 1106 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1095 1107 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1096 1108 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1097 1109 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1098 1110 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1099 1111 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1100 1112 // DATA FIELD HEADER
1101 1113 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1102 1114 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1103 1115 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1104 1116 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1105 1117 kcoefficients_dump->time[0] = 0x00;
1106 1118 kcoefficients_dump->time[1] = 0x00;
1107 1119 kcoefficients_dump->time[2] = 0x00;
1108 1120 kcoefficients_dump->time[3] = 0x00;
1109 1121 kcoefficients_dump->time[4] = 0x00;
1110 1122 kcoefficients_dump->time[5] = 0x00;
1111 1123 kcoefficients_dump->sid = SID_K_DUMP;
1112 1124
1113 1125 kcoefficients_dump->pkt_cnt = 2;
1114 1126 kcoefficients_dump->pkt_nr = pkt_nr;
1115 1127 kcoefficients_dump->blk_nr = blk_nr;
1116 1128
1117 1129 //******************
1118 1130 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1119 1131 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1120 1132 for (k=0; k<3900; k++)
1121 1133 {
1122 1134 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1123 1135 }
1124 1136 }
1125 1137
1126 1138
1127 1139
General Comments 0
You need to be logged in to leave comments. Login now