##// END OF EJS Templates
Bug 801 Don_Initialisation_P2
paul -
r320:6303d998f250 R3_plus draft
parent child
Show More
@@ -1,938 +1,945
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50
50
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
53 #endif
54
54
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
57 #endif
58
58
59 #endif
59 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
61
62 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
63 #endif
63 #endif
64
64
65 #include "fsw_init.h"
65 #include "fsw_init.h"
66 #include "fsw_config.c"
66 #include "fsw_config.c"
67 #include "GscMemoryLPP.hpp"
67 #include "GscMemoryLPP.hpp"
68
68
69 void initCache()
69 void initCache()
70 {
70 {
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
72 // These should only be read and written using 32-bit LDA/STA instructions.
72 // These should only be read and written using 32-bit LDA/STA instructions.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
74 // The table below shows the register addresses:
74 // The table below shows the register addresses:
75 // 0x00 Cache control register
75 // 0x00 Cache control register
76 // 0x04 Reserved
76 // 0x04 Reserved
77 // 0x08 Instruction cache configuration register
77 // 0x08 Instruction cache configuration register
78 // 0x0C Data cache configuration register
78 // 0x0C Data cache configuration register
79
79
80 // Cache Control Register Leon3 / Leon3FT
80 // Cache Control Register Leon3 / Leon3FT
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
82 // RFT PS TB DS FD FI FT ST IB
82 // RFT PS TB DS FD FI FT ST IB
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
85
85
86 unsigned int cacheControlRegister;
86 unsigned int cacheControlRegister;
87
87
88 CCR_resetCacheControlRegister();
88 CCR_resetCacheControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
90
90
91 cacheControlRegister = CCR_getValue();
91 cacheControlRegister = CCR_getValue();
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
94
94
95 CCR_enableInstructionCache(); // ICS bits
95 CCR_enableInstructionCache(); // ICS bits
96 CCR_enableDataCache(); // DCS bits
96 CCR_enableDataCache(); // DCS bits
97 CCR_enableInstructionBurstFetch(); // IB bit
97 CCR_enableInstructionBurstFetch(); // IB bit
98
98
99 faultTolerantScheme();
99 faultTolerantScheme();
100
100
101 cacheControlRegister = CCR_getValue();
101 cacheControlRegister = CCR_getValue();
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
104
104
105 PRINTF("\n");
105 PRINTF("\n");
106 }
106 }
107
107
108 rtems_task Init( rtems_task_argument ignored )
108 rtems_task Init( rtems_task_argument ignored )
109 {
109 {
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
111 *
111 *
112 * @param unused is the starting argument of the RTEMS task
112 * @param unused is the starting argument of the RTEMS task
113 *
113 *
114 * The INIT task create and run all other RTEMS tasks.
114 * The INIT task create and run all other RTEMS tasks.
115 *
115 *
116 */
116 */
117
117
118 //***********
118 //***********
119 // INIT CACHE
119 // INIT CACHE
120
120
121 unsigned char *vhdlVersion;
121 unsigned char *vhdlVersion;
122
122
123 reset_lfr();
123 reset_lfr();
124
124
125 reset_local_time();
125 reset_local_time();
126
126
127 rtems_cpu_usage_reset();
127 rtems_cpu_usage_reset();
128
128
129 rtems_status_code status;
129 rtems_status_code status;
130 rtems_status_code status_spw;
130 rtems_status_code status_spw;
131 rtems_isr_entry old_isr_handler;
131 rtems_isr_entry old_isr_handler;
132
132
133 old_isr_handler = NULL;
134
133 // UART settings
135 // UART settings
134 enable_apbuart_transmitter();
136 enable_apbuart_transmitter();
135 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
136
138
137 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
138
140
139
141
140 PRINTF("\n\n\n\n\n")
142 PRINTF("\n\n\n\n\n")
141
143
142 initCache();
144 initCache();
143
145
144 PRINTF("*************************\n")
146 PRINTF("*************************\n")
145 PRINTF("** LFR Flight Software **\n")
147 PRINTF("** LFR Flight Software **\n")
146
148
147 PRINTF1("** %d-", SW_VERSION_N1)
149 PRINTF1("** %d-", SW_VERSION_N1)
148 PRINTF1("%d-" , SW_VERSION_N2)
150 PRINTF1("%d-" , SW_VERSION_N2)
149 PRINTF1("%d-" , SW_VERSION_N3)
151 PRINTF1("%d-" , SW_VERSION_N3)
150 PRINTF1("%d **\n", SW_VERSION_N4)
152 PRINTF1("%d **\n", SW_VERSION_N4)
151
153
152 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
153 PRINTF("** VHDL **\n")
155 PRINTF("** VHDL **\n")
154 PRINTF1("** %d.", vhdlVersion[1])
156 PRINTF1("** %d.", vhdlVersion[1])
155 PRINTF1("%d." , vhdlVersion[2])
157 PRINTF1("%d." , vhdlVersion[2])
156 PRINTF1("%d **\n", vhdlVersion[3])
158 PRINTF1("%d **\n", vhdlVersion[3])
157 PRINTF("*************************\n")
159 PRINTF("*************************\n")
158 PRINTF("\n\n")
160 PRINTF("\n\n")
159
161
160 init_parameter_dump();
162 init_parameter_dump();
161 init_kcoefficients_dump();
163 init_kcoefficients_dump();
162 init_local_mode_parameters();
164 init_local_mode_parameters();
163 init_housekeeping_parameters();
165 init_housekeeping_parameters();
164 init_k_coefficients_prc0();
166 init_k_coefficients_prc0();
165 init_k_coefficients_prc1();
167 init_k_coefficients_prc1();
166 init_k_coefficients_prc2();
168 init_k_coefficients_prc2();
167 pa_bia_status_info = INIT_CHAR;
169 pa_bia_status_info = INIT_CHAR;
168 cp_rpw_sc_rw_f_flags = INIT_CHAR;
170 cp_rpw_sc_rw_f_flags = INIT_CHAR;
169 cp_rpw_sc_rw1_f1 = INIT_FLOAT;
171 cp_rpw_sc_rw1_f1 = INIT_FLOAT;
170 cp_rpw_sc_rw1_f2 = INIT_FLOAT;
172 cp_rpw_sc_rw1_f2 = INIT_FLOAT;
171 cp_rpw_sc_rw2_f1 = INIT_FLOAT;
173 cp_rpw_sc_rw2_f1 = INIT_FLOAT;
172 cp_rpw_sc_rw2_f2 = INIT_FLOAT;
174 cp_rpw_sc_rw2_f2 = INIT_FLOAT;
173 cp_rpw_sc_rw3_f1 = INIT_FLOAT;
175 cp_rpw_sc_rw3_f1 = INIT_FLOAT;
174 cp_rpw_sc_rw3_f2 = INIT_FLOAT;
176 cp_rpw_sc_rw3_f2 = INIT_FLOAT;
175 cp_rpw_sc_rw4_f1 = INIT_FLOAT;
177 cp_rpw_sc_rw4_f1 = INIT_FLOAT;
176 cp_rpw_sc_rw4_f2 = INIT_FLOAT;
178 cp_rpw_sc_rw4_f2 = INIT_FLOAT;
177 // initialize filtering parameters
179 // initialize filtering parameters
178 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
180 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
179 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
181 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
180 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
182 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
181 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
183 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
182 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
184 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
183 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
185 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
184 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
186 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
185
187
186 // waveform picker initialization
188 // waveform picker initialization
187 WFP_init_rings();
189 WFP_init_rings();
188 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
190 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
189 WFP_reset_current_ring_nodes();
191 WFP_reset_current_ring_nodes();
190 reset_waveform_picker_regs();
192 reset_waveform_picker_regs();
191
193
192 // spectral matrices initialization
194 // spectral matrices initialization
193 SM_init_rings(); // initialize spectral matrices rings
195 SM_init_rings(); // initialize spectral matrices rings
194 SM_reset_current_ring_nodes();
196 SM_reset_current_ring_nodes();
195 reset_spectral_matrix_regs();
197 reset_spectral_matrix_regs();
196
198
197 // configure calibration
199 // configure calibration
198 configureCalibration( false ); // true means interleaved mode, false is for normal mode
200 configureCalibration( false ); // true means interleaved mode, false is for normal mode
199
201
200 updateLFRCurrentMode( LFR_MODE_STANDBY );
202 updateLFRCurrentMode( LFR_MODE_STANDBY );
201
203
202 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
204 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
203
205
204 create_names(); // create all names
206 create_names(); // create all names
205
207
206 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
208 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
207 if (status != RTEMS_SUCCESSFUL)
209 if (status != RTEMS_SUCCESSFUL)
208 {
210 {
209 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
211 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
210 }
212 }
211
213
212 status = create_message_queues(); // create message queues
214 status = create_message_queues(); // create message queues
213 if (status != RTEMS_SUCCESSFUL)
215 if (status != RTEMS_SUCCESSFUL)
214 {
216 {
215 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
217 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
216 }
218 }
217
219
218 status = create_all_tasks(); // create all tasks
220 status = create_all_tasks(); // create all tasks
219 if (status != RTEMS_SUCCESSFUL)
221 if (status != RTEMS_SUCCESSFUL)
220 {
222 {
221 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
223 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
222 }
224 }
223
225
224 // **************************
226 // **************************
225 // <SPACEWIRE INITIALIZATION>
227 // <SPACEWIRE INITIALIZATION>
226 status_spw = spacewire_open_link(); // (1) open the link
228 status_spw = spacewire_open_link(); // (1) open the link
227 if ( status_spw != RTEMS_SUCCESSFUL )
229 if ( status_spw != RTEMS_SUCCESSFUL )
228 {
230 {
229 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
231 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
230 }
232 }
231
233
232 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
234 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
233 {
235 {
234 status_spw = spacewire_configure_link( fdSPW );
236 status_spw = spacewire_configure_link( fdSPW );
235 if ( status_spw != RTEMS_SUCCESSFUL )
237 if ( status_spw != RTEMS_SUCCESSFUL )
236 {
238 {
237 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
239 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
238 }
240 }
239 }
241 }
240
242
241 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
243 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
242 {
244 {
243 status_spw = spacewire_start_link( fdSPW );
245 status_spw = spacewire_start_link( fdSPW );
244 if ( status_spw != RTEMS_SUCCESSFUL )
246 if ( status_spw != RTEMS_SUCCESSFUL )
245 {
247 {
246 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
248 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
247 }
249 }
248 }
250 }
249 // </SPACEWIRE INITIALIZATION>
251 // </SPACEWIRE INITIALIZATION>
250 // ***************************
252 // ***************************
251
253
252 status = start_all_tasks(); // start all tasks
254 status = start_all_tasks(); // start all tasks
253 if (status != RTEMS_SUCCESSFUL)
255 if (status != RTEMS_SUCCESSFUL)
254 {
256 {
255 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
257 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
256 }
258 }
257
259
258 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
260 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
259 status = start_recv_send_tasks();
261 status = start_recv_send_tasks();
260 if ( status != RTEMS_SUCCESSFUL )
262 if ( status != RTEMS_SUCCESSFUL )
261 {
263 {
262 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
264 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
263 }
265 }
264
266
265 // suspend science tasks, they will be restarted later depending on the mode
267 // suspend science tasks, they will be restarted later depending on the mode
266 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
268 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
267 if (status != RTEMS_SUCCESSFUL)
269 if (status != RTEMS_SUCCESSFUL)
268 {
270 {
269 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
271 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
270 }
272 }
271
273
272 // configure IRQ handling for the waveform picker unit
274 // configure IRQ handling for the waveform picker unit
273 status = rtems_interrupt_catch( waveforms_isr,
275 status = rtems_interrupt_catch( waveforms_isr,
274 IRQ_SPARC_WAVEFORM_PICKER,
276 IRQ_SPARC_WAVEFORM_PICKER,
275 &old_isr_handler) ;
277 &old_isr_handler) ;
276 // configure IRQ handling for the spectral matrices unit
278 // configure IRQ handling for the spectral matrices unit
277 status = rtems_interrupt_catch( spectral_matrices_isr,
279 status = rtems_interrupt_catch( spectral_matrices_isr,
278 IRQ_SPARC_SPECTRAL_MATRIX,
280 IRQ_SPARC_SPECTRAL_MATRIX,
279 &old_isr_handler) ;
281 &old_isr_handler) ;
280
282
281 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
283 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
282 if ( status_spw != RTEMS_SUCCESSFUL )
284 if ( status_spw != RTEMS_SUCCESSFUL )
283 {
285 {
284 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
286 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
285 if ( status != RTEMS_SUCCESSFUL ) {
287 if ( status != RTEMS_SUCCESSFUL ) {
286 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
288 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
287 }
289 }
288 }
290 }
289
291
290 BOOT_PRINTF("delete INIT\n")
292 BOOT_PRINTF("delete INIT\n")
291
293
292 set_hk_lfr_sc_potential_flag( true );
294 set_hk_lfr_sc_potential_flag( true );
293
295
294 // start the timer to detect a missing spacewire timecode
296 // start the timer to detect a missing spacewire timecode
295 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
297 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
296 // if a tickout is generated, the timer is restarted
298 // if a tickout is generated, the timer is restarted
297 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
299 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
298
300
299 grspw_timecode_callback = &timecode_irq_handler;
301 grspw_timecode_callback = &timecode_irq_handler;
300
302
301 status = rtems_task_delete(RTEMS_SELF);
303 status = rtems_task_delete(RTEMS_SELF);
302
304
303 }
305 }
304
306
305 void init_local_mode_parameters( void )
307 void init_local_mode_parameters( void )
306 {
308 {
307 /** This function initialize the param_local global variable with default values.
309 /** This function initialize the param_local global variable with default values.
308 *
310 *
309 */
311 */
310
312
311 unsigned int i;
313 unsigned int i;
312
314
313 // LOCAL PARAMETERS
315 // LOCAL PARAMETERS
314
316
315 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
317 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
316 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
318 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
317
319
318 // init sequence counters
320 // init sequence counters
319
321
320 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
322 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
321 {
323 {
322 sequenceCounters_TC_EXE[i] = INIT_CHAR;
324 sequenceCounters_TC_EXE[i] = INIT_CHAR;
323 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
325 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
324 }
326 }
325 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
327 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
326 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
328 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
327 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
329 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
328 }
330 }
329
331
330 void reset_local_time( void )
332 void reset_local_time( void )
331 {
333 {
332 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
334 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
333 }
335 }
334
336
335 void create_names( void ) // create all names for tasks and queues
337 void create_names( void ) // create all names for tasks and queues
336 {
338 {
337 /** This function creates all RTEMS names used in the software for tasks and queues.
339 /** This function creates all RTEMS names used in the software for tasks and queues.
338 *
340 *
339 * @return RTEMS directive status codes:
341 * @return RTEMS directive status codes:
340 * - RTEMS_SUCCESSFUL - successful completion
342 * - RTEMS_SUCCESSFUL - successful completion
341 *
343 *
342 */
344 */
343
345
344 // task names
346 // task names
345 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
347 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
346 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
348 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
347 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
349 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
348 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
350 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
349 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
351 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
350 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
352 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
351 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
353 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
352 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
354 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
353 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
355 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
354 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
356 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
355 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
357 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
356 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
358 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
357 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
359 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
358 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
360 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
359 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
361 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
360 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
362 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
361 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
363 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
362 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
364 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
363 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
365 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
364
366
365 // rate monotonic period names
367 // rate monotonic period names
366 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
368 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
367
369
368 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
370 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
369 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
371 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
370 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
372 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
371 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
373 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
372 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
374 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
373
375
374 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
376 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
375 }
377 }
376
378
377 int create_all_tasks( void ) // create all tasks which run in the software
379 int create_all_tasks( void ) // create all tasks which run in the software
378 {
380 {
379 /** This function creates all RTEMS tasks used in the software.
381 /** This function creates all RTEMS tasks used in the software.
380 *
382 *
381 * @return RTEMS directive status codes:
383 * @return RTEMS directive status codes:
382 * - RTEMS_SUCCESSFUL - task created successfully
384 * - RTEMS_SUCCESSFUL - task created successfully
383 * - RTEMS_INVALID_ADDRESS - id is NULL
385 * - RTEMS_INVALID_ADDRESS - id is NULL
384 * - RTEMS_INVALID_NAME - invalid task name
386 * - RTEMS_INVALID_NAME - invalid task name
385 * - RTEMS_INVALID_PRIORITY - invalid task priority
387 * - RTEMS_INVALID_PRIORITY - invalid task priority
386 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
388 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
387 * - RTEMS_TOO_MANY - too many tasks created
389 * - RTEMS_TOO_MANY - too many tasks created
388 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
390 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
389 * - RTEMS_TOO_MANY - too many global objects
391 * - RTEMS_TOO_MANY - too many global objects
390 *
392 *
391 */
393 */
392
394
393 rtems_status_code status;
395 rtems_status_code status;
394
396
395 //**********
397 //**********
396 // SPACEWIRE
398 // SPACEWIRE
397 // RECV
399 // RECV
398 status = rtems_task_create(
400 status = rtems_task_create(
399 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
401 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
400 RTEMS_DEFAULT_MODES,
402 RTEMS_DEFAULT_MODES,
401 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
403 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
402 );
404 );
403 if (status == RTEMS_SUCCESSFUL) // SEND
405 if (status == RTEMS_SUCCESSFUL) // SEND
404 {
406 {
405 status = rtems_task_create(
407 status = rtems_task_create(
406 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
408 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
407 RTEMS_DEFAULT_MODES,
409 RTEMS_DEFAULT_MODES,
408 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
410 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
409 );
411 );
410 }
412 }
411 if (status == RTEMS_SUCCESSFUL) // LINK
413 if (status == RTEMS_SUCCESSFUL) // LINK
412 {
414 {
413 status = rtems_task_create(
415 status = rtems_task_create(
414 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
416 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
415 RTEMS_DEFAULT_MODES,
417 RTEMS_DEFAULT_MODES,
416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
418 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
417 );
419 );
418 }
420 }
419 if (status == RTEMS_SUCCESSFUL) // ACTN
421 if (status == RTEMS_SUCCESSFUL) // ACTN
420 {
422 {
421 status = rtems_task_create(
423 status = rtems_task_create(
422 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
424 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
423 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
425 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
426 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
425 );
427 );
426 }
428 }
427 if (status == RTEMS_SUCCESSFUL) // SPIQ
429 if (status == RTEMS_SUCCESSFUL) // SPIQ
428 {
430 {
429 status = rtems_task_create(
431 status = rtems_task_create(
430 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
432 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
431 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
433 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
434 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
433 );
435 );
434 }
436 }
435
437
436 //******************
438 //******************
437 // SPECTRAL MATRICES
439 // SPECTRAL MATRICES
438 if (status == RTEMS_SUCCESSFUL) // AVF0
440 if (status == RTEMS_SUCCESSFUL) // AVF0
439 {
441 {
440 status = rtems_task_create(
442 status = rtems_task_create(
441 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
443 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
442 RTEMS_DEFAULT_MODES,
444 RTEMS_DEFAULT_MODES,
443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
445 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
444 );
446 );
445 }
447 }
446 if (status == RTEMS_SUCCESSFUL) // PRC0
448 if (status == RTEMS_SUCCESSFUL) // PRC0
447 {
449 {
448 status = rtems_task_create(
450 status = rtems_task_create(
449 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
451 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
450 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
452 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
451 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
453 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
452 );
454 );
453 }
455 }
454 if (status == RTEMS_SUCCESSFUL) // AVF1
456 if (status == RTEMS_SUCCESSFUL) // AVF1
455 {
457 {
456 status = rtems_task_create(
458 status = rtems_task_create(
457 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
459 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
458 RTEMS_DEFAULT_MODES,
460 RTEMS_DEFAULT_MODES,
459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
461 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
460 );
462 );
461 }
463 }
462 if (status == RTEMS_SUCCESSFUL) // PRC1
464 if (status == RTEMS_SUCCESSFUL) // PRC1
463 {
465 {
464 status = rtems_task_create(
466 status = rtems_task_create(
465 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
467 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
468 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
469 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
468 );
470 );
469 }
471 }
470 if (status == RTEMS_SUCCESSFUL) // AVF2
472 if (status == RTEMS_SUCCESSFUL) // AVF2
471 {
473 {
472 status = rtems_task_create(
474 status = rtems_task_create(
473 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
475 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
474 RTEMS_DEFAULT_MODES,
476 RTEMS_DEFAULT_MODES,
475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
477 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
476 );
478 );
477 }
479 }
478 if (status == RTEMS_SUCCESSFUL) // PRC2
480 if (status == RTEMS_SUCCESSFUL) // PRC2
479 {
481 {
480 status = rtems_task_create(
482 status = rtems_task_create(
481 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
483 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
484 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
485 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
484 );
486 );
485 }
487 }
486
488
487 //****************
489 //****************
488 // WAVEFORM PICKER
490 // WAVEFORM PICKER
489 if (status == RTEMS_SUCCESSFUL) // WFRM
491 if (status == RTEMS_SUCCESSFUL) // WFRM
490 {
492 {
491 status = rtems_task_create(
493 status = rtems_task_create(
492 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
494 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
493 RTEMS_DEFAULT_MODES,
495 RTEMS_DEFAULT_MODES,
494 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
496 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
495 );
497 );
496 }
498 }
497 if (status == RTEMS_SUCCESSFUL) // CWF3
499 if (status == RTEMS_SUCCESSFUL) // CWF3
498 {
500 {
499 status = rtems_task_create(
501 status = rtems_task_create(
500 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
502 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
501 RTEMS_DEFAULT_MODES,
503 RTEMS_DEFAULT_MODES,
502 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
504 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
503 );
505 );
504 }
506 }
505 if (status == RTEMS_SUCCESSFUL) // CWF2
507 if (status == RTEMS_SUCCESSFUL) // CWF2
506 {
508 {
507 status = rtems_task_create(
509 status = rtems_task_create(
508 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
510 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
509 RTEMS_DEFAULT_MODES,
511 RTEMS_DEFAULT_MODES,
510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
512 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
511 );
513 );
512 }
514 }
513 if (status == RTEMS_SUCCESSFUL) // CWF1
515 if (status == RTEMS_SUCCESSFUL) // CWF1
514 {
516 {
515 status = rtems_task_create(
517 status = rtems_task_create(
516 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
518 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
517 RTEMS_DEFAULT_MODES,
519 RTEMS_DEFAULT_MODES,
518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
520 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
519 );
521 );
520 }
522 }
521 if (status == RTEMS_SUCCESSFUL) // SWBD
523 if (status == RTEMS_SUCCESSFUL) // SWBD
522 {
524 {
523 status = rtems_task_create(
525 status = rtems_task_create(
524 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
526 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
525 RTEMS_DEFAULT_MODES,
527 RTEMS_DEFAULT_MODES,
526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
528 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
527 );
529 );
528 }
530 }
529
531
530 //*****
532 //*****
531 // MISC
533 // MISC
532 if (status == RTEMS_SUCCESSFUL) // LOAD
534 if (status == RTEMS_SUCCESSFUL) // LOAD
533 {
535 {
534 status = rtems_task_create(
536 status = rtems_task_create(
535 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
537 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
536 RTEMS_DEFAULT_MODES,
538 RTEMS_DEFAULT_MODES,
537 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
539 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
538 );
540 );
539 }
541 }
540 if (status == RTEMS_SUCCESSFUL) // DUMB
542 if (status == RTEMS_SUCCESSFUL) // DUMB
541 {
543 {
542 status = rtems_task_create(
544 status = rtems_task_create(
543 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
545 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
544 RTEMS_DEFAULT_MODES,
546 RTEMS_DEFAULT_MODES,
545 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
547 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
546 );
548 );
547 }
549 }
548 if (status == RTEMS_SUCCESSFUL) // HOUS
550 if (status == RTEMS_SUCCESSFUL) // HOUS
549 {
551 {
550 status = rtems_task_create(
552 status = rtems_task_create(
551 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
553 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
552 RTEMS_DEFAULT_MODES,
554 RTEMS_DEFAULT_MODES,
553 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
555 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
554 );
556 );
555 }
557 }
556
558
557 return status;
559 return status;
558 }
560 }
559
561
560 int start_recv_send_tasks( void )
562 int start_recv_send_tasks( void )
561 {
563 {
562 rtems_status_code status;
564 rtems_status_code status;
563
565
564 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
566 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
565 if (status!=RTEMS_SUCCESSFUL) {
567 if (status!=RTEMS_SUCCESSFUL) {
566 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
568 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
567 }
569 }
568
570
569 if (status == RTEMS_SUCCESSFUL) // SEND
571 if (status == RTEMS_SUCCESSFUL) // SEND
570 {
572 {
571 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
573 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
572 if (status!=RTEMS_SUCCESSFUL) {
574 if (status!=RTEMS_SUCCESSFUL) {
573 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
575 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
574 }
576 }
575 }
577 }
576
578
577 return status;
579 return status;
578 }
580 }
579
581
580 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
582 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
581 {
583 {
582 /** This function starts all RTEMS tasks used in the software.
584 /** This function starts all RTEMS tasks used in the software.
583 *
585 *
584 * @return RTEMS directive status codes:
586 * @return RTEMS directive status codes:
585 * - RTEMS_SUCCESSFUL - ask started successfully
587 * - RTEMS_SUCCESSFUL - ask started successfully
586 * - RTEMS_INVALID_ADDRESS - invalid task entry point
588 * - RTEMS_INVALID_ADDRESS - invalid task entry point
587 * - RTEMS_INVALID_ID - invalid task id
589 * - RTEMS_INVALID_ID - invalid task id
588 * - RTEMS_INCORRECT_STATE - task not in the dormant state
590 * - RTEMS_INCORRECT_STATE - task not in the dormant state
589 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
591 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
590 *
592 *
591 */
593 */
592 // starts all the tasks fot eh flight software
594 // starts all the tasks fot eh flight software
593
595
594 rtems_status_code status;
596 rtems_status_code status;
595
597
596 //**********
598 //**********
597 // SPACEWIRE
599 // SPACEWIRE
598 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
600 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
599 if (status!=RTEMS_SUCCESSFUL) {
601 if (status!=RTEMS_SUCCESSFUL) {
600 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
602 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
601 }
603 }
602
604
603 if (status == RTEMS_SUCCESSFUL) // LINK
605 if (status == RTEMS_SUCCESSFUL) // LINK
604 {
606 {
605 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
607 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
606 if (status!=RTEMS_SUCCESSFUL) {
608 if (status!=RTEMS_SUCCESSFUL) {
607 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
609 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
608 }
610 }
609 }
611 }
610
612
611 if (status == RTEMS_SUCCESSFUL) // ACTN
613 if (status == RTEMS_SUCCESSFUL) // ACTN
612 {
614 {
613 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
615 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
614 if (status!=RTEMS_SUCCESSFUL) {
616 if (status!=RTEMS_SUCCESSFUL) {
615 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
617 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
616 }
618 }
617 }
619 }
618
620
619 //******************
621 //******************
620 // SPECTRAL MATRICES
622 // SPECTRAL MATRICES
621 if (status == RTEMS_SUCCESSFUL) // AVF0
623 if (status == RTEMS_SUCCESSFUL) // AVF0
622 {
624 {
623 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
625 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
624 if (status!=RTEMS_SUCCESSFUL) {
626 if (status!=RTEMS_SUCCESSFUL) {
625 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
627 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
626 }
628 }
627 }
629 }
628 if (status == RTEMS_SUCCESSFUL) // PRC0
630 if (status == RTEMS_SUCCESSFUL) // PRC0
629 {
631 {
630 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
632 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
631 if (status!=RTEMS_SUCCESSFUL) {
633 if (status!=RTEMS_SUCCESSFUL) {
632 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
634 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
633 }
635 }
634 }
636 }
635 if (status == RTEMS_SUCCESSFUL) // AVF1
637 if (status == RTEMS_SUCCESSFUL) // AVF1
636 {
638 {
637 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
639 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
638 if (status!=RTEMS_SUCCESSFUL) {
640 if (status!=RTEMS_SUCCESSFUL) {
639 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
641 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
640 }
642 }
641 }
643 }
642 if (status == RTEMS_SUCCESSFUL) // PRC1
644 if (status == RTEMS_SUCCESSFUL) // PRC1
643 {
645 {
644 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
646 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
645 if (status!=RTEMS_SUCCESSFUL) {
647 if (status!=RTEMS_SUCCESSFUL) {
646 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
648 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
647 }
649 }
648 }
650 }
649 if (status == RTEMS_SUCCESSFUL) // AVF2
651 if (status == RTEMS_SUCCESSFUL) // AVF2
650 {
652 {
651 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
653 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
652 if (status!=RTEMS_SUCCESSFUL) {
654 if (status!=RTEMS_SUCCESSFUL) {
653 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
655 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
654 }
656 }
655 }
657 }
656 if (status == RTEMS_SUCCESSFUL) // PRC2
658 if (status == RTEMS_SUCCESSFUL) // PRC2
657 {
659 {
658 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
660 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
659 if (status!=RTEMS_SUCCESSFUL) {
661 if (status!=RTEMS_SUCCESSFUL) {
660 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
662 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
661 }
663 }
662 }
664 }
663
665
664 //****************
666 //****************
665 // WAVEFORM PICKER
667 // WAVEFORM PICKER
666 if (status == RTEMS_SUCCESSFUL) // WFRM
668 if (status == RTEMS_SUCCESSFUL) // WFRM
667 {
669 {
668 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
670 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
669 if (status!=RTEMS_SUCCESSFUL) {
671 if (status!=RTEMS_SUCCESSFUL) {
670 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
672 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
671 }
673 }
672 }
674 }
673 if (status == RTEMS_SUCCESSFUL) // CWF3
675 if (status == RTEMS_SUCCESSFUL) // CWF3
674 {
676 {
675 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
677 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
676 if (status!=RTEMS_SUCCESSFUL) {
678 if (status!=RTEMS_SUCCESSFUL) {
677 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
679 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
678 }
680 }
679 }
681 }
680 if (status == RTEMS_SUCCESSFUL) // CWF2
682 if (status == RTEMS_SUCCESSFUL) // CWF2
681 {
683 {
682 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
684 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
683 if (status!=RTEMS_SUCCESSFUL) {
685 if (status!=RTEMS_SUCCESSFUL) {
684 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
686 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
685 }
687 }
686 }
688 }
687 if (status == RTEMS_SUCCESSFUL) // CWF1
689 if (status == RTEMS_SUCCESSFUL) // CWF1
688 {
690 {
689 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
691 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
690 if (status!=RTEMS_SUCCESSFUL) {
692 if (status!=RTEMS_SUCCESSFUL) {
691 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
693 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
692 }
694 }
693 }
695 }
694 if (status == RTEMS_SUCCESSFUL) // SWBD
696 if (status == RTEMS_SUCCESSFUL) // SWBD
695 {
697 {
696 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
698 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
697 if (status!=RTEMS_SUCCESSFUL) {
699 if (status!=RTEMS_SUCCESSFUL) {
698 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
700 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
699 }
701 }
700 }
702 }
701
703
702 //*****
704 //*****
703 // MISC
705 // MISC
704 if (status == RTEMS_SUCCESSFUL) // HOUS
706 if (status == RTEMS_SUCCESSFUL) // HOUS
705 {
707 {
706 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
708 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
707 if (status!=RTEMS_SUCCESSFUL) {
709 if (status!=RTEMS_SUCCESSFUL) {
708 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
710 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
709 }
711 }
710 }
712 }
711 if (status == RTEMS_SUCCESSFUL) // DUMB
713 if (status == RTEMS_SUCCESSFUL) // DUMB
712 {
714 {
713 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
715 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
714 if (status!=RTEMS_SUCCESSFUL) {
716 if (status!=RTEMS_SUCCESSFUL) {
715 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
717 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
716 }
718 }
717 }
719 }
718 if (status == RTEMS_SUCCESSFUL) // LOAD
720 if (status == RTEMS_SUCCESSFUL) // LOAD
719 {
721 {
720 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
722 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
721 if (status!=RTEMS_SUCCESSFUL) {
723 if (status!=RTEMS_SUCCESSFUL) {
722 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
724 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
723 }
725 }
724 }
726 }
725
727
726 return status;
728 return status;
727 }
729 }
728
730
729 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
731 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
730 {
732 {
731 rtems_status_code status_recv;
733 rtems_status_code status_recv;
732 rtems_status_code status_send;
734 rtems_status_code status_send;
733 rtems_status_code status_q_p0;
735 rtems_status_code status_q_p0;
734 rtems_status_code status_q_p1;
736 rtems_status_code status_q_p1;
735 rtems_status_code status_q_p2;
737 rtems_status_code status_q_p2;
736 rtems_status_code ret;
738 rtems_status_code ret;
737 rtems_id queue_id;
739 rtems_id queue_id;
738
740
741 ret = RTEMS_SUCCESSFUL;
742 queue_id = RTEMS_ID_NONE;
743
739 //****************************************
744 //****************************************
740 // create the queue for handling valid TCs
745 // create the queue for handling valid TCs
741 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
746 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
742 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
747 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
743 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
748 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
744 if ( status_recv != RTEMS_SUCCESSFUL ) {
749 if ( status_recv != RTEMS_SUCCESSFUL ) {
745 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
750 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
746 }
751 }
747
752
748 //************************************************
753 //************************************************
749 // create the queue for handling TM packet sending
754 // create the queue for handling TM packet sending
750 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
755 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
751 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
756 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
752 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
757 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
753 if ( status_send != RTEMS_SUCCESSFUL ) {
758 if ( status_send != RTEMS_SUCCESSFUL ) {
754 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
759 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
755 }
760 }
756
761
757 //*****************************************************************************
762 //*****************************************************************************
758 // create the queue for handling averaged spectral matrices for processing @ f0
763 // create the queue for handling averaged spectral matrices for processing @ f0
759 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
764 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
760 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
765 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
766 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
762 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
767 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
763 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
768 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
764 }
769 }
765
770
766 //*****************************************************************************
771 //*****************************************************************************
767 // create the queue for handling averaged spectral matrices for processing @ f1
772 // create the queue for handling averaged spectral matrices for processing @ f1
768 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
773 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
769 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
774 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
775 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
771 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
776 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
772 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
777 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
773 }
778 }
774
779
775 //*****************************************************************************
780 //*****************************************************************************
776 // create the queue for handling averaged spectral matrices for processing @ f2
781 // create the queue for handling averaged spectral matrices for processing @ f2
777 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
782 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
778 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
783 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
784 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
780 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
785 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
781 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
786 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
782 }
787 }
783
788
784 if ( status_recv != RTEMS_SUCCESSFUL )
789 if ( status_recv != RTEMS_SUCCESSFUL )
785 {
790 {
786 ret = status_recv;
791 ret = status_recv;
787 }
792 }
788 else if( status_send != RTEMS_SUCCESSFUL )
793 else if( status_send != RTEMS_SUCCESSFUL )
789 {
794 {
790 ret = status_send;
795 ret = status_send;
791 }
796 }
792 else if( status_q_p0 != RTEMS_SUCCESSFUL )
797 else if( status_q_p0 != RTEMS_SUCCESSFUL )
793 {
798 {
794 ret = status_q_p0;
799 ret = status_q_p0;
795 }
800 }
796 else if( status_q_p1 != RTEMS_SUCCESSFUL )
801 else if( status_q_p1 != RTEMS_SUCCESSFUL )
797 {
802 {
798 ret = status_q_p1;
803 ret = status_q_p1;
799 }
804 }
800 else
805 else
801 {
806 {
802 ret = status_q_p2;
807 ret = status_q_p2;
803 }
808 }
804
809
805 return ret;
810 return ret;
806 }
811 }
807
812
808 rtems_status_code create_timecode_timer( void )
813 rtems_status_code create_timecode_timer( void )
809 {
814 {
810 rtems_status_code status;
815 rtems_status_code status;
811
816
812 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
817 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
813
818
814 if ( status != RTEMS_SUCCESSFUL )
819 if ( status != RTEMS_SUCCESSFUL )
815 {
820 {
816 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
821 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
817 }
822 }
818 else
823 else
819 {
824 {
820 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
825 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
821 }
826 }
822
827
823 return status;
828 return status;
824 }
829 }
825
830
826 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
831 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
827 {
832 {
828 rtems_status_code status;
833 rtems_status_code status;
829 rtems_name queue_name;
834 rtems_name queue_name;
830
835
831 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
836 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
832
837
833 status = rtems_message_queue_ident( queue_name, 0, queue_id );
838 status = rtems_message_queue_ident( queue_name, 0, queue_id );
834
839
835 return status;
840 return status;
836 }
841 }
837
842
838 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
843 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
839 {
844 {
840 rtems_status_code status;
845 rtems_status_code status;
841 rtems_name queue_name;
846 rtems_name queue_name;
842
847
843 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
848 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
844
849
845 status = rtems_message_queue_ident( queue_name, 0, queue_id );
850 status = rtems_message_queue_ident( queue_name, 0, queue_id );
846
851
847 return status;
852 return status;
848 }
853 }
849
854
850 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
855 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
851 {
856 {
852 rtems_status_code status;
857 rtems_status_code status;
853 rtems_name queue_name;
858 rtems_name queue_name;
854
859
855 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
860 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
856
861
857 status = rtems_message_queue_ident( queue_name, 0, queue_id );
862 status = rtems_message_queue_ident( queue_name, 0, queue_id );
858
863
859 return status;
864 return status;
860 }
865 }
861
866
862 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
867 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
863 {
868 {
864 rtems_status_code status;
869 rtems_status_code status;
865 rtems_name queue_name;
870 rtems_name queue_name;
866
871
867 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
872 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
868
873
869 status = rtems_message_queue_ident( queue_name, 0, queue_id );
874 status = rtems_message_queue_ident( queue_name, 0, queue_id );
870
875
871 return status;
876 return status;
872 }
877 }
873
878
874 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
879 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
875 {
880 {
876 rtems_status_code status;
881 rtems_status_code status;
877 rtems_name queue_name;
882 rtems_name queue_name;
878
883
879 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
884 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
880
885
881 status = rtems_message_queue_ident( queue_name, 0, queue_id );
886 status = rtems_message_queue_ident( queue_name, 0, queue_id );
882
887
883 return status;
888 return status;
884 }
889 }
885
890
886 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
891 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
887 {
892 {
888 u_int32_t count;
893 u_int32_t count;
889 rtems_status_code status;
894 rtems_status_code status;
890
895
896 count = 0;
897
891 status = rtems_message_queue_get_number_pending( queue_id, &count );
898 status = rtems_message_queue_get_number_pending( queue_id, &count );
892
899
893 count = count + 1;
900 count = count + 1;
894
901
895 if (status != RTEMS_SUCCESSFUL)
902 if (status != RTEMS_SUCCESSFUL)
896 {
903 {
897 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
904 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
898 }
905 }
899 else
906 else
900 {
907 {
901 if (count > *fifo_size_max)
908 if (count > *fifo_size_max)
902 {
909 {
903 *fifo_size_max = count;
910 *fifo_size_max = count;
904 }
911 }
905 }
912 }
906 }
913 }
907
914
908 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
915 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
909 {
916 {
910 unsigned char i;
917 unsigned char i;
911
918
912 //***************
919 //***************
913 // BUFFER ADDRESS
920 // BUFFER ADDRESS
914 for(i=0; i<nbNodes; i++)
921 for(i=0; i<nbNodes; i++)
915 {
922 {
916 ring[i].coarseTime = INT32_ALL_F;
923 ring[i].coarseTime = INT32_ALL_F;
917 ring[i].fineTime = INT32_ALL_F;
924 ring[i].fineTime = INT32_ALL_F;
918 ring[i].sid = INIT_CHAR;
925 ring[i].sid = INIT_CHAR;
919 ring[i].status = INIT_CHAR;
926 ring[i].status = INIT_CHAR;
920 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
927 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
921 }
928 }
922
929
923 //*****
930 //*****
924 // NEXT
931 // NEXT
925 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
932 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
926 for(i=0; i<nbNodes-1; i++)
933 for(i=0; i<nbNodes-1; i++)
927 {
934 {
928 ring[i].next = (ring_node*) &ring[ i + 1 ];
935 ring[i].next = (ring_node*) &ring[ i + 1 ];
929 }
936 }
930
937
931 //*********
938 //*********
932 // PREVIOUS
939 // PREVIOUS
933 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
940 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
934 for(i=1; i<nbNodes; i++)
941 for(i=1; i<nbNodes; i++)
935 {
942 {
936 ring[i].previous = (ring_node*) &ring[ i - 1 ];
943 ring[i].previous = (ring_node*) &ring[ i - 1 ];
937 }
944 }
938 }
945 }
@@ -1,997 +1,995
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 old_isr_handler = NULL;
29
28 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
29
31
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
33 if (status!=RTEMS_SUCCESSFUL)
32 {
34 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
36 }
35
37
36 timer_set_clock_divider( timer, clock_divider);
38 timer_set_clock_divider( timer, clock_divider);
37 }
39 }
38
40
39 void timer_start(unsigned char timer)
41 void timer_start(unsigned char timer)
40 {
42 {
41 /** This function starts a GPTIMER timer.
43 /** This function starts a GPTIMER timer.
42 *
44 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 *
47 *
46 */
48 */
47
49
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
53 }
55 }
54
56
55 void timer_stop(unsigned char timer)
57 void timer_stop(unsigned char timer)
56 {
58 {
57 /** This function stops a GPTIMER timer.
59 /** This function stops a GPTIMER timer.
58 *
60 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 *
63 *
62 */
64 */
63
65
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
67 }
69 }
68
70
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
70 {
72 {
71 /** This function sets the clock divider of a GPTIMER timer.
73 /** This function sets the clock divider of a GPTIMER timer.
72 *
74 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
78 *
77 */
79 */
78
80
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
82 }
81
83
82 // WATCHDOG
84 // WATCHDOG
83
85
84 rtems_isr watchdog_isr( rtems_vector_number vector )
86 rtems_isr watchdog_isr( rtems_vector_number vector )
85 {
87 {
86 rtems_status_code status_code;
88 rtems_status_code status_code;
87
89
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
89
91
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
91
93
92 exit(0);
94 exit(0);
93 }
95 }
94
96
95 void watchdog_configure(void)
97 void watchdog_configure(void)
96 {
98 {
97 /** This function configure the watchdog.
99 /** This function configure the watchdog.
98 *
100 *
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
101 *
103 *
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
103 *
105 *
104 */
106 */
105
107
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
107
109
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
109
111
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
111 }
113 }
112
114
113 void watchdog_stop(void)
115 void watchdog_stop(void)
114 {
116 {
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
116 timer_stop( TIMER_WATCHDOG );
118 timer_stop( TIMER_WATCHDOG );
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
118 }
120 }
119
121
120 void watchdog_reload(void)
122 void watchdog_reload(void)
121 {
123 {
122 /** This function reloads the watchdog timer counter with the timer reload value.
124 /** This function reloads the watchdog timer counter with the timer reload value.
123 *
125 *
124 * @param void
126 * @param void
125 *
127 *
126 * @return void
128 * @return void
127 *
129 *
128 */
130 */
129
131
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
131 }
133 }
132
134
133 void watchdog_start(void)
135 void watchdog_start(void)
134 {
136 {
135 /** This function starts the watchdog timer.
137 /** This function starts the watchdog timer.
136 *
138 *
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
139 *
141 *
140 */
142 */
141
143
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
143
145
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
148
150
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
150
152
151 }
153 }
152
154
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
154 {
156 {
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
156
158
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
158
160
159 return 0;
161 return 0;
160 }
162 }
161
163
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
163 {
165 {
164 /** This function sets the scaler reload register of the apbuart module
166 /** This function sets the scaler reload register of the apbuart module
165 *
167 *
166 * @param regs is the address of the apbuart registers in memory
168 * @param regs is the address of the apbuart registers in memory
167 * @param value is the value that will be stored in the scaler register
169 * @param value is the value that will be stored in the scaler register
168 *
170 *
169 * The value shall be set by the software to get data on the serial interface.
171 * The value shall be set by the software to get data on the serial interface.
170 *
172 *
171 */
173 */
172
174
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
174
176
175 apbuart_regs->scaler = value;
177 apbuart_regs->scaler = value;
176
178
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
178 }
180 }
179
181
180 //************
182 //************
181 // RTEMS TASKS
183 // RTEMS TASKS
182
184
183 rtems_task load_task(rtems_task_argument argument)
185 rtems_task load_task(rtems_task_argument argument)
184 {
186 {
185 BOOT_PRINTF("in LOAD *** \n")
187 BOOT_PRINTF("in LOAD *** \n")
186
188
187 rtems_status_code status;
189 rtems_status_code status;
188 unsigned int i;
190 unsigned int i;
189 unsigned int j;
191 unsigned int j;
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
192
194
195 watchdog_period_id = RTEMS_ID_NONE;
196
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
194
198
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
196 if( status != RTEMS_SUCCESSFUL ) {
200 if( status != RTEMS_SUCCESSFUL ) {
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
198 }
202 }
199
203
200 i = 0;
204 i = 0;
201 j = 0;
205 j = 0;
202
206
203 watchdog_configure();
207 watchdog_configure();
204
208
205 watchdog_start();
209 watchdog_start();
206
210
207 set_sy_lfr_watchdog_enabled( true );
211 set_sy_lfr_watchdog_enabled( true );
208
212
209 while(1){
213 while(1){
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
211 watchdog_reload();
215 watchdog_reload();
212 i = i + 1;
216 i = i + 1;
213 if ( i == WATCHDOG_LOOP_PRINTF )
217 if ( i == WATCHDOG_LOOP_PRINTF )
214 {
218 {
215 i = 0;
219 i = 0;
216 j = j + 1;
220 j = j + 1;
217 PRINTF1("%d\n", j)
221 PRINTF1("%d\n", j)
218 }
222 }
219 #ifdef DEBUG_WATCHDOG
223 #ifdef DEBUG_WATCHDOG
220 if (j == WATCHDOG_LOOP_DEBUG )
224 if (j == WATCHDOG_LOOP_DEBUG )
221 {
225 {
222 status = rtems_task_delete(RTEMS_SELF);
226 status = rtems_task_delete(RTEMS_SELF);
223 }
227 }
224 #endif
228 #endif
225 }
229 }
226 }
230 }
227
231
228 rtems_task hous_task(rtems_task_argument argument)
232 rtems_task hous_task(rtems_task_argument argument)
229 {
233 {
230 rtems_status_code status;
234 rtems_status_code status;
231 rtems_status_code spare_status;
235 rtems_status_code spare_status;
232 rtems_id queue_id;
236 rtems_id queue_id;
233 rtems_rate_monotonic_period_status period_status;
237 rtems_rate_monotonic_period_status period_status;
234 bool isSynchronized;
238 bool isSynchronized;
235
239
240 queue_id = RTEMS_ID_NONE;
241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
236 isSynchronized = false;
242 isSynchronized = false;
237
243
238 status = get_message_queue_id_send( &queue_id );
244 status = get_message_queue_id_send( &queue_id );
239 if (status != RTEMS_SUCCESSFUL)
245 if (status != RTEMS_SUCCESSFUL)
240 {
246 {
241 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
242 }
248 }
243
249
244 BOOT_PRINTF("in HOUS ***\n");
250 BOOT_PRINTF("in HOUS ***\n");
245
251
246 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
247 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
248 if( status != RTEMS_SUCCESSFUL ) {
254 if( status != RTEMS_SUCCESSFUL ) {
249 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
250 }
256 }
251 }
257 }
252
258
253 status = rtems_rate_monotonic_cancel(HK_id);
259 status = rtems_rate_monotonic_cancel(HK_id);
254 if( status != RTEMS_SUCCESSFUL ) {
260 if( status != RTEMS_SUCCESSFUL ) {
255 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
256 }
262 }
257 else {
263 else {
258 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
259 }
265 }
260
266
261 // startup phase
267 // startup phase
262 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
263 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
264 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
265 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
266 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
267 {
273 {
268 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
269 {
275 {
270 isSynchronized = true;
276 isSynchronized = true;
271 }
277 }
272 else
278 else
273 {
279 {
274 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
275
281
276 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
277 }
283 }
278 }
284 }
279 status = rtems_rate_monotonic_cancel(HK_id);
285 status = rtems_rate_monotonic_cancel(HK_id);
280 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
281
287
282 set_hk_lfr_reset_cause( POWER_ON );
288 set_hk_lfr_reset_cause( POWER_ON );
283
289
284 while(1){ // launch the rate monotonic task
290 while(1){ // launch the rate monotonic task
285 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
286 if ( status != RTEMS_SUCCESSFUL ) {
292 if ( status != RTEMS_SUCCESSFUL ) {
287 PRINTF1( "in HOUS *** ERR period: %d\n", status);
293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
288 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
289 }
295 }
290 else {
296 else {
291 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
292 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
293 increment_seq_counter( &sequenceCounterHK );
299 increment_seq_counter( &sequenceCounterHK );
294
300
295 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
296 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
297 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
298 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
299 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
300 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
301
307
302 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
303
309
304 spacewire_read_statistics();
310 spacewire_read_statistics();
305
311
306 update_hk_with_grspw_stats();
312 update_hk_with_grspw_stats();
307
313
308 set_hk_lfr_time_not_synchro();
314 set_hk_lfr_time_not_synchro();
309
315
310 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
311 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
312 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
313 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
314 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
315
321
316 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
317 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
318 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
319 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
320 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
321
327
322 hk_lfr_le_me_he_update();
328 hk_lfr_le_me_he_update();
323
329
324 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
325
331
326 // SEND PACKET
332 // SEND PACKET
327 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
328 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
329 if (status != RTEMS_SUCCESSFUL) {
335 if (status != RTEMS_SUCCESSFUL) {
330 PRINTF1("in HOUS *** ERR send: %d\n", status)
336 PRINTF1("in HOUS *** ERR send: %d\n", status)
331 }
337 }
332 }
338 }
333 }
339 }
334
340
335 PRINTF("in HOUS *** deleting task\n")
341 PRINTF("in HOUS *** deleting task\n")
336
342
337 status = rtems_task_delete( RTEMS_SELF ); // should not return
343 status = rtems_task_delete( RTEMS_SELF ); // should not return
338
344
339 return;
345 return;
340 }
346 }
341
347
342 rtems_task avgv_task(rtems_task_argument argument)
348 rtems_task avgv_task(rtems_task_argument argument)
343 {
349 {
344 #define MOVING_AVERAGE 16
350 #define MOVING_AVERAGE 16
345 rtems_status_code status;
351 rtems_status_code status;
346 unsigned int v[MOVING_AVERAGE];
352 unsigned int v[MOVING_AVERAGE];
347 unsigned int e1[MOVING_AVERAGE];
353 unsigned int e1[MOVING_AVERAGE];
348 unsigned int e2[MOVING_AVERAGE];
354 unsigned int e2[MOVING_AVERAGE];
349 float average_v;
355 float average_v;
350 float average_e1;
356 float average_e1;
351 float average_e2;
357 float average_e2;
352 unsigned char k;
358 unsigned char k;
353 unsigned char indexOfOldValue;
359 unsigned char indexOfOldValue;
354
360
355 BOOT_PRINTF("in AVGV ***\n");
361 BOOT_PRINTF("in AVGV ***\n");
356
362
357 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
358 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
359 if( status != RTEMS_SUCCESSFUL ) {
365 if( status != RTEMS_SUCCESSFUL ) {
360 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
361 }
367 }
362 }
368 }
363
369
364 status = rtems_rate_monotonic_cancel(AVGV_id);
370 status = rtems_rate_monotonic_cancel(AVGV_id);
365 if( status != RTEMS_SUCCESSFUL ) {
371 if( status != RTEMS_SUCCESSFUL ) {
366 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
367 }
373 }
368 else {
374 else {
369 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
370 }
376 }
371
377
372 // initialize values
378 // initialize values
373 k = 0;
379 k = 0;
374 indexOfOldValue = MOVING_AVERAGE - 1;
380 indexOfOldValue = MOVING_AVERAGE - 1;
375 for (k = 0; k < MOVING_AVERAGE; k++)
381 for (k = 0; k < MOVING_AVERAGE; k++)
376 {
382 {
377 v[k] = 0;
383 v[k] = 0;
378 e1[k] = 0;
384 e1[k] = 0;
379 e2[k] = 0;
385 e2[k] = 0;
380 average_v = 0.;
386 average_v = 0.;
381 average_e1 = 0.;
387 average_e1 = 0.;
382 average_e2 = 0.;
388 average_e2 = 0.;
383 }
389 }
384
390
385 k = 0;
391 k = 0;
386
392
387 while(1){ // launch the rate monotonic task
393 while(1){ // launch the rate monotonic task
388 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
394 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
389 if ( status != RTEMS_SUCCESSFUL ) {
395 if ( status != RTEMS_SUCCESSFUL ) {
390 PRINTF1( "in AVGV *** ERR period: %d\n", status);
396 PRINTF1( "in AVGV *** ERR period: %d\n", status);
391 }
397 }
392 else {
398 else {
393 // store new value in buffer
399 // store new value in buffer
394 v[k] = waveform_picker_regs->v;
400 v[k] = waveform_picker_regs->v;
395 e1[k] = waveform_picker_regs->e1;
401 e1[k] = waveform_picker_regs->e1;
396 e2[k] = waveform_picker_regs->e2;
402 e2[k] = waveform_picker_regs->e2;
397 if (k == (MOVING_AVERAGE - 1))
403 if (k == (MOVING_AVERAGE - 1))
398 {
404 {
399 indexOfOldValue = 0;
405 indexOfOldValue = 0;
400 }
406 }
401 else
407 else
402 {
408 {
403 indexOfOldValue = k + 1;
409 indexOfOldValue = k + 1;
404 }
410 }
405 average_v = average_v + v[k] - v[indexOfOldValue];
411 average_v = average_v + v[k] - v[indexOfOldValue];
406 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
412 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
407 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
413 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
408 }
414 }
409 if (k == (MOVING_AVERAGE-1))
415 if (k == (MOVING_AVERAGE-1))
410 {
416 {
411 k = 0;
417 k = 0;
412 printf("tick\n");
418 printf("tick\n");
413 }
419 }
414 else
420 else
415 {
421 {
416 k++;
422 k++;
417 }
423 }
418 }
424 }
419
425
420 PRINTF("in AVGV *** deleting task\n")
426 PRINTF("in AVGV *** deleting task\n")
421
427
422 status = rtems_task_delete( RTEMS_SELF ); // should not return
428 status = rtems_task_delete( RTEMS_SELF ); // should not return
423
429
424 return;
430 return;
425 }
431 }
426
432
427 rtems_task dumb_task( rtems_task_argument unused )
433 rtems_task dumb_task( rtems_task_argument unused )
428 {
434 {
429 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
435 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
430 *
436 *
431 * @param unused is the starting argument of the RTEMS task
437 * @param unused is the starting argument of the RTEMS task
432 *
438 *
433 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
439 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
434 *
440 *
435 */
441 */
436
442
437 unsigned int i;
443 unsigned int i;
438 unsigned int intEventOut;
444 unsigned int intEventOut;
439 unsigned int coarse_time = 0;
445 unsigned int coarse_time = 0;
440 unsigned int fine_time = 0;
446 unsigned int fine_time = 0;
441 rtems_event_set event_out;
447 rtems_event_set event_out;
442
448
443 char *DumbMessages[DUMB_MESSAGE_NB] = {DUMB_MESSAGE_0, // RTEMS_EVENT_0
449 event_out = EVENT_SETS_NONE_PENDING;
444 DUMB_MESSAGE_1, // RTEMS_EVENT_1
445 DUMB_MESSAGE_2, // RTEMS_EVENT_2
446 DUMB_MESSAGE_3, // RTEMS_EVENT_3
447 DUMB_MESSAGE_4, // RTEMS_EVENT_4
448 DUMB_MESSAGE_5, // RTEMS_EVENT_5
449 DUMB_MESSAGE_6, // RTEMS_EVENT_6
450 DUMB_MESSAGE_7, // RTEMS_EVENT_7
451 DUMB_MESSAGE_8, // RTEMS_EVENT_8
452 DUMB_MESSAGE_9, // RTEMS_EVENT_9
453 DUMB_MESSAGE_10, // RTEMS_EVENT_10
454 DUMB_MESSAGE_11, // RTEMS_EVENT_11
455 DUMB_MESSAGE_12, // RTEMS_EVENT_12
456 DUMB_MESSAGE_13, // RTEMS_EVENT_13
457 DUMB_MESSAGE_14 // RTEMS_EVENT_14
458 };
459
450
460 BOOT_PRINTF("in DUMB *** \n")
451 BOOT_PRINTF("in DUMB *** \n")
461
452
462 while(1){
453 while(1){
463 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
454 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
464 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
455 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
465 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
456 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
466 | RTEMS_EVENT_14,
457 | RTEMS_EVENT_14,
467 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
458 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
468 intEventOut = (unsigned int) event_out;
459 intEventOut = (unsigned int) event_out;
469 for ( i=0; i<NB_RTEMS_EVENTS; i++)
460 for ( i=0; i<NB_RTEMS_EVENTS; i++)
470 {
461 {
471 if ( ((intEventOut >> i) & 1) != 0)
462 if ( ((intEventOut >> i) & 1) != 0)
472 {
463 {
473 coarse_time = time_management_regs->coarse_time;
464 coarse_time = time_management_regs->coarse_time;
474 fine_time = time_management_regs->fine_time;
465 fine_time = time_management_regs->fine_time;
475 if (i==EVENT_12)
466 if (i==EVENT_12)
476 {
467 {
477 PRINTF1("%s\n", DUMB_MESSAGE_12)
468 PRINTF1("%s\n", DUMB_MESSAGE_12)
478 }
469 }
479 if (i==EVENT_13)
470 if (i==EVENT_13)
480 {
471 {
481 PRINTF1("%s\n", DUMB_MESSAGE_13)
472 PRINTF1("%s\n", DUMB_MESSAGE_13)
482 }
473 }
483 if (i==EVENT_14)
474 if (i==EVENT_14)
484 {
475 {
485 PRINTF1("%s\n", DUMB_MESSAGE_1)
476 PRINTF1("%s\n", DUMB_MESSAGE_1)
486 }
477 }
487 }
478 }
488 }
479 }
489 }
480 }
490 }
481 }
491
482
492 //*****************************
483 //*****************************
493 // init housekeeping parameters
484 // init housekeeping parameters
494
485
495 void init_housekeeping_parameters( void )
486 void init_housekeeping_parameters( void )
496 {
487 {
497 /** This function initialize the housekeeping_packet global variable with default values.
488 /** This function initialize the housekeeping_packet global variable with default values.
498 *
489 *
499 */
490 */
500
491
501 unsigned int i = 0;
492 unsigned int i = 0;
502 unsigned char *parameters;
493 unsigned char *parameters;
503 unsigned char sizeOfHK;
494 unsigned char sizeOfHK;
504
495
505 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
496 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
506
497
507 parameters = (unsigned char*) &housekeeping_packet;
498 parameters = (unsigned char*) &housekeeping_packet;
508
499
509 for(i = 0; i< sizeOfHK; i++)
500 for(i = 0; i< sizeOfHK; i++)
510 {
501 {
511 parameters[i] = INIT_CHAR;
502 parameters[i] = INIT_CHAR;
512 }
503 }
513
504
514 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
505 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
515 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
506 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
516 housekeeping_packet.reserved = DEFAULT_RESERVED;
507 housekeeping_packet.reserved = DEFAULT_RESERVED;
517 housekeeping_packet.userApplication = CCSDS_USER_APP;
508 housekeeping_packet.userApplication = CCSDS_USER_APP;
518 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
509 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
519 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
510 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
520 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
511 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
521 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
512 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
522 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
513 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
523 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
514 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
524 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
515 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
525 housekeeping_packet.serviceType = TM_TYPE_HK;
516 housekeeping_packet.serviceType = TM_TYPE_HK;
526 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
517 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
527 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
518 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
528 housekeeping_packet.sid = SID_HK;
519 housekeeping_packet.sid = SID_HK;
529
520
530 // init status word
521 // init status word
531 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
522 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
532 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
523 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
533 // init software version
524 // init software version
534 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
525 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
535 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
526 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
536 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
527 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
537 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
528 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
538 // init fpga version
529 // init fpga version
539 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
530 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
540 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
531 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
541 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
532 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
542 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
533 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
543
534
544 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
535 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
545 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
536 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
546 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
537 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
547 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
538 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
548 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
539 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
549 }
540 }
550
541
551 void increment_seq_counter( unsigned short *packetSequenceControl )
542 void increment_seq_counter( unsigned short *packetSequenceControl )
552 {
543 {
553 /** This function increment the sequence counter passes in argument.
544 /** This function increment the sequence counter passes in argument.
554 *
545 *
555 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
546 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
556 *
547 *
557 */
548 */
558
549
559 unsigned short segmentation_grouping_flag;
550 unsigned short segmentation_grouping_flag;
560 unsigned short sequence_cnt;
551 unsigned short sequence_cnt;
561
552
562 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
553 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
563 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
554 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
564
555
565 if ( sequence_cnt < SEQ_CNT_MAX)
556 if ( sequence_cnt < SEQ_CNT_MAX)
566 {
557 {
567 sequence_cnt = sequence_cnt + 1;
558 sequence_cnt = sequence_cnt + 1;
568 }
559 }
569 else
560 else
570 {
561 {
571 sequence_cnt = 0;
562 sequence_cnt = 0;
572 }
563 }
573
564
574 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
565 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
575 }
566 }
576
567
577 void getTime( unsigned char *time)
568 void getTime( unsigned char *time)
578 {
569 {
579 /** This function write the current local time in the time buffer passed in argument.
570 /** This function write the current local time in the time buffer passed in argument.
580 *
571 *
581 */
572 */
582
573
583 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
574 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
584 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
575 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
585 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
576 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
586 time[3] = (unsigned char) (time_management_regs->coarse_time);
577 time[3] = (unsigned char) (time_management_regs->coarse_time);
587 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
578 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
588 time[5] = (unsigned char) (time_management_regs->fine_time);
579 time[5] = (unsigned char) (time_management_regs->fine_time);
589 }
580 }
590
581
591 unsigned long long int getTimeAsUnsignedLongLongInt( )
582 unsigned long long int getTimeAsUnsignedLongLongInt( )
592 {
583 {
593 /** This function write the current local time in the time buffer passed in argument.
584 /** This function write the current local time in the time buffer passed in argument.
594 *
585 *
595 */
586 */
596 unsigned long long int time;
587 unsigned long long int time;
597
588
598 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
589 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
599 + time_management_regs->fine_time;
590 + time_management_regs->fine_time;
600
591
601 return time;
592 return time;
602 }
593 }
603
594
604 void send_dumb_hk( void )
595 void send_dumb_hk( void )
605 {
596 {
606 Packet_TM_LFR_HK_t dummy_hk_packet;
597 Packet_TM_LFR_HK_t dummy_hk_packet;
607 unsigned char *parameters;
598 unsigned char *parameters;
608 unsigned int i;
599 unsigned int i;
609 rtems_id queue_id;
600 rtems_id queue_id;
610
601
602 queue_id = RTEMS_ID_NONE;
603
611 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
604 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
612 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
605 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
613 dummy_hk_packet.reserved = DEFAULT_RESERVED;
606 dummy_hk_packet.reserved = DEFAULT_RESERVED;
614 dummy_hk_packet.userApplication = CCSDS_USER_APP;
607 dummy_hk_packet.userApplication = CCSDS_USER_APP;
615 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
608 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
616 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
609 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
617 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
610 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
618 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
611 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
619 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
612 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
620 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
613 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
621 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
614 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
622 dummy_hk_packet.serviceType = TM_TYPE_HK;
615 dummy_hk_packet.serviceType = TM_TYPE_HK;
623 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
616 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
624 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
617 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
625 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
618 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
626 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
619 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
627 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
620 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
628 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
621 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
629 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
622 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
630 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
623 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
631 dummy_hk_packet.sid = SID_HK;
624 dummy_hk_packet.sid = SID_HK;
632
625
633 // init status word
626 // init status word
634 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
627 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
635 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
628 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
636 // init software version
629 // init software version
637 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
630 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
638 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
631 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
639 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
632 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
640 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
633 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
641 // init fpga version
634 // init fpga version
642 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
635 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
643 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
636 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
644 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
637 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
645 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
638 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
646
639
647 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
640 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
648
641
649 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
642 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
650 {
643 {
651 parameters[i] = INT8_ALL_F;
644 parameters[i] = INT8_ALL_F;
652 }
645 }
653
646
654 get_message_queue_id_send( &queue_id );
647 get_message_queue_id_send( &queue_id );
655
648
656 rtems_message_queue_send( queue_id, &dummy_hk_packet,
649 rtems_message_queue_send( queue_id, &dummy_hk_packet,
657 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
650 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
658 }
651 }
659
652
660 void get_temperatures( unsigned char *temperatures )
653 void get_temperatures( unsigned char *temperatures )
661 {
654 {
662 unsigned char* temp_scm_ptr;
655 unsigned char* temp_scm_ptr;
663 unsigned char* temp_pcb_ptr;
656 unsigned char* temp_pcb_ptr;
664 unsigned char* temp_fpga_ptr;
657 unsigned char* temp_fpga_ptr;
665
658
666 // SEL1 SEL0
659 // SEL1 SEL0
667 // 0 0 => PCB
660 // 0 0 => PCB
668 // 0 1 => FPGA
661 // 0 1 => FPGA
669 // 1 0 => SCM
662 // 1 0 => SCM
670
663
671 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
664 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
672 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
665 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
673 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
666 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
674
667
675 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
668 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
676 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
669 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
677 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
670 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
678 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
671 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
679 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
672 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
680 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
673 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
681 }
674 }
682
675
683 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
676 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
684 {
677 {
685 unsigned char* v_ptr;
678 unsigned char* v_ptr;
686 unsigned char* e1_ptr;
679 unsigned char* e1_ptr;
687 unsigned char* e2_ptr;
680 unsigned char* e2_ptr;
688
681
689 v_ptr = (unsigned char *) &waveform_picker_regs->v;
682 v_ptr = (unsigned char *) &waveform_picker_regs->v;
690 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
683 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
691 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
684 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
692
685
693 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
686 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
694 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
687 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
695 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
688 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
696 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
689 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
697 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
690 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
698 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
691 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
699 }
692 }
700
693
701 void get_cpu_load( unsigned char *resource_statistics )
694 void get_cpu_load( unsigned char *resource_statistics )
702 {
695 {
703 unsigned char cpu_load;
696 unsigned char cpu_load;
704
697
705 cpu_load = lfr_rtems_cpu_usage_report();
698 cpu_load = lfr_rtems_cpu_usage_report();
706
699
707 // HK_LFR_CPU_LOAD
700 // HK_LFR_CPU_LOAD
708 resource_statistics[0] = cpu_load;
701 resource_statistics[0] = cpu_load;
709
702
710 // HK_LFR_CPU_LOAD_MAX
703 // HK_LFR_CPU_LOAD_MAX
711 if (cpu_load > resource_statistics[1])
704 if (cpu_load > resource_statistics[1])
712 {
705 {
713 resource_statistics[1] = cpu_load;
706 resource_statistics[1] = cpu_load;
714 }
707 }
715
708
716 // CPU_LOAD_AVE
709 // CPU_LOAD_AVE
717 resource_statistics[BYTE_2] = 0;
710 resource_statistics[BYTE_2] = 0;
718
711
719 #ifndef PRINT_TASK_STATISTICS
712 #ifndef PRINT_TASK_STATISTICS
720 rtems_cpu_usage_reset();
713 rtems_cpu_usage_reset();
721 #endif
714 #endif
722
715
723 }
716 }
724
717
725 void set_hk_lfr_sc_potential_flag( bool state )
718 void set_hk_lfr_sc_potential_flag( bool state )
726 {
719 {
727 if (state == true)
720 if (state == true)
728 {
721 {
729 housekeeping_packet.lfr_status_word[1] =
722 housekeeping_packet.lfr_status_word[1] =
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
723 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
731 }
724 }
732 else
725 else
733 {
726 {
734 housekeeping_packet.lfr_status_word[1] =
727 housekeeping_packet.lfr_status_word[1] =
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
728 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
736 }
729 }
737 }
730 }
738
731
739 void set_sy_lfr_pas_filter_enabled( bool state )
732 void set_sy_lfr_pas_filter_enabled( bool state )
740 {
733 {
741 if (state == true)
734 if (state == true)
742 {
735 {
743 housekeeping_packet.lfr_status_word[1] =
736 housekeeping_packet.lfr_status_word[1] =
744 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
737 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
745 }
738 }
746 else
739 else
747 {
740 {
748 housekeeping_packet.lfr_status_word[1] =
741 housekeeping_packet.lfr_status_word[1] =
749 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
742 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
750 }
743 }
751 }
744 }
752
745
753 void set_sy_lfr_watchdog_enabled( bool state )
746 void set_sy_lfr_watchdog_enabled( bool state )
754 {
747 {
755 if (state == true)
748 if (state == true)
756 {
749 {
757 housekeeping_packet.lfr_status_word[1] =
750 housekeeping_packet.lfr_status_word[1] =
758 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
751 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
759 }
752 }
760 else
753 else
761 {
754 {
762 housekeeping_packet.lfr_status_word[1] =
755 housekeeping_packet.lfr_status_word[1] =
763 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
756 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
764 }
757 }
765 }
758 }
766
759
767 void set_hk_lfr_calib_enable( bool state )
760 void set_hk_lfr_calib_enable( bool state )
768 {
761 {
769 if (state == true)
762 if (state == true)
770 {
763 {
771 housekeeping_packet.lfr_status_word[1] =
764 housekeeping_packet.lfr_status_word[1] =
772 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
765 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
773 }
766 }
774 else
767 else
775 {
768 {
776 housekeeping_packet.lfr_status_word[1] =
769 housekeeping_packet.lfr_status_word[1] =
777 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
778 }
771 }
779 }
772 }
780
773
781 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
774 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
782 {
775 {
783 housekeeping_packet.lfr_status_word[1] =
776 housekeeping_packet.lfr_status_word[1] =
784 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
777 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
785
778
786 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
779 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
787 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
780 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
788
781
789 }
782 }
790
783
791 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
784 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
792 {
785 {
793 int delta;
786 int delta;
794
787
795 delta = 0;
788 delta = 0;
796
789
797 if (newValue >= oldValue)
790 if (newValue >= oldValue)
798 {
791 {
799 delta = newValue - oldValue;
792 delta = newValue - oldValue;
800 }
793 }
801 else
794 else
802 {
795 {
803 delta = 255 - oldValue + newValue;
796 delta = 255 - oldValue + newValue;
804 }
797 }
805
798
806 *counter = *counter + delta;
799 *counter = *counter + delta;
807 }
800 }
808
801
809 void hk_lfr_le_update( void )
802 void hk_lfr_le_update( void )
810 {
803 {
811 static hk_lfr_le_t old_hk_lfr_le = {0};
804 static hk_lfr_le_t old_hk_lfr_le = {0};
812 hk_lfr_le_t new_hk_lfr_le;
805 hk_lfr_le_t new_hk_lfr_le;
813 unsigned int counter;
806 unsigned int counter;
814
807
815 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
808 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
816
809
817 // DPU
810 // DPU
818 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
811 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
819 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
812 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
820 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
813 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
821 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
814 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
822 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
815 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
823 // TIMECODE
816 // TIMECODE
824 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
817 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
825 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
818 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
826 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
819 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
827 // TIME
820 // TIME
828 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
821 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
829 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
822 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
830 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
823 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
831 //AHB
824 //AHB
832 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
825 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
833 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
826 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
834 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
827 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
835
828
836 // update the le counter
829 // update the le counter
837 // DPU
830 // DPU
838 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
831 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
839 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
832 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
840 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
833 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
841 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
834 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
842 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
835 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
843 // TIMECODE
836 // TIMECODE
844 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
837 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
845 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
838 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
846 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
839 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
847 // TIME
840 // TIME
848 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
841 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
849 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
842 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
850 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
843 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
851 // AHB
844 // AHB
852 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
845 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
853
846
854 // DPU
847 // DPU
855 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
848 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
856 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
849 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
857 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
850 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
858 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
851 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
859 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
852 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
860 // TIMECODE
853 // TIMECODE
861 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
854 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
862 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
855 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
863 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
856 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
864 // TIME
857 // TIME
865 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
858 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
866 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
859 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
867 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
860 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
868 //AHB
861 //AHB
869 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
862 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
870 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
863 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
871 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
864 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
872
865
873 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
866 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
874 // LE
867 // LE
875 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
868 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
876 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
869 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
877 }
870 }
878
871
879 void hk_lfr_me_update( void )
872 void hk_lfr_me_update( void )
880 {
873 {
881 static hk_lfr_me_t old_hk_lfr_me = {0};
874 static hk_lfr_me_t old_hk_lfr_me = {0};
882 hk_lfr_me_t new_hk_lfr_me;
875 hk_lfr_me_t new_hk_lfr_me;
883 unsigned int counter;
876 unsigned int counter;
884
877
885 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
878 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
886
879
887 // get the current values
880 // get the current values
888 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
881 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
889 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
882 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
890 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
883 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
891 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
884 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
892
885
893 // update the me counter
886 // update the me counter
894 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
887 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
895 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
888 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
896 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
889 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
897 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
890 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
898
891
899 // store the counters for the next time
892 // store the counters for the next time
900 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
893 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
901 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
894 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
902 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
895 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
903 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
896 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
904
897
905 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
898 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
906 // ME
899 // ME
907 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
900 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
908 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
901 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
909 }
902 }
910
903
911 void hk_lfr_le_me_he_update()
904 void hk_lfr_le_me_he_update()
912 {
905 {
913
906
914 unsigned int hk_lfr_he_cnt;
907 unsigned int hk_lfr_he_cnt;
915
908
916 hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
909 hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
917
910
918 //update the low severity error counter
911 //update the low severity error counter
919 hk_lfr_le_update( );
912 hk_lfr_le_update( );
920
913
921 //update the medium severity error counter
914 //update the medium severity error counter
922 hk_lfr_me_update();
915 hk_lfr_me_update();
923
916
924 //update the high severity error counter
917 //update the high severity error counter
925 hk_lfr_he_cnt = 0;
918 hk_lfr_he_cnt = 0;
926
919
927 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
920 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
928 // HE
921 // HE
929 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
922 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
930 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
923 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
931
924
932 }
925 }
933
926
934 void set_hk_lfr_time_not_synchro()
927 void set_hk_lfr_time_not_synchro()
935 {
928 {
936 static unsigned char synchroLost = 1;
929 static unsigned char synchroLost = 1;
937 int synchronizationBit;
930 int synchronizationBit;
938
931
939 // get the synchronization bit
932 // get the synchronization bit
940 synchronizationBit =
933 synchronizationBit =
941 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
934 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
942
935
943 switch (synchronizationBit)
936 switch (synchronizationBit)
944 {
937 {
945 case 0:
938 case 0:
946 if (synchroLost == 1)
939 if (synchroLost == 1)
947 {
940 {
948 synchroLost = 0;
941 synchroLost = 0;
949 }
942 }
950 break;
943 break;
951 case 1:
944 case 1:
952 if (synchroLost == 0 )
945 if (synchroLost == 0 )
953 {
946 {
954 synchroLost = 1;
947 synchroLost = 1;
955 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
948 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
956 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
949 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
957 }
950 }
958 break;
951 break;
959 default:
952 default:
960 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
953 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
961 break;
954 break;
962 }
955 }
963
956
964 }
957 }
965
958
966 void set_hk_lfr_ahb_correctable() // CRITICITY L
959 void set_hk_lfr_ahb_correctable() // CRITICITY L
967 {
960 {
968 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
961 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
969 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
962 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
970 * detected errors in the cache, in the integer unit and in the floating point unit.
963 * detected errors in the cache, in the integer unit and in the floating point unit.
971 *
964 *
972 * @param void
965 * @param void
973 *
966 *
974 * @return void
967 * @return void
975 *
968 *
976 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
969 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
977 *
970 *
978 */
971 */
979
972
980 unsigned int ahb_correctable;
973 unsigned int ahb_correctable;
981 unsigned int instructionErrorCounter;
974 unsigned int instructionErrorCounter;
982 unsigned int dataErrorCounter;
975 unsigned int dataErrorCounter;
983 unsigned int fprfErrorCounter;
976 unsigned int fprfErrorCounter;
984 unsigned int iurfErrorCounter;
977 unsigned int iurfErrorCounter;
985
978
979 instructionErrorCounter = 0;
980 dataErrorCounter = 0;
981 fprfErrorCounter = 0;
982 iurfErrorCounter = 0;
983
986 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
984 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
987 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
985 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
988
986
989 ahb_correctable = instructionErrorCounter
987 ahb_correctable = instructionErrorCounter
990 + dataErrorCounter
988 + dataErrorCounter
991 + fprfErrorCounter
989 + fprfErrorCounter
992 + iurfErrorCounter
990 + iurfErrorCounter
993 + housekeeping_packet.hk_lfr_ahb_correctable;
991 + housekeeping_packet.hk_lfr_ahb_correctable;
994
992
995 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
993 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
996
994
997 }
995 }
@@ -1,1611 +1,1631
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
24
25 unsigned char previousTimecodeCtr = 0;
25 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
27
28 //***********
28 //***********
29 // RTEMS TASK
29 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
30 rtems_task spiq_task(rtems_task_argument unused)
31 {
31 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
33 *
34 * @param unused is the starting argument of the RTEMS task
34 * @param unused is the starting argument of the RTEMS task
35 *
35 *
36 */
36 */
37
37
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 int linkStatus;
40 int linkStatus;
41
41
42 event_out = EVENT_SETS_NONE_PENDING;
43 linkStatus = 0;
44
42 BOOT_PRINTF("in SPIQ *** \n")
45 BOOT_PRINTF("in SPIQ *** \n")
43
46
44 while(true){
47 while(true){
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47
50
48 // [0] SUSPEND RECV AND SEND TASKS
51 // [0] SUSPEND RECV AND SEND TASKS
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 if ( status != RTEMS_SUCCESSFUL ) {
53 if ( status != RTEMS_SUCCESSFUL ) {
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 }
55 }
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 if ( status != RTEMS_SUCCESSFUL ) {
57 if ( status != RTEMS_SUCCESSFUL ) {
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 }
59 }
57
60
58 // [1] CHECK THE LINK
61 // [1] CHECK THE LINK
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 if ( linkStatus != SPW_LINK_OK) {
63 if ( linkStatus != SPW_LINK_OK) {
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 }
66 }
64
67
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
68 {
71 {
69 spacewire_read_statistics();
72 spacewire_read_statistics();
70 status = spacewire_several_connect_attemps( );
73 status = spacewire_several_connect_attemps( );
71 }
74 }
72 else // [2.b] in run state, start the link
75 else // [2.b] in run state, start the link
73 {
76 {
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 if ( status != RTEMS_SUCCESSFUL)
78 if ( status != RTEMS_SUCCESSFUL)
76 {
79 {
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 }
81 }
79 }
82 }
80
83
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 {
86 {
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 if ( status != RTEMS_SUCCESSFUL ) {
88 if ( status != RTEMS_SUCCESSFUL ) {
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 }
90 }
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 if ( status != RTEMS_SUCCESSFUL ) {
92 if ( status != RTEMS_SUCCESSFUL ) {
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 }
94 }
92 }
95 }
93 else // [3.b] the link is not in run state, go in STANDBY mode
96 else // [3.b] the link is not in run state, go in STANDBY mode
94 {
97 {
95 status = enter_mode_standby();
98 status = enter_mode_standby();
96 if ( status != RTEMS_SUCCESSFUL )
99 if ( status != RTEMS_SUCCESSFUL )
97 {
100 {
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 }
102 }
100 {
103 {
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 }
105 }
103 // wake the LINK task up to wait for the link recovery
106 // wake the LINK task up to wait for the link recovery
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 status = rtems_task_suspend( RTEMS_SELF );
108 status = rtems_task_suspend( RTEMS_SELF );
106 }
109 }
107 }
110 }
108 }
111 }
109
112
110 rtems_task recv_task( rtems_task_argument unused )
113 rtems_task recv_task( rtems_task_argument unused )
111 {
114 {
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 *
116 *
114 * @param unused is the starting argument of the RTEMS task
117 * @param unused is the starting argument of the RTEMS task
115 *
118 *
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 * 1. It reads the incoming data.
120 * 1. It reads the incoming data.
118 * 2. Launches the acceptance procedure.
121 * 2. Launches the acceptance procedure.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 *
123 *
121 */
124 */
122
125
123 int len;
126 int len;
124 ccsdsTelecommandPacket_t currentTC;
127 ccsdsTelecommandPacket_t currentTC;
125 unsigned char computed_CRC[ BYTES_PER_CRC ];
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
126 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
127 unsigned char destinationID;
130 unsigned char destinationID;
128 unsigned int estimatedPacketLength;
131 unsigned int estimatedPacketLength;
129 unsigned int parserCode;
132 unsigned int parserCode;
130 rtems_status_code status;
133 rtems_status_code status;
131 rtems_id queue_recv_id;
134 rtems_id queue_recv_id;
132 rtems_id queue_send_id;
135 rtems_id queue_send_id;
133
136
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 destinationID = 0;
139 queue_recv_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
141
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135
143
136 status = get_message_queue_id_recv( &queue_recv_id );
144 status = get_message_queue_id_recv( &queue_recv_id );
137 if (status != RTEMS_SUCCESSFUL)
145 if (status != RTEMS_SUCCESSFUL)
138 {
146 {
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 }
148 }
141
149
142 status = get_message_queue_id_send( &queue_send_id );
150 status = get_message_queue_id_send( &queue_send_id );
143 if (status != RTEMS_SUCCESSFUL)
151 if (status != RTEMS_SUCCESSFUL)
144 {
152 {
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 }
154 }
147
155
148 BOOT_PRINTF("in RECV *** \n")
156 BOOT_PRINTF("in RECV *** \n")
149
157
150 while(1)
158 while(1)
151 {
159 {
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 if (len == -1){ // error during the read call
161 if (len == -1){ // error during the read call
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 }
163 }
156 else {
164 else {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 PRINTF("in RECV *** packet lenght too short\n")
166 PRINTF("in RECV *** packet lenght too short\n")
159 }
167 }
160 else {
168 else {
161 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
162 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
165 // CHECK THE TC
173 // CHECK THE TC
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
170 || (parserCode == WRONG_SRC_ID) )
178 || (parserCode == WRONG_SRC_ID) )
171 { // send TM_LFR_TC_EXE_CORRUPTED
179 { // send TM_LFR_TC_EXE_CORRUPTED
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
174 &&
182 &&
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
176 )
184 )
177 {
185 {
178 if ( parserCode == WRONG_SRC_ID )
186 if ( parserCode == WRONG_SRC_ID )
179 {
187 {
180 destinationID = SID_TC_GROUND;
188 destinationID = SID_TC_GROUND;
181 }
189 }
182 else
190 else
183 {
191 {
184 destinationID = currentTC.sourceID;
192 destinationID = currentTC.sourceID;
185 }
193 }
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
187 computed_CRC, currentTC_LEN_RCV,
195 computed_CRC, currentTC_LEN_RCV,
188 destinationID );
196 destinationID );
189 }
197 }
190 }
198 }
191 else
199 else
192 { // send valid TC to the action launcher
200 { // send valid TC to the action launcher
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
195 }
203 }
196 }
204 }
197 }
205 }
198
206
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
200
208
201 }
209 }
202 }
210 }
203
211
204 rtems_task send_task( rtems_task_argument argument)
212 rtems_task send_task( rtems_task_argument argument)
205 {
213 {
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
207 *
215 *
208 * @param unused is the starting argument of the RTEMS task
216 * @param unused is the starting argument of the RTEMS task
209 *
217 *
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
214 * data it contains.
222 * data it contains.
215 *
223 *
216 */
224 */
217
225
218 rtems_status_code status; // RTEMS status code
226 rtems_status_code status; // RTEMS status code
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
220 ring_node *incomingRingNodePtr;
228 ring_node *incomingRingNodePtr;
221 int ring_node_address;
229 int ring_node_address;
222 char *charPtr;
230 char *charPtr;
223 spw_ioctl_pkt_send *spw_ioctl_send;
231 spw_ioctl_pkt_send *spw_ioctl_send;
224 size_t size; // size of the incoming TC packet
232 size_t size; // size of the incoming TC packet
225 rtems_id queue_send_id;
233 rtems_id queue_send_id;
226 unsigned int sid;
234 unsigned int sid;
227 unsigned char sidAsUnsignedChar;
235 unsigned char sidAsUnsignedChar;
228 unsigned char type;
236 unsigned char type;
229
237
230 incomingRingNodePtr = NULL;
238 incomingRingNodePtr = NULL;
231 ring_node_address = 0;
239 ring_node_address = 0;
232 charPtr = (char *) &ring_node_address;
240 charPtr = (char *) &ring_node_address;
241 size = 0;
242 queue_send_id = RTEMS_ID_NONE;
233 sid = 0;
243 sid = 0;
234 sidAsUnsignedChar = 0;
244 sidAsUnsignedChar = 0;
235
245
236 init_header_cwf( &headerCWF );
246 init_header_cwf( &headerCWF );
237 init_header_swf( &headerSWF );
247 init_header_swf( &headerSWF );
238 init_header_asm( &headerASM );
248 init_header_asm( &headerASM );
239
249
240 status = get_message_queue_id_send( &queue_send_id );
250 status = get_message_queue_id_send( &queue_send_id );
241 if (status != RTEMS_SUCCESSFUL)
251 if (status != RTEMS_SUCCESSFUL)
242 {
252 {
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
244 }
254 }
245
255
246 BOOT_PRINTF("in SEND *** \n")
256 BOOT_PRINTF("in SEND *** \n")
247
257
248 while(1)
258 while(1)
249 {
259 {
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
252
262
253 if (status!=RTEMS_SUCCESSFUL)
263 if (status!=RTEMS_SUCCESSFUL)
254 {
264 {
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
256 }
266 }
257 else
267 else
258 {
268 {
259 if ( size == sizeof(ring_node*) )
269 if ( size == sizeof(ring_node*) )
260 {
270 {
261 charPtr[0] = incomingData[0];
271 charPtr[0] = incomingData[0];
262 charPtr[1] = incomingData[1];
272 charPtr[1] = incomingData[1];
263 charPtr[BYTE_2] = incomingData[BYTE_2];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
264 charPtr[BYTE_3] = incomingData[BYTE_3];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
265 incomingRingNodePtr = (ring_node*) ring_node_address;
275 incomingRingNodePtr = (ring_node*) ring_node_address;
266 sid = incomingRingNodePtr->sid;
276 sid = incomingRingNodePtr->sid;
267 if ( (sid==SID_NORM_CWF_LONG_F3)
277 if ( (sid==SID_NORM_CWF_LONG_F3)
268 || (sid==SID_BURST_CWF_F2 )
278 || (sid==SID_BURST_CWF_F2 )
269 || (sid==SID_SBM1_CWF_F1 )
279 || (sid==SID_SBM1_CWF_F1 )
270 || (sid==SID_SBM2_CWF_F2 ))
280 || (sid==SID_SBM2_CWF_F2 ))
271 {
281 {
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
273 }
283 }
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
275 {
285 {
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
277 }
287 }
278 else if ( (sid==SID_NORM_CWF_F3) )
288 else if ( (sid==SID_NORM_CWF_F3) )
279 {
289 {
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
281 }
291 }
282 else if (sid==SID_NORM_ASM_F0)
292 else if (sid==SID_NORM_ASM_F0)
283 {
293 {
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
285 }
295 }
286 else if (sid==SID_NORM_ASM_F1)
296 else if (sid==SID_NORM_ASM_F1)
287 {
297 {
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
289 }
299 }
290 else if (sid==SID_NORM_ASM_F2)
300 else if (sid==SID_NORM_ASM_F2)
291 {
301 {
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
293 }
303 }
294 else if ( sid==TM_CODE_K_DUMP )
304 else if ( sid==TM_CODE_K_DUMP )
295 {
305 {
296 spw_send_k_dump( incomingRingNodePtr );
306 spw_send_k_dump( incomingRingNodePtr );
297 }
307 }
298 else
308 else
299 {
309 {
300 PRINTF1("unexpected sid = %d\n", sid);
310 PRINTF1("unexpected sid = %d\n", sid);
301 }
311 }
302 }
312 }
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
304 {
314 {
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
306 sid = sidAsUnsignedChar;
316 sid = sidAsUnsignedChar;
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
310 {
320 {
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
312 }
322 }
313
323
314 status = write( fdSPW, incomingData, size );
324 status = write( fdSPW, incomingData, size );
315 if (status == -1){
325 if (status == -1){
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
317 }
327 }
318 }
328 }
319 else // the incoming message is a spw_ioctl_pkt_send structure
329 else // the incoming message is a spw_ioctl_pkt_send structure
320 {
330 {
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
323 if (status == -1){
333 if (status == -1){
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
325 }
335 }
326 }
336 }
327 }
337 }
328
338
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
330
340
331 }
341 }
332 }
342 }
333
343
334 rtems_task link_task( rtems_task_argument argument )
344 rtems_task link_task( rtems_task_argument argument )
335 {
345 {
336 rtems_event_set event_out;
346 rtems_event_set event_out;
337 rtems_status_code status;
347 rtems_status_code status;
338 int linkStatus;
348 int linkStatus;
339
349
350 event_out = EVENT_SETS_NONE_PENDING;
351 linkStatus = 0;
352
340 BOOT_PRINTF("in LINK ***\n")
353 BOOT_PRINTF("in LINK ***\n")
341
354
342 while(1)
355 while(1)
343 {
356 {
344 // wait for an RTEMS_EVENT
357 // wait for an RTEMS_EVENT
345 rtems_event_receive( RTEMS_EVENT_0,
358 rtems_event_receive( RTEMS_EVENT_0,
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
347 PRINTF("in LINK *** wait for the link\n")
360 PRINTF("in LINK *** wait for the link\n")
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
349 while( linkStatus != SPW_LINK_OK) // wait for the link
362 while( linkStatus != SPW_LINK_OK) // wait for the link
350 {
363 {
351 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
353 watchdog_reload();
366 watchdog_reload();
354 }
367 }
355
368
356 spacewire_read_statistics();
369 spacewire_read_statistics();
357 status = spacewire_stop_and_start_link( fdSPW );
370 status = spacewire_stop_and_start_link( fdSPW );
358
371
359 if (status != RTEMS_SUCCESSFUL)
372 if (status != RTEMS_SUCCESSFUL)
360 {
373 {
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
362 }
375 }
363 else
376 else
364 {
377 {
365 PRINTF("in LINK *** OK link started\n")
378 PRINTF("in LINK *** OK link started\n")
366 }
379 }
367
380
368 // restart the SPIQ task
381 // restart the SPIQ task
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
370 if ( status != RTEMS_SUCCESSFUL ) {
383 if ( status != RTEMS_SUCCESSFUL ) {
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
372 }
385 }
373
386
374 // restart RECV and SEND
387 // restart RECV and SEND
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
376 if ( status != RTEMS_SUCCESSFUL ) {
389 if ( status != RTEMS_SUCCESSFUL ) {
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
378 }
391 }
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
380 if ( status != RTEMS_SUCCESSFUL ) {
393 if ( status != RTEMS_SUCCESSFUL ) {
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
382 }
395 }
383 }
396 }
384 }
397 }
385
398
386 //****************
399 //****************
387 // OTHER FUNCTIONS
400 // OTHER FUNCTIONS
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
389 {
402 {
390 /** This function opens the SpaceWire link.
403 /** This function opens the SpaceWire link.
391 *
404 *
392 * @return a valid file descriptor in case of success, -1 in case of a failure
405 * @return a valid file descriptor in case of success, -1 in case of a failure
393 *
406 *
394 */
407 */
395 rtems_status_code status;
408 rtems_status_code status;
396
409
410 status = RTEMS_SUCCESSFUL;
411
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
398 if ( fdSPW < 0 ) {
413 if ( fdSPW < 0 ) {
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
400 }
415 }
401 else
416 else
402 {
417 {
403 status = RTEMS_SUCCESSFUL;
418 status = RTEMS_SUCCESSFUL;
404 }
419 }
405
420
406 return status;
421 return status;
407 }
422 }
408
423
409 int spacewire_start_link( int fd )
424 int spacewire_start_link( int fd )
410 {
425 {
411 rtems_status_code status;
426 rtems_status_code status;
412
427
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
414 // -1 default hardcoded driver timeout
429 // -1 default hardcoded driver timeout
415
430
416 return status;
431 return status;
417 }
432 }
418
433
419 int spacewire_stop_and_start_link( int fd )
434 int spacewire_stop_and_start_link( int fd )
420 {
435 {
421 rtems_status_code status;
436 rtems_status_code status;
422
437
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
425 // -1 default hardcoded driver timeout
440 // -1 default hardcoded driver timeout
426
441
427 return status;
442 return status;
428 }
443 }
429
444
430 int spacewire_configure_link( int fd )
445 int spacewire_configure_link( int fd )
431 {
446 {
432 /** This function configures the SpaceWire link.
447 /** This function configures the SpaceWire link.
433 *
448 *
434 * @return GR-RTEMS-DRIVER directive status codes:
449 * @return GR-RTEMS-DRIVER directive status codes:
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
441 * - 2 ENOENT - No such file or directory
456 * - 2 ENOENT - No such file or directory
442 */
457 */
443
458
444 rtems_status_code status;
459 rtems_status_code status;
445
460
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
448 spw_ioctl_packetsize packetsize;
463 spw_ioctl_packetsize packetsize;
449
464
450 packetsize.rxsize = SPW_RXSIZE;
465 packetsize.rxsize = SPW_RXSIZE;
451 packetsize.txdsize = SPW_TXDSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
452 packetsize.txhsize = SPW_TXHSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
453
468
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
455 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
457 }
472 }
458 //
473 //
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
460 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
462 }
477 }
463 //
478 //
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
465 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
467 }
482 }
468 //
483 //
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
470 if (status!=RTEMS_SUCCESSFUL) {
485 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
472 }
487 }
473 //
488 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
475 if (status!=RTEMS_SUCCESSFUL) {
490 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
477 }
492 }
478 //
493 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
480 if (status!=RTEMS_SUCCESSFUL) {
495 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
482 }
497 }
483 //
498 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
485 if (status!=RTEMS_SUCCESSFUL) {
500 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
487 }
502 }
488 //
503 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
490 if (status!=RTEMS_SUCCESSFUL) {
505 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
492 }
507 }
493
508
494 return status;
509 return status;
495 }
510 }
496
511
497 int spacewire_several_connect_attemps( void )
512 int spacewire_several_connect_attemps( void )
498 {
513 {
499 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
500 *
515 *
501 * @return RTEMS directive status code:
516 * @return RTEMS directive status code:
502 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
503 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
504 *
519 *
505 */
520 */
506
521
507 rtems_status_code status_spw;
522 rtems_status_code status_spw;
508 rtems_status_code status;
523 rtems_status_code status;
509 int i;
524 int i;
510
525
526 status_spw = RTEMS_SUCCESSFUL;
527
511 i = 0;
528 i = 0;
512 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
513 {
530 {
514 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
515
532
516 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
517
534
518 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
519
536
520 status_spw = spacewire_stop_and_start_link( fdSPW );
537 status_spw = spacewire_stop_and_start_link( fdSPW );
521
538
522 if ( status_spw != RTEMS_SUCCESSFUL )
539 if ( status_spw != RTEMS_SUCCESSFUL )
523 {
540 {
524 i = i + 1;
541 i = i + 1;
525 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
526 }
543 }
527 else
544 else
528 {
545 {
529 i = SY_LFR_DPU_CONNECT_ATTEMPT;
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
530 }
547 }
531 }
548 }
532
549
533 return status_spw;
550 return status_spw;
534 }
551 }
535
552
536 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
537 {
554 {
538 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
539 *
556 *
540 * @param val is the value, 0 or 1, used to set the value of the NP bit.
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
541 * @param regAddr is the address of the GRSPW control register.
558 * @param regAddr is the address of the GRSPW control register.
542 *
559 *
543 * NP is the bit 20 of the GRSPW control register.
560 * NP is the bit 20 of the GRSPW control register.
544 *
561 *
545 */
562 */
546
563
547 unsigned int *spwptr = (unsigned int*) regAddr;
564 unsigned int *spwptr = (unsigned int*) regAddr;
548
565
549 if (val == 1) {
566 if (val == 1) {
550 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
551 }
568 }
552 if (val== 0) {
569 if (val== 0) {
553 *spwptr = *spwptr & SPW_BIT_NP_MASK;
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
554 }
571 }
555 }
572 }
556
573
557 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
558 {
575 {
559 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
560 *
577 *
561 * @param val is the value, 0 or 1, used to set the value of the RE bit.
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
562 * @param regAddr is the address of the GRSPW control register.
579 * @param regAddr is the address of the GRSPW control register.
563 *
580 *
564 * RE is the bit 16 of the GRSPW control register.
581 * RE is the bit 16 of the GRSPW control register.
565 *
582 *
566 */
583 */
567
584
568 unsigned int *spwptr = (unsigned int*) regAddr;
585 unsigned int *spwptr = (unsigned int*) regAddr;
569
586
570 if (val == 1)
587 if (val == 1)
571 {
588 {
572 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
573 }
590 }
574 if (val== 0)
591 if (val== 0)
575 {
592 {
576 *spwptr = *spwptr & SPW_BIT_RE_MASK;
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
577 }
594 }
578 }
595 }
579
596
580 void spacewire_read_statistics( void )
597 void spacewire_read_statistics( void )
581 {
598 {
582 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
583 *
600 *
584 * @param void
601 * @param void
585 *
602 *
586 * @return void
603 * @return void
587 *
604 *
588 * Once they are read, the counters are stored in a global variable used during the building of the
605 * Once they are read, the counters are stored in a global variable used during the building of the
589 * HK packets.
606 * HK packets.
590 *
607 *
591 */
608 */
592
609
593 rtems_status_code status;
610 rtems_status_code status;
594 spw_stats current;
611 spw_stats current;
595
612
613 memset(&current, 0, sizeof(spw_stats));
614
596 spacewire_get_last_error();
615 spacewire_get_last_error();
597
616
598 // read the current statistics
617 // read the current statistics
599 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
600
619
601 // clear the counters
620 // clear the counters
602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
603
622
604 // typedef struct {
623 // typedef struct {
605 // unsigned int tx_link_err; // NOT IN HK
624 // unsigned int tx_link_err; // NOT IN HK
606 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
607 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
608 // unsigned int rx_eep_err;
627 // unsigned int rx_eep_err;
609 // unsigned int rx_truncated;
628 // unsigned int rx_truncated;
610 // unsigned int parity_err;
629 // unsigned int parity_err;
611 // unsigned int escape_err;
630 // unsigned int escape_err;
612 // unsigned int credit_err;
631 // unsigned int credit_err;
613 // unsigned int write_sync_err;
632 // unsigned int write_sync_err;
614 // unsigned int disconnect_err;
633 // unsigned int disconnect_err;
615 // unsigned int early_ep;
634 // unsigned int early_ep;
616 // unsigned int invalid_address;
635 // unsigned int invalid_address;
617 // unsigned int packets_sent;
636 // unsigned int packets_sent;
618 // unsigned int packets_received;
637 // unsigned int packets_received;
619 // } spw_stats;
638 // } spw_stats;
620
639
621 // rx_eep_err
640 // rx_eep_err
622 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
623 // rx_truncated
642 // rx_truncated
624 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
625 // parity_err
644 // parity_err
626 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
627 // escape_err
646 // escape_err
628 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
629 // credit_err
648 // credit_err
630 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
631 // write_sync_err
650 // write_sync_err
632 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
633 // disconnect_err
652 // disconnect_err
634 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
635 // early_ep
654 // early_ep
636 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
637 // invalid_address
656 // invalid_address
638 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
639 // packets_sent
658 // packets_sent
640 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
641 // packets_received
660 // packets_received
642 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
643
662
644 }
663 }
645
664
646 void spacewire_get_last_error( void )
665 void spacewire_get_last_error( void )
647 {
666 {
648 static spw_stats previous;
667 static spw_stats previous = {0};
649 spw_stats current;
668 spw_stats current;
650 rtems_status_code status;
669 rtems_status_code status;
651
670
652 unsigned int hk_lfr_last_er_rid;
671 unsigned int hk_lfr_last_er_rid;
653 unsigned char hk_lfr_last_er_code;
672 unsigned char hk_lfr_last_er_code;
654 int coarseTime;
673 int coarseTime;
655 int fineTime;
674 int fineTime;
656 unsigned char update_hk_lfr_last_er;
675 unsigned char update_hk_lfr_last_er;
657
676
677 memset(&current, 0, sizeof(spw_stats));
658 update_hk_lfr_last_er = 0;
678 update_hk_lfr_last_er = 0;
659
679
660 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
680 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
661
681
662 // get current time
682 // get current time
663 coarseTime = time_management_regs->coarse_time;
683 coarseTime = time_management_regs->coarse_time;
664 fineTime = time_management_regs->fine_time;
684 fineTime = time_management_regs->fine_time;
665
685
666 // typedef struct {
686 // typedef struct {
667 // unsigned int tx_link_err; // NOT IN HK
687 // unsigned int tx_link_err; // NOT IN HK
668 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
688 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
669 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
689 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
670 // unsigned int rx_eep_err;
690 // unsigned int rx_eep_err;
671 // unsigned int rx_truncated;
691 // unsigned int rx_truncated;
672 // unsigned int parity_err;
692 // unsigned int parity_err;
673 // unsigned int escape_err;
693 // unsigned int escape_err;
674 // unsigned int credit_err;
694 // unsigned int credit_err;
675 // unsigned int write_sync_err;
695 // unsigned int write_sync_err;
676 // unsigned int disconnect_err;
696 // unsigned int disconnect_err;
677 // unsigned int early_ep;
697 // unsigned int early_ep;
678 // unsigned int invalid_address;
698 // unsigned int invalid_address;
679 // unsigned int packets_sent;
699 // unsigned int packets_sent;
680 // unsigned int packets_received;
700 // unsigned int packets_received;
681 // } spw_stats;
701 // } spw_stats;
682
702
683 // tx_link_err *** no code associated to this field
703 // tx_link_err *** no code associated to this field
684 // rx_rmap_header_crc_err *** LE *** in HK
704 // rx_rmap_header_crc_err *** LE *** in HK
685 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
705 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
686 {
706 {
687 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
707 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
688 hk_lfr_last_er_code = CODE_HEADER_CRC;
708 hk_lfr_last_er_code = CODE_HEADER_CRC;
689 update_hk_lfr_last_er = 1;
709 update_hk_lfr_last_er = 1;
690 }
710 }
691 // rx_rmap_data_crc_err *** LE *** NOT IN HK
711 // rx_rmap_data_crc_err *** LE *** NOT IN HK
692 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
712 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
693 {
713 {
694 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
714 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
695 hk_lfr_last_er_code = CODE_DATA_CRC;
715 hk_lfr_last_er_code = CODE_DATA_CRC;
696 update_hk_lfr_last_er = 1;
716 update_hk_lfr_last_er = 1;
697 }
717 }
698 // rx_eep_err
718 // rx_eep_err
699 if (previous.rx_eep_err != current.rx_eep_err)
719 if (previous.rx_eep_err != current.rx_eep_err)
700 {
720 {
701 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
721 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
702 hk_lfr_last_er_code = CODE_EEP;
722 hk_lfr_last_er_code = CODE_EEP;
703 update_hk_lfr_last_er = 1;
723 update_hk_lfr_last_er = 1;
704 }
724 }
705 // rx_truncated
725 // rx_truncated
706 if (previous.rx_truncated != current.rx_truncated)
726 if (previous.rx_truncated != current.rx_truncated)
707 {
727 {
708 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
728 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
709 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
729 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
710 update_hk_lfr_last_er = 1;
730 update_hk_lfr_last_er = 1;
711 }
731 }
712 // parity_err
732 // parity_err
713 if (previous.parity_err != current.parity_err)
733 if (previous.parity_err != current.parity_err)
714 {
734 {
715 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
735 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
716 hk_lfr_last_er_code = CODE_PARITY;
736 hk_lfr_last_er_code = CODE_PARITY;
717 update_hk_lfr_last_er = 1;
737 update_hk_lfr_last_er = 1;
718 }
738 }
719 // escape_err
739 // escape_err
720 if (previous.parity_err != current.parity_err)
740 if (previous.parity_err != current.parity_err)
721 {
741 {
722 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
742 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
723 hk_lfr_last_er_code = CODE_ESCAPE;
743 hk_lfr_last_er_code = CODE_ESCAPE;
724 update_hk_lfr_last_er = 1;
744 update_hk_lfr_last_er = 1;
725 }
745 }
726 // credit_err
746 // credit_err
727 if (previous.credit_err != current.credit_err)
747 if (previous.credit_err != current.credit_err)
728 {
748 {
729 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
749 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
730 hk_lfr_last_er_code = CODE_CREDIT;
750 hk_lfr_last_er_code = CODE_CREDIT;
731 update_hk_lfr_last_er = 1;
751 update_hk_lfr_last_er = 1;
732 }
752 }
733 // write_sync_err
753 // write_sync_err
734 if (previous.write_sync_err != current.write_sync_err)
754 if (previous.write_sync_err != current.write_sync_err)
735 {
755 {
736 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
756 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
737 hk_lfr_last_er_code = CODE_WRITE_SYNC;
757 hk_lfr_last_er_code = CODE_WRITE_SYNC;
738 update_hk_lfr_last_er = 1;
758 update_hk_lfr_last_er = 1;
739 }
759 }
740 // disconnect_err
760 // disconnect_err
741 if (previous.disconnect_err != current.disconnect_err)
761 if (previous.disconnect_err != current.disconnect_err)
742 {
762 {
743 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
763 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
744 hk_lfr_last_er_code = CODE_DISCONNECT;
764 hk_lfr_last_er_code = CODE_DISCONNECT;
745 update_hk_lfr_last_er = 1;
765 update_hk_lfr_last_er = 1;
746 }
766 }
747 // early_ep
767 // early_ep
748 if (previous.early_ep != current.early_ep)
768 if (previous.early_ep != current.early_ep)
749 {
769 {
750 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
770 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
751 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
771 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
752 update_hk_lfr_last_er = 1;
772 update_hk_lfr_last_er = 1;
753 }
773 }
754 // invalid_address
774 // invalid_address
755 if (previous.invalid_address != current.invalid_address)
775 if (previous.invalid_address != current.invalid_address)
756 {
776 {
757 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
777 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
758 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
778 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
759 update_hk_lfr_last_er = 1;
779 update_hk_lfr_last_er = 1;
760 }
780 }
761
781
762 // if a field has changed, update the hk_last_er fields
782 // if a field has changed, update the hk_last_er fields
763 if (update_hk_lfr_last_er == 1)
783 if (update_hk_lfr_last_er == 1)
764 {
784 {
765 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
785 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
766 }
786 }
767
787
768 previous = current;
788 previous = current;
769 }
789 }
770
790
771 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
791 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
772 {
792 {
773 unsigned char *coarseTimePtr;
793 unsigned char *coarseTimePtr;
774 unsigned char *fineTimePtr;
794 unsigned char *fineTimePtr;
775
795
776 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
796 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
777 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
797 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
778
798
779 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
799 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
780 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
800 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
781 housekeeping_packet.hk_lfr_last_er_code = code;
801 housekeeping_packet.hk_lfr_last_er_code = code;
782 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
802 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
783 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
803 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
784 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
804 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
785 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
805 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
786 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
787 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
788 }
808 }
789
809
790 void update_hk_with_grspw_stats( void )
810 void update_hk_with_grspw_stats( void )
791 {
811 {
792 //****************************
812 //****************************
793 // DPU_SPACEWIRE_IF_STATISTICS
813 // DPU_SPACEWIRE_IF_STATISTICS
794 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
814 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
795 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
815 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
796 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
797 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
798
818
799 //******************************************
819 //******************************************
800 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
820 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
801 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
821 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
802 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
822 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
803 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
823 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
804 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
824 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
805 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
825 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
806
826
807 //*********************************************
827 //*********************************************
808 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
828 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
809 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
829 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
810 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
830 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
811 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
831 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
812 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
832 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
813 }
833 }
814
834
815 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
835 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
816 {
836 {
817 unsigned int *statusRegisterPtr;
837 unsigned int *statusRegisterPtr;
818 unsigned char linkState;
838 unsigned char linkState;
819
839
820 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
840 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
821 linkState =
841 linkState =
822 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
842 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
823
843
824 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
844 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
825
845
826 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
827 }
847 }
828
848
829 void increase_unsigned_char_counter( unsigned char *counter )
849 void increase_unsigned_char_counter( unsigned char *counter )
830 {
850 {
831 // update the number of valid timecodes that have been received
851 // update the number of valid timecodes that have been received
832 if (*counter == UINT8_MAX)
852 if (*counter == UINT8_MAX)
833 {
853 {
834 *counter = 0;
854 *counter = 0;
835 }
855 }
836 else
856 else
837 {
857 {
838 *counter = *counter + 1;
858 *counter = *counter + 1;
839 }
859 }
840 }
860 }
841
861
842 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
862 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
843 {
863 {
844 /** This function checks the coherency between the incoming timecode and the last valid timecode.
864 /** This function checks the coherency between the incoming timecode and the last valid timecode.
845 *
865 *
846 * @param currentTimecodeCtr is the incoming timecode
866 * @param currentTimecodeCtr is the incoming timecode
847 *
867 *
848 * @return returned codes::
868 * @return returned codes::
849 * - LFR_DEFAULT
869 * - LFR_DEFAULT
850 * - LFR_SUCCESSFUL
870 * - LFR_SUCCESSFUL
851 *
871 *
852 */
872 */
853
873
854 static unsigned char firstTickout = 1;
874 static unsigned char firstTickout = 1;
855 unsigned char ret;
875 unsigned char ret;
856
876
857 ret = LFR_DEFAULT;
877 ret = LFR_DEFAULT;
858
878
859 if (firstTickout == 0)
879 if (firstTickout == 0)
860 {
880 {
861 if (currentTimecodeCtr == 0)
881 if (currentTimecodeCtr == 0)
862 {
882 {
863 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
883 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
864 {
884 {
865 ret = LFR_SUCCESSFUL;
885 ret = LFR_SUCCESSFUL;
866 }
886 }
867 else
887 else
868 {
888 {
869 ret = LFR_DEFAULT;
889 ret = LFR_DEFAULT;
870 }
890 }
871 }
891 }
872 else
892 else
873 {
893 {
874 if (currentTimecodeCtr == (previousTimecodeCtr +1))
894 if (currentTimecodeCtr == (previousTimecodeCtr +1))
875 {
895 {
876 ret = LFR_SUCCESSFUL;
896 ret = LFR_SUCCESSFUL;
877 }
897 }
878 else
898 else
879 {
899 {
880 ret = LFR_DEFAULT;
900 ret = LFR_DEFAULT;
881 }
901 }
882 }
902 }
883 }
903 }
884 else
904 else
885 {
905 {
886 firstTickout = 0;
906 firstTickout = 0;
887 ret = LFR_SUCCESSFUL;
907 ret = LFR_SUCCESSFUL;
888 }
908 }
889
909
890 return ret;
910 return ret;
891 }
911 }
892
912
893 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
913 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
894 {
914 {
895 unsigned int ret;
915 unsigned int ret;
896
916
897 ret = LFR_DEFAULT;
917 ret = LFR_DEFAULT;
898
918
899 if (timecode == internalTime)
919 if (timecode == internalTime)
900 {
920 {
901 ret = LFR_SUCCESSFUL;
921 ret = LFR_SUCCESSFUL;
902 }
922 }
903 else
923 else
904 {
924 {
905 ret = LFR_DEFAULT;
925 ret = LFR_DEFAULT;
906 }
926 }
907
927
908 return ret;
928 return ret;
909 }
929 }
910
930
911 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
931 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
912 {
932 {
913 // a tickout has been emitted, perform actions on the incoming timecode
933 // a tickout has been emitted, perform actions on the incoming timecode
914
934
915 unsigned char incomingTimecode;
935 unsigned char incomingTimecode;
916 unsigned char updateTime;
936 unsigned char updateTime;
917 unsigned char internalTime;
937 unsigned char internalTime;
918 rtems_status_code status;
938 rtems_status_code status;
919
939
920 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
940 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
921 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
941 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
922 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
942 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
923
943
924 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
944 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
925
945
926 // update the number of tickout that have been generated
946 // update the number of tickout that have been generated
927 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
947 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
928
948
929 //**************************
949 //**************************
930 // HK_LFR_TIMECODE_ERRONEOUS
950 // HK_LFR_TIMECODE_ERRONEOUS
931 // MISSING and INVALID are handled by the timecode_timer_routine service routine
951 // MISSING and INVALID are handled by the timecode_timer_routine service routine
932 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
952 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
933 {
953 {
934 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
954 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
935 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
955 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
936 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
956 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
937 }
957 }
938
958
939 //************************
959 //************************
940 // HK_LFR_TIME_TIMECODE_IT
960 // HK_LFR_TIME_TIMECODE_IT
941 // check the coherency between the SpaceWire timecode and the Internal Time
961 // check the coherency between the SpaceWire timecode and the Internal Time
942 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
962 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
943 {
963 {
944 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
964 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
945 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
965 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
946 }
966 }
947
967
948 //********************
968 //********************
949 // HK_LFR_TIMECODE_CTR
969 // HK_LFR_TIMECODE_CTR
950 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
970 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
951 if (oneTcLfrUpdateTimeReceived == 1)
971 if (oneTcLfrUpdateTimeReceived == 1)
952 {
972 {
953 if ( incomingTimecode != updateTime )
973 if ( incomingTimecode != updateTime )
954 {
974 {
955 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
975 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
956 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
976 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
957 }
977 }
958 }
978 }
959
979
960 // launch the timecode timer to detect missing or invalid timecodes
980 // launch the timecode timer to detect missing or invalid timecodes
961 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
981 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
962 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
982 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
963 if (status != RTEMS_SUCCESSFUL)
983 if (status != RTEMS_SUCCESSFUL)
964 {
984 {
965 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
985 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
966 }
986 }
967 }
987 }
968
988
969 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
989 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
970 {
990 {
971 static unsigned char initStep = 1;
991 static unsigned char initStep = 1;
972
992
973 unsigned char currentTimecodeCtr;
993 unsigned char currentTimecodeCtr;
974
994
975 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
995 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
976
996
977 if (initStep == 1)
997 if (initStep == 1)
978 {
998 {
979 if (currentTimecodeCtr == previousTimecodeCtr)
999 if (currentTimecodeCtr == previousTimecodeCtr)
980 {
1000 {
981 //************************
1001 //************************
982 // HK_LFR_TIMECODE_MISSING
1002 // HK_LFR_TIMECODE_MISSING
983 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1003 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
984 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1004 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
985 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1005 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
986 }
1006 }
987 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1007 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
988 {
1008 {
989 // the timecode value has changed and the value is valid, this is unexpected because
1009 // the timecode value has changed and the value is valid, this is unexpected because
990 // the timer should not have fired, the timecode_irq_handler should have been raised
1010 // the timer should not have fired, the timecode_irq_handler should have been raised
991 }
1011 }
992 else
1012 else
993 {
1013 {
994 //************************
1014 //************************
995 // HK_LFR_TIMECODE_INVALID
1015 // HK_LFR_TIMECODE_INVALID
996 // the timecode value has changed and the value is not valid, no tickout has been generated
1016 // the timecode value has changed and the value is not valid, no tickout has been generated
997 // this is why the timer has fired
1017 // this is why the timer has fired
998 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1018 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
999 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1019 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1000 }
1020 }
1001 }
1021 }
1002 else
1022 else
1003 {
1023 {
1004 initStep = 1;
1024 initStep = 1;
1005 //************************
1025 //************************
1006 // HK_LFR_TIMECODE_MISSING
1026 // HK_LFR_TIMECODE_MISSING
1007 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1027 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1008 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1028 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1009 }
1029 }
1010
1030
1011 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1031 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1012 }
1032 }
1013
1033
1014 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1034 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1015 {
1035 {
1016 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1036 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1017 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1037 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1018 header->reserved = DEFAULT_RESERVED;
1038 header->reserved = DEFAULT_RESERVED;
1019 header->userApplication = CCSDS_USER_APP;
1039 header->userApplication = CCSDS_USER_APP;
1020 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1040 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1021 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1041 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1022 header->packetLength[0] = INIT_CHAR;
1042 header->packetLength[0] = INIT_CHAR;
1023 header->packetLength[1] = INIT_CHAR;
1043 header->packetLength[1] = INIT_CHAR;
1024 // DATA FIELD HEADER
1044 // DATA FIELD HEADER
1025 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1045 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1026 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1046 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1027 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1047 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1028 header->destinationID = TM_DESTINATION_ID_GROUND;
1048 header->destinationID = TM_DESTINATION_ID_GROUND;
1029 header->time[BYTE_0] = INIT_CHAR;
1049 header->time[BYTE_0] = INIT_CHAR;
1030 header->time[BYTE_1] = INIT_CHAR;
1050 header->time[BYTE_1] = INIT_CHAR;
1031 header->time[BYTE_2] = INIT_CHAR;
1051 header->time[BYTE_2] = INIT_CHAR;
1032 header->time[BYTE_3] = INIT_CHAR;
1052 header->time[BYTE_3] = INIT_CHAR;
1033 header->time[BYTE_4] = INIT_CHAR;
1053 header->time[BYTE_4] = INIT_CHAR;
1034 header->time[BYTE_5] = INIT_CHAR;
1054 header->time[BYTE_5] = INIT_CHAR;
1035 // AUXILIARY DATA HEADER
1055 // AUXILIARY DATA HEADER
1036 header->sid = INIT_CHAR;
1056 header->sid = INIT_CHAR;
1037 header->pa_bia_status_info = DEFAULT_HKBIA;
1057 header->pa_bia_status_info = DEFAULT_HKBIA;
1038 header->blkNr[0] = INIT_CHAR;
1058 header->blkNr[0] = INIT_CHAR;
1039 header->blkNr[1] = INIT_CHAR;
1059 header->blkNr[1] = INIT_CHAR;
1040 }
1060 }
1041
1061
1042 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1062 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1043 {
1063 {
1044 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1045 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1046 header->reserved = DEFAULT_RESERVED;
1066 header->reserved = DEFAULT_RESERVED;
1047 header->userApplication = CCSDS_USER_APP;
1067 header->userApplication = CCSDS_USER_APP;
1048 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1049 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1050 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1051 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1052 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1072 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1053 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1073 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1054 // DATA FIELD HEADER
1074 // DATA FIELD HEADER
1055 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1056 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1057 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1058 header->destinationID = TM_DESTINATION_ID_GROUND;
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1059 header->time[BYTE_0] = INIT_CHAR;
1079 header->time[BYTE_0] = INIT_CHAR;
1060 header->time[BYTE_1] = INIT_CHAR;
1080 header->time[BYTE_1] = INIT_CHAR;
1061 header->time[BYTE_2] = INIT_CHAR;
1081 header->time[BYTE_2] = INIT_CHAR;
1062 header->time[BYTE_3] = INIT_CHAR;
1082 header->time[BYTE_3] = INIT_CHAR;
1063 header->time[BYTE_4] = INIT_CHAR;
1083 header->time[BYTE_4] = INIT_CHAR;
1064 header->time[BYTE_5] = INIT_CHAR;
1084 header->time[BYTE_5] = INIT_CHAR;
1065 // AUXILIARY DATA HEADER
1085 // AUXILIARY DATA HEADER
1066 header->sid = INIT_CHAR;
1086 header->sid = INIT_CHAR;
1067 header->pa_bia_status_info = DEFAULT_HKBIA;
1087 header->pa_bia_status_info = DEFAULT_HKBIA;
1068 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1088 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1069 header->pktNr = INIT_CHAR;
1089 header->pktNr = INIT_CHAR;
1070 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1090 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1071 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1091 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1072 }
1092 }
1073
1093
1074 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1094 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1075 {
1095 {
1076 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1096 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1077 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1097 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1078 header->reserved = DEFAULT_RESERVED;
1098 header->reserved = DEFAULT_RESERVED;
1079 header->userApplication = CCSDS_USER_APP;
1099 header->userApplication = CCSDS_USER_APP;
1080 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1100 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1081 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1101 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1082 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1102 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1083 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1103 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1084 header->packetLength[0] = INIT_CHAR;
1104 header->packetLength[0] = INIT_CHAR;
1085 header->packetLength[1] = INIT_CHAR;
1105 header->packetLength[1] = INIT_CHAR;
1086 // DATA FIELD HEADER
1106 // DATA FIELD HEADER
1087 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1107 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1088 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1108 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1089 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1109 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1090 header->destinationID = TM_DESTINATION_ID_GROUND;
1110 header->destinationID = TM_DESTINATION_ID_GROUND;
1091 header->time[BYTE_0] = INIT_CHAR;
1111 header->time[BYTE_0] = INIT_CHAR;
1092 header->time[BYTE_1] = INIT_CHAR;
1112 header->time[BYTE_1] = INIT_CHAR;
1093 header->time[BYTE_2] = INIT_CHAR;
1113 header->time[BYTE_2] = INIT_CHAR;
1094 header->time[BYTE_3] = INIT_CHAR;
1114 header->time[BYTE_3] = INIT_CHAR;
1095 header->time[BYTE_4] = INIT_CHAR;
1115 header->time[BYTE_4] = INIT_CHAR;
1096 header->time[BYTE_5] = INIT_CHAR;
1116 header->time[BYTE_5] = INIT_CHAR;
1097 // AUXILIARY DATA HEADER
1117 // AUXILIARY DATA HEADER
1098 header->sid = INIT_CHAR;
1118 header->sid = INIT_CHAR;
1099 header->pa_bia_status_info = INIT_CHAR;
1119 header->pa_bia_status_info = INIT_CHAR;
1100 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1120 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1101 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1121 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1102 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1122 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1103 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1123 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1104 }
1124 }
1105
1125
1106 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1126 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1107 Header_TM_LFR_SCIENCE_CWF_t *header )
1127 Header_TM_LFR_SCIENCE_CWF_t *header )
1108 {
1128 {
1109 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1129 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1110 *
1130 *
1111 * @param waveform points to the buffer containing the data that will be send.
1131 * @param waveform points to the buffer containing the data that will be send.
1112 * @param sid is the source identifier of the data that will be sent.
1132 * @param sid is the source identifier of the data that will be sent.
1113 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1133 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1114 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1134 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1115 * contain information to setup the transmission of the data packets.
1135 * contain information to setup the transmission of the data packets.
1116 *
1136 *
1117 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1137 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1118 *
1138 *
1119 */
1139 */
1120
1140
1121 unsigned int i;
1141 unsigned int i;
1122 int ret;
1142 int ret;
1123 unsigned int coarseTime;
1143 unsigned int coarseTime;
1124 unsigned int fineTime;
1144 unsigned int fineTime;
1125 rtems_status_code status;
1145 rtems_status_code status;
1126 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1146 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1127 int *dataPtr;
1147 int *dataPtr;
1128 unsigned char sid;
1148 unsigned char sid;
1129
1149
1130 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1150 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1131 spw_ioctl_send_CWF.options = 0;
1151 spw_ioctl_send_CWF.options = 0;
1132
1152
1133 ret = LFR_DEFAULT;
1153 ret = LFR_DEFAULT;
1134 sid = (unsigned char) ring_node_to_send->sid;
1154 sid = (unsigned char) ring_node_to_send->sid;
1135
1155
1136 coarseTime = ring_node_to_send->coarseTime;
1156 coarseTime = ring_node_to_send->coarseTime;
1137 fineTime = ring_node_to_send->fineTime;
1157 fineTime = ring_node_to_send->fineTime;
1138 dataPtr = (int*) ring_node_to_send->buffer_address;
1158 dataPtr = (int*) ring_node_to_send->buffer_address;
1139
1159
1140 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1160 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1141 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1161 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1142 header->pa_bia_status_info = pa_bia_status_info;
1162 header->pa_bia_status_info = pa_bia_status_info;
1143 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1163 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1144 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1164 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1145 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1165 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1146
1166
1147 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1167 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1148 {
1168 {
1149 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1169 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1150 spw_ioctl_send_CWF.hdr = (char*) header;
1170 spw_ioctl_send_CWF.hdr = (char*) header;
1151 // BUILD THE DATA
1171 // BUILD THE DATA
1152 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1172 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1153
1173
1154 // SET PACKET SEQUENCE CONTROL
1174 // SET PACKET SEQUENCE CONTROL
1155 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1175 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1156
1176
1157 // SET SID
1177 // SET SID
1158 header->sid = sid;
1178 header->sid = sid;
1159
1179
1160 // SET PACKET TIME
1180 // SET PACKET TIME
1161 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1181 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1162 //
1182 //
1163 header->time[0] = header->acquisitionTime[0];
1183 header->time[0] = header->acquisitionTime[0];
1164 header->time[1] = header->acquisitionTime[1];
1184 header->time[1] = header->acquisitionTime[1];
1165 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1185 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1166 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1186 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1167 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1187 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1168 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1188 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1169
1189
1170 // SET PACKET ID
1190 // SET PACKET ID
1171 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1191 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1172 {
1192 {
1173 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1193 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1174 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1194 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1175 }
1195 }
1176 else
1196 else
1177 {
1197 {
1178 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1198 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1179 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1199 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1180 }
1200 }
1181
1201
1182 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1202 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1183 if (status != RTEMS_SUCCESSFUL) {
1203 if (status != RTEMS_SUCCESSFUL) {
1184 ret = LFR_DEFAULT;
1204 ret = LFR_DEFAULT;
1185 }
1205 }
1186 }
1206 }
1187
1207
1188 return ret;
1208 return ret;
1189 }
1209 }
1190
1210
1191 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1211 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1192 Header_TM_LFR_SCIENCE_SWF_t *header )
1212 Header_TM_LFR_SCIENCE_SWF_t *header )
1193 {
1213 {
1194 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1214 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1195 *
1215 *
1196 * @param waveform points to the buffer containing the data that will be send.
1216 * @param waveform points to the buffer containing the data that will be send.
1197 * @param sid is the source identifier of the data that will be sent.
1217 * @param sid is the source identifier of the data that will be sent.
1198 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1218 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1199 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1219 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1200 * contain information to setup the transmission of the data packets.
1220 * contain information to setup the transmission of the data packets.
1201 *
1221 *
1202 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1222 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1203 *
1223 *
1204 */
1224 */
1205
1225
1206 unsigned int i;
1226 unsigned int i;
1207 int ret;
1227 int ret;
1208 unsigned int coarseTime;
1228 unsigned int coarseTime;
1209 unsigned int fineTime;
1229 unsigned int fineTime;
1210 rtems_status_code status;
1230 rtems_status_code status;
1211 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1231 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1212 int *dataPtr;
1232 int *dataPtr;
1213 unsigned char sid;
1233 unsigned char sid;
1214
1234
1215 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1235 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1216 spw_ioctl_send_SWF.options = 0;
1236 spw_ioctl_send_SWF.options = 0;
1217
1237
1218 ret = LFR_DEFAULT;
1238 ret = LFR_DEFAULT;
1219
1239
1220 coarseTime = ring_node_to_send->coarseTime;
1240 coarseTime = ring_node_to_send->coarseTime;
1221 fineTime = ring_node_to_send->fineTime;
1241 fineTime = ring_node_to_send->fineTime;
1222 dataPtr = (int*) ring_node_to_send->buffer_address;
1242 dataPtr = (int*) ring_node_to_send->buffer_address;
1223 sid = ring_node_to_send->sid;
1243 sid = ring_node_to_send->sid;
1224
1244
1225 header->pa_bia_status_info = pa_bia_status_info;
1245 header->pa_bia_status_info = pa_bia_status_info;
1226 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1246 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1227
1247
1228 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1248 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1229 {
1249 {
1230 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1250 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1231 spw_ioctl_send_SWF.hdr = (char*) header;
1251 spw_ioctl_send_SWF.hdr = (char*) header;
1232
1252
1233 // SET PACKET SEQUENCE CONTROL
1253 // SET PACKET SEQUENCE CONTROL
1234 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1254 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1235
1255
1236 // SET PACKET LENGTH AND BLKNR
1256 // SET PACKET LENGTH AND BLKNR
1237 if (i == (PKTCNT_SWF-1))
1257 if (i == (PKTCNT_SWF-1))
1238 {
1258 {
1239 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1259 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1240 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1260 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1241 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1261 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1242 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1262 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1243 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1263 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1244 }
1264 }
1245 else
1265 else
1246 {
1266 {
1247 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1267 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1248 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1268 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1249 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1269 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1250 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1270 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1251 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1271 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1252 }
1272 }
1253
1273
1254 // SET PACKET TIME
1274 // SET PACKET TIME
1255 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1275 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1256 //
1276 //
1257 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1277 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1258 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1278 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1259 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1279 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1260 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1280 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1261 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1281 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1262 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1282 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1263
1283
1264 // SET SID
1284 // SET SID
1265 header->sid = sid;
1285 header->sid = sid;
1266
1286
1267 // SET PKTNR
1287 // SET PKTNR
1268 header->pktNr = i+1; // PKT_NR
1288 header->pktNr = i+1; // PKT_NR
1269
1289
1270 // SEND PACKET
1290 // SEND PACKET
1271 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1291 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1272 if (status != RTEMS_SUCCESSFUL) {
1292 if (status != RTEMS_SUCCESSFUL) {
1273 ret = LFR_DEFAULT;
1293 ret = LFR_DEFAULT;
1274 }
1294 }
1275 }
1295 }
1276
1296
1277 return ret;
1297 return ret;
1278 }
1298 }
1279
1299
1280 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1300 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1281 Header_TM_LFR_SCIENCE_CWF_t *header )
1301 Header_TM_LFR_SCIENCE_CWF_t *header )
1282 {
1302 {
1283 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1303 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1284 *
1304 *
1285 * @param waveform points to the buffer containing the data that will be send.
1305 * @param waveform points to the buffer containing the data that will be send.
1286 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1306 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1287 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1307 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1288 * contain information to setup the transmission of the data packets.
1308 * contain information to setup the transmission of the data packets.
1289 *
1309 *
1290 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1310 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1291 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1311 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1292 *
1312 *
1293 */
1313 */
1294
1314
1295 unsigned int i;
1315 unsigned int i;
1296 int ret;
1316 int ret;
1297 unsigned int coarseTime;
1317 unsigned int coarseTime;
1298 unsigned int fineTime;
1318 unsigned int fineTime;
1299 rtems_status_code status;
1319 rtems_status_code status;
1300 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1320 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1301 char *dataPtr;
1321 char *dataPtr;
1302 unsigned char sid;
1322 unsigned char sid;
1303
1323
1304 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1324 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1305 spw_ioctl_send_CWF.options = 0;
1325 spw_ioctl_send_CWF.options = 0;
1306
1326
1307 ret = LFR_DEFAULT;
1327 ret = LFR_DEFAULT;
1308 sid = ring_node_to_send->sid;
1328 sid = ring_node_to_send->sid;
1309
1329
1310 coarseTime = ring_node_to_send->coarseTime;
1330 coarseTime = ring_node_to_send->coarseTime;
1311 fineTime = ring_node_to_send->fineTime;
1331 fineTime = ring_node_to_send->fineTime;
1312 dataPtr = (char*) ring_node_to_send->buffer_address;
1332 dataPtr = (char*) ring_node_to_send->buffer_address;
1313
1333
1314 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1334 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1315 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1335 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1316 header->pa_bia_status_info = pa_bia_status_info;
1336 header->pa_bia_status_info = pa_bia_status_info;
1317 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1337 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1318 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1338 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1319 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1339 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1320
1340
1321 //*********************
1341 //*********************
1322 // SEND CWF3_light DATA
1342 // SEND CWF3_light DATA
1323 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1343 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1324 {
1344 {
1325 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1345 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1326 spw_ioctl_send_CWF.hdr = (char*) header;
1346 spw_ioctl_send_CWF.hdr = (char*) header;
1327 // BUILD THE DATA
1347 // BUILD THE DATA
1328 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1348 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1329
1349
1330 // SET PACKET SEQUENCE COUNTER
1350 // SET PACKET SEQUENCE COUNTER
1331 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1351 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1332
1352
1333 // SET SID
1353 // SET SID
1334 header->sid = sid;
1354 header->sid = sid;
1335
1355
1336 // SET PACKET TIME
1356 // SET PACKET TIME
1337 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1357 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1338 //
1358 //
1339 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1359 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1340 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1360 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1341 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1361 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1342 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1362 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1343 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1363 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1344 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1364 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1345
1365
1346 // SET PACKET ID
1366 // SET PACKET ID
1347 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1367 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1348 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1368 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1349
1369
1350 // SEND PACKET
1370 // SEND PACKET
1351 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1371 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1352 if (status != RTEMS_SUCCESSFUL) {
1372 if (status != RTEMS_SUCCESSFUL) {
1353 ret = LFR_DEFAULT;
1373 ret = LFR_DEFAULT;
1354 }
1374 }
1355 }
1375 }
1356
1376
1357 return ret;
1377 return ret;
1358 }
1378 }
1359
1379
1360 void spw_send_asm_f0( ring_node *ring_node_to_send,
1380 void spw_send_asm_f0( ring_node *ring_node_to_send,
1361 Header_TM_LFR_SCIENCE_ASM_t *header )
1381 Header_TM_LFR_SCIENCE_ASM_t *header )
1362 {
1382 {
1363 unsigned int i;
1383 unsigned int i;
1364 unsigned int length = 0;
1384 unsigned int length = 0;
1365 rtems_status_code status;
1385 rtems_status_code status;
1366 unsigned int sid;
1386 unsigned int sid;
1367 float *spectral_matrix;
1387 float *spectral_matrix;
1368 int coarseTime;
1388 int coarseTime;
1369 int fineTime;
1389 int fineTime;
1370 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1390 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1371
1391
1372 sid = ring_node_to_send->sid;
1392 sid = ring_node_to_send->sid;
1373 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1393 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1374 coarseTime = ring_node_to_send->coarseTime;
1394 coarseTime = ring_node_to_send->coarseTime;
1375 fineTime = ring_node_to_send->fineTime;
1395 fineTime = ring_node_to_send->fineTime;
1376
1396
1377 header->pa_bia_status_info = pa_bia_status_info;
1397 header->pa_bia_status_info = pa_bia_status_info;
1378 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1398 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1379
1399
1380 for (i=0; i<PKTCNT_ASM; i++)
1400 for (i=0; i<PKTCNT_ASM; i++)
1381 {
1401 {
1382 if ((i==0) || (i==1))
1402 if ((i==0) || (i==1))
1383 {
1403 {
1384 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1404 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1385 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1405 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1386 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1406 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1387 ];
1407 ];
1388 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1408 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1389 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1409 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1390 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1410 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1391 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1411 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1392 }
1412 }
1393 else
1413 else
1394 {
1414 {
1395 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1415 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1396 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1416 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1397 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1417 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1398 ];
1418 ];
1399 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1419 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1400 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1420 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1401 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1421 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1402 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1422 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1403 }
1423 }
1404
1424
1405 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1425 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1406 spw_ioctl_send_ASM.hdr = (char *) header;
1426 spw_ioctl_send_ASM.hdr = (char *) header;
1407 spw_ioctl_send_ASM.options = 0;
1427 spw_ioctl_send_ASM.options = 0;
1408
1428
1409 // (2) BUILD THE HEADER
1429 // (2) BUILD THE HEADER
1410 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1430 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1411 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1431 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1412 header->packetLength[1] = (unsigned char) (length);
1432 header->packetLength[1] = (unsigned char) (length);
1413 header->sid = (unsigned char) sid; // SID
1433 header->sid = (unsigned char) sid; // SID
1414 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1434 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1415 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1435 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1416
1436
1417 // (3) SET PACKET TIME
1437 // (3) SET PACKET TIME
1418 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1438 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1419 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1439 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1420 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1440 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1421 header->time[BYTE_3] = (unsigned char) (coarseTime);
1441 header->time[BYTE_3] = (unsigned char) (coarseTime);
1422 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1442 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1423 header->time[BYTE_5] = (unsigned char) (fineTime);
1443 header->time[BYTE_5] = (unsigned char) (fineTime);
1424 //
1444 //
1425 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1445 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1426 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1446 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1427 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1447 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1428 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1448 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1429 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1449 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1430 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1450 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1431
1451
1432 // (4) SEND PACKET
1452 // (4) SEND PACKET
1433 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1453 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1434 if (status != RTEMS_SUCCESSFUL) {
1454 if (status != RTEMS_SUCCESSFUL) {
1435 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1455 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1436 }
1456 }
1437 }
1457 }
1438 }
1458 }
1439
1459
1440 void spw_send_asm_f1( ring_node *ring_node_to_send,
1460 void spw_send_asm_f1( ring_node *ring_node_to_send,
1441 Header_TM_LFR_SCIENCE_ASM_t *header )
1461 Header_TM_LFR_SCIENCE_ASM_t *header )
1442 {
1462 {
1443 unsigned int i;
1463 unsigned int i;
1444 unsigned int length = 0;
1464 unsigned int length = 0;
1445 rtems_status_code status;
1465 rtems_status_code status;
1446 unsigned int sid;
1466 unsigned int sid;
1447 float *spectral_matrix;
1467 float *spectral_matrix;
1448 int coarseTime;
1468 int coarseTime;
1449 int fineTime;
1469 int fineTime;
1450 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1470 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1451
1471
1452 sid = ring_node_to_send->sid;
1472 sid = ring_node_to_send->sid;
1453 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1473 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1454 coarseTime = ring_node_to_send->coarseTime;
1474 coarseTime = ring_node_to_send->coarseTime;
1455 fineTime = ring_node_to_send->fineTime;
1475 fineTime = ring_node_to_send->fineTime;
1456
1476
1457 header->pa_bia_status_info = pa_bia_status_info;
1477 header->pa_bia_status_info = pa_bia_status_info;
1458 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1478 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1459
1479
1460 for (i=0; i<PKTCNT_ASM; i++)
1480 for (i=0; i<PKTCNT_ASM; i++)
1461 {
1481 {
1462 if ((i==0) || (i==1))
1482 if ((i==0) || (i==1))
1463 {
1483 {
1464 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1484 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1465 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1485 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1466 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1486 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1467 ];
1487 ];
1468 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1488 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1469 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1489 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1470 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1490 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1471 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1491 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1472 }
1492 }
1473 else
1493 else
1474 {
1494 {
1475 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1495 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1476 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1496 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1477 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1497 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1478 ];
1498 ];
1479 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1499 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1480 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1500 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1481 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1501 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1482 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1502 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1483 }
1503 }
1484
1504
1485 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1505 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1486 spw_ioctl_send_ASM.hdr = (char *) header;
1506 spw_ioctl_send_ASM.hdr = (char *) header;
1487 spw_ioctl_send_ASM.options = 0;
1507 spw_ioctl_send_ASM.options = 0;
1488
1508
1489 // (2) BUILD THE HEADER
1509 // (2) BUILD THE HEADER
1490 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1510 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1491 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1511 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1492 header->packetLength[1] = (unsigned char) (length);
1512 header->packetLength[1] = (unsigned char) (length);
1493 header->sid = (unsigned char) sid; // SID
1513 header->sid = (unsigned char) sid; // SID
1494 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1514 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1495 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1515 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1496
1516
1497 // (3) SET PACKET TIME
1517 // (3) SET PACKET TIME
1498 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1518 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1499 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1519 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1500 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1520 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1501 header->time[BYTE_3] = (unsigned char) (coarseTime);
1521 header->time[BYTE_3] = (unsigned char) (coarseTime);
1502 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1522 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1503 header->time[BYTE_5] = (unsigned char) (fineTime);
1523 header->time[BYTE_5] = (unsigned char) (fineTime);
1504 //
1524 //
1505 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1525 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1506 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1526 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1507 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1527 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1508 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1528 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1509 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1529 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1510 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1530 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1511
1531
1512 // (4) SEND PACKET
1532 // (4) SEND PACKET
1513 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1533 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1514 if (status != RTEMS_SUCCESSFUL) {
1534 if (status != RTEMS_SUCCESSFUL) {
1515 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1535 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1516 }
1536 }
1517 }
1537 }
1518 }
1538 }
1519
1539
1520 void spw_send_asm_f2( ring_node *ring_node_to_send,
1540 void spw_send_asm_f2( ring_node *ring_node_to_send,
1521 Header_TM_LFR_SCIENCE_ASM_t *header )
1541 Header_TM_LFR_SCIENCE_ASM_t *header )
1522 {
1542 {
1523 unsigned int i;
1543 unsigned int i;
1524 unsigned int length = 0;
1544 unsigned int length = 0;
1525 rtems_status_code status;
1545 rtems_status_code status;
1526 unsigned int sid;
1546 unsigned int sid;
1527 float *spectral_matrix;
1547 float *spectral_matrix;
1528 int coarseTime;
1548 int coarseTime;
1529 int fineTime;
1549 int fineTime;
1530 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1550 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1531
1551
1532 sid = ring_node_to_send->sid;
1552 sid = ring_node_to_send->sid;
1533 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1553 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1534 coarseTime = ring_node_to_send->coarseTime;
1554 coarseTime = ring_node_to_send->coarseTime;
1535 fineTime = ring_node_to_send->fineTime;
1555 fineTime = ring_node_to_send->fineTime;
1536
1556
1537 header->pa_bia_status_info = pa_bia_status_info;
1557 header->pa_bia_status_info = pa_bia_status_info;
1538 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1558 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1539
1559
1540 for (i=0; i<PKTCNT_ASM; i++)
1560 for (i=0; i<PKTCNT_ASM; i++)
1541 {
1561 {
1542
1562
1543 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1563 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1544 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1564 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1545 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1565 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1546 ];
1566 ];
1547 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1567 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1548 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1568 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1549 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1569 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1550 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1570 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1551
1571
1552 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1572 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1553 spw_ioctl_send_ASM.hdr = (char *) header;
1573 spw_ioctl_send_ASM.hdr = (char *) header;
1554 spw_ioctl_send_ASM.options = 0;
1574 spw_ioctl_send_ASM.options = 0;
1555
1575
1556 // (2) BUILD THE HEADER
1576 // (2) BUILD THE HEADER
1557 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1577 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1558 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1578 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1559 header->packetLength[1] = (unsigned char) (length);
1579 header->packetLength[1] = (unsigned char) (length);
1560 header->sid = (unsigned char) sid; // SID
1580 header->sid = (unsigned char) sid; // SID
1561 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1581 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1562 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1582 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1563
1583
1564 // (3) SET PACKET TIME
1584 // (3) SET PACKET TIME
1565 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1585 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1566 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1586 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1567 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1587 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1568 header->time[BYTE_3] = (unsigned char) (coarseTime);
1588 header->time[BYTE_3] = (unsigned char) (coarseTime);
1569 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1589 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1570 header->time[BYTE_5] = (unsigned char) (fineTime);
1590 header->time[BYTE_5] = (unsigned char) (fineTime);
1571 //
1591 //
1572 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1592 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1573 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1593 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1574 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1594 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1575 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1595 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1576 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1596 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1577 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1597 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1578
1598
1579 // (4) SEND PACKET
1599 // (4) SEND PACKET
1580 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1600 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1581 if (status != RTEMS_SUCCESSFUL) {
1601 if (status != RTEMS_SUCCESSFUL) {
1582 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1602 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1583 }
1603 }
1584 }
1604 }
1585 }
1605 }
1586
1606
1587 void spw_send_k_dump( ring_node *ring_node_to_send )
1607 void spw_send_k_dump( ring_node *ring_node_to_send )
1588 {
1608 {
1589 rtems_status_code status;
1609 rtems_status_code status;
1590 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1610 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1591 unsigned int packetLength;
1611 unsigned int packetLength;
1592 unsigned int size;
1612 unsigned int size;
1593
1613
1594 PRINTF("spw_send_k_dump\n")
1614 PRINTF("spw_send_k_dump\n")
1595
1615
1596 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1616 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1597
1617
1598 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1618 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1599
1619
1600 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1620 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1601
1621
1602 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1622 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1603
1623
1604 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1624 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1605
1625
1606 if (status == -1){
1626 if (status == -1){
1607 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1627 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1608 }
1628 }
1609
1629
1610 ring_node_to_send->status = INIT_CHAR;
1630 ring_node_to_send->status = INIT_CHAR;
1611 }
1631 }
@@ -1,116 +1,118
1 /*
1 /*
2 * CPU Usage Reporter
2 * CPU Usage Reporter
3 *
3 *
4 * COPYRIGHT (c) 1989-2009
4 * COPYRIGHT (c) 1989-2009
5 * On-Line Applications Research Corporation (OAR).
5 * On-Line Applications Research Corporation (OAR).
6 *
6 *
7 * The license and distribution terms for this file may be
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.com/license/LICENSE.
9 * http://www.rtems.com/license/LICENSE.
10 *
10 *
11 * $Id$
11 * $Id$
12 */
12 */
13
13
14 #include "lfr_cpu_usage_report.h"
14 #include "lfr_cpu_usage_report.h"
15
15
16 unsigned char lfr_rtems_cpu_usage_report( void )
16 unsigned char lfr_rtems_cpu_usage_report( void )
17 {
17 {
18 uint32_t api_index;
18 uint32_t api_index;
19 Thread_Control *the_thread;
19 Thread_Control *the_thread;
20 Objects_Information *information;
20 Objects_Information *information;
21 uint32_t ival;
21 uint32_t ival;
22 uint32_t fval;
22 uint32_t fval;
23 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
23 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
24 Timestamp_Control uptime;
24 Timestamp_Control uptime;
25 Timestamp_Control total;
25 Timestamp_Control total;
26 Timestamp_Control ran;
26 Timestamp_Control ran;
27 #else
27 #else
28 uint32_t total_units = 0;
28 uint32_t total_units = 0;
29 #endif
29 #endif
30
30
31 unsigned char cpu_load;
31 unsigned char cpu_load;
32
33 ival = 0;
32 cpu_load = 0;
34 cpu_load = 0;
33
35
34 /*
36 /*
35 * When not using nanosecond CPU usage resolution, we have to count
37 * When not using nanosecond CPU usage resolution, we have to count
36 * the number of "ticks" we gave credit for to give the user a rough
38 * the number of "ticks" we gave credit for to give the user a rough
37 * guideline as to what each number means proportionally.
39 * guideline as to what each number means proportionally.
38 */
40 */
39 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
41 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
40 _TOD_Get_uptime( &uptime );
42 _TOD_Get_uptime( &uptime );
41 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
43 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
42 #else
44 #else
43 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
45 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
44 if ( !_Objects_Information_table[ api_index ] ) { }
46 if ( !_Objects_Information_table[ api_index ] ) { }
45 else
47 else
46 {
48 {
47 information = _Objects_Information_table[ api_index ][ 1 ];
49 information = _Objects_Information_table[ api_index ][ 1 ];
48 if ( information != NULL )
50 if ( information != NULL )
49 {
51 {
50 for ( i=1 ; i <= information->maximum ; i++ ) {
52 for ( i=1 ; i <= information->maximum ; i++ ) {
51 the_thread = (Thread_Control *)information->local_table[ i ];
53 the_thread = (Thread_Control *)information->local_table[ i ];
52
54
53 if ( the_thread != NULL ) {
55 if ( the_thread != NULL ) {
54 total_units += the_thread->cpu_time_used; }
56 total_units += the_thread->cpu_time_used; }
55 }
57 }
56 }
58 }
57 }
59 }
58 }
60 }
59 #endif
61 #endif
60
62
61 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
63 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
62 {
64 {
63 if ( !_Objects_Information_table[ api_index ] ) { }
65 if ( !_Objects_Information_table[ api_index ] ) { }
64 else
66 else
65 {
67 {
66 information = _Objects_Information_table[ api_index ][ 1 ];
68 information = _Objects_Information_table[ api_index ][ 1 ];
67 if ( information != NULL )
69 if ( information != NULL )
68 {
70 {
69 the_thread = (Thread_Control *)information->local_table[ 1 ];
71 the_thread = (Thread_Control *)information->local_table[ 1 ];
70
72
71 if ( the_thread == NULL ) { }
73 if ( the_thread == NULL ) { }
72 else
74 else
73 {
75 {
74 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
76 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
75 /*
77 /*
76 * If this is the currently executing thread, account for time
78 * If this is the currently executing thread, account for time
77 * since the last context switch.
79 * since the last context switch.
78 */
80 */
79 ran = the_thread->cpu_time_used;
81 ran = the_thread->cpu_time_used;
80 if ( _Thread_Executing->Object.id == the_thread->Object.id )
82 if ( _Thread_Executing->Object.id == the_thread->Object.id )
81 {
83 {
82 Timestamp_Control used;
84 Timestamp_Control used;
83 _Timestamp_Subtract(
85 _Timestamp_Subtract(
84 &_Thread_Time_of_last_context_switch, &uptime, &used
86 &_Thread_Time_of_last_context_switch, &uptime, &used
85 );
87 );
86 _Timestamp_Add_to( &ran, &used );
88 _Timestamp_Add_to( &ran, &used );
87 }
89 }
88 _Timestamp_Divide( &ran, &total, &ival, &fval );
90 _Timestamp_Divide( &ran, &total, &ival, &fval );
89
91
90 #else
92 #else
91 if (total_units != 0)
93 if (total_units != 0)
92 {
94 {
93 uint64_t ival_64;
95 uint64_t ival_64;
94
96
95 ival_64 = the_thread->cpu_time_used;
97 ival_64 = the_thread->cpu_time_used;
96 ival_64 *= CONST_100000;
98 ival_64 *= CONST_100000;
97 ival = ival_64 / total_units;
99 ival = ival_64 / total_units;
98 }
100 }
99 else
101 else
100 {
102 {
101 ival = 0;
103 ival = 0;
102 }
104 }
103
105
104 fval = ival % CONST_1000;
106 fval = ival % CONST_1000;
105 ival /= CONST_1000;
107 ival /= CONST_1000;
106 #endif
108 #endif
107 }
109 }
108 }
110 }
109 }
111 }
110 }
112 }
111 cpu_load = (unsigned char) (CONST_100 - ival);
113 cpu_load = (unsigned char) (CONST_100 - ival);
112
114
113 return cpu_load;
115 return cpu_load;
114 }
116 }
115
117
116
118
@@ -1,414 +1,424
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf0_prc0.h"
10 #include "avf0_prc0.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14
14
15 //***
15 //***
16 // F0
16 // F0
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19
19
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
22
22
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
26
26
27 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
27 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
28 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
28 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
29
29
30 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
30 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
31 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
31 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
32
32
33 //************
33 //************
34 // RTEMS TASKS
34 // RTEMS TASKS
35
35
36 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
37 {
37 {
38 int i;
38 int i;
39
39
40 rtems_event_set event_out;
40 rtems_event_set event_out;
41 rtems_status_code status;
41 rtems_status_code status;
42 rtems_id queue_id_prc0;
42 rtems_id queue_id_prc0;
43 asm_msg msgForPRC;
43 asm_msg msgForPRC;
44 ring_node *nodeForAveraging;
44 ring_node *nodeForAveraging;
45 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
46 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
47 ring_node_asm *current_ring_node_asm_norm_f0;
47 ring_node_asm *current_ring_node_asm_norm_f0;
48
48
49 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp1;
50 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_bp2;
51 unsigned int nb_norm_asm;
51 unsigned int nb_norm_asm;
52 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp1;
53 unsigned int nb_sbm_bp2;
53 unsigned int nb_sbm_bp2;
54
54
55 nb_norm_bp1 = 0;
55 nb_norm_bp1 = 0;
56 nb_norm_bp2 = 0;
56 nb_norm_bp2 = 0;
57 nb_norm_asm = 0;
57 nb_norm_asm = 0;
58 nb_sbm_bp1 = 0;
58 nb_sbm_bp1 = 0;
59 nb_sbm_bp2 = 0;
59 nb_sbm_bp2 = 0;
60 event_out = EVENT_SETS_NONE_PENDING;
61 queue_id_prc0 = RTEMS_ID_NONE;
60
62
61 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
62 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
63 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
64 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
65 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
66
68
67 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
68
70
69 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 status = get_message_queue_id_prc0( &queue_id_prc0 );
70 if (status != RTEMS_SUCCESSFUL)
72 if (status != RTEMS_SUCCESSFUL)
71 {
73 {
72 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
73 }
75 }
74
76
75 while(1){
77 while(1){
76 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
77
79
78 //****************************************
80 //****************************************
79 // initialize the mesage for the MATR task
81 // initialize the mesage for the MATR task
80 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.norm = current_ring_node_asm_norm_f0;
81 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
82 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
83 //
85 //
84 //****************************************
86 //****************************************
85
87
86 nodeForAveraging = getRingNodeForAveraging( 0 );
88 nodeForAveraging = getRingNodeForAveraging( 0 );
87
89
88 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
89 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
90 {
92 {
91 nodeForAveraging = nodeForAveraging->previous;
93 nodeForAveraging = nodeForAveraging->previous;
92 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
94 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
93 }
95 }
94
96
95 // compute the average and store it in the averaged_sm_f1 buffer
97 // compute the average and store it in the averaged_sm_f1 buffer
96 SM_average( current_ring_node_asm_norm_f0->matrix,
98 SM_average( current_ring_node_asm_norm_f0->matrix,
97 current_ring_node_asm_burst_sbm_f0->matrix,
99 current_ring_node_asm_burst_sbm_f0->matrix,
98 ring_node_tab,
100 ring_node_tab,
99 nb_norm_bp1, nb_sbm_bp1,
101 nb_norm_bp1, nb_sbm_bp1,
100 &msgForPRC, 0 ); // 0 => frequency channel 0
102 &msgForPRC, 0 ); // 0 => frequency channel 0
101
103
102 // update nb_average
104 // update nb_average
103 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
104 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
106 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
108
110
109 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
110 {
112 {
111 nb_sbm_bp1 = 0;
113 nb_sbm_bp1 = 0;
112 // set another ring for the ASM storage
114 // set another ring for the ASM storage
113 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
114 if ( lfrCurrentMode == LFR_MODE_BURST )
116 if ( lfrCurrentMode == LFR_MODE_BURST )
115 {
117 {
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
117 }
119 }
118 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
119 {
121 {
120 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
121 }
123 }
122 }
124 }
123
125
124 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
125 {
127 {
126 nb_sbm_bp2 = 0;
128 nb_sbm_bp2 = 0;
127 if ( lfrCurrentMode == LFR_MODE_BURST )
129 if ( lfrCurrentMode == LFR_MODE_BURST )
128 {
130 {
129 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
130 }
132 }
131 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
132 {
134 {
133 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
134 }
136 }
135 }
137 }
136
138
137 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
138 {
140 {
139 nb_norm_bp1 = 0;
141 nb_norm_bp1 = 0;
140 // set another ring for the ASM storage
142 // set another ring for the ASM storage
141 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
142 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
143 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
144 {
146 {
145 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
146 }
148 }
147 }
149 }
148
150
149 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
150 {
152 {
151 nb_norm_bp2 = 0;
153 nb_norm_bp2 = 0;
152 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
153 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
154 {
156 {
155 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
156 }
158 }
157 }
159 }
158
160
159 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
160 {
162 {
161 nb_norm_asm = 0;
163 nb_norm_asm = 0;
162 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
163 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
164 {
166 {
165 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
166 }
168 }
167 }
169 }
168
170
169 //*************************
171 //*************************
170 // send the message to PRC
172 // send the message to PRC
171 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
172 {
174 {
173 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
174 }
176 }
175
177
176 if (status != RTEMS_SUCCESSFUL) {
178 if (status != RTEMS_SUCCESSFUL) {
177 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
178 }
180 }
179 }
181 }
180 }
182 }
181
183
182 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
183 {
185 {
184 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
185 size_t size; // size of the incoming TC packet
187 size_t size; // size of the incoming TC packet
186 asm_msg *incomingMsg;
188 asm_msg *incomingMsg;
187 //
189 //
188 unsigned char sid;
190 unsigned char sid;
189 rtems_status_code status;
191 rtems_status_code status;
190 rtems_id queue_id;
192 rtems_id queue_id;
191 rtems_id queue_id_q_p0;
193 rtems_id queue_id_q_p0;
192 bp_packet_with_spare packet_norm_bp1;
194 bp_packet_with_spare packet_norm_bp1;
193 bp_packet packet_norm_bp2;
195 bp_packet packet_norm_bp2;
194 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp1;
195 bp_packet packet_sbm_bp2;
197 bp_packet packet_sbm_bp2;
196 ring_node *current_ring_node_to_send_asm_f0;
198 ring_node *current_ring_node_to_send_asm_f0;
197 float nbSMInASMNORM;
199 float nbSMInASMNORM;
198 float nbSMInASMSBM;
200 float nbSMInASMSBM;
199
201
202 size = 0;
203 queue_id = RTEMS_ID_NONE;
204 queue_id_q_p0 = RTEMS_ID_NONE;
205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
209
200 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
201 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
211 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
202 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
212 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
203
213
204 //*************
214 //*************
205 // NORM headers
215 // NORM headers
206 BP_init_header_with_spare( &packet_norm_bp1,
216 BP_init_header_with_spare( &packet_norm_bp1,
207 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
208 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
209 BP_init_header( &packet_norm_bp2,
219 BP_init_header( &packet_norm_bp2,
210 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
211 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
212
222
213 //****************************
223 //****************************
214 // BURST SBM1 and SBM2 headers
224 // BURST SBM1 and SBM2 headers
215 if ( lfrRequestedMode == LFR_MODE_BURST )
225 if ( lfrRequestedMode == LFR_MODE_BURST )
216 {
226 {
217 BP_init_header( &packet_sbm_bp1,
227 BP_init_header( &packet_sbm_bp1,
218 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
219 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
220 BP_init_header( &packet_sbm_bp2,
230 BP_init_header( &packet_sbm_bp2,
221 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
222 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
223 }
233 }
224 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
234 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
225 {
235 {
226 BP_init_header( &packet_sbm_bp1,
236 BP_init_header( &packet_sbm_bp1,
227 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 BP_init_header( &packet_sbm_bp2,
239 BP_init_header( &packet_sbm_bp2,
230 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 }
242 }
233 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
243 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
234 {
244 {
235 BP_init_header( &packet_sbm_bp1,
245 BP_init_header( &packet_sbm_bp1,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
246 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
247 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 BP_init_header( &packet_sbm_bp2,
248 BP_init_header( &packet_sbm_bp2,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
249 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
250 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 }
251 }
242 else
252 else
243 {
253 {
244 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
254 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
245 }
255 }
246
256
247 status = get_message_queue_id_send( &queue_id );
257 status = get_message_queue_id_send( &queue_id );
248 if (status != RTEMS_SUCCESSFUL)
258 if (status != RTEMS_SUCCESSFUL)
249 {
259 {
250 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
260 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
251 }
261 }
252 status = get_message_queue_id_prc0( &queue_id_q_p0);
262 status = get_message_queue_id_prc0( &queue_id_q_p0);
253 if (status != RTEMS_SUCCESSFUL)
263 if (status != RTEMS_SUCCESSFUL)
254 {
264 {
255 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
265 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
256 }
266 }
257
267
258 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
268 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
259
269
260 while(1){
270 while(1){
261 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
271 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
262 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
272 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
263
273
264 incomingMsg = (asm_msg*) incomingData;
274 incomingMsg = (asm_msg*) incomingData;
265
275
266 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
276 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
267 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
277 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
268
278
269 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
279 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
270 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
280 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
271
281
272 //****************
282 //****************
273 //****************
283 //****************
274 // BURST SBM1 SBM2
284 // BURST SBM1 SBM2
275 //****************
285 //****************
276 //****************
286 //****************
277 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
287 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
278 {
288 {
279 sid = getSID( incomingMsg->event );
289 sid = getSID( incomingMsg->event );
280 // 1) compress the matrix for Basic Parameters calculation
290 // 1) compress the matrix for Basic Parameters calculation
281 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
291 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
282 nbSMInASMSBM,
292 nbSMInASMSBM,
283 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
293 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
284 ASM_F0_INDICE_START, CHANNELF0);
294 ASM_F0_INDICE_START, CHANNELF0);
285 // 2) compute the BP1 set
295 // 2) compute the BP1 set
286 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
296 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
287 // 3) send the BP1 set
297 // 3) send the BP1 set
288 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
289 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
300 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
291 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
292 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
302 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
293 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
303 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
294 sid);
304 sid);
295 // 4) compute the BP2 set if needed
305 // 4) compute the BP2 set if needed
296 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
306 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
297 {
307 {
298 // 1) compute the BP2 set
308 // 1) compute the BP2 set
299 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
309 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
300 // 2) send the BP2 set
310 // 2) send the BP2 set
301 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
302 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
312 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
313 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
304 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
305 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
315 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
306 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
316 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
307 sid);
317 sid);
308 }
318 }
309 }
319 }
310
320
311 //*****
321 //*****
312 //*****
322 //*****
313 // NORM
323 // NORM
314 //*****
324 //*****
315 //*****
325 //*****
316 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
326 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
317 {
327 {
318 // 1) compress the matrix for Basic Parameters calculation
328 // 1) compress the matrix for Basic Parameters calculation
319 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
329 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
320 nbSMInASMNORM,
330 nbSMInASMNORM,
321 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
331 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
322 ASM_F0_INDICE_START, CHANNELF0 );
332 ASM_F0_INDICE_START, CHANNELF0 );
323 // 2) compute the BP1 set
333 // 2) compute the BP1 set
324 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
334 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
325 // 3) send the BP1 set
335 // 3) send the BP1 set
326 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
327 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
337 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
338 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
329 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
339 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
330 BP_send( (char *) &packet_norm_bp1, queue_id,
340 BP_send( (char *) &packet_norm_bp1, queue_id,
331 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
341 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
332 SID_NORM_BP1_F0 );
342 SID_NORM_BP1_F0 );
333 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
343 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
334 {
344 {
335 // 1) compute the BP2 set using the same ASM as the one used for BP1
345 // 1) compute the BP2 set using the same ASM as the one used for BP1
336 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
346 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
337 // 2) send the BP2 set
347 // 2) send the BP2 set
338 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
339 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
349 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
350 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
341 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
351 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
342 BP_send( (char *) &packet_norm_bp2, queue_id,
352 BP_send( (char *) &packet_norm_bp2, queue_id,
343 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
353 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
344 SID_NORM_BP2_F0);
354 SID_NORM_BP2_F0);
345 }
355 }
346 }
356 }
347
357
348 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
358 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
349 {
359 {
350 // 1) reorganize the ASM and divide
360 // 1) reorganize the ASM and divide
351 ASM_reorganize_and_divide( asm_f0_patched_norm,
361 ASM_reorganize_and_divide( asm_f0_patched_norm,
352 (float*) current_ring_node_to_send_asm_f0->buffer_address,
362 (float*) current_ring_node_to_send_asm_f0->buffer_address,
353 nbSMInASMNORM );
363 nbSMInASMNORM );
354 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
364 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
355 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
365 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
356 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
366 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
357
367
358 // 3) send the spectral matrix packets
368 // 3) send the spectral matrix packets
359 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
369 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
360
370
361 // change asm ring node
371 // change asm ring node
362 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
372 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
363 }
373 }
364
374
365 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
375 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
366
376
367 }
377 }
368 }
378 }
369
379
370 //**********
380 //**********
371 // FUNCTIONS
381 // FUNCTIONS
372
382
373 void reset_nb_sm_f0( unsigned char lfrMode )
383 void reset_nb_sm_f0( unsigned char lfrMode )
374 {
384 {
375 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
385 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
376 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
386 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
377 nb_sm_before_f0.norm_asm =
387 nb_sm_before_f0.norm_asm =
378 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
388 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
379 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
389 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
380 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
390 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
381 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
391 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
382 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
392 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
383 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
393 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
384 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
394 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
385
395
386 if (lfrMode == LFR_MODE_SBM1)
396 if (lfrMode == LFR_MODE_SBM1)
387 {
397 {
388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
398 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
399 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
390 }
400 }
391 else if (lfrMode == LFR_MODE_SBM2)
401 else if (lfrMode == LFR_MODE_SBM2)
392 {
402 {
393 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
403 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
394 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
404 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
395 }
405 }
396 else if (lfrMode == LFR_MODE_BURST)
406 else if (lfrMode == LFR_MODE_BURST)
397 {
407 {
398 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
408 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
399 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
409 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
400 }
410 }
401 else
411 else
402 {
412 {
403 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
413 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
404 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
414 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
405 }
415 }
406 }
416 }
407
417
408 void init_k_coefficients_prc0( void )
418 void init_k_coefficients_prc0( void )
409 {
419 {
410 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
420 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
411
421
412 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
422 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
413 }
423 }
414
424
@@ -1,398 +1,409
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf1_prc1.h"
10 #include "avf1_prc1.h"
11
11
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13
13
14 extern ring_node sm_ring_f1[ ];
14 extern ring_node sm_ring_f1[ ];
15
15
16 //***
16 //***
17 // F1
17 // F1
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
20
20
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
23
23
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
27
27
28 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
28 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
29 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
29 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
30
30
31 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
31 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
32 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
32 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
33
33
34 //************
34 //************
35 // RTEMS TASKS
35 // RTEMS TASKS
36
36
37 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
37 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
38 {
38 {
39 int i;
39 int i;
40
40
41 rtems_event_set event_out;
41 rtems_event_set event_out;
42 rtems_status_code status;
42 rtems_status_code status;
43 rtems_id queue_id_prc1;
43 rtems_id queue_id_prc1;
44 asm_msg msgForPRC;
44 asm_msg msgForPRC;
45 ring_node *nodeForAveraging;
45 ring_node *nodeForAveraging;
46 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
46 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
47 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
47 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
48 ring_node_asm *current_ring_node_asm_norm_f1;
48 ring_node_asm *current_ring_node_asm_norm_f1;
49
49
50 unsigned int nb_norm_bp1;
50 unsigned int nb_norm_bp1;
51 unsigned int nb_norm_bp2;
51 unsigned int nb_norm_bp2;
52 unsigned int nb_norm_asm;
52 unsigned int nb_norm_asm;
53 unsigned int nb_sbm_bp1;
53 unsigned int nb_sbm_bp1;
54 unsigned int nb_sbm_bp2;
54 unsigned int nb_sbm_bp2;
55
55
56 event_out = EVENT_SETS_NONE_PENDING;
57 queue_id_prc1 = RTEMS_ID_NONE;
58
56 nb_norm_bp1 = 0;
59 nb_norm_bp1 = 0;
57 nb_norm_bp2 = 0;
60 nb_norm_bp2 = 0;
58 nb_norm_asm = 0;
61 nb_norm_asm = 0;
59 nb_sbm_bp1 = 0;
62 nb_sbm_bp1 = 0;
60 nb_sbm_bp2 = 0;
63 nb_sbm_bp2 = 0;
61
64
62 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
65 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
66 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
67 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
65 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
68 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
66 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
69 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
67
70
68 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
71 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69
72
70 status = get_message_queue_id_prc1( &queue_id_prc1 );
73 status = get_message_queue_id_prc1( &queue_id_prc1 );
71 if (status != RTEMS_SUCCESSFUL)
74 if (status != RTEMS_SUCCESSFUL)
72 {
75 {
73 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
76 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
74 }
77 }
75
78
76 while(1){
79 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
80 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
81
79 //****************************************
82 //****************************************
80 // initialize the mesage for the MATR task
83 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f1;
84 msgForPRC.norm = current_ring_node_asm_norm_f1;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
85 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
86 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
84 //
87 //
85 //****************************************
88 //****************************************
86
89
87 nodeForAveraging = getRingNodeForAveraging( 1 );
90 nodeForAveraging = getRingNodeForAveraging( 1 );
88
91
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
92 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
93 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 {
94 {
92 nodeForAveraging = nodeForAveraging->previous;
95 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
96 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
94 }
97 }
95
98
96 // compute the average and store it in the averaged_sm_f1 buffer
99 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f1->matrix,
100 SM_average( current_ring_node_asm_norm_f1->matrix,
98 current_ring_node_asm_burst_sbm_f1->matrix,
101 current_ring_node_asm_burst_sbm_f1->matrix,
99 ring_node_tab,
102 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
103 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC, 1 ); // 1 => frequency channel 1
104 &msgForPRC, 1 ); // 1 => frequency channel 1
102
105
103 // update nb_average
106 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
108 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
109 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
110 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
111 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109
112
110 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
113 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
111 {
114 {
112 nb_sbm_bp1 = 0;
115 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
116 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
117 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
118 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
119 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
120 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
118 }
121 }
119 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
122 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
120 {
123 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
124 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
122 }
125 }
123 }
126 }
124
127
125 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
128 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
126 {
129 {
127 nb_sbm_bp2 = 0;
130 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
131 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
132 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
133 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
131 }
134 }
132 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
135 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
133 {
136 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
137 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
135 }
138 }
136 }
139 }
137
140
138 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
141 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
139 {
142 {
140 nb_norm_bp1 = 0;
143 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
144 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
145 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
146 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
147 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
148 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
149 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
147 }
150 }
148 }
151 }
149
152
150 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
153 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
151 {
154 {
152 nb_norm_bp2 = 0;
155 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
156 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
157 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
158 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
159 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
157 }
160 }
158 }
161 }
159
162
160 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
163 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
161 {
164 {
162 nb_norm_asm = 0;
165 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
166 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
167 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
168 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
169 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
167 }
170 }
168 }
171 }
169
172
170 //*************************
173 //*************************
171 // send the message to PRC
174 // send the message to PRC
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
175 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 {
176 {
174 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
177 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
175 }
178 }
176
179
177 if (status != RTEMS_SUCCESSFUL) {
180 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
181 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
179 }
182 }
180 }
183 }
181 }
184 }
182
185
183 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
186 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
184 {
187 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
188 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
189 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
190 asm_msg *incomingMsg;
188 //
191 //
189 unsigned char sid;
192 unsigned char sid;
190 rtems_status_code status;
193 rtems_status_code status;
191 rtems_id queue_id_send;
194 rtems_id queue_id_send;
192 rtems_id queue_id_q_p1;
195 rtems_id queue_id_q_p1;
193 bp_packet_with_spare packet_norm_bp1;
196 bp_packet_with_spare packet_norm_bp1;
194 bp_packet packet_norm_bp2;
197 bp_packet packet_norm_bp2;
195 bp_packet packet_sbm_bp1;
198 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp2;
199 bp_packet packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f1;
200 ring_node *current_ring_node_to_send_asm_f1;
198 float nbSMInASMNORM;
201 float nbSMInASMNORM;
199 float nbSMInASMSBM;
202 float nbSMInASMSBM;
200
203
204 size = 0;
205 queue_id_send = RTEMS_ID_NONE;
206 queue_id_q_p1 = RTEMS_ID_NONE;
207 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
208 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
209 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
210 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
211
201 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
212 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
202 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
213 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
203 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
214 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
204
215
205 //*************
216 //*************
206 // NORM headers
217 // NORM headers
207 BP_init_header_with_spare( &packet_norm_bp1,
218 BP_init_header_with_spare( &packet_norm_bp1,
208 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
210 BP_init_header( &packet_norm_bp2,
221 BP_init_header( &packet_norm_bp2,
211 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
222 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
212 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
223 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
213
224
214 //***********************
225 //***********************
215 // BURST and SBM2 headers
226 // BURST and SBM2 headers
216 if ( lfrRequestedMode == LFR_MODE_BURST )
227 if ( lfrRequestedMode == LFR_MODE_BURST )
217 {
228 {
218 BP_init_header( &packet_sbm_bp1,
229 BP_init_header( &packet_sbm_bp1,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
220 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
221 BP_init_header( &packet_sbm_bp2,
232 BP_init_header( &packet_sbm_bp2,
222 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
233 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
223 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
234 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
224 }
235 }
225 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
236 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
226 {
237 {
227 BP_init_header( &packet_sbm_bp1,
238 BP_init_header( &packet_sbm_bp1,
228 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 BP_init_header( &packet_sbm_bp2,
241 BP_init_header( &packet_sbm_bp2,
231 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
242 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
243 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 }
244 }
234 else
245 else
235 {
246 {
236 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
247 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
237 }
248 }
238
249
239 status = get_message_queue_id_send( &queue_id_send );
250 status = get_message_queue_id_send( &queue_id_send );
240 if (status != RTEMS_SUCCESSFUL)
251 if (status != RTEMS_SUCCESSFUL)
241 {
252 {
242 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
253 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
243 }
254 }
244 status = get_message_queue_id_prc1( &queue_id_q_p1);
255 status = get_message_queue_id_prc1( &queue_id_q_p1);
245 if (status != RTEMS_SUCCESSFUL)
256 if (status != RTEMS_SUCCESSFUL)
246 {
257 {
247 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
258 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
248 }
259 }
249
260
250 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
261 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
251
262
252 while(1){
263 while(1){
253 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
264 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
254 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
265 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
255
266
256 incomingMsg = (asm_msg*) incomingData;
267 incomingMsg = (asm_msg*) incomingData;
257
268
258 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
269 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
259 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
270 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
260
271
261 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
272 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
262 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
273 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
263
274
264 //***********
275 //***********
265 //***********
276 //***********
266 // BURST SBM2
277 // BURST SBM2
267 //***********
278 //***********
268 //***********
279 //***********
269 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
280 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
270 {
281 {
271 sid = getSID( incomingMsg->event );
282 sid = getSID( incomingMsg->event );
272 // 1) compress the matrix for Basic Parameters calculation
283 // 1) compress the matrix for Basic Parameters calculation
273 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
284 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
274 nbSMInASMSBM,
285 nbSMInASMSBM,
275 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
286 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
276 ASM_F1_INDICE_START, CHANNELF1);
287 ASM_F1_INDICE_START, CHANNELF1);
277 // 2) compute the BP1 set
288 // 2) compute the BP1 set
278 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
289 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
279 // 3) send the BP1 set
290 // 3) send the BP1 set
280 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
281 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
292 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
282 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
293 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
283 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
294 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
284 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
295 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
285 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
296 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
286 sid );
297 sid );
287 // 4) compute the BP2 set if needed
298 // 4) compute the BP2 set if needed
288 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
299 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
289 {
300 {
290 // 1) compute the BP2 set
301 // 1) compute the BP2 set
291 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
302 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
292 // 2) send the BP2 set
303 // 2) send the BP2 set
293 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
294 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
305 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
295 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
306 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
296 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
307 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
297 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
308 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
298 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
309 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
299 sid );
310 sid );
300 }
311 }
301 }
312 }
302
313
303 //*****
314 //*****
304 //*****
315 //*****
305 // NORM
316 // NORM
306 //*****
317 //*****
307 //*****
318 //*****
308 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
319 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
309 {
320 {
310 // 1) compress the matrix for Basic Parameters calculation
321 // 1) compress the matrix for Basic Parameters calculation
311 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
322 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
312 nbSMInASMNORM,
323 nbSMInASMNORM,
313 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
324 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
314 ASM_F1_INDICE_START, CHANNELF1 );
325 ASM_F1_INDICE_START, CHANNELF1 );
315 // 2) compute the BP1 set
326 // 2) compute the BP1 set
316 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
327 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
317 // 3) send the BP1 set
328 // 3) send the BP1 set
318 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
330 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
320 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
331 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
321 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
332 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
322 BP_send( (char *) &packet_norm_bp1, queue_id_send,
333 BP_send( (char *) &packet_norm_bp1, queue_id_send,
323 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
334 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
324 SID_NORM_BP1_F1 );
335 SID_NORM_BP1_F1 );
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
336 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
326 {
337 {
327 // 1) compute the BP2 set
338 // 1) compute the BP2 set
328 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
339 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
329 // 2) send the BP2 set
340 // 2) send the BP2 set
330 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
331 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
342 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
332 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
343 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
333 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
344 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
334 BP_send( (char *) &packet_norm_bp2, queue_id_send,
345 BP_send( (char *) &packet_norm_bp2, queue_id_send,
335 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
346 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
336 SID_NORM_BP2_F1 );
347 SID_NORM_BP2_F1 );
337 }
348 }
338 }
349 }
339
350
340 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
351 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
341 {
352 {
342 // 1) reorganize the ASM and divide
353 // 1) reorganize the ASM and divide
343 ASM_reorganize_and_divide( asm_f1_patched_norm,
354 ASM_reorganize_and_divide( asm_f1_patched_norm,
344 (float*) current_ring_node_to_send_asm_f1->buffer_address,
355 (float*) current_ring_node_to_send_asm_f1->buffer_address,
345 nbSMInASMNORM );
356 nbSMInASMNORM );
346 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
357 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
347 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
358 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
348 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
359 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
349
360
350 // 3) send the spectral matrix packets
361 // 3) send the spectral matrix packets
351 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
362 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
352
363
353 // change asm ring node
364 // change asm ring node
354 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
365 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
355 }
366 }
356
367
357 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
368 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
358
369
359 }
370 }
360 }
371 }
361
372
362 //**********
373 //**********
363 // FUNCTIONS
374 // FUNCTIONS
364
375
365 void reset_nb_sm_f1( unsigned char lfrMode )
376 void reset_nb_sm_f1( unsigned char lfrMode )
366 {
377 {
367 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
378 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
368 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
379 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
369 nb_sm_before_f1.norm_asm =
380 nb_sm_before_f1.norm_asm =
370 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
381 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
371 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
382 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
372 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
383 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
373 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
384 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
374 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
385 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
375
386
376 if (lfrMode == LFR_MODE_SBM2)
387 if (lfrMode == LFR_MODE_SBM2)
377 {
388 {
378 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
389 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
379 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
390 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
380 }
391 }
381 else if (lfrMode == LFR_MODE_BURST)
392 else if (lfrMode == LFR_MODE_BURST)
382 {
393 {
383 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
394 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
384 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
395 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
385 }
396 }
386 else
397 else
387 {
398 {
388 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
399 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
389 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
400 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
390 }
401 }
391 }
402 }
392
403
393 void init_k_coefficients_prc1( void )
404 void init_k_coefficients_prc1( void )
394 {
405 {
395 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
406 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
396
407
397 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
408 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
398 }
409 }
@@ -1,326 +1,334
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf2_prc2.h"
10 #include "avf2_prc2.h"
11
11
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13
13
14 extern ring_node sm_ring_f2[ ];
14 extern ring_node sm_ring_f2[ ];
15
15
16 //***
16 //***
17 // F2
17 // F2
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
19
19
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
22
22
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
25
25
26 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
26 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
27
27
28 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
28 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
29
29
30 //************
30 //************
31 // RTEMS TASKS
31 // RTEMS TASKS
32
32
33 //***
33 //***
34 // F2
34 // F2
35 rtems_task avf2_task( rtems_task_argument argument )
35 rtems_task avf2_task( rtems_task_argument argument )
36 {
36 {
37 rtems_event_set event_out;
37 rtems_event_set event_out;
38 rtems_status_code status;
38 rtems_status_code status;
39 rtems_id queue_id_prc2;
39 rtems_id queue_id_prc2;
40 asm_msg msgForPRC;
40 asm_msg msgForPRC;
41 ring_node *nodeForAveraging;
41 ring_node *nodeForAveraging;
42 ring_node_asm *current_ring_node_asm_norm_f2;
42 ring_node_asm *current_ring_node_asm_norm_f2;
43
43
44 unsigned int nb_norm_bp1;
44 unsigned int nb_norm_bp1;
45 unsigned int nb_norm_bp2;
45 unsigned int nb_norm_bp2;
46 unsigned int nb_norm_asm;
46 unsigned int nb_norm_asm;
47
47
48 event_out = EVENT_SETS_NONE_PENDING;
49 queue_id_prc2 = RTEMS_ID_NONE;
48 nb_norm_bp1 = 0;
50 nb_norm_bp1 = 0;
49 nb_norm_bp2 = 0;
51 nb_norm_bp2 = 0;
50 nb_norm_asm = 0;
52 nb_norm_asm = 0;
51
53
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
54 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
55 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
56 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55
57
56 BOOT_PRINTF("in AVF2 ***\n")
58 BOOT_PRINTF("in AVF2 ***\n")
57
59
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
60 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 if (status != RTEMS_SUCCESSFUL)
61 if (status != RTEMS_SUCCESSFUL)
60 {
62 {
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
63 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 }
64 }
63
65
64 while(1){
66 while(1){
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
67 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66
68
67 //****************************************
69 //****************************************
68 // initialize the mesage for the MATR task
70 // initialize the mesage for the MATR task
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
71 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 msgForPRC.burst_sbm = NULL;
72 msgForPRC.burst_sbm = NULL;
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
73 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
72 //
74 //
73 //****************************************
75 //****************************************
74
76
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
77 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
76
78
77 // compute the average and store it in the averaged_sm_f2 buffer
79 // compute the average and store it in the averaged_sm_f2 buffer
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
80 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 nodeForAveraging,
81 nodeForAveraging,
80 nb_norm_bp1,
82 nb_norm_bp1,
81 &msgForPRC );
83 &msgForPRC );
82
84
83 // update nb_average
85 // update nb_average
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
86 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
87 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
88 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87
89
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
90 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 {
91 {
90 nb_norm_bp1 = 0;
92 nb_norm_bp1 = 0;
91 // set another ring for the ASM storage
93 // set another ring for the ASM storage
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
94 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
95 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
96 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 {
97 {
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
98 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 }
99 }
98 }
100 }
99
101
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
102 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 {
103 {
102 nb_norm_bp2 = 0;
104 nb_norm_bp2 = 0;
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 {
107 {
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
108 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 }
109 }
108 }
110 }
109
111
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
112 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 {
113 {
112 nb_norm_asm = 0;
114 nb_norm_asm = 0;
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 {
117 {
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 }
119 }
118 }
120 }
119
121
120 //*************************
122 //*************************
121 // send the message to PRC2
123 // send the message to PRC2
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
124 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
123 {
125 {
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
126 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 }
127 }
126
128
127 if (status != RTEMS_SUCCESSFUL) {
129 if (status != RTEMS_SUCCESSFUL) {
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
130 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 }
131 }
130 }
132 }
131 }
133 }
132
134
133 rtems_task prc2_task( rtems_task_argument argument )
135 rtems_task prc2_task( rtems_task_argument argument )
134 {
136 {
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
137 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 size_t size; // size of the incoming TC packet
138 size_t size; // size of the incoming TC packet
137 asm_msg *incomingMsg;
139 asm_msg *incomingMsg;
138 //
140 //
139 rtems_status_code status;
141 rtems_status_code status;
140 rtems_id queue_id_send;
142 rtems_id queue_id_send;
141 rtems_id queue_id_q_p2;
143 rtems_id queue_id_q_p2;
142 bp_packet packet_norm_bp1;
144 bp_packet packet_norm_bp1;
143 bp_packet packet_norm_bp2;
145 bp_packet packet_norm_bp2;
144 ring_node *current_ring_node_to_send_asm_f2;
146 ring_node *current_ring_node_to_send_asm_f2;
145 float nbSMInASMNORM;
147 float nbSMInASMNORM;
146
148
147 unsigned long long int localTime;
149 unsigned long long int localTime;
148
150
151 size = 0;
152 queue_id_send = RTEMS_ID_NONE;
153 queue_id_q_p2 = RTEMS_ID_NONE;
154 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
155 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
156
149 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
157 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
150 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
158 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
151 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
159 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
152
160
153 //*************
161 //*************
154 // NORM headers
162 // NORM headers
155 BP_init_header( &packet_norm_bp1,
163 BP_init_header( &packet_norm_bp1,
156 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
164 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
157 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
165 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
158 BP_init_header( &packet_norm_bp2,
166 BP_init_header( &packet_norm_bp2,
159 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
167 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
160 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
168 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
161
169
162 status = get_message_queue_id_send( &queue_id_send );
170 status = get_message_queue_id_send( &queue_id_send );
163 if (status != RTEMS_SUCCESSFUL)
171 if (status != RTEMS_SUCCESSFUL)
164 {
172 {
165 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
173 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
166 }
174 }
167 status = get_message_queue_id_prc2( &queue_id_q_p2);
175 status = get_message_queue_id_prc2( &queue_id_q_p2);
168 if (status != RTEMS_SUCCESSFUL)
176 if (status != RTEMS_SUCCESSFUL)
169 {
177 {
170 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
178 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
171 }
179 }
172
180
173 BOOT_PRINTF("in PRC2 ***\n")
181 BOOT_PRINTF("in PRC2 ***\n")
174
182
175 while(1){
183 while(1){
176 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
184 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
177 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
185 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
178
186
179 incomingMsg = (asm_msg*) incomingData;
187 incomingMsg = (asm_msg*) incomingData;
180
188
181 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
189 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
182
190
183 localTime = getTimeAsUnsignedLongLongInt( );
191 localTime = getTimeAsUnsignedLongLongInt( );
184
192
185 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
193 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
186
194
187 //*****
195 //*****
188 //*****
196 //*****
189 // NORM
197 // NORM
190 //*****
198 //*****
191 //*****
199 //*****
192 // 1) compress the matrix for Basic Parameters calculation
200 // 1) compress the matrix for Basic Parameters calculation
193 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
201 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
194 nbSMInASMNORM,
202 nbSMInASMNORM,
195 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
203 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
196 ASM_F2_INDICE_START, CHANNELF2 );
204 ASM_F2_INDICE_START, CHANNELF2 );
197 // BP1_F2
205 // BP1_F2
198 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
206 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
199 {
207 {
200 // 1) compute the BP1 set
208 // 1) compute the BP1 set
201 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
209 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
202 // 2) send the BP1 set
210 // 2) send the BP1 set
203 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
204 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
212 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
205 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
213 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
206 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
214 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
207 BP_send( (char *) &packet_norm_bp1, queue_id_send,
215 BP_send( (char *) &packet_norm_bp1, queue_id_send,
208 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
216 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
209 SID_NORM_BP1_F2 );
217 SID_NORM_BP1_F2 );
210 }
218 }
211 // BP2_F2
219 // BP2_F2
212 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
220 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
213 {
221 {
214 // 1) compute the BP2 set
222 // 1) compute the BP2 set
215 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
223 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
216 // 2) send the BP2 set
224 // 2) send the BP2 set
217 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
225 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
218 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
226 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
219 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
227 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
220 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
228 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
221 BP_send( (char *) &packet_norm_bp2, queue_id_send,
229 BP_send( (char *) &packet_norm_bp2, queue_id_send,
222 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
230 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
223 SID_NORM_BP2_F2 );
231 SID_NORM_BP2_F2 );
224 }
232 }
225
233
226 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
234 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
227 {
235 {
228 // 1) reorganize the ASM and divide
236 // 1) reorganize the ASM and divide
229 ASM_reorganize_and_divide( asm_f2_patched_norm,
237 ASM_reorganize_and_divide( asm_f2_patched_norm,
230 (float*) current_ring_node_to_send_asm_f2->buffer_address,
238 (float*) current_ring_node_to_send_asm_f2->buffer_address,
231 nb_sm_before_f2.norm_bp1 );
239 nb_sm_before_f2.norm_bp1 );
232 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
240 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
233 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
241 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
234 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
242 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
235
243
236 // 3) send the spectral matrix packets
244 // 3) send the spectral matrix packets
237 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
245 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
238
246
239 // change asm ring node
247 // change asm ring node
240 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
248 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
241 }
249 }
242
250
243 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
251 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
244
252
245 }
253 }
246 }
254 }
247
255
248 //**********
256 //**********
249 // FUNCTIONS
257 // FUNCTIONS
250
258
251 void reset_nb_sm_f2( void )
259 void reset_nb_sm_f2( void )
252 {
260 {
253 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
261 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
254 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
262 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
255 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
263 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
256 }
264 }
257
265
258 void SM_average_f2( float *averaged_spec_mat_f2,
266 void SM_average_f2( float *averaged_spec_mat_f2,
259 ring_node *ring_node,
267 ring_node *ring_node,
260 unsigned int nbAverageNormF2,
268 unsigned int nbAverageNormF2,
261 asm_msg *msgForMATR )
269 asm_msg *msgForMATR )
262 {
270 {
263 float sum;
271 float sum;
264 unsigned int i;
272 unsigned int i;
265 unsigned char keepMatrix;
273 unsigned char keepMatrix;
266
274
267 // test acquisitionTime validity
275 // test acquisitionTime validity
268 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
276 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
269
277
270 for(i=0; i<TOTAL_SIZE_SM; i++)
278 for(i=0; i<TOTAL_SIZE_SM; i++)
271 {
279 {
272 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
280 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
273 if ( (nbAverageNormF2 == 0) ) // average initialization
281 if ( (nbAverageNormF2 == 0) ) // average initialization
274 {
282 {
275 if (keepMatrix == 1) // keep the matrix and add it to the average
283 if (keepMatrix == 1) // keep the matrix and add it to the average
276 {
284 {
277 averaged_spec_mat_f2[ i ] = sum;
285 averaged_spec_mat_f2[ i ] = sum;
278 }
286 }
279 else // drop the matrix and initialize the average
287 else // drop the matrix and initialize the average
280 {
288 {
281 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
289 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
282 }
290 }
283 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
291 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
284 msgForMATR->fineTimeNORM = ring_node->fineTime;
292 msgForMATR->fineTimeNORM = ring_node->fineTime;
285 }
293 }
286 else
294 else
287 {
295 {
288 if (keepMatrix == 1) // keep the matrix and add it to the average
296 if (keepMatrix == 1) // keep the matrix and add it to the average
289 {
297 {
290 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
298 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
291 }
299 }
292 else
300 else
293 {
301 {
294 // nothing to do, the matrix is not valid
302 // nothing to do, the matrix is not valid
295 }
303 }
296 }
304 }
297 }
305 }
298
306
299 if (keepMatrix == 1)
307 if (keepMatrix == 1)
300 {
308 {
301 if ( (nbAverageNormF2 == 0) )
309 if ( (nbAverageNormF2 == 0) )
302 {
310 {
303 msgForMATR->numberOfSMInASMNORM = 1;
311 msgForMATR->numberOfSMInASMNORM = 1;
304 }
312 }
305 else
313 else
306 {
314 {
307 msgForMATR->numberOfSMInASMNORM++;
315 msgForMATR->numberOfSMInASMNORM++;
308 }
316 }
309 }
317 }
310 else
318 else
311 {
319 {
312 if ( (nbAverageNormF2 == 0) )
320 if ( (nbAverageNormF2 == 0) )
313 {
321 {
314 msgForMATR->numberOfSMInASMNORM = 0;
322 msgForMATR->numberOfSMInASMNORM = 0;
315 }
323 }
316 else
324 else
317 {
325 {
318 // nothing to do
326 // nothing to do
319 }
327 }
320 }
328 }
321 }
329 }
322
330
323 void init_k_coefficients_prc2( void )
331 void init_k_coefficients_prc2( void )
324 {
332 {
325 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
333 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
326 }
334 }
@@ -1,800 +1,802
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "fsw_processing.h"
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
11 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
12 #include "fsw_init.h"
13
13
14 unsigned int nb_sm_f0;
14 unsigned int nb_sm_f0;
15 unsigned int nb_sm_f0_aux_f1;
15 unsigned int nb_sm_f0_aux_f1;
16 unsigned int nb_sm_f1;
16 unsigned int nb_sm_f1;
17 unsigned int nb_sm_f0_aux_f2;
17 unsigned int nb_sm_f0_aux_f2;
18
18
19 typedef enum restartState_t
19 typedef enum restartState_t
20 {
20 {
21 WAIT_FOR_F2,
21 WAIT_FOR_F2,
22 WAIT_FOR_F1,
22 WAIT_FOR_F1,
23 WAIT_FOR_F0
23 WAIT_FOR_F0
24 } restartState;
24 } restartState;
25
25
26 //************************
26 //************************
27 // spectral matrices rings
27 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
31 ring_node *current_ring_node_sm_f0;
31 ring_node *current_ring_node_sm_f0;
32 ring_node *current_ring_node_sm_f1;
32 ring_node *current_ring_node_sm_f1;
33 ring_node *current_ring_node_sm_f2;
33 ring_node *current_ring_node_sm_f2;
34 ring_node *ring_node_for_averaging_sm_f0;
34 ring_node *ring_node_for_averaging_sm_f0;
35 ring_node *ring_node_for_averaging_sm_f1;
35 ring_node *ring_node_for_averaging_sm_f1;
36 ring_node *ring_node_for_averaging_sm_f2;
36 ring_node *ring_node_for_averaging_sm_f2;
37
37
38 //
38 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
40 {
41 ring_node *node;
41 ring_node *node;
42
42
43 node = NULL;
43 node = NULL;
44 switch ( frequencyChannel ) {
44 switch ( frequencyChannel ) {
45 case CHANNELF0:
45 case CHANNELF0:
46 node = ring_node_for_averaging_sm_f0;
46 node = ring_node_for_averaging_sm_f0;
47 break;
47 break;
48 case CHANNELF1:
48 case CHANNELF1:
49 node = ring_node_for_averaging_sm_f1;
49 node = ring_node_for_averaging_sm_f1;
50 break;
50 break;
51 case CHANNELF2:
51 case CHANNELF2:
52 node = ring_node_for_averaging_sm_f2;
52 node = ring_node_for_averaging_sm_f2;
53 break;
53 break;
54 default:
54 default:
55 break;
55 break;
56 }
56 }
57
57
58 return node;
58 return node;
59 }
59 }
60
60
61 //***********************************************************
61 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
62 // Interrupt Service Routine for spectral matrices processing
63
63
64 void spectral_matrices_isr_f0( int statusReg )
64 void spectral_matrices_isr_f0( int statusReg )
65 {
65 {
66 unsigned char status;
66 unsigned char status;
67 rtems_status_code status_code;
67 rtems_status_code status_code;
68 ring_node *full_ring_node;
68 ring_node *full_ring_node;
69
69
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
71
71
72 switch(status)
72 switch(status)
73 {
73 {
74 case 0:
74 case 0:
75 break;
75 break;
76 case BIT_READY_0_1:
76 case BIT_READY_0_1:
77 // UNEXPECTED VALUE
77 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
80 break;
81 case BIT_READY_0:
81 case BIT_READY_0:
82 full_ring_node = current_ring_node_sm_f0->previous;
82 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
87 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
88 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
90 {
90 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
91 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
93 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
95 }
96 nb_sm_f0 = 0;
96 nb_sm_f0 = 0;
97 }
97 }
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
99 break;
99 break;
100 case BIT_READY_1:
100 case BIT_READY_1:
101 full_ring_node = current_ring_node_sm_f0->previous;
101 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
106 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
107 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
109 {
109 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
110 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
112 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
114 }
115 nb_sm_f0 = 0;
115 nb_sm_f0 = 0;
116 }
116 }
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
118 break;
118 break;
119 default:
119 default:
120 break;
120 break;
121 }
121 }
122 }
122 }
123
123
124 void spectral_matrices_isr_f1( int statusReg )
124 void spectral_matrices_isr_f1( int statusReg )
125 {
125 {
126 rtems_status_code status_code;
126 rtems_status_code status_code;
127 unsigned char status;
127 unsigned char status;
128 ring_node *full_ring_node;
128 ring_node *full_ring_node;
129
129
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
131
131
132 switch(status)
132 switch(status)
133 {
133 {
134 case 0:
134 case 0:
135 break;
135 break;
136 case BIT_READY_0_1:
136 case BIT_READY_0_1:
137 // UNEXPECTED VALUE
137 // UNEXPECTED VALUE
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
140 break;
140 break;
141 case BIT_READY_0:
141 case BIT_READY_0:
142 full_ring_node = current_ring_node_sm_f1->previous;
142 full_ring_node = current_ring_node_sm_f1->previous;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
147 // if there are enough ring nodes ready, wake up an AVFx task
147 // if there are enough ring nodes ready, wake up an AVFx task
148 nb_sm_f1 = nb_sm_f1 + 1;
148 nb_sm_f1 = nb_sm_f1 + 1;
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
150 {
150 {
151 ring_node_for_averaging_sm_f1 = full_ring_node;
151 ring_node_for_averaging_sm_f1 = full_ring_node;
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
153 {
153 {
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
155 }
155 }
156 nb_sm_f1 = 0;
156 nb_sm_f1 = 0;
157 }
157 }
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
159 break;
159 break;
160 case BIT_READY_1:
160 case BIT_READY_1:
161 full_ring_node = current_ring_node_sm_f1->previous;
161 full_ring_node = current_ring_node_sm_f1->previous;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
166 // if there are enough ring nodes ready, wake up an AVFx task
166 // if there are enough ring nodes ready, wake up an AVFx task
167 nb_sm_f1 = nb_sm_f1 + 1;
167 nb_sm_f1 = nb_sm_f1 + 1;
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
169 {
169 {
170 ring_node_for_averaging_sm_f1 = full_ring_node;
170 ring_node_for_averaging_sm_f1 = full_ring_node;
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
172 {
172 {
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
174 }
174 }
175 nb_sm_f1 = 0;
175 nb_sm_f1 = 0;
176 }
176 }
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
178 break;
178 break;
179 default:
179 default:
180 break;
180 break;
181 }
181 }
182 }
182 }
183
183
184 void spectral_matrices_isr_f2( int statusReg )
184 void spectral_matrices_isr_f2( int statusReg )
185 {
185 {
186 unsigned char status;
186 unsigned char status;
187 rtems_status_code status_code;
187 rtems_status_code status_code;
188
188
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
190
190
191 switch(status)
191 switch(status)
192 {
192 {
193 case 0:
193 case 0:
194 break;
194 break;
195 case BIT_READY_0_1:
195 case BIT_READY_0_1:
196 // UNEXPECTED VALUE
196 // UNEXPECTED VALUE
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
199 break;
199 break;
200 case BIT_READY_0:
200 case BIT_READY_0:
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
208 {
208 {
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
210 }
210 }
211 break;
211 break;
212 case BIT_READY_1:
212 case BIT_READY_1:
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
220 {
220 {
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
222 }
222 }
223 break;
223 break;
224 default:
224 default:
225 break;
225 break;
226 }
226 }
227 }
227 }
228
228
229 void spectral_matrix_isr_error_handler( int statusReg )
229 void spectral_matrix_isr_error_handler( int statusReg )
230 {
230 {
231 // STATUS REGISTER
231 // STATUS REGISTER
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
233 // 10 9 8
233 // 10 9 8
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
235 // 7 6 5 4 3 2 1 0
235 // 7 6 5 4 3 2 1 0
236 // [bad_component_err] not defined in the last version of the VHDL code
236 // [bad_component_err] not defined in the last version of the VHDL code
237
237
238 rtems_status_code status_code;
238 rtems_status_code status_code;
239
239
240 //***************************************************
240 //***************************************************
241 // the ASM status register is copied in the HK packet
241 // the ASM status register is copied in the HK packet
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
243
243
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
245 {
245 {
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
247 }
247 }
248
248
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
250
250
251 }
251 }
252
252
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
254 {
254 {
255 // STATUS REGISTER
255 // STATUS REGISTER
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
257 // 10 9 8
257 // 10 9 8
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
259 // 7 6 5 4 3 2 1 0
259 // 7 6 5 4 3 2 1 0
260
260
261 int statusReg;
261 int statusReg;
262
262
263 static restartState state = WAIT_FOR_F2;
263 static restartState state = WAIT_FOR_F2;
264
264
265 statusReg = spectral_matrix_regs->status;
265 statusReg = spectral_matrix_regs->status;
266
266
267 if (thisIsAnASMRestart == 0)
267 if (thisIsAnASMRestart == 0)
268 { // this is not a restart sequence, process incoming matrices normally
268 { // this is not a restart sequence, process incoming matrices normally
269 spectral_matrices_isr_f0( statusReg );
269 spectral_matrices_isr_f0( statusReg );
270
270
271 spectral_matrices_isr_f1( statusReg );
271 spectral_matrices_isr_f1( statusReg );
272
272
273 spectral_matrices_isr_f2( statusReg );
273 spectral_matrices_isr_f2( statusReg );
274 }
274 }
275 else
275 else
276 { // a restart sequence has to be launched
276 { // a restart sequence has to be launched
277 switch (state) {
277 switch (state) {
278 case WAIT_FOR_F2:
278 case WAIT_FOR_F2:
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
280 {
280 {
281 state = WAIT_FOR_F1;
281 state = WAIT_FOR_F1;
282 }
282 }
283 break;
283 break;
284 case WAIT_FOR_F1:
284 case WAIT_FOR_F1:
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
286 {
286 {
287 state = WAIT_FOR_F0;
287 state = WAIT_FOR_F0;
288 }
288 }
289 break;
289 break;
290 case WAIT_FOR_F0:
290 case WAIT_FOR_F0:
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
292 {
292 {
293 state = WAIT_FOR_F2;
293 state = WAIT_FOR_F2;
294 thisIsAnASMRestart = 0;
294 thisIsAnASMRestart = 0;
295 }
295 }
296 break;
296 break;
297 default:
297 default:
298 break;
298 break;
299 }
299 }
300 reset_sm_status();
300 reset_sm_status();
301 }
301 }
302
302
303 spectral_matrix_isr_error_handler( statusReg );
303 spectral_matrix_isr_error_handler( statusReg );
304
304
305 }
305 }
306
306
307 //******************
307 //******************
308 // Spectral Matrices
308 // Spectral Matrices
309
309
310 void reset_nb_sm( void )
310 void reset_nb_sm( void )
311 {
311 {
312 nb_sm_f0 = 0;
312 nb_sm_f0 = 0;
313 nb_sm_f0_aux_f1 = 0;
313 nb_sm_f0_aux_f1 = 0;
314 nb_sm_f0_aux_f2 = 0;
314 nb_sm_f0_aux_f2 = 0;
315
315
316 nb_sm_f1 = 0;
316 nb_sm_f1 = 0;
317 }
317 }
318
318
319 void SM_init_rings( void )
319 void SM_init_rings( void )
320 {
320 {
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
324
324
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
331 }
331 }
332
332
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
334 {
334 {
335 unsigned char i;
335 unsigned char i;
336
336
337 ring[ nbNodes - 1 ].next
337 ring[ nbNodes - 1 ].next
338 = (ring_node_asm*) &ring[ 0 ];
338 = (ring_node_asm*) &ring[ 0 ];
339
339
340 for(i=0; i<nbNodes-1; i++)
340 for(i=0; i<nbNodes-1; i++)
341 {
341 {
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
343 }
343 }
344 }
344 }
345
345
346 void SM_reset_current_ring_nodes( void )
346 void SM_reset_current_ring_nodes( void )
347 {
347 {
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
351
351
352 ring_node_for_averaging_sm_f0 = NULL;
352 ring_node_for_averaging_sm_f0 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
355 }
355 }
356
356
357 //*****************
357 //*****************
358 // Basic Parameters
358 // Basic Parameters
359
359
360 void BP_init_header( bp_packet *packet,
360 void BP_init_header( bp_packet *packet,
361 unsigned int apid, unsigned char sid,
361 unsigned int apid, unsigned char sid,
362 unsigned int packetLength, unsigned char blkNr )
362 unsigned int packetLength, unsigned char blkNr )
363 {
363 {
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
366 packet->reserved = INIT_CHAR;
366 packet->reserved = INIT_CHAR;
367 packet->userApplication = CCSDS_USER_APP;
367 packet->userApplication = CCSDS_USER_APP;
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
369 packet->packetID[1] = (unsigned char) (apid);
369 packet->packetID[1] = (unsigned char) (apid);
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
371 packet->packetSequenceControl[1] = INIT_CHAR;
371 packet->packetSequenceControl[1] = INIT_CHAR;
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
373 packet->packetLength[1] = (unsigned char) (packetLength);
373 packet->packetLength[1] = (unsigned char) (packetLength);
374 // DATA FIELD HEADER
374 // DATA FIELD HEADER
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
379 packet->time[BYTE_0] = INIT_CHAR;
379 packet->time[BYTE_0] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
385 // AUXILIARY DATA HEADER
385 // AUXILIARY DATA HEADER
386 packet->sid = sid;
386 packet->sid = sid;
387 packet->pa_bia_status_info = INIT_CHAR;
387 packet->pa_bia_status_info = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
398 }
398 }
399
399
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
401 unsigned int apid, unsigned char sid,
401 unsigned int apid, unsigned char sid,
402 unsigned int packetLength , unsigned char blkNr)
402 unsigned int packetLength , unsigned char blkNr)
403 {
403 {
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
406 packet->reserved = INIT_CHAR;
406 packet->reserved = INIT_CHAR;
407 packet->userApplication = CCSDS_USER_APP;
407 packet->userApplication = CCSDS_USER_APP;
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
409 packet->packetID[1] = (unsigned char) (apid);
409 packet->packetID[1] = (unsigned char) (apid);
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
411 packet->packetSequenceControl[1] = INIT_CHAR;
411 packet->packetSequenceControl[1] = INIT_CHAR;
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
413 packet->packetLength[1] = (unsigned char) (packetLength);
413 packet->packetLength[1] = (unsigned char) (packetLength);
414 // DATA FIELD HEADER
414 // DATA FIELD HEADER
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
419 // AUXILIARY DATA HEADER
419 // AUXILIARY DATA HEADER
420 packet->sid = sid;
420 packet->sid = sid;
421 packet->pa_bia_status_info = INIT_CHAR;
421 packet->pa_bia_status_info = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
433 }
433 }
434
434
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
436 {
436 {
437 rtems_status_code status;
437 rtems_status_code status;
438
438
439 // SEND PACKET
439 // SEND PACKET
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
441 if (status != RTEMS_SUCCESSFUL)
441 if (status != RTEMS_SUCCESSFUL)
442 {
442 {
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
444 }
444 }
445 }
445 }
446
446
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
448 {
448 {
449 /** This function is used to send the BP paquets when needed.
449 /** This function is used to send the BP paquets when needed.
450 *
450 *
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
452 *
452 *
453 * @return void
453 * @return void
454 *
454 *
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
456 * BURST paquets are sent everytime.
456 * BURST paquets are sent everytime.
457 *
457 *
458 */
458 */
459
459
460 rtems_status_code status;
460 rtems_status_code status;
461
461
462 // SEND PACKET
462 // SEND PACKET
463 // before lastValidTransitionDate, the data are drops even if they are ready
463 // before lastValidTransitionDate, the data are drops even if they are ready
464 // this guarantees that no SBM packets will be received before the requested enter mode time
464 // this guarantees that no SBM packets will be received before the requested enter mode time
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
466 {
466 {
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
468 if (status != RTEMS_SUCCESSFUL)
468 if (status != RTEMS_SUCCESSFUL)
469 {
469 {
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
471 }
471 }
472 }
472 }
473 }
473 }
474
474
475 //******************
475 //******************
476 // general functions
476 // general functions
477
477
478 void reset_sm_status( void )
478 void reset_sm_status( void )
479 {
479 {
480 // error
480 // error
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
485
485
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
487 }
487 }
488
488
489 void reset_spectral_matrix_regs( void )
489 void reset_spectral_matrix_regs( void )
490 {
490 {
491 /** This function resets the spectral matrices module registers.
491 /** This function resets the spectral matrices module registers.
492 *
492 *
493 * The registers affected by this function are located at the following offset addresses:
493 * The registers affected by this function are located at the following offset addresses:
494 *
494 *
495 * - 0x00 config
495 * - 0x00 config
496 * - 0x04 status
496 * - 0x04 status
497 * - 0x08 matrixF0_Address0
497 * - 0x08 matrixF0_Address0
498 * - 0x10 matrixFO_Address1
498 * - 0x10 matrixFO_Address1
499 * - 0x14 matrixF1_Address
499 * - 0x14 matrixF1_Address
500 * - 0x18 matrixF2_Address
500 * - 0x18 matrixF2_Address
501 *
501 *
502 */
502 */
503
503
504 set_sm_irq_onError( 0 );
504 set_sm_irq_onError( 0 );
505
505
506 set_sm_irq_onNewMatrix( 0 );
506 set_sm_irq_onNewMatrix( 0 );
507
507
508 reset_sm_status();
508 reset_sm_status();
509
509
510 // F1
510 // F1
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
513 // F2
513 // F2
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
516 // F3
516 // F3
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
519
519
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
521 }
521 }
522
522
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
524 {
524 {
525 time[BYTE_0] = timeInBuffer[BYTE_0];
525 time[BYTE_0] = timeInBuffer[BYTE_0];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
531 }
531 }
532
532
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
534 {
534 {
535 unsigned long long int acquisitionTimeAslong;
535 unsigned long long int acquisitionTimeAslong;
536 acquisitionTimeAslong = INIT_CHAR;
536 acquisitionTimeAslong = INIT_CHAR;
537 acquisitionTimeAslong =
537 acquisitionTimeAslong =
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
543 + ( (unsigned long long int) timePtr[BYTE_7] );
543 + ( (unsigned long long int) timePtr[BYTE_7] );
544 return acquisitionTimeAslong;
544 return acquisitionTimeAslong;
545 }
545 }
546
546
547 unsigned char getSID( rtems_event_set event )
547 unsigned char getSID( rtems_event_set event )
548 {
548 {
549 unsigned char sid;
549 unsigned char sid;
550
550
551 rtems_event_set eventSetBURST;
551 rtems_event_set eventSetBURST;
552 rtems_event_set eventSetSBM;
552 rtems_event_set eventSetSBM;
553
553
554 sid = 0;
555
554 //******
556 //******
555 // BURST
557 // BURST
556 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
558 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
557 | RTEMS_EVENT_BURST_BP1_F1
559 | RTEMS_EVENT_BURST_BP1_F1
558 | RTEMS_EVENT_BURST_BP2_F0
560 | RTEMS_EVENT_BURST_BP2_F0
559 | RTEMS_EVENT_BURST_BP2_F1;
561 | RTEMS_EVENT_BURST_BP2_F1;
560
562
561 //****
563 //****
562 // SBM
564 // SBM
563 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
565 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
564 | RTEMS_EVENT_SBM_BP1_F1
566 | RTEMS_EVENT_SBM_BP1_F1
565 | RTEMS_EVENT_SBM_BP2_F0
567 | RTEMS_EVENT_SBM_BP2_F0
566 | RTEMS_EVENT_SBM_BP2_F1;
568 | RTEMS_EVENT_SBM_BP2_F1;
567
569
568 if (event & eventSetBURST)
570 if (event & eventSetBURST)
569 {
571 {
570 sid = SID_BURST_BP1_F0;
572 sid = SID_BURST_BP1_F0;
571 }
573 }
572 else if (event & eventSetSBM)
574 else if (event & eventSetSBM)
573 {
575 {
574 sid = SID_SBM1_BP1_F0;
576 sid = SID_SBM1_BP1_F0;
575 }
577 }
576 else
578 else
577 {
579 {
578 sid = 0;
580 sid = 0;
579 }
581 }
580
582
581 return sid;
583 return sid;
582 }
584 }
583
585
584 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
586 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
585 {
587 {
586 unsigned int i;
588 unsigned int i;
587 float re;
589 float re;
588 float im;
590 float im;
589
591
590 for (i=0; i<NB_BINS_PER_SM; i++){
592 for (i=0; i<NB_BINS_PER_SM; i++){
591 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
593 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
592 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
594 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
593 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
595 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
594 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
596 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
595 }
597 }
596 }
598 }
597
599
598 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
600 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
599 {
601 {
600 unsigned int i;
602 unsigned int i;
601 float re;
603 float re;
602
604
603 for (i=0; i<NB_BINS_PER_SM; i++){
605 for (i=0; i<NB_BINS_PER_SM; i++){
604 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
606 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
605 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
607 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
606 }
608 }
607 }
609 }
608
610
609 void ASM_patch( float *inputASM, float *outputASM )
611 void ASM_patch( float *inputASM, float *outputASM )
610 {
612 {
611 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
612 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
620 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
621 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
620 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
622 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
621
623
622 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
624 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
623 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
625 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
624 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
626 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
625 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
627 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
626 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
628 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
627 }
629 }
628
630
629 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
631 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
630 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
632 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
631 unsigned char ASMIndexStart,
633 unsigned char ASMIndexStart,
632 unsigned char channel )
634 unsigned char channel )
633 {
635 {
634 //*************
636 //*************
635 // input format
637 // input format
636 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
638 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
637 //**************
639 //**************
638 // output format
640 // output format
639 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
641 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
640 //************
642 //************
641 // compression
643 // compression
642 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
644 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
643 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
645 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
644
646
645 int frequencyBin;
647 int frequencyBin;
646 int asmComponent;
648 int asmComponent;
647 int offsetASM;
649 int offsetASM;
648 int offsetCompressed;
650 int offsetCompressed;
649 int offsetFBin;
651 int offsetFBin;
650 int fBinMask;
652 int fBinMask;
651 int k;
653 int k;
652
654
653 // BUILD DATA
655 // BUILD DATA
654 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
656 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
655 {
657 {
656 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
658 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
657 {
659 {
658 offsetCompressed = // NO TIME OFFSET
660 offsetCompressed = // NO TIME OFFSET
659 (frequencyBin * NB_VALUES_PER_SM)
661 (frequencyBin * NB_VALUES_PER_SM)
660 + asmComponent;
662 + asmComponent;
661 offsetASM = // NO TIME OFFSET
663 offsetASM = // NO TIME OFFSET
662 (asmComponent * NB_BINS_PER_SM)
664 (asmComponent * NB_BINS_PER_SM)
663 + ASMIndexStart
665 + ASMIndexStart
664 + (frequencyBin * nbBinsToAverage);
666 + (frequencyBin * nbBinsToAverage);
665 offsetFBin = ASMIndexStart
667 offsetFBin = ASMIndexStart
666 + (frequencyBin * nbBinsToAverage);
668 + (frequencyBin * nbBinsToAverage);
667 compressed_spec_mat[ offsetCompressed ] = 0;
669 compressed_spec_mat[ offsetCompressed ] = 0;
668 for ( k = 0; k < nbBinsToAverage; k++ )
670 for ( k = 0; k < nbBinsToAverage; k++ )
669 {
671 {
670 fBinMask = getFBinMask( offsetFBin + k, channel );
672 fBinMask = getFBinMask( offsetFBin + k, channel );
671 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
673 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
672 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
674 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
673 }
675 }
674 if (divider != 0)
676 if (divider != 0)
675 {
677 {
676 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
678 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
677 }
679 }
678 else
680 else
679 {
681 {
680 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
682 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
681 }
683 }
682 }
684 }
683 }
685 }
684
686
685 }
687 }
686
688
687 int getFBinMask( int index, unsigned char channel )
689 int getFBinMask( int index, unsigned char channel )
688 {
690 {
689 unsigned int indexInChar;
691 unsigned int indexInChar;
690 unsigned int indexInTheChar;
692 unsigned int indexInTheChar;
691 int fbin;
693 int fbin;
692 unsigned char *sy_lfr_fbins_fx_word1;
694 unsigned char *sy_lfr_fbins_fx_word1;
693
695
694 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
696 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
695
697
696 switch(channel)
698 switch(channel)
697 {
699 {
698 case CHANNELF0:
700 case CHANNELF0:
699 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
701 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
700 break;
702 break;
701 case CHANNELF1:
703 case CHANNELF1:
702 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
704 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
703 break;
705 break;
704 case CHANNELF2:
706 case CHANNELF2:
705 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
707 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
706 break;
708 break;
707 default:
709 default:
708 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
710 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
709 }
711 }
710
712
711 indexInChar = index >> SHIFT_3_BITS;
713 indexInChar = index >> SHIFT_3_BITS;
712 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
714 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
713
715
714 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
716 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
715
717
716 return fbin;
718 return fbin;
717 }
719 }
718
720
719 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
721 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
720 {
722 {
721 u_int64_t acquisitionTime;
723 u_int64_t acquisitionTime;
722 u_int64_t timecodeReference;
724 u_int64_t timecodeReference;
723 u_int64_t offsetInFineTime;
725 u_int64_t offsetInFineTime;
724 u_int64_t shiftInFineTime;
726 u_int64_t shiftInFineTime;
725 u_int64_t tBadInFineTime;
727 u_int64_t tBadInFineTime;
726 u_int64_t acquisitionTimeRangeMin;
728 u_int64_t acquisitionTimeRangeMin;
727 u_int64_t acquisitionTimeRangeMax;
729 u_int64_t acquisitionTimeRangeMax;
728 unsigned char pasFilteringIsEnabled;
730 unsigned char pasFilteringIsEnabled;
729 unsigned char ret;
731 unsigned char ret;
730
732
731 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
733 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
732 ret = 1;
734 ret = 1;
733
735
734 // compute acquisition time from caoarseTime and fineTime
736 // compute acquisition time from caoarseTime and fineTime
735 acquisitionTime = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
737 acquisitionTime = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
736 + (u_int64_t) fineTime;
738 + (u_int64_t) fineTime;
737
739
738 // compute the timecode reference
740 // compute the timecode reference
739 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
741 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
740 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
742 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
741
743
742 // compute the acquitionTime range
744 // compute the acquitionTime range
743 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
745 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
744 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
746 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
745 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
747 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
746
748
747 acquisitionTimeRangeMin =
749 acquisitionTimeRangeMin =
748 timecodeReference
750 timecodeReference
749 + offsetInFineTime
751 + offsetInFineTime
750 + shiftInFineTime
752 + shiftInFineTime
751 - acquisitionDurations[channel];
753 - acquisitionDurations[channel];
752 acquisitionTimeRangeMax =
754 acquisitionTimeRangeMax =
753 timecodeReference
755 timecodeReference
754 + offsetInFineTime
756 + offsetInFineTime
755 + shiftInFineTime
757 + shiftInFineTime
756 + tBadInFineTime;
758 + tBadInFineTime;
757
759
758 if ( (acquisitionTime >= acquisitionTimeRangeMin)
760 if ( (acquisitionTime >= acquisitionTimeRangeMin)
759 && (acquisitionTime <= acquisitionTimeRangeMax)
761 && (acquisitionTime <= acquisitionTimeRangeMax)
760 && (pasFilteringIsEnabled == 1) )
762 && (pasFilteringIsEnabled == 1) )
761 {
763 {
762 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
764 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
763 }
765 }
764 else
766 else
765 {
767 {
766 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
768 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
767 }
769 }
768
770
769 // printf("coarseTime = %x, fineTime = %x\n",
771 // printf("coarseTime = %x, fineTime = %x\n",
770 // coarseTime,
772 // coarseTime,
771 // fineTime);
773 // fineTime);
772
774
773 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
775 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
774 // ret,
776 // ret,
775 // acquisitionTime / 65536.,
777 // acquisitionTime / 65536.,
776 // timecodeReference / 65536.);
778 // timecodeReference / 65536.);
777
779
778 // printf(", Min = %f, Max = %f\n",
780 // printf(", Min = %f, Max = %f\n",
779 // acquisitionTimeRangeMin / 65536.,
781 // acquisitionTimeRangeMin / 65536.,
780 // acquisitionTimeRangeMax / 65536.);
782 // acquisitionTimeRangeMax / 65536.);
781
783
782 return ret;
784 return ret;
783 }
785 }
784
786
785 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
787 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
786 {
788 {
787 unsigned char bin;
789 unsigned char bin;
788 unsigned char kcoeff;
790 unsigned char kcoeff;
789
791
790 for (bin=0; bin<nb_bins_norm; bin++)
792 for (bin=0; bin<nb_bins_norm; bin++)
791 {
793 {
792 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
794 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
793 {
795 {
794 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
796 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
795 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
797 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
796 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF + 1 ]
798 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF + 1 ]
797 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
799 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
798 }
800 }
799 }
801 }
800 }
802 }
@@ -1,475 +1,481
1 /** Functions related to TeleCommand acceptance.
1 /** Functions related to TeleCommand acceptance.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands parsing.\n
6 * A group of functions to handle TeleCommands parsing.\n
7 *
7 *
8 */
8 */
9
9
10 #include "tc_acceptance.h"
10 #include "tc_acceptance.h"
11 #include <stdio.h>
11 #include <stdio.h>
12
12
13 unsigned int lookUpTableForCRC[CONST_256];
13 unsigned int lookUpTableForCRC[CONST_256];
14
14
15 //**********************
15 //**********************
16 // GENERAL USE FUNCTIONS
16 // GENERAL USE FUNCTIONS
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
18 {
18 {
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
20 *
20 *
21 * @param D is the current byte of data.
21 * @param D is the current byte of data.
22 * @param Chk is the current syndrom value.
22 * @param Chk is the current syndrom value.
23 *
23 *
24 * @return the value of the new syndrome on two bytes.
24 * @return the value of the new syndrome on two bytes.
25 *
25 *
26 */
26 */
27
27
28 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
28 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
29 }
29 }
30
30
31 void initLookUpTableForCRC( void )
31 void initLookUpTableForCRC( void )
32 {
32 {
33 /** This function is used to initiates the look-up table for fast CRC computation.
33 /** This function is used to initiates the look-up table for fast CRC computation.
34 *
34 *
35 * The global table lookUpTableForCRC[256] is initiated.
35 * The global table lookUpTableForCRC[256] is initiated.
36 *
36 *
37 */
37 */
38
38
39 unsigned int i;
39 unsigned int i;
40 unsigned int tmp;
40 unsigned int tmp;
41
41
42 for (i=0; i<CONST_256; i++)
42 for (i=0; i<CONST_256; i++)
43 {
43 {
44 tmp = 0;
44 tmp = 0;
45 if((i & BIT_0) != 0) {
45 if((i & BIT_0) != 0) {
46 tmp = tmp ^ CONST_CRC_0;
46 tmp = tmp ^ CONST_CRC_0;
47 }
47 }
48 if((i & BIT_1) != 0) {
48 if((i & BIT_1) != 0) {
49 tmp = tmp ^ CONST_CRC_1;
49 tmp = tmp ^ CONST_CRC_1;
50 }
50 }
51 if((i & BIT_2) != 0) {
51 if((i & BIT_2) != 0) {
52 tmp = tmp ^ CONST_CRC_2;
52 tmp = tmp ^ CONST_CRC_2;
53 }
53 }
54 if((i & BIT_3) != 0) {
54 if((i & BIT_3) != 0) {
55 tmp = tmp ^ CONST_CRC_3;
55 tmp = tmp ^ CONST_CRC_3;
56 }
56 }
57 if((i & BIT_4) != 0) {
57 if((i & BIT_4) != 0) {
58 tmp = tmp ^ CONST_CRC_4;
58 tmp = tmp ^ CONST_CRC_4;
59 }
59 }
60 if((i & BIT_5) != 0) {
60 if((i & BIT_5) != 0) {
61 tmp = tmp ^ CONST_CRC_5;
61 tmp = tmp ^ CONST_CRC_5;
62 }
62 }
63 if((i & BIT_6) != 0) {
63 if((i & BIT_6) != 0) {
64 tmp = tmp ^ CONST_CRC_6;
64 tmp = tmp ^ CONST_CRC_6;
65 }
65 }
66 if((i & BIT_7) != 0) {
66 if((i & BIT_7) != 0) {
67 tmp = tmp ^ CONST_CRC_7;
67 tmp = tmp ^ CONST_CRC_7;
68 }
68 }
69 lookUpTableForCRC[i] = tmp;
69 lookUpTableForCRC[i] = tmp;
70 }
70 }
71 }
71 }
72
72
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
74 {
74 {
75 /** This function calculates a two bytes Cyclic Redundancy Code.
75 /** This function calculates a two bytes Cyclic Redundancy Code.
76 *
76 *
77 * @param data points to a buffer containing the data on which to compute the CRC.
77 * @param data points to a buffer containing the data on which to compute the CRC.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
80 *
80 *
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
82 *
82 *
83 */
83 */
84
84
85 unsigned int Chk;
85 unsigned int Chk;
86 int j;
86 int j;
87 Chk = CRC_RESET; // reset the syndrom to all ones
87 Chk = CRC_RESET; // reset the syndrom to all ones
88 for (j=0; j<sizeOfData; j++) {
88 for (j=0; j<sizeOfData; j++) {
89 Chk = Crc_opt(data[j], Chk);
89 Chk = Crc_opt(data[j], Chk);
90 }
90 }
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
93 }
93 }
94
94
95 //*********************
95 //*********************
96 // ACCEPTANCE FUNCTIONS
96 // ACCEPTANCE FUNCTIONS
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
98 {
98 {
99 /** This function parses TeleCommands.
99 /** This function parses TeleCommands.
100 *
100 *
101 * @param TC points to the TeleCommand that will be parsed.
101 * @param TC points to the TeleCommand that will be parsed.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
103 *
103 *
104 * @return Status code of the parsing.
104 * @return Status code of the parsing.
105 *
105 *
106 * The parsing checks:
106 * The parsing checks:
107 * - process id
107 * - process id
108 * - category
108 * - category
109 * - length: a global check is performed and a per subtype check also
109 * - length: a global check is performed and a per subtype check also
110 * - type
110 * - type
111 * - subtype
111 * - subtype
112 * - crc
112 * - crc
113 *
113 *
114 */
114 */
115
115
116 int status;
116 int status;
117 int status_crc;
117 int status_crc;
118 unsigned char pid;
118 unsigned char pid;
119 unsigned char category;
119 unsigned char category;
120 unsigned int packetLength;
120 unsigned int packetLength;
121 unsigned char packetType;
121 unsigned char packetType;
122 unsigned char packetSubtype;
122 unsigned char packetSubtype;
123 unsigned char sid;
123 unsigned char sid;
124
124
125 status = CCSDS_TM_VALID;
125 status = CCSDS_TM_VALID;
126
126
127 // APID check *** APID on 2 bytes
127 // APID check *** APID on 2 bytes
128 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
128 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
129 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
129 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
130 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
130 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
131 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
131 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
132 packetType = TCPacket->serviceType;
132 packetType = TCPacket->serviceType;
133 packetSubtype = TCPacket->serviceSubType;
133 packetSubtype = TCPacket->serviceSubType;
134 sid = TCPacket->sourceID;
134 sid = TCPacket->sourceID;
135
135
136 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
136 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
137 {
137 {
138 status = ILLEGAL_APID;
138 status = ILLEGAL_APID;
139 }
139 }
140 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
140 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
141 {
141 {
142 if ( category != CCSDS_PACKET_CATEGORY )
142 if ( category != CCSDS_PACKET_CATEGORY )
143 {
143 {
144 status = ILLEGAL_APID;
144 status = ILLEGAL_APID;
145 }
145 }
146 }
146 }
147 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
147 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
148 {
148 {
149 if (packetLength != estimatedPacketLength ) {
149 if (packetLength != estimatedPacketLength ) {
150 status = WRONG_LEN_PKT;
150 status = WRONG_LEN_PKT;
151 }
151 }
152 }
152 }
153 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
153 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
154 {
154 {
155 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
155 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
156 status = WRONG_LEN_PKT;
156 status = WRONG_LEN_PKT;
157 }
157 }
158 }
158 }
159 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
159 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
160 {
160 {
161 status = tc_check_type( packetType );
161 status = tc_check_type( packetType );
162 }
162 }
163 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
163 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
164 {
164 {
165 status = tc_check_type_subtype( packetType, packetSubtype );
165 status = tc_check_type_subtype( packetType, packetSubtype );
166 }
166 }
167 if (status == CCSDS_TM_VALID) // CHECK THE SID
167 if (status == CCSDS_TM_VALID) // CHECK THE SID
168 {
168 {
169 status = tc_check_sid( sid );
169 status = tc_check_sid( sid );
170 }
170 }
171 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
171 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
172 {
172 {
173 status = tc_check_length( packetSubtype, packetLength );
173 status = tc_check_length( packetSubtype, packetLength );
174 }
174 }
175 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
175 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
176 if (status == CCSDS_TM_VALID ) // CHECK CRC
176 if (status == CCSDS_TM_VALID ) // CHECK CRC
177 {
177 {
178 status = status_crc;
178 status = status_crc;
179 }
179 }
180
180
181 return status;
181 return status;
182 }
182 }
183
183
184 int tc_check_type( unsigned char packetType )
184 int tc_check_type( unsigned char packetType )
185 {
185 {
186 /** This function checks that the type of a TeleCommand is valid.
186 /** This function checks that the type of a TeleCommand is valid.
187 *
187 *
188 * @param packetType is the type to check.
188 * @param packetType is the type to check.
189 *
189 *
190 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
190 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
191 *
191 *
192 */
192 */
193
193
194 int status;
194 int status;
195
195
196 status = ILL_TYPE;
197
196 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
198 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
197 {
199 {
198 status = CCSDS_TM_VALID;
200 status = CCSDS_TM_VALID;
199 }
201 }
200 else
202 else
201 {
203 {
202 status = ILL_TYPE;
204 status = ILL_TYPE;
203 }
205 }
204
206
205 return status;
207 return status;
206 }
208 }
207
209
208 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
210 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
209 {
211 {
210 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
212 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
211 *
213 *
212 * @param packetType is the type of the TC.
214 * @param packetType is the type of the TC.
213 * @param packetSubType is the subtype to check.
215 * @param packetSubType is the subtype to check.
214 *
216 *
215 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
217 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
216 *
218 *
217 */
219 */
218
220
219 int status;
221 int status;
220
222
221 switch(packetType)
223 switch(packetType)
222 {
224 {
223 case TC_TYPE_GEN:
225 case TC_TYPE_GEN:
224 if ( (packetSubType == TC_SUBTYPE_RESET)
226 if ( (packetSubType == TC_SUBTYPE_RESET)
225 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
227 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
226 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
228 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
227 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
229 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
228 || (packetSubType == TC_SUBTYPE_DUMP)
230 || (packetSubType == TC_SUBTYPE_DUMP)
229 || (packetSubType == TC_SUBTYPE_ENTER)
231 || (packetSubType == TC_SUBTYPE_ENTER)
230 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
232 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
231 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
233 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
232 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
234 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
233 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
235 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
234 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
236 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
235 {
237 {
236 status = CCSDS_TM_VALID;
238 status = CCSDS_TM_VALID;
237 }
239 }
238 else
240 else
239 {
241 {
240 status = ILL_SUBTYPE;
242 status = ILL_SUBTYPE;
241 }
243 }
242 break;
244 break;
243
245
244 case TC_TYPE_TIME:
246 case TC_TYPE_TIME:
245 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
247 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
246 {
248 {
247 status = CCSDS_TM_VALID;
249 status = CCSDS_TM_VALID;
248 }
250 }
249 else
251 else
250 {
252 {
251 status = ILL_SUBTYPE;
253 status = ILL_SUBTYPE;
252 }
254 }
253 break;
255 break;
254
256
255 default:
257 default:
256 status = ILL_SUBTYPE;
258 status = ILL_SUBTYPE;
257 break;
259 break;
258 }
260 }
259
261
260 return status;
262 return status;
261 }
263 }
262
264
263 int tc_check_sid( unsigned char sid )
265 int tc_check_sid( unsigned char sid )
264 {
266 {
265 /** This function checks that the sid of a TeleCommand is valid.
267 /** This function checks that the sid of a TeleCommand is valid.
266 *
268 *
267 * @param sid is the sid to check.
269 * @param sid is the sid to check.
268 *
270 *
269 * @return Status code CCSDS_TM_VALID or CORRUPTED.
271 * @return Status code CCSDS_TM_VALID or CORRUPTED.
270 *
272 *
271 */
273 */
272
274
273 int status;
275 int status;
274
276
277 status = WRONG_SRC_ID;
278
275 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
279 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
276 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
280 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
277 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
281 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
278 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
282 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
279 || (sid == SID_TC_RPW_INTERNAL))
283 || (sid == SID_TC_RPW_INTERNAL))
280 {
284 {
281 status = CCSDS_TM_VALID;
285 status = CCSDS_TM_VALID;
282 }
286 }
283 else
287 else
284 {
288 {
285 status = WRONG_SRC_ID;
289 status = WRONG_SRC_ID;
286 }
290 }
287
291
288 return status;
292 return status;
289 }
293 }
290
294
291 int tc_check_length( unsigned char packetSubType, unsigned int length )
295 int tc_check_length( unsigned char packetSubType, unsigned int length )
292 {
296 {
293 /** This function checks that the subtype and the length are compliant.
297 /** This function checks that the subtype and the length are compliant.
294 *
298 *
295 * @param packetSubType is the subtype to check.
299 * @param packetSubType is the subtype to check.
296 * @param length is the length to check.
300 * @param length is the length to check.
297 *
301 *
298 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
302 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
299 *
303 *
300 */
304 */
301
305
302 int status;
306 int status;
303
307
304 status = LFR_SUCCESSFUL;
308 status = LFR_SUCCESSFUL;
305
309
306 switch(packetSubType)
310 switch(packetSubType)
307 {
311 {
308 case TC_SUBTYPE_RESET:
312 case TC_SUBTYPE_RESET:
309 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
313 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
310 status = WRONG_LEN_PKT;
314 status = WRONG_LEN_PKT;
311 }
315 }
312 else {
316 else {
313 status = CCSDS_TM_VALID;
317 status = CCSDS_TM_VALID;
314 }
318 }
315 break;
319 break;
316 case TC_SUBTYPE_LOAD_COMM:
320 case TC_SUBTYPE_LOAD_COMM:
317 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
321 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
318 status = WRONG_LEN_PKT;
322 status = WRONG_LEN_PKT;
319 }
323 }
320 else {
324 else {
321 status = CCSDS_TM_VALID;
325 status = CCSDS_TM_VALID;
322 }
326 }
323 break;
327 break;
324 case TC_SUBTYPE_LOAD_NORM:
328 case TC_SUBTYPE_LOAD_NORM:
325 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
329 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
326 status = WRONG_LEN_PKT;
330 status = WRONG_LEN_PKT;
327 }
331 }
328 else {
332 else {
329 status = CCSDS_TM_VALID;
333 status = CCSDS_TM_VALID;
330 }
334 }
331 break;
335 break;
332 case TC_SUBTYPE_LOAD_BURST:
336 case TC_SUBTYPE_LOAD_BURST:
333 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
337 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
334 status = WRONG_LEN_PKT;
338 status = WRONG_LEN_PKT;
335 }
339 }
336 else {
340 else {
337 status = CCSDS_TM_VALID;
341 status = CCSDS_TM_VALID;
338 }
342 }
339 break;
343 break;
340 case TC_SUBTYPE_LOAD_SBM1:
344 case TC_SUBTYPE_LOAD_SBM1:
341 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
345 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
342 status = WRONG_LEN_PKT;
346 status = WRONG_LEN_PKT;
343 }
347 }
344 else {
348 else {
345 status = CCSDS_TM_VALID;
349 status = CCSDS_TM_VALID;
346 }
350 }
347 break;
351 break;
348 case TC_SUBTYPE_LOAD_SBM2:
352 case TC_SUBTYPE_LOAD_SBM2:
349 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
353 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
350 status = WRONG_LEN_PKT;
354 status = WRONG_LEN_PKT;
351 }
355 }
352 else {
356 else {
353 status = CCSDS_TM_VALID;
357 status = CCSDS_TM_VALID;
354 }
358 }
355 break;
359 break;
356 case TC_SUBTYPE_DUMP:
360 case TC_SUBTYPE_DUMP:
357 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
361 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
358 status = WRONG_LEN_PKT;
362 status = WRONG_LEN_PKT;
359 }
363 }
360 else {
364 else {
361 status = CCSDS_TM_VALID;
365 status = CCSDS_TM_VALID;
362 }
366 }
363 break;
367 break;
364 case TC_SUBTYPE_ENTER:
368 case TC_SUBTYPE_ENTER:
365 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
369 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
366 status = WRONG_LEN_PKT;
370 status = WRONG_LEN_PKT;
367 }
371 }
368 else {
372 else {
369 status = CCSDS_TM_VALID;
373 status = CCSDS_TM_VALID;
370 }
374 }
371 break;
375 break;
372 case TC_SUBTYPE_UPDT_INFO:
376 case TC_SUBTYPE_UPDT_INFO:
373 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
377 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
374 status = WRONG_LEN_PKT;
378 status = WRONG_LEN_PKT;
375 }
379 }
376 else {
380 else {
377 status = CCSDS_TM_VALID;
381 status = CCSDS_TM_VALID;
378 }
382 }
379 break;
383 break;
380 case TC_SUBTYPE_EN_CAL:
384 case TC_SUBTYPE_EN_CAL:
381 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
385 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
382 status = WRONG_LEN_PKT;
386 status = WRONG_LEN_PKT;
383 }
387 }
384 else {
388 else {
385 status = CCSDS_TM_VALID;
389 status = CCSDS_TM_VALID;
386 }
390 }
387 break;
391 break;
388 case TC_SUBTYPE_DIS_CAL:
392 case TC_SUBTYPE_DIS_CAL:
389 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
393 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
390 status = WRONG_LEN_PKT;
394 status = WRONG_LEN_PKT;
391 }
395 }
392 else {
396 else {
393 status = CCSDS_TM_VALID;
397 status = CCSDS_TM_VALID;
394 }
398 }
395 break;
399 break;
396 case TC_SUBTYPE_LOAD_K:
400 case TC_SUBTYPE_LOAD_K:
397 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
401 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
398 status = WRONG_LEN_PKT;
402 status = WRONG_LEN_PKT;
399 }
403 }
400 else {
404 else {
401 status = CCSDS_TM_VALID;
405 status = CCSDS_TM_VALID;
402 }
406 }
403 break;
407 break;
404 case TC_SUBTYPE_DUMP_K:
408 case TC_SUBTYPE_DUMP_K:
405 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
409 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
406 status = WRONG_LEN_PKT;
410 status = WRONG_LEN_PKT;
407 }
411 }
408 else {
412 else {
409 status = CCSDS_TM_VALID;
413 status = CCSDS_TM_VALID;
410 }
414 }
411 break;
415 break;
412 case TC_SUBTYPE_LOAD_FBINS:
416 case TC_SUBTYPE_LOAD_FBINS:
413 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
417 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
414 status = WRONG_LEN_PKT;
418 status = WRONG_LEN_PKT;
415 }
419 }
416 else {
420 else {
417 status = CCSDS_TM_VALID;
421 status = CCSDS_TM_VALID;
418 }
422 }
419 break;
423 break;
420 case TC_SUBTYPE_LOAD_FILTER_PAR:
424 case TC_SUBTYPE_LOAD_FILTER_PAR:
421 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
425 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
422 status = WRONG_LEN_PKT;
426 status = WRONG_LEN_PKT;
423 }
427 }
424 else {
428 else {
425 status = CCSDS_TM_VALID;
429 status = CCSDS_TM_VALID;
426 }
430 }
427 break;
431 break;
428 case TC_SUBTYPE_UPDT_TIME:
432 case TC_SUBTYPE_UPDT_TIME:
429 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
433 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
430 status = WRONG_LEN_PKT;
434 status = WRONG_LEN_PKT;
431 }
435 }
432 else {
436 else {
433 status = CCSDS_TM_VALID;
437 status = CCSDS_TM_VALID;
434 }
438 }
435 break;
439 break;
436 default: // if the subtype is not a legal value, return ILL_SUBTYPE
440 default: // if the subtype is not a legal value, return ILL_SUBTYPE
437 status = ILL_SUBTYPE;
441 status = ILL_SUBTYPE;
438 break ;
442 break ;
439 }
443 }
440
444
441 return status;
445 return status;
442 }
446 }
443
447
444 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
448 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
445 {
449 {
446 /** This function checks the CRC validity of the corresponding TeleCommand packet.
450 /** This function checks the CRC validity of the corresponding TeleCommand packet.
447 *
451 *
448 * @param TCPacket points to the TeleCommand packet to check.
452 * @param TCPacket points to the TeleCommand packet to check.
449 * @param length is the length of the TC packet.
453 * @param length is the length of the TC packet.
450 *
454 *
451 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
455 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
452 *
456 *
453 */
457 */
454
458
455 int status;
459 int status;
456 unsigned char * CCSDSContent;
460 unsigned char * CCSDSContent;
457
461
462 status = INCOR_CHECKSUM;
463
458 CCSDSContent = (unsigned char*) TCPacket->packetID;
464 CCSDSContent = (unsigned char*) TCPacket->packetID;
459 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
465 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
460
466
461 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
467 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
462 status = INCOR_CHECKSUM;
468 status = INCOR_CHECKSUM;
463 }
469 }
464 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
470 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
465 status = INCOR_CHECKSUM;
471 status = INCOR_CHECKSUM;
466 }
472 }
467 else {
473 else {
468 status = CCSDS_TM_VALID;
474 status = CCSDS_TM_VALID;
469 }
475 }
470
476
471 return status;
477 return status;
472 }
478 }
473
479
474
480
475
481
@@ -1,1654 +1,1661
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
35 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
43
39 status = get_message_queue_id_recv( &queue_rcv_id );
44 status = get_message_queue_id_recv( &queue_rcv_id );
40 if (status != RTEMS_SUCCESSFUL)
45 if (status != RTEMS_SUCCESSFUL)
41 {
46 {
42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
43 }
48 }
44
49
45 status = get_message_queue_id_send( &queue_snd_id );
50 status = get_message_queue_id_send( &queue_snd_id );
46 if (status != RTEMS_SUCCESSFUL)
51 if (status != RTEMS_SUCCESSFUL)
47 {
52 {
48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
49 }
54 }
50
55
51 result = LFR_SUCCESSFUL;
56 result = LFR_SUCCESSFUL;
52 subtype = 0; // subtype of the current TC packet
57 subtype = 0; // subtype of the current TC packet
53
58
54 BOOT_PRINTF("in ACTN *** \n");
59 BOOT_PRINTF("in ACTN *** \n");
55
60
56 while(1)
61 while(1)
57 {
62 {
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 getTime( time ); // set time to the current time
65 getTime( time ); // set time to the current time
61 if (status!=RTEMS_SUCCESSFUL)
66 if (status!=RTEMS_SUCCESSFUL)
62 {
67 {
63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
64 }
69 }
65 else
70 else
66 {
71 {
67 subtype = TC.serviceSubType;
72 subtype = TC.serviceSubType;
68 switch(subtype)
73 switch(subtype)
69 {
74 {
70 case TC_SUBTYPE_RESET:
75 case TC_SUBTYPE_RESET:
71 result = action_reset( &TC, queue_snd_id, time );
76 result = action_reset( &TC, queue_snd_id, time );
72 close_action( &TC, result, queue_snd_id );
77 close_action( &TC, result, queue_snd_id );
73 break;
78 break;
74 case TC_SUBTYPE_LOAD_COMM:
79 case TC_SUBTYPE_LOAD_COMM:
75 result = action_load_common_par( &TC );
80 result = action_load_common_par( &TC );
76 close_action( &TC, result, queue_snd_id );
81 close_action( &TC, result, queue_snd_id );
77 break;
82 break;
78 case TC_SUBTYPE_LOAD_NORM:
83 case TC_SUBTYPE_LOAD_NORM:
79 result = action_load_normal_par( &TC, queue_snd_id, time );
84 result = action_load_normal_par( &TC, queue_snd_id, time );
80 close_action( &TC, result, queue_snd_id );
85 close_action( &TC, result, queue_snd_id );
81 break;
86 break;
82 case TC_SUBTYPE_LOAD_BURST:
87 case TC_SUBTYPE_LOAD_BURST:
83 result = action_load_burst_par( &TC, queue_snd_id, time );
88 result = action_load_burst_par( &TC, queue_snd_id, time );
84 close_action( &TC, result, queue_snd_id );
89 close_action( &TC, result, queue_snd_id );
85 break;
90 break;
86 case TC_SUBTYPE_LOAD_SBM1:
91 case TC_SUBTYPE_LOAD_SBM1:
87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 close_action( &TC, result, queue_snd_id );
93 close_action( &TC, result, queue_snd_id );
89 break;
94 break;
90 case TC_SUBTYPE_LOAD_SBM2:
95 case TC_SUBTYPE_LOAD_SBM2:
91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 close_action( &TC, result, queue_snd_id );
97 close_action( &TC, result, queue_snd_id );
93 break;
98 break;
94 case TC_SUBTYPE_DUMP:
99 case TC_SUBTYPE_DUMP:
95 result = action_dump_par( &TC, queue_snd_id );
100 result = action_dump_par( &TC, queue_snd_id );
96 close_action( &TC, result, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
97 break;
102 break;
98 case TC_SUBTYPE_ENTER:
103 case TC_SUBTYPE_ENTER:
99 result = action_enter_mode( &TC, queue_snd_id );
104 result = action_enter_mode( &TC, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
101 break;
106 break;
102 case TC_SUBTYPE_UPDT_INFO:
107 case TC_SUBTYPE_UPDT_INFO:
103 result = action_update_info( &TC, queue_snd_id );
108 result = action_update_info( &TC, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
105 break;
110 break;
106 case TC_SUBTYPE_EN_CAL:
111 case TC_SUBTYPE_EN_CAL:
107 result = action_enable_calibration( &TC, queue_snd_id, time );
112 result = action_enable_calibration( &TC, queue_snd_id, time );
108 close_action( &TC, result, queue_snd_id );
113 close_action( &TC, result, queue_snd_id );
109 break;
114 break;
110 case TC_SUBTYPE_DIS_CAL:
115 case TC_SUBTYPE_DIS_CAL:
111 result = action_disable_calibration( &TC, queue_snd_id, time );
116 result = action_disable_calibration( &TC, queue_snd_id, time );
112 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
113 break;
118 break;
114 case TC_SUBTYPE_LOAD_K:
119 case TC_SUBTYPE_LOAD_K:
115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
116 close_action( &TC, result, queue_snd_id );
121 close_action( &TC, result, queue_snd_id );
117 break;
122 break;
118 case TC_SUBTYPE_DUMP_K:
123 case TC_SUBTYPE_DUMP_K:
119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
120 close_action( &TC, result, queue_snd_id );
125 close_action( &TC, result, queue_snd_id );
121 break;
126 break;
122 case TC_SUBTYPE_LOAD_FBINS:
127 case TC_SUBTYPE_LOAD_FBINS:
123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
124 close_action( &TC, result, queue_snd_id );
129 close_action( &TC, result, queue_snd_id );
125 break;
130 break;
126 case TC_SUBTYPE_LOAD_FILTER_PAR:
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
127 result = action_load_filter_par( &TC, queue_snd_id, time );
132 result = action_load_filter_par( &TC, queue_snd_id, time );
128 close_action( &TC, result, queue_snd_id );
133 close_action( &TC, result, queue_snd_id );
129 break;
134 break;
130 case TC_SUBTYPE_UPDT_TIME:
135 case TC_SUBTYPE_UPDT_TIME:
131 result = action_update_time( &TC );
136 result = action_update_time( &TC );
132 close_action( &TC, result, queue_snd_id );
137 close_action( &TC, result, queue_snd_id );
133 break;
138 break;
134 default:
139 default:
135 break;
140 break;
136 }
141 }
137 }
142 }
138 }
143 }
139 }
144 }
140
145
141 //***********
146 //***********
142 // TC ACTIONS
147 // TC ACTIONS
143
148
144 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 {
150 {
146 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
147 *
152 *
148 * @param TC points to the TeleCommand packet that is being processed
153 * @param TC points to the TeleCommand packet that is being processed
149 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
150 *
155 *
151 */
156 */
152
157
153 PRINTF("this is the end!!!\n");
158 PRINTF("this is the end!!!\n");
154 exit(0);
159 exit(0);
155
160
156 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
157
162
158 return LFR_DEFAULT;
163 return LFR_DEFAULT;
159 }
164 }
160
165
161 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
162 {
167 {
163 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
164 *
169 *
165 * @param TC points to the TeleCommand packet that is being processed
170 * @param TC points to the TeleCommand packet that is being processed
166 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
167 *
172 *
168 */
173 */
169
174
170 rtems_status_code status;
175 rtems_status_code status;
171 unsigned char requestedMode;
176 unsigned char requestedMode;
172 unsigned int *transitionCoarseTime_ptr;
177 unsigned int *transitionCoarseTime_ptr;
173 unsigned int transitionCoarseTime;
178 unsigned int transitionCoarseTime;
174 unsigned char * bytePosPtr;
179 unsigned char * bytePosPtr;
175
180
176 bytePosPtr = (unsigned char *) &TC->packetID;
181 bytePosPtr = (unsigned char *) &TC->packetID;
177
182
178 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
183 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
179 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
184 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
180 transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK;
185 transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK;
181
186
182 status = check_mode_value( requestedMode );
187 status = check_mode_value( requestedMode );
183
188
184 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
189 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
185 {
190 {
186 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
191 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
187 }
192 }
188
193
189 else // the mode value is valid, check the transition
194 else // the mode value is valid, check the transition
190 {
195 {
191 status = check_mode_transition(requestedMode);
196 status = check_mode_transition(requestedMode);
192 if (status != LFR_SUCCESSFUL)
197 if (status != LFR_SUCCESSFUL)
193 {
198 {
194 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
199 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
195 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
200 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
196 }
201 }
197 }
202 }
198
203
199 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
204 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
200 {
205 {
201 status = check_transition_date( transitionCoarseTime );
206 status = check_transition_date( transitionCoarseTime );
202 if (status != LFR_SUCCESSFUL)
207 if (status != LFR_SUCCESSFUL)
203 {
208 {
204 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
209 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
205 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
210 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
206 }
211 }
207 }
212 }
208
213
209 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
214 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
210 {
215 {
211 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
216 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
212
217
213 switch(requestedMode)
218 switch(requestedMode)
214 {
219 {
215 case LFR_MODE_STANDBY:
220 case LFR_MODE_STANDBY:
216 status = enter_mode_standby();
221 status = enter_mode_standby();
217 break;
222 break;
218 case LFR_MODE_NORMAL:
223 case LFR_MODE_NORMAL:
219 status = enter_mode_normal( transitionCoarseTime );
224 status = enter_mode_normal( transitionCoarseTime );
220 break;
225 break;
221 case LFR_MODE_BURST:
226 case LFR_MODE_BURST:
222 status = enter_mode_burst( transitionCoarseTime );
227 status = enter_mode_burst( transitionCoarseTime );
223 break;
228 break;
224 case LFR_MODE_SBM1:
229 case LFR_MODE_SBM1:
225 status = enter_mode_sbm1( transitionCoarseTime );
230 status = enter_mode_sbm1( transitionCoarseTime );
226 break;
231 break;
227 case LFR_MODE_SBM2:
232 case LFR_MODE_SBM2:
228 status = enter_mode_sbm2( transitionCoarseTime );
233 status = enter_mode_sbm2( transitionCoarseTime );
229 break;
234 break;
230 default:
235 default:
231 break;
236 break;
232 }
237 }
233
238
234 if (status != RTEMS_SUCCESSFUL)
239 if (status != RTEMS_SUCCESSFUL)
235 {
240 {
236 status = LFR_EXE_ERROR;
241 status = LFR_EXE_ERROR;
237 }
242 }
238 }
243 }
239
244
240 return status;
245 return status;
241 }
246 }
242
247
243 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
248 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
244 {
249 {
245 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
250 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
246 *
251 *
247 * @param TC points to the TeleCommand packet that is being processed
252 * @param TC points to the TeleCommand packet that is being processed
248 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
253 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
249 *
254 *
250 * @return LFR directive status code:
255 * @return LFR directive status code:
251 * - LFR_DEFAULT
256 * - LFR_DEFAULT
252 * - LFR_SUCCESSFUL
257 * - LFR_SUCCESSFUL
253 *
258 *
254 */
259 */
255
260
256 unsigned int val;
261 unsigned int val;
257 int result;
262 int result;
258 unsigned int status;
263 unsigned int status;
259 unsigned char mode;
264 unsigned char mode;
260 unsigned char * bytePosPtr;
265 unsigned char * bytePosPtr;
261
266
262 bytePosPtr = (unsigned char *) &TC->packetID;
267 bytePosPtr = (unsigned char *) &TC->packetID;
263
268
264 // check LFR mode
269 // check LFR mode
265 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
270 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
266 status = check_update_info_hk_lfr_mode( mode );
271 status = check_update_info_hk_lfr_mode( mode );
267 if (status == LFR_SUCCESSFUL) // check TDS mode
272 if (status == LFR_SUCCESSFUL) // check TDS mode
268 {
273 {
269 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
270 status = check_update_info_hk_tds_mode( mode );
275 status = check_update_info_hk_tds_mode( mode );
271 }
276 }
272 if (status == LFR_SUCCESSFUL) // check THR mode
277 if (status == LFR_SUCCESSFUL) // check THR mode
273 {
278 {
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
279 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
275 status = check_update_info_hk_thr_mode( mode );
280 status = check_update_info_hk_thr_mode( mode );
276 }
281 }
277 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
282 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
278 {
283 {
279 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
284 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
280 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
285 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
281 val++;
286 val++;
282 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
287 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
283 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
288 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
284 }
289 }
285
290
286 // pa_bia_status_info
291 // pa_bia_status_info
287 // => pa_bia_mode_mux_set 3 bits
292 // => pa_bia_mode_mux_set 3 bits
288 // => pa_bia_mode_hv_enabled 1 bit
293 // => pa_bia_mode_hv_enabled 1 bit
289 // => pa_bia_mode_bias1_enabled 1 bit
294 // => pa_bia_mode_bias1_enabled 1 bit
290 // => pa_bia_mode_bias2_enabled 1 bit
295 // => pa_bia_mode_bias2_enabled 1 bit
291 // => pa_bia_mode_bias3_enabled 1 bit
296 // => pa_bia_mode_bias3_enabled 1 bit
292 // => pa_bia_on_off (cp_dpu_bias_on_off)
297 // => pa_bia_on_off (cp_dpu_bias_on_off)
293 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
298 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
294 pa_bia_status_info = pa_bia_status_info
299 pa_bia_status_info = pa_bia_status_info
295 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
300 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
296
301
297 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
302 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
298
303
299 cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
304 cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
300 getReactionWheelsFrequencies( TC );
305 getReactionWheelsFrequencies( TC );
301 build_sy_lfr_rw_masks();
306 build_sy_lfr_rw_masks();
302
307
303 // once the masks are built, they have to be merged with the fbins_mask
308 // once the masks are built, they have to be merged with the fbins_mask
304 merge_fbins_masks();
309 merge_fbins_masks();
305
310
306 result = status;
311 result = status;
307
312
308 return result;
313 return result;
309 }
314 }
310
315
311 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
316 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
312 {
317 {
313 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
318 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
314 *
319 *
315 * @param TC points to the TeleCommand packet that is being processed
320 * @param TC points to the TeleCommand packet that is being processed
316 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
321 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
317 *
322 *
318 */
323 */
319
324
320 int result;
325 int result;
321
326
322 result = LFR_DEFAULT;
327 result = LFR_DEFAULT;
323
328
324 setCalibration( true );
329 setCalibration( true );
325
330
326 result = LFR_SUCCESSFUL;
331 result = LFR_SUCCESSFUL;
327
332
328 return result;
333 return result;
329 }
334 }
330
335
331 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
336 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
332 {
337 {
333 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
338 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
334 *
339 *
335 * @param TC points to the TeleCommand packet that is being processed
340 * @param TC points to the TeleCommand packet that is being processed
336 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
341 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
337 *
342 *
338 */
343 */
339
344
340 int result;
345 int result;
341
346
342 result = LFR_DEFAULT;
347 result = LFR_DEFAULT;
343
348
344 setCalibration( false );
349 setCalibration( false );
345
350
346 result = LFR_SUCCESSFUL;
351 result = LFR_SUCCESSFUL;
347
352
348 return result;
353 return result;
349 }
354 }
350
355
351 int action_update_time(ccsdsTelecommandPacket_t *TC)
356 int action_update_time(ccsdsTelecommandPacket_t *TC)
352 {
357 {
353 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
358 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
354 *
359 *
355 * @param TC points to the TeleCommand packet that is being processed
360 * @param TC points to the TeleCommand packet that is being processed
356 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
361 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
357 *
362 *
358 * @return LFR_SUCCESSFUL
363 * @return LFR_SUCCESSFUL
359 *
364 *
360 */
365 */
361
366
362 unsigned int val;
367 unsigned int val;
363
368
364 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
369 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
365 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
370 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
366 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
371 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
367 + TC->dataAndCRC[BYTE_3];
372 + TC->dataAndCRC[BYTE_3];
368
373
369 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
374 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
370 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
375 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
371 val++;
376 val++;
372 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
377 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
373 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
378 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
374
379
375 oneTcLfrUpdateTimeReceived = 1;
380 oneTcLfrUpdateTimeReceived = 1;
376
381
377 return LFR_SUCCESSFUL;
382 return LFR_SUCCESSFUL;
378 }
383 }
379
384
380 //*******************
385 //*******************
381 // ENTERING THE MODES
386 // ENTERING THE MODES
382 int check_mode_value( unsigned char requestedMode )
387 int check_mode_value( unsigned char requestedMode )
383 {
388 {
384 int status;
389 int status;
385
390
391 status = LFR_DEFAULT;
392
386 if ( (requestedMode != LFR_MODE_STANDBY)
393 if ( (requestedMode != LFR_MODE_STANDBY)
387 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
394 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
388 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
395 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
389 {
396 {
390 status = LFR_DEFAULT;
397 status = LFR_DEFAULT;
391 }
398 }
392 else
399 else
393 {
400 {
394 status = LFR_SUCCESSFUL;
401 status = LFR_SUCCESSFUL;
395 }
402 }
396
403
397 return status;
404 return status;
398 }
405 }
399
406
400 int check_mode_transition( unsigned char requestedMode )
407 int check_mode_transition( unsigned char requestedMode )
401 {
408 {
402 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
409 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
403 *
410 *
404 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
411 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
405 *
412 *
406 * @return LFR directive status codes:
413 * @return LFR directive status codes:
407 * - LFR_SUCCESSFUL - the transition is authorized
414 * - LFR_SUCCESSFUL - the transition is authorized
408 * - LFR_DEFAULT - the transition is not authorized
415 * - LFR_DEFAULT - the transition is not authorized
409 *
416 *
410 */
417 */
411
418
412 int status;
419 int status;
413
420
414 switch (requestedMode)
421 switch (requestedMode)
415 {
422 {
416 case LFR_MODE_STANDBY:
423 case LFR_MODE_STANDBY:
417 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
424 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
418 status = LFR_DEFAULT;
425 status = LFR_DEFAULT;
419 }
426 }
420 else
427 else
421 {
428 {
422 status = LFR_SUCCESSFUL;
429 status = LFR_SUCCESSFUL;
423 }
430 }
424 break;
431 break;
425 case LFR_MODE_NORMAL:
432 case LFR_MODE_NORMAL:
426 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
433 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
427 status = LFR_DEFAULT;
434 status = LFR_DEFAULT;
428 }
435 }
429 else {
436 else {
430 status = LFR_SUCCESSFUL;
437 status = LFR_SUCCESSFUL;
431 }
438 }
432 break;
439 break;
433 case LFR_MODE_BURST:
440 case LFR_MODE_BURST:
434 if ( lfrCurrentMode == LFR_MODE_BURST ) {
441 if ( lfrCurrentMode == LFR_MODE_BURST ) {
435 status = LFR_DEFAULT;
442 status = LFR_DEFAULT;
436 }
443 }
437 else {
444 else {
438 status = LFR_SUCCESSFUL;
445 status = LFR_SUCCESSFUL;
439 }
446 }
440 break;
447 break;
441 case LFR_MODE_SBM1:
448 case LFR_MODE_SBM1:
442 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
449 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
443 status = LFR_DEFAULT;
450 status = LFR_DEFAULT;
444 }
451 }
445 else {
452 else {
446 status = LFR_SUCCESSFUL;
453 status = LFR_SUCCESSFUL;
447 }
454 }
448 break;
455 break;
449 case LFR_MODE_SBM2:
456 case LFR_MODE_SBM2:
450 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
457 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
451 status = LFR_DEFAULT;
458 status = LFR_DEFAULT;
452 }
459 }
453 else {
460 else {
454 status = LFR_SUCCESSFUL;
461 status = LFR_SUCCESSFUL;
455 }
462 }
456 break;
463 break;
457 default:
464 default:
458 status = LFR_DEFAULT;
465 status = LFR_DEFAULT;
459 break;
466 break;
460 }
467 }
461
468
462 return status;
469 return status;
463 }
470 }
464
471
465 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
472 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
466 {
473 {
467 if (transitionCoarseTime == 0)
474 if (transitionCoarseTime == 0)
468 {
475 {
469 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
476 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
470 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
477 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
471 }
478 }
472 else
479 else
473 {
480 {
474 lastValidEnterModeTime = transitionCoarseTime;
481 lastValidEnterModeTime = transitionCoarseTime;
475 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
482 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
476 }
483 }
477 }
484 }
478
485
479 int check_transition_date( unsigned int transitionCoarseTime )
486 int check_transition_date( unsigned int transitionCoarseTime )
480 {
487 {
481 int status;
488 int status;
482 unsigned int localCoarseTime;
489 unsigned int localCoarseTime;
483 unsigned int deltaCoarseTime;
490 unsigned int deltaCoarseTime;
484
491
485 status = LFR_SUCCESSFUL;
492 status = LFR_SUCCESSFUL;
486
493
487 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
494 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
488 {
495 {
489 status = LFR_SUCCESSFUL;
496 status = LFR_SUCCESSFUL;
490 }
497 }
491 else
498 else
492 {
499 {
493 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
500 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
494
501
495 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
502 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
496
503
497 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
504 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
498 {
505 {
499 status = LFR_DEFAULT;
506 status = LFR_DEFAULT;
500 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
507 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
501 }
508 }
502
509
503 if (status == LFR_SUCCESSFUL)
510 if (status == LFR_SUCCESSFUL)
504 {
511 {
505 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
512 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
506 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
513 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
507 {
514 {
508 status = LFR_DEFAULT;
515 status = LFR_DEFAULT;
509 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
516 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
510 }
517 }
511 }
518 }
512 }
519 }
513
520
514 return status;
521 return status;
515 }
522 }
516
523
517 int restart_asm_activities( unsigned char lfrRequestedMode )
524 int restart_asm_activities( unsigned char lfrRequestedMode )
518 {
525 {
519 rtems_status_code status;
526 rtems_status_code status;
520
527
521 status = stop_spectral_matrices();
528 status = stop_spectral_matrices();
522
529
523 thisIsAnASMRestart = 1;
530 thisIsAnASMRestart = 1;
524
531
525 status = restart_asm_tasks( lfrRequestedMode );
532 status = restart_asm_tasks( lfrRequestedMode );
526
533
527 launch_spectral_matrix();
534 launch_spectral_matrix();
528
535
529 return status;
536 return status;
530 }
537 }
531
538
532 int stop_spectral_matrices( void )
539 int stop_spectral_matrices( void )
533 {
540 {
534 /** This function stops and restarts the current mode average spectral matrices activities.
541 /** This function stops and restarts the current mode average spectral matrices activities.
535 *
542 *
536 * @return RTEMS directive status codes:
543 * @return RTEMS directive status codes:
537 * - RTEMS_SUCCESSFUL - task restarted successfully
544 * - RTEMS_SUCCESSFUL - task restarted successfully
538 * - RTEMS_INVALID_ID - task id invalid
545 * - RTEMS_INVALID_ID - task id invalid
539 * - RTEMS_ALREADY_SUSPENDED - task already suspended
546 * - RTEMS_ALREADY_SUSPENDED - task already suspended
540 *
547 *
541 */
548 */
542
549
543 rtems_status_code status;
550 rtems_status_code status;
544
551
545 status = RTEMS_SUCCESSFUL;
552 status = RTEMS_SUCCESSFUL;
546
553
547 // (1) mask interruptions
554 // (1) mask interruptions
548 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
555 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
549
556
550 // (2) reset spectral matrices registers
557 // (2) reset spectral matrices registers
551 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
558 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
552 reset_sm_status();
559 reset_sm_status();
553
560
554 // (3) clear interruptions
561 // (3) clear interruptions
555 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
562 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
556
563
557 // suspend several tasks
564 // suspend several tasks
558 if (lfrCurrentMode != LFR_MODE_STANDBY) {
565 if (lfrCurrentMode != LFR_MODE_STANDBY) {
559 status = suspend_asm_tasks();
566 status = suspend_asm_tasks();
560 }
567 }
561
568
562 if (status != RTEMS_SUCCESSFUL)
569 if (status != RTEMS_SUCCESSFUL)
563 {
570 {
564 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
571 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
565 }
572 }
566
573
567 return status;
574 return status;
568 }
575 }
569
576
570 int stop_current_mode( void )
577 int stop_current_mode( void )
571 {
578 {
572 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
579 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
573 *
580 *
574 * @return RTEMS directive status codes:
581 * @return RTEMS directive status codes:
575 * - RTEMS_SUCCESSFUL - task restarted successfully
582 * - RTEMS_SUCCESSFUL - task restarted successfully
576 * - RTEMS_INVALID_ID - task id invalid
583 * - RTEMS_INVALID_ID - task id invalid
577 * - RTEMS_ALREADY_SUSPENDED - task already suspended
584 * - RTEMS_ALREADY_SUSPENDED - task already suspended
578 *
585 *
579 */
586 */
580
587
581 rtems_status_code status;
588 rtems_status_code status;
582
589
583 status = RTEMS_SUCCESSFUL;
590 status = RTEMS_SUCCESSFUL;
584
591
585 // (1) mask interruptions
592 // (1) mask interruptions
586 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
593 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
587 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
594 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
588
595
589 // (2) reset waveform picker registers
596 // (2) reset waveform picker registers
590 reset_wfp_burst_enable(); // reset burst and enable bits
597 reset_wfp_burst_enable(); // reset burst and enable bits
591 reset_wfp_status(); // reset all the status bits
598 reset_wfp_status(); // reset all the status bits
592
599
593 // (3) reset spectral matrices registers
600 // (3) reset spectral matrices registers
594 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
601 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
595 reset_sm_status();
602 reset_sm_status();
596
603
597 // reset lfr VHDL module
604 // reset lfr VHDL module
598 reset_lfr();
605 reset_lfr();
599
606
600 reset_extractSWF(); // reset the extractSWF flag to false
607 reset_extractSWF(); // reset the extractSWF flag to false
601
608
602 // (4) clear interruptions
609 // (4) clear interruptions
603 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
610 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
604 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
611 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
605
612
606 // suspend several tasks
613 // suspend several tasks
607 if (lfrCurrentMode != LFR_MODE_STANDBY) {
614 if (lfrCurrentMode != LFR_MODE_STANDBY) {
608 status = suspend_science_tasks();
615 status = suspend_science_tasks();
609 }
616 }
610
617
611 if (status != RTEMS_SUCCESSFUL)
618 if (status != RTEMS_SUCCESSFUL)
612 {
619 {
613 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
620 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
614 }
621 }
615
622
616 return status;
623 return status;
617 }
624 }
618
625
619 int enter_mode_standby( void )
626 int enter_mode_standby( void )
620 {
627 {
621 /** This function is used to put LFR in the STANDBY mode.
628 /** This function is used to put LFR in the STANDBY mode.
622 *
629 *
623 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
630 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
624 *
631 *
625 * @return RTEMS directive status codes:
632 * @return RTEMS directive status codes:
626 * - RTEMS_SUCCESSFUL - task restarted successfully
633 * - RTEMS_SUCCESSFUL - task restarted successfully
627 * - RTEMS_INVALID_ID - task id invalid
634 * - RTEMS_INVALID_ID - task id invalid
628 * - RTEMS_INCORRECT_STATE - task never started
635 * - RTEMS_INCORRECT_STATE - task never started
629 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
636 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
630 *
637 *
631 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
638 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
632 * is immediate.
639 * is immediate.
633 *
640 *
634 */
641 */
635
642
636 int status;
643 int status;
637
644
638 status = stop_current_mode(); // STOP THE CURRENT MODE
645 status = stop_current_mode(); // STOP THE CURRENT MODE
639
646
640 #ifdef PRINT_TASK_STATISTICS
647 #ifdef PRINT_TASK_STATISTICS
641 rtems_cpu_usage_report();
648 rtems_cpu_usage_report();
642 #endif
649 #endif
643
650
644 #ifdef PRINT_STACK_REPORT
651 #ifdef PRINT_STACK_REPORT
645 PRINTF("stack report selected\n")
652 PRINTF("stack report selected\n")
646 rtems_stack_checker_report_usage();
653 rtems_stack_checker_report_usage();
647 #endif
654 #endif
648
655
649 return status;
656 return status;
650 }
657 }
651
658
652 int enter_mode_normal( unsigned int transitionCoarseTime )
659 int enter_mode_normal( unsigned int transitionCoarseTime )
653 {
660 {
654 /** This function is used to start the NORMAL mode.
661 /** This function is used to start the NORMAL mode.
655 *
662 *
656 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
663 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
657 *
664 *
658 * @return RTEMS directive status codes:
665 * @return RTEMS directive status codes:
659 * - RTEMS_SUCCESSFUL - task restarted successfully
666 * - RTEMS_SUCCESSFUL - task restarted successfully
660 * - RTEMS_INVALID_ID - task id invalid
667 * - RTEMS_INVALID_ID - task id invalid
661 * - RTEMS_INCORRECT_STATE - task never started
668 * - RTEMS_INCORRECT_STATE - task never started
662 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
669 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
663 *
670 *
664 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
671 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
665 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
672 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
666 *
673 *
667 */
674 */
668
675
669 int status;
676 int status;
670
677
671 #ifdef PRINT_TASK_STATISTICS
678 #ifdef PRINT_TASK_STATISTICS
672 rtems_cpu_usage_reset();
679 rtems_cpu_usage_reset();
673 #endif
680 #endif
674
681
675 status = RTEMS_UNSATISFIED;
682 status = RTEMS_UNSATISFIED;
676
683
677 switch( lfrCurrentMode )
684 switch( lfrCurrentMode )
678 {
685 {
679 case LFR_MODE_STANDBY:
686 case LFR_MODE_STANDBY:
680 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
687 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
681 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
688 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
682 {
689 {
683 launch_spectral_matrix( );
690 launch_spectral_matrix( );
684 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
691 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
685 }
692 }
686 break;
693 break;
687 case LFR_MODE_BURST:
694 case LFR_MODE_BURST:
688 status = stop_current_mode(); // stop the current mode
695 status = stop_current_mode(); // stop the current mode
689 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
696 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
690 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
697 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
691 {
698 {
692 launch_spectral_matrix( );
699 launch_spectral_matrix( );
693 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
700 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
694 }
701 }
695 break;
702 break;
696 case LFR_MODE_SBM1:
703 case LFR_MODE_SBM1:
697 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
704 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
698 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
705 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
699 update_last_valid_transition_date( transitionCoarseTime );
706 update_last_valid_transition_date( transitionCoarseTime );
700 break;
707 break;
701 case LFR_MODE_SBM2:
708 case LFR_MODE_SBM2:
702 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
709 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
703 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
710 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
704 update_last_valid_transition_date( transitionCoarseTime );
711 update_last_valid_transition_date( transitionCoarseTime );
705 break;
712 break;
706 default:
713 default:
707 break;
714 break;
708 }
715 }
709
716
710 if (status != RTEMS_SUCCESSFUL)
717 if (status != RTEMS_SUCCESSFUL)
711 {
718 {
712 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
719 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
713 status = RTEMS_UNSATISFIED;
720 status = RTEMS_UNSATISFIED;
714 }
721 }
715
722
716 return status;
723 return status;
717 }
724 }
718
725
719 int enter_mode_burst( unsigned int transitionCoarseTime )
726 int enter_mode_burst( unsigned int transitionCoarseTime )
720 {
727 {
721 /** This function is used to start the BURST mode.
728 /** This function is used to start the BURST mode.
722 *
729 *
723 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
730 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
724 *
731 *
725 * @return RTEMS directive status codes:
732 * @return RTEMS directive status codes:
726 * - RTEMS_SUCCESSFUL - task restarted successfully
733 * - RTEMS_SUCCESSFUL - task restarted successfully
727 * - RTEMS_INVALID_ID - task id invalid
734 * - RTEMS_INVALID_ID - task id invalid
728 * - RTEMS_INCORRECT_STATE - task never started
735 * - RTEMS_INCORRECT_STATE - task never started
729 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
736 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
730 *
737 *
731 * The way the BURST mode is started does not depend on the LFR current mode.
738 * The way the BURST mode is started does not depend on the LFR current mode.
732 *
739 *
733 */
740 */
734
741
735
742
736 int status;
743 int status;
737
744
738 #ifdef PRINT_TASK_STATISTICS
745 #ifdef PRINT_TASK_STATISTICS
739 rtems_cpu_usage_reset();
746 rtems_cpu_usage_reset();
740 #endif
747 #endif
741
748
742 status = stop_current_mode(); // stop the current mode
749 status = stop_current_mode(); // stop the current mode
743 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
750 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
744 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
751 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
745 {
752 {
746 launch_spectral_matrix( );
753 launch_spectral_matrix( );
747 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
754 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
748 }
755 }
749
756
750 if (status != RTEMS_SUCCESSFUL)
757 if (status != RTEMS_SUCCESSFUL)
751 {
758 {
752 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
759 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
753 status = RTEMS_UNSATISFIED;
760 status = RTEMS_UNSATISFIED;
754 }
761 }
755
762
756 return status;
763 return status;
757 }
764 }
758
765
759 int enter_mode_sbm1( unsigned int transitionCoarseTime )
766 int enter_mode_sbm1( unsigned int transitionCoarseTime )
760 {
767 {
761 /** This function is used to start the SBM1 mode.
768 /** This function is used to start the SBM1 mode.
762 *
769 *
763 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
770 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
764 *
771 *
765 * @return RTEMS directive status codes:
772 * @return RTEMS directive status codes:
766 * - RTEMS_SUCCESSFUL - task restarted successfully
773 * - RTEMS_SUCCESSFUL - task restarted successfully
767 * - RTEMS_INVALID_ID - task id invalid
774 * - RTEMS_INVALID_ID - task id invalid
768 * - RTEMS_INCORRECT_STATE - task never started
775 * - RTEMS_INCORRECT_STATE - task never started
769 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
776 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
770 *
777 *
771 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
778 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
772 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
779 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
773 * cases, the acquisition is completely restarted.
780 * cases, the acquisition is completely restarted.
774 *
781 *
775 */
782 */
776
783
777 int status;
784 int status;
778
785
779 #ifdef PRINT_TASK_STATISTICS
786 #ifdef PRINT_TASK_STATISTICS
780 rtems_cpu_usage_reset();
787 rtems_cpu_usage_reset();
781 #endif
788 #endif
782
789
783 status = RTEMS_UNSATISFIED;
790 status = RTEMS_UNSATISFIED;
784
791
785 switch( lfrCurrentMode )
792 switch( lfrCurrentMode )
786 {
793 {
787 case LFR_MODE_STANDBY:
794 case LFR_MODE_STANDBY:
788 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
795 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
789 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
796 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
790 {
797 {
791 launch_spectral_matrix( );
798 launch_spectral_matrix( );
792 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
799 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
793 }
800 }
794 break;
801 break;
795 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
802 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
796 status = restart_asm_activities( LFR_MODE_SBM1 );
803 status = restart_asm_activities( LFR_MODE_SBM1 );
797 status = LFR_SUCCESSFUL;
804 status = LFR_SUCCESSFUL;
798 update_last_valid_transition_date( transitionCoarseTime );
805 update_last_valid_transition_date( transitionCoarseTime );
799 break;
806 break;
800 case LFR_MODE_BURST:
807 case LFR_MODE_BURST:
801 status = stop_current_mode(); // stop the current mode
808 status = stop_current_mode(); // stop the current mode
802 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
809 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
803 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
810 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
804 {
811 {
805 launch_spectral_matrix( );
812 launch_spectral_matrix( );
806 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
813 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
807 }
814 }
808 break;
815 break;
809 case LFR_MODE_SBM2:
816 case LFR_MODE_SBM2:
810 status = restart_asm_activities( LFR_MODE_SBM1 );
817 status = restart_asm_activities( LFR_MODE_SBM1 );
811 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
818 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
812 update_last_valid_transition_date( transitionCoarseTime );
819 update_last_valid_transition_date( transitionCoarseTime );
813 break;
820 break;
814 default:
821 default:
815 break;
822 break;
816 }
823 }
817
824
818 if (status != RTEMS_SUCCESSFUL)
825 if (status != RTEMS_SUCCESSFUL)
819 {
826 {
820 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
827 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
821 status = RTEMS_UNSATISFIED;
828 status = RTEMS_UNSATISFIED;
822 }
829 }
823
830
824 return status;
831 return status;
825 }
832 }
826
833
827 int enter_mode_sbm2( unsigned int transitionCoarseTime )
834 int enter_mode_sbm2( unsigned int transitionCoarseTime )
828 {
835 {
829 /** This function is used to start the SBM2 mode.
836 /** This function is used to start the SBM2 mode.
830 *
837 *
831 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
838 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
832 *
839 *
833 * @return RTEMS directive status codes:
840 * @return RTEMS directive status codes:
834 * - RTEMS_SUCCESSFUL - task restarted successfully
841 * - RTEMS_SUCCESSFUL - task restarted successfully
835 * - RTEMS_INVALID_ID - task id invalid
842 * - RTEMS_INVALID_ID - task id invalid
836 * - RTEMS_INCORRECT_STATE - task never started
843 * - RTEMS_INCORRECT_STATE - task never started
837 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
844 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
838 *
845 *
839 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
846 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
840 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
847 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
841 * cases, the acquisition is completely restarted.
848 * cases, the acquisition is completely restarted.
842 *
849 *
843 */
850 */
844
851
845 int status;
852 int status;
846
853
847 #ifdef PRINT_TASK_STATISTICS
854 #ifdef PRINT_TASK_STATISTICS
848 rtems_cpu_usage_reset();
855 rtems_cpu_usage_reset();
849 #endif
856 #endif
850
857
851 status = RTEMS_UNSATISFIED;
858 status = RTEMS_UNSATISFIED;
852
859
853 switch( lfrCurrentMode )
860 switch( lfrCurrentMode )
854 {
861 {
855 case LFR_MODE_STANDBY:
862 case LFR_MODE_STANDBY:
856 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
863 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
857 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
864 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
858 {
865 {
859 launch_spectral_matrix( );
866 launch_spectral_matrix( );
860 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
867 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
861 }
868 }
862 break;
869 break;
863 case LFR_MODE_NORMAL:
870 case LFR_MODE_NORMAL:
864 status = restart_asm_activities( LFR_MODE_SBM2 );
871 status = restart_asm_activities( LFR_MODE_SBM2 );
865 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
872 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
866 update_last_valid_transition_date( transitionCoarseTime );
873 update_last_valid_transition_date( transitionCoarseTime );
867 break;
874 break;
868 case LFR_MODE_BURST:
875 case LFR_MODE_BURST:
869 status = stop_current_mode(); // stop the current mode
876 status = stop_current_mode(); // stop the current mode
870 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
877 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
871 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
878 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
872 {
879 {
873 launch_spectral_matrix( );
880 launch_spectral_matrix( );
874 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
881 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
875 }
882 }
876 break;
883 break;
877 case LFR_MODE_SBM1:
884 case LFR_MODE_SBM1:
878 status = restart_asm_activities( LFR_MODE_SBM2 );
885 status = restart_asm_activities( LFR_MODE_SBM2 );
879 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
886 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
880 update_last_valid_transition_date( transitionCoarseTime );
887 update_last_valid_transition_date( transitionCoarseTime );
881 break;
888 break;
882 default:
889 default:
883 break;
890 break;
884 }
891 }
885
892
886 if (status != RTEMS_SUCCESSFUL)
893 if (status != RTEMS_SUCCESSFUL)
887 {
894 {
888 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
895 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
889 status = RTEMS_UNSATISFIED;
896 status = RTEMS_UNSATISFIED;
890 }
897 }
891
898
892 return status;
899 return status;
893 }
900 }
894
901
895 int restart_science_tasks( unsigned char lfrRequestedMode )
902 int restart_science_tasks( unsigned char lfrRequestedMode )
896 {
903 {
897 /** This function is used to restart all science tasks.
904 /** This function is used to restart all science tasks.
898 *
905 *
899 * @return RTEMS directive status codes:
906 * @return RTEMS directive status codes:
900 * - RTEMS_SUCCESSFUL - task restarted successfully
907 * - RTEMS_SUCCESSFUL - task restarted successfully
901 * - RTEMS_INVALID_ID - task id invalid
908 * - RTEMS_INVALID_ID - task id invalid
902 * - RTEMS_INCORRECT_STATE - task never started
909 * - RTEMS_INCORRECT_STATE - task never started
903 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
910 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
904 *
911 *
905 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
912 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
906 *
913 *
907 */
914 */
908
915
909 rtems_status_code status[NB_SCIENCE_TASKS];
916 rtems_status_code status[NB_SCIENCE_TASKS];
910 rtems_status_code ret;
917 rtems_status_code ret;
911
918
912 ret = RTEMS_SUCCESSFUL;
919 ret = RTEMS_SUCCESSFUL;
913
920
914 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
921 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
915 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
922 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
916 {
923 {
917 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
924 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
918 }
925 }
919
926
920 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
927 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
921 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
928 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
922 {
929 {
923 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
930 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
924 }
931 }
925
932
926 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
933 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
927 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
934 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
928 {
935 {
929 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
936 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
930 }
937 }
931
938
932 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
939 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
933 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
940 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
934 {
941 {
935 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
942 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
936 }
943 }
937
944
938 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
945 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
939 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
946 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
940 {
947 {
941 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
948 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
942 }
949 }
943
950
944 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
951 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
945 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
952 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
946 {
953 {
947 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
954 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
948 }
955 }
949
956
950 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
957 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
951 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
958 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
952 {
959 {
953 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
960 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
954 }
961 }
955
962
956 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
963 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
957 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
964 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
958 {
965 {
959 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
966 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
960 }
967 }
961
968
962 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
969 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
963 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
970 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
964 {
971 {
965 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
972 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
966 }
973 }
967
974
968 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
975 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
969 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
976 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
970 {
977 {
971 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
978 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
972 }
979 }
973
980
974 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
981 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
975 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
982 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
976 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
983 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
977 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
984 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
978 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
985 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
979 {
986 {
980 ret = RTEMS_UNSATISFIED;
987 ret = RTEMS_UNSATISFIED;
981 }
988 }
982
989
983 return ret;
990 return ret;
984 }
991 }
985
992
986 int restart_asm_tasks( unsigned char lfrRequestedMode )
993 int restart_asm_tasks( unsigned char lfrRequestedMode )
987 {
994 {
988 /** This function is used to restart average spectral matrices tasks.
995 /** This function is used to restart average spectral matrices tasks.
989 *
996 *
990 * @return RTEMS directive status codes:
997 * @return RTEMS directive status codes:
991 * - RTEMS_SUCCESSFUL - task restarted successfully
998 * - RTEMS_SUCCESSFUL - task restarted successfully
992 * - RTEMS_INVALID_ID - task id invalid
999 * - RTEMS_INVALID_ID - task id invalid
993 * - RTEMS_INCORRECT_STATE - task never started
1000 * - RTEMS_INCORRECT_STATE - task never started
994 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1001 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
995 *
1002 *
996 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1003 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
997 *
1004 *
998 */
1005 */
999
1006
1000 rtems_status_code status[NB_ASM_TASKS];
1007 rtems_status_code status[NB_ASM_TASKS];
1001 rtems_status_code ret;
1008 rtems_status_code ret;
1002
1009
1003 ret = RTEMS_SUCCESSFUL;
1010 ret = RTEMS_SUCCESSFUL;
1004
1011
1005 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1012 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1006 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1013 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1007 {
1014 {
1008 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1015 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1009 }
1016 }
1010
1017
1011 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1018 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1012 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1019 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1013 {
1020 {
1014 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1021 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1015 }
1022 }
1016
1023
1017 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1024 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1018 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1025 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1019 {
1026 {
1020 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1027 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1021 }
1028 }
1022
1029
1023 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1030 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1024 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1031 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1025 {
1032 {
1026 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1033 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1027 }
1034 }
1028
1035
1029 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1036 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1030 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1037 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1031 {
1038 {
1032 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1039 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1033 }
1040 }
1034
1041
1035 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1042 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1036 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1043 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1037 {
1044 {
1038 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1045 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1039 }
1046 }
1040
1047
1041 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1048 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1042 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1049 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1043 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1050 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1044 {
1051 {
1045 ret = RTEMS_UNSATISFIED;
1052 ret = RTEMS_UNSATISFIED;
1046 }
1053 }
1047
1054
1048 return ret;
1055 return ret;
1049 }
1056 }
1050
1057
1051 int suspend_science_tasks( void )
1058 int suspend_science_tasks( void )
1052 {
1059 {
1053 /** This function suspends the science tasks.
1060 /** This function suspends the science tasks.
1054 *
1061 *
1055 * @return RTEMS directive status codes:
1062 * @return RTEMS directive status codes:
1056 * - RTEMS_SUCCESSFUL - task restarted successfully
1063 * - RTEMS_SUCCESSFUL - task restarted successfully
1057 * - RTEMS_INVALID_ID - task id invalid
1064 * - RTEMS_INVALID_ID - task id invalid
1058 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1065 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1059 *
1066 *
1060 */
1067 */
1061
1068
1062 rtems_status_code status;
1069 rtems_status_code status;
1063
1070
1064 PRINTF("in suspend_science_tasks\n")
1071 PRINTF("in suspend_science_tasks\n")
1065
1072
1066 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1073 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1067 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1074 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1068 {
1075 {
1069 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1076 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1070 }
1077 }
1071 else
1078 else
1072 {
1079 {
1073 status = RTEMS_SUCCESSFUL;
1080 status = RTEMS_SUCCESSFUL;
1074 }
1081 }
1075 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1082 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1076 {
1083 {
1077 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1084 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1078 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1085 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1079 {
1086 {
1080 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1087 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1081 }
1088 }
1082 else
1089 else
1083 {
1090 {
1084 status = RTEMS_SUCCESSFUL;
1091 status = RTEMS_SUCCESSFUL;
1085 }
1092 }
1086 }
1093 }
1087 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1094 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1088 {
1095 {
1089 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1096 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1090 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1097 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1091 {
1098 {
1092 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1099 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1093 }
1100 }
1094 else
1101 else
1095 {
1102 {
1096 status = RTEMS_SUCCESSFUL;
1103 status = RTEMS_SUCCESSFUL;
1097 }
1104 }
1098 }
1105 }
1099 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1106 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1100 {
1107 {
1101 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1108 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1102 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1109 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1103 {
1110 {
1104 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1111 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1105 }
1112 }
1106 else
1113 else
1107 {
1114 {
1108 status = RTEMS_SUCCESSFUL;
1115 status = RTEMS_SUCCESSFUL;
1109 }
1116 }
1110 }
1117 }
1111 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1118 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1112 {
1119 {
1113 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1120 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1114 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1121 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1115 {
1122 {
1116 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1123 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1117 }
1124 }
1118 else
1125 else
1119 {
1126 {
1120 status = RTEMS_SUCCESSFUL;
1127 status = RTEMS_SUCCESSFUL;
1121 }
1128 }
1122 }
1129 }
1123 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1130 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1124 {
1131 {
1125 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1132 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1126 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1133 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1127 {
1134 {
1128 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1135 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1129 }
1136 }
1130 else
1137 else
1131 {
1138 {
1132 status = RTEMS_SUCCESSFUL;
1139 status = RTEMS_SUCCESSFUL;
1133 }
1140 }
1134 }
1141 }
1135 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1142 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1136 {
1143 {
1137 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1144 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1138 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1145 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1139 {
1146 {
1140 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1147 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1141 }
1148 }
1142 else
1149 else
1143 {
1150 {
1144 status = RTEMS_SUCCESSFUL;
1151 status = RTEMS_SUCCESSFUL;
1145 }
1152 }
1146 }
1153 }
1147 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1154 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1148 {
1155 {
1149 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1156 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1150 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1157 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1151 {
1158 {
1152 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1159 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1153 }
1160 }
1154 else
1161 else
1155 {
1162 {
1156 status = RTEMS_SUCCESSFUL;
1163 status = RTEMS_SUCCESSFUL;
1157 }
1164 }
1158 }
1165 }
1159 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1166 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1160 {
1167 {
1161 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1168 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1162 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1169 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1163 {
1170 {
1164 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1171 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1165 }
1172 }
1166 else
1173 else
1167 {
1174 {
1168 status = RTEMS_SUCCESSFUL;
1175 status = RTEMS_SUCCESSFUL;
1169 }
1176 }
1170 }
1177 }
1171 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1178 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1172 {
1179 {
1173 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1180 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1174 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1181 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1175 {
1182 {
1176 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1183 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1177 }
1184 }
1178 else
1185 else
1179 {
1186 {
1180 status = RTEMS_SUCCESSFUL;
1187 status = RTEMS_SUCCESSFUL;
1181 }
1188 }
1182 }
1189 }
1183
1190
1184 return status;
1191 return status;
1185 }
1192 }
1186
1193
1187 int suspend_asm_tasks( void )
1194 int suspend_asm_tasks( void )
1188 {
1195 {
1189 /** This function suspends the science tasks.
1196 /** This function suspends the science tasks.
1190 *
1197 *
1191 * @return RTEMS directive status codes:
1198 * @return RTEMS directive status codes:
1192 * - RTEMS_SUCCESSFUL - task restarted successfully
1199 * - RTEMS_SUCCESSFUL - task restarted successfully
1193 * - RTEMS_INVALID_ID - task id invalid
1200 * - RTEMS_INVALID_ID - task id invalid
1194 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1201 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1195 *
1202 *
1196 */
1203 */
1197
1204
1198 rtems_status_code status;
1205 rtems_status_code status;
1199
1206
1200 PRINTF("in suspend_science_tasks\n")
1207 PRINTF("in suspend_science_tasks\n")
1201
1208
1202 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1209 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1203 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1210 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1204 {
1211 {
1205 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1212 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1206 }
1213 }
1207 else
1214 else
1208 {
1215 {
1209 status = RTEMS_SUCCESSFUL;
1216 status = RTEMS_SUCCESSFUL;
1210 }
1217 }
1211
1218
1212 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1219 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1213 {
1220 {
1214 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1221 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1215 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1222 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1216 {
1223 {
1217 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1224 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1218 }
1225 }
1219 else
1226 else
1220 {
1227 {
1221 status = RTEMS_SUCCESSFUL;
1228 status = RTEMS_SUCCESSFUL;
1222 }
1229 }
1223 }
1230 }
1224
1231
1225 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1232 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1226 {
1233 {
1227 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1234 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1228 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1235 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1229 {
1236 {
1230 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1237 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1231 }
1238 }
1232 else
1239 else
1233 {
1240 {
1234 status = RTEMS_SUCCESSFUL;
1241 status = RTEMS_SUCCESSFUL;
1235 }
1242 }
1236 }
1243 }
1237
1244
1238 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1245 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1239 {
1246 {
1240 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1247 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1241 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1248 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1242 {
1249 {
1243 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1250 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1244 }
1251 }
1245 else
1252 else
1246 {
1253 {
1247 status = RTEMS_SUCCESSFUL;
1254 status = RTEMS_SUCCESSFUL;
1248 }
1255 }
1249 }
1256 }
1250
1257
1251 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1258 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1252 {
1259 {
1253 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1260 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1254 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1261 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1255 {
1262 {
1256 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1263 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1257 }
1264 }
1258 else
1265 else
1259 {
1266 {
1260 status = RTEMS_SUCCESSFUL;
1267 status = RTEMS_SUCCESSFUL;
1261 }
1268 }
1262 }
1269 }
1263
1270
1264 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1271 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1265 {
1272 {
1266 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1273 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1267 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1274 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1268 {
1275 {
1269 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1276 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1270 }
1277 }
1271 else
1278 else
1272 {
1279 {
1273 status = RTEMS_SUCCESSFUL;
1280 status = RTEMS_SUCCESSFUL;
1274 }
1281 }
1275 }
1282 }
1276
1283
1277 return status;
1284 return status;
1278 }
1285 }
1279
1286
1280 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1287 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1281 {
1288 {
1282
1289
1283 WFP_reset_current_ring_nodes();
1290 WFP_reset_current_ring_nodes();
1284
1291
1285 reset_waveform_picker_regs();
1292 reset_waveform_picker_regs();
1286
1293
1287 set_wfp_burst_enable_register( mode );
1294 set_wfp_burst_enable_register( mode );
1288
1295
1289 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1296 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1290 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1297 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1291
1298
1292 if (transitionCoarseTime == 0)
1299 if (transitionCoarseTime == 0)
1293 {
1300 {
1294 // instant transition means transition on the next valid date
1301 // instant transition means transition on the next valid date
1295 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1302 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1296 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1303 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1297 }
1304 }
1298 else
1305 else
1299 {
1306 {
1300 waveform_picker_regs->start_date = transitionCoarseTime;
1307 waveform_picker_regs->start_date = transitionCoarseTime;
1301 }
1308 }
1302
1309
1303 update_last_valid_transition_date(waveform_picker_regs->start_date);
1310 update_last_valid_transition_date(waveform_picker_regs->start_date);
1304
1311
1305 }
1312 }
1306
1313
1307 void launch_spectral_matrix( void )
1314 void launch_spectral_matrix( void )
1308 {
1315 {
1309 SM_reset_current_ring_nodes();
1316 SM_reset_current_ring_nodes();
1310
1317
1311 reset_spectral_matrix_regs();
1318 reset_spectral_matrix_regs();
1312
1319
1313 reset_nb_sm();
1320 reset_nb_sm();
1314
1321
1315 set_sm_irq_onNewMatrix( 1 );
1322 set_sm_irq_onNewMatrix( 1 );
1316
1323
1317 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1324 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1318 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1325 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1319
1326
1320 }
1327 }
1321
1328
1322 void set_sm_irq_onNewMatrix( unsigned char value )
1329 void set_sm_irq_onNewMatrix( unsigned char value )
1323 {
1330 {
1324 if (value == 1)
1331 if (value == 1)
1325 {
1332 {
1326 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1333 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1327 }
1334 }
1328 else
1335 else
1329 {
1336 {
1330 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1337 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1331 }
1338 }
1332 }
1339 }
1333
1340
1334 void set_sm_irq_onError( unsigned char value )
1341 void set_sm_irq_onError( unsigned char value )
1335 {
1342 {
1336 if (value == 1)
1343 if (value == 1)
1337 {
1344 {
1338 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1345 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1339 }
1346 }
1340 else
1347 else
1341 {
1348 {
1342 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1349 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1343 }
1350 }
1344 }
1351 }
1345
1352
1346 //*****************************
1353 //*****************************
1347 // CONFIGURE CALIBRATION SIGNAL
1354 // CONFIGURE CALIBRATION SIGNAL
1348 void setCalibrationPrescaler( unsigned int prescaler )
1355 void setCalibrationPrescaler( unsigned int prescaler )
1349 {
1356 {
1350 // prescaling of the master clock (25 MHz)
1357 // prescaling of the master clock (25 MHz)
1351 // master clock is divided by 2^prescaler
1358 // master clock is divided by 2^prescaler
1352 time_management_regs->calPrescaler = prescaler;
1359 time_management_regs->calPrescaler = prescaler;
1353 }
1360 }
1354
1361
1355 void setCalibrationDivisor( unsigned int divisionFactor )
1362 void setCalibrationDivisor( unsigned int divisionFactor )
1356 {
1363 {
1357 // division of the prescaled clock by the division factor
1364 // division of the prescaled clock by the division factor
1358 time_management_regs->calDivisor = divisionFactor;
1365 time_management_regs->calDivisor = divisionFactor;
1359 }
1366 }
1360
1367
1361 void setCalibrationData( void )
1368 void setCalibrationData( void )
1362 {
1369 {
1363 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1370 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1364 *
1371 *
1365 * @param void
1372 * @param void
1366 *
1373 *
1367 * @return void
1374 * @return void
1368 *
1375 *
1369 */
1376 */
1370
1377
1371 unsigned int k;
1378 unsigned int k;
1372 unsigned short data;
1379 unsigned short data;
1373 float val;
1380 float val;
1374 float Ts;
1381 float Ts;
1375
1382
1376 time_management_regs->calDataPtr = INIT_CHAR;
1383 time_management_regs->calDataPtr = INIT_CHAR;
1377
1384
1378 // build the signal for the SCM calibration
1385 // build the signal for the SCM calibration
1379 for (k = 0; k < CAL_NB_PTS; k++)
1386 for (k = 0; k < CAL_NB_PTS; k++)
1380 {
1387 {
1381 val = sin( 2 * pi * CAL_F0 * k * Ts )
1388 val = sin( 2 * pi * CAL_F0 * k * Ts )
1382 + sin( 2 * pi * CAL_F1 * k * Ts );
1389 + sin( 2 * pi * CAL_F1 * k * Ts );
1383 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1390 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1384 time_management_regs->calData = data & CAL_DATA_MASK;
1391 time_management_regs->calData = data & CAL_DATA_MASK;
1385 }
1392 }
1386 }
1393 }
1387
1394
1388 void setCalibrationDataInterleaved( void )
1395 void setCalibrationDataInterleaved( void )
1389 {
1396 {
1390 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1397 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1391 *
1398 *
1392 * @param void
1399 * @param void
1393 *
1400 *
1394 * @return void
1401 * @return void
1395 *
1402 *
1396 * In interleaved mode, one can store more values than in normal mode.
1403 * In interleaved mode, one can store more values than in normal mode.
1397 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1404 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1398 * T store 3 values, one need two write operations.
1405 * T store 3 values, one need two write operations.
1399 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1406 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1400 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1407 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1401 *
1408 *
1402 */
1409 */
1403
1410
1404 unsigned int k;
1411 unsigned int k;
1405 float val;
1412 float val;
1406 float Ts;
1413 float Ts;
1407 unsigned short data[CAL_NB_PTS_INTER];
1414 unsigned short data[CAL_NB_PTS_INTER];
1408 unsigned char *dataPtr;
1415 unsigned char *dataPtr;
1409
1416
1410 Ts = 1. / CAL_FS_INTER;
1417 Ts = 1. / CAL_FS_INTER;
1411
1418
1412 time_management_regs->calDataPtr = INIT_CHAR;
1419 time_management_regs->calDataPtr = INIT_CHAR;
1413
1420
1414 // build the signal for the SCM calibration
1421 // build the signal for the SCM calibration
1415 for (k=0; k<CAL_NB_PTS_INTER; k++)
1422 for (k=0; k<CAL_NB_PTS_INTER; k++)
1416 {
1423 {
1417 val = sin( 2 * pi * CAL_F0 * k * Ts )
1424 val = sin( 2 * pi * CAL_F0 * k * Ts )
1418 + sin( 2 * pi * CAL_F1 * k * Ts );
1425 + sin( 2 * pi * CAL_F1 * k * Ts );
1419 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1426 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1420 }
1427 }
1421
1428
1422 // write the signal in interleaved mode
1429 // write the signal in interleaved mode
1423 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1430 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1424 {
1431 {
1425 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1432 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1426 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1433 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1427 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1434 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1428 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1435 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1429 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1436 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1430 }
1437 }
1431 }
1438 }
1432
1439
1433 void setCalibrationReload( bool state)
1440 void setCalibrationReload( bool state)
1434 {
1441 {
1435 if (state == true)
1442 if (state == true)
1436 {
1443 {
1437 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1444 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1438 }
1445 }
1439 else
1446 else
1440 {
1447 {
1441 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1448 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1442 }
1449 }
1443 }
1450 }
1444
1451
1445 void setCalibrationEnable( bool state )
1452 void setCalibrationEnable( bool state )
1446 {
1453 {
1447 // this bit drives the multiplexer
1454 // this bit drives the multiplexer
1448 if (state == true)
1455 if (state == true)
1449 {
1456 {
1450 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1457 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1451 }
1458 }
1452 else
1459 else
1453 {
1460 {
1454 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1461 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1455 }
1462 }
1456 }
1463 }
1457
1464
1458 void setCalibrationInterleaved( bool state )
1465 void setCalibrationInterleaved( bool state )
1459 {
1466 {
1460 // this bit drives the multiplexer
1467 // this bit drives the multiplexer
1461 if (state == true)
1468 if (state == true)
1462 {
1469 {
1463 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1470 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1464 }
1471 }
1465 else
1472 else
1466 {
1473 {
1467 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1474 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1468 }
1475 }
1469 }
1476 }
1470
1477
1471 void setCalibration( bool state )
1478 void setCalibration( bool state )
1472 {
1479 {
1473 if (state == true)
1480 if (state == true)
1474 {
1481 {
1475 setCalibrationEnable( true );
1482 setCalibrationEnable( true );
1476 setCalibrationReload( false );
1483 setCalibrationReload( false );
1477 set_hk_lfr_calib_enable( true );
1484 set_hk_lfr_calib_enable( true );
1478 }
1485 }
1479 else
1486 else
1480 {
1487 {
1481 setCalibrationEnable( false );
1488 setCalibrationEnable( false );
1482 setCalibrationReload( true );
1489 setCalibrationReload( true );
1483 set_hk_lfr_calib_enable( false );
1490 set_hk_lfr_calib_enable( false );
1484 }
1491 }
1485 }
1492 }
1486
1493
1487 void configureCalibration( bool interleaved )
1494 void configureCalibration( bool interleaved )
1488 {
1495 {
1489 setCalibration( false );
1496 setCalibration( false );
1490 if ( interleaved == true )
1497 if ( interleaved == true )
1491 {
1498 {
1492 setCalibrationInterleaved( true );
1499 setCalibrationInterleaved( true );
1493 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1500 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1494 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1501 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1495 setCalibrationDataInterleaved();
1502 setCalibrationDataInterleaved();
1496 }
1503 }
1497 else
1504 else
1498 {
1505 {
1499 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1506 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1500 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1507 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1501 setCalibrationData();
1508 setCalibrationData();
1502 }
1509 }
1503 }
1510 }
1504
1511
1505 //****************
1512 //****************
1506 // CLOSING ACTIONS
1513 // CLOSING ACTIONS
1507 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1514 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1508 {
1515 {
1509 /** This function is used to update the HK packets statistics after a successful TC execution.
1516 /** This function is used to update the HK packets statistics after a successful TC execution.
1510 *
1517 *
1511 * @param TC points to the TC being processed
1518 * @param TC points to the TC being processed
1512 * @param time is the time used to date the TC execution
1519 * @param time is the time used to date the TC execution
1513 *
1520 *
1514 */
1521 */
1515
1522
1516 unsigned int val;
1523 unsigned int val;
1517
1524
1518 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1525 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1519 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1526 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1520 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1527 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1521 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1528 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1522 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1529 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1523 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1530 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1524 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1531 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1525 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1532 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1526 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1533 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1527 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1528 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1535 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1529 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1536 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1530
1537
1531 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1538 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1532 val++;
1539 val++;
1533 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1540 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1534 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1541 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1535 }
1542 }
1536
1543
1537 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1544 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1538 {
1545 {
1539 /** This function is used to update the HK packets statistics after a TC rejection.
1546 /** This function is used to update the HK packets statistics after a TC rejection.
1540 *
1547 *
1541 * @param TC points to the TC being processed
1548 * @param TC points to the TC being processed
1542 * @param time is the time used to date the TC rejection
1549 * @param time is the time used to date the TC rejection
1543 *
1550 *
1544 */
1551 */
1545
1552
1546 unsigned int val;
1553 unsigned int val;
1547
1554
1548 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1555 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1549 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1556 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1550 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1557 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1551 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1558 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1552 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1559 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1553 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1560 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1554 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1561 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1555 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1562 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1556 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1563 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1557 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1558 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1565 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1559 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1566 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1560
1567
1561 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1568 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1562 val++;
1569 val++;
1563 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1570 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1564 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1571 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1565 }
1572 }
1566
1573
1567 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1574 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1568 {
1575 {
1569 /** This function is the last step of the TC execution workflow.
1576 /** This function is the last step of the TC execution workflow.
1570 *
1577 *
1571 * @param TC points to the TC being processed
1578 * @param TC points to the TC being processed
1572 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1579 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1573 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1580 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1574 * @param time is the time used to date the TC execution
1581 * @param time is the time used to date the TC execution
1575 *
1582 *
1576 */
1583 */
1577
1584
1578 unsigned char requestedMode;
1585 unsigned char requestedMode;
1579
1586
1580 if (result == LFR_SUCCESSFUL)
1587 if (result == LFR_SUCCESSFUL)
1581 {
1588 {
1582 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1589 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1583 &
1590 &
1584 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1591 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1585 )
1592 )
1586 {
1593 {
1587 send_tm_lfr_tc_exe_success( TC, queue_id );
1594 send_tm_lfr_tc_exe_success( TC, queue_id );
1588 }
1595 }
1589 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1596 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1590 {
1597 {
1591 //**********************************
1598 //**********************************
1592 // UPDATE THE LFRMODE LOCAL VARIABLE
1599 // UPDATE THE LFRMODE LOCAL VARIABLE
1593 requestedMode = TC->dataAndCRC[1];
1600 requestedMode = TC->dataAndCRC[1];
1594 updateLFRCurrentMode( requestedMode );
1601 updateLFRCurrentMode( requestedMode );
1595 }
1602 }
1596 }
1603 }
1597 else if (result == LFR_EXE_ERROR)
1604 else if (result == LFR_EXE_ERROR)
1598 {
1605 {
1599 send_tm_lfr_tc_exe_error( TC, queue_id );
1606 send_tm_lfr_tc_exe_error( TC, queue_id );
1600 }
1607 }
1601 }
1608 }
1602
1609
1603 //***************************
1610 //***************************
1604 // Interrupt Service Routines
1611 // Interrupt Service Routines
1605 rtems_isr commutation_isr1( rtems_vector_number vector )
1612 rtems_isr commutation_isr1( rtems_vector_number vector )
1606 {
1613 {
1607 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1614 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1608 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1615 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1609 }
1616 }
1610 }
1617 }
1611
1618
1612 rtems_isr commutation_isr2( rtems_vector_number vector )
1619 rtems_isr commutation_isr2( rtems_vector_number vector )
1613 {
1620 {
1614 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1621 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1615 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1622 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1616 }
1623 }
1617 }
1624 }
1618
1625
1619 //****************
1626 //****************
1620 // OTHER FUNCTIONS
1627 // OTHER FUNCTIONS
1621 void updateLFRCurrentMode( unsigned char requestedMode )
1628 void updateLFRCurrentMode( unsigned char requestedMode )
1622 {
1629 {
1623 /** This function updates the value of the global variable lfrCurrentMode.
1630 /** This function updates the value of the global variable lfrCurrentMode.
1624 *
1631 *
1625 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1632 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1626 *
1633 *
1627 */
1634 */
1628
1635
1629 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1636 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1630 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1637 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1631 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1638 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1632 lfrCurrentMode = requestedMode;
1639 lfrCurrentMode = requestedMode;
1633 }
1640 }
1634
1641
1635 void set_lfr_soft_reset( unsigned char value )
1642 void set_lfr_soft_reset( unsigned char value )
1636 {
1643 {
1637 if (value == 1)
1644 if (value == 1)
1638 {
1645 {
1639 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1646 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1640 }
1647 }
1641 else
1648 else
1642 {
1649 {
1643 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1650 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1644 }
1651 }
1645 }
1652 }
1646
1653
1647 void reset_lfr( void )
1654 void reset_lfr( void )
1648 {
1655 {
1649 set_lfr_soft_reset( 1 );
1656 set_lfr_soft_reset( 1 );
1650
1657
1651 set_lfr_soft_reset( 0 );
1658 set_lfr_soft_reset( 0 );
1652
1659
1653 set_hk_lfr_sc_potential_flag( true );
1660 set_hk_lfr_sc_potential_flag( true );
1654 }
1661 }
@@ -1,1650 +1,1657
1 /** Functions to load and dump parameters in the LFR registers.
1 /** Functions to load and dump parameters in the LFR registers.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
12 *
13 */
13 */
14
14
15 #include "tc_load_dump_parameters.h"
15 #include "tc_load_dump_parameters.h"
16
16
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 ring_node kcoefficient_node_1;
19 ring_node kcoefficient_node_1;
20 ring_node kcoefficient_node_2;
20 ring_node kcoefficient_node_2;
21
21
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
23 {
24 /** This function updates the LFR registers with the incoming common parameters.
24 /** This function updates the LFR registers with the incoming common parameters.
25 *
25 *
26 * @param TC points to the TeleCommand packet that is being processed
26 * @param TC points to the TeleCommand packet that is being processed
27 *
27 *
28 *
28 *
29 */
29 */
30
30
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
33 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
34 return LFR_SUCCESSFUL;
35 }
35 }
36
36
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
38 {
39 /** This function updates the LFR registers with the incoming normal parameters.
39 /** This function updates the LFR registers with the incoming normal parameters.
40 *
40 *
41 * @param TC points to the TeleCommand packet that is being processed
41 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int result;
46 int result;
47 int flag;
47 int flag;
48 rtems_status_code status;
48 rtems_status_code status;
49
49
50 flag = LFR_SUCCESSFUL;
50 flag = LFR_SUCCESSFUL;
51
51
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
55 flag = LFR_DEFAULT;
56 }
56 }
57
57
58 // CHECK THE PARAMETERS SET CONSISTENCY
58 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
59 if (flag == LFR_SUCCESSFUL)
60 {
60 {
61 flag = check_normal_par_consistency( TC, queue_id );
61 flag = check_normal_par_consistency( TC, queue_id );
62 }
62 }
63
63
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
65 if (flag == LFR_SUCCESSFUL)
66 {
66 {
67 result = set_sy_lfr_n_swf_l( TC );
67 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
68 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
71 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
73 }
74
74
75 return flag;
75 return flag;
76 }
76 }
77
77
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
79 {
80 /** This function updates the LFR registers with the incoming burst parameters.
80 /** This function updates the LFR registers with the incoming burst parameters.
81 *
81 *
82 * @param TC points to the TeleCommand packet that is being processed
82 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
87 int flag;
88 rtems_status_code status;
88 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
89 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
90 unsigned char sy_lfr_b_bp_p1;
91 float aux;
91 float aux;
92
92
93 flag = LFR_SUCCESSFUL;
93 flag = LFR_SUCCESSFUL;
94
94
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
97 flag = LFR_DEFAULT;
98 }
98 }
99
99
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
102
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
104 if (flag == LFR_SUCCESSFUL)
105 {
105 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
107 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
109 flag = WRONG_APP_DATA;
110 }
110 }
111 }
111 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
113 if (flag == LFR_SUCCESSFUL)
114 {
114 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
116 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
118 flag = WRONG_APP_DATA;
119 }
119 }
120 }
120 }
121 //****************************************************************
121 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
123 if (flag == LFR_SUCCESSFUL)
124 {
124 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
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 if (aux > FLOAT_EQUAL_ZERO)
128 if (aux > FLOAT_EQUAL_ZERO)
129 {
129 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
131 flag = LFR_DEFAULT;
132 }
132 }
133 }
133 }
134
134
135 // SET THE PARAMETERS
135 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
136 if (flag == LFR_SUCCESSFUL)
137 {
137 {
138 flag = set_sy_lfr_b_bp_p0( TC );
138 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
140 }
140 }
141
141
142 return flag;
142 return flag;
143 }
143 }
144
144
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
146 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
148 *
149 * @param TC points to the TeleCommand packet that is being processed
149 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
154 int flag;
155 rtems_status_code status;
155 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
156 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
157 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
158 float aux;
159
159
160 flag = LFR_SUCCESSFUL;
160 flag = LFR_SUCCESSFUL;
161
161
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
164 flag = LFR_DEFAULT;
165 }
165 }
166
166
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
169
170 // sy_lfr_s1_bp_p0
170 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
171 if (flag == LFR_SUCCESSFUL)
172 {
172 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
174 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
176 flag = WRONG_APP_DATA;
177 }
177 }
178 }
178 }
179 // sy_lfr_s1_bp_p1
179 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
180 if (flag == LFR_SUCCESSFUL)
181 {
181 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
183 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
185 flag = WRONG_APP_DATA;
186 }
186 }
187 }
187 }
188 //******************************************************************
188 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
190 if (flag == LFR_SUCCESSFUL)
191 {
191 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 if (aux > FLOAT_EQUAL_ZERO)
194 if (aux > FLOAT_EQUAL_ZERO)
195 {
195 {
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 flag = LFR_DEFAULT;
197 flag = LFR_DEFAULT;
198 }
198 }
199 }
199 }
200
200
201 // SET THE PARAMETERS
201 // SET THE PARAMETERS
202 if (flag == LFR_SUCCESSFUL)
202 if (flag == LFR_SUCCESSFUL)
203 {
203 {
204 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p0( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
206 }
206 }
207
207
208 return flag;
208 return flag;
209 }
209 }
210
210
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 {
212 {
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 *
214 *
215 * @param TC points to the TeleCommand packet that is being processed
215 * @param TC points to the TeleCommand packet that is being processed
216 * @param queue_id is the id of the queue which handles TM related to this execution step
216 * @param queue_id is the id of the queue which handles TM related to this execution step
217 *
217 *
218 */
218 */
219
219
220 int flag;
220 int flag;
221 rtems_status_code status;
221 rtems_status_code status;
222 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p0;
223 unsigned char sy_lfr_s2_bp_p1;
223 unsigned char sy_lfr_s2_bp_p1;
224 float aux;
224 float aux;
225
225
226 flag = LFR_SUCCESSFUL;
226 flag = LFR_SUCCESSFUL;
227
227
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 flag = LFR_DEFAULT;
230 flag = LFR_DEFAULT;
231 }
231 }
232
232
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235
235
236 // sy_lfr_s2_bp_p0
236 // sy_lfr_s2_bp_p0
237 if (flag == LFR_SUCCESSFUL)
237 if (flag == LFR_SUCCESSFUL)
238 {
238 {
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 {
240 {
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 flag = WRONG_APP_DATA;
242 flag = WRONG_APP_DATA;
243 }
243 }
244 }
244 }
245 // sy_lfr_s2_bp_p1
245 // sy_lfr_s2_bp_p1
246 if (flag == LFR_SUCCESSFUL)
246 if (flag == LFR_SUCCESSFUL)
247 {
247 {
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 {
249 {
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 flag = WRONG_APP_DATA;
251 flag = WRONG_APP_DATA;
252 }
252 }
253 }
253 }
254 //******************************************************************
254 //******************************************************************
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 if (flag == LFR_SUCCESSFUL)
256 if (flag == LFR_SUCCESSFUL)
257 {
257 {
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 if (aux > FLOAT_EQUAL_ZERO)
261 if (aux > FLOAT_EQUAL_ZERO)
262 {
262 {
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 flag = LFR_DEFAULT;
264 flag = LFR_DEFAULT;
265 }
265 }
266 }
266 }
267
267
268 // SET THE PARAMETERS
268 // SET THE PARAMETERS
269 if (flag == LFR_SUCCESSFUL)
269 if (flag == LFR_SUCCESSFUL)
270 {
270 {
271 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p0( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
273 }
273 }
274
274
275 return flag;
275 return flag;
276 }
276 }
277
277
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 {
279 {
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 *
281 *
282 * @param TC points to the TeleCommand packet that is being processed
282 * @param TC points to the TeleCommand packet that is being processed
283 * @param queue_id is the id of the queue which handles TM related to this execution step
283 * @param queue_id is the id of the queue which handles TM related to this execution step
284 *
284 *
285 */
285 */
286
286
287 int flag;
287 int flag;
288
288
289 flag = LFR_DEFAULT;
289 flag = LFR_DEFAULT;
290
290
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
292
292
293 return flag;
293 return flag;
294 }
294 }
295
295
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 {
297 {
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 *
299 *
300 * @param TC points to the TeleCommand packet that is being processed
300 * @param TC points to the TeleCommand packet that is being processed
301 * @param queue_id is the id of the queue which handles TM related to this execution step
301 * @param queue_id is the id of the queue which handles TM related to this execution step
302 *
302 *
303 */
303 */
304
304
305 int flag;
305 int flag;
306
306
307 flag = LFR_DEFAULT;
307 flag = LFR_DEFAULT;
308
308
309 flag = set_sy_lfr_fbins( TC );
309 flag = set_sy_lfr_fbins( TC );
310
310
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 merge_fbins_masks();
312 merge_fbins_masks();
313
313
314 return flag;
314 return flag;
315 }
315 }
316
316
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
318 {
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 *
320 *
321 * @param TC points to the TeleCommand packet that is being processed
321 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM related to this execution step
322 * @param queue_id is the id of the queue which handles TM related to this execution step
323 *
323 *
324 */
324 */
325
325
326 int flag;
326 int flag;
327
327
328 flag = LFR_DEFAULT;
328 flag = LFR_DEFAULT;
329
329
330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
331
331
332 if (flag == LFR_SUCCESSFUL)
332 if (flag == LFR_SUCCESSFUL)
333 {
333 {
334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
349
349
350 //****************************
350 //****************************
351 // store PAS filter parameters
351 // store PAS filter parameters
352 // sy_lfr_pas_filter_enabled
352 // sy_lfr_pas_filter_enabled
353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
355 // sy_lfr_pas_filter_modulus
355 // sy_lfr_pas_filter_modulus
356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
357 // sy_lfr_pas_filter_tbad
357 // sy_lfr_pas_filter_tbad
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
360 // sy_lfr_pas_filter_offset
360 // sy_lfr_pas_filter_offset
361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
362 // sy_lfr_pas_filter_shift
362 // sy_lfr_pas_filter_shift
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
364 parameter_dump_packet.sy_lfr_pas_filter_shift );
364 parameter_dump_packet.sy_lfr_pas_filter_shift );
365
365
366 //****************************************************
366 //****************************************************
367 // store the parameter sy_lfr_sc_rw_delta_f as a float
367 // store the parameter sy_lfr_sc_rw_delta_f as a float
368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
370 }
370 }
371
371
372 return flag;
372 return flag;
373 }
373 }
374
374
375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
376 {
376 {
377 /** This function updates the LFR registers with the incoming sbm2 parameters.
377 /** This function updates the LFR registers with the incoming sbm2 parameters.
378 *
378 *
379 * @param TC points to the TeleCommand packet that is being processed
379 * @param TC points to the TeleCommand packet that is being processed
380 * @param queue_id is the id of the queue which handles TM related to this execution step
380 * @param queue_id is the id of the queue which handles TM related to this execution step
381 *
381 *
382 */
382 */
383
383
384 unsigned int address;
384 unsigned int address;
385 rtems_status_code status;
385 rtems_status_code status;
386 unsigned int freq;
386 unsigned int freq;
387 unsigned int bin;
387 unsigned int bin;
388 unsigned int coeff;
388 unsigned int coeff;
389 unsigned char *kCoeffPtr;
389 unsigned char *kCoeffPtr;
390 unsigned char *kCoeffDumpPtr;
390 unsigned char *kCoeffDumpPtr;
391
391
392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
393 // F0 => 11 bins
393 // F0 => 11 bins
394 // F1 => 13 bins
394 // F1 => 13 bins
395 // F2 => 12 bins
395 // F2 => 12 bins
396 // 36 bins to dump in two packets (30 bins max per packet)
396 // 36 bins to dump in two packets (30 bins max per packet)
397
397
398 //*********
398 //*********
399 // PACKET 1
399 // PACKET 1
400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
401 kcoefficients_dump_1.destinationID = TC->sourceID;
401 kcoefficients_dump_1.destinationID = TC->sourceID;
402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
403 for( freq = 0;
403 for( freq = 0;
404 freq < NB_BINS_COMPRESSED_SM_F0;
404 freq < NB_BINS_COMPRESSED_SM_F0;
405 freq++ )
405 freq++ )
406 {
406 {
407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
408 bin = freq;
408 bin = freq;
409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
411 {
411 {
412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
414 ]; // 2 for the kcoeff_frequency
414 ]; // 2 for the kcoeff_frequency
415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
417 }
417 }
418 }
418 }
419 for( freq = NB_BINS_COMPRESSED_SM_F0;
419 for( freq = NB_BINS_COMPRESSED_SM_F0;
420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
421 freq++ )
421 freq++ )
422 {
422 {
423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
427 {
427 {
428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
430 ]; // 2 for the kcoeff_frequency
430 ]; // 2 for the kcoeff_frequency
431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
433 }
433 }
434 }
434 }
435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
436 freq < KCOEFF_BLK_NR_PKT1 ;
436 freq < KCOEFF_BLK_NR_PKT1 ;
437 freq++ )
437 freq++ )
438 {
438 {
439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
443 {
443 {
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 ]; // 2 for the kcoeff_frequency
446 ]; // 2 for the kcoeff_frequency
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 }
449 }
450 }
450 }
451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
457 // SEND DATA
457 // SEND DATA
458 kcoefficient_node_1.status = 1;
458 kcoefficient_node_1.status = 1;
459 address = (unsigned int) &kcoefficient_node_1;
459 address = (unsigned int) &kcoefficient_node_1;
460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
461 if (status != RTEMS_SUCCESSFUL) {
461 if (status != RTEMS_SUCCESSFUL) {
462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
463 }
463 }
464
464
465 //********
465 //********
466 // PACKET 2
466 // PACKET 2
467 // 6 F2 bins
467 // 6 F2 bins
468 kcoefficients_dump_2.destinationID = TC->sourceID;
468 kcoefficients_dump_2.destinationID = TC->sourceID;
469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
470 for( freq = 0;
470 for( freq = 0;
471 freq < KCOEFF_BLK_NR_PKT2;
471 freq < KCOEFF_BLK_NR_PKT2;
472 freq++ )
472 freq++ )
473 {
473 {
474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
475 bin = freq + KCOEFF_BLK_NR_PKT2;
475 bin = freq + KCOEFF_BLK_NR_PKT2;
476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
478 {
478 {
479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
483 }
483 }
484 }
484 }
485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
491 // SEND DATA
491 // SEND DATA
492 kcoefficient_node_2.status = 1;
492 kcoefficient_node_2.status = 1;
493 address = (unsigned int) &kcoefficient_node_2;
493 address = (unsigned int) &kcoefficient_node_2;
494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
495 if (status != RTEMS_SUCCESSFUL) {
495 if (status != RTEMS_SUCCESSFUL) {
496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
497 }
497 }
498
498
499 return status;
499 return status;
500 }
500 }
501
501
502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
503 {
503 {
504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
505 *
505 *
506 * @param queue_id is the id of the queue which handles TM related to this execution step.
506 * @param queue_id is the id of the queue which handles TM related to this execution step.
507 *
507 *
508 * @return RTEMS directive status codes:
508 * @return RTEMS directive status codes:
509 * - RTEMS_SUCCESSFUL - message sent successfully
509 * - RTEMS_SUCCESSFUL - message sent successfully
510 * - RTEMS_INVALID_ID - invalid queue id
510 * - RTEMS_INVALID_ID - invalid queue id
511 * - RTEMS_INVALID_SIZE - invalid message size
511 * - RTEMS_INVALID_SIZE - invalid message size
512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
513 * - RTEMS_UNSATISFIED - out of message buffers
513 * - RTEMS_UNSATISFIED - out of message buffers
514 * - RTEMS_TOO_MANY - queue s limit has been reached
514 * - RTEMS_TOO_MANY - queue s limit has been reached
515 *
515 *
516 */
516 */
517
517
518 int status;
518 int status;
519
519
520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
521 parameter_dump_packet.destinationID = TC->sourceID;
521 parameter_dump_packet.destinationID = TC->sourceID;
522
522
523 // UPDATE TIME
523 // UPDATE TIME
524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
530 // SEND DATA
530 // SEND DATA
531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
533 if (status != RTEMS_SUCCESSFUL) {
533 if (status != RTEMS_SUCCESSFUL) {
534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
535 }
535 }
536
536
537 return status;
537 return status;
538 }
538 }
539
539
540 //***********************
540 //***********************
541 // NORMAL MODE PARAMETERS
541 // NORMAL MODE PARAMETERS
542
542
543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
544 {
544 {
545 unsigned char msb;
545 unsigned char msb;
546 unsigned char lsb;
546 unsigned char lsb;
547 int flag;
547 int flag;
548 float aux;
548 float aux;
549 rtems_status_code status;
549 rtems_status_code status;
550
550
551 unsigned int sy_lfr_n_swf_l;
551 unsigned int sy_lfr_n_swf_l;
552 unsigned int sy_lfr_n_swf_p;
552 unsigned int sy_lfr_n_swf_p;
553 unsigned int sy_lfr_n_asm_p;
553 unsigned int sy_lfr_n_asm_p;
554 unsigned char sy_lfr_n_bp_p0;
554 unsigned char sy_lfr_n_bp_p0;
555 unsigned char sy_lfr_n_bp_p1;
555 unsigned char sy_lfr_n_bp_p1;
556 unsigned char sy_lfr_n_cwf_long_f3;
556 unsigned char sy_lfr_n_cwf_long_f3;
557
557
558 flag = LFR_SUCCESSFUL;
558 flag = LFR_SUCCESSFUL;
559
559
560 //***************
560 //***************
561 // get parameters
561 // get parameters
562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
565
565
566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
569
569
570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
573
573
574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
575
575
576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
577
577
578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
579
579
580 //******************
580 //******************
581 // check consistency
581 // check consistency
582 // sy_lfr_n_swf_l
582 // sy_lfr_n_swf_l
583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
584 {
584 {
585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
586 flag = WRONG_APP_DATA;
586 flag = WRONG_APP_DATA;
587 }
587 }
588 // sy_lfr_n_swf_p
588 // sy_lfr_n_swf_p
589 if (flag == LFR_SUCCESSFUL)
589 if (flag == LFR_SUCCESSFUL)
590 {
590 {
591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
592 {
592 {
593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
594 flag = WRONG_APP_DATA;
594 flag = WRONG_APP_DATA;
595 }
595 }
596 }
596 }
597 // sy_lfr_n_bp_p0
597 // sy_lfr_n_bp_p0
598 if (flag == LFR_SUCCESSFUL)
598 if (flag == LFR_SUCCESSFUL)
599 {
599 {
600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
601 {
601 {
602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
603 flag = WRONG_APP_DATA;
603 flag = WRONG_APP_DATA;
604 }
604 }
605 }
605 }
606 // sy_lfr_n_asm_p
606 // sy_lfr_n_asm_p
607 if (flag == LFR_SUCCESSFUL)
607 if (flag == LFR_SUCCESSFUL)
608 {
608 {
609 if (sy_lfr_n_asm_p == 0)
609 if (sy_lfr_n_asm_p == 0)
610 {
610 {
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
612 flag = WRONG_APP_DATA;
612 flag = WRONG_APP_DATA;
613 }
613 }
614 }
614 }
615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
616 if (flag == LFR_SUCCESSFUL)
616 if (flag == LFR_SUCCESSFUL)
617 {
617 {
618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
619 if (aux > FLOAT_EQUAL_ZERO)
619 if (aux > FLOAT_EQUAL_ZERO)
620 {
620 {
621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
622 flag = WRONG_APP_DATA;
622 flag = WRONG_APP_DATA;
623 }
623 }
624 }
624 }
625 // sy_lfr_n_bp_p1
625 // sy_lfr_n_bp_p1
626 if (flag == LFR_SUCCESSFUL)
626 if (flag == LFR_SUCCESSFUL)
627 {
627 {
628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
629 {
629 {
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
631 flag = WRONG_APP_DATA;
631 flag = WRONG_APP_DATA;
632 }
632 }
633 }
633 }
634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
635 if (flag == LFR_SUCCESSFUL)
635 if (flag == LFR_SUCCESSFUL)
636 {
636 {
637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
638 if (aux > FLOAT_EQUAL_ZERO)
638 if (aux > FLOAT_EQUAL_ZERO)
639 {
639 {
640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
641 flag = LFR_DEFAULT;
641 flag = LFR_DEFAULT;
642 }
642 }
643 }
643 }
644 // sy_lfr_n_cwf_long_f3
644 // sy_lfr_n_cwf_long_f3
645
645
646 return flag;
646 return flag;
647 }
647 }
648
648
649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
650 {
650 {
651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
652 *
652 *
653 * @param TC points to the TeleCommand packet that is being processed
653 * @param TC points to the TeleCommand packet that is being processed
654 * @param queue_id is the id of the queue which handles TM related to this execution step
654 * @param queue_id is the id of the queue which handles TM related to this execution step
655 *
655 *
656 */
656 */
657
657
658 int result;
658 int result;
659
659
660 result = LFR_SUCCESSFUL;
660 result = LFR_SUCCESSFUL;
661
661
662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
664
664
665 return result;
665 return result;
666 }
666 }
667
667
668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
669 {
669 {
670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
671 *
671 *
672 * @param TC points to the TeleCommand packet that is being processed
672 * @param TC points to the TeleCommand packet that is being processed
673 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int result;
677 int result;
678
678
679 result = LFR_SUCCESSFUL;
679 result = LFR_SUCCESSFUL;
680
680
681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
683
683
684 return result;
684 return result;
685 }
685 }
686
686
687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
688 {
688 {
689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
690 *
690 *
691 * @param TC points to the TeleCommand packet that is being processed
691 * @param TC points to the TeleCommand packet that is being processed
692 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int result;
696 int result;
697
697
698 result = LFR_SUCCESSFUL;
698 result = LFR_SUCCESSFUL;
699
699
700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
702
702
703 return result;
703 return result;
704 }
704 }
705
705
706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
707 {
707 {
708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
709 *
709 *
710 * @param TC points to the TeleCommand packet that is being processed
710 * @param TC points to the TeleCommand packet that is being processed
711 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int status;
715 int status;
716
716
717 status = LFR_SUCCESSFUL;
717 status = LFR_SUCCESSFUL;
718
718
719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
720
720
721 return status;
721 return status;
722 }
722 }
723
723
724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
725 {
725 {
726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
727 *
727 *
728 * @param TC points to the TeleCommand packet that is being processed
728 * @param TC points to the TeleCommand packet that is being processed
729 * @param queue_id is the id of the queue which handles TM related to this execution step
729 * @param queue_id is the id of the queue which handles TM related to this execution step
730 *
730 *
731 */
731 */
732
732
733 int status;
733 int status;
734
734
735 status = LFR_SUCCESSFUL;
735 status = LFR_SUCCESSFUL;
736
736
737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
738
738
739 return status;
739 return status;
740 }
740 }
741
741
742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
743 {
743 {
744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
745 *
745 *
746 * @param TC points to the TeleCommand packet that is being processed
746 * @param TC points to the TeleCommand packet that is being processed
747 * @param queue_id is the id of the queue which handles TM related to this execution step
747 * @param queue_id is the id of the queue which handles TM related to this execution step
748 *
748 *
749 */
749 */
750
750
751 int status;
751 int status;
752
752
753 status = LFR_SUCCESSFUL;
753 status = LFR_SUCCESSFUL;
754
754
755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
756
756
757 return status;
757 return status;
758 }
758 }
759
759
760 //**********************
760 //**********************
761 // BURST MODE PARAMETERS
761 // BURST MODE PARAMETERS
762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
763 {
763 {
764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
765 *
765 *
766 * @param TC points to the TeleCommand packet that is being processed
766 * @param TC points to the TeleCommand packet that is being processed
767 * @param queue_id is the id of the queue which handles TM related to this execution step
767 * @param queue_id is the id of the queue which handles TM related to this execution step
768 *
768 *
769 */
769 */
770
770
771 int status;
771 int status;
772
772
773 status = LFR_SUCCESSFUL;
773 status = LFR_SUCCESSFUL;
774
774
775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
776
776
777 return status;
777 return status;
778 }
778 }
779
779
780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
781 {
781 {
782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
783 *
783 *
784 * @param TC points to the TeleCommand packet that is being processed
784 * @param TC points to the TeleCommand packet that is being processed
785 * @param queue_id is the id of the queue which handles TM related to this execution step
785 * @param queue_id is the id of the queue which handles TM related to this execution step
786 *
786 *
787 */
787 */
788
788
789 int status;
789 int status;
790
790
791 status = LFR_SUCCESSFUL;
791 status = LFR_SUCCESSFUL;
792
792
793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
794
794
795 return status;
795 return status;
796 }
796 }
797
797
798 //*********************
798 //*********************
799 // SBM1 MODE PARAMETERS
799 // SBM1 MODE PARAMETERS
800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
801 {
801 {
802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
803 *
803 *
804 * @param TC points to the TeleCommand packet that is being processed
804 * @param TC points to the TeleCommand packet that is being processed
805 * @param queue_id is the id of the queue which handles TM related to this execution step
805 * @param queue_id is the id of the queue which handles TM related to this execution step
806 *
806 *
807 */
807 */
808
808
809 int status;
809 int status;
810
810
811 status = LFR_SUCCESSFUL;
811 status = LFR_SUCCESSFUL;
812
812
813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
814
814
815 return status;
815 return status;
816 }
816 }
817
817
818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
819 {
819 {
820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
821 *
821 *
822 * @param TC points to the TeleCommand packet that is being processed
822 * @param TC points to the TeleCommand packet that is being processed
823 * @param queue_id is the id of the queue which handles TM related to this execution step
823 * @param queue_id is the id of the queue which handles TM related to this execution step
824 *
824 *
825 */
825 */
826
826
827 int status;
827 int status;
828
828
829 status = LFR_SUCCESSFUL;
829 status = LFR_SUCCESSFUL;
830
830
831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
832
832
833 return status;
833 return status;
834 }
834 }
835
835
836 //*********************
836 //*********************
837 // SBM2 MODE PARAMETERS
837 // SBM2 MODE PARAMETERS
838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
839 {
839 {
840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
841 *
841 *
842 * @param TC points to the TeleCommand packet that is being processed
842 * @param TC points to the TeleCommand packet that is being processed
843 * @param queue_id is the id of the queue which handles TM related to this execution step
843 * @param queue_id is the id of the queue which handles TM related to this execution step
844 *
844 *
845 */
845 */
846
846
847 int status;
847 int status;
848
848
849 status = LFR_SUCCESSFUL;
849 status = LFR_SUCCESSFUL;
850
850
851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
852
852
853 return status;
853 return status;
854 }
854 }
855
855
856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
857 {
857 {
858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
859 *
859 *
860 * @param TC points to the TeleCommand packet that is being processed
860 * @param TC points to the TeleCommand packet that is being processed
861 * @param queue_id is the id of the queue which handles TM related to this execution step
861 * @param queue_id is the id of the queue which handles TM related to this execution step
862 *
862 *
863 */
863 */
864
864
865 int status;
865 int status;
866
866
867 status = LFR_SUCCESSFUL;
867 status = LFR_SUCCESSFUL;
868
868
869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
870
870
871 return status;
871 return status;
872 }
872 }
873
873
874 //*******************
874 //*******************
875 // TC_LFR_UPDATE_INFO
875 // TC_LFR_UPDATE_INFO
876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
877 {
877 {
878 unsigned int status;
878 unsigned int status;
879
879
880 status = LFR_DEFAULT;
881
880 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
882 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
881 || (mode == LFR_MODE_BURST)
883 || (mode == LFR_MODE_BURST)
882 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
884 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
883 {
885 {
884 status = LFR_SUCCESSFUL;
886 status = LFR_SUCCESSFUL;
885 }
887 }
886 else
888 else
887 {
889 {
888 status = LFR_DEFAULT;
890 status = LFR_DEFAULT;
889 }
891 }
890
892
891 return status;
893 return status;
892 }
894 }
893
895
894 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
896 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
895 {
897 {
896 unsigned int status;
898 unsigned int status;
897
899
900 status = LFR_DEFAULT;
901
898 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
902 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
899 || (mode == TDS_MODE_BURST)
903 || (mode == TDS_MODE_BURST)
900 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
904 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
901 || (mode == TDS_MODE_LFM))
905 || (mode == TDS_MODE_LFM))
902 {
906 {
903 status = LFR_SUCCESSFUL;
907 status = LFR_SUCCESSFUL;
904 }
908 }
905 else
909 else
906 {
910 {
907 status = LFR_DEFAULT;
911 status = LFR_DEFAULT;
908 }
912 }
909
913
910 return status;
914 return status;
911 }
915 }
912
916
913 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
917 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
914 {
918 {
915 unsigned int status;
919 unsigned int status;
916
920
921 status = LFR_DEFAULT;
922
917 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
923 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
918 || (mode == THR_MODE_BURST))
924 || (mode == THR_MODE_BURST))
919 {
925 {
920 status = LFR_SUCCESSFUL;
926 status = LFR_SUCCESSFUL;
921 }
927 }
922 else
928 else
923 {
929 {
924 status = LFR_DEFAULT;
930 status = LFR_DEFAULT;
925 }
931 }
926
932
927 return status;
933 return status;
928 }
934 }
929
935
930 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
936 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
931 {
937 {
932 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
938 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
933 *
939 *
934 * @param TC points to the TeleCommand packet that is being processed
940 * @param TC points to the TeleCommand packet that is being processed
935 *
941 *
936 */
942 */
937
943
938 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
944 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
939
945
940 bytePosPtr = (unsigned char *) &TC->packetID;
946 bytePosPtr = (unsigned char *) &TC->packetID;
941
947
942 // cp_rpw_sc_rw1_f1
948 // cp_rpw_sc_rw1_f1
943 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
944 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
945
951
946 // cp_rpw_sc_rw1_f2
952 // cp_rpw_sc_rw1_f2
947 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
948 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
949
955
950 // cp_rpw_sc_rw2_f1
956 // cp_rpw_sc_rw2_f1
951 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
952 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
953
959
954 // cp_rpw_sc_rw2_f2
960 // cp_rpw_sc_rw2_f2
955 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
961 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
956 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
962 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
957
963
958 // cp_rpw_sc_rw3_f1
964 // cp_rpw_sc_rw3_f1
959 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
965 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
960 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
966 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
961
967
962 // cp_rpw_sc_rw3_f2
968 // cp_rpw_sc_rw3_f2
963 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
969 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
964 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
970 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
965
971
966 // cp_rpw_sc_rw4_f1
972 // cp_rpw_sc_rw4_f1
967 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
973 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
968 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
974 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
969
975
970 // cp_rpw_sc_rw4_f2
976 // cp_rpw_sc_rw4_f2
971 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
977 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
972 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
978 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
973 }
979 }
974
980
975 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
981 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
976 {
982 {
977 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
983 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
978 *
984 *
979 * @param fbins_mask
985 * @param fbins_mask
980 * @param rw_f is the reaction wheel frequency to filter
986 * @param rw_f is the reaction wheel frequency to filter
981 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
987 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
982 * @param flag [true] filtering enabled [false] filtering disabled
988 * @param flag [true] filtering enabled [false] filtering disabled
983 *
989 *
984 * @return void
990 * @return void
985 *
991 *
986 */
992 */
987
993
988 float f_RW_min;
994 float f_RW_min;
989 float f_RW_MAX;
995 float f_RW_MAX;
990 float fi_min;
996 float fi_min;
991 float fi_MAX;
997 float fi_MAX;
992 float fi;
998 float fi;
993 float deltaBelow;
999 float deltaBelow;
994 float deltaAbove;
1000 float deltaAbove;
995 int binBelow;
1001 int binBelow;
996 int binAbove;
1002 int binAbove;
997 int closestBin;
1003 int closestBin;
998 unsigned int whichByte;
1004 unsigned int whichByte;
999 int selectedByte;
1005 int selectedByte;
1000 int bin;
1006 int bin;
1001 int binToRemove[NB_BINS_TO_REMOVE];
1007 int binToRemove[NB_BINS_TO_REMOVE];
1002 int k;
1008 int k;
1003
1009
1010 closestBin = 0;
1004 whichByte = 0;
1011 whichByte = 0;
1005 bin = 0;
1012 bin = 0;
1006
1013
1007 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1014 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1008 {
1015 {
1009 binToRemove[k] = -1;
1016 binToRemove[k] = -1;
1010 }
1017 }
1011
1018
1012 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1019 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1013 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1020 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1014 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1021 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1015
1022
1016 // compute the index of the frequency bin immediately below rw_f
1023 // compute the index of the frequency bin immediately below rw_f
1017 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1024 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1018 deltaBelow = rw_f - binBelow * deltaFreq;
1025 deltaBelow = rw_f - binBelow * deltaFreq;
1019
1026
1020 // compute the index of the frequency bin immediately above rw_f
1027 // compute the index of the frequency bin immediately above rw_f
1021 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1028 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1022 deltaAbove = binAbove * deltaFreq - rw_f;
1029 deltaAbove = binAbove * deltaFreq - rw_f;
1023
1030
1024 // search the closest bin
1031 // search the closest bin
1025 if (deltaAbove > deltaBelow)
1032 if (deltaAbove > deltaBelow)
1026 {
1033 {
1027 closestBin = binBelow;
1034 closestBin = binBelow;
1028 }
1035 }
1029 else
1036 else
1030 {
1037 {
1031 closestBin = binAbove;
1038 closestBin = binAbove;
1032 }
1039 }
1033
1040
1034 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1041 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1035 fi = closestBin * deltaFreq;
1042 fi = closestBin * deltaFreq;
1036 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1043 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1037 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1044 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1038
1045
1039 //**************************************************************************************
1046 //**************************************************************************************
1040 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1047 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1041 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1048 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1042 //**************************************************************************************
1049 //**************************************************************************************
1043
1050
1044 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1051 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1045 // => remove f_(i), f_(i-1) and f_(i+1)
1052 // => remove f_(i), f_(i-1) and f_(i+1)
1046 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1053 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1047 {
1054 {
1048 binToRemove[0] = (closestBin - 1) - 1;
1055 binToRemove[0] = (closestBin - 1) - 1;
1049 binToRemove[1] = (closestBin) - 1;
1056 binToRemove[1] = (closestBin) - 1;
1050 binToRemove[2] = (closestBin + 1) - 1;
1057 binToRemove[2] = (closestBin + 1) - 1;
1051 }
1058 }
1052 // 2. ELSE
1059 // 2. ELSE
1053 // => remove the two f_(i) which are around f_RW
1060 // => remove the two f_(i) which are around f_RW
1054 else
1061 else
1055 {
1062 {
1056 binToRemove[0] = (binBelow) - 1;
1063 binToRemove[0] = (binBelow) - 1;
1057 binToRemove[1] = (binAbove) - 1;
1064 binToRemove[1] = (binAbove) - 1;
1058 binToRemove[2] = (-1);
1065 binToRemove[2] = (-1);
1059 }
1066 }
1060
1067
1061 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1068 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1062 {
1069 {
1063 bin = binToRemove[k];
1070 bin = binToRemove[k];
1064 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1071 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1065 {
1072 {
1066 if (flag == 1)
1073 if (flag == 1)
1067 {
1074 {
1068 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1075 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1069 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1076 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1070 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1077 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1071 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1078 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1072 }
1079 }
1073 }
1080 }
1074 }
1081 }
1075 }
1082 }
1076
1083
1077 void build_sy_lfr_rw_mask( unsigned int channel )
1084 void build_sy_lfr_rw_mask( unsigned int channel )
1078 {
1085 {
1079 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1086 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1080 unsigned char *maskPtr;
1087 unsigned char *maskPtr;
1081 double deltaF;
1088 double deltaF;
1082 unsigned k;
1089 unsigned k;
1083
1090
1084 k = 0;
1091 k = 0;
1085
1092
1086 maskPtr = NULL;
1093 maskPtr = NULL;
1087 deltaF = DELTAF_F2;
1094 deltaF = DELTAF_F2;
1088
1095
1089 switch (channel)
1096 switch (channel)
1090 {
1097 {
1091 case CHANNELF0:
1098 case CHANNELF0:
1092 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1099 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1093 deltaF = DELTAF_F0;
1100 deltaF = DELTAF_F0;
1094 break;
1101 break;
1095 case CHANNELF1:
1102 case CHANNELF1:
1096 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1103 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1097 deltaF = DELTAF_F1;
1104 deltaF = DELTAF_F1;
1098 break;
1105 break;
1099 case CHANNELF2:
1106 case CHANNELF2:
1100 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1107 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1101 deltaF = DELTAF_F2;
1108 deltaF = DELTAF_F2;
1102 break;
1109 break;
1103 default:
1110 default:
1104 break;
1111 break;
1105 }
1112 }
1106
1113
1107 for (k = 0; k < BYTES_PER_MASK; k++)
1114 for (k = 0; k < BYTES_PER_MASK; k++)
1108 {
1115 {
1109 local_rw_fbins_mask[k] = INT8_ALL_F;
1116 local_rw_fbins_mask[k] = INT8_ALL_F;
1110 }
1117 }
1111
1118
1112 // RW1 F1
1119 // RW1 F1
1113 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1120 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1114
1121
1115 // RW1 F2
1122 // RW1 F2
1116 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1123 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1117
1124
1118 // RW2 F1
1125 // RW2 F1
1119 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1126 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1120
1127
1121 // RW2 F2
1128 // RW2 F2
1122 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1129 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1123
1130
1124 // RW3 F1
1131 // RW3 F1
1125 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1132 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1126
1133
1127 // RW3 F2
1134 // RW3 F2
1128 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1135 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1129
1136
1130 // RW4 F1
1137 // RW4 F1
1131 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1138 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1132
1139
1133 // RW4 F2
1140 // RW4 F2
1134 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1141 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1135
1142
1136 // update the value of the fbins related to reaction wheels frequency filtering
1143 // update the value of the fbins related to reaction wheels frequency filtering
1137 if (maskPtr != NULL)
1144 if (maskPtr != NULL)
1138 {
1145 {
1139 for (k = 0; k < BYTES_PER_MASK; k++)
1146 for (k = 0; k < BYTES_PER_MASK; k++)
1140 {
1147 {
1141 maskPtr[k] = local_rw_fbins_mask[k];
1148 maskPtr[k] = local_rw_fbins_mask[k];
1142 }
1149 }
1143 }
1150 }
1144 }
1151 }
1145
1152
1146 void build_sy_lfr_rw_masks( void )
1153 void build_sy_lfr_rw_masks( void )
1147 {
1154 {
1148 build_sy_lfr_rw_mask( CHANNELF0 );
1155 build_sy_lfr_rw_mask( CHANNELF0 );
1149 build_sy_lfr_rw_mask( CHANNELF1 );
1156 build_sy_lfr_rw_mask( CHANNELF1 );
1150 build_sy_lfr_rw_mask( CHANNELF2 );
1157 build_sy_lfr_rw_mask( CHANNELF2 );
1151 }
1158 }
1152
1159
1153 void merge_fbins_masks( void )
1160 void merge_fbins_masks( void )
1154 {
1161 {
1155 unsigned char k;
1162 unsigned char k;
1156
1163
1157 unsigned char *fbins_f0;
1164 unsigned char *fbins_f0;
1158 unsigned char *fbins_f1;
1165 unsigned char *fbins_f1;
1159 unsigned char *fbins_f2;
1166 unsigned char *fbins_f2;
1160 unsigned char *rw_mask_f0;
1167 unsigned char *rw_mask_f0;
1161 unsigned char *rw_mask_f1;
1168 unsigned char *rw_mask_f1;
1162 unsigned char *rw_mask_f2;
1169 unsigned char *rw_mask_f2;
1163
1170
1164 fbins_f0 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
1171 fbins_f0 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
1165 fbins_f1 = parameter_dump_packet.sy_lfr_fbins.fx.f1_word1;
1172 fbins_f1 = parameter_dump_packet.sy_lfr_fbins.fx.f1_word1;
1166 fbins_f2 = parameter_dump_packet.sy_lfr_fbins.fx.f2_word1;
1173 fbins_f2 = parameter_dump_packet.sy_lfr_fbins.fx.f2_word1;
1167 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1174 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1168 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1175 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1169 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1176 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1170
1177
1171 for( k=0; k < BYTES_PER_MASK; k++ )
1178 for( k=0; k < BYTES_PER_MASK; k++ )
1172 {
1179 {
1173 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1180 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1174 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1181 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1175 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1182 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1176 }
1183 }
1177 }
1184 }
1178
1185
1179 //***********
1186 //***********
1180 // FBINS MASK
1187 // FBINS MASK
1181
1188
1182 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1189 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1183 {
1190 {
1184 int status;
1191 int status;
1185 unsigned int k;
1192 unsigned int k;
1186 unsigned char *fbins_mask_dump;
1193 unsigned char *fbins_mask_dump;
1187 unsigned char *fbins_mask_TC;
1194 unsigned char *fbins_mask_TC;
1188
1195
1189 status = LFR_SUCCESSFUL;
1196 status = LFR_SUCCESSFUL;
1190
1197
1191 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins.raw;
1198 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins.raw;
1192 fbins_mask_TC = TC->dataAndCRC;
1199 fbins_mask_TC = TC->dataAndCRC;
1193
1200
1194 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1201 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1195 {
1202 {
1196 fbins_mask_dump[k] = fbins_mask_TC[k];
1203 fbins_mask_dump[k] = fbins_mask_TC[k];
1197 }
1204 }
1198
1205
1199 return status;
1206 return status;
1200 }
1207 }
1201
1208
1202 //***************************
1209 //***************************
1203 // TC_LFR_LOAD_PAS_FILTER_PAR
1210 // TC_LFR_LOAD_PAS_FILTER_PAR
1204
1211
1205 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1212 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1206 {
1213 {
1207 int flag;
1214 int flag;
1208 rtems_status_code status;
1215 rtems_status_code status;
1209
1216
1210 unsigned char sy_lfr_pas_filter_enabled;
1217 unsigned char sy_lfr_pas_filter_enabled;
1211 unsigned char sy_lfr_pas_filter_modulus;
1218 unsigned char sy_lfr_pas_filter_modulus;
1212 float sy_lfr_pas_filter_tbad;
1219 float sy_lfr_pas_filter_tbad;
1213 unsigned char sy_lfr_pas_filter_offset;
1220 unsigned char sy_lfr_pas_filter_offset;
1214 float sy_lfr_pas_filter_shift;
1221 float sy_lfr_pas_filter_shift;
1215 float sy_lfr_sc_rw_delta_f;
1222 float sy_lfr_sc_rw_delta_f;
1216 char *parPtr;
1223 char *parPtr;
1217
1224
1218 flag = LFR_SUCCESSFUL;
1225 flag = LFR_SUCCESSFUL;
1219 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1226 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1220 sy_lfr_pas_filter_shift = INIT_FLOAT;
1227 sy_lfr_pas_filter_shift = INIT_FLOAT;
1221 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1228 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1222 parPtr = NULL;
1229 parPtr = NULL;
1223
1230
1224 //***************
1231 //***************
1225 // get parameters
1232 // get parameters
1226 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1233 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1227 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1234 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1228 copyFloatByChar(
1235 copyFloatByChar(
1229 (unsigned char*) &sy_lfr_pas_filter_tbad,
1236 (unsigned char*) &sy_lfr_pas_filter_tbad,
1230 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1237 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1231 );
1238 );
1232 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1239 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1233 copyFloatByChar(
1240 copyFloatByChar(
1234 (unsigned char*) &sy_lfr_pas_filter_shift,
1241 (unsigned char*) &sy_lfr_pas_filter_shift,
1235 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1242 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1236 );
1243 );
1237 copyFloatByChar(
1244 copyFloatByChar(
1238 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1245 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1239 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1246 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1240 );
1247 );
1241
1248
1242 //******************
1249 //******************
1243 // CHECK CONSISTENCY
1250 // CHECK CONSISTENCY
1244
1251
1245 //**************************
1252 //**************************
1246 // sy_lfr_pas_filter_enabled
1253 // sy_lfr_pas_filter_enabled
1247 // nothing to check, value is 0 or 1
1254 // nothing to check, value is 0 or 1
1248
1255
1249 //**************************
1256 //**************************
1250 // sy_lfr_pas_filter_modulus
1257 // sy_lfr_pas_filter_modulus
1251 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1258 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1252 {
1259 {
1253 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1260 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1254 flag = WRONG_APP_DATA;
1261 flag = WRONG_APP_DATA;
1255 }
1262 }
1256
1263
1257 //***********************
1264 //***********************
1258 // sy_lfr_pas_filter_tbad
1265 // sy_lfr_pas_filter_tbad
1259 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1266 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1260 {
1267 {
1261 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1268 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1269 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1263 flag = WRONG_APP_DATA;
1270 flag = WRONG_APP_DATA;
1264 }
1271 }
1265
1272
1266 //*************************
1273 //*************************
1267 // sy_lfr_pas_filter_offset
1274 // sy_lfr_pas_filter_offset
1268 if (flag == LFR_SUCCESSFUL)
1275 if (flag == LFR_SUCCESSFUL)
1269 {
1276 {
1270 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1277 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1271 {
1278 {
1272 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1279 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1273 flag = WRONG_APP_DATA;
1280 flag = WRONG_APP_DATA;
1274 }
1281 }
1275 }
1282 }
1276
1283
1277 //************************
1284 //************************
1278 // sy_lfr_pas_filter_shift
1285 // sy_lfr_pas_filter_shift
1279 if (flag == LFR_SUCCESSFUL)
1286 if (flag == LFR_SUCCESSFUL)
1280 {
1287 {
1281 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1288 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1282 {
1289 {
1283 parPtr = (char*) &sy_lfr_pas_filter_shift;
1290 parPtr = (char*) &sy_lfr_pas_filter_shift;
1284 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1291 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1285 flag = WRONG_APP_DATA;
1292 flag = WRONG_APP_DATA;
1286 }
1293 }
1287 }
1294 }
1288
1295
1289 //*************************************
1296 //*************************************
1290 // check global coherency of the values
1297 // check global coherency of the values
1291 if (flag == LFR_SUCCESSFUL)
1298 if (flag == LFR_SUCCESSFUL)
1292 {
1299 {
1293 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1300 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1294 {
1301 {
1295 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1302 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1296 flag = WRONG_APP_DATA;
1303 flag = WRONG_APP_DATA;
1297 }
1304 }
1298 }
1305 }
1299
1306
1300 //*********************
1307 //*********************
1301 // sy_lfr_sc_rw_delta_f
1308 // sy_lfr_sc_rw_delta_f
1302 // nothing to check, no default value in the ICD
1309 // nothing to check, no default value in the ICD
1303
1310
1304 return flag;
1311 return flag;
1305 }
1312 }
1306
1313
1307 //**************
1314 //**************
1308 // KCOEFFICIENTS
1315 // KCOEFFICIENTS
1309 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1316 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1310 {
1317 {
1311 unsigned int kcoeff;
1318 unsigned int kcoeff;
1312 unsigned short sy_lfr_kcoeff_frequency;
1319 unsigned short sy_lfr_kcoeff_frequency;
1313 unsigned short bin;
1320 unsigned short bin;
1314 unsigned short *freqPtr;
1321 unsigned short *freqPtr;
1315 float *kcoeffPtr_norm;
1322 float *kcoeffPtr_norm;
1316 float *kcoeffPtr_sbm;
1323 float *kcoeffPtr_sbm;
1317 int status;
1324 int status;
1318 unsigned char *kcoeffLoadPtr;
1325 unsigned char *kcoeffLoadPtr;
1319 unsigned char *kcoeffNormPtr;
1326 unsigned char *kcoeffNormPtr;
1320 unsigned char *kcoeffSbmPtr_a;
1327 unsigned char *kcoeffSbmPtr_a;
1321 unsigned char *kcoeffSbmPtr_b;
1328 unsigned char *kcoeffSbmPtr_b;
1322
1329
1323 status = LFR_SUCCESSFUL;
1330 status = LFR_SUCCESSFUL;
1324
1331
1325 kcoeffPtr_norm = NULL;
1332 kcoeffPtr_norm = NULL;
1326 kcoeffPtr_sbm = NULL;
1333 kcoeffPtr_sbm = NULL;
1327 bin = 0;
1334 bin = 0;
1328
1335
1329 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1336 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1330 sy_lfr_kcoeff_frequency = *freqPtr;
1337 sy_lfr_kcoeff_frequency = *freqPtr;
1331
1338
1332 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1339 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1333 {
1340 {
1334 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1341 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1335 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1342 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1336 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1343 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1337 status = LFR_DEFAULT;
1344 status = LFR_DEFAULT;
1338 }
1345 }
1339 else
1346 else
1340 {
1347 {
1341 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1348 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1342 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1349 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1343 {
1350 {
1344 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1351 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1345 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1352 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1346 bin = sy_lfr_kcoeff_frequency;
1353 bin = sy_lfr_kcoeff_frequency;
1347 }
1354 }
1348 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1355 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1349 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1356 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1350 {
1357 {
1351 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1358 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1352 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1359 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1353 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1360 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1354 }
1361 }
1355 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1362 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1356 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1363 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1357 {
1364 {
1358 kcoeffPtr_norm = k_coeff_intercalib_f2;
1365 kcoeffPtr_norm = k_coeff_intercalib_f2;
1359 kcoeffPtr_sbm = NULL;
1366 kcoeffPtr_sbm = NULL;
1360 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1367 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1361 }
1368 }
1362 }
1369 }
1363
1370
1364 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1371 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1365 {
1372 {
1366 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1373 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1367 {
1374 {
1368 // destination
1375 // destination
1369 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1376 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1370 // source
1377 // source
1371 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1378 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1372 // copy source to destination
1379 // copy source to destination
1373 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1380 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1374 }
1381 }
1375 }
1382 }
1376
1383
1377 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1384 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1378 {
1385 {
1379 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1386 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1380 {
1387 {
1381 // destination
1388 // destination
1382 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1389 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1383 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1390 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1384 // source
1391 // source
1385 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1392 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1386 // copy source to destination
1393 // copy source to destination
1387 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1394 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1388 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1395 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1389 }
1396 }
1390 }
1397 }
1391
1398
1392 // print_k_coeff();
1399 // print_k_coeff();
1393
1400
1394 return status;
1401 return status;
1395 }
1402 }
1396
1403
1397 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1404 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1398 {
1405 {
1399 destination[BYTE_0] = source[BYTE_0];
1406 destination[BYTE_0] = source[BYTE_0];
1400 destination[BYTE_1] = source[BYTE_1];
1407 destination[BYTE_1] = source[BYTE_1];
1401 destination[BYTE_2] = source[BYTE_2];
1408 destination[BYTE_2] = source[BYTE_2];
1402 destination[BYTE_3] = source[BYTE_3];
1409 destination[BYTE_3] = source[BYTE_3];
1403 }
1410 }
1404
1411
1405 void floatToChar( float value, unsigned char* ptr)
1412 void floatToChar( float value, unsigned char* ptr)
1406 {
1413 {
1407 unsigned char* valuePtr;
1414 unsigned char* valuePtr;
1408
1415
1409 valuePtr = (unsigned char*) &value;
1416 valuePtr = (unsigned char*) &value;
1410 ptr[BYTE_0] = valuePtr[BYTE_0];
1417 ptr[BYTE_0] = valuePtr[BYTE_0];
1411 ptr[BYTE_1] = valuePtr[BYTE_1];
1418 ptr[BYTE_1] = valuePtr[BYTE_1];
1412 ptr[BYTE_2] = valuePtr[BYTE_2];
1419 ptr[BYTE_2] = valuePtr[BYTE_2];
1413 ptr[BYTE_3] = valuePtr[BYTE_3];
1420 ptr[BYTE_3] = valuePtr[BYTE_3];
1414 }
1421 }
1415
1422
1416 //**********
1423 //**********
1417 // init dump
1424 // init dump
1418
1425
1419 void init_parameter_dump( void )
1426 void init_parameter_dump( void )
1420 {
1427 {
1421 /** This function initialize the parameter_dump_packet global variable with default values.
1428 /** This function initialize the parameter_dump_packet global variable with default values.
1422 *
1429 *
1423 */
1430 */
1424
1431
1425 unsigned int k;
1432 unsigned int k;
1426
1433
1427 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1434 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1428 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1435 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1429 parameter_dump_packet.reserved = CCSDS_RESERVED;
1436 parameter_dump_packet.reserved = CCSDS_RESERVED;
1430 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1437 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1431 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1438 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1432 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1439 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1433 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1440 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1434 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1441 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1435 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1442 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1436 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1443 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1437 // DATA FIELD HEADER
1444 // DATA FIELD HEADER
1438 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1445 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1439 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1446 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1440 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1447 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1441 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1448 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1442 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1449 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1443 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1450 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1444 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1451 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1445 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1452 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1446 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1453 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1447 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1454 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1448 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1455 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1449
1456
1450 //******************
1457 //******************
1451 // COMMON PARAMETERS
1458 // COMMON PARAMETERS
1452 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1459 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1453 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1460 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1454
1461
1455 //******************
1462 //******************
1456 // NORMAL PARAMETERS
1463 // NORMAL PARAMETERS
1457 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1464 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1458 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1465 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1459 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1466 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1460 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1467 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1461 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1468 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1462 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1469 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1463 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1470 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1464 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1471 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1465 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1472 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1466
1473
1467 //*****************
1474 //*****************
1468 // BURST PARAMETERS
1475 // BURST PARAMETERS
1469 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1476 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1470 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1477 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1471
1478
1472 //****************
1479 //****************
1473 // SBM1 PARAMETERS
1480 // SBM1 PARAMETERS
1474 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
1481 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
1475 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1482 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1476
1483
1477 //****************
1484 //****************
1478 // SBM2 PARAMETERS
1485 // SBM2 PARAMETERS
1479 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1486 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1480 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1487 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1481
1488
1482 //************
1489 //************
1483 // FBINS MASKS
1490 // FBINS MASKS
1484 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1491 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1485 {
1492 {
1486 parameter_dump_packet.sy_lfr_fbins.raw[k] = INT8_ALL_F;
1493 parameter_dump_packet.sy_lfr_fbins.raw[k] = INT8_ALL_F;
1487 }
1494 }
1488
1495
1489 // PAS FILTER PARAMETERS
1496 // PAS FILTER PARAMETERS
1490 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1497 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1491 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1498 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1492 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1499 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1493 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1500 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1494 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1501 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1495 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1502 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1496 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1503 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1497
1504
1498 // LFR_RW_MASK
1505 // LFR_RW_MASK
1499 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1506 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1500 {
1507 {
1501 parameter_dump_packet.sy_lfr_rw_mask.raw[k] = INT8_ALL_F;
1508 parameter_dump_packet.sy_lfr_rw_mask.raw[k] = INT8_ALL_F;
1502 }
1509 }
1503
1510
1504 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1511 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1505 merge_fbins_masks();
1512 merge_fbins_masks();
1506 }
1513 }
1507
1514
1508 void init_kcoefficients_dump( void )
1515 void init_kcoefficients_dump( void )
1509 {
1516 {
1510 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1517 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1511 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1518 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1512
1519
1513 kcoefficient_node_1.previous = NULL;
1520 kcoefficient_node_1.previous = NULL;
1514 kcoefficient_node_1.next = NULL;
1521 kcoefficient_node_1.next = NULL;
1515 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1522 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1516 kcoefficient_node_1.coarseTime = INIT_CHAR;
1523 kcoefficient_node_1.coarseTime = INIT_CHAR;
1517 kcoefficient_node_1.fineTime = INIT_CHAR;
1524 kcoefficient_node_1.fineTime = INIT_CHAR;
1518 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1525 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1519 kcoefficient_node_1.status = INIT_CHAR;
1526 kcoefficient_node_1.status = INIT_CHAR;
1520
1527
1521 kcoefficient_node_2.previous = NULL;
1528 kcoefficient_node_2.previous = NULL;
1522 kcoefficient_node_2.next = NULL;
1529 kcoefficient_node_2.next = NULL;
1523 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1530 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1524 kcoefficient_node_2.coarseTime = INIT_CHAR;
1531 kcoefficient_node_2.coarseTime = INIT_CHAR;
1525 kcoefficient_node_2.fineTime = INIT_CHAR;
1532 kcoefficient_node_2.fineTime = INIT_CHAR;
1526 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1533 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1527 kcoefficient_node_2.status = INIT_CHAR;
1534 kcoefficient_node_2.status = INIT_CHAR;
1528 }
1535 }
1529
1536
1530 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1537 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1531 {
1538 {
1532 unsigned int k;
1539 unsigned int k;
1533 unsigned int packetLength;
1540 unsigned int packetLength;
1534
1541
1535 packetLength =
1542 packetLength =
1536 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1543 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1537
1544
1538 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1545 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1539 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1546 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1540 kcoefficients_dump->reserved = CCSDS_RESERVED;
1547 kcoefficients_dump->reserved = CCSDS_RESERVED;
1541 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1548 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1542 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1549 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1543 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1550 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1544 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1551 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1545 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1552 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1546 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1553 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1547 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1554 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1548 // DATA FIELD HEADER
1555 // DATA FIELD HEADER
1549 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1556 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1550 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1557 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1551 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1558 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1552 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1559 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1553 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1560 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1554 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1561 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1555 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1562 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1556 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1563 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1557 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1564 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1558 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1565 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1559 kcoefficients_dump->sid = SID_K_DUMP;
1566 kcoefficients_dump->sid = SID_K_DUMP;
1560
1567
1561 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1568 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1562 kcoefficients_dump->pkt_nr = PKTNR_1;
1569 kcoefficients_dump->pkt_nr = PKTNR_1;
1563 kcoefficients_dump->blk_nr = blk_nr;
1570 kcoefficients_dump->blk_nr = blk_nr;
1564
1571
1565 //******************
1572 //******************
1566 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1573 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1567 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1574 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1568 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1575 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1569 {
1576 {
1570 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1577 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1571 }
1578 }
1572 }
1579 }
1573
1580
1574 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1581 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1575 {
1582 {
1576 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1583 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1577 *
1584 *
1578 * @param packet_sequence_control points to the packet sequence control which will be incremented
1585 * @param packet_sequence_control points to the packet sequence control which will be incremented
1579 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1586 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1580 *
1587 *
1581 * If the destination ID is not known, a dedicated counter is incremented.
1588 * If the destination ID is not known, a dedicated counter is incremented.
1582 *
1589 *
1583 */
1590 */
1584
1591
1585 unsigned short sequence_cnt;
1592 unsigned short sequence_cnt;
1586 unsigned short segmentation_grouping_flag;
1593 unsigned short segmentation_grouping_flag;
1587 unsigned short new_packet_sequence_control;
1594 unsigned short new_packet_sequence_control;
1588 unsigned char i;
1595 unsigned char i;
1589
1596
1590 switch (destination_id)
1597 switch (destination_id)
1591 {
1598 {
1592 case SID_TC_GROUND:
1599 case SID_TC_GROUND:
1593 i = GROUND;
1600 i = GROUND;
1594 break;
1601 break;
1595 case SID_TC_MISSION_TIMELINE:
1602 case SID_TC_MISSION_TIMELINE:
1596 i = MISSION_TIMELINE;
1603 i = MISSION_TIMELINE;
1597 break;
1604 break;
1598 case SID_TC_TC_SEQUENCES:
1605 case SID_TC_TC_SEQUENCES:
1599 i = TC_SEQUENCES;
1606 i = TC_SEQUENCES;
1600 break;
1607 break;
1601 case SID_TC_RECOVERY_ACTION_CMD:
1608 case SID_TC_RECOVERY_ACTION_CMD:
1602 i = RECOVERY_ACTION_CMD;
1609 i = RECOVERY_ACTION_CMD;
1603 break;
1610 break;
1604 case SID_TC_BACKUP_MISSION_TIMELINE:
1611 case SID_TC_BACKUP_MISSION_TIMELINE:
1605 i = BACKUP_MISSION_TIMELINE;
1612 i = BACKUP_MISSION_TIMELINE;
1606 break;
1613 break;
1607 case SID_TC_DIRECT_CMD:
1614 case SID_TC_DIRECT_CMD:
1608 i = DIRECT_CMD;
1615 i = DIRECT_CMD;
1609 break;
1616 break;
1610 case SID_TC_SPARE_GRD_SRC1:
1617 case SID_TC_SPARE_GRD_SRC1:
1611 i = SPARE_GRD_SRC1;
1618 i = SPARE_GRD_SRC1;
1612 break;
1619 break;
1613 case SID_TC_SPARE_GRD_SRC2:
1620 case SID_TC_SPARE_GRD_SRC2:
1614 i = SPARE_GRD_SRC2;
1621 i = SPARE_GRD_SRC2;
1615 break;
1622 break;
1616 case SID_TC_OBCP:
1623 case SID_TC_OBCP:
1617 i = OBCP;
1624 i = OBCP;
1618 break;
1625 break;
1619 case SID_TC_SYSTEM_CONTROL:
1626 case SID_TC_SYSTEM_CONTROL:
1620 i = SYSTEM_CONTROL;
1627 i = SYSTEM_CONTROL;
1621 break;
1628 break;
1622 case SID_TC_AOCS:
1629 case SID_TC_AOCS:
1623 i = AOCS;
1630 i = AOCS;
1624 break;
1631 break;
1625 case SID_TC_RPW_INTERNAL:
1632 case SID_TC_RPW_INTERNAL:
1626 i = RPW_INTERNAL;
1633 i = RPW_INTERNAL;
1627 break;
1634 break;
1628 default:
1635 default:
1629 i = GROUND;
1636 i = GROUND;
1630 break;
1637 break;
1631 }
1638 }
1632
1639
1633 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1640 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1634 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1641 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1635
1642
1636 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1643 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1637
1644
1638 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1645 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1639 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1646 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1640
1647
1641 // increment the sequence counter
1648 // increment the sequence counter
1642 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1649 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1643 {
1650 {
1644 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1651 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1645 }
1652 }
1646 else
1653 else
1647 {
1654 {
1648 sequenceCounters_TM_DUMP[ i ] = 0;
1655 sequenceCounters_TM_DUMP[ i ] = 0;
1649 }
1656 }
1650 }
1657 }
@@ -1,1319 +1,1343
1 /** Functions and tasks related to waveform packet generation.
1 /** Functions and tasks related to waveform packet generation.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
7 *
8 */
8 */
9
9
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11
11
12 //***************
12 //***************
13 // waveform rings
13 // waveform rings
14 // F0
14 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
16 ring_node *current_ring_node_f0;
16 ring_node *current_ring_node_f0;
17 ring_node *ring_node_to_send_swf_f0;
17 ring_node *ring_node_to_send_swf_f0;
18 // F1
18 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
20 ring_node *current_ring_node_f1;
20 ring_node *current_ring_node_f1;
21 ring_node *ring_node_to_send_swf_f1;
21 ring_node *ring_node_to_send_swf_f1;
22 ring_node *ring_node_to_send_cwf_f1;
22 ring_node *ring_node_to_send_cwf_f1;
23 // F2
23 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
25 ring_node *current_ring_node_f2;
25 ring_node *current_ring_node_f2;
26 ring_node *ring_node_to_send_swf_f2;
26 ring_node *ring_node_to_send_swf_f2;
27 ring_node *ring_node_to_send_cwf_f2;
27 ring_node *ring_node_to_send_cwf_f2;
28 // F3
28 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
30 ring_node *current_ring_node_f3;
30 ring_node *current_ring_node_f3;
31 ring_node *ring_node_to_send_cwf_f3;
31 ring_node *ring_node_to_send_cwf_f3;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
33
33
34 bool extractSWF1 = false;
34 bool extractSWF1 = false;
35 bool extractSWF2 = false;
35 bool extractSWF2 = false;
36 bool swf0_ready_flag_f1 = false;
36 bool swf0_ready_flag_f1 = false;
37 bool swf0_ready_flag_f2 = false;
37 bool swf0_ready_flag_f2 = false;
38 bool swf1_ready = false;
38 bool swf1_ready = false;
39 bool swf2_ready = false;
39 bool swf2_ready = false;
40
40
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
43 ring_node ring_node_swf1_extracted;
43 ring_node ring_node_swf1_extracted;
44 ring_node ring_node_swf2_extracted;
44 ring_node ring_node_swf2_extracted;
45
45
46 typedef enum resynchro_state_t
46 typedef enum resynchro_state_t
47 {
47 {
48 MEASURE,
48 MEASURE,
49 CORRECTION
49 CORRECTION
50 } resynchro_state;
50 } resynchro_state;
51
51
52 //*********************
52 //*********************
53 // Interrupt SubRoutine
53 // Interrupt SubRoutine
54
54
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 {
56 {
57 ring_node *node;
57 ring_node *node;
58
58
59 node = NULL;
59 node = NULL;
60 switch ( frequencyChannel ) {
60 switch ( frequencyChannel ) {
61 case CHANNELF1:
61 case CHANNELF1:
62 node = ring_node_to_send_cwf_f1;
62 node = ring_node_to_send_cwf_f1;
63 break;
63 break;
64 case CHANNELF2:
64 case CHANNELF2:
65 node = ring_node_to_send_cwf_f2;
65 node = ring_node_to_send_cwf_f2;
66 break;
66 break;
67 case CHANNELF3:
67 case CHANNELF3:
68 node = ring_node_to_send_cwf_f3;
68 node = ring_node_to_send_cwf_f3;
69 break;
69 break;
70 default:
70 default:
71 break;
71 break;
72 }
72 }
73
73
74 return node;
74 return node;
75 }
75 }
76
76
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 {
78 {
79 ring_node *node;
79 ring_node *node;
80
80
81 node = NULL;
81 node = NULL;
82 switch ( frequencyChannel ) {
82 switch ( frequencyChannel ) {
83 case CHANNELF0:
83 case CHANNELF0:
84 node = ring_node_to_send_swf_f0;
84 node = ring_node_to_send_swf_f0;
85 break;
85 break;
86 case CHANNELF1:
86 case CHANNELF1:
87 node = ring_node_to_send_swf_f1;
87 node = ring_node_to_send_swf_f1;
88 break;
88 break;
89 case CHANNELF2:
89 case CHANNELF2:
90 node = ring_node_to_send_swf_f2;
90 node = ring_node_to_send_swf_f2;
91 break;
91 break;
92 default:
92 default:
93 break;
93 break;
94 }
94 }
95
95
96 return node;
96 return node;
97 }
97 }
98
98
99 void reset_extractSWF( void )
99 void reset_extractSWF( void )
100 {
100 {
101 extractSWF1 = false;
101 extractSWF1 = false;
102 extractSWF2 = false;
102 extractSWF2 = false;
103 swf0_ready_flag_f1 = false;
103 swf0_ready_flag_f1 = false;
104 swf0_ready_flag_f2 = false;
104 swf0_ready_flag_f2 = false;
105 swf1_ready = false;
105 swf1_ready = false;
106 swf2_ready = false;
106 swf2_ready = false;
107 }
107 }
108
108
109 inline void waveforms_isr_f3( void )
109 inline void waveforms_isr_f3( void )
110 {
110 {
111 rtems_status_code spare_status;
111 rtems_status_code spare_status;
112
112
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 //***
116 //***
117 // F3
117 // F3
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 current_ring_node_f3 = current_ring_node_f3->next;
120 current_ring_node_f3 = current_ring_node_f3->next;
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 }
126 }
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 }
132 }
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 }
135 }
136 }
136 }
137 }
137 }
138 }
138 }
139
139
140 inline void waveforms_isr_burst( void )
140 inline void waveforms_isr_burst( void )
141 {
141 {
142 unsigned char status;
142 unsigned char status;
143 rtems_status_code spare_status;
143 rtems_status_code spare_status;
144
144
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146
146
147 switch(status)
147 switch(status)
148 {
148 {
149 case BIT_WFP_BUFFER_0:
149 case BIT_WFP_BUFFER_0:
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
154 current_ring_node_f2 = current_ring_node_f2->next;
154 current_ring_node_f2 = current_ring_node_f2->next;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 }
158 }
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
160 break;
160 break;
161 case BIT_WFP_BUFFER_1:
161 case BIT_WFP_BUFFER_1:
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
166 current_ring_node_f2 = current_ring_node_f2->next;
166 current_ring_node_f2 = current_ring_node_f2->next;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
170 }
170 }
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
172 break;
172 break;
173 default:
173 default:
174 break;
174 break;
175 }
175 }
176 }
176 }
177
177
178 inline void waveform_isr_normal_sbm1_sbm2( void )
178 inline void waveform_isr_normal_sbm1_sbm2( void )
179 {
179 {
180 rtems_status_code status;
180 rtems_status_code status;
181
181
182 //***
182 //***
183 // F0
183 // F0
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
185 {
185 {
186 swf0_ready_flag_f1 = true;
186 swf0_ready_flag_f1 = true;
187 swf0_ready_flag_f2 = true;
187 swf0_ready_flag_f2 = true;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
189 current_ring_node_f0 = current_ring_node_f0->next;
189 current_ring_node_f0 = current_ring_node_f0->next;
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
191 {
191 {
192
192
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
197 }
197 }
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
199 {
199 {
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
204 }
204 }
205 // send an event to the WFRM task for resynchro activities
205 // send an event to the WFRM task for resynchro activities
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
207 }
207 }
208
208
209 //***
209 //***
210 // F1
210 // F1
211 if ( (waveform_picker_regs->status & 0x0c) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
211 if ( (waveform_picker_regs->status & 0x0c) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
212 // (1) change the receiving buffer for the waveform picker
212 // (1) change the receiving buffer for the waveform picker
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
214 current_ring_node_f1 = current_ring_node_f1->next;
214 current_ring_node_f1 = current_ring_node_f1->next;
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
216 {
216 {
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
221 }
221 }
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
223 {
223 {
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
228 }
228 }
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
231 }
231 }
232
232
233 //***
233 //***
234 // F2
234 // F2
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
236 // (1) change the receiving buffer for the waveform picker
236 // (1) change the receiving buffer for the waveform picker
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
239 current_ring_node_f2 = current_ring_node_f2->next;
239 current_ring_node_f2 = current_ring_node_f2->next;
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
241 {
241 {
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
246 }
246 }
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
248 {
248 {
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
253 }
253 }
254 // (2) send an event for the waveforms transmission
254 // (2) send an event for the waveforms transmission
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
256 }
256 }
257 }
257 }
258
258
259 rtems_isr waveforms_isr( rtems_vector_number vector )
259 rtems_isr waveforms_isr( rtems_vector_number vector )
260 {
260 {
261 /** This is the interrupt sub routine called by the waveform picker core.
261 /** This is the interrupt sub routine called by the waveform picker core.
262 *
262 *
263 * This ISR launch different actions depending mainly on two pieces of information:
263 * This ISR launch different actions depending mainly on two pieces of information:
264 * 1. the values read in the registers of the waveform picker.
264 * 1. the values read in the registers of the waveform picker.
265 * 2. the current LFR mode.
265 * 2. the current LFR mode.
266 *
266 *
267 */
267 */
268
268
269 // STATUS
269 // STATUS
270 // new error error buffer full
270 // new error error buffer full
271 // 15 14 13 12 11 10 9 8
271 // 15 14 13 12 11 10 9 8
272 // f3 f2 f1 f0 f3 f2 f1 f0
272 // f3 f2 f1 f0 f3 f2 f1 f0
273 //
273 //
274 // ready buffer
274 // ready buffer
275 // 7 6 5 4 3 2 1 0
275 // 7 6 5 4 3 2 1 0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
277
277
278 rtems_status_code spare_status;
278 rtems_status_code spare_status;
279
279
280 waveforms_isr_f3();
280 waveforms_isr_f3();
281
281
282 //*************************************************
282 //*************************************************
283 // copy the status bits in the housekeeping packets
283 // copy the status bits in the housekeeping packets
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
286
286
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
288 {
288 {
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
290 }
290 }
291
291
292 switch(lfrCurrentMode)
292 switch(lfrCurrentMode)
293 {
293 {
294 //********
294 //********
295 // STANDBY
295 // STANDBY
296 case LFR_MODE_STANDBY:
296 case LFR_MODE_STANDBY:
297 break;
297 break;
298 //**************************
298 //**************************
299 // LFR NORMAL, SBM1 and SBM2
299 // LFR NORMAL, SBM1 and SBM2
300 case LFR_MODE_NORMAL:
300 case LFR_MODE_NORMAL:
301 case LFR_MODE_SBM1:
301 case LFR_MODE_SBM1:
302 case LFR_MODE_SBM2:
302 case LFR_MODE_SBM2:
303 waveform_isr_normal_sbm1_sbm2();
303 waveform_isr_normal_sbm1_sbm2();
304 break;
304 break;
305 //******
305 //******
306 // BURST
306 // BURST
307 case LFR_MODE_BURST:
307 case LFR_MODE_BURST:
308 waveforms_isr_burst();
308 waveforms_isr_burst();
309 break;
309 break;
310 //********
310 //********
311 // DEFAULT
311 // DEFAULT
312 default:
312 default:
313 break;
313 break;
314 }
314 }
315 }
315 }
316
316
317 //************
317 //************
318 // RTEMS TASKS
318 // RTEMS TASKS
319
319
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
321 {
321 {
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
323 *
323 *
324 * @param unused is the starting argument of the RTEMS task
324 * @param unused is the starting argument of the RTEMS task
325 *
325 *
326 * The following data packets are sent by this task:
326 * The following data packets are sent by this task:
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
330 *
330 *
331 */
331 */
332
332
333 rtems_event_set event_out;
333 rtems_event_set event_out;
334 rtems_id queue_id;
334 rtems_id queue_id;
335 rtems_status_code status;
335 rtems_status_code status;
336 ring_node *ring_node_swf1_extracted_ptr;
336 ring_node *ring_node_swf1_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
338
338
339 event_out = EVENT_SETS_NONE_PENDING;
340 queue_id = RTEMS_ID_NONE;
341
339 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
342 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
340 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
343 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
341
344
342 status = get_message_queue_id_send( &queue_id );
345 status = get_message_queue_id_send( &queue_id );
343 if (status != RTEMS_SUCCESSFUL)
346 if (status != RTEMS_SUCCESSFUL)
344 {
347 {
345 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
348 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
346 }
349 }
347
350
348 BOOT_PRINTF("in WFRM ***\n");
351 BOOT_PRINTF("in WFRM ***\n");
349
352
350 while(1){
353 while(1){
351 // wait for an RTEMS_EVENT
354 // wait for an RTEMS_EVENT
352 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
355 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
353 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
356 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
354
357
355 if (event_out == RTEMS_EVENT_MODE_NORMAL)
358 if (event_out == RTEMS_EVENT_MODE_NORMAL)
356 {
359 {
357 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
360 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
358 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
361 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
359 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
362 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
360 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
363 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
361 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
364 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
362 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
365 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
363 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
366 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
364 }
367 }
365 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
368 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
366 {
369 {
367 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
370 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
368 }
371 }
369 }
372 }
370 }
373 }
371
374
372 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
375 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
373 {
376 {
374 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
377 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
375 *
378 *
376 * @param unused is the starting argument of the RTEMS task
379 * @param unused is the starting argument of the RTEMS task
377 *
380 *
378 * The following data packet is sent by this task:
381 * The following data packet is sent by this task:
379 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
382 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
380 *
383 *
381 */
384 */
382
385
383 rtems_event_set event_out;
386 rtems_event_set event_out;
384 rtems_id queue_id;
387 rtems_id queue_id;
385 rtems_status_code status;
388 rtems_status_code status;
386 ring_node ring_node_cwf3_light;
389 ring_node ring_node_cwf3_light;
387 ring_node *ring_node_to_send_cwf;
390 ring_node *ring_node_to_send_cwf;
388
391
392 event_out = EVENT_SETS_NONE_PENDING;
393 queue_id = RTEMS_ID_NONE;
394
389 status = get_message_queue_id_send( &queue_id );
395 status = get_message_queue_id_send( &queue_id );
390 if (status != RTEMS_SUCCESSFUL)
396 if (status != RTEMS_SUCCESSFUL)
391 {
397 {
392 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
398 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
393 }
399 }
394
400
395 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
401 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
396
402
397 // init the ring_node_cwf3_light structure
403 // init the ring_node_cwf3_light structure
398 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
404 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
399 ring_node_cwf3_light.coarseTime = INIT_CHAR;
405 ring_node_cwf3_light.coarseTime = INIT_CHAR;
400 ring_node_cwf3_light.fineTime = INIT_CHAR;
406 ring_node_cwf3_light.fineTime = INIT_CHAR;
401 ring_node_cwf3_light.next = NULL;
407 ring_node_cwf3_light.next = NULL;
402 ring_node_cwf3_light.previous = NULL;
408 ring_node_cwf3_light.previous = NULL;
403 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
409 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
404 ring_node_cwf3_light.status = INIT_CHAR;
410 ring_node_cwf3_light.status = INIT_CHAR;
405
411
406 BOOT_PRINTF("in CWF3 ***\n");
412 BOOT_PRINTF("in CWF3 ***\n");
407
413
408 while(1){
414 while(1){
409 // wait for an RTEMS_EVENT
415 // wait for an RTEMS_EVENT
410 rtems_event_receive( RTEMS_EVENT_0,
416 rtems_event_receive( RTEMS_EVENT_0,
411 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
417 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
412 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
418 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
413 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
419 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
414 {
420 {
415 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
421 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
416 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
422 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
417 {
423 {
418 PRINTF("send CWF_LONG_F3\n");
424 PRINTF("send CWF_LONG_F3\n");
419 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
425 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
420 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
426 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
421 }
427 }
422 else
428 else
423 {
429 {
424 PRINTF("send CWF_F3 (light)\n");
430 PRINTF("send CWF_F3 (light)\n");
425 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
431 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
426 }
432 }
427
433
428 }
434 }
429 else
435 else
430 {
436 {
431 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
437 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
432 }
438 }
433 }
439 }
434 }
440 }
435
441
436 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
442 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
437 {
443 {
438 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
444 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
439 *
445 *
440 * @param unused is the starting argument of the RTEMS task
446 * @param unused is the starting argument of the RTEMS task
441 *
447 *
442 * The following data packet is sent by this function:
448 * The following data packet is sent by this function:
443 * - TM_LFR_SCIENCE_BURST_CWF_F2
449 * - TM_LFR_SCIENCE_BURST_CWF_F2
444 * - TM_LFR_SCIENCE_SBM2_CWF_F2
450 * - TM_LFR_SCIENCE_SBM2_CWF_F2
445 *
451 *
446 */
452 */
447
453
448 rtems_event_set event_out;
454 rtems_event_set event_out;
449 rtems_id queue_id;
455 rtems_id queue_id;
450 rtems_status_code status;
456 rtems_status_code status;
451 ring_node *ring_node_to_send;
457 ring_node *ring_node_to_send;
452 unsigned long long int acquisitionTimeF0_asLong;
458 unsigned long long int acquisitionTimeF0_asLong;
453
459
460 event_out = EVENT_SETS_NONE_PENDING;
461 queue_id = RTEMS_ID_NONE;
462
454 acquisitionTimeF0_asLong = INIT_CHAR;
463 acquisitionTimeF0_asLong = INIT_CHAR;
455
464
456 status = get_message_queue_id_send( &queue_id );
465 status = get_message_queue_id_send( &queue_id );
457 if (status != RTEMS_SUCCESSFUL)
466 if (status != RTEMS_SUCCESSFUL)
458 {
467 {
459 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
468 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
460 }
469 }
461
470
462 BOOT_PRINTF("in CWF2 ***\n");
471 BOOT_PRINTF("in CWF2 ***\n");
463
472
464 while(1){
473 while(1){
465 // wait for an RTEMS_EVENT// send the snapshot when built
474 // wait for an RTEMS_EVENT// send the snapshot when built
466 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
475 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
467 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
476 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
468 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
477 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
469 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
478 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
470 if (event_out == RTEMS_EVENT_MODE_BURST)
479 if (event_out == RTEMS_EVENT_MODE_BURST)
471 { // data are sent whatever the transition time
480 { // data are sent whatever the transition time
472 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
473 }
482 }
474 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
483 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
475 {
484 {
476 if ( lfrCurrentMode == LFR_MODE_SBM2 )
485 if ( lfrCurrentMode == LFR_MODE_SBM2 )
477 {
486 {
478 // data are sent depending on the transition time
487 // data are sent depending on the transition time
479 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
488 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
480 {
489 {
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
490 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
482 }
491 }
483 }
492 }
484 // launch snapshot extraction if needed
493 // launch snapshot extraction if needed
485 if (extractSWF2 == true)
494 if (extractSWF2 == true)
486 {
495 {
487 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
496 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
488 // extract the snapshot
497 // extract the snapshot
489 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
498 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
490 &ring_node_swf2_extracted, swf2_extracted );
499 &ring_node_swf2_extracted, swf2_extracted );
491 extractSWF2 = false;
500 extractSWF2 = false;
492 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
501 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
493 }
502 }
494 if (swf0_ready_flag_f2 == true)
503 if (swf0_ready_flag_f2 == true)
495 {
504 {
496 extractSWF2 = true;
505 extractSWF2 = true;
497 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
506 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
498 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
507 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
499 swf0_ready_flag_f2 = false;
508 swf0_ready_flag_f2 = false;
500 }
509 }
501 }
510 }
502 }
511 }
503 }
512 }
504
513
505 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
514 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
506 {
515 {
507 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
516 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
508 *
517 *
509 * @param unused is the starting argument of the RTEMS task
518 * @param unused is the starting argument of the RTEMS task
510 *
519 *
511 * The following data packet is sent by this function:
520 * The following data packet is sent by this function:
512 * - TM_LFR_SCIENCE_SBM1_CWF_F1
521 * - TM_LFR_SCIENCE_SBM1_CWF_F1
513 *
522 *
514 */
523 */
515
524
516 rtems_event_set event_out;
525 rtems_event_set event_out;
517 rtems_id queue_id;
526 rtems_id queue_id;
518 rtems_status_code status;
527 rtems_status_code status;
519
528
520 ring_node *ring_node_to_send_cwf;
529 ring_node *ring_node_to_send_cwf;
521
530
531 event_out = EVENT_SETS_NONE_PENDING;
532 queue_id = RTEMS_ID_NONE;
533
522 status = get_message_queue_id_send( &queue_id );
534 status = get_message_queue_id_send( &queue_id );
523 if (status != RTEMS_SUCCESSFUL)
535 if (status != RTEMS_SUCCESSFUL)
524 {
536 {
525 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
537 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
526 }
538 }
527
539
528 BOOT_PRINTF("in CWF1 ***\n");
540 BOOT_PRINTF("in CWF1 ***\n");
529
541
530 while(1){
542 while(1){
531 // wait for an RTEMS_EVENT
543 // wait for an RTEMS_EVENT
532 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
544 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
533 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
545 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
534 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
546 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
535 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
547 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
536 if (lfrCurrentMode == LFR_MODE_SBM1)
548 if (lfrCurrentMode == LFR_MODE_SBM1)
537 {
549 {
538 // data are sent depending on the transition time
550 // data are sent depending on the transition time
539 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
551 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
540 {
552 {
541 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
553 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
542 }
554 }
543 }
555 }
544 // launch snapshot extraction if needed
556 // launch snapshot extraction if needed
545 if (extractSWF1 == true)
557 if (extractSWF1 == true)
546 {
558 {
547 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
559 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
548 // launch the snapshot extraction
560 // launch the snapshot extraction
549 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
561 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
550 extractSWF1 = false;
562 extractSWF1 = false;
551 }
563 }
552 if (swf0_ready_flag_f1 == true)
564 if (swf0_ready_flag_f1 == true)
553 {
565 {
554 extractSWF1 = true;
566 extractSWF1 = true;
555 swf0_ready_flag_f1 = false; // this step shall be executed only one time
567 swf0_ready_flag_f1 = false; // this step shall be executed only one time
556 }
568 }
557 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
569 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
558 {
570 {
559 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
571 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
560 swf1_ready = false;
572 swf1_ready = false;
561 swf2_ready = false;
573 swf2_ready = false;
562 }
574 }
563 }
575 }
564 }
576 }
565
577
566 rtems_task swbd_task(rtems_task_argument argument)
578 rtems_task swbd_task(rtems_task_argument argument)
567 {
579 {
568 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
580 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
569 *
581 *
570 * @param unused is the starting argument of the RTEMS task
582 * @param unused is the starting argument of the RTEMS task
571 *
583 *
572 */
584 */
573
585
574 rtems_event_set event_out;
586 rtems_event_set event_out;
575 unsigned long long int acquisitionTimeF0_asLong;
587 unsigned long long int acquisitionTimeF0_asLong;
576
588
589 event_out = EVENT_SETS_NONE_PENDING;
577 acquisitionTimeF0_asLong = INIT_CHAR;
590 acquisitionTimeF0_asLong = INIT_CHAR;
578
591
579 BOOT_PRINTF("in SWBD ***\n")
592 BOOT_PRINTF("in SWBD ***\n")
580
593
581 while(1){
594 while(1){
582 // wait for an RTEMS_EVENT
595 // wait for an RTEMS_EVENT
583 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
596 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
584 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
597 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
585 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
598 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
586 {
599 {
587 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
600 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
588 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
601 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
589 &ring_node_swf1_extracted, swf1_extracted );
602 &ring_node_swf1_extracted, swf1_extracted );
590 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
603 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
591 }
604 }
592 else
605 else
593 {
606 {
594 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
607 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
595 }
608 }
596 }
609 }
597 }
610 }
598
611
599 //******************
612 //******************
600 // general functions
613 // general functions
601
614
602 void WFP_init_rings( void )
615 void WFP_init_rings( void )
603 {
616 {
604 // F0 RING
617 // F0 RING
605 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
618 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
606 // F1 RING
619 // F1 RING
607 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
620 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
608 // F2 RING
621 // F2 RING
609 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
622 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
610 // F3 RING
623 // F3 RING
611 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
624 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
612
625
613 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
626 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
614 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
627 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
615
628
616 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
629 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
617 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
630 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
618 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
631 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
619 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
632 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
620 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
633 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
621 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
634 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
622 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
635 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
623 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
636 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
624
637
625 }
638 }
626
639
627 void WFP_reset_current_ring_nodes( void )
640 void WFP_reset_current_ring_nodes( void )
628 {
641 {
629 current_ring_node_f0 = waveform_ring_f0[0].next;
642 current_ring_node_f0 = waveform_ring_f0[0].next;
630 current_ring_node_f1 = waveform_ring_f1[0].next;
643 current_ring_node_f1 = waveform_ring_f1[0].next;
631 current_ring_node_f2 = waveform_ring_f2[0].next;
644 current_ring_node_f2 = waveform_ring_f2[0].next;
632 current_ring_node_f3 = waveform_ring_f3[0].next;
645 current_ring_node_f3 = waveform_ring_f3[0].next;
633
646
634 ring_node_to_send_swf_f0 = waveform_ring_f0;
647 ring_node_to_send_swf_f0 = waveform_ring_f0;
635 ring_node_to_send_swf_f1 = waveform_ring_f1;
648 ring_node_to_send_swf_f1 = waveform_ring_f1;
636 ring_node_to_send_swf_f2 = waveform_ring_f2;
649 ring_node_to_send_swf_f2 = waveform_ring_f2;
637
650
638 ring_node_to_send_cwf_f1 = waveform_ring_f1;
651 ring_node_to_send_cwf_f1 = waveform_ring_f1;
639 ring_node_to_send_cwf_f2 = waveform_ring_f2;
652 ring_node_to_send_cwf_f2 = waveform_ring_f2;
640 ring_node_to_send_cwf_f3 = waveform_ring_f3;
653 ring_node_to_send_cwf_f3 = waveform_ring_f3;
641 }
654 }
642
655
643 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
656 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
644 {
657 {
645 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
658 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
646 *
659 *
647 * @param waveform points to the buffer containing the data that will be send.
660 * @param waveform points to the buffer containing the data that will be send.
648 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
661 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
649 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
662 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
650 * contain information to setup the transmission of the data packets.
663 * contain information to setup the transmission of the data packets.
651 *
664 *
652 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
665 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
653 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
666 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
654 *
667 *
655 */
668 */
656
669
657 unsigned int i;
670 unsigned int i;
658 unsigned int j;
671 unsigned int j;
659 int ret;
672 int ret;
660 rtems_status_code status;
673 rtems_status_code status;
661
674
662 char *sample;
675 char *sample;
663 int *dataPtr;
676 int *dataPtr;
664
677
665 ret = LFR_DEFAULT;
678 ret = LFR_DEFAULT;
666
679
667 dataPtr = (int*) ring_node_to_send->buffer_address;
680 dataPtr = (int*) ring_node_to_send->buffer_address;
668
681
669 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
682 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
670 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
683 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
671
684
672 //**********************
685 //**********************
673 // BUILD CWF3_light DATA
686 // BUILD CWF3_light DATA
674 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
687 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
675 {
688 {
676 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
689 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
677 for (j=0; j < CWF_BLK_SIZE; j++)
690 for (j=0; j < CWF_BLK_SIZE; j++)
678 {
691 {
679 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
692 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
680 }
693 }
681 }
694 }
682
695
683 // SEND PACKET
696 // SEND PACKET
684 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
697 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
685 if (status != RTEMS_SUCCESSFUL) {
698 if (status != RTEMS_SUCCESSFUL) {
686 ret = LFR_DEFAULT;
699 ret = LFR_DEFAULT;
687 }
700 }
688
701
689 return ret;
702 return ret;
690 }
703 }
691
704
692 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
705 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
693 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
706 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
694 {
707 {
695 unsigned long long int acquisitionTimeAsLong;
708 unsigned long long int acquisitionTimeAsLong;
696 unsigned char localAcquisitionTime[BYTES_PER_TIME];
709 unsigned char localAcquisitionTime[BYTES_PER_TIME];
697 double deltaT;
710 double deltaT;
698
711
699 deltaT = INIT_FLOAT;
712 deltaT = INIT_FLOAT;
700
713
701 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
714 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
702 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
715 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
703 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
716 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
704 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
717 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
705 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
718 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
706 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
719 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
707
720
708 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
721 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
709 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
722 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
710 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
723 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
711 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
724 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
712 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
725 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
713 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
726 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
714
727
715 switch( sid )
728 switch( sid )
716 {
729 {
717 case SID_NORM_SWF_F0:
730 case SID_NORM_SWF_F0:
718 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
731 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
719 break;
732 break;
720
733
721 case SID_NORM_SWF_F1:
734 case SID_NORM_SWF_F1:
722 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
735 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
723 break;
736 break;
724
737
725 case SID_NORM_SWF_F2:
738 case SID_NORM_SWF_F2:
726 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
739 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
727 break;
740 break;
728
741
729 case SID_SBM1_CWF_F1:
742 case SID_SBM1_CWF_F1:
730 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
743 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
731 break;
744 break;
732
745
733 case SID_SBM2_CWF_F2:
746 case SID_SBM2_CWF_F2:
734 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
747 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
735 break;
748 break;
736
749
737 case SID_BURST_CWF_F2:
750 case SID_BURST_CWF_F2:
738 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
751 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
739 break;
752 break;
740
753
741 case SID_NORM_CWF_F3:
754 case SID_NORM_CWF_F3:
742 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
755 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
743 break;
756 break;
744
757
745 case SID_NORM_CWF_LONG_F3:
758 case SID_NORM_CWF_LONG_F3:
746 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
759 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
747 break;
760 break;
748
761
749 default:
762 default:
750 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
763 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
751 deltaT = 0.;
764 deltaT = 0.;
752 break;
765 break;
753 }
766 }
754
767
755 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
768 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
756 //
769 //
757 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
770 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
758 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
771 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
759 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
772 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
760 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
773 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
761 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
774 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
762 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
775 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
763
776
764 }
777 }
765
778
766 void build_snapshot_from_ring( ring_node *ring_node_to_send,
779 void build_snapshot_from_ring( ring_node *ring_node_to_send,
767 unsigned char frequencyChannel,
780 unsigned char frequencyChannel,
768 unsigned long long int acquisitionTimeF0_asLong,
781 unsigned long long int acquisitionTimeF0_asLong,
769 ring_node *ring_node_swf_extracted,
782 ring_node *ring_node_swf_extracted,
770 int *swf_extracted)
783 int *swf_extracted)
771 {
784 {
772 unsigned int i;
785 unsigned int i;
773 unsigned int node;
786 unsigned int node;
774 unsigned long long int centerTime_asLong;
787 unsigned long long int centerTime_asLong;
775 unsigned long long int acquisitionTime_asLong;
788 unsigned long long int acquisitionTime_asLong;
776 unsigned long long int bufferAcquisitionTime_asLong;
789 unsigned long long int bufferAcquisitionTime_asLong;
777 unsigned char *ptr1;
790 unsigned char *ptr1;
778 unsigned char *ptr2;
791 unsigned char *ptr2;
779 unsigned char *timeCharPtr;
792 unsigned char *timeCharPtr;
780 unsigned char nb_ring_nodes;
793 unsigned char nb_ring_nodes;
781 unsigned long long int frequency_asLong;
794 unsigned long long int frequency_asLong;
782 unsigned long long int nbTicksPerSample_asLong;
795 unsigned long long int nbTicksPerSample_asLong;
783 unsigned long long int nbSamplesPart1_asLong;
796 unsigned long long int nbSamplesPart1_asLong;
784 unsigned long long int sampleOffset_asLong;
797 unsigned long long int sampleOffset_asLong;
785
798
786 unsigned int deltaT_F0;
799 unsigned int deltaT_F0;
787 unsigned int deltaT_F1;
800 unsigned int deltaT_F1;
788 unsigned long long int deltaT_F2;
801 unsigned long long int deltaT_F2;
789
802
790 deltaT_F0 = DELTAT_F0;
803 deltaT_F0 = DELTAT_F0;
791 deltaT_F1 = DELTAF_F1;
804 deltaT_F1 = DELTAF_F1;
792 deltaT_F2 = DELTAF_F2;
805 deltaT_F2 = DELTAF_F2;
793 sampleOffset_asLong = INIT_CHAR;
806 sampleOffset_asLong = INIT_CHAR;
794
807
795 // (1) get the f0 acquisition time => the value is passed in argument
808 // (1) get the f0 acquisition time => the value is passed in argument
796
809
797 // (2) compute the central reference time
810 // (2) compute the central reference time
798 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
811 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
812 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
813 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
814 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
799
815
800 // (3) compute the acquisition time of the current snapshot
816 // (3) compute the acquisition time of the current snapshot
801 switch(frequencyChannel)
817 switch(frequencyChannel)
802 {
818 {
803 case CHANNELF1: // 1 is for F1 = 4096 Hz
819 case CHANNELF1: // 1 is for F1 = 4096 Hz
804 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
820 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
805 nb_ring_nodes = NB_RING_NODES_F1;
821 nb_ring_nodes = NB_RING_NODES_F1;
806 frequency_asLong = FREQ_F1;
822 frequency_asLong = FREQ_F1;
807 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
823 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
808 break;
824 break;
809 case CHANNELF2: // 2 is for F2 = 256 Hz
825 case CHANNELF2: // 2 is for F2 = 256 Hz
810 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
826 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
811 nb_ring_nodes = NB_RING_NODES_F2;
827 nb_ring_nodes = NB_RING_NODES_F2;
812 frequency_asLong = FREQ_F2;
828 frequency_asLong = FREQ_F2;
813 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
829 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
814 break;
830 break;
815 default:
831 default:
816 acquisitionTime_asLong = centerTime_asLong;
832 acquisitionTime_asLong = centerTime_asLong;
817 nb_ring_nodes = 0;
833 nb_ring_nodes = 0;
818 frequency_asLong = FREQ_F2;
834 frequency_asLong = FREQ_F2;
819 nbTicksPerSample_asLong = TICKS_PER_T2;
835 nbTicksPerSample_asLong = TICKS_PER_T2;
820 break;
836 break;
821 }
837 }
822
838
823 //*****************************************************************************
839 //*****************************************************************************
824 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
840 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
825 node = 0;
841 node = 0;
826 while ( node < nb_ring_nodes)
842 while ( node < nb_ring_nodes)
827 {
843 {
828 //PRINTF1("%d ... ", node);
844 //PRINTF1("%d ... ", node);
829 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
830 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
831 {
847 {
832 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
848 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
833 node = nb_ring_nodes;
849 node = nb_ring_nodes;
834 }
850 }
835 else
851 else
836 {
852 {
837 node = node + 1;
853 node = node + 1;
838 ring_node_to_send = ring_node_to_send->previous;
854 ring_node_to_send = ring_node_to_send->previous;
839 }
855 }
840 }
856 }
841
857
842 // (5) compute the number of samples to take in the current buffer
858 // (5) compute the number of samples to take in the current buffer
843 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
859 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
844 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
860 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
845 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
861 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
846
862
847 // (6) compute the final acquisition time
863 // (6) compute the final acquisition time
848 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
864 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
849 (sampleOffset_asLong * nbTicksPerSample_asLong);
865 (sampleOffset_asLong * nbTicksPerSample_asLong);
850
866
851 // (7) copy the acquisition time at the beginning of the extrated snapshot
867 // (7) copy the acquisition time at the beginning of the extrated snapshot
852 ptr1 = (unsigned char*) &acquisitionTime_asLong;
868 ptr1 = (unsigned char*) &acquisitionTime_asLong;
853 // fine time
869 // fine time
854 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
870 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
855 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
871 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
856 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
872 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
857 // coarse time
873 // coarse time
858 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
874 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
859 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
875 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
860 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
876 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
861 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
877 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
862 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
878 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
863
879
864 // re set the synchronization bit
880 // re set the synchronization bit
865 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
881 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
866 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
882 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
867
883
868 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
884 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
869 {
885 {
870 nbSamplesPart1_asLong = 0;
886 nbSamplesPart1_asLong = 0;
871 }
887 }
872 // copy the part 1 of the snapshot in the extracted buffer
888 // copy the part 1 of the snapshot in the extracted buffer
873 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
889 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
874 {
890 {
875 swf_extracted[i] =
891 swf_extracted[i] =
876 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
892 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
877 }
893 }
878 // copy the part 2 of the snapshot in the extracted buffer
894 // copy the part 2 of the snapshot in the extracted buffer
879 ring_node_to_send = ring_node_to_send->next;
895 ring_node_to_send = ring_node_to_send->next;
880 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
896 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
881 {
897 {
882 swf_extracted[i] =
898 swf_extracted[i] =
883 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
899 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
884 }
900 }
885 }
901 }
886
902
887 double computeCorrection( unsigned char *timePtr )
903 double computeCorrection( unsigned char *timePtr )
888 {
904 {
889 unsigned long long int acquisitionTime;
905 unsigned long long int acquisitionTime;
890 unsigned long long int centerTime;
906 unsigned long long int centerTime;
891 unsigned long long int previousTick;
907 unsigned long long int previousTick;
892 unsigned long long int nextTick;
908 unsigned long long int nextTick;
893 unsigned long long int deltaPreviousTick;
909 unsigned long long int deltaPreviousTick;
894 unsigned long long int deltaNextTick;
910 unsigned long long int deltaNextTick;
895 double deltaPrevious_ms;
911 double deltaPrevious_ms;
896 double deltaNext_ms;
912 double deltaNext_ms;
897 double correctionInF2;
913 double correctionInF2;
898
914
915 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
916
899 // get acquisition time in fine time ticks
917 // get acquisition time in fine time ticks
900 acquisitionTime = get_acquisition_time( timePtr );
918 acquisitionTime = get_acquisition_time( timePtr );
901
919
902 // compute center time
920 // compute center time
903 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
921 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
904 previousTick = centerTime - (centerTime & INT16_ALL_F);
922 previousTick = centerTime - (centerTime & INT16_ALL_F);
905 nextTick = previousTick + TICKS_PER_S;
923 nextTick = previousTick + TICKS_PER_S;
906
924
907 deltaPreviousTick = centerTime - previousTick;
925 deltaPreviousTick = centerTime - previousTick;
908 deltaNextTick = nextTick - centerTime;
926 deltaNextTick = nextTick - centerTime;
909
927
910 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
928 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
911 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
929 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
912
930
913 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
931 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
914
932
915 // which tick is the closest?
933 // which tick is the closest?
916 if (deltaPreviousTick > deltaNextTick)
934 if (deltaPreviousTick > deltaNextTick)
917 {
935 {
918 // the snapshot center is just before the second => increase delta_snapshot
936 // the snapshot center is just before the second => increase delta_snapshot
919 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
937 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
920 }
938 }
921 else
939 else
922 {
940 {
923 // the snapshot center is just after the second => decrease delta_snapshot
941 // the snapshot center is just after the second => decrease delta_snapshot
924 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
942 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
925 }
943 }
926
944
927 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
945 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
928
946
929 return correctionInF2;
947 return correctionInF2;
930 }
948 }
931
949
932 void applyCorrection( double correction )
950 void applyCorrection( double correction )
933 {
951 {
934 int correctionInt;
952 int correctionInt;
935
953
954 correctionInt = 0;
955
936 if (correction >= 0.)
956 if (correction >= 0.)
937 {
957 {
938 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
958 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
939 {
959 {
940 correctionInt = ONE_TICK_CORR;
960 correctionInt = ONE_TICK_CORR;
941 }
961 }
942 else
962 else
943 {
963 {
944 correctionInt = CORR_MULT * floor(correction);
964 correctionInt = CORR_MULT * floor(correction);
945 }
965 }
946 }
966 }
947 else
967 else
948 {
968 {
949 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
969 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
950 {
970 {
951 correctionInt = -ONE_TICK_CORR;
971 correctionInt = -ONE_TICK_CORR;
952 }
972 }
953 else
973 else
954 {
974 {
955 correctionInt = CORR_MULT * ceil(correction);
975 correctionInt = CORR_MULT * ceil(correction);
956 }
976 }
957 }
977 }
958 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
978 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
959 }
979 }
960
980
961 void snapshot_resynchronization( unsigned char *timePtr )
981 void snapshot_resynchronization( unsigned char *timePtr )
962 {
982 {
963 /** This function compute a correction to apply on delta_snapshot.
983 /** This function compute a correction to apply on delta_snapshot.
964 *
984 *
965 *
985 *
966 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
986 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
967 *
987 *
968 * @return void
988 * @return void
969 *
989 *
970 */
990 */
971
991
972 static double correction = INIT_FLOAT;
992 static double correction = INIT_FLOAT;
973 static resynchro_state state = MEASURE;
993 static resynchro_state state = MEASURE;
974 static unsigned int nbSnapshots = 0;
994 static unsigned int nbSnapshots = 0;
975
995
976 int correctionInt;
996 int correctionInt;
977
997
978 correctionInt = 0;
998 correctionInt = 0;
979
999
980 switch (state)
1000 switch (state)
981 {
1001 {
982
1002
983 case MEASURE:
1003 case MEASURE:
984 // ********
1004 // ********
985 PRINTF1("MEASURE === %d\n", nbSnapshots);
1005 PRINTF1("MEASURE === %d\n", nbSnapshots);
986 state = CORRECTION;
1006 state = CORRECTION;
987 correction = computeCorrection( timePtr );
1007 correction = computeCorrection( timePtr );
988 PRINTF1("MEASURE === correction = %.2f\n", correction );
1008 PRINTF1("MEASURE === correction = %.2f\n", correction );
989 applyCorrection( correction );
1009 applyCorrection( correction );
990 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1010 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
991 //****
1011 //****
992 break;
1012 break;
993
1013
994 case CORRECTION:
1014 case CORRECTION:
995 //************
1015 //************
996 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1016 PRINTF1("CORRECTION === %d\n", nbSnapshots);
997 state = MEASURE;
1017 state = MEASURE;
998 computeCorrection( timePtr );
1018 computeCorrection( timePtr );
999 set_wfp_delta_snapshot();
1019 set_wfp_delta_snapshot();
1000 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1020 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1001 //****
1021 //****
1002 break;
1022 break;
1003
1023
1004 default:
1024 default:
1005 break;
1025 break;
1006
1026
1007 }
1027 }
1008
1028
1009 nbSnapshots++;
1029 nbSnapshots++;
1010 }
1030 }
1011
1031
1012 //**************
1032 //**************
1013 // wfp registers
1033 // wfp registers
1014 void reset_wfp_burst_enable( void )
1034 void reset_wfp_burst_enable( void )
1015 {
1035 {
1016 /** This function resets the waveform picker burst_enable register.
1036 /** This function resets the waveform picker burst_enable register.
1017 *
1037 *
1018 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1038 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1019 *
1039 *
1020 */
1040 */
1021
1041
1022 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1042 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1023 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1043 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1024 }
1044 }
1025
1045
1026 void reset_wfp_status( void )
1046 void reset_wfp_status( void )
1027 {
1047 {
1028 /** This function resets the waveform picker status register.
1048 /** This function resets the waveform picker status register.
1029 *
1049 *
1030 * All status bits are set to 0 [new_err full_err full].
1050 * All status bits are set to 0 [new_err full_err full].
1031 *
1051 *
1032 */
1052 */
1033
1053
1034 waveform_picker_regs->status = INT16_ALL_F;
1054 waveform_picker_regs->status = INT16_ALL_F;
1035 }
1055 }
1036
1056
1037 void reset_wfp_buffer_addresses( void )
1057 void reset_wfp_buffer_addresses( void )
1038 {
1058 {
1039 // F0
1059 // F0
1040 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1060 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1041 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1061 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1042 // F1
1062 // F1
1043 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1063 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1044 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1064 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1045 // F2
1065 // F2
1046 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1066 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1047 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1067 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1048 // F3
1068 // F3
1049 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1069 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1050 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1070 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1051 }
1071 }
1052
1072
1053 void reset_waveform_picker_regs( void )
1073 void reset_waveform_picker_regs( void )
1054 {
1074 {
1055 /** This function resets the waveform picker module registers.
1075 /** This function resets the waveform picker module registers.
1056 *
1076 *
1057 * The registers affected by this function are located at the following offset addresses:
1077 * The registers affected by this function are located at the following offset addresses:
1058 * - 0x00 data_shaping
1078 * - 0x00 data_shaping
1059 * - 0x04 run_burst_enable
1079 * - 0x04 run_burst_enable
1060 * - 0x08 addr_data_f0
1080 * - 0x08 addr_data_f0
1061 * - 0x0C addr_data_f1
1081 * - 0x0C addr_data_f1
1062 * - 0x10 addr_data_f2
1082 * - 0x10 addr_data_f2
1063 * - 0x14 addr_data_f3
1083 * - 0x14 addr_data_f3
1064 * - 0x18 status
1084 * - 0x18 status
1065 * - 0x1C delta_snapshot
1085 * - 0x1C delta_snapshot
1066 * - 0x20 delta_f0
1086 * - 0x20 delta_f0
1067 * - 0x24 delta_f0_2
1087 * - 0x24 delta_f0_2
1068 * - 0x28 delta_f1 (obsolet parameter)
1088 * - 0x28 delta_f1 (obsolet parameter)
1069 * - 0x2c delta_f2
1089 * - 0x2c delta_f2
1070 * - 0x30 nb_data_by_buffer
1090 * - 0x30 nb_data_by_buffer
1071 * - 0x34 nb_snapshot_param
1091 * - 0x34 nb_snapshot_param
1072 * - 0x38 start_date
1092 * - 0x38 start_date
1073 * - 0x3c nb_word_in_buffer
1093 * - 0x3c nb_word_in_buffer
1074 *
1094 *
1075 */
1095 */
1076
1096
1077 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1097 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1078
1098
1079 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1099 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1080
1100
1081 reset_wfp_buffer_addresses();
1101 reset_wfp_buffer_addresses();
1082
1102
1083 reset_wfp_status(); // 0x18
1103 reset_wfp_status(); // 0x18
1084
1104
1085 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1105 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1086
1106
1087 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1107 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1088
1108
1089 //the parameter delta_f1 [0x28] is not used anymore
1109 //the parameter delta_f1 [0x28] is not used anymore
1090
1110
1091 set_wfp_delta_f2(); // 0x2c
1111 set_wfp_delta_f2(); // 0x2c
1092
1112
1093 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1113 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1094 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1114 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1095 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1115 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1096 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1116 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1097 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1117 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1098 // 2688 = 8 * 336
1118 // 2688 = 8 * 336
1099 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1119 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1100 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1120 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1101 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1121 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1102 //
1122 //
1103 // coarse time and fine time registers are not initialized, they are volatile
1123 // coarse time and fine time registers are not initialized, they are volatile
1104 //
1124 //
1105 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1125 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1106 }
1126 }
1107
1127
1108 void set_wfp_data_shaping( void )
1128 void set_wfp_data_shaping( void )
1109 {
1129 {
1110 /** This function sets the data_shaping register of the waveform picker module.
1130 /** This function sets the data_shaping register of the waveform picker module.
1111 *
1131 *
1112 * The value is read from one field of the parameter_dump_packet structure:\n
1132 * The value is read from one field of the parameter_dump_packet structure:\n
1113 * bw_sp0_sp1_r0_r1
1133 * bw_sp0_sp1_r0_r1
1114 *
1134 *
1115 */
1135 */
1116
1136
1117 unsigned char data_shaping;
1137 unsigned char data_shaping;
1118
1138
1119 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1139 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1120 // waveform picker : [R1 R0 SP1 SP0 BW]
1140 // waveform picker : [R1 R0 SP1 SP0 BW]
1121
1141
1122 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1142 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1123
1143
1124 waveform_picker_regs->data_shaping =
1144 waveform_picker_regs->data_shaping =
1125 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1145 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1126 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1146 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1127 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1147 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1128 + ( (data_shaping & BIT_2) << 1 ) // R0
1148 + ( (data_shaping & BIT_2) << 1 ) // R0
1129 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1149 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1130 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1150 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1131 }
1151 }
1132
1152
1133 void set_wfp_burst_enable_register( unsigned char mode )
1153 void set_wfp_burst_enable_register( unsigned char mode )
1134 {
1154 {
1135 /** This function sets the waveform picker burst_enable register depending on the mode.
1155 /** This function sets the waveform picker burst_enable register depending on the mode.
1136 *
1156 *
1137 * @param mode is the LFR mode to launch.
1157 * @param mode is the LFR mode to launch.
1138 *
1158 *
1139 * The burst bits shall be before the enable bits.
1159 * The burst bits shall be before the enable bits.
1140 *
1160 *
1141 */
1161 */
1142
1162
1143 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1163 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1144 // the burst bits shall be set first, before the enable bits
1164 // the burst bits shall be set first, before the enable bits
1145 switch(mode) {
1165 switch(mode) {
1146 case LFR_MODE_NORMAL:
1166 case LFR_MODE_NORMAL:
1147 case LFR_MODE_SBM1:
1167 case LFR_MODE_SBM1:
1148 case LFR_MODE_SBM2:
1168 case LFR_MODE_SBM2:
1149 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1169 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1150 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1170 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1151 break;
1171 break;
1152 case LFR_MODE_BURST:
1172 case LFR_MODE_BURST:
1153 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1173 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1154 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2
1174 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2
1155 break;
1175 break;
1156 default:
1176 default:
1157 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1177 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1158 break;
1178 break;
1159 }
1179 }
1160 }
1180 }
1161
1181
1162 void set_wfp_delta_snapshot( void )
1182 void set_wfp_delta_snapshot( void )
1163 {
1183 {
1164 /** This function sets the delta_snapshot register of the waveform picker module.
1184 /** This function sets the delta_snapshot register of the waveform picker module.
1165 *
1185 *
1166 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1186 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1167 * - sy_lfr_n_swf_p[0]
1187 * - sy_lfr_n_swf_p[0]
1168 * - sy_lfr_n_swf_p[1]
1188 * - sy_lfr_n_swf_p[1]
1169 *
1189 *
1170 */
1190 */
1171
1191
1172 unsigned int delta_snapshot;
1192 unsigned int delta_snapshot;
1173 unsigned int delta_snapshot_in_T2;
1193 unsigned int delta_snapshot_in_T2;
1174
1194
1175 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1195 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1176 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1196 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1177
1197
1178 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1198 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1179 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1199 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1180 }
1200 }
1181
1201
1182 void set_wfp_delta_f0_f0_2( void )
1202 void set_wfp_delta_f0_f0_2( void )
1183 {
1203 {
1184 unsigned int delta_snapshot;
1204 unsigned int delta_snapshot;
1185 unsigned int nb_samples_per_snapshot;
1205 unsigned int nb_samples_per_snapshot;
1186 float delta_f0_in_float;
1206 float delta_f0_in_float;
1187
1207
1188 delta_snapshot = waveform_picker_regs->delta_snapshot;
1208 delta_snapshot = waveform_picker_regs->delta_snapshot;
1189 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1209 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1190 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1210 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1191
1211
1192 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1212 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1193 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; // 48 = 11 0000, max 7 bits
1213 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; // 48 = 11 0000, max 7 bits
1194 }
1214 }
1195
1215
1196 void set_wfp_delta_f1( void )
1216 void set_wfp_delta_f1( void )
1197 {
1217 {
1198 /** Sets the value of the delta_f1 parameter
1218 /** Sets the value of the delta_f1 parameter
1199 *
1219 *
1200 * @param void
1220 * @param void
1201 *
1221 *
1202 * @return void
1222 * @return void
1203 *
1223 *
1204 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1224 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1205 *
1225 *
1206 */
1226 */
1207
1227
1208 unsigned int delta_snapshot;
1228 unsigned int delta_snapshot;
1209 unsigned int nb_samples_per_snapshot;
1229 unsigned int nb_samples_per_snapshot;
1210 float delta_f1_in_float;
1230 float delta_f1_in_float;
1211
1231
1212 delta_snapshot = waveform_picker_regs->delta_snapshot;
1232 delta_snapshot = waveform_picker_regs->delta_snapshot;
1213 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1233 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1214 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1234 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1215
1235
1216 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1236 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1217 }
1237 }
1218
1238
1219 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1239 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1220 {
1240 {
1221 /** Sets the value of the delta_f2 parameter
1241 /** Sets the value of the delta_f2 parameter
1222 *
1242 *
1223 * @param void
1243 * @param void
1224 *
1244 *
1225 * @return void
1245 * @return void
1226 *
1246 *
1227 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1247 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1228 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1248 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1229 *
1249 *
1230 */
1250 */
1231
1251
1232 unsigned int delta_snapshot;
1252 unsigned int delta_snapshot;
1233 unsigned int nb_samples_per_snapshot;
1253 unsigned int nb_samples_per_snapshot;
1234
1254
1235 delta_snapshot = waveform_picker_regs->delta_snapshot;
1255 delta_snapshot = waveform_picker_regs->delta_snapshot;
1236 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1256 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1237
1257
1238 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1258 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1239 }
1259 }
1240
1260
1241 //*****************
1261 //*****************
1242 // local parameters
1262 // local parameters
1243
1263
1244 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1264 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1245 {
1265 {
1246 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1266 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1247 *
1267 *
1248 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1268 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1249 * @param sid is the source identifier of the packet being updated.
1269 * @param sid is the source identifier of the packet being updated.
1250 *
1270 *
1251 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1271 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1252 * The sequence counters shall wrap around from 2^14 to zero.
1272 * The sequence counters shall wrap around from 2^14 to zero.
1253 * The sequence counter shall start at zero at startup.
1273 * The sequence counter shall start at zero at startup.
1254 *
1274 *
1255 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1275 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1256 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1276 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1257 *
1277 *
1258 */
1278 */
1259
1279
1260 unsigned short *sequence_cnt;
1280 unsigned short *sequence_cnt;
1261 unsigned short segmentation_grouping_flag;
1281 unsigned short segmentation_grouping_flag;
1262 unsigned short new_packet_sequence_control;
1282 unsigned short new_packet_sequence_control;
1263 rtems_mode initial_mode_set;
1283 rtems_mode initial_mode_set;
1264 rtems_mode current_mode_set;
1284 rtems_mode current_mode_set;
1265 rtems_status_code status;
1285 rtems_status_code status;
1266
1286
1287 initial_mode_set = RTEMS_DEFAULT_MODES;
1288 current_mode_set = RTEMS_DEFAULT_MODES;
1289 sequence_cnt = NULL;
1290
1267 //******************************************
1291 //******************************************
1268 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1292 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1269 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1293 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1270
1294
1271 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1295 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1272 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1296 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1273 || (sid == SID_BURST_CWF_F2)
1297 || (sid == SID_BURST_CWF_F2)
1274 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1298 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1275 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1299 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1276 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1300 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1277 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1301 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1278 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1302 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1279 {
1303 {
1280 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1304 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1281 }
1305 }
1282 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1306 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1283 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1307 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1284 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1308 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1285 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1309 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1286 {
1310 {
1287 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1311 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1288 }
1312 }
1289 else
1313 else
1290 {
1314 {
1291 sequence_cnt = (unsigned short *) NULL;
1315 sequence_cnt = (unsigned short *) NULL;
1292 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1316 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1293 }
1317 }
1294
1318
1295 if (sequence_cnt != NULL)
1319 if (sequence_cnt != NULL)
1296 {
1320 {
1297 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1321 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1298 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1322 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1299
1323
1300 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1324 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1301
1325
1302 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1326 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1303 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1327 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1304
1328
1305 // increment the sequence counter
1329 // increment the sequence counter
1306 if ( *sequence_cnt < SEQ_CNT_MAX)
1330 if ( *sequence_cnt < SEQ_CNT_MAX)
1307 {
1331 {
1308 *sequence_cnt = *sequence_cnt + 1;
1332 *sequence_cnt = *sequence_cnt + 1;
1309 }
1333 }
1310 else
1334 else
1311 {
1335 {
1312 *sequence_cnt = 0;
1336 *sequence_cnt = 0;
1313 }
1337 }
1314 }
1338 }
1315
1339
1316 //*************************************
1340 //*************************************
1317 // RESTORE THE MODE OF THE CALLING TASK
1341 // RESTORE THE MODE OF THE CALLING TASK
1318 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1342 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1319 }
1343 }
General Comments 0
You need to be logged in to leave comments. Login now