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