##// END OF EJS Templates
Beginning of the message queue implementation for the actions handler
admin@pc-p-leroy3.LAB-LPP.LOCAL -
r8:ab2dbbe22332 default
parent child
Show More
@@ -1,69 +1,69
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 <CodeBlocks_project_file>
2 <CodeBlocks_project_file>
3 <FileVersion major="1" minor="6" />
3 <FileVersion major="1" minor="6" />
4 <Project>
4 <Project>
5 <Option title="FSW-rtems" />
5 <Option title="FSW-rtems" />
6 <Option pch_mode="2" />
6 <Option pch_mode="2" />
7 <Option compiler="sparc_rtems_gcc" />
7 <Option compiler="sparcrtemsgcc446" />
8 <Build>
8 <Build>
9 <Target title="Debug">
9 <Target title="Debug">
10 <Option output="bin/Debug/fsw" prefix_auto="1" extension_auto="1" />
10 <Option output="bin/Debug/fsw" prefix_auto="1" extension_auto="1" />
11 <Option object_output="obj/Debug/" />
11 <Option object_output="obj/Debug/" />
12 <Option type="1" />
12 <Option type="1" />
13 <Option compiler="sparc_rtems_gcc_compiler" />
13 <Option compiler="sparcrtems446" />
14 <Compiler>
14 <Compiler>
15 <Add option="-fexpensive-optimizations" />
15 <Add option="-fexpensive-optimizations" />
16 <Add option="-O3" />
16 <Add option="-O3" />
17 <Add option="-g" />
17 <Add option="-g" />
18 <Add directory="../header" />
18 <Add directory="../header" />
19 <Add directory="../src" />
19 <Add directory="../src" />
20 </Compiler>
20 </Compiler>
21 </Target>
21 </Target>
22 <Target title="Release">
22 <Target title="Release">
23 <Option output="bin/Release/FSW-rtems" prefix_auto="1" extension_auto="1" />
23 <Option output="bin/Release/FSW-rtems" prefix_auto="1" extension_auto="1" />
24 <Option object_output="obj/Release/" />
24 <Option object_output="obj/Release/" />
25 <Option type="1" />
25 <Option type="1" />
26 <Option compiler="sparc_rtems_gcc" />
26 <Option compiler="sparcrtemsgcc446" />
27 <Compiler>
27 <Compiler>
28 <Add option="-O2" />
28 <Add option="-O2" />
29 </Compiler>
29 </Compiler>
30 <Linker>
30 <Linker>
31 <Add option="-s" />
31 <Add option="-s" />
32 </Linker>
32 </Linker>
33 </Target>
33 </Target>
34 </Build>
34 </Build>
35 <Compiler>
35 <Compiler>
36 <Add option="-Wall" />
36 <Add option="-Wall" />
37 </Compiler>
37 </Compiler>
38 <Unit filename="../header/ccsds_types.h" />
38 <Unit filename="../header/ccsds_types.h" />
39 <Unit filename="../header/fsw_init.h" />
39 <Unit filename="../header/fsw_init.h" />
40 <Unit filename="../header/fsw_misc.h" />
40 <Unit filename="../header/fsw_misc.h" />
41 <Unit filename="../header/fsw_params.h" />
41 <Unit filename="../header/fsw_params.h" />
42 <Unit filename="../header/fsw_processing.h" />
42 <Unit filename="../header/fsw_processing.h" />
43 <Unit filename="../header/grlib_regs.h" />
43 <Unit filename="../header/grlib_regs.h" />
44 <Unit filename="../header/tc_handler.h" />
44 <Unit filename="../header/tc_handler.h" />
45 <Unit filename="../header/wf_handler.h" />
45 <Unit filename="../header/wf_handler.h" />
46 <Unit filename="../src/fsw_globals.c">
46 <Unit filename="../src/fsw_globals.c">
47 <Option compilerVar="CC" />
47 <Option compilerVar="CC" />
48 </Unit>
48 </Unit>
49 <Unit filename="../src/fsw_init.c">
49 <Unit filename="../src/fsw_init.c">
50 <Option compilerVar="CC" />
50 <Option compilerVar="CC" />
51 </Unit>
51 </Unit>
52 <Unit filename="../src/fsw_misc.c">
52 <Unit filename="../src/fsw_misc.c">
53 <Option compilerVar="CC" />
53 <Option compilerVar="CC" />
54 </Unit>
54 </Unit>
55 <Unit filename="../src/fsw_processing.c">
55 <Unit filename="../src/fsw_processing.c">
56 <Option compilerVar="CC" />
56 <Option compilerVar="CC" />
57 </Unit>
57 </Unit>
58 <Unit filename="../src/tc_handler.c">
58 <Unit filename="../src/tc_handler.c">
59 <Option compilerVar="CC" />
59 <Option compilerVar="CC" />
60 </Unit>
60 </Unit>
61 <Unit filename="../src/wf_handler.c">
61 <Unit filename="../src/wf_handler.c">
62 <Option compilerVar="CC" />
62 <Option compilerVar="CC" />
63 </Unit>
63 </Unit>
64 <Extensions>
64 <Extensions>
65 <code_completion />
65 <code_completion />
66 <debugger />
66 <debugger />
67 </Extensions>
67 </Extensions>
68 </Project>
68 </Project>
69 </CodeBlocks_project_file>
69 </CodeBlocks_project_file>
@@ -1,43 +1,43
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 <CodeBlocks_layout_file>
2 <CodeBlocks_layout_file>
3 <ActiveTarget name="Debug" />
3 <ActiveTarget name="Debug" />
4 <File name="../header/ccsds_types.h" open="1" top="0" tabpos="5">
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="5">
5 <Cursor position="1172" topLine="24" />
5 <Cursor position="1172" topLine="24" />
6 </File>
6 </File>
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="0">
7 <File name="../header/fsw_init.h" open="1" top="0" tabpos="3">
8 <Cursor position="307" topLine="0" />
8 <Cursor position="410" topLine="16" />
9 </File>
9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
11 <Cursor position="114" topLine="0" />
11 <Cursor position="114" topLine="0" />
12 </File>
12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="0">
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="0">
14 <Cursor position="1320" topLine="8" />
14 <Cursor position="1320" topLine="8" />
15 </File>
15 </File>
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 <Cursor position="175" topLine="1" />
17 <Cursor position="510" topLine="0" />
18 </File>
18 </File>
19 <File name="../header/tc_handler.h" open="1" top="0" tabpos="4">
19 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
20 <Cursor position="634" topLine="0" />
20 <Cursor position="634" topLine="0" />
21 </File>
21 </File>
22 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
22 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
23 <Cursor position="212" topLine="0" />
23 <Cursor position="212" topLine="0" />
24 </File>
24 </File>
25 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="0">
25 <File name="../src/fsw_globals.c" open="1" top="0" tabpos="4">
26 <Cursor position="908" topLine="0" />
26 <Cursor position="46" topLine="0" />
27 </File>
27 </File>
28 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
28 <File name="../src/fsw_init.c" open="1" top="1" tabpos="2">
29 <Cursor position="1703" topLine="42" />
29 <Cursor position="3361" topLine="60" />
30 </File>
30 </File>
31 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="0">
31 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="0">
32 <Cursor position="20" topLine="0" />
32 <Cursor position="20" topLine="0" />
33 </File>
33 </File>
34 <File name="../src/fsw_processing.c" open="1" top="0" tabpos="2">
34 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="2">
35 <Cursor position="1175" topLine="46" />
35 <Cursor position="1175" topLine="46" />
36 </File>
36 </File>
37 <File name="../src/tc_handler.c" open="1" top="1" tabpos="3">
37 <File name="../src/tc_handler.c" open="1" top="0" tabpos="1">
38 <Cursor position="2672" topLine="26" />
38 <Cursor position="11070" topLine="270" />
39 </File>
39 </File>
40 <File name="../src/wf_handler.c" open="0" top="0" tabpos="0">
40 <File name="../src/wf_handler.c" open="0" top="0" tabpos="0">
41 <Cursor position="3936" topLine="62" />
41 <Cursor position="3936" topLine="62" />
42 </File>
42 </File>
43 </CodeBlocks_layout_file>
43 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,39 +1,41
1 #ifndef FSW_RTEMS_H_INCLUDED
1 #ifndef FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
3
3
4 #include <errno.h>
4 #include <errno.h>
5 #include <fcntl.h>
5 #include <fcntl.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <stdlib.h>
7 #include <stdlib.h>
8
8
9 #include <grspw.h>
9 #include <grspw.h>
10 #include <apbuart.h>
10 #include <apbuart.h>
11
11
12 #include <fsw_params.h>
12 #include <fsw_params.h>
13 #include <fsw_misc.h>
13 #include <fsw_misc.h>
14 #include <fsw_processing.h>
14 #include <fsw_processing.h>
15 #include <tc_handler.h>
15 #include <tc_handler.h>
16 #include <wf_handler.h>
16 #include <wf_handler.h>
17 #include <grlib_regs.h>
17 #include <grlib_regs.h>
18
18
19 extern int sched_yield();
19 extern int sched_yield();
20 extern int errno;
20 extern int errno;
21 extern rtems_name misc_names[ ];
21
22
22 // RTEMS TASKS
23 // RTEMS TASKS
23 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
24 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
24 rtems_task spw_recv_task(rtems_task_argument argument);
25 rtems_task spw_recv_task(rtems_task_argument argument);
25 rtems_task spw_spiq_task(rtems_task_argument argument);
26 rtems_task spw_spiq_task(rtems_task_argument argument);
26 rtems_task spw_stat_task(rtems_task_argument argument);
27 rtems_task spw_stat_task(rtems_task_argument argument);
27 rtems_task spw_wfrm_task(rtems_task_argument argument);
28 rtems_task spw_wfrm_task(rtems_task_argument argument);
28 int create_all_tasks();
29 int create_all_tasks();
29 int start_all_tasks();
30 int start_all_tasks();
31 int create_message_queue();
30
32
31 // OTHER functions
33 // OTHER functions
32 int configure_spw_link();
34 int configure_spw_link();
33 int send_console_outputs_on_serial_port();
35 int send_console_outputs_on_serial_port();
34 extern int rtems_cpu_usage_report();
36 extern int rtems_cpu_usage_report();
35 extern int rtems_cpu_usage_reset();
37 extern int rtems_cpu_usage_reset();
36 void print_statistics(spw_stats *);
38 void print_statistics(spw_stats *);
37 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
39 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
38
40
39 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
41 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,25 +1,29
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <rtems.h>
3
4 // RTEMS GLOBAL VARIABLES
5 rtems_name misc_names[5];
2
6
3 // WAVEFORMS GLOBAL VARIABLES
7 // WAVEFORMS GLOBAL VARIABLES
4 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
8 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
5 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
9 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
6 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
10 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
7 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
11 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
8
12
9 // SPECTRAL MATRICES GLOBAL VARIABLES
13 // SPECTRAL MATRICES GLOBAL VARIABLES
10 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
14 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
11 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
15 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
12 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
16 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
13 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
17 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
14 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
18 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
15 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
19 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
16 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
20 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
17 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
21 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
18 //
22 //
19 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
23 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
20 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
24 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
21
25
22 // BASIC PARAMETERS GLOBAL VAIRABLES
26 // BASIC PARAMETERS GLOBAL VAIRABLES
23 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
27 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
24
28
25 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
29 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
@@ -1,250 +1,257
1 //*************************
1 //*************************
2 // GPL reminder to be added
2 // GPL reminder to be added
3 //*************************
3 //*************************
4
4
5 #include <rtems.h>
5 #include <rtems.h>
6
6
7 /* configuration information */
7 /* configuration information */
8
8
9 #define CONFIGURE_INIT
9 #define CONFIGURE_INIT
10
10
11 #include <bsp.h> /* for device driver prototypes */
11 #include <bsp.h> /* for device driver prototypes */
12
12
13 /* configuration information */
13 /* configuration information */
14
14
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17
17
18 #define CONFIGURE_MAXIMUM_TASKS 10
18 #define CONFIGURE_MAXIMUM_TASKS 10
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 #define CONFIGURE_MAXIMUM_PERIODS 1
24 #define CONFIGURE_MAXIMUM_PERIODS 1
25
25
26 #include <rtems/confdefs.h>
26 #include <rtems/confdefs.h>
27
27
28 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
28 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
29 #ifdef RTEMS_DRVMGR_STARTUP
29 #ifdef RTEMS_DRVMGR_STARTUP
30 #ifdef LEON3
30 #ifdef LEON3
31 /* Add Timer and UART Driver */
31 /* Add Timer and UART Driver */
32 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
32 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
33 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
33 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
34 #endif
34 #endif
35 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
35 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
36 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
36 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
37 #endif
37 #endif
38 #endif
38 #endif
39 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
39 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
40 #include <drvmgr/drvmgr_confdefs.h>
40 #include <drvmgr/drvmgr_confdefs.h>
41 #endif
41 #endif
42
42
43 #include <fsw_init.h>
43 #include <fsw_init.h>
44 #include <fsw_config.c>
44 #include <fsw_config.c>
45
45
46 int fdSPW;
46 int fdSPW;
47 int fdUART;
47 int fdUART;
48
48
49 char *link_status(int status);
49 char *link_status(int status);
50
50
51 char *lstates[6] = {"Error-reset",
51 char *lstates[6] = {"Error-reset",
52 "Error-wait",
52 "Error-wait",
53 "Ready",
53 "Ready",
54 "Started",
54 "Started",
55 "Connecting",
55 "Connecting",
56 "Run"
56 "Run"
57 };
57 };
58
58
59 rtems_id Task_id[10]; /* array of task ids */
59 rtems_id Task_id[10]; /* array of task ids */
60 rtems_name Task_name[10]; /* array of task names */
60 rtems_name Task_name[10]; /* array of task names */
61
61
62 rtems_task Init( rtems_task_argument ignored )
62 rtems_task Init( rtems_task_argument ignored )
63 {
63 {
64 rtems_status_code status;
64 rtems_status_code status;
65
65
66 //send_console_outputs_on_serial_port();
66 //send_console_outputs_on_serial_port();
67
67
68 InitLookUpTableForCRC(); // in tc_handler.h
68 InitLookUpTableForCRC(); // in tc_handler.h
69
69
70 create_message_queue();
70 create_all_tasks();
71 create_all_tasks();
71 start_all_tasks();
72 start_all_tasks();
72
73
73 configure_spw_link();
74 configure_spw_link();
74 // configure timer for spectral matrices simulation
75 // configure timer for spectral matrices simulation
75 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
76 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
76 IRQ_SPARC_SM, spectral_matrices_isr );
77 IRQ_SPARC_SM, spectral_matrices_isr );
77 // configure timer for waveforms simulation
78 // configure timer for waveforms simulation
78 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
79 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
79 IRQ_SPARC_WF, waveforms_isr );
80 IRQ_SPARC_WF, waveforms_isr );
80
81
81 LEON_Unmask_interrupt( IRQ_SM );
82 LEON_Unmask_interrupt( IRQ_SM );
82 LEON_Unmask_interrupt( IRQ_WF );
83 LEON_Unmask_interrupt( IRQ_WF );
83
84
84 status = rtems_task_delete(RTEMS_SELF);
85 status = rtems_task_delete(RTEMS_SELF);
85 }
86 }
86
87
87 rtems_task spw_spiq_task(rtems_task_argument unused)
88 rtems_task spw_spiq_task(rtems_task_argument unused)
88 {
89 {
89 rtems_event_set event_out;
90 rtems_event_set event_out;
90 struct grspw_regs_str *grspw_regs;
91 struct grspw_regs_str *grspw_regs;
91 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
92 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
92
93
93 while(1){
94 while(1){
94 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
95 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
95 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
96 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
96
97
97 if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task
98 if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task
98 PRINTF("In SPIQ *** Error suspending RECV Task\n")
99 PRINTF("In SPIQ *** Error suspending RECV Task\n")
99
100
100 configure_spw_link();
101 configure_spw_link();
101
102
102 if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
103 if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
103 PRINTF("In SPIQ *** Error resume RECV Task\n")
104 PRINTF("In SPIQ *** Error resume RECV Task\n")
104 }
105 }
105 }
106 }
106
107
108 int create_message_queue()
109 {
110 misc_names[0] = rtems_build_name( 'D', 'O', 'I', 'T' );
111 return 0;
112 }
113
107 int create_all_tasks()
114 int create_all_tasks()
108 {
115 {
109 rtems_status_code status;
116 rtems_status_code status;
110
117
111 Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
118 Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
112 Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' );
119 Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' );
113 Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' );
120 Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' );
114 Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' );
121 Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' );
115 Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' );
122 Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' );
116 Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' );
123 Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' );
117 Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' );
124 Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' );
118
125
119 // RECV
126 // RECV
120 status = rtems_task_create(
127 status = rtems_task_create(
121 Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
128 Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
122 RTEMS_DEFAULT_MODES,
129 RTEMS_DEFAULT_MODES,
123 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]
130 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]
124 );
131 );
125 // SPIQ
132 // SPIQ
126 status = rtems_task_create(
133 status = rtems_task_create(
127 Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
134 Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
128 RTEMS_DEFAULT_MODES,
135 RTEMS_DEFAULT_MODES,
129 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]
136 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]
130 );
137 );
131 // SMIQ
138 // SMIQ
132 status = rtems_task_create(
139 status = rtems_task_create(
133 Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
140 Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
134 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
141 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
135 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4]
142 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4]
136 );
143 );
137 // STAT
144 // STAT
138 status = rtems_task_create(
145 status = rtems_task_create(
139 Task_name[5], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
146 Task_name[5], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
140 RTEMS_DEFAULT_MODES,
147 RTEMS_DEFAULT_MODES,
141 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5]
148 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5]
142 );
149 );
143 // AVF0
150 // AVF0
144 status = rtems_task_create(
151 status = rtems_task_create(
145 Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
152 Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
146 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
153 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
147 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6]
154 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6]
148 );
155 );
149 // BPF0
156 // BPF0
150 status = rtems_task_create(
157 status = rtems_task_create(
151 Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
158 Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
152 RTEMS_DEFAULT_MODES,
159 RTEMS_DEFAULT_MODES,
153 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7]
160 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7]
154 );
161 );
155 // WFRM
162 // WFRM
156 status = rtems_task_create(
163 status = rtems_task_create(
157 Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
164 Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
158 RTEMS_DEFAULT_MODES,
165 RTEMS_DEFAULT_MODES,
159 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8]
166 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8]
160 );
167 );
161
168
162 return 0;
169 return 0;
163 }
170 }
164
171
165 int start_all_tasks()
172 int start_all_tasks()
166 {
173 {
167 rtems_status_code status;
174 rtems_status_code status;
168
175
169 status = rtems_task_start( Task_id[3], spw_spiq_task, 1 );
176 status = rtems_task_start( Task_id[3], spw_spiq_task, 1 );
170 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
177 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
171
178
172 status = rtems_task_start( Task_id[1], spw_recv_task, 1 );
179 status = rtems_task_start( Task_id[1], spw_recv_task, 1 );
173 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
180 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
174
181
175 //status = rtems_task_start( Task_id[4], spw_bppr_task_rate_monotonic, 1 );
182 //status = rtems_task_start( Task_id[4], spw_bppr_task_rate_monotonic, 1 );
176 status = rtems_task_start( Task_id[4], spw_smiq_task, 1 );
183 status = rtems_task_start( Task_id[4], spw_smiq_task, 1 );
177 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
184 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
178
185
179 status = rtems_task_start( Task_id[5], spw_stat_task, 1 );
186 status = rtems_task_start( Task_id[5], spw_stat_task, 1 );
180 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
187 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
181
188
182 status = rtems_task_start( Task_id[6], spw_avf0_task, 1 );
189 status = rtems_task_start( Task_id[6], spw_avf0_task, 1 );
183 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
190 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
184
191
185 status = rtems_task_start( Task_id[7], spw_bpf0_task, 1 );
192 status = rtems_task_start( Task_id[7], spw_bpf0_task, 1 );
186 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
193 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
187
194
188 status = rtems_task_start( Task_id[8], spw_wfrm_task, 1 );
195 status = rtems_task_start( Task_id[8], spw_wfrm_task, 1 );
189 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
196 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
190
197
191 return 0;
198 return 0;
192 }
199 }
193
200
194 int configure_spw_link()
201 int configure_spw_link()
195 {
202 {
196 rtems_status_code status;
203 rtems_status_code status;
197
204
198 close(fdSPW); // close the device if it is already open
205 close(fdSPW); // close the device if it is already open
199 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
206 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
200 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
207 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
201 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
208 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
202 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
209 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
203 close(fdSPW); // close the device
210 close(fdSPW); // close the device
204 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
211 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
205 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
212 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
206 rtems_task_wake_after(100);
213 rtems_task_wake_after(100);
207 }
214 }
208
215
209 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
216 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
210
217
211 // sets a few parameters of the link
218 // sets a few parameters of the link
212 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
219 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
213 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
220 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
214 //
221 //
215 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
222 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
216 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
223 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
217 //
224 //
218 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
225 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
219 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
226 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
220 //
227 //
221 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
228 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
222 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
229 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
223 //
230 //
224 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
231 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
225 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
232 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
226
233
227 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
234 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
228 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
235 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
229 //
236 //
230 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
237 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
231 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
238 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
232 //
239 //
233 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
240 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
234
241
235 return RTEMS_SUCCESSFUL;
242 return RTEMS_SUCCESSFUL;
236 }
243 }
237
244
238 char *link_status(int status){
245 char *link_status(int status){
239 return lstates[status];
246 return lstates[status];
240 }
247 }
241
248
242 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
249 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
243 {
250 {
244 rtems_status_code status;
251 rtems_status_code status;
245 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
252 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
246 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
253 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
247 return status;
254 return status;
248 }
255 }
249
256
250
257
@@ -1,331 +1,331
1 #include <tc_handler.h>
1 #include <tc_handler.h>
2 #include <fsw_params.h>
2 #include <fsw_params.h>
3
3
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
5 "WRONG_LEN_PACKET 1",
5 "WRONG_LEN_PACKET 1",
6 "INCOR_CHECKSUM 2",
6 "INCOR_CHECKSUM 2",
7 "ILL_TYPE 3",
7 "ILL_TYPE 3",
8 "ILL_SUBTYPE 4",
8 "ILL_SUBTYPE 4",
9 "WRONG_APP_DATA 5",
9 "WRONG_APP_DATA 5",
10 "WRONG_CMD_CODE 6",
10 "WRONG_CMD_CODE 6",
11 "CCSDS_TM_VALID 7"
11 "CCSDS_TM_VALID 7"
12 };
12 };
13
13
14 //**********************
14 //**********************
15 // GENERAL USE FUNCTIONS
15 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 {
17 {
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 }
19 }
20
20
21 void InitLookUpTableForCRC()
21 void InitLookUpTableForCRC()
22 {
22 {
23 unsigned int i, tmp;
23 unsigned int i, tmp;
24 for (i=0; i<256; i++)
24 for (i=0; i<256; i++)
25 {
25 {
26 tmp = 0;
26 tmp = 0;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
35 lookUpTableForCRC[i] = tmp;
35 lookUpTableForCRC[i] = tmp;
36 }
36 }
37 }
37 }
38
38
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
40 {
40 {
41 unsigned int Chk;
41 unsigned int Chk;
42 int j;
42 int j;
43 Chk = 0xffff; // reset the syndrom to all ones
43 Chk = 0xffff; // reset the syndrom to all ones
44 for (j=0; j<sizeOfData; j++) {
44 for (j=0; j<sizeOfData; j++) {
45 Chk = Crc_opt(data[j], Chk);
45 Chk = Crc_opt(data[j], Chk);
46 }
46 }
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 }
49 }
50
50
51
51
52 //*********************
52 //*********************
53 // ACCEPTANCE FUNCTIONS
53 // ACCEPTANCE FUNCTIONS
54 unsigned int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV,
54 unsigned int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV,
55 TMHeader_t *TM_Header, unsigned int *hlen, char *data)
55 TMHeader_t *TM_Header, unsigned int *hlen, char *data)
56 {
56 {
57 unsigned int code = 0;
57 unsigned int code = 0;
58 unsigned int data_length = 0;
58 unsigned int data_length = 0;
59 unsigned char computed_CRC[2];
59 unsigned char computed_CRC[2];
60 unsigned char subtype = 0;
60 unsigned char subtype = 0;
61
61
62 subtype = TC->dataFieldHeader[2];
62 subtype = TC->dataFieldHeader[2];
63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, TC_LEN_RCV + 5 );
63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, TC_LEN_RCV + 5 );
64 code = acceptTM( TC, TC_LEN_RCV ) ;
64 code = acceptTM( TC, TC_LEN_RCV ) ;
65 //PRINTF1("in TC_checker *** %s\n", errorCCSDSMsg[code]);
65 //PRINTF1("in TC_checker *** %s\n", errorCCSDSMsg[code]);
66 if ( (code == 0) | (code == 1) | (code == 2)
66 if ( (code == 0) | (code == 1) | (code == 2)
67 | (code == 3) | (code == 4) | (code == 5) )
67 | (code == 3) | (code == 4) | (code == 5) )
68 { // generate TM_LFR_TC_EXE_CORRUPTED
68 { // generate TM_LFR_TC_EXE_CORRUPTED
69 // BUILD HEADER
69 // BUILD HEADER
70 TM_build_header( TM_LFR_TC_EXE_ERR, SID_EXE_CORR, TM_LEN_EXE_CORR, 0, 0, TM_Header);
70 TM_build_header( TM_LFR_TC_EXE_ERR, SID_EXE_CORR, TM_LEN_EXE_CORR, 0, 0, TM_Header);
71 // BUILD DATA
71 // BUILD DATA
72 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
72 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
73 data_length = TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
73 data_length = TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
74 }
74 }
75 if (subtype == SID_TC_UPDT_TIME){
75 if (subtype == SID_TC_UPDT_TIME){
76 // BUILD HEADER
76 // BUILD HEADER
77 TM_build_header( TM_LFR_TC_EXE_OK, SID_DEFAULT, TM_LEN_EXE, 0, 0, TM_Header);
77 TM_build_header( TM_LFR_TC_EXE_OK, SID_DEFAULT, TM_LEN_EXE, 0, 0, TM_Header);
78 // BUILD DATA
78 // BUILD DATA
79 TM_build_data( TC, data, SID_DEFAULT, computed_CRC);
79 TM_build_data( TC, data, SID_DEFAULT, computed_CRC);
80 data_length = TM_LEN_NOT_IMP + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
80 data_length = TM_LEN_NOT_IMP + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
81 }
81 }
82 else { // TM_LFR_TC_EXE_NOT_IMPLEMENTED
82 else { // TM_LFR_TC_EXE_NOT_IMPLEMENTED
83 // BUILD HEADER
83 // BUILD HEADER
84 TM_build_header( TM_LFR_TC_EXE_ERR, SID_NOT_IMP, TM_LEN_NOT_IMP, 0, 0, TM_Header);
84 TM_build_header( TM_LFR_TC_EXE_ERR, SID_NOT_IMP, TM_LEN_NOT_IMP, 0, 0, TM_Header);
85 // BUILD DATA
85 // BUILD DATA
86 TM_build_data( TC, data, SID_NOT_IMP, computed_CRC);
86 TM_build_data( TC, data, SID_NOT_IMP, computed_CRC);
87 data_length = TM_LEN_NOT_IMP + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
87 data_length = TM_LEN_NOT_IMP + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
88 }
88 }
89
89
90 return data_length;
90 return data_length;
91 }
91 }
92
92
93 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
93 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
94 {
94 {
95 unsigned char pid = 0;
95 unsigned char pid = 0;
96 unsigned char category = 0;
96 unsigned char category = 0;
97 unsigned int length = 0;
97 unsigned int length = 0;
98 unsigned char packetType = 0;
98 unsigned char packetType = 0;
99 unsigned char packetSubtype = 0;
99 unsigned char packetSubtype = 0;
100 unsigned char * CCSDSContent;
100 unsigned char * CCSDSContent;
101
101
102 // APID check *** APID on 2 bytes
102 // APID check *** APID on 2 bytes
103 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
103 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
104 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
104 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
105 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
105 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
106 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
106 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
107
107
108 // packet length check
108 // packet length check
109 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
109 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
110 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
110 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
111 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
111 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
112
112
113 packetType = TMPacket->dataFieldHeader[1];
113 packetType = TMPacket->dataFieldHeader[1];
114 packetSubtype = TMPacket->dataFieldHeader[2];
114 packetSubtype = TMPacket->dataFieldHeader[2];
115 // service type, subtype and packet length check
115 // service type, subtype and packet length check
116 if (packetType == 181){
116 if (packetType == 181){
117 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
117 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
118 case 3:
118 case 3:
119 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
119 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
120 break;
120 break;
121 case 20:
121 case 20:
122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
123 break;
123 break;
124 case 21:
124 case 21:
125 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
125 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
126 break;
126 break;
127 case 24:
127 case 24:
128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
129 break;
129 break;
130 case 27:
130 case 27:
131 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
131 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
132 break;
132 break;
133 case 28:
133 case 28:
134 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
134 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
135 break;
135 break;
136 case 30:
136 case 30:
137 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
137 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
138 break;
138 break;
139 case 40:
139 case 40:
140 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
140 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
141 break;
141 break;
142 case 50:
142 case 50:
143 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
143 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
144 break;
144 break;
145 case 60:
145 case 60:
146 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
146 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
147 break;
147 break;
148 case 61:
148 case 61:
149 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
149 if (length!=