##// END OF EJS Templates
First implementation of the TC checker...
paul@pc-solar1.lab-lpp.local -
r2:a683a5ce5797 default
parent child
Show More
@@ -7,20 +7,20
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\Debug\FSW-rtems" prefix_auto="1" extension_auto="1" />
10 <Option output="bin/Debug/fsw" prefix_auto="1" extension_auto="1" />
11 <Option object_output="obj\Debug\" />
11 <Option object_output="obj/Debug/" />
12 <Option type="1" />
12 <Option type="1" />
13 <Option compiler="sparc_rtems_gcc" />
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="..\header" />
17 <Add directory="../header" />
18 <Add directory="..\src" />
18 <Add directory="../src" />
19 </Compiler>
19 </Compiler>
20 </Target>
20 </Target>
21 <Target title="Release">
21 <Target title="Release">
22 <Option output="bin\Release\FSW-rtems" prefix_auto="1" extension_auto="1" />
22 <Option output="bin/Release/FSW-rtems" prefix_auto="1" extension_auto="1" />
23 <Option object_output="obj\Release\" />
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>
@@ -34,11 +34,16
34 <Compiler>
34 <Compiler>
35 <Add option="-Wall" />
35 <Add option="-Wall" />
36 </Compiler>
36 </Compiler>
37 <Unit filename="..\header\FSW-rtems-processing.h" />
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="..\src\FSW-rtems.c">
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>
@@ -1,4 +1,4
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>
@@ -13,25 +13,67 1355231335 source:e:\missions\solo\dev_p
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="..\header\FSW-rtems-processing.h" open="1" top="0" tabpos="3">
4 <File name="../header/FSW-rtems-processing.h" open="0" top="0" tabpos="3">
5 <Cursor position="1016" topLine="1" />
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="..\src\FSW-rtems-processing.c" open="1" top="0" tabpos="2">
13 <File name="../src/FSW-rtems-processing.c" open="0" top="0" tabpos="2">
8 <Cursor position="17123" topLine="155" />
14 <Cursor position="18" topLine="0" />
9 </File>
15 </File>
10 <File name="..\src\FSW-rtems.c" open="1" top="1" tabpos="1">
16 <File name="../src/FSW-rtems.c" open="1" top="1" tabpos="1">
11 <Cursor position="14203" topLine="83" />
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 <..\header\ccsds_types.h>
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(ccsdsTelecommandSourcePacketHeader_t * TMPacket);
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_TELECOMMAND_MAX_PACKET_LENGTH 248
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_PACKET_CATEGORY 12
9 #define CCSDS_PROCESS_ID 76
9
10 #define CCSDS_PACKET_CATEGORY 12
10 #define CCSDS_ERR_PID -1
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 ccsdsTelecommandSourcePacketHeader_str
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[4];
44 volatile unsigned char dataFieldHeader[10];
45 volatile unsigned char data[CCSDS_TM_PKT_MAX_SIZE-16];
42 };
46 };
43 typedef struct ccsdsTelemetrySourcePacketHeader_str ccsdsTelecommandSourcePacketHeader_t;
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
@@ -2,20 +2,18
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
@@ -71,8 +69,23
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);
@@ -124,8 +137,7 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' );
@@ -190,28 +202,19 rtems_task Init( rtems_task_argument ign
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
@@ -221,8 +224,8 rtems_task Init( rtems_task_argument ign
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")
@@ -232,11 +235,13 rtems_task Init( rtems_task_argument ign
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;
@@ -286,29 +291,69 rtems_task spw_recv_task( rtems_task_arg
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*) &currentTC, 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(&currentTC);
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(&currentTC, &currentTM);
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*)&currentTM, 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(&currentTC, code, &currentTM);
311 }
350 PRINTF1(" %s\n", tmGeneratorMsg[result])
351 result = write( fdSPW, (char*)&currentTM, 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
@@ -373,15 +418,23 int configure_spw_link()
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_DISABLE_ERR\n")
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;
@@ -1,74 +1,207
1 #include <..\header\TC_handler.h>
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 CCSDS_ERR_PID;
49 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
13 if (category!=CCSDS_PACKET_CATEGORY) return CCSDS_ERR_CAT;
50 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
14
51
15 // packet length check
52 // packet length check
16 length = TMPacket->packetLength[1] + TMPacket->packetLength[0] * 256;
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 break;
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