##// END OF EJS Templates
automatic reconnexion of the spacewire link...
paul@pc-solar1.lab-lpp.local -
r17:3a73d9962d4a default
parent child
Show More
@@ -1,46 +1,46
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 <CodeBlocks_layout_file>
2 <CodeBlocks_layout_file>
3 <ActiveTarget name="Debug" />
3 <ActiveTarget name="Debug" />
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
5 <Cursor position="384" topLine="87" />
5 <Cursor position="4971" topLine="100" />
6 </File>
6 </File>
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
8 <Cursor position="1133" topLine="22" />
8 <Cursor position="597" topLine="0" />
9 </File>
9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="3">
11 <Cursor position="545" topLine="0" />
11 <Cursor position="279" topLine="0" />
12 </File>
12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="3">
14 <Cursor position="1157" topLine="0" />
14 <Cursor position="1416" topLine="31" />
15 </File>
15 </File>
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 <Cursor position="628" topLine="7" />
17 <Cursor position="1216" topLine="5" />
18 </File>
18 </File>
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
20 <Cursor position="1153" topLine="16" />
20 <Cursor position="444" topLine="0" />
21 </File>
21 </File>
22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
23 <Cursor position="1380" topLine="35" />
23 <Cursor position="1380" topLine="35" />
24 </File>
24 </File>
25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
26 <Cursor position="341" topLine="0" />
26 <Cursor position="316" topLine="0" />
27 </File>
27 </File>
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="5">
28 <File name="../src/fsw_globals.c" open="1" top="0" tabpos="3">
29 <Cursor position="184" topLine="0" />
29 <Cursor position="1246" topLine="6" />
30 </File>
30 </File>
31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
31 <File name="../src/fsw_init.c" open="1" top="1" tabpos="1">
32 <Cursor position="12072" topLine="91" />
32 <Cursor position="2317" topLine="59" />
33 </File>
33 </File>
34 <File name="../src/fsw_misc.c" open="1" top="1" tabpos="2">
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
35 <Cursor position="4309" topLine="44" />
35 <Cursor position="6076" topLine="0" />
36 </File>
36 </File>
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0">
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="4">
38 <Cursor position="20570" topLine="67" />
38 <Cursor position="19048" topLine="64" />
39 </File>
39 </File>
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="2">
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="5">
41 <Cursor position="15292" topLine="0" />
41 <Cursor position="536" topLine="0" />
42 </File>
42 </File>
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="4">
43 <File name="../src/wf_handler.c" open="1" top="0" tabpos="2">
44 <Cursor position="2540" topLine="42" />
44 <Cursor position="5858" topLine="70" />
45 </File>
45 </File>
46 </CodeBlocks_layout_file>
46 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,142 +1,199
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_TM_PKT_MAX_SIZE 4412
6 #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
6 #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
7 #define CCSDS_TC_PKT_MAX_SIZE 50 // size of the TC_LFR_UPDATE_INFO packet
7 #define CCSDS_TC_PKT_MAX_SIZE 50 // size of the TC_LFR_UPDATE_INFO packet
8 #define CCSDS_TC_TM_PACKET_OFFSET 7
8 #define CCSDS_TC_TM_PACKET_OFFSET 7
9 #define CCSDS_PROCESS_ID 76
9 #define CCSDS_PROCESS_ID 76
10 #define CCSDS_PACKET_CATEGORY 12
10 #define CCSDS_PACKET_CATEGORY 12
11 #define CCSDS_NODE_ADDRESS 0xfe
11 #define CCSDS_NODE_ADDRESS 0xfe
12 //
13 #define CCSDS_DESTINATION_ID_GROUND 0x00
12 #define CCSDS_DESTINATION_ID 0x01
14 #define CCSDS_DESTINATION_ID 0x01
15 #define CCSDS_DESTINATION_ID_DPU 0x01
16 //
13 #define CCSDS_PROTOCOLE_ID 0x02
17 #define CCSDS_PROTOCOLE_ID 0x02
14 #define CCSDS_USER_APP 0x00
18 #define CCSDS_USER_APP 0x00
15
19
16 #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
20 #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
17 #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
21 #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
18
22
19 #define ILLEGAL_APID 0
23 #define ILLEGAL_APID 0
20 #define WRONG_LEN_PACKET 1
24 #define WRONG_LEN_PACKET 1
21 #define INCOR_CHECKSUM 2
25 #define INCOR_CHECKSUM 2
22 #define ILL_TYPE 3
26 #define ILL_TYPE 3
23 #define ILL_SUBTYPE 4
27 #define ILL_SUBTYPE 4
24 #define WRONG_APP_DATA 5
28 #define WRONG_APP_DATA 5
25 #define WRONG_CMD_CODE 6
29 #define WRONG_CMD_CODE 6
26 #define CCSDS_TM_VALID 7
30 #define CCSDS_TM_VALID 7
27 //
31 //
28 #define TC_NOT_EXE 40000
32 #define TC_NOT_EXE 40000
29 #define WRONG_SRC_ID 40001
33 #define WRONG_SRC_ID 40001
30 #define FUNCT_NOT_IMPL 40002
34 #define FUNCT_NOT_IMPL 40002
31 #define FAIL_DETECTED 40003
35 #define FAIL_DETECTED 40003
32 #define NOT_ALLOWED 40004
36 #define NOT_ALLOWED 40004
33 #define CORRUPTED 40005
37 #define CORRUPTED 40005
34
38
35 // // TC SUBTYPES
39 // // TC SUBTYPES
36 #define TC_SUBTYPE_RESET 3
40 #define TC_SUBTYPE_RESET 3
37 #define TC_SUBTYPE_LOAD_COMM 20
41 #define TC_SUBTYPE_LOAD_COMM 20
38 #define TC_SUBTYPE_LOAD_NORM 21
42 #define TC_SUBTYPE_LOAD_NORM 21
39 #define TC_SUBTYPE_LOAD_BURST 24
43 #define TC_SUBTYPE_LOAD_BURST 24
40 #define TC_SUBTYPE_LOAD_SBM1 27
44 #define TC_SUBTYPE_LOAD_SBM1 27
41 #define TC_SUBTYPE_LOAD_SBM2 28
45 #define TC_SUBTYPE_LOAD_SBM2 28
42 #define TC_SUBTYPE_DUMP 30
46 #define TC_SUBTYPE_DUMP 30
43 #define TC_SUBTYPE_ENTER 40
47 #define TC_SUBTYPE_ENTER 40
44 #define TC_SUBTYPE_UPDT_INFO 50
48 #define TC_SUBTYPE_UPDT_INFO 50
45 #define TC_SUBTYPE_EN_CAL 60
49 #define TC_SUBTYPE_EN_CAL 60
46 #define TC_SUBTYPE_DIS_CAL 61
50 #define TC_SUBTYPE_DIS_CAL 61
47 #define TC_SUBTYPE_UPDT_TIME 129
51 #define TC_SUBTYPE_UPDT_TIME 129
48
52
49 #define SID_DEFAULT 0
53 #define SID_DEFAULT 0
54 #define SID_HK 1
50 #define SID_EXE_INC 5
55 #define SID_EXE_INC 5
51 #define SID_NOT_EXE 40000
56 #define SID_NOT_EXE 40000
52 #define SID_NOT_IMP 40002
57 #define SID_NOT_IMP 40002
53 #define SID_EXE_ERR 40003
58 #define SID_EXE_ERR 40003
54 #define SID_EXE_CORR 40005
59 #define SID_EXE_CORR 40005
55
60
56 #define SID_NORM_SWF_F0 3
61 #define SID_NORM_SWF_F0 3
57 #define SID_NORM_SWF_F1 4
62 #define SID_NORM_SWF_F1 4
58 #define SID_NORM_SWF_F2 5
63 #define SID_NORM_SWF_F2 5
59 #define SID_NORM_CWF_F3 1
64 #define SID_NORM_CWF_F3 1
60 #define SID_BURST_CWF_F2 2
65 #define SID_BURST_CWF_F2 2
61 #define SID_SBM1_CWF_F1 24
66 #define SID_SBM1_CWF_F1 24
62 #define SID_SBM2_CWF_F2 25
67 #define SID_SBM2_CWF_F2 25
63 #define SID_NORM_ASM_F0 11
68 #define SID_NORM_ASM_F0 11
64 #define SID_NORM_ASM_F1 12
69 #define SID_NORM_ASM_F1 12
65 #define SID_NORM_ASM_F2 13
70 #define SID_NORM_ASM_F2 13
66 #define SID_NORM_BP1_F0 14
71 #define SID_NORM_BP1_F0 14
67 #define SID_NORM_BP1_F1 15
72 #define SID_NORM_BP1_F1 15
68 #define SID_NORM_BP1_F2 16
73 #define SID_NORM_BP1_F2 16
69 #define SID_NORM_BP2_F0 19
74 #define SID_NORM_BP2_F0 19
70 #define SID_NORM_BP2_F1 20
75 #define SID_NORM_BP2_F1 20
71 #define SID_NORM_BP2_F2 21
76 #define SID_NORM_BP2_F2 21
72 #define SID_BURST_BP1_F0 17
77 #define SID_BURST_BP1_F0 17
73 #define SID_BURST_BP2_F0 22
78 #define SID_BURST_BP2_F0 22
74 #define SID_BURST_BP1_F1 18
79 #define SID_BURST_BP1_F1 18
75 #define SID_BURST_BP2_F1 23
80 #define SID_BURST_BP2_F1 23
76 #define SID_SBM1_BP1_F0 28
81 #define SID_SBM1_BP1_F0 28
77 #define SID_SBM1_BP2_F0 31
82 #define SID_SBM1_BP2_F0 31
78 #define SID_SBM2_BP1_F0 29
83 #define SID_SBM2_BP1_F0 29
79 #define SID_SBM2_BP2_F0 32
84 #define SID_SBM2_BP2_F0 32
80 #define SID_SBM1_BP1_F1 30
85 #define SID_SBM1_BP1_F1 30
81 #define SID_SBM1_BP2_F1 33
86 #define SID_SBM1_BP2_F1 33
82
87
88 // LENGTH (BYTES)
89 #define LENGTH_TM_LFR_HK 126
90 #define LENGTH_TM_LFR_TC_EXE_MAX 32
91 #define LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX 4102
92 //
83 #define TM_LEN_EXE 20 - CCSDS_TC_TM_PACKET_OFFSET
93 #define TM_LEN_EXE 20 - CCSDS_TC_TM_PACKET_OFFSET
84 #define TM_LEN_NOT_EXE 26 - CCSDS_TC_TM_PACKET_OFFSET
94 #define TM_LEN_NOT_EXE 26 - CCSDS_TC_TM_PACKET_OFFSET
85 #define TM_LEN_NOT_IMP 24 - CCSDS_TC_TM_PACKET_OFFSET
95 #define TM_LEN_NOT_IMP 24 - CCSDS_TC_TM_PACKET_OFFSET
86 #define TM_LEN_EXE_ERR 24 - CCSDS_TC_TM_PACKET_OFFSET
96 #define TM_LEN_EXE_ERR 24 - CCSDS_TC_TM_PACKET_OFFSET
87 #define TM_LEN_EXE_CORR 32 - CCSDS_TC_TM_PACKET_OFFSET
97 #define TM_LEN_EXE_CORR 32 - CCSDS_TC_TM_PACKET_OFFSET
88 #define TM_HEADER_LEN 16
98 #define TM_HEADER_LEN 16
99
100 #define LEN_TM_LFR_HK 126 + 4
101 #define LEN_TM_LFR_TC_EXE_NOT_IMP 24 +4
102
89 #define TM_LEN_SCI_NORM_SWF_340 340 * 12 + 6 + 10 - 1
103 #define TM_LEN_SCI_NORM_SWF_340 340 * 12 + 6 + 10 - 1
90 #define TM_LEN_SCI_NORM_SWF_8 8 * 12 + 6 + 10 - 1
104 #define TM_LEN_SCI_NORM_SWF_8 8 * 12 + 6 + 10 - 1
91
105
92 enum TM_TYPE{
106 enum TM_TYPE{
93 TM_LFR_TC_EXE_OK,
107 TM_LFR_TC_EXE_OK,
94 TM_LFR_TC_EXE_ERR,
108 TM_LFR_TC_EXE_ERR,
95 TM_LFR_HK,
109 TM_LFR_HK,
96 TM_LFR_SCI,
110 TM_LFR_SCI,
97 TM_LFR_SCI_SBM,
111 TM_LFR_SCI_SBM,
98 TM_LFR_PAR_DUMP
112 TM_LFR_PAR_DUMP
99 };
113 };
100
114
101 struct TMHeader_str
115 struct TMHeader_str
102 {
116 {
103 volatile unsigned char targetLogicalAddress;
117 volatile unsigned char targetLogicalAddress;
104 volatile unsigned char protocolIdentifier;
118 volatile unsigned char protocolIdentifier;
105 volatile unsigned char reserved;
119 volatile unsigned char reserved;
106 volatile unsigned char userApplication;
120 volatile unsigned char userApplication;
107 volatile unsigned char packetID[2];
121 volatile unsigned char packetID[2];
108 volatile unsigned char packetSequenceControl[2];
122 volatile unsigned char packetSequenceControl[2];
109 volatile unsigned char packetLength[2];
123 volatile unsigned char packetLength[2];
110 volatile unsigned char dataFieldHeader[10];
124 volatile unsigned char dataFieldHeader[10];
111 };
125 };
112 typedef struct TMHeader_str TMHeader_t;
126 typedef struct TMHeader_str TMHeader_t;
113
127
128 struct Packet_TM_LFR_HK_str
129 {
130 volatile unsigned char targetLogicalAddress;
131 volatile unsigned char protocolIdentifier;
132 volatile unsigned char reserved;
133 volatile unsigned char userApplication;
134 volatile unsigned char packetID[2];
135 volatile unsigned char packetSequenceControl[2];
136 volatile unsigned char packetLength[2];
137 volatile unsigned char dataFieldHeader[10];
138 volatile unsigned char data[LENGTH_TM_LFR_HK - 10 + 1];
139 };
140 typedef struct Packet_TM_LFR_HK_str Packet_TM_LFR_HK_t;
141
142 struct Packet_TM_LFR_TC_EXE_str
143 {
144 volatile unsigned char targetLogicalAddress;
145 volatile unsigned char protocolIdentifier;
146 volatile unsigned char reserved;
147 volatile unsigned char userApplication;
148 volatile unsigned char packetID[2];
149 volatile unsigned char packetSequenceControl[2];
150 volatile unsigned char packetLength[2];
151 volatile unsigned char dataFieldHeader[10];
152 volatile unsigned char data[LENGTH_TM_LFR_TC_EXE_MAX - 10 + 1];
153 };
154 typedef struct Packet_TM_LFR_TC_EXE_str Packet_TM_LFR_TC_EXE_t;
155
156 struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str
157 {
158 volatile unsigned char targetLogicalAddress;
159 volatile unsigned char protocolIdentifier;
160 volatile unsigned char reserved;
161 volatile unsigned char userApplication;
162 volatile unsigned char packetID[2];
163 volatile unsigned char packetSequenceControl[2];
164 volatile unsigned char packetLength[2];
165 volatile unsigned char dataFieldHeader[10];
166 volatile unsigned char auxiliaryHeader[6];
167 volatile unsigned char data[LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX - 10 + 1];
168 };
169 typedef struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str Packet_TM_LFR_SCIENCE_NORMAL_WF_t;
170
114 struct ExtendedTMHeader_str
171 struct ExtendedTMHeader_str
115 {
172 {
116 volatile unsigned char targetLogicalAddress;
173 volatile unsigned char targetLogicalAddress;
117 volatile unsigned char protocolIdentifier;
174 volatile unsigned char protocolIdentifier;
118 volatile unsigned char reserved;
175 volatile unsigned char reserved;
119 volatile unsigned char userApplication;
176 volatile unsigned char userApplication;
120 volatile unsigned char packetID[2];
177 volatile unsigned char packetID[2];
121 volatile unsigned char packetSequenceControl[2];
178 volatile unsigned char packetSequenceControl[2];
122 volatile unsigned char packetLength[2];
179 volatile unsigned char packetLength[2];
123 volatile unsigned char dataFieldHeader[10];
180 volatile unsigned char dataFieldHeader[10];
124 volatile unsigned char auxiliaryHeader[6];
181 volatile unsigned char auxiliaryHeader[6];
125 };
182 };
126 typedef struct ExtendedTMHeader_str ExtendedTMHeader_t;
183 typedef struct ExtendedTMHeader_str ExtendedTMHeader_t;
127
184
128 struct ccsdsTelecommandPacket_str
185 struct ccsdsTelecommandPacket_str
129 {
186 {
130 //unsigned char targetLogicalAddress; // removed by the grspw module
187 //unsigned char targetLogicalAddress; // removed by the grspw module
131 volatile unsigned char protocolIdentifier;
188 volatile unsigned char protocolIdentifier;
132 volatile unsigned char reserved;
189 volatile unsigned char reserved;
133 volatile unsigned char userApplication;
190 volatile unsigned char userApplication;
134 volatile unsigned char packetID[2];
191 volatile unsigned char packetID[2];
135 volatile unsigned char packetSequenceControl[2];
192 volatile unsigned char packetSequenceControl[2];
136 volatile unsigned char packetLength[2];
193 volatile unsigned char packetLength[2];
137 volatile unsigned char dataFieldHeader[4];
194 volatile unsigned char dataFieldHeader[4];
138 volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
195 volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
139 };
196 };
140 typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
197 typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
141
198
142 #endif // CCSDS_H_INCLUDED
199 #endif // CCSDS_H_INCLUDED
@@ -1,59 +1,60
1 #ifndef FSW_RTEMS_H_INCLUDED
1 #ifndef FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
3
3
4 #include <errno.h>
4 #include <errno.h>
5 #include <fcntl.h>
5 #include <fcntl.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <stdlib.h>
7 #include <stdlib.h>
8
8
9 #include <grspw.h>
9 #include <grspw.h>
10 #include <apbuart.h>
10 #include <apbuart.h>
11
11
12 #include <fsw_params.h>
12 #include <fsw_params.h>
13 #include <fsw_misc.h>
13 #include <fsw_misc.h>
14 #include <fsw_processing.h>
14 #include <fsw_processing.h>
15 #include <tc_handler.h>
15 #include <tc_handler.h>
16 #include <wf_handler.h>
16 #include <wf_handler.h>
17 #include <grlib_regs.h>
17 #include <grlib_regs.h>
18
18
19 extern int sched_yield();
19 extern int sched_yield();
20 extern int errno;
20 extern int errno;
21 extern rtems_id Task_id[ ]; /* array of task ids */
21 extern rtems_id Task_id[ ]; /* array of task ids */
22 extern rtems_name Task_name[ ]; /* array of task names */
22 extern rtems_name Task_name[ ]; /* array of task names */
23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
24 extern int fdSPW; // grspw file descriptor
24 extern int fdSPW; // grspw file descriptor
25 extern int fdUART; // uart file descriptor
25 extern int fdUART; // uart file descriptor
26
26
27 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
27 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
28
28
29 // MODE PARAMETERS
29 // MODE PARAMETERS
30 extern struct param_norm_str param_norm;
30 extern struct param_norm_str param_norm;
31 extern struct param_burst_str param_burst;
31 extern struct param_burst_str param_burst;
32 extern struct param_sbm1_str param_sbm1;
32 extern struct param_sbm1_str param_sbm1;
33 extern struct param_sbm2_str param_sbm2;
33 extern struct param_sbm2_str param_sbm2;
34 extern unsigned char param_common[];
34 extern unsigned char param_common[];
35
35
36 // RTEMS TASKS
36 // RTEMS TASKS
37 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
37 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
38 rtems_task recv_task(rtems_task_argument argument);
38 rtems_task recv_task(rtems_task_argument argument);
39 rtems_task spiq_task(rtems_task_argument argument);
39 rtems_task spiq_task(rtems_task_argument argument);
40 rtems_task stat_task(rtems_task_argument argument);
40 rtems_task stat_task(rtems_task_argument argument);
41 rtems_task wfrm_task(rtems_task_argument argument);
41 rtems_task wfrm_task(rtems_task_argument argument);
42 int create_names();
42 int create_all_tasks();
43 int create_all_tasks();
43 int start_all_tasks();
44 int start_all_tasks();
44 int create_message_queue();
45 int create_message_queue();
45
46
46 // OTHER functions
47 // OTHER functions
47 void init_default_mode_parameters();
48 void init_default_mode_parameters();
48
49
49 int configure_spw_link();
50 int configure_spw_link();
50 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
51 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
51 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
52 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
52
53
53 extern int rtems_cpu_usage_report();
54 extern int rtems_cpu_usage_report();
54 extern int rtems_cpu_usage_reset();
55 extern int rtems_cpu_usage_reset();
55 void print_statistics(spw_stats *);
56 void print_statistics(spw_stats *);
56 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
57 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
57 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
58 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
58
59
59 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
60 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,20 +1,28
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 <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6
6
7 #include <fsw_init.h>
7 #include <fsw_init.h>
8 #include <fsw_params.h>
8 #include <fsw_params.h>
9 #include <grlib_regs.h>
9 #include <grlib_regs.h>
10 #include <grspw.h>
10 #include <grspw.h>
11 #include <ccsds_types.h>
11 #include <ccsds_types.h>
12
12
13 rtems_name HK_name; /* name of the HK rate monotonic */
14 rtems_id HK_id; /* id of the HK rate monotonic period */
15
13 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
14 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
15 void print_statistics(spw_stats *stats);
18 void print_statistics(spw_stats *stats);
19
20 // SERIAL LINK
16 int send_console_outputs_on_serial_port();
21 int send_console_outputs_on_serial_port();
22 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
23
24 // RTEMS TASKS
17 rtems_task stat_task(rtems_task_argument argument);
25 rtems_task stat_task(rtems_task_argument argument);
18 rtems_task hous_task(rtems_task_argument argument);
26 rtems_task hous_task(rtems_task_argument argument);
19
27
20 #endif // FSW_MISC_H_INCLUDED
28 #endif // FSW_MISC_H_INCLUDED
@@ -1,107 +1,106
1 #ifndef FSW_RTEMS_CONFIG_H_INCLUDED
1 #ifndef FSW_RTEMS_CONFIG_H_INCLUDED
2 #define FSW_RTEMS_CONFIG_H_INCLUDED
2 #define FSW_RTEMS_CONFIG_H_INCLUDED
3
3
4 #define GRSPW_DEVICE_NAME "/dev/grspw0"
4 #define GRSPW_DEVICE_NAME "/dev/grspw0"
5 #define UART_DEVICE_NAME "/dev/console"
5 #define UART_DEVICE_NAME "/dev/console"
6
6
7 //**********
7 //**********
8 // LFR MODES
8 // LFR MODES
9 #define LFR_MODE_STANDBY 0
9 #define LFR_MODE_STANDBY 0
10 #define LFR_MODE_NORMAL 1
10 #define LFR_MODE_NORMAL 1
11 #define LFR_MODE_BURST 2
11 #define LFR_MODE_BURST 2
12 #define LFR_MODE_SBM1 3
12 #define LFR_MODE_SBM1 3
13 #define LFR_MODE_SBM2 4
13 #define LFR_MODE_SBM2 4
14
14
15 //*****************************
15 //*****************************
16 // APB REGISTERS BASE ADDRESSES
16 // APB REGISTERS BASE ADDRESSES
17 #define REGS_ADDR_APBUART 0x80000100
17 #define REGS_ADDR_APBUART 0x80000100
18 #define REGS_ADDR_GPTIMER 0x80000300
18 #define REGS_ADDR_GPTIMER 0x80000300
19 #define REGS_ADDR_GRSPW 0x80000500
19 #define REGS_ADDR_GRSPW 0x80000500
20 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
20 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
21 #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700
21 #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700
22
22
23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
24 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
24
25
25 //**********
26 //**********
26 // IRQ LINES
27 // IRQ LINES
27 #define IRQ_SM 9
28 #define IRQ_SM 9
28 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
29 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
29 #define IRQ_WF 10
30 #define IRQ_WF 10
30 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
31 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
31 #define IRQ_TIME1 12
32 #define IRQ_TIME1 12
32 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
33 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
33 #define IRQ_TIME2 13
34 #define IRQ_TIME2 13
34 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
35 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
35
36
36 //*****
37 //*****
37 // TIME
38 // TIME
38 #define CLKDIV_SM_SIMULATOR 9999
39 #define CLKDIV_SM_SIMULATOR 9999
39 #define CLKDIV_WF_SIMULATOR 9999999
40 #define CLKDIV_WF_SIMULATOR 9999999
40 #define TIMER_SM_SIMULATOR 1
41 #define TIMER_SM_SIMULATOR 1
41 #define TIMER_WF_SIMULATOR 2
42 #define TIMER_WF_SIMULATOR 2
42 #define HK_PERIOD 100 // 100 * 10ms => 1sec
43 #define HK_PERIOD 100 // 100 * 10ms => 1sec
43
44
44 //******
45 //******
45 // RTEMS
46 // RTEMS
46 #define TASKID_RECV 1
47 #define TASKID_RECV 1
47 #define TASKID_ACTN 2
48 #define TASKID_ACTN 2
48 #define TASKID_SPIQ 3
49 #define TASKID_SPIQ 3
49 #define TASKID_SMIQ 4
50 #define TASKID_SMIQ 4
50 #define TASKID_STAT 5
51 #define TASKID_STAT 5
51 #define TASKID_AVF0 6
52 #define TASKID_AVF0 6
52 #define TASKID_BPF0 7
53 #define TASKID_BPF0 7
53 #define TASKID_WFRM 8
54 #define TASKID_WFRM 8
54 #define TASKID_DUMB 9
55 #define TASKID_DUMB 9
55 #define TASKID_HOUS 10
56 #define TASKID_HOUS 10
56
57
57 #define ACTION_MSG_QUEUE_COUNT 10
58 #define ACTION_MSG_QUEUE_COUNT 10
58
59
59 // LENGTH (BYTES)
60 #define LENGTH_TM_LFR_HK 126
61
62 //*******
60 //*******
63 // MACROS
61 // MACROS
64 //#define PRINT_TASK_STATISTICS
62 #define PRINT_TASK_STATISTICS
65 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
63 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
66 #ifdef PRINT_MESSAGES_ON_CONSOLE
64 #ifdef PRINT_MESSAGES_ON_CONSOLE
67 #define PRINTF(x) printf(x);
65 #define PRINTF(x) printf(x);
68 #define PRINTF1(x,y) printf(x,y);
66 #define PRINTF1(x,y) printf(x,y);
69 #define PRINTF2(x,y,z) printf(x,y,z);
67 #define PRINTF2(x,y,z) printf(x,y,z);
70 #else
68 #else
71 #define PRINTF(x) ;
69 #define PRINTF(x) ;
72 #define PRINTF1(x,y) ;
70 #define PRINTF1(x,y) ;
73 #define PRINTF2(x,y,z) ;
71 #define PRINTF2(x,y,z) ;
74 #endif
72 #endif
75
73
76 #define NB_SAMPLES_PER_SNAPSHOT 2048
74 #define NB_SAMPLES_PER_SNAPSHOT 2048
77 #define NB_BYTES_SWF_BLK 2 * 6
75 #define NB_BYTES_SWF_BLK 2 * 6
76 #define NB_WORDS_SWF_BLK 3
78
77
79 struct param_norm_str{
78 struct param_norm_str{
80 unsigned int sy_lfr_n_swf_l; // length of the snapshots
79 unsigned int sy_lfr_n_swf_l; // length of the snapshots
81 unsigned int sy_lfr_n_swf_p; // time between two snapshots
80 unsigned int sy_lfr_n_swf_p; // time between two snapshots
82 unsigned int sy_lfr_n_asm_p; // time between two asm
81 unsigned int sy_lfr_n_asm_p; // time between two asm
83 unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set
82 unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set
84 unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set
83 unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set
85 };
84 };
86
85
87 struct param_burst_str{
86 struct param_burst_str{
88 unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set
87 unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set
89 unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set
88 unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set
90 };
89 };
91
90
92 struct param_sbm1_str{
91 struct param_sbm1_str{
93 unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set
92 unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set
94 unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set
93 unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set
95 };
94 };
96
95
97 struct param_sbm2_str{
96 struct param_sbm2_str{
98 unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set
97 unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set
99 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
98 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
100 };
99 };
101
100
102 extern volatile int wf_snap_f0[ ]; // 24576 bytes
101 extern volatile int wf_snap_f0[ ]; // 24576 bytes
103 extern volatile int wf_snap_f1[ ]; // 24576 bytes
102 extern volatile int wf_snap_f1[ ]; // 24576 bytes
104 extern volatile int wf_snap_f2[ ]; // 24576 bytes
103 extern volatile int wf_snap_f2[ ]; // 24576 bytes
105 extern volatile int wf_cont_f3[ ]; // 24576 bytes
104 extern volatile int wf_cont_f3[ ]; // 24576 bytes
106
105
107 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
106 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,44 +1,45
1 #ifndef FSW_RTEMS_PROCESSING_H_INCLUDED
1 #ifndef FSW_RTEMS_PROCESSING_H_INCLUDED
2 #define FSW_RTEMS_PROCESSING_H_INCLUDED
2 #define FSW_RTEMS_PROCESSING_H_INCLUDED
3
3
4 #define NB_BINS_spec_mat 128
4 #define NB_BINS_spec_mat 128
5 #define NB_VALUES_PER_spec_mat 25
5 #define NB_VALUES_PER_spec_mat 25
6 #define TOTAL_SIZE_SPEC_MAT NB_BINS_spec_mat * NB_VALUES_PER_spec_mat
6 #define TOTAL_SIZE_SPEC_MAT NB_BINS_spec_mat * NB_VALUES_PER_spec_mat
7 #define NB_BINS_COMPRESSED_MATRIX_f0 11
7 #define NB_BINS_COMPRESSED_MATRIX_f0 11
8 #define SIZE_COMPRESSED_spec_mat_f1 13
8 #define SIZE_COMPRESSED_spec_mat_f1 13
9 #define SIZE_COMPRESSED_spec_mat_f2 12
9 #define SIZE_COMPRESSED_spec_mat_f2 12
10 #define TOTAL_SIZE_COMPRESSED_MATRIX_f0 NB_BINS_COMPRESSED_MATRIX_f0 * NB_VALUES_PER_spec_mat
10 #define TOTAL_SIZE_COMPRESSED_MATRIX_f0 NB_BINS_COMPRESSED_MATRIX_f0 * NB_VALUES_PER_spec_mat
11 #define NB_AVERAGE_NORMAL_f0 96*4
11 #define NB_AVERAGE_NORMAL_f0 96*4
12 #define NB_SM_TO_RECEIVE_BEFORE_AVF0 8
12 #define NB_SM_TO_RECEIVE_BEFORE_AVF0 8
13
13
14 #include <rtems.h>
14 #include <rtems.h>
15 #include <grlib_regs.h>
15 #include <grlib_regs.h>
16 #include <fsw_params.h>
16 #include <fsw_params.h>
17
17
18 struct BP1_str{
18 struct BP1_str{
19 volatile unsigned char PE[2];
19 volatile unsigned char PE[2];
20 volatile unsigned char PB[2];
20 volatile unsigned char PB[2];
21 volatile unsigned char V0;
21 volatile unsigned char V0;
22 volatile unsigned char V1;
22 volatile unsigned char V1;
23 volatile unsigned char V2_ELLIP_DOP;
23 volatile unsigned char V2_ELLIP_DOP;
24 volatile unsigned char SZ;
24 volatile unsigned char SZ;
25 volatile unsigned char VPHI;
25 volatile unsigned char VPHI;
26 };
26 };
27 typedef struct BP1_str BP1_t;
27 typedef struct BP1_str BP1_t;
28
28
29 // ISR
29 // ISR
30 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
30 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
31
31 // RTEMS TASKS
32 // RTEMS TASKS
32 rtems_task spw_bppr_task(rtems_task_argument argument);
33 rtems_task spw_bppr_task(rtems_task_argument argument);
33 rtems_task avf0_task(rtems_task_argument argument);
34 rtems_task avf0_task(rtems_task_argument argument);
34 rtems_task bpf0_task(rtems_task_argument argument);
35 rtems_task bpf0_task(rtems_task_argument argument);
35 rtems_task smiq_task(rtems_task_argument argument); // added to test the spectral matrix simulator
36 rtems_task smiq_task(rtems_task_argument argument); // added to test the spectral matrix simulator
36 //
37
37 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument);
38 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument);
38 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat);
39 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat);
39 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat);
40 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat);
40 void matrix_reset(float *averaged_spec_mat);
41 void matrix_reset(float *averaged_spec_mat);
41 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1);
42 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1);
42 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43
44
44 #endif // FSW_RTEMS_PROCESSING_H_INCLUDED
45 #endif // FSW_RTEMS_PROCESSING_H_INCLUDED
@@ -1,20 +1,25
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 <rtems.h>
4 #include <rtems.h>
5 #include <fsw_params.h>
5 #include <fsw_params.h>
6 #include <grspw.h>
6 #include <grspw.h>
7 #include <grlib_regs.h>
7 #include <grlib_regs.h>
8 #include <ccsds_types.h>
8 #include <ccsds_types.h>
9 #include <stdio.h>
9 #include <stdio.h>
10 #include <fsw_init.h>
10 #include <fsw_init.h>
11
11
12 //#include <sys/ioctl.h>
12 //#include <sys/ioctl.h>
13
13
14 extern rtems_id Task_id[]; /* array of task ids */
14 extern rtems_id Task_id[]; /* array of task ids */
15 extern int fdSPW;
15 extern int fdSPW;
16
16
17 rtems_isr waveforms_isr( rtems_vector_number vector );
17 rtems_isr waveforms_isr( rtems_vector_number vector );
18 rtems_task wfrm_task(rtems_task_argument argument);
18 rtems_task wfrm_task(rtems_task_argument argument);
19
19
20 //******************
21 // general functions
22 void init_waveforms();
23 int buil_value(int value1, int value0);
24
20 #endif // WF_HANDLER_H_INCLUDED
25 #endif // WF_HANDLER_H_INCLUDED
@@ -1,49 +1,48
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <rtems.h>
2 #include <rtems.h>
3 #include <ccsds_types.h>
3 #include <ccsds_types.h>
4
4
5 // RTEMS GLOBAL VARIABLES
5 // RTEMS GLOBAL VARIABLES
6 rtems_name misc_name[5];
6 rtems_name misc_name[5];
7 rtems_name misc_id[5];
7 rtems_name misc_id[5];
8 rtems_id Task_id[15]; /* array of task ids */
8 rtems_id Task_id[15]; /* array of task ids */
9 rtems_name Task_name[15]; /* array of task names */
9 rtems_name Task_name[15]; /* array of task names */
10 int fdSPW;
10 int fdSPW;
11 int fdUART;
11 int fdUART;
12
12
13 // APB CONFIGURATION REGISTERS
13 // APB CONFIGURATION REGISTERS
14 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
14 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
15
15
16 // WAVEFORMS GLOBAL VARIABLES
16 // WAVEFORMS GLOBAL VARIABLES
17 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
17 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
18 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
18 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
19 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
19 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
20 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
20 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
21
21
22 // SPECTRAL MATRICES GLOBAL VARIABLES
22 // SPECTRAL MATRICES GLOBAL VARIABLES
23 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
23 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
24 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
24 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
25 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
25 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
26 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
26 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
27 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
27 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
28 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
28 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
29 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
29 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
30 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
30 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
31 //
31 //
32 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
32 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
33 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
33 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
34
34
35 // MODE PARAMETERS
35 // MODE PARAMETERS
36 struct param_norm_str param_norm;
36 struct param_norm_str param_norm;
37 struct param_burst_str param_burst;
37 struct param_burst_str param_burst;
38 struct param_sbm1_str param_sbm1;
38 struct param_sbm1_str param_sbm1;
39 struct param_sbm2_str param_sbm2;
39 struct param_sbm2_str param_sbm2;
40 unsigned char param_common[2];
40 unsigned char param_common[2];
41
41
42 // HK PACKETS
42 // HK PACKETS
43 TMHeader_t housekeeping_header;
43 Packet_TM_LFR_HK_t housekeeping_packet;
44 char housekeeping_data[LENGTH_TM_LFR_HK - 10 + 1];
45
44
46 // BASIC PARAMETERS GLOBAL VARIABLES
45 // BASIC PARAMETERS GLOBAL VARIABLES
47 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
46 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
48 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
47 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
49
48
@@ -1,361 +1,373
1 //*************************
1 //*************************
2 // GPL reminder to be added
2 // GPL reminder to be added
3 //*************************
3 //*************************
4
4
5 #include <rtems.h>
5 #include <rtems.h>
6
6
7 /* configuration information */
7 /* configuration information */
8
8
9 #define CONFIGURE_INIT
9 #define CONFIGURE_INIT
10
10
11 #include <bsp.h> /* for device driver prototypes */
11 #include <bsp.h> /* for device driver prototypes */
12
12
13 /* configuration information */
13 /* configuration information */
14
14
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17
17
18 #define CONFIGURE_MAXIMUM_TASKS 15
18 #define CONFIGURE_MAXIMUM_TASKS 15
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 #define CONFIGURE_MAXIMUM_PERIODS 1
24 #define CONFIGURE_MAXIMUM_PERIODS 5
25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
26
26
27 #include <rtems/confdefs.h>
27 #include <rtems/confdefs.h>
28
28
29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
30 #ifdef RTEMS_DRVMGR_STARTUP
30 #ifdef RTEMS_DRVMGR_STARTUP
31 #ifdef LEON3
31 #ifdef LEON3
32 /* Add Timer and UART Driver */
32 /* Add Timer and UART Driver */
33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
35 #endif
35 #endif
36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
38 #endif
38 #endif
39 #endif
39 #endif
40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
41 #include <drvmgr/drvmgr_confdefs.h>
41 #include <drvmgr/drvmgr_confdefs.h>
42 #endif
42 #endif
43
43
44 #include <fsw_init.h>
44 #include <fsw_init.h>
45 #include <fsw_config.c>
45 #include <fsw_config.c>
46
46
47 char *link_status(int status);
47 char *link_status(int status);
48
48
49 char *lstates[6] = {"Error-reset",
49 char *lstates[6] = {"Error-reset",
50 "Error-wait",
50 "Error-wait",
51 "Ready",
51 "Ready",
52 "Started",
52 "Started",
53 "Connecting",
53 "Connecting",
54 "Run"
54 "Run"
55 };
55 };
56
56
57 rtems_task Init( rtems_task_argument ignored )
57 rtems_task Init( rtems_task_argument ignored )
58 {
58 {
59 rtems_status_code status;
59 rtems_status_code status;
60 rtems_isr_entry old_isr_handler;
60 rtems_isr_entry old_isr_handler;
61
61
62 PRINTF("\n\n\n\n\n")
63 PRINTF("***************************\n")
64 PRINTF("** START Flight Software **\n")
65 PRINTF("***************************\n")
66 PRINTF("\n\n")
67
62 //send_console_outputs_on_serial_port();
68 //send_console_outputs_on_serial_port();
69 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
63
70
64 initLookUpTableForCRC(); // in tc_handler.h
71 initLookUpTableForCRC(); // in tc_handler.h
65 init_default_mode_parameters();
72 init_default_mode_parameters();
66 create_message_queue();
73 create_message_queue();
74
75 create_names();
67 create_all_tasks();
76 create_all_tasks();
68 start_all_tasks();
77 start_all_tasks();
69
78
70 grspw_timecode_callback = &timecode_irq_handler;
79 grspw_timecode_callback = &timecode_irq_handler;
71
80
72 configure_spw_link();
81 configure_spw_link();
73
82
83 init_waveforms();
84
74 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
85 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
75 IRQ_SPARC_SM, spectral_matrices_isr );
86 IRQ_SPARC_SM, spectral_matrices_isr );
76 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
87 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
77 IRQ_SPARC_WF, waveforms_isr );
88 IRQ_SPARC_WF, waveforms_isr );
78
89
79 // irq handling of the time management unit
90 // irq handling of the time management unit
80 status = rtems_interrupt_catch( commutation_isr1,
91 status = rtems_interrupt_catch( commutation_isr1,
81 IRQ_SPARC_TIME1,
92 IRQ_SPARC_TIME1,
82 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
93 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
83 if (status==RTEMS_SUCCESSFUL)
94 if (status==RTEMS_SUCCESSFUL)
84 PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
95 PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
85
96
86 status = rtems_interrupt_catch( commutation_isr2,
97 status = rtems_interrupt_catch( commutation_isr2,
87 IRQ_SPARC_TIME2,
98 IRQ_SPARC_TIME2,
88 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
99 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
89 if (status==RTEMS_SUCCESSFUL)
100 if (status==RTEMS_SUCCESSFUL)
90 PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
101 PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
91
102
92 LEON_Unmask_interrupt( IRQ_TIME1 );
103 LEON_Unmask_interrupt( IRQ_TIME1 );
93 LEON_Unmask_interrupt( IRQ_TIME2 );
104 LEON_Unmask_interrupt( IRQ_TIME2 );
94
105
95 status = rtems_task_delete(RTEMS_SELF);
106 status = rtems_task_delete(RTEMS_SELF);
96 }
107 }
97
108
98 rtems_task spiq_task(rtems_task_argument unused)
109 rtems_task spiq_task(rtems_task_argument unused)
99 {
110 {
100 rtems_event_set event_out;
111 rtems_event_set event_out;
101 struct grspw_regs_str *grspw_regs;
112 struct grspw_regs_str *grspw_regs;
102 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
113 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
114 rtems_status_code status;
103
115
104 while(1){
116 while(1){
105 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
117 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
106 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
118 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
107
119
108 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) // suspend RECV task
120 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) // suspend RECV task
109 PRINTF("In SPIQ *** Error suspending RECV Task\n")
121 PRINTF("in SPIQ *** Error suspending RECV Task\n")
110 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) // suspend HOUS task
122 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) // suspend HOUS task
111 PRINTF("In SPIQ *** Error suspending HOUS Task\n")
123 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
112
124
113 configure_spw_link();
125 configure_spw_link();
126
127 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
128 if (status!=RTEMS_SUCCESSFUL)
129 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
114
130
115 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
131 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
116 PRINTF("In SPIQ *** Error resume RECV Task\n")
132 PRINTF("in SPIQ *** Error restarting RECV Task\n")
117 if (rtems_task_restart(Task_id[TASKID_HOUS], 1)!=RTEMS_SUCCESSFUL) // restart HOUS task
118 PRINTF("In SPIQ *** Error resume HOUS Task\n")
119
120 }
133 }
121 }
134 }
122
135
123 void init_default_mode_parameters()
136 void init_default_mode_parameters()
124 {
137 {
125 // COMMON PARAMETERS
138 // COMMON PARAMETERS
126 param_common[0] = 0x00;
139 param_common[0] = 0x00;
127 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
140 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
128 // NORMAL MODE
141 // NORMAL MODE
129 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
142 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
130 param_norm.sy_lfr_n_swf_p = 300; // sec
143 param_norm.sy_lfr_n_swf_p = 300; // sec
131 param_norm.sy_lfr_n_asm_p = 3600; // sec
144 param_norm.sy_lfr_n_asm_p = 3600; // sec
132 param_norm.sy_lfr_n_bp_p0 = 4; // sec
145 param_norm.sy_lfr_n_bp_p0 = 4; // sec
133 param_norm.sy_lfr_n_bp_p1 = 20; // sec
146 param_norm.sy_lfr_n_bp_p1 = 20; // sec
134 // BURST MODE
147 // BURST MODE
135 param_burst.sy_lfr_b_bp_p0 = 1; // sec
148 param_burst.sy_lfr_b_bp_p0 = 1; // sec
136 param_burst.sy_lfr_b_bp_p1 = 5; // sec
149 param_burst.sy_lfr_b_bp_p1 = 5; // sec
137 // SBM1 MODE
150 // SBM1 MODE
138 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
151 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
139 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
152 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
140 // SBM2 MODE
153 // SBM2 MODE
141 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
154 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
142 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
155 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
143 }
156 }
144
157
145 int create_all_tasks()
158 int create_names()
146 {
159 {
147 rtems_status_code status;
160 // task names
148
149 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
161 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
150 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
162 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
151 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
163 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
152 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
164 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
153 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
165 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
154 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
166 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
155 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
167 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
156 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
168 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
157 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
169 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
158 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
170 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
171
172 // rate monotonic period name
173 HK_name = rtems_build_name( 'H', 'O', 'U', 'S' );
174
175 return 0;
176 }
177
178 int create_all_tasks()
179 {
180 rtems_status_code status;
159
181
160 // RECV
182 // RECV
161 status = rtems_task_create(
183 status = rtems_task_create(
162 Task_name[TASKID_RECV], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
184 Task_name[TASKID_RECV], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
163 RTEMS_DEFAULT_MODES,
185 RTEMS_DEFAULT_MODES,
164 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
186 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
165 );
187 );
166 // ACTN
188 // ACTN
167 status = rtems_task_create(
189 status = rtems_task_create(
168 Task_name[TASKID_ACTN], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
190 Task_name[TASKID_ACTN], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
169 RTEMS_DEFAULT_MODES,
191 RTEMS_DEFAULT_MODES,
170 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_ACTN]
192 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_ACTN]
171 );
193 );
172 // SPIQ
194 // SPIQ
173 status = rtems_task_create(
195 status = rtems_task_create(
174 Task_name[TASKID_SPIQ], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
196 Task_name[TASKID_SPIQ], 5, RTEMS_MINIMUM_STACK_SIZE * 2,
175 RTEMS_DEFAULT_MODES,
197 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
176 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
198 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
177 );
199 );
178 // SMIQ
200 // SMIQ
179 status = rtems_task_create(
201 status = rtems_task_create(
180 Task_name[TASKID_SMIQ], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
202 Task_name[TASKID_SMIQ], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
181 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
203 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
182 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SMIQ]
204 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SMIQ]
183 );
205 );
184 // STAT
206 // STAT
185 status = rtems_task_create(
207 status = rtems_task_create(
186 Task_name[TASKID_STAT], 150, RTEMS_MINIMUM_STACK_SIZE * 2,
208 Task_name[TASKID_STAT], 150, RTEMS_MINIMUM_STACK_SIZE * 2,
187 RTEMS_DEFAULT_MODES,
209 RTEMS_DEFAULT_MODES,
188 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
210 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
189 );
211 );
190 // AVF0
212 // AVF0
191 status = rtems_task_create(
213 status = rtems_task_create(
192 Task_name[TASKID_AVF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
214 Task_name[TASKID_AVF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
193 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
215 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
194 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
216 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
195 );
217 );
196 // BPF0
218 // BPF0
197 status = rtems_task_create(
219 status = rtems_task_create(
198 Task_name[TASKID_BPF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
220 Task_name[TASKID_BPF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
199 RTEMS_DEFAULT_MODES,
221 RTEMS_DEFAULT_MODES,
200 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_BPF0]
222 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_BPF0]
201 );
223 );
202 // WFRM
224 // WFRM
203 status = rtems_task_create(
225 status = rtems_task_create(
204 Task_name[TASKID_WFRM], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
226 Task_name[TASKID_WFRM], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
205 RTEMS_DEFAULT_MODES,
227 RTEMS_DEFAULT_MODES,
206 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
228 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
207 );
229 );
208 // DUMB
230 // DUMB
209 status = rtems_task_create(
231 status = rtems_task_create(
210 Task_name[TASKID_DUMB], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
232 Task_name[TASKID_DUMB], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
211 RTEMS_DEFAULT_MODES,
233 RTEMS_DEFAULT_MODES,
212 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
234 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
213 );
235 );
214 // HOUS
236 // HOUS
215 status = rtems_task_create(
237 status = rtems_task_create(
216 Task_name[TASKID_HOUS], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
238 Task_name[TASKID_HOUS], 199, RTEMS_MINIMUM_STACK_SIZE * 2,
217 RTEMS_DEFAULT_MODES,
239 RTEMS_DEFAULT_MODES,
218 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
240 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
219 );
241 );
220
242
221 return 0;
243 return 0;
222 }
244 }
223
245
224 int start_all_tasks()
246 int start_all_tasks()
225 {
247 {
226 rtems_status_code status;
248 rtems_status_code status;
227
249
228 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
250 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
229 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
251 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
230
252
231 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
253 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
232 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
254 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
233
255
234 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
256 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
235 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
257 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
236
258
237 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
259 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
238 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
260 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
239
261
240 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
262 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
241 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
263 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
242
264
243 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
265 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
244 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
266 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
245
267
246 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
268 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
247 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
269 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
248
270
249 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
271 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
250 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
272 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
251
273
252 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
274 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
253 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
275 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
254
276
255 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
277 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
256 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_HOUS\n")
278 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_HOUS\n")
257
279
258 return 0;
280 return 0;
259 }
281 }
260
282
261 int configure_spw_link()
283 int configure_spw_link()
262 {
284 {
263 rtems_status_code status;
285 rtems_status_code status;
264
286
265 close(fdSPW); // close the device if it is already open
287 close(fdSPW); // close the device if it is already open
288 PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
266 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
289 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
267 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
290 if (fdSPW<0) PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
268 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
291 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
269 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
292 PRINTF(".")
293 fflush(stdout);
270 close(fdSPW); // close the device
294 close(fdSPW); // close the device
271 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
295 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
272 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
296 if (fdSPW<0) PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
273 rtems_task_wake_after(100);
297 rtems_task_wake_after(100);
274 }
298 }
275
299
276 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
300 PRINTF("OK *** In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
277
278 // sets a few parameters of the link
279 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
280 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
281
301
282 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
302 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
283 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
303 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
284
304
285 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
305 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
286 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
287 //
307 //
288 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
308 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
289 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
290 //
310 //
291 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
311 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
292 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
312 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
293 //
313 //
294 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
314 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
295 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
315 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
296 //
316 //
297 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
317 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
298 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
318 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
299 //
300 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
301 PRINTF1("destination address set to: %d\n", CCSDS_DESTINATION_ID)
302 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DESTKEY\n")
303 //
304 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_NODEADDR, CCSDS_NODE_ADDRESS); // sets the node address
305 PRINTF1("node address set to: %d\n", CCSDS_NODE_ADDRESS)
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_NODEADDR\n")
307 //
319 //
308 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
320 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
321 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
310
322
311 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
323 PRINTF("OK *** in configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
312
324
313 return RTEMS_SUCCESSFUL;
325 return RTEMS_SUCCESSFUL;
314 }
326 }
315
327
316 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // No Port force
328 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // No Port force
317 {
329 {
318 unsigned int *spwptr;
330 unsigned int *spwptr;
319 spwptr = (unsigned int*) regAddr;
331 spwptr = (unsigned int*) regAddr;
320 if (val == 1)
332 if (val == 1)
321 {
333 {
322 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
334 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
323 }
335 }
324 if (val== 0)
336 if (val== 0)
325 {
337 {
326 *spwptr = *spwptr & 0xffdfffff;
338 *spwptr = *spwptr & 0xffdfffff;
327 }
339 }
328 }
340 }
329
341
330 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // RMAP Enable
342 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // RMAP Enable
331 {
343 {
332 unsigned int *spwptr;
344 unsigned int *spwptr;
333 spwptr = (unsigned int*) regAddr;
345 spwptr = (unsigned int*) regAddr;
334 if (val == 1)
346 if (val == 1)
335 {
347 {
336 *spwptr = *spwptr | 0x00010000; // [NP] set the No port force bit
348 *spwptr = *spwptr | 0x00010000; // [NP] set the No port force bit
337 }
349 }
338 if (val== 0)
350 if (val== 0)
339 {
351 {
340 *spwptr = *spwptr & 0xfffdffff;
352 *spwptr = *spwptr & 0xfffdffff;
341 }
353 }
342 }
354 }
343
355
344 char *link_status(int status){
356 char *link_status(int status){
345 return lstates[status];
357 return lstates[status];
346 }
358 }
347
359
348 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
360 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
349 {
361 {
350 rtems_status_code status;
362 rtems_status_code status;
351 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
363 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
352 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
364 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
353 return status;
365 return status;
354 }
366 }
355
367
356 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
368 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
357 {
369 {
358 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
370 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
359 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
371 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
360 }
372 }
361
373
@@ -1,138 +1,158
1 #include <fsw_misc.h>
1 #include <fsw_misc.h>
2 #include <fsw_params.h>
2 #include <fsw_params.h>
3
3
4 extern rtems_id Task_id[]; /* array of task ids */
4 extern rtems_id Task_id[]; /* array of task ids */
5 extern int fdSPW;
5 extern int fdSPW;
6 extern TMHeader_t housekeeping_header;
6 extern TMHeader_t housekeeping_header;
7 extern char housekeeping_data[];
7 extern char housekeeping_data[];
8 extern Packet_TM_LFR_HK_t housekeeping_packet;
8
9
9 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 { // configure the timer for the waveforms simulation
12 { // configure the timer for the waveforms simulation
12 rtems_status_code status;
13 rtems_status_code status;
13 rtems_isr_entry old_isr_handler;
14 rtems_isr_entry old_isr_handler;
14
15
15 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
16 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
16 //if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n")
17 //if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n")
17
18
18 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
19 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
19 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
20 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
20 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
21 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
21 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
22 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
22 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
23 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
23 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
24 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
24
25
25 return 1;
26 return 1;
26 }
27 }
27
28
28 void print_statistics(spw_stats *stats)
29 void print_statistics(spw_stats *stats)
29 {
30 {
30 //printf(" ******** STATISTICS ******** \n");
31 //printf(" ******** STATISTICS ******** \n");
31 printf("Transmit link errors: %i\n", stats->tx_link_err);
32 printf("Transmit link errors: %i\n", stats->tx_link_err);
32 printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err);
33 printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err);
33 printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err);
34 printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err);
34 printf("Receiver EEP errors: %i\n", stats->rx_eep_err);
35 printf("Receiver EEP errors: %i\n", stats->rx_eep_err);
35 printf("Receiver truncation errors: %i\n", stats->rx_truncated);
36 printf("Receiver truncation errors: %i\n", stats->rx_truncated);
36 printf("Parity errors: %i\n", stats->parity_err);
37 printf("Parity errors: %i\n", stats->parity_err);
37 printf("Escape errors: %i\n", stats->escape_err);
38 printf("Escape errors: %i\n", stats->escape_err);
38 printf("Credit errors: %i\n", stats->credit_err);
39 printf("Credit errors: %i\n", stats->credit_err);
39 printf("Disconnect errors: %i\n", stats->disconnect_err);
40 printf("Disconnect errors: %i\n", stats->disconnect_err);
40 printf("Write synchronization errors: %i\n", stats->write_sync_err);
41 printf("Write synchronization errors: %i\n", stats->write_sync_err);
41 printf("Early EOP/EEP: %i\n", stats->early_ep);
42 printf("Early EOP/EEP: %i\n", stats->early_ep);
42 printf("Invalid Node Address: %i\n", stats->invalid_address);
43 printf("Invalid Node Address: %i\n", stats->invalid_address);
43 printf("Packets transmitted: %i\n", stats->packets_sent);
44 printf("Packets transmitted: %i\n", stats->packets_sent);
44 printf("Packets received: %i\n", stats->packets_received);
45 printf("Packets received: %i\n", stats->packets_received);
45 }
46 }
46
47
47 int send_console_outputs_on_serial_port() // Send the console outputs on the serial port
48 int send_console_outputs_on_serial_port() // Send the console outputs on the serial port
48 {
49 {
49 struct apbuart_regs_str *apbuart_regs;
50 struct apbuart_regs_str *apbuart_regs;
50
51
51 apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
52 apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
52 apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
53 apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
53 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
54 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
54
55
55 return 0;
56 return 0;
56 }
57 }
57
58
59 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
60 {
61 struct apbuart_regs_str *apbuart_regs;
62
63 apbuart_regs = (struct apbuart_regs_str *) regs;
64 apbuart_regs->scaler = value;
65 PRINTF1("OK *** COM port scaler reload register set to %x\n", value)
66
67 return 0;
68 }
69
70 //************
71 // RTEMS TASKS
72
58 rtems_task stat_task(rtems_task_argument argument)
73 rtems_task stat_task(rtems_task_argument argument)
59 {
74 {
60 int i;
75 int i;
61 i = 0;
76 int j;
62 PRINTF("In STAT *** \n")
77 i = 0;
78 j = 0;
79 PRINTF("in STAT *** \n")
63 while(1){
80 while(1){
64 rtems_task_wake_after(1000);
81 rtems_task_wake_after(1000);
65 PRINTF1("%d\n", i)
82 PRINTF1("%d\n", j)
66 if (i == 2) {
83 if (i == 2) {
67 #ifdef PRINT_TASK_STATISTICS
84 #ifdef PRINT_TASK_STATISTICS
68 rtems_cpu_usage_report();
85 rtems_cpu_usage_report();
69 rtems_cpu_usage_reset();
86 rtems_cpu_usage_reset();
70 #endif
87 #endif
71 i = 0;
88 i = 0;
72 }
89 }
73 else i++;
90 else i++;
91 j++;
74 }
92 }
75 }
93 }
76
94
77 rtems_task hous_task(rtems_task_argument argument)
95 rtems_task hous_task(rtems_task_argument argument)
78 {
96 {
97 PRINTF("in HOUS ***\n")
98
99 int result;
79 rtems_status_code status;
100 rtems_status_code status;
80
101
81 spw_ioctl_pkt_send spw_ioctl_send;
102 if (rtems_rate_monotonic_ident( HK_name, &HK_id)!=RTEMS_SUCCESSFUL)
103 {
104 status = rtems_rate_monotonic_create( HK_name, &HK_id );
105 if( status != RTEMS_SUCCESSFUL )
106 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
107 }
108
109 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
110 housekeeping_packet.protocolIdentifier = 0x02;
111 housekeeping_packet.reserved = 0x00;
112 housekeeping_packet.userApplication = 0x00;
113 housekeeping_packet.packetID[0] = 0x0c;
114 housekeeping_packet.packetID[1] = 0xc4;
115 housekeeping_packet.packetSequenceControl[0] = 0xc0;
116 housekeeping_packet.packetSequenceControl[1] = 0x00;
117 housekeeping_packet.packetLength[0] = 0x00;
118 housekeeping_packet.packetLength[1] = 0x77;
119 housekeeping_packet.dataFieldHeader[0] = 0x10;
120 housekeeping_packet.dataFieldHeader[1] = 0x03;
121 housekeeping_packet.dataFieldHeader[2] = 0x19;
122 housekeeping_packet.dataFieldHeader[3] = 0x00;
123
124 status = rtems_rate_monotonic_cancel(HK_id);
125 if( status != RTEMS_SUCCESSFUL )
126 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
127 else
128 PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
82
129
83 rtems_name name;
130 while(1){ // launch the rate monotonic task
84 rtems_id period;
131 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
85 name = rtems_build_name( 'H', 'O', 'U', 'S' );
132 if ( status != RTEMS_SUCCESSFUL ){
86 status = rtems_rate_monotonic_create( name, &period );
133 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_period *** code %d\n", status);
87 if( status != RTEMS_SUCCESSFUL ) {
134 }
88 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
135 else
89 exit( 1 );
136 {
137 housekeeping_packet.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
138 housekeeping_packet.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
139 housekeeping_packet.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
140 housekeeping_packet.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
141 housekeeping_packet.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
142 housekeeping_packet.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
143 housekeeping_packet.data[0] = CCSDS_DESTINATION_ID_DPU;
144 result = write ( fdSPW, &housekeeping_packet, LEN_TM_LFR_HK);
145 if (result==-1)
146 {
147 PRINTF("ERR *** in HOUS *** HK send\n");
148 }
149 }
90 }
150 }
91
151
92 // filling the structure for the spacewire transmission
152 PRINTF("in HOUS *** deleting task\n")
93 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
94 spw_ioctl_send.hdr = (char*) &housekeeping_header;
95 spw_ioctl_send.dlen = LENGTH_TM_LFR_HK - 10 + 1;
96 spw_ioctl_send.data = housekeeping_data;
97
98 housekeeping_header.targetLogicalAddress = CCSDS_DESTINATION_ID;
99 housekeeping_header.protocolIdentifier = 0x02;
100 housekeeping_header.reserved = 0x00;
101 housekeeping_header.userApplication = 0x00;
102 housekeeping_header.packetID[0] = 0x0c;
103 housekeeping_header.packetID[1] = 0xc4;
104 housekeeping_header.packetSequenceControl[0] = 0xc0;
105 housekeeping_header.packetSequenceControl[1] = 0x00;
106 housekeeping_header.packetLength[0] = 0x00;
107 housekeeping_header.packetLength[1] = 0x77;
108 housekeeping_header.dataFieldHeader[0] = 0x10;
109 housekeeping_header.dataFieldHeader[1] = 0x03;
110 housekeeping_header.dataFieldHeader[2] = 0x19;
111 housekeeping_header.dataFieldHeader[3] = 0x00;
112
153
113 printf("In HOUS ***\n");
114
115 while(1){ // launch the rate monotonic task
116 if ( rtems_rate_monotonic_period( period, HK_PERIOD ) == RTEMS_TIMEOUT ){
117 printf( "ERR *** in hous_task *** RTEMS_TIMEOUT\n" );
118 break;
119 }
120 housekeeping_header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
121 housekeeping_header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
122 housekeeping_header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
123 housekeeping_header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
124 housekeeping_header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
125 housekeeping_header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
126 status = write_spw(&spw_ioctl_send);
127 }
128
129 status = rtems_rate_monotonic_delete( period );
130 if ( status != RTEMS_SUCCESSFUL ) {
131 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
132 exit( 1 );
133 }
134 status = rtems_task_delete( RTEMS_SELF ); // should not return
154 status = rtems_task_delete( RTEMS_SELF ); // should not return
135 printf( "rtems_task_delete returned with status of %d.\n", status );
155 printf( "rtems_task_delete returned with status of %d.\n", status );
136 exit( 1 );
156 exit( 1 );
137 }
157 }
138
158
@@ -1,447 +1,406
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <math.h>
2 #include <math.h>
3 #include <stdio.h>
3 #include <stdio.h>
4 #include <stdlib.h>
4 #include <stdlib.h>
5 #include <leon.h>
5 #include <leon.h>
6
6
7 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
7 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
8 // SX 12 coefficients
8 // SX 12 coefficients
9 float k14_sx_re = 1;
9 float k14_sx_re = 1;
10 float k14_sx_im = 1;
10 float k14_sx_im = 1;
11 float k15_sx_re = 1;
11 float k15_sx_re = 1;
12 float k15_sx_im = 1;
12 float k15_sx_im = 1;
13 float k24_sx_re = 1;
13 float k24_sx_re = 1;
14 float k24_sx_im = 1;
14 float k24_sx_im = 1;
15 float k25_sx_re = 1;
15 float k25_sx_re = 1;
16 float k25_sx_im = 1;
16 float k25_sx_im = 1;
17 float k34_sx_re = 1;
17 float k34_sx_re = 1;
18 float k34_sx_im = 1;
18 float k34_sx_im = 1;
19 float k35_sx_re = 1;
19 float k35_sx_re = 1;
20 float k35_sx_im = 1;
20 float k35_sx_im = 1;
21 // NY 8 coefficients
21 // NY 8 coefficients
22 float k24_ny_re = 1;
22 float k24_ny_re = 1;
23 float k24_ny_im = 1;
23 float k24_ny_im = 1;
24 float k25_ny_re = 1;
24 float k25_ny_re = 1;
25 float k25_ny_im = 1;
25 float k25_ny_im = 1;
26 float k34_ny_re = 1;
26 float k34_ny_re = 1;
27 float k34_ny_im = 1;
27 float k34_ny_im = 1;
28 float k35_ny_re = 1;
28 float k35_ny_re = 1;
29 float k35_ny_im = 1;
29 float k35_ny_im = 1;
30 // NZ 8 coefficients
30 // NZ 8 coefficients
31 float k24_nz_re = 1;
31 float k24_nz_re = 1;
32 float k24_nz_im = 1;
32 float k24_nz_im = 1;
33 float k25_nz_re = 1;
33 float k25_nz_re = 1;
34 float k25_nz_im = 1;
34 float k25_nz_im = 1;
35 float k34_nz_re = 1;
35 float k34_nz_re = 1;
36 float k34_nz_im = 1;
36 float k34_nz_im = 1;
37 float k35_nz_re = 1;
37 float k35_nz_re = 1;
38 float k35_nz_im = 1;
38 float k35_nz_im = 1;
39 // PE 4 coefficients
39 // PE 4 coefficients
40 float k44_pe = 1;
40 float k44_pe = 1;
41 float k55_pe = 1;
41 float k55_pe = 1;
42 float k45_pe_re = 1;
42 float k45_pe_re = 1;
43 float k45_pe_im = 1;
43 float k45_pe_im = 1;
44
44
45 float alpha_M = M_PI/4;
45 float alpha_M = M_PI/4;
46
46
47 extern volatile int spec_mat_f0_a[ ];
47 extern volatile int spec_mat_f0_a[ ];
48 extern volatile int spec_mat_f0_b[ ];
48 extern volatile int spec_mat_f0_b[ ];
49 extern volatile int spec_mat_f0_c[ ];
49 extern volatile int spec_mat_f0_c[ ];
50 extern volatile int spec_mat_f0_d[ ];
50 extern volatile int spec_mat_f0_d[ ];
51 extern volatile int spec_mat_f0_e[ ];
51 extern volatile int spec_mat_f0_e[ ];
52 extern volatile int spec_mat_f0_f[ ];
52 extern volatile int spec_mat_f0_f[ ];
53 extern volatile int spec_mat_f0_g[ ];
53 extern volatile int spec_mat_f0_g[ ];
54 extern volatile int spec_mat_f0_h[ ];
54 extern volatile int spec_mat_f0_h[ ];
55 extern float averaged_spec_mat_f0[ ];
55 extern float averaged_spec_mat_f0[ ];
56 extern float compressed_spec_mat_f0[ ];
56 extern float compressed_spec_mat_f0[ ];
57 extern unsigned char LFR_BP1_F0[ ];
57 extern unsigned char LFR_BP1_F0[ ];
58
58
59 extern BP1_t data_BP1[ ];
59 extern BP1_t data_BP1[ ];
60
60
61 extern rtems_id Task_id[ ]; /* array of task ids */
61 extern rtems_id Task_id[ ]; /* array of task ids */
62
62
63 spectral_matrices_regs_t *spectral_matrices_regs;
63 spectral_matrices_regs_t *spectral_matrices_regs;
64
64
65 //***********************************************************
65 // Interrupt Service Routine for spectral matrices processing
66 // Interrupt Service Routine for spectral matrices processing
66 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
67 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
67 {
68 {
68 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
69 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
69 printf("In spectral_matrices_isr *** Error sending event to AVF0\n");
70 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
70 }
71 }
71
72
73 //************
74 // RTEMS TASKS
72 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
75 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
73 {
76 {
74 rtems_event_set event_out;
77 rtems_event_set event_out;
75 gptimer_regs_t *gptimer_regs;
78 gptimer_regs_t *gptimer_regs;
76 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
79 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
77 unsigned char nb_interrupt_f0 = 0;
80 unsigned char nb_interrupt_f0 = 0;
78
81
79 PRINTF("In SMIQ *** \n")
82 PRINTF("in SMIQ *** \n")
80
83
81 while(1){
84 while(1){
82 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
85 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
83 nb_interrupt_f0 = nb_interrupt_f0 + 1;
86 nb_interrupt_f0 = nb_interrupt_f0 + 1;
84 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
87 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
85 if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
88 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
86 printf("In smiq_task *** Error sending event to AVF0\n");
89 printf("in SMIQ *** Error sending event to AVF0\n");
87 nb_interrupt_f0 = 0;
90 nb_interrupt_f0 = 0;
88 }
91 }
89 gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010;
90 }
92 }
91 }
93 }
92
94
93 rtems_task spw_bppr_task(rtems_task_argument argument)
95 rtems_task spw_bppr_task(rtems_task_argument argument)
94 {
96 {
95 rtems_status_code status;
97 rtems_status_code status;
96 rtems_event_set event_out;
98 rtems_event_set event_out;
97 static int nb_average_f0 = 0;
99 static int nb_average_f0 = 0;
98 //static int nb_average_f1 = 0;
100 //static int nb_average_f1 = 0;
99 //static int nb_average_f2 = 0;
101 //static int nb_average_f2 = 0;
100
102
101 while(1)
103 while(1)
102
104
103 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
105 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
104 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
106 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
105 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
107 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
106
108
107 printf("In BPPR ***\n");
109 printf("in BPPR ***\n");
108
110
109 while(1){ // wait for an event to begin with the processing
111 while(1){ // wait for an event to begin with the processing
110 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
112 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
111 if (status == RTEMS_SUCCESSFUL){
113 if (status == RTEMS_SUCCESSFUL){
112 if ((spectral_matrices_regs->ctrl & 0x00000001)==1){
114 if ((spectral_matrices_regs->ctrl & 0x00000001)==1){
113 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
115 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
114 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
116 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
115 //printf("f0_a\n");
117 //printf("f0_a\n");
116 nb_average_f0++;
118 nb_average_f0++;
117 }
119 }
118 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){
120 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){
119 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
121 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
120 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
122 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
121 //printf("f0_b\n");
123 //printf("f0_b\n");
122 nb_average_f0++;
124 nb_average_f0++;
123 }
125 }
124 if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){
126 if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){
125 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
127 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
126 //printf("f0 compressed\n");
128 //printf("f0 compressed\n");
127 nb_average_f0 = 0;
129 nb_average_f0 = 0;
128 matrix_reset(averaged_spec_mat_f0);
130 matrix_reset(averaged_spec_mat_f0);
129 }
131 }
130 }
132 }
131 }
133 }
132 }
134 }
133
135
136 rtems_task avf0_task(rtems_task_argument argument){
137 int i;
138 static int nb_average;
139 rtems_event_set event_out;
140 rtems_status_code status;
141
142 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
143 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
144 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
145
146 nb_average = 0;
147
148 PRINTF("in AVFO *** \n")
149
150 while(1){
151 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
152 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
153 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
154 + spec_mat_f0_b[i]
155 + spec_mat_f0_c[i]
156 + spec_mat_f0_d[i]
157 + spec_mat_f0_e[i]
158 + spec_mat_f0_f[i]
159 + spec_mat_f0_g[i]
160 + spec_mat_f0_h[i];
161 }
162 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
163 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
164 if (nb_average == NB_AVERAGE_NORMAL_f0) {
165 nb_average = 0;
166 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
167 if (status != RTEMS_SUCCESSFUL) printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
168 }
169 }
170 }
171
172 rtems_task bpf0_task(rtems_task_argument argument){
173 rtems_event_set event_out;
174
175 PRINTF("in BPFO *** \n")
176
177 while(1){
178 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
179 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
180 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
181 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
182 }
183 }
184
185 //*****************************
186 // Spectral matrices processing
134 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
187 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
135 {
188 {
136 int i;
189 int i;
137 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
190 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
138 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
191 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
139 + spec_mat_f0_b[i]
192 + spec_mat_f0_b[i]
140 + spec_mat_f0_c[i]
193 + spec_mat_f0_c[i]
141 + spec_mat_f0_d[i]
194 + spec_mat_f0_d[i]
142 + spec_mat_f0_e[i]
195 + spec_mat_f0_e[i]
143 + spec_mat_f0_f[i]
196 + spec_mat_f0_f[i]
144 + spec_mat_f0_g[i]
197 + spec_mat_f0_g[i]
145 + spec_mat_f0_h[i];
198 + spec_mat_f0_h[i];
146 }
199 }
147 }
200 }
148
201
149 void matrix_reset(float *averaged_spec_mat)
202 void matrix_reset(float *averaged_spec_mat)
150 {
203 {
151 int i;
204 int i;
152 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
205 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
153 averaged_spec_mat_f0[i] = 0;
206 averaged_spec_mat_f0[i] = 0;
154 }
207 }
155 }
208 }
156
209
157 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
210 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
158 {
211 {
159 int i, j;
212 int i, j;
160 switch (fChannel){
213 switch (fChannel){
161 case 0:
214 case 0:
162 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
215 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
163 j = 17 + i * 8;
216 j = 17 + i * 8;
164 compressed_spec_mat[i] = (averaged_spec_mat[j]
217 compressed_spec_mat[i] = (averaged_spec_mat[j]
165 + averaged_spec_mat[j+1]
218 + averaged_spec_mat[j+1]
166 + averaged_spec_mat[j+2]
219 + averaged_spec_mat[j+2]
167 + averaged_spec_mat[j+3]
220 + averaged_spec_mat[j+3]
168 + averaged_spec_mat[j+4]
221 + averaged_spec_mat[j+4]
169 + averaged_spec_mat[j+5]
222 + averaged_spec_mat[j+5]
170 + averaged_spec_mat[j+6]
223 + averaged_spec_mat[j+6]
171 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
224 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
172 }
225 }
173 break;
226 break;
174 case 1:
227 case 1:
175 // case fChannel = f1 tp be completed later
228 // case fChannel = f1 to be completed later
176 break;
229 break;
177 case 2:
230 case 2:
178 // case fChannel = f1 tp be completed later
231 // case fChannel = f1 to be completed later
179 break;
232 break;
180 default:
233 default:
181 break;
234 break;
182 }
235 }
183 }
236 }
184
237
185 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
238 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
186 int i, j;
239 int i, j;
187 unsigned char tmp_u_char;
240 unsigned char tmp_u_char;
188 unsigned char * pt_char;
241 unsigned char * pt_char;
189 float PSDB, PSDE;
242 float PSDB, PSDE;
190 float NVEC_V0, NVEC_V1, NVEC_V2;
243 float NVEC_V0, NVEC_V1, NVEC_V2;
191 //float significand;
244 //float significand;
192 //int exponent;
245 //int exponent;
193 float aux, tr_SB_SB, tmp;
246 float aux, tr_SB_SB, tmp;
194 float sx_re, sx_im;
247 float sx_re, sx_im;
195 float nebx_re = 0, nebx_im = 0;
248 float nebx_re = 0, nebx_im = 0;
196 float ny = 0, nz = 0;
249 float ny = 0, nz = 0;
197 float bx_bx_star = 0;
250 float bx_bx_star = 0;
198 for(i=0; i<nb_bins_compressed_spec_mat; i++){
251 for(i=0; i<nb_bins_compressed_spec_mat; i++){
199 //==============================================
252 //==============================================
200 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
253 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
201 PSDB = compressed_spec_mat[i*30] // S11
254 PSDB = compressed_spec_mat[i*30] // S11
202 + compressed_spec_mat[i*30+10] // S22
255 + compressed_spec_mat[i*30+10] // S22
203 + compressed_spec_mat[i*30+18]; // S33
256 + compressed_spec_mat[i*30+18]; // S33
204 //significand = frexp(PSDB, &exponent);
257 //significand = frexp(PSDB, &exponent);
205 pt_char = (unsigned char*) &PSDB;
258 pt_char = (unsigned char*) &PSDB;
206 LFR_BP1[i*9+2] = pt_char[0]; // bits 31 downto 24 of the float
259 LFR_BP1[i*9+2] = pt_char[0]; // bits 31 downto 24 of the float
207 LFR_BP1[i*9+3] = pt_char[1]; // bits 23 downto 16 of the float
260 LFR_BP1[i*9+3] = pt_char[1]; // bits 23 downto 16 of the float
208 //==============================================
261 //==============================================
209 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
262 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
210 PSDE = compressed_spec_mat[i*30+24] * k44_pe // S44
263 PSDE = compressed_spec_mat[i*30+24] * k44_pe // S44
211 + compressed_spec_mat[i*30+28] * k55_pe // S55
264 + compressed_spec_mat[i*30+28] * k55_pe // S55
212 + compressed_spec_mat[i*30+26] * k45_pe_re // S45
265 + compressed_spec_mat[i*30+26] * k45_pe_re // S45
213 - compressed_spec_mat[i*30+27] * k45_pe_im; // S45
266 - compressed_spec_mat[i*30+27] * k45_pe_im; // S45
214 pt_char = (unsigned char*) &PSDE;
267 pt_char = (unsigned char*) &PSDE;
215 LFR_BP1[i*9+0] = pt_char[0]; // bits 31 downto 24 of the float
268 LFR_BP1[i*9+0] = pt_char[0]; // bits 31 downto 24 of the float
216 LFR_BP1[i*9+1] = pt_char[1]; // bits 23 downto 16 of the float
269 LFR_BP1[i*9+1] = pt_char[1]; // bits 23 downto 16 of the float
217 //==============================================================================
270 //==============================================================================
218 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
271 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
219 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
272 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
220 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
273 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
221 tmp = sqrt(
274 tmp = sqrt(
222 compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12
275 compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12
223 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13
276 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13
224 +compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13] //Im S23
277 +compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13] //Im S23
225 );
278 );
226 NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23
279 NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23
227 NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13
280 NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13
228 NVEC_V2 = compressed_spec_mat[i*30+3] / tmp; // Im S12
281 NVEC_V2 = compressed_spec_mat[i*30+3] / tmp; // Im S12
229 LFR_BP1[i*9+4] = (char) (NVEC_V0*127);
282 LFR_BP1[i*9+4] = (char) (NVEC_V0*127);
230 LFR_BP1[i*9+5] = (char) (NVEC_V1*127);
283 LFR_BP1[i*9+5] = (char) (NVEC_V1*127);
231 pt_char = (unsigned char*) &NVEC_V2;
284 pt_char = (unsigned char*) &NVEC_V2;
232 LFR_BP1[i*9+6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
285 LFR_BP1[i*9+6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
233 //=======================================================
286 //=======================================================
234 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
287 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
235 aux = 2*tmp / PSDB; // compute the ellipticity
288 aux = 2*tmp / PSDB; // compute the ellipticity
236 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
289 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
237 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
290 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
238 //==============================================================
291 //==============================================================
239 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
292 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
240 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
293 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
241 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
294 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
242 + compressed_spec_mat[i*30+10] * compressed_spec_mat[i*30+10]
295 + compressed_spec_mat[i*30+10] * compressed_spec_mat[i*30+10]
243 + compressed_spec_mat[i*30+18] * compressed_spec_mat[i*30+18]
296 + compressed_spec_mat[i*30+18] * compressed_spec_mat[i*30+18]
244 + 2 * compressed_spec_mat[i*30+2] * compressed_spec_mat[i*30+2]
297 + 2 * compressed_spec_mat[i*30+2] * compressed_spec_mat[i*30+2]
245 + 2 * compressed_spec_mat[i*30+3] * compressed_spec_mat[i*30+3]
298 + 2 * compressed_spec_mat[i*30+3] * compressed_spec_mat[i*30+3]
246 + 2 * compressed_spec_mat[i*30+4] * compressed_spec_mat[i*30+4]
299 + 2 * compressed_spec_mat[i*30+4] * compressed_spec_mat[i*30+4]
247 + 2 * compressed_spec_mat[i*30+5] * compressed_spec_mat[i*30+5]
300 + 2 * compressed_spec_mat[i*30+5] * compressed_spec_mat[i*30+5]
248 + 2 * compressed_spec_mat[i*30+12] * compressed_spec_mat[i*30+12]
301 + 2 * compressed_spec_mat[i*30+12] * compressed_spec_mat[i*30+12]
249 + 2 * compressed_spec_mat[i*30+13] * compressed_spec_mat[i*30+13];
302 + 2 * compressed_spec_mat[i*30+13] * compressed_spec_mat[i*30+13];
250 }
303 }
251 aux = PSDB*PSDB;
304 aux = PSDB*PSDB;
252 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
305 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
253 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
306 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
254 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
307 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
255 //=======================================================================================
308 //=======================================================================================
256 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
309 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
257 sx_re = compressed_spec_mat[i*30+20] * k34_sx_re
310 sx_re = compressed_spec_mat[i*30+20] * k34_sx_re
258 + compressed_spec_mat[i*30+6] * k14_sx_re
311 + compressed_spec_mat[i*30+6] * k14_sx_re
259 + compressed_spec_mat[i*30+8] * k15_sx_re
312 + compressed_spec_mat[i*30+8] * k15_sx_re
260 + compressed_spec_mat[i*30+14] * k24_sx_re
313 + compressed_spec_mat[i*30+14] * k24_sx_re
261 + compressed_spec_mat[i*30+16] * k25_sx_re
314 + compressed_spec_mat[i*30+16] * k25_sx_re
262 + compressed_spec_mat[i*30+22] * k35_sx_re;
315 + compressed_spec_mat[i*30+22] * k35_sx_re;
263 sx_im = compressed_spec_mat[i*30+21] * k34_sx_im
316 sx_im = compressed_spec_mat[i*30+21] * k34_sx_im
264 + compressed_spec_mat[i*30+7] * k14_sx_im
317 + compressed_spec_mat[i*30+7] * k14_sx_im
265 + compressed_spec_mat[i*30+9] * k15_sx_im
318 + compressed_spec_mat[i*30+9] * k15_sx_im
266 + compressed_spec_mat[i*30+15] * k24_sx_im
319 + compressed_spec_mat[i*30+15] * k24_sx_im
267 + compressed_spec_mat[i*30+17] * k25_sx_im
320 + compressed_spec_mat[i*30+17] * k25_sx_im
268 + compressed_spec_mat[i*30+23] * k35_sx_im;
321 + compressed_spec_mat[i*30+23] * k35_sx_im;
269 LFR_BP1[i*9+7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
322 LFR_BP1[i*9+7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
270 if ( abs(sx_re) > abs(sx_im) )
323 if ( abs(sx_re) > abs(sx_im) )
271 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] | (0x80); // extract the sector of sx
324 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] | (0x80); // extract the sector of sx
272 else
325 else
273 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] & (0x7f); // extract the sector of sx
326 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] & (0x7f); // extract the sector of sx
274 //======================================================================
327 //======================================================================
275 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
328 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
276 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
329 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
277 nz = NVEC_V0;
330 nz = NVEC_V0;
278 bx_bx_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+10] // re S22
331 bx_bx_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+10] // re S22
279 + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+18] // re S33
332 + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+18] // re S33
280 - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+12]; // re S23
333 - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+12]; // re S23
281 nebx_re = ny * (compressed_spec_mat[i*30+14] * k24_ny_re
334 nebx_re = ny * (compressed_spec_mat[i*30+14] * k24_ny_re
282 +compressed_spec_mat[i*30+16] * k25_ny_re
335 +compressed_spec_mat[i*30+16] * k25_ny_re
283 +compressed_spec_mat[i*30+20] * k34_ny_re
336 +compressed_spec_mat[i*30+20] * k34_ny_re
284 +compressed_spec_mat[i*30+22] * k35_ny_re)
337 +compressed_spec_mat[i*30+22] * k35_ny_re)
285 + nz * (compressed_spec_mat[i*30+14] * k24_nz_re
338 + nz * (compressed_spec_mat[i*30+14] * k24_nz_re
286 +compressed_spec_mat[i*30+16] * k25_nz_re
339 +compressed_spec_mat[i*30+16] * k25_nz_re
287 +compressed_spec_mat[i*30+20] * k34_nz_re
340 +compressed_spec_mat[i*30+20] * k34_nz_re
288 +compressed_spec_mat[i*30+22] * k35_nz_re);
341 +compressed_spec_mat[i*30+22] * k35_nz_re);
289 nebx_im = ny * (compressed_spec_mat[i*30+15]*k24_ny_re
342 nebx_im = ny * (compressed_spec_mat[i*30+15]*k24_ny_re
290 +compressed_spec_mat[i*30+17] * k25_ny_re
343 +compressed_spec_mat[i*30+17] * k25_ny_re
291 +compressed_spec_mat[i*30+21] * k34_ny_re
344 +compressed_spec_mat[i*30+21] * k34_ny_re
292 +compressed_spec_mat[i*30+23] * k35_ny_re)
345 +compressed_spec_mat[i*30+23] * k35_ny_re)
293 + nz * (compressed_spec_mat[i*30+15] * k24_nz_im
346 + nz * (compressed_spec_mat[i*30+15] * k24_nz_im
294 +compressed_spec_mat[i*30+17] * k25_nz_im
347 +compressed_spec_mat[i*30+17] * k25_nz_im
295 +compressed_spec_mat[i*30+21] * k34_nz_im
348 +compressed_spec_mat[i*30+21] * k34_nz_im
296 +compressed_spec_mat[i*30+23] * k35_nz_im);
349 +compressed_spec_mat[i*30+23] * k35_nz_im);
297 tmp = nebx_re / bx_bx_star;
350 tmp = nebx_re / bx_bx_star;
298 LFR_BP1[i*9+8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
351 LFR_BP1[i*9+8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
299 if ( abs(nebx_re) > abs(nebx_im) )
352 if ( abs(nebx_re) > abs(nebx_im) )
300 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (0x80); // extract the sector of nebx
353 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (0x80); // extract the sector of nebx
301 else
354 else
302 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] & (0x7f); // extract the sector of nebx
355 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] & (0x7f); // extract the sector of nebx
303 }
356 }
304
357
305 }
358 }
306
359
307 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
360 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
308 // BP2 autocorrelation
361 // BP2 autocorrelation
309 int i, aux = 0;
362 int i, aux = 0;
310 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
363 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
311 // S12
364 // S12
312 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]);
365 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]);
313 compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux;
366 compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux;
314 compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux;
367 compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux;
315 // S13
368 // S13
316 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]);
369 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]);
317 compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux;
370 compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux;
318 compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux;
371 compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux;
319 // S23
372 // S23
320 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]);
373 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]);
321 compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux;
374 compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux;
322 compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux;
375 compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux;
323 // S45
376 // S45
324 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]);
377 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]);
325 compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux;
378 compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux;
326 compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux;
379 compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux;
327 // S14
380 // S14
328 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
381 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
329 compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux;
382 compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux;
330 compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux;
383 compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux;
331 // S15
384 // S15
332 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]);
385 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]);
333 compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux;
386 compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux;
334 compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux;
387 compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux;
335 // S24
388 // S24
336 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]);
389 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]);
337 compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux;
390 compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux;
338 compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux;
391 compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux;
339 // S25
392 // S25
340 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]);
393 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]);
341 compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux;
394 compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux;
342 compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux;
395 compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux;
343 // S34
396 // S34
344 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]);
397 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]);
345 compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux;
398 compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux;
346 compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux;
399 compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux;
347 // S35
400 // S35
348 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]);
401 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]);
349 compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux;
402 compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux;
350 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
403 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
351 }
404 }
352 }
405 }
353
354 rtems_task avf0_task(rtems_task_argument argument){
355 int i;
356 static int nb_average;
357 rtems_event_set event_out;
358 rtems_status_code status;
359
406
360 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
361 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
362 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
363
364 nb_average = 0;
365
366 PRINTF("In AVFO *** \n")
367
368 while(1){
369 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
370 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
371 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
372 + spec_mat_f0_b[i]
373 + spec_mat_f0_c[i]
374 + spec_mat_f0_d[i]
375 + spec_mat_f0_e[i]
376 + spec_mat_f0_f[i]
377 + spec_mat_f0_g[i]
378 + spec_mat_f0_h[i];
379 }
380 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
381 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
382 if (nb_average == NB_AVERAGE_NORMAL_f0) {
383 nb_average = 0;
384 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
385 if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
386 }
387 }
388 }
389
390 rtems_task bpf0_task(rtems_task_argument argument){
391 rtems_event_set event_out;
392
393 PRINTF("In BPFO *** \n")
394
395 while(1){
396 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
397 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
398 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
399 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
400 }
401 }
402
403 //*******
404 // UNUSED
405 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument)
406 {/*
407 rtems_status_code status;
408 //static int nb_average_f1 = 0;
409 //static int nb_average_f2 = 0;
410
411 rtems_name name;
412 rtems_id period;
413 name = rtems_build_name( 'P', 'E', 'R', 'D' );
414 status = rtems_rate_monotonic_create( name, &period );
415 if( status != RTEMS_SUCCESSFUL ) {
416 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
417 //exit( 1 );
418 }
419
420 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
421 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
422 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
423
424 printf("In BPPR BIS ***\n");
425
426 while(1){ // launch the rate monotonic task
427 if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){
428 printf("TIMEOUT\n");
429 //break;
430 }
431 status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0
432 if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status);
433 }
434
435 status = rtems_rate_monotonic_delete( period );
436 if ( status != RTEMS_SUCCESSFUL ) {
437 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
438 //exit( 1 );
439 }
440 status = rtems_task_delete( RTEMS_SELF ); // should not return
441 printf( "rtems_task_delete returned with status of %d.\n", status );
442 //exit( 1 );*/
443 }
444
445
446
447
@@ -1,531 +1,582
1 #include <tc_handler.h>
1 #include <tc_handler.h>
2 #include <fsw_params.h>
2 #include <fsw_params.h>
3
3
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
5 "WRONG_LEN_PACKET 1",
5 "WRONG_LEN_PACKET 1",
6 "INCOR_CHECKSUM 2",
6 "INCOR_CHECKSUM 2",
7 "ILL_TYPE 3",
7 "ILL_TYPE 3",
8 "ILL_SUBTYPE 4",
8 "ILL_SUBTYPE 4",
9 "WRONG_APP_DATA 5",
9 "WRONG_APP_DATA 5",
10 "WRONG_CMD_CODE 6",
10 "WRONG_CMD_CODE 6",
11 "CCSDS_TM_VALID 7"
11 "CCSDS_TM_VALID 7"
12 };
12 };
13
13
14 //**********************
14 //**********************
15 // GENERAL USE FUNCTIONS
15 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 {
17 {
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 }
19 }
20
20
21 void initLookUpTableForCRC()
21 void initLookUpTableForCRC()
22 {
22 {
23 unsigned int i, tmp;
23 unsigned int i, tmp;
24 for (i=0; i<256; i++)
24 for (i=0; i<256; i++)
25 {
25 {
26 tmp = 0;
26 tmp = 0;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
35 lookUpTableForCRC[i] = tmp;
35 lookUpTableForCRC[i] = tmp;
36 }
36 }
37 }
37 }
38
38
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
40 {
40 {
41 unsigned int Chk;
41 unsigned int Chk;
42 int j;
42 int j;
43 Chk = 0xffff; // reset the syndrom to all ones
43 Chk = 0xffff; // reset the syndrom to all ones
44 for (j=0; j<sizeOfData; j++) {
44 for (j=0; j<sizeOfData; j++) {
45 Chk = Crc_opt(data[j], Chk);
45 Chk = Crc_opt(data[j], Chk);
46 }
46 }
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 }
49 }
50
50
51
52 //*********************
51 //*********************
53 // ACCEPTANCE FUNCTIONS
52 // ACCEPTANCE FUNCTIONS
54 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
53 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
55 {
54 {
56 rtems_status_code status;
55 rtems_status_code status;
57 spw_ioctl_pkt_send spw_ioctl_send;
56 spw_ioctl_pkt_send spw_ioctl_send;
58 TMHeader_t TM_header;
57 TMHeader_t TM_header;
59 unsigned int code = 0;
58 unsigned int code = 0;
60 unsigned char computed_CRC[2];
59 unsigned char computed_CRC[2];
61 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
60 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
62
61
63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
62 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
64 code = acceptTM( TC, tc_len_recv ) ;
63 code = acceptTM( TC, tc_len_recv ) ;
65 if ( (code == 0) | (code == 1) | (code == 2)
64 if ( (code == 0) | (code == 1) | (code == 2)
66 | (code == 3) | (code == 4) | (code == 5) )
65 | (code == 3) | (code == 4) | (code == 5) )
67 { // generate TM_LFR_TC_EXE_CORRUPTED
66 { // generate TM_LFR_TC_EXE_CORRUPTED
68 // BUILD HEADER
67 // BUILD HEADER
69 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
68 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
70 // BUILD DATA
69 // BUILD DATA
71 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
70 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
72 // PREPARE TM SENDING
71 // PREPARE TM SENDING
73 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
72 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
74 spw_ioctl_send.hdr = (char*) &TM_header;
73 spw_ioctl_send.hdr = (char*) &TM_header;
75 spw_ioctl_send.dlen = 16;
74 spw_ioctl_send.dlen = 16;
76 spw_ioctl_send.data = data;
75 spw_ioctl_send.data = data;
77 // SEND PACKET
76 // SEND PACKET
78 write_spw(&spw_ioctl_send);
77 write_spw(&spw_ioctl_send);
79 }
78 }
80 else { // send valid TC to the action launcher
79 else { // send valid TC to the action launcher
81 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
80 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
82 return -1;
81 return -1;
83 }
82 }
84 return -1;
83 return -1;
85 }
84 }
86
85
87 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
86 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
88 {
87 {
89 unsigned char pid = 0;
88 unsigned char pid = 0;
90 unsigned char category = 0;
89 unsigned char category = 0;
91 unsigned int length = 0;
90 unsigned int length = 0;
92 unsigned char packetType = 0;
91 unsigned char packetType = 0;
93 unsigned char packetSubtype = 0;
92 unsigned char packetSubtype = 0;
94 unsigned char * CCSDSContent;
93 unsigned char * CCSDSContent;
95
94
96 // APID check *** APID on 2 bytes
95 // APID check *** APID on 2 bytes
97 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
96 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
98 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
97 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
99 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
98 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
100 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
99 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
101
100
102 // packet length check
101 // packet length check
103 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
102 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
104 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
103 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
105 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
104 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
106
105
107 packetType = TMPacket->dataFieldHeader[1];
106 packetType = TMPacket->dataFieldHeader[1];
108 packetSubtype = TMPacket->dataFieldHeader[2];
107 packetSubtype = TMPacket->dataFieldHeader[2];
109 // service type, subtype and packet length check
108 // service type, subtype and packet length check
110 if (packetType == 181){
109 if (packetType == 181){
111 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
110 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
112 case 3:
111 case 3:
113 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
112 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
114 break;
113 break;
115 case 20:
114 case 20:
116 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
115 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
117 break;
116 break;
118 case 21:
117 case 21:
119 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
118 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
120 break;
119 break;
121 case 24:
120 case 24:
122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
121 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
123 break;
122 break;
124 case 27:
123 case 27:
125 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
124 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
126 break;
125 break;
127 case 28:
126 case 28:
128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
127 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
129 break;
128 break;
130 case 30:
129 case 30:
131 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
130 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
132 break;
131 break;
133 case 40:
132 case 40:
134 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
133 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
135 break;
134 break;
136 case 50:
135 case 50:
137 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
136 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
138 break;
137 break;
139 case 60:
138 case 60:
140 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
139 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
141 break;
140 break;
142 case 61:
141 case 61:
143 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
142 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
144 break;
143 break;
145 default:
144 default:
146 return ILL_SUBTYPE;
145 return ILL_SUBTYPE;
147 break;
146 break;
148 }
147 }
149 }
148 }
150 else if (packetType == 9){
149 else if (packetType == 9){
151 if (packetSubtype!=129) return ILL_SUBTYPE;
150 if (packetSubtype!=129) return ILL_SUBTYPE;
152 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
151 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
153 }
152 }
154 else return ILL_TYPE;
153 else return ILL_TYPE;
155
154
156 // source ID check // Source ID not documented in the ICD
155 // source ID check // Source ID not documented in the ICD
157
156
158 // packet error control, CRC check
157 // packet error control, CRC check
159 CCSDSContent = (unsigned char*) TMPacket->packetID;
158 CCSDSContent = (unsigned char*) TMPacket->packetID;
160 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
159 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
161 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
160 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
162 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
161 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
163
162
164 return CCSDS_TM_VALID;
163 return CCSDS_TM_VALID;
165 }
164 }
166
165
167 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
166 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
168 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
167 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
169 {
168 {
170 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
169 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
171 TMHeader->protocolIdentifier = 0x02;
170 TMHeader->protocolIdentifier = 0x02;
172 TMHeader->reserved = 0x00;
171 TMHeader->reserved = 0x00;
173 TMHeader->userApplication = 0x00;
172 TMHeader->userApplication = 0x00;
174 TMHeader->packetID[0] = 0x0c;
173 TMHeader->packetID[0] = 0x0c;
175 TMHeader->packetSequenceControl[0] = 0xc0;
174 TMHeader->packetSequenceControl[0] = 0xc0;
176 TMHeader->packetSequenceControl[1] = 0x00;
175 TMHeader->packetSequenceControl[1] = 0x00;
177 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
176 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
178 TMHeader->packetLength[1] = (unsigned char) packetLength;
177 TMHeader->packetLength[1] = (unsigned char) packetLength;
179 TMHeader->dataFieldHeader[0] = 0x10;
178 TMHeader->dataFieldHeader[0] = 0x10;
180 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
179 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
181 switch (tm_type){
180 switch (tm_type){
182 case(TM_LFR_TC_EXE_OK):
181 case(TM_LFR_TC_EXE_OK):
183 TMHeader->packetID[1] = 0xc1;
182 TMHeader->packetID[1] = 0xc1;
184 TMHeader->dataFieldHeader[1] = 1; // type
183 TMHeader->dataFieldHeader[1] = 1; // type
185 TMHeader->dataFieldHeader[2] = 7; // subtype
184 TMHeader->dataFieldHeader[2] = 7; // subtype
186 break;
185 break;
187 case(TM_LFR_TC_EXE_ERR):
186 case(TM_LFR_TC_EXE_ERR):
188 TMHeader->packetID[1] = 0xc1;
187 TMHeader->packetID[1] = 0xc1;
189 TMHeader->dataFieldHeader[1] = 1; // type
188 TMHeader->dataFieldHeader[1] = 1; // type
190 TMHeader->dataFieldHeader[2] = 8; // subtype
189 TMHeader->dataFieldHeader[2] = 8; // subtype
191 break;
190 break;
192 case(TM_LFR_HK):
191 case(TM_LFR_HK):
193 TMHeader->packetID[1] = 0xc4;
192 TMHeader->packetID[1] = 0xc4;
194 TMHeader->dataFieldHeader[1] = 3; // type
193 TMHeader->dataFieldHeader[1] = 3; // type
195 TMHeader->dataFieldHeader[2] = 25; // subtype
194 TMHeader->dataFieldHeader[2] = 25; // subtype
196 break;
195 break;
197 case(TM_LFR_SCI):
196 case(TM_LFR_SCI):
198 TMHeader->packetID[1] = 0xcc;
197 TMHeader->packetID[1] = 0xcc;
199 TMHeader->dataFieldHeader[1] = 21; // type
198 TMHeader->dataFieldHeader[1] = 21; // type
200 TMHeader->dataFieldHeader[2] = 3; // subtype
199 TMHeader->dataFieldHeader[2] = 3; // subtype
201 break;
200 break;
202 case(TM_LFR_SCI_SBM):
201 case(TM_LFR_SCI_SBM):
203 TMHeader->packetID[1] = 0xfc;
202 TMHeader->packetID[1] = 0xfc;
204 TMHeader->dataFieldHeader[1] = 21; // type
203 TMHeader->dataFieldHeader[1] = 21; // type
205 TMHeader->dataFieldHeader[2] = 3; // subtype
204 TMHeader->dataFieldHeader[2] = 3; // subtype
206 break;
205 break;
207 case(TM_LFR_PAR_DUMP):
206 case(TM_LFR_PAR_DUMP):
208 TMHeader->packetID[1] = 0xc9;
207 TMHeader->packetID[1] = 0xc9;
209 TMHeader->dataFieldHeader[1] = 181; // type
208 TMHeader->dataFieldHeader[1] = 181; // type
210 TMHeader->dataFieldHeader[2] = 31; // subtype
209 TMHeader->dataFieldHeader[2] = 31; // subtype
211 break;
210 break;
212 default:
211 default:
213 return 0;
212 return 0;
214 }
213 }
215 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
214 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
216 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
215 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
217 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
216 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
218 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
217 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
219 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
218 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
220 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
219 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
221 return 1;
220 return 1;
222 }
221 }
223
222
223 unsigned char TM_build_header_bis( enum TM_TYPE tm_type, unsigned int packetLength,
224 unsigned int coarseTime, unsigned int fineTime, Packet_TM_LFR_TC_EXE_t *packet)
225 {
226
227 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
228 packet->protocolIdentifier = 0x02;
229 packet->reserved = 0x00;
230 packet->userApplication = 0x00;
231 packet->packetID[0] = 0x0c;
232 packet->packetSequenceControl[0] = 0xc0;
233 packet->packetSequenceControl[1] = 0x00;
234 packet->packetLength[0] = (unsigned char) (packetLength>>8);
235 packet->packetLength[1] = (unsigned char) packetLength;
236 packet->dataFieldHeader[0] = 0x10;
237 packet->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
238 switch (tm_type){
239 case(TM_LFR_TC_EXE_OK):
240 packet->packetID[1] = 0xc1;
241 packet->dataFieldHeader[1] = 1; // type
242 packet->dataFieldHeader[2] = 7; // subtype
243 break;
244 case(TM_LFR_TC_EXE_ERR):
245 packet->packetID[1] = 0xc1;
246 packet->dataFieldHeader[1] = 1; // type
247 packet->dataFieldHeader[2] = 8; // subtype
248 break;
249 case(TM_LFR_HK):
250 packet->packetID[1] = 0xc4;
251 packet->dataFieldHeader[1] = 3; // type
252 packet->dataFieldHeader[2] = 25; // subtype
253 break;
254 case(TM_LFR_SCI):
255 packet->packetID[1] = 0xcc;
256 packet->dataFieldHeader[1] = 21; // type
257 packet->dataFieldHeader[2] = 3; // subtype
258 break;
259 case(TM_LFR_SCI_SBM):
260 packet->packetID[1] = 0xfc;
261 packet->dataFieldHeader[1] = 21; // type
262 packet->dataFieldHeader[2] = 3; // subtype
263 break;
264 case(TM_LFR_PAR_DUMP):
265 packet->packetID[1] = 0xc9;
266 packet->dataFieldHeader[1] = 181; // type
267 packet->dataFieldHeader[2] = 31; // subtype
268 break;
269 default:
270 return 0;
271 }
272 packet->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
273 packet->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
274 packet->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
275 packet->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
276 packet->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
277 packet->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
278 return 1;
279 }
280
224 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
281 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
225 {
282 {
226 unsigned int packetLength;
283 unsigned int packetLength;
227 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
284 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
228 switch (SID){
285 switch (SID){
229 case (SID_NOT_EXE):
286 case (SID_NOT_EXE):
230 break;
287 break;
231 case (SID_NOT_IMP):
288 case (SID_NOT_IMP):
232 data[0] = 0x9c;
289 data[0] = 0x9c;
233 data[1] = 0x42;
290 data[1] = 0x42;
234 data[2] = TC->packetID[0];
291 data[2] = TC->packetID[0];
235 data[3] = TC->packetID[1];
292 data[3] = TC->packetID[1];
236 data[4] = TC->packetSequenceControl[0];
293 data[4] = TC->packetSequenceControl[0];
237 data[5] = TC->packetSequenceControl[1];
294 data[5] = TC->packetSequenceControl[1];
238 data[6] = TC->dataFieldHeader[1]; // type
295 data[6] = TC->dataFieldHeader[1]; // type
239 data[7] = TC->dataFieldHeader[2]; // subtype
296 data[7] = TC->dataFieldHeader[2]; // subtype
240 break;
297 break;
241 case (SID_EXE_ERR):
298 case (SID_EXE_ERR):
242 break;
299 break;
243 case (SID_EXE_CORR):
300 case (SID_EXE_CORR):
244 data[0] = 0x9c;
301 data[0] = 0x9c;
245 data[1] = 0x45;
302 data[1] = 0x45;
246 data[2] = TC->packetID[0];
303 data[2] = TC->packetID[0];
247 data[3] = TC->packetID[1];
304 data[3] = TC->packetID[1];
248 data[4] = TC->packetSequenceControl[0];
305 data[4] = TC->packetSequenceControl[0];
249 data[5] = TC->packetSequenceControl[1];
306 data[5] = TC->packetSequenceControl[1];
250 data[6] = TC->dataFieldHeader[1]; // type
307 data[6] = TC->dataFieldHeader[1]; // type
251 data[7] = TC->dataFieldHeader[2]; // subtype
308 data[7] = TC->dataFieldHeader[2]; // subtype
252 data[8] = currentTC_LEN_RCV[0];
309 data[8] = currentTC_LEN_RCV[0];
253 data[9] = currentTC_LEN_RCV[1];
310 data[9] = currentTC_LEN_RCV[1];
254 data[10] = TC->packetLength[0];
311 data[10] = TC->packetLength[0];
255 data[11] = TC->packetLength[1];
312 data[11] = TC->packetLength[1];
256 data[12] = TC->dataAndCRC[packetLength];
313 data[12] = TC->dataAndCRC[packetLength];
257 data[13] = TC->dataAndCRC[packetLength+1];
314 data[13] = TC->dataAndCRC[packetLength+1];
258 data[14] = computed_CRC[0];
315 data[14] = computed_CRC[0];
259 data[15] = computed_CRC[1];
316 data[15] = computed_CRC[1];
260 break;
317 break;
261 default:
318 default:
262 return 0;
319 return 0;
263 }
320 }
264 return 1;
321 return 1;
265 }
322 }
266
323
324 int create_message_queue()
325 {
326 rtems_status_code status;
327 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
328 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
329 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
330 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
331
332 return 0;
333 }
334
267 //***********
335 //***********
268 // RTEMS TASK
336 // RTEMS TASK
269 rtems_task recv_task( rtems_task_argument unused )
337 rtems_task recv_task( rtems_task_argument unused )
270 {
338 {
271 int len = 0;
339 int len = 0;
272 unsigned int i = 0;
340 unsigned int i = 0;
273 unsigned int data_length = 0;
341 unsigned int data_length = 0;
274 ccsdsTelecommandPacket_t currentTC;
342 ccsdsTelecommandPacket_t currentTC;
275 char data[100];
343 char data[100];
276
344
277 for(i=0; i<100; i++) data[i] = 0;
345 for(i=0; i<100; i++) data[i] = 0;
278
346
279 PRINTF("In RECV *** \n")
347 PRINTF("in RECV *** \n")
280
348
281 while(1)
349 while(1)
282 {
350 {
283 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
351 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
284 if (len == -1){ // error during the read call
352 if (len == -1){ // error during the read call
285 PRINTF("In RECV *** last read call returned -1\n")
353 PRINTF("In RECV *** last read call returned -1\n")
286 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
354 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
287 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
355 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
288 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
356 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
289 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
357 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
290 }
358 }
291 else {
359 else {
292 PRINTF1("Got pck of length %d\n", len+1)
360 PRINTF1("Got pck of length %d\n", len+1)
293 currentTC_LEN_RCV[0] = 0x00;
361 currentTC_LEN_RCV[0] = 0x00;
294 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
362 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
295 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
363 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
296 // CHECK THE TC AND BUILD THE APPROPRIATE TM
364 // CHECK THE TC AND BUILD THE APPROPRIATE TM
297 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
365 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
298 if (data_length!=-1)
366 if (data_length!=-1)
299 {
367 {
300 }
368 }
301 }
369 }
302 }
370 }
303 }
371 }
304
372
305 rtems_task actn_task( rtems_task_argument unused )
373 rtems_task actn_task( rtems_task_argument unused )
306 {
374 {
307 int result = 0;
375 int result = 0;
308 rtems_status_code status; // RTEMS status code
376 rtems_status_code status; // RTEMS status code
309 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
377 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
310 size_t size; // size of the incoming TC packet
378 size_t size; // size of the incoming TC packet
311 unsigned char subtype = 0; // subtype of the current TC packet
379 unsigned char subtype = 0; // subtype of the current TC packet
312
380
313 PRINTF("In ACTN *** \n")
381 PRINTF("in ACTN *** \n")
314
382
315 while(1)
383 while(1)
316 {
384 {
317 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
385 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
318 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
386 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
319 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
387 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
320 else
388 else
321 {
389 {
322 subtype = TC.dataFieldHeader[2];
390 subtype = TC.dataFieldHeader[2];
323 switch(subtype)
391 switch(subtype)
324 {
392 {
325 case TC_SUBTYPE_RESET:
393 case TC_SUBTYPE_RESET:
326 result = action_default( &TC );
394 result = action_default( &TC );
327 break;
395 break;
328 //
396 //
329 case TC_SUBTYPE_LOAD_COMM:
397 case TC_SUBTYPE_LOAD_COMM:
330 result = action_default( &TC );
398 result = action_default( &TC );
331 break;
399 break;
332 //
400 //
333 case TC_SUBTYPE_LOAD_NORM:
401 case TC_SUBTYPE_LOAD_NORM:
334 result = action_load_norm( &TC );
402 result = action_load_norm( &TC );
335 send_tm_lfr_tc_exe_success( &TC );
403 send_tm_lfr_tc_exe_success( &TC );
336 break;
404 break;
337 //
405 //
338 case TC_SUBTYPE_LOAD_BURST:
406 case TC_SUBTYPE_LOAD_BURST:
339 result = action_default( &TC );
407 result = action_default( &TC );
340 break;
408 break;
341 //
409 //
342 case TC_SUBTYPE_LOAD_SBM1:
410 case TC_SUBTYPE_LOAD_SBM1:
343 result = action_default( &TC );
411 result = action_default( &TC );
344 break;
412 break;
345 //
413 //
346 case TC_SUBTYPE_LOAD_SBM2:
414 case TC_SUBTYPE_LOAD_SBM2:
347 result = action_default( &TC );
415 result = action_default( &TC );
348 break;
416 break;
349 //
417 //
350 case TC_SUBTYPE_DUMP:
418 case TC_SUBTYPE_DUMP:
351 result = action_default( &TC );
419 result = action_default( &TC );
352 break;
420 break;
353 //
421 //
354 case TC_SUBTYPE_ENTER:
422 case TC_SUBTYPE_ENTER:
355 result = action_enter( &TC );
423 result = action_enter( &TC );
356 send_tm_lfr_tc_exe_success( &TC );
424 send_tm_lfr_tc_exe_success( &TC );
357 break;
425 break;
358 //
426 //
359 case TC_SUBTYPE_UPDT_INFO:
427 case TC_SUBTYPE_UPDT_INFO:
360 result = action_default( &TC );
428 result = action_default( &TC );
361 break;
429 break;
362 //
430 //
363 case TC_SUBTYPE_EN_CAL:
431 case TC_SUBTYPE_EN_CAL:
364 result = action_default( &TC );
432 result = action_default( &TC );
365 break;
433 break;
366 //
434 //
367 case TC_SUBTYPE_DIS_CAL:
435 case TC_SUBTYPE_DIS_CAL:
368 result = action_default( &TC );
436 result = action_default( &TC );
369 break;
437 break;
370 //
438 //
371 case TC_SUBTYPE_UPDT_TIME:
439 case TC_SUBTYPE_UPDT_TIME:
372 result = action_updt_time( &TC );
440 result = action_updt_time( &TC );
373 send_tm_lfr_tc_exe_success( &TC );
441 send_tm_lfr_tc_exe_success( &TC );
374 break;
442 break;
375 //
443 //
376 default:
444 default:
377 break;
445 break;
378 }
446 }
379 }
447 }
380 }
448 }
381 }
449 }
382
450
383 int create_message_queue()
451 rtems_task dumb_task( rtems_task_argument unused )
384 {
452 {
385 rtems_status_code status;
453 unsigned int coarse_time;
386 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
454 unsigned int fine_time;
387 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
455 rtems_event_set event_out;
388 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
456
389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
457 PRINTF("in DUMB *** \n")
390
458
391 return 0;
459 while(1){
460 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
461 coarse_time = time_management_regs->coarse_time;
462 fine_time = time_management_regs->fine_time;
463 printf("in DUMB *** coarse time = %x, fine time = %x\n", coarse_time, fine_time);
464 }
392 }
465 }
393
466
394 //***********
467 //***********
395 // TC ACTIONS
468 // TC ACTIONS
396
469
397 int action_default(ccsdsTelecommandPacket_t *TC)
470 int action_default(ccsdsTelecommandPacket_t *TC)
398 {
471 {
399 TMHeader_t TM_header;
472 Packet_TM_LFR_TC_EXE_t packet;
400 char data[8];
401 spw_ioctl_pkt_send spw_ioctl_send;
402
473
403 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
474 TM_build_header_bis( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
404 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
475 time_management_regs->coarse_time, time_management_regs->fine_time, &packet);
405
476
406 data[0] = 0x9c;
477 packet.data[0] = 0x9c;
407 data[1] = 0x42;
478 packet.data[1] = 0x42;
408 data[2] = TC->packetID[0];
479 packet.data[2] = TC->packetID[0];
409 data[3] = TC->packetID[1];
480 packet.data[3] = TC->packetID[1];
410 data[4] = TC->packetSequenceControl[0];
481 packet.data[4] = TC->packetSequenceControl[0];
411 data[5] = TC->packetSequenceControl[1];
482 packet.data[5] = TC->packetSequenceControl[1];
412 data[6] = TC->dataFieldHeader[1]; // type
483 packet.data[6] = TC->dataFieldHeader[1]; // type
413 data[7] = TC->dataFieldHeader[2]; // subtype
484 packet.data[7] = TC->dataFieldHeader[2]; // subtype
414
415 // filling the structure for the spacewire transmission
416 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
417 spw_ioctl_send.hdr = (char*) &TM_header;
418 spw_ioctl_send.dlen = 8;
419 spw_ioctl_send.data = data;
420
485
421 // SEND DATA
486 // SEND DATA
422 write_spw(&spw_ioctl_send);
487 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1)
488 PRINTF("ERR *** in action_default *** send TM packet\n");
423
489
424 return 0;
490 return 0;
425 }
491 }
426
492
427 int action_enter(ccsdsTelecommandPacket_t *TC)
493 int action_enter(ccsdsTelecommandPacket_t *TC)
428 {
494 {
429 unsigned char lfr_mode = TC->dataAndCRC[1];
495 unsigned char lfr_mode = TC->dataAndCRC[1];
430 printf("enter mode %d\n", lfr_mode);
496 printf("enter mode %d\n", lfr_mode);
431 switch(lfr_mode)
497 switch(lfr_mode)
432 {
498 {
433 case(LFR_MODE_STANDBY):
499 case(LFR_MODE_STANDBY):
434 LEON_Mask_interrupt( IRQ_WF );
500 LEON_Mask_interrupt( IRQ_WF );
435 LEON_Mask_interrupt( IRQ_SM );
501 LEON_Mask_interrupt( IRQ_SM );
436 break;
502 break;
437 case(LFR_MODE_NORMAL):
503 case(LFR_MODE_NORMAL):
438 LEON_Unmask_interrupt( IRQ_WF );
504 LEON_Unmask_interrupt( IRQ_WF );
439 LEON_Unmask_interrupt( IRQ_SM );
505 LEON_Unmask_interrupt( IRQ_SM );
440 break;
506 break;
441 case(LFR_MODE_BURST):
507 case(LFR_MODE_BURST):
442 break;
508 break;
443 case(LFR_MODE_SBM1):
509 case(LFR_MODE_SBM1):
444 break;
510 break;
445 case(LFR_MODE_SBM2):
511 case(LFR_MODE_SBM2):
446 break;
512 break;
447 }
513 }
448 return 0;
514 return 0;
449 }
515 }
450
516
451 int action_load_norm(ccsdsTelecommandPacket_t *TC)
517 int action_load_norm(ccsdsTelecommandPacket_t *TC)
452 {
518 {
453 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
519 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
454 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
520 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
455 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
521 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
456 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
522 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
457 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
523 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
458 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
524 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
459 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
525 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
460 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
526 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
461 return 0;
527 return 0;
462 }
528 }
463
529
464 int action_updt_time(ccsdsTelecommandPacket_t *TC)
530 int action_updt_time(ccsdsTelecommandPacket_t *TC)
465 {
531 {
466 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
532 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
467 + (TC->dataAndCRC[1] << 16)
533 + (TC->dataAndCRC[1] << 16)
468 + (TC->dataAndCRC[2] << 8)
534 + (TC->dataAndCRC[2] << 8)
469 + TC->dataAndCRC[3];
535 + TC->dataAndCRC[3];
470 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
536 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
471 return 0;
537 return 0;
472 }
538 }
473
539
474 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
540 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
475 {
541 {
476 TMHeader_t TM_header;
542 TMHeader_t TM_header;
477 char data[4];
543 char data[4];
478 spw_ioctl_pkt_send spw_ioctl_send;
544 spw_ioctl_pkt_send spw_ioctl_send;
479
545
480 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
546 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
481 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
547 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
482
548
483 data[0] = TC->packetID[0];
549 data[0] = TC->packetID[0];
484 data[1] = TC->packetID[1];
550 data[1] = TC->packetID[1];
485 data[2] = TC->packetSequenceControl[0];
551 data[2] = TC->packetSequenceControl[0];
486 data[3] = TC->packetSequenceControl[1];
552 data[3] = TC->packetSequenceControl[1];
487
553
488 // filling the structure for the spacewire transmission
554 // filling the structure for the spacewire transmission
489 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
555 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
490 spw_ioctl_send.hdr = (char*) &TM_header;
556 spw_ioctl_send.hdr = (char*) &TM_header;
491 spw_ioctl_send.dlen = 3;
557 spw_ioctl_send.dlen = 3;
492 spw_ioctl_send.data = data;
558 spw_ioctl_send.data = data;
493
559
494 // SEND DATA
560 // SEND DATA
495 write_spw(&spw_ioctl_send);
561 write_spw(&spw_ioctl_send);
496
562
497 return 0;
563 return 0;
498 }
564 }
499
565
500 //***************************
566 //***************************
501 // Interrupt Service Routines
567 // Interrupt Service Routines
502 rtems_isr commutation_isr1( rtems_vector_number vector )
568 rtems_isr commutation_isr1( rtems_vector_number vector )
503 {
569 {
504 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
570 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
505 printf("In commutation_isr1 *** Error sending event to DUMB\n");
571 printf("In commutation_isr1 *** Error sending event to DUMB\n");
506 }
572 }
507
573
508 rtems_isr commutation_isr2( rtems_vector_number vector )
574 rtems_isr commutation_isr2( rtems_vector_number vector )
509 {
575 {
510 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
576 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
511 printf("In commutation_isr2 *** Error sending event to DUMB\n");
577 printf("In commutation_isr2 *** Error sending event to DUMB\n");
512 }
578 }
513
579
514 rtems_task dumb_task( rtems_task_argument unused )
515 {
516 unsigned int coarse_time;
517 unsigned int fine_time;
518 rtems_event_set event_out;
519
520 PRINTF("In DUMB *** \n")
521
522 while(1){
523 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
524 coarse_time = time_management_regs->coarse_time;
525 fine_time = time_management_regs->fine_time;
526 printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time);
527 }
528 }
529
580
530
581
531
582
@@ -1,115 +1,176
1 #include <wf_handler.h>
1 #include <wf_handler.h>
2
2
3 rtems_isr waveforms_isr( rtems_vector_number vector )
3 rtems_isr waveforms_isr( rtems_vector_number vector )
4 {
4 {
5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
6 printf("In waveforms_isr *** Error sending event to WFRM\n");
6 printf("In waveforms_isr *** Error sending event to WFRM\n");
7 }
7 }
8
8
9 rtems_task wfrm_task(rtems_task_argument argument)
9 rtems_task wfrm_task(rtems_task_argument argument)
10 {
10 {
11 unsigned int length;
11 unsigned int length;
12 unsigned int i = 0;
12 unsigned int i = 0;
13 spw_ioctl_pkt_send spw_ioctl_send;
13 spw_ioctl_pkt_send spw_ioctl_send;
14 rtems_event_set event_out;
14 rtems_event_set event_out;
15 gptimer_regs_t *gptimer_regs;
15 gptimer_regs_t *gptimer_regs;
16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
17 ExtendedTMHeader_t header;
17 ExtendedTMHeader_t header;
18
18
19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
21 header.reserved = 0x00;
21 header.reserved = 0x00;
22 header.userApplication = CCSDS_USER_APP;
22 header.userApplication = CCSDS_USER_APP;
23 header.packetID[0] = 0x0c;
23 header.packetID[0] = 0x0c;
24 header.packetID[1] = 0xcc;
24 header.packetID[1] = 0xcc;
25 header.packetSequenceControl[0] = 0x00;
25 header.packetSequenceControl[0] = 0x00;
26 header.packetSequenceControl[1] = 0x00;
26 header.packetSequenceControl[1] = 0x00;
27 header.packetLength[0] = 0x00;
27 header.packetLength[0] = 0x00;
28 header.packetLength[1] = 0x00;
28 header.packetLength[1] = 0x00;
29 header.dataFieldHeader[0] = 0x10;
29 header.dataFieldHeader[0] = 0x10;
30 header.dataFieldHeader[1] = 0x15; // service type
30 header.dataFieldHeader[1] = 0x15; // service type
31 header.dataFieldHeader[2] = 0x03; // service subtype
31 header.dataFieldHeader[2] = 0x03; // service subtype
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
33
33
34 header.auxiliaryHeader[0] = 0x00;
34 header.auxiliaryHeader[0] = 0x00;
35 header.auxiliaryHeader[1] = 0x1f;
35 header.auxiliaryHeader[1] = 0x1f;
36 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
36 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
37 header.auxiliaryHeader[3] = 0x00; // PKT_NR
37 header.auxiliaryHeader[3] = 0x00; // PKT_NR
38 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
38 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
39 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
39 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
40
40
41 // BUILD THE PACKET HEADER
41 // BUILD THE PACKET HEADER
42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
43 spw_ioctl_send.hdr = (char*) &header;
43 spw_ioctl_send.hdr = (char*) &header;
44
44
45 PRINTF("In WFRM *** \n")
45 PRINTF("in WFRM *** \n")
46
46
47 while(1){
47 while(1){
48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
55 for (i=0; i<7; i++) // send F0
55 for (i=0; i<7; i++) // send F0
56 {
56 {
57 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
57 // BUILD THE DATA
58 // BUILD THE DATA
58 if (i==6) {
59 if (i==6) {
59 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
60 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
60 length = TM_LEN_SCI_NORM_SWF_340;
61 length = TM_LEN_SCI_NORM_SWF_8;
61 }
62 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
63 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
64 }
62 else {
65 else {
63 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
66 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
64 length = TM_LEN_SCI_NORM_SWF_8;
67 length = TM_LEN_SCI_NORM_SWF_340;
68 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
69 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
65 }
70 }
66 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
71 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
67 // BUILD THE HEADER
72 // BUILD THE HEADER
68 header.packetLength[0] = (unsigned char) (length>>8);
73 header.packetLength[0] = (unsigned char) (length>>8);
69 header.packetLength[1] = (unsigned char) (length);
74 header.packetLength[1] = (unsigned char) (length);
70 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
75 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
71 // SEND PACKET
76 // SEND PACKET
72 write_spw(&spw_ioctl_send);
77 write_spw(&spw_ioctl_send);
73 }
78 }
74 for (i=0; i<7; i++) // send F1
79 for (i=0; i<7; i++) // send F1
75 {
80 {
81 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
76 // BUILD THE DATA
82 // BUILD THE DATA
77 if (i==6) {
83 if (i==6) {
78 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
84 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
79 length = TM_LEN_SCI_NORM_SWF_340;
85 length = TM_LEN_SCI_NORM_SWF_8;
80 }
86 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
87 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
88 }
81 else {
89 else {
82 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
90 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
83 length = TM_LEN_SCI_NORM_SWF_8;
91 length = TM_LEN_SCI_NORM_SWF_340;
92 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
93 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
84 }
94 }
85 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
95 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
86 // BUILD THE HEADER
96 // BUILD THE HEADER
87 header.packetLength[0] = (unsigned char) (length>>8);
97 header.packetLength[0] = (unsigned char) (length>>8);
88 header.packetLength[1] = (unsigned char) (length);
98 header.packetLength[1] = (unsigned char) (length);
89 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
99 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
90 // SEND PACKET
100 // SEND PACKET
91 write_spw(&spw_ioctl_send);
101 write_spw(&spw_ioctl_send);
92 }
102 }
93 for (i=0; i<7; i++) // send F0
103 for (i=0; i<7; i++) // send F2
94 {
104 {
105 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
95 // BUILD THE DATA
106 // BUILD THE DATA
96 if (i==6) {
107 if (i==6) {
97 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
108 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
98 length = TM_LEN_SCI_NORM_SWF_340;
109 length = TM_LEN_SCI_NORM_SWF_8;
99 }
110 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
111 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
112 }
100 else {
113 else {
101 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
114 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
102 length = TM_LEN_SCI_NORM_SWF_8;
115 length = TM_LEN_SCI_NORM_SWF_340;
116 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
117 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
103 }
118 }
104 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
119 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
105 // BUILD THE HEADER
120 // BUILD THE HEADER
106 header.packetLength[0] = (unsigned char) (length>>8);
121 header.packetLength[0] = (unsigned char) (length>>8);
107 header.packetLength[1] = (unsigned char) (length);
122 header.packetLength[1] = (unsigned char) (length);
108 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
123 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
109 // SEND PACKET
124 // SEND PACKET
110 write_spw(&spw_ioctl_send);
125 write_spw(&spw_ioctl_send);
111 }
126 }
112 // irq processed, reset the related register of the timer unit
127 // irq processed, reset the related register of the timer unit
113 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
128 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
114 }
129 }
115 }
130 }
131
132 //******************
133 // general functions
134 void init_waveforms()
135 {
136 int i = 0;
137
138 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
139 {
140 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and e1
141 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( 3*i, 4*i ); // e2 and b1
142 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
143 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
144 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
145 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
146 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
147 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
148 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
149 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
150 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
151 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
152 }
153 }
154
155 int buil_value(int value1, int value0)
156 {
157 int aux = 0;
158 int aux1 = 0;
159 int aux0 = 0;
160 //******
161 // B3 B2
162 aux1 = ( (int) ( (char) (value1 >> 8) ) << 8 )
163 + ( (int) ( (char) (value1 ) ) );
164
165 //******
166 // B1 B0
167 aux0 = ( (int) ( (char) (value0 >> 8) ) << 8 )
168 + ( (int) ( (char) (value0 ) ) );
169
170 aux = (aux1 << 16) + aux0;
171
172 return aux;
173 }
174
175
176
General Comments 0
You need to be logged in to leave comments. Login now