##// END OF EJS Templates
Minor changes in .h inclusion
paul -
r45:c48d02b72186 default
parent child
Show More
@@ -0,0 +1,24
1 #ifndef TC_ACCEPTANCE_H_INCLUDED
2 #define TC_ACCEPTANCE_H_INCLUDED
3
4 //#include "tm_lfr_tc_exe.h"
5 #include "fsw_params.h"
6
7 //**********************
8 // GENERAL USE FUNCTIONS
9 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
10 void initLookUpTableForCRC( void );
11 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
12
13 //*********************
14 // ACCEPTANCE FUNCTIONS
15 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int TC_LEN_RCV, unsigned char *computed_CRC);
16 int tc_check_type( unsigned char packetType );
17 int tc_check_subtype( unsigned char packetType );
18 int tc_check_length( unsigned char packetType, unsigned int length );
19 int tc_check_crc(ccsdsTelecommandPacket_t * TCPacket, unsigned int length , unsigned char *computed_CRC);
20
21 #endif // TC_ACCEPTANCE_H_INCLUDED
22
23
24
@@ -0,0 +1,374
1 /** Functions related to TeleCommand acceptance.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TeleCommands parsing.\n
7 *
8 */
9
10 #include "tc_acceptance.h"
11
12 unsigned int lookUpTableForCRC[256];
13
14 //**********************
15 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 {
18 /** This function generate the CRC for one byte and returns the value of the new syndrome.
19 *
20 * @param D is the current byte of data.
21 * @param Chk is the current syndrom value.
22 * @return the value of the new syndrome on two bytes.
23 *
24 */
25
26 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
27 }
28
29 void initLookUpTableForCRC( void )
30 {
31 /** This function is used to initiates the look-up table for fast CRC computation.
32 *
33 * The global table lookUpTableForCRC[256] is initiated.
34 *
35 */
36
37 unsigned int i;
38 unsigned int tmp;
39
40 for (i=0; i<256; i++)
41 {
42 tmp = 0;
43 if((i & 1) != 0) {
44 tmp = tmp ^ 0x1021;
45 }
46 if((i & 2) != 0) {
47 tmp = tmp ^ 0x2042;
48 }
49 if((i & 4) != 0) {
50 tmp = tmp ^ 0x4084;
51 }
52 if((i & 8) != 0) {
53 tmp = tmp ^ 0x8108;
54 }
55 if((i & 16) != 0) {
56 tmp = tmp ^ 0x1231;
57 }
58 if((i & 32) != 0) {
59 tmp = tmp ^ 0x2462;
60 }
61 if((i & 64) != 0) {
62 tmp = tmp ^ 0x48c4;
63 }
64 if((i & 128) != 0) {
65 tmp = tmp ^ 0x9188;
66 }
67 lookUpTableForCRC[i] = tmp;
68 }
69 }
70
71 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
72 {
73 /** This function calculates a two bytes Cyclic Redundancy Code.
74 *
75 * @param data points to a buffer containing the data on which to compute the CRC.
76 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
77 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
78 *
79 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
80 *
81 */
82
83 unsigned int Chk;
84 int j;
85 Chk = 0xffff; // reset the syndrom to all ones
86 for (j=0; j<sizeOfData; j++) {
87 Chk = Crc_opt(data[j], Chk);
88 }
89 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
90 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
91 }
92
93 //*********************
94 // ACCEPTANCE FUNCTIONS
95 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int TC_LEN_RCV, unsigned char *computed_CRC)
96 {
97 /** This function parses TeleCommands.
98 *
99 * @param TC points to the TeleCommand that will be parsed.
100 * @param TC_LEN_RCV is the received packet length.
101 * @return Status code of the parsing.
102 *
103 * The parsing checks:
104 * - process id
105 * - category
106 * - length: a global check is performed and a per subtype check also
107 * - type
108 * - subtype
109 * - crc
110 *
111 */
112
113 int status;
114 unsigned char pid;
115 unsigned char category;
116 unsigned int length;
117 unsigned char packetType;
118 unsigned char packetSubtype;
119
120 status = CCSDS_TM_VALID;
121
122 // APID check *** APID on 2 bytes
123 pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
124 category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
125 length = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
126 packetType = TCPacket->serviceType;
127 packetSubtype = TCPacket->serviceSubType;
128
129 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
130 {
131 status = ILLEGAL_APID;
132 }
133 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
134 {
135 if ( category != CCSDS_PACKET_CATEGORY )
136 {
137 status = ILLEGAL_APID;
138 }
139 }
140 if (status == CCSDS_TM_VALID) // CHECK THE PACKET LENGTH FIELD AND THE ACTUAL LENGTH COMPLIANCE
141 {
142 if (length != TC_LEN_RCV ) {
143 status = WRONG_LEN_PACKET;
144 }
145 }
146 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
147 {
148 if ( length >= CCSDS_TC_PKT_MAX_SIZE ) {
149 status = WRONG_LEN_PACKET;
150 }
151 }
152 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
153 {
154 status = tc_check_type( packetType );
155 }
156 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
157 {
158 status = tc_check_subtype( packetSubtype );
159 }
160 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
161 {
162 status = tc_check_length( packetSubtype, length );
163 }
164 if (status == CCSDS_TM_VALID ) // CHECK CRC
165 {
166 status = tc_check_crc( TCPacket, length, computed_CRC );
167 }
168
169 return status;
170 }
171
172 int tc_check_type( unsigned char packetType )
173 {
174 /** This function checks that the type of a TeleCommand is valid.
175 *
176 * @param packetType is the type to check.
177 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
178 *
179 */
180
181 int status;
182
183 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
184 {
185 status = CCSDS_TM_VALID;
186 }
187 else
188 {
189 status = ILL_TYPE;
190 }
191
192 return status;
193 }
194
195 int tc_check_subtype( unsigned char packetSubType )
196 {
197 /** This function checks that the subtype of a TeleCommand is valid.
198 *
199 * @param packetSubType is the subtype to check.
200 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
201 *
202 */
203
204 int status;
205
206 if ( (packetSubType == TC_SUBTYPE_RESET)
207 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
208 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
209 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
210 || (packetSubType == TC_SUBTYPE_DUMP)
211 || (packetSubType == TC_SUBTYPE_ENTER)
212 || (packetSubType == TC_SUBTYPE_UPDT_INFO) || (packetSubType == TC_SUBTYPE_UPDT_TIME)
213 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL) )
214 {
215 status = CCSDS_TM_VALID;
216 }
217 else
218 {
219 status = ILL_TYPE;
220 }
221
222 return status;
223 }
224
225 int tc_check_length( unsigned char packetSubType, unsigned int length )
226 {
227 /** This function checks that the subtype and the length are compliant.
228 *
229 * @param packetSubType is the subtype to check.
230 * @param length is the length to check.
231 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
232 *
233 */
234
235 int status;
236
237 status = LFR_SUCCESSFUL;
238
239 switch(packetSubType)
240 {
241 case TC_SUBTYPE_RESET:
242 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
243 status = WRONG_LEN_PACKET;
244 }
245 else {
246 status = CCSDS_TM_VALID;
247 }
248 break;
249 case TC_SUBTYPE_LOAD_COMM:
250 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
251 status = WRONG_LEN_PACKET;
252 }
253 else {
254 status = CCSDS_TM_VALID;
255 }
256 break;
257 case TC_SUBTYPE_LOAD_NORM:
258 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
259 status = WRONG_LEN_PACKET;
260 }
261 else {
262 status = CCSDS_TM_VALID;
263 }
264 break;
265 case TC_SUBTYPE_LOAD_BURST:
266 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
267 status = WRONG_LEN_PACKET;
268 }
269 else {
270 status = CCSDS_TM_VALID;
271 }
272 break;
273 case TC_SUBTYPE_LOAD_SBM1:
274 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
275 status = WRONG_LEN_PACKET;
276 }
277 else {
278 status = CCSDS_TM_VALID;
279 }
280 break;
281 case TC_SUBTYPE_LOAD_SBM2:
282 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
283 status = WRONG_LEN_PACKET;
284 }
285 else {
286 status = CCSDS_TM_VALID;
287 }
288 break;
289 case TC_SUBTYPE_DUMP:
290 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
291 status = WRONG_LEN_PACKET;
292 }
293 else {
294 status = CCSDS_TM_VALID;
295 }
296 break;
297 case TC_SUBTYPE_ENTER:
298 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
299 status = WRONG_LEN_PACKET;
300 }
301 else {
302 status = CCSDS_TM_VALID;
303 }
304 break;
305 case TC_SUBTYPE_UPDT_INFO:
306 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
307 status = WRONG_LEN_PACKET;
308 }
309 else {
310 status = CCSDS_TM_VALID;
311 }
312 break;
313 case TC_SUBTYPE_EN_CAL:
314 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
315 status = WRONG_LEN_PACKET;
316 }
317 else {
318 status = CCSDS_TM_VALID;
319 }
320 break;
321 case TC_SUBTYPE_DIS_CAL:
322 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
323 status = WRONG_LEN_PACKET;
324 }
325 else {
326 status = CCSDS_TM_VALID;
327 }
328 break;
329 case TC_SUBTYPE_UPDT_TIME:
330 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
331 status = WRONG_LEN_PACKET;
332 }
333 else {
334 status = CCSDS_TM_VALID;
335 }
336 break;
337 default: // if the subtype is not a legal value, return ILL_SUBTYPE
338 status = ILL_SUBTYPE;
339 break ;
340 }
341
342 return status;
343 }
344
345 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
346 {
347 /** This function checks the CRC validity of the corresponding TeleCommand packet.
348 *
349 * @param TCPacket points to the TeleCommand packet to check.
350 * @param length is the length of the TC packet.
351 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
352 *
353 */
354
355 int status;
356 unsigned char * CCSDSContent;
357
358 CCSDSContent = (unsigned char*) TCPacket->packetID;
359 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
360 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
361 status = INCOR_CHECKSUM;
362 }
363 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
364 status = INCOR_CHECKSUM;
365 }
366 else {
367 status = CCSDS_TM_VALID;
368 }
369
370 return status;
371 }
372
373
374
@@ -1,6 +1,6
1 #############################################################################
1 #############################################################################
2 # Makefile for building: bin/fsw
2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Thu Oct 17 13:22:13 2013
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Fri Oct 18 15:44:51 2013
4 # Project: fsw-qt.pro
4 # Project: fsw-qt.pro
5 # Template: app
5 # Template: app
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
@@ -51,7 +51,8 SOURCES = ../src/wf_handler.c \
51 ../src/fsw_globals.c \
51 ../src/fsw_globals.c \
52 ../src/fsw_spacewire.c \
52 ../src/fsw_spacewire.c \
53 ../src/tc_load_dump_parameters.c \
53 ../src/tc_load_dump_parameters.c \
54 ../src/tm_lfr_tc_exe.c
54 ../src/tm_lfr_tc_exe.c \
55 ../src/tc_acceptance.c
55 OBJECTS = obj/wf_handler.o \
56 OBJECTS = obj/wf_handler.o \
56 obj/tc_handler.o \
57 obj/tc_handler.o \
57 obj/fsw_processing.o \
58 obj/fsw_processing.o \
@@ -60,7 +61,8 OBJECTS = obj/wf_handler.o \
60 obj/fsw_globals.o \
61 obj/fsw_globals.o \
61 obj/fsw_spacewire.o \
62 obj/fsw_spacewire.o \
62 obj/tc_load_dump_parameters.o \
63 obj/tc_load_dump_parameters.o \
63 obj/tm_lfr_tc_exe.o
64 obj/tm_lfr_tc_exe.o \
65 obj/tc_acceptance.o
64 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
66 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
65 /usr/lib64/qt4/mkspecs/common/linux.conf \
67 /usr/lib64/qt4/mkspecs/common/linux.conf \
66 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
68 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
@@ -212,7 +214,7 obj/wf_handler.o: ../src/wf_handler.c
212 obj/tc_handler.o: ../src/tc_handler.c
214 obj/tc_handler.o: ../src/tc_handler.c
213 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_handler.o ../src/tc_handler.c
215 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_handler.o ../src/tc_handler.c
214
216
215 obj/fsw_processing.o: ../src/fsw_processing.c
217 obj/fsw_processing.o: ../src/fsw_processing.c ../src/fsw_processing_globals.c
216 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_processing.o ../src/fsw_processing.c
218 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_processing.o ../src/fsw_processing.c
217
219
218 obj/fsw_misc.o: ../src/fsw_misc.c
220 obj/fsw_misc.o: ../src/fsw_misc.c
@@ -233,6 +235,9 obj/tc_load_dump_parameters.o: ../src/tc
233 obj/tm_lfr_tc_exe.o: ../src/tm_lfr_tc_exe.c
235 obj/tm_lfr_tc_exe.o: ../src/tm_lfr_tc_exe.c
234 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tm_lfr_tc_exe.o ../src/tm_lfr_tc_exe.c
236 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tm_lfr_tc_exe.o ../src/tm_lfr_tc_exe.c
235
237
238 obj/tc_acceptance.o: ../src/tc_acceptance.c
239 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_acceptance.o ../src/tc_acceptance.c
240
236 ####### Install
241 ####### Install
237
242
238 install: FORCE
243 install: FORCE
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -52,7 +52,9 SOURCES += \
52 ../src/fsw_globals.c \
52 ../src/fsw_globals.c \
53 ../src/fsw_spacewire.c \
53 ../src/fsw_spacewire.c \
54 ../src/tc_load_dump_parameters.c \
54 ../src/tc_load_dump_parameters.c \
55 ../src/tm_lfr_tc_exe.c
55 ../src/tm_lfr_tc_exe.c \
56 ../src/tc_acceptance.c
57
56
58
57 HEADERS += \
59 HEADERS += \
58 ../header/wf_handler.h \
60 ../header/wf_handler.h \
@@ -67,5 +69,6 HEADERS += \
67 ../header/fsw_spacewire.h \
69 ../header/fsw_spacewire.h \
68 ../header/tm_byte_positions.h \
70 ../header/tm_byte_positions.h \
69 ../header/tc_load_dump_parameters.h \
71 ../header/tc_load_dump_parameters.h \
70 ../header/tm_lfr_tc_exe.h
72 ../header/tm_lfr_tc_exe.h \
73 ../header/tc_acceptance.h
71
74
@@ -1,6 +1,6
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE QtCreatorProject>
2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by QtCreator 2.8.0, 2013-10-17T08:46:24. -->
3 <!-- Written by QtCreator 2.8.0, 2013-10-18T15:44:56. -->
4 <qtcreator>
4 <qtcreator>
5 <data>
5 <data>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -1806,7 +1806,7 CALL_GRAPH = YES
1806 # the time of a run. So in most cases it will be better to enable caller
1806 # the time of a run. So in most cases it will be better to enable caller
1807 # graphs for selected functions only using the \callergraph command.
1807 # graphs for selected functions only using the \callergraph command.
1808
1808
1809 CALLER_GRAPH = NO
1809 CALLER_GRAPH = YES
1810
1810
1811 # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
1811 # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
1812 # will generate a graphical hierarchy of all classes instead of a textual one.
1812 # will generate a graphical hierarchy of all classes instead of a textual one.
@@ -1,5 +1,5
1 #ifndef CCSDS_H_INCLUDED
1 #ifndef CCSDS_TYPES_H_INCLUDED
2 #define CCSDS_H_INCLUDED
2 #define CCSDS_TYPES_H_INCLUDED
3
3
4 #define CCSDS_PROTOCOLE_EXTRA_BYTES 4
4 #define CCSDS_PROTOCOLE_EXTRA_BYTES 4
5 #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
5 #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
@@ -624,4 +624,4 struct Packet_TM_LFR_PARAMETER_DUMP_str
624 typedef struct Packet_TM_LFR_PARAMETER_DUMP_str Packet_TM_LFR_PARAMETER_DUMP_t;
624 typedef struct Packet_TM_LFR_PARAMETER_DUMP_str Packet_TM_LFR_PARAMETER_DUMP_t;
625
625
626
626
627 #endif // CCSDS_H_INCLUDED
627 #endif // CCSDS_TYPES_H_INCLUDED
@@ -1,16 +1,7
1 #ifndef FSW_RTEMS_H_INCLUDED
1 #ifndef FSW_INIT_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
2 #define FSW_INIT_H_INCLUDED
3
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h> // for the read call
9 #include <sys/ioctl.h> // for the ioctl call
10
3
11 #include <rtems.h>
4 #include <rtems.h>
12 #include <grspw.h>
13 #include <apbuart.h>
14 #include <leon.h>
5 #include <leon.h>
15
6
16 #include "fsw_params.h"
7 #include "fsw_params.h"
@@ -55,4 +46,4 extern void rtems_stack_checker_report_u
55 extern int sched_yield( void );
46 extern int sched_yield( void );
56 extern int errno;
47 extern int errno;
57
48
58 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
49 #endif // FSW_INIT_H_INCLUDED
@@ -1,10 +1,18
1 #ifndef FSW_MISC_H_INCLUDED
1 #ifndef FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
3
3
4 #include "fsw_init.h"
4 #include <rtems.h>
5 #include <stdio.h>
6 #include <grspw.h>
7
8 #include "fsw_params.h"
9 #include "fsw_spacewire.h"
5
10
6 rtems_name HK_name; // name of the HK rate monotonic
11 rtems_name HK_name; // name of the HK rate monotonic
7 rtems_id HK_id; // id of the HK rate monotonic period
12 rtems_id HK_id; // id of the HK rate monotonic period
13
14 extern rtems_name misc_name[5];
15 time_management_regs_t *time_management_regs;
8 extern Packet_TM_LFR_HK_t housekeeping_packet;
16 extern Packet_TM_LFR_HK_t housekeeping_packet;
9
17
10 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
18 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
@@ -12,7 +20,6 int configure_timer(gptimer_regs_t *gpti
12 int timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
20 int timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
13 int timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
21 int timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
14 int timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
22 int timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
15 void update_spacewire_statistics();
16
23
17 // SERIAL LINK
24 // SERIAL LINK
18 int send_console_outputs_on_apbuart_port( void );
25 int send_console_outputs_on_apbuart_port( void );
@@ -21,8 +28,6 void set_apbuart_scaler_reload_register(
21 // RTEMS TASKS
28 // RTEMS TASKS
22 rtems_task stat_task(rtems_task_argument argument);
29 rtems_task stat_task( rtems_task_argument argument );
23 rtems_task hous_task(rtems_task_argument argument);
30 rtems_task hous_task( rtems_task_argument argument );
24 rtems_task send_task(rtems_task_argument argument);
31 rtems_task dumb_task( rtems_task_argument unused );
25
26 rtems_id get_pkts_queue_id( void );
27
32
28 #endif // FSW_MISC_H_INCLUDED
33 #endif // FSW_MISC_H_INCLUDED
@@ -1,5 +1,5
1 #ifndef FSW_RTEMS_CONFIG_H_INCLUDED
1 #ifndef FSW_PARAMS_H_INCLUDED
2 #define FSW_RTEMS_CONFIG_H_INCLUDED
2 #define FSW_PARAMS_H_INCLUDED
3
3
4 #include "grlib_regs.h"
4 #include "grlib_regs.h"
5 #include "fsw_params_processing.h"
5 #include "fsw_params_processing.h"
@@ -222,4 +222,4 struct param_local_str{
222 unsigned int local_nb_interrupt_f0_MAX;
222 unsigned int local_nb_interrupt_f0_MAX;
223 };
223 };
224
224
225 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
225 #endif // FSW_PARAMS_H_INCLUDED
@@ -1,7 +1,14
1 #ifndef FSW_RTEMS_PROCESSING_H_INCLUDED
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_RTEMS_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
3
4 #include "fsw_init.h"
4 #include <rtems.h>
5 #include <grspw.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h> // printf()
9
10 #include "fsw_params.h"
11
5
12
6 extern volatile int spec_mat_f0_0[ ];
13 extern volatile int spec_mat_f0_0[ ];
7 extern volatile int spec_mat_f0_1[ ];
14 extern volatile int spec_mat_f0_1[ ];
@@ -29,6 +36,9 extern struct param_local_str param_loca
29 extern time_management_regs_t *time_management_regs;
36 extern time_management_regs_t *time_management_regs;
30 extern spectral_matrix_regs_t *spectral_matrix_regs;
37 extern spectral_matrix_regs_t *spectral_matrix_regs;
31
38
39 extern rtems_name misc_name[5];
40 extern rtems_id Task_id[20]; /* array of task ids */
41
32 // ISR
42 // ISR
33 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
43 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
34 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
44 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
@@ -52,4 +62,4 void convert_averaged_spectral_matrix(vo
52 void fill_averaged_spectral_matrix( void );
62 void fill_averaged_spectral_matrix( void );
53 void reset_spectral_matrix_regs();
63 void reset_spectral_matrix_regs();
54
64
55 #endif // FSW_RTEMS_PROCESSING_H_INCLUDED
65 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,19 +1,33
1 #ifndef FSW_SPACEWIRE_H_INCLUDED
1 #ifndef FSW_SPACEWIRE_H_INCLUDED
2 #define FSW_SPACEWIRE_H_INCLUDED
2 #define FSW_SPACEWIRE_H_INCLUDED
3
3
4 #include "fsw_init.h"
4 #include <rtems.h>
5 #include <grspw.h>
6
7 #include <fcntl.h> // for O_RDWR
8 #include <unistd.h> // for the read call
9 #include <sys/ioctl.h> // for the ioctl call
10 #include <errno.h>
11
12 #include "fsw_params.h"
13 #include "tc_handler.h"
5
14
6 extern spw_stats spacewire_stats;
15 extern spw_stats spacewire_stats;
7 extern spw_stats spacewire_stats_backup;
16 extern spw_stats spacewire_stats_backup;
17 extern Packet_TM_LFR_HK_t housekeeping_packet;
18 extern rtems_id Task_id[20]; /* array of task ids */
8
19
9 // RTEMS TASK
20 // RTEMS TASK
10 rtems_task spiq_task(rtems_task_argument argument);
21 rtems_task spiq_task( rtems_task_argument argument );
22 rtems_task recv_task( rtems_task_argument unused );
23 rtems_task send_task( rtems_task_argument argument );
11
24
12 int spacewire_configure_link( void );
25 int spacewire_configure_link( void );
13 int spacewire_wait_for_link(void);
26 int spacewire_wait_for_link( void );
14 void spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
27 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
15 void spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
28 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
16 void spacewire_compute_stats_offsets(void);
29 void spacewire_compute_stats_offsets( void );
30 void spacewire_update_statistics( void );
17
31
18 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
32 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
19
33
@@ -1,5 +1,5
1 #ifndef GRLIBREGS_H_INCLUDED
1 #ifndef GRLIB_REGS_H_INCLUDED
2 #define GRLIBREGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
3
3
4 #define NB_GPTIMER 3
4 #define NB_GPTIMER 3
5
5
@@ -71,4 +71,4 struct spectral_matrix_regs_str{
71 };
71 };
72 typedef struct spectral_matrix_regs_str spectral_matrix_regs_t;
72 typedef struct spectral_matrix_regs_str spectral_matrix_regs_t;
73
73
74 #endif // GRLIBREGS_H_INCLUDED
74 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,9 +1,13
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 "fsw_init.h"
4 #include <rtems.h>
5 #include <leon.h>
6
5 #include "tc_load_dump_parameters.h"
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
6 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "wf_handler.h"
7
11
8 // MODE PARAMETERS
12 // MODE PARAMETERS
9 extern struct param_sbm1_str param_sbm1;
13 extern struct param_sbm1_str param_sbm1;
@@ -11,33 +15,20 extern struct param_sbm2_str param_sbm2;
11 extern time_management_regs_t *time_management_regs;
15 extern time_management_regs_t *time_management_regs;
12 extern waveform_picker_regs_t *waveform_picker_regs;
16 extern waveform_picker_regs_t *waveform_picker_regs;
13 extern gptimer_regs_t *gptimer_regs;
17 extern gptimer_regs_t *gptimer_regs;
18 extern rtems_name misc_name[5];
19 extern rtems_id Task_id[20]; /* array of task ids */
20 extern unsigned char lfrCurrentMode;
21 extern unsigned int maxCount;
22
14
23
15 //****
24 //****
16 // ISR
25 // ISR
17 rtems_isr commutation_isr1( rtems_vector_number vector );
26 rtems_isr commutation_isr1( rtems_vector_number vector );
18 rtems_isr commutation_isr2( rtems_vector_number vector );
27 rtems_isr commutation_isr2( rtems_vector_number vector );
19
28
20 //**********************
21 // GENERAL USE FUNCTIONS
22 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
23 void initLookUpTableForCRC( void );
24 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
25 void updateLFRCurrentMode();
26
27 //*********************
28 // ACCEPTANCE FUNCTIONS
29 int tc_acceptance(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV, rtems_id queue_recv_id, rtems_id queue_send_id);
30 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int TC_LEN_RCV);
31 int tc_check_type( unsigned char packetType );
32 int tc_check_subtype( unsigned char packetType );
33 int tc_check_length( unsigned char packetType, unsigned int length );
34 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length );
35
36 //***********
29 //***********
37 // RTEMS TASK
30 // RTEMS TASK
38 rtems_task recv_task( rtems_task_argument unused );
39 rtems_task actn_task( rtems_task_argument unused );
31 rtems_task actn_task( rtems_task_argument unused );
40 rtems_task dumb_task( rtems_task_argument unused );
41
32
42 //***********
33 //***********
43 // TC ACTIONS
34 // TC ACTIONS
@@ -61,6 +52,7 int restart_science_tasks();
61 int suspend_science_tasks();
52 int suspend_science_tasks();
62
53
63 // other functions
54 // other functions
55 void updateLFRCurrentMode();
64 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC);
56 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC);
65 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC);
57 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC);
66 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id);
58 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id);
@@ -1,7 +1,17
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
3
4 #include "tc_handler.h"
4 #include <rtems.h>
5 #include <stdio.h>
6
7 #include "fsw_params.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
10
11 extern int fdSPW;
12 extern unsigned char lfrCurrentMode;
13 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
14 extern Packet_TM_LFR_HK_t housekeeping_packet;
5
15
6 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
16 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
7 int action_load_normal_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
17 int action_load_normal_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
@@ -1,9 +1,12
1 #ifndef WF_HANDLER_H_INCLUDED
1 #ifndef WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
3
3
4 #include "fsw_init.h"
4 #include <rtems.h>
5 #include <grspw.h>
6 #include <stdio.h>
7 #include <math.h>
5
8
6 #include <math.h>
9 #include "fsw_params.h"
7
10
8 #define pi 3.1415
11 #define pi 3.1415
9
12
@@ -22,6 +25,14 extern volatile int wf_cont_f3[ ];
22 extern volatile int wf_cont_f3_bis[ ];
25 extern volatile int wf_cont_f3_bis[ ];
23 extern char wf_cont_f3_light[ ];
26 extern char wf_cont_f3_light[ ];
24 extern waveform_picker_regs_t *waveform_picker_regs;
27 extern waveform_picker_regs_t *waveform_picker_regs;
28 extern time_management_regs_t *time_management_regs;
29 extern Packet_TM_LFR_HK_t housekeeping_packet;
30 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
31 extern struct param_local_str param_local;
32
33 extern rtems_name misc_name[5];
34 extern rtems_id Task_id[20]; /* array of task ids */
35 extern unsigned char lfrCurrentMode;
25
36
26 rtems_isr waveforms_isr( rtems_vector_number vector );
37 rtems_isr waveforms_isr( rtems_vector_number vector );
27 rtems_isr waveforms_simulator_isr( rtems_vector_number vector );
38 rtems_isr waveforms_simulator_isr( rtems_vector_number vector );
@@ -39,11 +50,13 int init_header_continuous_wf_table(
39 int init_header_continuous_wf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
50 int init_header_continuous_wf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
40 //
51 //
41 void reset_waveforms( void );
52 void reset_waveforms( void );
42
53 //
43 int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
54 int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
44 int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
55 int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
45 int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
56 int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
46 int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
57 int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
58 //
59 rtems_id get_pkts_queue_id( void );
47
60
48 //**************
61 //**************
49 // wfp registers
62 // wfp registers
@@ -1,6 +1,22
1 //#include <fsw_processing.h>
1 /** Global variables of the LFR flight software.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * Among global variables, there are:
7 * - RTEMS names and id.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
14 *
15 */
16
2 #include <rtems.h>
17 #include <rtems.h>
3 #include <grspw.h>
18 #include <grspw.h>
19
4 #include "ccsds_types.h"
20 #include "ccsds_types.h"
5 #include "grlib_regs.h"
21 #include "grlib_regs.h"
6 #include "fsw_params.h"
22 #include "fsw_params.h"
@@ -1,3 +1,14
1 /** This is the RTEMS initialization module.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
10 */
11
1 //*************************
12 //*************************
2 // GPL reminder to be added
13 // GPL reminder to be added
3 //*************************
14 //*************************
@@ -51,6 +62,15
51
62
52 rtems_task Init( rtems_task_argument ignored )
63 rtems_task Init( rtems_task_argument ignored )
53 {
64 {
65 /** This is the RTEMS INIT taks, it the first task launched by the system.
66 *
67 * @param unused is the starting argument of the RTEMS task
68 *
69 * The INIT task create and run all other RTEMS tasks.
70 *
71 */
72
73
54 rtems_status_code status;
74 rtems_status_code status;
55 rtems_isr_entry old_isr_handler;
75 rtems_isr_entry old_isr_handler;
56
76
@@ -131,6 +151,10 rtems_task Init( rtems_task_argument ign
131
151
132 void init_parameter_dump( void )
152 void init_parameter_dump( void )
133 {
153 {
154 /** This function initialize the parameter_dump_packet global variable with default values.
155 *
156 */
157
134 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
158 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
135 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
159 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
136 parameter_dump_packet.reserved = CCSDS_RESERVED;
160 parameter_dump_packet.reserved = CCSDS_RESERVED;
@@ -188,6 +212,10 void init_parameter_dump( void )
188
212
189 void init_local_mode_parameters( void )
213 void init_local_mode_parameters( void )
190 {
214 {
215 /** This function initialize the param_local global variable with default values.
216 *
217 */
218
191 // LOCAL PARAMETERS
219 // LOCAL PARAMETERS
192 set_local_sbm1_nb_cwf_max();
220 set_local_sbm1_nb_cwf_max();
193 set_local_sbm2_nb_cwf_max();
221 set_local_sbm2_nb_cwf_max();
@@ -203,6 +231,10 void init_local_mode_parameters( void )
203
231
204 void init_housekeeping_parameters( void )
232 void init_housekeeping_parameters( void )
205 {
233 {
234 /** This function initialize the housekeeping_packet global variable with default values.
235 *
236 */
237
206 unsigned int i = 0;
238 unsigned int i = 0;
207 unsigned int j = 0;
239 unsigned int j = 0;
208 unsigned int k = 0;
240 unsigned int k = 0;
@@ -240,7 +272,7 int create_names( void ) // create all n
240 /** This function creates all RTEMS names used in the software for tasks and queues.
272 /** This function creates all RTEMS names used in the software for tasks and queues.
241 *
273 *
242 * @return RTEMS directive status codes:
274 * @return RTEMS directive status codes:
243 * - RTEMS_SUCCESSFUL - message sent successfully
275 * - RTEMS_SUCCESSFUL - successful completion
244 *
276 *
245 */
277 */
246
278
@@ -1,8 +1,37
1 /** General usage functions and RTEMS tasks.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 */
7
1 #include "fsw_misc.h"
8 #include "fsw_misc.h"
2
9
10 char *DumbMessages[6] = {"in DUMB *** default", // RTEMS_EVENT_0
11 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
12 "in DUMB *** waveforms_isr", // RTEMS_EVENT_2
13 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
14 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
15 "in DUMB *** waveforms_simulator_isr" // RTEMS_EVENT_5
16 };
17
3 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
18 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
4 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
19 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
5 { // configure the timer for the waveforms simulation
20 {
21 /** This function configures a GPTIMER timer instantiated in the VHDL design.
22 *
23 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
24 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
25 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
26 * @param interrupt_level is the interrupt level that the timer drives.
27 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
28 *
29 * @return
30 *
31 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
32 *
33 */
34
6 rtems_status_code status;
35 rtems_status_code status;
7 rtems_isr_entry old_isr_handler;
36 rtems_isr_entry old_isr_handler;
8
37
@@ -19,6 +48,15 int configure_timer(gptimer_regs_t *gpti
19
48
20 int timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
49 int timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
21 {
50 {
51 /** This function starts a GPTIMER timer.
52 *
53 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
54 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
55 *
56 * @return 1
57 *
58 */
59
22 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
60 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
23 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
61 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
24 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
62 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
@@ -30,6 +68,15 int timer_start(gptimer_regs_t *gptimer_
30
68
31 int timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
69 int timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
32 {
70 {
71 /** This function stops a GPTIMER timer.
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 *
76 * @return 1
77 *
78 */
79
33 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
80 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
34 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
81 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
35 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
82 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
@@ -39,76 +86,21 int timer_stop(gptimer_regs_t *gptimer_r
39
86
40 int timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
87 int timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
41 {
88 {
89 /** This function sets the clock divider of a GPTIMER timer.
90 *
91 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
92 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
93 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
94 *
95 * @return 1
96 *
97 */
98
42 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
99 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
43
100
44 return 1;
101 return 1;
45 }
102 }
46
103
47 void update_spacewire_statistics()
48 {
49 rtems_status_code status;
50 spw_stats spacewire_stats_grspw;
51
52 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
53
54 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
55 + spacewire_stats_grspw.packets_received;
56 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
57 + spacewire_stats_grspw.packets_sent;
58 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
59 + spacewire_stats_grspw.parity_err;
60 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
61 + spacewire_stats_grspw.disconnect_err;
62 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
63 + spacewire_stats_grspw.escape_err;
64 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
65 + spacewire_stats_grspw.credit_err;
66 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
67 + spacewire_stats_grspw.write_sync_err;
68 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
69 + spacewire_stats_grspw.rx_rmap_header_crc_err;
70 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
71 + spacewire_stats_grspw.rx_rmap_data_crc_err;
72 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
73 + spacewire_stats_grspw.early_ep;
74 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
75 + spacewire_stats_grspw.invalid_address;
76 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
77 + spacewire_stats_grspw.rx_eep_err;
78 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
79 + spacewire_stats_grspw.rx_truncated;
80 //spacewire_stats.tx_link_err;
81
82 //****************************
83 // DPU_SPACEWIRE_IF_STATISTICS
84 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
85 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
86 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
87 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
88 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
89 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
90
91 //******************************************
92 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
93 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
94 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
95 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
96 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
97 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
98 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb;
99 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb;
100 housekeeping_packet.hk_lfr_dpu_spw_header_crc = (unsigned char) spacewire_stats.rx_rmap_header_crc_err;
101 housekeeping_packet.hk_lfr_dpu_spw_data_crc = (unsigned char) spacewire_stats.rx_rmap_data_crc_err;
102
103 //*********************************************
104 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
105 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
106 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
107 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
108 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
109
110 }
111
112 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
104 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
113 {
105 {
114 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
106 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
@@ -225,7 +217,7 rtems_task hous_task(rtems_task_argument
225 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
217 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
226 housekeeping_packet.sid = SID_HK;
218 housekeeping_packet.sid = SID_HK;
227
219
228 update_spacewire_statistics();
220 spacewire_update_statistics();
229
221
230 // SEND PACKET
222 // SEND PACKET
231 status = rtems_message_queue_send( queue_id, &spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
223 status = rtems_message_queue_send( queue_id, &spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
@@ -239,92 +231,43 rtems_task hous_task(rtems_task_argument
239
231
240 status = rtems_task_delete( RTEMS_SELF ); // should not return
232 status = rtems_task_delete( RTEMS_SELF ); // should not return
241 printf( "rtems_task_delete returned with status of %d.\n", status );
233 printf( "rtems_task_delete returned with status of %d.\n", status );
242 exit( 1 );
234 return;
243 }
244
245 rtems_task send_task( rtems_task_argument argument)
246 {
247 rtems_status_code status; // RTEMS status code
248 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
249 spw_ioctl_pkt_send *spw_ioctl_send;
250 size_t size; // size of the incoming TC packet
251 u_int32_t count;
252 rtems_id queue_id;
253
254 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_id );
255 if (status != RTEMS_SUCCESSFUL)
256 {
257 PRINTF1("in SEND *** ERR getting queue id, %d\n", status)
258 }
235 }
259
236
260 BOOT_PRINTF("in SEND *** \n")
237 rtems_task dumb_task( rtems_task_argument unused )
261
262 while(1)
263 {
264 status = rtems_message_queue_receive( queue_id, incomingData, &size,
265 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
266
267 if (status!=RTEMS_SUCCESSFUL)
268 {
269 PRINTF1("in SEND *** (1) ERR = %d\n", status)
270 }
271 else
272 {
273 if ( incomingData[0] == CCSDS_DESTINATION_ID) // the incoming message is a ccsds packet
274 {
238 {
275 status = write( fdSPW, incomingData, size );
239 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
276 if (status == -1){
240 *
277 PRINTF2("in SEND *** (2.a) ERR = %d, size = %d\n", status, size)
241 * @param unused is the starting argument of the RTEMS task
278 }
242 *
279 }
243 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
280 else // the incoming message is a spw_ioctl_pkt_send structure
244 *
281 {
245 */
282 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
246
283 if (spw_ioctl_send->hlen == 0)
247 unsigned int i;
248 unsigned int intEventOut;
249 unsigned int coarse_time = 0;
250 unsigned int fine_time = 0;
251 rtems_event_set event_out;
252
253 BOOT_PRINTF("in DUMB *** \n")
254
255 while(1){
256 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4 | RTEMS_EVENT_5,
257 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
258 intEventOut = (unsigned int) event_out;
259 for ( i=0; i<32; i++)
284 {
260 {
285 status = write( fdSPW, spw_ioctl_send->data, spw_ioctl_send->dlen );
261 if ( ((intEventOut >> i) & 0x0001) != 0)
286 if (status == -1){
287 PRINTF2("in SEND *** (2.b) ERR = %d, dlen = %d\n", status, spw_ioctl_send->dlen)
288 }
289 }
290 else
291 {
262 {
292 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
263 coarse_time = time_management_regs->coarse_time;
293 if (status == -1){
264 fine_time = time_management_regs->fine_time;
294 PRINTF2("in SEND *** (2.c) ERR = %d, dlen = %d\n", status, spw_ioctl_send->dlen)
265 printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
295 PRINTF1(" hlen = %d\n", spw_ioctl_send->hlen)
296 }
266 }
297 }
267 }
298 }
268 }
299 }
269 }
300
270
301 status = rtems_message_queue_get_number_pending( queue_id, &count );
302 if (status != RTEMS_SUCCESSFUL)
303 {
304 PRINTF1("in SEND *** (3) ERR = %d\n", status)
305 }
306 else
307 {
308 if (count > maxCount)
309 {
310 maxCount = count;
311 }
312 }
313 }
314 }
315
316 rtems_id get_pkts_queue_id( void )
317 {
318 rtems_id queue_id;
319 rtems_status_code status;
320
321 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_id );
322 if (status != RTEMS_SUCCESSFUL)
323 {
324 PRINTF1("in get_pkts_queue_id *** ERR %d\n", status)
325 }
326 return queue_id;
327 }
328
271
329
272
330
273
@@ -1,7 +1,16
1 /** Functions related to data processing.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
8 */
9
1 #include <fsw_processing.h>
10 #include <fsw_processing.h>
2 #include <math.h>
11 #include <math.h>
3
12
4 #include <fsw_processing_globals.c>
13 #include "fsw_processing_globals.c"
5
14
6 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_SM_F0 * 9 ];
15 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_SM_F0 * 9 ];
7 BP1_t data_BP1[ NB_BINS_COMPRESSED_SM_F0 ];
16 BP1_t data_BP1[ NB_BINS_COMPRESSED_SM_F0 ];
@@ -1,3 +1,10
1 /** Global variables used by the processing functions.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 */
7
1 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
8 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
2 // SX 12 coefficients
9 // SX 12 coefficients
3 float K14_sx_re = 1;
10 float K14_sx_re = 1;
@@ -1,3 +1,16
1 /** Functions related to the SpaceWire interface.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
12 */
13
1 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
2
15
3 char *lstates[6] = {"Error-reset",
16 char *lstates[6] = {"Error-reset",
@@ -8,9 +21,16 char *lstates[6] = {"Error-reset",
8 "Run"
21 "Run"
9 };
22 };
10
23
24 //***********
11 // RTEMS TASK
25 // RTEMS TASK
12 rtems_task spiq_task(rtems_task_argument unused)
26 rtems_task spiq_task(rtems_task_argument unused)
13 {
27 {
28 /** This RTEMS task is dedicated to the handling of interruption requests raised by the SpaceWire driver.
29 *
30 * @param unused is the starting argument of the RTEMS task
31 *
32 */
33
14 rtems_event_set event_out;
34 rtems_event_set event_out;
15 rtems_status_code status;
35 rtems_status_code status;
16 unsigned char lfrMode;
36 unsigned char lfrMode;
@@ -56,15 +76,182 rtems_task spiq_task(rtems_task_argument
56 }
76 }
57 }
77 }
58
78
79 rtems_task recv_task( rtems_task_argument unused )
80 {
81 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
82 *
83 * @param unused is the starting argument of the RTEMS task
84 *
85 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
86 * 1. It reads the incoming data.
87 * 2. Launches the acceptance procedure.
88 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
89 *
90 */
91
92 int len;
93 ccsdsTelecommandPacket_t currentTC;
94 unsigned char computed_CRC[ 2 ];
95 unsigned char currentTC_LEN_RCV[ 2 ];
96 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
97 unsigned int parserCode;
98 rtems_status_code status;
99 rtems_id queue_recv_id;
100 rtems_id queue_send_id;
101
102 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
103
104 status = rtems_message_queue_ident( misc_name[QUEUE_RECV], 0, &queue_recv_id );
105 if (status != RTEMS_SUCCESSFUL)
106 {
107 PRINTF1("in RECV *** ERR getting QUEUE_RECV id, %d\n", status)
108 }
109
110 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_send_id );
111 if (status != RTEMS_SUCCESSFUL)
112 {
113 PRINTF1("in RECV *** ERR getting QUEUE_SEND id, %d\n", status)
114 }
115
116 BOOT_PRINTF("in RECV *** \n")
117
118 while(1)
119 {
120 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
121 if (len == -1){ // error during the read call
122 PRINTF("In RECV *** last read call returned -1\n")
123 }
124 else {
125 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
126 PRINTF("In RECV *** packet lenght too short\n")
127 }
128 else {
129 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
130 currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8);
131 currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt );
132 // CHECK THE TC
133 parserCode = tc_parser( &currentTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ;
134 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PACKET) || (parserCode == INCOR_CHECKSUM)
135 | (parserCode == ILL_TYPE) || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) )
136 { // send TM_LFR_TC_EXE_CORRUPTED
137 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id, computed_CRC, currentTC_LEN_RCV );
138 }
139 else
140 { // send valid TC to the action launcher
141 status = rtems_message_queue_send( queue_recv_id, &currentTC,
142 currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3);
143 }
144 }
145 }
146 }
147 }
148
149 rtems_task send_task( rtems_task_argument argument)
150 {
151 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
152 *
153 * @param unused is the starting argument of the RTEMS task
154 *
155 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
156 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
157 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
158 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
159 * data it contains.
160 *
161 */
162
163 rtems_status_code status; // RTEMS status code
164 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
165 spw_ioctl_pkt_send *spw_ioctl_send;
166 size_t size; // size of the incoming TC packet
167 u_int32_t count;
168 rtems_id queue_id;
169
170 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_id );
171 if (status != RTEMS_SUCCESSFUL)
172 {
173 PRINTF1("in SEND *** ERR getting queue id, %d\n", status)
174 }
175
176 BOOT_PRINTF("in SEND *** \n")
177
178 while(1)
179 {
180 status = rtems_message_queue_receive( queue_id, incomingData, &size,
181 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
182
183 if (status!=RTEMS_SUCCESSFUL)
184 {
185 PRINTF1("in SEND *** (1) ERR = %d\n", status)
186 }
187 else
188 {
189 if ( incomingData[0] == CCSDS_DESTINATION_ID) // the incoming message is a ccsds packet
190 {
191 status = write( fdSPW, incomingData, size );
192 if (status == -1){
193 PRINTF2("in SEND *** (2.a) ERR = %d, size = %d\n", status, size)
194 }
195 }
196 else // the incoming message is a spw_ioctl_pkt_send structure
197 {
198 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
199 if (spw_ioctl_send->hlen == 0)
200 {
201 status = write( fdSPW, spw_ioctl_send->data, spw_ioctl_send->dlen );
202 if (status == -1){
203 PRINTF2("in SEND *** (2.b) ERR = %d, dlen = %d\n", status, spw_ioctl_send->dlen)
204 }
205 }
206 else
207 {
208 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
209 if (status == -1){
210 PRINTF2("in SEND *** (2.c) ERR = %d, dlen = %d\n", status, spw_ioctl_send->dlen)
211 PRINTF1(" hlen = %d\n", spw_ioctl_send->hlen)
212 }
213 }
214 }
215 }
216
217 status = rtems_message_queue_get_number_pending( queue_id, &count );
218 if (status != RTEMS_SUCCESSFUL)
219 {
220 PRINTF1("in SEND *** (3) ERR = %d\n", status)
221 }
222 else
223 {
224 if (count > maxCount)
225 {
226 maxCount = count;
227 }
228 }
229 }
230 }
231
232 //****************
233 // OTHER FUNCTIONS
59 int spacewire_configure_link( void )
234 int spacewire_configure_link( void )
60 {
235 {
236 /** This function configures the SpaceWire link.
237 *
238 * @return GR-RTEMS-DRIVER directive status codes:
239 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
240 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
241 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
242 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
243 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
244 * - 5 EIO - Error when writing to grswp hardware registers.
245 * - 2 ENOENT - No such file or directory
246 */
247
61 rtems_status_code status;
248 rtems_status_code status;
62
249
63 close(fdSPW); // close the device if it is already open
250 close(fdSPW); // close the device if it is already open
64 BOOT_PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
251 BOOT_PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
65 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
252 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
66 if ( fdSPW<0 ) {
253 if ( fdSPW<0 ) {
67 PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
254 PRINTF1("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME" with ERR %d\n", errno)
68 }
255 }
69
256
70 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, -1) != RTEMS_SUCCESSFUL){
257 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, -1) != RTEMS_SUCCESSFUL){
@@ -73,7 +260,7 int spacewire_configure_link( void )
73 close( fdSPW ); // close the device
260 close( fdSPW ); // close the device
74 fdSPW = open( GRSPW_DEVICE_NAME, O_RDWR ); // open the device. the open call reset the hardware
261 fdSPW = open( GRSPW_DEVICE_NAME, O_RDWR ); // open the device. the open call reset the hardware
75 if (fdSPW<0) {
262 if (fdSPW<0) {
76 PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
263 PRINTF1("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME" with ERR %d\n", errno)
77 }
264 }
78 rtems_task_wake_after(100);
265 rtems_task_wake_after(100);
79 }
266 }
@@ -111,6 +298,14 int spacewire_configure_link( void )
111
298
112 int spacewire_wait_for_link(void)
299 int spacewire_wait_for_link( void )
113 {
300 {
301 /** This function is executed when an interruption is raised by the SpaceWire driver.
302 *
303 * @return RTEMS directive status code:
304 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
305 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
306 *
307 */
308
114 unsigned int i;
309 unsigned int i;
115 int linkStatus;
310 int linkStatus;
116 rtems_status_code status = RTEMS_UNSATISFIED;
311 rtems_status_code status = RTEMS_UNSATISFIED;
@@ -133,6 +328,15 int spacewire_wait_for_link(void)
133
328
134 void spacewire_set_NP(unsigned char val, unsigned int regAddr) // [N]o [P]ort force
329 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
135 {
330 {
331 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
332 *
333 * @param val is the value, 0 or 1, used to set the value of the NP bit.
334 * @param regAddr is the address of the GRSPW control register.
335 *
336 * NP is the bit 20 of the GRSPW control register.
337 *
338 */
339
136 unsigned int *spwptr = (unsigned int*) regAddr;
340 unsigned int *spwptr = (unsigned int*) regAddr;
137
341
138 if (val == 1) {
342 if (val == 1) {
@@ -145,6 +349,15 void spacewire_set_NP(unsigned char val,
145
349
146 void spacewire_set_RE(unsigned char val, unsigned int regAddr) // [R]MAP [E]nable
350 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
147 {
351 {
352 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
353 *
354 * @param val is the value, 0 or 1, used to set the value of the RE bit.
355 * @param regAddr is the address of the GRSPW control register.
356 *
357 * RE is the bit 16 of the GRSPW control register.
358 *
359 */
360
148 unsigned int *spwptr = (unsigned int*) regAddr;
361 unsigned int *spwptr = (unsigned int*) regAddr;
149
362
150 if (val == 1)
363 if (val == 1)
@@ -162,7 +375,8 void spacewire_compute_stats_offsets( vo
162 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
375 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
163 *
376 *
164 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
377 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
165 * to keep the counters consistent even after a reset of the SpaceWire driver.
378 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
379 * during the open systel call).
166 *
380 *
167 */
381 */
168
382
@@ -199,6 +413,71 void spacewire_compute_stats_offsets( vo
199 + spacewire_stats.rx_truncated;
413 + spacewire_stats.rx_truncated;
200 }
414 }
201
415
416 void spacewire_update_statistics( void )
417 {
418 rtems_status_code status;
419 spw_stats spacewire_stats_grspw;
420
421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
422
423 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
424 + spacewire_stats_grspw.packets_received;
425 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
426 + spacewire_stats_grspw.packets_sent;
427 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
428 + spacewire_stats_grspw.parity_err;
429 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
430 + spacewire_stats_grspw.disconnect_err;
431 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
432 + spacewire_stats_grspw.escape_err;
433 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
434 + spacewire_stats_grspw.credit_err;
435 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
436 + spacewire_stats_grspw.write_sync_err;
437 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
438 + spacewire_stats_grspw.rx_rmap_header_crc_err;
439 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
440 + spacewire_stats_grspw.rx_rmap_data_crc_err;
441 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
442 + spacewire_stats_grspw.early_ep;
443 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
444 + spacewire_stats_grspw.invalid_address;
445 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
446 + spacewire_stats_grspw.rx_eep_err;
447 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
448 + spacewire_stats_grspw.rx_truncated;
449 //spacewire_stats.tx_link_err;
450
451 //****************************
452 // DPU_SPACEWIRE_IF_STATISTICS
453 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
454 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
455 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
456 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
457 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
458 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
459
460 //******************************************
461 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
462 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
463 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
464 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
465 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
466 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
467 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb;
468 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb;
469 housekeeping_packet.hk_lfr_dpu_spw_header_crc = (unsigned char) spacewire_stats.rx_rmap_header_crc_err;
470 housekeeping_packet.hk_lfr_dpu_spw_data_crc = (unsigned char) spacewire_stats.rx_rmap_data_crc_err;
471
472 //*********************************************
473 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
474 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
475 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
476 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
477 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
478
479 }
480
202 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
481 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
203 {
482 {
204 //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
483 //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
This diff has been collapsed as it changes many lines, (528 lines changed) Show them Hide them
@@ -12,488 +12,8
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14
14
15 char *DumbMessages[6] = {"in DUMB *** default", // RTEMS_EVENT_0
16 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
17 "in DUMB *** waveforms_isr", // RTEMS_EVENT_2
18 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
19 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
20 "in DUMB *** waveforms_simulator_isr" // RTEMS_EVENT_5
21 };
22
23 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
24 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
25 unsigned int currentTM_length;
26 unsigned char currentTC_processedFlag;
27
28 unsigned int lookUpTableForCRC[256];
29
30 //**********************
31 // GENERAL USE FUNCTIONS
32 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
33 {
34 /** This function generate the CRC for one byte and returns the value of the new syndrome.
35 *
36 * @param D is the current byte of data.
37 * @param Chk is the current syndrom value.
38 * @return the value of the new syndrome on two bytes.
39 *
40 */
41
42 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
43 }
44
45 void initLookUpTableForCRC( void )
46 {
47 /** This function is used to initiates the look-up table for fast CRC computation.
48 *
49 * The global table lookUpTableForCRC[256] is initiated.
50 *
51 */
52
53 unsigned int i;
54 unsigned int tmp;
55
56 for (i=0; i<256; i++)
57 {
58 tmp = 0;
59 if((i & 1) != 0) {
60 tmp = tmp ^ 0x1021;
61 }
62 if((i & 2) != 0) {
63 tmp = tmp ^ 0x2042;
64 }
65 if((i & 4) != 0) {
66 tmp = tmp ^ 0x4084;
67 }
68 if((i & 8) != 0) {
69 tmp = tmp ^ 0x8108;
70 }
71 if((i & 16) != 0) {
72 tmp = tmp ^ 0x1231;
73 }
74 if((i & 32) != 0) {
75 tmp = tmp ^ 0x2462;
76 }
77 if((i & 64) != 0) {
78 tmp = tmp ^ 0x48c4;
79 }
80 if((i & 128) != 0) {
81 tmp = tmp ^ 0x9188;
82 }
83 lookUpTableForCRC[i] = tmp;
84 }
85 }
86
87 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
88 {
89 /** This function calculates a two bytes Cyclic Redundancy Code.
90 *
91 * @param data points to a buffer containing the data on which to compute the CRC.
92 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
93 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
94 *
95 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
96 *
97 */
98
99 unsigned int Chk;
100 int j;
101 Chk = 0xffff; // reset the syndrom to all ones
102 for (j=0; j<sizeOfData; j++) {
103 Chk = Crc_opt(data[j], Chk);
104 }
105 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
106 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
107 }
108
109 void updateLFRCurrentMode()
110 {
111 /** This function updates the value of the global variable lfrCurrentMode.
112 *
113 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
114 *
115 */
116 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
117 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
118 }
119
120 //*********************
121 // ACCEPTANCE FUNCTIONS
122 int tc_acceptance(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv, rtems_id queue_recv_id, rtems_id queue_send_id)
123 {
124 /** This function executes the TeleCommand acceptance steps.
125 *
126 * @param TC points to the TeleCommand packet which is under investigation.
127 * @param tc_len_recv contains the length of the packet that has been received.
128 * @param queue_recv_id is the id of the rtems queue in which messages are written if the acceptance is not successful
129 * @param queue_send_id is the id of the rtems queue in which messages are written if the acceptance is successful
130 * @return status code
131 *
132 * The acceptance steps can result in two different actions.
133 * 1. If the acceptance is successful, the TC is sent in the receiving queue for processing.
134 * 2. If the acceptance fails, a TM packet is transmitted to report the error.
135 *
136 */
137
138 int ret = 0;
139 rtems_status_code status;
140 unsigned int parserCode = 0;
141 unsigned char computed_CRC[2];
142
143 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
144 parserCode = tc_parser( TC, tc_len_recv ) ;
145 if ( (parserCode == ILLEGAL_APID) | (parserCode == WRONG_LEN_PACKET) | (parserCode == INCOR_CHECKSUM)
146 | (parserCode == ILL_TYPE) | (parserCode == ILL_SUBTYPE) | (parserCode == WRONG_APP_DATA) )
147 { // send TM_LFR_TC_EXE_CORRUPTED
148 send_tm_lfr_tc_exe_corrupted( TC, queue_send_id, computed_CRC, currentTC_LEN_RCV );
149 }
150 else { // send valid TC to the action launcher
151 status = rtems_message_queue_send( queue_recv_id, TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
152 ret = LFR_SUCCESSFUL;
153 }
154 return ret;
155 }
156
157 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int TC_LEN_RCV)
158 {
159 /** This function parses TeleCommands.
160 *
161 * @param TC points to the TeleCommand that will be parsed.
162 * @param TC_LEN_RCV is the received packet length.
163 * @return Status code of the parsing.
164 *
165 * The parsing checks:
166 * - process id
167 * - category
168 * - length: a global check is performed and a per subtype check also
169 * - type
170 * - subtype
171 * - crc
172 *
173 */
174
175 int status;
176 unsigned char pid;
177 unsigned char category;
178 unsigned int length;
179 unsigned char packetType;
180 unsigned char packetSubtype;
181
182 status = CCSDS_TM_VALID;
183
184 // APID check *** APID on 2 bytes
185 pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
186 category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
187 length = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
188 packetType = TCPacket->serviceType;
189 packetSubtype = TCPacket->serviceSubType;
190
191 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
192 {
193 status = ILLEGAL_APID;
194 }
195 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
196 {
197 if ( category != CCSDS_PACKET_CATEGORY )
198 {
199 status = ILLEGAL_APID;
200 }
201 }
202 if (status == CCSDS_TM_VALID) // CHECK THE PACKET LENGTH FIELD AND THE ACTUAL LENGTH COMPLIANCE
203 {
204 if (length != TC_LEN_RCV ) {
205 status = WRONG_LEN_PACKET;
206 }
207 }
208 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
209 {
210 if ( length >= CCSDS_TC_PKT_MAX_SIZE ) {
211 status = WRONG_LEN_PACKET;
212 }
213 }
214 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
215 {
216 status = tc_check_type( packetType );
217 }
218 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
219 {
220 status = tc_check_subtype( packetSubtype );
221 }
222 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
223 {
224 status = tc_check_length( packetSubtype, length );
225 }
226 if (status == CCSDS_TM_VALID ) // CHECK CRC
227 {
228 status = tc_check_crc( TCPacket, length );
229 }
230
231 return status;
232 }
233
234 int tc_check_type( unsigned char packetType )
235 {
236 /** This function checks that the type of a TeleCommand is valid.
237 *
238 * @param packetType is the type to check.
239 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
240 *
241 */
242
243 int status;
244
245 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
246 {
247 status = CCSDS_TM_VALID;
248 }
249 else
250 {
251 status = ILL_TYPE;
252 }
253
254 return status;
255 }
256
257 int tc_check_subtype( unsigned char packetSubType )
258 {
259 /** This function checks that the subtype of a TeleCommand is valid.
260 *
261 * @param packetSubType is the subtype to check.
262 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
263 *
264 */
265
266 int status;
267
268 if ( (packetSubType == TC_SUBTYPE_RESET)
269 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
270 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
271 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
272 || (packetSubType == TC_SUBTYPE_DUMP)
273 || (packetSubType == TC_SUBTYPE_ENTER)
274 || (packetSubType == TC_SUBTYPE_UPDT_INFO) || (packetSubType == TC_SUBTYPE_UPDT_TIME)
275 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL) )
276 {
277 status = CCSDS_TM_VALID;
278 }
279 else
280 {
281 status = ILL_TYPE;
282 }
283
284 return status;
285 }
286
287 int tc_check_length( unsigned char packetSubType, unsigned int length )
288 {
289 /** This function checks that the subtype and the length are compliant.
290 *
291 * @param packetSubType is the subtype to check.
292 * @param length is the length to check.
293 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
294 *
295 */
296
297 int status;
298
299 status = LFR_SUCCESSFUL;
300
301 switch(packetSubType)
302 {
303 case TC_SUBTYPE_RESET:
304 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
305 status = WRONG_LEN_PACKET;
306 }
307 else {
308 status = CCSDS_TM_VALID;
309 }
310 break;
311 case TC_SUBTYPE_LOAD_COMM:
312 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
313 status = WRONG_LEN_PACKET;
314 }
315 else {
316 status = CCSDS_TM_VALID;
317 }
318 break;
319 case TC_SUBTYPE_LOAD_NORM:
320 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
321 status = WRONG_LEN_PACKET;
322 }
323 else {
324 status = CCSDS_TM_VALID;
325 }
326 break;
327 case TC_SUBTYPE_LOAD_BURST:
328 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
329 status = WRONG_LEN_PACKET;
330 }
331 else {
332 status = CCSDS_TM_VALID;
333 }
334 break;
335 case TC_SUBTYPE_LOAD_SBM1:
336 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
337 status = WRONG_LEN_PACKET;
338 }
339 else {
340 status = CCSDS_TM_VALID;
341 }
342 break;
343 case TC_SUBTYPE_LOAD_SBM2:
344 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
345 status = WRONG_LEN_PACKET;
346 }
347 else {
348 status = CCSDS_TM_VALID;
349 }
350 break;
351 case TC_SUBTYPE_DUMP:
352 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
353 status = WRONG_LEN_PACKET;
354 }
355 else {
356 status = CCSDS_TM_VALID;
357 }
358 break;
359 case TC_SUBTYPE_ENTER:
360 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
361 status = WRONG_LEN_PACKET;
362 }
363 else {
364 status = CCSDS_TM_VALID;
365 }
366 break;
367 case TC_SUBTYPE_UPDT_INFO:
368 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
369 status = WRONG_LEN_PACKET;
370 }
371 else {
372 status = CCSDS_TM_VALID;
373 }
374 break;
375 case TC_SUBTYPE_EN_CAL:
376 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
377 status = WRONG_LEN_PACKET;
378 }
379 else {
380 status = CCSDS_TM_VALID;
381 }
382 break;
383 case TC_SUBTYPE_DIS_CAL:
384 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
385 status = WRONG_LEN_PACKET;
386 }
387 else {
388 status = CCSDS_TM_VALID;
389 }
390 break;
391 case TC_SUBTYPE_UPDT_TIME:
392 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
393 status = WRONG_LEN_PACKET;
394 }
395 else {
396 status = CCSDS_TM_VALID;
397 }
398 break;
399 default: // if the subtype is not a legal value, return ILL_SUBTYPE
400 status = ILL_SUBTYPE;
401 break ;
402 }
403
404 return status;
405 }
406
407 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length )
408 {
409 /** This function checks the CRC validity of the corresponding TeleCommand packet.
410 *
411 * @param TCPacket points to the TeleCommand packet to check.
412 * @param length is the length of the TC packet.
413 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
414 *
415 */
416
417 int status;
418 unsigned char * CCSDSContent;
419 unsigned char currentTC_COMPUTED_CRC[2];
420
421 CCSDSContent = (unsigned char*) TCPacket->packetID;
422 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
423 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
424 status = INCOR_CHECKSUM;
425 }
426 else if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
427 status = INCOR_CHECKSUM;
428 }
429 else {
430 status = CCSDS_TM_VALID;
431 }
432
433 return status;
434 }
435
436 //***********
15 //***********
437 // RTEMS TASK
16 // RTEMS TASK
438 rtems_task recv_task( rtems_task_argument unused )
439 {
440 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
441 *
442 * @param unused is the starting argument of the RTEMS task
443 *
444 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
445 * 1. It reads the incoming data.
446 * 2. Launches the acceptance procedure.
447 * 3. If the Telecommand is valid, sends it to the ACTN task using an RTEMS message queue.
448 *
449 */
450
451 int len = 0;
452 unsigned int i = 0;
453 ccsdsTelecommandPacket_t currentTC;
454 char data[100];
455 rtems_status_code status;
456 rtems_id queue_recv_id;
457 rtems_id queue_send_id;
458
459 for(i=0; i<100; i++) data[i] = 0;
460
461 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
462
463 status = rtems_message_queue_ident( misc_name[QUEUE_RECV], 0, &queue_recv_id );
464 if (status != RTEMS_SUCCESSFUL)
465 {
466 PRINTF1("in RECV *** ERR getting QUEUE_RECV id, %d\n", status)
467 }
468
469 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_send_id );
470 if (status != RTEMS_SUCCESSFUL)
471 {
472 PRINTF1("in RECV *** ERR getting QUEUE_SEND id, %d\n", status)
473 }
474
475 BOOT_PRINTF("in RECV *** \n")
476
477 while(1)
478 {
479 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
480 if (len == -1){ // error during the read call
481 PRINTF("In RECV *** last read call returned -1\n")
482 }
483 else {
484 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
485 PRINTF("In RECV *** packet lenght too short\n")
486 }
487 else {
488 currentTC_LEN_RCV[0] = 0x00;
489 currentTC_LEN_RCV[1] = (unsigned char) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // build the corresponding packet size field
490 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
491 // CHECK THE TC
492 tc_acceptance(&currentTC, currentTC_LEN_RCV_AsUnsignedInt, queue_recv_id, queue_send_id);
493 }
494 }
495 }
496 }
497
17
498 rtems_task actn_task( rtems_task_argument unused )
18 rtems_task actn_task( rtems_task_argument unused )
499 {
19 {
@@ -608,40 +128,6 rtems_task actn_task( rtems_task_argumen
608 }
128 }
609 }
129 }
610
130
611 rtems_task dumb_task( rtems_task_argument unused )
612 {
613 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
614 *
615 * @param unused is the starting argument of the RTEMS task
616 *
617 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
618 *
619 */
620
621 unsigned int i;
622 unsigned int intEventOut;
623 unsigned int coarse_time = 0;
624 unsigned int fine_time = 0;
625 rtems_event_set event_out;
626
627 BOOT_PRINTF("in DUMB *** \n")
628
629 while(1){
630 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4 | RTEMS_EVENT_5,
631 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
632 intEventOut = (unsigned int) event_out;
633 for ( i=0; i<32; i++)
634 {
635 if ( ((intEventOut >> i) & 0x0001) != 0)
636 {
637 coarse_time = time_management_regs->coarse_time;
638 fine_time = time_management_regs->fine_time;
639 printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
640 }
641 }
642 }
643 }
644
645 //***********
131 //***********
646 // TC ACTIONS
132 // TC ACTIONS
647
133
@@ -1279,6 +765,16 rtems_isr commutation_isr2( rtems_vector
1279 }
765 }
1280 }
766 }
1281
767
1282
768 //****************
769 // OTHER FUNCTIONS
770 void updateLFRCurrentMode()
771 {
772 /** This function updates the value of the global variable lfrCurrentMode.
773 *
774 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
775 *
776 */
777 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
778 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
779 }
1283
780
1284
@@ -22,6 +22,7 int action_load_common_par(ccsdsTelecomm
22 *
22 *
23 *
23 *
24 */
24 */
25
25 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
26 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
26 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
27 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
27 set_wfp_data_shaping(parameter_dump_packet.bw_sp0_sp1_r0_r1);
28 set_wfp_data_shaping(parameter_dump_packet.bw_sp0_sp1_r0_r1);
@@ -36,6 +37,7 int action_load_normal_par(ccsdsTelecomm
36 * @param queue_id is the id of the queue which handles TM related to this execution step
37 * @param queue_id is the id of the queue which handles TM related to this execution step
37 *
38 *
38 */
39 */
40
39 int result;
41 int result;
40 int flag;
42 int flag;
41
43
@@ -113,6 +115,7 int action_load_burst_par(ccsdsTelecomma
113 * @param queue_id is the id of the queue which handles TM related to this execution step
115 * @param queue_id is the id of the queue which handles TM related to this execution step
114 *
116 *
115 */
117 */
118
116 int result;
119 int result;
117 unsigned char lfrMode;
120 unsigned char lfrMode;
118
121
@@ -25,6 +25,13 unsigned char doubleSendCWF2 = 0;
25
25
26 rtems_isr waveforms_isr( rtems_vector_number vector )
26 rtems_isr waveforms_isr( rtems_vector_number vector )
27 {
27 {
28 /** This is the interrupt sub routine called by the waveform picker core.
29 *
30 * This ISR launch different actions depending mainly on two pieces of information:
31 * 1. the values read in the registers of the waveform picker.
32 * 2. the current LFR mode.
33 *
34 */
28
35
29 #ifdef GSA
36 #ifdef GSA
30 #else
37 #else
@@ -190,6 +197,12 rtems_isr waveforms_isr( rtems_vector_nu
190
197
191 rtems_isr waveforms_simulator_isr( rtems_vector_number vector )
198 rtems_isr waveforms_simulator_isr( rtems_vector_number vector )
192 {
199 {
200 /** This is the interrupt sub routine called by the waveform picker simulator.
201 *
202 * This ISR is for debug purpose only.
203 *
204 */
205
193 unsigned char lfrMode;
206 unsigned char lfrMode;
194 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
207 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
195
208
@@ -212,6 +225,17 rtems_isr waveforms_simulator_isr( rtems
212
225
213 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
226 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
214 {
227 {
228 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
229 *
230 * @param unused is the starting argument of the RTEMS task
231 *
232 * The following data packets are sent by this task:
233 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
234 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
235 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
236 *
237 */
238
215 rtems_event_set event_out;
239 rtems_event_set event_out;
216 rtems_id queue_id;
240 rtems_id queue_id;
217 rtems_status_code status;
241 rtems_status_code status;
@@ -283,6 +307,15 rtems_task wfrm_task(rtems_task_argument
283
307
284 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
308 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
285 {
309 {
310 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
311 *
312 * @param unused is the starting argument of the RTEMS task
313 *
314 * The following data packet is sent by this task:
315 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
316 *
317 */
318
286 rtems_event_set event_out;
319 rtems_event_set event_out;
287 rtems_id queue_id;
320 rtems_id queue_id;
288
321
@@ -312,6 +345,16 rtems_task cwf3_task(rtems_task_argument
312
345
313 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
346 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
314 {
347 {
348 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
349 *
350 * @param unused is the starting argument of the RTEMS task
351 *
352 * The following data packet is sent by this function:
353 * - TM_LFR_SCIENCE_BURST_CWF_F2
354 * - TM_LFR_SCIENCE_SBM2_CWF_F2
355 *
356 */
357
315 rtems_event_set event_out;
358 rtems_event_set event_out;
316 rtems_id queue_id;
359 rtems_id queue_id;
317
360
@@ -368,6 +411,15 rtems_task cwf2_task(rtems_task_argument
368
411
369 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
412 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
370 {
413 {
414 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
415 *
416 * @param unused is the starting argument of the RTEMS task
417 *
418 * The following data packet is sent by this function:
419 * - TM_LFR_SCIENCE_SBM1_CWF_F1
420 *
421 */
422
371 rtems_event_set event_out;
423 rtems_event_set event_out;
372 rtems_id queue_id;
424 rtems_id queue_id;
373
425
@@ -900,9 +952,9 char set_wfp_delta_snapshot()
900 {
952 {
901 /** This function sets the delta_snapshot register of the waveform picker module.
953 /** This function sets the delta_snapshot register of the waveform picker module.
902 *
954 *
903 * The value is read from two (unsigned char) of the parameter_dump_packet structure:\n
955 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
904 * sy_lfr_n_swf_p[0] \n
956 * - sy_lfr_n_swf_p[0]
905 * sy_lfr_n_swf_p[1]
957 * - sy_lfr_n_swf_p[1]
906 *
958 *
907 */
959 */
908
960
@@ -928,7 +980,7 char set_wfp_delta_snapshot()
928 aux = delta_snapshot ;
980 aux = delta_snapshot ;
929 ret = LFR_SUCCESSFUL;
981 ret = LFR_SUCCESSFUL;
930 }
982 }
931 waveform_picker_regs->delta_snapshot = aux; // max 2 bytes
983 waveform_picker_regs->delta_snapshot = aux - 1; // max 2 bytes
932 #endif
984 #endif
933
985
934 return ret;
986 return ret;
@@ -1104,3 +1156,16 void reset_local_sbm2_nb_cwf_sent()
1104
1156
1105 param_local.local_sbm2_nb_cwf_sent = 0;
1157 param_local.local_sbm2_nb_cwf_sent = 0;
1106 }
1158 }
1159
1160 rtems_id get_pkts_queue_id( void )
1161 {
1162 rtems_id queue_id;
1163 rtems_status_code status;
1164
1165 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_id );
1166 if (status != RTEMS_SUCCESSFUL)
1167 {
1168 PRINTF1("in get_pkts_queue_id *** ERR %d\n", status)
1169 }
1170 return queue_id;
1171 }
General Comments 0
You need to be logged in to leave comments. Login now