##// END OF EJS Templates
Bug 912 champ HK_LFR_SC_POTENTIEL_FLAG passe à OFF...
paul -
r342:ff406706df10 R3++ draft
parent child
Show More
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 058c1234c2defe215d3dd655a7ef65abb33c922d header/lfr_common_headers
2 21ada91882790323b08a38518ed1af5a36fa4deb header/lfr_common_headers
@@ -1,1005 +1,1005
1 1 /** General usage functions and RTEMS tasks.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 */
7 7
8 8 #include "fsw_misc.h"
9 9
10 10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
11 11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
12 12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
13 13
14 14 void timer_configure(unsigned char timer, unsigned int clock_divider,
15 15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
16 16 {
17 17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
18 18 *
19 19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
20 20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
21 21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
22 22 * @param interrupt_level is the interrupt level that the timer drives.
23 23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
24 24 *
25 25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
26 26 *
27 27 */
28 28
29 29 rtems_status_code status;
30 30 rtems_isr_entry old_isr_handler;
31 31
32 32 old_isr_handler = NULL;
33 33
34 34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
35 35
36 36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
37 37 if (status!=RTEMS_SUCCESSFUL)
38 38 {
39 39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
40 40 }
41 41
42 42 timer_set_clock_divider( timer, clock_divider);
43 43 }
44 44
45 45 void timer_start(unsigned char timer)
46 46 {
47 47 /** This function starts a GPTIMER timer.
48 48 *
49 49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
50 50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
51 51 *
52 52 */
53 53
54 54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
55 55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
56 56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
57 57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
58 58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
59 59 }
60 60
61 61 void timer_stop(unsigned char timer)
62 62 {
63 63 /** This function stops a GPTIMER timer.
64 64 *
65 65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
66 66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
67 67 *
68 68 */
69 69
70 70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
71 71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
72 72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
73 73 }
74 74
75 75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
76 76 {
77 77 /** This function sets the clock divider of a GPTIMER timer.
78 78 *
79 79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
80 80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
81 81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
82 82 *
83 83 */
84 84
85 85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
86 86 }
87 87
88 88 // WATCHDOG
89 89
90 90 rtems_isr watchdog_isr( rtems_vector_number vector )
91 91 {
92 92 rtems_status_code status_code;
93 93
94 94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
95 95
96 96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
97 97
98 98 exit(0);
99 99 }
100 100
101 101 void watchdog_configure(void)
102 102 {
103 103 /** This function configure the watchdog.
104 104 *
105 105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
106 106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
107 107 *
108 108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
109 109 *
110 110 */
111 111
112 112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
113 113
114 114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
115 115
116 116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 117 }
118 118
119 119 void watchdog_stop(void)
120 120 {
121 121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
122 122 timer_stop( TIMER_WATCHDOG );
123 123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
124 124 }
125 125
126 126 void watchdog_reload(void)
127 127 {
128 128 /** This function reloads the watchdog timer counter with the timer reload value.
129 129 *
130 130 * @param void
131 131 *
132 132 * @return void
133 133 *
134 134 */
135 135
136 136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
137 137 }
138 138
139 139 void watchdog_start(void)
140 140 {
141 141 /** This function starts the watchdog timer.
142 142 *
143 143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
144 144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
145 145 *
146 146 */
147 147
148 148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
149 149
150 150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
151 151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
152 152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
153 153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
154 154
155 155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
156 156
157 157 }
158 158
159 159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
160 160 {
161 161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
162 162
163 163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
164 164
165 165 return 0;
166 166 }
167 167
168 168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
169 169 {
170 170 /** This function sets the scaler reload register of the apbuart module
171 171 *
172 172 * @param regs is the address of the apbuart registers in memory
173 173 * @param value is the value that will be stored in the scaler register
174 174 *
175 175 * The value shall be set by the software to get data on the serial interface.
176 176 *
177 177 */
178 178
179 179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
180 180
181 181 apbuart_regs->scaler = value;
182 182
183 183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
184 184 }
185 185
186 186 //************
187 187 // RTEMS TASKS
188 188
189 189 rtems_task load_task(rtems_task_argument argument)
190 190 {
191 191 BOOT_PRINTF("in LOAD *** \n")
192 192
193 193 rtems_status_code status;
194 194 unsigned int i;
195 195 unsigned int j;
196 196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
197 197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
198 198
199 199 watchdog_period_id = RTEMS_ID_NONE;
200 200
201 201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
202 202
203 203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
204 204 if( status != RTEMS_SUCCESSFUL ) {
205 205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
206 206 }
207 207
208 208 i = 0;
209 209 j = 0;
210 210
211 211 watchdog_configure();
212 212
213 213 watchdog_start();
214 214
215 215 set_sy_lfr_watchdog_enabled( true );
216 216
217 217 while(1){
218 218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
219 219 watchdog_reload();
220 220 i = i + 1;
221 221 if ( i == WATCHDOG_LOOP_PRINTF )
222 222 {
223 223 i = 0;
224 224 j = j + 1;
225 225 PRINTF1("%d\n", j)
226 226 }
227 227 #ifdef DEBUG_WATCHDOG
228 228 if (j == WATCHDOG_LOOP_DEBUG )
229 229 {
230 230 status = rtems_task_delete(RTEMS_SELF);
231 231 }
232 232 #endif
233 233 }
234 234 }
235 235
236 236 rtems_task hous_task(rtems_task_argument argument)
237 237 {
238 238 rtems_status_code status;
239 239 rtems_status_code spare_status;
240 240 rtems_id queue_id;
241 241 rtems_rate_monotonic_period_status period_status;
242 242 bool isSynchronized;
243 243
244 244 queue_id = RTEMS_ID_NONE;
245 245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
246 246 isSynchronized = false;
247 247
248 248 status = get_message_queue_id_send( &queue_id );
249 249 if (status != RTEMS_SUCCESSFUL)
250 250 {
251 251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
252 252 }
253 253
254 254 BOOT_PRINTF("in HOUS ***\n");
255 255
256 256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
257 257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
258 258 if( status != RTEMS_SUCCESSFUL ) {
259 259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
260 260 }
261 261 }
262 262
263 263 status = rtems_rate_monotonic_cancel(HK_id);
264 264 if( status != RTEMS_SUCCESSFUL ) {
265 265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
266 266 }
267 267 else {
268 268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
269 269 }
270 270
271 271 // startup phase
272 272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
273 273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
275 275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
276 276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
277 277 {
278 278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
279 279 {
280 280 isSynchronized = true;
281 281 }
282 282 else
283 283 {
284 284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
285 285
286 286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
287 287 }
288 288 }
289 289 status = rtems_rate_monotonic_cancel(HK_id);
290 290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
291 291
292 292 set_hk_lfr_reset_cause( POWER_ON );
293 293
294 294 while(1){ // launch the rate monotonic task
295 295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
296 296 if ( status != RTEMS_SUCCESSFUL ) {
297 297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
298 298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
299 299 }
300 300 else {
301 301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
302 302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
303 303 increment_seq_counter( &sequenceCounterHK );
304 304
305 305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
306 306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
307 307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
308 308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
309 309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
310 310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
311 311
312 312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
313 313
314 314 spacewire_read_statistics();
315 315
316 316 update_hk_with_grspw_stats();
317 317
318 318 set_hk_lfr_time_not_synchro();
319 319
320 320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
321 321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
322 322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
323 323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
324 324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
325 325
326 326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
327 327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
328 328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
329 329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
330 330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
331 331
332 332 hk_lfr_le_me_he_update();
333 333
334 334 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = cp_rpw_sc_rw1_rw2_f_flags;
335 335 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = cp_rpw_sc_rw3_rw4_f_flags;
336 336
337 337 // SEND PACKET
338 338 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
339 339 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
340 340 if (status != RTEMS_SUCCESSFUL) {
341 341 PRINTF1("in HOUS *** ERR send: %d\n", status)
342 342 }
343 343 }
344 344 }
345 345
346 346 PRINTF("in HOUS *** deleting task\n")
347 347
348 348 status = rtems_task_delete( RTEMS_SELF ); // should not return
349 349
350 350 return;
351 351 }
352 352
353 353 rtems_task avgv_task(rtems_task_argument argument)
354 354 {
355 355 #define MOVING_AVERAGE 16
356 356 rtems_status_code status;
357 357 static unsigned int v[MOVING_AVERAGE] = {0};
358 358 static unsigned int e1[MOVING_AVERAGE] = {0};
359 359 static unsigned int e2[MOVING_AVERAGE] = {0};
360 360 float average_v;
361 361 float average_e1;
362 362 float average_e2;
363 363 float newValue_v;
364 364 float newValue_e1;
365 365 float newValue_e2;
366 366 unsigned char k;
367 367 unsigned char indexOfOldValue;
368 368
369 369 BOOT_PRINTF("in AVGV ***\n");
370 370
371 371 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
372 372 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
373 373 if( status != RTEMS_SUCCESSFUL ) {
374 374 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
375 375 }
376 376 }
377 377
378 378 status = rtems_rate_monotonic_cancel(AVGV_id);
379 379 if( status != RTEMS_SUCCESSFUL ) {
380 380 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
381 381 }
382 382 else {
383 383 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
384 384 }
385 385
386 386 // initialize values
387 387 indexOfOldValue = MOVING_AVERAGE - 1;
388 388 average_v = INIT_FLOAT;
389 389 average_e1 = INIT_FLOAT;
390 390 average_e2 = INIT_FLOAT;
391 391 newValue_v = INIT_FLOAT;
392 392 newValue_e1 = INIT_FLOAT;
393 393 newValue_e2 = INIT_FLOAT;
394 394
395 395 k = INIT_CHAR;
396 396
397 397 while(1)
398 398 { // launch the rate monotonic task
399 399 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
400 400 if ( status != RTEMS_SUCCESSFUL )
401 401 {
402 402 PRINTF1( "in AVGV *** ERR period: %d\n", status);
403 403 }
404 404 else
405 405 {
406 406 // get new values
407 407 newValue_v = waveform_picker_regs->v;
408 408 newValue_e1 = waveform_picker_regs->e1;
409 409 newValue_e2 = waveform_picker_regs->e2;
410 410
411 411 // compute the moving average
412 412 average_v = average_v + newValue_v - v[k];
413 413 average_e1 = average_e1 + newValue_e1 - e1[k];
414 414 average_e2 = average_e2 + newValue_e2 - e2[k];
415 415
416 416 // store new values in buffers
417 417 v[k] = newValue_v;
418 418 e1[k] = newValue_e1;
419 419 e2[k] = newValue_e2;
420 420 }
421 421 if (k == (MOVING_AVERAGE-1))
422 422 {
423 423 k = 0;
424 424 PRINTF("tick\n");
425 425 }
426 426 else
427 427 {
428 428 k++;
429 429 }
430 430 //update int16 values
431 431 hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / ((float) MOVING_AVERAGE) );
432 432 hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / ((float) MOVING_AVERAGE) );
433 433 hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / ((float) MOVING_AVERAGE) );
434 434 }
435 435
436 436 PRINTF("in AVGV *** deleting task\n");
437 437
438 438 status = rtems_task_delete( RTEMS_SELF ); // should not return
439 439
440 440 return;
441 441 }
442 442
443 443 rtems_task dumb_task( rtems_task_argument unused )
444 444 {
445 445 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
446 446 *
447 447 * @param unused is the starting argument of the RTEMS task
448 448 *
449 449 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
450 450 *
451 451 */
452 452
453 453 unsigned int i;
454 454 unsigned int intEventOut;
455 455 unsigned int coarse_time = 0;
456 456 unsigned int fine_time = 0;
457 457 rtems_event_set event_out;
458 458
459 459 event_out = EVENT_SETS_NONE_PENDING;
460 460
461 461 BOOT_PRINTF("in DUMB *** \n")
462 462
463 463 while(1){
464 464 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
465 465 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
466 466 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
467 467 | RTEMS_EVENT_14,
468 468 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
469 469 intEventOut = (unsigned int) event_out;
470 470 for ( i=0; i<NB_RTEMS_EVENTS; i++)
471 471 {
472 472 if ( ((intEventOut >> i) & 1) != 0)
473 473 {
474 474 coarse_time = time_management_regs->coarse_time;
475 475 fine_time = time_management_regs->fine_time;
476 476 if (i==EVENT_12)
477 477 {
478 478 PRINTF1("%s\n", DUMB_MESSAGE_12)
479 479 }
480 480 if (i==EVENT_13)
481 481 {
482 482 PRINTF1("%s\n", DUMB_MESSAGE_13)
483 483 }
484 484 if (i==EVENT_14)
485 485 {
486 486 PRINTF1("%s\n", DUMB_MESSAGE_1)
487 487 }
488 488 }
489 489 }
490 490 }
491 491 }
492 492
493 493 //*****************************
494 494 // init housekeeping parameters
495 495
496 496 void init_housekeeping_parameters( void )
497 497 {
498 498 /** This function initialize the housekeeping_packet global variable with default values.
499 499 *
500 500 */
501 501
502 502 unsigned int i = 0;
503 503 unsigned char *parameters;
504 504 unsigned char sizeOfHK;
505 505
506 506 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
507 507
508 508 parameters = (unsigned char*) &housekeeping_packet;
509 509
510 510 for(i = 0; i< sizeOfHK; i++)
511 511 {
512 512 parameters[i] = INIT_CHAR;
513 513 }
514 514
515 515 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
516 516 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
517 517 housekeeping_packet.reserved = DEFAULT_RESERVED;
518 518 housekeeping_packet.userApplication = CCSDS_USER_APP;
519 519 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
520 520 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
521 521 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
522 522 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
523 523 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
524 524 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
525 525 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
526 526 housekeeping_packet.serviceType = TM_TYPE_HK;
527 527 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
528 528 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
529 529 housekeeping_packet.sid = SID_HK;
530 530
531 531 // init status word
532 532 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
533 533 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
534 534 // init software version
535 535 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
536 536 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
537 537 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
538 538 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
539 539 // init fpga version
540 540 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
541 541 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
542 542 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
543 543 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
544 544
545 545 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
546 546 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
547 547 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
548 548 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
549 549 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
550 550 }
551 551
552 552 void increment_seq_counter( unsigned short *packetSequenceControl )
553 553 {
554 554 /** This function increment the sequence counter passes in argument.
555 555 *
556 556 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
557 557 *
558 558 */
559 559
560 560 unsigned short segmentation_grouping_flag;
561 561 unsigned short sequence_cnt;
562 562
563 563 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
564 564 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
565 565
566 566 if ( sequence_cnt < SEQ_CNT_MAX)
567 567 {
568 568 sequence_cnt = sequence_cnt + 1;
569 569 }
570 570 else
571 571 {
572 572 sequence_cnt = 0;
573 573 }
574 574
575 575 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
576 576 }
577 577
578 578 void getTime( unsigned char *time)
579 579 {
580 580 /** This function write the current local time in the time buffer passed in argument.
581 581 *
582 582 */
583 583
584 584 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
585 585 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
586 586 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
587 587 time[3] = (unsigned char) (time_management_regs->coarse_time);
588 588 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
589 589 time[5] = (unsigned char) (time_management_regs->fine_time);
590 590 }
591 591
592 592 unsigned long long int getTimeAsUnsignedLongLongInt( )
593 593 {
594 594 /** This function write the current local time in the time buffer passed in argument.
595 595 *
596 596 */
597 597 unsigned long long int time;
598 598
599 599 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
600 600 + time_management_regs->fine_time;
601 601
602 602 return time;
603 603 }
604 604
605 605 void send_dumb_hk( void )
606 606 {
607 607 Packet_TM_LFR_HK_t dummy_hk_packet;
608 608 unsigned char *parameters;
609 609 unsigned int i;
610 610 rtems_id queue_id;
611 611
612 612 queue_id = RTEMS_ID_NONE;
613 613
614 614 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
615 615 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
616 616 dummy_hk_packet.reserved = DEFAULT_RESERVED;
617 617 dummy_hk_packet.userApplication = CCSDS_USER_APP;
618 618 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
619 619 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
620 620 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
621 621 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
622 622 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
623 623 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
624 624 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
625 625 dummy_hk_packet.serviceType = TM_TYPE_HK;
626 626 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
627 627 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
628 628 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
629 629 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
630 630 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
631 631 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
632 632 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
633 633 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
634 634 dummy_hk_packet.sid = SID_HK;
635 635
636 636 // init status word
637 637 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
638 638 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
639 639 // init software version
640 640 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
641 641 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
642 642 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
643 643 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
644 644 // init fpga version
645 645 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
646 646 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
647 647 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
648 648 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
649 649
650 650 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
651 651
652 652 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
653 653 {
654 654 parameters[i] = INT8_ALL_F;
655 655 }
656 656
657 657 get_message_queue_id_send( &queue_id );
658 658
659 659 rtems_message_queue_send( queue_id, &dummy_hk_packet,
660 660 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
661 661 }
662 662
663 663 void get_temperatures( unsigned char *temperatures )
664 664 {
665 665 unsigned char* temp_scm_ptr;
666 666 unsigned char* temp_pcb_ptr;
667 667 unsigned char* temp_fpga_ptr;
668 668
669 669 // SEL1 SEL0
670 670 // 0 0 => PCB
671 671 // 0 1 => FPGA
672 672 // 1 0 => SCM
673 673
674 674 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
675 675 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
676 676 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
677 677
678 678 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
679 679 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
680 680 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
681 681 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
682 682 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
683 683 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
684 684 }
685 685
686 686 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
687 687 {
688 688 unsigned char* v_ptr;
689 689 unsigned char* e1_ptr;
690 690 unsigned char* e2_ptr;
691 691
692 692 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
693 693 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
694 694 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
695 695
696 696 spacecraft_potential[BYTE_0] = v_ptr[0];
697 697 spacecraft_potential[BYTE_1] = v_ptr[1];
698 698 spacecraft_potential[BYTE_2] = e1_ptr[0];
699 699 spacecraft_potential[BYTE_3] = e1_ptr[1];
700 700 spacecraft_potential[BYTE_4] = e2_ptr[0];
701 701 spacecraft_potential[BYTE_5] = e2_ptr[1];
702 702 }
703 703
704 704 void get_cpu_load( unsigned char *resource_statistics )
705 705 {
706 706 unsigned char cpu_load;
707 707
708 708 cpu_load = lfr_rtems_cpu_usage_report();
709 709
710 710 // HK_LFR_CPU_LOAD
711 711 resource_statistics[0] = cpu_load;
712 712
713 713 // HK_LFR_CPU_LOAD_MAX
714 714 if (cpu_load > resource_statistics[1])
715 715 {
716 716 resource_statistics[1] = cpu_load;
717 717 }
718 718
719 719 // CPU_LOAD_AVE
720 720 resource_statistics[BYTE_2] = 0;
721 721
722 722 #ifndef PRINT_TASK_STATISTICS
723 723 rtems_cpu_usage_reset();
724 724 #endif
725 725
726 726 }
727 727
728 728 void set_hk_lfr_sc_potential_flag( bool state )
729 729 {
730 730 if (state == true)
731 731 {
732 732 housekeeping_packet.lfr_status_word[1] =
733 733 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
734 734 }
735 735 else
736 736 {
737 737 housekeeping_packet.lfr_status_word[1] =
738 738 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
739 739 }
740 740 }
741 741
742 742 void set_sy_lfr_pas_filter_enabled( bool state )
743 743 {
744 744 if (state == true)
745 745 {
746 746 housekeeping_packet.lfr_status_word[1] =
747 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
747 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
748 748 }
749 749 else
750 750 {
751 751 housekeeping_packet.lfr_status_word[1] =
752 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
752 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
753 753 }
754 754 }
755 755
756 756 void set_sy_lfr_watchdog_enabled( bool state )
757 757 {
758 758 if (state == true)
759 759 {
760 760 housekeeping_packet.lfr_status_word[1] =
761 761 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
762 762 }
763 763 else
764 764 {
765 765 housekeeping_packet.lfr_status_word[1] =
766 766 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
767 767 }
768 768 }
769 769
770 770 void set_hk_lfr_calib_enable( bool state )
771 771 {
772 772 if (state == true)
773 773 {
774 774 housekeeping_packet.lfr_status_word[1] =
775 775 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
776 776 }
777 777 else
778 778 {
779 779 housekeeping_packet.lfr_status_word[1] =
780 780 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
781 781 }
782 782 }
783 783
784 784 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
785 785 {
786 786 housekeeping_packet.lfr_status_word[1] =
787 787 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
788 788
789 789 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
790 790 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
791 791
792 792 }
793 793
794 794 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
795 795 {
796 796 int delta;
797 797
798 798 delta = 0;
799 799
800 800 if (newValue >= oldValue)
801 801 {
802 802 delta = newValue - oldValue;
803 803 }
804 804 else
805 805 {
806 806 delta = (255 - oldValue) + newValue;
807 807 }
808 808
809 809 *counter = *counter + delta;
810 810 }
811 811
812 812 void hk_lfr_le_update( void )
813 813 {
814 814 static hk_lfr_le_t old_hk_lfr_le = {0};
815 815 hk_lfr_le_t new_hk_lfr_le;
816 816 unsigned int counter;
817 817
818 818 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
819 819
820 820 // DPU
821 821 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
822 822 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
823 823 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
824 824 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
825 825 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
826 826 // TIMECODE
827 827 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
828 828 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
829 829 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
830 830 // TIME
831 831 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
832 832 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
833 833 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
834 834 //AHB
835 835 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
836 836 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
837 837 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
838 838
839 839 // update the le counter
840 840 // DPU
841 841 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
842 842 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
843 843 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
844 844 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
845 845 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
846 846 // TIMECODE
847 847 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
848 848 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
849 849 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
850 850 // TIME
851 851 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
852 852 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
853 853 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
854 854 // AHB
855 855 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
856 856
857 857 // DPU
858 858 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
859 859 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
860 860 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
861 861 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
862 862 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
863 863 // TIMECODE
864 864 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
865 865 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
866 866 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
867 867 // TIME
868 868 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
869 869 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
870 870 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
871 871 //AHB
872 872 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
873 873 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
874 874 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
875 875
876 876 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
877 877 // LE
878 878 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
879 879 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
880 880 }
881 881
882 882 void hk_lfr_me_update( void )
883 883 {
884 884 static hk_lfr_me_t old_hk_lfr_me = {0};
885 885 hk_lfr_me_t new_hk_lfr_me;
886 886 unsigned int counter;
887 887
888 888 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
889 889
890 890 // get the current values
891 891 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
892 892 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
893 893 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
894 894 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
895 895
896 896 // update the me counter
897 897 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
898 898 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
899 899 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
900 900 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
901 901
902 902 // store the counters for the next time
903 903 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
904 904 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
905 905 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
906 906 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
907 907
908 908 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
909 909 // ME
910 910 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
911 911 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
912 912 }
913 913
914 914 void hk_lfr_le_me_he_update()
915 915 {
916 916
917 917 unsigned int hk_lfr_he_cnt;
918 918
919 919 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
920 920
921 921 //update the low severity error counter
922 922 hk_lfr_le_update( );
923 923
924 924 //update the medium severity error counter
925 925 hk_lfr_me_update();
926 926
927 927 //update the high severity error counter
928 928 hk_lfr_he_cnt = 0;
929 929
930 930 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
931 931 // HE
932 932 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
933 933 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
934 934
935 935 }
936 936
937 937 void set_hk_lfr_time_not_synchro()
938 938 {
939 939 static unsigned char synchroLost = 1;
940 940 int synchronizationBit;
941 941
942 942 // get the synchronization bit
943 943 synchronizationBit =
944 944 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
945 945
946 946 switch (synchronizationBit)
947 947 {
948 948 case 0:
949 949 if (synchroLost == 1)
950 950 {
951 951 synchroLost = 0;
952 952 }
953 953 break;
954 954 case 1:
955 955 if (synchroLost == 0 )
956 956 {
957 957 synchroLost = 1;
958 958 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
959 959 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
960 960 }
961 961 break;
962 962 default:
963 963 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
964 964 break;
965 965 }
966 966
967 967 }
968 968
969 969 void set_hk_lfr_ahb_correctable() // CRITICITY L
970 970 {
971 971 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
972 972 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
973 973 * detected errors in the cache, in the integer unit and in the floating point unit.
974 974 *
975 975 * @param void
976 976 *
977 977 * @return void
978 978 *
979 979 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
980 980 *
981 981 */
982 982
983 983 unsigned int ahb_correctable;
984 984 unsigned int instructionErrorCounter;
985 985 unsigned int dataErrorCounter;
986 986 unsigned int fprfErrorCounter;
987 987 unsigned int iurfErrorCounter;
988 988
989 989 instructionErrorCounter = 0;
990 990 dataErrorCounter = 0;
991 991 fprfErrorCounter = 0;
992 992 iurfErrorCounter = 0;
993 993
994 994 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
995 995 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
996 996
997 997 ahb_correctable = instructionErrorCounter
998 998 + dataErrorCounter
999 999 + fprfErrorCounter
1000 1000 + iurfErrorCounter
1001 1001 + housekeeping_packet.hk_lfr_ahb_correctable;
1002 1002
1003 1003 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1004 1004
1005 1005 }
@@ -1,1812 +1,1795
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 = {0};
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 19 ring_node kcoefficient_node_1 = {0};
20 20 ring_node kcoefficient_node_2 = {0};
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_normal_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 shall not be lower than its default value
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 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1 shall not be lower than its default value
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 + DATAFIELD_OFFSET, 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 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET THE 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 + DATAFIELD_OFFSET, 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 + DATAFIELD_OFFSET, 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 * S1_BP_P0_SCALE) )
193 193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 194 if (aux > FLOAT_EQUAL_ZERO)
195 195 {
196 196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 197 flag = LFR_DEFAULT;
198 198 }
199 199 }
200 200
201 201 // SET THE PARAMETERS
202 202 if (flag == LFR_SUCCESSFUL)
203 203 {
204 204 flag = set_sy_lfr_s1_bp_p0( TC );
205 205 flag = set_sy_lfr_s1_bp_p1( TC );
206 206 }
207 207
208 208 return flag;
209 209 }
210 210
211 211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 212 {
213 213 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 214 *
215 215 * @param TC points to the TeleCommand packet that is being processed
216 216 * @param queue_id is the id of the queue which handles TM related to this execution step
217 217 *
218 218 */
219 219
220 220 int flag;
221 221 rtems_status_code status;
222 222 unsigned char sy_lfr_s2_bp_p0;
223 223 unsigned char sy_lfr_s2_bp_p1;
224 224 float aux;
225 225
226 226 flag = LFR_SUCCESSFUL;
227 227
228 228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 230 flag = LFR_DEFAULT;
231 231 }
232 232
233 233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235 235
236 236 // sy_lfr_s2_bp_p0
237 237 if (flag == LFR_SUCCESSFUL)
238 238 {
239 239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 240 {
241 241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 242 flag = WRONG_APP_DATA;
243 243 }
244 244 }
245 245 // sy_lfr_s2_bp_p1
246 246 if (flag == LFR_SUCCESSFUL)
247 247 {
248 248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 249 {
250 250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 251 flag = WRONG_APP_DATA;
252 252 }
253 253 }
254 254 //******************************************************************
255 255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 256 if (flag == LFR_SUCCESSFUL)
257 257 {
258 258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 261 if (aux > FLOAT_EQUAL_ZERO)
262 262 {
263 263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 264 flag = LFR_DEFAULT;
265 265 }
266 266 }
267 267
268 268 // SET THE PARAMETERS
269 269 if (flag == LFR_SUCCESSFUL)
270 270 {
271 271 flag = set_sy_lfr_s2_bp_p0( TC );
272 272 flag = set_sy_lfr_s2_bp_p1( TC );
273 273 }
274 274
275 275 return flag;
276 276 }
277 277
278 278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 279 {
280 280 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 281 *
282 282 * @param TC points to the TeleCommand packet that is being processed
283 283 * @param queue_id is the id of the queue which handles TM related to this execution step
284 284 *
285 285 */
286 286
287 287 int flag;
288 288
289 289 flag = LFR_DEFAULT;
290 290
291 291 flag = set_sy_lfr_kcoeff( TC, queue_id );
292 292
293 293 return flag;
294 294 }
295 295
296 296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 297 {
298 298 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 299 *
300 300 * @param TC points to the TeleCommand packet that is being processed
301 301 * @param queue_id is the id of the queue which handles TM related to this execution step
302 302 *
303 303 */
304 304
305 305 int flag;
306 306
307 307 flag = LFR_DEFAULT;
308 308
309 309 flag = set_sy_lfr_fbins( TC );
310 310
311 311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 312 merge_fbins_masks();
313 313
314 314 return flag;
315 315 }
316 316
317 317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 318 {
319 319 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 320 *
321 321 * @param TC points to the TeleCommand packet that is being processed
322 322 * @param queue_id is the id of the queue which handles TM related to this execution step
323 323 *
324 324 */
325 325
326 326 int flag;
327 327 unsigned char k;
328 328
329 329 flag = LFR_DEFAULT;
330 330 k = INIT_CHAR;
331 331
332 332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
333 333
334 334 if (flag == LFR_SUCCESSFUL)
335 335 {
336 336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
337 337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
338 338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
339 339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
340 340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
341 341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
342 342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
343 343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
344 344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
345 345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
346 346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
347 347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
348 348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
349 349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
350 350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
351 351
352 352 //****************************
353 353 // store PAS filter parameters
354 354 // sy_lfr_pas_filter_enabled
355 355 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
356 356 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
357 357 // sy_lfr_pas_filter_modulus
358 358 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
359 359 // sy_lfr_pas_filter_tbad
360 360 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
361 361 parameter_dump_packet.sy_lfr_pas_filter_tbad );
362 362 // sy_lfr_pas_filter_offset
363 363 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
364 364 // sy_lfr_pas_filter_shift
365 365 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
366 366 parameter_dump_packet.sy_lfr_pas_filter_shift );
367 367
368 368 //****************************************************
369 369 // store the parameter sy_lfr_sc_rw_delta_f as a float
370 370 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
371 371 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
372 372
373 373 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
374 374 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
375 375 {
376 376 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
377 377 }
378 378
379 379 //***********************************************
380 380 // store the parameter sy_lfr_rw.._k.. as a float
381 381 // rw1_k
382 382 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
383 383 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
384 384 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
385 385 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
386 386 // rw2_k
387 387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
388 388 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
389 389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
390 390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
391 391 // rw3_k
392 392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
393 393 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
394 394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
395 395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
396 396 // rw4_k
397 397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
398 398 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
399 399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
400 400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
401 401
402 402 }
403 403
404 404 return flag;
405 405 }
406 406
407 407 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
408 408 {
409 409 /** This function updates the LFR registers with the incoming sbm2 parameters.
410 410 *
411 411 * @param TC points to the TeleCommand packet that is being processed
412 412 * @param queue_id is the id of the queue which handles TM related to this execution step
413 413 *
414 414 */
415 415
416 416 unsigned int address;
417 417 rtems_status_code status;
418 418 unsigned int freq;
419 419 unsigned int bin;
420 420 unsigned int coeff;
421 421 unsigned char *kCoeffPtr;
422 422 unsigned char *kCoeffDumpPtr;
423 423
424 424 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
425 425 // F0 => 11 bins
426 426 // F1 => 13 bins
427 427 // F2 => 12 bins
428 428 // 36 bins to dump in two packets (30 bins max per packet)
429 429
430 430 //*********
431 431 // PACKET 1
432 432 // 11 F0 bins, 13 F1 bins and 6 F2 bins
433 433 kcoefficients_dump_1.destinationID = TC->sourceID;
434 434 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
435 435 for( freq = 0;
436 436 freq < NB_BINS_COMPRESSED_SM_F0;
437 437 freq++ )
438 438 {
439 439 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
440 440 bin = freq;
441 441 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
442 442 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
443 443 {
444 444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 445 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 446 ]; // 2 for the kcoeff_frequency
447 447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 449 }
450 450 }
451 451 for( freq = NB_BINS_COMPRESSED_SM_F0;
452 452 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
453 453 freq++ )
454 454 {
455 455 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
456 456 bin = freq - NB_BINS_COMPRESSED_SM_F0;
457 457 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
458 458 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
459 459 {
460 460 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
461 461 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
462 462 ]; // 2 for the kcoeff_frequency
463 463 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
464 464 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
465 465 }
466 466 }
467 467 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
468 468 freq < KCOEFF_BLK_NR_PKT1 ;
469 469 freq++ )
470 470 {
471 471 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
472 472 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
473 473 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
474 474 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
475 475 {
476 476 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
477 477 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
478 478 ]; // 2 for the kcoeff_frequency
479 479 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
480 480 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
481 481 }
482 482 }
483 483 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
484 484 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
485 485 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
486 486 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
487 487 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
488 488 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
489 489 // SEND DATA
490 490 kcoefficient_node_1.status = 1;
491 491 address = (unsigned int) &kcoefficient_node_1;
492 492 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
493 493 if (status != RTEMS_SUCCESSFUL) {
494 494 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
495 495 }
496 496
497 497 //********
498 498 // PACKET 2
499 499 // 6 F2 bins
500 500 kcoefficients_dump_2.destinationID = TC->sourceID;
501 501 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
502 502 for( freq = 0;
503 503 freq < KCOEFF_BLK_NR_PKT2;
504 504 freq++ )
505 505 {
506 506 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
507 507 bin = freq + KCOEFF_BLK_NR_PKT2;
508 508 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
509 509 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
510 510 {
511 511 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
512 512 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
513 513 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
514 514 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
515 515 }
516 516 }
517 517 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
518 518 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
519 519 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
520 520 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
521 521 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
522 522 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
523 523 // SEND DATA
524 524 kcoefficient_node_2.status = 1;
525 525 address = (unsigned int) &kcoefficient_node_2;
526 526 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
527 527 if (status != RTEMS_SUCCESSFUL) {
528 528 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
529 529 }
530 530
531 531 return status;
532 532 }
533 533
534 534 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
535 535 {
536 536 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
537 537 *
538 538 * @param queue_id is the id of the queue which handles TM related to this execution step.
539 539 *
540 540 * @return RTEMS directive status codes:
541 541 * - RTEMS_SUCCESSFUL - message sent successfully
542 542 * - RTEMS_INVALID_ID - invalid queue id
543 543 * - RTEMS_INVALID_SIZE - invalid message size
544 544 * - RTEMS_INVALID_ADDRESS - buffer is NULL
545 545 * - RTEMS_UNSATISFIED - out of message buffers
546 546 * - RTEMS_TOO_MANY - queue s limit has been reached
547 547 *
548 548 */
549 549
550 550 int status;
551 551
552 552 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
553 553 parameter_dump_packet.destinationID = TC->sourceID;
554 554
555 555 // UPDATE TIME
556 556 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
557 557 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
558 558 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
559 559 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
560 560 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
561 561 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
562 562 // SEND DATA
563 563 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
564 564 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
565 565 if (status != RTEMS_SUCCESSFUL) {
566 566 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
567 567 }
568 568
569 569 return status;
570 570 }
571 571
572 572 //***********************
573 573 // NORMAL MODE PARAMETERS
574 574
575 575 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
576 576 {
577 577 unsigned char msb;
578 578 unsigned char lsb;
579 579 int flag;
580 580 float aux;
581 581 rtems_status_code status;
582 582
583 583 unsigned int sy_lfr_n_swf_l;
584 584 unsigned int sy_lfr_n_swf_p;
585 585 unsigned int sy_lfr_n_asm_p;
586 586 unsigned char sy_lfr_n_bp_p0;
587 587 unsigned char sy_lfr_n_bp_p1;
588 588 unsigned char sy_lfr_n_cwf_long_f3;
589 589
590 590 flag = LFR_SUCCESSFUL;
591 591
592 592 //***************
593 593 // get parameters
594 594 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
595 595 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
596 596 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
597 597
598 598 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
599 599 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
600 600 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
601 601
602 602 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
603 603 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
604 604 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
605 605
606 606 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
607 607
608 608 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
609 609
610 610 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
611 611
612 612 //******************
613 613 // check consistency
614 614 // sy_lfr_n_swf_l
615 615 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
616 616 {
617 617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
618 618 flag = WRONG_APP_DATA;
619 619 }
620 620 // sy_lfr_n_swf_p
621 621 if (flag == LFR_SUCCESSFUL)
622 622 {
623 623 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
624 624 {
625 625 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
626 626 flag = WRONG_APP_DATA;
627 627 }
628 628 }
629 629 // sy_lfr_n_bp_p0
630 630 if (flag == LFR_SUCCESSFUL)
631 631 {
632 632 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
633 633 {
634 634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
635 635 flag = WRONG_APP_DATA;
636 636 }
637 637 }
638 638 // sy_lfr_n_asm_p
639 639 if (flag == LFR_SUCCESSFUL)
640 640 {
641 641 if (sy_lfr_n_asm_p == 0)
642 642 {
643 643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
644 644 flag = WRONG_APP_DATA;
645 645 }
646 646 }
647 647 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
648 648 if (flag == LFR_SUCCESSFUL)
649 649 {
650 650 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
651 651 if (aux > FLOAT_EQUAL_ZERO)
652 652 {
653 653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
654 654 flag = WRONG_APP_DATA;
655 655 }
656 656 }
657 657 // sy_lfr_n_bp_p1
658 658 if (flag == LFR_SUCCESSFUL)
659 659 {
660 660 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
661 661 {
662 662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
663 663 flag = WRONG_APP_DATA;
664 664 }
665 665 }
666 666 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
667 667 if (flag == LFR_SUCCESSFUL)
668 668 {
669 669 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
670 670 if (aux > FLOAT_EQUAL_ZERO)
671 671 {
672 672 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
673 673 flag = LFR_DEFAULT;
674 674 }
675 675 }
676 676 // sy_lfr_n_cwf_long_f3
677 677
678 678 return flag;
679 679 }
680 680
681 681 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
682 682 {
683 683 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
684 684 *
685 685 * @param TC points to the TeleCommand packet that is being processed
686 686 * @param queue_id is the id of the queue which handles TM related to this execution step
687 687 *
688 688 */
689 689
690 690 int result;
691 691
692 692 result = LFR_SUCCESSFUL;
693 693
694 694 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
695 695 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
696 696
697 697 return result;
698 698 }
699 699
700 700 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
701 701 {
702 702 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
703 703 *
704 704 * @param TC points to the TeleCommand packet that is being processed
705 705 * @param queue_id is the id of the queue which handles TM related to this execution step
706 706 *
707 707 */
708 708
709 709 int result;
710 710
711 711 result = LFR_SUCCESSFUL;
712 712
713 713 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
714 714 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
715 715
716 716 return result;
717 717 }
718 718
719 719 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
720 720 {
721 721 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
722 722 *
723 723 * @param TC points to the TeleCommand packet that is being processed
724 724 * @param queue_id is the id of the queue which handles TM related to this execution step
725 725 *
726 726 */
727 727
728 728 int result;
729 729
730 730 result = LFR_SUCCESSFUL;
731 731
732 732 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
733 733 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
734 734
735 735 return result;
736 736 }
737 737
738 738 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
739 739 {
740 740 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
741 741 *
742 742 * @param TC points to the TeleCommand packet that is being processed
743 743 * @param queue_id is the id of the queue which handles TM related to this execution step
744 744 *
745 745 */
746 746
747 747 int status;
748 748
749 749 status = LFR_SUCCESSFUL;
750 750
751 751 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
752 752
753 753 return status;
754 754 }
755 755
756 756 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
757 757 {
758 758 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
759 759 *
760 760 * @param TC points to the TeleCommand packet that is being processed
761 761 * @param queue_id is the id of the queue which handles TM related to this execution step
762 762 *
763 763 */
764 764
765 765 int status;
766 766
767 767 status = LFR_SUCCESSFUL;
768 768
769 769 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
770 770
771 771 return status;
772 772 }
773 773
774 774 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
775 775 {
776 776 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
777 777 *
778 778 * @param TC points to the TeleCommand packet that is being processed
779 779 * @param queue_id is the id of the queue which handles TM related to this execution step
780 780 *
781 781 */
782 782
783 783 int status;
784 784
785 785 status = LFR_SUCCESSFUL;
786 786
787 787 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
788 788
789 789 return status;
790 790 }
791 791
792 792 //**********************
793 793 // BURST MODE PARAMETERS
794 794 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
795 795 {
796 796 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
797 797 *
798 798 * @param TC points to the TeleCommand packet that is being processed
799 799 * @param queue_id is the id of the queue which handles TM related to this execution step
800 800 *
801 801 */
802 802
803 803 int status;
804 804
805 805 status = LFR_SUCCESSFUL;
806 806
807 807 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
808 808
809 809 return status;
810 810 }
811 811
812 812 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
813 813 {
814 814 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
815 815 *
816 816 * @param TC points to the TeleCommand packet that is being processed
817 817 * @param queue_id is the id of the queue which handles TM related to this execution step
818 818 *
819 819 */
820 820
821 821 int status;
822 822
823 823 status = LFR_SUCCESSFUL;
824 824
825 825 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
826 826
827 827 return status;
828 828 }
829 829
830 830 //*********************
831 831 // SBM1 MODE PARAMETERS
832 832 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
833 833 {
834 834 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
835 835 *
836 836 * @param TC points to the TeleCommand packet that is being processed
837 837 * @param queue_id is the id of the queue which handles TM related to this execution step
838 838 *
839 839 */
840 840
841 841 int status;
842 842
843 843 status = LFR_SUCCESSFUL;
844 844
845 845 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
846 846
847 847 return status;
848 848 }
849 849
850 850 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
851 851 {
852 852 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
853 853 *
854 854 * @param TC points to the TeleCommand packet that is being processed
855 855 * @param queue_id is the id of the queue which handles TM related to this execution step
856 856 *
857 857 */
858 858
859 859 int status;
860 860
861 861 status = LFR_SUCCESSFUL;
862 862
863 863 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
864 864
865 865 return status;
866 866 }
867 867
868 868 //*********************
869 869 // SBM2 MODE PARAMETERS
870 870 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
871 871 {
872 872 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
873 873 *
874 874 * @param TC points to the TeleCommand packet that is being processed
875 875 * @param queue_id is the id of the queue which handles TM related to this execution step
876 876 *
877 877 */
878 878
879 879 int status;
880 880
881 881 status = LFR_SUCCESSFUL;
882 882
883 883 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
884 884
885 885 return status;
886 886 }
887 887
888 888 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
889 889 {
890 890 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
891 891 *
892 892 * @param TC points to the TeleCommand packet that is being processed
893 893 * @param queue_id is the id of the queue which handles TM related to this execution step
894 894 *
895 895 */
896 896
897 897 int status;
898 898
899 899 status = LFR_SUCCESSFUL;
900 900
901 901 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
902 902
903 903 return status;
904 904 }
905 905
906 906 //*******************
907 907 // TC_LFR_UPDATE_INFO
908 908 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
909 909 {
910 910 unsigned int status;
911 911
912 912 status = LFR_DEFAULT;
913 913
914 914 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
915 915 || (mode == LFR_MODE_BURST)
916 916 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
917 917 {
918 918 status = LFR_SUCCESSFUL;
919 919 }
920 920 else
921 921 {
922 922 status = LFR_DEFAULT;
923 923 }
924 924
925 925 return status;
926 926 }
927 927
928 928 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
929 929 {
930 930 unsigned int status;
931 931
932 932 status = LFR_DEFAULT;
933 933
934 934 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
935 935 || (mode == TDS_MODE_BURST)
936 936 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
937 937 || (mode == TDS_MODE_LFM))
938 938 {
939 939 status = LFR_SUCCESSFUL;
940 940 }
941 941 else
942 942 {
943 943 status = LFR_DEFAULT;
944 944 }
945 945
946 946 return status;
947 947 }
948 948
949 949 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
950 950 {
951 951 unsigned int status;
952 952
953 953 status = LFR_DEFAULT;
954 954
955 955 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
956 956 || (mode == THR_MODE_BURST))
957 957 {
958 958 status = LFR_SUCCESSFUL;
959 959 }
960 960 else
961 961 {
962 962 status = LFR_DEFAULT;
963 963 }
964 964
965 965 return status;
966 966 }
967 967
968 968 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
969 969 {
970 970 unsigned char flag;
971 971 unsigned char flagPosInByte;
972 972 unsigned char newFlag;
973 973 unsigned char flagMask;
974 974
975 975 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
976 976 if (isnan(value))
977 977 {
978 978 flag = FLAG_NAN;
979 979 }
980 980 else
981 981 {
982 982 flag = FLAG_IAN;
983 983 }
984 984
985 985 switch(wheel)
986 986 {
987 987 case WHEEL_1:
988 988 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
989 989 flagMask = ~(1 << flagPosInByte);
990 990 newFlag = flag << flagPosInByte;
991 991 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
992 992 break;
993 993 case WHEEL_2:
994 994 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
995 995 flagMask = ~(1 << flagPosInByte);
996 996 newFlag = flag << flagPosInByte;
997 997 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
998 998 break;
999 999 case WHEEL_3:
1000 1000 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1001 1001 flagMask = ~(1 << flagPosInByte);
1002 1002 newFlag = flag << flagPosInByte;
1003 1003 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1004 1004 break;
1005 1005 case WHEEL_4:
1006 1006 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1007 1007 flagMask = ~(1 << flagPosInByte);
1008 1008 newFlag = flag << flagPosInByte;
1009 1009 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1010 1010 break;
1011 1011 default:
1012 1012 break;
1013 1013 }
1014 1014 }
1015 1015
1016 1016 void set_hk_lfr_sc_rw_f_flags( void )
1017 1017 {
1018 1018 // RW1
1019 1019 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1020 1020 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1021 1021 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1022 1022 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1023 1023
1024 1024 // RW2
1025 1025 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1026 1026 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1027 1027 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1028 1028 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1029 1029
1030 1030 // RW3
1031 1031 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1032 1032 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1033 1033 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1034 1034 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1035 1035
1036 1036 // RW4
1037 1037 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1038 1038 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1039 1039 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1040 1040 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1041 1041 }
1042 1042
1043 1043 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1044 1044 {
1045 1045 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1046 1046 *
1047 1047 * @param TC points to the TeleCommand packet that is being processed
1048 1048 *
1049 1049 */
1050 1050
1051 1051 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1052 1052
1053 1053 bytePosPtr = (unsigned char *) &TC->packetID;
1054 1054
1055 1055 // rw1_f
1056 1056 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1057 1057 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1058 1058 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1059 1059 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1060 1060
1061 1061 // rw2_f
1062 1062 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1063 1063 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1064 1064 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1065 1065 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1066 1066
1067 1067 // rw3_f
1068 1068 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1069 1069 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1070 1070 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1071 1071 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1072 1072
1073 1073 // rw4_f
1074 1074 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1075 1075 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1076 1076 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1077 1077 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1078 1078
1079 1079 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1080 1080
1081 1081 }
1082 1082
1083 1083 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff )
1084 1084 {
1085 1085 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1086 1086 *
1087 1087 * @param fbins_mask
1088 1088 * @param rw_f is the reaction wheel frequency to filter
1089 1089 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1090 1090 * @param flag [true] filtering enabled [false] filtering disabled
1091 1091 *
1092 1092 * @return void
1093 1093 *
1094 1094 */
1095 1095
1096 1096 float f_RW_min;
1097 1097 float f_RW_MAX;
1098 1098 float fi_min;
1099 1099 float fi_MAX;
1100 1100 float fi;
1101 1101 float deltaBelow;
1102 1102 float deltaAbove;
1103 1103 int binBelow;
1104 1104 int binAbove;
1105 1105 int closestBin;
1106 1106 unsigned int whichByte;
1107 1107 int selectedByte;
1108 1108 int bin;
1109 1109 int binToRemove[NB_BINS_TO_REMOVE];
1110 1110 int i;
1111 1111
1112 1112 closestBin = 0;
1113 1113 whichByte = 0;
1114 1114 bin = 0;
1115 1115
1116 1116 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1117 1117 {
1118 1118 binToRemove[i] = -1;
1119 1119 }
1120 1120
1121 1121 if (!isnan(rw_f))
1122 1122 {
1123 1123
1124 1124 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1125 1125 f_RW_min = rw_f - ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1126 1126 f_RW_MAX = rw_f + ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV);
1127 1127
1128 1128 // compute the index of the frequency bin immediately below rw_f
1129 1129 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1130 1130 deltaBelow = rw_f - binBelow * deltaFreq;
1131 1131
1132 1132 // compute the index of the frequency bin immediately above rw_f
1133 1133 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1134 1134 deltaAbove = binAbove * deltaFreq - rw_f;
1135 1135
1136 1136 // search the closest bin
1137 1137 if (deltaAbove > deltaBelow)
1138 1138 {
1139 1139 closestBin = binBelow;
1140 1140 }
1141 1141 else
1142 1142 {
1143 1143 closestBin = binAbove;
1144 1144 }
1145 1145
1146 1146 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1147 1147 fi = closestBin * deltaFreq;
1148 1148 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1149 1149 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1150 1150
1151 1151 //**************************************************************************************
1152 1152 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1153 1153 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1154 1154 //**************************************************************************************
1155 1155
1156 1156 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1157 1157 // => remove f_(i), f_(i-1) and f_(i+1)
1158 1158 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1159 1159 {
1160 1160 binToRemove[0] = (closestBin - 1) - 1;
1161 1161 binToRemove[1] = (closestBin) - 1;
1162 1162 binToRemove[2] = (closestBin + 1) - 1;
1163 1163 }
1164 1164 // 2. ELSE
1165 1165 // => remove the two f_(i) which are around f_RW
1166 1166 else
1167 1167 {
1168 1168 binToRemove[0] = (binBelow) - 1;
1169 1169 binToRemove[1] = (binAbove) - 1;
1170 1170 binToRemove[2] = (-1);
1171 1171 }
1172 1172
1173 1173 for (i = 0; i < NB_BINS_TO_REMOVE; i++)
1174 1174 {
1175 1175 bin = binToRemove[i];
1176 1176 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1177 1177 {
1178 1178
1179 1179 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1180 1180 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1181 1181 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1182 1182 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1183 1183 }
1184 1184 }
1185 1185 }
1186 1186 }
1187 1187
1188 1188 void build_sy_lfr_rw_mask( unsigned int channel )
1189 1189 {
1190 1190 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1191 1191 unsigned char *maskPtr;
1192 1192 double deltaF;
1193 1193 unsigned k;
1194 1194
1195 1195 maskPtr = NULL;
1196 1196 deltaF = DELTAF_F2;
1197 1197
1198 1198 switch (channel)
1199 1199 {
1200 1200 case CHANNELF0:
1201 1201 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1202 1202 deltaF = DELTAF_F0;
1203 1203 break;
1204 1204 case CHANNELF1:
1205 1205 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1206 1206 deltaF = DELTAF_F1;
1207 1207 break;
1208 1208 case CHANNELF2:
1209 1209 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1210 1210 deltaF = DELTAF_F2;
1211 1211 break;
1212 1212 default:
1213 1213 break;
1214 1214 }
1215 1215
1216 1216 for (k = 0; k < BYTES_PER_MASK; k++)
1217 1217 {
1218 1218 local_rw_fbins_mask[k] = INT8_ALL_F;
1219 1219 }
1220 1220
1221 1221 // RW1
1222 1222 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1223 1223 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1224 1224 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1225 1225 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1226 1226
1227 1227 // RW2
1228 1228 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1229 1229 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1230 1230 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1231 1231 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1232 1232
1233 1233 // RW3
1234 1234 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1235 1235 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1236 1236 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1237 1237 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1238 1238
1239 1239 // RW4
1240 1240 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1241 1241 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1242 1242 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1243 1243 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1244 1244
1245 1245 // update the value of the fbins related to reaction wheels frequency filtering
1246 1246 if (maskPtr != NULL)
1247 1247 {
1248 1248 for (k = 0; k < BYTES_PER_MASK; k++)
1249 1249 {
1250 1250 maskPtr[k] = local_rw_fbins_mask[k];
1251 1251 }
1252 1252 }
1253 1253 }
1254 1254
1255 1255 void build_sy_lfr_rw_masks( void )
1256 1256 {
1257 1257 build_sy_lfr_rw_mask( CHANNELF0 );
1258 1258 build_sy_lfr_rw_mask( CHANNELF1 );
1259 1259 build_sy_lfr_rw_mask( CHANNELF2 );
1260 1260 }
1261 1261
1262 1262 void merge_fbins_masks( void )
1263 1263 {
1264 1264 unsigned char k;
1265 1265
1266 1266 unsigned char *fbins_f0;
1267 1267 unsigned char *fbins_f1;
1268 1268 unsigned char *fbins_f2;
1269 1269 unsigned char *rw_mask_f0;
1270 1270 unsigned char *rw_mask_f1;
1271 1271 unsigned char *rw_mask_f2;
1272 1272
1273 1273 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1274 1274 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1275 1275 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1276 1276 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1277 1277 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1278 1278 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1279 1279
1280 1280 for( k=0; k < BYTES_PER_MASK; k++ )
1281 1281 {
1282 1282 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1283 1283 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1284 1284 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1285 1285 }
1286 1286 }
1287 1287
1288 1288 //***********
1289 1289 // FBINS MASK
1290 1290
1291 1291 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1292 1292 {
1293 1293 int status;
1294 1294 unsigned int k;
1295 1295 unsigned char *fbins_mask_dump;
1296 1296 unsigned char *fbins_mask_TC;
1297 1297
1298 1298 status = LFR_SUCCESSFUL;
1299 1299
1300 1300 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1301 1301 fbins_mask_TC = TC->dataAndCRC;
1302 1302
1303 1303 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1304 1304 {
1305 1305 fbins_mask_dump[k] = fbins_mask_TC[k];
1306 1306 }
1307 1307
1308 1308 return status;
1309 1309 }
1310 1310
1311 1311 //***************************
1312 1312 // TC_LFR_LOAD_PAS_FILTER_PAR
1313 1313
1314 1314 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1315 1315 {
1316 1316 int flag;
1317 1317 rtems_status_code status;
1318 1318
1319 1319 unsigned char sy_lfr_pas_filter_enabled;
1320 1320 unsigned char sy_lfr_pas_filter_modulus;
1321 1321 float sy_lfr_pas_filter_tbad;
1322 1322 unsigned char sy_lfr_pas_filter_offset;
1323 1323 float sy_lfr_pas_filter_shift;
1324 1324 float sy_lfr_sc_rw_delta_f;
1325 1325 char *parPtr;
1326 1326
1327 1327 flag = LFR_SUCCESSFUL;
1328 1328 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1329 1329 sy_lfr_pas_filter_shift = INIT_FLOAT;
1330 1330 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1331 1331 parPtr = NULL;
1332 1332
1333 1333 //***************
1334 1334 // get parameters
1335 1335 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1336 1336 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1337 1337 copyFloatByChar(
1338 1338 (unsigned char*) &sy_lfr_pas_filter_tbad,
1339 1339 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1340 1340 );
1341 1341 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1342 1342 copyFloatByChar(
1343 1343 (unsigned char*) &sy_lfr_pas_filter_shift,
1344 1344 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1345 1345 );
1346 1346 copyFloatByChar(
1347 1347 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1348 1348 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1349 1349 );
1350 1350
1351 1351 //******************
1352 1352 // CHECK CONSISTENCY
1353 1353
1354 1354 //**************************
1355 1355 // sy_lfr_pas_filter_enabled
1356 1356 // nothing to check, value is 0 or 1
1357 1357
1358 1358 //**************************
1359 1359 // sy_lfr_pas_filter_modulus
1360 1360 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1361 1361 {
1362 1362 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1363 1363 flag = WRONG_APP_DATA;
1364 1364 }
1365 1365
1366 1366 //***********************
1367 1367 // sy_lfr_pas_filter_tbad
1368 1368 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1369 1369 {
1370 1370 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1371 1371 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1372 1372 flag = WRONG_APP_DATA;
1373 1373 }
1374 1374
1375 1375 //*************************
1376 1376 // sy_lfr_pas_filter_offset
1377 1377 if (flag == LFR_SUCCESSFUL)
1378 1378 {
1379 1379 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1380 1380 {
1381 1381 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1382 1382 flag = WRONG_APP_DATA;
1383 1383 }
1384 1384 }
1385 1385
1386 1386 //************************
1387 1387 // sy_lfr_pas_filter_shift
1388 1388 if (flag == LFR_SUCCESSFUL)
1389 1389 {
1390 1390 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1391 1391 {
1392 1392 parPtr = (char*) &sy_lfr_pas_filter_shift;
1393 1393 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1394 1394 flag = WRONG_APP_DATA;
1395 1395 }
1396 1396 }
1397 1397
1398 1398 //*************************************
1399 1399 // check global coherency of the values
1400 1400 if (flag == LFR_SUCCESSFUL)
1401 1401 {
1402 1402 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1403 1403 {
1404 1404 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1405 1405 flag = WRONG_APP_DATA;
1406 1406 }
1407 1407 }
1408 1408
1409 1409 //*********************
1410 1410 // sy_lfr_sc_rw_delta_f
1411 1411 // nothing to check, no default value in the ICD
1412 1412
1413 1413 return flag;
1414 1414 }
1415 1415
1416 1416 //**************
1417 1417 // KCOEFFICIENTS
1418 1418 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1419 1419 {
1420 1420 unsigned int kcoeff;
1421 1421 unsigned short sy_lfr_kcoeff_frequency;
1422 1422 unsigned short bin;
1423 1423 float *kcoeffPtr_norm;
1424 1424 float *kcoeffPtr_sbm;
1425 1425 int status;
1426 1426 unsigned char *kcoeffLoadPtr;
1427 1427 unsigned char *kcoeffNormPtr;
1428 1428 unsigned char *kcoeffSbmPtr_a;
1429 1429 unsigned char *kcoeffSbmPtr_b;
1430 1430
1431 1431 sy_lfr_kcoeff_frequency = 0;
1432 1432 bin = 0;
1433 1433 kcoeffPtr_norm = NULL;
1434 1434 kcoeffPtr_sbm = NULL;
1435 1435 status = LFR_SUCCESSFUL;
1436 1436
1437 1437 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1438 1438 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1439 1439
1440 1440
1441 1441 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1442 1442 {
1443 1443 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1444 1444 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1445 1445 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1446 1446 status = LFR_DEFAULT;
1447 1447 }
1448 1448 else
1449 1449 {
1450 1450 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1451 1451 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1452 1452 {
1453 1453 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1454 1454 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1455 1455 bin = sy_lfr_kcoeff_frequency;
1456 1456 }
1457 1457 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1458 1458 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1459 1459 {
1460 1460 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1461 1461 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1462 1462 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1463 1463 }
1464 1464 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1465 1465 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1466 1466 {
1467 1467 kcoeffPtr_norm = k_coeff_intercalib_f2;
1468 1468 kcoeffPtr_sbm = NULL;
1469 1469 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1470 1470 }
1471 1471 }
1472 1472
1473 1473 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1474 1474 {
1475 1475 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1476 1476 {
1477 1477 // destination
1478 1478 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1479 1479 // source
1480 1480 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1481 1481 // copy source to destination
1482 1482 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1483 1483 }
1484 1484 }
1485 1485
1486 1486 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1487 1487 {
1488 1488 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1489 1489 {
1490 1490 // destination
1491 1491 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1492 1492 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1493 1493 // source
1494 1494 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1495 1495 // copy source to destination
1496 1496 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1497 1497 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1498 1498 }
1499 1499 }
1500 1500
1501 1501 // print_k_coeff();
1502 1502
1503 1503 return status;
1504 1504 }
1505 1505
1506 1506 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1507 1507 {
1508 1508 destination[BYTE_0] = source[BYTE_0];
1509 1509 destination[BYTE_1] = source[BYTE_1];
1510 1510 destination[BYTE_2] = source[BYTE_2];
1511 1511 destination[BYTE_3] = source[BYTE_3];
1512 1512 }
1513 1513
1514 1514 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1515 1515 {
1516 1516 destination[BYTE_0] = source[BYTE_0];
1517 1517 destination[BYTE_1] = source[BYTE_1];
1518 1518 destination[BYTE_2] = source[BYTE_2];
1519 1519 destination[BYTE_3] = source[BYTE_3];
1520 1520 }
1521 1521
1522 1522 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1523 1523 {
1524 1524 destination[BYTE_0] = source[BYTE_0];
1525 1525 destination[BYTE_1] = source[BYTE_1];
1526 1526 }
1527 1527
1528 1528 void floatToChar( float value, unsigned char* ptr)
1529 1529 {
1530 1530 unsigned char* valuePtr;
1531 1531
1532 1532 valuePtr = (unsigned char*) &value;
1533 1533
1534 1534 ptr[BYTE_0] = valuePtr[BYTE_0];
1535 1535 ptr[BYTE_1] = valuePtr[BYTE_1];
1536 1536 ptr[BYTE_2] = valuePtr[BYTE_2];
1537 1537 ptr[BYTE_3] = valuePtr[BYTE_3];
1538
1539 // <TEST>
1540 printf("\n\n<TEST>\n");
1541
1542 float aux = NAN;
1543 unsigned char* auxPtr;
1544 auxPtr = (unsigned char*) &aux;
1545
1546 printf("aux = %f, value = %f\n", aux, value);
1547
1548 auxPtr[BYTE_0] = valuePtr[BYTE_0];
1549 auxPtr[BYTE_1] = valuePtr[BYTE_1];
1550 auxPtr[BYTE_2] = valuePtr[BYTE_2];
1551 auxPtr[BYTE_3] = valuePtr[BYTE_3];
1552
1553 printf("aux = %f\n", aux);
1554 // </TEST>
1555 1538 }
1556 1539
1557 1540 //**********
1558 1541 // init dump
1559 1542
1560 1543 void init_parameter_dump( void )
1561 1544 {
1562 1545 /** This function initialize the parameter_dump_packet global variable with default values.
1563 1546 *
1564 1547 */
1565 1548
1566 1549 unsigned int k;
1567 1550
1568 1551 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1569 1552 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1570 1553 parameter_dump_packet.reserved = CCSDS_RESERVED;
1571 1554 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1572 1555 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1573 1556 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1574 1557 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1575 1558 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1576 1559 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1577 1560 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1578 1561 // DATA FIELD HEADER
1579 1562 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1580 1563 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1581 1564 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1582 1565 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1583 1566 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1584 1567 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1585 1568 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1586 1569 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1587 1570 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1588 1571 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1589 1572 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1590 1573
1591 1574 //******************
1592 1575 // COMMON PARAMETERS
1593 1576 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1594 1577 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1595 1578
1596 1579 //******************
1597 1580 // NORMAL PARAMETERS
1598 1581 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1599 1582 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1600 1583 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1601 1584 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1602 1585 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1603 1586 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1604 1587 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1605 1588 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1606 1589 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1607 1590
1608 1591 //*****************
1609 1592 // BURST PARAMETERS
1610 1593 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1611 1594 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1612 1595
1613 1596 //****************
1614 1597 // SBM1 PARAMETERS
1615 1598 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
1616 1599 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1617 1600
1618 1601 //****************
1619 1602 // SBM2 PARAMETERS
1620 1603 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1621 1604 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1622 1605
1623 1606 //************
1624 1607 // FBINS MASKS
1625 1608 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1626 1609 {
1627 1610 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1628 1611 }
1629 1612
1630 1613 // PAS FILTER PARAMETERS
1631 1614 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1632 1615 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1633 1616 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1634 1617 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1635 1618 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1636 1619 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1637 1620 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1638 1621
1639 1622 // RW1_K
1640 1623 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1641 1624 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1642 1625 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1643 1626 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1644 1627 // RW2_K
1645 1628 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1646 1629 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1647 1630 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1648 1631 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1649 1632 // RW3_K
1650 1633 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1651 1634 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1652 1635 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1653 1636 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1654 1637 // RW4_K
1655 1638 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1656 1639 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1657 1640 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1658 1641 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1659 1642
1660 1643 // LFR_RW_MASK
1661 1644 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1662 1645 {
1663 1646 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1664 1647 }
1665 1648
1666 1649 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1667 1650 merge_fbins_masks();
1668 1651 }
1669 1652
1670 1653 void init_kcoefficients_dump( void )
1671 1654 {
1672 1655 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1673 1656 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1674 1657
1675 1658 kcoefficient_node_1.previous = NULL;
1676 1659 kcoefficient_node_1.next = NULL;
1677 1660 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1678 1661 kcoefficient_node_1.coarseTime = INIT_CHAR;
1679 1662 kcoefficient_node_1.fineTime = INIT_CHAR;
1680 1663 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1681 1664 kcoefficient_node_1.status = INIT_CHAR;
1682 1665
1683 1666 kcoefficient_node_2.previous = NULL;
1684 1667 kcoefficient_node_2.next = NULL;
1685 1668 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1686 1669 kcoefficient_node_2.coarseTime = INIT_CHAR;
1687 1670 kcoefficient_node_2.fineTime = INIT_CHAR;
1688 1671 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1689 1672 kcoefficient_node_2.status = INIT_CHAR;
1690 1673 }
1691 1674
1692 1675 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1693 1676 {
1694 1677 unsigned int k;
1695 1678 unsigned int packetLength;
1696 1679
1697 1680 packetLength =
1698 1681 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1699 1682
1700 1683 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1701 1684 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1702 1685 kcoefficients_dump->reserved = CCSDS_RESERVED;
1703 1686 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1704 1687 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1705 1688 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1706 1689 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1707 1690 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1708 1691 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1709 1692 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1710 1693 // DATA FIELD HEADER
1711 1694 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1712 1695 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1713 1696 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1714 1697 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1715 1698 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1716 1699 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1717 1700 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1718 1701 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1719 1702 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1720 1703 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1721 1704 kcoefficients_dump->sid = SID_K_DUMP;
1722 1705
1723 1706 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1724 1707 kcoefficients_dump->pkt_nr = PKTNR_1;
1725 1708 kcoefficients_dump->blk_nr = blk_nr;
1726 1709
1727 1710 //******************
1728 1711 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1729 1712 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1730 1713 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1731 1714 {
1732 1715 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1733 1716 }
1734 1717 }
1735 1718
1736 1719 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1737 1720 {
1738 1721 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1739 1722 *
1740 1723 * @param packet_sequence_control points to the packet sequence control which will be incremented
1741 1724 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1742 1725 *
1743 1726 * If the destination ID is not known, a dedicated counter is incremented.
1744 1727 *
1745 1728 */
1746 1729
1747 1730 unsigned short sequence_cnt;
1748 1731 unsigned short segmentation_grouping_flag;
1749 1732 unsigned short new_packet_sequence_control;
1750 1733 unsigned char i;
1751 1734
1752 1735 switch (destination_id)
1753 1736 {
1754 1737 case SID_TC_GROUND:
1755 1738 i = GROUND;
1756 1739 break;
1757 1740 case SID_TC_MISSION_TIMELINE:
1758 1741 i = MISSION_TIMELINE;
1759 1742 break;
1760 1743 case SID_TC_TC_SEQUENCES:
1761 1744 i = TC_SEQUENCES;
1762 1745 break;
1763 1746 case SID_TC_RECOVERY_ACTION_CMD:
1764 1747 i = RECOVERY_ACTION_CMD;
1765 1748 break;
1766 1749 case SID_TC_BACKUP_MISSION_TIMELINE:
1767 1750 i = BACKUP_MISSION_TIMELINE;
1768 1751 break;
1769 1752 case SID_TC_DIRECT_CMD:
1770 1753 i = DIRECT_CMD;
1771 1754 break;
1772 1755 case SID_TC_SPARE_GRD_SRC1:
1773 1756 i = SPARE_GRD_SRC1;
1774 1757 break;
1775 1758 case SID_TC_SPARE_GRD_SRC2:
1776 1759 i = SPARE_GRD_SRC2;
1777 1760 break;
1778 1761 case SID_TC_OBCP:
1779 1762 i = OBCP;
1780 1763 break;
1781 1764 case SID_TC_SYSTEM_CONTROL:
1782 1765 i = SYSTEM_CONTROL;
1783 1766 break;
1784 1767 case SID_TC_AOCS:
1785 1768 i = AOCS;
1786 1769 break;
1787 1770 case SID_TC_RPW_INTERNAL:
1788 1771 i = RPW_INTERNAL;
1789 1772 break;
1790 1773 default:
1791 1774 i = GROUND;
1792 1775 break;
1793 1776 }
1794 1777
1795 1778 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1796 1779 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1797 1780
1798 1781 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1799 1782
1800 1783 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1801 1784 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1802 1785
1803 1786 // increment the sequence counter
1804 1787 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1805 1788 {
1806 1789 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1807 1790 }
1808 1791 else
1809 1792 {
1810 1793 sequenceCounters_TM_DUMP[ i ] = 0;
1811 1794 }
1812 1795 }
General Comments 0
You need to be logged in to leave comments. Login now