@@ -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 |
|
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 |
|
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 |
|
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=" |
|
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=" |
|
7 | <File name="../header/fsw_init.h" open="1" top="0" tabpos="3"> | |
8 |
<Cursor position=" |
|
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=" |
|
17 | <Cursor position="510" topLine="0" /> | |
18 | </File> |
|
18 | </File> | |
19 |
<File name="../header/tc_handler.h" open=" |
|
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=" |
|
25 | <File name="../src/fsw_globals.c" open="1" top="0" tabpos="4"> | |
26 |
<Cursor position=" |
|
26 | <Cursor position="46" topLine="0" /> | |
27 | </File> |
|
27 | </File> | |
28 |
<File name="../src/fsw_init.c" open="1" top=" |
|
28 | <File name="../src/fsw_init.c" open="1" top="1" tabpos="2"> | |
29 |
<Cursor position=" |
|
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=" |
|
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=" |
|
37 | <File name="../src/tc_handler.c" open="1" top="0" tabpos="1"> | |
38 |
<Cursor position=" |
|
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!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
150 | break; |
|
150 | break; | |
151 | default: |
|
151 | default: | |
152 | return ILL_SUBTYPE; |
|
152 | return ILL_SUBTYPE; | |
153 | break; |
|
153 | break; | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 | else if (packetType == 9){ |
|
156 | else if (packetType == 9){ | |
157 | if (packetSubtype!=129) return ILL_SUBTYPE; |
|
157 | if (packetSubtype!=129) return ILL_SUBTYPE; | |
158 | if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; |
|
158 | if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
159 | } |
|
159 | } | |
160 | else return ILL_TYPE; |
|
160 | else return ILL_TYPE; | |
161 |
|
161 | |||
162 | // source ID check // Source ID not documented in the ICD |
|
162 | // source ID check // Source ID not documented in the ICD | |
163 |
|
163 | |||
164 | // packet error control, CRC check |
|
164 | // packet error control, CRC check | |
165 | CCSDSContent = (unsigned char*) TMPacket->packetID; |
|
165 | CCSDSContent = (unsigned char*) TMPacket->packetID; | |
166 | GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC |
|
166 | GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC | |
167 | if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM; |
|
167 | if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM; | |
168 | if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM; |
|
168 | if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM; | |
169 |
|
169 | |||
170 | return CCSDS_TM_VALID; |
|
170 | return CCSDS_TM_VALID; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int SID, unsigned int packetLength, |
|
173 | unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int SID, unsigned int packetLength, | |
174 | unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader) |
|
174 | unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader) | |
175 | { |
|
175 | { | |
176 | TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
176 | TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
177 | TMHeader->protocolIdentifier = 0x02; |
|
177 | TMHeader->protocolIdentifier = 0x02; | |
178 | TMHeader->reserved = 0x00; |
|
178 | TMHeader->reserved = 0x00; | |
179 | TMHeader->userApplication = 0x00; |
|
179 | TMHeader->userApplication = 0x00; | |
180 | TMHeader->packetID[0] = 0x0c; |
|
180 | TMHeader->packetID[0] = 0x0c; | |
181 | TMHeader->packetSequenceControl[0] = 0xc0; |
|
181 | TMHeader->packetSequenceControl[0] = 0xc0; | |
182 | TMHeader->packetSequenceControl[1] = 0x00; |
|
182 | TMHeader->packetSequenceControl[1] = 0x00; | |
183 | TMHeader->packetLength[0] = (unsigned char) (packetLength>>8); |
|
183 | TMHeader->packetLength[0] = (unsigned char) (packetLength>>8); | |
184 | TMHeader->packetLength[1] = (unsigned char) packetLength; |
|
184 | TMHeader->packetLength[1] = (unsigned char) packetLength; | |
185 | TMHeader->dataFieldHeader[0] = 0x10; |
|
185 | TMHeader->dataFieldHeader[0] = 0x10; | |
186 | TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID; |
|
186 | TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID; | |
187 | switch (tm_type){ |
|
187 | switch (tm_type){ | |
188 | case(TM_LFR_TC_EXE_OK): |
|
188 | case(TM_LFR_TC_EXE_OK): | |
189 | TMHeader->packetID[1] = 0xc1; |
|
189 | TMHeader->packetID[1] = 0xc1; | |
190 | TMHeader->dataFieldHeader[1] = 1; // type |
|
190 | TMHeader->dataFieldHeader[1] = 1; // type | |
191 | TMHeader->dataFieldHeader[2] = 7; // subtype |
|
191 | TMHeader->dataFieldHeader[2] = 7; // subtype | |
192 | break; |
|
192 | break; | |
193 | case(TM_LFR_TC_EXE_ERR): |
|
193 | case(TM_LFR_TC_EXE_ERR): | |
194 | TMHeader->packetID[1] = 0xc1; |
|
194 | TMHeader->packetID[1] = 0xc1; | |
195 | TMHeader->dataFieldHeader[1] = 1; // type |
|
195 | TMHeader->dataFieldHeader[1] = 1; // type | |
196 | TMHeader->dataFieldHeader[2] = 8; // subtype |
|
196 | TMHeader->dataFieldHeader[2] = 8; // subtype | |
197 | break; |
|
197 | break; | |
198 | case(TM_LFR_HK): |
|
198 | case(TM_LFR_HK): | |
199 | TMHeader->packetID[1] = 0xc4; |
|
199 | TMHeader->packetID[1] = 0xc4; | |
200 | TMHeader->dataFieldHeader[1] = 3; // type |
|
200 | TMHeader->dataFieldHeader[1] = 3; // type | |
201 | TMHeader->dataFieldHeader[2] = 25; // subtype |
|
201 | TMHeader->dataFieldHeader[2] = 25; // subtype | |
202 | break; |
|
202 | break; | |
203 | case(TM_LFR_SCI): |
|
203 | case(TM_LFR_SCI): | |
204 | TMHeader->packetID[1] = 0xcc; |
|
204 | TMHeader->packetID[1] = 0xcc; | |
205 | TMHeader->dataFieldHeader[1] = 21; // type |
|
205 | TMHeader->dataFieldHeader[1] = 21; // type | |
206 | TMHeader->dataFieldHeader[2] = 3; // subtype |
|
206 | TMHeader->dataFieldHeader[2] = 3; // subtype | |
207 | break; |
|
207 | break; | |
208 | case(TM_LFR_SCI_SBM): |
|
208 | case(TM_LFR_SCI_SBM): | |
209 | TMHeader->packetID[1] = 0xfc; |
|
209 | TMHeader->packetID[1] = 0xfc; | |
210 | TMHeader->dataFieldHeader[1] = 21; // type |
|
210 | TMHeader->dataFieldHeader[1] = 21; // type | |
211 | TMHeader->dataFieldHeader[2] = 3; // subtype |
|
211 | TMHeader->dataFieldHeader[2] = 3; // subtype | |
212 | break; |
|
212 | break; | |
213 | case(TM_LFR_PAR_DUMP): |
|
213 | case(TM_LFR_PAR_DUMP): | |
214 | TMHeader->packetID[1] = 0xc9; |
|
214 | TMHeader->packetID[1] = 0xc9; | |
215 | TMHeader->dataFieldHeader[1] = 181; // type |
|
215 | TMHeader->dataFieldHeader[1] = 181; // type | |
216 | TMHeader->dataFieldHeader[2] = 31; // subtype |
|
216 | TMHeader->dataFieldHeader[2] = 31; // subtype | |
217 | break; |
|
217 | break; | |
218 | default: |
|
218 | default: | |
219 | return 0; |
|
219 | return 0; | |
220 | } |
|
220 | } | |
221 | /*TMHeader->dataFieldHeader[4] = (unsigned char) (coarseTime>>24); |
|
221 | /*TMHeader->dataFieldHeader[4] = (unsigned char) (coarseTime>>24); | |
222 | TMHeader->dataFieldHeader[5] = (unsigned char) (coarseTime>>16); |
|
222 | TMHeader->dataFieldHeader[5] = (unsigned char) (coarseTime>>16); | |
223 | TMHeader->dataFieldHeader[6] = (unsigned char) (coarseTime>>8); |
|
223 | TMHeader->dataFieldHeader[6] = (unsigned char) (coarseTime>>8); | |
224 | TMHeader->dataFieldHeader[7] = (unsigned char) (coarseTime); |
|
224 | TMHeader->dataFieldHeader[7] = (unsigned char) (coarseTime); | |
225 | TMHeader->dataFieldHeader[8] = (unsigned char) (fineTime>>8); |
|
225 | TMHeader->dataFieldHeader[8] = (unsigned char) (fineTime>>8); | |
226 | TMHeader->dataFieldHeader[9] = (unsigned char) (fineTime);*/ |
|
226 | TMHeader->dataFieldHeader[9] = (unsigned char) (fineTime);*/ | |
227 | TMHeader->dataFieldHeader[4] = 0xaa; |
|
227 | TMHeader->dataFieldHeader[4] = 0xaa; | |
228 | TMHeader->dataFieldHeader[5] = 0xbb; |
|
228 | TMHeader->dataFieldHeader[5] = 0xbb; | |
229 | TMHeader->dataFieldHeader[6] = 0xcc; |
|
229 | TMHeader->dataFieldHeader[6] = 0xcc; | |
230 | TMHeader->dataFieldHeader[7] = 0xdd; |
|
230 | TMHeader->dataFieldHeader[7] = 0xdd; | |
231 | TMHeader->dataFieldHeader[8] = 0xee; |
|
231 | TMHeader->dataFieldHeader[8] = 0xee; | |
232 | TMHeader->dataFieldHeader[9] = 0xff; |
|
232 | TMHeader->dataFieldHeader[9] = 0xff; | |
233 | return 1; |
|
233 | return 1; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC) |
|
236 | unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC) | |
237 | { |
|
237 | { | |
238 | unsigned int packetLength; |
|
238 | unsigned int packetLength; | |
239 | packetLength = TC->packetLength[0] * 256 + TC->packetLength[1]; |
|
239 | packetLength = TC->packetLength[0] * 256 + TC->packetLength[1]; | |
240 | switch (SID){ |
|
240 | switch (SID){ | |
241 | case (SID_NOT_EXE): |
|
241 | case (SID_NOT_EXE): | |
242 | break; |
|
242 | break; | |
243 | case (SID_NOT_IMP): |
|
243 | case (SID_NOT_IMP): | |
244 | data[0] = 0x9c; |
|
244 | data[0] = 0x9c; | |
245 | data[1] = 0x42; |
|
245 | data[1] = 0x42; | |
246 | data[2] = TC->packetID[0]; |
|
246 | data[2] = TC->packetID[0]; | |
247 | data[3] = TC->packetID[1]; |
|
247 | data[3] = TC->packetID[1]; | |
248 | data[4] = TC->packetSequenceControl[0]; |
|
248 | data[4] = TC->packetSequenceControl[0]; | |
249 | data[5] = TC->packetSequenceControl[1]; |
|
249 | data[5] = TC->packetSequenceControl[1]; | |
250 | data[6] = TC->dataFieldHeader[1]; // type |
|
250 | data[6] = TC->dataFieldHeader[1]; // type | |
251 | data[7] = TC->dataFieldHeader[2]; // subtype |
|
251 | data[7] = TC->dataFieldHeader[2]; // subtype | |
252 | break; |
|
252 | break; | |
253 | case (SID_EXE_ERR): |
|
253 | case (SID_EXE_ERR): | |
254 | break; |
|
254 | break; | |
255 | case (SID_EXE_CORR): |
|
255 | case (SID_EXE_CORR): | |
256 | data[0] = 0x9c; |
|
256 | data[0] = 0x9c; | |
257 | data[1] = 0x45; |
|
257 | data[1] = 0x45; | |
258 | data[2] = TC->packetID[0]; |
|
258 | data[2] = TC->packetID[0]; | |
259 | data[3] = TC->packetID[1]; |
|
259 | data[3] = TC->packetID[1]; | |
260 | data[4] = TC->packetSequenceControl[0]; |
|
260 | data[4] = TC->packetSequenceControl[0]; | |
261 | data[5] = TC->packetSequenceControl[1]; |
|
261 | data[5] = TC->packetSequenceControl[1]; | |
262 | data[6] = TC->dataFieldHeader[1]; // type |
|
262 | data[6] = TC->dataFieldHeader[1]; // type | |
263 | data[7] = TC->dataFieldHeader[2]; // subtype |
|
263 | data[7] = TC->dataFieldHeader[2]; // subtype | |
264 | data[8] = currentTC_LEN_RCV[0]; |
|
264 | data[8] = currentTC_LEN_RCV[0]; | |
265 | data[9] = currentTC_LEN_RCV[1]; |
|
265 | data[9] = currentTC_LEN_RCV[1]; | |
266 | data[10] = TC->packetLength[0]; |
|
266 | data[10] = TC->packetLength[0]; | |
267 | data[11] = TC->packetLength[1]; |
|
267 | data[11] = TC->packetLength[1]; | |
268 | data[12] = TC->dataAndCRC[packetLength]; |
|
268 | data[12] = TC->dataAndCRC[packetLength]; | |
269 | data[13] = TC->dataAndCRC[packetLength+1]; |
|
269 | data[13] = TC->dataAndCRC[packetLength+1]; | |
270 | data[14] = computed_CRC[0]; |
|
270 | data[14] = computed_CRC[0]; | |
271 | data[15] = computed_CRC[1]; |
|
271 | data[15] = computed_CRC[1]; | |
272 | break; |
|
272 | break; | |
273 | default: |
|
273 | default: | |
274 | return 0; |
|
274 | return 0; | |
275 | } |
|
275 | } | |
276 | return 1; |
|
276 | return 1; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | unsigned char actionLauncher(unsigned int sid) |
|
279 | unsigned char actionLauncher(unsigned int sid) | |
280 | { |
|
280 | { | |
281 |
|
281 | return 0; | ||
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | //*********** |
|
284 | //*********** | |
285 | // RTEMS TASK |
|
285 | // RTEMS TASK | |
286 | rtems_task spw_recv_task( rtems_task_argument unused ) |
|
286 | rtems_task spw_recv_task( rtems_task_argument unused ) | |
287 | { |
|
287 | { | |
288 | rtems_status_code status; |
|
288 | rtems_status_code status; | |
289 | int len = 0; |
|
289 | int len = 0; | |
290 | unsigned int i = 0; |
|
290 | unsigned int i = 0; | |
291 | unsigned int data_length = 0; |
|
291 | unsigned int data_length = 0; | |
292 | ccsdsTelecommandPacket_t currentTC; |
|
292 | ccsdsTelecommandPacket_t currentTC; | |
293 | spw_ioctl_pkt_send spw_ioctl_send; |
|
293 | spw_ioctl_pkt_send spw_ioctl_send; | |
294 | TMHeader_t TM_header; |
|
294 | TMHeader_t TM_header; | |
295 | char data[100]; |
|
295 | char data[100]; | |
296 |
|
296 | |||
297 | for(i=0; i<100; i++) data[i] = 0; |
|
297 | for(i=0; i<100; i++) data[i] = 0; | |
298 |
|
298 | |||
299 | PRINTF("In RECV *** \n") |
|
299 | PRINTF("In RECV *** \n") | |
300 |
|
300 | |||
301 | while(1){ |
|
301 | while(1){ | |
302 | len = read(fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking |
|
302 | len = read(fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking | |
303 | if (len == -1){ // error during the read call |
|
303 | if (len == -1){ // error during the read call | |
304 | PRINTF("In RECV *** last read call returned -1\n") |
|
304 | PRINTF("In RECV *** last read call returned -1\n") | |
305 | if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) |
|
305 | if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) | |
306 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") |
|
306 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") | |
307 | if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) |
|
307 | if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) | |
308 | PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") |
|
308 | PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") | |
309 | } |
|
309 | } | |
310 | else { |
|
310 | else { | |
311 | //PRINTF1("In RECV *** Got Message of length %d\n", len) |
|
311 | //PRINTF1("In RECV *** Got Message of length %d\n", len) | |
312 | currentTC_LEN_RCV[0] = 0x00; |
|
312 | currentTC_LEN_RCV[0] = 0x00; | |
313 | currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field |
|
313 | currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field | |
314 | currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes |
|
314 | currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes | |
315 | // CHECK THE TC AND BUILD THE APPROPRIATE TM |
|
315 | // CHECK THE TC AND BUILD THE APPROPRIATE TM | |
316 | data_length = TC_checker(¤tTC, currentTC_LEN_RCV_AsUnsignedInt, |
|
316 | data_length = TC_checker(¤tTC, currentTC_LEN_RCV_AsUnsignedInt, | |
317 | &TM_header, &spw_ioctl_send.hlen, data); |
|
317 | &TM_header, &spw_ioctl_send.hlen, data); | |
318 | spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header |
|
318 | spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header | |
319 | spw_ioctl_send.hdr = (char*) &TM_header; |
|
319 | spw_ioctl_send.hdr = (char*) &TM_header; | |
320 | spw_ioctl_send.dlen = data_length; |
|
320 | spw_ioctl_send.dlen = data_length; | |
321 | spw_ioctl_send.data = data; |
|
321 | spw_ioctl_send.data = data; | |
322 | //printf("hlen %d, dlen %d\n", spw_ioctl_send.hlen, spw_ioctl_send.dlen); |
|
322 | //printf("hlen %d, dlen %d\n", spw_ioctl_send.hlen, spw_ioctl_send.dlen); | |
323 | // SEND PACKET |
|
323 | // SEND PACKET | |
324 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send ); |
|
324 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send ); | |
325 | if (status!=RTEMS_SUCCESSFUL) printf("In TC_checker *** Error SPACEWIRE_IOCTRL_SEND\n"); |
|
325 | if (status!=RTEMS_SUCCESSFUL) printf("In TC_checker *** Error SPACEWIRE_IOCTRL_SEND\n"); | |
326 | //PRINTF1("In TC_checker *** packet of size %d sent\n", spw_ioctl_send.sent) |
|
326 | //PRINTF1("In TC_checker *** packet of size %d sent\n", spw_ioctl_send.sent) | |
327 | } |
|
327 | } | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 |
|
331 |
General Comments 0
You need to be logged in to leave comments.
Login now