##// END OF EJS Templates
Several TC actions added...
paul@pc-solar1.lab-lpp.local -
r11:84136ad726a3 default
parent child
Show More
@@ -1,69 +1,69
1 1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 2 <CodeBlocks_project_file>
3 3 <FileVersion major="1" minor="6" />
4 4 <Project>
5 5 <Option title="FSW-rtems" />
6 6 <Option pch_mode="2" />
7 7 <Option compiler="sparcrtemsgcc446" />
8 8 <Build>
9 9 <Target title="Debug">
10 10 <Option output="bin/Debug/fsw" prefix_auto="1" extension_auto="1" />
11 11 <Option object_output="obj/Debug/" />
12 12 <Option type="1" />
13 <Option compiler="sparcrtems446" />
13 <Option compiler="sparcrtemsgcc446" />
14 14 <Compiler>
15 15 <Add option="-fexpensive-optimizations" />
16 16 <Add option="-O3" />
17 17 <Add option="-g" />
18 18 <Add directory="../header" />
19 19 <Add directory="../src" />
20 20 </Compiler>
21 21 </Target>
22 22 <Target title="Release">
23 23 <Option output="bin/Release/FSW-rtems" prefix_auto="1" extension_auto="1" />
24 24 <Option object_output="obj/Release/" />
25 25 <Option type="1" />
26 26 <Option compiler="sparcrtemsgcc446" />
27 27 <Compiler>
28 28 <Add option="-O2" />
29 29 </Compiler>
30 30 <Linker>
31 31 <Add option="-s" />
32 32 </Linker>
33 33 </Target>
34 34 </Build>
35 35 <Compiler>
36 36 <Add option="-Wall" />
37 37 </Compiler>
38 38 <Unit filename="../header/ccsds_types.h" />
39 39 <Unit filename="../header/fsw_init.h" />
40 40 <Unit filename="../header/fsw_misc.h" />
41 41 <Unit filename="../header/fsw_params.h" />
42 42 <Unit filename="../header/fsw_processing.h" />
43 43 <Unit filename="../header/grlib_regs.h" />
44 44 <Unit filename="../header/tc_handler.h" />
45 45 <Unit filename="../header/wf_handler.h" />
46 46 <Unit filename="../src/fsw_globals.c">
47 47 <Option compilerVar="CC" />
48 48 </Unit>
49 49 <Unit filename="../src/fsw_init.c">
50 50 <Option compilerVar="CC" />
51 51 </Unit>
52 52 <Unit filename="../src/fsw_misc.c">
53 53 <Option compilerVar="CC" />
54 54 </Unit>
55 55 <Unit filename="../src/fsw_processing.c">
56 56 <Option compilerVar="CC" />
57 57 </Unit>
58 58 <Unit filename="../src/tc_handler.c">
59 59 <Option compilerVar="CC" />
60 60 </Unit>
61 61 <Unit filename="../src/wf_handler.c">
62 62 <Option compilerVar="CC" />
63 63 </Unit>
64 64 <Extensions>
65 65 <code_completion />
66 66 <debugger />
67 67 </Extensions>
68 68 </Project>
69 69 </CodeBlocks_project_file>
@@ -1,310 +1,310
1 1 # depslib dependency file v1.0
2 2 1355231335 source:e:\missions\solo\dev_ple\src\fsw-rtems.c
3 3 <rtems.h>
4 4 <bsp.h>
5 5 <rtems/confdefs.h>
6 6 <drvmgr/drvmgr_confdefs.h>
7 7 <rtems.h>
8 8 <errno.h>
9 9 <fcntl.h>
10 10 <stdio.h>
11 11 <stdlib.h>
12 12 <FSW-config.c>
13 13 <grspw.h>
14 14 <apbuart.h>
15 15 <FSW-rtems-processing.h>
16 16
17 17 1355231335 -processing.h>
18 18
19 19 1350983928 source:e:\missions\solo\dev_ple\src\grspw.c
20 20 <..\header\grspw.h>
21 21 <stdio.h>
22 22
23 23 1354190601
24 24
25 25 1350983928 e:\missions\solo\dev_ple\header\grspw.h
26 26
27 27 1351173364 source:e:\missions\solo\dev_ple\src\fsw-config.c
28 28 <drvmgr/ambapp_bus.h>
29 29
30 30 1354190602 bapp_bus.h>
31 31
32 32 1354190602 e:\missions\solo\dev_ple\src\fsw-config.c
33 33 <drvmgr/ambapp_bus.h>
34 34
35 35 1354190602 source:e:\missions\solo\dev_ple\src\fsw-rtems-processing.c
36 36 <FSW-rtems-processing.h>
37 37 <math.h>
38 38 <stdio.h>
39 39 <leon.h>
40 40
41 41 1354190601 e:\missions\solo\dev_ple\header\fsw-rtems-processing.h
42 42 <rtems.h>
43 43
44 44 1359451040 source:/opt/DEV_PLE/src/FSW-rtems-processing.c
45 45 <FSW-rtems-processing.h>
46 46 <math.h>
47 47 <stdio.h>
48 48 <leon.h>
49 49
50 50 1359458568 /opt/DEV_PLE/header/FSW-rtems-processing.h
51 51 <rtems.h>
52 52 <grlibregs.h>
53 53 <FSW-params.h>
54 54
55 55 1359458854 source:/opt/DEV_PLE/src/FSW-rtems.c
56 56 <rtems.h>
57 57 <bsp.h>
58 58 <rtems/confdefs.h>
59 59 <drvmgr/drvmgr_confdefs.h>
60 60 <FSW-rtems.h>
61 61 <FSW-config.c>
62 62
63 63 1359365823 /opt/DEV_PLE/src/FSW-config.c
64 64 <drvmgr/ambapp_bus.h>
65 65
66 66 1359458568 source:/opt/DEV_PLE/src/TC_handler.c
67 67 <TC_handler.h>
68 68 <FSW-params.h>
69 69
70 70 1359377846 /opt/DEV_PLE/header/TC_handler.h
71 71 <stdio.h>
72 72 <ccsds_types.h>
73 73
74 74 1359640245 /opt/DEV_PLE/header/ccsds_types.h
75 75
76 76 1359365823 source:/opt/DEV_PLE/src/FSW-config.c
77 77 <drvmgr/ambapp_bus.h>
78 78
79 79 1359452642 /opt/DEV_PLE/header/FSW-config.h
80 80
81 81 1359440704 /opt/DEV_PLE/header/grlibregs.h
82 82
83 83 1359382989 source:/opt/DEV_PLE/src/WF_handler.c
84 84
85 85 1359459475 source:/opt/DEV_PLE/src/FSW-misc.c
86 86 <FSW-misc.h>
87 87 <FSW-params.h>
88 88
89 89 1359459330 /opt/DEV_PLE/header/FSW-misc.h
90 90 <rtems.h>
91 91 <stdio.h>
92 92 <FSW-rtems.h>
93 93 <FSW-params.h>
94 94 <grlibregs.h>
95 95 <grspw.h>
96 96 <ccsds_types.h>
97 97
98 98 1359459364 /opt/DEV_PLE/header/FSW-rtems.h
99 99 <errno.h>
100 100 <fcntl.h>
101 101 <stdio.h>
102 102 <stdlib.h>
103 103 <grspw.h>
104 104 <apbuart.h>
105 105 <FSW-params.h>
106 106 <FSW-misc.h>
107 107 <FSW-rtems-processing.h>
108 108 <TC_handler.h>
109 109 <WF_handler.h>
110 110 <grlibregs.h>
111 111
112 112 1359458453 /opt/DEV_PLE/header/FSW-params.h
113 113
114 114 1359459642 /opt/DEV_PLE/header/WF_handler.h
115 115 <rtems.h>
116 116 <FSW-params.h>
117 117 <grspw.h>
118 118 <grlibregs.h>
119 119 <ccsds_types.h>
120 120 <stdio.h>
121 121 <FSW-rtems.h>
122 122
123 123 1359464354 source:/opt/DEV_PLE/src/fsw_main.c
124 124 <rtems.h>
125 125 <bsp.h>
126 126 <rtems/confdefs.h>
127 127 <drvmgr/drvmgr_confdefs.h>
128 128 <fsw_main.h>
129 129 <fsw_config.c>
130 130
131 131 1359464346 /opt/DEV_PLE/header/fsw_main.h
132 132 <errno.h>
133 133 <fcntl.h>
134 134 <stdio.h>
135 135 <stdlib.h>
136 136 <grspw.h>
137 137 <apbuart.h>
138 138 <fsw_params.h>
139 139 <fsw_misc.h>
140 140 <fsw_processing.h>
141 141 <tc_handler.h>
142 142 <wf_handler.h>
143 143 <grlib_regs.h>
144 144
145 1359616894 /opt/DEV_PLE/header/fsw_params.h
145 1359959307 /opt/DEV_PLE/header/fsw_params.h
146 146
147 147 1359614518 /opt/DEV_PLE/header/fsw_misc.h
148 148 <rtems.h>
149 149 <stdio.h>
150 150 <fsw_init.h>
151 151 <fsw_params.h>
152 152 <grlib_regs.h>
153 153 <grspw.h>
154 154 <ccsds_types.h>
155 155
156 1359440704 /opt/DEV_PLE/header/grlib_regs.h
156 1359959822 /opt/DEV_PLE/header/grlib_regs.h
157 157
158 158 1359614517 /opt/DEV_PLE/header/fsw_processing.h
159 159 <rtems.h>
160 160 <grlib_regs.h>
161 161 <fsw_params.h>
162 162
163 1359643450 /opt/DEV_PLE/header/tc_handler.h
163 1359959377 /opt/DEV_PLE/header/tc_handler.h
164 164 <rtems.h>
165 165 <stdio.h>
166 166 <unistd.h>
167 167 <sys/ioctl.h>
168 168 <ccsds_types.h>
169 169 <grspw.h>
170 170 <fsw_init.h>
171 171
172 172 1359614518 /opt/DEV_PLE/header/wf_handler.h
173 173 <rtems.h>
174 174 <fsw_params.h>
175 175 <grspw.h>
176 176 <grlib_regs.h>
177 177 <ccsds_types.h>
178 178 <stdio.h>
179 179 <fsw_init.h>
180 180
181 181 1359365823 /opt/DEV_PLE/src/fsw_config.c
182 182 <drvmgr/ambapp_bus.h>
183 183
184 184 1359614518 source:/opt/DEV_PLE/src/fsw_misc.c
185 185 <fsw_misc.h>
186 186 <fsw_params.h>
187 187
188 1359643720 source:/opt/DEV_PLE/src/tc_handler.c
188 1359715931 source:/opt/DEV_PLE/src/tc_handler.c
189 189 <tc_handler.h>
190 190 <fsw_params.h>
191 191
192 1359614518 source:/opt/DEV_PLE/src/wf_handler.c
192 1359715982 source:/opt/DEV_PLE/src/wf_handler.c
193 193 <wf_handler.h>
194 194
195 1359615705 source:/opt/DEV_PLE/src/fsw_globals.c
195 1359959319 source:/opt/DEV_PLE/src/fsw_globals.c
196 196 <fsw_processing.h>
197 197 <rtems.h>
198 198
199 1359622160 source:/opt/DEV_PLE/src/fsw_init.c
199 1359959173 source:/opt/DEV_PLE/src/fsw_init.c
200 200 <rtems.h>
201 201 <bsp.h>
202 202 <rtems/confdefs.h>
203 203 <drvmgr/drvmgr_confdefs.h>
204 204 <fsw_init.h>
205 205 <fsw_config.c>
206 206
207 1359615705 /opt/DEV_PLE/header/fsw_init.h
207 1359714779 /opt/DEV_PLE/header/fsw_init.h
208 208 <errno.h>
209 209 <fcntl.h>
210 210 <stdio.h>
211 211 <stdlib.h>
212 212 <grspw.h>
213 213 <apbuart.h>
214 214 <fsw_params.h>
215 215 <fsw_misc.h>
216 216 <fsw_processing.h>
217 217 <tc_handler.h>
218 218 <wf_handler.h>
219 219 <grlib_regs.h>
220 220
221 1359614518 source:/opt/DEV_PLE/src/fsw_processing.c
221 1359715903 source:/opt/DEV_PLE/src/fsw_processing.c
222 222 <fsw_processing.h>
223 223 <math.h>
224 224 <stdio.h>
225 225 <leon.h>
226 226
227 227 1359665502 source:/home/admin/opt/DEV_PLE/src/fsw_globals.c
228 228 <fsw_processing.h>
229 229 <rtems.h>
230 230
231 231 1359663364 /home/admin/opt/DEV_PLE/header/fsw_processing.h
232 232 <rtems.h>
233 233 <grlib_regs.h>
234 234 <fsw_params.h>
235 235
236 236 1359470426 /home/admin/opt/DEV_PLE/header/grlib_regs.h
237 237
238 238 1359665475 /home/admin/opt/DEV_PLE/header/fsw_params.h
239 239
240 240 1359666330 source:/home/admin/opt/DEV_PLE/src/fsw_init.c
241 241 <rtems.h>
242 242 <bsp.h>
243 243 <rtems/confdefs.h>
244 244 <drvmgr/drvmgr_confdefs.h>
245 245 <fsw_init.h>
246 246 <fsw_config.c>
247 247
248 248 1359666373 /home/admin/opt/DEV_PLE/header/fsw_init.h
249 249 <errno.h>
250 250 <fcntl.h>
251 251 <stdio.h>
252 252 <stdlib.h>
253 253 <grspw.h>
254 254 <apbuart.h>
255 255 <fsw_params.h>
256 256 <fsw_misc.h>
257 257 <fsw_processing.h>
258 258 <tc_handler.h>
259 259 <wf_handler.h>
260 260 <grlib_regs.h>
261 261
262 262 1359663364 /home/admin/opt/DEV_PLE/header/fsw_misc.h
263 263 <rtems.h>
264 264 <stdio.h>
265 265 <fsw_init.h>
266 266 <fsw_params.h>
267 267 <grlib_regs.h>
268 268 <grspw.h>
269 269 <ccsds_types.h>
270 270
271 271 1359663364 /home/admin/opt/DEV_PLE/header/ccsds_types.h
272 272
273 273 1359665643 /home/admin/opt/DEV_PLE/header/tc_handler.h
274 274 <rtems.h>
275 275 <stdio.h>
276 276 <unistd.h>
277 277 <sys/ioctl.h>
278 278 <ccsds_types.h>
279 279 <grspw.h>
280 280 <fsw_init.h>
281 281
282 282 1359663364 /home/admin/opt/DEV_PLE/header/wf_handler.h
283 283 <rtems.h>
284 284 <fsw_params.h>
285 285 <grspw.h>
286 286 <grlib_regs.h>
287 287 <ccsds_types.h>
288 288 <stdio.h>
289 289 <fsw_init.h>
290 290
291 291 1359470426 /home/admin/opt/DEV_PLE/src/fsw_config.c
292 292 <drvmgr/ambapp_bus.h>
293 293
294 294 1359663364 source:/home/admin/opt/DEV_PLE/src/fsw_misc.c
295 295 <fsw_misc.h>
296 296 <fsw_params.h>
297 297
298 298 1359663364 source:/home/admin/opt/DEV_PLE/src/fsw_processing.c
299 299 <fsw_processing.h>
300 300 <math.h>
301 301 <stdio.h>
302 302 <leon.h>
303 303
304 304 1359663364 source:/home/admin/opt/DEV_PLE/src/wf_handler.c
305 305 <wf_handler.h>
306 306
307 307 1359665083 source:/home/admin/opt/DEV_PLE/src/tc_handler.c
308 308 <tc_handler.h>
309 309 <fsw_params.h>
310 310
@@ -1,43 +1,46
1 1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 2 <CodeBlocks_layout_file>
3 3 <ActiveTarget name="Debug" />
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="5">
5 <Cursor position="4079" topLine="120" />
4 <File name="../header/ccsds_types.h" open="1" top="0" tabpos="3">
5 <Cursor position="3403" topLine="101" />
6 6 </File>
7 7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="3">
8 <Cursor position="1128" topLine="26" />
8 <Cursor position="899" topLine="0" />
9 9 </File>
10 10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
11 11 <Cursor position="114" topLine="0" />
12 12 </File>
13 13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="0">
14 <Cursor position="1374" topLine="49" />
14 <Cursor position="2405" topLine="52" />
15 15 </File>
16 16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 17 <Cursor position="576" topLine="0" />
18 18 </File>
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="0">
20 <Cursor position="1072" topLine="0" />
21 </File>
19 22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
20 <Cursor position="437" topLine="35" />
23 <Cursor position="481" topLine="0" />
21 24 </File>
22 25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
23 26 <Cursor position="212" topLine="0" />
24 27 </File>
25 28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="4">
26 <Cursor position="1271" topLine="18" />
29 <Cursor position="1531" topLine="1" />
27 30 </File>
28 31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
29 <Cursor position="1814" topLine="48" />
32 <Cursor position="9387" topLine="83" />
30 33 </File>
31 34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="0">
32 35 <Cursor position="20" topLine="0" />
33 36 </File>
34 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="2">
35 <Cursor position="1175" topLine="46" />
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="3">
38 <Cursor position="1797" topLine="73" />
36 39 </File>
37 40 <File name="../src/tc_handler.c" open="1" top="1" tabpos="2">
38 <Cursor position="13133" topLine="89" />
41 <Cursor position="10603" topLine="21" />
39 42 </File>
40 43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="0">
41 <Cursor position="3936" topLine="62" />
44 <Cursor position="542" topLine="0" />
42 45 </File>
43 46 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
@@ -1,47 +1,52
1 1 #ifndef FSW_RTEMS_H_INCLUDED
2 2 #define FSW_RTEMS_H_INCLUDED
3 3
4 4 #include <errno.h>
5 5 #include <fcntl.h>
6 6 #include <stdio.h>
7 7 #include <stdlib.h>
8 8
9 9 #include <grspw.h>
10 10 #include <apbuart.h>
11 11
12 12 #include <fsw_params.h>
13 13 #include <fsw_misc.h>
14 14 #include <fsw_processing.h>
15 15 #include <tc_handler.h>
16 16 #include <wf_handler.h>
17 17 #include <grlib_regs.h>
18 18
19 19 extern int sched_yield();
20 20 extern int errno;
21 21 extern rtems_id Task_id[ ]; /* array of task ids */
22 22 extern rtems_name Task_name[ ]; /* array of task names */
23 23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
24 24 extern int fdSPW; // grspw file descriptor
25 25 extern int fdUART; // uart file descriptor
26 // MODE PARAMETERS
26 27 extern struct param_norm_str param_norm;
28 extern struct param_burst_str param_burst;
29 extern struct param_sbm1_str param_sbm1;
30 extern struct param_sbm2_str param_sbm2;
31 extern unsigned char param_common[];
27 32
28 33 // RTEMS TASKS
29 34 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
30 35 rtems_task recv_task(rtems_task_argument argument);
31 36 rtems_task spiq_task(rtems_task_argument argument);
32 37 rtems_task stat_task(rtems_task_argument argument);
33 38 rtems_task wfrm_task(rtems_task_argument argument);
34 39 int create_all_tasks();
35 40 int start_all_tasks();
36 41 int create_message_queue();
37 42
38 43 // OTHER functions
39 44 void init_default_mode_parameters();
40 45 int configure_spw_link();
41 46 int send_console_outputs_on_serial_port();
42 47 extern int rtems_cpu_usage_report();
43 48 extern int rtems_cpu_usage_reset();
44 49 void print_statistics(spw_stats *);
45 50 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
46 51
47 52 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,68 +1,92
1 1 #ifndef FSW_RTEMS_CONFIG_H_INCLUDED
2 2 #define FSW_RTEMS_CONFIG_H_INCLUDED
3 3
4 4 #define GRSPW_DEVICE_NAME "/dev/grspw0"
5 5 #define UART_DEVICE_NAME "/dev/console"
6 6
7 //**********
8 // LFR MODES
9 #define LFR_MODE_STANDBY 0
10 #define LFR_MODE_NORMAL 1
11 #define LFR_MODE_BURST 2
12 #define LFR_MODE_SBM1 3
13 #define LFR_MODE_SBM2 4
14
7 15 //*****************************
8 16 // APB REGISTERS BASE ADDRESSES
9 17 #define REGS_ADDR_APBUART 0x80000100
10 18 #define REGS_ADDR_GPTIMER 0x80000300
11 19 #define REGS_ADDR_GRSPW 0x80000500
20 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
12 21 #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700
13 22
14 23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
15 24
16 25 #define IRQ_SM 9
17 26 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
18 27 #define IRQ_WF 10
19 28 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
20 29
21 30 #define CLKDIV_SM_SIMULATOR 9999
22 31 #define CLKDIV_WF_SIMULATOR 9999999
23 32 #define TIMER_SM_SIMULATOR 1
24 33 #define TIMER_WF_SIMULATOR 2
25 34
26 35 //******
27 36 // RTEMS
28 37 #define TASKID_RECV 1
29 38 #define TASKID_ACTN 1
30 39 #define TASKID_SPIQ 3
31 40 #define TASKID_SMIQ 4
32 41 #define TASKID_STAT 5
33 42 #define TASKID_AVF0 6
34 43 #define TASKID_BPF0 7
35 44 #define TASKID_WFRM 8
36 45
37 46 #define ACTION_MSG_QUEUE_COUNT 10
38 47
39 48 //*******
40 49 // MACROS
41 50 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
42 51 #ifdef PRINT_MESSAGES_ON_CONSOLE
43 52 #define PRINTF(x) printf(x);
44 53 #define PRINTF1(x,y) printf(x,y);
45 54 #define PRINTF2(x,y,z) printf(x,y,z);
46 55 #else
47 56 #define PRINTF(x) ;
48 57 #define PRINTF1(x,y) ;
49 58 #define PRINTF2(x,y,z) ;
50 59 #endif
51 60
52 61 #define NB_SAMPLES_PER_SNAPSHOT 2048
53 62 #define NB_BYTES_SWF_BLK 2 * 6
54 63
55 64 struct param_norm_str{
56 65 unsigned int sy_lfr_n_swf_l; // length of the snapshots
57 66 unsigned int sy_lfr_n_swf_p; // time between two snapshots
58 67 unsigned int sy_lfr_n_asm_p; // time between two asm
59 68 unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set
60 69 unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set
61 70 };
62 71
72 struct param_burst_str{
73 unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set
74 unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set
75 };
76
77 struct param_sbm1_str{
78 unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set
79 unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set
80 };
81
82 struct param_sbm2_str{
83 unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set
84 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
85 };
86
63 87 extern volatile int wf_snap_f0[ ]; // 24576 bytes
64 88 extern volatile int wf_snap_f1[ ]; // 24576 bytes
65 89 extern volatile int wf_snap_f2[ ]; // 24576 bytes
66 90 extern volatile int wf_cont_f3[ ]; // 24576 bytes
67 91
68 92 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,40 +1,48
1 1 #ifndef GRLIBREGS_H_INCLUDED
2 2 #define GRLIBREGS_H_INCLUDED
3 3
4 4 #define NB_GPTIMER 3
5 5
6 6 struct apbuart_regs_str{
7 7 volatile unsigned int data;
8 8 volatile unsigned int status;
9 9 volatile unsigned int ctrl;
10 10 volatile unsigned int scaler;
11 11 volatile unsigned int fifoDebug;
12 12 };
13 13
14 14 struct timer_regs_str
15 15 {
16 16 volatile unsigned int counter;
17 17 volatile unsigned int reload;
18 18 volatile unsigned int ctrl;
19 19 volatile unsigned int unused;
20 20 };
21 21 typedef struct timer_regs_str timer_regs_t;
22 22
23 23 struct gptimer_regs_str
24 24 {
25 25 volatile unsigned int scaler_value;
26 26 volatile unsigned int scaler_reload;
27 27 volatile unsigned int conf;
28 28 volatile unsigned int unused0;
29 29 timer_regs_t timer[NB_GPTIMER];
30 30 };
31 31 typedef struct gptimer_regs_str gptimer_regs_t;
32 32
33 33 struct spectral_matrices_regs_str{
34 34 volatile int ctrl;
35 35 volatile int address0;
36 36 volatile int address1;
37 37 };
38 38 typedef struct spectral_matrices_regs_str spectral_matrices_regs_t;
39 39
40 struct time_management_regs_str{
41 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
42 volatile int coarse_time_load;
43 volatile int coarse_time;
44 volatile int fine_time;
45 };
46 typedef struct time_management_regs_str time_management_regs_t;
47
40 48 #endif // GRLIBREGS_H_INCLUDED
@@ -1,54 +1,63
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 #include <bsp.h> // for the LEON_Unmask_interrupt function
5 6 #include <stdio.h>
6 7 #include <unistd.h> // for the read call
7 8 #include <sys/ioctl.h> // for the ioctl call
8 9 #include <ccsds_types.h>
9 10 #include <grspw.h>
10 11 #include <fsw_init.h>
11 12
12 13 extern int fdSPW;
13 14 extern rtems_name misc_name[ ];
14 15 extern rtems_name misc_id[ ];
15 16 extern rtems_id Task_id[ ]; // array of task ids
17 // MODE PARAMETERS
16 18 extern struct param_norm_str param_norm;
19 extern struct param_sbm1_str param_sbm1;
20 extern struct param_sbm2_str param_sbm2;
21 extern time_management_regs_t *time_management_regs;
22 extern unsigned char param_common[];
17 23
18 24 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
19 25 unsigned char currentTC_COMPUTED_CRC[2];
20 26 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
21 27 unsigned int currentTM_length;
22 28 unsigned char currentTC_processedFlag;
23 29
24 30 //**********************
25 31 // GENERAL USE FUNCTIONS
26 32 unsigned int lookUpTableForCRC[256];
27 void InitLookUpTableForCRC();
33 void initLookUpTableForCRC();
28 34 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
29 35
30 36 //*********************
31 37 // ACCEPTANCE FUNCTIONS
32 38 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv);
33 39
34 40 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
35 41 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader);
36 42 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC);
37 43 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV);
38 44
39 45 //***********
40 46 // RTEMS TASK
41 47 rtems_task recv_task( rtems_task_argument unused );
42 48 rtems_task actn_task( rtems_task_argument unused );
43 49 int create_message_queue();
44 50
45 51 //***********
46 52 // TC ACTIONS
47 53 int action_default(ccsdsTelecommandPacket_t *TC);
54 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC);
55 //
48 56 int action_load_norm(ccsdsTelecommandPacket_t *TC);
49 57 int action_enter(ccsdsTelecommandPacket_t *TC);
58 int action_updt_time(ccsdsTelecommandPacket_t *TC);
50 59
51 60 #endif // TC_HANDLER_H_INCLUDED
52 61
53 62
54 63
@@ -1,37 +1,44
1 1 #include <fsw_processing.h>
2 2 #include <rtems.h>
3 3
4 4 // RTEMS GLOBAL VARIABLES
5 5 rtems_name misc_name[5];
6 6 rtems_name misc_id[5];
7 7 rtems_id Task_id[10]; /* array of task ids */
8 8 rtems_name Task_name[10]; /* array of task names */
9 9 int fdSPW;
10 10 int fdUART;
11 11
12 // APB CONFIGURATION REGISTERS
13 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
14
12 15 // WAVEFORMS GLOBAL VARIABLES
13 16 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
14 17 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
15 18 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
16 19 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
17 20
18 21 // SPECTRAL MATRICES GLOBAL VARIABLES
19 22 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
20 23 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
21 24 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
22 25 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
23 26 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
24 27 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
25 28 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
26 29 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
27 30 //
28 31 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
29 32 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
30 33
31 // NORMAL MODE PARAMETERS
34 // MODE PARAMETERS
32 35 struct param_norm_str param_norm;
36 struct param_burst_str param_burst;
37 struct param_sbm1_str param_sbm1;
38 struct param_sbm2_str param_sbm2;
39 unsigned char param_common[2];
33 40
34 41 // BASIC PARAMETERS GLOBAL VARIABLES
35 42 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
36 43
37 44 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
@@ -1,264 +1,272
1 1 //*************************
2 2 // GPL reminder to be added
3 3 //*************************
4 4
5 5 #include <rtems.h>
6 6
7 7 /* configuration information */
8 8
9 9 #define CONFIGURE_INIT
10 10
11 11 #include <bsp.h> /* for device driver prototypes */
12 12
13 13 /* configuration information */
14 14
15 15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16 16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17 17
18 18 #define CONFIGURE_MAXIMUM_TASKS 10
19 19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
20 20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
21 21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 24 #define CONFIGURE_MAXIMUM_PERIODS 1
25 25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
26 26
27 27 #include <rtems/confdefs.h>
28 28
29 29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
30 30 #ifdef RTEMS_DRVMGR_STARTUP
31 31 #ifdef LEON3
32 32 /* Add Timer and UART Driver */
33 33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
34 34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
35 35 #endif
36 36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
37 37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
38 38 #endif
39 39 #endif
40 40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
41 41 #include <drvmgr/drvmgr_confdefs.h>
42 42 #endif
43 43
44 44 #include <fsw_init.h>
45 45 #include <fsw_config.c>
46 46
47 47 char *link_status(int status);
48 48
49 49 char *lstates[6] = {"Error-reset",
50 50 "Error-wait",
51 51 "Ready",
52 52 "Started",
53 53 "Connecting",
54 54 "Run"
55 55 };
56 56
57 57 rtems_task Init( rtems_task_argument ignored )
58 58 {
59 59 rtems_status_code status;
60 60
61 61 //send_console_outputs_on_serial_port();
62 62
63 InitLookUpTableForCRC(); // in tc_handler.h
63 initLookUpTableForCRC(); // in tc_handler.h
64 64 init_default_mode_parameters();
65 65 create_message_queue();
66 66 create_all_tasks();
67 67 start_all_tasks();
68 68
69 69 configure_spw_link();
70 // configure timer for spectral matrices simulation
71 70 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
72 71 IRQ_SPARC_SM, spectral_matrices_isr );
73 // configure timer for waveforms simulation
74 72 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
75 73 IRQ_SPARC_WF, waveforms_isr );
76
77 LEON_Unmask_interrupt( IRQ_SM );
78 LEON_Unmask_interrupt( IRQ_WF );
79 74
80 75 status = rtems_task_delete(RTEMS_SELF);
81 76 }
82 77
83 78 rtems_task spiq_task(rtems_task_argument unused)
84 79 {
85 80 rtems_event_set event_out;
86 81 struct grspw_regs_str *grspw_regs;
87 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
82 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
88 83
89 84 while(1){
90 85 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
91 86 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
92 87
93 88 if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task
94 89 PRINTF("In SPIQ *** Error suspending RECV Task\n")
95 90
96 91 configure_spw_link();
97 92
98 93 if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
99 94 PRINTF("In SPIQ *** Error resume RECV Task\n")
100 95 }
101 96 }
102 97
103 98 void init_default_mode_parameters()
104 99 {
100 // COMMON PARAMETERS
101 param_common[0] = 0x00;
102 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
103 // NORMAL MODE
105 104 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
106 105 param_norm.sy_lfr_n_swf_p = 300; // sec
107 106 param_norm.sy_lfr_n_asm_p = 3600; // sec
108 107 param_norm.sy_lfr_n_bp_p0 = 4; // sec
109 108 param_norm.sy_lfr_n_bp_p1 = 20; // sec
109 // BURST MODE
110 param_burst.sy_lfr_b_bp_p0 = 1; // sec
111 param_burst.sy_lfr_b_bp_p1 = 5; // sec
112 // SBM1 MODE
113 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
114 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
115 // SBM2 MODE
116 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
117 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
110 118 }
111 119
112 120 int create_all_tasks()
113 121 {
114 122 rtems_status_code status;
115 123
116 124 Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
117 125 Task_name[2] = rtems_build_name( 'A', 'C', 'T', 'N' );
118 126 Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' );
119 127 Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' );
120 128 Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' );
121 129 Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' );
122 130 Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' );
123 131 Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' );
124 132
125 133 // RECV
126 134 status = rtems_task_create(
127 135 Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
128 136 RTEMS_DEFAULT_MODES,
129 137 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]
130 138 );
131 139 // ACTN
132 140 status = rtems_task_create(
133 141 Task_name[2], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
134 142 RTEMS_DEFAULT_MODES,
135 143 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2]
136 144 );
137 145 // SPIQ
138 146 status = rtems_task_create(
139 147 Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
140 148 RTEMS_DEFAULT_MODES,
141 149 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]
142 150 );
143 151 // SMIQ
144 152 status = rtems_task_create(
145 153 Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
146 154 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
147 155 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4]
148 156 );
149 157 // STAT
150 158 status = rtems_task_create(
151 159 Task_name[5], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
152 160 RTEMS_DEFAULT_MODES,
153 161 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5]
154 162 );
155 163 // AVF0
156 164 status = rtems_task_create(
157 165 Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
158 166 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
159 167 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6]
160 168 );
161 169 // BPF0
162 170 status = rtems_task_create(
163 171 Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
164 172 RTEMS_DEFAULT_MODES,
165 173 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7]
166 174 );
167 175 // WFRM
168 176 status = rtems_task_create(
169 177 Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
170 178 RTEMS_DEFAULT_MODES,
171 179 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8]
172 180 );
173 181
174 182 return 0;
175 183 }
176 184
177 185 int start_all_tasks()
178 186 {
179 187 rtems_status_code status;
180 188
181 189 status = rtems_task_start( Task_id[3], spiq_task, 1 );
182 190 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
183 191
184 192 status = rtems_task_start( Task_id[1], recv_task, 1 );
185 193 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
186 194
187 195 status = rtems_task_start( Task_id[2], actn_task, 1 );
188 196 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
189 197
190 198 status = rtems_task_start( Task_id[4], smiq_task, 1 );
191 199 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
192 200
193 201 status = rtems_task_start( Task_id[5], stat_task, 1 );
194 202 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
195 203
196 204 status = rtems_task_start( Task_id[6], avf0_task, 1 );
197 205 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
198 206
199 207 status = rtems_task_start( Task_id[7], bpf0_task, 1 );
200 208 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
201 209
202 210 status = rtems_task_start( Task_id[8], wfrm_task, 1 );
203 211 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
204 212
205 213 return 0;
206 214 }
207 215
208 216 int configure_spw_link()
209 217 {
210 218 rtems_status_code status;
211 219
212 220 close(fdSPW); // close the device if it is already open
213 221 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
214 222 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
215 223 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
216 224 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
217 225 close(fdSPW); // close the device
218 226 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
219 227 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
220 228 rtems_task_wake_after(100);
221 229 }
222 230
223 231 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
224 232
225 233 // sets a few parameters of the link
226 234 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
227 235 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
228 236 //
229 237 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
230 238 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
231 239 //
232 240 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
233 241 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
234 242 //
235 243 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
236 244 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
237 245 //
238 246 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
239 247 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
240 248
241 249 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
242 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
250 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
243 251 //
244 252 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
245 253 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
246 254 //
247 255 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
248 256
249 257 return RTEMS_SUCCESSFUL;
250 258 }
251 259
252 260 char *link_status(int status){
253 261 return lstates[status];
254 262 }
255 263
256 264 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
257 265 {
258 266 rtems_status_code status;
259 267 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
260 268 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
261 269 return status;
262 270 }
263 271
264 272
@@ -1,423 +1,427
1 1 #include <fsw_processing.h>
2 2 #include <math.h>
3 3 #include <stdio.h>
4 4 #include <leon.h>
5 5
6 6 float k14_re = 1;
7 7 float k14_im = 1;
8 8 float k14_bis_re = 1;
9 9 float k14_bis_im = 1;
10 10 float k14_tris_re = 1;
11 11 float k14_tris_im = 1;
12 12 float k15_re = 1;
13 13 float k15_im = 1;
14 14 float k15_bis_re = 1;
15 15 float k15_bis_im = 1;
16 16 float k24_re = 1;
17 17 float k24_im = 1;
18 18 float k24_bis_re = 1;
19 19 float k24_bis_im = 1;
20 20 float k24_tris_re = 1;
21 21 float k24_tris_im = 1;
22 22 float k25_re = 1;
23 23 float k25_im = 1;
24 24 float k25_bis_re = 1;
25 25 float k25_bis_im = 1;
26 26 float k34_re = 1;
27 27 float k34_im = 1;
28 28 float k44 = 1;
29 29 float k55 = 1;
30 30 float k45_re = 1;
31 31 float k45_im = 1;
32 32 float alpha_M = M_PI/4;
33 33
34 34 extern volatile int spec_mat_f0_a[ ];
35 35 extern volatile int spec_mat_f0_b[ ];
36 36 extern volatile int spec_mat_f0_c[ ];
37 37 extern volatile int spec_mat_f0_d[ ];
38 38 extern volatile int spec_mat_f0_e[ ];
39 39 extern volatile int spec_mat_f0_f[ ];
40 40 extern volatile int spec_mat_f0_g[ ];
41 41 extern volatile int spec_mat_f0_h[ ];
42 42 extern float averaged_spec_mat_f0[ ];
43 43 extern float compressed_spec_mat_f0[ ];
44 44 extern unsigned char LFR_BP1_F0[ ];
45 45
46 46 extern BP1_t data_BP1[ ];
47 47
48 48 extern rtems_id Task_id[ ]; /* array of task ids */
49 49
50 50 spectral_matrices_regs_t *spectral_matrices_regs;
51 51
52 52 // Interrupt Service Routine for spectral matrices processing
53 53 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
54 54 {
55 55 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
56 56 printf("In spectral_matrices_isr *** Error sending event to AVF0\n");
57 57 }
58 58
59 59 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
60 60 {
61 61 rtems_event_set event_out;
62 62 gptimer_regs_t *gptimer_regs;
63 63 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
64 64 unsigned char nb_interrupt_f0 = 0;
65
66 PRINTF("In SMIQ *** \n")
65 67
66 68 while(1){
67 69 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
68 70 nb_interrupt_f0 = nb_interrupt_f0 + 1;
69 71 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
70 72 if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
71 73 printf("In smiq_task *** Error sending event to AVF0\n");
72 74 nb_interrupt_f0 = 0;
73 75 }
74 76 gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010;
75 77 }
76 78 }
77 79
78 80 rtems_task spw_bppr_task(rtems_task_argument argument)
79 81 {
80 82 rtems_status_code status;
81 83 rtems_event_set event_out;
82 84 static int nb_average_f0 = 0;
83 85 //static int nb_average_f1 = 0;
84 86 //static int nb_average_f2 = 0;
85 87
86 88 while(1)
87 89
88 90 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
89 91 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
90 92 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
91 93
92 94 printf("In BPPR ***\n");
93 95
94 96 while(1){ // wait for an event to begin with the processing
95 97 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
96 98 if (status == RTEMS_SUCCESSFUL){
97 99 if ((spectral_matrices_regs->ctrl & 0x00000001)==1){
98 100 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
99 101 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
100 102 //printf("f0_a\n");
101 103 nb_average_f0++;
102 104 }
103 105 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){
104 106 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
105 107 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
106 108 //printf("f0_b\n");
107 109 nb_average_f0++;
108 110 }
109 111 if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){
110 112 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
111 113 //printf("f0 compressed\n");
112 114 nb_average_f0 = 0;
113 115 matrix_reset(averaged_spec_mat_f0);
114 116 }
115 117 }
116 118 }
117 119 }
118 120
119 121 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
120 122 {
121 123 int i;
122 124 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
123 125 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
124 126 + spec_mat_f0_b[i]
125 127 + spec_mat_f0_c[i]
126 128 + spec_mat_f0_d[i]
127 129 + spec_mat_f0_e[i]
128 130 + spec_mat_f0_f[i]
129 131 + spec_mat_f0_g[i]
130 132 + spec_mat_f0_h[i];
131 133 }
132 134 }
133 135
134 136 void matrix_reset(float *averaged_spec_mat)
135 137 {
136 138 int i;
137 139 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
138 140 averaged_spec_mat_f0[i] = 0;
139 141 }
140 142 }
141 143
142 144 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
143 145 {
144 146 int i, j;
145 147 switch (fChannel){
146 148 case 0:
147 149 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
148 150 j = 17 + i * 8;
149 151 compressed_spec_mat[i] = (averaged_spec_mat[j]
150 152 + averaged_spec_mat[j+1]
151 153 + averaged_spec_mat[j+2]
152 154 + averaged_spec_mat[j+3]
153 155 + averaged_spec_mat[j+4]
154 156 + averaged_spec_mat[j+5]
155 157 + averaged_spec_mat[j+6]
156 158 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
157 159 }
158 160 break;
159 161 case 1:
160 162 // case fChannel = f1 tp be completed later
161 163 break;
162 164 case 2:
163 165 // case fChannel = f1 tp be completed later
164 166 break;
165 167 default:
166 168 break;
167 169 }
168 170 }
169 171
170 172 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
171 173 int i, j;
172 174 unsigned char tmp_u_char;
173 175 unsigned char * pt_char;
174 176 float PSDB, PSDE;
175 177 float NVEC_V0, NVEC_V1, NVEC_V2;
176 178 float significand;
177 179 int exponent;
178 180 float aux, tr_SB_SB, tmp;
179 181 float e_cross_b_re, e_cross_b_im;
180 182 float n_cross_e_scal_b_re = 0, n_cross_e_scal_b_im = 0;
181 183 float nx = 0, ny = 0;
182 184 float bz_bz_star = 0;
183 185 for(i=0; i<nb_bins_compressed_spec_mat; i++){
184 186 //==============================================
185 187 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
186 188 PSDB = compressed_spec_mat[i*30] // S11
187 189 + compressed_spec_mat[i*30+10] // S22
188 190 + compressed_spec_mat[i*30+18]; // S33
189 191 significand = frexp(PSDB, &exponent);
190 192 pt_char = (unsigned char*) &PSDB;
191 193 LFR_BP1[i*9+8] = pt_char[0]; // bits 31 downto 24 of the float
192 194 LFR_BP1[i*9+7] = pt_char[1]; // bits 23 downto 16 of the float
193 195 //==============================================
194 196 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
195 197 PSDE = compressed_spec_mat[i*30+24] * k44 // S44
196 198 + compressed_spec_mat[i*30+28] * k55 // S55
197 199 + compressed_spec_mat[i*30+26] * k45_re // S45
198 200 - compressed_spec_mat[i*30+27] * k45_im; // S45
199 201 pt_char = (unsigned char*) &PSDE;
200 202 LFR_BP1[i*9+6] = pt_char[0]; // bits 31 downto 24 of the float
201 203 LFR_BP1[i*9+5] = pt_char[1]; // bits 23 downto 16 of the float
202 204 //==============================================================================
203 205 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
204 206 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
205 207 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
206 208 tmp = sqrt(
207 209 compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12
208 210 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13
209 211 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+13] //Im S23
210 212 );
211 213 NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23
212 214 NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13
213 215 NVEC_V2 = compressed_spec_mat[i*30+1] / tmp; // Im S12
214 216 LFR_BP1[i*9+4] = (char) (NVEC_V0*256);
215 217 LFR_BP1[i*9+3] = (char) (NVEC_V1*256);
216 218 pt_char = (unsigned char*) &NVEC_V2;
217 219 LFR_BP1[i*9+2] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
218 220 //=======================================================
219 221 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
220 222 aux = 2*tmp / PSDB; // compute the ellipticity
221 223 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
222 224 LFR_BP1[i*9+2] = LFR_BP1[i*9+2] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
223 225 //==============================================================
224 226 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
225 227 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
226 228 tr_SB_SB = compressed_spec_mat[i*30]*compressed_spec_mat[i*30]
227 229 + compressed_spec_mat[i*30+10]*compressed_spec_mat[i*30+10]
228 230 + compressed_spec_mat[i*30+18]*compressed_spec_mat[i*30+18]
229 231 + 2 * compressed_spec_mat[i*30+2]*compressed_spec_mat[i*30+2]
230 232 + 2 * compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3]
231 233 + 2 * compressed_spec_mat[i*30+4]*compressed_spec_mat[i*30+4]
232 234 + 2 * compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5]
233 235 + 2 * compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+12]
234 236 + 2 * compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13];
235 237 }
236 238 aux = PSDB*PSDB;
237 239 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux );
238 240 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
239 241 LFR_BP1[i*9+2] = LFR_BP1[i*9+2] | ((tmp_u_char&0x07)); // keeps 3 bits of the resulting unsigned char
240 242 //=======================================================================================
241 243 // BP1 z-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
242 244 e_cross_b_re = compressed_spec_mat[i*30+20]*k34_re
243 245 + compressed_spec_mat[i*30+6]*k14_re
244 246 + compressed_spec_mat[i*30+8]*k15_re
245 247 + compressed_spec_mat[i*30+14]*k24_re
246 248 + compressed_spec_mat[i*30+16]*k25_re;
247 249 e_cross_b_im = compressed_spec_mat[i*30+21]*k34_im
248 250 + compressed_spec_mat[i*30+7]*k14_im
249 251 + compressed_spec_mat[i*30+9]*k15_im
250 252 + compressed_spec_mat[i*30+15]*k24_im
251 253 + compressed_spec_mat[i*30+17]*k25_im;
252 254 tmp = e_cross_b_re / PSDE; // compute ReaSz
253 255 LFR_BP1[i*9+1] = ((unsigned char) (tmp * 128)) & 0x7f; // is it always positive?
254 256 tmp = e_cross_b_re * e_cross_b_im;
255 257 pt_char = (unsigned char*) &tmp;
256 258 LFR_BP1[i*9+1] = LFR_BP1[i*9+1] | (pt_char[0] & 0x80); // extract the sign of ArgSz
257 259 //======================================================================
258 260 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
259 261 nx = -sin(alpha_M)*NVEC_V0 - cos(alpha_M)*NVEC_V1;
260 262 ny = NVEC_V2;
261 263 bz_bz_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30] // re S11
262 264 + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+10] // re S22
263 265 - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+2]; // re S12
264 266 n_cross_e_scal_b_re = nx * (compressed_spec_mat[i*30+8]*k15_bis_re
265 267 +compressed_spec_mat[i*30+6]*k14_bis_re
266 268 +compressed_spec_mat[i*30+16]*k25_bis_re
267 269 +compressed_spec_mat[i*30+14]*k24_bis_re)
268 270 + ny * (compressed_spec_mat[i*30+6]*k14_tris_re
269 271 +compressed_spec_mat[i*30+14]*k24_tris_re);
270 272 n_cross_e_scal_b_im = nx * (compressed_spec_mat[i*30+8]*k15_bis_im
271 273 +compressed_spec_mat[i*30+6]*k14_bis_im
272 274 +compressed_spec_mat[i*30+16]*k25_bis_im
273 275 +compressed_spec_mat[i*30+14]*k24_bis_im)
274 276 + ny * (compressed_spec_mat[i*30+6]*k14_tris_im
275 277 +compressed_spec_mat[i*30+14]*k24_tris_im);
276 278 tmp = n_cross_e_scal_b_re / bz_bz_star;
277 279 LFR_BP1[i*9+0] = ((unsigned char) (tmp * 128)) & 0x7f; // is it always positive?
278 280 tmp = n_cross_e_scal_b_re * n_cross_e_scal_b_im;
279 281 pt_char = (unsigned char*) &tmp;
280 282 LFR_BP1[i*9+1] = LFR_BP1[i*9+0] | (pt_char[0] & 0x80); // extract the sign of ArgV
281 283 }
282 284
283 285 }
284 286
285 287 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
286 288 // BP2 autocorrelation
287 289 int i, aux = 0;
288 290 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
289 291 // S12
290 292 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]);
291 293 compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux;
292 294 compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux;
293 295 // S13
294 296 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]);
295 297 compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux;
296 298 compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux;
297 299 // S23
298 300 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]);
299 301 compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux;
300 302 compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux;
301 303 // S45
302 304 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]);
303 305 compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux;
304 306 compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux;
305 307 // S14
306 308 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
307 309 compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux;
308 310 compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux;
309 311 // S15
310 312 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]);
311 313 compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux;
312 314 compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux;
313 315 // S24
314 316 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]);
315 317 compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux;
316 318 compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux;
317 319 // S25
318 320 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]);
319 321 compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux;
320 322 compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux;
321 323 // S34
322 324 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]);
323 325 compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux;
324 326 compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux;
325 327 // S35
326 328 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]);
327 329 compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux;
328 330 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
329 331 }
330 332 }
331 333
332 334 rtems_task avf0_task(rtems_task_argument argument){
333 335 int i;
334 336 static int nb_average;
335 337 rtems_event_set event_out;
336 338 rtems_status_code status;
337 339
338 340 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
339 341 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
340 342 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
341 343
342 344 nb_average = 0;
343 345
344 346 PRINTF("In AVFO *** \n")
345 347
346 348 while(1){
347 349 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
348 350 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
349 351 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
350 352 + spec_mat_f0_b[i]
351 353 + spec_mat_f0_c[i]
352 354 + spec_mat_f0_d[i]
353 355 + spec_mat_f0_e[i]
354 356 + spec_mat_f0_f[i]
355 357 + spec_mat_f0_g[i]
356 358 + spec_mat_f0_h[i];
357 359 }
358 360 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
359 361 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
360 362 if (nb_average == NB_AVERAGE_NORMAL_f0) {
361 363 nb_average = 0;
362 364 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
363 365 if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
364 366 }
365 367 }
366 368 }
367 369
368 370 rtems_task bpf0_task(rtems_task_argument argument){
369 371 rtems_event_set event_out;
372
373 PRINTF("In BPFO *** \n")
370 374
371 375 while(1){
372 376 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
373 377 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
374 378 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
375 379 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
376 380 }
377 381 }
378 382
379 383 //*******
380 384 // UNUSED
381 385 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument)
382 386 {/*
383 387 rtems_status_code status;
384 388 //static int nb_average_f1 = 0;
385 389 //static int nb_average_f2 = 0;
386 390
387 391 rtems_name name;
388 392 rtems_id period;
389 393 name = rtems_build_name( 'P', 'E', 'R', 'D' );
390 394 status = rtems_rate_monotonic_create( name, &period );
391 395 if( status != RTEMS_SUCCESSFUL ) {
392 396 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
393 397 //exit( 1 );
394 398 }
395 399
396 400 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
397 401 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
398 402 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
399 403
400 404 printf("In BPPR BIS ***\n");
401 405
402 406 while(1){ // launch the rate monotonic task
403 407 if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){
404 408 printf("TIMEOUT\n");
405 409 //break;
406 410 }
407 411 status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0
408 412 if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status);
409 413 }
410 414
411 415 status = rtems_rate_monotonic_delete( period );
412 416 if ( status != RTEMS_SUCCESSFUL ) {
413 417 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
414 418 //exit( 1 );
415 419 }
416 420 status = rtems_task_delete( RTEMS_SELF ); // should not return
417 421 printf( "rtems_task_delete returned with status of %d.\n", status );
418 422 //exit( 1 );*/
419 423 }
420 424
421 425
422 426
423 427
@@ -1,414 +1,489
1 1 #include <tc_handler.h>
2 2 #include <fsw_params.h>
3 3
4 4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
5 5 "WRONG_LEN_PACKET 1",
6 6 "INCOR_CHECKSUM 2",
7 7 "ILL_TYPE 3",
8 8 "ILL_SUBTYPE 4",
9 9 "WRONG_APP_DATA 5",
10 10 "WRONG_CMD_CODE 6",
11 11 "CCSDS_TM_VALID 7"
12 12 };
13 13
14 14 //**********************
15 15 // GENERAL USE FUNCTIONS
16 16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 17 {
18 18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 19 }
20 20
21 void InitLookUpTableForCRC()
21 void initLookUpTableForCRC()
22 22 {
23 23 unsigned int i, tmp;
24 24 for (i=0; i<256; i++)
25 25 {
26 26 tmp = 0;
27 27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
28 28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
29 29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
30 30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
31 31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
32 32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
33 33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
34 34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
35 35 lookUpTableForCRC[i] = tmp;
36 36 }
37 37 }
38 38
39 39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
40 40 {
41 41 unsigned int Chk;
42 42 int j;
43 43 Chk = 0xffff; // reset the syndrom to all ones
44 44 for (j=0; j<sizeOfData; j++) {
45 45 Chk = Crc_opt(data[j], Chk);
46 46 }
47 47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
48 48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 49 }
50 50
51 51
52 52 //*********************
53 53 // ACCEPTANCE FUNCTIONS
54 54 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
55 55 {
56 56 rtems_status_code status;
57 57 spw_ioctl_pkt_send spw_ioctl_send;
58 58 TMHeader_t TM_header;
59 59 unsigned int code = 0;
60 60 unsigned char computed_CRC[2];
61 61 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
62 62
63 63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
64 64 code = acceptTM( TC, tc_len_recv ) ;
65 65 if ( (code == 0) | (code == 1) | (code == 2)
66 66 | (code == 3) | (code == 4) | (code == 5) )
67 67 { // generate TM_LFR_TC_EXE_CORRUPTED
68 68 // BUILD HEADER
69 69 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
70 70 // BUILD DATA
71 71 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
72 72 // PREPARE TM SENDING
73 73 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
74 74 spw_ioctl_send.hdr = (char*) &TM_header;
75 spw_ioctl_send.dlen = TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
75 spw_ioctl_send.dlen = 16;
76 76 spw_ioctl_send.data = data;
77 77 // SEND PACKET
78 78 write_spw(&spw_ioctl_send);
79 79 }
80 80 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);
81 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
82 82 return -1;
83 83 }
84 84 return -1;
85 85 }
86 86
87 87 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
88 88 {
89 89 unsigned char pid = 0;
90 90 unsigned char category = 0;
91 91 unsigned int length = 0;
92 92 unsigned char packetType = 0;
93 93 unsigned char packetSubtype = 0;
94 94 unsigned char * CCSDSContent;
95 95
96 96 // APID check *** APID on 2 bytes
97 97 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
98 98 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
99 99 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
100 100 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
101 101
102 102 // packet length check
103 103 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
104 104 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
105 105 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
106 106
107 107 packetType = TMPacket->dataFieldHeader[1];
108 108 packetSubtype = TMPacket->dataFieldHeader[2];
109 109 // service type, subtype and packet length check
110 110 if (packetType == 181){
111 111 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
112 112 case 3:
113 113 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
114 114 break;
115 115 case 20:
116 116 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
117 117 break;
118 118 case 21:
119 119 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
120 120 break;
121 121 case 24:
122 122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
123 123 break;
124 124 case 27:
125 125 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
126 126 break;
127 127 case 28:
128 128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
129 129 break;
130 130 case 30:
131 131 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
132 132 break;
133 133 case 40:
134 134 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
135 135 break;
136 136 case 50:
137 137 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
138 138 break;
139 139 case 60:
140 140 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
141 141 break;
142 142 case 61:
143 143 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
144 144 break;
145 145 default:
146 146 return ILL_SUBTYPE;
147 147 break;
148 148 }
149 149 }
150 150 else if (packetType == 9){
151 151 if (packetSubtype!=129) return ILL_SUBTYPE;
152 152 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
153 153 }
154 154 else return ILL_TYPE;
155 155
156 156 // source ID check // Source ID not documented in the ICD
157 157
158 158 // packet error control, CRC check
159 159 CCSDSContent = (unsigned char*) TMPacket->packetID;
160 160 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
161 161 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
162 162 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
163 163
164 164 return CCSDS_TM_VALID;
165 165 }
166 166
167 167 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
168 168 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
169 169 {
170 170 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
171 171 TMHeader->protocolIdentifier = 0x02;
172 172 TMHeader->reserved = 0x00;
173 173 TMHeader->userApplication = 0x00;
174 174 TMHeader->packetID[0] = 0x0c;
175 175 TMHeader->packetSequenceControl[0] = 0xc0;
176 176 TMHeader->packetSequenceControl[1] = 0x00;
177 177 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
178 178 TMHeader->packetLength[1] = (unsigned char) packetLength;
179 179 TMHeader->dataFieldHeader[0] = 0x10;
180 180 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
181 181 switch (tm_type){
182 182 case(TM_LFR_TC_EXE_OK):
183 183 TMHeader->packetID[1] = 0xc1;
184 184 TMHeader->dataFieldHeader[1] = 1; // type
185 185 TMHeader->dataFieldHeader[2] = 7; // subtype
186 186 break;
187 187 case(TM_LFR_TC_EXE_ERR):
188 188 TMHeader->packetID[1] = 0xc1;
189 189 TMHeader->dataFieldHeader[1] = 1; // type
190 190 TMHeader->dataFieldHeader[2] = 8; // subtype
191 191 break;
192 192 case(TM_LFR_HK):
193 193 TMHeader->packetID[1] = 0xc4;
194 194 TMHeader->dataFieldHeader[1] = 3; // type
195 195 TMHeader->dataFieldHeader[2] = 25; // subtype
196 196 break;
197 197 case(TM_LFR_SCI):
198 198 TMHeader->packetID[1] = 0xcc;
199 199 TMHeader->dataFieldHeader[1] = 21; // type
200 200 TMHeader->dataFieldHeader[2] = 3; // subtype
201 201 break;
202 202 case(TM_LFR_SCI_SBM):
203 203 TMHeader->packetID[1] = 0xfc;
204 204 TMHeader->dataFieldHeader[1] = 21; // type
205 205 TMHeader->dataFieldHeader[2] = 3; // subtype
206 206 break;
207 207 case(TM_LFR_PAR_DUMP):
208 208 TMHeader->packetID[1] = 0xc9;
209 209 TMHeader->dataFieldHeader[1] = 181; // type
210 210 TMHeader->dataFieldHeader[2] = 31; // subtype
211 211 break;
212 212 default:
213 213 return 0;
214 214 }
215 /*TMHeader->dataFieldHeader[4] = (unsigned char) (coarseTime>>24);
216 TMHeader->dataFieldHeader[5] = (unsigned char) (coarseTime>>16);
217 TMHeader->dataFieldHeader[6] = (unsigned char) (coarseTime>>8);
218 TMHeader->dataFieldHeader[7] = (unsigned char) (coarseTime);
219 TMHeader->dataFieldHeader[8] = (unsigned char) (fineTime>>8);
220 TMHeader->dataFieldHeader[9] = (unsigned char) (fineTime);*/
221 TMHeader->dataFieldHeader[4] = 0xaa;
222 TMHeader->dataFieldHeader[5] = 0xbb;
223 TMHeader->dataFieldHeader[6] = 0xcc;
224 TMHeader->dataFieldHeader[7] = 0xdd;
225 TMHeader->dataFieldHeader[8] = 0xee;
226 TMHeader->dataFieldHeader[9] = 0xff;
215 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
216 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
217 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
218 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
219 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
220 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
227 221 return 1;
228 222 }
229 223
230 224 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
231 225 {
232 226 unsigned int packetLength;
233 227 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
234 228 switch (SID){
235 229 case (SID_NOT_EXE):
236 230 break;
237 231 case (SID_NOT_IMP):
238 232 data[0] = 0x9c;
239 233 data[1] = 0x42;
240 234 data[2] = TC->packetID[0];
241 235 data[3] = TC->packetID[1];
242 236 data[4] = TC->packetSequenceControl[0];
243 237 data[5] = TC->packetSequenceControl[1];
244 238 data[6] = TC->dataFieldHeader[1]; // type
245 239 data[7] = TC->dataFieldHeader[2]; // subtype
246 240 break;
247 241 case (SID_EXE_ERR):
248 242 break;
249 243 case (SID_EXE_CORR):
250 244 data[0] = 0x9c;
251 245 data[1] = 0x45;
252 246 data[2] = TC->packetID[0];
253 247 data[3] = TC->packetID[1];
254 248 data[4] = TC->packetSequenceControl[0];
255 249 data[5] = TC->packetSequenceControl[1];
256 250 data[6] = TC->dataFieldHeader[1]; // type
257 251 data[7] = TC->dataFieldHeader[2]; // subtype
258 252 data[8] = currentTC_LEN_RCV[0];
259 253 data[9] = currentTC_LEN_RCV[1];
260 254 data[10] = TC->packetLength[0];
261 255 data[11] = TC->packetLength[1];
262 256 data[12] = TC->dataAndCRC[packetLength];
263 257 data[13] = TC->dataAndCRC[packetLength+1];
264 258 data[14] = computed_CRC[0];
265 259 data[15] = computed_CRC[1];
266 260 break;
267 261 default:
268 262 return 0;
269 263 }
270 264 return 1;
271 265 }
272 266
273 267 //***********
274 268 // RTEMS TASK
275 269 rtems_task recv_task( rtems_task_argument unused )
276 270 {
277 271 int len = 0;
278 272 unsigned int i = 0;
279 273 unsigned int data_length = 0;
280 274 ccsdsTelecommandPacket_t currentTC;
281 275 char data[100];
282 276
283 277 for(i=0; i<100; i++) data[i] = 0;
284 278
285 279 PRINTF("In RECV *** \n")
286 280
287 281 while(1)
288 282 {
289 283 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
290 284 if (len == -1){ // error during the read call
291 285 PRINTF("In RECV *** last read call returned -1\n")
292 286 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
293 287 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
294 288 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
295 289 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
296 290 }
297 291 else {
298 292 //PRINTF1("In RECV *** Got Message of length %d\n", len)
299 293 currentTC_LEN_RCV[0] = 0x00;
300 294 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
301 295 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
302 296 // CHECK THE TC AND BUILD THE APPROPRIATE TM
303 297 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
304 298 if (data_length!=-1)
305 299 {
306 300 }
307 301 }
308 302 }
309 303 }
310 304
311 305 rtems_task actn_task( rtems_task_argument unused )
312 306 {
307 int result = 0;
313 308 rtems_status_code status; // RTEMS status code
314 309 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
315 310 size_t size; // size of the incoming TC packet
316 311 unsigned char subtype = 0; // subtype of the current TC packet
317 312
313 PRINTF("In ACTN *** \n")
314
318 315 while(1)
319 316 {
320 317 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
321 318 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
322 319 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
323 320 else
324 321 {
325 322 subtype = TC.dataFieldHeader[2];
326 323 switch(subtype)
327 324 {
328 325 case TC_SUBTYPE_RESET:
329 break;
330 case TC_SUBTYPE_LOAD_COMM:
326 result = action_default( &TC );
331 327 break;
328 //
329 case TC_SUBTYPE_LOAD_COMM:
330 result = action_default( &TC );
331 break;
332 //
332 333 case TC_SUBTYPE_LOAD_NORM:
333 action_load_norm( &TC );
334 result = action_load_norm( &TC );
335 send_tm_lfr_tc_exe_success( &TC );
334 336 break;
337 //
335 338 case TC_SUBTYPE_LOAD_BURST:
339 result = action_default( &TC );
336 340 break;
341 //
337 342 case TC_SUBTYPE_LOAD_SBM1:
343 result = action_default( &TC );
338 344 break;
345 //
339 346 case TC_SUBTYPE_LOAD_SBM2:
347 result = action_default( &TC );
340 348 break;
349 //
341 350 case TC_SUBTYPE_DUMP:
342 action_default( &TC );
351 result = action_default( &TC );
343 352 break;
353 //
344 354 case TC_SUBTYPE_ENTER:
345 action_enter( &TC );
355 result = action_enter( &TC );
356 send_tm_lfr_tc_exe_success( &TC );
346 357 break;
358 //
347 359 case TC_SUBTYPE_UPDT_INFO:
360 result = action_default( &TC );
348 361 break;
362 //
349 363 case TC_SUBTYPE_EN_CAL:
364 result = action_default( &TC );
350 365 break;
366 //
351 367 case TC_SUBTYPE_DIS_CAL:
368 result = action_default( &TC );
352 369 break;
370 //
353 371 case TC_SUBTYPE_UPDT_TIME:
372 result = action_updt_time( &TC );
373 send_tm_lfr_tc_exe_success( &TC );
354 374 break;
375 //
355 376 default:
356 377 break;
357 378 }
358 379 }
359 380 }
360 381 }
361 382
362 383 int create_message_queue()
363 384 {
364 385 rtems_status_code status;
365 386 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
366 387 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
367 388 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
368 389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
369 390
370 391 return 0;
371 392 }
372 393
373 394 //***********
374 395 // TC ACTIONS
375 396 int action_default(ccsdsTelecommandPacket_t *TC)
376 397 {
377 398 char data[100]; // buffer for the generic TM packet
378 399 TMHeader_t TM_header; // TM header
379 400 spw_ioctl_pkt_send spw_ioctl_send; // structure to send the TM packet if any
380 401 // BUILD HEADER
381 402 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP, 0, 0, &TM_header);
382 403 // BUILD DATA
383 404 TM_build_data( TC, data, SID_NOT_IMP, NULL);
384 405 // filling the strture for the spcawire transmission
385 406 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
386 407 spw_ioctl_send.hdr = (char*) &TM_header;
387 spw_ioctl_send.dlen = TM_LEN_NOT_IMP + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN;
408 spw_ioctl_send.dlen = 8;
388 409 spw_ioctl_send.data = data;
389 410 // SEND DATA
390 411 write_spw(&spw_ioctl_send);
391 412
392 413 return 0;
393 414 }
394 415
395 416 int action_enter(ccsdsTelecommandPacket_t *TC)
396 417 {
418 unsigned char lfr_mode = TC->dataAndCRC[1];
419 printf("enter mode %d\n", lfr_mode);
420 switch(lfr_mode)
421 {
422 case(LFR_MODE_STANDBY):
423 LEON_Mask_interrupt( IRQ_WF );
424 LEON_Mask_interrupt( IRQ_SM );
425 break;
426 case(LFR_MODE_NORMAL):
427 LEON_Unmask_interrupt( IRQ_WF );
428 LEON_Unmask_interrupt( IRQ_SM );
429 break;
430 case(LFR_MODE_BURST):
431 break;
432 case(LFR_MODE_SBM1):
433 break;
434 case(LFR_MODE_SBM2):
435 break;
436 }
397 437 return 0;
398 438 }
399 439
400 440 int action_load_norm(ccsdsTelecommandPacket_t *TC)
401 441 {
402 442 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
403 443 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
404 444 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
405 445 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
406 446 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
407 printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
447 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
408 448 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
409 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);
449 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
450 return 0;
451 }
452
453 int action_updt_time(ccsdsTelecommandPacket_t *TC)
454 {
455 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
456 + (TC->dataAndCRC[1] << 16)
457 + (TC->dataAndCRC[2] << 8)
458 + TC->dataAndCRC[3];
459 time_management_regs->ctrl = time_management_regs->ctrl | 1;
460 return 0;
461 }
462
463 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
464 {
465 TMHeader_t TM_header;
466 char data[4];
467 spw_ioctl_pkt_send spw_ioctl_send;
468
469 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
470 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
471
472 data[0] = TC->packetID[0];
473 data[1] = TC->packetID[1];
474 data[2] = TC->packetSequenceControl[0];
475 data[3] = TC->packetSequenceControl[1];
476
477 // filling the structure for the spacewire transmission
478 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
479 spw_ioctl_send.hdr = (char*) &TM_header;
480 spw_ioctl_send.dlen = 3;
481 spw_ioctl_send.data = data;
482
483 // SEND DATA
484 write_spw(&spw_ioctl_send);
485
410 486 return 0;
411 487 }
412 488
413 489
414
@@ -1,113 +1,115
1 1 #include <wf_handler.h>
2 2
3 3 rtems_isr waveforms_isr( rtems_vector_number vector )
4 4 {
5 5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
6 6 printf("In spectral_matrices_isr *** Error sending event to WFRM\n");
7 7 }
8 8
9 9 rtems_task wfrm_task(rtems_task_argument argument)
10 10 {
11 11 unsigned int length;
12 12 unsigned int i = 0;
13 13 spw_ioctl_pkt_send spw_ioctl_send;
14 14 rtems_event_set event_out;
15 15 gptimer_regs_t *gptimer_regs;
16 16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
17 17 ExtendedTMHeader_t header;
18 18
19 19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
20 20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
21 21 header.reserved = 0x00;
22 22 header.userApplication = CCSDS_USER_APP;
23 23 header.packetID[0] = 0x0c;
24 24 header.packetID[1] = 0xcc;
25 25 header.packetSequenceControl[0] = 0x00;
26 26 header.packetSequenceControl[1] = 0x00;
27 27 header.packetLength[0] = 0x00;
28 28 header.packetLength[1] = 0x00;
29 29 header.dataFieldHeader[0] = 0x10;
30 30 header.dataFieldHeader[1] = 0x15; // service type
31 31 header.dataFieldHeader[2] = 0x03; // service subtype
32 32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
33 33 header.dataFieldHeader[4] = 0xaa;
34 34 header.dataFieldHeader[5] = 0xbb;
35 35 header.dataFieldHeader[6] = 0xcc;
36 36 header.dataFieldHeader[7] = 0xdd;
37 37 header.dataFieldHeader[8] = 0xee;
38 38 header.dataFieldHeader[9] = 0xff;
39 39
40 40 header.auxiliaryHeader[0] = 0x00;
41 41 header.auxiliaryHeader[1] = 0x1f;
42 42 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
43 43 header.auxiliaryHeader[3] = 0x00; // PKT_NR
44 44 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
45 45 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
46 46
47 47 // BUILD THE PACKET HEADER
48 48 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
49 49 spw_ioctl_send.hdr = (char*) &header;
50
51 PRINTF("In WFRM *** \n")
50 52
51 53 while(1){
52 54 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
53 55 for (i=0; i<7; i++) // send F0
54 56 {
55 57 // BUILD THE DATA
56 58 if (i==6) {
57 59 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
58 60 length = TM_LEN_SCI_NORM_SWF_340;
59 61 }
60 62 else {
61 63 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
62 64 length = TM_LEN_SCI_NORM_SWF_8;
63 65 }
64 66 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
65 67 // BUILD THE HEADER
66 68 header.packetLength[0] = (unsigned char) (length>>8);
67 69 header.packetLength[1] = (unsigned char) (length);
68 70 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
69 71 // SEND PACKET
70 72 write_spw(&spw_ioctl_send);
71 73 }
72 74 for (i=0; i<7; i++) // send F1
73 75 {
74 76 // BUILD THE DATA
75 77 if (i==6) {
76 78 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
77 79 length = TM_LEN_SCI_NORM_SWF_340;
78 80 }
79 81 else {
80 82 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
81 83 length = TM_LEN_SCI_NORM_SWF_8;
82 84 }
83 85 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
84 86 // BUILD THE HEADER
85 87 header.packetLength[0] = (unsigned char) (length>>8);
86 88 header.packetLength[1] = (unsigned char) (length);
87 89 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
88 90 // SEND PACKET
89 91 write_spw(&spw_ioctl_send);
90 92 }
91 93 for (i=0; i<7; i++) // send F0
92 94 {
93 95 // BUILD THE DATA
94 96 if (i==6) {
95 97 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
96 98 length = TM_LEN_SCI_NORM_SWF_340;
97 99 }
98 100 else {
99 101 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
100 102 length = TM_LEN_SCI_NORM_SWF_8;
101 103 }
102 104 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
103 105 // BUILD THE HEADER
104 106 header.packetLength[0] = (unsigned char) (length>>8);
105 107 header.packetLength[1] = (unsigned char) (length);
106 108 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
107 109 // SEND PACKET
108 110 write_spw(&spw_ioctl_send);
109 111 }
110 112 // irq processed, reset the related register of the timer unit
111 113 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
112 114 }
113 115 }
General Comments 0
You need to be logged in to leave comments. Login now