##// END OF EJS Templates
Bug 657 HK_LFR_xE_CNT doesn't manage the wrap of 8bits counter error
paul -
r343:66679eb623f2 R3++ draft
parent child
Show More
@@ -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 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 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 delta = (255 - oldValue) + newValue;
806 delta = (CONST_256 - 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 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
818 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_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 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
888 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_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 }
General Comments 0
You need to be logged in to leave comments. Login now