##// END OF EJS Templates
Corrections:...
paul -
r107:c303d2da6108 VHDLib206
parent child
Show More
@@ -0,0 +1,41
1 #ifndef TIMEGEN_INIT_H_INCLUDED
2 #define TIMEGEN_INIT_H_INCLUDED
3
4 #include <rtems.h>
5 #include <leon.h>
6
7 #include "fsw_params.h"
8 #include "fsw_misc.h"
9 #include "fsw_processing.h"
10 #include "wf_handler.h"
11
12 #include "timegen_spacewire.h"
13 #include "timegen_misc.h"
14
15 extern rtems_name Task_name[20]; /* array of task names */
16 extern rtems_id Task_id[20]; /* array of task ids */
17
18 // RTEMS TASKS
19 rtems_task Init( rtems_task_argument argument);
20
21 // OTHER functions
22 void create_names( void );
23 int create_all_tasks( void );
24 int start_all_tasks( void );
25 //
26 rtems_status_code create_message_queues( void );
27 rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
28 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
29 //
30 int start_recv_send_tasks( void );
31 //
32 void init_local_mode_parameters( void );
33 void reset_local_time( void );
34
35 extern int rtems_cpu_usage_report( void );
36 extern int rtems_cpu_usage_reset( void );
37 extern void rtems_stack_checker_report_usage( void );
38
39 extern int sched_yield( void );
40
41 #endif // TIMEGEN_INIT_H_INCLUDED
@@ -0,0 +1,39
1 #ifndef TIMEGEN_MISC_H_INCLUDED
2 #define TIMEGEN_MISC_H_INCLUDED
3
4 #include <rtems.h>
5 #include <leon.h>
6
7 #include "fsw_params.h"
8 #include "TC_types.h"
9 #include "tc_acceptance.h"
10 #include "timegen_init.h"
11
12 #define TASK_PRIORITY_UPDT 40
13
14 typedef struct {
15 unsigned char targetLogicalAddress;
16 unsigned char protocolIdentifier;
17 unsigned char reserved;
18 unsigned char userApplication;
19 // PACKET HEADER
20 Packet_TC_LFR_UPDATE_TIME_t update_time;
21 } Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t;
22
23 unsigned int coarseTime;
24
25 rtems_name rtems_name_updt;
26 rtems_id rtems_id_updt;
27
28 void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
29
30 void initCoarseTime( void );
31
32 rtems_task updt_task( rtems_task_argument unused );
33
34 int send_tc_lfr_update_time( rtems_id queue_id );
35
36 #endif // TIMEGEN_MISC_H_INCLUDED
37
38
39
@@ -0,0 +1,48
1 #ifndef TIMEGEN_SPACEWIRE_H_INCLUDED
2 #define TIMEGEN_SPACEWIRE_H_INCLUDED
3
4 #include <rtems.h>
5 #include <grspw.h>
6
7 #include <fcntl.h> // for O_RDWR
8 #include <unistd.h> // for the read call
9 #include <sys/ioctl.h> // for the ioctl call
10 #include <errno.h>
11
12 #include "fsw_params.h"
13 #include "tc_acceptance.h"
14 #include "timegen_tc_handler.h"
15
16 #define DESTINATION_ID_LFR 0xfe
17 #define DESTINATION_ID_DPU 0x01
18 #define SPACEWIRE_LINK_LFR 0x01
19 #define NODEADDR_TIMEGEN 0xfd
20
21 extern rtems_id Task_id[20]; /* array of task ids */
22 extern int fdSPW;
23
24 extern spw_stats spacewire_stats;
25 extern spw_stats spacewire_stats_backup;
26
27 // RTEMS TASK
28 rtems_task spiq_task( rtems_task_argument argument );
29 rtems_task recv_task( rtems_task_argument unused );
30 rtems_task send_task( rtems_task_argument argument );
31 rtems_task wtdg_task( rtems_task_argument argument );
32
33 int spacewire_open_link( void );
34 int spacewire_start_link( int fd );
35 int spacewire_stop_start_link( int fd );
36 int spacewire_configure_link(int fd );
37 int spacewire_reset_link( void );
38 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
39 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
40 void spacewire_compute_stats_offsets( void );
41 void spacewire_update_statistics( void );
42
43 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
44 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data );
45
46 void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc );
47
48 #endif // TIMEGEN_SPACEWIRE_H_INCLUDED
@@ -0,0 +1,56
1 #ifndef TIMEGEN_TC_HANDLER_H_INCLUDED
2 #define TIMEGEN_TC_HANDLER_H_INCLUDED
3
4 #include <rtems.h>
5 #include <leon.h>
6
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
9 #include "tm_lfr_tc_exe.h"
10
11 // MODE PARAMETERS
12 extern unsigned int maxCount;
13
14 //****
15 // ISR
16 rtems_isr commutation_isr1( rtems_vector_number vector );
17 rtems_isr commutation_isr2( rtems_vector_number vector );
18
19 //***********
20 // RTEMS TASK
21 rtems_task actn_task( rtems_task_argument unused );
22
23 //***********
24 // TC ACTIONS
25 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
26 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
27 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
28 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
29 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
30 int action_update_time(ccsdsTelecommandPacket_t *TC);
31
32 // mode transition
33 int transition_validation(unsigned char requestedMode);
34 int stop_current_mode( void );
35 int enter_mode(unsigned char mode);
36 int restart_science_tasks();
37 int suspend_science_tasks();
38 void launch_waveform_picker( unsigned char mode );
39 void launch_spectral_matrix( unsigned char mode );
40 void set_irq_on_new_ready_matrix(unsigned char value );
41 void set_run_matrix_spectral( unsigned char value );
42 void launch_spectral_matrix_simu( unsigned char mode );
43
44 // other functions
45 void updateLFRCurrentMode();
46 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC );
47 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC );
48 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
49
50 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
51 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
52
53 #endif // TIMEGEN_TC_HANDLER_H_INCLUDED
54
55
56
@@ -0,0 +1,476
1 /** This is the RTEMS initialization module.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
10 */
11
12 //*************************
13 // GPL reminder to be added
14 //*************************
15
16 #include <rtems.h>
17
18 /* configuration information */
19
20 #define CONFIGURE_INIT
21
22 #include <bsp.h> /* for device driver prototypes */
23
24 /* configuration information */
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
38 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 2
39 #ifdef PRINT_STACK_REPORT
40 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #endif
42
43 #include <rtems/confdefs.h>
44
45 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef LEON3
48 /* Add Timer and UART Driver */
49 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
50 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
51 #endif
52 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
53 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
54 #endif
55 #endif
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
57 #include <drvmgr/drvmgr_confdefs.h>
58 #endif
59
60 #include "timegen_init.h"
61 #include "fsw_config.c"
62
63 rtems_task Init( rtems_task_argument ignored )
64 {
65 /** This is the RTEMS INIT taks, it the first task launched by the system.
66 *
67 * @param unused is the starting argument of the RTEMS task
68 *
69 * The INIT task create and run all other RTEMS tasks.
70 *
71 */
72
73 rtems_status_code status;
74 rtems_status_code status_spw;
75
76 // initCoarseTime();
77
78 // UART settings
79 send_console_outputs_on_apbuart_port();
80 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
81 enable_apbuart_transmitter();
82 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
83
84 PRINTF("\n\n\n\n\n")
85 PRINTF("*************************\n")
86 PRINTF("** Time Generator **\n")
87 PRINTF1("** %d.", SW_VERSION_N1)
88 PRINTF1("%d.", SW_VERSION_N2)
89 PRINTF1("%d.", SW_VERSION_N3)
90 PRINTF1("%d **\n", SW_VERSION_N4)
91 PRINTF("*************************\n")
92 PRINTF("\n\n")
93
94 // init_local_mode_parameters();
95 // init_housekeeping_parameters();
96
97 // updateLFRCurrentMode();
98
99 // BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
100
101 create_names(); // create all names
102
103 status = create_message_queues(); // create message queues
104 if (status != RTEMS_SUCCESSFUL)
105 {
106 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
107 }
108
109 status = create_all_tasks(); // create all tasks
110 if (status != RTEMS_SUCCESSFUL)
111 {
112 PRINTF1("in INIT *** ERR in create_all_tasks, code %d", status)
113 }
114
115 // **************************
116 // <SPACEWIRE INITIALIZATION>
117 grspw_timecode_callback = &timegen_timecode_irq_handler;
118
119 status_spw = spacewire_open_link(); // (1) open the link
120 if ( status_spw != RTEMS_SUCCESSFUL )
121 {
122 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
123 }
124
125 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
126 {
127 status_spw = spacewire_configure_link( fdSPW );
128 if ( status_spw != RTEMS_SUCCESSFUL )
129 {
130 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
131 }
132 }
133
134 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
135 {
136 status_spw = spacewire_start_link( fdSPW );
137 if ( status_spw != RTEMS_SUCCESSFUL )
138 {
139 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
140 }
141 }
142 // </SPACEWIRE INITIALIZATION>
143 // ***************************
144
145 status = start_all_tasks(); // start all tasks
146 if (status != RTEMS_SUCCESSFUL)
147 {
148 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
149 }
150
151 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
152 status = start_recv_send_tasks();
153 if ( status != RTEMS_SUCCESSFUL )
154 {
155 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
156 }
157
158 // suspend science tasks. they will be restarted later depending on the mode
159 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
160 if (status != RTEMS_SUCCESSFUL)
161 {
162 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
163 }
164
165 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
166 if ( status_spw != RTEMS_SUCCESSFUL )
167 {
168 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
169 if ( status != RTEMS_SUCCESSFUL ) {
170 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
171 }
172 }
173
174 BOOT_PRINTF("delete INIT\n")
175
176 status = rtems_task_delete(RTEMS_SELF);
177
178 }
179
180 void init_local_mode_parameters( void )
181 {
182 /** This function initialize the param_local global variable with default values.
183 *
184 */
185
186 unsigned int i;
187
188 // LOCAL PARAMETERS
189 // set_local_nb_interrupt_f0_MAX();
190
191 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
192 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
193 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
194
195 // init sequence counters
196
197 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
198 {
199 sequenceCounters_TC_EXE[i] = 0x00;
200 }
201 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
202 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
203 }
204
205 void create_names( void ) // create all names for tasks and queues
206 {
207 /** This function creates all RTEMS names used in the software for tasks and queues.
208 *
209 * @return RTEMS directive status codes:
210 * - RTEMS_SUCCESSFUL - successful completion
211 *
212 */
213
214 // task names
215 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
216 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
217 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
218 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
219 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
220 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
221 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
222 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
223 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
224 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
225 Task_name[TASKID_MATR] = rtems_build_name( 'M', 'A', 'T', 'R' );
226 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
227 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
228 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
229 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
230 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
231
232 // TIMEGEN
233 rtems_name_updt = rtems_build_name( 'U', 'P', 'D', 'T' );
234
235 // rate monotonic period names
236 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
237
238 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
239 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
240 }
241
242 int create_all_tasks( void ) // create all tasks which run in the software
243 {
244 /** This function creates all RTEMS tasks used in the software.
245 *
246 * @return RTEMS directive status codes:
247 * - RTEMS_SUCCESSFUL - task created successfully
248 * - RTEMS_INVALID_ADDRESS - id is NULL
249 * - RTEMS_INVALID_NAME - invalid task name
250 * - RTEMS_INVALID_PRIORITY - invalid task priority
251 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
252 * - RTEMS_TOO_MANY - too many tasks created
253 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
254 * - RTEMS_TOO_MANY - too many global objects
255 *
256 */
257
258 rtems_status_code status;
259
260 //**********
261 // SPACEWIRE
262 // RECV
263 status = rtems_task_create(
264 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
265 RTEMS_DEFAULT_MODES,
266 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
267 );
268 if (status == RTEMS_SUCCESSFUL) // SEND
269 {
270 status = rtems_task_create(
271 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
272 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
273 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
274 );
275 }
276 if (status == RTEMS_SUCCESSFUL) // WTDG
277 {
278 status = rtems_task_create(
279 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
280 RTEMS_DEFAULT_MODES,
281 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
282 );
283 }
284 if (status == RTEMS_SUCCESSFUL) // ACTN
285 {
286 status = rtems_task_create(
287 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
288 RTEMS_DEFAULT_MODES,
289 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
290 );
291 }
292 if (status == RTEMS_SUCCESSFUL) // SPIQ
293 {
294 status = rtems_task_create(
295 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
296 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
297 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
298 );
299 }
300
301 //*****
302 // MISC
303 if (status == RTEMS_SUCCESSFUL) // STAT
304 {
305 status = rtems_task_create(
306 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
307 RTEMS_DEFAULT_MODES,
308 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
309 );
310 }
311 if (status == RTEMS_SUCCESSFUL) // DUMB
312 {
313 status = rtems_task_create(
314 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
315 RTEMS_DEFAULT_MODES,
316 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
317 );
318 }
319 if (status == RTEMS_SUCCESSFUL) // UPDT
320 {
321 status = rtems_task_create(
322 rtems_name_updt, TASK_PRIORITY_UPDT, RTEMS_MINIMUM_STACK_SIZE,
323 RTEMS_DEFAULT_MODES,
324 RTEMS_DEFAULT_ATTRIBUTES, &rtems_id_updt
325 );
326 }
327
328 return status;
329 }
330
331 int start_recv_send_tasks( void )
332 {
333 rtems_status_code status;
334
335 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
336 if (status!=RTEMS_SUCCESSFUL) {
337 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
338 }
339
340 if (status == RTEMS_SUCCESSFUL) // SEND
341 {
342 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
343 if (status!=RTEMS_SUCCESSFUL) {
344 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
345 }
346 }
347
348 return status;
349 }
350
351 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
352 {
353 /** This function starts all RTEMS tasks used in the software.
354 *
355 * @return RTEMS directive status codes:
356 * - RTEMS_SUCCESSFUL - ask started successfully
357 * - RTEMS_INVALID_ADDRESS - invalid task entry point
358 * - RTEMS_INVALID_ID - invalid task id
359 * - RTEMS_INCORRECT_STATE - task not in the dormant state
360 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
361 *
362 */
363 // starts all the tasks fot eh flight software
364
365 rtems_status_code status;
366
367 //**********
368 // SPACEWIRE
369 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
370 if (status!=RTEMS_SUCCESSFUL) {
371 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
372 }
373
374 if (status == RTEMS_SUCCESSFUL) // WTDG
375 {
376 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
377 if (status!=RTEMS_SUCCESSFUL) {
378 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
379 }
380 }
381
382 if (status == RTEMS_SUCCESSFUL) // ACTN
383 {
384 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
385 if (status!=RTEMS_SUCCESSFUL) {
386 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
387 }
388 }
389
390 //*****
391 // MISC
392 if (status == RTEMS_SUCCESSFUL) // DUMB
393 {
394 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
395 if (status!=RTEMS_SUCCESSFUL) {
396 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
397 }
398 }
399
400 if (status == RTEMS_SUCCESSFUL) // STAT
401 {
402 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
403 if (status!=RTEMS_SUCCESSFUL) {
404 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
405 }
406 }
407
408 if (status == RTEMS_SUCCESSFUL) // UPDT
409 {
410 status = rtems_task_start( rtems_id_updt, updt_task, 1 );
411 if (status!=RTEMS_SUCCESSFUL) {
412 BOOT_PRINTF("in INIT *** Error starting TASK_UPDT\n")
413 }
414 }
415
416 return status;
417 }
418
419 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
420 {
421 rtems_status_code status_recv;
422 rtems_status_code status_send;
423 rtems_status_code ret;
424 rtems_id queue_id;
425
426 // create the queue for handling valid TCs
427 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
428 ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
429 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
430 if ( status_recv != RTEMS_SUCCESSFUL ) {
431 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
432 }
433
434 // create the queue for handling TM packet sending
435 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
436 ACTION_MSG_PKTS_COUNT, ACTION_MSG_PKTS_MAX_SIZE,
437 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
438 if ( status_send != RTEMS_SUCCESSFUL ) {
439 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
440 }
441
442 if ( status_recv != RTEMS_SUCCESSFUL )
443 {
444 ret = status_recv;
445 }
446 else
447 {
448 ret = status_send;
449 }
450
451 return ret;
452 }
453
454 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
455 {
456 rtems_status_code status;
457 rtems_name queue_name;
458
459 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
460
461 status = rtems_message_queue_ident( queue_name, 0, queue_id );
462
463 return status;
464 }
465
466 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
467 {
468 rtems_status_code status;
469 rtems_name queue_name;
470
471 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
472
473 status = rtems_message_queue_ident( queue_name, 0, queue_id );
474
475 return status;
476 }
@@ -0,0 +1,110
1 /** Functions and tasks related to TeleCommand handling.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
8 * TC parsing\n
9 * ...
10 *
11 */
12
13 #include "timegen_misc.h"
14 #include <stdio.h>
15
16 void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
17 {
18 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
19
20 grgpio_regs->io_port_direction_register =
21 grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled
22
23 if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 )
24 {
25 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7;
26 }
27 else
28 {
29 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08;
30 }
31
32 rtems_event_send( rtems_id_updt, RTEMS_EVENT_0 );
33 }
34
35 void initCoarseTime()
36 {
37 coarseTime = 0x00;
38 }
39
40 rtems_task updt_task( rtems_task_argument unused )
41 {
42 rtems_event_set event_out;
43 rtems_id send_queue_id;
44
45 get_message_queue_id_send( &send_queue_id );
46
47 BOOT_PRINTF("in UPDT *** waiting for SpaceWire ticks\n")
48
49 while(1)
50 {
51 // wait for an RTEMS_EVENT
52 rtems_event_receive( RTEMS_EVENT_0,
53 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
54 // increment the coarse time
55 coarseTime = coarseTime + 1;
56 PRINTF2("next valid coarseTime = 0x%x *** %d s\n", coarseTime, coarseTime)
57 rtems_task_wake_after(70); // 10 ms * 70 = 700 ms
58 send_tc_lfr_update_time( send_queue_id );
59 }
60 }
61
62 int send_tc_lfr_update_time(rtems_id queue_id )
63 {
64
65 rtems_status_code status;
66 unsigned char messageSize;
67
68 Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t packet;
69 unsigned char crcAsTwoBytes[2];
70
71 // OVERHEAD
72 packet.targetLogicalAddress = DESTINATION_ID_LFR;
73 packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
74 packet.reserved = DEFAULT_RESERVED;
75 packet.userApplication = CCSDS_USER_APP;
76
77 // TIME PACKET
78 packet.update_time.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8);
79 packet.update_time.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID );
80 packet.update_time.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8);
81 packet.update_time.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL );
82 packet.update_time.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8);
83 packet.update_time.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME );
84
85 packet.update_time.ccsdsSecHeaderFlag_pusVersion_ack = 0x19;
86 packet.update_time.serviceType = TC_TYPE_LFR_UPDATE_TIME;
87 packet.update_time.serviceSubType = TC_SUBTYPE_UPDATE_TIME;
88 packet.update_time.sourceID = SID_TC_RPW_INTERNAL;
89 packet.update_time.cp_rpw_time[0] = (unsigned char) (coarseTime >> 24);
90 packet.update_time.cp_rpw_time[1] = (unsigned char) (coarseTime >> 16);
91 packet.update_time.cp_rpw_time[2] = (unsigned char) (coarseTime >> 8);
92 packet.update_time.cp_rpw_time[3] = (unsigned char) (coarseTime);
93 packet.update_time.cp_rpw_time[4] = 0; // fine time MSB
94 packet.update_time.cp_rpw_time[5] = 0; // fine time LSB
95
96 GetCRCAsTwoBytes((unsigned char*) &packet.update_time, crcAsTwoBytes,
97 PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2);
98 packet.update_time.crc[0] = crcAsTwoBytes[0];
99 packet.update_time.crc[1] = crcAsTwoBytes[1];
100
101 messageSize = PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
102
103 // SEND DATA
104 status = rtems_message_queue_send( queue_id, &packet, messageSize);
105 if (status != RTEMS_SUCCESSFUL) {
106 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
107 }
108
109 return status;
110 }
This diff has been collapsed as it changes many lines, (601 lines changed) Show them Hide them
@@ -0,0 +1,601
1 /** Functions related to the SpaceWire interface.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
12 */
13
14 #include "timegen_spacewire.h"
15
16 rtems_name semq_name;
17 rtems_id semq_id;
18
19 //***********
20 // RTEMS TASK
21 rtems_task spiq_task(rtems_task_argument unused)
22 {
23 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
24 *
25 * @param unused is the starting argument of the RTEMS task
26 *
27 */
28
29 rtems_event_set event_out;
30 rtems_status_code status;
31 int linkStatus;
32
33 BOOT_PRINTF("in SPIQ *** \n")
34
35 while(true){
36 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
37 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
38
39 // [0] SUSPEND RECV AND SEND TASKS
40 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
41 if ( status != RTEMS_SUCCESSFUL ) {
42 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
43 }
44 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
45 if ( status != RTEMS_SUCCESSFUL ) {
46 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
47 }
48
49 // [1] CHECK THE LINK
50 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
51 if ( linkStatus != 5) {
52 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
53 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
54 }
55
56 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
57 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
58 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
59 {
60 spacewire_compute_stats_offsets();
61 status = spacewire_reset_link( );
62 }
63 else // [2.b] in run state, start the link
64 {
65 status = spacewire_stop_start_link( fdSPW ); // start the link
66 if ( status != RTEMS_SUCCESSFUL)
67 {
68 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
69 }
70 }
71
72 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
73 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
74 {
75 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
76 if ( status != RTEMS_SUCCESSFUL ) {
77 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
78 }
79 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
80 if ( status != RTEMS_SUCCESSFUL ) {
81 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
82 }
83 }
84 else // [3.b] the link is not in run state, go in STANDBY mode
85 {
86 status = stop_current_mode();
87 if ( status != RTEMS_SUCCESSFUL ) {
88 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
89 }
90 status = enter_mode( LFR_MODE_STANDBY );
91 if ( status != RTEMS_SUCCESSFUL ) {
92 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
93 }
94 // wake the WTDG task up to wait for the link recovery
95 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
96 status = rtems_task_suspend( RTEMS_SELF );
97 }
98 }
99 }
100
101 rtems_task recv_task( rtems_task_argument unused )
102 {
103 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
104 *
105 * @param unused is the starting argument of the RTEMS task
106 *
107 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
108 * 1. It reads the incoming data.
109 * 2. Launches the acceptance procedure.
110 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
111 *
112 */
113
114 int len;
115 ccsdsTelecommandPacket_t currentTC;
116 unsigned char computed_CRC[ 2 ];
117 unsigned char currentTC_LEN_RCV[ 2 ];
118 unsigned char destinationID;
119 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
120 unsigned int parserCode;
121 unsigned char time[6];
122 rtems_status_code status;
123 rtems_id queue_recv_id;
124 rtems_id queue_send_id;
125
126 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
127
128 status = get_message_queue_id_recv( &queue_recv_id );
129 if (status != RTEMS_SUCCESSFUL)
130 {
131 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
132 }
133
134 status = get_message_queue_id_send( &queue_send_id );
135 if (status != RTEMS_SUCCESSFUL)
136 {
137 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
138 }
139
140 BOOT_PRINTF("in RECV *** \n")
141
142 while(1)
143 {
144 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
145 if (len == -1){ // error during the read call
146 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
147 }
148 else {
149 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
150 PRINTF("in RECV *** packet lenght too short\n")
151 }
152 else {
153 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
154 currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8);
155 currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt );
156 // CHECK THE TC
157 parserCode = tc_parser( &currentTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ;
158 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
159 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
160 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
161 || (parserCode == WRONG_SRC_ID) )
162 { // send TM_LFR_TC_EXE_CORRUPTED
163 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
164 &&
165 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
166 )
167 {
168 if ( parserCode == WRONG_SRC_ID )
169 {
170 destinationID = SID_TC_GROUND;
171 }
172 else
173 {
174 destinationID = currentTC.sourceID;
175 }
176 getTime( time );
177 close_action( &currentTC, LFR_DEFAULT, queue_send_id );
178 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
179 computed_CRC, currentTC_LEN_RCV,
180 destinationID );
181 }
182 }
183 else
184 { // send valid TC to the action launcher
185 status = rtems_message_queue_send( queue_recv_id, &currentTC,
186 currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3);
187 }
188 }
189 }
190 }
191 }
192
193 rtems_task send_task( rtems_task_argument argument)
194 {
195 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
196 *
197 * @param unused is the starting argument of the RTEMS task
198 *
199 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
200 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
201 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
202 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
203 * data it contains.
204 *
205 */
206
207 rtems_status_code status; // RTEMS status code
208 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
209 size_t size; // size of the incoming TC packet
210 u_int32_t count;
211 rtems_id queue_id;
212
213 status = get_message_queue_id_send( &queue_id );
214 if (status != RTEMS_SUCCESSFUL)
215 {
216 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
217 }
218
219 BOOT_PRINTF("in SEND *** \n")
220
221 while(1)
222 {
223 status = rtems_message_queue_receive( queue_id, incomingData, &size,
224 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
225
226 if (status!=RTEMS_SUCCESSFUL)
227 {
228 PRINTF1("in SEND *** (1) ERR = %d\n", status)
229 }
230 else
231 {
232 status = write( fdSPW, incomingData, size );
233 if (status == -1){
234 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
235 }
236 }
237
238 status = rtems_message_queue_get_number_pending( queue_id, &count );
239 if (status != RTEMS_SUCCESSFUL)
240 {
241 PRINTF1("in SEND *** (3) ERR = %d\n", status)
242 }
243 else
244 {
245 if (count > maxCount)
246 {
247 maxCount = count;
248 }
249 }
250 }
251 }
252
253 rtems_task wtdg_task( rtems_task_argument argument )
254 {
255 rtems_event_set event_out;
256 rtems_status_code status;
257 int linkStatus;
258
259 BOOT_PRINTF("in WTDG ***\n")
260
261 while(1)
262 {
263 // wait for an RTEMS_EVENT
264 rtems_event_receive( RTEMS_EVENT_0,
265 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
266 PRINTF("in WTDG *** wait for the link\n")
267 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
268 while( linkStatus != 5) // wait for the link
269 {
270 rtems_task_wake_after( 10 );
271 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
272 }
273
274 status = spacewire_stop_start_link( fdSPW );
275
276 if (status != RTEMS_SUCCESSFUL)
277 {
278 PRINTF1("in WTDG *** ERR link not started %d\n", status)
279 }
280 else
281 {
282 PRINTF("in WTDG *** OK link started\n")
283 }
284
285 // restart the SPIQ task
286 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
287 if ( status != RTEMS_SUCCESSFUL ) {
288 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
289 }
290
291 // restart RECV and SEND
292 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
293 if ( status != RTEMS_SUCCESSFUL ) {
294 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
295 }
296 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
297 if ( status != RTEMS_SUCCESSFUL ) {
298 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
299 }
300 }
301 }
302
303 //****************
304 // OTHER FUNCTIONS
305 int spacewire_open_link( void )
306 {
307 /** This function opens the SpaceWire link.
308 *
309 * @return a valid file descriptor in case of success, -1 in case of a failure
310 *
311 */
312 rtems_status_code status;
313
314 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
315 if ( fdSPW < 0 ) {
316 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
317 }
318 else
319 {
320 status = RTEMS_SUCCESSFUL;
321 }
322
323 return status;
324 }
325
326 int spacewire_start_link( int fd )
327 {
328 rtems_status_code status;
329
330 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
331 // -1 default hardcoded driver timeout
332
333 return status;
334 }
335
336 int spacewire_stop_start_link( int fd )
337 {
338 rtems_status_code status;
339
340 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
341 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
342 // -1 default hardcoded driver timeout
343
344 return status;
345 }
346
347 int spacewire_configure_link( int fd )
348 {
349 /** This function configures the SpaceWire link.
350 *
351 * @return GR-RTEMS-DRIVER directive status codes:
352 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
353 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
354 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
355 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
356 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
357 * - 5 EIO - Error when writing to grswp hardware registers.
358 * - 2 ENOENT - No such file or directory
359 */
360
361 rtems_status_code status;
362
363 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
364 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
365
366 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
367 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
368 //
369 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
370 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
371 //
372 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
373 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
374 //
375 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
376 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
377 //
378 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
379 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
380 //
381 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
382 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
383 //
384 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
385 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL\n")
386
387 return status;
388 }
389
390 int spacewire_reset_link( void )
391 {
392 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
393 *
394 * @return RTEMS directive status code:
395 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
396 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
397 *
398 */
399
400 rtems_status_code status_spw;
401 int i;
402
403 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
404 {
405 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
406
407 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
408
409 status_spw = spacewire_stop_start_link( fdSPW );
410 if ( status_spw != RTEMS_SUCCESSFUL )
411 {
412 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
413 }
414
415 if ( status_spw == RTEMS_SUCCESSFUL)
416 {
417 break;
418 }
419 }
420
421 return status_spw;
422 }
423
424 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
425 {
426 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
427 *
428 * @param val is the value, 0 or 1, used to set the value of the NP bit.
429 * @param regAddr is the address of the GRSPW control register.
430 *
431 * NP is the bit 20 of the GRSPW control register.
432 *
433 */
434
435 unsigned int *spwptr = (unsigned int*) regAddr;
436
437 if (val == 1) {
438 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
439 }
440 if (val== 0) {
441 *spwptr = *spwptr & 0xffdfffff;
442 }
443 }
444
445 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
446 {
447 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
448 *
449 * @param val is the value, 0 or 1, used to set the value of the RE bit.
450 * @param regAddr is the address of the GRSPW control register.
451 *
452 * RE is the bit 16 of the GRSPW control register.
453 *
454 */
455
456 unsigned int *spwptr = (unsigned int*) regAddr;
457
458 if (val == 1)
459 {
460 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
461 }
462 if (val== 0)
463 {
464 *spwptr = *spwptr & 0xfffdffff;
465 }
466 }
467
468 void spacewire_compute_stats_offsets( void )
469 {
470 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
471 *
472 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
473 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
474 * during the open systel call).
475 *
476 */
477
478 spw_stats spacewire_stats_grspw;
479 rtems_status_code status;
480
481 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
482
483 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
484 + spacewire_stats.packets_received;
485 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
486 + spacewire_stats.packets_sent;
487 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
488 + spacewire_stats.parity_err;
489 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
490 + spacewire_stats.disconnect_err;
491 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
492 + spacewire_stats.escape_err;
493 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
494 + spacewire_stats.credit_err;
495 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
496 + spacewire_stats.write_sync_err;
497 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
498 + spacewire_stats.rx_rmap_header_crc_err;
499 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
500 + spacewire_stats.rx_rmap_data_crc_err;
501 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
502 + spacewire_stats.early_ep;
503 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
504 + spacewire_stats.invalid_address;
505 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
506 + spacewire_stats.rx_eep_err;
507 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
508 + spacewire_stats.rx_truncated;
509 }
510
511 void spacewire_update_statistics( void )
512 {
513 rtems_status_code status;
514 spw_stats spacewire_stats_grspw;
515
516 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
517
518 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
519 + spacewire_stats_grspw.packets_received;
520 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
521 + spacewire_stats_grspw.packets_sent;
522 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
523 + spacewire_stats_grspw.parity_err;
524 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
525 + spacewire_stats_grspw.disconnect_err;
526 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
527 + spacewire_stats_grspw.escape_err;
528 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
529 + spacewire_stats_grspw.credit_err;
530 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
531 + spacewire_stats_grspw.write_sync_err;
532 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
533 + spacewire_stats_grspw.rx_rmap_header_crc_err;
534 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
535 + spacewire_stats_grspw.rx_rmap_data_crc_err;
536 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
537 + spacewire_stats_grspw.early_ep;
538 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
539 + spacewire_stats_grspw.invalid_address;
540 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
541 + spacewire_stats_grspw.rx_eep_err;
542 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
543 + spacewire_stats_grspw.rx_truncated;
544 //spacewire_stats.tx_link_err;
545
546 //****************************
547 // DPU_SPACEWIRE_IF_STATISTICS
548 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
549 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
550 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
551 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
552 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
553 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
554
555 //******************************************
556 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
557 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
558 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
559 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
560 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
561 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
562
563 //*********************************************
564 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
565 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
566 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
567 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
568 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
569 }
570
571 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
572 {
573 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 );
574 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
575
576 grgpio_regs->io_port_direction_register =
577 grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled
578
579 if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 )
580 {
581 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7;
582 }
583 else
584 {
585 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08;
586 }
587
588 }
589
590 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
591 {
592 int linkStatus;
593 rtems_status_code status;
594
595 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
596
597 if ( linkStatus == 5) {
598 PRINTF("in spacewire_reset_link *** link is running\n")
599 status = RTEMS_SUCCESSFUL;
600 }
601 }
This diff has been collapsed as it changes many lines, (793 lines changed) Show them Hide them
@@ -0,0 +1,793
1 /** Functions and tasks related to TeleCommand handling.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
8 * TC parsing\n
9 * ...
10 *
11 */
12
13 #include "timegen_tc_handler.h"
14
15 //***********
16 // RTEMS TASK
17
18 rtems_task actn_task( rtems_task_argument unused )
19 {
20 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 *
22 * @param unused is the starting argument of the RTEMS task
23 *
24 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * on the incoming TeleCommand.
26 *
27 */
28
29 int result;
30 rtems_status_code status; // RTEMS status code
31 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 size_t size; // size of the incoming TC packet
33 unsigned char subtype; // subtype of the current TC packet
34 unsigned char time[6];
35 rtems_id queue_rcv_id;
36 rtems_id queue_snd_id;
37
38 status = get_message_queue_id_recv( &queue_rcv_id );
39 if (status != RTEMS_SUCCESSFUL)
40 {
41 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 }
43
44 status = get_message_queue_id_send( &queue_snd_id );
45 if (status != RTEMS_SUCCESSFUL)
46 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 }
49
50 result = LFR_SUCCESSFUL;
51 subtype = 0; // subtype of the current TC packet
52
53 BOOT_PRINTF("in ACTN *** \n")
54
55 while(1)
56 {
57 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 getTime( time ); // set time to the current time
60 if (status!=RTEMS_SUCCESSFUL)
61 {
62 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 }
64 else
65 {
66 subtype = TC.serviceSubType;
67 switch(subtype)
68 {
69 case TC_SUBTYPE_RESET:
70 // result = action_reset( &TC, queue_snd_id, time );
71 close_action( &TC, result, queue_snd_id );
72 break;
73 //
74 case TC_SUBTYPE_LOAD_COMM:
75 // result = action_load_common_par( &TC );
76 close_action( &TC, result, queue_snd_id );
77 break;
78 //
79 case TC_SUBTYPE_LOAD_NORM:
80 // result = action_load_normal_par( &TC, queue_snd_id, time );
81 close_action( &TC, result, queue_snd_id );
82 break;
83 //
84 case TC_SUBTYPE_LOAD_BURST:
85 // result = action_load_burst_par( &TC, queue_snd_id, time );
86 close_action( &TC, result, queue_snd_id );
87 break;
88 //
89 case TC_SUBTYPE_LOAD_SBM1:
90 // result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 close_action( &TC, result, queue_snd_id );
92 break;
93 //
94 case TC_SUBTYPE_LOAD_SBM2:
95 // result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 close_action( &TC, result, queue_snd_id );
97 break;
98 //
99 case TC_SUBTYPE_DUMP:
100 // result = action_dump_par( queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
102 break;
103 //
104 case TC_SUBTYPE_ENTER:
105 result = action_enter_mode( &TC, queue_snd_id, time );
106 close_action( &TC, result, queue_snd_id );
107 break;
108 //
109 case TC_SUBTYPE_UPDT_INFO:
110 // result = action_update_info( &TC, queue_snd_id );
111 close_action( &TC, result, queue_snd_id );
112 break;
113 //
114 case TC_SUBTYPE_EN_CAL:
115 // result = action_enable_calibration( &TC, queue_snd_id, time );
116 close_action( &TC, result, queue_snd_id );
117 break;
118 //
119 case TC_SUBTYPE_DIS_CAL:
120 // result = action_disable_calibration( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
122 break;
123 //
124 case TC_SUBTYPE_UPDT_TIME:
125 result = action_update_time( &TC );
126 close_action( &TC, result, queue_snd_id );
127 break;
128 //
129 default:
130 break;
131 }
132 }
133 }
134 }
135
136 //***********
137 // TC ACTIONS
138
139 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 {
141 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 *
143 * @param TC points to the TeleCommand packet that is being processed
144 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 *
146 */
147
148 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
149 return LFR_DEFAULT;
150 }
151
152 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
153 {
154 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
155 *
156 * @param TC points to the TeleCommand packet that is being processed
157 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
158 *
159 */
160
161 rtems_status_code status;
162 unsigned char requestedMode;
163
164 requestedMode = TC->dataAndCRC[1];
165
166 if ( (requestedMode != LFR_MODE_STANDBY)
167 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
168 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
169 {
170 status = RTEMS_UNSATISFIED;
171 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_LFR_MODE, requestedMode );
172 }
173 else
174 {
175 printf("in action_enter_mode *** enter mode %d\n", requestedMode);
176
177 status = transition_validation(requestedMode);
178
179 if ( status == LFR_SUCCESSFUL ) {
180 if ( lfrCurrentMode != LFR_MODE_STANDBY)
181 {
182 status = stop_current_mode();
183 }
184 if (status != RTEMS_SUCCESSFUL)
185 {
186 PRINTF("ERR *** in action_enter *** stop_current_mode\n")
187 }
188 status = enter_mode( requestedMode );
189 }
190 else
191 {
192 PRINTF("ERR *** in action_enter *** transition rejected\n")
193 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
194 }
195 }
196
197 return status;
198 }
199
200 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
201 {
202 // /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
203 // *
204 // * @param TC points to the TeleCommand packet that is being processed
205 // * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
206 // *
207 // * @return LFR directive status code:
208 // * - LFR_DEFAULT
209 // * - LFR_SUCCESSFUL
210 // *
211 // */
212
213 // unsigned int val;
214 int result;
215
216 result = LFR_DEFAULT;
217 // unsigned int status;
218 // unsigned char mode;
219
220 // // check LFR MODE
221 // mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET5 ] & 0x1e) >> 1;
222 // status = check_update_info_hk_lfr_mode( mode );
223 // if (status != LFR_DEFAULT) // check TDS mode
224 // {
225 // mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0xf0) >> 4;
226 // status = check_update_info_hk_tds_mode( mode );
227 // }
228 // if (status != LFR_DEFAULT) // check THR mode
229 // {
230 // mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0x0f);
231 // status = check_update_info_hk_thr_mode( mode );
232 // }
233 // if (status != LFR_DEFAULT) // if the parameter check is successful
234 // {
235 // val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
236 // + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
237 // val++;
238 // housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
239 // housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
240 // }
241
242 // result = status;
243
244 return result;
245 }
246
247 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
248 {
249 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
250 *
251 * @param TC points to the TeleCommand packet that is being processed
252 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
253 *
254 */
255
256 int result;
257 unsigned char lfrMode;
258
259 result = LFR_DEFAULT;
260 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
261
262 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
263 result = LFR_DEFAULT;
264
265 return result;
266 }
267
268 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
269 {
270 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
271 *
272 * @param TC points to the TeleCommand packet that is being processed
273 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
274 *
275 */
276
277 int result;
278 unsigned char lfrMode;
279
280 result = LFR_DEFAULT;
281 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
282
283 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
284 result = LFR_DEFAULT;
285
286 return result;
287 }
288
289 int action_update_time(ccsdsTelecommandPacket_t *TC)
290 {
291 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
292 *
293 * @param TC points to the TeleCommand packet that is being processed
294 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
295 *
296 * @return LFR_SUCCESSFUL
297 *
298 */
299
300 unsigned int val;
301
302 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
303 + (TC->dataAndCRC[1] << 16)
304 + (TC->dataAndCRC[2] << 8)
305 + TC->dataAndCRC[3];
306 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
307 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
308 val++;
309 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
310 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
311 // time_management_regs->ctrl = time_management_regs->ctrl | 1; // force tick
312
313 return LFR_SUCCESSFUL;
314 }
315
316 //*******************
317 // ENTERING THE MODES
318
319 int transition_validation(unsigned char requestedMode)
320 {
321 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
322 *
323 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
324 *
325 * @return LFR directive status codes:
326 * - LFR_SUCCESSFUL - the transition is authorized
327 * - LFR_DEFAULT - the transition is not authorized
328 *
329 */
330
331 int status;
332
333 switch (requestedMode)
334 {
335 case LFR_MODE_STANDBY:
336 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
337 status = LFR_DEFAULT;
338 }
339 else
340 {
341 status = LFR_SUCCESSFUL;
342 }
343 break;
344 case LFR_MODE_NORMAL:
345 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
346 status = LFR_DEFAULT;
347 }
348 else {
349 status = LFR_SUCCESSFUL;
350 }
351 break;
352 case LFR_MODE_BURST:
353 if ( lfrCurrentMode == LFR_MODE_BURST ) {
354 status = LFR_DEFAULT;
355 }
356 else {
357 status = LFR_SUCCESSFUL;
358 }
359 break;
360 case LFR_MODE_SBM1:
361 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
362 status = LFR_DEFAULT;
363 }
364 else {
365 status = LFR_SUCCESSFUL;
366 }
367 break;
368 case LFR_MODE_SBM2:
369 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
370 status = LFR_DEFAULT;
371 }
372 else {
373 status = LFR_SUCCESSFUL;
374 }
375 break;
376 default:
377 status = LFR_DEFAULT;
378 break;
379 }
380
381 return status;
382 }
383
384 int stop_current_mode(void)
385 {
386 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
387 *
388 * @return RTEMS directive status codes:
389 * - RTEMS_SUCCESSFUL - task restarted successfully
390 * - RTEMS_INVALID_ID - task id invalid
391 * - RTEMS_ALREADY_SUSPENDED - task already suspended
392 *
393 */
394
395 rtems_status_code status;
396
397 status = RTEMS_SUCCESSFUL;
398
399 // (1) mask interruptions
400 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
401 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
402
403 // (2) clear interruptions
404 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
405 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
406
407 // (3) reset registers
408 // waveform picker
409 // reset_wfp_burst_enable(); // reset burst and enable bits
410 // reset_wfp_status(); // reset all the status bits
411 // spectral matrices
412 set_irq_on_new_ready_matrix( 0 ); // stop the spectral matrices
413 set_run_matrix_spectral( 0 ); // run_matrix_spectral is set to 0
414 // reset_extractSWF(); // reset the extractSWF flag to false
415
416 // <Spectral Matrices simulator>
417 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
418 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
419 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
420 // </Spectral Matrices simulator>
421
422 // suspend several tasks
423 if (lfrCurrentMode != LFR_MODE_STANDBY) {
424 status = suspend_science_tasks();
425 }
426
427 if (status != RTEMS_SUCCESSFUL)
428 {
429 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
430 }
431
432 return status;
433 }
434
435 int enter_mode(unsigned char mode )
436 {
437 /** This function is launched after a mode transition validation.
438 *
439 * @param mode is the mode in which LFR will be put.
440 *
441 * @return RTEMS directive status codes:
442 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
443 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
444 *
445 */
446
447 rtems_status_code status;
448
449 status = RTEMS_UNSATISFIED;
450
451 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d);
452 updateLFRCurrentMode();
453
454 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
455 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
456 {
457 #ifdef PRINT_TASK_STATISTICS
458 rtems_cpu_usage_reset();
459 maxCount = 0;
460 #endif
461 status = restart_science_tasks();
462 // launch_waveform_picker( mode );
463 // launch_spectral_matrix( mode );
464 }
465 else if ( mode == LFR_MODE_STANDBY )
466 {
467 #ifdef PRINT_TASK_STATISTICS
468 rtems_cpu_usage_report();
469 #endif
470
471 #ifdef PRINT_STACK_REPORT
472 rtems_stack_checker_report_usage();
473 #endif
474 status = stop_current_mode();
475 PRINTF1("maxCount = %d\n", maxCount)
476 }
477 else
478 {
479 status = RTEMS_UNSATISFIED;
480 }
481
482 if (status != RTEMS_SUCCESSFUL)
483 {
484 PRINTF1("in enter_mode *** ERR = %d\n", status)
485 status = RTEMS_UNSATISFIED;
486 }
487
488 return status;
489 }
490
491 int restart_science_tasks()
492 {
493 /** This function is used to restart all science tasks.
494 *
495 * @return RTEMS directive status codes:
496 * - RTEMS_SUCCESSFUL - task restarted successfully
497 * - RTEMS_INVALID_ID - task id invalid
498 * - RTEMS_INCORRECT_STATE - task never started
499 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
500 *
501 * Science tasks are AVF0, BPF0, WFRM, CWF3, CW2, CWF1
502 *
503 */
504
505 rtems_status_code status[6];
506 rtems_status_code ret;
507
508 ret = RTEMS_SUCCESSFUL;
509
510 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], 1 );
511 if (status[0] != RTEMS_SUCCESSFUL)
512 {
513 PRINTF1("in restart_science_task *** 0 ERR %d\n", status[0])
514 }
515
516 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
517 if (status[2] != RTEMS_SUCCESSFUL)
518 {
519 PRINTF1("in restart_science_task *** 2 ERR %d\n", status[2])
520 }
521
522 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
523 if (status[3] != RTEMS_SUCCESSFUL)
524 {
525 PRINTF1("in restart_science_task *** 3 ERR %d\n", status[3])
526 }
527
528 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
529 if (status[4] != RTEMS_SUCCESSFUL)
530 {
531 PRINTF1("in restart_science_task *** 4 ERR %d\n", status[4])
532 }
533
534 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
535 if (status[5] != RTEMS_SUCCESSFUL)
536 {
537 PRINTF1("in restart_science_task *** 5 ERR %d\n", status[5])
538 }
539
540 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[2] != RTEMS_SUCCESSFUL) ||
541 (status[3] != RTEMS_SUCCESSFUL) || (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) )
542 {
543 ret = RTEMS_UNSATISFIED;
544 }
545
546 return ret;
547 }
548
549 int suspend_science_tasks()
550 {
551 /** This function suspends the science tasks.
552 *
553 * @return RTEMS directive status codes:
554 * - RTEMS_SUCCESSFUL - task restarted successfully
555 * - RTEMS_INVALID_ID - task id invalid
556 * - RTEMS_ALREADY_SUSPENDED - task already suspended
557 *
558 */
559
560 rtems_status_code status;
561
562 status = rtems_task_suspend( Task_id[TASKID_AVF0] );
563 if (status != RTEMS_SUCCESSFUL)
564 {
565 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
566 }
567
568 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
569 {
570 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
571 if (status != RTEMS_SUCCESSFUL)
572 {
573 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
574 }
575 }
576
577 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
578 {
579 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
580 if (status != RTEMS_SUCCESSFUL)
581 {
582 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
583 }
584 }
585
586 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
587 {
588 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
589 if (status != RTEMS_SUCCESSFUL)
590 {
591 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
592 }
593 }
594
595 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
596 {
597 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
598 if (status != RTEMS_SUCCESSFUL)
599 {
600 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
601 }
602 }
603
604 return status;
605 }
606
607 void launch_waveform_picker( unsigned char mode )
608 {
609 // int startDate;
610
611 // reset_current_ring_nodes();
612 // reset_waveform_picker_regs();
613 // set_wfp_burst_enable_register( mode );
614
615 // LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
616 // LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
617
618 // startDate = time_management_regs->coarse_time + 2;
619 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x80; // [1000 0000]
620 // waveform_picker_regs->start_date = startDate;
621 }
622
623 void launch_spectral_matrix( unsigned char mode )
624 {
625 // reset_nb_sm_f0();
626 // reset_current_sm_ring_nodes();
627 // reset_spectral_matrix_regs();
628
629 //#ifdef VHDL_DEV
630 // set_irq_on_new_ready_matrix( 1 );
631 // LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
632 // LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
633 // set_run_matrix_spectral( 1 );
634 //#else
635 // // Spectral Matrices simulator
636 // timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
637 // LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
638 // LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
639 //#endif
640 }
641
642 void set_irq_on_new_ready_matrix( unsigned char value )
643 {
644 if (value == 1)
645 {
646 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
647 }
648 else
649 {
650 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
651 }
652 }
653
654 void set_run_matrix_spectral( unsigned char value )
655 {
656 if (value == 1)
657 {
658 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // 0100 set run_matrix spectral to 1
659 }
660 else
661 {
662 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // 1011 set run_matrix spectral to 0
663 }
664 }
665
666 void launch_spectral_matrix_simu( unsigned char mode )
667 {
668 // reset_nb_sm_f0();
669 // reset_current_sm_ring_nodes();
670 // reset_spectral_matrix_regs();
671
672 // // Spectral Matrices simulator
673 // timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
674 // LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
675 // LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
676 // set_local_nb_interrupt_f0_MAX();
677 }
678
679 //****************
680 // CLOSING ACTIONS
681 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC)
682 {
683 /** This function is used to update the HK packets statistics after a successful TC execution.
684 *
685 * @param TC points to the TC being processed
686 * @param time is the time used to date the TC execution
687 *
688 */
689
690 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
691 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
692 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
693 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
694 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
695 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
696 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
697 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
698 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
699 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = (unsigned char) (time_management_regs->coarse_time);
700 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8);
701 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = (unsigned char) (time_management_regs->fine_time);
702 }
703
704 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC )
705 {
706 /** This function is used to update the HK packets statistics after a TC rejection.
707 *
708 * @param TC points to the TC being processed
709 * @param time is the time used to date the TC rejection
710 *
711 */
712
713 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
714 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
715 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
716 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
717 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
718 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
719 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
720 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
721 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
722 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = (unsigned char) (time_management_regs->coarse_time);
723 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8);
724 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = (unsigned char) (time_management_regs->fine_time);
725 }
726
727 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
728 {
729 /** This function is the last step of the TC execution workflow.
730 *
731 * @param TC points to the TC being processed
732 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
733 * @param queue_id is the id of the RTEMS message queue used to send TM packets
734 * @param time is the time used to date the TC execution
735 *
736 */
737
738 unsigned int val = 0;
739
740 if (result == LFR_SUCCESSFUL)
741 {
742 if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
743 &&
744 !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
745 )
746 {
747 send_tm_lfr_tc_exe_success( TC, queue_id );
748 }
749 update_last_TC_exe( TC );
750 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
751 val++;
752 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
753 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
754 }
755 else
756 {
757 update_last_TC_rej( TC );
758 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
759 val++;
760 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
761 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
762 }
763 }
764
765 //***************************
766 // Interrupt Service Routines
767 rtems_isr commutation_isr1( rtems_vector_number vector )
768 {
769 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
770 printf("In commutation_isr1 *** Error sending event to DUMB\n");
771 }
772 }
773
774 rtems_isr commutation_isr2( rtems_vector_number vector )
775 {
776 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
777 printf("In commutation_isr2 *** Error sending event to DUMB\n");
778 }
779 }
780
781 //****************
782 // OTHER FUNCTIONS
783 void updateLFRCurrentMode()
784 {
785 /** This function updates the value of the global variable lfrCurrentMode.
786 *
787 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
788 *
789 */
790 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
791 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
792 }
793
@@ -1,253 +1,253
1 1 #############################################################################
2 2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Tue Mar 11 15:58:37 2014
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Tue Mar 25 09:47:02 2014
4 4 # Project: fsw-qt.pro
5 5 # Template: app
6 6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
7 7 #############################################################################
8 8
9 9 ####### Compiler, tools and options
10 10
11 11 CC = sparc-rtems-gcc
12 12 CXX = sparc-rtems-g++
13 DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=3 -DPRINT_MESSAGES_ON_CONSOLE -DDEBUG_MESSAGES
13 DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=3 -DVHDL_DEV -DPRINT_MESSAGES_ON_CONSOLE
14 14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
15 15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
16 16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header -I../../LFR_basic-parameters
17 17 LINK = sparc-rtems-g++
18 18 LFLAGS =
19 19 LIBS = $(SUBLIBS)
20 20 AR = sparc-rtems-ar rcs
21 21 RANLIB =
22 22 QMAKE = /usr/bin/qmake-qt4
23 23 TAR = tar -cf
24 24 COMPRESS = gzip -9f
25 25 COPY = cp -f
26 26 SED = sed
27 27 COPY_FILE = $(COPY)
28 28 COPY_DIR = $(COPY) -r
29 29 STRIP = sparc-rtems-strip
30 30 INSTALL_FILE = install -m 644 -p
31 31 INSTALL_DIR = $(COPY_DIR)
32 32 INSTALL_PROGRAM = install -m 755 -p
33 33 DEL_FILE = rm -f
34 34 SYMLINK = ln -f -s
35 35 DEL_DIR = rmdir
36 36 MOVE = mv -f
37 37 CHK_DIR_EXISTS= test -d
38 38 MKDIR = mkdir -p
39 39
40 40 ####### Output directory
41 41
42 42 OBJECTS_DIR = obj/
43 43
44 44 ####### Files
45 45
46 46 SOURCES = ../src/wf_handler.c \
47 47 ../src/tc_handler.c \
48 48 ../src/fsw_processing.c \
49 49 ../src/fsw_misc.c \
50 50 ../src/fsw_init.c \
51 51 ../src/fsw_globals.c \
52 52 ../src/fsw_spacewire.c \
53 53 ../src/tc_load_dump_parameters.c \
54 54 ../src/tm_lfr_tc_exe.c \
55 55 ../src/tc_acceptance.c \
56 56 ../../LFR_basic-parameters/basic_parameters.c
57 57 OBJECTS = obj/wf_handler.o \
58 58 obj/tc_handler.o \
59 59 obj/fsw_processing.o \
60 60 obj/fsw_misc.o \
61 61 obj/fsw_init.o \
62 62 obj/fsw_globals.o \
63 63 obj/fsw_spacewire.o \
64 64 obj/tc_load_dump_parameters.o \
65 65 obj/tm_lfr_tc_exe.o \
66 66 obj/tc_acceptance.o \
67 67 obj/basic_parameters.o
68 68 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
69 69 /usr/lib64/qt4/mkspecs/common/linux.conf \
70 70 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
71 71 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
72 72 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
73 73 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
74 74 /usr/lib64/qt4/mkspecs/qconfig.pri \
75 75 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
76 76 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
77 77 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
78 78 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
79 79 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
80 80 sparc.pri \
81 81 /usr/lib64/qt4/mkspecs/features/release.prf \
82 82 /usr/lib64/qt4/mkspecs/features/default_post.prf \
83 83 /usr/lib64/qt4/mkspecs/features/shared.prf \
84 84 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
85 85 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
86 86 /usr/lib64/qt4/mkspecs/features/resources.prf \
87 87 /usr/lib64/qt4/mkspecs/features/uic.prf \
88 88 /usr/lib64/qt4/mkspecs/features/yacc.prf \
89 89 /usr/lib64/qt4/mkspecs/features/lex.prf \
90 90 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf \
91 91 fsw-qt.pro
92 92 QMAKE_TARGET = fsw
93 93 DESTDIR = bin/
94 94 TARGET = bin/fsw
95 95
96 96 first: all
97 97 ####### Implicit rules
98 98
99 99 .SUFFIXES: .o .c .cpp .cc .cxx .C
100 100
101 101 .cpp.o:
102 102 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
103 103
104 104 .cc.o:
105 105 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
106 106
107 107 .cxx.o:
108 108 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
109 109
110 110 .C.o:
111 111 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
112 112
113 113 .c.o:
114 114 $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
115 115
116 116 ####### Build rules
117 117
118 118 all: Makefile $(TARGET)
119 119
120 120 $(TARGET): $(OBJECTS)
121 121 @$(CHK_DIR_EXISTS) bin/ || $(MKDIR) bin/
122 122 $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
123 123
124 124 Makefile: fsw-qt.pro /usr/lib64/qt4/mkspecs/linux-g++/qmake.conf /usr/lib64/qt4/mkspecs/common/unix.conf \
125 125 /usr/lib64/qt4/mkspecs/common/linux.conf \
126 126 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
127 127 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
128 128 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
129 129 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
130 130 /usr/lib64/qt4/mkspecs/qconfig.pri \
131 131 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
132 132 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
133 133 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
134 134 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
135 135 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
136 136 sparc.pri \
137 137 /usr/lib64/qt4/mkspecs/features/release.prf \
138 138 /usr/lib64/qt4/mkspecs/features/default_post.prf \
139 139 /usr/lib64/qt4/mkspecs/features/shared.prf \
140 140 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
141 141 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
142 142 /usr/lib64/qt4/mkspecs/features/resources.prf \
143 143 /usr/lib64/qt4/mkspecs/features/uic.prf \
144 144 /usr/lib64/qt4/mkspecs/features/yacc.prf \
145 145 /usr/lib64/qt4/mkspecs/features/lex.prf \
146 146 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf
147 147 $(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
148 148 /usr/lib64/qt4/mkspecs/common/unix.conf:
149 149 /usr/lib64/qt4/mkspecs/common/linux.conf:
150 150 /usr/lib64/qt4/mkspecs/common/gcc-base.conf:
151 151 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf:
152 152 /usr/lib64/qt4/mkspecs/common/g++-base.conf:
153 153 /usr/lib64/qt4/mkspecs/common/g++-unix.conf:
154 154 /usr/lib64/qt4/mkspecs/qconfig.pri:
155 155 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri:
156 156 /usr/lib64/qt4/mkspecs/features/qt_functions.prf:
157 157 /usr/lib64/qt4/mkspecs/features/qt_config.prf:
158 158 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf:
159 159 /usr/lib64/qt4/mkspecs/features/default_pre.prf:
160 160 sparc.pri:
161 161 /usr/lib64/qt4/mkspecs/features/release.prf:
162 162 /usr/lib64/qt4/mkspecs/features/default_post.prf:
163 163 /usr/lib64/qt4/mkspecs/features/shared.prf:
164 164 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
165 165 /usr/lib64/qt4/mkspecs/features/warn_on.prf:
166 166 /usr/lib64/qt4/mkspecs/features/resources.prf:
167 167 /usr/lib64/qt4/mkspecs/features/uic.prf:
168 168 /usr/lib64/qt4/mkspecs/features/yacc.prf:
169 169 /usr/lib64/qt4/mkspecs/features/lex.prf:
170 170 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf:
171 171 qmake: FORCE
172 172 @$(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
173 173
174 174 dist:
175 175 @$(CHK_DIR_EXISTS) obj/fsw1.0.0 || $(MKDIR) obj/fsw1.0.0
176 176 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/fsw1.0.0/ && (cd `dirname obj/fsw1.0.0` && $(TAR) fsw1.0.0.tar fsw1.0.0 && $(COMPRESS) fsw1.0.0.tar) && $(MOVE) `dirname obj/fsw1.0.0`/fsw1.0.0.tar.gz . && $(DEL_FILE) -r obj/fsw1.0.0
177 177
178 178
179 179 clean:compiler_clean
180 180 -$(DEL_FILE) $(OBJECTS)
181 181 -$(DEL_FILE) *~ core *.core
182 182
183 183
184 184 ####### Sub-libraries
185 185
186 186 distclean: clean
187 187 -$(DEL_FILE) $(TARGET)
188 188 -$(DEL_FILE) Makefile
189 189
190 190
191 191 grmon:
192 192 cd bin && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
193 193
194 194 check: first
195 195
196 196 compiler_rcc_make_all:
197 197 compiler_rcc_clean:
198 198 compiler_uic_make_all:
199 199 compiler_uic_clean:
200 200 compiler_image_collection_make_all: qmake_image_collection.cpp
201 201 compiler_image_collection_clean:
202 202 -$(DEL_FILE) qmake_image_collection.cpp
203 203 compiler_yacc_decl_make_all:
204 204 compiler_yacc_decl_clean:
205 205 compiler_yacc_impl_make_all:
206 206 compiler_yacc_impl_clean:
207 207 compiler_lex_make_all:
208 208 compiler_lex_clean:
209 209 compiler_clean:
210 210
211 211 ####### Compile
212 212
213 213 obj/wf_handler.o: ../src/wf_handler.c
214 214 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/wf_handler.o ../src/wf_handler.c
215 215
216 216 obj/tc_handler.o: ../src/tc_handler.c
217 217 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_handler.o ../src/tc_handler.c
218 218
219 219 obj/fsw_processing.o: ../src/fsw_processing.c ../src/fsw_processing_globals.c
220 220 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_processing.o ../src/fsw_processing.c
221 221
222 222 obj/fsw_misc.o: ../src/fsw_misc.c
223 223 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_misc.o ../src/fsw_misc.c
224 224
225 225 obj/fsw_init.o: ../src/fsw_init.c ../src/fsw_config.c
226 226 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_init.o ../src/fsw_init.c
227 227
228 228 obj/fsw_globals.o: ../src/fsw_globals.c
229 229 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_globals.o ../src/fsw_globals.c
230 230
231 231 obj/fsw_spacewire.o: ../src/fsw_spacewire.c
232 232 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_spacewire.o ../src/fsw_spacewire.c
233 233
234 234 obj/tc_load_dump_parameters.o: ../src/tc_load_dump_parameters.c
235 235 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_load_dump_parameters.o ../src/tc_load_dump_parameters.c
236 236
237 237 obj/tm_lfr_tc_exe.o: ../src/tm_lfr_tc_exe.c
238 238 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tm_lfr_tc_exe.o ../src/tm_lfr_tc_exe.c
239 239
240 240 obj/tc_acceptance.o: ../src/tc_acceptance.c
241 241 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_acceptance.o ../src/tc_acceptance.c
242 242
243 243 obj/basic_parameters.o: ../../LFR_basic-parameters/basic_parameters.c ../../LFR_basic-parameters/basic_parameters.h
244 244 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/basic_parameters.o ../../LFR_basic-parameters/basic_parameters.c
245 245
246 246 ####### Install
247 247
248 248 install: FORCE
249 249
250 250 uninstall: FORCE
251 251
252 252 FORCE:
253 253
@@ -1,6 +1,9
1 1 #!/usr/bin/lppmon -e
2 2
3 RMAPPlugin0.setValueSpaceWireLinkNumber( 1 )
4 RMAPPlugin0.setValueTargetLogicalAddress( 254 )
5
3 6 dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw")
4 7 dsu3plugin0.loadFile()
5 8 dsu3plugin0.run()
6 9
@@ -1,81 +1,85
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev
4 CONFIG += console verbose debug_messages
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 CONFIG += console verbose vhdl_dev
5 5 CONFIG -= qt
6 6
7 7 include(./sparc.pri)
8 8
9 9 # flight software version
10 10 SWVERSION=-1-0
11 11 DEFINES += SW_VERSION_N1=1 # major
12 12 DEFINES += SW_VERSION_N2=0 # minor
13 13 DEFINES += SW_VERSION_N3=0 # patch
14 14 DEFINES += SW_VERSION_N4=3 # internal
15 15
16 contains( CONFIG, debug_tch ) {
17 DEFINES += DEBUG_TCH
18 }
19
16 20 contains( CONFIG, vhdl_dev ) {
17 21 DEFINES += VHDL_DEV
18 22 }
19 23
20 24 contains( CONFIG, verbose ) {
21 25 DEFINES += PRINT_MESSAGES_ON_CONSOLE
22 26 }
23 27
24 28 contains( CONFIG, debug_messages ) {
25 29 DEFINES += DEBUG_MESSAGES
26 30 }
27 31
28 32 contains( CONFIG, cpu_usage_report ) {
29 33 DEFINES += PRINT_TASK_STATISTICS
30 34 }
31 35
32 36 contains( CONFIG, stack_report ) {
33 37 DEFINES += PRINT_STACK_REPORT
34 38 }
35 39
36 40 contains( CONFIG, boot_messages ) {
37 41 DEFINES += BOOT_MESSAGES
38 42 }
39 43
40 44 #doxygen.target = doxygen
41 45 #doxygen.commands = doxygen ../doc/Doxyfile
42 46 #QMAKE_EXTRA_TARGETS += doxygen
43 47
44 48 TARGET = fsw
45 49
46 50 INCLUDEPATH += \
47 51 ../src \
48 52 ../header \
49 53 ../../LFR_basic-parameters
50 54
51 55 SOURCES += \
52 56 ../src/wf_handler.c \
53 57 ../src/tc_handler.c \
54 58 ../src/fsw_processing.c \
55 59 ../src/fsw_misc.c \
56 60 ../src/fsw_init.c \
57 61 ../src/fsw_globals.c \
58 62 ../src/fsw_spacewire.c \
59 63 ../src/tc_load_dump_parameters.c \
60 64 ../src/tm_lfr_tc_exe.c \
61 65 ../src/tc_acceptance.c \
62 66 ../../LFR_basic-parameters/basic_parameters.c
63 67
64 68
65 69 HEADERS += \
66 70 ../header/wf_handler.h \
67 71 ../header/tc_handler.h \
68 72 ../header/grlib_regs.h \
69 73 ../header/fsw_processing.h \
70 74 ../header/fsw_params.h \
71 75 ../header/fsw_misc.h \
72 76 ../header/fsw_init.h \
73 77 ../header/ccsds_types.h \
74 78 ../header/fsw_params_processing.h \
75 79 ../header/fsw_spacewire.h \
76 80 ../header/tc_load_dump_parameters.h \
77 81 ../header/tm_lfr_tc_exe.h \
78 82 ../header/tc_acceptance.h \
79 83 ../header/fsw_params_nb_bytes.h \
80 84 ../../LFR_basic-parameters/basic_parameters.h
81 85
@@ -1,339 +1,339
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by QtCreator 3.0.1, 2014-03-13T15:53:26. -->
3 <!-- Written by QtCreator 3.0.1, 2014-03-25T08:40:48. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
7 7 <value type="int">1</value>
8 8 </data>
9 9 <data>
10 10 <variable>ProjectExplorer.Project.EditorSettings</variable>
11 11 <valuemap type="QVariantMap">
12 12 <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
13 13 <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
14 14 <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
15 15 <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
16 16 <value type="QString" key="language">Cpp</value>
17 17 <valuemap type="QVariantMap" key="value">
18 18 <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
19 19 </valuemap>
20 20 </valuemap>
21 21 <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
22 22 <value type="QString" key="language">QmlJS</value>
23 23 <valuemap type="QVariantMap" key="value">
24 24 <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
25 25 </valuemap>
26 26 </valuemap>
27 27 <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
28 28 <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
29 29 <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
30 30 <value type="int" key="EditorConfiguration.IndentSize">4</value>
31 31 <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
32 32 <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
33 33 <value type="int" key="EditorConfiguration.PaddingMode">1</value>
34 34 <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
35 35 <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
36 36 <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
37 37 <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
38 38 <value type="int" key="EditorConfiguration.TabSize">8</value>
39 39 <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
40 40 <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
41 41 <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
42 42 <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
43 43 <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
44 44 <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
45 45 </valuemap>
46 46 </data>
47 47 <data>
48 48 <variable>ProjectExplorer.Project.PluginSettings</variable>
49 49 <valuemap type="QVariantMap"/>
50 50 </data>
51 51 <data>
52 52 <variable>ProjectExplorer.Project.Target.0</variable>
53 53 <valuemap type="QVariantMap">
54 54 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
55 55 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
56 56 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{e04e3924-0bd8-4708-be18-f1474e45608e}</value>
57 57 <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
58 58 <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
59 59 <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
60 60 <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
61 61 <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory"></value>
62 62 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
63 63 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
64 64 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
65 65 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
66 66 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
67 67 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
68 68 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
69 69 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">false</value>
70 70 <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
71 71 <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
72 72 </valuemap>
73 73 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
74 74 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
75 75 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
76 76 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
77 77 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
78 78 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
79 79 <value type="QString">-w</value>
80 80 <value type="QString">-r</value>
81 81 </valuelist>
82 82 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
83 83 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
84 84 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
85 85 </valuemap>
86 86 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
87 87 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
88 88 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
89 89 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
90 90 </valuemap>
91 91 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
92 92 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
93 93 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
94 94 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
95 95 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
96 96 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
97 97 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
98 98 <value type="QString">-w</value>
99 99 <value type="QString">-r</value>
100 100 </valuelist>
101 101 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
102 102 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
103 103 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
104 104 </valuemap>
105 105 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
106 106 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
107 107 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
108 108 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
109 109 </valuemap>
110 110 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
111 111 <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
112 112 <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
113 113 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
114 114 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
115 115 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
116 116 <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
117 117 <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
118 118 </valuemap>
119 119 <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
120 120 <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
121 121 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
122 122 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
123 123 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
124 124 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
125 125 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
126 126 </valuemap>
127 127 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
128 128 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
129 129 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
130 130 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
131 131 </valuemap>
132 132 <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
133 133 <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
134 134 <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
135 135 <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
136 136 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
137 137 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
138 138 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
139 139 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
140 140 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
141 141 <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
142 142 <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
143 143 <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
144 144 <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
145 145 <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
146 146 <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
147 147 <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
148 148 <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
149 149 <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
150 150 <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
151 151 <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
152 152 <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
153 153 <value type="int">0</value>
154 154 <value type="int">1</value>
155 155 <value type="int">2</value>
156 156 <value type="int">3</value>
157 157 <value type="int">4</value>
158 158 <value type="int">5</value>
159 159 <value type="int">6</value>
160 160 <value type="int">7</value>
161 161 <value type="int">8</value>
162 162 <value type="int">9</value>
163 163 <value type="int">10</value>
164 164 <value type="int">11</value>
165 165 <value type="int">12</value>
166 166 <value type="int">13</value>
167 167 <value type="int">14</value>
168 168 </valuelist>
169 169 <value type="int" key="PE.EnvironmentAspect.Base">2</value>
170 170 <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
171 171 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">fsw-qt</value>
172 172 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
173 173 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/opt/DEV_PLE/FSW-qt/fsw-qt.pro</value>
174 174 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
175 175 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">fsw-qt.pro</value>
176 176 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
177 177 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
178 178 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
179 179 <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
180 180 <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
181 181 <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
182 182 <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
183 183 <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
184 184 <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
185 185 </valuemap>
186 186 <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
187 187 </valuemap>
188 188 </data>
189 189 <data>
190 190 <variable>ProjectExplorer.Project.Target.1</variable>
191 191 <valuemap type="QVariantMap">
192 192 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop-Qt 4.8.2 in PATH (System)</value>
193 193 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop-Qt 4.8.2 in PATH (System)</value>
194 194 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{5289e843-9ef2-45ce-88c6-ad27d8e08def}</value>
195 195 <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
196 196 <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
197 197 <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
198 198 <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
199 199 <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory"></value>
200 200 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
201 201 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
202 202 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
203 203 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
204 204 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
205 205 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
206 206 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
207 207 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">false</value>
208 208 <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
209 209 <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
210 210 </valuemap>
211 211 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
212 212 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
213 213 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
214 214 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
215 215 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
216 216 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
217 217 <value type="QString">-w</value>
218 218 <value type="QString">-r</value>
219 219 </valuelist>
220 220 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
221 221 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
222 222 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
223 223 </valuemap>
224 224 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
225 225 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
226 226 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
227 227 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
228 228 </valuemap>
229 229 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
230 230 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
231 231 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
232 232 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
233 233 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
234 234 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
235 235 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
236 236 <value type="QString">-w</value>
237 237 <value type="QString">-r</value>
238 238 </valuelist>
239 239 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
240 240 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
241 241 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
242 242 </valuemap>
243 243 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
244 244 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
245 245 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
246 246 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
247 247 </valuemap>
248 248 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
249 249 <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
250 250 <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
251 251 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
252 252 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
253 253 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
254 254 <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
255 255 <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
256 256 </valuemap>
257 257 <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
258 258 <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
259 259 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
260 260 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
261 261 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
262 262 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
263 263 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
264 264 </valuemap>
265 265 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
266 266 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
267 267 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
268 268 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
269 269 </valuemap>
270 270 <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
271 271 <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
272 272 <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
273 273 <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
274 274 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
275 275 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
276 276 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
277 277 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
278 278 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
279 279 <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
280 280 <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
281 281 <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
282 282 <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
283 283 <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
284 284 <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
285 285 <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
286 286 <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
287 287 <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
288 288 <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
289 289 <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
290 290 <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
291 291 <value type="int">0</value>
292 292 <value type="int">1</value>
293 293 <value type="int">2</value>
294 294 <value type="int">3</value>
295 295 <value type="int">4</value>
296 296 <value type="int">5</value>
297 297 <value type="int">6</value>
298 298 <value type="int">7</value>
299 299 <value type="int">8</value>
300 300 <value type="int">9</value>
301 301 <value type="int">10</value>
302 302 <value type="int">11</value>
303 303 <value type="int">12</value>
304 304 <value type="int">13</value>
305 305 <value type="int">14</value>
306 306 </valuelist>
307 307 <value type="int" key="PE.EnvironmentAspect.Base">2</value>
308 308 <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
309 309 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">fsw-qt</value>
310 310 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
311 311 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/opt/DEV_PLE/FSW-qt/fsw-qt.pro</value>
312 312 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
313 313 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">fsw-qt.pro</value>
314 314 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
315 315 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
316 316 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
317 317 <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
318 318 <value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
319 319 <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
320 320 <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
321 321 <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
322 322 <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
323 323 </valuemap>
324 324 <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
325 325 </valuemap>
326 326 </data>
327 327 <data>
328 328 <variable>ProjectExplorer.Project.TargetCount</variable>
329 329 <value type="int">2</value>
330 330 </data>
331 331 <data>
332 332 <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
333 333 <value type="QByteArray">{2e58a81f-9962-4bba-ae6b-760177f0656c}</value>
334 334 </data>
335 335 <data>
336 336 <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
337 337 <value type="int">15</value>
338 338 </data>
339 339 </qtcreator>
@@ -1,609 +1,610
1 1 #ifndef CCSDS_TYPES_H_INCLUDED
2 2 #define CCSDS_TYPES_H_INCLUDED
3 3
4 4 #include "fsw_params_processing.h"
5 5
6 6 #define CCSDS_PROTOCOLE_EXTRA_BYTES 4
7 7 #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
8 8 #define CCSDS_TM_PKT_MAX_SIZE 4412
9 9 #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
10 10 #define CCSDS_TC_PKT_MAX_SIZE 256
11 11 #define CCSDS_TC_PKT_MIN_SIZE 16
12 12 #define CCSDS_TC_TM_PACKET_OFFSET 7
13 13 #define CCSDS_PROCESS_ID 76
14 14 #define CCSDS_PACKET_CATEGORY 12
15 15 #define CCSDS_NODE_ADDRESS 0xfe
16 16 #define CCSDS_USER_APP 0x00
17 17
18 18 #define DEFAULT_SPARE1_PUSVERSION_SPARE2 0x10
19 19 #define DEFAULT_RESERVED 0x00
20 20 #define DEFAULT_HKBIA 0x1e // 0001 1110
21 21
22 22 // PACKET ID
23 23 #define TM_PACKET_ID_TC_EXE 0x0cc1 // PID 76 CAT 1
24 24 #define TM_PACKET_ID_HK 0x0cc4 // PID 76 CAT 4
25 25 #define TM_PACKET_ID_PARAMETER_DUMP 0x0cc9 // PID 76 CAT 9
26 26 #define TM_PACKET_ID_SCIENCE_NORMAL_BURST 0x0ccc // PID 76 CAT 12
27 27 #define TM_PACKET_ID_SCIENCE_SBM1_SBM2 0x0cfc // PID 79 CAT 12
28 28 #define TM_PACKET_PID_DEFAULT 76
29 29 #define TM_PACKET_PID_BURST_SBM1_SBM2 79
30 30 #define TM_PACKET_CAT_TC_EXE 1
31 31 #define TM_PACKET_CAT_HK 4
32 32 #define TM_PACKET_CAT_PARAMETER_DUMP 9
33 33 #define TM_PACKET_CAT_SCIENCE 12
34 #define TC_PACKET_CAT 12
34 35
35 36 // PACKET SEQUENCE CONTROL
36 37 #define TM_PACKET_SEQ_CTRL_CONTINUATION 0x00 // [0000 0000]
37 38 #define TM_PACKET_SEQ_CTRL_FIRST 0x40 // [0100 0000]
38 39 #define TM_PACKET_SEQ_CTRL_LAST 0x80 // [1000 0000]
39 40 #define TM_PACKET_SEQ_CTRL_STANDALONE 0xc0 // [1100 0000]
40 41 #define TM_PACKET_SEQ_CNT_DEFAULT 0x00 // [0000 0000]
41 42
42 43 // DESTINATION ID
43 44 #define TM_DESTINATION_ID_GROUND 0
44 45 #define TM_DESTINATION_ID_MISSION_TIMELINE 110
45 46 #define TM_DESTINATION_ID_TC_SEQUENCES 111
46 47 #define TM_DESTINATION_ID_RECOVERY_ACTION_COMMAND 112
47 48 #define TM_DESTINATION_ID_BACKUP_MISSION_TIMELINE 113
48 49 #define TM_DESTINATION_ID_DIRECT_CMD 120
49 50 #define TM_DESTINATION_ID_SPARE_GRD_SRC1 121
50 51 #define TM_DESTINATION_ID_SPARE_GRD_SRC2 122
51 52 #define TM_DESTINATION_ID_OBCP 15
52 53 #define TM_DESTINATION_ID_SYSTEM_CONTROL 14
53 54 #define TM_DESTINATION_ID_AOCS 11
54 55
55 56 #define CCSDS_DESTINATION_ID 0x01
56 57 #define CCSDS_PROTOCOLE_ID 0x02
57 58 #define CCSDS_RESERVED 0x00
58 59 #define CCSDS_USER_APP 0x00
59 60
60 61 #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
61 62 #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
62 63 #define SIZE_HK_PARAMETERS 112
63 64
64 65 // TC TYPES
65 66 #define TC_TYPE_GEN 181
66 67 #define TC_TYPE_TIME 9
67 68
68 69 // TC SUBTYPES
69 70 #define TC_SUBTYPE_RESET 1
70 71 #define TC_SUBTYPE_LOAD_COMM 11
71 72 #define TC_SUBTYPE_LOAD_NORM 13
72 73 #define TC_SUBTYPE_LOAD_BURST 19
73 74 #define TC_SUBTYPE_LOAD_SBM1 25
74 75 #define TC_SUBTYPE_LOAD_SBM2 27
75 76 #define TC_SUBTYPE_DUMP 31
76 77 #define TC_SUBTYPE_ENTER 41
77 78 #define TC_SUBTYPE_UPDT_INFO 51
78 79 #define TC_SUBTYPE_EN_CAL 61
79 80 #define TC_SUBTYPE_DIS_CAL 63
80 81 #define TC_SUBTYPE_UPDT_TIME 129
81 82
82 83 // TC LEN
83 84 #define TC_LEN_RESET 12
84 85 #define TC_LEN_LOAD_COMM 14
85 86 #define TC_LEN_LOAD_NORM 22
86 87 #define TC_LEN_LOAD_BURST 14
87 88 #define TC_LEN_LOAD_SBM1 14
88 89 #define TC_LEN_LOAD_SBM2 14
89 90 #define TC_LEN_DUMP 12
90 91 #define TC_LEN_ENTER 20
91 92 #define TC_LEN_UPDT_INFO 46
92 93 #define TC_LEN_EN_CAL 12
93 94 #define TC_LEN_DIS_CAL 12
94 95 #define TC_LEN_UPDT_TIME 18
95 96
96 97 // TM TYPES
97 98 #define TM_TYPE_TC_EXE 1
98 99 #define TM_TYPE_HK 3
99 100 #define TM_TYPE_PARAMETER_DUMP 3
100 101 #define TM_TYPE_LFR_SCIENCE 21
101 102
102 103 // TM SUBTYPES
103 104 #define TM_SUBTYPE_EXE_OK 7
104 105 #define TM_SUBTYPE_EXE_NOK 8
105 106 #define TM_SUBTYPE_HK 25
106 107 #define TM_SUBTYPE_PARAMETER_DUMP 25
107 108 #define TM_SUBTYPE_SCIENCE 3
108 109 #define TM_SUBTYPE_LFR_SCIENCE 3
109 110
110 111 // FAILURE CODES
111 112 #define ILLEGAL_APID 0
112 113 #define WRONG_LEN_PKT 1
113 114 #define INCOR_CHECKSUM 2
114 115 #define ILL_TYPE 3
115 116 #define ILL_SUBTYPE 4
116 117 #define WRONG_APP_DATA 5 // 0x00 0x05
117 118 #define TC_NOT_EXE 42000 // 0xa4 0x10
118 119 #define WRONG_SRC_ID 42001 // 0xa4 0x11
119 120 #define FUNCT_NOT_IMPL 42002 // 0xa4 0x12
120 121 #define FAIL_DETECTED 42003 // 0xa4 0x13
121 122 #define NOT_ALLOWED 42004 // 0xa4 0x14
122 123 #define CORRUPTED 42005 // 0xa4 0x15
123 124 #define CCSDS_TM_VALID 7
124 125
125 126 // TC SID
126 127 #define SID_TC_GROUND 0
127 128 #define SID_TC_MISSION_TIMELINE 110
128 129 #define SID_TC_TC_SEQUENCES 111
129 130 #define SID_TC_RECOVERY_ACTION_CMD 112
130 131 #define SID_TC_BACKUP_MISSION_TIMELINE 113
131 132 #define SID_TC_DIRECT_CMD 120
132 133 #define SID_TC_SPARE_GRD_SRC1 121
133 134 #define SID_TC_SPARE_GRD_SRC2 122
134 135 #define SID_TC_OBCP 15
135 136 #define SID_TC_SYSTEM_CONTROL 14
136 137 #define SID_TC_AOCS 11
137 138 #define SID_TC_RPW_INTERNAL 254
138 139
139 140 enum apid_destid{
140 141 GROUND,
141 142 MISSION_TIMELINE,
142 143 TC_SEQUENCES,
143 144 RECOVERY_ACTION_CMD,
144 145 BACKUP_MISSION_TIMELINE,
145 146 DIRECT_CMD,
146 147 SPARE_GRD_SRC1,
147 148 SPARE_GRD_SRC2,
148 149 OBCP,
149 150 SYSTEM_CONTROL,
150 151 AOCS,
151 152 RPW_INTERNAL
152 153 };
153 154 // SEQUENCE COUNTERS
154 155 #define SEQ_CNT_MAX 16383
155 156 #define SEQ_CNT_NB_DEST_ID 12
156 157
157 158 // TM SID
158 159 #define SID_HK 1
159 160 #define SID_PARAMETER_DUMP 10
160 161
161 162 #define SID_NORM_SWF_F0 3
162 163 #define SID_NORM_SWF_F1 4
163 164 #define SID_NORM_SWF_F2 5
164 165 #define SID_NORM_CWF_F3 1
165 166 #define SID_BURST_CWF_F2 2
166 167 #define SID_SBM1_CWF_F1 24
167 168 #define SID_SBM2_CWF_F2 25
168 169 #define SID_NORM_ASM_F0 11
169 170 #define SID_NORM_ASM_F1 12
170 171 #define SID_NORM_ASM_F2 13
171 172 #define SID_NORM_BP1_F0 14
172 173 #define SID_NORM_BP1_F1 15
173 174 #define SID_NORM_BP1_F2 16
174 175 #define SID_NORM_BP2_F0 19
175 176 #define SID_NORM_BP2_F1 20
176 177 #define SID_NORM_BP2_F2 21
177 178 #define SID_BURST_BP1_F0 17
178 179 #define SID_BURST_BP2_F0 22
179 180 #define SID_BURST_BP1_F1 18
180 181 #define SID_BURST_BP2_F1 23
181 182 #define SID_SBM1_BP1_F0 28
182 183 #define SID_SBM1_BP2_F0 31
183 184 #define SID_SBM2_BP1_F0 29
184 185 #define SID_SBM2_BP2_F0 32
185 186 #define SID_SBM2_BP1_F1 30
186 187 #define SID_SBM2_BP2_F1 33
187 188 #define SID_NORM_CWF_LONG_F3 34
188 189
189 190 // LENGTH (BYTES)
190 191 #define LENGTH_TM_LFR_TC_EXE_MAX 32
191 192 #define LENGTH_TM_LFR_HK 126
192 193
193 194 // HEADER_LENGTH
194 195 #define TM_HEADER_LEN 16
195 196 #define HEADER_LENGTH_TM_LFR_SCIENCE_ASM 28
196 197 // PACKET_LENGTH
197 198 #define PACKET_LENGTH_TC_EXE_SUCCESS (20 - CCSDS_TC_TM_PACKET_OFFSET)
198 199 #define PACKET_LENGTH_TC_EXE_INCONSISTENT (26 - CCSDS_TC_TM_PACKET_OFFSET)
199 200 #define PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE (26 - CCSDS_TC_TM_PACKET_OFFSET)
200 201 #define PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED (24 - CCSDS_TC_TM_PACKET_OFFSET)
201 202 #define PACKET_LENGTH_TC_EXE_ERROR (24 - CCSDS_TC_TM_PACKET_OFFSET)
202 203 #define PACKET_LENGTH_TC_EXE_CORRUPTED (32 - CCSDS_TC_TM_PACKET_OFFSET)
203 204 #define PACKET_LENGTH_HK (124 - CCSDS_TC_TM_PACKET_OFFSET)
204 205 #define PACKET_LENGTH_PARAMETER_DUMP (36 - CCSDS_TC_TM_PACKET_OFFSET)
205 206 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0 2221 // 44 * 25 * 2 + 28 - 7
206 207 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1 2621 // 52 * 25 * 2 + 28 - 7
207 208 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2 2421 // 48 * 25 * 2 + 28 - 7
208 209
209 210 #define SPARE1_PUSVERSION_SPARE2 0x10
210 211
211 212 // R1
212 213 #define TM_LEN_SCI_SWF_340 4101 // 340 * 12 + 10 + 12 - 1
213 214 #define TM_LEN_SCI_SWF_8 117 // 8 * 12 + 10 + 12 - 1
214 215 #define TM_LEN_SCI_CWF_340 4099 // 340 * 12 + 10 + 10 - 1
215 216 #define TM_LEN_SCI_CWF_8 115 // 8 * 12 + 10 + 10 - 1
216 217 #define TM_LEN_SCI_CWF3_LIGHT_340 2059 // 340 * 6 + 10 + 10 - 1
217 218 #define TM_LEN_SCI_CWF3_LIGHT_8 67 // 8 * 6 + 10 + 10 - 1
218 219 // R2
219 220 #define TM_LEN_SCI_SWF_304 3669 // 304 * 12 + 10 + 12 - 1
220 221 #define TM_LEN_SCI_SWF_224 2709 // 224 * 12 + 10 + 12 - 1
221 222 #define TM_LEN_SCI_CWF_336 4051 // 336 * 12 + 10 + 10 - 1
222 223 #define TM_LEN_SCI_CWF_672 4051 // 672 * 6 + 10 + 10 - 1
223 224 //
224 225 #define DEFAULT_PKTCNT 0x07
225 226 #define BLK_NR_304 0x0130
226 227 #define BLK_NR_224 0x00e0
227 228 #define BLK_NR_CWF 0x0150 // 336
228 229 #define BLK_NR_CWF_SHORT_F3 0x02a0 // 672
229 230
230 231 enum TM_TYPE{
231 232 TM_LFR_TC_EXE_OK,
232 233 TM_LFR_TC_EXE_ERR,
233 234 TM_LFR_HK,
234 235 TM_LFR_SCI,
235 236 TM_LFR_SCI_SBM,
236 237 TM_LFR_PAR_DUMP
237 238 };
238 239
239 240 typedef struct {
240 241 unsigned char targetLogicalAddress;
241 242 unsigned char protocolIdentifier;
242 243 unsigned char reserved;
243 244 unsigned char userApplication;
244 245 // PACKET HEADER
245 246 unsigned char packetID[2];
246 247 unsigned char packetSequenceControl[2];
247 248 unsigned char packetLength[2];
248 249 // DATA FIELD HEADER
249 250 unsigned char spare1_pusVersion_spare2;
250 251 unsigned char serviceType;
251 252 unsigned char serviceSubType;
252 253 unsigned char destinationID;
253 254 unsigned char time[6];
254 255 //
255 256 unsigned char telecommand_pkt_id[2];
256 257 unsigned char pkt_seq_control[2];
257 258 } Packet_TM_LFR_TC_EXE_SUCCESS_t;
258 259
259 260 typedef struct {
260 261 unsigned char targetLogicalAddress;
261 262 unsigned char protocolIdentifier;
262 263 unsigned char reserved;
263 264 unsigned char userApplication;
264 265 // PACKET HEADER
265 266 unsigned char packetID[2];
266 267 unsigned char packetSequenceControl[2];
267 268 unsigned char packetLength[2];
268 269 // DATA FIELD HEADER
269 270 unsigned char spare1_pusVersion_spare2;
270 271 unsigned char serviceType;
271 272 unsigned char serviceSubType;
272 273 unsigned char destinationID;
273 274 unsigned char time[6];
274 275 //
275 276 unsigned char tc_failure_code[2];
276 277 unsigned char telecommand_pkt_id[2];
277 278 unsigned char pkt_seq_control[2];
278 279 unsigned char tc_service;
279 280 unsigned char tc_subtype;
280 281 unsigned char byte_position;
281 282 unsigned char rcv_value;
282 283 } Packet_TM_LFR_TC_EXE_INCONSISTENT_t;
283 284
284 285 typedef struct {
285 286 unsigned char targetLogicalAddress;
286 287 unsigned char protocolIdentifier;
287 288 unsigned char reserved;
288 289 unsigned char userApplication;
289 290 // PACKET HEADER
290 291 unsigned char packetID[2];
291 292 unsigned char packetSequenceControl[2];
292 293 unsigned char packetLength[2];
293 294 // DATA FIELD HEADER
294 295 unsigned char spare1_pusVersion_spare2;
295 296 unsigned char serviceType;
296 297 unsigned char serviceSubType;
297 298 unsigned char destinationID;
298 299 unsigned char time[6];
299 300 //
300 301 unsigned char tc_failure_code[2];
301 302 unsigned char telecommand_pkt_id[2];
302 303 unsigned char pkt_seq_control[2];
303 304 unsigned char tc_service;
304 305 unsigned char tc_subtype;
305 306 unsigned char lfr_status_word[2];
306 307 } Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t;
307 308
308 309 typedef struct {
309 310 unsigned char targetLogicalAddress;
310 311 unsigned char protocolIdentifier;
311 312 unsigned char reserved;
312 313 unsigned char userApplication;
313 314 // PACKET HEADER
314 315 unsigned char packetID[2];
315 316 unsigned char packetSequenceControl[2];
316 317 unsigned char packetLength[2];
317 318 // DATA FIELD HEADER
318 319 unsigned char spare1_pusVersion_spare2;
319 320 unsigned char serviceType;
320 321 unsigned char serviceSubType;
321 322 unsigned char destinationID;
322 323 unsigned char time[6];
323 324 //
324 325 unsigned char tc_failure_code[2];
325 326 unsigned char telecommand_pkt_id[2];
326 327 unsigned char pkt_seq_control[2];
327 328 unsigned char tc_service;
328 329 unsigned char tc_subtype;
329 330 } Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t;
330 331
331 332 typedef struct {
332 333 unsigned char targetLogicalAddress;
333 334 unsigned char protocolIdentifier;
334 335 unsigned char reserved;
335 336 unsigned char userApplication;
336 337 // PACKET HEADER
337 338 unsigned char packetID[2];
338 339 unsigned char packetSequenceControl[2];
339 340 unsigned char packetLength[2];
340 341 // DATA FIELD HEADER
341 342 unsigned char spare1_pusVersion_spare2;
342 343 unsigned char serviceType;
343 344 unsigned char serviceSubType;
344 345 unsigned char destinationID;
345 346 unsigned char time[6];
346 347 //
347 348 unsigned char tc_failure_code[2];
348 349 unsigned char telecommand_pkt_id[2];
349 350 unsigned char pkt_seq_control[2];
350 351 unsigned char tc_service;
351 352 unsigned char tc_subtype;
352 353 } Packet_TM_LFR_TC_EXE_ERROR_t;
353 354
354 355 typedef struct {
355 356 unsigned char targetLogicalAddress;
356 357 unsigned char protocolIdentifier;
357 358 unsigned char reserved;
358 359 unsigned char userApplication;
359 360 // PACKET HEADER
360 361 unsigned char packetID[2];
361 362 unsigned char packetSequenceControl[2];
362 363 unsigned char packetLength[2];
363 364 // DATA FIELD HEADER
364 365 unsigned char spare1_pusVersion_spare2;
365 366 unsigned char serviceType;
366 367 unsigned char serviceSubType;
367 368 unsigned char destinationID;
368 369 unsigned char time[6];
369 370 //
370 371 unsigned char tc_failure_code[2];
371 372 unsigned char telecommand_pkt_id[2];
372 373 unsigned char pkt_seq_control[2];
373 374 unsigned char tc_service;
374 375 unsigned char tc_subtype;
375 376 unsigned char pkt_len_rcv_value[2];
376 377 unsigned char pkt_datafieldsize_cnt[2];
377 378 unsigned char rcv_crc[2];
378 379 unsigned char computed_crc[2];
379 380 } Packet_TM_LFR_TC_EXE_CORRUPTED_t;
380 381
381 382 typedef struct {
382 383 unsigned char targetLogicalAddress;
383 384 unsigned char protocolIdentifier;
384 385 unsigned char reserved;
385 386 unsigned char userApplication;
386 387 unsigned char packetID[2];
387 388 unsigned char packetSequenceControl[2];
388 389 unsigned char packetLength[2];
389 390 // DATA FIELD HEADER
390 391 unsigned char spare1_pusVersion_spare2;
391 392 unsigned char serviceType;
392 393 unsigned char serviceSubType;
393 394 unsigned char destinationID;
394 395 unsigned char time[6];
395 396 // AUXILIARY HEADER
396 397 unsigned char sid;
397 398 unsigned char hkBIA;
398 399 unsigned char pktCnt;
399 400 unsigned char pktNr;
400 401 unsigned char acquisitionTime[6];
401 402 unsigned char blkNr[2];
402 403 } Header_TM_LFR_SCIENCE_SWF_t;
403 404
404 405 typedef struct {
405 406 unsigned char targetLogicalAddress;
406 407 unsigned char protocolIdentifier;
407 408 unsigned char reserved;
408 409 unsigned char userApplication;
409 410 unsigned char packetID[2];
410 411 unsigned char packetSequenceControl[2];
411 412 unsigned char packetLength[2];
412 413 // DATA FIELD HEADER
413 414 unsigned char spare1_pusVersion_spare2;
414 415 unsigned char serviceType;
415 416 unsigned char serviceSubType;
416 417 unsigned char destinationID;
417 418 unsigned char time[6];
418 419 // AUXILIARY DATA HEADER
419 420 unsigned char sid;
420 421 unsigned char hkBIA;
421 422 unsigned char acquisitionTime[6];
422 423 unsigned char blkNr[2];
423 424 } Header_TM_LFR_SCIENCE_CWF_t;
424 425
425 426 typedef struct {
426 427 unsigned char targetLogicalAddress;
427 428 unsigned char protocolIdentifier;
428 429 unsigned char reserved;
429 430 unsigned char userApplication;
430 431 unsigned char packetID[2];
431 432 unsigned char packetSequenceControl[2];
432 433 unsigned char packetLength[2];
433 434 // DATA FIELD HEADER
434 435 unsigned char spare1_pusVersion_spare2;
435 436 unsigned char serviceType;
436 437 unsigned char serviceSubType;
437 438 unsigned char destinationID;
438 439 unsigned char time[6];
439 440 // AUXILIARY HEADER
440 441 unsigned char sid;
441 442 unsigned char biaStatusInfo;
442 443 unsigned char pa_lfr_pkt_cnt_asm;
443 444 unsigned char pa_lfr_pkt_nr_asm;
444 445 unsigned char acquisitionTime[6];
445 446 unsigned char pa_lfr_asm_blk_nr[2];
446 447 } Header_TM_LFR_SCIENCE_ASM_t;
447 448
448 449 typedef struct {
449 450 //targetLogicalAddress is removed by the grspw module
450 451 unsigned char protocolIdentifier;
451 452 unsigned char reserved;
452 453 unsigned char userApplication;
453 454 unsigned char packetID[2];
454 455 unsigned char packetSequenceControl[2];
455 456 unsigned char packetLength[2];
456 457 // DATA FIELD HEADER
457 458 unsigned char headerFlag_pusVersion_Ack;
458 459 unsigned char serviceType;
459 460 unsigned char serviceSubType;
460 461 unsigned char sourceID;
461 462 unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
462 463 } ccsdsTelecommandPacket_t;
463 464
464 465 typedef struct {
465 466 unsigned char targetLogicalAddress;
466 467 unsigned char protocolIdentifier;
467 468 unsigned char reserved;
468 469 unsigned char userApplication;
469 470 unsigned char packetID[2];
470 471 unsigned char packetSequenceControl[2];
471 472 unsigned char packetLength[2];
472 473 unsigned char spare1_pusVersion_spare2;
473 474 unsigned char serviceType;
474 475 unsigned char serviceSubType;
475 476 unsigned char destinationID;
476 477 unsigned char time[6];
477 478 unsigned char sid;
478 479
479 480 //**************
480 481 // HK PARAMETERS
481 482 unsigned char lfr_status_word[2];
482 483 unsigned char lfr_sw_version[4];
483 484 unsigned char lfr_fpga_version[3];
484 485 // ressource statistics
485 486 unsigned char hk_lfr_cpu_load;
486 487 unsigned char hk_lfr_load_max;
487 488 unsigned char hk_lfr_load_aver;
488 489 // tc statistics
489 490 unsigned char hk_lfr_update_info_tc_cnt[2];
490 491 unsigned char hk_lfr_update_time_tc_cnt[2];
491 492 unsigned char hk_lfr_exe_tc_cnt[2];
492 493 unsigned char hk_lfr_rej_tc_cnt[2];
493 494 unsigned char hk_lfr_last_exe_tc_id[2];
494 495 unsigned char hk_lfr_last_exe_tc_type[2];
495 496 unsigned char hk_lfr_last_exe_tc_subtype[2];
496 497 unsigned char hk_lfr_last_exe_tc_time[6];
497 498 unsigned char hk_lfr_last_rej_tc_id[2];
498 499 unsigned char hk_lfr_last_rej_tc_type[2];
499 500 unsigned char hk_lfr_last_rej_tc_subtype[2];
500 501 unsigned char hk_lfr_last_rej_tc_time[6];
501 502 // anomaly statistics
502 503 unsigned char hk_lfr_le_cnt[2];
503 504 unsigned char hk_lfr_me_cnt[2];
504 505 unsigned char hk_lfr_he_cnt[2];
505 506 unsigned char hk_lfr_last_er_rid[2];
506 507 unsigned char hk_lfr_last_er_code;
507 508 unsigned char hk_lfr_last_er_time[6];
508 509 // vhdl_blk_status
509 510 unsigned char hk_lfr_vhdl_aa_sm;
510 511 unsigned char hk_lfr_vhdl_fft_sr;
511 512 unsigned char hk_lfr_vhdl_cic_hk;
512 513 unsigned char hk_lfr_vhdl_iir_cal;
513 514 // spacewire_if_statistics
514 515 unsigned char hk_lfr_dpu_spw_pkt_rcv_cnt[2];
515 516 unsigned char hk_lfr_dpu_spw_pkt_sent_cnt[2];
516 517 unsigned char hk_lfr_dpu_spw_tick_out_cnt;
517 518 unsigned char hk_lfr_dpu_spw_last_timc;
518 519 // ahb error statistics
519 520 unsigned int hk_lfr_last_fail_addr;
520 521 // temperatures
521 522 unsigned char hk_lfr_temp_scm[2];
522 523 unsigned char hk_lfr_temp_pcb[2];
523 524 unsigned char hk_lfr_temp_fpga[2];
524 525 // spacecraft potential
525 526 unsigned char hk_lfr_sc_v_f3[2];
526 527 unsigned char hk_lfr_sc_e1_f3[2];
527 528 unsigned char hk_lfr_sc_e2_f3[2];
528 529 // error counters
529 530 unsigned char hk_lfr_dpu_spw_parity;
530 531 unsigned char hk_lfr_dpu_spw_disconnect;
531 532 unsigned char hk_lfr_dpu_spw_escape;
532 533 unsigned char hk_lfr_dpu_spw_credit;
533 534 unsigned char hk_lfr_dpu_spw_write_sync;
534 535 unsigned char hk_lfr_dpu_spw_rx_ahb;
535 536 unsigned char hk_lfr_dpu_spw_tx_ahb;
536 537 unsigned char hk_lfr_dpu_spw_early_eop;
537 538 unsigned char hk_lfr_dpu_spw_invalid_addr;
538 539 unsigned char hk_lfr_dpu_spw_eep;
539 540 unsigned char hk_lfr_dpu_spw_rx_too_big;
540 541 // timecode
541 542 unsigned char hk_lfr_timecode_erroneous;
542 543 unsigned char hk_lfr_timecode_missing;
543 544 unsigned char hk_lfr_timecode_invalid;
544 545 // time
545 546 unsigned char hk_lfr_time_timecode_it;
546 547 unsigned char hk_lfr_time_not_synchro;
547 548 unsigned char hk_lfr_time_timecode_ctr;
548 549 // hk_lfr_buffer_dpu_
549 550 unsigned char hk_lfr_buffer_dpu_tc_fifo;
550 551 unsigned char hk_lfr_buffer_dpu_tm_fifo;
551 552 // hk_lfr_ahb_
552 553 unsigned char hk_lfr_ahb_correctable;
553 554 unsigned char hk_lfr_ahb_uncorrectable;
554 555 // spare
555 556 unsigned char parameters_spare;
556 557 } Packet_TM_LFR_HK_t;
557 558
558 559 typedef struct {
559 560 unsigned char targetLogicalAddress;
560 561 unsigned char protocolIdentifier;
561 562 unsigned char reserved;
562 563 unsigned char userApplication;
563 564 unsigned char packetID[2];
564 565 unsigned char packetSequenceControl[2];
565 566 unsigned char packetLength[2];
566 567 // DATA FIELD HEADER
567 568 unsigned char spare1_pusVersion_spare2;
568 569 unsigned char serviceType;
569 570 unsigned char serviceSubType;
570 571 unsigned char destinationID;
571 572 unsigned char time[6];
572 573 unsigned char sid;
573 574
574 575 //******************
575 576 // COMMON PARAMETERS
576 577 unsigned char unused0;
577 578 unsigned char bw_sp0_sp1_r0_r1;
578 579
579 580 //******************
580 581 // NORMAL PARAMETERS
581 582 unsigned char sy_lfr_n_swf_l[2];
582 583 unsigned char sy_lfr_n_swf_p[2];
583 584 unsigned char sy_lfr_n_asm_p[2];
584 585 unsigned char sy_lfr_n_bp_p0;
585 586 unsigned char sy_lfr_n_bp_p1;
586 587 unsigned char sy_lfr_n_cwf_long_f3;
587 588 unsigned char lfr_normal_parameters_spare;
588 589
589 590 //*****************
590 591 // BURST PARAMETERS
591 592 unsigned char sy_lfr_b_bp_p0;
592 593 unsigned char sy_lfr_b_bp_p1;
593 594
594 595 //****************
595 596 // SBM1 PARAMETERS
596 597 unsigned char sy_lfr_s1_bp_p0;
597 598 unsigned char sy_lfr_s1_bp_p1;
598 599
599 600 //****************
600 601 // SBM2 PARAMETERS
601 602 unsigned char sy_lfr_s2_bp_p0;
602 603 unsigned char sy_lfr_s2_bp_p1;
603 604
604 605 // SPARE
605 606 unsigned char source_data_spare;
606 607 } Packet_TM_LFR_PARAMETER_DUMP_t;
607 608
608 609
609 610 #endif // CCSDS_TYPES_H_INCLUDED
@@ -1,229 +1,230
1 1 #ifndef FSW_PARAMS_H_INCLUDED
2 2 #define FSW_PARAMS_H_INCLUDED
3 3
4 4 #include "grlib_regs.h"
5 5 #include "fsw_params_processing.h"
6 6 #include "fsw_params_nb_bytes.h"
7 7 #include "tm_byte_positions.h"
8 8 #include "ccsds_types.h"
9 9
10 10 #define GRSPW_DEVICE_NAME "/dev/grspw0"
11 11 #define UART_DEVICE_NAME "/dev/console"
12 12
13 13 typedef struct ring_node
14 14 {
15 15 struct ring_node *previous;
16 16 int buffer_address;
17 17 struct ring_node *next;
18 18 unsigned int status;
19 19 } ring_node;
20 20
21 21 //************************
22 22 // flight software version
23 23 // this parameters is handled by the Qt project options
24 24
25 25 #define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk
26 26 #define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk
27 27 #define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688
28 28 #define TIME_OFFSET 2
29 29 #define TIME_OFFSET_IN_BYTES 8
30 30 #define WAVEFORM_EXTENDED_HEADER_OFFSET 22
31 31 #define NB_BYTES_SWF_BLK (2 * 6)
32 32 #define NB_WORDS_SWF_BLK 3
33 33 #define NB_BYTES_CWF3_LIGHT_BLK 6
34 34 #define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8
35 35 #define NB_RING_NODES_F0 3 // AT LEAST 3
36 36 #define NB_RING_NODES_F1 5 // AT LEAST 3
37 37 #define NB_RING_NODES_F2 5 // AT LEAST 3
38 38
39 39 //**********
40 40 // LFR MODES
41 41 #define LFR_MODE_STANDBY 0
42 42 #define LFR_MODE_NORMAL 1
43 43 #define LFR_MODE_BURST 2
44 44 #define LFR_MODE_SBM1 3
45 45 #define LFR_MODE_SBM2 4
46 46
47 47 #define TDS_MODE_LFM 5
48 48 #define TDS_MODE_STANDBY 0
49 49 #define TDS_MODE_NORMAL 1
50 50 #define TDS_MODE_BURST 2
51 51 #define TDS_MODE_SBM1 3
52 52 #define TDS_MODE_SBM2 4
53 53
54 54 #define THR_MODE_STANDBY 0
55 55 #define THR_MODE_NORMAL 1
56 56 #define THR_MODE_BURST 2
57 57
58 58 #define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0
59 59 #define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1
60 60 #define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2
61 61 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
62 62 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
63 63 #define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5
64 64 #define RTEMS_EVENT_MODE_NORMAL_SWF_F0 RTEMS_EVENT_6
65 65 #define RTEMS_EVENT_MODE_NORMAL_SWF_F1 RTEMS_EVENT_7
66 66 #define RTEMS_EVENT_MODE_NORMAL_SWF_F2 RTEMS_EVENT_8
67 67
68 68 //****************************
69 69 // LFR DEFAULT MODE PARAMETERS
70 70 // COMMON
71 71 #define DEFAULT_SY_LFR_COMMON0 0x00
72 72 #define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0
73 73 // NORM
74 74 #define SY_LFR_N_SWF_L 2048 // nb sample
75 75 #define SY_LFR_N_SWF_P 300 // sec
76 76 #define SY_LFR_N_ASM_P 3600 // sec
77 77 #define SY_LFR_N_BP_P0 4 // sec
78 78 #define SY_LFR_N_BP_P1 20 // sec
79 79 #define SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3
80 80 #define MIN_DELTA_SNAPSHOT 16 // sec
81 81 // BURST
82 82 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
83 83 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
84 84 // SBM1
85 85 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
86 86 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
87 87 // SBM2
88 88 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
89 89 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
90 90 // ADDITIONAL PARAMETERS
91 91 #define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms
92 92 #define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s
93 93 // STATUS WORD
94 94 #define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits
95 95 #define DEFAULT_STATUS_WORD_BYTE1 0x00
96 96 //
97 97 #define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s
98 98 #define SY_LFR_DPU_CONNECT_ATTEMPT 3
99 99 //****************************
100 100
101 101 //*****************************
102 102 // APB REGISTERS BASE ADDRESSES
103 103 #define REGS_ADDR_APBUART 0x80000100
104 104 #define REGS_ADDR_GPTIMER 0x80000300
105 105 #define REGS_ADDR_GRSPW 0x80000500
106 106 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
107 #define REGS_ADDR_GRGPIO 0x80000b00
107 108
108 109 #ifdef VHDL_DEV
109 110 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
110 111 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f40
111 112 #else
112 113 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
113 114 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f20
114 115 #endif
115 116
116 117 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
117 118 #define APBUART_CTRL_REG_MASK_TE 0x00000002
118 119 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50)
119 120
120 121 //**********
121 122 // IRQ LINES
122 123 #define IRQ_SM_SIMULATOR 9
123 124 #define IRQ_SPARC_SM_SIMULATOR 0x19 // see sparcv8.pdf p.76 for interrupt levels
124 125 #define IRQ_WAVEFORM_PICKER 14
125 126 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
126 127 #define IRQ_SPECTRAL_MATRIX 6
127 128 #define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels
128 129
129 130 //*****
130 131 // TIME
131 132 #define CLKDIV_SM_SIMULATOR (10000 - 1) // 10 ms
132 133 #define TIMER_SM_SIMULATOR 1
133 134 #define HK_PERIOD 100 // 100 * 10ms => 1s
134 135 #define SY_LFR_TIME_SYN_TIMEOUT_in_ms 2000
135 136 #define SY_LFR_TIME_SYN_TIMEOUT_in_ticks 200 // 200 * 10 ms = 2 s
136 137
137 138 //**********
138 139 // LPP CODES
139 140 #define LFR_SUCCESSFUL 0
140 141 #define LFR_DEFAULT 1
141 142
142 143 //******
143 144 // RTEMS
144 145 #define TASKID_RECV 1
145 146 #define TASKID_ACTN 2
146 147 #define TASKID_SPIQ 3
147 148 #define TASKID_SMIQ 4
148 149 #define TASKID_STAT 5
149 150 #define TASKID_AVF0 6
150 151 #define TASKID_SWBD 7
151 152 #define TASKID_WFRM 8
152 153 #define TASKID_DUMB 9
153 154 #define TASKID_HOUS 10
154 155 #define TASKID_MATR 11
155 156 #define TASKID_CWF3 12
156 157 #define TASKID_CWF2 13
157 158 #define TASKID_CWF1 14
158 159 #define TASKID_SEND 15
159 160 #define TASKID_WTDG 16
160 161
161 162 #define TASK_PRIORITY_SPIQ 5
162 163 #define TASK_PRIORITY_SMIQ 10
163 164 #define TASK_PRIORITY_WTDG 20
164 165 #define TASK_PRIORITY_HOUS 30
165 166 #define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together
166 167 #define TASK_PRIORITY_CWF2 35 //
167 168 #define TASK_PRIORITY_SWBD 37 // SWBD has a lower priority than WFRM, this is to extract the snapshot before sending it
168 169 #define TASK_PRIORITY_WFRM 40
169 170 #define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1
170 171 #define TASK_PRIORITY_SEND 45
171 172 #define TASK_PRIORITY_RECV 50
172 173 #define TASK_PRIORITY_ACTN 50
173 174 #define TASK_PRIORITY_AVF0 60
174 175 #define TASK_PRIORITY_BPF0 60
175 176 #define TASK_PRIORITY_MATR 100
176 177 #define TASK_PRIORITY_STAT 200
177 178 #define TASK_PRIORITY_DUMB 200
178 179
179 180 #define ACTION_MSG_QUEUE_COUNT 10
180 181 #define ACTION_MSG_PKTS_COUNT 50
181 182 #define ACTION_MSG_PKTS_MAX_SIZE (PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES)
182 183 #define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options
183 184
184 185 #define QUEUE_RECV 0
185 186 #define QUEUE_SEND 1
186 187
187 188 //*******
188 189 // MACROS
189 190 #ifdef PRINT_MESSAGES_ON_CONSOLE
190 191 #define PRINTF(x) printf(x);
191 192 #define PRINTF1(x,y) printf(x,y);
192 193 #define PRINTF2(x,y,z) printf(x,y,z);
193 194 #else
194 195 #define PRINTF(x) ;
195 196 #define PRINTF1(x,y) ;
196 197 #define PRINTF2(x,y,z) ;
197 198 #endif
198 199
199 200 #ifdef BOOT_MESSAGES
200 201 #define BOOT_PRINTF(x) printf(x);
201 202 #define BOOT_PRINTF1(x,y) printf(x,y);
202 203 #define BOOT_PRINTF2(x,y,z) printf(x,y,z);
203 204 #else
204 205 #define BOOT_PRINTF(x) ;
205 206 #define BOOT_PRINTF1(x,y) ;
206 207 #define BOOT_PRINTF2(x,y,z) ;
207 208 #endif
208 209
209 210 #ifdef DEBUG_MESSAGES
210 211 #define DEBUG_PRINTF(x) printf(x);
211 212 #define DEBUG_PRINTF1(x,y) printf(x,y);
212 213 #define DEBUG_PRINTF2(x,y,z) printf(x,y,z);
213 214 #else
214 215 #define DEBUG_PRINTF(x) ;
215 216 #define DEBUG_PRINTF1(x,y) ;
216 217 #define DEBUG_PRINTF2(x,y,z) ;
217 218 #endif
218 219
219 220 #define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period
220 221
221 222 struct param_local_str{
222 223 unsigned int local_sbm1_nb_cwf_sent;
223 224 unsigned int local_sbm1_nb_cwf_max;
224 225 unsigned int local_sbm2_nb_cwf_sent;
225 226 unsigned int local_sbm2_nb_cwf_max;
226 227 unsigned int local_nb_interrupt_f0_MAX;
227 228 };
228 229
229 230 #endif // FSW_PARAMS_H_INCLUDED
@@ -1,54 +1,57
1 1 #ifndef FSW_PARAMS_PROCESSING_H
2 2 #define FSW_PARAMS_PROCESSING_H
3 3
4 4 #define NB_BINS_PER_SM 128
5 5 #define NB_VALUES_PER_SM 25
6 6 #define TOTAL_SIZE_SM 3200 // 25 * 128
7 #define TOTAL_SIZE_BP1_F0 99 // 11 * 9 = 99
8 #define TOTAL_SIZE_BP1_F1 117 // 13 * 9 = 117
9 #define TOTAL_SIZE_BP1_F2 108 // 12 * 9 = 108
7 10 //
8 11 #define NB_RING_NODES_ASM_F0 12 // AT LEAST 3
9 12 #define NB_RING_NODES_ASM_F1 2 // AT LEAST 3
10 13 #define NB_RING_NODES_ASM_F2 2 // AT LEAST 3
11 14 //
12 15 #define NB_BINS_PER_ASM_F0 88
13 16 #define NB_BINS_PER_PKT_ASM_F0 44
14 17 #define TOTAL_SIZE_ASM_F0_IN_BYTES 4400 // 25 * 88 * 2
15 18 #define ASM_F0_INDICE_START 17 // 88 bins
16 19 #define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins
17 20 //
18 21 #define NB_BINS_PER_ASM_F1 104
19 22 #define NB_BINS_PER_PKT_ASM_F1 52
20 23 #define TOTAL_SIZE_ASM_F1 2600 // 25 * 104
21 24 #define ASM_F1_INDICE_START 6 // 104 bins
22 25 #define ASM_F1_INDICE_STOP 109 // 2 packets of 52 bins
23 26 //
24 27 #define NB_BINS_PER_ASM_F2 96
25 28 #define NB_BINS_PER_PKT_ASM_F2 48
26 29 #define TOTAL_SIZE_ASM_F2 2400 // 25 * 96
27 30 #define ASM_F2_INDICE_START 7 // 96 bins
28 31 #define ASM_F2_INDICE_STOP 102 // 2 packets of 48 bins
29 32 //
30 33 #define NB_BINS_COMPRESSED_SM_F0 11
31 34 #define NB_BINS_COMPRESSED_SM_F1 13
32 35 #define NB_BINS_COMPRESSED_SM_F2 12
33 36 //
34 37 #define NB_BINS_TO_AVERAGE_ASM_F0 8
35 38 #define NB_BINS_TO_AVERAGE_ASM_F1 8
36 39 #define NB_BINS_TO_AVERAGE_ASM_F2 8
37 40 //
38 41 #define TOTAL_SIZE_COMPRESSED_ASM_F0 275 // 11 * 25
39 42 #define TOTAL_SIZE_COMPRESSED_ASM_F1 325 // 13 * 25
40 43 #define TOTAL_SIZE_COMPRESSED_ASM_F2 300 // 12 * 25
41 44 #define NB_AVERAGE_NORMAL_f0 96*4
42 45 #define NB_SM_TO_RECEIVE_BEFORE_AVF0 8
43 46
44 47 typedef struct {
45 48 volatile unsigned char PE[2];
46 49 volatile unsigned char PB[2];
47 50 volatile unsigned char V0;
48 51 volatile unsigned char V1;
49 52 volatile unsigned char V2_ELLIP_DOP;
50 53 volatile unsigned char SZ;
51 54 volatile unsigned char VPHI;
52 55 } BP1_t;
53 56
54 57 #endif // FSW_PARAMS_PROCESSING_H
@@ -1,55 +1,54
1 1 #ifndef FSW_PROCESSING_H_INCLUDED
2 2 #define FSW_PROCESSING_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <math.h>
7 7 #include <stdlib.h> // abs() is in the stdlib
8 8 #include <stdio.h> // printf()
9 9 #include <math.h>
10 10
11 11 #include "fsw_params.h"
12 12 #include "fsw_spacewire.h"
13 #include "basic_parameters.h"
14 13
15 14 extern volatile int sm_f0[ ];
16 15 extern volatile int sm_f1[ ];
17 16 extern volatile int sm_f2[ ];
18 17
19 18 // parameters
20 19 extern struct param_local_str param_local;
21 20
22 21 // registers
23 22 extern time_management_regs_t *time_management_regs;
24 23 extern spectral_matrix_regs_t *spectral_matrix_regs;
25 24
26 25 extern rtems_name misc_name[5];
27 26 extern rtems_id Task_id[20]; /* array of task ids */
28 27
29 28 void init_sm_rings( void );
30 29 void reset_current_sm_ring_nodes( void );
31 30
32 31 // ISR
33 32 void reset_nb_sm_f0( void );
34 33 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
35 34 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
36 35
37 36 // RTEMS TASKS
38 37 rtems_task avf0_task(rtems_task_argument argument);
39 38 rtems_task smiq_task(rtems_task_argument argument); // added to test the spectral matrix simulator
40 39 rtems_task matr_task(rtems_task_argument argument);
41 40
42 41 void matrix_reset(volatile float *averaged_spec_mat);
43 42 void BP1_set_old(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1);
44 43 void BP2_set_old(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
45 44 //
46 45 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header);
47 46 void ASM_reorganize( float *averaged_spec_mat, float *averaged_spec_mat_reorganized );
48 47 void ASM_compress( float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat );
49 48 void ASM_convert(volatile float *input_matrix, char *output_matrix);
50 49 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
51 50 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id);
52 51 void fill_averaged_spectral_matrix( void );
53 52 void reset_spectral_matrix_regs();
54 53
55 54 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,95 +1,100
1 1 #ifndef GRLIB_REGS_H_INCLUDED
2 2 #define GRLIB_REGS_H_INCLUDED
3 3
4 4 #define NB_GPTIMER 3
5 5
6 6 struct apbuart_regs_str{
7 7 volatile unsigned int data;
8 8 volatile unsigned int status;
9 9 volatile unsigned int ctrl;
10 10 volatile unsigned int scaler;
11 11 volatile unsigned int fifoDebug;
12 12 };
13 13
14 struct ahbuart_regs_str{
15 volatile unsigned int unused;
16 volatile unsigned int status;
17 volatile unsigned int ctrl;
18 volatile unsigned int scaler;
14 struct grgpio_regs_str{
15 volatile int io_port_data_register;
16 int io_port_output_register;
17 int io_port_direction_register;
18 int interrupt_mak_register;
19 int interrupt_polarity_register;
20 int interrupt_edge_register;
21 int bypass_register;
22 int reserved;
23 // 0x20-0x3c interrupt map register(s)
19 24 };
20 25
21 26 typedef struct {
22 27 volatile unsigned int counter;
23 28 volatile unsigned int reload;
24 29 volatile unsigned int ctrl;
25 30 volatile unsigned int unused;
26 31 } timer_regs_t;
27 32
28 33 typedef struct {
29 34 volatile unsigned int scaler_value;
30 35 volatile unsigned int scaler_reload;
31 36 volatile unsigned int conf;
32 37 volatile unsigned int unused0;
33 38 timer_regs_t timer[NB_GPTIMER];
34 39 } gptimer_regs_t;
35 40
36 41 typedef struct {
37 42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
38 43 volatile int coarse_time_load;
39 44 volatile int coarse_time;
40 45 volatile int fine_time;
41 46 } time_management_regs_t;
42 47
43 48 typedef struct {
44 49 volatile int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
45 50 volatile int burst_enable; // 0x04 01 *** burst f2, f1, f0 enable f3, f2, f1, f0
46 51 volatile int addr_data_f0; // 0x08 10 ***
47 52 volatile int addr_data_f1; // 0x0c 11 ***
48 53 volatile int addr_data_f2; // 0x10 100 ***
49 54 volatile int addr_data_f3; // 0x14 101 ***
50 55 volatile int status; // 0x18 110 ***
51 56 volatile int delta_snapshot; // 0x1c 111 ***
52 57 volatile int delta_f2_f1; // 0x20 0000 ***
53 58 volatile int delta_f2_f0; // 0x24 0001 ***
54 59 volatile int nb_burst_available;// 0x28 0010 ***
55 60 volatile int nb_snapshot_param; // 0x2c 0011 ***
56 61 } waveform_picker_regs_t;
57 62
58 63 typedef struct{
59 64 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
60 65 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
61 66 int addr_data_f0; // 0x08
62 67 int addr_data_f1; // 0x0c
63 68 int addr_data_f2; // 0x10
64 69 int addr_data_f3; // 0x14
65 70 volatile int status; // 0x18
66 71 int delta_snapshot; // 0x1c
67 72 int delta_f0; // 0x20
68 73 int delta_f0_2; // 0x24
69 74 int delta_f1; // 0x28
70 75 int delta_f2; // 0x2c
71 76 int nb_data_by_buffer; // 0x30
72 77 int snapshot_param; // 0x34
73 78 int start_date; // 0x38
74 79 int nb_word_in_buffer; // 0x3c
75 80 } waveform_picker_regs_new_t;
76 81
77 82 typedef struct {
78 83 volatile int config;
79 84 volatile int status;
80 85 volatile int matrixF0_Address0;
81 86 volatile int matrixFO_Address1;
82 87 volatile int matrixF1_Address;
83 88 volatile int matrixF2_Address;
84 89 volatile int coarse_time_F0_0;
85 90 volatile int coarse_time_F0_1;
86 91 volatile int coarse_time_F1;
87 92 volatile int coarse_time_F2;
88 93 volatile int fine_time_FO_0;
89 94 volatile int fine_time_F0_1;
90 95 volatile int fine_time_F1;
91 96 volatile int fine_time_F2;
92 97 volatile int debug;
93 98 } spectral_matrix_regs_t;
94 99
95 100 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,58 +1,58
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 // MODE PARAMETERS
14 14 extern unsigned int maxCount;
15 15
16 16 //****
17 17 // ISR
18 18 rtems_isr commutation_isr1( rtems_vector_number vector );
19 19 rtems_isr commutation_isr2( rtems_vector_number vector );
20 20
21 21 //***********
22 22 // RTEMS TASK
23 23 rtems_task actn_task( rtems_task_argument unused );
24 24
25 25 //***********
26 26 // TC ACTIONS
27 27 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
28 28 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
29 29 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
30 30 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
31 31 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
32 32 int action_update_time(ccsdsTelecommandPacket_t *TC);
33 33
34 34 // mode transition
35 35 int transition_validation(unsigned char requestedMode);
36 36 int stop_current_mode( void );
37 37 int enter_mode(unsigned char mode);
38 38 int restart_science_tasks();
39 39 int suspend_science_tasks();
40 40 void launch_waveform_picker( unsigned char mode );
41 41 void launch_spectral_matrix( unsigned char mode );
42 42 void set_irq_on_new_ready_matrix(unsigned char value );
43 43 void set_run_matrix_spectral( unsigned char value );
44 44 void launch_spectral_matrix_simu( unsigned char mode );
45 45
46 46 // other functions
47 47 void updateLFRCurrentMode();
48 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC );
49 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC );
50 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
48 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
49 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
50 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
51 51
52 52 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
53 53 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
54 54
55 55 #endif // TC_HANDLER_H_INCLUDED
56 56
57 57
58 58
@@ -1,760 +1,766
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include <fsw_processing.h>
11 11
12 12 #include "fsw_processing_globals.c"
13 13
14 14 //************************
15 15 // spectral matrices rings
16 16 ring_node sm_ring_f0[NB_RING_NODES_ASM_F0];
17 17 ring_node sm_ring_f1[NB_RING_NODES_ASM_F1];
18 18 ring_node sm_ring_f2[NB_RING_NODES_ASM_F2];
19 19 ring_node *current_ring_node_sm_f0;
20 20 ring_node *ring_node_for_averaging_sm_f0;
21 21 ring_node *current_ring_node_sm_f1;
22 22 ring_node *current_ring_node_sm_f2;
23 23
24 24 BP1_t data_BP1[ NB_BINS_COMPRESSED_SM_F0 ];
25 25 float averaged_sm_f0 [ TIME_OFFSET + TOTAL_SIZE_SM ];
26 26 float averaged_sm_f0_reorganized[ TIME_OFFSET + TOTAL_SIZE_SM ];
27 char averaged_sm_f0_char [ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_SM * 2 ];
27 char averaged_sm_f0_char [ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_SM ];
28 28 float compressed_sm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_F0 ];
29 29
30 unsigned char LFR_BP1_F0[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F0 * 2 ];
31 unsigned char LFR_BP1_F1[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F1 ];
32 unsigned char LFR_BP1_F2[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F2 ];
33
30 34 unsigned int nb_sm_f0;
31 35
32 36 void init_sm_rings( void )
33 37 {
34 38 unsigned char i;
35 39
36 40 // F0 RING
37 41 sm_ring_f0[0].next = (ring_node*) &sm_ring_f0[1];
38 42 sm_ring_f0[0].previous = (ring_node*) &sm_ring_f0[NB_RING_NODES_ASM_F0-1];
39 43 sm_ring_f0[0].buffer_address =
40 44 (int) &sm_f0[ 0 ];
41 45
42 46 sm_ring_f0[NB_RING_NODES_ASM_F0-1].next = (ring_node*) &sm_ring_f0[0];
43 47 sm_ring_f0[NB_RING_NODES_ASM_F0-1].previous = (ring_node*) &sm_ring_f0[NB_RING_NODES_ASM_F0-2];
44 48 sm_ring_f0[NB_RING_NODES_ASM_F0-1].buffer_address =
45 49 (int) &sm_f0[ (NB_RING_NODES_ASM_F0-1) * TOTAL_SIZE_SM ];
46 50
47 51 for(i=1; i<NB_RING_NODES_ASM_F0-1; i++)
48 52 {
49 53 sm_ring_f0[i].next = (ring_node*) &sm_ring_f0[i+1];
50 54 sm_ring_f0[i].previous = (ring_node*) &sm_ring_f0[i-1];
51 55 sm_ring_f0[i].buffer_address =
52 56 (int) &sm_f0[ i * TOTAL_SIZE_SM ];
53 57 }
54 58
55 59 // F1 RING
56 60 sm_ring_f1[0].next = (ring_node*) &sm_ring_f1[1];
57 61 sm_ring_f1[0].previous = (ring_node*) &sm_ring_f1[NB_RING_NODES_ASM_F1-1];
58 62 sm_ring_f1[0].buffer_address =
59 63 (int) &sm_f1[ 0 ];
60 64
61 65 sm_ring_f1[NB_RING_NODES_ASM_F1-1].next = (ring_node*) &sm_ring_f1[0];
62 66 sm_ring_f1[NB_RING_NODES_ASM_F1-1].previous = (ring_node*) &sm_ring_f1[NB_RING_NODES_ASM_F1-2];
63 67 sm_ring_f1[NB_RING_NODES_ASM_F1-1].buffer_address =
64 68 (int) &sm_f1[ (NB_RING_NODES_ASM_F1-1) * TOTAL_SIZE_SM ];
65 69
66 70 for(i=1; i<NB_RING_NODES_ASM_F1-1; i++)
67 71 {
68 72 sm_ring_f1[i].next = (ring_node*) &sm_ring_f1[i+1];
69 73 sm_ring_f1[i].previous = (ring_node*) &sm_ring_f1[i-1];
70 74 sm_ring_f1[i].buffer_address =
71 75 (int) &sm_f1[ i * TOTAL_SIZE_SM ];
72 76 }
73 77
74 78 // F2 RING
75 79 sm_ring_f2[0].next = (ring_node*) &sm_ring_f2[1];
76 80 sm_ring_f2[0].previous = (ring_node*) &sm_ring_f2[NB_RING_NODES_ASM_F2-1];
77 81 sm_ring_f2[0].buffer_address =
78 82 (int) &sm_f2[ 0 ];
79 83
80 84 sm_ring_f2[NB_RING_NODES_ASM_F2-1].next = (ring_node*) &sm_ring_f2[0];
81 85 sm_ring_f2[NB_RING_NODES_ASM_F2-1].previous = (ring_node*) &sm_ring_f2[NB_RING_NODES_ASM_F2-2];
82 86 sm_ring_f2[NB_RING_NODES_ASM_F2-1].buffer_address =
83 87 (int) &sm_f2[ (NB_RING_NODES_ASM_F2-1) * TOTAL_SIZE_SM ];
84 88
85 89 for(i=1; i<NB_RING_NODES_ASM_F2-1; i++)
86 90 {
87 91 sm_ring_f2[i].next = (ring_node*) &sm_ring_f2[i+1];
88 92 sm_ring_f2[i].previous = (ring_node*) &sm_ring_f2[i-1];
89 93 sm_ring_f2[i].buffer_address =
90 94 (int) &sm_f2[ i * TOTAL_SIZE_SM ];
91 95 }
92 96
93 97 DEBUG_PRINTF1("asm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
94 98 DEBUG_PRINTF1("asm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
95 99 DEBUG_PRINTF1("asm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
96 100
97 101 spectral_matrix_regs->matrixF0_Address0 = sm_ring_f0[0].buffer_address;
98 102 DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->matrixF0_Address0)
99 103 }
100 104
101 105 void reset_current_sm_ring_nodes( void )
102 106 {
103 107 current_ring_node_sm_f0 = sm_ring_f0;
104 108 current_ring_node_sm_f1 = sm_ring_f1;
105 109 current_ring_node_sm_f2 = sm_ring_f2;
106 110
107 111 ring_node_for_averaging_sm_f0 = sm_ring_f0;
108 112 }
109 113
110 114 //***********************************************************
111 115 // Interrupt Service Routine for spectral matrices processing
112 116 void reset_nb_sm_f0( void )
113 117 {
114 118 nb_sm_f0 = 0;
115 119 }
116 120
117 121 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
118 122 {
119 123 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
120 124
121 125 if ( (spectral_matrix_regs->status & 0x1) == 0x01)
122 126 {
123 127 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
124 128 spectral_matrix_regs->matrixF0_Address0 = current_ring_node_sm_f0->buffer_address;
125 129 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffe; // 1110
126 130 nb_sm_f0 = nb_sm_f0 + 1;
127 131 }
128 132 else if ( (spectral_matrix_regs->status & 0x2) == 0x02)
129 133 {
130 134 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
131 135 spectral_matrix_regs->matrixFO_Address1 = current_ring_node_sm_f0->buffer_address;
132 136 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffd; // 1101
133 137 nb_sm_f0 = nb_sm_f0 + 1;
134 138 }
135 139
136 140 if ( (spectral_matrix_regs->status & 0x30) != 0x00)
137 141 {
138 142 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
139 143 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xffffffcf; // 1100 1111
140 144 }
141 145
142 146 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffff3; // 0011
143 147
144 148 if (nb_sm_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) )
145 149 {
146 150 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
147 151 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
148 152 {
149 153 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
150 154 }
151 155 nb_sm_f0 = 0;
152 156 }
153 157 else
154 158 {
155 159 nb_sm_f0 = nb_sm_f0 + 1;
156 160 }
157 161 }
158 162
159 163 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
160 164 {
161 165 if (nb_sm_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) )
162 166 {
163 167 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
164 168 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
165 169 {
166 170 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
167 171 }
168 172 nb_sm_f0 = 0;
169 173 }
170 174 else
171 175 {
172 176 nb_sm_f0 = nb_sm_f0 + 1;
173 177 }
174 178 }
175 179
176 180 //************
177 181 // RTEMS TASKS
178 182
179 183 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
180 184 {
181 185 rtems_event_set event_out;
182 186
183 187 BOOT_PRINTF("in SMIQ *** \n")
184 188
185 189 while(1){
186 190 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
187 191 }
188 192 }
189 193
190 194 rtems_task avf0_task(rtems_task_argument argument)
191 195 {
192 196 int i;
193 197 static int nb_average;
194 198 rtems_event_set event_out;
195 199 rtems_status_code status;
196 200 ring_node *ring_node_tab[8];
197 201
198 202 nb_average = 0;
199 203
200 204 BOOT_PRINTF("in AVFO *** \n")
201 205
202 206 while(1){
203 207 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
204 208 ring_node_tab[NB_SM_TO_RECEIVE_BEFORE_AVF0-1] = ring_node_for_averaging_sm_f0;
205 209 for (i=2; i<NB_SM_TO_RECEIVE_BEFORE_AVF0+1; i++)
206 210 {
207 211 ring_node_for_averaging_sm_f0 = ring_node_for_averaging_sm_f0->previous;
208 212 ring_node_tab[NB_SM_TO_RECEIVE_BEFORE_AVF0-i] = ring_node_for_averaging_sm_f0;
209 213 }
210 214
211 215 averaged_sm_f0[0] = ( (int *) (ring_node_tab[7]->buffer_address) ) [0];
212 216 averaged_sm_f0[1] = ( (int *) (ring_node_tab[7]->buffer_address) ) [1];
213 217 for(i=0; i<TOTAL_SIZE_SM; i++)
214 218 {
215 219 averaged_sm_f0[i] = ( (int *) (ring_node_tab[0]->buffer_address) ) [i + TIME_OFFSET]
216 220 + ( (int *) (ring_node_tab[1]->buffer_address) ) [i + TIME_OFFSET]
217 221 + ( (int *) (ring_node_tab[2]->buffer_address) ) [i + TIME_OFFSET]
218 222 + ( (int *) (ring_node_tab[3]->buffer_address) ) [i + TIME_OFFSET]
219 223 + ( (int *) (ring_node_tab[4]->buffer_address) ) [i + TIME_OFFSET]
220 224 + ( (int *) (ring_node_tab[5]->buffer_address) ) [i + TIME_OFFSET]
221 225 + ( (int *) (ring_node_tab[6]->buffer_address) ) [i + TIME_OFFSET]
222 226 + ( (int *) (ring_node_tab[7]->buffer_address) ) [i + TIME_OFFSET];
223 227 }
224 228
225 229 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
226 230 if (nb_average == NB_AVERAGE_NORMAL_f0) {
227 231 nb_average = 0;
228 232 status = rtems_event_send( Task_id[TASKID_MATR], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
229 233 if (status != RTEMS_SUCCESSFUL) {
230 234 printf("in AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
231 235 }
232 236 }
233 237 }
234 238 }
235 239
236 240 rtems_task matr_task(rtems_task_argument argument)
237 241 {
238 242 spw_ioctl_pkt_send spw_ioctl_send_ASM;
239 243 rtems_event_set event_out;
240 244 rtems_status_code status;
241 245 rtems_id queue_id;
242 246 Header_TM_LFR_SCIENCE_ASM_t headerASM;
243 247
244 248 init_header_asm( &headerASM );
245 249
246 250 status = get_message_queue_id_send( &queue_id );
247 251 if (status != RTEMS_SUCCESSFUL)
248 252 {
249 253 PRINTF1("in MATR *** ERR get_message_queue_id_send %d\n", status)
250 254 }
251 255
252 256 BOOT_PRINTF("in MATR *** \n")
253 257
254 258 fill_averaged_spectral_matrix( );
255 259
256 260 while(1){
257 261 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
258 262 // 1) compress the matrix for Basic Parameters calculation
259 263 ASM_compress( averaged_sm_f0, 0, compressed_sm_f0 );
260 264 // 2)
261 //BP1_set(compressed_sm_f0, NB_BINS_COMPRESSED_SM_F0, LFR_BP1_F0);
265 // BP1_set( (float *) &compressed_sm_f0[TIME_OFFSET], NB_BINS_COMPRESSED_SM_F0, (unsigned char *) &LFR_BP1_F0[TIME_OFFSET_IN_BYTES] );
262 266 // 3) convert the float array in a char array
263 267 ASM_reorganize( averaged_sm_f0, averaged_sm_f0_reorganized );
264 268 ASM_convert( averaged_sm_f0_reorganized, averaged_sm_f0_char);
265 269 // 4) send the spectral matrix packets
266 270 ASM_send( &headerASM, averaged_sm_f0_char, SID_NORM_ASM_F0, &spw_ioctl_send_ASM, queue_id);
267 271 }
268 272 }
269 273
270 274 //*****************************
271 275 // Spectral matrices processing
272 276
273 277 void matrix_reset(volatile float *averaged_spec_mat)
274 278 {
275 279 int i;
276 280 for(i=0; i<TOTAL_SIZE_SM; i++){
277 281 averaged_spec_mat[i] = 0;
278 282 }
279 283 }
280 284
281 285 void ASM_reorganize( float *averaged_spec_mat, float *averaged_spec_mat_reorganized )
282 286 {
283 287 int frequencyBin;
284 288 int asmComponent;
285 289
286 290 // copy the time information
287 291 averaged_spec_mat_reorganized[ 0 ] = averaged_spec_mat[ 0 ];
288 292 averaged_spec_mat_reorganized[ 1 ] = averaged_spec_mat[ 1 ];
289 293
290 294 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
291 295 {
292 296 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
293 297 {
294 298 averaged_spec_mat_reorganized[ frequencyBin * NB_VALUES_PER_SM + asmComponent + TIME_OFFSET ] =
295 299 averaged_spec_mat[ asmComponent * NB_BINS_PER_SM + frequencyBin + TIME_OFFSET];
296 300 }
297 301 }
298 302 }
299 303
300 304 void ASM_compress( float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat )
301 305 {
302 306 int frequencyBin;
303 307 int asmComponent;
304 308 int offsetASM;
305 309 int offsetCompressed;
306 310 int k;
307 311
308 312 switch (fChannel){
309 313 case 0:
310 314 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
311 315 {
312 316 for( frequencyBin = 0; frequencyBin < NB_BINS_COMPRESSED_SM_F0; frequencyBin++ )
313 317 {
314 offsetASM = asmComponent * NB_BINS_PER_SM
318 offsetCompressed = TIME_OFFSET
319 + frequencyBin * NB_VALUES_PER_SM
320 + asmComponent;
321 offsetASM = TIME_OFFSET
322 + asmComponent * NB_BINS_PER_SM
315 323 + ASM_F0_INDICE_START
316 324 + frequencyBin * NB_BINS_TO_AVERAGE_ASM_F0;
317 offsetCompressed = frequencyBin * NB_VALUES_PER_SM
318 + asmComponent;
319 325 compressed_spec_mat[ offsetCompressed ] = 0;
320 326 for ( k = 0; k < NB_BINS_TO_AVERAGE_ASM_F0; k++ )
321 327 {
322 328 compressed_spec_mat[offsetCompressed ] =
323 329 compressed_spec_mat[ offsetCompressed ]
324 330 + averaged_spec_mat[ offsetASM + k ];
325 331 }
326 332 }
327 333 }
328 334 break;
329 335
330 336 case 1:
331 337 // case fChannel = f1 to be completed later
332 338 break;
333 339
334 340 case 2:
335 341 // case fChannel = f1 to be completed later
336 342 break;
337 343
338 344 default:
339 345 break;
340 346 }
341 347 }
342 348
343 349 void ASM_convert( volatile float *input_matrix, char *output_matrix)
344 350 {
345 351 unsigned int i;
346 352 unsigned int frequencyBin;
347 353 unsigned int asmComponent;
348 354 char * pt_char_input;
349 355 char * pt_char_output;
350 356
351 357 pt_char_input = (char*) &input_matrix;
352 358 pt_char_output = (char*) &output_matrix;
353 359
354 360 // copy the time information
355 361 for (i=0; i<TIME_OFFSET_IN_BYTES; i++)
356 362 {
357 363 pt_char_output[ i ] = pt_char_output[ i ];
358 364 }
359 365
360 366 // convert all other data
361 367 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
362 368 {
363 369 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
364 370 {
365 371 pt_char_input = (char*) &input_matrix [ (frequencyBin*NB_VALUES_PER_SM) + asmComponent + TIME_OFFSET ];
366 372 pt_char_output = (char*) &output_matrix[ 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) + TIME_OFFSET_IN_BYTES ];
367 373 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
368 374 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
369 375 }
370 376 }
371 377 }
372 378
373 379 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
374 380 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id)
375 381 {
376 382 unsigned int i;
377 383 unsigned int length = 0;
378 384 rtems_status_code status;
379 385
380 386 for (i=0; i<2; i++)
381 387 {
382 388 // (1) BUILD THE DATA
383 389 switch(sid)
384 390 {
385 391 case SID_NORM_ASM_F0:
386 392 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2;
387 393 spw_ioctl_send->data = &spectral_matrix[
388 394 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2
389 395 + TIME_OFFSET_IN_BYTES
390 396 ];
391 397 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0;
392 398 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB
393 399 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB
394 400 break;
395 401 case SID_NORM_ASM_F1:
396 402 break;
397 403 case SID_NORM_ASM_F2:
398 404 break;
399 405 default:
400 406 PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid)
401 407 break;
402 408 }
403 409 spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES;
404 410 spw_ioctl_send->hdr = (char *) header;
405 411 spw_ioctl_send->options = 0;
406 412
407 413 // (2) BUILD THE HEADER
408 414 header->packetLength[0] = (unsigned char) (length>>8);
409 415 header->packetLength[1] = (unsigned char) (length);
410 416 header->sid = (unsigned char) sid; // SID
411 417 header->pa_lfr_pkt_cnt_asm = 2;
412 418 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
413 419
414 420 // (3) SET PACKET TIME
415 421 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
416 422 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
417 423 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
418 424 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
419 425 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
420 426 header->time[5] = (unsigned char) (time_management_regs->fine_time);
421 427 //
422 428 header->acquisitionTime[0] = (unsigned char) (time_management_regs->coarse_time>>24);
423 429 header->acquisitionTime[1] = (unsigned char) (time_management_regs->coarse_time>>16);
424 430 header->acquisitionTime[2] = (unsigned char) (time_management_regs->coarse_time>>8);
425 431 header->acquisitionTime[3] = (unsigned char) (time_management_regs->coarse_time);
426 432 header->acquisitionTime[4] = (unsigned char) (time_management_regs->fine_time>>8);
427 433 header->acquisitionTime[5] = (unsigned char) (time_management_regs->fine_time);
428 434
429 435 // (4) SEND PACKET
430 436 status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
431 437 if (status != RTEMS_SUCCESSFUL) {
432 438 printf("in ASM_send *** ERR %d\n", (int) status);
433 439 }
434 440 }
435 441 }
436 442
437 443 void BP1_set_old(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
438 444 int i;
439 445 int j;
440 446 unsigned char tmp_u_char;
441 447 unsigned char * pt_char = NULL;
442 448 float PSDB, PSDE;
443 449 float NVEC_V0;
444 450 float NVEC_V1;
445 451 float NVEC_V2;
446 452 //float significand;
447 453 //int exponent;
448 454 float aux;
449 455 float tr_SB_SB;
450 456 float tmp;
451 457 float sx_re;
452 458 float sx_im;
453 459 float nebx_re = 0;
454 460 float nebx_im = 0;
455 461 float ny = 0;
456 462 float nz = 0;
457 463 float bx_bx_star = 0;
458 464 for(i=0; i<nb_bins_compressed_spec_mat; i++){
459 465 //==============================================
460 466 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
461 467 PSDB = compressed_spec_mat[i*30] // S11
462 468 + compressed_spec_mat[(i*30) + 10] // S22
463 469 + compressed_spec_mat[(i*30) + 18]; // S33
464 470 //significand = frexp(PSDB, &exponent);
465 471 pt_char = (unsigned char*) &PSDB;
466 472 LFR_BP1[(i*9) + 2] = pt_char[0]; // bits 31 downto 24 of the float
467 473 LFR_BP1[(i*9) + 3] = pt_char[1]; // bits 23 downto 16 of the float
468 474 //==============================================
469 475 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
470 476 PSDE = compressed_spec_mat[(i*30) + 24] * K44_pe // S44
471 477 + compressed_spec_mat[(i*30) + 28] * K55_pe // S55
472 478 + compressed_spec_mat[(i*30) + 26] * K45_pe_re // S45
473 479 - compressed_spec_mat[(i*30) + 27] * K45_pe_im; // S45
474 480 pt_char = (unsigned char*) &PSDE;
475 481 LFR_BP1[(i*9) + 0] = pt_char[0]; // bits 31 downto 24 of the float
476 482 LFR_BP1[(i*9) + 1] = pt_char[1]; // bits 23 downto 16 of the float
477 483 //==============================================================================
478 484 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
479 485 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
480 486 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
481 487 tmp = sqrt(
482 488 compressed_spec_mat[(i*30) + 3]*compressed_spec_mat[(i*30) + 3] //Im S12
483 489 +compressed_spec_mat[(i*30) + 5]*compressed_spec_mat[(i*30) + 5] //Im S13
484 490 +compressed_spec_mat[(i*30) + 13]*compressed_spec_mat[(i*30) + 13] //Im S23
485 491 );
486 492 NVEC_V0 = compressed_spec_mat[(i*30) + 13] / tmp; // Im S23
487 493 NVEC_V1 = -compressed_spec_mat[(i*30) + 5] / tmp; // Im S13
488 494 NVEC_V2 = compressed_spec_mat[(i*30) + 3] / tmp; // Im S12
489 495 LFR_BP1[(i*9) + 4] = (char) (NVEC_V0*127);
490 496 LFR_BP1[(i*9) + 5] = (char) (NVEC_V1*127);
491 497 pt_char = (unsigned char*) &NVEC_V2;
492 498 LFR_BP1[(i*9) + 6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
493 499 //=======================================================
494 500 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
495 501 aux = 2*tmp / PSDB; // compute the ellipticity
496 502 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
497 503 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
498 504 //==============================================================
499 505 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
500 506 for(j = 0; j<NB_VALUES_PER_SM;j++){
501 507 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
502 508 + compressed_spec_mat[(i*30) + 10] * compressed_spec_mat[(i*30) + 10]
503 509 + compressed_spec_mat[(i*30) + 18] * compressed_spec_mat[(i*30) + 18]
504 510 + 2 * compressed_spec_mat[(i*30) + 2] * compressed_spec_mat[(i*30) + 2]
505 511 + 2 * compressed_spec_mat[(i*30) + 3] * compressed_spec_mat[(i*30) + 3]
506 512 + 2 * compressed_spec_mat[(i*30) + 4] * compressed_spec_mat[(i*30) + 4]
507 513 + 2 * compressed_spec_mat[(i*30) + 5] * compressed_spec_mat[(i*30) + 5]
508 514 + 2 * compressed_spec_mat[(i*30) + 12] * compressed_spec_mat[(i*30) + 12]
509 515 + 2 * compressed_spec_mat[(i*30) + 13] * compressed_spec_mat[(i*30) + 13];
510 516 }
511 517 aux = PSDB*PSDB;
512 518 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
513 519 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
514 520 LFR_BP1[(i*9) + 6] = LFR_BP1[(i*9) + 6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
515 521 //=======================================================================================
516 522 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
517 523 sx_re = compressed_spec_mat[(i*30) + 20] * K34_sx_re
518 524 + compressed_spec_mat[(i*30) + 6] * K14_sx_re
519 525 + compressed_spec_mat[(i*30) + 8] * K15_sx_re
520 526 + compressed_spec_mat[(i*30) + 14] * K24_sx_re
521 527 + compressed_spec_mat[(i*30) + 16] * K25_sx_re
522 528 + compressed_spec_mat[(i*30) + 22] * K35_sx_re;
523 529 sx_im = compressed_spec_mat[(i*30) + 21] * K34_sx_im
524 530 + compressed_spec_mat[(i*30) + 7] * K14_sx_im
525 531 + compressed_spec_mat[(i*30) + 9] * K15_sx_im
526 532 + compressed_spec_mat[(i*30) + 15] * K24_sx_im
527 533 + compressed_spec_mat[(i*30) + 17] * K25_sx_im
528 534 + compressed_spec_mat[(i*30) + 23] * K35_sx_im;
529 535 LFR_BP1[(i*9) + 7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
530 536 if ( abs(sx_re) > abs(sx_im) ) {
531 537 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] | (0x80); // extract the sector of sx
532 538 }
533 539 else {
534 540 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] & (0x7f); // extract the sector of sx
535 541 }
536 542 //======================================================================
537 543 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
538 544 ny = sin(Alpha_M)*NVEC_V1 + cos(Alpha_M)*NVEC_V2;
539 545 nz = NVEC_V0;
540 546 bx_bx_star = cos(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+10] // re S22
541 547 + sin(Alpha_M) * sin(Alpha_M) * compressed_spec_mat[i*30+18] // re S33
542 548 - 2 * sin(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+12]; // re S23
543 549 nebx_re = ny * (compressed_spec_mat[(i*30) + 14] * K24_ny_re
544 550 +compressed_spec_mat[(i*30) + 16] * K25_ny_re
545 551 +compressed_spec_mat[(i*30) + 20] * K34_ny_re
546 552 +compressed_spec_mat[(i*30) + 22] * K35_ny_re)
547 553 + nz * (compressed_spec_mat[(i*30) + 14] * K24_nz_re
548 554 +compressed_spec_mat[(i*30) + 16] * K25_nz_re
549 555 +compressed_spec_mat[(i*30) + 20] * K34_nz_re
550 556 +compressed_spec_mat[(i*30) + 22] * K35_nz_re);
551 557 nebx_im = ny * (compressed_spec_mat[(i*30) + 15]*K24_ny_re
552 558 +compressed_spec_mat[(i*30) + 17] * K25_ny_re
553 559 +compressed_spec_mat[(i*30) + 21] * K34_ny_re
554 560 +compressed_spec_mat[(i*30) + 23] * K35_ny_re)
555 561 + nz * (compressed_spec_mat[(i*30) + 15] * K24_nz_im
556 562 +compressed_spec_mat[(i*30) + 17] * K25_nz_im
557 563 +compressed_spec_mat[(i*30) + 21] * K34_nz_im
558 564 +compressed_spec_mat[(i*30) + 23] * K35_nz_im);
559 565 tmp = nebx_re / bx_bx_star;
560 566 LFR_BP1[(i*9) + 8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
561 567 if ( abs(nebx_re) > abs(nebx_im) ) {
562 568 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] | (0x80); // extract the sector of nebx
563 569 }
564 570 else {
565 571 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] & (0x7f); // extract the sector of nebx
566 572 }
567 573 }
568 574
569 575 }
570 576
571 577 void BP2_set_old(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
572 578 // BP2 autocorrelation
573 579 int i;
574 580 int aux = 0;
575 581
576 582 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
577 583 // S12
578 584 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 10]);
579 585 compressed_spec_mat[(i*30) + 2] = compressed_spec_mat[(i*30) + 2] / aux;
580 586 compressed_spec_mat[(i*30) + 3] = compressed_spec_mat[(i*30) + 3] / aux;
581 587 // S13
582 588 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 18]);
583 589 compressed_spec_mat[(i*30) + 4] = compressed_spec_mat[(i*30) + 4] / aux;
584 590 compressed_spec_mat[(i*30) + 5] = compressed_spec_mat[(i*30) + 5] / aux;
585 591 // S23
586 592 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[(i*30) + 18]);
587 593 compressed_spec_mat[(i*30) + 12] = compressed_spec_mat[(i*30) + 12] / aux;
588 594 compressed_spec_mat[(i*30) + 13] = compressed_spec_mat[(i*30) + 13] / aux;
589 595 // S45
590 596 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[(i*30) + 28]);
591 597 compressed_spec_mat[(i*30) + 26] = compressed_spec_mat[(i*30) + 26] / aux;
592 598 compressed_spec_mat[(i*30) + 27] = compressed_spec_mat[(i*30) + 27] / aux;
593 599 // S14
594 600 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) +24]);
595 601 compressed_spec_mat[(i*30) + 6] = compressed_spec_mat[(i*30) + 6] / aux;
596 602 compressed_spec_mat[(i*30) + 7] = compressed_spec_mat[(i*30) + 7] / aux;
597 603 // S15
598 604 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 28]);
599 605 compressed_spec_mat[(i*30) + 8] = compressed_spec_mat[(i*30) + 8] / aux;
600 606 compressed_spec_mat[(i*30) + 9] = compressed_spec_mat[(i*30) + 9] / aux;
601 607 // S24
602 608 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 24]);
603 609 compressed_spec_mat[(i*30) + 14] = compressed_spec_mat[(i*30) + 14] / aux;
604 610 compressed_spec_mat[(i*30) + 15] = compressed_spec_mat[(i*30) + 15] / aux;
605 611 // S25
606 612 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 28]);
607 613 compressed_spec_mat[(i*30) + 16] = compressed_spec_mat[(i*30) + 16] / aux;
608 614 compressed_spec_mat[(i*30) + 17] = compressed_spec_mat[(i*30) + 17] / aux;
609 615 // S34
610 616 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 24]);
611 617 compressed_spec_mat[(i*30) + 20] = compressed_spec_mat[(i*30) + 20] / aux;
612 618 compressed_spec_mat[(i*30) + 21] = compressed_spec_mat[(i*30) + 21] / aux;
613 619 // S35
614 620 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 28]);
615 621 compressed_spec_mat[(i*30) + 22] = compressed_spec_mat[(i*30) + 22] / aux;
616 622 compressed_spec_mat[(i*30) + 23] = compressed_spec_mat[(i*30) + 23] / aux;
617 623 }
618 624 }
619 625
620 626 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header)
621 627 {
622 628 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
623 629 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
624 630 header->reserved = 0x00;
625 631 header->userApplication = CCSDS_USER_APP;
626 632 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
627 633 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
628 634 header->packetSequenceControl[0] = 0xc0;
629 635 header->packetSequenceControl[1] = 0x00;
630 636 header->packetLength[0] = 0x00;
631 637 header->packetLength[1] = 0x00;
632 638 // DATA FIELD HEADER
633 639 header->spare1_pusVersion_spare2 = 0x10;
634 640 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
635 641 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
636 642 header->destinationID = TM_DESTINATION_ID_GROUND;
637 643 // AUXILIARY DATA HEADER
638 644 header->sid = 0x00;
639 645 header->biaStatusInfo = 0x00;
640 646 header->pa_lfr_pkt_cnt_asm = 0x00;
641 647 header->pa_lfr_pkt_nr_asm = 0x00;
642 648 header->time[0] = 0x00;
643 649 header->time[0] = 0x00;
644 650 header->time[0] = 0x00;
645 651 header->time[0] = 0x00;
646 652 header->time[0] = 0x00;
647 653 header->time[0] = 0x00;
648 654 header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB
649 655 header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB
650 656 }
651 657
652 658 void fill_averaged_spectral_matrix(void)
653 659 {
654 660 /** This function fills spectral matrices related buffers with arbitrary data.
655 661 *
656 662 * This function is for testing purpose only.
657 663 *
658 664 */
659 665
660 666 float offset;
661 667 float coeff;
662 668
663 669 offset = 10.;
664 670 coeff = 100000.;
665 671 averaged_sm_f0[ 0 + 25 * 0 ] = 0. + offset;
666 672 averaged_sm_f0[ 0 + 25 * 1 ] = 1. + offset;
667 673 averaged_sm_f0[ 0 + 25 * 2 ] = 2. + offset;
668 674 averaged_sm_f0[ 0 + 25 * 3 ] = 3. + offset;
669 675 averaged_sm_f0[ 0 + 25 * 4 ] = 4. + offset;
670 676 averaged_sm_f0[ 0 + 25 * 5 ] = 5. + offset;
671 677 averaged_sm_f0[ 0 + 25 * 6 ] = 6. + offset;
672 678 averaged_sm_f0[ 0 + 25 * 7 ] = 7. + offset;
673 679 averaged_sm_f0[ 0 + 25 * 8 ] = 8. + offset;
674 680 averaged_sm_f0[ 0 + 25 * 9 ] = 9. + offset;
675 681 averaged_sm_f0[ 0 + 25 * 10 ] = 10. + offset;
676 682 averaged_sm_f0[ 0 + 25 * 11 ] = 11. + offset;
677 683 averaged_sm_f0[ 0 + 25 * 12 ] = 12. + offset;
678 684 averaged_sm_f0[ 0 + 25 * 13 ] = 13. + offset;
679 685 averaged_sm_f0[ 0 + 25 * 14 ] = 14. + offset;
680 686 averaged_sm_f0[ 9 + 25 * 0 ] = -(0. + offset)* coeff;
681 687 averaged_sm_f0[ 9 + 25 * 1 ] = -(1. + offset)* coeff;
682 688 averaged_sm_f0[ 9 + 25 * 2 ] = -(2. + offset)* coeff;
683 689 averaged_sm_f0[ 9 + 25 * 3 ] = -(3. + offset)* coeff;
684 690 averaged_sm_f0[ 9 + 25 * 4 ] = -(4. + offset)* coeff;
685 691 averaged_sm_f0[ 9 + 25 * 5 ] = -(5. + offset)* coeff;
686 692 averaged_sm_f0[ 9 + 25 * 6 ] = -(6. + offset)* coeff;
687 693 averaged_sm_f0[ 9 + 25 * 7 ] = -(7. + offset)* coeff;
688 694 averaged_sm_f0[ 9 + 25 * 8 ] = -(8. + offset)* coeff;
689 695 averaged_sm_f0[ 9 + 25 * 9 ] = -(9. + offset)* coeff;
690 696 averaged_sm_f0[ 9 + 25 * 10 ] = -(10. + offset)* coeff;
691 697 averaged_sm_f0[ 9 + 25 * 11 ] = -(11. + offset)* coeff;
692 698 averaged_sm_f0[ 9 + 25 * 12 ] = -(12. + offset)* coeff;
693 699 averaged_sm_f0[ 9 + 25 * 13 ] = -(13. + offset)* coeff;
694 700 averaged_sm_f0[ 9 + 25 * 14 ] = -(14. + offset)* coeff;
695 701
696 702 offset = 10000000;
697 703 averaged_sm_f0[ 16 + 25 * 0 ] = (0. + offset)* coeff;
698 704 averaged_sm_f0[ 16 + 25 * 1 ] = (1. + offset)* coeff;
699 705 averaged_sm_f0[ 16 + 25 * 2 ] = (2. + offset)* coeff;
700 706 averaged_sm_f0[ 16 + 25 * 3 ] = (3. + offset)* coeff;
701 707 averaged_sm_f0[ 16 + 25 * 4 ] = (4. + offset)* coeff;
702 708 averaged_sm_f0[ 16 + 25 * 5 ] = (5. + offset)* coeff;
703 709 averaged_sm_f0[ 16 + 25 * 6 ] = (6. + offset)* coeff;
704 710 averaged_sm_f0[ 16 + 25 * 7 ] = (7. + offset)* coeff;
705 711 averaged_sm_f0[ 16 + 25 * 8 ] = (8. + offset)* coeff;
706 712 averaged_sm_f0[ 16 + 25 * 9 ] = (9. + offset)* coeff;
707 713 averaged_sm_f0[ 16 + 25 * 10 ] = (10. + offset)* coeff;
708 714 averaged_sm_f0[ 16 + 25 * 11 ] = (11. + offset)* coeff;
709 715 averaged_sm_f0[ 16 + 25 * 12 ] = (12. + offset)* coeff;
710 716 averaged_sm_f0[ 16 + 25 * 13 ] = (13. + offset)* coeff;
711 717 averaged_sm_f0[ 16 + 25 * 14 ] = (14. + offset)* coeff;
712 718
713 719 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 0 ] = averaged_sm_f0[ 0 ];
714 720 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 1 ] = averaged_sm_f0[ 1 ];
715 721 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 2 ] = averaged_sm_f0[ 2 ];
716 722 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 3 ] = averaged_sm_f0[ 3 ];
717 723 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 4 ] = averaged_sm_f0[ 4 ];
718 724 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 5 ] = averaged_sm_f0[ 5 ];
719 725 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 6 ] = averaged_sm_f0[ 6 ];
720 726 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 7 ] = averaged_sm_f0[ 7 ];
721 727 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 8 ] = averaged_sm_f0[ 8 ];
722 728 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 9 ] = averaged_sm_f0[ 9 ];
723 729 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 10 ] = averaged_sm_f0[ 10 ];
724 730 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 11 ] = averaged_sm_f0[ 11 ];
725 731 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 12 ] = averaged_sm_f0[ 12 ];
726 732 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 13 ] = averaged_sm_f0[ 13 ];
727 733 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 14 ] = averaged_sm_f0[ 14 ];
728 734 averaged_sm_f0[ (TOTAL_SIZE_SM/2) + 15 ] = averaged_sm_f0[ 15 ];
729 735 }
730 736
731 737 void reset_spectral_matrix_regs()
732 738 {
733 739 /** This function resets the spectral matrices module registers.
734 740 *
735 741 * The registers affected by this function are located at the following offset addresses:
736 742 *
737 743 * - 0x00 config
738 744 * - 0x04 status
739 745 * - 0x08 matrixF0_Address0
740 746 * - 0x10 matrixFO_Address1
741 747 * - 0x14 matrixF1_Address
742 748 * - 0x18 matrixF2_Address
743 749 *
744 750 */
745 751
746 752 spectral_matrix_regs->config = 0x00;
747 753 spectral_matrix_regs->status = 0x00;
748 754
749 755 spectral_matrix_regs->matrixF0_Address0 = current_ring_node_sm_f0->buffer_address;
750 756 spectral_matrix_regs->matrixFO_Address1 = current_ring_node_sm_f0->buffer_address;
751 757 spectral_matrix_regs->matrixF1_Address = current_ring_node_sm_f1->buffer_address;
752 758 spectral_matrix_regs->matrixF2_Address = current_ring_node_sm_f2->buffer_address;
753 759 }
754 760
755 761 //******************
756 762 // general functions
757 763
758 764
759 765
760 766
@@ -1,601 +1,611
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 rtems_name semq_name;
17 17 rtems_id semq_id;
18 18
19 19 //***********
20 20 // RTEMS TASK
21 21 rtems_task spiq_task(rtems_task_argument unused)
22 22 {
23 23 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
24 24 *
25 25 * @param unused is the starting argument of the RTEMS task
26 26 *
27 27 */
28 28
29 29 rtems_event_set event_out;
30 30 rtems_status_code status;
31 31 int linkStatus;
32 32
33 33 BOOT_PRINTF("in SPIQ *** \n")
34 34
35 35 while(true){
36 36 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
37 37 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
38 38
39 39 // [0] SUSPEND RECV AND SEND TASKS
40 40 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
41 41 if ( status != RTEMS_SUCCESSFUL ) {
42 42 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
43 43 }
44 44 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
45 45 if ( status != RTEMS_SUCCESSFUL ) {
46 46 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
47 47 }
48 48
49 49 // [1] CHECK THE LINK
50 50 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
51 51 if ( linkStatus != 5) {
52 52 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
53 53 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
54 54 }
55 55
56 56 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
57 57 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
58 58 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
59 59 {
60 60 spacewire_compute_stats_offsets();
61 61 status = spacewire_reset_link( );
62 62 }
63 63 else // [2.b] in run state, start the link
64 64 {
65 65 status = spacewire_stop_start_link( fdSPW ); // start the link
66 66 if ( status != RTEMS_SUCCESSFUL)
67 67 {
68 68 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
69 69 }
70 70 }
71 71
72 72 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
73 73 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
74 74 {
75 75 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
76 76 if ( status != RTEMS_SUCCESSFUL ) {
77 77 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
78 78 }
79 79 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
80 80 if ( status != RTEMS_SUCCESSFUL ) {
81 81 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
82 82 }
83 83 }
84 84 else // [3.b] the link is not in run state, go in STANDBY mode
85 85 {
86 86 status = stop_current_mode();
87 87 if ( status != RTEMS_SUCCESSFUL ) {
88 88 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
89 89 }
90 90 status = enter_mode( LFR_MODE_STANDBY );
91 91 if ( status != RTEMS_SUCCESSFUL ) {
92 92 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
93 93 }
94 94 // wake the WTDG task up to wait for the link recovery
95 95 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
96 96 status = rtems_task_suspend( RTEMS_SELF );
97 97 }
98 98 }
99 99 }
100 100
101 101 rtems_task recv_task( rtems_task_argument unused )
102 102 {
103 103 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
104 104 *
105 105 * @param unused is the starting argument of the RTEMS task
106 106 *
107 107 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
108 108 * 1. It reads the incoming data.
109 109 * 2. Launches the acceptance procedure.
110 110 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
111 111 *
112 112 */
113 113
114 114 int len;
115 115 ccsdsTelecommandPacket_t currentTC;
116 116 unsigned char computed_CRC[ 2 ];
117 117 unsigned char currentTC_LEN_RCV[ 2 ];
118 118 unsigned char destinationID;
119 119 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
120 120 unsigned int parserCode;
121 unsigned char time[6];
122 121 rtems_status_code status;
123 122 rtems_id queue_recv_id;
124 123 rtems_id queue_send_id;
125 124
126 125 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
127 126
128 127 status = get_message_queue_id_recv( &queue_recv_id );
129 128 if (status != RTEMS_SUCCESSFUL)
130 129 {
131 130 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
132 131 }
133 132
134 133 status = get_message_queue_id_send( &queue_send_id );
135 134 if (status != RTEMS_SUCCESSFUL)
136 135 {
137 136 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
138 137 }
139 138
140 139 BOOT_PRINTF("in RECV *** \n")
141 140
142 141 while(1)
143 142 {
144 143 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
145 144 if (len == -1){ // error during the read call
146 145 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
147 146 }
148 147 else {
149 148 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
150 149 PRINTF("in RECV *** packet lenght too short\n")
151 150 }
152 151 else {
153 152 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
154 153 currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8);
155 154 currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt );
156 155 // CHECK THE TC
157 156 parserCode = tc_parser( &currentTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ;
158 157 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
159 158 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
160 159 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
161 160 || (parserCode == WRONG_SRC_ID) )
162 161 { // send TM_LFR_TC_EXE_CORRUPTED
162 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
163 163 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
164 164 &&
165 165 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
166 166 )
167 167 {
168 168 if ( parserCode == WRONG_SRC_ID )
169 169 {
170 170 destinationID = SID_TC_GROUND;
171 171 }
172 172 else
173 173 {
174 174 destinationID = currentTC.sourceID;
175 175 }
176 getTime( time );
177 close_action( &currentTC, LFR_DEFAULT, queue_send_id );
178 176 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
179 177 computed_CRC, currentTC_LEN_RCV,
180 178 destinationID );
181 179 }
182 180 }
183 181 else
184 182 { // send valid TC to the action launcher
185 183 status = rtems_message_queue_send( queue_recv_id, &currentTC,
186 184 currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3);
187 185 }
188 186 }
189 187 }
190 188 }
191 189 }
192 190
193 191 rtems_task send_task( rtems_task_argument argument)
194 192 {
195 193 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
196 194 *
197 195 * @param unused is the starting argument of the RTEMS task
198 196 *
199 197 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
200 198 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
201 199 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
202 200 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
203 201 * data it contains.
204 202 *
205 203 */
206 204
207 205 rtems_status_code status; // RTEMS status code
208 206 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
209 207 spw_ioctl_pkt_send *spw_ioctl_send;
210 208 size_t size; // size of the incoming TC packet
211 209 u_int32_t count;
212 210 rtems_id queue_id;
213 211
214 212 status = get_message_queue_id_send( &queue_id );
215 213 if (status != RTEMS_SUCCESSFUL)
216 214 {
217 215 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
218 216 }
219 217
220 218 BOOT_PRINTF("in SEND *** \n")
221 219
222 220 while(1)
223 221 {
224 222 status = rtems_message_queue_receive( queue_id, incomingData, &size,
225 223 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
226 224
227 225 if (status!=RTEMS_SUCCESSFUL)
228 226 {
229 227 PRINTF1("in SEND *** (1) ERR = %d\n", status)
230 228 }
231 229 else
232 230 {
233 231 if ( incomingData[0] == CCSDS_DESTINATION_ID) // the incoming message is a ccsds packet
234 232 {
235 233 status = write( fdSPW, incomingData, size );
236 234 if (status == -1){
237 235 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
238 236 }
239 237 }
240 238 else // the incoming message is a spw_ioctl_pkt_send structure
241 239 {
242 240 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
243 241 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
244 242 if (status == -1){
245 243 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
246 244 }
247 245 }
248 246 }
249 247
250 248 status = rtems_message_queue_get_number_pending( queue_id, &count );
251 249 if (status != RTEMS_SUCCESSFUL)
252 250 {
253 251 PRINTF1("in SEND *** (3) ERR = %d\n", status)
254 252 }
255 253 else
256 254 {
257 255 if (count > maxCount)
258 256 {
259 257 maxCount = count;
260 258 }
261 259 }
262 260 }
263 261 }
264 262
265 263 rtems_task wtdg_task( rtems_task_argument argument )
266 264 {
267 265 rtems_event_set event_out;
268 266 rtems_status_code status;
269 267 int linkStatus;
270 268
271 269 BOOT_PRINTF("in WTDG ***\n")
272 270
273 271 while(1)
274 272 {
275 273 // wait for an RTEMS_EVENT
276 274 rtems_event_receive( RTEMS_EVENT_0,
277 275 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
278 276 PRINTF("in WTDG *** wait for the link\n")
279 277 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
280 278 while( linkStatus != 5) // wait for the link
281 279 {
282 280 rtems_task_wake_after( 10 );
283 281 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
284 282 }
285 283
286 284 status = spacewire_stop_start_link( fdSPW );
287 285
288 286 if (status != RTEMS_SUCCESSFUL)
289 287 {
290 288 PRINTF1("in WTDG *** ERR link not started %d\n", status)
291 289 }
292 290 else
293 291 {
294 292 PRINTF("in WTDG *** OK link started\n")
295 293 }
296 294
297 295 // restart the SPIQ task
298 296 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
299 297 if ( status != RTEMS_SUCCESSFUL ) {
300 298 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
301 299 }
302 300
303 301 // restart RECV and SEND
304 302 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
305 303 if ( status != RTEMS_SUCCESSFUL ) {
306 304 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
307 305 }
308 306 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
309 307 if ( status != RTEMS_SUCCESSFUL ) {
310 308 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
311 309 }
312 310 }
313 311 }
314 312
315 313 //****************
316 314 // OTHER FUNCTIONS
317 315 int spacewire_open_link( void )
318 316 {
319 317 /** This function opens the SpaceWire link.
320 318 *
321 319 * @return a valid file descriptor in case of success, -1 in case of a failure
322 320 *
323 321 */
324 322 rtems_status_code status;
325 323
326 324 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
327 325 if ( fdSPW < 0 ) {
328 326 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
329 327 }
330 328 else
331 329 {
332 330 status = RTEMS_SUCCESSFUL;
333 331 }
334 332
335 333 return status;
336 334 }
337 335
338 336 int spacewire_start_link( int fd )
339 337 {
340 338 rtems_status_code status;
341 339
342 340 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
343 341 // -1 default hardcoded driver timeout
344 342
345 343 return status;
346 344 }
347 345
348 346 int spacewire_stop_start_link( int fd )
349 347 {
350 348 rtems_status_code status;
351 349
352 350 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
353 351 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
354 352 // -1 default hardcoded driver timeout
355 353
356 354 return status;
357 355 }
358 356
359 357 int spacewire_configure_link( int fd )
360 358 {
361 359 /** This function configures the SpaceWire link.
362 360 *
363 361 * @return GR-RTEMS-DRIVER directive status codes:
364 362 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
365 363 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
366 364 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
367 365 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
368 366 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
369 367 * - 5 EIO - Error when writing to grswp hardware registers.
370 368 * - 2 ENOENT - No such file or directory
371 369 */
372 370
373 371 rtems_status_code status;
374 372
375 373 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
376 374 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
377 375
378 376 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
379 377 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
380 378 //
381 379 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
382 380 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
383 381 //
384 382 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
385 383 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
386 384 //
387 385 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
388 386 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
389 387 //
390 388 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
391 389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
392 390 //
393 391 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
394 392 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
395 393 //
396 394 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
397 395 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
398 396
399 397 return status;
400 398 }
401 399
402 400 int spacewire_reset_link( void )
403 401 {
404 402 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
405 403 *
406 404 * @return RTEMS directive status code:
407 405 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
408 406 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
409 407 *
410 408 */
411 409
412 410 rtems_status_code status_spw;
413 411 int i;
414 412
415 413 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
416 414 {
417 415 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
418 416
419 417 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
420 418
421 419 status_spw = spacewire_stop_start_link( fdSPW );
422 420 if ( status_spw != RTEMS_SUCCESSFUL )
423 421 {
424 422 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
425 423 }
426 424
427 425 if ( status_spw == RTEMS_SUCCESSFUL)
428 426 {
429 427 break;
430 428 }
431 429 }
432 430
433 431 return status_spw;
434 432 }
435 433
436 434 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
437 435 {
438 436 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
439 437 *
440 438 * @param val is the value, 0 or 1, used to set the value of the NP bit.
441 439 * @param regAddr is the address of the GRSPW control register.
442 440 *
443 441 * NP is the bit 20 of the GRSPW control register.
444 442 *
445 443 */
446 444
447 445 unsigned int *spwptr = (unsigned int*) regAddr;
448 446
449 447 if (val == 1) {
450 448 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
451 449 }
452 450 if (val== 0) {
453 451 *spwptr = *spwptr & 0xffdfffff;
454 452 }
455 453 }
456 454
457 455 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
458 456 {
459 457 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
460 458 *
461 459 * @param val is the value, 0 or 1, used to set the value of the RE bit.
462 460 * @param regAddr is the address of the GRSPW control register.
463 461 *
464 462 * RE is the bit 16 of the GRSPW control register.
465 463 *
466 464 */
467 465
468 466 unsigned int *spwptr = (unsigned int*) regAddr;
469 467
470 468 if (val == 1)
471 469 {
472 470 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
473 471 }
474 472 if (val== 0)
475 473 {
476 474 *spwptr = *spwptr & 0xfffdffff;
477 475 }
478 476 }
479 477
480 478 void spacewire_compute_stats_offsets( void )
481 479 {
482 480 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
483 481 *
484 482 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
485 483 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
486 484 * during the open systel call).
487 485 *
488 486 */
489 487
490 488 spw_stats spacewire_stats_grspw;
491 489 rtems_status_code status;
492 490
493 491 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
494 492
495 493 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
496 494 + spacewire_stats.packets_received;
497 495 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
498 496 + spacewire_stats.packets_sent;
499 497 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
500 498 + spacewire_stats.parity_err;
501 499 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
502 500 + spacewire_stats.disconnect_err;
503 501 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
504 502 + spacewire_stats.escape_err;
505 503 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
506 504 + spacewire_stats.credit_err;
507 505 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
508 506 + spacewire_stats.write_sync_err;
509 507 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
510 508 + spacewire_stats.rx_rmap_header_crc_err;
511 509 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
512 510 + spacewire_stats.rx_rmap_data_crc_err;
513 511 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
514 512 + spacewire_stats.early_ep;
515 513 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
516 514 + spacewire_stats.invalid_address;
517 515 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
518 516 + spacewire_stats.rx_eep_err;
519 517 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
520 518 + spacewire_stats.rx_truncated;
521 519 }
522 520
523 521 void spacewire_update_statistics( void )
524 522 {
525 523 rtems_status_code status;
526 524 spw_stats spacewire_stats_grspw;
527 525
528 526 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
529 527
530 528 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
531 529 + spacewire_stats_grspw.packets_received;
532 530 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
533 531 + spacewire_stats_grspw.packets_sent;
534 532 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
535 533 + spacewire_stats_grspw.parity_err;
536 534 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
537 535 + spacewire_stats_grspw.disconnect_err;
538 536 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
539 537 + spacewire_stats_grspw.escape_err;
540 538 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
541 539 + spacewire_stats_grspw.credit_err;
542 540 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
543 541 + spacewire_stats_grspw.write_sync_err;
544 542 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
545 543 + spacewire_stats_grspw.rx_rmap_header_crc_err;
546 544 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
547 545 + spacewire_stats_grspw.rx_rmap_data_crc_err;
548 546 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
549 547 + spacewire_stats_grspw.early_ep;
550 548 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
551 549 + spacewire_stats_grspw.invalid_address;
552 550 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
553 551 + spacewire_stats_grspw.rx_eep_err;
554 552 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
555 553 + spacewire_stats_grspw.rx_truncated;
556 554 //spacewire_stats.tx_link_err;
557 555
558 556 //****************************
559 557 // DPU_SPACEWIRE_IF_STATISTICS
560 558 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
561 559 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
562 560 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
563 561 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
564 562 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
565 563 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
566 564
567 565 //******************************************
568 566 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
569 567 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
570 568 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
571 569 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
572 570 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
573 571 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
574 572
575 573 //*********************************************
576 574 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
577 575 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
578 576 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
579 577 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
580 578 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
581 579 }
582 580
583 581 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
584 582 {
585 //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
586 // printf("In timecode_irq_handler *** Error sending event to DUMB\n");
587 //}
583 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 );
584 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
585
586 grgpio_regs->io_port_direction_register =
587 grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled
588
589 if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 )
590 {
591 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7;
592 }
593 else
594 {
595 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08;
596 }
597
588 598 }
589 599
590 600 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
591 601 {
592 602 int linkStatus;
593 603 rtems_status_code status;
594 604
595 605 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
596 606
597 607 if ( linkStatus == 5) {
598 608 PRINTF("in spacewire_reset_link *** link is running\n")
599 609 status = RTEMS_SUCCESSFUL;
600 610 }
601 611 }
@@ -1,791 +1,790
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14
15 15 //***********
16 16 // RTEMS TASK
17 17
18 18 rtems_task actn_task( rtems_task_argument unused )
19 19 {
20 20 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 21 *
22 22 * @param unused is the starting argument of the RTEMS task
23 23 *
24 24 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 25 * on the incoming TeleCommand.
26 26 *
27 27 */
28 28
29 29 int result;
30 30 rtems_status_code status; // RTEMS status code
31 31 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 32 size_t size; // size of the incoming TC packet
33 33 unsigned char subtype; // subtype of the current TC packet
34 34 unsigned char time[6];
35 35 rtems_id queue_rcv_id;
36 36 rtems_id queue_snd_id;
37 37
38 38 status = get_message_queue_id_recv( &queue_rcv_id );
39 39 if (status != RTEMS_SUCCESSFUL)
40 40 {
41 41 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 42 }
43 43
44 44 status = get_message_queue_id_send( &queue_snd_id );
45 45 if (status != RTEMS_SUCCESSFUL)
46 46 {
47 47 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 48 }
49 49
50 50 result = LFR_SUCCESSFUL;
51 51 subtype = 0; // subtype of the current TC packet
52 52
53 53 BOOT_PRINTF("in ACTN *** \n")
54 54
55 55 while(1)
56 56 {
57 57 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 58 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 59 getTime( time ); // set time to the current time
60 60 if (status!=RTEMS_SUCCESSFUL)
61 61 {
62 62 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 63 }
64 64 else
65 65 {
66 66 subtype = TC.serviceSubType;
67 67 switch(subtype)
68 68 {
69 69 case TC_SUBTYPE_RESET:
70 70 result = action_reset( &TC, queue_snd_id, time );
71 71 close_action( &TC, result, queue_snd_id );
72 72 break;
73 73 //
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id );
77 77 break;
78 78 //
79 79 case TC_SUBTYPE_LOAD_NORM:
80 80 result = action_load_normal_par( &TC, queue_snd_id, time );
81 81 close_action( &TC, result, queue_snd_id );
82 82 break;
83 83 //
84 84 case TC_SUBTYPE_LOAD_BURST:
85 85 result = action_load_burst_par( &TC, queue_snd_id, time );
86 86 close_action( &TC, result, queue_snd_id );
87 87 break;
88 88 //
89 89 case TC_SUBTYPE_LOAD_SBM1:
90 90 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 91 close_action( &TC, result, queue_snd_id );
92 92 break;
93 93 //
94 94 case TC_SUBTYPE_LOAD_SBM2:
95 95 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 96 close_action( &TC, result, queue_snd_id );
97 97 break;
98 98 //
99 99 case TC_SUBTYPE_DUMP:
100 100 result = action_dump_par( queue_snd_id );
101 101 close_action( &TC, result, queue_snd_id );
102 102 break;
103 103 //
104 104 case TC_SUBTYPE_ENTER:
105 105 result = action_enter_mode( &TC, queue_snd_id, time );
106 106 close_action( &TC, result, queue_snd_id );
107 107 break;
108 108 //
109 109 case TC_SUBTYPE_UPDT_INFO:
110 110 result = action_update_info( &TC, queue_snd_id );
111 111 close_action( &TC, result, queue_snd_id );
112 112 break;
113 113 //
114 114 case TC_SUBTYPE_EN_CAL:
115 115 result = action_enable_calibration( &TC, queue_snd_id, time );
116 116 close_action( &TC, result, queue_snd_id );
117 117 break;
118 118 //
119 119 case TC_SUBTYPE_DIS_CAL:
120 120 result = action_disable_calibration( &TC, queue_snd_id, time );
121 121 close_action( &TC, result, queue_snd_id );
122 122 break;
123 123 //
124 124 case TC_SUBTYPE_UPDT_TIME:
125 125 result = action_update_time( &TC );
126 126 close_action( &TC, result, queue_snd_id );
127 127 break;
128 128 //
129 129 default:
130 130 break;
131 131 }
132 132 }
133 133 }
134 134 }
135 135
136 136 //***********
137 137 // TC ACTIONS
138 138
139 139 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 140 {
141 141 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 142 *
143 143 * @param TC points to the TeleCommand packet that is being processed
144 144 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 145 *
146 146 */
147 147
148 148 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
149 149 return LFR_DEFAULT;
150 150 }
151 151
152 152 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
153 153 {
154 154 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
155 155 *
156 156 * @param TC points to the TeleCommand packet that is being processed
157 157 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
158 158 *
159 159 */
160 160
161 161 rtems_status_code status;
162 162 unsigned char requestedMode;
163 163
164 164 requestedMode = TC->dataAndCRC[1];
165 165
166 166 if ( (requestedMode != LFR_MODE_STANDBY)
167 167 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
168 168 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
169 169 {
170 170 status = RTEMS_UNSATISFIED;
171 171 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_LFR_MODE, requestedMode );
172 172 }
173 173 else
174 174 {
175 175 printf("in action_enter_mode *** enter mode %d\n", requestedMode);
176 176
177 177 status = transition_validation(requestedMode);
178 178
179 179 if ( status == LFR_SUCCESSFUL ) {
180 180 if ( lfrCurrentMode != LFR_MODE_STANDBY)
181 181 {
182 182 status = stop_current_mode();
183 183 }
184 184 if (status != RTEMS_SUCCESSFUL)
185 185 {
186 186 PRINTF("ERR *** in action_enter *** stop_current_mode\n")
187 187 }
188 188 status = enter_mode( requestedMode );
189 189 }
190 190 else
191 191 {
192 192 PRINTF("ERR *** in action_enter *** transition rejected\n")
193 193 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
194 194 }
195 195 }
196 196
197 197 return status;
198 198 }
199 199
200 200 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
201 201 {
202 202 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
203 203 *
204 204 * @param TC points to the TeleCommand packet that is being processed
205 205 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
206 206 *
207 207 * @return LFR directive status code:
208 208 * - LFR_DEFAULT
209 209 * - LFR_SUCCESSFUL
210 210 *
211 211 */
212 212
213 213 unsigned int val;
214 214 int result;
215 215 unsigned int status;
216 216 unsigned char mode;
217 217
218 // check LFR MODE
218 // check LFR mode
219 219 mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET5 ] & 0x1e) >> 1;
220 220 status = check_update_info_hk_lfr_mode( mode );
221 if (status != LFR_DEFAULT) // check TDS mode
221 if (status == LFR_SUCCESSFUL) // check TDS mode
222 222 {
223 223 mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0xf0) >> 4;
224 224 status = check_update_info_hk_tds_mode( mode );
225 225 }
226 if (status != LFR_DEFAULT) // check THR mode
226 if (status == LFR_SUCCESSFUL) // check THR mode
227 227 {
228 228 mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0x0f);
229 229 status = check_update_info_hk_thr_mode( mode );
230 230 }
231 if (status != LFR_DEFAULT) // if the parameter check is successful
231 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
232 232 {
233 233 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
234 234 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
235 235 val++;
236 236 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
237 237 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
238 238 }
239 239
240 240 result = status;
241 241
242 242 return result;
243 243 }
244 244
245 245 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
246 246 {
247 247 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
248 248 *
249 249 * @param TC points to the TeleCommand packet that is being processed
250 250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
251 251 *
252 252 */
253 253
254 254 int result;
255 255 unsigned char lfrMode;
256 256
257 257 result = LFR_DEFAULT;
258 258 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
259 259
260 260 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
261 261 result = LFR_DEFAULT;
262 262
263 263 return result;
264 264 }
265 265
266 266 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
267 267 {
268 268 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
269 269 *
270 270 * @param TC points to the TeleCommand packet that is being processed
271 271 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
272 272 *
273 273 */
274 274
275 275 int result;
276 276 unsigned char lfrMode;
277 277
278 278 result = LFR_DEFAULT;
279 279 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
280 280
281 281 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
282 282 result = LFR_DEFAULT;
283 283
284 284 return result;
285 285 }
286 286
287 287 int action_update_time(ccsdsTelecommandPacket_t *TC)
288 288 {
289 289 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
290 290 *
291 291 * @param TC points to the TeleCommand packet that is being processed
292 292 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
293 293 *
294 294 * @return LFR_SUCCESSFUL
295 295 *
296 296 */
297 297
298 298 unsigned int val;
299 299
300 300 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
301 301 + (TC->dataAndCRC[1] << 16)
302 302 + (TC->dataAndCRC[2] << 8)
303 303 + TC->dataAndCRC[3];
304 304 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
305 305 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
306 306 val++;
307 307 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
308 308 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
309 time_management_regs->ctrl = time_management_regs->ctrl | 1;
309 // time_management_regs->ctrl = time_management_regs->ctrl | 1; // force tick
310 310
311 311 return LFR_SUCCESSFUL;
312 312 }
313 313
314 314 //*******************
315 315 // ENTERING THE MODES
316 316
317 317 int transition_validation(unsigned char requestedMode)
318 318 {
319 319 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
320 320 *
321 321 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
322 322 *
323 323 * @return LFR directive status codes:
324 324 * - LFR_SUCCESSFUL - the transition is authorized
325 325 * - LFR_DEFAULT - the transition is not authorized
326 326 *
327 327 */
328 328
329 329 int status;
330 330
331 331 switch (requestedMode)
332 332 {
333 333 case LFR_MODE_STANDBY:
334 334 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
335 335 status = LFR_DEFAULT;
336 336 }
337 337 else
338 338 {
339 339 status = LFR_SUCCESSFUL;
340 340 }
341 341 break;
342 342 case LFR_MODE_NORMAL:
343 343 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
344 344 status = LFR_DEFAULT;
345 345 }
346 346 else {
347 347 status = LFR_SUCCESSFUL;
348 348 }
349 349 break;
350 350 case LFR_MODE_BURST:
351 351 if ( lfrCurrentMode == LFR_MODE_BURST ) {
352 352 status = LFR_DEFAULT;
353 353 }
354 354 else {
355 355 status = LFR_SUCCESSFUL;
356 356 }
357 357 break;
358 358 case LFR_MODE_SBM1:
359 359 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
360 360 status = LFR_DEFAULT;
361 361 }
362 362 else {
363 363 status = LFR_SUCCESSFUL;
364 364 }
365 365 break;
366 366 case LFR_MODE_SBM2:
367 367 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
368 368 status = LFR_DEFAULT;
369 369 }
370 370 else {
371 371 status = LFR_SUCCESSFUL;
372 372 }
373 373 break;
374 374 default:
375 375 status = LFR_DEFAULT;
376 376 break;
377 377 }
378 378
379 379 return status;
380 380 }
381 381
382 382 int stop_current_mode(void)
383 383 {
384 384 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
385 385 *
386 386 * @return RTEMS directive status codes:
387 387 * - RTEMS_SUCCESSFUL - task restarted successfully
388 388 * - RTEMS_INVALID_ID - task id invalid
389 389 * - RTEMS_ALREADY_SUSPENDED - task already suspended
390 390 *
391 391 */
392 392
393 393 rtems_status_code status;
394 394
395 395 status = RTEMS_SUCCESSFUL;
396 396
397 397 // (1) mask interruptions
398 398 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
399 399 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
400 400
401 401 // (2) clear interruptions
402 402 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
403 403 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
404 404
405 405 // (3) reset registers
406 406 // waveform picker
407 407 reset_wfp_burst_enable(); // reset burst and enable bits
408 408 reset_wfp_status(); // reset all the status bits
409 409 // spectral matrices
410 410 set_irq_on_new_ready_matrix( 0 ); // stop the spectral matrices
411 411 set_run_matrix_spectral( 0 ); // run_matrix_spectral is set to 0
412 412 reset_extractSWF(); // reset the extractSWF flag to false
413 413
414 414 // <Spectral Matrices simulator>
415 415 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
416 416 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
417 417 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
418 418 // </Spectral Matrices simulator>
419 419
420 420 // suspend several tasks
421 421 if (lfrCurrentMode != LFR_MODE_STANDBY) {
422 422 status = suspend_science_tasks();
423 423 }
424 424
425 425 if (status != RTEMS_SUCCESSFUL)
426 426 {
427 427 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
428 428 }
429 429
430 430 return status;
431 431 }
432 432
433 433 int enter_mode(unsigned char mode )
434 434 {
435 435 /** This function is launched after a mode transition validation.
436 436 *
437 437 * @param mode is the mode in which LFR will be put.
438 438 *
439 439 * @return RTEMS directive status codes:
440 440 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
441 441 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
442 442 *
443 443 */
444 444
445 445 rtems_status_code status;
446 446
447 447 status = RTEMS_UNSATISFIED;
448 448
449 449 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d);
450 450 updateLFRCurrentMode();
451 451
452 452 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
453 453 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
454 454 {
455 455 #ifdef PRINT_TASK_STATISTICS
456 456 rtems_cpu_usage_reset();
457 457 maxCount = 0;
458 458 #endif
459 459 status = restart_science_tasks();
460 460 launch_waveform_picker( mode );
461 461 launch_spectral_matrix( mode );
462 462 }
463 463 else if ( mode == LFR_MODE_STANDBY )
464 464 {
465 465 #ifdef PRINT_TASK_STATISTICS
466 466 rtems_cpu_usage_report();
467 467 #endif
468 468
469 469 #ifdef PRINT_STACK_REPORT
470 470 rtems_stack_checker_report_usage();
471 471 #endif
472 472 status = stop_current_mode();
473 473 PRINTF1("maxCount = %d\n", maxCount)
474 474 }
475 475 else
476 476 {
477 477 status = RTEMS_UNSATISFIED;
478 478 }
479 479
480 480 if (status != RTEMS_SUCCESSFUL)
481 481 {
482 482 PRINTF1("in enter_mode *** ERR = %d\n", status)
483 483 status = RTEMS_UNSATISFIED;
484 484 }
485 485
486 486 return status;
487 487 }
488 488
489 489 int restart_science_tasks()
490 490 {
491 491 /** This function is used to restart all science tasks.
492 492 *
493 493 * @return RTEMS directive status codes:
494 494 * - RTEMS_SUCCESSFUL - task restarted successfully
495 495 * - RTEMS_INVALID_ID - task id invalid
496 496 * - RTEMS_INCORRECT_STATE - task never started
497 497 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
498 498 *
499 499 * Science tasks are AVF0, BPF0, WFRM, CWF3, CW2, CWF1
500 500 *
501 501 */
502 502
503 503 rtems_status_code status[6];
504 504 rtems_status_code ret;
505 505
506 506 ret = RTEMS_SUCCESSFUL;
507 507
508 508 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], 1 );
509 509 if (status[0] != RTEMS_SUCCESSFUL)
510 510 {
511 511 PRINTF1("in restart_science_task *** 0 ERR %d\n", status[0])
512 512 }
513 513
514 514 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
515 515 if (status[2] != RTEMS_SUCCESSFUL)
516 516 {
517 517 PRINTF1("in restart_science_task *** 2 ERR %d\n", status[2])
518 518 }
519 519
520 520 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
521 521 if (status[3] != RTEMS_SUCCESSFUL)
522 522 {
523 523 PRINTF1("in restart_science_task *** 3 ERR %d\n", status[3])
524 524 }
525 525
526 526 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
527 527 if (status[4] != RTEMS_SUCCESSFUL)
528 528 {
529 529 PRINTF1("in restart_science_task *** 4 ERR %d\n", status[4])
530 530 }
531 531
532 532 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
533 533 if (status[5] != RTEMS_SUCCESSFUL)
534 534 {
535 535 PRINTF1("in restart_science_task *** 5 ERR %d\n", status[5])
536 536 }
537 537
538 538 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[2] != RTEMS_SUCCESSFUL) ||
539 539 (status[3] != RTEMS_SUCCESSFUL) || (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) )
540 540 {
541 541 ret = RTEMS_UNSATISFIED;
542 542 }
543 543
544 544 return ret;
545 545 }
546 546
547 547 int suspend_science_tasks()
548 548 {
549 549 /** This function suspends the science tasks.
550 550 *
551 551 * @return RTEMS directive status codes:
552 552 * - RTEMS_SUCCESSFUL - task restarted successfully
553 553 * - RTEMS_INVALID_ID - task id invalid
554 554 * - RTEMS_ALREADY_SUSPENDED - task already suspended
555 555 *
556 556 */
557 557
558 558 rtems_status_code status;
559 559
560 560 status = rtems_task_suspend( Task_id[TASKID_AVF0] );
561 561 if (status != RTEMS_SUCCESSFUL)
562 562 {
563 563 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
564 564 }
565 565
566 566 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
567 567 {
568 568 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
569 569 if (status != RTEMS_SUCCESSFUL)
570 570 {
571 571 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
572 572 }
573 573 }
574 574
575 575 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
576 576 {
577 577 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
578 578 if (status != RTEMS_SUCCESSFUL)
579 579 {
580 580 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
581 581 }
582 582 }
583 583
584 584 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
585 585 {
586 586 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
587 587 if (status != RTEMS_SUCCESSFUL)
588 588 {
589 589 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
590 590 }
591 591 }
592 592
593 593 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
594 594 {
595 595 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
596 596 if (status != RTEMS_SUCCESSFUL)
597 597 {
598 598 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
599 599 }
600 600 }
601 601
602 602 return status;
603 603 }
604 604
605 605 void launch_waveform_picker( unsigned char mode )
606 606 {
607 607 int startDate;
608 608
609 609 reset_current_ring_nodes();
610 610 reset_waveform_picker_regs();
611 611 set_wfp_burst_enable_register( mode );
612 612
613 613 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
614 614 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
615 615
616 616 startDate = time_management_regs->coarse_time + 2;
617 617 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x80; // [1000 0000]
618 618 waveform_picker_regs->start_date = startDate;
619 619 }
620 620
621 621 void launch_spectral_matrix( unsigned char mode )
622 622 {
623 623 reset_nb_sm_f0();
624 624 reset_current_sm_ring_nodes();
625 625 reset_spectral_matrix_regs();
626 626
627 627 #ifdef VHDL_DEV
628 628 set_irq_on_new_ready_matrix( 1 );
629 629 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
630 630 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
631 631 set_run_matrix_spectral( 1 );
632 632 #else
633 633 // Spectral Matrices simulator
634 634 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
635 635 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
636 636 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
637 637 #endif
638 638 }
639 639
640 640 void set_irq_on_new_ready_matrix( unsigned char value )
641 641 {
642 642 if (value == 1)
643 643 {
644 644 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
645 645 }
646 646 else
647 647 {
648 648 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
649 649 }
650 650 }
651 651
652 652 void set_run_matrix_spectral( unsigned char value )
653 653 {
654 654 if (value == 1)
655 655 {
656 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // 0100 set run_matrix spectral to 1
656 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // [0100] set run_matrix spectral to 1
657 657 }
658 658 else
659 659 {
660 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // 1011 set run_matrix spectral to 0
660 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // [1011] set run_matrix spectral to 0
661 661 }
662 662 }
663 663
664 664 void launch_spectral_matrix_simu( unsigned char mode )
665 665 {
666 666 reset_nb_sm_f0();
667 667 reset_current_sm_ring_nodes();
668 668 reset_spectral_matrix_regs();
669 669
670 670 // Spectral Matrices simulator
671 671 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
672 672 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
673 673 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
674 674 set_local_nb_interrupt_f0_MAX();
675 675 }
676 676
677 677 //****************
678 678 // CLOSING ACTIONS
679 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC)
679 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
680 680 {
681 681 /** This function is used to update the HK packets statistics after a successful TC execution.
682 682 *
683 683 * @param TC points to the TC being processed
684 684 * @param time is the time used to date the TC execution
685 685 *
686 686 */
687 687
688 unsigned int val;
689
688 690 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
689 691 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
690 692 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
691 693 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
692 694 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
693 695 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
694 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
695 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
696 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
697 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = (unsigned char) (time_management_regs->coarse_time);
698 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8);
699 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = (unsigned char) (time_management_regs->fine_time);
696 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
697 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
698 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
699 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
700 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
701 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
702
703 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
704 val++;
705 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
706 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
700 707 }
701 708
702 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC )
709 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
703 710 {
704 711 /** This function is used to update the HK packets statistics after a TC rejection.
705 712 *
706 713 * @param TC points to the TC being processed
707 714 * @param time is the time used to date the TC rejection
708 715 *
709 716 */
710 717
718 unsigned int val;
719
711 720 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
712 721 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
713 722 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
714 723 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
715 724 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
716 725 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
717 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
718 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
719 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
720 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = (unsigned char) (time_management_regs->coarse_time);
721 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8);
722 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = (unsigned char) (time_management_regs->fine_time);
726 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
727 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
728 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
729 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
730 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
731 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
732
733 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
734 val++;
735 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
736 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
723 737 }
724 738
725 739 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
726 740 {
727 741 /** This function is the last step of the TC execution workflow.
728 742 *
729 743 * @param TC points to the TC being processed
730 744 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
731 745 * @param queue_id is the id of the RTEMS message queue used to send TM packets
732 746 * @param time is the time used to date the TC execution
733 747 *
734 748 */
735 749
736 unsigned int val = 0;
737
738 750 if (result == LFR_SUCCESSFUL)
739 751 {
740 if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
741 &&
742 !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
752 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
753 &
754 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
743 755 )
744 756 {
745 757 send_tm_lfr_tc_exe_success( TC, queue_id );
746 758 }
747 update_last_TC_exe( TC );
748 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
749 val++;
750 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
751 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
752 }
753 else
754 {
755 update_last_TC_rej( TC );
756 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
757 val++;
758 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
759 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
760 759 }
761 760 }
762 761
763 762 //***************************
764 763 // Interrupt Service Routines
765 764 rtems_isr commutation_isr1( rtems_vector_number vector )
766 765 {
767 766 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
768 767 printf("In commutation_isr1 *** Error sending event to DUMB\n");
769 768 }
770 769 }
771 770
772 771 rtems_isr commutation_isr2( rtems_vector_number vector )
773 772 {
774 773 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
775 774 printf("In commutation_isr2 *** Error sending event to DUMB\n");
776 775 }
777 776 }
778 777
779 778 //****************
780 779 // OTHER FUNCTIONS
781 780 void updateLFRCurrentMode()
782 781 {
783 782 /** This function updates the value of the global variable lfrCurrentMode.
784 783 *
785 784 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
786 785 *
787 786 */
788 787 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
789 788 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
790 789 }
791 790
@@ -1,539 +1,539
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
18 18 {
19 19 /** This function updates the LFR registers with the incoming common parameters.
20 20 *
21 21 * @param TC points to the TeleCommand packet that is being processed
22 22 *
23 23 *
24 24 */
25 25
26 26 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
27 27 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
28 28 set_wfp_data_shaping( );
29 29 return LFR_SUCCESSFUL;
30 30 }
31 31
32 32 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
33 33 {
34 34 /** This function updates the LFR registers with the incoming normal parameters.
35 35 *
36 36 * @param TC points to the TeleCommand packet that is being processed
37 37 * @param queue_id is the id of the queue which handles TM related to this execution step
38 38 *
39 39 */
40 40
41 41 int result;
42 42 int flag;
43 43 rtems_status_code status;
44 44
45 45 flag = LFR_SUCCESSFUL;
46 46
47 47 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
48 48 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
49 49 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
50 50 flag = LFR_DEFAULT;
51 51 }
52 52
53 53 //***************
54 54 // sy_lfr_n_swf_l
55 55 if (flag == LFR_SUCCESSFUL)
56 56 {
57 57 result = set_sy_lfr_n_swf_l( TC, queue_id, time );
58 58 if (result != LFR_SUCCESSFUL)
59 59 {
60 60 flag = LFR_DEFAULT;
61 61 }
62 62 }
63 63
64 64 //***************
65 65 // sy_lfr_n_swf_p
66 66 if (flag == LFR_SUCCESSFUL)
67 67 {
68 68 result = set_sy_lfr_n_swf_p( TC, queue_id, time );
69 69 if (result != LFR_SUCCESSFUL)
70 70 {
71 71 flag = LFR_DEFAULT;
72 72 }
73 73 }
74 74
75 75 //***************
76 76 // sy_lfr_n_asm_p
77 77 if (flag == LFR_SUCCESSFUL)
78 78 {
79 79 result = set_sy_lfr_n_asm_p( TC, queue_id );
80 80 if (result != LFR_SUCCESSFUL)
81 81 {
82 82 flag = LFR_DEFAULT;
83 83 }
84 84 }
85 85
86 86 //***************
87 87 // sy_lfr_n_bp_p0
88 88 if (flag == LFR_SUCCESSFUL)
89 89 {
90 90 result = set_sy_lfr_n_bp_p0( TC, queue_id );
91 91 if (result != LFR_SUCCESSFUL)
92 92 {
93 93 flag = LFR_DEFAULT;
94 94 }
95 95 }
96 96
97 97 //***************
98 98 // sy_lfr_n_bp_p1
99 99 if (flag == LFR_SUCCESSFUL)
100 100 {
101 101 result = set_sy_lfr_n_bp_p1( TC, queue_id );
102 102 if (result != LFR_SUCCESSFUL)
103 103 {
104 104 flag = LFR_DEFAULT;
105 105 }
106 106 }
107 107
108 108 //*********************
109 109 // sy_lfr_n_cwf_long_f3
110 110 if (flag == LFR_SUCCESSFUL)
111 111 {
112 112 result = set_sy_lfr_n_cwf_long_f3( TC, queue_id );
113 113 if (result != LFR_SUCCESSFUL)
114 114 {
115 115 flag = LFR_DEFAULT;
116 116 }
117 117 }
118 118
119 119 return flag;
120 120 }
121 121
122 122 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
123 123 {
124 124 /** This function updates the LFR registers with the incoming burst parameters.
125 125 *
126 126 * @param TC points to the TeleCommand packet that is being processed
127 127 * @param queue_id is the id of the queue which handles TM related to this execution step
128 128 *
129 129 */
130 130
131 131 int result;
132 132 unsigned char lfrMode;
133 133 rtems_status_code status;
134 134
135 135 result = LFR_DEFAULT;
136 136 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
137 137
138 138 if ( lfrMode == LFR_MODE_BURST ) {
139 139 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
140 140 result = LFR_DEFAULT;
141 141 }
142 142 else {
143 143 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[0];
144 144 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[1];
145 145
146 146 result = LFR_SUCCESSFUL;
147 147 }
148 148
149 149 return result;
150 150 }
151 151
152 152 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
153 153 {
154 154 /** This function updates the LFR registers with the incoming sbm1 parameters.
155 155 *
156 156 * @param TC points to the TeleCommand packet that is being processed
157 157 * @param queue_id is the id of the queue which handles TM related to this execution step
158 158 *
159 159 */
160 160 int result;
161 161 unsigned char lfrMode;
162 162 rtems_status_code status;
163 163
164 164 result = LFR_DEFAULT;
165 165 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
166 166
167 167 if ( (lfrMode == LFR_MODE_SBM1) || (lfrMode == LFR_MODE_SBM2) ) {
168 168 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
169 169 result = LFR_DEFAULT;
170 170 }
171 171 else {
172 172 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[0];
173 173 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[1];
174 174
175 175 result = LFR_SUCCESSFUL;
176 176 }
177 177
178 178 return result;
179 179 }
180 180
181 181 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
182 182 {
183 183 /** This function updates the LFR registers with the incoming sbm2 parameters.
184 184 *
185 185 * @param TC points to the TeleCommand packet that is being processed
186 186 * @param queue_id is the id of the queue which handles TM related to this execution step
187 187 *
188 188 */
189 189
190 190 int result;
191 191 unsigned char lfrMode;
192 192 rtems_status_code status;
193 193
194 194 result = LFR_DEFAULT;
195 195 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
196 196
197 197 if ( (lfrMode == LFR_MODE_SBM1) || (lfrMode == LFR_MODE_SBM2) ) {
198 198 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
199 199 result = LFR_DEFAULT;
200 200 }
201 201 else {
202 202 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[0];
203 203 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[1];
204 204
205 205 result = LFR_SUCCESSFUL;
206 206 }
207 207
208 208 return result;
209 209 }
210 210
211 211 int action_dump_par( rtems_id queue_id )
212 212 {
213 213 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
214 214 *
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step.
216 216 *
217 217 * @return RTEMS directive status codes:
218 218 * - RTEMS_SUCCESSFUL - message sent successfully
219 219 * - RTEMS_INVALID_ID - invalid queue id
220 220 * - RTEMS_INVALID_SIZE - invalid message size
221 221 * - RTEMS_INVALID_ADDRESS - buffer is NULL
222 222 * - RTEMS_UNSATISFIED - out of message buffers
223 223 * - RTEMS_TOO_MANY - queue s limit has been reached
224 224 *
225 225 */
226 226
227 227 int status;
228 228
229 229 // UPDATE TIME
230 230 increment_seq_counter( parameter_dump_packet.packetSequenceControl );
231 231 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
232 232 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
233 233 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
234 234 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
235 235 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
236 236 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
237 237 // SEND DATA
238 238 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
239 239 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
240 240 if (status != RTEMS_SUCCESSFUL) {
241 241 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
242 242 }
243 243
244 244 return status;
245 245 }
246 246
247 247 //***********************
248 248 // NORMAL MODE PARAMETERS
249 249
250 250 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
251 251 {
252 252 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
253 253 *
254 254 * @param TC points to the TeleCommand packet that is being processed
255 255 * @param queue_id is the id of the queue which handles TM related to this execution step
256 256 *
257 257 */
258 258
259 259 unsigned int tmp;
260 260 int result;
261 261 unsigned char msb;
262 262 unsigned char lsb;
263 263 rtems_status_code status;
264 264
265 265 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L ];
266 266 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L+1 ];
267 267
268 268 tmp = ( unsigned int ) floor(
269 269 ( ( msb*256 ) + lsb ) / 16
270 270 ) * 16;
271 271
272 272 if ( (tmp < 16) || (tmp > 2048) ) // the snapshot period is a multiple of 16
273 273 { // 2048 is the maximum limit due to the size of the buffers
274 274 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_L+10, lsb );
275 275 result = WRONG_APP_DATA;
276 276 }
277 277 else if (tmp != 2048)
278 278 {
279 279 status = send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
280 280 result = FUNCT_NOT_IMPL;
281 281 }
282 282 else
283 283 {
284 284 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (tmp >> 8);
285 285 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (tmp );
286 286 result = LFR_SUCCESSFUL;
287 287 }
288 288
289 289 return result;
290 290 }
291 291
292 292 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time)
293 293 {
294 294 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
295 295 *
296 296 * @param TC points to the TeleCommand packet that is being processed
297 297 * @param queue_id is the id of the queue which handles TM related to this execution step
298 298 *
299 299 */
300 300
301 301 unsigned int tmp;
302 302 int result;
303 303 unsigned char msb;
304 304 unsigned char lsb;
305 305 rtems_status_code status;
306 306
307 307 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P ];
308 308 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P+1 ];
309 309
310 310 tmp = msb * 256 + lsb;
311 311
312 312 if ( tmp < 16 )
313 313 {
314 314 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_P+10, lsb );
315 315 result = WRONG_APP_DATA;
316 316 }
317 317 else
318 318 {
319 319 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (tmp >> 8);
320 320 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (tmp );
321 321 result = LFR_SUCCESSFUL;
322 322 }
323 323
324 324 return result;
325 325 }
326 326
327 327 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
328 328 {
329 329 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
330 330 *
331 331 * @param TC points to the TeleCommand packet that is being processed
332 332 * @param queue_id is the id of the queue which handles TM related to this execution step
333 333 *
334 334 */
335 335
336 336 int result;
337 337 unsigned char msb;
338 338 unsigned char lsb;
339 339
340 340 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P ];
341 341 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P+1 ];
342 342
343 343 parameter_dump_packet.sy_lfr_n_asm_p[0] = msb;
344 344 parameter_dump_packet.sy_lfr_n_asm_p[1] = lsb;
345 345 result = LFR_SUCCESSFUL;
346 346
347 347 return result;
348 348 }
349 349
350 350 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
351 351 {
352 352 /** This function sets the time between two basic parameter sets, in s (SY_LFR_N_BP_P0).
353 353 *
354 354 * @param TC points to the TeleCommand packet that is being processed
355 355 * @param queue_id is the id of the queue which handles TM related to this execution step
356 356 *
357 357 */
358 358
359 359 int status;
360 360
361 361 status = LFR_SUCCESSFUL;
362 362
363 363 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P0 ];
364 364
365 365 return status;
366 366 }
367 367
368 368 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
369 369 {
370 370 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
371 371 *
372 372 * @param TC points to the TeleCommand packet that is being processed
373 373 * @param queue_id is the id of the queue which handles TM related to this execution step
374 374 *
375 375 */
376 376
377 377 int status;
378 378
379 379 status = LFR_SUCCESSFUL;
380 380
381 381 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P1 ];
382 382
383 383 return status;
384 384 }
385 385
386 386 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
387 387 {
388 388 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
389 389 *
390 390 * @param TC points to the TeleCommand packet that is being processed
391 391 * @param queue_id is the id of the queue which handles TM related to this execution step
392 392 *
393 393 */
394 394
395 395 int status;
396 396
397 397 status = LFR_SUCCESSFUL;
398 398
399 399 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_CWF_LONG_F3 ];
400 400
401 401 return status;
402 402 }
403 403
404 404 //**********************
405 405 // BURST MODE PARAMETERS
406 406
407 407 //*********************
408 408 // SBM1 MODE PARAMETERS
409 409
410 410 //*********************
411 411 // SBM2 MODE PARAMETERS
412 412
413 413 //*******************
414 414 // TC_LFR_UPDATE_INFO
415 415 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
416 416 {
417 417 unsigned int status;
418 418
419 419 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
420 || (mode = LFR_MODE_BURST)
420 || (mode == LFR_MODE_BURST)
421 421 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
422 422 {
423 423 status = LFR_SUCCESSFUL;
424 424 }
425 425 else
426 426 {
427 427 status = LFR_DEFAULT;
428 428 }
429 429
430 430 return status;
431 431 }
432 432
433 433 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
434 434 {
435 435 unsigned int status;
436 436
437 437 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
438 || (mode = TDS_MODE_BURST)
438 || (mode == TDS_MODE_BURST)
439 439 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
440 440 || (mode == TDS_MODE_LFM))
441 441 {
442 442 status = LFR_SUCCESSFUL;
443 443 }
444 444 else
445 445 {
446 446 status = LFR_DEFAULT;
447 447 }
448 448
449 449 return status;
450 450 }
451 451
452 452 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
453 453 {
454 454 unsigned int status;
455 455
456 456 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
457 || (mode = THR_MODE_BURST))
457 || (mode == THR_MODE_BURST))
458 458 {
459 459 status = LFR_SUCCESSFUL;
460 460 }
461 461 else
462 462 {
463 463 status = LFR_DEFAULT;
464 464 }
465 465
466 466 return status;
467 467 }
468 468
469 469 //**********
470 470 // init dump
471 471
472 472 void init_parameter_dump( void )
473 473 {
474 474 /** This function initialize the parameter_dump_packet global variable with default values.
475 475 *
476 476 */
477 477
478 478 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
479 479 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
480 480 parameter_dump_packet.reserved = CCSDS_RESERVED;
481 481 parameter_dump_packet.userApplication = CCSDS_USER_APP;
482 482 parameter_dump_packet.packetID[0] = (unsigned char) (TM_PACKET_ID_PARAMETER_DUMP >> 8);
483 483 parameter_dump_packet.packetID[1] = (unsigned char) TM_PACKET_ID_PARAMETER_DUMP;
484 484 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
485 485 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
486 486 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
487 487 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
488 488 // DATA FIELD HEADER
489 489 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
490 490 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
491 491 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
492 492 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
493 493 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
494 494 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
495 495 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
496 496 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
497 497 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
498 498 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
499 499 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
500 500
501 501 //******************
502 502 // COMMON PARAMETERS
503 503 parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0;
504 504 parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1;
505 505
506 506 //******************
507 507 // NORMAL PARAMETERS
508 508 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (SY_LFR_N_SWF_L >> 8);
509 509 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (SY_LFR_N_SWF_L );
510 510 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (SY_LFR_N_SWF_P >> 8);
511 511 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (SY_LFR_N_SWF_P );
512 512 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (SY_LFR_N_ASM_P >> 8);
513 513 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (SY_LFR_N_ASM_P );
514 514 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) SY_LFR_N_BP_P0;
515 515 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) SY_LFR_N_BP_P1;
516 516 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) SY_LFR_N_CWF_LONG_F3;
517 517
518 518 //*****************
519 519 // BURST PARAMETERS
520 520 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
521 521 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
522 522
523 523 //****************
524 524 // SBM1 PARAMETERS
525 525 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
526 526 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
527 527
528 528 //****************
529 529 // SBM2 PARAMETERS
530 530 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
531 531 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
532 532 }
533 533
534 534
535 535
536 536
537 537
538 538
539 539
@@ -1,493 +1,511
1 1 /** Functions to send TM packets related to TC parsing and execution.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to send appropriate TM packets after parsing and execution:
7 7 * - TM_LFR_TC_EXE_SUCCESS
8 8 * - TM_LFR_TC_EXE_INCONSISTENT
9 9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 11 * - TM_LFR_TC_EXE_ERROR
12 12 * - TM_LFR_TC_EXE_CORRUPTED
13 13 *
14 14 */
15 15
16 16 #include "tm_lfr_tc_exe.h"
17 17
18 18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 19 {
20 20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 21 *
22 22 * @param TC points to the TeleCommand packet that is being processed
23 23 * @param queue_id is the id of the queue which handles TM
24 24 *
25 25 * @return RTEMS directive status code:
26 26 * - RTEMS_SUCCESSFUL - message sent successfully
27 27 * - RTEMS_INVALID_ID - invalid queue id
28 28 * - RTEMS_INVALID_SIZE - invalid message size
29 29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 30 * - RTEMS_UNSATISFIED - out of message buffers
31 31 * - RTEMS_TOO_MANY - queue s limit has been reached
32 32 *
33 33 */
34 34
35 35 rtems_status_code status;
36 36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 37 unsigned char messageSize;
38 38
39 39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 41 TM.reserved = DEFAULT_RESERVED;
42 42 TM.userApplication = CCSDS_USER_APP;
43 43 // PACKET HEADER
44 44 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
45 45 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
46 46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> 8);
48 48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 49 // DATA FIELD HEADER
50 50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 51 TM.serviceType = TM_TYPE_TC_EXE;
52 52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 53 TM.destinationID = TC->sourceID;
54 54 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
55 55 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
56 56 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
57 57 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
58 58 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
59 59 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
60 60 //
61 61 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 62 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65 65
66 66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67 67
68 68 // SEND DATA
69 69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 70 if (status != RTEMS_SUCCESSFUL) {
71 71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 72 }
73 73
74 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
76
74 77 return status;
75 78 }
76 79
77 80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
78 81 unsigned char byte_position, unsigned char rcv_value )
79 82 {
80 83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
81 84 *
82 85 * @param TC points to the TeleCommand packet that is being processed
83 86 * @param queue_id is the id of the queue which handles TM
84 87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
85 88 * @param rcv_value is the value of the LSB of the parameter that has been deteced as inconsistent
86 89 *
87 90 * @return RTEMS directive status code:
88 91 * - RTEMS_SUCCESSFUL - message sent successfully
89 92 * - RTEMS_INVALID_ID - invalid queue id
90 93 * - RTEMS_INVALID_SIZE - invalid message size
91 94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
92 95 * - RTEMS_UNSATISFIED - out of message buffers
93 96 * - RTEMS_TOO_MANY - queue s limit has been reached
94 97 *
95 98 */
96 99
97 100 rtems_status_code status;
98 101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
99 102 unsigned char messageSize;
100 103
101 104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
102 105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
103 106 TM.reserved = DEFAULT_RESERVED;
104 107 TM.userApplication = CCSDS_USER_APP;
105 108 // PACKET HEADER
106 109 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
107 110 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
108 111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
109 112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> 8);
110 113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
111 114 // DATA FIELD HEADER
112 115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
113 116 TM.serviceType = TM_TYPE_TC_EXE;
114 117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
115 118 TM.destinationID = TC->sourceID;
116 119 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
117 120 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
118 121 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
119 122 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
120 123 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
121 124 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
122 125 //
123 126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> 8);
124 127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
125 128 TM.telecommand_pkt_id[0] = TC->packetID[0];
126 129 TM.telecommand_pkt_id[1] = TC->packetID[1];
127 130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
128 131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
129 132 TM.tc_service = TC->serviceType; // type of the rejected TC
130 133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
131 134 TM.byte_position = byte_position;
132 135 TM.rcv_value = rcv_value;
133 136
134 137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
135 138
136 139 // SEND DATA
137 140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
138 141 if (status != RTEMS_SUCCESSFUL) {
139 142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
140 143 }
141 144
145 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
147
142 148 return status;
143 149 }
144 150
145 151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
146 152 {
147 153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
148 154 *
149 155 * @param TC points to the TeleCommand packet that is being processed
150 156 * @param queue_id is the id of the queue which handles TM
151 157 *
152 158 * @return RTEMS directive status code:
153 159 * - RTEMS_SUCCESSFUL - message sent successfully
154 160 * - RTEMS_INVALID_ID - invalid queue id
155 161 * - RTEMS_INVALID_SIZE - invalid message size
156 162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
157 163 * - RTEMS_UNSATISFIED - out of message buffers
158 164 * - RTEMS_TOO_MANY - queue s limit has been reached
159 165 *
160 166 */
161 167
162 168 rtems_status_code status;
163 169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
164 170 unsigned char messageSize;
165 171
166 172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
167 173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
168 174 TM.reserved = DEFAULT_RESERVED;
169 175 TM.userApplication = CCSDS_USER_APP;
170 176 // PACKET HEADER
171 177 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
172 178 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
173 179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
174 180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> 8);
175 181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
176 182 // DATA FIELD HEADER
177 183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
178 184 TM.serviceType = TM_TYPE_TC_EXE;
179 185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
180 186 TM.destinationID = TC->sourceID; // default destination id
181 187 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
182 188 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
183 189 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
184 190 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
185 191 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
186 192 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
187 193 //
188 194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> 8);
189 195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
190 196 TM.telecommand_pkt_id[0] = TC->packetID[0];
191 197 TM.telecommand_pkt_id[1] = TC->packetID[1];
192 198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
193 199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
194 200 TM.tc_service = TC->serviceType; // type of the rejected TC
195 201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
196 202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
197 203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
198 204
199 205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
200 206
201 207 // SEND DATA
202 208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
203 209 if (status != RTEMS_SUCCESSFUL) {
204 210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
205 211 }
206 212
213 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
215
207 216 return status;
208 217 }
209 218
210 219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
211 220 {
212 221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
213 222 *
214 223 * @param TC points to the TeleCommand packet that is being processed
215 224 * @param queue_id is the id of the queue which handles TM
216 225 *
217 226 * @return RTEMS directive status code:
218 227 * - RTEMS_SUCCESSFUL - message sent successfully
219 228 * - RTEMS_INVALID_ID - invalid queue id
220 229 * - RTEMS_INVALID_SIZE - invalid message size
221 230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
222 231 * - RTEMS_UNSATISFIED - out of message buffers
223 232 * - RTEMS_TOO_MANY - queue s limit has been reached
224 233 *
225 234 */
226 235
227 236 rtems_status_code status;
228 237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
229 238 unsigned char messageSize;
230 239
231 240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
232 241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
233 242 TM.reserved = DEFAULT_RESERVED;
234 243 TM.userApplication = CCSDS_USER_APP;
235 244 // PACKET HEADER
236 245 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
237 246 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
238 247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
239 248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> 8);
240 249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
241 250 // DATA FIELD HEADER
242 251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
243 252 TM.serviceType = TM_TYPE_TC_EXE;
244 253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
245 254 TM.destinationID = TC->sourceID; // default destination id
246 255 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
247 256 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
248 257 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
249 258 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
250 259 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
251 260 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
252 261 //
253 262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> 8);
254 263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
255 264 TM.telecommand_pkt_id[0] = TC->packetID[0];
256 265 TM.telecommand_pkt_id[1] = TC->packetID[1];
257 266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
258 267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
259 268 TM.tc_service = TC->serviceType; // type of the rejected TC
260 269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
261 270
262 271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
263 272
264 273 // SEND DATA
265 274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
266 275 if (status != RTEMS_SUCCESSFUL) {
267 276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
268 277 }
269 278
279 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
281
270 282 return status;
271 283 }
272 284
273 285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
274 286 {
275 287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
276 288 *
277 289 * @param TC points to the TeleCommand packet that is being processed
278 290 * @param queue_id is the id of the queue which handles TM
279 291 *
280 292 * @return RTEMS directive status code:
281 293 * - RTEMS_SUCCESSFUL - message sent successfully
282 294 * - RTEMS_INVALID_ID - invalid queue id
283 295 * - RTEMS_INVALID_SIZE - invalid message size
284 296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
285 297 * - RTEMS_UNSATISFIED - out of message buffers
286 298 * - RTEMS_TOO_MANY - queue s limit has been reached
287 299 *
288 300 */
289 301
290 302 rtems_status_code status;
291 303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
292 304 unsigned char messageSize;
293 305
294 306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
295 307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
296 308 TM.reserved = DEFAULT_RESERVED;
297 309 TM.userApplication = CCSDS_USER_APP;
298 310 // PACKET HEADER
299 311 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
300 312 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
301 313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
302 314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> 8);
303 315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
304 316 // DATA FIELD HEADER
305 317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
306 318 TM.serviceType = TM_TYPE_TC_EXE;
307 319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
308 320 TM.destinationID = TC->sourceID; // default destination id
309 321 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
310 322 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
311 323 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
312 324 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
313 325 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
314 326 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
315 327 //
316 328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> 8);
317 329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
318 330 TM.telecommand_pkt_id[0] = TC->packetID[0];
319 331 TM.telecommand_pkt_id[1] = TC->packetID[1];
320 332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
321 333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
322 334 TM.tc_service = TC->serviceType; // type of the rejected TC
323 335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
324 336
325 337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
326 338
327 339 // SEND DATA
328 340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
329 341 if (status != RTEMS_SUCCESSFUL) {
330 342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
331 343 }
332 344
345 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
347
333 348 return status;
334 349 }
335 350
336 351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
337 352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
338 353 unsigned char destinationID )
339 354 {
340 355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
341 356 *
342 357 * @param TC points to the TeleCommand packet that is being processed
343 358 * @param queue_id is the id of the queue which handles TM
344 359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
345 360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
346 361 *
347 362 * @return RTEMS directive status code:
348 363 * - RTEMS_SUCCESSFUL - message sent successfully
349 364 * - RTEMS_INVALID_ID - invalid queue id
350 365 * - RTEMS_INVALID_SIZE - invalid message size
351 366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
352 367 * - RTEMS_UNSATISFIED - out of message buffers
353 368 * - RTEMS_TOO_MANY - queue s limit has been reached
354 369 *
355 370 */
356 371
357 372 rtems_status_code status;
358 373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
359 374 unsigned char messageSize;
360 375 unsigned int packetLength;
361 376 unsigned char *packetDataField;
362 377
363 378 packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; // compute the packet length parameter
364 379 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
365 380
366 381 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
367 382 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
368 383 TM.reserved = DEFAULT_RESERVED;
369 384 TM.userApplication = CCSDS_USER_APP;
370 385 // PACKET HEADER
371 386 TM.packetID[0] = (unsigned char) (TM_PACKET_ID_TC_EXE >> 8);
372 387 TM.packetID[1] = (unsigned char) (TM_PACKET_ID_TC_EXE );
373 388 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
374 389 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> 8);
375 390 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
376 391 // DATA FIELD HEADER
377 392 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
378 393 TM.serviceType = TM_TYPE_TC_EXE;
379 394 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
380 395 TM.destinationID = destinationID;
381 396 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
382 397 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
383 398 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
384 399 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
385 400 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
386 401 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
387 402 //
388 403 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> 8);
389 404 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
390 405 TM.telecommand_pkt_id[0] = TC->packetID[0];
391 406 TM.telecommand_pkt_id[1] = TC->packetID[1];
392 407 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
393 408 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
394 409 TM.tc_service = TC->serviceType; // type of the rejected TC
395 410 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
396 411 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
397 412 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
398 413 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
399 414 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
400 415 TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
401 416 TM.rcv_crc[1] = packetDataField[ packetLength ];
402 417 TM.computed_crc[0] = computed_CRC[0];
403 418 TM.computed_crc[1] = computed_CRC[1];
404 419
405 420 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
406 421
407 422 // SEND DATA
408 423 status = rtems_message_queue_send( queue_id, &TM, messageSize);
409 424 if (status != RTEMS_SUCCESSFUL) {
410 425 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
411 426 }
412 427
428 // UPDATE HK FIELDS
429 update_last_TC_rej( TC, TM.time );
430
413 431 return status;
414 432 }
415 433
416 434 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
417 435 {
418 436 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
419 437 *
420 438 * @param packet_sequence_control points to the packet sequence control which will be incremented
421 439 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
422 440 *
423 441 * If the destination ID is not known, a dedicated counter is incremented.
424 442 *
425 443 */
426 444
427 445 unsigned short sequence_cnt;
428 446 unsigned short segmentation_grouping_flag;
429 447 unsigned short new_packet_sequence_control;
430 448 unsigned char i;
431 449
432 450 switch (destination_id)
433 451 {
434 452 case SID_TC_GROUND:
435 453 i = GROUND;
436 454 break;
437 455 case SID_TC_MISSION_TIMELINE:
438 456 i = MISSION_TIMELINE;
439 457 break;
440 458 case SID_TC_TC_SEQUENCES:
441 459 i = TC_SEQUENCES;
442 460 break;
443 461 case SID_TC_RECOVERY_ACTION_CMD:
444 462 i = RECOVERY_ACTION_CMD;
445 463 break;
446 464 case SID_TC_BACKUP_MISSION_TIMELINE:
447 465 i = BACKUP_MISSION_TIMELINE;
448 466 break;
449 467 case SID_TC_DIRECT_CMD:
450 468 i = DIRECT_CMD;
451 469 break;
452 470 case SID_TC_SPARE_GRD_SRC1:
453 471 i = SPARE_GRD_SRC1;
454 472 break;
455 473 case SID_TC_SPARE_GRD_SRC2:
456 474 i = SPARE_GRD_SRC2;
457 475 break;
458 476 case SID_TC_OBCP:
459 477 i = OBCP;
460 478 break;
461 479 case SID_TC_SYSTEM_CONTROL:
462 480 i = SYSTEM_CONTROL;
463 481 break;
464 482 case SID_TC_AOCS:
465 483 i = AOCS;
466 484 break;
467 485 case SID_TC_RPW_INTERNAL:
468 486 i = RPW_INTERNAL;
469 487 break;
470 488 default:
471 489 i = GROUND;
472 490 break;
473 491 }
474 492
475 493 // increment the sequence counter
476 494 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
477 495 {
478 496 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
479 497 }
480 498 else
481 499 {
482 500 sequenceCounters_TC_EXE[ i ] = 0;
483 501 }
484 502
485 503 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
486 504 sequence_cnt = sequenceCounters_TC_EXE[ i ] & 0x3fff;
487 505
488 506 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
489 507
490 508 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
491 509 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
492 510
493 511 }
@@ -1,1363 +1,1358
1 1 /** Functions and tasks related to waveform packet generation.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 7 *
8 8 */
9 9
10 10 #include "wf_handler.h"
11 11
12 12 //*****************
13 13 // waveform headers
14 14 // SWF
15 15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
16 16 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
17 17 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
18 18 // CWF
19 19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ];
20 20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ];
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ];
22 22 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ];
23 23 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ];
24 24
25 25 //**************
26 26 // waveform ring
27 27 ring_node waveform_ring_f0[NB_RING_NODES_F0];
28 28 ring_node waveform_ring_f1[NB_RING_NODES_F1];
29 29 ring_node waveform_ring_f2[NB_RING_NODES_F2];
30 30 ring_node *current_ring_node_f0;
31 31 ring_node *ring_node_to_send_swf_f0;
32 32 ring_node *current_ring_node_f1;
33 33 ring_node *ring_node_to_send_swf_f1;
34 34 ring_node *ring_node_to_send_cwf_f1;
35 35 ring_node *current_ring_node_f2;
36 36 ring_node *ring_node_to_send_swf_f2;
37 37 ring_node *ring_node_to_send_cwf_f2;
38 38
39 39 bool extractSWF = false;
40 40 bool swf_f0_ready = false;
41 41 bool swf_f1_ready = false;
42 42 bool swf_f2_ready = false;
43 43
44 44 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
45 45
46 46 //*********************
47 47 // Interrupt SubRoutine
48 48
49 49 void reset_extractSWF( void )
50 50 {
51 51 extractSWF = false;
52 52 swf_f0_ready = false;
53 53 swf_f1_ready = false;
54 54 swf_f2_ready = false;
55 55 }
56 56
57 57 rtems_isr waveforms_isr( rtems_vector_number vector )
58 58 {
59 59 /** This is the interrupt sub routine called by the waveform picker core.
60 60 *
61 61 * This ISR launch different actions depending mainly on two pieces of information:
62 62 * 1. the values read in the registers of the waveform picker.
63 63 * 2. the current LFR mode.
64 64 *
65 65 */
66 66
67 67 rtems_status_code status;
68 68 static unsigned char nb_swf = 0;
69 69
70 70 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
71 71 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
72 72 { // in modes other than STANDBY and BURST, send the CWF_F3 data
73 73 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
74 74 // (1) change the receiving buffer for the waveform picker
75 75 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3_a) {
76 76 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_b);
77 77 }
78 78 else {
79 79 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_a);
80 80 }
81 81 // (2) send an event for the waveforms transmission
82 82 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
83 83 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
84 84 }
85 85 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
86 86 }
87 87 }
88 88
89 89 switch(lfrCurrentMode)
90 90 {
91 91 //********
92 92 // STANDBY
93 93 case(LFR_MODE_STANDBY):
94 94 break;
95 95
96 96 //******
97 97 // NORMAL
98 98 case(LFR_MODE_NORMAL):
99 99 if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits
100 100 {
101 101 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
102 102 }
103 103 if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits
104 104 {
105 105 // change F0 ring node
106 106 ring_node_to_send_swf_f0 = current_ring_node_f0;
107 107 current_ring_node_f0 = current_ring_node_f0->next;
108 108 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address;
109 109 // change F1 ring node
110 110 ring_node_to_send_swf_f1 = current_ring_node_f1;
111 111 current_ring_node_f1 = current_ring_node_f1->next;
112 112 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
113 113 // change F2 ring node
114 114 ring_node_to_send_swf_f2 = current_ring_node_f2;
115 115 current_ring_node_f2 = current_ring_node_f2->next;
116 116 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
117 117 //
118 118 // if (nb_swf < 2)
119 119 if (true)
120 120 {
121 121 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
122 122 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
123 123 }
124 124 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000]
125 125 nb_swf = nb_swf + 1;
126 126 }
127 127 else
128 128 {
129 129 reset_wfp_burst_enable();
130 130 nb_swf = 0;
131 131 }
132 132
133 133 }
134 134
135 135 break;
136 136
137 137 //******
138 138 // BURST
139 139 case(LFR_MODE_BURST):
140 140 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
141 141 // (1) change the receiving buffer for the waveform picker
142 142 ring_node_to_send_cwf_f2 = current_ring_node_f2;
143 143 current_ring_node_f2 = current_ring_node_f2->next;
144 144 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
145 145 // (2) send an event for the waveforms transmission
146 146 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
147 147 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
148 148 }
149 149 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
150 150 }
151 151 break;
152 152
153 153 //*****
154 154 // SBM1
155 155 case(LFR_MODE_SBM1):
156 156 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
157 157 // (0) launch snapshot extraction if needed
158 158 if (extractSWF == true)
159 159 {
160 160 ring_node_to_send_swf_f1 = current_ring_node_f1;
161 161 // extract the snapshot
162 162 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
163 163 extractSWF = false;
164 164 swf_f1_ready = true;
165 165 }
166 166 // (1) change the receiving buffer for the waveform picker
167 167 ring_node_to_send_cwf_f1 = current_ring_node_f1;
168 168 current_ring_node_f1 = current_ring_node_f1->next;
169 169 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
170 170 // (2) send an event for the the CWF1 task for transmission
171 171 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
172 172 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0
173 173 if (swf_f0_ready == true)
174 174 {
175 175 extractSWF = true;
176 176 swf_f0_ready = false;
177 177 }
178 178 if ((swf_f1_ready == true) && (swf_f2_ready == true))
179 179 {
180 180 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
181 181 swf_f1_ready = false;
182 182 swf_f2_ready = false;
183 183 }
184 184 }
185 185 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
186 186 swf_f0_ready = true;
187 187 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
188 188 }
189 189 if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit
190 190 swf_f2_ready = true;
191 191 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0
192 192 }
193 193 break;
194 194
195 195 //*****
196 196 // SBM2
197 197 case(LFR_MODE_SBM2):
198 198 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
199 199 // (0) launch snapshot extraction if needed
200 200 if (extractSWF == true)
201 201 {
202 202 ring_node_to_send_swf_f2 = current_ring_node_f2;
203 203 // extract the snapshot
204 204 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM2 );
205 205 // send the snapshot when build, SWBD priority < WFRM priority
206 206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
207 207 extractSWF = false;
208 208 }
209 209 // (1) change the receiving buffer for the waveform picker
210 210 ring_node_to_send_cwf_f2 = current_ring_node_f2;
211 211 current_ring_node_f2 = current_ring_node_f2->next;
212 212 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
213 213 // (2) send an event for the waveforms transmission
214 214 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
215 215 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
216 216 // (3) check whether swf_fo and swf_f& are ready or not
217 217 if (swf_f0_ready && swf_f1_ready)
218 218 {
219 219 extractSWF = true;
220 220 swf_f0_ready = false;
221 221 swf_f1_ready = false;
222 222 }
223 223 }
224 224 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
225 225 swf_f0_ready = true;
226 226 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
227 227 }
228 228 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
229 229 swf_f1_ready = true;
230 230 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0
231 231 }
232 232 break;
233 233
234 234 //********
235 235 // DEFAULT
236 236 default:
237 237 break;
238 238 }
239 239 }
240 240
241 241 //************
242 242 // RTEMS TASKS
243 243
244 244 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
245 245 {
246 246 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
247 247 *
248 248 * @param unused is the starting argument of the RTEMS task
249 249 *
250 250 * The following data packets are sent by this task:
251 251 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
252 252 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
253 253 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
254 254 *
255 255 */
256 256
257 257 rtems_event_set event_out;
258 258 rtems_id queue_id;
259 259 rtems_status_code status;
260 260
261 261 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
262 262 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
263 263 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
264 264
265 265 init_waveforms();
266 266
267 267 status = get_message_queue_id_send( &queue_id );
268 268 if (status != RTEMS_SUCCESSFUL)
269 269 {
270 270 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
271 271 }
272 272
273 273 BOOT_PRINTF("in WFRM ***\n")
274 274
275 275 while(1){
276 276 // wait for an RTEMS_EVENT
277 277 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
278 278 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
279 279 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
280 280 if (event_out == RTEMS_EVENT_MODE_NORMAL)
281 281 {
282 282 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
283 283 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
284 284 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
285 285 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
286 286 }
287 287 if (event_out == RTEMS_EVENT_MODE_SBM1)
288 288 {
289 289 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
290 290 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
291 291 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id);
292 292 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
293 293 }
294 294 if (event_out == RTEMS_EVENT_MODE_SBM2)
295 295 {
296 296 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
297 297 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
298 298 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
299 299 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id);
300 300 }
301 301 }
302 302 }
303 303
304 304 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
305 305 {
306 306 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
307 307 *
308 308 * @param unused is the starting argument of the RTEMS task
309 309 *
310 310 * The following data packet is sent by this task:
311 311 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
312 312 *
313 313 */
314 314
315 315 rtems_event_set event_out;
316 316 rtems_id queue_id;
317 317 rtems_status_code status;
318 318
319 319 init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 );
320 320 init_header_continuous_cwf3_light_table( headerCWF_F3_light );
321 321
322 322 status = get_message_queue_id_send( &queue_id );
323 323 if (status != RTEMS_SUCCESSFUL)
324 324 {
325 325 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
326 326 }
327 327
328 328 BOOT_PRINTF("in CWF3 ***\n")
329 329
330 330 while(1){
331 331 // wait for an RTEMS_EVENT
332 332 rtems_event_receive( RTEMS_EVENT_0,
333 333 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
334 334 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
335 335 {
336 336 PRINTF("send CWF_LONG_F3\n")
337 337 }
338 338 else
339 339 {
340 340 PRINTF("send CWF_F3 (light)\n")
341 341 }
342 342 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3_a) {
343 343 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
344 344 {
345 345 send_waveform_CWF( wf_cont_f3_b, SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
346 346 }
347 347 else
348 348 {
349 349 send_waveform_CWF3_light( wf_cont_f3_b, headerCWF_F3_light, queue_id );
350 350 }
351 351 }
352 352 else
353 353 {
354 354 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
355 355 {
356 356 send_waveform_CWF( wf_cont_f3_a, SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
357 357 }
358 358 else
359 359 {
360 360 send_waveform_CWF3_light( wf_cont_f3_a, headerCWF_F3_light, queue_id );
361 361 }
362 362
363 363 }
364 364 }
365 365 }
366 366
367 367 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
368 368 {
369 369 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
370 370 *
371 371 * @param unused is the starting argument of the RTEMS task
372 372 *
373 373 * The following data packet is sent by this function:
374 374 * - TM_LFR_SCIENCE_BURST_CWF_F2
375 375 * - TM_LFR_SCIENCE_SBM2_CWF_F2
376 376 *
377 377 */
378 378
379 379 rtems_event_set event_out;
380 380 rtems_id queue_id;
381 381 rtems_status_code status;
382 382
383 383 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
384 384 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
385 385
386 386 status = get_message_queue_id_send( &queue_id );
387 387 if (status != RTEMS_SUCCESSFUL)
388 388 {
389 389 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
390 390 }
391 391
392 392 BOOT_PRINTF("in CWF2 ***\n")
393 393
394 394 while(1){
395 395 // wait for an RTEMS_EVENT
396 396 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
397 397 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
398 398 if (event_out == RTEMS_EVENT_MODE_BURST)
399 399 {
400 400 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
401 401 }
402 402 if (event_out == RTEMS_EVENT_MODE_SBM2)
403 403 {
404 404 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
405 405 }
406 406 }
407 407 }
408 408
409 409 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
410 410 {
411 411 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
412 412 *
413 413 * @param unused is the starting argument of the RTEMS task
414 414 *
415 415 * The following data packet is sent by this function:
416 416 * - TM_LFR_SCIENCE_SBM1_CWF_F1
417 417 *
418 418 */
419 419
420 420 rtems_event_set event_out;
421 421 rtems_id queue_id;
422 422 rtems_status_code status;
423 423
424 424 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
425 425
426 426 status = get_message_queue_id_send( &queue_id );
427 427 if (status != RTEMS_SUCCESSFUL)
428 428 {
429 429 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
430 430 }
431 431
432 432 BOOT_PRINTF("in CWF1 ***\n")
433 433
434 434 while(1){
435 435 // wait for an RTEMS_EVENT
436 436 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
437 437 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
438 438 send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
439 439 }
440 440 }
441 441
442 442 rtems_task swbd_task(rtems_task_argument argument)
443 443 {
444 444 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
445 445 *
446 446 * @param unused is the starting argument of the RTEMS task
447 447 *
448 448 */
449 449
450 450 rtems_event_set event_out;
451 451
452 452 BOOT_PRINTF("in SWBD ***\n")
453 453
454 454 while(1){
455 455 // wait for an RTEMS_EVENT
456 456 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
457 457 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
458 458 if (event_out == RTEMS_EVENT_MODE_SBM1)
459 459 {
460 460 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 );
461 461 }
462 462 else if (event_out == RTEMS_EVENT_MODE_SBM2)
463 463 {
464 464 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 );
465 465 }
466 466 else
467 467 {
468 468 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
469 469 }
470 470 }
471 471 }
472 472
473 473 //******************
474 474 // general functions
475 475 void init_waveforms( void )
476 476 {
477 477 int i = 0;
478 478
479 479 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
480 480 {
481 481 //***
482 482 // F0
483 483 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x88887777; //
484 484 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; //
485 485 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0x44443333; //
486 486
487 487 //***
488 488 // F1
489 489 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x22221111;
490 490 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x44443333;
491 491 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
492 492
493 493 //***
494 494 // F2
495 495 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x44443333;
496 496 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111;
497 497 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
498 498
499 499 //***
500 500 // F3
501 501 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 0 ] = val1;
502 502 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 1 ] = val2;
503 503 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 2 ] = 0xaaaa0000;
504 504 }
505 505 }
506 506
507 507 void init_waveform_rings( void )
508 508 {
509 509 unsigned char i;
510 510
511 511 // F0 RING
512 512 waveform_ring_f0[0].next = (ring_node*) &waveform_ring_f0[1];
513 513 waveform_ring_f0[0].previous = (ring_node*) &waveform_ring_f0[NB_RING_NODES_F0-1];
514 514 waveform_ring_f0[0].buffer_address = (int) &wf_snap_f0[0][0];
515 515
516 516 waveform_ring_f0[NB_RING_NODES_F0-1].next = (ring_node*) &waveform_ring_f0[0];
517 517 waveform_ring_f0[NB_RING_NODES_F0-1].previous = (ring_node*) &waveform_ring_f0[NB_RING_NODES_F0-2];
518 518 waveform_ring_f0[NB_RING_NODES_F0-1].buffer_address = (int) &wf_snap_f0[NB_RING_NODES_F0-1][0];
519 519
520 520 for(i=1; i<NB_RING_NODES_F0-1; i++)
521 521 {
522 522 waveform_ring_f0[i].next = (ring_node*) &waveform_ring_f0[i+1];
523 523 waveform_ring_f0[i].previous = (ring_node*) &waveform_ring_f0[i-1];
524 524 waveform_ring_f0[i].buffer_address = (int) &wf_snap_f0[i][0];
525 525 }
526 526
527 527 // F1 RING
528 528 waveform_ring_f1[0].next = (ring_node*) &waveform_ring_f1[1];
529 529 waveform_ring_f1[0].previous = (ring_node*) &waveform_ring_f1[NB_RING_NODES_F1-1];
530 530 waveform_ring_f1[0].buffer_address = (int) &wf_snap_f1[0][0];
531 531
532 532 waveform_ring_f1[NB_RING_NODES_F1-1].next = (ring_node*) &waveform_ring_f1[0];
533 533 waveform_ring_f1[NB_RING_NODES_F1-1].previous = (ring_node*) &waveform_ring_f1[NB_RING_NODES_F1-2];
534 534 waveform_ring_f1[NB_RING_NODES_F1-1].buffer_address = (int) &wf_snap_f1[NB_RING_NODES_F1-1][0];
535 535
536 536 for(i=1; i<NB_RING_NODES_F1-1; i++)
537 537 {
538 538 waveform_ring_f1[i].next = (ring_node*) &waveform_ring_f1[i+1];
539 539 waveform_ring_f1[i].previous = (ring_node*) &waveform_ring_f1[i-1];
540 540 waveform_ring_f1[i].buffer_address = (int) &wf_snap_f1[i][0];
541 541 }
542 542
543 543 // F2 RING
544 544 waveform_ring_f2[0].next = (ring_node*) &waveform_ring_f2[1];
545 545 waveform_ring_f2[0].previous = (ring_node*) &waveform_ring_f2[NB_RING_NODES_F2-1];
546 546 waveform_ring_f2[0].buffer_address = (int) &wf_snap_f2[0][0];
547 547
548 548 waveform_ring_f2[NB_RING_NODES_F2-1].next = (ring_node*) &waveform_ring_f2[0];
549 549 waveform_ring_f2[NB_RING_NODES_F2-1].previous = (ring_node*) &waveform_ring_f2[NB_RING_NODES_F2-2];
550 550 waveform_ring_f2[NB_RING_NODES_F2-1].buffer_address = (int) &wf_snap_f2[NB_RING_NODES_F2-1][0];
551 551
552 552 for(i=1; i<NB_RING_NODES_F2-1; i++)
553 553 {
554 554 waveform_ring_f2[i].next = (ring_node*) &waveform_ring_f2[i+1];
555 555 waveform_ring_f2[i].previous = (ring_node*) &waveform_ring_f2[i-1];
556 556 waveform_ring_f2[i].buffer_address = (int) &wf_snap_f2[i][0];
557 557 }
558 558
559 559 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
560 560 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
561 561 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
562 562
563 563 }
564 564
565 565 void reset_current_ring_nodes( void )
566 566 {
567 567 current_ring_node_f0 = waveform_ring_f0;
568 568 ring_node_to_send_swf_f0 = waveform_ring_f0;
569 569
570 570 current_ring_node_f1 = waveform_ring_f1;
571 571 ring_node_to_send_cwf_f1 = waveform_ring_f1;
572 572 ring_node_to_send_swf_f1 = waveform_ring_f1;
573 573
574 574 current_ring_node_f2 = waveform_ring_f2;
575 575 ring_node_to_send_cwf_f2 = waveform_ring_f2;
576 576 ring_node_to_send_swf_f2 = waveform_ring_f2;
577 577 }
578 578
579 579 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
580 580 {
581 581 unsigned char i;
582 582
583 583 for (i=0; i<7; i++)
584 584 {
585 585 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
586 586 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
587 587 headerSWF[ i ].reserved = DEFAULT_RESERVED;
588 588 headerSWF[ i ].userApplication = CCSDS_USER_APP;
589 589 headerSWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
590 590 headerSWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
591 591 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
592 592 if (i == 6)
593 593 {
594 594 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
595 595 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
596 596 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
597 597 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 );
598 598 }
599 599 else
600 600 {
601 601 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
602 602 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
603 603 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
604 604 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 );
605 605 }
606 606 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
607 607 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
608 608 headerSWF[ i ].pktNr = i+1; // PKT_NR
609 609 // DATA FIELD HEADER
610 610 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
611 611 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
612 612 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
613 613 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
614 614 // AUXILIARY DATA HEADER
615 615 headerSWF[ i ].time[0] = 0x00;
616 616 headerSWF[ i ].time[0] = 0x00;
617 617 headerSWF[ i ].time[0] = 0x00;
618 618 headerSWF[ i ].time[0] = 0x00;
619 619 headerSWF[ i ].time[0] = 0x00;
620 620 headerSWF[ i ].time[0] = 0x00;
621 621 headerSWF[ i ].sid = sid;
622 622 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
623 623 }
624 624 return LFR_SUCCESSFUL;
625 625 }
626 626
627 627 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
628 628 {
629 629 unsigned int i;
630 630
631 631 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++)
632 632 {
633 633 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
634 634 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
635 635 headerCWF[ i ].reserved = DEFAULT_RESERVED;
636 636 headerCWF[ i ].userApplication = CCSDS_USER_APP;
637 637 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
638 638 {
639 639 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2 >> 8);
640 640 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2);
641 641 }
642 642 else
643 643 {
644 644 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
645 645 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
646 646 }
647 647 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
648 648 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
649 649 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
650 650 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
651 651 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF );
652 652 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
653 653 // DATA FIELD HEADER
654 654 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
655 655 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
656 656 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
657 657 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
658 658 // AUXILIARY DATA HEADER
659 659 headerCWF[ i ].sid = sid;
660 660 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
661 661 headerCWF[ i ].time[0] = 0x00;
662 662 headerCWF[ i ].time[0] = 0x00;
663 663 headerCWF[ i ].time[0] = 0x00;
664 664 headerCWF[ i ].time[0] = 0x00;
665 665 headerCWF[ i ].time[0] = 0x00;
666 666 headerCWF[ i ].time[0] = 0x00;
667 667 }
668 668 return LFR_SUCCESSFUL;
669 669 }
670 670
671 671 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
672 672 {
673 673 unsigned int i;
674 674
675 675 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++)
676 676 {
677 677 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
678 678 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
679 679 headerCWF[ i ].reserved = DEFAULT_RESERVED;
680 680 headerCWF[ i ].userApplication = CCSDS_USER_APP;
681 681
682 682 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
683 683 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
684 684
685 685 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
686 686 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
687 687 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
688 688 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
689 689 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
690 690
691 691 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
692 692 // DATA FIELD HEADER
693 693 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
694 694 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
695 695 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
696 696 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
697 697 // AUXILIARY DATA HEADER
698 698 headerCWF[ i ].sid = SID_NORM_CWF_F3;
699 699 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
700 700 headerCWF[ i ].time[0] = 0x00;
701 701 headerCWF[ i ].time[0] = 0x00;
702 702 headerCWF[ i ].time[0] = 0x00;
703 703 headerCWF[ i ].time[0] = 0x00;
704 704 headerCWF[ i ].time[0] = 0x00;
705 705 headerCWF[ i ].time[0] = 0x00;
706 706 }
707 707 return LFR_SUCCESSFUL;
708 708 }
709 709
710 710 int send_waveform_SWF( volatile int *waveform, unsigned int sid,
711 711 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
712 712 {
713 713 /** This function sends SWF CCSDS packets (F2, F1 or F0).
714 714 *
715 715 * @param waveform points to the buffer containing the data that will be send.
716 716 * @param sid is the source identifier of the data that will be sent.
717 717 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
718 718 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
719 719 * contain information to setup the transmission of the data packets.
720 720 *
721 721 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
722 722 *
723 723 */
724 724
725 725 unsigned int i;
726 726 int ret;
727 727 unsigned int coarseTime;
728 728 unsigned int fineTime;
729 729 rtems_status_code status;
730 730 spw_ioctl_pkt_send spw_ioctl_send_SWF;
731 731
732 732 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
733 733 spw_ioctl_send_SWF.options = 0;
734 734
735 735 ret = LFR_DEFAULT;
736 736
737 737 coarseTime = waveform[0];
738 738 fineTime = waveform[1];
739 739
740 740 for (i=0; i<7; i++) // send waveform
741 741 {
742 742 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET];
743 743 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
744 744 // BUILD THE DATA
745 745 if (i==6) {
746 746 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
747 747 }
748 748 else {
749 749 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
750 750 }
751 751 // SET PACKET SEQUENCE COUNTER
752 752 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
753 753 // SET PACKET TIME
754 754 compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime );
755 755 //
756 756 headerSWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
757 757 headerSWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
758 758 headerSWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
759 759 headerSWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
760 760 headerSWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
761 761 headerSWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
762 762 // SEND PACKET
763 763 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
764 764 if (status != RTEMS_SUCCESSFUL) {
765 765 printf("%d-%d, ERR %d\n", sid, i, (int) status);
766 766 ret = LFR_DEFAULT;
767 767 }
768 768 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
769 769 }
770 770
771 771 return ret;
772 772 }
773 773
774 774 int send_waveform_CWF(volatile int *waveform, unsigned int sid,
775 775 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
776 776 {
777 777 /** This function sends CWF CCSDS packets (F2, F1 or F0).
778 778 *
779 779 * @param waveform points to the buffer containing the data that will be send.
780 780 * @param sid is the source identifier of the data that will be sent.
781 781 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
782 782 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
783 783 * contain information to setup the transmission of the data packets.
784 784 *
785 785 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
786 786 *
787 787 */
788 788
789 789 unsigned int i;
790 790 int ret;
791 791 unsigned int coarseTime;
792 792 unsigned int fineTime;
793 793 rtems_status_code status;
794 794 spw_ioctl_pkt_send spw_ioctl_send_CWF;
795 795
796 796 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
797 797 spw_ioctl_send_CWF.options = 0;
798 798
799 799 ret = LFR_DEFAULT;
800 800
801 801 coarseTime = waveform[0];
802 802 fineTime = waveform[1];
803 803
804 804 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
805 805 {
806 806 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) + TIME_OFFSET];
807 807 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
808 808 // BUILD THE DATA
809 809 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
810 810 // SET PACKET SEQUENCE COUNTER
811 811 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
812 812 // SET PACKET TIME
813 813 compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime);
814 814 //
815 815 headerCWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
816 816 headerCWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
817 817 headerCWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
818 818 headerCWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
819 819 headerCWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
820 820 headerCWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
821 821 // SEND PACKET
822 822 if (sid == SID_NORM_CWF_LONG_F3)
823 823 {
824 824 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
825 825 if (status != RTEMS_SUCCESSFUL) {
826 826 printf("%d-%d, ERR %d\n", sid, i, (int) status);
827 827 ret = LFR_DEFAULT;
828 828 }
829 829 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
830 830 }
831 831 else
832 832 {
833 833 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
834 834 if (status != RTEMS_SUCCESSFUL) {
835 835 printf("%d-%d, ERR %d\n", sid, i, (int) status);
836 836 ret = LFR_DEFAULT;
837 837 }
838 838 }
839 839 }
840 840
841 841 return ret;
842 842 }
843 843
844 844 int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
845 845 {
846 846 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
847 847 *
848 848 * @param waveform points to the buffer containing the data that will be send.
849 849 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
850 850 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
851 851 * contain information to setup the transmission of the data packets.
852 852 *
853 853 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
854 854 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
855 855 *
856 856 */
857 857
858 858 unsigned int i;
859 859 int ret;
860 860 unsigned int coarseTime;
861 861 unsigned int fineTime;
862 862 rtems_status_code status;
863 863 spw_ioctl_pkt_send spw_ioctl_send_CWF;
864 864 char *sample;
865 865
866 866 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
867 867 spw_ioctl_send_CWF.options = 0;
868 868
869 869 ret = LFR_DEFAULT;
870 870
871 871 //**********************
872 872 // BUILD CWF3_light DATA
873 873 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
874 874 {
875 875 sample = (char*) &waveform[ (i * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
876 876 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES ] = sample[ 0 ];
877 877 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 + TIME_OFFSET_IN_BYTES ] = sample[ 1 ];
878 878 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 + TIME_OFFSET_IN_BYTES ] = sample[ 2 ];
879 879 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 + TIME_OFFSET_IN_BYTES ] = sample[ 3 ];
880 880 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 + TIME_OFFSET_IN_BYTES ] = sample[ 4 ];
881 881 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ];
882 882 }
883 883
884 884 coarseTime = waveform[0];
885 885 fineTime = waveform[1];
886 886
887 887 //*********************
888 888 // SEND CWF3_light DATA
889 889 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
890 890 {
891 891 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES];
892 892 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
893 893 // BUILD THE DATA
894 894 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
895 895 // SET PACKET SEQUENCE COUNTER
896 896 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
897 897 // SET PACKET TIME
898 898 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime );
899 899 //
900 900 headerCWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
901 901 headerCWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
902 902 headerCWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
903 903 headerCWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
904 904 headerCWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
905 905 headerCWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
906 906 // SEND PACKET
907 907 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
908 908 if (status != RTEMS_SUCCESSFUL) {
909 909 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
910 910 ret = LFR_DEFAULT;
911 911 }
912 912 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
913 913 }
914 914
915 915 return ret;
916 916 }
917 917
918 918 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
919 919 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
920 920 {
921 921 unsigned long long int acquisitionTimeAsLong;
922 922 unsigned char localAcquisitionTime[6];
923 923 double deltaT;
924 924
925 925 deltaT = 0.;
926 926
927 927 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 8 );
928 928 localAcquisitionTime[1] = (unsigned char) ( coarseTime );
929 929 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 24 );
930 930 localAcquisitionTime[3] = (unsigned char) ( coarseTime >> 16 );
931 931 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 24 );
932 932 localAcquisitionTime[5] = (unsigned char) ( fineTime >> 16 );
933 933
934 934 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
935 935 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
936 936 + ( localAcquisitionTime[2] << 24 )
937 937 + ( localAcquisitionTime[3] << 16 )
938 938 + ( localAcquisitionTime[4] << 8 )
939 939 + ( localAcquisitionTime[5] );
940 940
941 941 switch( sid )
942 942 {
943 943 case SID_NORM_SWF_F0:
944 944 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
945 945 break;
946 946
947 947 case SID_NORM_SWF_F1:
948 948 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
949 949 break;
950 950
951 951 case SID_NORM_SWF_F2:
952 952 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
953 953 break;
954 954
955 955 case SID_SBM1_CWF_F1:
956 956 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
957 957 break;
958 958
959 959 case SID_SBM2_CWF_F2:
960 960 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
961 961 break;
962 962
963 963 case SID_BURST_CWF_F2:
964 964 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
965 965 break;
966 966
967 967 case SID_NORM_CWF_F3:
968 968 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
969 969 break;
970 970
971 971 case SID_NORM_CWF_LONG_F3:
972 972 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
973 973 break;
974 974
975 975 default:
976 976 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid)
977 977 deltaT = 0.;
978 978 break;
979 979 }
980 980
981 981 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
982 982 //
983 983 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
984 984 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
985 985 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
986 986 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
987 987 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
988 988 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
989 989
990 990 }
991 991
992 992 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel )
993 993 {
994 994 unsigned int i;
995 995 unsigned long long int centerTime_asLong;
996 996 unsigned long long int acquisitionTimeF0_asLong;
997 997 unsigned long long int acquisitionTime_asLong;
998 998 unsigned long long int bufferAcquisitionTime_asLong;
999 999 unsigned char *ptr1;
1000 1000 unsigned char *ptr2;
1001 1001 unsigned char nb_ring_nodes;
1002 1002 unsigned long long int frequency_asLong;
1003 1003 unsigned long long int nbTicksPerSample_asLong;
1004 1004 unsigned long long int nbSamplesPart1_asLong;
1005 1005 unsigned long long int sampleOffset_asLong;
1006 1006
1007 1007 unsigned int deltaT_F0;
1008 1008 unsigned int deltaT_F1;
1009 1009 unsigned long long int deltaT_F2;
1010 1010
1011 1011 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1012 1012 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
1013 1013 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
1014 1014 sampleOffset_asLong = 0x00;
1015 1015
1016 1016 // get the f0 acquisition time
1017 1017 build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 );
1018 PRINTF1("acquisitionTimeF0_asLong %llx \n", acquisitionTimeF0_asLong)
1019 1018
1020 1019 // compute the central reference time
1021 1020 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
1022 PRINTF1("centerTime_asLong %llx \n", centerTime_asLong)
1023 1021
1024 1022 // compute the acquisition time of the current snapshot
1025 1023 switch(frequencyChannel)
1026 1024 {
1027 1025 case 1: // 1 is for F1 = 4096 Hz
1028 1026 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
1029 1027 nb_ring_nodes = NB_RING_NODES_F1;
1030 1028 frequency_asLong = 4096;
1031 1029 nbTicksPerSample_asLong = 16; // 65536 / 4096;
1032 1030 break;
1033 1031 case 2: // 2 is for F2 = 256 Hz
1034 1032 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
1035 1033 nb_ring_nodes = NB_RING_NODES_F2;
1036 1034 frequency_asLong = 256;
1037 1035 nbTicksPerSample_asLong = 256; // 65536 / 256;
1038 1036 break;
1039 1037 default:
1040 1038 acquisitionTime_asLong = centerTime_asLong;
1041 1039 frequency_asLong = 256;
1042 1040 nbTicksPerSample_asLong = 256;
1043 1041 break;
1044 1042 }
1045 PRINTF1("acquisitionTime_asLong %llx\n", acquisitionTime_asLong)
1046 1043
1047 1044 //****************************************************************************
1048 1045 // 1) search the ring_node with the acquisition time <= acquisitionTime_asLong
1049 1046 for (i=0; i<nb_ring_nodes; i++)
1050 1047 {
1051 1048 PRINTF1("%d ... ", i)
1052 1049 build_acquisition_time( &bufferAcquisitionTime_asLong, ring_node_to_send );
1053 1050 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
1054 1051 {
1055 1052 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
1056 1053 break;
1057 1054 }
1058 1055 ring_node_to_send = ring_node_to_send->previous;
1059 1056 }
1060 1057
1061 1058 //*************************************************
1062 1059 // (2) once the buffer is found, build the snapshot
1063 1060
1064 1061 // compute the number of samples to take in the current buffer
1065 1062 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
1066 1063 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
1067 PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1 = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1068 1064
1069 1065 // compute the final acquisition time
1070 1066 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
1071 1067 sampleOffset_asLong * nbTicksPerSample_asLong;
1072 PRINTF1("FINAL acquisitionTime_asLong %llx\n\n", acquisitionTime_asLong)
1073 1068
1074 1069 // copy the acquisition time at the beginning of the extrated snapshot
1075 1070 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1076 1071 ptr2 = (unsigned char*) wf_snap_extracted;
1077 1072 ptr2[0] = ptr1[ 2 + 2 ];
1078 1073 ptr2[1] = ptr1[ 3 + 2 ];
1079 1074 ptr2[2] = ptr1[ 0 + 2 ];
1080 1075 ptr2[3] = ptr1[ 1 + 2 ];
1081 1076 ptr2[4] = ptr1[ 4 + 2 ];
1082 1077 ptr2[5] = ptr1[ 5 + 2 ];
1083 1078
1084 1079 // re set the synchronization bit
1085 1080
1086 1081
1087 1082 // copy the part 1 of the snapshot in the extracted buffer
1088 1083 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1089 1084 {
1090 1085 wf_snap_extracted[i + TIME_OFFSET] =
1091 1086 ((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET];
1092 1087 }
1093 1088 // copy the part 2 of the snapshot in the extracted buffer
1094 1089 ring_node_to_send = ring_node_to_send->next;
1095 1090 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1096 1091 {
1097 1092 wf_snap_extracted[i + TIME_OFFSET] =
1098 1093 ((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET];
1099 1094 }
1100 1095 }
1101 1096
1102 1097 void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node )
1103 1098 {
1104 1099 unsigned char *acquisitionTimeCharPtr;
1105 1100
1106 1101 acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address;
1107 1102
1108 1103 *acquisitionTimeAslong = 0x00;
1109 1104 *acquisitionTimeAslong = ( acquisitionTimeCharPtr[0] << 24 )
1110 1105 + ( acquisitionTimeCharPtr[1] << 16 )
1111 1106 + ( (unsigned long long int) (acquisitionTimeCharPtr[2] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
1112 1107 + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 32 )
1113 1108 + ( acquisitionTimeCharPtr[4] << 8 )
1114 1109 + ( acquisitionTimeCharPtr[5] );
1115 1110 }
1116 1111
1117 1112 //**************
1118 1113 // wfp registers
1119 1114 void reset_wfp_burst_enable(void)
1120 1115 {
1121 1116 /** This function resets the waveform picker burst_enable register.
1122 1117 *
1123 1118 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1124 1119 *
1125 1120 */
1126 1121
1127 1122 waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1128 1123 }
1129 1124
1130 1125 void reset_wfp_status( void )
1131 1126 {
1132 1127 /** This function resets the waveform picker status register.
1133 1128 *
1134 1129 * All status bits are set to 0 [new_err full_err full].
1135 1130 *
1136 1131 */
1137 1132
1138 1133 waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1139 1134 }
1140 1135
1141 1136 void reset_waveform_picker_regs(void)
1142 1137 {
1143 1138 /** This function resets the waveform picker module registers.
1144 1139 *
1145 1140 * The registers affected by this function are located at the following offset addresses:
1146 1141 * - 0x00 data_shaping
1147 1142 * - 0x04 run_burst_enable
1148 1143 * - 0x08 addr_data_f0
1149 1144 * - 0x0C addr_data_f1
1150 1145 * - 0x10 addr_data_f2
1151 1146 * - 0x14 addr_data_f3
1152 1147 * - 0x18 status
1153 1148 * - 0x1C delta_snapshot
1154 1149 * - 0x20 delta_f0
1155 1150 * - 0x24 delta_f0_2
1156 1151 * - 0x28 delta_f1
1157 1152 * - 0x2c delta_f2
1158 1153 * - 0x30 nb_data_by_buffer
1159 1154 * - 0x34 nb_snapshot_param
1160 1155 * - 0x38 start_date
1161 1156 * - 0x3c nb_word_in_buffer
1162 1157 *
1163 1158 */
1164 1159
1165 waveform_picker_regs->data_shaping = 0x01; // 0x00 *** R1 R0 SP1 SP0 BW
1160 // waveform_picker_regs->data_shaping = 0x01; // 0x00 *** R1 R0 SP1 SP0 BW
1166 1161 waveform_picker_regs->run_burst_enable = 0x00; // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1167 1162 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08
1168 1163 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c
1169 1164 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10
1170 1165 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_a); // 0x14
1171 1166 waveform_picker_regs->status = 0x00; // 0x18
1172 1167 //
1173 1168 set_wfp_delta_snapshot(); // 0x1c
1174 1169 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1175 1170 set_wfp_delta_f1(); // 0x28
1176 1171 set_wfp_delta_f2(); // 0x2c
1177 1172 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1178 1173 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1179 1174 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1180 1175 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1181 1176 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1182 1177 // 2688 = 8 * 336
1183 1178 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1184 1179 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1185 1180 waveform_picker_regs->start_date = 0x00; // 0x38
1186 1181 waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066
1187 1182 }
1188 1183
1189 1184 void set_wfp_data_shaping( void )
1190 1185 {
1191 1186 /** This function sets the data_shaping register of the waveform picker module.
1192 1187 *
1193 1188 * The value is read from one field of the parameter_dump_packet structure:\n
1194 1189 * bw_sp0_sp1_r0_r1
1195 1190 *
1196 1191 */
1197 1192
1198 1193 unsigned char data_shaping;
1199 1194
1200 1195 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1201 1196 // waveform picker : [R1 R0 SP1 SP0 BW]
1202 1197
1203 1198 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
1204 1199
1205 1200 waveform_picker_regs->data_shaping =
1206 1201 ( (data_shaping & 0x10) >> 4 ) // BW
1207 1202 + ( (data_shaping & 0x08) >> 2 ) // SP0
1208 1203 + ( (data_shaping & 0x04) ) // SP1
1209 1204 + ( (data_shaping & 0x02) << 2 ) // R0
1210 1205 + ( (data_shaping & 0x01) << 4 ); // R1
1211 1206 }
1212 1207
1213 1208 void set_wfp_burst_enable_register( unsigned char mode )
1214 1209 {
1215 1210 /** This function sets the waveform picker burst_enable register depending on the mode.
1216 1211 *
1217 1212 * @param mode is the LFR mode to launch.
1218 1213 *
1219 1214 * The burst bits shall be before the enable bits.
1220 1215 *
1221 1216 */
1222 1217
1223 1218 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1224 1219 // the burst bits shall be set first, before the enable bits
1225 1220 switch(mode) {
1226 1221 case(LFR_MODE_NORMAL):
1227 1222 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1228 1223 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1229 1224 break;
1230 1225 case(LFR_MODE_BURST):
1231 1226 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1232 1227 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1233 1228 break;
1234 1229 case(LFR_MODE_SBM1):
1235 1230 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1236 1231 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1237 1232 break;
1238 1233 case(LFR_MODE_SBM2):
1239 1234 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1240 1235 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1241 1236 break;
1242 1237 default:
1243 1238 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1244 1239 break;
1245 1240 }
1246 1241 }
1247 1242
1248 1243 void set_wfp_delta_snapshot( void )
1249 1244 {
1250 1245 /** This function sets the delta_snapshot register of the waveform picker module.
1251 1246 *
1252 1247 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1253 1248 * - sy_lfr_n_swf_p[0]
1254 1249 * - sy_lfr_n_swf_p[1]
1255 1250 *
1256 1251 */
1257 1252
1258 1253 unsigned int delta_snapshot;
1259 1254 unsigned int delta_snapshot_in_T2;
1260 1255
1261 1256 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1262 1257 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1263 1258
1264 1259 delta_snapshot_in_T2 = delta_snapshot * 256;
1265 1260 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2; // max 4 bytes
1266 1261 }
1267 1262
1268 1263 void set_wfp_delta_f0_f0_2( void )
1269 1264 {
1270 1265 unsigned int delta_snapshot;
1271 1266 unsigned int nb_samples_per_snapshot;
1272 1267 float delta_f0_in_float;
1273 1268
1274 1269 delta_snapshot = waveform_picker_regs->delta_snapshot;
1275 1270 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1276 1271 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1277 1272
1278 1273 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1279 1274 waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits
1280 1275 }
1281 1276
1282 1277 void set_wfp_delta_f1( void )
1283 1278 {
1284 1279 unsigned int delta_snapshot;
1285 1280 unsigned int nb_samples_per_snapshot;
1286 1281 float delta_f1_in_float;
1287 1282
1288 1283 delta_snapshot = waveform_picker_regs->delta_snapshot;
1289 1284 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1290 1285 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1291 1286
1292 1287 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1293 1288 }
1294 1289
1295 1290 void set_wfp_delta_f2()
1296 1291 {
1297 1292 unsigned int delta_snapshot;
1298 1293 unsigned int nb_samples_per_snapshot;
1299 1294
1300 1295 delta_snapshot = waveform_picker_regs->delta_snapshot;
1301 1296 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1302 1297
1303 1298 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1304 1299 }
1305 1300
1306 1301 //*****************
1307 1302 // local parameters
1308 1303 void set_local_nb_interrupt_f0_MAX( void )
1309 1304 {
1310 1305 /** This function sets the value of the nb_interrupt_f0_MAX local parameter.
1311 1306 *
1312 1307 * This parameter is used for the SM validation only.\n
1313 1308 * The software waits param_local.local_nb_interrupt_f0_MAX interruptions from the spectral matrices
1314 1309 * module before launching a basic processing.
1315 1310 *
1316 1311 */
1317 1312
1318 1313 param_local.local_nb_interrupt_f0_MAX = ( (parameter_dump_packet.sy_lfr_n_asm_p[0]) * 256
1319 1314 + parameter_dump_packet.sy_lfr_n_asm_p[1] ) * 100;
1320 1315 }
1321 1316
1322 1317 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1323 1318 {
1324 1319 unsigned short *sequence_cnt;
1325 1320 unsigned short segmentation_grouping_flag;
1326 1321 unsigned short new_packet_sequence_control;
1327 1322
1328 1323 if ( (sid ==SID_NORM_SWF_F0) || (sid ==SID_NORM_SWF_F1) || (sid ==SID_NORM_SWF_F2)
1329 1324 || (sid ==SID_NORM_CWF_F3) || (sid==SID_NORM_CWF_LONG_F3) || (sid ==SID_BURST_CWF_F2) )
1330 1325 {
1331 1326 sequence_cnt = &sequenceCounters_SCIENCE_NORMAL_BURST;
1332 1327 }
1333 1328 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) )
1334 1329 {
1335 1330 sequence_cnt = &sequenceCounters_SCIENCE_SBM1_SBM2;
1336 1331 }
1337 1332 else
1338 1333 {
1339 1334 sequence_cnt = NULL;
1340 1335 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1341 1336 }
1342 1337
1343 1338 if (sequence_cnt != NULL)
1344 1339 {
1345 1340 segmentation_grouping_flag = (packet_sequence_control[ 0 ] & 0xc0) << 8;
1346 1341 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1347 1342
1348 1343 new_packet_sequence_control = segmentation_grouping_flag | *sequence_cnt ;
1349 1344
1350 1345 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1351 1346 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1352 1347
1353 1348 // increment the sequence counter for the next packet
1354 1349 if ( *sequence_cnt < SEQ_CNT_MAX)
1355 1350 {
1356 1351 *sequence_cnt = *sequence_cnt + 1;
1357 1352 }
1358 1353 else
1359 1354 {
1360 1355 *sequence_cnt = 0;
1361 1356 }
1362 1357 }
1363 1358 }
General Comments 0
You need to be logged in to leave comments. Login now