@@ -1,49 +1,54 | |||||
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="sparc_rtems_gcc" /> | |
8 | <Build> |
|
8 | <Build> | |
9 | <Target title="Debug"> |
|
9 | <Target title="Debug"> | |
10 |
<Option output="bin |
|
10 | <Option output="bin/Debug/fsw" prefix_auto="1" extension_auto="1" /> | |
11 |
<Option object_output="obj |
|
11 | <Option object_output="obj/Debug/" /> | |
12 | <Option type="1" /> |
|
12 | <Option type="1" /> | |
13 | <Option compiler="sparc_rtems_gcc" /> |
|
13 | <Option compiler="sparc_rtems_gcc_compiler" /> | |
14 | <Compiler> |
|
14 | <Compiler> | |
15 | <Add option="-O3" /> |
|
15 | <Add option="-O3" /> | |
16 | <Add option="-g" /> |
|
16 | <Add option="-g" /> | |
17 |
<Add directory=".. |
|
17 | <Add directory="../header" /> | |
18 |
<Add directory=".. |
|
18 | <Add directory="../src" /> | |
19 | </Compiler> |
|
19 | </Compiler> | |
20 | </Target> |
|
20 | </Target> | |
21 | <Target title="Release"> |
|
21 | <Target title="Release"> | |
22 |
<Option output="bin |
|
22 | <Option output="bin/Release/FSW-rtems" prefix_auto="1" extension_auto="1" /> | |
23 |
<Option object_output="obj |
|
23 | <Option object_output="obj/Release/" /> | |
24 | <Option type="1" /> |
|
24 | <Option type="1" /> | |
25 | <Option compiler="sparc_rtems_gcc" /> |
|
25 | <Option compiler="sparc_rtems_gcc" /> | |
26 | <Compiler> |
|
26 | <Compiler> | |
27 | <Add option="-O2" /> |
|
27 | <Add option="-O2" /> | |
28 | </Compiler> |
|
28 | </Compiler> | |
29 | <Linker> |
|
29 | <Linker> | |
30 | <Add option="-s" /> |
|
30 | <Add option="-s" /> | |
31 | </Linker> |
|
31 | </Linker> | |
32 | </Target> |
|
32 | </Target> | |
33 | </Build> |
|
33 | </Build> | |
34 | <Compiler> |
|
34 | <Compiler> | |
35 | <Add option="-Wall" /> |
|
35 | <Add option="-Wall" /> | |
36 | </Compiler> |
|
36 | </Compiler> | |
37 |
<Unit filename=".. |
|
37 | <Unit filename="../header/FSW-rtems-processing.h" /> | |
38 | <Unit filename="..\src\FSW-rtems-processing.c"> |
|
38 | <Unit filename="../header/TC_handler.h" /> | |
|
39 | <Unit filename="../header/ccsds_types.h" /> | |||
|
40 | <Unit filename="../src/FSW-rtems-processing.c"> | |||
39 | <Option compilerVar="CC" /> |
|
41 | <Option compilerVar="CC" /> | |
40 | </Unit> |
|
42 | </Unit> | |
41 |
<Unit filename=".. |
|
43 | <Unit filename="../src/FSW-rtems.c"> | |
|
44 | <Option compilerVar="CC" /> | |||
|
45 | </Unit> | |||
|
46 | <Unit filename="../src/TC_handler.c"> | |||
42 | <Option compilerVar="CC" /> |
|
47 | <Option compilerVar="CC" /> | |
43 | </Unit> |
|
48 | </Unit> | |
44 | <Extensions> |
|
49 | <Extensions> | |
45 | <code_completion /> |
|
50 | <code_completion /> | |
46 | <debugger /> |
|
51 | <debugger /> | |
47 | </Extensions> |
|
52 | </Extensions> | |
48 | </Project> |
|
53 | </Project> | |
49 | </CodeBlocks_project_file> |
|
54 | </CodeBlocks_project_file> |
@@ -1,37 +1,79 | |||||
1 |
# depslib dependency file v1.0 |
|
1 | # depslib dependency file v1.0 | |
2 | 1355231335 source:e:\missions\solo\dev_ple\src\fsw-rtems.c |
|
2 | 1355231335 source:e:\missions\solo\dev_ple\src\fsw-rtems.c | |
3 | <rtems.h> |
|
3 | <rtems.h> | |
4 | <bsp.h> |
|
4 | <bsp.h> | |
5 | <rtems/confdefs.h> |
|
5 | <rtems/confdefs.h> | |
6 | <drvmgr/drvmgr_confdefs.h> |
|
6 | <drvmgr/drvmgr_confdefs.h> | |
7 | <rtems.h> |
|
7 | <rtems.h> | |
8 | <errno.h> |
|
8 | <errno.h> | |
9 | <fcntl.h> |
|
9 | <fcntl.h> | |
10 | <stdio.h> |
|
10 | <stdio.h> | |
11 | <stdlib.h> |
|
11 | <stdlib.h> | |
12 | <FSW-config.c> |
|
12 | <FSW-config.c> | |
13 | <grspw.h> |
|
13 | <grspw.h> | |
14 | <apbuart.h> |
|
14 | <apbuart.h> | |
15 | <FSW-rtems-processing.h> |
|
15 | <FSW-rtems-processing.h> | |
16 |
|
16 | |||
|
17 | 1355231335 -processing.h> | |||
|
18 | ||||
17 | 1350983928 source:e:\missions\solo\dev_ple\src\grspw.c |
|
19 | 1350983928 source:e:\missions\solo\dev_ple\src\grspw.c | |
18 | <..\header\grspw.h> |
|
20 | <..\header\grspw.h> | |
19 | <stdio.h> |
|
21 | <stdio.h> | |
20 |
|
22 | |||
|
23 | 1354190601 | |||
|
24 | ||||
21 | 1350983928 e:\missions\solo\dev_ple\header\grspw.h |
|
25 | 1350983928 e:\missions\solo\dev_ple\header\grspw.h | |
22 |
|
26 | |||
23 | 1351173364 source:e:\missions\solo\dev_ple\src\fsw-config.c |
|
27 | 1351173364 source:e:\missions\solo\dev_ple\src\fsw-config.c | |
24 | <drvmgr/ambapp_bus.h> |
|
28 | <drvmgr/ambapp_bus.h> | |
25 |
|
29 | |||
|
30 | 1354190602 bapp_bus.h> | |||
|
31 | ||||
26 | 1354190602 e:\missions\solo\dev_ple\src\fsw-config.c |
|
32 | 1354190602 e:\missions\solo\dev_ple\src\fsw-config.c | |
27 | <drvmgr/ambapp_bus.h> |
|
33 | <drvmgr/ambapp_bus.h> | |
28 |
|
34 | |||
29 | 1354190602 source:e:\missions\solo\dev_ple\src\fsw-rtems-processing.c |
|
35 | 1354190602 source:e:\missions\solo\dev_ple\src\fsw-rtems-processing.c | |
30 | <FSW-rtems-processing.h> |
|
36 | <FSW-rtems-processing.h> | |
31 | <math.h> |
|
37 | <math.h> | |
32 | <stdio.h> |
|
38 | <stdio.h> | |
33 | <leon.h> |
|
39 | <leon.h> | |
34 |
|
40 | |||
35 | 1354190601 e:\missions\solo\dev_ple\header\fsw-rtems-processing.h |
|
41 | 1354190601 e:\missions\solo\dev_ple\header\fsw-rtems-processing.h | |
36 | <rtems.h> |
|
42 | <rtems.h> | |
37 |
|
43 | |||
|
44 | 1358144203 source:/opt/DEV_PLE/src/FSW-rtems-processing.c | |||
|
45 | <FSW-rtems-processing.h> | |||
|
46 | <math.h> | |||
|
47 | <stdio.h> | |||
|
48 | <leon.h> | |||
|
49 | ||||
|
50 | 1358144202 /opt/DEV_PLE/header/FSW-rtems-processing.h | |||
|
51 | <rtems.h> | |||
|
52 | ||||
|
53 | 1358441917 source:/opt/DEV_PLE/src/FSW-rtems.c | |||
|
54 | <rtems.h> | |||
|
55 | <bsp.h> | |||
|
56 | <rtems/confdefs.h> | |||
|
57 | <drvmgr/drvmgr_confdefs.h> | |||
|
58 | <rtems.h> | |||
|
59 | <errno.h> | |||
|
60 | <fcntl.h> | |||
|
61 | <stdio.h> | |||
|
62 | <stdlib.h> | |||
|
63 | <FSW-config.c> | |||
|
64 | <grspw.h> | |||
|
65 | <apbuart.h> | |||
|
66 | <TC_handler.h> | |||
|
67 | <FSW-rtems-processing.h> | |||
|
68 | ||||
|
69 | 1358144203 /opt/DEV_PLE/src/FSW-config.c | |||
|
70 | <drvmgr/ambapp_bus.h> | |||
|
71 | ||||
|
72 | 1358441070 source:/opt/DEV_PLE/src/TC_handler.c | |||
|
73 | <TC_handler.h> | |||
|
74 | ||||
|
75 | 1358435124 /opt/DEV_PLE/header/TC_handler.h | |||
|
76 | <ccsds_types.h> | |||
|
77 | ||||
|
78 | 1358440633 /opt/DEV_PLE/header/ccsds_types.h | |||
|
79 |
@@ -1,13 +1,22 | |||||
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=".. |
|
4 | <File name="../header/FSW-rtems-processing.h" open="0" top="0" tabpos="3"> | |
5 |
<Cursor position=" |
|
5 | <Cursor position="82" topLine="0" /> | |
|
6 | </File> | |||
|
7 | <File name="../header/TC_handler.h" open="1" top="0" tabpos="2"> | |||
|
8 | <Cursor position="352" topLine="0" /> | |||
|
9 | </File> | |||
|
10 | <File name="../header/ccsds_types.h" open="1" top="0" tabpos="3"> | |||
|
11 | <Cursor position="1263" topLine="31" /> | |||
6 | </File> |
|
12 | </File> | |
7 |
<File name=".. |
|
13 | <File name="../src/FSW-rtems-processing.c" open="0" top="0" tabpos="2"> | |
8 |
<Cursor position="1 |
|
14 | <Cursor position="18" topLine="0" /> | |
9 | </File> |
|
15 | </File> | |
10 |
<File name=".. |
|
16 | <File name="../src/FSW-rtems.c" open="1" top="1" tabpos="1"> | |
11 |
<Cursor position="1 |
|
17 | <Cursor position="91" topLine="0" /> | |
|
18 | </File> | |||
|
19 | <File name="../src/TC_handler.c" open="1" top="0" tabpos="4"> | |||
|
20 | <Cursor position="7237" topLine="36" /> | |||
12 | </File> |
|
21 | </File> | |
13 | </CodeBlocks_layout_file> |
|
22 | </CodeBlocks_layout_file> |
@@ -1,8 +1,22 | |||||
1 | #ifndef TC_HANDLER_H_INCLUDED |
|
1 | #ifndef TC_HANDLER_H_INCLUDED | |
2 | #define TC_HANDLER_H_INCLUDED |
|
2 | #define TC_HANDLER_H_INCLUDED | |
3 |
|
3 | |||
4 |
#include < |
|
4 | #include <ccsds_types.h> | |
|
5 | ||||
|
6 | unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field | |||
|
7 | unsigned char currentTC_COMPUTED_CRC[2]; | |||
|
8 | unsigned int currentTC_LEN_RCV_AsUnsignedInt; | |||
|
9 | unsigned int currentTM_length; | |||
|
10 | ccsdsTelemetryPacket_t currentTM; | |||
|
11 | ccsdsTelecommandPacket_t currentTC; | |||
|
12 | unsigned char currentTC_processedFlag; | |||
|
13 | ||||
|
14 | unsigned int lookUpTableForCRC[256]; | |||
|
15 | void InitLookUpTableForCRC(); | |||
|
16 | void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData); | |||
5 |
|
17 | |||
6 |
char TM_checker(ccsdsTelecommand |
|
18 | unsigned char TM_checker(ccsdsTelecommandPacket_t * TMPacket); | |
|
19 | unsigned char TM_acceptance_generator(ccsdsTelecommandPacket_t * TCPacket, unsigned int code, ccsdsTelemetryPacket_t * TMPacket); | |||
|
20 | unsigned char TM_not_implemented_generator(ccsdsTelecommandPacket_t * TCPacket, ccsdsTelemetryPacket_t * TMPacket); | |||
7 |
|
21 | |||
8 | #endif // TC_HANDLER_H_INCLUDED |
|
22 | #endif // TC_HANDLER_H_INCLUDED |
@@ -1,68 +1,63 | |||||
1 | #ifndef CCSDS_H_INCLUDED |
|
1 | #ifndef CCSDS_H_INCLUDED | |
2 | #define CCSDS_H_INCLUDED |
|
2 | #define CCSDS_H_INCLUDED | |
3 |
|
3 | |||
4 | #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4 |
|
4 | #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4 | |
|
5 | #define CCSDS_TM_PKT_MAX_SIZE 4412 | |||
5 | #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4 |
|
6 | #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4 | |
6 |
#define CCSDS_T |
|
7 | #define CCSDS_TC_PKT_MAX_SIZE 248 | |
7 | #define CCSDS_PROCESS_ID 11 |
|
8 | #define CCSDS_TC_TM_PACKET_OFFSET 7 | |
8 |
#define CCSDS_P |
|
9 | #define CCSDS_PROCESS_ID 76 | |
9 |
|
10 | #define CCSDS_PACKET_CATEGORY 12 | ||
10 |
#define CCSDS_ |
|
11 | #define CCSDS_DESTINATION_ID 0x21 | |
11 | #define CCSDS_ERR_CAT -2 |
|
12 | ||
12 | #define CCSDS_ERR_LENGTH -3 |
|
13 | #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24 | |
13 | #define CCSDS_ERR_TYPE -4 |
|
14 | #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32 | |
14 | #define CCSDS_ERR_SUBTYPE -5 |
|
|||
15 | #define CCSDS_ERR_SRC -6 |
|
|||
16 | #define CCSDS_ERR_CRC -7 |
|
|||
17 | #define CCSDS_TM_VALID 1 |
|
|||
18 |
|
15 | |||
19 | struct ccsdsTelemetrySourcePacketHeader_str |
|
16 | #define ILLEGAL_APID 0 | |
20 | { |
|
17 | #define WRONG_LEN_PACKET 1 | |
21 | unsigned char targetLogicalAddress; |
|
18 | #define INCOR_CHECKSUM 2 | |
22 | unsigned char protocolIdentifier; |
|
19 | #define ILL_TYPE 3 | |
23 | unsigned char reserved; |
|
20 | #define ILL_SUBTYPE 4 | |
24 | unsigned char userApplication; |
|
21 | #define WRONG_APP_DATA 5 | |
25 | unsigned char packetID[2]; |
|
22 | #define WRONG_CMD_CODE 6 | |
26 | unsigned char packetSequenceControl[2]; |
|
23 | #define CCSDS_TM_VALID 7 | |
27 | unsigned char packetLength[2]; |
|
24 | // | |
28 | unsigned char dataFieldHeader[10]; |
|
25 | #define TC_NOT_EXE 40000 | |
29 | }; |
|
26 | #define WRONG_SRC_ID 40001 | |
30 | typedef struct ccsdsTelemetrySourcePacketHeader_str ccsdsTelemetrySourcePacketHeader_t; |
|
27 | #define FUNCT_NOT_IMPL 40002 | |
|
28 | #define FAIL_DETECTED 40003 | |||
|
29 | #define NOT_ALLOWED 40004 | |||
|
30 | #define CORRUPTED 40005 | |||
|
31 | // | |||
|
32 | #define CCSDS_ERR_SRC 8 | |||
|
33 | #define CCSDS_ERR_CAT 9 | |||
31 |
|
34 | |||
32 |
struct ccsdsTele |
|
35 | struct ccsdsTelemetryPacket_str | |
33 | { |
|
36 | { | |
34 | unsigned char targetLogicalAddress; |
|
37 | volatile unsigned char targetLogicalAddress; | |
35 | unsigned char protocolIdentifier; |
|
38 | volatile unsigned char protocolIdentifier; | |
36 | unsigned char reserved; |
|
39 | volatile unsigned char reserved; | |
37 | unsigned char userApplication; |
|
40 | volatile unsigned char userApplication; | |
38 | unsigned char packetID[2]; |
|
41 | volatile unsigned char packetID[2]; | |
39 | unsigned char packetSequenceControl[2]; |
|
42 | volatile unsigned char packetSequenceControl[2]; | |
40 | unsigned char packetLength[2]; |
|
43 | volatile unsigned char packetLength[2]; | |
41 |
unsigned char dataFieldHeader[ |
|
44 | volatile unsigned char dataFieldHeader[10]; | |
|
45 | volatile unsigned char data[CCSDS_TM_PKT_MAX_SIZE-16]; | |||
42 | }; |
|
46 | }; | |
43 |
typedef struct ccsdsTelemetry |
|
47 | typedef struct ccsdsTelemetryPacket_str ccsdsTelemetryPacket_t; | |
44 |
|
48 | |||
45 | // initialize the ccsds telemetry header |
|
49 | struct ccsdsTelecommandPacket_str | |
46 | ccsdsTelemetrySourcePacketHeader_t ccsdsTelemetryHeader; |
|
50 | { | |
47 | #define INIT_CCSDS_TELEMETRY_HEADER ccsdsTelemetryHeader.targetLogicalAddress = 0x21; \ |
|
51 | //unsigned char targetLogicalAddress; | |
48 | ccsdsTelemetryHeader.protocolIdentifier = 0x02; \ |
|
52 | volatile unsigned char protocolIdentifier; | |
49 | ccsdsTelemetryHeader.reserved = 0x00; \ |
|
53 | volatile unsigned char reserved; | |
50 | ccsdsTelemetryHeader.userApplication = 0x00; \ |
|
54 | volatile unsigned char userApplication; | |
51 | ccsdsTelemetryHeader.packetID[0] = 0x08; \ |
|
55 | volatile unsigned char packetID[2]; | |
52 | ccsdsTelemetryHeader.packetID[1] = 0xbc; \ |
|
56 | volatile unsigned char packetSequenceControl[2]; | |
53 | ccsdsTelemetryHeader.packetSequenceControl[0] = 0xc0; \ |
|
57 | volatile unsigned char packetLength[2]; | |
54 | ccsdsTelemetryHeader.packetSequenceControl[1] = 0x00; \ |
|
58 | volatile unsigned char dataFieldHeader[4]; | |
55 | ccsdsTelemetryHeader.packetLength[0] = 0x00; \ |
|
59 | volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10]; | |
56 | ccsdsTelemetryHeader.packetLength[1] = 0x00; \ |
|
60 | }; | |
57 | ccsdsTelemetryHeader.dataFieldHeader[0] = 0x00; \ |
|
61 | typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t; | |
58 | ccsdsTelemetryHeader.dataFieldHeader[1] = 0x00; \ |
|
|||
59 | ccsdsTelemetryHeader.dataFieldHeader[2] = 0x00; \ |
|
|||
60 | ccsdsTelemetryHeader.dataFieldHeader[3] = 0x00; \ |
|
|||
61 | ccsdsTelemetryHeader.dataFieldHeader[4] = 0x00; \ |
|
|||
62 | ccsdsTelemetryHeader.dataFieldHeader[5] = 0x00; \ |
|
|||
63 | ccsdsTelemetryHeader.dataFieldHeader[6] = 0x00; \ |
|
|||
64 | ccsdsTelemetryHeader.dataFieldHeader[7] = 0x00; \ |
|
|||
65 | ccsdsTelemetryHeader.dataFieldHeader[8] = 0x00; \ |
|
|||
66 | ccsdsTelemetryHeader.dataFieldHeader[9] = 0x00; |
|
|||
67 |
|
62 | |||
68 | #endif // CCSDS_H_INCLUDED |
|
63 | #endif // CCSDS_H_INCLUDED |
@@ -1,407 +1,460 | |||||
1 | //************************* |
|
1 | //************************* | |
2 | // GPL reminder to be added |
|
2 | // GPL reminder to be added | |
3 | //************************* |
|
3 | //************************* | |
4 |
|
4 | |||
5 | #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions |
|
5 | //#define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions | |
6 | #ifdef PRINT_MESSAGES_ON_CONSOLE |
|
6 | #ifdef PRINT_MESSAGES_ON_CONSOLE | |
7 | #define PRINTF(x) printf(x); |
|
7 | #define PRINTF(x) printf(x); | |
8 | #define PRINTF1(x,y) printf(x,y); |
|
8 | #define PRINTF1(x,y) printf(x,y); | |
9 | #define PRINTF2(x,y,z) printf(x,y,z); |
|
9 | #define PRINTF2(x,y,z) printf(x,y,z); | |
10 | #else |
|
10 | #else | |
11 | #define PRINTF(x) |
|
11 | #define PRINTF(x) ; | |
12 | #define PRINTF1(x,y) |
|
12 | #define PRINTF1(x,y) ; | |
13 | #define PRINTF2(x,y,z) |
|
13 | #define PRINTF2(x,y,z) ; | |
14 | #endif |
|
14 | #endif | |
15 |
|
15 | |||
16 | #define CCSDS_TC_PKT_MAX_SIZE 500 // 248 |
|
16 | #define OFFSET_COARSE_TIME 4+10-1 // -1 => the receiver suppresses the target logical address | |
17 | #define CCSDS_TM_PKT_MAX_SIZE 4412 |
|
|||
18 | #define OFFSET_COARSE_TIME 4+10-1 // -1 => the receiver suppressed the target logical address |
|
|||
19 | #define OFFSET_FINE_TIME OFFSET_COARSE_TIME+4 |
|
17 | #define OFFSET_FINE_TIME OFFSET_COARSE_TIME+4 | |
20 | #define TC_FIFO_SIZE 5 |
|
18 | #define TC_FIFO_SIZE 5 | |
21 |
|
19 | |||
22 | #define ADDRESS_APBUART_REGISTERS 0x80000100 |
|
20 | #define ADDRESS_APBUART_REGISTERS 0x80000100 | |
23 | #define ADDRESS_GRSPW_REGISTERS 0x80000500 |
|
21 | #define ADDRESS_GRSPW_REGISTERS 0x80000500 | |
24 | #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff |
|
22 | #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff | |
25 |
|
23 | |||
26 | #define GRSPW_DEVICE_NAME "/dev/grspw0" |
|
24 | #define GRSPW_DEVICE_NAME "/dev/grspw0" | |
27 | #define UART_DEVICE_NAME "/dev/console" |
|
25 | #define UART_DEVICE_NAME "/dev/console" | |
28 |
|
26 | |||
29 | #include <rtems.h> |
|
27 | #include <rtems.h> | |
30 |
|
28 | |||
31 | /* configuration information */ |
|
29 | /* configuration information */ | |
32 |
|
30 | |||
33 | #define CONFIGURE_INIT |
|
31 | #define CONFIGURE_INIT | |
34 | #include <bsp.h> /* for device driver prototypes */ |
|
32 | #include <bsp.h> /* for device driver prototypes */ | |
35 |
|
33 | |||
36 | /* configuration information */ |
|
34 | /* configuration information */ | |
37 |
|
35 | |||
38 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
36 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER | |
39 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
37 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER | |
40 |
|
38 | |||
41 | #define CONFIGURE_MAXIMUM_TASKS 10 |
|
39 | #define CONFIGURE_MAXIMUM_TASKS 10 | |
42 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
|
40 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE | |
43 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
|
41 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) | |
44 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 |
|
42 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 | |
45 | #define CONFIGURE_INIT_TASK_PRIORITY 100 |
|
43 | #define CONFIGURE_INIT_TASK_PRIORITY 100 | |
46 | #define CONFIGURE_MAXIMUM_DRIVERS 16 |
|
44 | #define CONFIGURE_MAXIMUM_DRIVERS 16 | |
47 | #define CONFIGURE_MAXIMUM_PERIODS 1 |
|
45 | #define CONFIGURE_MAXIMUM_PERIODS 1 | |
48 |
|
46 | |||
49 | #include <rtems/confdefs.h> |
|
47 | #include <rtems/confdefs.h> | |
50 |
|
48 | |||
51 | /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ |
|
49 | /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ | |
52 | #ifdef RTEMS_DRVMGR_STARTUP |
|
50 | #ifdef RTEMS_DRVMGR_STARTUP | |
53 | #ifdef LEON3 |
|
51 | #ifdef LEON3 | |
54 | /* Add Timer and UART Driver */ |
|
52 | /* Add Timer and UART Driver */ | |
55 | #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
53 | #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER | |
56 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER |
|
54 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER | |
57 | #endif |
|
55 | #endif | |
58 | #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
56 | #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER | |
59 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART |
|
57 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART | |
60 | #endif |
|
58 | #endif | |
61 | #endif |
|
59 | #endif | |
62 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ |
|
60 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ | |
63 | #include <drvmgr/drvmgr_confdefs.h> |
|
61 | #include <drvmgr/drvmgr_confdefs.h> | |
64 | #endif |
|
62 | #endif | |
65 |
|
63 | |||
66 | #include <rtems.h> |
|
64 | #include <rtems.h> | |
67 | #include <errno.h> |
|
65 | #include <errno.h> | |
68 | #include <fcntl.h> |
|
66 | #include <fcntl.h> | |
69 | #include <stdio.h> |
|
67 | #include <stdio.h> | |
70 | #include <stdlib.h> |
|
68 | #include <stdlib.h> | |
71 |
|
69 | |||
72 | #include <FSW-config.c> |
|
70 | #include <FSW-config.c> | |
73 | #include <grspw.h> |
|
71 | #include <grspw.h> | |
74 | #include <apbuart.h> |
|
72 | #include <apbuart.h> | |
|
73 | #include <TC_handler.h> | |||
75 | #include <FSW-rtems-processing.h> |
|
74 | #include <FSW-rtems-processing.h> | |
|
75 | ||||
|
76 | char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0", | |||
|
77 | "WRONG_LEN_PACKET 1", | |||
|
78 | "INCOR_CHECKSUM 2", | |||
|
79 | "ILL_TYPE 3", | |||
|
80 | "ILL_SUBTYPE 4", | |||
|
81 | "WRONG_APP_DATA 5", | |||
|
82 | "WRONG_CMD_CODE 6", | |||
|
83 | "CCSDS_TM_VALID 7" | |||
|
84 | }; | |||
|
85 | ||||
|
86 | char *tmGeneratorMsg[2] = { "NOTHING_TO_DO", | |||
|
87 | "TM_GENERATED" | |||
|
88 | }; | |||
76 |
|
89 | |||
77 | rtems_task Init( rtems_task_argument argument); /* forward declaration needed */ |
|
90 | rtems_task Init( rtems_task_argument argument); /* forward declaration needed */ | |
78 | rtems_task spw_recv_task(rtems_task_argument argument); |
|
91 | rtems_task spw_recv_task(rtems_task_argument argument); | |
79 | rtems_task spw_tcck_task(rtems_task_argument argument); |
|
92 | rtems_task spw_tcck_task(rtems_task_argument argument); | |
80 | rtems_task spw_spiq_task(rtems_task_argument argument); |
|
93 | rtems_task spw_spiq_task(rtems_task_argument argument); | |
81 | rtems_task spw_stat_task(rtems_task_argument argument); |
|
94 | rtems_task spw_stat_task(rtems_task_argument argument); | |
82 | int configure_spw_link(); |
|
95 | int configure_spw_link(); | |
83 | extern int rtems_cpu_usage_report(); |
|
96 | extern int rtems_cpu_usage_report(); | |
84 | extern int rtems_cpu_usage_reset(); |
|
97 | extern int rtems_cpu_usage_reset(); | |
85 |
|
98 | |||
86 | char *link_status(int status); |
|
99 | char *link_status(int status); | |
87 | void print_statistics(spw_stats *); |
|
100 | void print_statistics(spw_stats *); | |
88 | extern int sched_yield(); |
|
101 | extern int sched_yield(); | |
89 | extern int errno; |
|
102 | extern int errno; | |
90 |
|
103 | |||
91 | char *lstates[6] = {"Error-reset", |
|
104 | char *lstates[6] = {"Error-reset", | |
92 | "Error-wait", |
|
105 | "Error-wait", | |
93 | "Ready", |
|
106 | "Ready", | |
94 | "Started", |
|
107 | "Started", | |
95 | "Connecting", |
|
108 | "Connecting", | |
96 | "Run" |
|
109 | "Run" | |
97 | }; |
|
110 | }; | |
98 |
|
111 | |||
99 | struct tc_fifo_str{ |
|
112 | struct tc_fifo_str{ | |
100 | struct tc_fifo_str *next; |
|
113 | struct tc_fifo_str *next; | |
101 | unsigned char *tc_pkt; |
|
114 | unsigned char *tc_pkt; | |
102 | unsigned int tc_pktlength; |
|
115 | unsigned int tc_pktlength; | |
103 | unsigned char ready; |
|
116 | unsigned char ready; | |
104 | }; |
|
117 | }; | |
105 | struct tc_fifo_str tc_fifo[TC_FIFO_SIZE]; |
|
118 | struct tc_fifo_str tc_fifo[TC_FIFO_SIZE]; | |
106 | struct tc_fifo_str *tc_being_processed; |
|
119 | struct tc_fifo_str *tc_being_processed; | |
107 | struct tc_fifo_str *tc_pending_reception; |
|
120 | struct tc_fifo_str *tc_pending_reception; | |
108 |
|
121 | |||
109 | struct apbuart_regs_str{ |
|
122 | struct apbuart_regs_str{ | |
110 | volatile unsigned int data; |
|
123 | volatile unsigned int data; | |
111 | volatile unsigned int status; |
|
124 | volatile unsigned int status; | |
112 | volatile unsigned int ctrl; |
|
125 | volatile unsigned int ctrl; | |
113 | volatile unsigned int scaler; |
|
126 | volatile unsigned int scaler; | |
114 | volatile unsigned int fifoDebug; |
|
127 | volatile unsigned int fifoDebug; | |
115 | }; |
|
128 | }; | |
116 |
|
129 | |||
117 | int fdSPW; |
|
130 | int fdSPW; | |
118 | int fdUART; |
|
131 | int fdUART; | |
119 |
|
132 | |||
120 | rtems_id Task_id[10]; /* array of task ids */ |
|
133 | rtems_id Task_id[10]; /* array of task ids */ | |
121 | rtems_name Task_name[10]; /* array of task names */ |
|
134 | rtems_name Task_name[10]; /* array of task names */ | |
122 | rtems_name sem_tc_fifo_name; |
|
135 | rtems_name sem_tc_fifo_name; | |
123 | rtems_id sem_tc_fifo_id; |
|
136 | rtems_id sem_tc_fifo_id; | |
124 |
|
137 | |||
125 | rtems_task Init( rtems_task_argument ignored ) { |
|
138 | rtems_task Init( rtems_task_argument ignored ) { | |
126 | rtems_status_code status; |
|
139 | rtems_status_code status; | |
127 | struct apbuart_regs_str *apbuart_regs; |
|
140 | //struct apbuart_regs_str *apbuart_regs; | |
128 | int i; |
|
|||
129 | rtems_isr_entry old_isr_handler; |
|
141 | rtems_isr_entry old_isr_handler; | |
130 |
|
142 | |||
131 | Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' ); |
|
143 | Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' ); | |
132 | Task_name[2] = rtems_build_name( 'T', 'C', 'C', 'K' ); |
|
144 | Task_name[2] = rtems_build_name( 'T', 'C', 'C', 'K' ); | |
133 | Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' ); |
|
145 | Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' ); | |
134 | Task_name[4] = rtems_build_name( 'B', 'P', 'P', 'R' ); |
|
146 | Task_name[4] = rtems_build_name( 'B', 'P', 'P', 'R' ); | |
135 | Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' ); |
|
147 | Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' ); | |
136 | Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' ); |
|
148 | Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' ); | |
137 | Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' ); |
|
149 | Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' ); | |
138 | sem_tc_fifo_name = rtems_build_name( 'S', 'E', 'M', '0' ); |
|
150 | sem_tc_fifo_name = rtems_build_name( 'S', 'E', 'M', '0' ); | |
139 |
|
151 | |||
140 | // RECV |
|
152 | // RECV | |
141 | status = rtems_task_create( |
|
153 | status = rtems_task_create( | |
142 | Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
154 | Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2, | |
143 | RTEMS_DEFAULT_MODES, |
|
155 | RTEMS_DEFAULT_MODES, | |
144 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1] |
|
156 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1] | |
145 | ); |
|
157 | ); | |
146 | // TCCK |
|
158 | // TCCK | |
147 | status = rtems_task_create( |
|
159 | status = rtems_task_create( | |
148 | Task_name[2], 200, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
160 | Task_name[2], 200, RTEMS_MINIMUM_STACK_SIZE * 2, | |
149 | RTEMS_DEFAULT_MODES, |
|
161 | RTEMS_DEFAULT_MODES, | |
150 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2] |
|
162 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2] | |
151 | ); |
|
163 | ); | |
152 | // SPIQ |
|
164 | // SPIQ | |
153 | status = rtems_task_create( |
|
165 | status = rtems_task_create( | |
154 | Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
166 | Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
155 | RTEMS_DEFAULT_MODES, |
|
167 | RTEMS_DEFAULT_MODES, | |
156 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3] |
|
168 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3] | |
157 | ); |
|
169 | ); | |
158 | // BPPR |
|
170 | // BPPR | |
159 | status = rtems_task_create( |
|
171 | status = rtems_task_create( | |
160 | Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
172 | Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2, | |
161 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
173 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
162 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4] |
|
174 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4] | |
163 | ); |
|
175 | ); | |
164 | // STAT |
|
176 | // STAT | |
165 | status = rtems_task_create( |
|
177 | status = rtems_task_create( | |
166 | Task_name[5], 200, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
178 | Task_name[5], 200, RTEMS_MINIMUM_STACK_SIZE * 2, | |
167 | RTEMS_DEFAULT_MODES, |
|
179 | RTEMS_DEFAULT_MODES, | |
168 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5] |
|
180 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5] | |
169 | ); |
|
181 | ); | |
170 | // AVF0 |
|
182 | // AVF0 | |
171 | status = rtems_task_create( |
|
183 | status = rtems_task_create( | |
172 | Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
184 | Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
173 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
185 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
174 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6] |
|
186 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6] | |
175 | ); |
|
187 | ); | |
176 | // BPF0 |
|
188 | // BPF0 | |
177 | status = rtems_task_create( |
|
189 | status = rtems_task_create( | |
178 | Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
190 | Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
179 | RTEMS_DEFAULT_MODES, |
|
191 | RTEMS_DEFAULT_MODES, | |
180 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7] |
|
192 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7] | |
181 | ); |
|
193 | ); | |
182 |
|
194 | |||
183 | status = rtems_semaphore_create( |
|
195 | status = rtems_semaphore_create( | |
184 | sem_tc_fifo_name, |
|
196 | sem_tc_fifo_name, | |
185 | 1, |
|
197 | 1, | |
186 | RTEMS_BINARY_SEMAPHORE, |
|
198 | RTEMS_BINARY_SEMAPHORE, | |
187 | 1, |
|
199 | 1, | |
188 | &sem_tc_fifo_id |
|
200 | &sem_tc_fifo_id | |
189 | ); |
|
201 | ); | |
190 |
|
202 | |||
191 | //******************************************** |
|
203 | //******************************************** | |
192 | // Send the console outputs on the serial port |
|
204 | // Send the console outputs on the serial port | |
193 | apbuart_regs = (struct apbuart_regs_str *) ADDRESS_APBUART_REGISTERS; |
|
205 | //apbuart_regs = (struct apbuart_regs_str *) ADDRESS_APBUART_REGISTERS; | |
194 | apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB; |
|
206 | //apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB; | |
195 | PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") |
|
207 | //PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") | |
196 | // |
|
208 | // | |
197 | //******************************************** |
|
209 | //******************************************** | |
198 |
|
210 | |||
199 | configure_spw_link(); |
|
211 | configure_spw_link(); | |
200 |
|
212 | |||
201 | for (i = 0; i<TC_FIFO_SIZE; i++){ |
|
|||
202 | if (i==TC_FIFO_SIZE-1) tc_fifo[i].next = &tc_fifo[0]; |
|
|||
203 | else tc_fifo[i].next = &tc_fifo[i+1]; |
|
|||
204 | tc_fifo[i].tc_pkt = (unsigned char *) malloc(CCSDS_TC_PKT_MAX_SIZE); |
|
|||
205 | tc_fifo[i].tc_pktlength = 0; |
|
|||
206 | tc_fifo[i].ready = 0; |
|
|||
207 | } |
|
|||
208 |
|
||||
209 | status = rtems_interrupt_catch( spectral_matrices_isr, 0x1c, &old_isr_handler) ; // 0x1c comes from sparcv8.pdf p.76 |
|
213 | status = rtems_interrupt_catch( spectral_matrices_isr, 0x1c, &old_isr_handler) ; // 0x1c comes from sparcv8.pdf p.76 | |
210 | if (status==RTEMS_SUCCESSFUL) PRINTF("In INIT *** rtems_interrupt_catch successfullly configured\n") |
|
214 | if (status==RTEMS_SUCCESSFUL) PRINTF("In INIT *** rtems_interrupt_catch successfullly configured\n") | |
211 |
|
215 | |||
212 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRICES ); |
|
216 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRICES ); | |
213 |
|
217 | |||
214 |
|
||||
215 | status = rtems_task_start( Task_id[2], spw_tcck_task, 1 ); |
|
218 | status = rtems_task_start( Task_id[2], spw_tcck_task, 1 ); | |
216 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_TCCK\n") |
|
219 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_TCCK\n") | |
217 |
|
220 | |||
218 | status = rtems_task_start( Task_id[3], spw_spiq_task, 1 ); |
|
221 | status = rtems_task_start( Task_id[3], spw_spiq_task, 1 ); | |
219 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n") |
|
222 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n") | |
220 |
|
223 | |||
221 | status = rtems_task_start( Task_id[1], spw_recv_task, 1 ); |
|
224 | status = rtems_task_start( Task_id[1], spw_recv_task, 1 ); | |
222 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n") |
|
225 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n") | |
223 |
|
226 | |||
224 | status = rtems_task_start( Task_id[4], spw_bppr_task_rate_monotonic, 1 ); |
|
227 | //status = rtems_task_start( Task_id[4], spw_bppr_task_rate_monotonic, 1 ); | |
225 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n") |
|
228 | //if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n") | |
226 |
|
229 | |||
227 | status = rtems_task_start( Task_id[5], spw_stat_task, 1 ); |
|
230 | status = rtems_task_start( Task_id[5], spw_stat_task, 1 ); | |
228 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n") |
|
231 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n") | |
229 |
|
232 | |||
230 | status = rtems_task_start( Task_id[6], spw_avf0_task, 1 ); |
|
233 | status = rtems_task_start( Task_id[6], spw_avf0_task, 1 ); | |
231 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n") |
|
234 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n") | |
232 |
|
235 | |||
233 | status = rtems_task_start( Task_id[7], spw_bpf0_task, 1 ); |
|
236 | status = rtems_task_start( Task_id[7], spw_bpf0_task, 1 ); | |
234 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n") |
|
237 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n") | |
|
238 | ||||
|
239 | InitLookUpTableForCRC(); // in TC_handler.h | |||
235 |
|
240 | |||
236 | status = rtems_task_delete(RTEMS_SELF); |
|
241 | status = rtems_task_delete(RTEMS_SELF); | |
237 | } |
|
242 | } | |
238 |
|
243 | |||
239 | rtems_task spw_recv_task( rtems_task_argument unused ) { |
|
244 | rtems_task spw_recv_task_old( rtems_task_argument unused ) { | |
240 | rtems_status_code status; |
|
245 | rtems_status_code status; | |
241 | int len = 0; |
|
246 | int len = 0; | |
242 | unsigned int i; |
|
247 | unsigned int i; | |
243 |
|
248 | |||
244 | PRINTF("In RECV *** \n") |
|
249 | PRINTF("In RECV *** \n") | |
245 |
|
250 | |||
246 | status = rtems_semaphore_obtain( sem_tc_fifo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
251 | status = rtems_semaphore_obtain( sem_tc_fifo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); | |
247 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error: rtems_semaphore_obtain\n") |
|
252 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error: rtems_semaphore_obtain\n") | |
248 | for (i = 0; i<TC_FIFO_SIZE; i++){ // initialize the tc fifo ring |
|
253 | for (i = 0; i<TC_FIFO_SIZE; i++){ // initialize the tc fifo ring | |
249 | tc_fifo[i].tc_pktlength = 0; |
|
254 | tc_fifo[i].tc_pktlength = 0; | |
250 | tc_fifo[i].ready = 0; |
|
255 | tc_fifo[i].ready = 0; | |
251 | } |
|
256 | } | |
252 | status = rtems_semaphore_release( sem_tc_fifo_id ); |
|
257 | status = rtems_semaphore_release( sem_tc_fifo_id ); | |
253 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error: rtems_semaphore_release\n") |
|
258 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error: rtems_semaphore_release\n") | |
254 |
|
259 | |||
255 | tc_being_processed = tc_fifo; |
|
260 | tc_being_processed = tc_fifo; | |
256 | tc_pending_reception = tc_fifo; |
|
261 | tc_pending_reception = tc_fifo; | |
257 |
|
262 | |||
258 | while(1){ |
|
263 | while(1){ | |
259 | if (tc_pending_reception->ready == 0){ |
|
264 | if (tc_pending_reception->ready == 0){ | |
260 | PRINTF("In RECV *** Just before read\n") |
|
265 | PRINTF("In RECV *** Just before read\n") | |
261 | len = read(fdSPW, tc_pending_reception->tc_pkt, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking |
|
266 | len = read(fdSPW, tc_pending_reception->tc_pkt, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking | |
262 | PRINTF("In RECV *** Just after read\n") |
|
267 | PRINTF("In RECV *** Just after read\n") | |
263 | if (len == -1) { // error during the read call |
|
268 | if (len == -1) { // error during the read call | |
264 | PRINTF("In RECV *** last read call returned -1\n") |
|
269 | PRINTF("In RECV *** last read call returned -1\n") | |
265 | if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) |
|
270 | if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) | |
266 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") |
|
271 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") | |
267 | if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) |
|
272 | if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) | |
268 | PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") |
|
273 | PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") | |
269 | } |
|
274 | } | |
270 | else { |
|
275 | else { | |
271 | tc_pending_reception->tc_pktlength = len; |
|
276 | tc_pending_reception->tc_pktlength = len; | |
272 | tc_pending_reception->ready = 1; |
|
277 | tc_pending_reception->ready = 1; | |
273 | PRINTF1("In RECV *** Got Message of length %d\n",tc_pending_reception->tc_pktlength) |
|
278 | PRINTF1("In RECV *** Got Message of length %d\n",tc_pending_reception->tc_pktlength) | |
274 | status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK |
|
279 | status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK | |
275 | if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n") |
|
280 | if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n") | |
276 | tc_pending_reception = tc_pending_reception->next; |
|
281 | tc_pending_reception = tc_pending_reception->next; | |
277 | sched_yield(); |
|
282 | sched_yield(); | |
278 | } |
|
283 | } | |
279 | } |
|
284 | } | |
280 | else { |
|
285 | else { | |
281 | status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK |
|
286 | status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK | |
282 | if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n") |
|
287 | if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n") | |
283 | sched_yield(); // if not executed, the system blocks when the packets arrive faster than the processing |
|
288 | sched_yield(); // if not executed, the system blocks when the packets arrive faster than the processing | |
284 | // this call gives back the hand to the scheduler and allows TCCK to process the TC packets |
|
289 | // this call gives back the hand to the scheduler and allows TCCK to process the TC packets | |
285 | } |
|
290 | } | |
286 | } |
|
291 | } | |
287 |
|
292 | |||
288 | close(fdSPW); |
|
293 | close(fdSPW); | |
|
294 | } | |||
|
295 | ||||
|
296 | rtems_task spw_recv_task( rtems_task_argument unused ) { | |||
|
297 | rtems_status_code status; | |||
|
298 | int len = 0; | |||
|
299 | ||||
|
300 | PRINTF("In RECV BIS *** \n") | |||
|
301 | ||||
|
302 | currentTC_processedFlag = 1; // reset the flag | |||
|
303 | ||||
|
304 | while(1){ | |||
|
305 | while(currentTC_processedFlag == 0) sched_yield(); | |||
|
306 | len = read(fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking | |||
|
307 | if (len == -1){ // error during the read call | |||
|
308 | PRINTF("In RECV *** last read call returned -1\n") | |||
|
309 | if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) | |||
|
310 | PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n") | |||
|
311 | if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) | |||
|
312 | PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n") | |||
|
313 | } | |||
|
314 | else { | |||
|
315 | currentTC_processedFlag = 0; | |||
|
316 | PRINTF1("In RECV *** Got Message of length %d\n", len) | |||
|
317 | currentTC_LEN_RCV[0] = 0x00; | |||
|
318 | currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field | |||
|
319 | currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes | |||
|
320 | status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK | |||
|
321 | if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n") | |||
|
322 | } | |||
|
323 | } | |||
|
324 | ||||
|
325 | close(fdSPW); | |||
289 | } |
|
326 | } | |
290 |
|
327 | |||
291 | rtems_task spw_tcck_task( rtems_task_argument unused ) { |
|
328 | rtems_task spw_tcck_task( rtems_task_argument unused ) { | |
292 | rtems_status_code status; |
|
329 | rtems_status_code status; | |
293 | rtems_event_set event_out; |
|
330 | rtems_event_set event_out; | |
|
331 | unsigned char result; | |||
|
332 | unsigned int code; | |||
294 |
|
333 | |||
295 | PRINTF("In TCCK ***\n") |
|
334 | PRINTF("In TCCK ***\n") | |
296 | while(1){ |
|
335 | while(1){ | |
297 | status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); |
|
336 | status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an event to process a TC packet | |
298 | if (status == RTEMS_SUCCESSFUL) |
|
337 | if (status == RTEMS_SUCCESSFUL) | |
299 | { |
|
338 | { | |
300 | while(tc_being_processed->ready==1){ |
|
339 | GetCRCAsTwoBytes((unsigned char*)currentTC.packetID, currentTC_COMPUTED_CRC, currentTC_LEN_RCV_AsUnsignedInt + 5); | |
301 | printf("In TCCK *** COARSE TIME 0x%x 0x%x 0x%x 0x%x FINE_TIME 0x%x 0x%x\n", |
|
340 | code = TM_checker(¤tTC); | |
302 | tc_being_processed->tc_pkt[OFFSET_COARSE_TIME], |
|
341 | PRINTF1(" %s\n", errorCCSDSMsg[code]) | |
303 | tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+1], |
|
342 | if (code == 7){ // if the TC is valid, the TM_LFR_TC_EXE_NOT_IMPLEMENTED packet is sent | |
304 | tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+2], |
|
343 | result = TM_not_implemented_generator(¤tTC, ¤tTM); | |
305 | tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+3], |
|
344 | PRINTF1(" %s\n", tmGeneratorMsg[result]) | |
306 | tc_being_processed->tc_pkt[OFFSET_FINE_TIME], |
|
345 | result = write( fdSPW, (char*)¤tTM, currentTM_length ); | |
307 | tc_being_processed->tc_pkt[OFFSET_FINE_TIME+1]); |
|
346 | if (result==-1) printf("IN TCCK *** error sending TM of size: %d\n", currentTM_length); | |
308 | tc_being_processed->ready = 0; |
|
347 | } | |
309 | tc_being_processed = tc_being_processed->next; |
|
348 | else{ // if the TC is not valid, the TM_LFR_TC_EXE_CORRUPTED is sent | |
310 | } |
|
349 | result = TM_acceptance_generator(¤tTC, code, ¤tTM); | |
311 | } |
|
350 | PRINTF1(" %s\n", tmGeneratorMsg[result]) | |
|
351 | result = write( fdSPW, (char*)¤tTM, currentTM_length ); | |||
|
352 | if (result==-1) printf("IN TCCK *** error sending TM of size: %d\n", currentTM_length); | |||
|
353 | } | |||
|
354 | ||||
|
355 | currentTC_processedFlag = 1; | |||
|
356 | } | |||
312 | } |
|
357 | } | |
313 | } |
|
358 | } | |
314 |
|
359 | |||
315 | rtems_task spw_spiq_task(rtems_task_argument unused){ |
|
360 | rtems_task spw_spiq_task(rtems_task_argument unused){ | |
316 | rtems_event_set event_out; |
|
361 | rtems_event_set event_out; | |
317 | struct grspw_regs_str *grspw_regs; |
|
362 | struct grspw_regs_str *grspw_regs; | |
318 | grspw_regs = (struct grspw_regs_str *) ADDRESS_GRSPW_REGISTERS; |
|
363 | grspw_regs = (struct grspw_regs_str *) ADDRESS_GRSPW_REGISTERS; | |
319 |
|
364 | |||
320 | while(1){ |
|
365 | while(1){ | |
321 | PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n") |
|
366 | PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n") | |
322 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
367 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
323 |
|
368 | |||
324 | if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task |
|
369 | if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task | |
325 | PRINTF("In SPIQ *** Error suspending RECV Task\n") |
|
370 | PRINTF("In SPIQ *** Error suspending RECV Task\n") | |
326 |
|
371 | |||
327 | configure_spw_link(); |
|
372 | configure_spw_link(); | |
328 |
|
373 | |||
329 | if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task |
|
374 | if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task | |
330 | PRINTF("In SPIQ *** Error resume RECV Task\n") |
|
375 | PRINTF("In SPIQ *** Error resume RECV Task\n") | |
331 | } |
|
376 | } | |
332 | } |
|
377 | } | |
333 |
|
378 | |||
334 | char *link_status(int status){ |
|
379 | char *link_status(int status){ | |
335 | return lstates[status]; |
|
380 | return lstates[status]; | |
336 | } |
|
381 | } | |
337 |
|
382 | |||
338 | void print_statistics(spw_stats *stats) |
|
383 | void print_statistics(spw_stats *stats) | |
339 | { |
|
384 | { | |
340 | //printf(" ******** STATISTICS ******** \n"); |
|
385 | //printf(" ******** STATISTICS ******** \n"); | |
341 | printf("Transmit link errors: %i\n", stats->tx_link_err); |
|
386 | printf("Transmit link errors: %i\n", stats->tx_link_err); | |
342 | printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err); |
|
387 | printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err); | |
343 | printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err); |
|
388 | printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err); | |
344 | printf("Receiver EEP errors: %i\n", stats->rx_eep_err); |
|
389 | printf("Receiver EEP errors: %i\n", stats->rx_eep_err); | |
345 | printf("Receiver truncation errors: %i\n", stats->rx_truncated); |
|
390 | printf("Receiver truncation errors: %i\n", stats->rx_truncated); | |
346 | printf("Parity errors: %i\n", stats->parity_err); |
|
391 | printf("Parity errors: %i\n", stats->parity_err); | |
347 | printf("Escape errors: %i\n", stats->escape_err); |
|
392 | printf("Escape errors: %i\n", stats->escape_err); | |
348 | printf("Credit errors: %i\n", stats->credit_err); |
|
393 | printf("Credit errors: %i\n", stats->credit_err); | |
349 | printf("Disconnect errors: %i\n", stats->disconnect_err); |
|
394 | printf("Disconnect errors: %i\n", stats->disconnect_err); | |
350 | printf("Write synchronization errors: %i\n", stats->write_sync_err); |
|
395 | printf("Write synchronization errors: %i\n", stats->write_sync_err); | |
351 | printf("Early EOP/EEP: %i\n", stats->early_ep); |
|
396 | printf("Early EOP/EEP: %i\n", stats->early_ep); | |
352 | printf("Invalid Node Address: %i\n", stats->invalid_address); |
|
397 | printf("Invalid Node Address: %i\n", stats->invalid_address); | |
353 | printf("Packets transmitted: %i\n", stats->packets_sent); |
|
398 | printf("Packets transmitted: %i\n", stats->packets_sent); | |
354 | printf("Packets received: %i\n", stats->packets_received); |
|
399 | printf("Packets received: %i\n", stats->packets_received); | |
355 | } |
|
400 | } | |
356 |
|
401 | |||
357 | int configure_spw_link() |
|
402 | int configure_spw_link() | |
358 | { |
|
403 | { | |
359 | rtems_status_code status; |
|
404 | rtems_status_code status; | |
360 |
|
405 | |||
361 | close(fdSPW); // close the device if it is already open |
|
406 | close(fdSPW); // close the device if it is already open | |
362 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware |
|
407 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware | |
363 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") |
|
408 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") | |
364 | while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){ |
|
409 | while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){ | |
365 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n") |
|
410 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n") | |
366 | close(fdSPW); // close the device |
|
411 | close(fdSPW); // close the device | |
367 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware |
|
412 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware | |
368 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") |
|
413 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") | |
369 | rtems_task_wake_after(100); |
|
414 | rtems_task_wake_after(100); | |
370 | } |
|
415 | } | |
371 |
|
416 | |||
372 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n") |
|
417 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n") | |
373 |
|
418 | |||
374 | // sets a few parameters of the link |
|
419 | // sets a few parameters of the link | |
375 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit |
|
420 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit | |
376 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n") |
|
421 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n") | |
377 | ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
422 | // | |
378 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
423 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception | |
379 | ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a |
|
424 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") | |
380 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
425 | // | |
381 | ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts |
|
426 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a | |
382 |
if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_ |
|
427 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs | |
383 | ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
428 | // | |
384 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
429 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts | |
|
430 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") | |||
|
431 | // | |||
|
432 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit | |||
|
433 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |||
|
434 | // | |||
|
435 | //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destinatino key | |||
|
436 | //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |||
|
437 | // | |||
385 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n") |
|
438 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n") | |
386 |
|
439 | |||
387 | return RTEMS_SUCCESSFUL; |
|
440 | return RTEMS_SUCCESSFUL; | |
388 | } |
|
441 | } | |
389 |
|
442 | |||
390 | rtems_task spw_stat_task(rtems_task_argument argument){ |
|
443 | rtems_task spw_stat_task(rtems_task_argument argument){ | |
391 | int i; |
|
444 | int i; | |
392 | i = 0; |
|
445 | i = 0; | |
393 | PRINTF("In STAT *** \n") |
|
446 | PRINTF("In STAT *** \n") | |
394 | while(1){ |
|
447 | while(1){ | |
395 | rtems_task_wake_after(1000); |
|
448 | rtems_task_wake_after(1000); | |
396 | PRINTF1("%d\n", i) |
|
449 | PRINTF1("%d\n", i) | |
397 | if (i == 2) { |
|
450 | if (i == 2) { | |
398 | rtems_cpu_usage_report(); |
|
451 | rtems_cpu_usage_report(); | |
399 | rtems_cpu_usage_reset(); |
|
452 | rtems_cpu_usage_reset(); | |
400 | i = 0; |
|
453 | i = 0; | |
401 | } |
|
454 | } | |
402 | else i++; |
|
455 | else i++; | |
403 | } |
|
456 | } | |
404 | } |
|
457 | } | |
405 |
|
458 | |||
406 |
|
459 | |||
407 |
|
460 |
@@ -1,74 +1,207 | |||||
1 |
#include < |
|
1 | #include <TC_handler.h> | |
2 |
|
2 | |||
3 | char TM_checker(ccsdsTelecommandSourcePacketHeader_t * TMPacket) |
|
3 | unsigned int Crc_opt( unsigned char D, unsigned int Chk) | |
|
4 | { | |||
|
5 | return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]); | |||
|
6 | } | |||
|
7 | ||||
|
8 | void InitLookUpTableForCRC() | |||
|
9 | { | |||
|
10 | unsigned int i, tmp; | |||
|
11 | for (i=0; i<256; i++) | |||
|
12 | { | |||
|
13 | tmp = 0; | |||
|
14 | if((i & 1) != 0) tmp = tmp ^ 0x1021; | |||
|
15 | if((i & 2) != 0) tmp = tmp ^ 0x2042; | |||
|
16 | if((i & 4) != 0) tmp = tmp ^ 0x4084; | |||
|
17 | if((i & 8) != 0) tmp = tmp ^ 0x8108; | |||
|
18 | if((i & 16) != 0) tmp = tmp ^ 0x1231; | |||
|
19 | if((i & 32) != 0) tmp = tmp ^ 0x2462; | |||
|
20 | if((i & 64) != 0) tmp = tmp ^ 0x48c4; | |||
|
21 | if((i & 128) != 0) tmp = tmp ^ 0x9188; | |||
|
22 | lookUpTableForCRC[i] = tmp; | |||
|
23 | } | |||
|
24 | } | |||
|
25 | ||||
|
26 | void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData){ | |||
|
27 | unsigned int Chk; | |||
|
28 | int j; | |||
|
29 | Chk = 0xffff; // reset the syndrom to all ones | |||
|
30 | for (j=0; j<sizeOfData; j++) { | |||
|
31 | Chk = Crc_opt(data[j], Chk); | |||
|
32 | } | |||
|
33 | crcAsTwoBytes[0] = (unsigned char) (Chk >> 8); | |||
|
34 | crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff); | |||
|
35 | } | |||
|
36 | ||||
|
37 | unsigned char TM_checker(ccsdsTelecommandPacket_t * TMPacket) | |||
4 | { |
|
38 | { | |
5 | unsigned char pid = 0; |
|
39 | unsigned char pid = 0; | |
6 | unsigned char category = 0; |
|
40 | unsigned char category = 0; | |
7 | unsigned int length = 0; |
|
41 | unsigned int length = 0; | |
|
42 | unsigned char packetType = 0; | |||
|
43 | unsigned char packetSubtype = 0; | |||
|
44 | unsigned char * CCSDSContent; | |||
8 |
|
45 | |||
9 | // APID check *** APID on 2 bytes |
|
46 | // APID check *** APID on 2 bytes | |
10 | pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx |
|
47 | pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx | |
11 | category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210 |
|
48 | category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210 | |
12 |
if (pid!=CCSDS_PROCESS_ID) return |
|
49 | if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID; | |
13 |
if (category!=CCSDS_PACKET_CATEGORY) return |
|
50 | if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID; | |
14 |
|
51 | |||
15 | // packet length check |
|
52 | // packet length check | |
16 |
length = |
|
53 | length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1]; | |
17 | if (category<=CCSDS_TELECOMMAND_MAX_PACKET_LENGTH) return CCSDS_ERR_LENGTH; // check that the packet does not exceed the MAX size |
|
54 | if (length != (currentTC_LEN_RCV[0] * 256 + currentTC_LEN_RCV[1]) ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD | |
18 |
|
55 | if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size | ||
19 | // service type, subtype and packet length check |
|
56 | ||
20 | switch(TMPacket->dataFieldHeader[1]) { // service type, authorized values are 181 and 9 |
|
57 | packetType = TMPacket->dataFieldHeader[1]; | |
21 | case 181: |
|
58 | packetSubtype = TMPacket->dataFieldHeader[2]; | |
22 | switch(TMPacket->dataFieldHeader[2]){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61 |
|
59 | // service type, subtype and packet length check | |
23 | case 3: |
|
60 | if (packetType == 181){ | |
24 | if (length!=12) return CCSDS_ERR_LENGTH; |
|
61 | switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61 | |
25 | break; |
|
62 | case 3: | |
26 | case 20: |
|
63 | if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
27 | if (length!=14) return CCSDS_ERR_LENGTH; |
|
64 | break; | |
28 | break; |
|
65 | case 20: | |
29 | case 21: |
|
66 | if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
30 | if (length!=20) return CCSDS_ERR_LENGTH; |
|
67 | break; | |
31 | break; |
|
68 | case 21: | |
32 | case 24: |
|
69 | if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
33 | if (length!=14) return CCSDS_ERR_LENGTH; |
|
70 | break; | |
34 | break; |
|
71 | case 24: | |
35 | case 27: |
|
72 | if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
36 | if (length!=14) return CCSDS_ERR_LENGTH; |
|
73 | break; | |
37 | break; |
|
74 | case 27: | |
38 | case 28: |
|
75 | if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
39 | if (length!=14) return CCSDS_ERR_LENGTH; |
|
76 | break; | |
40 | break; |
|
77 | case 28: | |
41 | case 30: |
|
78 | if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
42 | if (length!=12) return CCSDS_ERR_LENGTH; |
|
79 | break; | |
43 | break; |
|
80 | case 30: | |
44 | case 40: |
|
81 | if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
45 | if (length!=20) return CCSDS_ERR_LENGTH; |
|
82 | break; | |
46 | break; |
|
83 | case 40: | |
47 | case 50: |
|
84 | if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
48 | if (length!=50) return CCSDS_ERR_LENGTH; |
|
85 | break; | |
49 | break; |
|
86 | case 50: | |
50 | case 60: |
|
87 | if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
51 | if (length!=12) return CCSDS_ERR_LENGTH; |
|
88 | break; | |
52 | break; |
|
89 | case 60: | |
53 | case 61: |
|
90 | if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
54 | if (length!=12) return CCSDS_ERR_LENGTH; |
|
91 | break; | |
55 | break; |
|
92 | case 61: | |
56 | default: |
|
93 | if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
57 | return CCSDS_ERR_SUBTYPE; |
|
94 | break; | |
58 |
|
|
95 | default: | |
59 | } |
|
96 | return ILL_SUBTYPE; | |
60 | case 9: |
|
97 | break; | |
61 | if (TMPacket->dataFieldHeader[2]==129) return CCSDS_ERR_SUBTYPE; |
|
98 | } | |
62 | if (length!=18) return CCSDS_ERR_LENGTH; |
|
99 | } | |
63 | break; |
|
100 | else if (packetType == 9){ | |
64 | default: |
|
101 | if (packetSubtype!=129) return ILL_SUBTYPE; | |
65 | return CCSDS_ERR_TYPE; |
|
102 | if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET; | |
66 | break; |
|
103 | } | |
67 | } |
|
104 | else return ILL_TYPE; | |
68 |
|
105 | |||
69 | // source ID check // Source ID not documented in the ICD |
|
106 | // source ID check // Source ID not documented in the ICD | |
70 |
|
107 | |||
71 | // packet error control, CRC check |
|
108 | // packet error control, CRC check | |
|
109 | CCSDSContent = (unsigned char*) TMPacket->packetID; | |||
|
110 | GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC | |||
|
111 | if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM; | |||
|
112 | if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM; | |||
72 |
|
113 | |||
73 | return CCSDS_TM_VALID; |
|
114 | return CCSDS_TM_VALID; | |
74 | } |
|
115 | } | |
|
116 | ||||
|
117 | unsigned char TM_acceptance_generator(ccsdsTelecommandPacket_t * TCPacket, unsigned int code, ccsdsTelemetryPacket_t * TMPacket) | |||
|
118 | { | |||
|
119 | unsigned int packetLength = 0; | |||
|
120 | packetLength = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1]; | |||
|
121 | if ( (code == 0) | (code == 1) | (code == 2) | |||
|
122 | | (code == 3) | (code == 4) | (code == 5) ) | |||
|
123 | { // generated TM_LFR_TC_EXE_CORRUPTED | |||
|
124 | TMPacket->targetLogicalAddress = CCSDS_DESTINATION_ID; | |||
|
125 | TMPacket->protocolIdentifier = 0x02; | |||
|
126 | TMPacket->reserved = 0x00; | |||
|
127 | TMPacket->userApplication = 0x00; | |||
|
128 | // | |||
|
129 | TMPacket->packetID[0] = 0x0c; | |||
|
130 | TMPacket->packetID[1] = 0xc1; | |||
|
131 | TMPacket->packetSequenceControl[0] = 0xc0; | |||
|
132 | TMPacket->packetSequenceControl[1] = 0x00; | |||
|
133 | TMPacket->packetLength[0] = 0x00; | |||
|
134 | TMPacket->packetLength[1] = SIZE_TM_LFR_TC_EXE_CORRUPTED-CCSDS_TC_TM_PACKET_OFFSET; | |||
|
135 | // | |||
|
136 | TMPacket->dataFieldHeader[0] = 0x10; | |||
|
137 | TMPacket->dataFieldHeader[1] = 0x01; // service type | |||
|
138 | TMPacket->dataFieldHeader[2] = 0x08; // service subtype | |||
|
139 | TMPacket->dataFieldHeader[3] = CCSDS_DESTINATION_ID; | |||
|
140 | TMPacket->dataFieldHeader[4] = 0x00; // time | |||
|
141 | TMPacket->dataFieldHeader[5] = 0x00; // time | |||
|
142 | TMPacket->dataFieldHeader[6] = 0x00; // time | |||
|
143 | TMPacket->dataFieldHeader[7] = 0x00; // time | |||
|
144 | TMPacket->dataFieldHeader[8] = 0x00; // time | |||
|
145 | TMPacket->dataFieldHeader[9] = 0x00; // time | |||
|
146 | // | |||
|
147 | TMPacket->data[0] = 0x9c; // failure code | |||
|
148 | TMPacket->data[1] = 0x45; // failure code | |||
|
149 | TMPacket->data[2] = TCPacket->packetID[0]; | |||
|
150 | TMPacket->data[3] = TCPacket->packetID[1]; | |||
|
151 | TMPacket->data[4] = TCPacket->packetSequenceControl[0]; | |||
|
152 | TMPacket->data[5] = TCPacket->packetSequenceControl[1]; | |||
|
153 | TMPacket->data[6] = TCPacket->dataFieldHeader[1]; // type | |||
|
154 | TMPacket->data[7] = TCPacket->dataFieldHeader[2]; // subtype | |||
|
155 | TMPacket->data[8] = currentTC_LEN_RCV[0]; | |||
|
156 | TMPacket->data[9] = currentTC_LEN_RCV[1]; | |||
|
157 | TMPacket->data[10] = TCPacket->packetLength[0]; | |||
|
158 | TMPacket->data[11] = TCPacket->packetLength[1]; | |||
|
159 | TMPacket->data[12] = TCPacket->dataAndCRC[packetLength]; | |||
|
160 | TMPacket->data[13] = TCPacket->dataAndCRC[packetLength+1]; | |||
|
161 | TMPacket->data[14] = currentTC_COMPUTED_CRC[0]; | |||
|
162 | TMPacket->data[15] = currentTC_COMPUTED_CRC[1]; | |||
|
163 | // | |||
|
164 | currentTM_length = SIZE_TM_LFR_TC_EXE_CORRUPTED-CCSDS_TC_TM_PACKET_OFFSET; | |||
|
165 | } | |||
|
166 | else return 0; | |||
|
167 | return 1; | |||
|
168 | } | |||
|
169 | ||||
|
170 | unsigned char TM_not_implemented_generator(ccsdsTelecommandPacket_t * TCPacket, ccsdsTelemetryPacket_t * TMPacket) | |||
|
171 | { | |||
|
172 | TMPacket->targetLogicalAddress = CCSDS_DESTINATION_ID; | |||
|
173 | TMPacket->protocolIdentifier = 0x02; | |||
|
174 | TMPacket->reserved = 0x00; | |||
|
175 | TMPacket->userApplication = 0x00; | |||
|
176 | // | |||
|
177 | TMPacket->packetID[0] = 0x0c; | |||
|
178 | TMPacket->packetID[1] = 0xc1; | |||
|
179 | TMPacket->packetSequenceControl[0] = 0xc0; | |||
|
180 | TMPacket->packetSequenceControl[1] = 0x00; | |||
|
181 | TMPacket->packetLength[0] = 0x00; | |||
|
182 | TMPacket->packetLength[1] = SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED-CCSDS_TC_TM_PACKET_OFFSET; | |||
|
183 | // | |||
|
184 | TMPacket->dataFieldHeader[0] = 0x10; | |||
|
185 | TMPacket->dataFieldHeader[1] = 0x01; // service type | |||
|
186 | TMPacket->dataFieldHeader[2] = 0x08; // service subtype | |||
|
187 | TMPacket->dataFieldHeader[3] = CCSDS_DESTINATION_ID; | |||
|
188 | TMPacket->dataFieldHeader[4] = 0x00; // time | |||
|
189 | TMPacket->dataFieldHeader[5] = 0x00; // time | |||
|
190 | TMPacket->dataFieldHeader[6] = 0x00; // time | |||
|
191 | TMPacket->dataFieldHeader[7] = 0x00; // time | |||
|
192 | TMPacket->dataFieldHeader[8] = 0x00; // time | |||
|
193 | TMPacket->dataFieldHeader[9] = 0x00; // time | |||
|
194 | // | |||
|
195 | TMPacket->data[0] = 0x9c; // failure code | |||
|
196 | TMPacket->data[1] = 0x42; // failure code | |||
|
197 | TMPacket->data[2] = TCPacket->packetID[0]; | |||
|
198 | TMPacket->data[3] = TCPacket->packetID[1]; | |||
|
199 | TMPacket->data[4] = TCPacket->packetSequenceControl[0]; | |||
|
200 | TMPacket->data[5] = TCPacket->packetSequenceControl[1]; | |||
|
201 | TMPacket->data[6] = TCPacket->dataFieldHeader[1]; // type | |||
|
202 | TMPacket->data[7] = TCPacket->dataFieldHeader[2]; // subtype | |||
|
203 | // | |||
|
204 | currentTM_length = SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED-CCSDS_TC_TM_PACKET_OFFSET; | |||
|
205 | ||||
|
206 | return 1; | |||
|
207 | } |
General Comments 0
You need to be logged in to leave comments.
Login now