##// END OF EJS Templates
correction de Bug 514, lfr_reset_cause = power_on
paul -
r226:f5d7b21b3770 R3
parent child
Show More
@@ -1,58 +1,69
1 1 #ifndef FSW_MISC_H_INCLUDED
2 2 #define FSW_MISC_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6 #include <grspw.h>
7 7 #include <grlib_regs.h>
8 8
9 9 #include "fsw_params.h"
10 10 #include "fsw_spacewire.h"
11 11 #include "lfr_cpu_usage_report.h"
12 12
13 enum lfr_reset_cause_t{
14 UNKNOWN_CAUSE,
15 POWER_ON,
16 TC_RESET,
17 WATCHDOG,
18 ERROR_RESET,
19 UNEXP_RESET
20 };
21
22 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
23
13 24 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
14 25 rtems_id HK_id; // id of the HK rate monotonic period
15 26
16 27 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
17 28 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
18 29 void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
19 30 void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
20 31 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
21 32
22 33 // SERIAL LINK
23 34 int send_console_outputs_on_apbuart_port( void );
24 35 int enable_apbuart_transmitter( void );
25 36 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
26 37
27 38 // RTEMS TASKS
28 39 rtems_task stat_task( rtems_task_argument argument );
29 40 rtems_task hous_task( rtems_task_argument argument );
30 41 rtems_task dumb_task( rtems_task_argument unused );
31 42
32 43 void init_housekeeping_parameters( void );
33 44 void increment_seq_counter(unsigned short *packetSequenceControl);
34 45 void getTime( unsigned char *time);
35 46 unsigned long long int getTimeAsUnsignedLongLongInt( );
36 47 void send_dumb_hk( void );
37 48 void get_temperatures( unsigned char *temperatures );
38 49 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
39 50 void get_cpu_load( unsigned char *resource_statistics );
40 51 void set_hk_lfr_sc_potential_flag( bool state );
41 52 void set_hk_lfr_mag_fields_flag( bool state );
42 53 void set_hk_lfr_calib_enable( bool state );
43
54 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
44 55
45 56 extern int sched_yield( void );
46 57 extern void rtems_cpu_usage_reset();
47 58 extern ring_node *current_ring_node_f3;
48 59 extern ring_node *ring_node_to_send_cwf_f3;
49 60 extern ring_node waveform_ring_f3[];
50 61 extern unsigned short sequenceCounterHK;
51 62
52 63 extern unsigned char hk_lfr_q_sd_fifo_size_max;
53 64 extern unsigned char hk_lfr_q_rv_fifo_size_max;
54 65 extern unsigned char hk_lfr_q_p0_fifo_size_max;
55 66 extern unsigned char hk_lfr_q_p1_fifo_size_max;
56 67 extern unsigned char hk_lfr_q_p2_fifo_size_max;
57 68
58 69 #endif // FSW_MISC_H_INCLUDED
@@ -1,564 +1,571
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 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 12 {
13 13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 14 *
15 15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 18 * @param interrupt_level is the interrupt level that the timer drives.
19 19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 20 *
21 21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 22 *
23 23 */
24 24
25 25 rtems_status_code status;
26 26 rtems_isr_entry old_isr_handler;
27 27
28 28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29 29
30 30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 31 if (status!=RTEMS_SUCCESSFUL)
32 32 {
33 33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 34 }
35 35
36 36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 37 }
38 38
39 39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 40 {
41 41 /** This function starts a GPTIMER timer.
42 42 *
43 43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 45 *
46 46 */
47 47
48 48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 53 }
54 54
55 55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 56 {
57 57 /** This function stops a GPTIMER timer.
58 58 *
59 59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 61 *
62 62 */
63 63
64 64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 67 }
68 68
69 69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 70 {
71 71 /** This function sets the clock divider of a GPTIMER timer.
72 72 *
73 73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 76 *
77 77 */
78 78
79 79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 80 }
81 81
82 82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 83 {
84 84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85 85
86 86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87 87
88 88 return 0;
89 89 }
90 90
91 91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 92 {
93 93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94 94
95 95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96 96
97 97 return 0;
98 98 }
99 99
100 100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 101 {
102 102 /** This function sets the scaler reload register of the apbuart module
103 103 *
104 104 * @param regs is the address of the apbuart registers in memory
105 105 * @param value is the value that will be stored in the scaler register
106 106 *
107 107 * The value shall be set by the software to get data on the serial interface.
108 108 *
109 109 */
110 110
111 111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112 112
113 113 apbuart_regs->scaler = value;
114 114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 115 }
116 116
117 117 //************
118 118 // RTEMS TASKS
119 119
120 120 rtems_task stat_task(rtems_task_argument argument)
121 121 {
122 122 int i;
123 123 int j;
124 124 i = 0;
125 125 j = 0;
126 126 BOOT_PRINTF("in STAT *** \n")
127 127 while(1){
128 128 rtems_task_wake_after(1000);
129 129 PRINTF1("%d\n", j)
130 130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 131 // #ifdef PRINT_TASK_STATISTICS
132 132 // rtems_cpu_usage_report();
133 133 // rtems_cpu_usage_reset();
134 134 // #endif
135 135 i = 0;
136 136 }
137 137 else i++;
138 138 j++;
139 139 }
140 140 }
141 141
142 142 rtems_task hous_task(rtems_task_argument argument)
143 143 {
144 144 rtems_status_code status;
145 145 rtems_status_code spare_status;
146 146 rtems_id queue_id;
147 147 rtems_rate_monotonic_period_status period_status;
148 148
149 149 status = get_message_queue_id_send( &queue_id );
150 150 if (status != RTEMS_SUCCESSFUL)
151 151 {
152 152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 153 }
154 154
155 155 BOOT_PRINTF("in HOUS ***\n")
156 156
157 157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 159 if( status != RTEMS_SUCCESSFUL ) {
160 160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 161 }
162 162 }
163 163
164 164 status = rtems_rate_monotonic_cancel(HK_id);
165 165 if( status != RTEMS_SUCCESSFUL ) {
166 166 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
167 167 }
168 168 else {
169 169 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
170 170 }
171 171
172 172 // startup phase
173 173 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
174 174 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
175 175 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
176 176 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
177 177 {
178 178 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
179 179 {
180 180 break; // break if LFR is synchronized
181 181 }
182 182 else
183 183 {
184 184 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
185 185 // sched_yield();
186 186 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
187 187 }
188 188 }
189 189 status = rtems_rate_monotonic_cancel(HK_id);
190 190 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
191 191
192 set_hk_lfr_reset_cause( POWER_ON );
193
192 194 while(1){ // launch the rate monotonic task
193 195 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
194 196 if ( status != RTEMS_SUCCESSFUL ) {
195 197 PRINTF1( "in HOUS *** ERR period: %d\n", status);
196 198 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
197 199 }
198 200 else {
199 201 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
200 202 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
201 203 increment_seq_counter( &sequenceCounterHK );
202 204
203 205 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
204 206 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
205 207 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
206 208 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
207 209 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
208 210 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
209 211
210 212 spacewire_update_statistics();
211 213
212 214 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
213 215 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
214 216 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
215 217 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
216 218 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
217 219
218 220 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
219 221 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
220 222 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
221 223 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
222 224 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
223 225
224 226 // SEND PACKET
225 227 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
226 228 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
227 229 if (status != RTEMS_SUCCESSFUL) {
228 230 PRINTF1("in HOUS *** ERR send: %d\n", status)
229 231 }
230 232 }
231 233 }
232 234
233 235 PRINTF("in HOUS *** deleting task\n")
234 236
235 237 status = rtems_task_delete( RTEMS_SELF ); // should not return
236 238 printf( "rtems_task_delete returned with status of %d.\n", status );
237 239 return;
238 240 }
239 241
240 242 rtems_task dumb_task( rtems_task_argument unused )
241 243 {
242 244 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
243 245 *
244 246 * @param unused is the starting argument of the RTEMS task
245 247 *
246 248 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
247 249 *
248 250 */
249 251
250 252 unsigned int i;
251 253 unsigned int intEventOut;
252 254 unsigned int coarse_time = 0;
253 255 unsigned int fine_time = 0;
254 256 rtems_event_set event_out;
255 257
256 258 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
257 259 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
258 260 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
259 261 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
260 262 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
261 263 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
262 264 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
263 265 "ready for dump", // RTEMS_EVENT_7
264 266 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
265 267 "tick", // RTEMS_EVENT_9
266 268 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
267 269 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
268 270 };
269 271
270 272 BOOT_PRINTF("in DUMB *** \n")
271 273
272 274 while(1){
273 275 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
274 276 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
275 277 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
276 278 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
277 279 intEventOut = (unsigned int) event_out;
278 280 for ( i=0; i<32; i++)
279 281 {
280 282 if ( ((intEventOut >> i) & 0x0001) != 0)
281 283 {
282 284 coarse_time = time_management_regs->coarse_time;
283 285 fine_time = time_management_regs->fine_time;
284 286 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
285 287 if (i==8)
286 288 {
287 289 }
288 290 if (i==10)
289 291 {
290 292 }
291 293 }
292 294 }
293 295 }
294 296 }
295 297
296 298 //*****************************
297 299 // init housekeeping parameters
298 300
299 301 void init_housekeeping_parameters( void )
300 302 {
301 303 /** This function initialize the housekeeping_packet global variable with default values.
302 304 *
303 305 */
304 306
305 307 unsigned int i = 0;
306 308 unsigned char *parameters;
307 309 unsigned char sizeOfHK;
308 310
309 311 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
310 312
311 313 parameters = (unsigned char*) &housekeeping_packet;
312 314
313 315 for(i = 0; i< sizeOfHK; i++)
314 316 {
315 317 parameters[i] = 0x00;
316 318 }
317 319
318 320 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
319 321 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
320 322 housekeeping_packet.reserved = DEFAULT_RESERVED;
321 323 housekeeping_packet.userApplication = CCSDS_USER_APP;
322 324 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
323 325 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
324 326 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
325 327 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
326 328 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
327 329 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
328 330 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
329 331 housekeeping_packet.serviceType = TM_TYPE_HK;
330 332 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
331 333 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
332 334 housekeeping_packet.sid = SID_HK;
333 335
334 336 // init status word
335 337 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
336 338 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
337 339 // init software version
338 340 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
339 341 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
340 342 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
341 343 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
342 344 // init fpga version
343 345 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
344 346 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
345 347 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
346 348 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
347 349
348 350 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
349 351 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
350 352 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
351 353 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
352 354 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
353 355 }
354 356
355 357 void increment_seq_counter( unsigned short *packetSequenceControl )
356 358 {
357 359 /** This function increment the sequence counter passes in argument.
358 360 *
359 361 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
360 362 *
361 363 */
362 364
363 365 unsigned short segmentation_grouping_flag;
364 366 unsigned short sequence_cnt;
365 367
366 368 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
367 369 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
368 370
369 371 if ( sequence_cnt < SEQ_CNT_MAX)
370 372 {
371 373 sequence_cnt = sequence_cnt + 1;
372 374 }
373 375 else
374 376 {
375 377 sequence_cnt = 0;
376 378 }
377 379
378 380 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
379 381 }
380 382
381 383 void getTime( unsigned char *time)
382 384 {
383 385 /** This function write the current local time in the time buffer passed in argument.
384 386 *
385 387 */
386 388
387 389 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
388 390 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
389 391 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
390 392 time[3] = (unsigned char) (time_management_regs->coarse_time);
391 393 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
392 394 time[5] = (unsigned char) (time_management_regs->fine_time);
393 395 }
394 396
395 397 unsigned long long int getTimeAsUnsignedLongLongInt( )
396 398 {
397 399 /** This function write the current local time in the time buffer passed in argument.
398 400 *
399 401 */
400 402 unsigned long long int time;
401 403
402 404 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
403 405 + time_management_regs->fine_time;
404 406
405 407 return time;
406 408 }
407 409
408 410 void send_dumb_hk( void )
409 411 {
410 412 Packet_TM_LFR_HK_t dummy_hk_packet;
411 413 unsigned char *parameters;
412 414 unsigned int i;
413 415 rtems_id queue_id;
414 416
415 417 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
416 418 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
417 419 dummy_hk_packet.reserved = DEFAULT_RESERVED;
418 420 dummy_hk_packet.userApplication = CCSDS_USER_APP;
419 421 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
420 422 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
421 423 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
422 424 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
423 425 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
424 426 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
425 427 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
426 428 dummy_hk_packet.serviceType = TM_TYPE_HK;
427 429 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
428 430 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
429 431 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
430 432 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
431 433 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
432 434 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
433 435 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
434 436 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
435 437 dummy_hk_packet.sid = SID_HK;
436 438
437 439 // init status word
438 440 dummy_hk_packet.lfr_status_word[0] = 0xff;
439 441 dummy_hk_packet.lfr_status_word[1] = 0xff;
440 442 // init software version
441 443 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
442 444 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
443 445 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
444 446 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
445 447 // init fpga version
446 448 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
447 449 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
448 450 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
449 451 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
450 452
451 453 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
452 454
453 455 for (i=0; i<100; i++)
454 456 {
455 457 parameters[i] = 0xff;
456 458 }
457 459
458 460 get_message_queue_id_send( &queue_id );
459 461
460 462 rtems_message_queue_send( queue_id, &dummy_hk_packet,
461 463 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
462 464 }
463 465
464 466 void get_temperatures( unsigned char *temperatures )
465 467 {
466 468 unsigned char* temp_scm_ptr;
467 469 unsigned char* temp_pcb_ptr;
468 470 unsigned char* temp_fpga_ptr;
469 471
470 472 // SEL1 SEL0
471 473 // 0 0 => PCB
472 474 // 0 1 => FPGA
473 475 // 1 0 => SCM
474 476
475 477 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
476 478 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
477 479 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
478 480
479 481 temperatures[0] = temp_scm_ptr[2];
480 482 temperatures[1] = temp_scm_ptr[3];
481 483 temperatures[2] = temp_pcb_ptr[2];
482 484 temperatures[3] = temp_pcb_ptr[3];
483 485 temperatures[4] = temp_fpga_ptr[2];
484 486 temperatures[5] = temp_fpga_ptr[3];
485 487 }
486 488
487 489 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
488 490 {
489 491 unsigned char* v_ptr;
490 492 unsigned char* e1_ptr;
491 493 unsigned char* e2_ptr;
492 494
493 495 v_ptr = (unsigned char *) &waveform_picker_regs->v;
494 496 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
495 497 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
496 498
497 499 spacecraft_potential[0] = v_ptr[2];
498 500 spacecraft_potential[1] = v_ptr[3];
499 501 spacecraft_potential[2] = e1_ptr[2];
500 502 spacecraft_potential[3] = e1_ptr[3];
501 503 spacecraft_potential[4] = e2_ptr[2];
502 504 spacecraft_potential[5] = e2_ptr[3];
503 505 }
504 506
505 507 void get_cpu_load( unsigned char *resource_statistics )
506 508 {
507 509 unsigned char cpu_load;
508 510
509 511 cpu_load = lfr_rtems_cpu_usage_report();
510 512
511 513 // HK_LFR_CPU_LOAD
512 514 resource_statistics[0] = cpu_load;
513 515
514 516 // HK_LFR_CPU_LOAD_MAX
515 517 if (cpu_load > resource_statistics[1])
516 518 {
517 519 resource_statistics[1] = cpu_load;
518 520 }
519 521
520 522 // CPU_LOAD_AVE
521 523 resource_statistics[2] = 0;
522 524
523 525 #ifndef PRINT_TASK_STATISTICS
524 526 rtems_cpu_usage_reset();
525 527 #endif
526 528
527 529 }
528 530
529 531 void set_hk_lfr_sc_potential_flag( bool state )
530 532 {
531 533 if (state == true)
532 534 {
533 535 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
534 536 }
535 537 else
536 538 {
537 539 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
538 540 }
539 541 }
540 542
541 543 void set_hk_lfr_mag_fields_flag( bool state )
542 544 {
543 545 if (state == true)
544 546 {
545 547 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
546 548 }
547 549 else
548 550 {
549 551 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111]
550 552 }
551 553 }
552 554
553 555 void set_hk_lfr_calib_enable( bool state )
554 556 {
555 557 if (state == true)
556 558 {
557 559 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
558 560 }
559 561 else
560 562 {
561 563 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
562 564 }
563 565 }
564 566
567 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
568 {
569 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
570 | (lfr_reset_cause & 0x07 ); // [0000 0111]
571 }
General Comments 0
You need to be logged in to leave comments. Login now