##// END OF EJS Templates
Fusion avec No PWD scrub with FPU
jeandet -
r392:75028d90a6e7 merge R3++ draft
parent child
Show More
@@ -0,0 +1,4
1 3236b2a1a6a04bc11754d3f995873876b5046183 3.2.0.17
2 ad411bb94578a052d1b4aa6b4c8a769fe2711072 3.2.0.18
3 a9b894b0ab6a8fa48f50ce3dd7200406b83e2a62 3.2.0.19
4 bd1252670981361939ed2a1c3febc94247019956 3.2.0.20
@@ -0,0 +1,17
1 cmake_minimum_required(VERSION 3.6)
2 project(libgcov C)
3 include(sparc-rtems)
4 include(cppcheck)
5
6 set(LIB_GCOV_SOURCES
7 gcov-io.c
8 gcov-io.h
9 gcov-iov.h
10 libgcov.c
11 )
12
13 add_library(gcov STATIC ${LIB_GCOV_SOURCES})
14
15 add_custom_target(gcovr
16 COMMAND gcovr --exclude='.*gcov.*' --gcov-executable=${rtems_dir}/bin/sparc-rtems-gcov --object-directory ${CMAKE_BINARY_DIR} -r ${CMAKE_SOURCE_DIR} --html --html-details -o ${CMAKE_CURRENT_BINARY_DIR}/gcov.html && xdg-open ${CMAKE_CURRENT_BINARY_DIR}/gcov.html
17 )
@@ -0,0 +1,41
1 #!/usr/bin/env python3
2
3 __author__ = "Alexis Jeandet"
4 __copyright__ = "Copyright 2018, Laboratory of Plasma Physics"
5 __credits__ = []
6 __license__ = "GPLv2"
7 __version__ = "1.0.0"
8 __maintainer__ = "Alexis Jeandet"
9 __email__ = "alexis.jeandet@member.fsf.org"
10 __status__ = "Development"
11
12 import time
13 import sys
14 import os
15 import serial
16 import argparse
17 from datetime import datetime
18
19 parser = argparse.ArgumentParser()
20 parser.add_argument("-f", "--gcov-file", help="Gcov output file generated by record_lfr_console.py")
21 args = parser.parse_args()
22
23
24
25 def main():
26 with open(args.gcov_file,'r') as gcov:
27 files = []
28 for line in gcov.readlines():
29 head,dest_file,data = line.split(',')
30 if dest_file not in files:
31 files.append(dest_file)
32 if head == '_GCOV_':
33 print(f"Writing {dest_file}\n")
34 with open(dest_file,'wb') as gcda_file:
35 gcda_file.write(bytes([int(''.join(value),16) for value in zip(data[::2],data[1::2]) ]))
36 else:
37 raise
38
39
40 if __name__ == "__main__":
41 main()
@@ -0,0 +1,488
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 //#if ( ( __GNUC__ > 3 ) || \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 // ( ( __GNUC__ < 4 ) || \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 /*
9 * =====================================================================================
10 *
11 * Filename: gcov-io.c
12 *
13 * Description: This is the I/O file for embedded systems
14 *
15 * Version: 1.0
16 * Created: 03/04/08 09:51:59
17 * Revision: none
18 * Compiler: gcc
19 *
20 * Author: Aitor Viana Sanchez (avs), aitor.viana.sanchez@esa.int
21 * Company: European Space Agency (ESA-ESTEC)
22 *
23 * =====================================================================================
24 */
25
26 /* File format for coverage information
27 Copyright (C) 1996, 1997, 1998, 2000, 2002,
28 2003 Free Software Foundation, Inc.
29 Contributed by Bob Manson <manson@cygnus.com>.
30 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
31
32 This file is part of GCC.
33
34 GCC is free software; you can redistribute it and/or modify it under
35 the terms of the GNU General Public License as published by the Free
36 Software Foundation; either version 2, or (at your option) any later
37 version.
38
39 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
40 WARRANTY; without even the implied warranty of MERCHANTABILITY or
41 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42 for more details.
43
44 You should have received a copy of the GNU General Public License
45 along with GCC; see the file COPYING. If not, write to the Free
46 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
47 02111-1307, USA. */
48
49 #include <stdio.h>
50 #include <stdlib.h> /* for atexit() */
51 #include <string.h>
52 #include "gcov-io.h"
53
54 /* Routines declared in gcov-io.h. This file should be #included by
55 another source file, after having #included gcov-io.h. */
56
57
58 /* This function shall be defined somewhere else */
59 //int send_data(unsigned char * buffer, unsigned int size);
60
61 /*-----------------------------------------------------------------------------
62 * PRIVATE INTERFACE
63 *-----------------------------------------------------------------------------*/
64
65 static void gcov_write_block (unsigned);
66 static gcov_unsigned_t *gcov_write_words (unsigned);
67 GCOV_LINKAGE int gcov_send (void);
68 GCOV_LINKAGE int gcov_close(void);
69
70 extern struct gcov_info * gcov_list;
71 extern gcov_unsigned_t gcov_crc32;
72
73 int dev_id = 0;
74
75 /*
76 * === FUNCTION ======================================================================
77 * Name: from_file
78 * Description: This function just return the given parameter
79 * =====================================================================================
80 */
81 static inline gcov_unsigned_t from_file (gcov_unsigned_t value)
82 {
83 return value;
84 }
85
86 /*
87 * === FUNCTION ======================================================================
88 * Name: gcov_version
89 * Description: This function returns TRUE (1) if the gcov version is the
90 * version expected. The function returns FALSE (0) in any other case.
91 * =====================================================================================
92 */
93 static int gcov_version (struct gcov_info *ptr, gcov_unsigned_t version)
94 {
95 if (version != GCOV_VERSION)
96 {
97 char v[4], e[4];
98
99 GCOV_UNSIGNED2STRING (v, version);
100 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
101
102 printf ("profiling:%s:Version mismatch - expected %.4s got %.4s\n",
103 ptr->filename, e, v);
104
105 return 0;
106 }
107 return 1;
108 }
109
110
111 /*-----------------------------------------------------------------------------
112 * PUBLIC INTERFACE
113 *-----------------------------------------------------------------------------*/
114
115 /* Dump the coverage counts. We merge with existing counts when
116 possible, to avoid growing the .da files ad infinitum. We use this
117 program's checksum to make sure we only accumulate whole program
118 statistics to the correct summary. An object file might be embedded
119 in two separate programs, and we must keep the two program
120 summaries separate. */
121
122 /*
123 * === FUNCTION ======================================================================
124 * Name: gcov_exit
125 * Description: This function dumps the coverage couns. The merging with
126 * existing counts is not done in embedded systems.
127 * =====================================================================================
128 */
129 void gcov_exit (void)
130 {
131 struct gcov_info *gi_ptr;
132 struct gcov_summary this_program;
133 struct gcov_summary all;
134 struct gcov_ctr_summary *cs_ptr;
135 const struct gcov_ctr_info *ci_ptr;
136 unsigned t_ix;
137 gcov_unsigned_t c_num;
138 unsigned long coreId = 0;
139
140 /* retrieve the id of the CPU the program is running on */
141 #ifdef LEON3
142 __asm__ __volatile__("rd %%asr17,%0\n\t"
143 "srl %0,28,%0" :
144 "=&r" (coreId) : );
145 #endif
146
147 printf("_GCOVEXIT_BEGIN_,core%d\n", coreId); /* see also _GCOVEXIT_END_ */
148
149 if(gcov_list == (void*)0x0)
150 printf("%s: gcov_list == NULL\n", __func__);
151
152 memset (&all, 0, sizeof (all));
153 /* Find the totals for this execution. */
154 memset (&this_program, 0, sizeof (this_program));
155 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
156 {
157
158 ci_ptr = gi_ptr->counts;
159 for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++)
160 {
161 if (!((1 << t_ix) & gi_ptr->ctr_mask))
162 continue;
163
164 cs_ptr = &this_program.ctrs[t_ix];
165 cs_ptr->num += ci_ptr->num;
166 for (c_num = 0; c_num < ci_ptr->num; c_num++)
167 {
168 cs_ptr->sum_all += ci_ptr->values[c_num];
169 if (cs_ptr->run_max < ci_ptr->values[c_num])
170 cs_ptr->run_max = ci_ptr->values[c_num];
171 }
172 ci_ptr++;
173 }
174 }
175 /* Now merge each file. */
176 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
177 {
178
179 struct gcov_summary program;
180 gcov_type *values[GCOV_COUNTERS];
181 const struct gcov_fn_info *fi_ptr;
182 unsigned fi_stride;
183 unsigned c_ix, f_ix, n_counts;
184
185 c_ix = 0;
186 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
187 if ((1 << t_ix) & gi_ptr->ctr_mask)
188 {
189 values[c_ix] = gi_ptr->counts[c_ix].values;
190 c_ix++;
191 }
192
193 /* Calculate the function_info stride. This depends on the
194 number of counter types being measured. */
195 fi_stride = sizeof (struct gcov_fn_info) + c_ix * sizeof (unsigned);
196 if (__alignof__ (struct gcov_fn_info) > sizeof (unsigned))
197 {
198 fi_stride += __alignof__ (struct gcov_fn_info) - 1;
199 fi_stride &= ~(__alignof__ (struct gcov_fn_info) - 1);
200 }
201
202 if (!gcov_open (gi_ptr->filename))
203 {
204 printf ("profiling:%s:Cannot open\n", gi_ptr->filename);
205 continue;
206 }
207
208 program.checksum = gcov_crc32;
209
210 /* Write out the data. */
211 gcov_write_tag_length (GCOV_DATA_MAGIC, GCOV_VERSION);
212 gcov_write_unsigned (gi_ptr->stamp);
213
214 /* Write execution counts for each function. */
215 for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
216 {
217 fi_ptr = (const struct gcov_fn_info *)
218 ((const char *) gi_ptr->functions + f_ix * fi_stride);
219
220 /* Announce function. */
221 gcov_write_tag_length (GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH);
222 gcov_write_unsigned (fi_ptr->ident);
223 gcov_write_unsigned (fi_ptr->checksum);
224
225 c_ix = 0;
226 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
227 {
228 gcov_type *c_ptr;
229
230 if (!((1 << t_ix) & gi_ptr->ctr_mask))
231 continue;
232
233 n_counts = fi_ptr->n_ctrs[c_ix];
234
235 gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix),
236 GCOV_TAG_COUNTER_LENGTH (n_counts));
237 c_ptr = values[c_ix];
238 while (n_counts--)
239 gcov_write_counter (*c_ptr++);
240
241 values[c_ix] = c_ptr;
242 c_ix++;
243 }
244 }
245
246 gcov_send();
247 gcov_close();
248
249 }
250
251 printf("_GCOVEXIT_END_,core%d\n", coreId);
252 }
253
254
255 /* Called before fork or exec - write out profile information gathered so
256 far and reset it to zero. This avoids duplication or loss of the
257 profile information gathered so far. */
258
259 void
260 __gcov_flush (void)
261 {
262 const struct gcov_info *gi_ptr;
263
264 gcov_exit ();
265 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
266 {
267 unsigned t_ix;
268 const struct gcov_ctr_info *ci_ptr;
269
270 for (t_ix = 0, ci_ptr = gi_ptr->counts; t_ix != GCOV_COUNTERS; t_ix++)
271 if ((1 << t_ix) & gi_ptr->ctr_mask)
272 {
273 memset (ci_ptr->values, 0, sizeof (gcov_type) * ci_ptr->num);
274 ci_ptr++;
275 }
276 }
277 }
278
279
280
281 /* Open a gcov file. NAME is the name of the file to open and MODE
282 indicates whether a new file should be created, or an existing file
283 opened for modification. If MODE is >= 0 an existing file will be
284 opened, if possible, and if MODE is <= 0, a new file will be
285 created. Use MODE=0 to attempt to reopen an existing file and then
286 fall back on creating a new one. Return zero on failure, >0 on
287 opening an existing file and <0 on creating a new one. */
288 GCOV_LINKAGE int gcov_open(const char *name)
289 {
290 // gcov_var.start is cleared in the gcov_close function.
291 // If this variable is not cleared...ERROR
292 if( gcov_var.start != 0 )
293 return 0;
294
295 // Clear everything
296 gcov_var.start = 0;
297 gcov_var.offset = gcov_var.length = 0;
298 gcov_var.overread = -1u;
299 gcov_var.error = 0;
300
301
302 // copy the filename in the gcov_var structure
303 strcpy(gcov_var.filename, name);
304
305
306 // return 1 means everything is OK
307 return 1;
308 }
309
310 /* Close the current gcov file. Flushes data to disk. Returns nonzero
311 on failure or error flag set. */
312
313 GCOV_LINKAGE int gcov_send (void)
314 {
315 /*printf("%s: file %s\n", __func__, gcov_var.filename);*/
316 if (gcov_var.offset)
317 gcov_write_block (gcov_var.offset);
318
319 gcov_var.length = 0;
320 return gcov_var.error;
321 }
322
323 GCOV_LINKAGE int gcov_close(void)
324 {
325 memset(gcov_var.filename, 0, strlen(gcov_var.filename));
326
327 // Clear the start variable because will be tested in the gcov_open
328 // function
329 gcov_var.start = 0;
330
331 // Return the error, not sure whether the error is modifed.
332 return gcov_var.error;
333 }
334
335
336 static void gcov_write_block (unsigned size) {
337 unsigned char *buffer = (unsigned char*) gcov_var.buffer;
338 unsigned int i;
339
340 printf("_GCOV_,%s,", gcov_var.filename);
341 /* to speed up the printing process, we display bytes 4 by 4 */
342 for(i = 0; i < size; i++) {
343 printf("%02X%02X%02X%02X", (unsigned int)(buffer[0]),
344 (unsigned int)(buffer[1]),
345 (unsigned int)(buffer[2]),
346 (unsigned int)(buffer[3]));
347
348 buffer += sizeof(gcov_unsigned_t);
349 }
350 printf("\n");
351
352 gcov_var.start += size;
353 gcov_var.offset -= size;
354 }
355
356 /* Allocate space to write BYTES bytes to the gcov file. Return a
357 pointer to those bytes, or NULL on failure. */
358
359 static gcov_unsigned_t *gcov_write_words (unsigned words) {
360 gcov_unsigned_t *result;
361
362 GCOV_CHECK_WRITING ();
363 if (gcov_var.offset >= GCOV_BLOCK_SIZE)
364 {
365 gcov_write_block (GCOV_BLOCK_SIZE);
366 if (gcov_var.offset)
367 {
368 GCOV_CHECK (gcov_var.offset == 1);
369 memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4);
370 }
371 }
372 result = &gcov_var.buffer[gcov_var.offset];
373 gcov_var.offset += words;
374
375 return result;
376 }
377
378 /* Write unsigned VALUE to coverage file. Sets error flag
379 appropriately. */
380
381 GCOV_LINKAGE void
382 gcov_write_unsigned (gcov_unsigned_t value)
383 {
384 gcov_unsigned_t *buffer = gcov_write_words (1);
385
386 buffer[0] = value;
387 }
388
389 /* Write counter VALUE to coverage file. Sets error flag
390 appropriately. */
391
392 GCOV_LINKAGE void
393 gcov_write_counter (gcov_type value)
394 {
395 gcov_unsigned_t *buffer = gcov_write_words (2);
396
397 buffer[0] = (gcov_unsigned_t) value;
398 if (sizeof (value) > sizeof (gcov_unsigned_t))
399 buffer[1] = (gcov_unsigned_t) (value >> 32);
400 else
401 buffer[1] = 0;
402
403 }
404
405 /* Write a tag TAG and length LENGTH. */
406
407 GCOV_LINKAGE void
408 gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t length)
409 {
410 gcov_unsigned_t *buffer = gcov_write_words (2);
411
412 buffer[0] = tag;
413 buffer[1] = length;
414 }
415
416 /* Write a summary structure to the gcov file. Return nonzero on
417 overflow. */
418
419 GCOV_LINKAGE void
420 gcov_write_summary (gcov_unsigned_t tag, const struct gcov_summary *summary)
421 {
422 unsigned ix;
423 const struct gcov_ctr_summary *csum;
424
425 gcov_write_tag_length (tag, GCOV_TAG_SUMMARY_LENGTH);
426 gcov_write_unsigned (summary->checksum);
427 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
428 {
429 gcov_write_unsigned (csum->num);
430 gcov_write_unsigned (csum->runs);
431 gcov_write_counter (csum->sum_all);
432 gcov_write_counter (csum->run_max);
433 gcov_write_counter (csum->sum_max);
434 }
435 }
436
437 GCOV_LINKAGE gcov_type
438 gcov_read_counter (void)
439 {
440 return 0;
441 }
442
443 /* Add a new object file onto the bb chain. Invoked automatically
444 when running an object file's global ctors. */
445
446 void
447 __gcov_init (struct gcov_info *info)
448 {
449 if (!info->version)
450 return;
451 if (gcov_version (info, info->version))
452 {
453 const char *ptr = info->filename;
454 gcov_unsigned_t crc32 = gcov_crc32;
455
456 /* Added by LESIA*/
457 printf("Covered file: %s\n", info->filename);
458 /* End of Added by LESIA*/
459
460 do
461 {
462 unsigned ix;
463 gcov_unsigned_t value = *ptr << 24;
464
465 for (ix = 8; ix--; value <<= 1)
466 {
467 gcov_unsigned_t feedback;
468
469 feedback = (value ^ crc32) & 0x80000000 ? 0x04c11db7 : 0;
470 crc32 <<= 1;
471 crc32 ^= feedback;
472 }
473 }
474 while (*ptr++);
475
476 gcov_crc32 = crc32;
477
478 if (!gcov_list)
479 atexit (gcov_exit);
480
481 info->next = gcov_list;
482 gcov_list = info;
483 }
484 else
485 printf("%s: Version mismatch\n", "WARNING");
486 info->version = 0;
487 }
488 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -0,0 +1,485
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 //#if ( ( __GNUC__ > 3 ) || \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 // ( ( __GNUC__ < 4 ) || \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 //#include <stdlib.h>
9 //#include <stdio.h>
10 /* File format for coverage information
11 Copyright (C) 1996, 1997, 1998, 2000, 2002,
12 2003, 2004 Free Software Foundation, Inc.
13 Contributed by Bob Manson <manson@cygnus.com>.
14 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
15
16 This file is part of GCC.
17
18 GCC is free software; you can redistribute it and/or modify it under
19 the terms of the GNU General Public License as published by the Free
20 Software Foundation; either version 2, or (at your option) any later
21 version.
22
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING. If not, write to the Free
30 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 02111-1307, USA. */
32
33 /* As a special exception, if you link this library with other files,
34 some of which are compiled with GCC, to produce an executable,
35 this library does not by itself cause the resulting executable
36 to be covered by the GNU General Public License.
37 This exception does not however invalidate any other reasons why
38 the executable file might be covered by the GNU General Public License. */
39
40 /* Coverage information is held in two files. A notes file, which is
41 generated by the compiler, and a data file, which is generated
42 by the program under test. Both files use a similar structure. We
43 do not attempt to make these files backwards compatible with
44 previous versions, as you only need coverage information when
45 developing a program. We do hold version information, so that
46 mismatches can be detected, and we use a format that allows tools
47 to skip information they do not understand or are not interested
48 in.
49
50 Numbers are recorded in the 32 bit unsigned binary form of the
51 endianness of the machine generating the file. 64 bit numbers are
52 stored as two 32 bit numbers, the low part first. Strings are
53 padded with 1 to 4 NUL bytes, to bring the length up to a multiple
54 of 4. The number of 4 bytes is stored, followed by the padded
55 string. Zero length and NULL strings are simply stored as
56 a length of zero (they have no trailing NUL or padding).
57
58 int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3
59 int64: int32:low int32:high
60 string: int32:0 | int32:length char* char:0 padding
61 padding: | char:0 | char:0 char:0 | char:0 char:0 char:0
62 item: int32 | int64 | string
63
64 The basic format of the files is
65
66 file : int32:magic int32:version int32:stamp record*
67
68 The magic ident is different for the notes and the data files. The
69 magic ident is used to determine the endianness of the file, when
70 reading. The version is the same for both files and is derived
71 from gcc's version number. The stamp value is used to synchronize
72 note and data files and to synchronize merging within a data
73 file. It need not be an absolute time stamp, merely a ticker that
74 increments fast enough and cycles slow enough to distinguish
75 different compile/run/compile cycles.
76
77 Although the ident and version are formally 32 bit numbers, they
78 are derived from 4 character ASCII strings. The version number
79 consists of the single character major version number, a two
80 character minor version number (leading zero for versions less than
81 10), and a single character indicating the status of the release.
82 That will be 'e' experimental, 'p' prerelease and 'r' for release.
83 Because, by good fortune, these are in alphabetical order, string
84 collating can be used to compare version strings. Be aware that
85 the 'e' designation will (naturally) be unstable and might be
86 incompatible with itself. For gcc 3.4 experimental, it would be
87 '304e' (0x33303465). When the major version reaches 10, the
88 letters A-Z will be used. Assuming minor increments releases every
89 6 months, we have to make a major increment every 50 years.
90 Assuming major increments releases every 5 years, we're ok for the
91 next 155 years -- good enough for me.
92
93 A record has a tag, length and variable amount of data.
94
95 record: header data
96 header: int32:tag int32:length
97 data: item*
98
99 Records are not nested, but there is a record hierarchy. Tag
100 numbers reflect this hierarchy. Tags are unique across note and
101 data files. Some record types have a varying amount of data. The
102 LENGTH is the number of 4bytes that follow and is usually used to
103 determine how much data. The tag value is split into 4 8-bit
104 fields, one for each of four possible levels. The most significant
105 is allocated first. Unused levels are zero. Active levels are
106 odd-valued, so that the LSB of the level is one. A sub-level
107 incorporates the values of its superlevels. This formatting allows
108 you to determine the tag hierarchy, without understanding the tags
109 themselves, and is similar to the standard section numbering used
110 in technical documents. Level values [1..3f] are used for common
111 tags, values [41..9f] for the notes file and [a1..ff] for the data
112 file.
113
114 The basic block graph file contains the following records
115 note: unit function-graph*
116 unit: header int32:checksum string:source
117 function-graph: announce_function basic_blocks {arcs | lines}*
118 announce_function: header int32:ident int32:checksum
119 string:name string:source int32:lineno
120 basic_block: header int32:flags*
121 arcs: header int32:block_no arc*
122 arc: int32:dest_block int32:flags
123 lines: header int32:block_no line*
124 int32:0 string:NULL
125 line: int32:line_no | int32:0 string:filename
126
127 The BASIC_BLOCK record holds per-bb flags. The number of blocks
128 can be inferred from its data length. There is one ARCS record per
129 basic block. The number of arcs from a bb is implicit from the
130 data length. It enumerates the destination bb and per-arc flags.
131 There is one LINES record per basic block, it enumerates the source
132 lines which belong to that basic block. Source file names are
133 introduced by a line number of 0, following lines are from the new
134 source file. The initial source file for the function is NULL, but
135 the current source file should be remembered from one LINES record
136 to the next. The end of a block is indicated by an empty filename
137 - this does not reset the current source file. Note there is no
138 ordering of the ARCS and LINES records: they may be in any order,
139 interleaved in any manner. The current filename follows the order
140 the LINES records are stored in the file, *not* the ordering of the
141 blocks they are for.
142
143 The data file contains the following records.
144 data: {unit function-data* summary:object summary:program*}*
145 unit: header int32:checksum
146 function-data: announce_function arc_counts
147 announce_function: header int32:ident int32:checksum
148 arc_counts: header int64:count*
149 summary: int32:checksum {count-summary}GCOV_COUNTERS
150 count-summary: int32:num int32:runs int64:sum
151 int64:max int64:sum_max
152
153 The ANNOUNCE_FUNCTION record is the same as that in the note file,
154 but without the source location. The ARC_COUNTS gives the counter
155 values for those arcs that are instrumented. The SUMMARY records
156 give information about the whole object file and about the whole
157 program. The checksum is used for whole program summaries, and
158 disambiguates different programs which include the same
159 instrumented object file. There may be several program summaries,
160 each with a unique checksum. The object summary's checksum is zero.
161 Note that the data file might contain information from several runs
162 concatenated, or the data might be merged.
163
164 This file is included by both the compiler, gcov tools and the
165 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to
166 distinguish which case is which. If IN_LIBGCOV is nonzero,
167 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are
168 being built. Otherwise the compiler is being built. IN_GCOV may be
169 positive or negative. If positive, we are compiling a tool that
170 requires additional functions (see the code for knowledge of what
171 those functions are). */
172
173 #ifndef GCC_GCOV_IO_H
174 #define GCC_GCOV_IO_H
175
176 typedef unsigned int gcov_unsigned_t;
177 typedef unsigned int gcov_position_t;
178
179 typedef unsigned long long gcov_type;
180
181 /* No tengo ni idea de que es el SETLKW, asi que de momento el target
182 * no tiene de eso */
183
184 //#if defined (TARGET_HAS_F_SETLKW)
185 //#define GCOV_LOCKED 1
186 //#else
187 #define GCOV_LOCKED 0
188 //#endif
189 //#endif
190
191
192
193 /* In gcov we want function linkage to be static. In the compiler we want
194 it extern, so that they can be accessed from elsewhere. In libgcov we
195 need these functions to be extern, so prefix them with __gcov. In
196 libgcov they must also be hidden so that the instance in the executable
197 is not also used in a DSO. */
198
199 #define gcov_var __gcov_var
200 #define gcov_open __gcov_open
201 #define gcov_close __gcov_close
202 #define gcov_write_tag_length __gcov_write_tag_length
203 #define gcov_position __gcov_position
204 #define gcov_seek __gcov_seek
205 #define gcov_rewrite __gcov_rewrite
206 #define gcov_is_error __gcov_is_error
207 #define gcov_is_eof __gcov_is_eof
208 #define gcov_write_unsigned __gcov_write_unsigned
209 #define gcov_write_counter __gcov_write_counter
210 #define gcov_write_summary __gcov_write_summary
211 #define gcov_read_unsigned __gcov_read_unsigned
212 #define gcov_read_counter __gcov_read_counter
213 #define gcov_read_summary __gcov_read_summary
214
215 /* Esto no tengo ni repajolera idea de para que vale */
216
217 /* Poison these, so they don't accidentally slip in. */
218 //#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
219 //#pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic
220
221 #ifdef HAVE_GAS_HIDDEN
222 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
223 #else
224 #define ATTRIBUTE_HIDDEN
225 #endif
226
227 #ifndef GCOV_LINKAGE
228 #define GCOV_LINKAGE extern
229 //#define GCOV_LINKAGE
230 #endif
231
232 /* File suffixes. */
233 #define GCOV_DATA_SUFFIX ".gcda"
234 #define GCOV_NOTE_SUFFIX ".gcno"
235
236 /* File magic. Must not be palindromes. */
237 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
238 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
239
240 /* gcov-iov.h is automatically generated by the makefile from
241 version.c, it looks like
242 #define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
243 */
244 #include "gcov-iov.h"
245
246 /* Convert a magic or version number to a 4 character string. */
247 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \
248 ((ARRAY)[0] = (char)((VALUE) >> 24), \
249 (ARRAY)[1] = (char)((VALUE) >> 16), \
250 (ARRAY)[2] = (char)((VALUE) >> 8), \
251 (ARRAY)[3] = (char)((VALUE) >> 0))
252
253 /* The record tags. Values [1..3f] are for tags which may be in either
254 file. Values [41..9f] for those in the note file and [a1..ff] for
255 the data file. */
256
257 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
258 #define GCOV_TAG_FUNCTION_LENGTH (2)
259 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000)
260 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM)
261 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH)
262 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000)
263 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2)
264 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2)
265 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000)
266 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000)
267 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2)
268 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2)
269 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000)
270 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000)
271 #define GCOV_TAG_SUMMARY_LENGTH \
272 (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2))
273
274 /* Counters that are collected. */
275 #define GCOV_COUNTER_ARCS 0 /* Arc transitions. */
276 #define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be
277 summaried. */
278 #define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value
279 profiling. They must form a consecutive
280 interval and their order must match
281 the order of HIST_TYPEs in
282 value-prof.h. */
283 #define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */
284 #define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm
285 of a value. */
286 #define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */
287 #define GCOV_COUNTER_V_DELTA 4 /* The most common difference between
288 consecutive values of expression. */
289 #define GCOV_LAST_VALUE_COUNTER 4 /* The last of counters used for value
290 profiling. */
291 #define GCOV_COUNTERS 5
292
293 /* Number of counters used for value profiling. */
294 #define GCOV_N_VALUE_COUNTERS \
295 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
296
297 /* A list of human readable names of the counters */
298 #define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", "delta"}
299
300 /* Names of merge functions for counters. */
301 #define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \
302 "__gcov_merge_add", \
303 "__gcov_merge_add", \
304 "__gcov_merge_single", \
305 "__gcov_merge_delta"}
306
307 /* Convert a counter index to a tag. */
308 #define GCOV_TAG_FOR_COUNTER(COUNT) \
309 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
310 /* Convert a tag to a counter. */
311 #define GCOV_COUNTER_FOR_TAG(TAG) \
312 ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17))
313 /* Check whether a tag is a counter tag. */
314 #define GCOV_TAG_IS_COUNTER(TAG) \
315 (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS)
316
317 /* The tag level mask has 1's in the position of the inner levels, &
318 the lsb of the current level, and zero on the current and outer
319 levels. */
320 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG))
321
322 /* Return nonzero if SUB is an immediate subtag of TAG. */
323 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \
324 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \
325 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG)))
326
327 /* Return nonzero if SUB is at a sublevel to TAG. */
328 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \
329 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
330
331 /* Basic block flags. */
332 #define GCOV_BLOCK_UNEXPECTED (1 << 1)
333
334 /* Arc flags. */
335 #define GCOV_ARC_ON_TREE (1 << 0)
336 #define GCOV_ARC_FAKE (1 << 1)
337 #define GCOV_ARC_FALLTHROUGH (1 << 2)
338
339 /* Structured records. */
340
341 /* Cumulative counter data. */
342 struct gcov_ctr_summary
343 {
344 gcov_unsigned_t num; /* number of counters. */
345 gcov_unsigned_t runs; /* number of program runs */
346 gcov_type sum_all; /* sum of all counters accumulated. */
347 gcov_type run_max; /* maximum value on a single run. */
348 gcov_type sum_max; /* sum of individual run max values. */
349 };
350
351
352 /* Object & program summary record. */
353 struct gcov_summary
354 {
355 gcov_unsigned_t checksum; /* checksum of program */
356 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE];
357 };
358
359 /* Structures embedded in coveraged program. The structures generated
360 by write_profile must match these. */
361
362 /* Information about a single function. This uses the trailing array
363 idiom. The number of counters is determined from the counter_mask
364 in gcov_info. We hold an array of function info, so have to
365 explicitly calculate the correct array stride. */
366 struct gcov_fn_info
367 {
368 gcov_unsigned_t ident; /* unique ident of function */
369 gcov_unsigned_t checksum; /* function checksum */
370 unsigned n_ctrs[0]; /* instrumented counters */
371 };
372
373 /* Type of function used to merge counters. */
374 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
375
376 /* Information about counters. */
377 struct gcov_ctr_info
378 {
379 gcov_unsigned_t num; /* number of counters. */
380 gcov_type *values; /* their values. */
381 gcov_merge_fn merge; /* The function used to merge them. */
382 };
383
384 /* Information about a single object file. */
385 struct gcov_info
386 {
387 gcov_unsigned_t version; /* expected version number */
388 struct gcov_info *next; /* link to next, used by libgcov */
389
390 gcov_unsigned_t stamp; /* uniquifying time stamp */
391 const char *filename; /* output file name */
392
393 unsigned n_functions; /* number of functions */
394 const struct gcov_fn_info *functions; /* table of functions */
395
396 unsigned ctr_mask; /* mask of counters instrumented. */
397 struct gcov_ctr_info counts[0]; /* count data. The number of bits
398 set in the ctr_mask field
399 determines how big this array
400 is. */
401 };
402
403 /* Register a new object file module. */
404 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
405
406 /* Called before fork, to avoid double counting. */
407 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
408
409 /* The merge function that just sums the counters. */
410 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
411
412 /* The merge function to choose the most common value. */
413 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
414
415 /* The merge function to choose the most common difference between
416 consecutive values. */
417 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
418
419 /* Optimum number of gcov_unsigned_t's read from or written to disk. */
420 // We limit GCOV_BLOCK_SIZE to 512 unsigned long because post processing with
421 // DOS batch cannot handle command lines bigger than 8191 characters, knowing
422 // that for each char, we print 4 characters (e.g "\x00")
423 #define GCOV_BLOCK_SIZE (1 << 11)
424 #define MAXFILENAME (1024)
425
426 GCOV_LINKAGE struct gcov_var
427 {
428 // FILE *file;
429 char filename[MAXFILENAME];
430 gcov_position_t start; /* Position of first byte of block */
431 unsigned offset; /* Read/write position within the block. */
432 unsigned length; /* Read limit in the block. */
433 unsigned overread; /* Number of words overread. */
434 int error; /* < 0 overflow, > 0 disk error. */
435 /* Holds one block plus 4 bytes, thus all coverage reads & writes
436 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
437 to and from the disk. libgcov never backtracks and only writes 4
438 or 8 byte objects. */
439 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
440 } gcov_var ATTRIBUTE_HIDDEN;
441
442 #if 1
443 /* Functions for reading and writing gcov files. In libgcov you can
444 open the file for reading then writing. Elsewhere you can open the
445 file either for reading or for writing. When reading a file you may
446 use the gcov_read_* functions, gcov_sync, gcov_position, &
447 gcov_error. When writing a file you may use the gcov_write
448 functions, gcov_seek & gcov_error. When a file is to be rewritten
449 you use the functions for reading, then gcov_rewrite then the
450 functions for writing. Your file may become corrupted if you break
451 these invariants. */
452 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
453 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN;
454
455 /* Available everywhere. */
456 /* static gcov_position_t gcov_position (void);
457 * static int gcov_is_error (void);
458 * static int gcov_is_eof (void);
459 */
460
461 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN;
462 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN;
463 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN;
464 #endif
465 /* Available only in libgcov */
466 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
467 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t,
468 gcov_unsigned_t) ATTRIBUTE_HIDDEN;
469 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
470 const struct gcov_summary *) ATTRIBUTE_HIDDEN;
471
472 /* Available outside gcov */
473 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN;
474
475 /* Make sure the library is used correctly. */
476 #if ENABLE_CHECKING
477 #define GCOV_CHECK(expr) ((expr) ? (void)0 : (void)abort ())
478 #else
479 #define GCOV_CHECK(expr)
480 #endif
481 #define GCOV_CHECK_READING() GCOV_CHECK(gcov_var.mode > 0)
482 #define GCOV_CHECK_WRITING() GCOV_CHECK(gcov_var.mode < 0)
483
484 #endif /* GCC_GCOV_IO_H */
485 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -0,0 +1,13
1 /* Generated by the program `C:\home\obswteam\workspace\sparc-gcov-master\tools\version\gcov-iov.exe'
2 from `4.4 (4 4) and (*)'. */
3 #if ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 )
4 #define GCOV_VERSION ((gcov_unsigned_t)0x3330342a) /* type 'gcov-iov 3.4 ""' */
5 #endif /* __GNUC__ __GNUC_MINOR__ */
6
7 #if ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 )
8 #define GCOV_VERSION ((gcov_unsigned_t)0x3430342a) /* type 'gcov-iov 4.4 ""' */
9 #endif /* __GNUC__ __GNUC_MINOR__ */
10
11 #if ( __GNUC__ > 4 )
12 #define GCOV_VERSION ((gcov_unsigned_t)0x3430342a) /* type 'gcov-iov 4.4 ""' */
13 #endif /* __GNUC__ __GNUC_MINOR__ */
@@ -0,0 +1,134
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 /*#if ( ( __GNUC__ > 3 ) || \
3 ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 ( ( __GNUC__ < 4 ) || \
6 ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 */
9 /* Routines required for instrumenting a program. */
10 /* Compile this one with gcc. */
11 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
12 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
13
14 This file is part of GCC.
15
16 GCC is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free
18 Software Foundation; either version 2, or (at your option) any later
19 version.
20
21 In addition to the permissions in the GNU General Public License, the
22 Free Software Foundation gives you unlimited permission to link the
23 compiled version of this file into combinations with other programs,
24 and to distribute those combinations without any restriction coming
25 from the use of this file. (The General Public License restrictions
26 do apply in other respects; for example, they cover modification of
27 the file, and distribution when not linked into a combine
28 executable.)
29
30 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
31 WARRANTY; without even the implied warranty of MERCHANTABILITY or
32 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33 for more details.
34
35 You should have received a copy of the GNU General Public License
36 along with GCC; see the file COPYING. If not, write to the Free
37 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
38 02111-1307, USA. */
39
40 #define GCOV_LINKAGE /* nothing */
41
42 #include "gcov-io.h"
43
44 /* Chain of per-object gcov structures. */
45 struct gcov_info *gcov_list;
46
47 /* A program checksum allows us to distinguish program data for an
48 object file included in multiple programs. */
49 gcov_unsigned_t gcov_crc32;
50
51 /* The profile merging function that just adds the counters. It is given
52 an array COUNTERS of N_COUNTERS old counters and it reads the same number
53 of counters from the gcov file. */
54 void
55 __gcov_merge_add (gcov_type *counters, unsigned n_counters)
56 {
57 for (; n_counters; counters++, n_counters--)
58 *counters += gcov_read_counter ();
59 }
60 /* The profile merging function for choosing the most common value.
61 It is given an array COUNTERS of N_COUNTERS old counters and it
62 reads the same number of counters from the gcov file. The counters
63 are split into 3-tuples where the members of the tuple have
64 meanings:
65
66 -- the stored candidate on the most common value of the measured entity
67 -- counter
68 -- total number of evaluations of the value */
69 void
70 __gcov_merge_single (gcov_type *counters, unsigned n_counters)
71 {
72 unsigned i, n_measures;
73 gcov_type value, counter, all;
74
75 GCOV_CHECK (!(n_counters % 3));
76 n_measures = n_counters / 3;
77 for (i = 0; i < n_measures; i++, counters += 3)
78 {
79 value = gcov_read_counter ();
80 counter = gcov_read_counter ();
81 all = gcov_read_counter ();
82
83 if (counters[0] == value)
84 counters[1] += counter;
85 else if (counter > counters[1])
86 {
87 counters[0] = value;
88 counters[1] = counter - counters[1];
89 }
90 else
91 counters[1] -= counter;
92 counters[2] += all;
93 }
94 }
95
96 /* The profile merging function for choosing the most common
97 difference between two consecutive evaluations of the value. It is
98 given an array COUNTERS of N_COUNTERS old counters and it reads the
99 same number of counters from the gcov file. The counters are split
100 into 4-tuples where the members of the tuple have meanings:
101
102 -- the last value of the measured entity
103 -- the stored candidate on the most common difference
104 -- counter
105 -- total number of evaluations of the value */
106
107 void
108 __gcov_merge_delta (gcov_type *counters, unsigned n_counters)
109 {
110 unsigned i, n_measures;
111 gcov_type last, value, counter, all;
112
113 GCOV_CHECK (!(n_counters % 4));
114 n_measures = n_counters / 4;
115 for (i = 0; i < n_measures; i++, counters += 4)
116 {
117 last = gcov_read_counter ();
118 value = gcov_read_counter ();
119 counter = gcov_read_counter ();
120 all = gcov_read_counter ();
121
122 if (counters[1] == value)
123 counters[2] += counter;
124 else if (counter > counters[2])
125 {
126 counters[1] = value;
127 counters[2] = counter - counters[2];
128 }
129 else
130 counters[2] -= counter;
131 counters[3] += all;
132 }
133 }
134 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -0,0 +1,40
1 #!/usr/bin/env python3
2
3 __author__ = "Alexis Jeandet"
4 __copyright__ = "Copyright 2018, Laboratory of Plasma Physics"
5 __credits__ = []
6 __license__ = "GPLv2"
7 __version__ = "1.0.0"
8 __maintainer__ = "Alexis Jeandet"
9 __email__ = "alexis.jeandet@member.fsf.org"
10 __status__ = "Development"
11
12 import time
13 import sys
14 import os
15 import serial
16 import argparse
17 from datetime import datetime
18
19 parser = argparse.ArgumentParser()
20 parser.add_argument("-p", "--port", help="Serial port")
21 parser.add_argument("-s", "--speed", help="Baud rate")
22 args = parser.parse_args()
23
24
25
26 def main():
27 with open('gcov_out_'+str(datetime.now())+'.txt','w') as gcov:
28 with open('console_'+str(datetime.now())+'.txt','w') as console:
29 with serial.Serial(args.port, args.speed, timeout=None) as ser:
30 line = ser.readline().decode()
31 while '_GCOVEXIT_BEGIN_' not in line:
32 console.write(line)
33 line = ser.readline().decode()
34 line = ser.readline().decode()
35 while '_GCOVEXIT_END_' not in line:
36 gcov.write(line)
37 line = ser.readline().decode()
38
39 if __name__ == "__main__":
40 main()
@@ -1,4 +1,4
1 header/lfr_common_headers = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/SOLO_LFR/lfr_common_headers
1 header/lfr_common_headers = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/USERS/JEANDET/lfr_common_headers
2
2
3 LFR_basic-parameters = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/USERS/CHUST/LFR_basic-parameters
3 LFR_basic-parameters = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/USERS/CHUST/LFR_basic-parameters
4
4
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 e904b329ff977514bf36af92617afefd22fd06ab header/lfr_common_headers
2 f5b83fb540b1cfd5d87c68621fb53f238eb623ae header/lfr_common_headers
@@ -1,14 +1,14
1 cmake_minimum_required (VERSION 2.6)
1 cmake_minimum_required (VERSION 2.6)
2 project (LFR_FSW)
2 project (LFR_FSW)
3
3
4 if(NOT CMAKE_BUILD_TYPE)
4 if(NOT CMAKE_BUILD_TYPE)
5 set(CMAKE_BUILD_TYPE "Release" CACHE STRING
5 set(CMAKE_BUILD_TYPE "Release" CACHE STRING
6 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
6 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
7 endif(NOT CMAKE_BUILD_TYPE)
7 endif(NOT CMAKE_BUILD_TYPE)
8
8
9 set(LFR_BP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/LFR_basic-parameters/basic_parameters.c)
9 set(LFR_BP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/LFR_basic-parameters/basic_parameters.c)
10
10
11 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/sparc")
11 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/sparc")
12
12
13 add_subdirectory(libgcov)
13 add_subdirectory(src)
14 add_subdirectory(src)
14 #add_subdirectory(timegen)
@@ -1,8 +1,32
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 #ifndef GRSPW_H_INCLUDED
25 #ifndef GRSPW_H_INCLUDED
2 #define GRSPW_H_INCLUDED
26 #define GRSPW_H_INCLUDED
3
27
4 int grspw_set_ie( unsigned char value, unsigned int *ctrlReg );
28 int grspw_set_ie( unsigned char value, unsigned int *ctrlReg );
5 int grspw_set_tq( unsigned char value, unsigned int *ctrlReg );
29 int grspw_set_tq( unsigned char value, unsigned int *ctrlReg );
6 int grspw_set_tr( unsigned char value, unsigned int *ctrlReg );
30 int grspw_set_tr( unsigned char value, unsigned int *ctrlReg );
7
31
8 #endif // GRSPW_H_INCLUDED
32 #endif // GRSPW_H_INCLUDED
@@ -1,169 +1,156
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 #include <grspw.h>
6 #include <grspw.h>
7 #include <grlib_regs.h>
7 #include <grlib_regs.h>
8
8
9 #include "fsw_params.h"
9 #include "fsw_params.h"
10 #include "fsw_spacewire.h"
10 #include "fsw_spacewire.h"
11 #include "lfr_cpu_usage_report.h"
11 #include "lfr_cpu_usage_report.h"
12
12
13 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
14 #define WATCHDOG_LOOP_PRINTF 10
13 #define WATCHDOG_LOOP_PRINTF 10
15 #define WATCHDOG_LOOP_DEBUG 3
14 #define WATCHDOG_LOOP_DEBUG 3
16
15
17 #define DUMB_MESSAGE_NB 15
18 #define NB_RTEMS_EVENTS 32
16 #define NB_RTEMS_EVENTS 32
19 #define EVENT_12 12
17 #define EVENT_12 12
20 #define EVENT_13 13
18 #define EVENT_13 13
21 #define EVENT_14 14
19 #define EVENT_14 14
22 #define DUMB_MESSAGE_0 "in DUMB *** default"
23 #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler"
20 #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler"
24 #define DUMB_MESSAGE_2 "in DUMB *** f3 buffer changed"
25 #define DUMB_MESSAGE_3 "in DUMB *** in SMIQ *** Error sending event to AVF0"
26 #define DUMB_MESSAGE_4 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ"
27 #define DUMB_MESSAGE_5 "in DUMB *** waveforms_simulator_isr"
28 #define DUMB_MESSAGE_6 "VHDL SM *** two buffers f0 ready"
29 #define DUMB_MESSAGE_7 "ready for dump"
30 #define DUMB_MESSAGE_8 "VHDL ERR *** spectral matrix"
31 #define DUMB_MESSAGE_9 "tick"
32 #define DUMB_MESSAGE_10 "VHDL ERR *** waveform picker"
33 #define DUMB_MESSAGE_11 "VHDL ERR *** unexpected ready matrix values"
34 #define DUMB_MESSAGE_12 "WATCHDOG timer"
21 #define DUMB_MESSAGE_12 "WATCHDOG timer"
35 #define DUMB_MESSAGE_13 "TIMECODE timer"
22 #define DUMB_MESSAGE_13 "TIMECODE timer"
36 #define DUMB_MESSAGE_14 "TIMECODE ISR"
37
23
38 enum lfr_reset_cause_t{
24 enum lfr_reset_cause_t{
39 UNKNOWN_CAUSE,
25 UNKNOWN_CAUSE,
40 POWER_ON,
26 POWER_ON,
41 TC_RESET,
27 TC_RESET,
42 WATCHDOG,
28 WATCHDOG,
43 ERROR_RESET,
29 ERROR_RESET,
44 UNEXP_RESET
30 UNEXP_RESET
45 };
31 };
46
32
47 typedef struct{
33 typedef struct{
48 unsigned char dpu_spw_parity;
34 unsigned char dpu_spw_parity;
49 unsigned char dpu_spw_disconnect;
35 unsigned char dpu_spw_disconnect;
50 unsigned char dpu_spw_escape;
36 unsigned char dpu_spw_escape;
51 unsigned char dpu_spw_credit;
37 unsigned char dpu_spw_credit;
52 unsigned char dpu_spw_write_sync;
38 unsigned char dpu_spw_write_sync;
53 unsigned char timecode_erroneous;
39 unsigned char timecode_erroneous;
54 unsigned char timecode_missing;
40 unsigned char timecode_missing;
55 unsigned char timecode_invalid;
41 unsigned char timecode_invalid;
56 unsigned char time_timecode_it;
42 unsigned char time_timecode_it;
57 unsigned char time_not_synchro;
43 unsigned char time_not_synchro;
58 unsigned char time_timecode_ctr;
44 unsigned char time_timecode_ctr;
59 unsigned char ahb_correctable;
45 unsigned char ahb_correctable;
60 } hk_lfr_le_t;
46 } hk_lfr_le_t;
61
47
62 typedef struct{
48 typedef struct{
63 unsigned char dpu_spw_early_eop;
49 unsigned char dpu_spw_early_eop;
64 unsigned char dpu_spw_invalid_addr;
50 unsigned char dpu_spw_invalid_addr;
65 unsigned char dpu_spw_eep;
51 unsigned char dpu_spw_eep;
66 unsigned char dpu_spw_rx_too_big;
52 unsigned char dpu_spw_rx_too_big;
67 } hk_lfr_me_t;
53 } hk_lfr_me_t;
68
54
69 #define B00 196
55 #define B00 196
70 #define B01 196
56 #define B01 196
71 #define B02 0
57 #define B02 0
72 #define B10 131
58 #define B10 131
73 #define B11 -244
59 #define B11 -244
74 #define B12 131
60 #define B12 131
75 #define B20 161
61 #define B20 161
76 #define B21 -314
62 #define B21 -314
77 #define B22 161
63 #define B22 161
78
64
79 #define A00 1
65 #define A00 1
80 #define A01 -925
66 #define A01 -925
81 #define A02 0
67 #define A02 0
82 #define A10 1
68 #define A10 1
83 #define A11 -947
69 #define A11 -947
84 #define A12 439
70 #define A12 439
85 #define A20 1
71 #define A20 1
86 #define A21 -993
72 #define A21 -993
87 #define A22 486
73 #define A22 486
88
74
89 #define GAIN_B0 12
75 #define GAIN_B0 12
90 #define GAIN_B1 11
76 #define GAIN_B1 11
91 #define GAIN_B2 10
77 #define GAIN_B2 10
92
78
93 #define GAIN_A0 10
79 #define GAIN_A0 10
94 #define GAIN_A1 9
80 #define GAIN_A1 9
95 #define GAIN_A2 9
81 #define GAIN_A2 9
96
82
97 #define NB_COEFFS 3
83 #define NB_COEFFS 3
98 #define COEFF0 0
84 #define COEFF0 0
99 #define COEFF1 1
85 #define COEFF1 1
100 #define COEFF2 2
86 #define COEFF2 2
101
87
102 typedef struct filter_ctx
88 typedef struct filter_ctx
103 {
89 {
104 int W[NB_COEFFS][NB_COEFFS];
90 int W[NB_COEFFS][NB_COEFFS];
105 }filter_ctx;
91 }filter_ctx;
106
92
107 extern gptimer_regs_t *gptimer_regs;
93 extern gptimer_regs_t *gptimer_regs;
108 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
94 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
109 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
95 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
110
96
111 extern rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
97 extern rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
112 extern rtems_id HK_id;// id of the HK rate monotonic period
98 extern rtems_id HK_id;// id of the HK rate monotonic period
113 extern rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic
99 extern rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic
114 extern rtems_id AVGV_id;// id of the AVGV rate monotonic period
100 extern rtems_id AVGV_id;// id of the AVGV rate monotonic period
115
101
116 void timer_configure( unsigned char timer, unsigned int clock_divider,
102 void timer_configure( unsigned char timer, unsigned int clock_divider,
117 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
103 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
118 void timer_start( unsigned char timer );
104 void timer_start( unsigned char timer );
119 void timer_stop( unsigned char timer );
105 void timer_stop( unsigned char timer );
120 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
106 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
121
107
122 // WATCHDOG
108 // WATCHDOG
123 rtems_isr watchdog_isr( rtems_vector_number vector );
109 rtems_isr watchdog_isr( rtems_vector_number vector );
124 void watchdog_configure(void);
110 void watchdog_configure(void);
125 void watchdog_stop(void);
111 void watchdog_stop(void);
126 void watchdog_reload(void);
112 void watchdog_reload(void);
127 void watchdog_start(void);
113 void watchdog_start(void);
128
114
129 // SERIAL LINK
115 // SERIAL LINK
130 int send_console_outputs_on_apbuart_port( void );
116 int send_console_outputs_on_apbuart_port( void );
131 int enable_apbuart_transmitter( void );
117 int enable_apbuart_transmitter( void );
132 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
118 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
133
119
134 // RTEMS TASKS
120 // RTEMS TASKS
135 rtems_task load_task( rtems_task_argument argument );
121 rtems_task load_task( rtems_task_argument argument );
136 rtems_task hous_task( rtems_task_argument argument );
122 rtems_task hous_task( rtems_task_argument argument );
137 rtems_task avgv_task( rtems_task_argument argument );
123 rtems_task avgv_task( rtems_task_argument argument );
138 rtems_task dumb_task( rtems_task_argument unused );
124 rtems_task dumb_task( rtems_task_argument unused );
125 rtems_task scrubbing_task( rtems_task_argument unused );
126 rtems_task calibration_sweep_task( rtems_task_argument unused );
139
127
140 void init_housekeeping_parameters( void );
128 void init_housekeeping_parameters( void );
141 void increment_seq_counter(unsigned short *packetSequenceControl);
129 void increment_seq_counter(unsigned short *packetSequenceControl);
142 void getTime( unsigned char *time);
130 void getTime( unsigned char *time);
143 unsigned long long int getTimeAsUnsignedLongLongInt( );
131 unsigned long long int getTimeAsUnsignedLongLongInt( );
144 void send_dumb_hk( void );
145 void get_temperatures( unsigned char *temperatures );
132 void get_temperatures( unsigned char *temperatures );
146 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
133 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
147 void get_cpu_load( unsigned char *resource_statistics );
134 void get_cpu_load( unsigned char *resource_statistics );
148 void set_hk_lfr_sc_potential_flag( bool state );
135 void set_hk_lfr_sc_potential_flag( bool state );
149 void set_sy_lfr_pas_filter_enabled( bool state );
136 void set_sy_lfr_pas_filter_enabled( bool state );
150 void set_sy_lfr_watchdog_enabled( bool state );
137 void set_sy_lfr_watchdog_enabled( bool state );
151 void set_hk_lfr_calib_enable( bool state );
138 void set_hk_lfr_calib_enable( bool state );
152 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
139 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
153 void hk_lfr_le_me_he_update();
140 void hk_lfr_le_me_he_update();
154 void set_hk_lfr_time_not_synchro();
141 void set_hk_lfr_time_not_synchro();
155
142
156 extern int sched_yield( void );
143 extern int sched_yield( void );
157 extern void rtems_cpu_usage_reset();
144 extern void rtems_cpu_usage_reset();
158 extern ring_node *current_ring_node_f3;
145 extern ring_node *current_ring_node_f3;
159 extern ring_node *ring_node_to_send_cwf_f3;
146 extern ring_node *ring_node_to_send_cwf_f3;
160 extern ring_node waveform_ring_f3[];
147 extern ring_node waveform_ring_f3[];
161 extern unsigned short sequenceCounterHK;
148 extern unsigned short sequenceCounterHK;
162
149
163 extern unsigned char hk_lfr_q_sd_fifo_size_max;
150 extern unsigned char hk_lfr_q_sd_fifo_size_max;
164 extern unsigned char hk_lfr_q_rv_fifo_size_max;
151 extern unsigned char hk_lfr_q_rv_fifo_size_max;
165 extern unsigned char hk_lfr_q_p0_fifo_size_max;
152 extern unsigned char hk_lfr_q_p0_fifo_size_max;
166 extern unsigned char hk_lfr_q_p1_fifo_size_max;
153 extern unsigned char hk_lfr_q_p1_fifo_size_max;
167 extern unsigned char hk_lfr_q_p2_fifo_size_max;
154 extern unsigned char hk_lfr_q_p2_fifo_size_max;
168
155
169 #endif // FSW_MISC_H_INCLUDED
156 #endif // FSW_MISC_H_INCLUDED
@@ -1,36 +1,37
1 #ifndef LFR_CPU_USAGE_REPORT_H
1 #ifndef LFR_CPU_USAGE_REPORT_H
2 #define LFR_CPU_USAGE_REPORT_H
2 #define LFR_CPU_USAGE_REPORT_H
3
3
4 #ifdef HAVE_CONFIG_H
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
5 #include "config.h"
6 #endif
6 #endif
7
7
8 #include <rtems.h>
8 #include <rtems.h>
9
9
10 #include <assert.h>
10 #include <assert.h>
11 #include <string.h>
11 #include <string.h>
12 #include <stdlib.h>
12 #include <stdlib.h>
13 #include <stdio.h>
13 #include <stdio.h>
14 #include <ctype.h>
14 #include <ctype.h>
15 #include <inttypes.h>
15 #include <inttypes.h>
16
16
17 #include <rtems/cpuuse.h>
17 #include <rtems/cpuuse.h>
18 #include <rtems/bspIo.h>
18 #include <rtems/bspIo.h>
19
19
20 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
20 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
21 #include <rtems/score/timestamp.h>
21 #include <rtems/score/timestamp.h>
22 #endif
22 #endif
23
23
24 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
24 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
25 extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
25 extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
26 #else
26 #else
27 extern uint32_t CPU_usage_Ticks_at_last_reset;
27 extern uint32_t CPU_usage_Ticks_at_last_reset;
28 #endif
28 #endif
29
29
30 unsigned char lfr_rtems_cpu_usage_report( void );
30 unsigned char lfr_rtems_cpu_usage_report( void );
31
31
32 #define CONST_10 10
32 #define CONST_100 100
33 #define CONST_100 100
34 #define CONST_255 255
33 #define CONST_1000 1000
35 #define CONST_1000 1000
34 #define CONST_100000 100000
35
36
36 #endif // LFR_CPU_USAGE_REPORT_H
37 #endif // LFR_CPU_USAGE_REPORT_H
@@ -1,373 +1,364
1 #ifndef FSW_PROCESSING_H_INCLUDED
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <math.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h>
8 #include <stdio.h>
9 #include <math.h>
9 #include <math.h>
10 #include <grlib_regs.h>
10 #include <grlib_regs.h>
11
11
12 #include "fsw_params.h"
12 #include "fsw_params.h"
13
13
14 #define SBM_COEFF_PER_NORM_COEFF 2
14 #define SBM_COEFF_PER_NORM_COEFF 2
15 #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
15 #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
16 #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes
16 #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes
17
17
18 #define NODE_0 0
19 #define NODE_1 1
20 #define NODE_2 2
21 #define NODE_3 3
22 #define NODE_4 4
23 #define NODE_5 5
24 #define NODE_6 6
25 #define NODE_7 7
26
27 typedef struct ring_node_asm
18 typedef struct ring_node_asm
28 {
19 {
29 struct ring_node_asm *next;
20 struct ring_node_asm *next;
30 float matrix[ TOTAL_SIZE_SM ];
21 float matrix[ TOTAL_SIZE_SM ];
31 unsigned int status;
22 unsigned int status;
32 } ring_node_asm;
23 } ring_node_asm;
33
24
34 typedef struct
25 typedef struct
35 {
26 {
36 unsigned char targetLogicalAddress;
27 unsigned char targetLogicalAddress;
37 unsigned char protocolIdentifier;
28 unsigned char protocolIdentifier;
38 unsigned char reserved;
29 unsigned char reserved;
39 unsigned char userApplication;
30 unsigned char userApplication;
40 unsigned char packetID[BYTES_PER_PACKETID];
31 unsigned char packetID[BYTES_PER_PACKETID];
41 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
32 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
42 unsigned char packetLength[BYTES_PER_PKT_LEN];
33 unsigned char packetLength[BYTES_PER_PKT_LEN];
43 // DATA FIELD HEADER
34 // DATA FIELD HEADER
44 unsigned char spare1_pusVersion_spare2;
35 unsigned char spare1_pusVersion_spare2;
45 unsigned char serviceType;
36 unsigned char serviceType;
46 unsigned char serviceSubType;
37 unsigned char serviceSubType;
47 unsigned char destinationID;
38 unsigned char destinationID;
48 unsigned char time[BYTES_PER_TIME];
39 unsigned char time[BYTES_PER_TIME];
49 // AUXILIARY HEADER
40 // AUXILIARY HEADER
50 unsigned char sid;
41 unsigned char sid;
51 unsigned char pa_bia_status_info;
42 unsigned char pa_bia_status_info;
52 unsigned char sy_lfr_common_parameters_spare;
43 unsigned char sy_lfr_common_parameters_spare;
53 unsigned char sy_lfr_common_parameters;
44 unsigned char sy_lfr_common_parameters;
54 unsigned char acquisitionTime[BYTES_PER_TIME];
45 unsigned char acquisitionTime[BYTES_PER_TIME];
55 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
46 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
56 // SOURCE DATA
47 // SOURCE DATA
57 unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
48 unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
58 } bp_packet;
49 } bp_packet;
59
50
60 typedef struct
51 typedef struct
61 {
52 {
62 unsigned char targetLogicalAddress;
53 unsigned char targetLogicalAddress;
63 unsigned char protocolIdentifier;
54 unsigned char protocolIdentifier;
64 unsigned char reserved;
55 unsigned char reserved;
65 unsigned char userApplication;
56 unsigned char userApplication;
66 unsigned char packetID[BYTES_PER_PACKETID];
57 unsigned char packetID[BYTES_PER_PACKETID];
67 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
58 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
68 unsigned char packetLength[BYTES_PER_PKT_LEN];
59 unsigned char packetLength[BYTES_PER_PKT_LEN];
69 // DATA FIELD HEADER
60 // DATA FIELD HEADER
70 unsigned char spare1_pusVersion_spare2;
61 unsigned char spare1_pusVersion_spare2;
71 unsigned char serviceType;
62 unsigned char serviceType;
72 unsigned char serviceSubType;
63 unsigned char serviceSubType;
73 unsigned char destinationID;
64 unsigned char destinationID;
74 unsigned char time[BYTES_PER_TIME];
65 unsigned char time[BYTES_PER_TIME];
75 // AUXILIARY HEADER
66 // AUXILIARY HEADER
76 unsigned char sid;
67 unsigned char sid;
77 unsigned char pa_bia_status_info;
68 unsigned char pa_bia_status_info;
78 unsigned char sy_lfr_common_parameters_spare;
69 unsigned char sy_lfr_common_parameters_spare;
79 unsigned char sy_lfr_common_parameters;
70 unsigned char sy_lfr_common_parameters;
80 unsigned char acquisitionTime[BYTES_PER_TIME];
71 unsigned char acquisitionTime[BYTES_PER_TIME];
81 unsigned char source_data_spare;
72 unsigned char source_data_spare;
82 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
73 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
83 // SOURCE DATA
74 // SOURCE DATA
84 unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes
75 unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes
85 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
76 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
86
77
87 typedef struct asm_msg
78 typedef struct asm_msg
88 {
79 {
89 ring_node_asm *norm;
80 ring_node_asm *norm;
90 ring_node_asm *burst_sbm;
81 ring_node_asm *burst_sbm;
91 rtems_event_set event;
82 rtems_event_set event;
92 unsigned int coarseTimeNORM;
83 unsigned int coarseTimeNORM;
93 unsigned int fineTimeNORM;
84 unsigned int fineTimeNORM;
94 unsigned int coarseTimeSBM;
85 unsigned int coarseTimeSBM;
95 unsigned int fineTimeSBM;
86 unsigned int fineTimeSBM;
96 unsigned int numberOfSMInASMNORM;
87 unsigned int numberOfSMInASMNORM;
97 unsigned int numberOfSMInASMSBM;
88 unsigned int numberOfSMInASMSBM;
98 } asm_msg;
89 } asm_msg;
99
90
100 extern unsigned char thisIsAnASMRestart;
91 extern unsigned char thisIsAnASMRestart;
101
92
102 extern volatile int sm_f0[ ];
93 extern volatile int sm_f0[ ];
103 extern volatile int sm_f1[ ];
94 extern volatile int sm_f1[ ];
104 extern volatile int sm_f2[ ];
95 extern volatile int sm_f2[ ];
105 extern unsigned int acquisitionDurations[];
96 extern unsigned int acquisitionDurations[];
106
97
107 // parameters
98 // parameters
108 extern struct param_local_str param_local;
99 extern struct param_local_str param_local;
109 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
100 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
110
101
111 // registers
102 // registers
112 extern time_management_regs_t *time_management_regs;
103 extern time_management_regs_t *time_management_regs;
113 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
104 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
114
105
115 extern rtems_name misc_name[];
106 extern rtems_name misc_name[];
116 extern rtems_id Task_id[]; /* array of task ids */
107 extern rtems_id Task_id[]; /* array of task ids */
117
108
118 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
109 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
119 // ISR
110 // ISR
120 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
111 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
121
112
122 //******************
113 //******************
123 // Spectral Matrices
114 // Spectral Matrices
124 void reset_nb_sm( void );
115 void reset_nb_sm( void );
125 // SM
116 // SM
126 void SM_init_rings( void );
117 void SM_init_rings( void );
127 void SM_reset_current_ring_nodes( void );
118 void SM_reset_current_ring_nodes( void );
128 // ASM
119 // ASM
129 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
120 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
130
121
131 //*****************
122 //*****************
132 // Basic Parameters
123 // Basic Parameters
133
124
134 void BP_reset_current_ring_nodes( void );
125 void BP_reset_current_ring_nodes( void );
135 void BP_init_header(bp_packet *packet,
126 void BP_init_header(bp_packet *packet,
136 unsigned int apid, unsigned char sid,
127 unsigned int apid, unsigned char sid,
137 unsigned int packetLength , unsigned char blkNr);
128 unsigned int packetLength , unsigned char blkNr);
138 void BP_init_header_with_spare(bp_packet_with_spare *packet,
129 void BP_init_header_with_spare(bp_packet_with_spare *packet,
139 unsigned int apid, unsigned char sid,
130 unsigned int apid, unsigned char sid,
140 unsigned int packetLength, unsigned char blkNr );
131 unsigned int packetLength, unsigned char blkNr );
141 void BP_send( char *data,
132 void BP_send( char *data,
142 rtems_id queue_id,
133 rtems_id queue_id,
143 unsigned int nbBytesToSend , unsigned int sid );
134 unsigned int nbBytesToSend , unsigned int sid );
144 void BP_send_s1_s2(char *data,
135 void BP_send_s1_s2(char *data,
145 rtems_id queue_id,
136 rtems_id queue_id,
146 unsigned int nbBytesToSend, unsigned int sid );
137 unsigned int nbBytesToSend, unsigned int sid );
147
138
148 //******************
139 //******************
149 // general functions
140 // general functions
150 void reset_sm_status( void );
141 void reset_sm_status( void );
151 void reset_spectral_matrix_regs( void );
142 void reset_spectral_matrix_regs( void );
152 void set_time(unsigned char *time, unsigned char *timeInBuffer );
143 void set_time(unsigned char *time, unsigned char *timeInBuffer );
153 unsigned long long int get_acquisition_time( unsigned char *timePtr );
144 unsigned long long int get_acquisition_time( unsigned char *timePtr );
154 unsigned char getSID( rtems_event_set event );
145 unsigned char getSID( rtems_event_set event );
155
146
156 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
147 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
157 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
148 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
158
149
159 //***************************************
150 //***************************************
160 // DEFINITIONS OF STATIC INLINE FUNCTIONS
151 // DEFINITIONS OF STATIC INLINE FUNCTIONS
161 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
152 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
162 ring_node *ring_node_tab[],
153 ring_node *ring_node_tab[],
163 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
154 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
164 asm_msg *msgForMATR , unsigned char channel);
155 asm_msg *msgForMATR , unsigned char channel);
165
156
166 void ASM_patch( float *inputASM, float *outputASM );
157 void ASM_patch( float *inputASM, float *outputASM );
167
158
168 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
159 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
169
160
170 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
161 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
171 float divider );
162 float divider );
172
163
173 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
164 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
174 float divider,
165 float divider,
175 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
166 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
176
167
177 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
168 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
178
169
179 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 );
170 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 );
180
171
181 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
172 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
182
173
183 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
174 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
184 ring_node *ring_node_tab[],
175 ring_node *ring_node_tab[],
185 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
176 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
186 asm_msg *msgForMATR, unsigned char channel )
177 asm_msg *msgForMATR, unsigned char channel )
187 {
178 {
188 float sum;
179 float sum;
189 unsigned int i;
180 unsigned int i;
190 unsigned int k;
181 unsigned int k;
191 unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1];
182 unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1];
192 unsigned int numberOfValidSM;
183 unsigned int numberOfValidSM;
193 unsigned char isValid;
184 unsigned char isValid;
194
185
195 //**************
186 //**************
196 // PAS FILTERING
187 // PAS FILTERING
197 // check acquisitionTime of the incoming data
188 // check acquisitionTime of the incoming data
198 numberOfValidSM = 0;
189 numberOfValidSM = 0;
199 for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++)
190 for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++)
200 {
191 {
201 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
192 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
202 incomingSMIsValid[k] = isValid;
193 incomingSMIsValid[k] = isValid;
203 numberOfValidSM = numberOfValidSM + isValid;
194 numberOfValidSM = numberOfValidSM + isValid;
204 }
195 }
205
196
206 //************************
197 //************************
207 // AVERAGE SPECTRAL MATRIX
198 // AVERAGE SPECTRAL MATRIX
208 for(i=0; i<TOTAL_SIZE_SM; i++)
199 for(i=0; i<TOTAL_SIZE_SM; i++)
209 {
200 {
210 sum = INIT_FLOAT;
201 sum = INIT_FLOAT;
211 for ( k = 0; k < NB_SM_BEFORE_AVF0_F1; k++ )
202 for ( k = 0; k < NB_SM_BEFORE_AVF0_F1; k++ )
212 {
203 {
213 if (incomingSMIsValid[k] == MATRIX_IS_NOT_POLLUTED)
204 if (incomingSMIsValid[k] == MATRIX_IS_NOT_POLLUTED)
214 {
205 {
215 sum = sum + ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] ;
206 sum = sum + ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] ;
216 }
207 }
217 }
208 }
218
209
219 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
210 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
220 {
211 {
221 averaged_spec_mat_NORM[ i ] = sum;
212 averaged_spec_mat_NORM[ i ] = sum;
222 averaged_spec_mat_SBM[ i ] = sum;
213 averaged_spec_mat_SBM[ i ] = sum;
223 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
214 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
224 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
215 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
225 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
216 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
226 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
217 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
227 }
218 }
228 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
219 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
229 {
220 {
230 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
221 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
231 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
222 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
232 }
223 }
233 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
224 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
234 {
225 {
235 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
226 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
236 averaged_spec_mat_SBM[ i ] = sum;
227 averaged_spec_mat_SBM[ i ] = sum;
237 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
228 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
238 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
229 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
239 }
230 }
240 else
231 else
241 {
232 {
242 averaged_spec_mat_NORM[ i ] = sum;
233 averaged_spec_mat_NORM[ i ] = sum;
243 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
234 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
244 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
235 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
245 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
236 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
246 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
237 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
247 }
238 }
248 }
239 }
249
240
250 //*******************
241 //*******************
251 // UPDATE SM COUNTERS
242 // UPDATE SM COUNTERS
252 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
243 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
253 {
244 {
254 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
245 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
255 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
246 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
256 }
247 }
257 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
248 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
258 {
249 {
259 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
250 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
260 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
251 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
261 }
252 }
262 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
253 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
263 {
254 {
264 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
255 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
265 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
256 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
266 }
257 }
267 else
258 else
268 {
259 {
269 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
260 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
270 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
261 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
271 }
262 }
272 }
263 }
273
264
274 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
265 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
275 {
266 {
276 int frequencyBin;
267 int frequencyBin;
277 int asmComponent;
268 int asmComponent;
278 unsigned int offsetASM;
269 unsigned int offsetASM;
279 unsigned int offsetASMReorganized;
270 unsigned int offsetASMReorganized;
280
271
281 // BUILD DATA
272 // BUILD DATA
282 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
273 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
283 {
274 {
284 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
275 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
285 {
276 {
286 offsetASMReorganized =
277 offsetASMReorganized =
287 (frequencyBin * NB_VALUES_PER_SM)
278 (frequencyBin * NB_VALUES_PER_SM)
288 + asmComponent;
279 + asmComponent;
289 offsetASM =
280 offsetASM =
290 (asmComponent * NB_BINS_PER_SM)
281 (asmComponent * NB_BINS_PER_SM)
291 + frequencyBin;
282 + frequencyBin;
292 if ( divider != INIT_FLOAT )
283 if ( divider != INIT_FLOAT )
293 {
284 {
294 averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider;
285 averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider;
295 }
286 }
296 else
287 else
297 {
288 {
298 averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT;
289 averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT;
299 }
290 }
300 }
291 }
301 }
292 }
302 }
293 }
303
294
304 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
295 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
305 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
296 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
306 {
297 {
307 int frequencyBin;
298 int frequencyBin;
308 int asmComponent;
299 int asmComponent;
309 int offsetASM;
300 int offsetASM;
310 int offsetCompressed;
301 int offsetCompressed;
311 int k;
302 int k;
312
303
313 // BUILD DATA
304 // BUILD DATA
314 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
305 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
315 {
306 {
316 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
307 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
317 {
308 {
318 offsetCompressed = // NO TIME OFFSET
309 offsetCompressed = // NO TIME OFFSET
319 (frequencyBin * NB_VALUES_PER_SM)
310 (frequencyBin * NB_VALUES_PER_SM)
320 + asmComponent;
311 + asmComponent;
321 offsetASM = // NO TIME OFFSET
312 offsetASM = // NO TIME OFFSET
322 (asmComponent * NB_BINS_PER_SM)
313 (asmComponent * NB_BINS_PER_SM)
323 + ASMIndexStart
314 + ASMIndexStart
324 + (frequencyBin * nbBinsToAverage);
315 + (frequencyBin * nbBinsToAverage);
325 compressed_spec_mat[ offsetCompressed ] = 0;
316 compressed_spec_mat[ offsetCompressed ] = 0;
326 for ( k = 0; k < nbBinsToAverage; k++ )
317 for ( k = 0; k < nbBinsToAverage; k++ )
327 {
318 {
328 compressed_spec_mat[offsetCompressed ] =
319 compressed_spec_mat[offsetCompressed ] =
329 ( compressed_spec_mat[ offsetCompressed ]
320 ( compressed_spec_mat[ offsetCompressed ]
330 + averaged_spec_mat[ offsetASM + k ] );
321 + averaged_spec_mat[ offsetASM + k ] );
331 }
322 }
332 compressed_spec_mat[ offsetCompressed ] =
323 compressed_spec_mat[ offsetCompressed ] =
333 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
324 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
334 }
325 }
335 }
326 }
336 }
327 }
337
328
338 void ASM_convert( volatile float *input_matrix, char *output_matrix)
329 void ASM_convert( volatile float *input_matrix, char *output_matrix)
339 {
330 {
340 unsigned int frequencyBin;
331 unsigned int frequencyBin;
341 unsigned int asmComponent;
332 unsigned int asmComponent;
342 char * pt_char_input;
333 char * pt_char_input;
343 char * pt_char_output;
334 char * pt_char_output;
344 unsigned int offsetInput;
335 unsigned int offsetInput;
345 unsigned int offsetOutput;
336 unsigned int offsetOutput;
346
337
347 pt_char_input = (char*) &input_matrix;
338 pt_char_input = (char*) &input_matrix;
348 pt_char_output = (char*) &output_matrix;
339 pt_char_output = (char*) &output_matrix;
349
340
350 // convert all other data
341 // convert all other data
351 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
342 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
352 {
343 {
353 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
344 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
354 {
345 {
355 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
346 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
356 offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
347 offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
357 pt_char_input = (char*) &input_matrix [ offsetInput ];
348 pt_char_input = (char*) &input_matrix [ offsetInput ];
358 pt_char_output = (char*) &output_matrix[ offsetOutput ];
349 pt_char_output = (char*) &output_matrix[ offsetOutput ];
359 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
350 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
360 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
351 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
361 }
352 }
362 }
353 }
363 }
354 }
364
355
365 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
356 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
366 float divider,
357 float divider,
367 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
358 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
368
359
369 int getFBinMask(int k, unsigned char channel);
360 int getFBinMask(int k, unsigned char channel);
370
361
371 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
362 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
372
363
373 #endif // FSW_PROCESSING_H_INCLUDED
364 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,115 +1,117
1 #ifndef TC_HANDLER_H_INCLUDED
1 #ifndef TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <leon.h>
5 #include <leon.h>
6
6
7 #include "tc_load_dump_parameters.h"
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
8 #include "tc_acceptance.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 #include "lfr_cpu_usage_report.h"
13 #include "lfr_cpu_usage_report.h"
14
14
15 #define MAX_DELTA_COARSE_TIME 3
15 #define MAX_DELTA_COARSE_TIME 3
16 #define NB_SCIENCE_TASKS 10
16 #define NB_SCIENCE_TASKS 10
17 #define NB_ASM_TASKS 6
17 #define NB_ASM_TASKS 6
18 #define STATUS_0 0
18 #define STATUS_0 0
19 #define STATUS_1 1
19 #define STATUS_1 1
20 #define STATUS_2 2
20 #define STATUS_2 2
21 #define STATUS_3 3
21 #define STATUS_3 3
22 #define STATUS_4 4
22 #define STATUS_4 4
23 #define STATUS_5 5
23 #define STATUS_5 5
24 #define STATUS_6 6
24 #define STATUS_6 6
25 #define STATUS_7 7
25 #define STATUS_7 7
26 #define STATUS_8 8
26 #define STATUS_8 8
27 #define STATUS_9 9
27 #define STATUS_9 9
28
28
29 #define CAL_F0 625.
29 #define CAL_F0 625.
30 #define CAL_F1 10000.
30 #define CAL_F1 10000.
31 #define CAL_W0 (2. * pi * CAL_F0)
31 #define CAL_W0 (2. * pi * CAL_F0)
32 #define CAL_W1 (2. * pi * CAL_F1)
32 #define CAL_W1 (2. * pi * CAL_F1)
33 #define CAL_A0 1.
33 #define CAL_A0 1.
34 #define CAL_A1 2.
34 #define CAL_A1 2.
35 #define CAL_FS 160256.410
35 #define CAL_FS 160256.410
36 #define CAL_SCALE_FACTOR (0.250 / 0.000654) // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
36 #define CAL_SCALE_FACTOR (0.250 / 0.000654) // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
37 #define CAL_NB_PTS 256
37 #define CAL_NB_PTS 256
38 #define CAL_DATA_MASK 0xfff
38 #define CAL_DATA_MASK 0xfff
39 #define CAL_F_DIVISOR 38 // 25 MHz => 160 256 (39 - 1)
39 #define CAL_F_DIVISOR 38 // 25 MHz => 160 256 (39 - 1)
40 #define CAL_F_DIVISOR_MIN 38
41 #define CAL_F_DIVISOR_MAX (38*2*2*2*2)
40 // INTERLEAVED MODE
42 // INTERLEAVED MODE
41 #define CAL_FS_INTER 240384.615
43 #define CAL_FS_INTER 240384.615
42 #define CAL_NB_PTS_INTER 384
44 #define CAL_NB_PTS_INTER 384
43 #define CAL_DATA_MASK_INTER 0x3f
45 #define CAL_DATA_MASK_INTER 0x3f
44 #define CAL_DATA_SHIFT_INTER 12
46 #define CAL_DATA_SHIFT_INTER 12
45 #define BYTES_FOR_2_SAMPLES 3 // one need 3 bytes = 24 bits to store 3 samples of 12 bits in interleaved mode
47 #define BYTES_FOR_2_SAMPLES 3 // one need 3 bytes = 24 bits to store 3 samples of 12 bits in interleaved mode
46 #define STEPS_FOR_STORAGE_INTER 128
48 #define STEPS_FOR_STORAGE_INTER 128
47 #define CAL_F_DIVISOR_INTER 26 // 25 MHz => 240 384
49 #define CAL_F_DIVISOR_INTER 26 // 25 MHz => 240 384
48
50
49 extern unsigned int lastValidEnterModeTime;
51 extern unsigned int lastValidEnterModeTime;
50 extern unsigned char oneTcLfrUpdateTimeReceived;
52 extern unsigned char oneTcLfrUpdateTimeReceived;
51
53
52 //****
54 //****
53 // ISR
55 // ISR
54 rtems_isr commutation_isr1( rtems_vector_number vector );
56 rtems_isr commutation_isr1( rtems_vector_number vector );
55 rtems_isr commutation_isr2( rtems_vector_number vector );
57 rtems_isr commutation_isr2( rtems_vector_number vector );
56
58
57 //***********
59 //***********
58 // RTEMS TASK
60 // RTEMS TASK
59 rtems_task actn_task( rtems_task_argument unused );
61 rtems_task actn_task( rtems_task_argument unused );
60
62
61 //***********
63 //***********
62 // TC ACTIONS
64 // TC ACTIONS
63 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
65 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
64 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
66 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
65 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
67 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
66 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
68 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
67 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
69 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
68 int action_update_time( ccsdsTelecommandPacket_t *TC);
70 int action_update_time( ccsdsTelecommandPacket_t *TC);
69
71
70 // mode transition
72 // mode transition
71 int check_mode_value( unsigned char requestedMode );
73 int check_mode_value( unsigned char requestedMode );
72 int check_mode_transition( unsigned char requestedMode );
74 int check_mode_transition( unsigned char requestedMode );
73 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
75 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
74 int check_transition_date( unsigned int transitionCoarseTime );
76 int check_transition_date( unsigned int transitionCoarseTime );
75 int stop_spectral_matrices( void );
77 int stop_spectral_matrices( void );
76 int stop_current_mode( void );
78 int stop_current_mode( void );
77 int enter_mode_standby(void );
79 int enter_mode_standby(void );
78 int enter_mode_normal( unsigned int transitionCoarseTime );
80 int enter_mode_normal( unsigned int transitionCoarseTime );
79 int enter_mode_burst( unsigned int transitionCoarseTime );
81 int enter_mode_burst( unsigned int transitionCoarseTime );
80 int enter_mode_sbm1( unsigned int transitionCoarseTime );
82 int enter_mode_sbm1( unsigned int transitionCoarseTime );
81 int enter_mode_sbm2( unsigned int transitionCoarseTime );
83 int enter_mode_sbm2( unsigned int transitionCoarseTime );
82 int restart_science_tasks( unsigned char lfrRequestedMode );
84 int restart_science_tasks( unsigned char lfrRequestedMode );
83 int restart_asm_tasks(unsigned char lfrRequestedMode );
85 int restart_asm_tasks(unsigned char lfrRequestedMode );
84 int suspend_science_tasks(void);
86 int suspend_science_tasks(void);
85 int suspend_asm_tasks( void );
87 int suspend_asm_tasks( void );
86 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
88 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
87 void launch_spectral_matrix( void );
89 void launch_spectral_matrix( void );
88 void set_sm_irq_onNewMatrix( unsigned char value );
90 void set_sm_irq_onNewMatrix( unsigned char value );
89 void set_sm_irq_onError( unsigned char value );
91 void set_sm_irq_onError( unsigned char value );
90
92
91 // other functions
93 // other functions
92 void updateLFRCurrentMode(unsigned char requestedMode);
94 void updateLFRCurrentMode(unsigned char requestedMode);
93 void set_lfr_soft_reset( unsigned char value );
95 void set_lfr_soft_reset( unsigned char value );
94 void reset_lfr( void );
96 void reset_lfr( void );
95 // CALIBRATION
97 // CALIBRATION
96 void setCalibrationPrescaler( unsigned int prescaler );
98 void setCalibrationPrescaler( unsigned int prescaler );
97 void setCalibrationDivisor( unsigned int divisionFactor );
99 void setCalibrationDivisor( unsigned int divisionFactor );
98 void setCalibrationData( void );
100 void setCalibrationData( void );
99 void setCalibrationReload( bool state);
101 void setCalibrationReload( bool state);
100 void setCalibrationEnable( bool state );
102 void setCalibrationEnable( bool state );
101 void setCalibrationInterleaved( bool state );
103 void setCalibrationInterleaved( bool state );
102 void setCalibration( bool state );
104 void setCalibration( bool state );
103 void configureCalibration( bool interleaved );
105 void configureCalibration( bool interleaved );
104 //
106 //
105 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
107 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
106 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
108 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
107 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
109 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
108
110
109 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
111 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
110 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
112 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
111
113
112 #endif // TC_HANDLER_H_INCLUDED
114 #endif // TC_HANDLER_H_INCLUDED
113
115
114
116
115
117
@@ -1,124 +1,114
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6
6
7 #include "fsw_params.h"
7 #include "fsw_params.h"
8 #include "wf_handler.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "fsw_misc.h"
10 #include "fsw_misc.h"
11 #include "basic_parameters_params.h"
11 #include "basic_parameters_params.h"
12 #include "avf0_prc0.h"
12 #include "avf0_prc0.h"
13
13
14 #define FLOAT_EQUAL_ZERO 0.001
14 #define FLOAT_EQUAL_ZERO 0.001
15 #define NB_BINS_TO_REMOVE 3
15 #define NB_BINS_TO_REMOVE 3
16 #define FI_INTERVAL_COEFF 0.285
16 #define FI_INTERVAL_COEFF 0.285
17 #define BIN_MIN 0
17 #define BIN_MIN 0
18 #define BIN_MAX 127
18 #define BIN_MAX 127
19 #define DELTAF_F0 96.
19 #define DELTAF_F0 96.
20 #define DELTAF_F1 16.
20 #define DELTAF_F1 16.
21 #define DELTAF_F2 1.
21 #define DELTAF_F2 1.
22 #define DELTAF_DIV 2.
23
24 #define BIT_RW1_F1 0x80
25 #define BIT_RW1_F2 0x40
26 #define BIT_RW2_F1 0x20
27 #define BIT_RW2_F2 0x10
28 #define BIT_RW3_F1 0x08
29 #define BIT_RW3_F2 0x04
30 #define BIT_RW4_F1 0x02
31 #define BIT_RW4_F2 0x01
32
22
33 #define WHEEL_1 1
23 #define WHEEL_1 1
34 #define WHEEL_2 2
24 #define WHEEL_2 2
35 #define WHEEL_3 3
25 #define WHEEL_3 3
36 #define WHEEL_4 4
26 #define WHEEL_4 4
37 #define FREQ_1 1
27 #define FREQ_1 1
38 #define FREQ_2 2
28 #define FREQ_2 2
39 #define FREQ_3 3
29 #define FREQ_3 3
40 #define FREQ_4 4
30 #define FREQ_4 4
41 #define FLAG_OFFSET_WHEELS_1_3 8
31 #define FLAG_OFFSET_WHEELS_1_3 8
42 #define FLAG_OFFSET_WHEELS_2_4 4
32 #define FLAG_OFFSET_WHEELS_2_4 4
43
33
44 #define FLAG_NAN 0 // Not A NUMBER
34 #define FLAG_NAN 0 // Not A NUMBER
45 #define FLAG_IAN 1 // Is A Number
35 #define FLAG_IAN 1 // Is A Number
46
36
47 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
37 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
48
38
49 extern unsigned short sequenceCounterParameterDump;
39 extern unsigned short sequenceCounterParameterDump;
50 extern unsigned short sequenceCounters_TM_DUMP[];
40 extern unsigned short sequenceCounters_TM_DUMP[];
51 extern float k_coeff_intercalib_f0_norm[ ];
41 extern float k_coeff_intercalib_f0_norm[ ];
52 extern float k_coeff_intercalib_f0_sbm[ ];
42 extern float k_coeff_intercalib_f0_sbm[ ];
53 extern float k_coeff_intercalib_f1_norm[ ];
43 extern float k_coeff_intercalib_f1_norm[ ];
54 extern float k_coeff_intercalib_f1_sbm[ ];
44 extern float k_coeff_intercalib_f1_sbm[ ];
55 extern float k_coeff_intercalib_f2[ ];
45 extern float k_coeff_intercalib_f2[ ];
56 extern fbins_masks_t fbins_masks;
46 extern fbins_masks_t fbins_masks;
57
47
58 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
48 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
59 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
49 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
60 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
50 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
61 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
51 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
62 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
52 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
63 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
53 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
64 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
54 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
65 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
55 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
66 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
56 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
67 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
57 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
68
58
69 // NORMAL
59 // NORMAL
70 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
60 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
71 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
61 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
62 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
63 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
64 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
75 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
65 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
76 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
66 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
77
67
78 // BURST
68 // BURST
79 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
69 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
80 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
70 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
81
71
82 // SBM1
72 // SBM1
83 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
84 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
85
75
86 // SBM2
76 // SBM2
87 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
77 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
88 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
78 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
89
79
90 // TC_LFR_UPDATE_INFO
80 // TC_LFR_UPDATE_INFO
91 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
81 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
92 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
82 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
93 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
83 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
94 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
84 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
95 void set_hk_lfr_sc_rw_f_flags( void );
85 void set_hk_lfr_sc_rw_f_flags( void );
96 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
86 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
97 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
87 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
98 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
88 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
99 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k );
89 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k );
100 void build_sy_lfr_rw_mask( unsigned int channel );
90 void build_sy_lfr_rw_mask( unsigned int channel );
101 void build_sy_lfr_rw_masks();
91 void build_sy_lfr_rw_masks();
102 void merge_fbins_masks( void );
92 void merge_fbins_masks( void );
103
93
104 // FBINS_MASK
94 // FBINS_MASK
105 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
95 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
106
96
107 // TC_LFR_LOAD_PARS_FILTER_PAR
97 // TC_LFR_LOAD_PARS_FILTER_PAR
108 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
98 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
109 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
99 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
110 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
100 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
111
101
112 // KCOEFFICIENTS
102 // KCOEFFICIENTS
113 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
103 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
114 void copyFloatByChar( unsigned char *destination, unsigned char *source );
104 void copyFloatByChar( unsigned char *destination, unsigned char *source );
115 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
105 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
116 void copyInt16ByChar( unsigned char *destination, unsigned char *source );
106 void copyInt16ByChar( unsigned char *destination, unsigned char *source );
117 void floatToChar( float value, unsigned char* ptr);
107 void floatToChar( float value, unsigned char* ptr);
118
108
119 void init_parameter_dump( void );
109 void init_parameter_dump( void );
120 void init_kcoefficients_dump( void );
110 void init_kcoefficients_dump( void );
121 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
111 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
122 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
112 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
123
113
124 #endif // TC_LOAD_DUMP_PARAMETERS_H
114 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -1,116 +1,115
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 <grspw.h>
5 #include <grspw.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <math.h>
7 #include <math.h>
8 #include <fsw_params.h>
8 #include <fsw_params.h>
9
9
10 #include "fsw_init.h"
10 #include "fsw_init.h"
11 #include "fsw_params_wf_handler.h"
11 #include "fsw_params_wf_handler.h"
12
12
13 #define pi 3.14159265359
13 #define pi 3.14159265359
14 #define T0_IN_FINETIME ( 65536. / 24576. )
14 #define T0_IN_FINETIME ( 65536. / 24576. )
15 #define T1_IN_FINETIME ( 65536. / 4096. )
15 #define T1_IN_FINETIME ( 65536. / 4096. )
16 #define T2_IN_FINETIME ( 65536. / 256. )
16 #define T2_IN_FINETIME ( 65536. / 256. )
17 #define T3_IN_FINETIME ( 65536. / 16. )
17 #define T3_IN_FINETIME ( 65536. / 16. )
18
18
19 #define TICKS_PER_T1 16
19 #define TICKS_PER_T1 16
20 #define TICKS_PER_T2 256
20 #define TICKS_PER_T2 256
21 #define TICKS_PER_S 65536.
21 #define TICKS_PER_S 65536.
22 #define MS_PER_S 1000.
22 #define MS_PER_S 1000.
23
23
24 #define FREQ_F0 24576.
24 #define FREQ_F0 24576.
25 #define FREQ_F1 4096.
25 #define FREQ_F1 4096.
26 #define FREQ_F2 256.
26 #define FREQ_F2 256.
27 #define FREQ_F3 16.
28
27
29 #define DELTAT_F0 2731 // (2048. / 24576. / 2.) * 65536. = 2730.667;
28 #define DELTAT_F0 2731 // (2048. / 24576. / 2.) * 65536. = 2730.667;
30 #define DELTAT_F1 16384 // (2048. / 4096. / 2.) * 65536. = 16384;
29 #define DELTAT_F1 16384 // (2048. / 4096. / 2.) * 65536. = 16384;
31 #define DELTAT_F2 262144 // (2048. / 256. / 2.) * 65536. = 262144;
30 #define DELTAT_F2 262144 // (2048. / 256. / 2.) * 65536. = 262144;
32
31
33 #define OFFSET_2_BYTES 2
32 #define OFFSET_2_BYTES 2
34
33
35 #define ONE_TICK_CORR_INTERVAL_0_MIN 0.5
34 #define ONE_TICK_CORR_INTERVAL_0_MIN 0.5
36 #define ONE_TICK_CORR_INTERVAL_0_MAX 1.0
35 #define ONE_TICK_CORR_INTERVAL_0_MAX 1.0
37 #define ONE_TICK_CORR_INTERVAL_1_MIN -1.0
36 #define ONE_TICK_CORR_INTERVAL_1_MIN -1.0
38 #define ONE_TICK_CORR_INTERVAL_1_MAX -0.5
37 #define ONE_TICK_CORR_INTERVAL_1_MAX -0.5
39 #define ONE_TICK_CORR 1
38 #define ONE_TICK_CORR 1
40 #define CORR_MULT 2
39 #define CORR_MULT 2
41
40
42 extern int fdSPW;
41 extern int fdSPW;
43
42
44 //*****************
43 //*****************
45 // waveform buffers
44 // waveform buffers
46 extern volatile int wf_buffer_f0[ ];
45 extern volatile int wf_buffer_f0[ ];
47 extern volatile int wf_buffer_f1[ ];
46 extern volatile int wf_buffer_f1[ ];
48 extern volatile int wf_buffer_f2[ ];
47 extern volatile int wf_buffer_f2[ ];
49 extern volatile int wf_buffer_f3[ ];
48 extern volatile int wf_buffer_f3[ ];
50
49
51 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
50 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
52 extern time_management_regs_t *time_management_regs;
51 extern time_management_regs_t *time_management_regs;
53 extern Packet_TM_LFR_HK_t housekeeping_packet;
52 extern Packet_TM_LFR_HK_t housekeeping_packet;
54 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
53 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
55 extern struct param_local_str param_local;
54 extern struct param_local_str param_local;
56
55
57 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
56 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
58 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
57 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
59
58
60 extern rtems_id Task_id[]; /* array of task ids */
59 extern rtems_id Task_id[]; /* array of task ids */
61
60
62 extern unsigned char lfrCurrentMode;
61 extern unsigned char lfrCurrentMode;
63
62
64 //**********
63 //**********
65 // RTEMS_ISR
64 // RTEMS_ISR
66 void reset_extractSWF( void );
65 void reset_extractSWF( void );
67 rtems_isr waveforms_isr( rtems_vector_number vector );
66 rtems_isr waveforms_isr( rtems_vector_number vector );
68
67
69 //***********
68 //***********
70 // RTEMS_TASK
69 // RTEMS_TASK
71 rtems_task wfrm_task( rtems_task_argument argument );
70 rtems_task wfrm_task( rtems_task_argument argument );
72 rtems_task cwf3_task( rtems_task_argument argument );
71 rtems_task cwf3_task( rtems_task_argument argument );
73 rtems_task cwf2_task( rtems_task_argument argument );
72 rtems_task cwf2_task( rtems_task_argument argument );
74 rtems_task cwf1_task( rtems_task_argument argument );
73 rtems_task cwf1_task( rtems_task_argument argument );
75 rtems_task swbd_task( rtems_task_argument argument );
74 rtems_task swbd_task( rtems_task_argument argument );
76
75
77 //******************
76 //******************
78 // general functions
77 // general functions
79 void WFP_init_rings( void );
78 void WFP_init_rings( void );
80 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
79 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
81 void WFP_reset_current_ring_nodes( void );
80 void WFP_reset_current_ring_nodes( void );
82 //
81 //
83 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
82 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
84 //
83 //
85 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
84 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
86 //
85 //
87 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
86 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
88 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
87 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
89 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel ,
88 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel ,
90 unsigned long long acquisitionTimeF0_asLong, ring_node *ring_node_swf_extracted, int *swf_extracted);
89 unsigned long long acquisitionTimeF0_asLong, ring_node *ring_node_swf_extracted, int *swf_extracted);
91 double computeCorrection( unsigned char *timePtr );
90 double computeCorrection( unsigned char *timePtr );
92 void applyCorrection( double correction );
91 void applyCorrection( double correction );
93 void snapshot_resynchronization( unsigned char *timePtr );
92 void snapshot_resynchronization( unsigned char *timePtr );
94 //
93 //
95 rtems_id get_pkts_queue_id( void );
94 rtems_id get_pkts_queue_id( void );
96
95
97 //**************
96 //**************
98 // wfp registers
97 // wfp registers
99 // RESET
98 // RESET
100 void reset_wfp_burst_enable( void );
99 void reset_wfp_burst_enable( void );
101 void reset_wfp_status( void );
100 void reset_wfp_status( void );
102 void reset_wfp_buffer_addresses( void );
101 void reset_wfp_buffer_addresses( void );
103 void reset_waveform_picker_regs( void );
102 void reset_waveform_picker_regs( void );
104 // SET
103 // SET
105 void set_wfp_data_shaping(void);
104 void set_wfp_data_shaping(void);
106 void set_wfp_burst_enable_register( unsigned char mode );
105 void set_wfp_burst_enable_register( unsigned char mode );
107 void set_wfp_delta_snapshot( void );
106 void set_wfp_delta_snapshot( void );
108 void set_wfp_delta_f0_f0_2( void );
107 void set_wfp_delta_f0_f0_2( void );
109 void set_wfp_delta_f1( void );
108 void set_wfp_delta_f1( void );
110 void set_wfp_delta_f2( void );
109 void set_wfp_delta_f2( void );
111
110
112 //*****************
111 //*****************
113 // local parameters
112 // local parameters
114 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
113 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
115
114
116 #endif // WF_HANDLER_H_INCLUDED
115 #endif // WF_HANDLER_H_INCLUDED
@@ -1,25 +1,39
1 set(rtems_dir /opt/rtems-4.10/)
1 set(rtems_dir /opt/rtems-4.10/)
2
2
3 set(CMAKE_SYSTEM_NAME rtems)
3 set(CMAKE_SYSTEM_NAME rtems)
4 set(CMAKE_C_COMPILER ${rtems_dir}/bin/sparc-rtems-gcc)
4 set(CMAKE_C_COMPILER ${rtems_dir}/bin/sparc-rtems-gcc)
5 set(CMAKE_CXX_COMPILER ${rtems_dir}/bin/sparc-rtems-g++)
5 set(CMAKE_CXX_COMPILER ${rtems_dir}/bin/sparc-rtems-g++)
6 set(CMAKE_LINKER ${rtems_dir}/bin/sparc-rtems-g++)
6 set(CMAKE_LINKER ${rtems_dir}/bin/sparc-rtems-g++)
7 SET(CMAKE_EXE_LINKER_FLAGS "-static")
7 SET(CMAKE_EXE_LINKER_FLAGS "-static")
8 option(fix-b2bst "Activate -mfix-b2bst switch to mitigate \"LEON3FT Stale Cache Entry After Store with Data Tag Parity Error\" errata, GRLIB-TN-0009" ON)
8 option(fix-b2bst "Activate -mfix-b2bst switch to mitigate \"LEON3FT Stale Cache Entry After Store with Data Tag Parity Error\" errata, GRLIB-TN-0009" ON)
9
9
10 option(Coverage "Enables code coverage" OFF)
11
12
13 set(CMAKE_C_FLAGS_RELEASE "-O3")
14 set(CMAKE_C_FLAGS_DEBUG "-O0")
15
16
10 if(fix-b2bst)
17 if(fix-b2bst)
11 set(CMAKE_C_FLAGS_RELEASE "-O3 -mfix-b2bst")
18 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfix-b2bst")
12 else()
19 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfix-b2bst")
13 set(CMAKE_C_FLAGS_RELEASE "-O3")
14 endif()
20 endif()
15
21
22
16 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> -Xlinker -Map=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
23 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> -Xlinker -Map=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
17
24
18 include_directories("${rtems_dir}/sparc-rtems/leon3/lib/include")
25 include_directories("${rtems_dir}/sparc-rtems/leon3/lib/include")
19
26
20 function (check_b2bst target bin)
27 function (check_b2bst target bin)
21 add_custom_command(TARGET ${target}
28 add_custom_command(TARGET ${target}
22 POST_BUILD
29 POST_BUILD
23 COMMAND ${rtems_dir}/bin/sparc-rtems-objdump -d ${bin}/${target} | ${CMAKE_SOURCE_DIR}/sparc/leon3ft-b2bst-scan.tcl
30 COMMAND ${rtems_dir}/bin/sparc-rtems-objdump -d ${bin}/${target} | ${CMAKE_SOURCE_DIR}/sparc/leon3ft-b2bst-scan.tcl
24 )
31 )
25 endfunction()
32 endfunction()
33
34 function (build_srec target bin rev)
35 add_custom_command(TARGET ${target}
36 POST_BUILD
37 COMMAND ${rtems_dir}/bin/sparc-rtems-objcopy -j .data -F srec ${bin}/${target} RpwLfrApp_XXXX_data_rev-${rev}.srec && ${rtems_dir}/bin/sparc-rtems-objcopy -j .text -F srec ${bin}/${target} RpwLfrApp_XXXX_text_rev-${rev}.srec
38 )
39 endfunction()
@@ -1,112 +1,130
1 cmake_minimum_required (VERSION 2.6)
1 cmake_minimum_required (VERSION 2.6)
2 project (fsw)
2 project (fsw)
3
3
4 include(sparc-rtems)
4 include(sparc-rtems)
5 include(cppcheck)
5 include(cppcheck)
6
6
7 include_directories("../header"
7 include_directories("../header"
8 "../header/lfr_common_headers"
8 "../header/lfr_common_headers"
9 "../header/processing"
9 "../header/processing"
10 "../LFR_basic-parameters"
10 "../LFR_basic-parameters"
11 "../src")
11 "../src")
12
12
13 set(SOURCES wf_handler.c
13 set(SOURCES wf_handler.c
14 tc_handler.c
14 tc_handler.c
15 fsw_misc.c
15 fsw_misc.c
16 fsw_init.c
16 fsw_init.c
17 fsw_globals.c
17 fsw_globals.c
18 fsw_spacewire.c
18 fsw_spacewire.c
19 tc_load_dump_parameters.c
19 tc_load_dump_parameters.c
20 tm_lfr_tc_exe.c
20 tm_lfr_tc_exe.c
21 tc_acceptance.c
21 tc_acceptance.c
22 processing/fsw_processing.c
22 processing/fsw_processing.c
23 processing/avf0_prc0.c
23 processing/avf0_prc0.c
24 processing/avf1_prc1.c
24 processing/avf1_prc1.c
25 processing/avf2_prc2.c
25 processing/avf2_prc2.c
26 lfr_cpu_usage_report.c
26 lfr_cpu_usage_report.c
27 ${LFR_BP_SRC}
27 ${LFR_BP_SRC}
28 ../header/wf_handler.h
28 ../header/wf_handler.h
29 ../header/tc_handler.h
29 ../header/tc_handler.h
30 ../header/grlib_regs.h
30 ../header/grlib_regs.h
31 ../header/fsw_misc.h
31 ../header/fsw_misc.h
32 ../header/fsw_init.h
32 ../header/fsw_init.h
33 ../header/fsw_spacewire.h
33 ../header/fsw_spacewire.h
34 ../header/tc_load_dump_parameters.h
34 ../header/tc_load_dump_parameters.h
35 ../header/tm_lfr_tc_exe.h
35 ../header/tm_lfr_tc_exe.h
36 ../header/tc_acceptance.h
36 ../header/tc_acceptance.h
37 ../header/processing/fsw_processing.h
37 ../header/processing/fsw_processing.h
38 ../header/processing/avf0_prc0.h
38 ../header/processing/avf0_prc0.h
39 ../header/processing/avf1_prc1.h
39 ../header/processing/avf1_prc1.h
40 ../header/processing/avf2_prc2.h
40 ../header/processing/avf2_prc2.h
41 ../header/fsw_params_wf_handler.h
41 ../header/fsw_params_wf_handler.h
42 ../header/lfr_cpu_usage_report.h
42 ../header/lfr_cpu_usage_report.h
43 ../header/lfr_common_headers/ccsds_types.h
43 ../header/lfr_common_headers/ccsds_types.h
44 ../header/lfr_common_headers/fsw_params.h
44 ../header/lfr_common_headers/fsw_params.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
46 ../header/lfr_common_headers/fsw_params_processing.h
46 ../header/lfr_common_headers/fsw_params_processing.h
47 ../header/lfr_common_headers/tm_byte_positions.h
47 ../header/lfr_common_headers/tm_byte_positions.h
48 ../LFR_basic-parameters/basic_parameters.h
48 ../LFR_basic-parameters/basic_parameters.h
49 ../LFR_basic-parameters/basic_parameters_params.h
49 ../LFR_basic-parameters/basic_parameters_params.h
50 ../header/GscMemoryLPP.hpp
50 ../header/GscMemoryLPP.hpp
51 )
51 )
52
52
53
53
54 option(FSW_verbose "Enable verbose LFR" OFF)
54 option(FSW_verbose "Enable verbose LFR" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
59 option(FSW_vhdl_dev "?" OFF)
59 option(FSW_vhdl_dev "?" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
62 option(FSW_debug_tch "?" OFF)
62 option(FSW_debug_tch "?" OFF)
63 option(FSW_Instrument_Scrubbing "Enable scrubbing counter" OFF)
63
64
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
66 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N4 "15" CACHE STRING "Choose N4 FSW Version." FORCE)
68 set(SW_VERSION_N4 "20" CACHE STRING "Choose N4 FSW Version." FORCE)
68
69
69 if(FSW_verbose)
70 if(FSW_verbose)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 endif()
72 endif()
72 if(FSW_boot_messages)
73 if(FSW_boot_messages)
73 add_definitions(-DBOOT_MESSAGES)
74 add_definitions(-DBOOT_MESSAGES)
74 endif()
75 endif()
75 if(FSW_debug_messages)
76 if(FSW_debug_messages)
76 add_definitions(-DDEBUG_MESSAGES)
77 add_definitions(-DDEBUG_MESSAGES)
77 endif()
78 endif()
78 if(FSW_cpu_usage_report)
79 if(FSW_cpu_usage_report)
79 add_definitions(-DPRINT_TASK_STATISTICS)
80 add_definitions(-DPRINT_TASK_STATISTICS)
80 endif()
81 endif()
81 if(FSW_stack_report)
82 if(FSW_stack_report)
82 add_definitions(-DPRINT_STACK_REPORT)
83 add_definitions(-DPRINT_STACK_REPORT)
83 endif()
84 endif()
84 if(FSW_vhdl_dev)
85 if(FSW_vhdl_dev)
85 add_definitions(-DVHDL_DEV)
86 add_definitions(-DVHDL_DEV)
86 endif()
87 endif()
87 if(FSW_lpp_dpu_destid)
88 if(FSW_lpp_dpu_destid)
88 add_definitions(-DLPP_DPU_DESTID)
89 add_definitions(-DLPP_DPU_DESTID)
89 endif()
90 endif()
90 if(FSW_debug_watchdog)
91 if(FSW_debug_watchdog)
91 add_definitions(-DDEBUG_WATCHDOG)
92 add_definitions(-DDEBUG_WATCHDOG)
92 endif()
93 endif()
93 if(FSW_debug_tch)
94 if(FSW_debug_tch)
94 add_definitions(-DDEBUG_TCH)
95 add_definitions(-DDEBUG_TCH)
95 endif()
96 endif()
96
97
98
99
97 add_definitions(-DMSB_FIRST_TCH)
100 add_definitions(-DMSB_FIRST_TCH)
98
101
99 add_definitions(-DSWVERSION=-1-0)
102 add_definitions(-DSWVERSION=-1-0)
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
103 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
104 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
105 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
106 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
104
107
105 add_executable(fsw ${SOURCES})
108 add_executable(fsw ${SOURCES})
106
109
110 if(FSW_Instrument_Scrubbing)
111 add_definitions(-DENABLE_SCRUBBING_COUNTER)
112 endif()
113
114 if(Coverage)
115 target_link_libraries(fsw gcov)
116 SET_TARGET_PROPERTIES(fsw PROPERTIES COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
117 endif()
118
119
107 if(fix-b2bst)
120 if(fix-b2bst)
108 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
121 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
109 endif()
122 endif()
110
123
124 if(NOT FSW_lpp_dpu_destid)
125 build_srec(fsw ${CMAKE_CURRENT_BINARY_DIR} "${SW_VERSION_N1}-${SW_VERSION_N2}-${SW_VERSION_N3}-${SW_VERSION_N4}")
126 endif()
127
128
111 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
129 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
112
130
@@ -1,96 +1,119
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Global variables of the LFR flight software.
24 /** Global variables of the LFR flight software.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * Among global variables, there are:
29 * Among global variables, there are:
7 * - RTEMS names and id.
30 * - RTEMS names and id.
8 * - APB configuration registers.
31 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
32 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
33 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
34 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
35 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
36 * - the global dump parameter buffer.
14 *
37 *
15 */
38 */
16
39
17 #include <rtems.h>
40 #include <rtems.h>
18 #include <grspw.h>
41 #include <grspw.h>
19
42
20 #include "ccsds_types.h"
43 #include "ccsds_types.h"
21 #include "grlib_regs.h"
44 #include "grlib_regs.h"
22 #include "fsw_params.h"
45 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
46 #include "fsw_params_wf_handler.h"
24
47
25 #define NB_OF_TASKS 20
48
26 #define NB_OF_MISC_NAMES 5
49 #define NB_OF_MISC_NAMES 5
27
50
28 // RTEMS GLOBAL VARIABLES
51 // RTEMS GLOBAL VARIABLES
29 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
52 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
30 rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */
53 rtems_name Task_name[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task names */
31 rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */
54 rtems_id Task_id[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task ids */
32 rtems_name timecode_timer_name = 0;
55 rtems_name timecode_timer_name = 0;
33 rtems_id timecode_timer_id = RTEMS_ID_NONE;
56 rtems_id timecode_timer_id = RTEMS_ID_NONE;
34 rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic
57 rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic
35 rtems_id HK_id = RTEMS_ID_NONE;// id of the HK rate monotonic period
58 rtems_id HK_id = RTEMS_ID_NONE;// id of the HK rate monotonic period
36 rtems_name name_avgv_rate_monotonic = 0; // name of the AVGV rate monotonic
59 rtems_name name_avgv_rate_monotonic = 0; // name of the AVGV rate monotonic
37 rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period
60 rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period
38 int fdSPW = 0;
61 int fdSPW = 0;
39 int fdUART = 0;
62 int fdUART = 0;
40 unsigned char lfrCurrentMode = 0;
63 unsigned char lfrCurrentMode = 0;
41 unsigned char pa_bia_status_info = 0;
64 unsigned char pa_bia_status_info = 0;
42 unsigned char thisIsAnASMRestart = 0;
65 unsigned char thisIsAnASMRestart = 0;
43 unsigned char oneTcLfrUpdateTimeReceived = 0;
66 unsigned char oneTcLfrUpdateTimeReceived = 0;
44
67
45 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
68 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
46 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
69 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
47 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
70 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
48 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
71 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
49 // F0 F1 F2 F3
72 // F0 F1 F2 F3
50 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
73 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
51 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
74 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
52 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
75 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
53 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
76 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
54
77
55 //***********************************
78 //***********************************
56 // SPECTRAL MATRICES GLOBAL VARIABLES
79 // SPECTRAL MATRICES GLOBAL VARIABLES
57
80
58 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
81 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
59 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
82 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
60 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
83 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
61 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
84 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
62
85
63 // APB CONFIGURATION REGISTERS
86 // APB CONFIGURATION REGISTERS
64 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
87 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
65 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
88 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
66 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
89 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
67 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
90 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
68
91
69 // MODE PARAMETERS
92 // MODE PARAMETERS
70 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
93 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
71 struct param_local_str param_local = {0};
94 struct param_local_str param_local = {0};
72 unsigned int lastValidEnterModeTime = {0};
95 unsigned int lastValidEnterModeTime = {0};
73
96
74 // HK PACKETS
97 // HK PACKETS
75 Packet_TM_LFR_HK_t housekeeping_packet = {0};
98 Packet_TM_LFR_HK_t housekeeping_packet = {0};
76 // message queues occupancy
99 // message queues occupancy
77 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
100 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
78 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
101 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
79 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
102 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
103 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
104 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
82 // sequence counters are incremented by APID (PID + CAT) and destination ID
105 // sequence counters are incremented by APID (PID + CAT) and destination ID
83 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST __attribute__((aligned(0x4))) = 0;
106 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST __attribute__((aligned(0x4))) = 0;
84 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 __attribute__((aligned(0x4))) = 0;
107 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 __attribute__((aligned(0x4))) = 0;
85 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
108 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
86 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
109 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
87 unsigned short sequenceCounterHK __attribute__((aligned(0x4))) = {0};
110 unsigned short sequenceCounterHK __attribute__((aligned(0x4))) = {0};
88 spw_stats grspw_stats __attribute__((aligned(0x4))) = {0};
111 spw_stats grspw_stats __attribute__((aligned(0x4))) = {0};
89
112
90 // TC_LFR_UPDATE_INFO
113 // TC_LFR_UPDATE_INFO
91 rw_f_t rw_f;
114 rw_f_t rw_f;
92
115
93 // TC_LFR_LOAD_FILTER_PAR
116 // TC_LFR_LOAD_FILTER_PAR
94 filterPar_t filterPar = {0};
117 filterPar_t filterPar = {0};
95
118
96 fbins_masks_t fbins_masks = {0};
119 fbins_masks_t fbins_masks = {0};
@@ -1,974 +1,1029
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** This is the RTEMS initialization module.
25 /** This is the RTEMS initialization module.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * This module contains two very different information:
30 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
31 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
32 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
33 *
10 */
34 */
11
35
12 //*************************
36 #include <rtems.h>
13 // GPL reminder to be added
14 //*************************
15
37
16 #include <rtems.h>
17
38
18 /* configuration information */
39 /* configuration information */
19
40
20 #define CONFIGURE_INIT
41 #define CONFIGURE_INIT
21
42
22 #include <bsp.h> /* for device driver prototypes */
43 #include <bsp.h> /* for device driver prototypes */
23
44
24 /* configuration information */
45 /* configuration information */
25
46
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
47 #include <fsw_params.h>
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
29 #define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 6 // [hous] [load] [avgv]
38 #define CONFIGURE_MAXIMUM_TIMERS 6 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
43
48
44 #include <rtems/confdefs.h>
49 #include <rtems/confdefs.h>
45
50
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
51 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
52 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
53 #ifdef LEON3
49 /* Add Timer and UART Driver */
54 /* Add Timer and UART Driver */
50
55
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
56 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
58 #endif
54
59
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
60 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
61 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
62 #endif
58
63
59 #endif
64 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
65 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
66 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
63 #endif
67 #endif
64
68
65 #include "fsw_init.h"
69 #include "fsw_init.h"
66 #include "fsw_config.c"
70 #include "fsw_config.c"
67 #include "GscMemoryLPP.hpp"
71 #include "GscMemoryLPP.hpp"
68
72
69 void initCache()
73 void initCache()
70 {
74 {
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
75 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
72 // These should only be read and written using 32-bit LDA/STA instructions.
76 // These should only be read and written using 32-bit LDA/STA instructions.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
77 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
74 // The table below shows the register addresses:
78 // The table below shows the register addresses:
75 // 0x00 Cache control register
79 // 0x00 Cache control register
76 // 0x04 Reserved
80 // 0x04 Reserved
77 // 0x08 Instruction cache configuration register
81 // 0x08 Instruction cache configuration register
78 // 0x0C Data cache configuration register
82 // 0x0C Data cache configuration register
79
83
80 // Cache Control Register Leon3 / Leon3FT
84 // Cache Control Register Leon3 / Leon3FT
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
85 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
82 // RFT PS TB DS FD FI FT ST IB
86 // RFT PS TB DS FD FI FT ST IB
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
87 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
88 // IP DP ITE IDE DTE DDE DF IF DCS ICS
85
89
86 unsigned int cacheControlRegister;
90 unsigned int cacheControlRegister;
87
91
88 CCR_resetCacheControlRegister();
92 CCR_resetCacheControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
93 ASR16_resetRegisterProtectionControlRegister();
90
94
91 cacheControlRegister = CCR_getValue();
95 cacheControlRegister = CCR_getValue();
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
96 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
97 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
94
98
95 CCR_enableInstructionCache(); // ICS bits
99 CCR_enableInstructionCache(); // ICS bits
96 CCR_enableDataCache(); // DCS bits
100 CCR_enableDataCache(); // DCS bits
97 CCR_enableInstructionBurstFetch(); // IB bit
101 CCR_enableInstructionBurstFetch(); // IB bit
98
102
99 faultTolerantScheme();
103 faultTolerantScheme();
100
104
101 cacheControlRegister = CCR_getValue();
105 cacheControlRegister = CCR_getValue();
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
106 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
107 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
104
108
105 PRINTF("\n");
109 PRINTF("\n");
106 }
110 }
107
111
108 rtems_task Init( rtems_task_argument ignored )
112 rtems_task Init( rtems_task_argument ignored )
109 {
113 {
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
114 /** This is the RTEMS INIT taks, it is the first task launched by the system.
111 *
115 *
112 * @param unused is the starting argument of the RTEMS task
116 * @param unused is the starting argument of the RTEMS task
113 *
117 *
114 * The INIT task create and run all other RTEMS tasks.
118 * The INIT task create and run all other RTEMS tasks.
115 *
119 *
116 */
120 */
117
121
118 //***********
122 //***********
119 // INIT CACHE
123 // INIT CACHE
120
124
121 unsigned char *vhdlVersion;
125 unsigned char *vhdlVersion;
122
126
123 reset_lfr();
127 reset_lfr();
124
128
125 reset_local_time();
129 reset_local_time();
126
130
127 rtems_cpu_usage_reset();
131 rtems_cpu_usage_reset();
128
132
129 rtems_status_code status;
133 rtems_status_code status;
130 rtems_status_code status_spw;
134 rtems_status_code status_spw;
131 rtems_isr_entry old_isr_handler;
135 rtems_isr_entry old_isr_handler;
132
136
133 old_isr_handler = NULL;
137 old_isr_handler = NULL;
134
138
135 // UART settings
139 // UART settings
136 enable_apbuart_transmitter();
140 enable_apbuart_transmitter();
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
141 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
138
142
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
143 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
140
144
141
145
142 PRINTF("\n\n\n\n\n")
146 PRINTF("\n\n\n\n\n")
143
147
144 initCache();
148 initCache();
145
149
146 PRINTF("*************************\n")
150 PRINTF("*************************\n")
147 PRINTF("** LFR Flight Software **\n")
151 PRINTF("** LFR Flight Software **\n")
148
152
149 PRINTF1("** %d-", SW_VERSION_N1)
153 PRINTF1("** %d-", SW_VERSION_N1)
150 PRINTF1("%d-" , SW_VERSION_N2)
154 PRINTF1("%d-" , SW_VERSION_N2)
151 PRINTF1("%d-" , SW_VERSION_N3)
155 PRINTF1("%d-" , SW_VERSION_N3)
152 PRINTF1("%d **\n", SW_VERSION_N4)
156 PRINTF1("%d **\n", SW_VERSION_N4)
153
157
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
158 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
155 PRINTF("** VHDL **\n")
159 PRINTF("** VHDL **\n")
156 PRINTF1("** %d-", vhdlVersion[1])
160 PRINTF1("** %d-", vhdlVersion[1])
157 PRINTF1("%d-" , vhdlVersion[2])
161 PRINTF1("%d-" , vhdlVersion[2])
158 PRINTF1("%d **\n", vhdlVersion[3])
162 PRINTF1("%d **\n", vhdlVersion[3])
159 PRINTF("*************************\n")
163 PRINTF("*************************\n")
160 PRINTF("\n\n")
164 PRINTF("\n\n")
161
165
162 init_parameter_dump();
166 init_parameter_dump();
163 init_kcoefficients_dump();
167 init_kcoefficients_dump();
164 init_local_mode_parameters();
168 init_local_mode_parameters();
165 init_housekeeping_parameters();
169 init_housekeeping_parameters();
166 init_k_coefficients_prc0();
170 init_k_coefficients_prc0();
167 init_k_coefficients_prc1();
171 init_k_coefficients_prc1();
168 init_k_coefficients_prc2();
172 init_k_coefficients_prc2();
169 pa_bia_status_info = INIT_CHAR;
173 pa_bia_status_info = INIT_CHAR;
170
174
171 // initialize all reaction wheels frequencies to NaN
175 // initialize all reaction wheels frequencies to NaN
172 rw_f.cp_rpw_sc_rw1_f1 = NAN;
176 rw_f.cp_rpw_sc_rw1_f1 = NAN;
173 rw_f.cp_rpw_sc_rw1_f2 = NAN;
177 rw_f.cp_rpw_sc_rw1_f2 = NAN;
174 rw_f.cp_rpw_sc_rw1_f3 = NAN;
178 rw_f.cp_rpw_sc_rw1_f3 = NAN;
175 rw_f.cp_rpw_sc_rw1_f4 = NAN;
179 rw_f.cp_rpw_sc_rw1_f4 = NAN;
176 rw_f.cp_rpw_sc_rw2_f1 = NAN;
180 rw_f.cp_rpw_sc_rw2_f1 = NAN;
177 rw_f.cp_rpw_sc_rw2_f2 = NAN;
181 rw_f.cp_rpw_sc_rw2_f2 = NAN;
178 rw_f.cp_rpw_sc_rw2_f3 = NAN;
182 rw_f.cp_rpw_sc_rw2_f3 = NAN;
179 rw_f.cp_rpw_sc_rw2_f4 = NAN;
183 rw_f.cp_rpw_sc_rw2_f4 = NAN;
180 rw_f.cp_rpw_sc_rw3_f1 = NAN;
184 rw_f.cp_rpw_sc_rw3_f1 = NAN;
181 rw_f.cp_rpw_sc_rw3_f2 = NAN;
185 rw_f.cp_rpw_sc_rw3_f2 = NAN;
182 rw_f.cp_rpw_sc_rw3_f3 = NAN;
186 rw_f.cp_rpw_sc_rw3_f3 = NAN;
183 rw_f.cp_rpw_sc_rw3_f4 = NAN;
187 rw_f.cp_rpw_sc_rw3_f4 = NAN;
184 rw_f.cp_rpw_sc_rw4_f1 = NAN;
188 rw_f.cp_rpw_sc_rw4_f1 = NAN;
185 rw_f.cp_rpw_sc_rw4_f2 = NAN;
189 rw_f.cp_rpw_sc_rw4_f2 = NAN;
186 rw_f.cp_rpw_sc_rw4_f3 = NAN;
190 rw_f.cp_rpw_sc_rw4_f3 = NAN;
187 rw_f.cp_rpw_sc_rw4_f4 = NAN;
191 rw_f.cp_rpw_sc_rw4_f4 = NAN;
188
192
189 // initialize filtering parameters
193 // initialize filtering parameters
190 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
194 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
191 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
195 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
192 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
196 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
193 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
197 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
194 filterPar.modulus_in_finetime = DEFAULT_MODULUS;
198 filterPar.modulus_in_finetime = DEFAULT_MODULUS;
195 filterPar.tbad_in_finetime = DEFAULT_TBAD;
199 filterPar.tbad_in_finetime = DEFAULT_TBAD;
196 filterPar.offset_in_finetime = DEFAULT_OFFSET;
200 filterPar.offset_in_finetime = DEFAULT_OFFSET;
197 filterPar.shift_in_finetime = DEFAULT_SHIFT;
201 filterPar.shift_in_finetime = DEFAULT_SHIFT;
198 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
202 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
199
203
200 // waveform picker initialization
204 // waveform picker initialization
201 WFP_init_rings();
205 WFP_init_rings();
202 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
206 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
203 WFP_reset_current_ring_nodes();
207 WFP_reset_current_ring_nodes();
204 reset_waveform_picker_regs();
208 reset_waveform_picker_regs();
205
209
206 // spectral matrices initialization
210 // spectral matrices initialization
207 SM_init_rings(); // initialize spectral matrices rings
211 SM_init_rings(); // initialize spectral matrices rings
208 SM_reset_current_ring_nodes();
212 SM_reset_current_ring_nodes();
209 reset_spectral_matrix_regs();
213 reset_spectral_matrix_regs();
210
214
211 // configure calibration
215 // configure calibration
212 configureCalibration( false ); // true means interleaved mode, false is for normal mode
216 configureCalibration( false ); // true means interleaved mode, false is for normal mode
213
217
214 updateLFRCurrentMode( LFR_MODE_STANDBY );
218 updateLFRCurrentMode( LFR_MODE_STANDBY );
215
219
216 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
220 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
217
221
218 create_names(); // create all names
222 create_names(); // create all names
219
223
220 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
224 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
221 if (status != RTEMS_SUCCESSFUL)
225 if (status != RTEMS_SUCCESSFUL)
222 {
226 {
223 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
227 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
224 }
228 }
225
229
226 status = create_message_queues(); // create message queues
230 status = create_message_queues(); // create message queues
227 if (status != RTEMS_SUCCESSFUL)
231 if (status != RTEMS_SUCCESSFUL)
228 {
232 {
229 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
233 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
230 }
234 }
231
235
232 status = create_all_tasks(); // create all tasks
236 status = create_all_tasks(); // create all tasks
233 if (status != RTEMS_SUCCESSFUL)
237 if (status != RTEMS_SUCCESSFUL)
234 {
238 {
235 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
239 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
236 }
240 }
237
241
238 // **************************
242 // **************************
239 // <SPACEWIRE INITIALIZATION>
243 // <SPACEWIRE INITIALIZATION>
240 status_spw = spacewire_open_link(); // (1) open the link
244 status_spw = spacewire_open_link(); // (1) open the link
241 if ( status_spw != RTEMS_SUCCESSFUL )
245 if ( status_spw != RTEMS_SUCCESSFUL )
242 {
246 {
243 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
247 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
244 }
248 }
245
249
246 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
250 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
247 {
251 {
248 status_spw = spacewire_configure_link( fdSPW );
252 status_spw = spacewire_configure_link( fdSPW );
249 if ( status_spw != RTEMS_SUCCESSFUL )
253 if ( status_spw != RTEMS_SUCCESSFUL )
250 {
254 {
251 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
255 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
252 }
256 }
253 }
257 }
254
258
255 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
259 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
256 {
260 {
257 status_spw = spacewire_start_link( fdSPW );
261 status_spw = spacewire_start_link( fdSPW );
258 if ( status_spw != RTEMS_SUCCESSFUL )
262 if ( status_spw != RTEMS_SUCCESSFUL )
259 {
263 {
260 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
264 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
261 }
265 }
262 }
266 }
263 // </SPACEWIRE INITIALIZATION>
267 // </SPACEWIRE INITIALIZATION>
264 // ***************************
268 // ***************************
265
269
266 status = start_all_tasks(); // start all tasks
270 status = start_all_tasks(); // start all tasks
267 if (status != RTEMS_SUCCESSFUL)
271 if (status != RTEMS_SUCCESSFUL)
268 {
272 {
269 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
273 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
270 }
274 }
271
275
272 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
276 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
273 status = start_recv_send_tasks();
277 status = start_recv_send_tasks();
274 if ( status != RTEMS_SUCCESSFUL )
278 if ( status != RTEMS_SUCCESSFUL )
275 {
279 {
276 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
280 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
277 }
281 }
278
282
279 // suspend science tasks, they will be restarted later depending on the mode
283 // suspend science tasks, they will be restarted later depending on the mode
280 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
284 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
281 if (status != RTEMS_SUCCESSFUL)
285 if (status != RTEMS_SUCCESSFUL)
282 {
286 {
283 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
287 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
284 }
288 }
285
289
286 // configure IRQ handling for the waveform picker unit
290 // configure IRQ handling for the waveform picker unit
287 status = rtems_interrupt_catch( waveforms_isr,
291 status = rtems_interrupt_catch( waveforms_isr,
288 IRQ_SPARC_WAVEFORM_PICKER,
292 IRQ_SPARC_WAVEFORM_PICKER,
289 &old_isr_handler) ;
293 &old_isr_handler) ;
290 // configure IRQ handling for the spectral matrices unit
294 // configure IRQ handling for the spectral matrices unit
291 status = rtems_interrupt_catch( spectral_matrices_isr,
295 status = rtems_interrupt_catch( spectral_matrices_isr,
292 IRQ_SPARC_SPECTRAL_MATRIX,
296 IRQ_SPARC_SPECTRAL_MATRIX,
293 &old_isr_handler) ;
297 &old_isr_handler) ;
294
298
295 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
299 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
296 if ( status_spw != RTEMS_SUCCESSFUL )
300 if ( status_spw != RTEMS_SUCCESSFUL )
297 {
301 {
298 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
302 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
299 if ( status != RTEMS_SUCCESSFUL ) {
303 if ( status != RTEMS_SUCCESSFUL ) {
300 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
304 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
301 }
305 }
302 }
306 }
303
307
304 BOOT_PRINTF("delete INIT\n")
308 BOOT_PRINTF("delete INIT\n")
305
309
306 set_hk_lfr_sc_potential_flag( true );
310 set_hk_lfr_sc_potential_flag( true );
307
311
308 // start the timer to detect a missing spacewire timecode
312 // start the timer to detect a missing spacewire timecode
309 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
313 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
310 // if a tickout is generated, the timer is restarted
314 // if a tickout is generated, the timer is restarted
311 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
315 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
312
316
313 grspw_timecode_callback = &timecode_irq_handler;
317 grspw_timecode_callback = &timecode_irq_handler;
314
318
315 status = rtems_task_delete(RTEMS_SELF);
319 status = rtems_task_delete(RTEMS_SELF);
316
320
317 }
321 }
318
322
319 void init_local_mode_parameters( void )
323 void init_local_mode_parameters( void )
320 {
324 {
321 /** This function initialize the param_local global variable with default values.
325 /** This function initialize the param_local global variable with default values.
322 *
326 *
323 */
327 */
324
328
325 unsigned int i;
329 unsigned int i;
326
330
327 // LOCAL PARAMETERS
331 // LOCAL PARAMETERS
328
332
329 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
333 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
330 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
334 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
331
335
332 // init sequence counters
336 // init sequence counters
333
337
334 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
338 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
335 {
339 {
336 sequenceCounters_TC_EXE[i] = INIT_CHAR;
340 sequenceCounters_TC_EXE[i] = INIT_CHAR;
337 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
341 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
338 }
342 }
339 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
343 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
340 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
344 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
341 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
345 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
342 }
346 }
343
347
344 void reset_local_time( void )
348 void reset_local_time( void )
345 {
349 {
346 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
350 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
347 }
351 }
348
352
349 void create_names( void ) // create all names for tasks and queues
353 void create_names( void ) // create all names for tasks and queues
350 {
354 {
351 /** This function creates all RTEMS names used in the software for tasks and queues.
355 /** This function creates all RTEMS names used in the software for tasks and queues.
352 *
356 *
353 * @return RTEMS directive status codes:
357 * @return RTEMS directive status codes:
354 * - RTEMS_SUCCESSFUL - successful completion
358 * - RTEMS_SUCCESSFUL - successful completion
355 *
359 *
356 */
360 */
357
361
358 // task names
362 // task names
359 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
363 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
360 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
364 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
361 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
365 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
362 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
366 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
363 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
367 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
364 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
368 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
365 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
369 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
366 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
370 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
367 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
371 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
368 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
372 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
369 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
373 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
370 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
374 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
371 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
375 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
372 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
376 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
373 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
377 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
374 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
378 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
375 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
379 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
376 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
380 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
377 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
381 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
378 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
382 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
383 Task_name[TASKID_SCRB] = rtems_build_name( 'S', 'C', 'R', 'B' );
384 Task_name[TASKID_CALI] = rtems_build_name( 'C', 'A', 'L', 'I' );
379
385
380 // rate monotonic period names
386 // rate monotonic period names
381 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
387 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
382 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
388 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
383
389
384 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
390 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
385 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
391 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
386 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
392 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
387 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
393 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
388 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
394 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
389
395
390 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
396 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
391 }
397 }
392
398
393 int create_all_tasks( void ) // create all tasks which run in the software
399 int create_all_tasks( void ) // create all tasks which run in the software
394 {
400 {
395 /** This function creates all RTEMS tasks used in the software.
401 /** This function creates all RTEMS tasks used in the software.
396 *
402 *
397 * @return RTEMS directive status codes:
403 * @return RTEMS directive status codes:
398 * - RTEMS_SUCCESSFUL - task created successfully
404 * - RTEMS_SUCCESSFUL - task created successfully
399 * - RTEMS_INVALID_ADDRESS - id is NULL
405 * - RTEMS_INVALID_ADDRESS - id is NULL
400 * - RTEMS_INVALID_NAME - invalid task name
406 * - RTEMS_INVALID_NAME - invalid task name
401 * - RTEMS_INVALID_PRIORITY - invalid task priority
407 * - RTEMS_INVALID_PRIORITY - invalid task priority
402 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
408 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
403 * - RTEMS_TOO_MANY - too many tasks created
409 * - RTEMS_TOO_MANY - too many tasks created
404 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
410 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
405 * - RTEMS_TOO_MANY - too many global objects
411 * - RTEMS_TOO_MANY - too many global objects
406 *
412 *
407 */
413 */
408
414
409 rtems_status_code status;
415 rtems_status_code status;
410
416
411 //**********
417 //**********
412 // SPACEWIRE
418 // SPACEWIRE
413 // RECV
419 // RECV
414 status = rtems_task_create(
420 status = rtems_task_create(
415 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
421 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
416 RTEMS_DEFAULT_MODES,
422 RTEMS_DEFAULT_MODES,
417 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
423 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
418 );
424 );
419 if (status == RTEMS_SUCCESSFUL) // SEND
425 if (status == RTEMS_SUCCESSFUL) // SEND
420 {
426 {
421 status = rtems_task_create(
427 status = rtems_task_create(
422 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
428 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
423 RTEMS_DEFAULT_MODES,
429 RTEMS_DEFAULT_MODES,
424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
430 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
425 );
431 );
426 }
432 }
427 if (status == RTEMS_SUCCESSFUL) // LINK
433 if (status == RTEMS_SUCCESSFUL) // LINK
428 {
434 {
429 status = rtems_task_create(
435 status = rtems_task_create(
430 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
436 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
431 RTEMS_DEFAULT_MODES,
437 RTEMS_DEFAULT_MODES,
432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
438 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
433 );
439 );
434 }
440 }
435 if (status == RTEMS_SUCCESSFUL) // ACTN
441 if (status == RTEMS_SUCCESSFUL) // ACTN
436 {
442 {
437 status = rtems_task_create(
443 status = rtems_task_create(
438 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
444 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
439 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
445 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
440 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
446 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
441 );
447 );
442 }
448 }
443 if (status == RTEMS_SUCCESSFUL) // SPIQ
449 if (status == RTEMS_SUCCESSFUL) // SPIQ
444 {
450 {
445 status = rtems_task_create(
451 status = rtems_task_create(
446 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
452 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
447 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
453 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
448 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
454 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
449 );
455 );
450 }
456 }
451
457
452 //******************
458 //******************
453 // SPECTRAL MATRICES
459 // SPECTRAL MATRICES
454 if (status == RTEMS_SUCCESSFUL) // AVF0
460 if (status == RTEMS_SUCCESSFUL) // AVF0
455 {
461 {
456 status = rtems_task_create(
462 status = rtems_task_create(
457 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
463 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
458 RTEMS_DEFAULT_MODES,
464 RTEMS_DEFAULT_MODES,
459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
460 );
466 );
461 }
467 }
462 if (status == RTEMS_SUCCESSFUL) // PRC0
468 if (status == RTEMS_SUCCESSFUL) // PRC0
463 {
469 {
464 status = rtems_task_create(
470 status = rtems_task_create(
465 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
471 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
472 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
468 );
474 );
469 }
475 }
470 if (status == RTEMS_SUCCESSFUL) // AVF1
476 if (status == RTEMS_SUCCESSFUL) // AVF1
471 {
477 {
472 status = rtems_task_create(
478 status = rtems_task_create(
473 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
479 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
474 RTEMS_DEFAULT_MODES,
480 RTEMS_DEFAULT_MODES,
475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
481 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
476 );
482 );
477 }
483 }
478 if (status == RTEMS_SUCCESSFUL) // PRC1
484 if (status == RTEMS_SUCCESSFUL) // PRC1
479 {
485 {
480 status = rtems_task_create(
486 status = rtems_task_create(
481 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
487 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
488 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
489 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
484 );
490 );
485 }
491 }
486 if (status == RTEMS_SUCCESSFUL) // AVF2
492 if (status == RTEMS_SUCCESSFUL) // AVF2
487 {
493 {
488 status = rtems_task_create(
494 status = rtems_task_create(
489 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
495 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
490 RTEMS_DEFAULT_MODES,
496 RTEMS_DEFAULT_MODES,
491 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
492 );
498 );
493 }
499 }
494 if (status == RTEMS_SUCCESSFUL) // PRC2
500 if (status == RTEMS_SUCCESSFUL) // PRC2
495 {
501 {
496 status = rtems_task_create(
502 status = rtems_task_create(
497 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
503 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
498 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
504 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
499 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
505 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
500 );
506 );
501 }
507 }
502
508
503 //****************
509 //****************
504 // WAVEFORM PICKER
510 // WAVEFORM PICKER
505 if (status == RTEMS_SUCCESSFUL) // WFRM
511 if (status == RTEMS_SUCCESSFUL) // WFRM
506 {
512 {
507 status = rtems_task_create(
513 status = rtems_task_create(
508 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
514 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
509 RTEMS_DEFAULT_MODES,
515 RTEMS_DEFAULT_MODES,
510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
516 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
511 );
517 );
512 }
518 }
513 if (status == RTEMS_SUCCESSFUL) // CWF3
519 if (status == RTEMS_SUCCESSFUL) // CWF3
514 {
520 {
515 status = rtems_task_create(
521 status = rtems_task_create(
516 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
522 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
517 RTEMS_DEFAULT_MODES,
523 RTEMS_DEFAULT_MODES,
518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
524 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
519 );
525 );
520 }
526 }
521 if (status == RTEMS_SUCCESSFUL) // CWF2
527 if (status == RTEMS_SUCCESSFUL) // CWF2
522 {
528 {
523 status = rtems_task_create(
529 status = rtems_task_create(
524 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
530 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
525 RTEMS_DEFAULT_MODES,
531 RTEMS_DEFAULT_MODES,
526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
532 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
527 );
533 );
528 }
534 }
529 if (status == RTEMS_SUCCESSFUL) // CWF1
535 if (status == RTEMS_SUCCESSFUL) // CWF1
530 {
536 {
531 status = rtems_task_create(
537 status = rtems_task_create(
532 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
538 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
533 RTEMS_DEFAULT_MODES,
539 RTEMS_DEFAULT_MODES,
534 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
540 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
535 );
541 );
536 }
542 }
537 if (status == RTEMS_SUCCESSFUL) // SWBD
543 if (status == RTEMS_SUCCESSFUL) // SWBD
538 {
544 {
539 status = rtems_task_create(
545 status = rtems_task_create(
540 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
546 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
541 RTEMS_DEFAULT_MODES,
547 RTEMS_DEFAULT_MODES,
542 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
548 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
543 );
549 );
544 }
550 }
545
551
546 //*****
552 //*****
547 // MISC
553 // MISC
548 if (status == RTEMS_SUCCESSFUL) // LOAD
554 if (status == RTEMS_SUCCESSFUL) // LOAD
549 {
555 {
550 status = rtems_task_create(
556 status = rtems_task_create(
551 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
557 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
552 RTEMS_DEFAULT_MODES,
558 RTEMS_DEFAULT_MODES,
553 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
559 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
554 );
560 );
555 }
561 }
556 if (status == RTEMS_SUCCESSFUL) // DUMB
562 if (status == RTEMS_SUCCESSFUL) // DUMB
557 {
563 {
558 status = rtems_task_create(
564 status = rtems_task_create(
559 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
565 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
560 RTEMS_DEFAULT_MODES,
566 RTEMS_DEFAULT_MODES,
561 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
567 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
562 );
568 );
563 }
569 }
570 if (status == RTEMS_SUCCESSFUL) // SCRUBBING TASK
571 {
572 status = rtems_task_create(
573 Task_name[TASKID_SCRB], TASK_PRIORITY_SCRB, RTEMS_MINIMUM_STACK_SIZE,
574 RTEMS_DEFAULT_MODES,
575 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SCRB]
576 );
577 }
564 if (status == RTEMS_SUCCESSFUL) // HOUS
578 if (status == RTEMS_SUCCESSFUL) // HOUS
565 {
579 {
566 status = rtems_task_create(
580 status = rtems_task_create(
567 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
581 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
568 RTEMS_DEFAULT_MODES,
582 RTEMS_DEFAULT_MODES,
569 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
583 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
570 );
584 );
571 }
585 }
572 if (status == RTEMS_SUCCESSFUL) // AVGV
586 if (status == RTEMS_SUCCESSFUL) // AVGV
573 {
587 {
574 status = rtems_task_create(
588 status = rtems_task_create(
575 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
589 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
576 RTEMS_DEFAULT_MODES,
590 RTEMS_DEFAULT_MODES,
577 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
591 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
578 );
592 );
579 }
593 }
594 if (status == RTEMS_SUCCESSFUL) // CALI
595 {
596 status = rtems_task_create(
597 Task_name[TASKID_CALI], TASK_PRIORITY_CALI, RTEMS_MINIMUM_STACK_SIZE,
598 RTEMS_DEFAULT_MODES,
599 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CALI]
600 );
601 }
580
602
581 return status;
603 return status;
582 }
604 }
583
605
584 int start_recv_send_tasks( void )
606 int start_recv_send_tasks( void )
585 {
607 {
586 rtems_status_code status;
608 rtems_status_code status;
587
609
588 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
610 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
589 if (status!=RTEMS_SUCCESSFUL) {
611 if (status!=RTEMS_SUCCESSFUL) {
590 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
612 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
591 }
613 }
592
614
593 if (status == RTEMS_SUCCESSFUL) // SEND
615 if (status == RTEMS_SUCCESSFUL) // SEND
594 {
616 {
595 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
617 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
596 if (status!=RTEMS_SUCCESSFUL) {
618 if (status!=RTEMS_SUCCESSFUL) {
597 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
619 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
598 }
620 }
599 }
621 }
600
622
601 return status;
623 return status;
602 }
624 }
603
625
604 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
626 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
605 {
627 {
606 /** This function starts all RTEMS tasks used in the software.
628 /** This function starts all RTEMS tasks used in the software.
607 *
629 *
608 * @return RTEMS directive status codes:
630 * @return RTEMS directive status codes:
609 * - RTEMS_SUCCESSFUL - ask started successfully
631 * - RTEMS_SUCCESSFUL - ask started successfully
610 * - RTEMS_INVALID_ADDRESS - invalid task entry point
632 * - RTEMS_INVALID_ADDRESS - invalid task entry point
611 * - RTEMS_INVALID_ID - invalid task id
633 * - RTEMS_INVALID_ID - invalid task id
612 * - RTEMS_INCORRECT_STATE - task not in the dormant state
634 * - RTEMS_INCORRECT_STATE - task not in the dormant state
613 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
635 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
614 *
636 *
615 */
637 */
616 // starts all the tasks fot eh flight software
638 // starts all the tasks fot eh flight software
617
639
618 rtems_status_code status;
640 rtems_status_code status;
619
641
620 //**********
642 //**********
621 // SPACEWIRE
643 // SPACEWIRE
622 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
644 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
623 if (status!=RTEMS_SUCCESSFUL) {
645 if (status!=RTEMS_SUCCESSFUL) {
624 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
646 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
625 }
647 }
626
648
627 if (status == RTEMS_SUCCESSFUL) // LINK
649 if (status == RTEMS_SUCCESSFUL) // LINK
628 {
650 {
629 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
651 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
630 if (status!=RTEMS_SUCCESSFUL) {
652 if (status!=RTEMS_SUCCESSFUL) {
631 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
653 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
632 }
654 }
633 }
655 }
634
656
635 if (status == RTEMS_SUCCESSFUL) // ACTN
657 if (status == RTEMS_SUCCESSFUL) // ACTN
636 {
658 {
637 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
659 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
638 if (status!=RTEMS_SUCCESSFUL) {
660 if (status!=RTEMS_SUCCESSFUL) {
639 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
661 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
640 }
662 }
641 }
663 }
642
664
643 //******************
665 //******************
644 // SPECTRAL MATRICES
666 // SPECTRAL MATRICES
645 if (status == RTEMS_SUCCESSFUL) // AVF0
667 if (status == RTEMS_SUCCESSFUL) // AVF0
646 {
668 {
647 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
669 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
648 if (status!=RTEMS_SUCCESSFUL) {
670 if (status!=RTEMS_SUCCESSFUL) {
649 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
671 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
650 }
672 }
651 }
673 }
652 if (status == RTEMS_SUCCESSFUL) // PRC0
674 if (status == RTEMS_SUCCESSFUL) // PRC0
653 {
675 {
654 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
676 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
655 if (status!=RTEMS_SUCCESSFUL) {
677 if (status!=RTEMS_SUCCESSFUL) {
656 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
678 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
657 }
679 }
658 }
680 }
659 if (status == RTEMS_SUCCESSFUL) // AVF1
681 if (status == RTEMS_SUCCESSFUL) // AVF1
660 {
682 {
661 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
683 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
662 if (status!=RTEMS_SUCCESSFUL) {
684 if (status!=RTEMS_SUCCESSFUL) {
663 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
685 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
664 }
686 }
665 }
687 }
666 if (status == RTEMS_SUCCESSFUL) // PRC1
688 if (status == RTEMS_SUCCESSFUL) // PRC1
667 {
689 {
668 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
690 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
669 if (status!=RTEMS_SUCCESSFUL) {
691 if (status!=RTEMS_SUCCESSFUL) {
670 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
692 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
671 }
693 }
672 }
694 }
673 if (status == RTEMS_SUCCESSFUL) // AVF2
695 if (status == RTEMS_SUCCESSFUL) // AVF2
674 {
696 {
675 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
697 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
676 if (status!=RTEMS_SUCCESSFUL) {
698 if (status!=RTEMS_SUCCESSFUL) {
677 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
699 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
678 }
700 }
679 }
701 }
680 if (status == RTEMS_SUCCESSFUL) // PRC2
702 if (status == RTEMS_SUCCESSFUL) // PRC2
681 {
703 {
682 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
704 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
683 if (status!=RTEMS_SUCCESSFUL) {
705 if (status!=RTEMS_SUCCESSFUL) {
684 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
706 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
685 }
707 }
686 }
708 }
687
709
688 //****************
710 //****************
689 // WAVEFORM PICKER
711 // WAVEFORM PICKER
690 if (status == RTEMS_SUCCESSFUL) // WFRM
712 if (status == RTEMS_SUCCESSFUL) // WFRM
691 {
713 {
692 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
714 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
693 if (status!=RTEMS_SUCCESSFUL) {
715 if (status!=RTEMS_SUCCESSFUL) {
694 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
716 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
695 }
717 }
696 }
718 }
697 if (status == RTEMS_SUCCESSFUL) // CWF3
719 if (status == RTEMS_SUCCESSFUL) // CWF3
698 {
720 {
699 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
721 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
700 if (status!=RTEMS_SUCCESSFUL) {
722 if (status!=RTEMS_SUCCESSFUL) {
701 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
723 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
702 }
724 }
703 }
725 }
704 if (status == RTEMS_SUCCESSFUL) // CWF2
726 if (status == RTEMS_SUCCESSFUL) // CWF2
705 {
727 {
706 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
728 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
707 if (status!=RTEMS_SUCCESSFUL) {
729 if (status!=RTEMS_SUCCESSFUL) {
708 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
730 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
709 }
731 }
710 }
732 }
711 if (status == RTEMS_SUCCESSFUL) // CWF1
733 if (status == RTEMS_SUCCESSFUL) // CWF1
712 {
734 {
713 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
735 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
714 if (status!=RTEMS_SUCCESSFUL) {
736 if (status!=RTEMS_SUCCESSFUL) {
715 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
737 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
716 }
738 }
717 }
739 }
718 if (status == RTEMS_SUCCESSFUL) // SWBD
740 if (status == RTEMS_SUCCESSFUL) // SWBD
719 {
741 {
720 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
742 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
721 if (status!=RTEMS_SUCCESSFUL) {
743 if (status!=RTEMS_SUCCESSFUL) {
722 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
744 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
723 }
745 }
724 }
746 }
725
747
726 //*****
748 //*****
727 // MISC
749 // MISC
728 if (status == RTEMS_SUCCESSFUL) // HOUS
750 if (status == RTEMS_SUCCESSFUL) // HOUS
729 {
751 {
730 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
752 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
731 if (status!=RTEMS_SUCCESSFUL) {
753 if (status!=RTEMS_SUCCESSFUL) {
732 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
754 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
733 }
755 }
734 }
756 }
735 if (status == RTEMS_SUCCESSFUL) // AVGV
757 if (status == RTEMS_SUCCESSFUL) // AVGV
736 {
758 {
737 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
759 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
738 if (status!=RTEMS_SUCCESSFUL) {
760 if (status!=RTEMS_SUCCESSFUL) {
739 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
761 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
740 }
762 }
741 }
763 }
742 if (status == RTEMS_SUCCESSFUL) // DUMB
764 if (status == RTEMS_SUCCESSFUL) // DUMB
743 {
765 {
744 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
766 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
745 if (status!=RTEMS_SUCCESSFUL) {
767 if (status!=RTEMS_SUCCESSFUL) {
746 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
768 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
747 }
769 }
748 }
770 }
771 if (status == RTEMS_SUCCESSFUL) // SCRUBBING
772 {
773 status = rtems_task_start( Task_id[TASKID_SCRB], scrubbing_task, 1 );
774 if (status!=RTEMS_SUCCESSFUL) {
775 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
776 }
777 }
749 if (status == RTEMS_SUCCESSFUL) // LOAD
778 if (status == RTEMS_SUCCESSFUL) // LOAD
750 {
779 {
751 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
780 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
752 if (status!=RTEMS_SUCCESSFUL) {
781 if (status!=RTEMS_SUCCESSFUL) {
753 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
782 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
754 }
783 }
755 }
784 }
785 if (status == RTEMS_SUCCESSFUL) // CALI
786 {
787 status = rtems_task_start( Task_id[TASKID_CALI], calibration_sweep_task, 1 );
788 if (status!=RTEMS_SUCCESSFUL) {
789 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
790 }
791 }
756
792
757 return status;
793 return status;
758 }
794 }
759
795
760 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
796 rtems_status_code create_message_queues( void ) // create the five message queues used in the software
761 {
797 {
762 rtems_status_code status_recv;
798 rtems_status_code status_recv;
763 rtems_status_code status_send;
799 rtems_status_code status_send;
764 rtems_status_code status_q_p0;
800 rtems_status_code status_q_p0;
765 rtems_status_code status_q_p1;
801 rtems_status_code status_q_p1;
766 rtems_status_code status_q_p2;
802 rtems_status_code status_q_p2;
767 rtems_status_code ret;
803 rtems_status_code ret;
768 rtems_id queue_id;
804 rtems_id queue_id;
769
805
770 ret = RTEMS_SUCCESSFUL;
806 ret = RTEMS_SUCCESSFUL;
771 queue_id = RTEMS_ID_NONE;
807 queue_id = RTEMS_ID_NONE;
772
808
773 //****************************************
809 //****************************************
774 // create the queue for handling valid TCs
810 // create the queue for handling valid TCs
775 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
811 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
776 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
812 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
777 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
813 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
778 if ( status_recv != RTEMS_SUCCESSFUL ) {
814 if ( status_recv != RTEMS_SUCCESSFUL ) {
779 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
815 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
780 }
816 }
781
817
782 //************************************************
818 //************************************************
783 // create the queue for handling TM packet sending
819 // create the queue for handling TM packet sending
784 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
820 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
785 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
821 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
786 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
822 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
787 if ( status_send != RTEMS_SUCCESSFUL ) {
823 if ( status_send != RTEMS_SUCCESSFUL ) {
788 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
824 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
789 }
825 }
790
826
791 //*****************************************************************************
827 //*****************************************************************************
792 // create the queue for handling averaged spectral matrices for processing @ f0
828 // create the queue for handling averaged spectral matrices for processing @ f0
793 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
829 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
794 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
830 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
795 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
831 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
796 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
832 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
797 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
833 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
798 }
834 }
799
835
800 //*****************************************************************************
836 //*****************************************************************************
801 // create the queue for handling averaged spectral matrices for processing @ f1
837 // create the queue for handling averaged spectral matrices for processing @ f1
802 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
838 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
803 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
839 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
804 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
840 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
805 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
841 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
806 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
842 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
807 }
843 }
808
844
809 //*****************************************************************************
845 //*****************************************************************************
810 // create the queue for handling averaged spectral matrices for processing @ f2
846 // create the queue for handling averaged spectral matrices for processing @ f2
811 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
847 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
812 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
848 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
813 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
849 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
814 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
850 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
815 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
851 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
816 }
852 }
817
853
818 if ( status_recv != RTEMS_SUCCESSFUL )
854 if ( status_recv != RTEMS_SUCCESSFUL )
819 {
855 {
820 ret = status_recv;
856 ret = status_recv;
821 }
857 }
822 else if( status_send != RTEMS_SUCCESSFUL )
858 else if( status_send != RTEMS_SUCCESSFUL )
823 {
859 {
824 ret = status_send;
860 ret = status_send;
825 }
861 }
826 else if( status_q_p0 != RTEMS_SUCCESSFUL )
862 else if( status_q_p0 != RTEMS_SUCCESSFUL )
827 {
863 {
828 ret = status_q_p0;
864 ret = status_q_p0;
829 }
865 }
830 else if( status_q_p1 != RTEMS_SUCCESSFUL )
866 else if( status_q_p1 != RTEMS_SUCCESSFUL )
831 {
867 {
832 ret = status_q_p1;
868 ret = status_q_p1;
833 }
869 }
834 else
870 else
835 {
871 {
836 ret = status_q_p2;
872 ret = status_q_p2;
837 }
873 }
838
874
839 return ret;
875 return ret;
840 }
876 }
841
877
842 rtems_status_code create_timecode_timer( void )
878 rtems_status_code create_timecode_timer( void )
843 {
879 {
844 rtems_status_code status;
880 rtems_status_code status;
845
881
846 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
882 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
847
883
848 if ( status != RTEMS_SUCCESSFUL )
884 if ( status != RTEMS_SUCCESSFUL )
849 {
885 {
850 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
886 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
851 }
887 }
852 else
888 else
853 {
889 {
854 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
890 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
855 }
891 }
856
892
857 return status;
893 return status;
858 }
894 }
859
895
860 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
896 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
861 {
897 {
862 rtems_status_code status;
898 rtems_status_code status;
863 rtems_name queue_name;
899 rtems_name queue_name;
864
900
865 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
901 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
866
902
867 status = rtems_message_queue_ident( queue_name, 0, queue_id );
903 status = rtems_message_queue_ident( queue_name, 0, queue_id );
868
904
869 return status;
905 return status;
870 }
906 }
871
907
872 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
908 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
873 {
909 {
874 rtems_status_code status;
910 rtems_status_code status;
875 rtems_name queue_name;
911 rtems_name queue_name;
876
912
877 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
913 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
878
914
879 status = rtems_message_queue_ident( queue_name, 0, queue_id );
915 status = rtems_message_queue_ident( queue_name, 0, queue_id );
880
916
881 return status;
917 return status;
882 }
918 }
883
919
884 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
920 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
885 {
921 {
886 rtems_status_code status;
922 rtems_status_code status;
887 rtems_name queue_name;
923 rtems_name queue_name;
888
924
889 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
925 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
890
926
891 status = rtems_message_queue_ident( queue_name, 0, queue_id );
927 status = rtems_message_queue_ident( queue_name, 0, queue_id );
892
928
893 return status;
929 return status;
894 }
930 }
895
931
896 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
932 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
897 {
933 {
898 rtems_status_code status;
934 rtems_status_code status;
899 rtems_name queue_name;
935 rtems_name queue_name;
900
936
901 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
937 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
902
938
903 status = rtems_message_queue_ident( queue_name, 0, queue_id );
939 status = rtems_message_queue_ident( queue_name, 0, queue_id );
904
940
905 return status;
941 return status;
906 }
942 }
907
943
908 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
944 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
909 {
945 {
910 rtems_status_code status;
946 rtems_status_code status;
911 rtems_name queue_name;
947 rtems_name queue_name;
912
948
913 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
949 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
914
950
915 status = rtems_message_queue_ident( queue_name, 0, queue_id );
951 status = rtems_message_queue_ident( queue_name, 0, queue_id );
916
952
917 return status;
953 return status;
918 }
954 }
919
955
956 /**
957 * @brief update_queue_max_count returns max(fifo_size_max, pending_messages + 1)
958 * @param queue_id
959 * @param fifo_size_max
960 */
920 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
961 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
921 {
962 {
922 u_int32_t count;
963 u_int32_t count;
923 rtems_status_code status;
964 rtems_status_code status;
924
965
925 count = 0;
966 count = 0;
926
967
927 status = rtems_message_queue_get_number_pending( queue_id, &count );
968 status = rtems_message_queue_get_number_pending( queue_id, &count );
928
969
929 count = count + 1;
970 count = count + 1;
930
971
931 if (status != RTEMS_SUCCESSFUL)
972 if (status != RTEMS_SUCCESSFUL)
932 {
973 {
933 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
974 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
934 }
975 }
935 else
976 else
936 {
977 {
937 if (count > *fifo_size_max)
978 if (count > *fifo_size_max)
938 {
979 {
939 *fifo_size_max = count;
980 *fifo_size_max = count;
940 }
981 }
941 }
982 }
942 }
983 }
943
984
985 /**
986 * @brief init_ring initializes given ring buffer
987 * @param ring array of nodes to initialize
988 * @param nbNodes number of node in the ring buffer
989 * @param buffer memory space given to the ring buffer
990 * @param bufferSize size of the whole ring buffer memory space
991 *
992 * @details This function creates a circular buffer from a given number of nodes and a given memory space. It first sets all nodes attributes to thier defaults values
993 * and associates a portion of the given memory space with each node. Then it connects each nodes to build a circular buffer.
994 *
995 * Each node capacity will be bufferSize/nbNodes.
996 *
997 * https://en.wikipedia.org/wiki/Circular_buffer
998 */
944 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
999 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
945 {
1000 {
946 unsigned char i;
1001 unsigned char i;
947
1002
948 //***************
1003 //***************
949 // BUFFER ADDRESS
1004 // BUFFER ADDRESS
950 for(i=0; i<nbNodes; i++)
1005 for(i=0; i<nbNodes; i++)
951 {
1006 {
952 ring[i].coarseTime = INT32_ALL_F;
1007 ring[i].coarseTime = INT32_ALL_F;
953 ring[i].fineTime = INT32_ALL_F;
1008 ring[i].fineTime = INT32_ALL_F;
954 ring[i].sid = INIT_CHAR;
1009 ring[i].sid = INIT_CHAR;
955 ring[i].status = INIT_CHAR;
1010 ring[i].status = INIT_CHAR;
956 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
1011 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
957 }
1012 }
958
1013
959 //*****
1014 //*****
960 // NEXT
1015 // NEXT
961 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
1016 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
962 for(i=0; i<nbNodes-1; i++)
1017 for(i=0; i<nbNodes-1; i++)
963 {
1018 {
964 ring[i].next = (ring_node*) &ring[ i + 1 ];
1019 ring[i].next = (ring_node*) &ring[ i + 1 ];
965 }
1020 }
966
1021
967 //*********
1022 //*********
968 // PREVIOUS
1023 // PREVIOUS
969 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
1024 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
970 for(i=1; i<nbNodes; i++)
1025 for(i=1; i<nbNodes; i++)
971 {
1026 {
972 ring[i].previous = (ring_node*) &ring[ i - 1 ];
1027 ring[i].previous = (ring_node*) &ring[ i - 1 ];
973 }
1028 }
974 }
1029 }
@@ -1,1036 +1,1109
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** General usage functions and RTEMS tasks.
25 /** General usage functions and RTEMS tasks.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 */
30 */
7
31
8 #include "fsw_misc.h"
32 #include "fsw_misc.h"
9
33
10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
34 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
35 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
36 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
13
37
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
38 void timer_configure(unsigned char timer, unsigned int clock_divider,
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
39 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
16 {
40 {
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
41 /** This function configures a GPTIMER timer instantiated in the VHDL design.
18 *
42 *
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
45 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
22 * @param interrupt_level is the interrupt level that the timer drives.
46 * @param interrupt_level is the interrupt level that the timer drives.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
47 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
24 *
48 *
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
49 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
26 *
50 *
27 */
51 */
28
52
29 rtems_status_code status;
53 rtems_status_code status;
30 rtems_isr_entry old_isr_handler;
54 rtems_isr_entry old_isr_handler;
31
55
32 old_isr_handler = NULL;
56 old_isr_handler = NULL;
33
57
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
58 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
35
59
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
60 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
37 if (status!=RTEMS_SUCCESSFUL)
61 if (status!=RTEMS_SUCCESSFUL)
38 {
62 {
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
63 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
40 }
64 }
41
65
42 timer_set_clock_divider( timer, clock_divider);
66 timer_set_clock_divider( timer, clock_divider);
43 }
67 }
44
68
45 void timer_start(unsigned char timer)
69 void timer_start(unsigned char timer)
46 {
70 {
47 /** This function starts a GPTIMER timer.
71 /** This function starts a GPTIMER timer.
48 *
72 *
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
51 *
75 *
52 */
76 */
53
77
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
78 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
79 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
80 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
81 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
82 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
59 }
83 }
60
84
61 void timer_stop(unsigned char timer)
85 void timer_stop(unsigned char timer)
62 {
86 {
63 /** This function stops a GPTIMER timer.
87 /** This function stops a GPTIMER timer.
64 *
88 *
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
89 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
90 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
67 *
91 *
68 */
92 */
69
93
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
94 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
95 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
96 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
73 }
97 }
74
98
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
99 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
76 {
100 {
77 /** This function sets the clock divider of a GPTIMER timer.
101 /** This function sets the clock divider of a GPTIMER timer.
78 *
102 *
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
103 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
104 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
105 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
82 *
106 *
83 */
107 */
84
108
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
109 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
86 }
110 }
87
111
88 // WATCHDOG
112 // WATCHDOG, this ISR should never be triggered.
89
113
90 rtems_isr watchdog_isr( rtems_vector_number vector )
114 rtems_isr watchdog_isr( rtems_vector_number vector )
91 {
115 {
92 rtems_status_code status_code;
116 rtems_status_code status_code;
93
117
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
118 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
95
119
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
120 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
97
121
98 exit(0);
122 exit(0);
99 }
123 }
100
124
101 void watchdog_configure(void)
125 void watchdog_configure(void)
102 {
126 {
103 /** This function configure the watchdog.
127 /** This function configure the watchdog.
104 *
128 *
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
129 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
130 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
107 *
131 *
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
132 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
109 *
133 *
110 */
134 */
111
135
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
136 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
113
137
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
138 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
115
139
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
140 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 }
141 }
118
142
119 void watchdog_stop(void)
143 void watchdog_stop(void)
120 {
144 {
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
145 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
122 timer_stop( TIMER_WATCHDOG );
146 timer_stop( TIMER_WATCHDOG );
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
147 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
124 }
148 }
125
149
126 void watchdog_reload(void)
150 void watchdog_reload(void)
127 {
151 {
128 /** This function reloads the watchdog timer counter with the timer reload value.
152 /** This function reloads the watchdog timer counter with the timer reload value.
129 *
153 *
130 * @param void
154 * @param void
131 *
155 *
132 * @return void
156 * @return void
133 *
157 *
134 */
158 */
135
159
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
160 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
137 }
161 }
138
162
139 void watchdog_start(void)
163 void watchdog_start(void)
140 {
164 {
141 /** This function starts the watchdog timer.
165 /** This function starts the watchdog timer.
142 *
166 *
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
167 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
168 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
145 *
169 *
146 */
170 */
147
171
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
172 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
149
173
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
174 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
175 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
176 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
177 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
154
178
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
179 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
156
180
157 }
181 }
158
182
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
183 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
160 {
184 {
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
185 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
162
186
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
187 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
164
188
165 return 0;
189 return 0;
166 }
190 }
167
191
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
192 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
169 {
193 {
170 /** This function sets the scaler reload register of the apbuart module
194 /** This function sets the scaler reload register of the apbuart module
171 *
195 *
172 * @param regs is the address of the apbuart registers in memory
196 * @param regs is the address of the apbuart registers in memory
173 * @param value is the value that will be stored in the scaler register
197 * @param value is the value that will be stored in the scaler register
174 *
198 *
175 * The value shall be set by the software to get data on the serial interface.
199 * The value shall be set by the software to get data on the serial interface.
176 *
200 *
177 */
201 */
178
202
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
203 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
180
204
181 apbuart_regs->scaler = value;
205 apbuart_regs->scaler = value;
182
206
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
207 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
184 }
208 }
185
209
186 //************
210 /**
187 // RTEMS TASKS
211 * @brief load_task starts and keeps the watchdog alive.
212 * @param argument
213 * @return
214 */
188
215
189 rtems_task load_task(rtems_task_argument argument)
216 rtems_task load_task(rtems_task_argument argument)
190 {
217 {
191 BOOT_PRINTF("in LOAD *** \n")
218 BOOT_PRINTF("in LOAD *** \n")
192
219
193 rtems_status_code status;
220 rtems_status_code status;
194 unsigned int i;
221 unsigned int i;
195 unsigned int j;
222 unsigned int j;
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
223 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
224 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
198
225
199 watchdog_period_id = RTEMS_ID_NONE;
226 watchdog_period_id = RTEMS_ID_NONE;
200
227
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
228 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
202
229
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
230 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
204 if( status != RTEMS_SUCCESSFUL ) {
231 if( status != RTEMS_SUCCESSFUL ) {
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
232 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
206 }
233 }
207
234
208 i = 0;
235 i = 0;
209 j = 0;
236 j = 0;
210
237
211 watchdog_configure();
238 watchdog_configure();
212
239
213 watchdog_start();
240 watchdog_start();
214
241
215 set_sy_lfr_watchdog_enabled( true );
242 set_sy_lfr_watchdog_enabled( true );
216
243
217 while(1){
244 while(1){
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
245 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
219 watchdog_reload();
246 watchdog_reload();
220 i = i + 1;
247 i = i + 1;
221 if ( i == WATCHDOG_LOOP_PRINTF )
248 if ( i == WATCHDOG_LOOP_PRINTF )
222 {
249 {
223 i = 0;
250 i = 0;
224 j = j + 1;
251 j = j + 1;
225 PRINTF1("%d\n", j)
252 PRINTF1("%d\n", j)
226 }
253 }
227 #ifdef DEBUG_WATCHDOG
254 #ifdef DEBUG_WATCHDOG
228 if (j == WATCHDOG_LOOP_DEBUG )
255 if (j == WATCHDOG_LOOP_DEBUG )
229 {
256 {
230 status = rtems_task_delete(RTEMS_SELF);
257 status = rtems_task_delete(RTEMS_SELF);
231 }
258 }
232 #endif
259 #endif
233 }
260 }
234 }
261 }
235
262
263 /**
264 * @brief hous_task produces and sends HK each seconds
265 * @param argument
266 * @return
267 */
236 rtems_task hous_task(rtems_task_argument argument)
268 rtems_task hous_task(rtems_task_argument argument)
237 {
269 {
238 rtems_status_code status;
270 rtems_status_code status;
239 rtems_status_code spare_status;
271 rtems_status_code spare_status;
240 rtems_id queue_id;
272 rtems_id queue_id;
241 rtems_rate_monotonic_period_status period_status;
273 rtems_rate_monotonic_period_status period_status;
242 bool isSynchronized;
274 bool isSynchronized;
243
275
244 queue_id = RTEMS_ID_NONE;
276 queue_id = RTEMS_ID_NONE;
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
277 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
246 isSynchronized = false;
278 isSynchronized = false;
247
279
248 status = get_message_queue_id_send( &queue_id );
280 status = get_message_queue_id_send( &queue_id );
249 if (status != RTEMS_SUCCESSFUL)
281 if (status != RTEMS_SUCCESSFUL)
250 {
282 {
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
283 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
252 }
284 }
253
285
254 BOOT_PRINTF("in HOUS ***\n");
286 BOOT_PRINTF("in HOUS ***\n");
255
287
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
288 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
289 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
258 if( status != RTEMS_SUCCESSFUL ) {
290 if( status != RTEMS_SUCCESSFUL ) {
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
291 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
260 }
292 }
261 }
293 }
262
294
263 status = rtems_rate_monotonic_cancel(HK_id);
295 status = rtems_rate_monotonic_cancel(HK_id);
264 if( status != RTEMS_SUCCESSFUL ) {
296 if( status != RTEMS_SUCCESSFUL ) {
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
297 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
266 }
298 }
267 else {
299 else {
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
300 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
269 }
301 }
270
302
271 // startup phase
303 // startup phase
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
304 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
305 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
306 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
307 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
308 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
277 {
309 {
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
310 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
279 {
311 {
280 isSynchronized = true;
312 isSynchronized = true;
281 }
313 }
282 else
314 else
283 {
315 {
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
316 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
285
317
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
318 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
287 }
319 }
288 }
320 }
289 status = rtems_rate_monotonic_cancel(HK_id);
321 status = rtems_rate_monotonic_cancel(HK_id);
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
322 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
291
323
292 set_hk_lfr_reset_cause( POWER_ON );
324 set_hk_lfr_reset_cause( POWER_ON );
293
325
294 while(1){ // launch the rate monotonic task
326 while(1){ // launch the rate monotonic task
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
327 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
296 if ( status != RTEMS_SUCCESSFUL ) {
328 if ( status != RTEMS_SUCCESSFUL ) {
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
329 PRINTF1( "in HOUS *** ERR period: %d\n", status);
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
330 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
299 }
331 }
300 else {
332 else {
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
333 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
334 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
335 increment_seq_counter( &sequenceCounterHK );
304
336
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
337 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
338 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
339 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
340 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
341 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
342 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
311
343
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
344 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
313
345
314 spacewire_read_statistics();
346 spacewire_read_statistics();
315
347
316 update_hk_with_grspw_stats();
348 update_hk_with_grspw_stats();
317
349
318 set_hk_lfr_time_not_synchro();
350 set_hk_lfr_time_not_synchro();
319
351
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
352 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
353 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
354 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
355 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
356 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
325
357
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
358 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
359 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
360 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
361 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
362 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
331
363
332 hk_lfr_le_me_he_update();
364 hk_lfr_le_me_he_update();
333
365
334 // SEND PACKET
366 // SEND PACKET
335 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
367 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
336 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
368 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
337 if (status != RTEMS_SUCCESSFUL) {
369 if (status != RTEMS_SUCCESSFUL) {
338 PRINTF1("in HOUS *** ERR send: %d\n", status)
370 PRINTF1("in HOUS *** ERR send: %d\n", status)
339 }
371 }
340 }
372 }
341 }
373 }
342
374
343 PRINTF("in HOUS *** deleting task\n")
375 PRINTF("in HOUS *** deleting task\n")
344
376
345 status = rtems_task_delete( RTEMS_SELF ); // should not return
377 status = rtems_task_delete( RTEMS_SELF ); // should not return
346
378
347 return;
379 return;
348 }
380 }
349
381
382 /**
383 * @brief filter is a Direct-Form-II filter implementation, mostly used to filter electric field for HK
384 * @param x, new sample
385 * @param ctx, filter context, used to store previous input and output samples
386 * @return a new filtered sample
387 */
350 int filter( int x, filter_ctx* ctx )
388 int filter( int x, filter_ctx* ctx )
351 {
389 {
352 static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} };
390 static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} };
353 static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} };
391 static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} };
354 static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2};
392 static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2};
355 static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2};
393 static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2};
356
394
357 int_fast32_t W;
395 int_fast32_t W;
358 int i;
396 int i;
359
397
360 W = INIT_INT;
398 W = INIT_INT;
361 i = INIT_INT;
399 i = INIT_INT;
362
400
363 //Direct-Form-II
401 //Direct-Form-II
364 for ( i = 0; i < NB_COEFFS; i++ )
402 for ( i = 0; i < NB_COEFFS; i++ )
365 {
403 {
366 x = x << a_gain[i];
404 x = x << a_gain[i];
367 W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] )
405 W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] )
368 - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i];
406 - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i];
369 x = ( b[i][COEFF0] * W )
407 x = ( b[i][COEFF0] * W )
370 + ( b[i][COEFF1] * ctx->W[i][COEFF0] )
408 + ( b[i][COEFF1] * ctx->W[i][COEFF0] )
371 + ( b[i][COEFF2] * ctx->W[i][COEFF1] );
409 + ( b[i][COEFF2] * ctx->W[i][COEFF1] );
372 x = x >> b_gain[i];
410 x = x >> b_gain[i];
373 ctx->W[i][1] = ctx->W[i][0];
411 ctx->W[i][1] = ctx->W[i][0];
374 ctx->W[i][0] = W;
412 ctx->W[i][0] = W;
375 }
413 }
376 return x;
414 return x;
377 }
415 }
378
416
417 /**
418 * @brief avgv_task pruduces HK rate elctrical field from F3 data
419 * @param argument
420 * @return
421 */
379 rtems_task avgv_task(rtems_task_argument argument)
422 rtems_task avgv_task(rtems_task_argument argument)
380 {
423 {
381 #define MOVING_AVERAGE 16
424 #define MOVING_AVERAGE 16
382 rtems_status_code status;
425 rtems_status_code status;
383 static int32_t v[MOVING_AVERAGE] = {0};
426 static int32_t v[MOVING_AVERAGE] = {0};
384 static int32_t e1[MOVING_AVERAGE] = {0};
427 static int32_t e1[MOVING_AVERAGE] = {0};
385 static int32_t e2[MOVING_AVERAGE] = {0};
428 static int32_t e2[MOVING_AVERAGE] = {0};
386 static int old_v = 0;
429 static int old_v = 0;
387 static int old_e1 = 0;
430 static int old_e1 = 0;
388 static int old_e2 = 0;
431 static int old_e2 = 0;
389 int32_t current_v;
432 int32_t current_v;
390 int32_t current_e1;
433 int32_t current_e1;
391 int32_t current_e2;
434 int32_t current_e2;
392 int32_t average_v;
435 int32_t average_v;
393 int32_t average_e1;
436 int32_t average_e1;
394 int32_t average_e2;
437 int32_t average_e2;
395 int32_t newValue_v;
438 int32_t newValue_v;
396 int32_t newValue_e1;
439 int32_t newValue_e1;
397 int32_t newValue_e2;
440 int32_t newValue_e2;
398 unsigned char k;
441 unsigned char k;
399 unsigned char indexOfOldValue;
442 unsigned char indexOfOldValue;
400
443
401 static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } };
444 static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } };
402 static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
445 static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
403 static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
446 static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
404
447
405 BOOT_PRINTF("in AVGV ***\n");
448 BOOT_PRINTF("in AVGV ***\n");
406
449
407 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
450 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
408 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
451 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
409 if( status != RTEMS_SUCCESSFUL ) {
452 if( status != RTEMS_SUCCESSFUL ) {
410 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
453 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
411 }
454 }
412 }
455 }
413
456
414 status = rtems_rate_monotonic_cancel(AVGV_id);
457 status = rtems_rate_monotonic_cancel(AVGV_id);
415 if( status != RTEMS_SUCCESSFUL ) {
458 if( status != RTEMS_SUCCESSFUL ) {
416 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
459 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
417 }
460 }
418 else {
461 else {
419 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
462 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
420 }
463 }
421
464
422 // initialize values
465 // initialize values
423 indexOfOldValue = MOVING_AVERAGE - 1;
466 indexOfOldValue = MOVING_AVERAGE - 1;
424 current_v = 0;
467 current_v = 0;
425 current_e1 = 0;
468 current_e1 = 0;
426 current_e2 = 0;
469 current_e2 = 0;
427 average_v = 0;
470 average_v = 0;
428 average_e1 = 0;
471 average_e1 = 0;
429 average_e2 = 0;
472 average_e2 = 0;
430 newValue_v = 0;
473 newValue_v = 0;
431 newValue_e1 = 0;
474 newValue_e1 = 0;
432 newValue_e2 = 0;
475 newValue_e2 = 0;
433
476
434 k = INIT_CHAR;
477 k = INIT_CHAR;
435
478
436 while(1)
479 while(1)
437 { // launch the rate monotonic task
480 { // launch the rate monotonic task
438 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
481 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
439 if ( status != RTEMS_SUCCESSFUL )
482 if ( status != RTEMS_SUCCESSFUL )
440 {
483 {
441 PRINTF1( "in AVGV *** ERR period: %d\n", status);
484 PRINTF1( "in AVGV *** ERR period: %d\n", status);
442 }
485 }
443 else
486 else
444 {
487 {
445 current_v = waveform_picker_regs->v;
488 current_v = waveform_picker_regs->v;
446 current_e1 = waveform_picker_regs->e1;
489 current_e1 = waveform_picker_regs->e1;
447 current_e2 = waveform_picker_regs->e2;
490 current_e2 = waveform_picker_regs->e2;
448 if ( (current_v != old_v)
491 if ( (current_v != old_v)
449 || (current_e1 != old_e1)
492 || (current_e1 != old_e1)
450 || (current_e2 != old_e2))
493 || (current_e2 != old_e2))
451 {
494 {
452 average_v = filter( current_v, &ctx_v );
495 average_v = filter( current_v, &ctx_v );
453 average_e1 = filter( current_e1, &ctx_e1 );
496 average_e1 = filter( current_e1, &ctx_e1 );
454 average_e2 = filter( current_e2, &ctx_e2 );
497 average_e2 = filter( current_e2, &ctx_e2 );
455
498
456 //update int16 values
499 //update int16 values
457 hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v;
500 hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v;
458 hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1;
501 hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1;
459 hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2;
502 hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2;
460 }
503 }
461 old_v = current_v;
504 old_v = current_v;
462 old_e1 = current_e1;
505 old_e1 = current_e1;
463 old_e2 = current_e2;
506 old_e2 = current_e2;
464 }
507 }
465 }
508 }
466
509
467 PRINTF("in AVGV *** deleting task\n");
510 PRINTF("in AVGV *** deleting task\n");
468
511
469 status = rtems_task_delete( RTEMS_SELF ); // should not return
512 status = rtems_task_delete( RTEMS_SELF ); // should not return
470
513
471 return;
514 return;
472 }
515 }
473
516
474 rtems_task dumb_task( rtems_task_argument unused )
517 rtems_task dumb_task( rtems_task_argument unused )
475 {
518 {
476 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
519 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
477 *
520 *
478 * @param unused is the starting argument of the RTEMS task
521 * @param unused is the starting argument of the RTEMS task
479 *
522 *
480 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
523 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
481 *
524 *
482 */
525 */
483
526
484 unsigned int i;
527 unsigned int i;
485 unsigned int intEventOut;
528 unsigned int intEventOut;
486 unsigned int coarse_time = 0;
529 unsigned int coarse_time = 0;
487 unsigned int fine_time = 0;
530 unsigned int fine_time = 0;
488 rtems_event_set event_out;
531 rtems_event_set event_out;
489
532
490 event_out = EVENT_SETS_NONE_PENDING;
533 event_out = EVENT_SETS_NONE_PENDING;
491
534
492 BOOT_PRINTF("in DUMB *** \n")
535 BOOT_PRINTF("in DUMB *** \n")
493
536
494 while(1){
537 while(1){
495 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
538 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
496 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
539 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
497 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
540 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
498 | RTEMS_EVENT_14,
541 | RTEMS_EVENT_14,
499 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
542 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
500 intEventOut = (unsigned int) event_out;
543 intEventOut = (unsigned int) event_out;
501 for ( i=0; i<NB_RTEMS_EVENTS; i++)
544 for ( i=0; i<NB_RTEMS_EVENTS; i++)
502 {
545 {
503 if ( ((intEventOut >> i) & 1) != 0)
546 if ( ((intEventOut >> i) & 1) != 0)
504 {
547 {
505 coarse_time = time_management_regs->coarse_time;
548 coarse_time = time_management_regs->coarse_time;
506 fine_time = time_management_regs->fine_time;
549 fine_time = time_management_regs->fine_time;
507 if (i==EVENT_12)
550 if (i==EVENT_12)
508 {
551 {
509 PRINTF1("%s\n", DUMB_MESSAGE_12)
552 PRINTF1("%s\n", DUMB_MESSAGE_12)
510 }
553 }
511 if (i==EVENT_13)
554 if (i==EVENT_13)
512 {
555 {
513 PRINTF1("%s\n", DUMB_MESSAGE_13)
556 PRINTF1("%s\n", DUMB_MESSAGE_13)
514 }
557 }
515 if (i==EVENT_14)
558 if (i==EVENT_14)
516 {
559 {
517 PRINTF1("%s\n", DUMB_MESSAGE_1)
560 PRINTF1("%s\n", DUMB_MESSAGE_1)
518 }
561 }
519 }
562 }
520 }
563 }
521 }
564 }
522 }
565 }
523
566
567 rtems_task scrubbing_task( rtems_task_argument unused )
568 {
569 /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency.
570 *
571 * @param unused is the starting argument of the RTEMS task
572 *
573 * The scrubbing reads continuously memory when no other tasks are ready.
574 *
575 */
576
577 BOOT_PRINTF("in SCRUBBING *** \n");
578 volatile int i=0;
579 volatile float valuef = 1.;
580 volatile uint32_t* RAM=(uint32_t*)0x40000000;
581 volatile uint32_t value;
582 #ifdef ENABLE_SCRUBBING_COUNTER
583 housekeeping_packet.lfr_fpga_version[BYTE_0] = 0;
584 #endif
585 while(1){
586 i=(i+1)%(1024*1024);
587 valuef += 10.f*(float)RAM[i];
588 #ifdef ENABLE_SCRUBBING_COUNTER
589 if(i==0)
590 {
591 housekeeping_packet.lfr_fpga_version[BYTE_0] += 1;
592 }
593 #endif
594 }
595 }
596
597 rtems_task calibration_sweep_task( rtems_task_argument unused )
598 {
599 /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots.
600 *
601 * @param unused is the starting argument of the RTEMS task
602 *
603 * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots.
604 * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely.
605 *
606 */
607 rtems_event_set event_out;
608 BOOT_PRINTF("in calibration sweep *** \n");
609 rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second();
610 while(1){
611 // Waiting for next F0 snapshot
612 rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
613 if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE)
614 {
615 unsigned int delta_snapshot;
616 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
617 + parameter_dump_packet.sy_lfr_n_swf_p[1];
618 // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2
619 rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2);
620 if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){
621 time_management_regs->calDivisor = CAL_F_DIVISOR_MIN;
622 }
623 else{
624 time_management_regs->calDivisor *= 2;
625 }
626 }
627
628
629
630 }
631
632 }
633
634
524 //*****************************
635 //*****************************
525 // init housekeeping parameters
636 // init housekeeping parameters
526
637
527 void init_housekeeping_parameters( void )
638 void init_housekeeping_parameters( void )
528 {
639 {
529 /** This function initialize the housekeeping_packet global variable with default values.
640 /** This function initialize the housekeeping_packet global variable with default values.
530 *
641 *
531 */
642 */
532
643
533 unsigned int i = 0;
644 unsigned int i = 0;
534 unsigned char *parameters;
645 unsigned char *parameters;
535 unsigned char sizeOfHK;
646 unsigned char sizeOfHK;
536
647
537 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
648 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
538
649
539 parameters = (unsigned char*) &housekeeping_packet;
650 parameters = (unsigned char*) &housekeeping_packet;
540
651
541 for(i = 0; i< sizeOfHK; i++)
652 for(i = 0; i< sizeOfHK; i++)
542 {
653 {
543 parameters[i] = INIT_CHAR;
654 parameters[i] = INIT_CHAR;
544 }
655 }
545
656
546 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
657 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
547 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
658 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
548 housekeeping_packet.reserved = DEFAULT_RESERVED;
659 housekeeping_packet.reserved = DEFAULT_RESERVED;
549 housekeeping_packet.userApplication = CCSDS_USER_APP;
660 housekeeping_packet.userApplication = CCSDS_USER_APP;
550 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
661 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
551 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
662 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
552 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
663 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
553 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
664 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
554 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
665 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
555 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
666 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
556 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
667 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
557 housekeeping_packet.serviceType = TM_TYPE_HK;
668 housekeeping_packet.serviceType = TM_TYPE_HK;
558 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
669 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
559 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
670 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
560 housekeeping_packet.sid = SID_HK;
671 housekeeping_packet.sid = SID_HK;
561
672
562 // init status word
673 // init status word
563 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
674 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
564 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
675 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
565 // init software version
676 // init software version
566 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
677 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
567 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
678 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
568 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
679 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
569 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
680 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
570 // init fpga version
681 // init fpga version
571 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
682 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
572 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
683 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
573 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
684 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
574 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
685 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
575
686
576 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
687 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
577 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
688 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
578 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
689 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
579 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
690 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
580 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
691 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
581 }
692 }
582
693
583 void increment_seq_counter( unsigned short *packetSequenceControl )
694 void increment_seq_counter( unsigned short *packetSequenceControl )
584 {
695 {
585 /** This function increment the sequence counter passes in argument.
696 /** This function increment the sequence counter passes in argument.
586 *
697 *
587 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
698 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
588 *
699 *
589 */
700 */
590
701
591 unsigned short segmentation_grouping_flag;
702 unsigned short segmentation_grouping_flag;
592 unsigned short sequence_cnt;
703 unsigned short sequence_cnt;
593
704
594 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
705 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
595 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
706 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
596
707
597 if ( sequence_cnt < SEQ_CNT_MAX)
708 if ( sequence_cnt < SEQ_CNT_MAX)
598 {
709 {
599 sequence_cnt = sequence_cnt + 1;
710 sequence_cnt = sequence_cnt + 1;
600 }
711 }
601 else
712 else
602 {
713 {
603 sequence_cnt = 0;
714 sequence_cnt = 0;
604 }
715 }
605
716
606 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
717 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
607 }
718 }
608
719
609 void getTime( unsigned char *time)
720 void getTime( unsigned char *time)
610 {
721 {
611 /** This function write the current local time in the time buffer passed in argument.
722 /** This function write the current local time in the time buffer passed in argument.
612 *
723 *
613 */
724 */
614
725
615 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
726 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
616 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
727 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
617 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
728 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
618 time[3] = (unsigned char) (time_management_regs->coarse_time);
729 time[3] = (unsigned char) (time_management_regs->coarse_time);
619 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
730 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
620 time[5] = (unsigned char) (time_management_regs->fine_time);
731 time[5] = (unsigned char) (time_management_regs->fine_time);
621 }
732 }
622
733
623 unsigned long long int getTimeAsUnsignedLongLongInt( )
734 unsigned long long int getTimeAsUnsignedLongLongInt( )
624 {
735 {
625 /** This function write the current local time in the time buffer passed in argument.
736 /** This function write the current local time in the time buffer passed in argument.
626 *
737 *
627 */
738 */
628 unsigned long long int time;
739 unsigned long long int time;
629
740
630 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
741 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
631 + time_management_regs->fine_time;
742 + time_management_regs->fine_time;
632
743
633 return time;
744 return time;
634 }
745 }
635
746
636 void send_dumb_hk( void )
637 {
638 Packet_TM_LFR_HK_t dummy_hk_packet;
639 unsigned char *parameters;
640 unsigned int i;
641 rtems_id queue_id;
642
643 queue_id = RTEMS_ID_NONE;
644
645 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
646 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
647 dummy_hk_packet.reserved = DEFAULT_RESERVED;
648 dummy_hk_packet.userApplication = CCSDS_USER_APP;
649 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
650 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
651 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
652 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
653 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
654 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
655 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
656 dummy_hk_packet.serviceType = TM_TYPE_HK;
657 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
658 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
659 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
660 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
661 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
662 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
663 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
664 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
665 dummy_hk_packet.sid = SID_HK;
666
667 // init status word
668 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
669 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
670 // init software version
671 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
672 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
673 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
674 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
675 // init fpga version
676 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
677 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
678 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
679 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
680
681 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
682
683 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
684 {
685 parameters[i] = INT8_ALL_F;
686 }
687
688 get_message_queue_id_send( &queue_id );
689
690 rtems_message_queue_send( queue_id, &dummy_hk_packet,
691 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
692 }
693
694 void get_temperatures( unsigned char *temperatures )
747 void get_temperatures( unsigned char *temperatures )
695 {
748 {
696 unsigned char* temp_scm_ptr;
749 unsigned char* temp_scm_ptr;
697 unsigned char* temp_pcb_ptr;
750 unsigned char* temp_pcb_ptr;
698 unsigned char* temp_fpga_ptr;
751 unsigned char* temp_fpga_ptr;
699
752
700 // SEL1 SEL0
753 // SEL1 SEL0
701 // 0 0 => PCB
754 // 0 0 => PCB
702 // 0 1 => FPGA
755 // 0 1 => FPGA
703 // 1 0 => SCM
756 // 1 0 => SCM
704
757
705 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
758 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
706 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
759 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
707 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
760 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
708
761
709 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
762 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
710 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
763 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
711 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
764 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
712 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
765 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
713 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
766 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
714 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
767 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
715 }
768 }
716
769
717 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
770 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
718 {
771 {
719 unsigned char* v_ptr;
772 unsigned char* v_ptr;
720 unsigned char* e1_ptr;
773 unsigned char* e1_ptr;
721 unsigned char* e2_ptr;
774 unsigned char* e2_ptr;
722
775
723 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
776 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
724 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
777 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
725 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
778 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
726
779
727 spacecraft_potential[BYTE_0] = v_ptr[0];
780 spacecraft_potential[BYTE_0] = v_ptr[0];
728 spacecraft_potential[BYTE_1] = v_ptr[1];
781 spacecraft_potential[BYTE_1] = v_ptr[1];
729 spacecraft_potential[BYTE_2] = e1_ptr[0];
782 spacecraft_potential[BYTE_2] = e1_ptr[0];
730 spacecraft_potential[BYTE_3] = e1_ptr[1];
783 spacecraft_potential[BYTE_3] = e1_ptr[1];
731 spacecraft_potential[BYTE_4] = e2_ptr[0];
784 spacecraft_potential[BYTE_4] = e2_ptr[0];
732 spacecraft_potential[BYTE_5] = e2_ptr[1];
785 spacecraft_potential[BYTE_5] = e2_ptr[1];
733 }
786 }
734
787
788 /**
789 * @brief get_cpu_load, computes CPU load, CPU load average and CPU load max
790 * @param resource_statistics stores:
791 * - CPU load at index 0
792 * - CPU load max at index 1
793 * - CPU load average at index 2
794 *
795 * The CPU load average is computed on the last 60 values with a simple moving average.
796 */
735 void get_cpu_load( unsigned char *resource_statistics )
797 void get_cpu_load( unsigned char *resource_statistics )
736 {
798 {
799 #define LOAD_AVG_SIZE 60
800 static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0};
801 static char old_avg_pos=0;
802 static unsigned int cpu_load_avg;
737 unsigned char cpu_load;
803 unsigned char cpu_load;
738
804
739 cpu_load = lfr_rtems_cpu_usage_report();
805 cpu_load = lfr_rtems_cpu_usage_report();
740
806
741 // HK_LFR_CPU_LOAD
807 // HK_LFR_CPU_LOAD
742 resource_statistics[0] = cpu_load;
808 resource_statistics[BYTE_0] = cpu_load;
743
809
744 // HK_LFR_CPU_LOAD_MAX
810 // HK_LFR_CPU_LOAD_MAX
745 if (cpu_load > resource_statistics[1])
811 if (cpu_load > resource_statistics[BYTE_1])
746 {
812 {
747 resource_statistics[1] = cpu_load;
813 resource_statistics[BYTE_1] = cpu_load;
748 }
814 }
749
815
816 cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load;
817 cpu_load_hist[(int)old_avg_pos] = cpu_load;
818 old_avg_pos += 1;
819 old_avg_pos %= LOAD_AVG_SIZE;
750 // CPU_LOAD_AVE
820 // CPU_LOAD_AVE
751 resource_statistics[BYTE_2] = 0;
821 resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE);
752
822 // this will change the way LFR compute usage
753 #ifndef PRINT_TASK_STATISTICS
823 #ifndef PRINT_TASK_STATISTICS
754 rtems_cpu_usage_reset();
824 rtems_cpu_usage_reset();
755 #endif
825 #endif
756
826
757 }
827 }
758
828
759 void set_hk_lfr_sc_potential_flag( bool state )
829 void set_hk_lfr_sc_potential_flag( bool state )
760 {
830 {
761 if (state == true)
831 if (state == true)
762 {
832 {
763 housekeeping_packet.lfr_status_word[1] =
833 housekeeping_packet.lfr_status_word[1] =
764 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
834 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
765 }
835 }
766 else
836 else
767 {
837 {
768 housekeeping_packet.lfr_status_word[1] =
838 housekeeping_packet.lfr_status_word[1] =
769 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
839 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
770 }
840 }
771 }
841 }
772
842
773 void set_sy_lfr_pas_filter_enabled( bool state )
843 void set_sy_lfr_pas_filter_enabled( bool state )
774 {
844 {
775 if (state == true)
845 if (state == true)
776 {
846 {
777 housekeeping_packet.lfr_status_word[1] =
847 housekeeping_packet.lfr_status_word[1] =
778 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
848 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
779 }
849 }
780 else
850 else
781 {
851 {
782 housekeeping_packet.lfr_status_word[1] =
852 housekeeping_packet.lfr_status_word[1] =
783 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
853 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
784 }
854 }
785 }
855 }
786
856
787 void set_sy_lfr_watchdog_enabled( bool state )
857 void set_sy_lfr_watchdog_enabled( bool state )
788 {
858 {
789 if (state == true)
859 if (state == true)
790 {
860 {
791 housekeeping_packet.lfr_status_word[1] =
861 housekeeping_packet.lfr_status_word[1] =
792 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
862 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
793 }
863 }
794 else
864 else
795 {
865 {
796 housekeeping_packet.lfr_status_word[1] =
866 housekeeping_packet.lfr_status_word[1] =
797 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
867 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
798 }
868 }
799 }
869 }
800
870
801 void set_hk_lfr_calib_enable( bool state )
871 void set_hk_lfr_calib_enable( bool state )
802 {
872 {
803 if (state == true)
873 if (state == true)
804 {
874 {
805 housekeeping_packet.lfr_status_word[1] =
875 housekeeping_packet.lfr_status_word[1] =
806 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
876 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
807 }
877 }
808 else
878 else
809 {
879 {
810 housekeeping_packet.lfr_status_word[1] =
880 housekeeping_packet.lfr_status_word[1] =
811 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
881 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
812 }
882 }
813 }
883 }
814
884
815 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
885 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
816 {
886 {
817 housekeeping_packet.lfr_status_word[1] =
887 housekeeping_packet.lfr_status_word[1] =
818 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
888 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
819
889
820 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
890 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
821 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
891 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
822
892
823 }
893 }
824
894
825 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
895 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
826 {
896 {
827 int delta;
897 int delta;
828
898
829 delta = 0;
899 delta = 0;
830
900
831 if (newValue >= oldValue)
901 if (newValue >= oldValue)
832 {
902 {
833 delta = newValue - oldValue;
903 delta = newValue - oldValue;
834 }
904 }
835 else
905 else
836 {
906 {
837 delta = (CONST_256 - oldValue) + newValue;
907 delta = (CONST_256 - oldValue) + newValue;
838 }
908 }
839
909
840 *counter = *counter + delta;
910 *counter = *counter + delta;
841 }
911 }
842
912
913 // Low severity error counters update
843 void hk_lfr_le_update( void )
914 void hk_lfr_le_update( void )
844 {
915 {
845 static hk_lfr_le_t old_hk_lfr_le = {0};
916 static hk_lfr_le_t old_hk_lfr_le = {0};
846 hk_lfr_le_t new_hk_lfr_le;
917 hk_lfr_le_t new_hk_lfr_le;
847 unsigned int counter;
918 unsigned int counter;
848
919
849 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
920 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
850
921
851 // DPU
922 // DPU
852 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
923 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
853 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
924 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
854 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
925 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
855 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
926 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
856 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
927 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
857 // TIMECODE
928 // TIMECODE
858 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
929 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
859 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
930 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
860 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
931 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
861 // TIME
932 // TIME
862 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
933 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
863 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
934 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
864 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
935 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
865 //AHB
936 //AHB
866 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
937 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
867 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
938 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
868 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
939 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
869
940
870 // update the le counter
941 // update the le counter
871 // DPU
942 // DPU
872 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
943 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
873 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
944 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
874 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
945 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
875 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
946 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
876 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
947 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
877 // TIMECODE
948 // TIMECODE
878 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
949 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
879 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
950 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
880 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
951 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
881 // TIME
952 // TIME
882 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
953 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
883 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
954 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
884 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
955 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
885 // AHB
956 // AHB
886 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
957 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
887
958
888 // DPU
959 // DPU
889 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
960 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
890 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
961 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
891 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
962 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
892 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
963 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
893 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
964 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
894 // TIMECODE
965 // TIMECODE
895 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
966 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
896 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
967 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
897 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
968 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
898 // TIME
969 // TIME
899 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
970 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
900 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
971 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
901 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
972 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
902 //AHB
973 //AHB
903 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
974 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
904 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
975 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
905 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
976 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
906
977
907 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
978 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
908 // LE
979 // LE
909 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
980 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
910 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
981 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
911 }
982 }
912
983
984 // Medium severity error counters update
913 void hk_lfr_me_update( void )
985 void hk_lfr_me_update( void )
914 {
986 {
915 static hk_lfr_me_t old_hk_lfr_me = {0};
987 static hk_lfr_me_t old_hk_lfr_me = {0};
916 hk_lfr_me_t new_hk_lfr_me;
988 hk_lfr_me_t new_hk_lfr_me;
917 unsigned int counter;
989 unsigned int counter;
918
990
919 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
991 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
920
992
921 // get the current values
993 // get the current values
922 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
994 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
923 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
995 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
924 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
996 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
925 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
997 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
926
998
927 // update the me counter
999 // update the me counter
928 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
1000 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
929 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
1001 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
930 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
1002 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
931 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
1003 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
932
1004
933 // store the counters for the next time
1005 // store the counters for the next time
934 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
1006 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
935 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
1007 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
936 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
1008 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
937 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
1009 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
938
1010
939 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
1011 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
940 // ME
1012 // ME
941 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
1013 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
942 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
1014 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
943 }
1015 }
944
1016
1017 // High severity error counters update
945 void hk_lfr_le_me_he_update()
1018 void hk_lfr_le_me_he_update()
946 {
1019 {
947
1020
948 unsigned int hk_lfr_he_cnt;
1021 unsigned int hk_lfr_he_cnt;
949
1022
950 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
1023 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
951
1024
952 //update the low severity error counter
1025 //update the low severity error counter
953 hk_lfr_le_update( );
1026 hk_lfr_le_update( );
954
1027
955 //update the medium severity error counter
1028 //update the medium severity error counter
956 hk_lfr_me_update();
1029 hk_lfr_me_update();
957
1030
958 //update the high severity error counter
1031 //update the high severity error counter
959 hk_lfr_he_cnt = 0;
1032 hk_lfr_he_cnt = 0;
960
1033
961 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
1034 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
962 // HE
1035 // HE
963 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
1036 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
964 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
1037 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
965
1038
966 }
1039 }
967
1040
968 void set_hk_lfr_time_not_synchro()
1041 void set_hk_lfr_time_not_synchro()
969 {
1042 {
970 static unsigned char synchroLost = 1;
1043 static unsigned char synchroLost = 1;
971 int synchronizationBit;
1044 int synchronizationBit;
972
1045
973 // get the synchronization bit
1046 // get the synchronization bit
974 synchronizationBit =
1047 synchronizationBit =
975 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
1048 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
976
1049
977 switch (synchronizationBit)
1050 switch (synchronizationBit)
978 {
1051 {
979 case 0:
1052 case 0:
980 if (synchroLost == 1)
1053 if (synchroLost == 1)
981 {
1054 {
982 synchroLost = 0;
1055 synchroLost = 0;
983 }
1056 }
984 break;
1057 break;
985 case 1:
1058 case 1:
986 if (synchroLost == 0 )
1059 if (synchroLost == 0 )
987 {
1060 {
988 synchroLost = 1;
1061 synchroLost = 1;
989 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
1062 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
990 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
1063 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
991 }
1064 }
992 break;
1065 break;
993 default:
1066 default:
994 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
1067 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
995 break;
1068 break;
996 }
1069 }
997
1070
998 }
1071 }
999
1072
1000 void set_hk_lfr_ahb_correctable() // CRITICITY L
1073 void set_hk_lfr_ahb_correctable() // CRITICITY L
1001 {
1074 {
1002 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
1075 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
1003 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
1076 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
1004 * detected errors in the cache, in the integer unit and in the floating point unit.
1077 * detected errors in the cache, in the integer unit and in the floating point unit.
1005 *
1078 *
1006 * @param void
1079 * @param void
1007 *
1080 *
1008 * @return void
1081 * @return void
1009 *
1082 *
1010 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
1083 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
1011 *
1084 *
1012 */
1085 */
1013
1086
1014 unsigned int ahb_correctable;
1087 unsigned int ahb_correctable;
1015 unsigned int instructionErrorCounter;
1088 unsigned int instructionErrorCounter;
1016 unsigned int dataErrorCounter;
1089 unsigned int dataErrorCounter;
1017 unsigned int fprfErrorCounter;
1090 unsigned int fprfErrorCounter;
1018 unsigned int iurfErrorCounter;
1091 unsigned int iurfErrorCounter;
1019
1092
1020 instructionErrorCounter = 0;
1093 instructionErrorCounter = 0;
1021 dataErrorCounter = 0;
1094 dataErrorCounter = 0;
1022 fprfErrorCounter = 0;
1095 fprfErrorCounter = 0;
1023 iurfErrorCounter = 0;
1096 iurfErrorCounter = 0;
1024
1097
1025 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
1098 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
1026 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
1099 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
1027
1100
1028 ahb_correctable = instructionErrorCounter
1101 ahb_correctable = instructionErrorCounter
1029 + dataErrorCounter
1102 + dataErrorCounter
1030 + fprfErrorCounter
1103 + fprfErrorCounter
1031 + iurfErrorCounter
1104 + iurfErrorCounter
1032 + housekeeping_packet.hk_lfr_ahb_correctable;
1105 + housekeeping_packet.hk_lfr_ahb_correctable;
1033
1106
1034 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1107 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1035
1108
1036 }
1109 }
@@ -1,1633 +1,1632
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to the SpaceWire interface.
25 /** Functions related to the SpaceWire interface.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle SpaceWire transmissions:
30 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
31 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
32 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
33 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
34 * - reception of TeleCommands by a dedicated RTEMS task
11 *
35 *
12 */
36 */
13
37
14 #include "fsw_spacewire.h"
38 #include "fsw_spacewire.h"
15
39
16 rtems_name semq_name = 0;
40 rtems_name semq_name = 0;
17 rtems_id semq_id = RTEMS_ID_NONE;
41 rtems_id semq_id = RTEMS_ID_NONE;
18
42
19 //*****************
43 //*****************
20 // waveform headers
44 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
45 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
46 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
47 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
24
48
25 unsigned char previousTimecodeCtr = 0;
49 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
50 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
51
28 //***********
52 //***********
29 // RTEMS TASK
53 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
54 rtems_task spiq_task(rtems_task_argument unused)
31 {
55 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
56 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
57 *
34 * @param unused is the starting argument of the RTEMS task
58 * @param unused is the starting argument of the RTEMS task
35 *
59 *
36 */
60 */
37
61
38 rtems_event_set event_out;
62 rtems_event_set event_out;
39 rtems_status_code status;
63 rtems_status_code status;
40 int linkStatus;
64 int linkStatus;
41
65
42 event_out = EVENT_SETS_NONE_PENDING;
66 event_out = EVENT_SETS_NONE_PENDING;
43 linkStatus = 0;
67 linkStatus = 0;
44
68
45 BOOT_PRINTF("in SPIQ *** \n")
69 BOOT_PRINTF("in SPIQ *** \n")
46
70
47 while(true){
71 while(true){
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
72 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
73 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
50
74
51 // [0] SUSPEND RECV AND SEND TASKS
75 // [0] SUSPEND RECV AND SEND TASKS
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
76 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
53 if ( status != RTEMS_SUCCESSFUL ) {
77 if ( status != RTEMS_SUCCESSFUL ) {
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
78 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
55 }
79 }
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
80 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
57 if ( status != RTEMS_SUCCESSFUL ) {
81 if ( status != RTEMS_SUCCESSFUL ) {
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
82 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
59 }
83 }
60
84
61 // [1] CHECK THE LINK
85 // [1] CHECK THE LINK
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
86 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
63 if ( linkStatus != SPW_LINK_OK) {
87 if ( linkStatus != SPW_LINK_OK) {
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
88 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
89 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
66 }
90 }
67
91
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
92 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
93 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
94 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
71 {
95 {
72 spacewire_read_statistics();
96 spacewire_read_statistics();
73 status = spacewire_several_connect_attemps( );
97 status = spacewire_several_connect_attemps( );
74 }
98 }
75 else // [2.b] in run state, start the link
99 else // [2.b] in run state, start the link
76 {
100 {
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
101 status = spacewire_stop_and_start_link( fdSPW ); // start the link
78 if ( status != RTEMS_SUCCESSFUL)
102 if ( status != RTEMS_SUCCESSFUL)
79 {
103 {
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
104 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
81 }
105 }
82 }
106 }
83
107
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
108 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
109 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
86 {
110 {
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
111 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
88 if ( status != RTEMS_SUCCESSFUL ) {
112 if ( status != RTEMS_SUCCESSFUL ) {
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
113 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
90 }
114 }
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
115 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
92 if ( status != RTEMS_SUCCESSFUL ) {
116 if ( status != RTEMS_SUCCESSFUL ) {
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
117 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
94 }
118 }
95 }
119 }
96 else // [3.b] the link is not in run state, go in STANDBY mode
120 else // [3.b] the link is not in run state, go in STANDBY mode
97 {
121 {
98 status = enter_mode_standby();
122 status = enter_mode_standby();
99 if ( status != RTEMS_SUCCESSFUL )
123 if ( status != RTEMS_SUCCESSFUL )
100 {
124 {
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
125 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
102 }
126 }
103 {
127 {
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
128 updateLFRCurrentMode( LFR_MODE_STANDBY );
105 }
129 }
106 // wake the LINK task up to wait for the link recovery
130 // wake the LINK task up to wait for the link recovery
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
131 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
108 status = rtems_task_suspend( RTEMS_SELF );
132 status = rtems_task_suspend( RTEMS_SELF );
109 }
133 }
110 }
134 }
111 }
135 }
112
136
113 rtems_task recv_task( rtems_task_argument unused )
137 rtems_task recv_task( rtems_task_argument unused )
114 {
138 {
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
139 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
116 *
140 *
117 * @param unused is the starting argument of the RTEMS task
141 * @param unused is the starting argument of the RTEMS task
118 *
142 *
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
143 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
120 * 1. It reads the incoming data.
144 * 1. It reads the incoming data.
121 * 2. Launches the acceptance procedure.
145 * 2. Launches the acceptance procedure.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
146 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
123 *
147 *
124 */
148 */
125
149
126 int len;
150 int len;
127 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
151 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
152 unsigned char computed_CRC[ BYTES_PER_CRC ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
153 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
130 unsigned char destinationID;
154 unsigned char destinationID;
131 unsigned int estimatedPacketLength;
155 unsigned int estimatedPacketLength;
132 unsigned int parserCode;
156 unsigned int parserCode;
133 rtems_status_code status;
157 rtems_status_code status;
134 rtems_id queue_recv_id;
158 rtems_id queue_recv_id;
135 rtems_id queue_send_id;
159 rtems_id queue_send_id;
136
160
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
161 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 destinationID = 0;
162 destinationID = 0;
139 queue_recv_id = RTEMS_ID_NONE;
163 queue_recv_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
164 queue_send_id = RTEMS_ID_NONE;
141
165
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
166 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
143
167
144 status = get_message_queue_id_recv( &queue_recv_id );
168 status = get_message_queue_id_recv( &queue_recv_id );
145 if (status != RTEMS_SUCCESSFUL)
169 if (status != RTEMS_SUCCESSFUL)
146 {
170 {
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
171 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
148 }
172 }
149
173
150 status = get_message_queue_id_send( &queue_send_id );
174 status = get_message_queue_id_send( &queue_send_id );
151 if (status != RTEMS_SUCCESSFUL)
175 if (status != RTEMS_SUCCESSFUL)
152 {
176 {
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
177 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
154 }
178 }
155
179
156 BOOT_PRINTF("in RECV *** \n")
180 BOOT_PRINTF("in RECV *** \n")
157
181
158 while(1)
182 while(1)
159 {
183 {
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
184 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
161 if (len == -1){ // error during the read call
185 if (len == -1){ // error during the read call
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
186 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
163 }
187 }
164 else {
188 else {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
189 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
166 PRINTF("in RECV *** packet lenght too short\n")
190 PRINTF("in RECV *** packet lenght too short\n")
167 }
191 }
168 else {
192 else {
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
193 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
170 PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
194 PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
195 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
196 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
173 // CHECK THE TC
197 // CHECK THE TC
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
198 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
199 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
200 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
201 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
178 || (parserCode == WRONG_SRC_ID) )
202 || (parserCode == WRONG_SRC_ID) )
179 { // send TM_LFR_TC_EXE_CORRUPTED
203 { // send TM_LFR_TC_EXE_CORRUPTED
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
204 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
205 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
182 &&
206 &&
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
207 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
184 )
208 )
185 {
209 {
186 if ( parserCode == WRONG_SRC_ID )
210 if ( parserCode == WRONG_SRC_ID )
187 {
211 {
188 destinationID = SID_TC_GROUND;
212 destinationID = SID_TC_GROUND;
189 }
213 }
190 else
214 else
191 {
215 {
192 destinationID = currentTC.sourceID;
216 destinationID = currentTC.sourceID;
193 }
217 }
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
218 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
195 computed_CRC, currentTC_LEN_RCV,
219 computed_CRC, currentTC_LEN_RCV,
196 destinationID );
220 destinationID );
197 }
221 }
198 }
222 }
199 else
223 else
200 { // send valid TC to the action launcher
224 { // send valid TC to the action launcher
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
225 status = rtems_message_queue_send( queue_recv_id, &currentTC,
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
226 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
203 }
227 }
204 }
228 }
205 }
229 }
206
230
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
231 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
208
232
209 }
233 }
210 }
234 }
211
235
212 rtems_task send_task( rtems_task_argument argument)
236 rtems_task send_task( rtems_task_argument argument)
213 {
237 {
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
238 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
215 *
239 *
216 * @param unused is the starting argument of the RTEMS task
240 * @param unused is the starting argument of the RTEMS task
217 *
241 *
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
242 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
243 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
244 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
245 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
222 * data it contains.
246 * data it contains.
223 *
247 *
224 */
248 */
225
249
226 rtems_status_code status; // RTEMS status code
250 rtems_status_code status; // RTEMS status code
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
251 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
228 ring_node *incomingRingNodePtr;
252 ring_node *incomingRingNodePtr;
229 int ring_node_address;
253 int ring_node_address;
230 char *charPtr;
254 char *charPtr;
231 spw_ioctl_pkt_send *spw_ioctl_send;
255 spw_ioctl_pkt_send *spw_ioctl_send;
232 size_t size; // size of the incoming TC packet
256 size_t size; // size of the incoming TC packet
233 rtems_id queue_send_id;
257 rtems_id queue_send_id;
234 unsigned int sid;
258 unsigned int sid;
235 unsigned char sidAsUnsignedChar;
259 unsigned char sidAsUnsignedChar;
236 unsigned char type;
260 unsigned char type;
237
261
238 incomingRingNodePtr = NULL;
262 incomingRingNodePtr = NULL;
239 ring_node_address = 0;
263 ring_node_address = 0;
240 charPtr = (char *) &ring_node_address;
264 charPtr = (char *) &ring_node_address;
241 size = 0;
265 size = 0;
242 queue_send_id = RTEMS_ID_NONE;
266 queue_send_id = RTEMS_ID_NONE;
243 sid = 0;
267 sid = 0;
244 sidAsUnsignedChar = 0;
268 sidAsUnsignedChar = 0;
245
269
246 init_header_cwf( &headerCWF );
270 init_header_cwf( &headerCWF );
247 init_header_swf( &headerSWF );
271 init_header_swf( &headerSWF );
248 init_header_asm( &headerASM );
272 init_header_asm( &headerASM );
249
273
250 status = get_message_queue_id_send( &queue_send_id );
274 status = get_message_queue_id_send( &queue_send_id );
251 if (status != RTEMS_SUCCESSFUL)
275 if (status != RTEMS_SUCCESSFUL)
252 {
276 {
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
277 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
254 }
278 }
255
279
256 BOOT_PRINTF("in SEND *** \n")
280 BOOT_PRINTF("in SEND *** \n")
257
281
258 while(1)
282 while(1)
259 {
283 {
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
284 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
285 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
262
286
263 if (status!=RTEMS_SUCCESSFUL)
287 if (status!=RTEMS_SUCCESSFUL)
264 {
288 {
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
289 PRINTF1("in SEND *** (1) ERR = %d\n", status)
266 }
290 }
267 else
291 else
268 {
292 {
269 if ( size == sizeof(ring_node*) )
293 if ( size == sizeof(ring_node*) )
270 {
294 {
271 charPtr[0] = incomingData[0];
295 charPtr[0] = incomingData[0];
272 charPtr[1] = incomingData[1];
296 charPtr[1] = incomingData[1];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
297 charPtr[BYTE_2] = incomingData[BYTE_2];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
298 charPtr[BYTE_3] = incomingData[BYTE_3];
275 incomingRingNodePtr = (ring_node*) ring_node_address;
299 incomingRingNodePtr = (ring_node*) ring_node_address;
276 sid = incomingRingNodePtr->sid;
300 sid = incomingRingNodePtr->sid;
277 if ( (sid==SID_NORM_CWF_LONG_F3)
301 if ( (sid==SID_NORM_CWF_LONG_F3)
278 || (sid==SID_BURST_CWF_F2 )
302 || (sid==SID_BURST_CWF_F2 )
279 || (sid==SID_SBM1_CWF_F1 )
303 || (sid==SID_SBM1_CWF_F1 )
280 || (sid==SID_SBM2_CWF_F2 ))
304 || (sid==SID_SBM2_CWF_F2 ))
281 {
305 {
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
306 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
283 }
307 }
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
308 else if ( (sid==SID_NORM_SWF_F0) || (sid==SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
285 {
309 {
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
310 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
287 }
311 }
288 else if ( (sid==SID_NORM_CWF_F3) )
312 else if (sid==SID_NORM_CWF_F3)
289 {
313 {
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
314 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
291 }
315 }
292 else if (sid==SID_NORM_ASM_F0)
316 else if (sid==SID_NORM_ASM_F0)
293 {
317 {
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
318 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
295 }
319 }
296 else if (sid==SID_NORM_ASM_F1)
320 else if (sid==SID_NORM_ASM_F1)
297 {
321 {
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
322 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
299 }
323 }
300 else if (sid==SID_NORM_ASM_F2)
324 else if (sid==SID_NORM_ASM_F2)
301 {
325 {
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
326 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
303 }
327 }
304 else if ( sid==TM_CODE_K_DUMP )
328 else if (sid==TM_CODE_K_DUMP)
305 {
329 {
306 spw_send_k_dump( incomingRingNodePtr );
330 spw_send_k_dump( incomingRingNodePtr );
307 }
331 }
308 else
332 else
309 {
333 {
310 PRINTF1("unexpected sid = %d\n", sid);
334 PRINTF1("unexpected sid = %d\n", sid);
311 }
335 }
312 }
336 }
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
337 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
314 {
338 {
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
339 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
316 sid = sidAsUnsignedChar;
340 sid = sidAsUnsignedChar;
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
341 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
342 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
343 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
320 {
344 {
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
345 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
322 }
346 }
323
347
324 status = write( fdSPW, incomingData, size );
348 status = write( fdSPW, incomingData, size );
325 if (status == -1){
349 if (status == -1){
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
350 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
327 }
351 }
328 }
352 }
329 else // the incoming message is a spw_ioctl_pkt_send structure
353 else // the incoming message is a spw_ioctl_pkt_send structure
330 {
354 {
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
355 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
356 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
333 if (status == -1){
357 if (status == -1){
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
358 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
335 }
359 }
336 }
360 }
337 }
361 }
338
362
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
363 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
340
364
341 }
365 }
342 }
366 }
343
367
344 rtems_task link_task( rtems_task_argument argument )
368 rtems_task link_task( rtems_task_argument argument )
345 {
369 {
346 rtems_event_set event_out;
370 rtems_event_set event_out;
347 rtems_status_code status;
371 rtems_status_code status;
348 int linkStatus;
372 int linkStatus;
349
373
350 event_out = EVENT_SETS_NONE_PENDING;
374 event_out = EVENT_SETS_NONE_PENDING;
351 linkStatus = 0;
375 linkStatus = 0;
352
376
353 BOOT_PRINTF("in LINK ***\n")
377 BOOT_PRINTF("in LINK ***\n")
354
378
355 while(1)
379 while(1)
356 {
380 {
357 // wait for an RTEMS_EVENT
381 // wait for an RTEMS_EVENT
358 rtems_event_receive( RTEMS_EVENT_0,
382 rtems_event_receive( RTEMS_EVENT_0,
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
383 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
360 PRINTF("in LINK *** wait for the link\n")
384 PRINTF("in LINK *** wait for the link\n")
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
385 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
362 while( linkStatus != SPW_LINK_OK) // wait for the link
386 while( linkStatus != SPW_LINK_OK) // wait for the link
363 {
387 {
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
388 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
389 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
366 watchdog_reload();
390 watchdog_reload();
367 }
391 }
368
392
369 spacewire_read_statistics();
393 spacewire_read_statistics();
370 status = spacewire_stop_and_start_link( fdSPW );
394 status = spacewire_stop_and_start_link( fdSPW );
371
395
372 if (status != RTEMS_SUCCESSFUL)
396 if (status != RTEMS_SUCCESSFUL)
373 {
397 {
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
398 PRINTF1("in LINK *** ERR link not started %d\n", status)
375 }
399 }
376 else
400 else
377 {
401 {
378 PRINTF("in LINK *** OK link started\n")
402 PRINTF("in LINK *** OK link started\n")
379 }
403 }
380
404
381 // restart the SPIQ task
405 // restart the SPIQ task
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
406 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
383 if ( status != RTEMS_SUCCESSFUL ) {
407 if ( status != RTEMS_SUCCESSFUL ) {
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
408 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
385 }
409 }
386
410
387 // restart RECV and SEND
411 // restart RECV and SEND
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
412 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
389 if ( status != RTEMS_SUCCESSFUL ) {
413 if ( status != RTEMS_SUCCESSFUL ) {
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
414 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
391 }
415 }
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
416 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
393 if ( status != RTEMS_SUCCESSFUL ) {
417 if ( status != RTEMS_SUCCESSFUL ) {
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
418 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
395 }
419 }
396 }
420 }
397 }
421 }
398
422
399 //****************
423 //****************
400 // OTHER FUNCTIONS
424 // OTHER FUNCTIONS
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
425 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
402 {
426 {
403 /** This function opens the SpaceWire link.
427 /** This function opens the SpaceWire link.
404 *
428 *
405 * @return a valid file descriptor in case of success, -1 in case of a failure
429 * @return a valid file descriptor in case of success, -1 in case of a failure
406 *
430 *
407 */
431 */
408 rtems_status_code status;
432 rtems_status_code status;
409
433
410 status = RTEMS_SUCCESSFUL;
434 status = RTEMS_SUCCESSFUL;
411
435
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
436 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
413 if ( fdSPW < 0 ) {
437 if ( fdSPW < 0 ) {
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
438 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
415 }
439 }
416 else
440 else
417 {
441 {
418 status = RTEMS_SUCCESSFUL;
442 status = RTEMS_SUCCESSFUL;
419 }
443 }
420
444
421 return status;
445 return status;
422 }
446 }
423
447
424 int spacewire_start_link( int fd )
448 int spacewire_start_link( int fd )
425 {
449 {
426 rtems_status_code status;
450 rtems_status_code status;
427
451
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
452 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
429 // -1 default hardcoded driver timeout
453 // -1 default hardcoded driver timeout
430
454
431 return status;
455 return status;
432 }
456 }
433
457
434 int spacewire_stop_and_start_link( int fd )
458 int spacewire_stop_and_start_link( int fd )
435 {
459 {
436 rtems_status_code status;
460 rtems_status_code status;
437
461
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
462 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
463 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
440 // -1 default hardcoded driver timeout
464 // -1 default hardcoded driver timeout
441
465
442 return status;
466 return status;
443 }
467 }
444
468
445 int spacewire_configure_link( int fd )
469 int spacewire_configure_link( int fd )
446 {
470 {
447 /** This function configures the SpaceWire link.
471 /** This function configures the SpaceWire link.
448 *
472 *
449 * @return GR-RTEMS-DRIVER directive status codes:
473 * @return GR-RTEMS-DRIVER directive status codes:
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
474 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
475 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
476 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
477 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
478 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
479 * - 5 EIO - Error when writing to grswp hardware registers.
456 * - 2 ENOENT - No such file or directory
480 * - 2 ENOENT - No such file or directory
457 */
481 */
458
482
459 rtems_status_code status;
483 rtems_status_code status;
460
484
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
485 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
486 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
463 spw_ioctl_packetsize packetsize;
487 spw_ioctl_packetsize packetsize;
464
488
465 packetsize.rxsize = SPW_RXSIZE;
489 packetsize.rxsize = SPW_RXSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
490 packetsize.txdsize = SPW_TXDSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
491 packetsize.txhsize = SPW_TXHSIZE;
468
492
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
493 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
470 if (status!=RTEMS_SUCCESSFUL) {
494 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
495 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
472 }
496 }
473 //
497 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
498 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
475 if (status!=RTEMS_SUCCESSFUL) {
499 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
500 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
477 }
501 }
478 //
502 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
503 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
480 if (status!=RTEMS_SUCCESSFUL) {
504 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
505 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
482 }
506 }
483 //
507 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
508 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
485 if (status!=RTEMS_SUCCESSFUL) {
509 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
510 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
487 }
511 }
488 //
512 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
513 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
490 if (status!=RTEMS_SUCCESSFUL) {
514 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
515 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
492 }
516 }
493 //
517 //
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
518 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
495 if (status!=RTEMS_SUCCESSFUL) {
519 if (status!=RTEMS_SUCCESSFUL) {
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
520 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
497 }
521 }
498 //
522 //
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
523 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
500 if (status!=RTEMS_SUCCESSFUL) {
524 if (status!=RTEMS_SUCCESSFUL) {
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
525 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
502 }
526 }
503 //
527 //
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
528 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
505 if (status!=RTEMS_SUCCESSFUL) {
529 if (status!=RTEMS_SUCCESSFUL) {
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
530 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
507 }
531 }
508
532
509 return status;
533 return status;
510 }
534 }
511
535
512 int spacewire_several_connect_attemps( void )
536 int spacewire_several_connect_attemps( void )
513 {
537 {
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
538 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
515 *
539 *
516 * @return RTEMS directive status code:
540 * @return RTEMS directive status code:
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
541 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
542 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
519 *
543 *
520 */
544 */
521
545
522 rtems_status_code status_spw;
546 rtems_status_code status_spw;
523 rtems_status_code status;
547 rtems_status_code status;
524 int i;
548 int i;
525
549
526 status_spw = RTEMS_SUCCESSFUL;
550 status_spw = RTEMS_SUCCESSFUL;
527
551
528 i = 0;
552 i = 0;
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
553 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
530 {
554 {
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
555 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
532
556
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
557 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
534
558
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
559 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
536
560
537 status_spw = spacewire_stop_and_start_link( fdSPW );
561 status_spw = spacewire_stop_and_start_link( fdSPW );
538
562
539 if ( status_spw != RTEMS_SUCCESSFUL )
563 if ( status_spw != RTEMS_SUCCESSFUL )
540 {
564 {
541 i = i + 1;
565 i = i + 1;
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
566 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
543 }
567 }
544 else
568 else
545 {
569 {
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
570 i = SY_LFR_DPU_CONNECT_ATTEMPT;
547 }
571 }
548 }
572 }
549
573
550 return status_spw;
574 return status_spw;
551 }
575 }
552
576
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
577 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
554 {
578 {
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
579 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
556 *
580 *
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
581 * @param val is the value, 0 or 1, used to set the value of the NP bit.
558 * @param regAddr is the address of the GRSPW control register.
582 * @param regAddr is the address of the GRSPW control register.
559 *
583 *
560 * NP is the bit 20 of the GRSPW control register.
584 * NP is the bit 20 of the GRSPW control register.
561 *
585 *
562 */
586 */
563
587
564 unsigned int *spwptr = (unsigned int*) regAddr;
588 unsigned int *spwptr = (unsigned int*) regAddr;
565
589
566 if (val == 1) {
590 if (val == 1) {
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
591 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
568 }
592 }
569 if (val== 0) {
593 if (val== 0) {
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
594 *spwptr = *spwptr & SPW_BIT_NP_MASK;
571 }
595 }
572 }
596 }
573
597
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
598 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
575 {
599 {
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
600 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
577 *
601 *
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
602 * @param val is the value, 0 or 1, used to set the value of the RE bit.
579 * @param regAddr is the address of the GRSPW control register.
603 * @param regAddr is the address of the GRSPW control register.
580 *
604 *
581 * RE is the bit 16 of the GRSPW control register.
605 * RE is the bit 16 of the GRSPW control register.
582 *
606 *
583 */
607 */
584
608
585 unsigned int *spwptr = (unsigned int*) regAddr;
609 unsigned int *spwptr = (unsigned int*) regAddr;
586
610
587 if (val == 1)
611 if (val == 1)
588 {
612 {
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
613 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
590 }
614 }
591 if (val== 0)
615 if (val== 0)
592 {
616 {
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
617 *spwptr = *spwptr & SPW_BIT_RE_MASK;
594 }
618 }
595 }
619 }
596
620
597 void spacewire_read_statistics( void )
621 void spacewire_read_statistics( void )
598 {
622 {
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
623 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
600 *
624 *
601 * @param void
625 * @param void
602 *
626 *
603 * @return void
627 * @return void
604 *
628 *
605 * Once they are read, the counters are stored in a global variable used during the building of the
629 * Once they are read, the counters are stored in a global variable used during the building of the
606 * HK packets.
630 * HK packets.
607 *
631 *
608 */
632 */
609
633
610 rtems_status_code status;
634 rtems_status_code status;
611 spw_stats current;
635 spw_stats current;
612
636
613 memset(&current, 0, sizeof(spw_stats));
637 memset(&current, 0, sizeof(spw_stats));
614
638
615 spacewire_get_last_error();
639 spacewire_get_last_error();
616
640
617 // read the current statistics
641 // read the current statistics
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
642 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
619
643
620 // clear the counters
644 // clear the counters
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
645 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
622
646
623 // typedef struct {
624 // unsigned int tx_link_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
627 // unsigned int rx_eep_err;
628 // unsigned int rx_truncated;
629 // unsigned int parity_err;
630 // unsigned int escape_err;
631 // unsigned int credit_err;
632 // unsigned int write_sync_err;
633 // unsigned int disconnect_err;
634 // unsigned int early_ep;
635 // unsigned int invalid_address;
636 // unsigned int packets_sent;
637 // unsigned int packets_received;
638 // } spw_stats;
639
640 // rx_eep_err
647 // rx_eep_err
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
648 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
642 // rx_truncated
649 // rx_truncated
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
650 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
644 // parity_err
651 // parity_err
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
652 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
646 // escape_err
653 // escape_err
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
654 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
648 // credit_err
655 // credit_err
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
656 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
650 // write_sync_err
657 // write_sync_err
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
658 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
652 // disconnect_err
659 // disconnect_err
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
660 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
654 // early_ep
661 // early_ep
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
662 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
656 // invalid_address
663 // invalid_address
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
664 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
658 // packets_sent
665 // packets_sent
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
666 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
660 // packets_received
667 // packets_received
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
668 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
662
669
663 }
670 }
664
671
665 void spacewire_get_last_error( void )
672 void spacewire_get_last_error( void )
666 {
673 {
667 static spw_stats previous = {0};
674 static spw_stats previous = {0};
668 spw_stats current;
675 spw_stats current;
669 rtems_status_code status;
676 rtems_status_code status;
670
677
671 unsigned int hk_lfr_last_er_rid;
678 unsigned int hk_lfr_last_er_rid;
672 unsigned char hk_lfr_last_er_code;
679 unsigned char hk_lfr_last_er_code;
673 int coarseTime;
680 int coarseTime;
674 int fineTime;
681 int fineTime;
675 unsigned char update_hk_lfr_last_er;
682 unsigned char update_hk_lfr_last_er;
676
683
677 memset(&current, 0, sizeof(spw_stats));
684 memset(&current, 0, sizeof(spw_stats));
678 hk_lfr_last_er_rid = INIT_CHAR;
685 hk_lfr_last_er_rid = INIT_CHAR;
679 hk_lfr_last_er_code = INIT_CHAR;
686 hk_lfr_last_er_code = INIT_CHAR;
680 update_hk_lfr_last_er = INIT_CHAR;
687 update_hk_lfr_last_er = INIT_CHAR;
681
688
682 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
689 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
683
690
684 // get current time
691 // get current time
685 coarseTime = time_management_regs->coarse_time;
692 coarseTime = time_management_regs->coarse_time;
686 fineTime = time_management_regs->fine_time;
693 fineTime = time_management_regs->fine_time;
687
694
688 // typedef struct {
689 // unsigned int tx_link_err; // NOT IN HK
690 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
691 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
692 // unsigned int rx_eep_err;
693 // unsigned int rx_truncated;
694 // unsigned int parity_err;
695 // unsigned int escape_err;
696 // unsigned int credit_err;
697 // unsigned int write_sync_err;
698 // unsigned int disconnect_err;
699 // unsigned int early_ep;
700 // unsigned int invalid_address;
701 // unsigned int packets_sent;
702 // unsigned int packets_received;
703 // } spw_stats;
704
705 // tx_link_err *** no code associated to this field
695 // tx_link_err *** no code associated to this field
706 // rx_rmap_header_crc_err *** LE *** in HK
696 // rx_rmap_header_crc_err *** LE *** in HK
707 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
697 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
708 {
698 {
709 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
699 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
710 hk_lfr_last_er_code = CODE_HEADER_CRC;
700 hk_lfr_last_er_code = CODE_HEADER_CRC;
711 update_hk_lfr_last_er = 1;
701 update_hk_lfr_last_er = 1;
712 }
702 }
713 // rx_rmap_data_crc_err *** LE *** NOT IN HK
703 // rx_rmap_data_crc_err *** LE *** NOT IN HK
714 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
704 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
715 {
705 {
716 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
706 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
717 hk_lfr_last_er_code = CODE_DATA_CRC;
707 hk_lfr_last_er_code = CODE_DATA_CRC;
718 update_hk_lfr_last_er = 1;
708 update_hk_lfr_last_er = 1;
719 }
709 }
720 // rx_eep_err
710 // rx_eep_err
721 if (previous.rx_eep_err != current.rx_eep_err)
711 if (previous.rx_eep_err != current.rx_eep_err)
722 {
712 {
723 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
713 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
724 hk_lfr_last_er_code = CODE_EEP;
714 hk_lfr_last_er_code = CODE_EEP;
725 update_hk_lfr_last_er = 1;
715 update_hk_lfr_last_er = 1;
726 }
716 }
727 // rx_truncated
717 // rx_truncated
728 if (previous.rx_truncated != current.rx_truncated)
718 if (previous.rx_truncated != current.rx_truncated)
729 {
719 {
730 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
720 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
731 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
721 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
732 update_hk_lfr_last_er = 1;
722 update_hk_lfr_last_er = 1;
733 }
723 }
734 // parity_err
724 // parity_err
735 if (previous.parity_err != current.parity_err)
725 if (previous.parity_err != current.parity_err)
736 {
726 {
737 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
727 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
738 hk_lfr_last_er_code = CODE_PARITY;
728 hk_lfr_last_er_code = CODE_PARITY;
739 update_hk_lfr_last_er = 1;
729 update_hk_lfr_last_er = 1;
740 }
730 }
741 // escape_err
731 // escape_err
742 if (previous.parity_err != current.parity_err)
732 if (previous.parity_err != current.parity_err)
743 {
733 {
744 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
734 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
745 hk_lfr_last_er_code = CODE_ESCAPE;
735 hk_lfr_last_er_code = CODE_ESCAPE;
746 update_hk_lfr_last_er = 1;
736 update_hk_lfr_last_er = 1;
747 }
737 }
748 // credit_err
738 // credit_err
749 if (previous.credit_err != current.credit_err)
739 if (previous.credit_err != current.credit_err)
750 {
740 {
751 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
741 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
752 hk_lfr_last_er_code = CODE_CREDIT;
742 hk_lfr_last_er_code = CODE_CREDIT;
753 update_hk_lfr_last_er = 1;
743 update_hk_lfr_last_er = 1;
754 }
744 }
755 // write_sync_err
745 // write_sync_err
756 if (previous.write_sync_err != current.write_sync_err)
746 if (previous.write_sync_err != current.write_sync_err)
757 {
747 {
758 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
748 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
759 hk_lfr_last_er_code = CODE_WRITE_SYNC;
749 hk_lfr_last_er_code = CODE_WRITE_SYNC;
760 update_hk_lfr_last_er = 1;
750 update_hk_lfr_last_er = 1;
761 }
751 }
762 // disconnect_err
752 // disconnect_err
763 if (previous.disconnect_err != current.disconnect_err)
753 if (previous.disconnect_err != current.disconnect_err)
764 {
754 {
765 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
755 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
766 hk_lfr_last_er_code = CODE_DISCONNECT;
756 hk_lfr_last_er_code = CODE_DISCONNECT;
767 update_hk_lfr_last_er = 1;
757 update_hk_lfr_last_er = 1;
768 }
758 }
769 // early_ep
759 // early_ep
770 if (previous.early_ep != current.early_ep)
760 if (previous.early_ep != current.early_ep)
771 {
761 {
772 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
762 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
773 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
763 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
774 update_hk_lfr_last_er = 1;
764 update_hk_lfr_last_er = 1;
775 }
765 }
776 // invalid_address
766 // invalid_address
777 if (previous.invalid_address != current.invalid_address)
767 if (previous.invalid_address != current.invalid_address)
778 {
768 {
779 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
769 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
780 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
770 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
781 update_hk_lfr_last_er = 1;
771 update_hk_lfr_last_er = 1;
782 }
772 }
783
773
784 // if a field has changed, update the hk_last_er fields
774 // if a field has changed, update the hk_last_er fields
785 if (update_hk_lfr_last_er == 1)
775 if (update_hk_lfr_last_er == 1)
786 {
776 {
787 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
777 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
788 }
778 }
789
779
790 previous = current;
780 previous = current;
791 }
781 }
792
782
793 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
783 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
794 {
784 {
795 unsigned char *coarseTimePtr;
785 unsigned char *coarseTimePtr;
796 unsigned char *fineTimePtr;
786 unsigned char *fineTimePtr;
797
787
798 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
788 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
799 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
789 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
800
790
801 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
791 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
802 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
792 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
803 housekeeping_packet.hk_lfr_last_er_code = code;
793 housekeeping_packet.hk_lfr_last_er_code = code;
804 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
794 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
805 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
795 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
796 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
797 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
808 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
798 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
809 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
799 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
810 }
800 }
811
801
812 void update_hk_with_grspw_stats( void )
802 void update_hk_with_grspw_stats( void )
813 {
803 {
814 //****************************
804 //****************************
815 // DPU_SPACEWIRE_IF_STATISTICS
805 // DPU_SPACEWIRE_IF_STATISTICS
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
806 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
807 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
818 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
808 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
819 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
809 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
820
810
821 //******************************************
811 //******************************************
822 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
812 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
823 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
813 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
824 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
814 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
825 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
815 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
826 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
816 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
827 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
817 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
828
818
829 //*********************************************
819 //*********************************************
830 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
820 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
831 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
821 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
832 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
822 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
833 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
823 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
834 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
824 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
835 }
825 }
836
826
837 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
827 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
838 {
828 {
839 unsigned int *statusRegisterPtr;
829 unsigned int *statusRegisterPtr;
840 unsigned char linkState;
830 unsigned char linkState;
841
831
842 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
832 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
843 linkState =
833 linkState =
844 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
834 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
845
835
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
836 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
847
837
848 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
838 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
849 }
839 }
850
840
851 void increase_unsigned_char_counter( unsigned char *counter )
841 void increase_unsigned_char_counter( unsigned char *counter )
852 {
842 {
853 // update the number of valid timecodes that have been received
843 // update the number of valid timecodes that have been received
854 if (*counter == UINT8_MAX)
844 if (*counter == UINT8_MAX)
855 {
845 {
856 *counter = 0;
846 *counter = 0;
857 }
847 }
858 else
848 else
859 {
849 {
860 *counter = *counter + 1;
850 *counter = *counter + 1;
861 }
851 }
862 }
852 }
863
853
864 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
854 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
865 {
855 {
866 /** This function checks the coherency between the incoming timecode and the last valid timecode.
856 /** This function checks the coherency between the incoming timecode and the last valid timecode.
867 *
857 *
868 * @param currentTimecodeCtr is the incoming timecode
858 * @param currentTimecodeCtr is the incoming timecode
869 *
859 *
870 * @return returned codes::
860 * @return returned codes::
871 * - LFR_DEFAULT
861 * - LFR_DEFAULT
872 * - LFR_SUCCESSFUL
862 * - LFR_SUCCESSFUL
873 *
863 *
874 */
864 */
875
865
876 static unsigned char firstTickout = 1;
866 static unsigned char firstTickout = 1;
877 unsigned char ret;
867 unsigned char ret;
878
868
879 ret = LFR_DEFAULT;
869 ret = LFR_DEFAULT;
880
870
881 if (firstTickout == 0)
871 if (firstTickout == 0)
882 {
872 {
883 if (currentTimecodeCtr == 0)
873 if (currentTimecodeCtr == 0)
884 {
874 {
885 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
875 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
886 {
876 {
887 ret = LFR_SUCCESSFUL;
877 ret = LFR_SUCCESSFUL;
888 }
878 }
889 else
879 else
890 {
880 {
891 ret = LFR_DEFAULT;
881 ret = LFR_DEFAULT;
892 }
882 }
893 }
883 }
894 else
884 else
895 {
885 {
896 if (currentTimecodeCtr == (previousTimecodeCtr +1))
886 if (currentTimecodeCtr == (previousTimecodeCtr +1))
897 {
887 {
898 ret = LFR_SUCCESSFUL;
888 ret = LFR_SUCCESSFUL;
899 }
889 }
900 else
890 else
901 {
891 {
902 ret = LFR_DEFAULT;
892 ret = LFR_DEFAULT;
903 }
893 }
904 }
894 }
905 }
895 }
906 else
896 else
907 {
897 {
908 firstTickout = 0;
898 firstTickout = 0;
909 ret = LFR_SUCCESSFUL;
899 ret = LFR_SUCCESSFUL;
910 }
900 }
911
901
912 return ret;
902 return ret;
913 }
903 }
914
904
915 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
905 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
916 {
906 {
917 unsigned int ret;
907 unsigned int ret;
918
908
919 ret = LFR_DEFAULT;
909 ret = LFR_DEFAULT;
920
910
921 if (timecode == internalTime)
911 if (timecode == internalTime)
922 {
912 {
923 ret = LFR_SUCCESSFUL;
913 ret = LFR_SUCCESSFUL;
924 }
914 }
925 else
915 else
926 {
916 {
927 ret = LFR_DEFAULT;
917 ret = LFR_DEFAULT;
928 }
918 }
929
919
930 return ret;
920 return ret;
931 }
921 }
932
922
933 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
923 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
934 {
924 {
935 // a tickout has been emitted, perform actions on the incoming timecode
925 // a tickout has been emitted, perform actions on the incoming timecode
936
926
937 unsigned char incomingTimecode;
927 unsigned char incomingTimecode;
938 unsigned char updateTime;
928 unsigned char updateTime;
939 unsigned char internalTime;
929 unsigned char internalTime;
940 rtems_status_code status;
930 rtems_status_code status;
941
931
942 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
932 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
943 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
933 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
944 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
934 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
945
935
946 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
936 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
947
937
948 // update the number of tickout that have been generated
938 // update the number of tickout that have been generated
949 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
939 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
950
940
951 //**************************
941 //**************************
952 // HK_LFR_TIMECODE_ERRONEOUS
942 // HK_LFR_TIMECODE_ERRONEOUS
953 // MISSING and INVALID are handled by the timecode_timer_routine service routine
943 // MISSING and INVALID are handled by the timecode_timer_routine service routine
954 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
944 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
955 {
945 {
956 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
946 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
957 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
947 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
948 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
959 }
949 }
960
950
961 //************************
951 //************************
962 // HK_LFR_TIME_TIMECODE_IT
952 // HK_LFR_TIME_TIMECODE_IT
963 // check the coherency between the SpaceWire timecode and the Internal Time
953 // check the coherency between the SpaceWire timecode and the Internal Time
964 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
954 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
965 {
955 {
966 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
956 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
967 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
957 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
968 }
958 }
969
959
970 //********************
960 //********************
971 // HK_LFR_TIMECODE_CTR
961 // HK_LFR_TIMECODE_CTR
972 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
962 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
973 if (oneTcLfrUpdateTimeReceived == 1)
963 if (oneTcLfrUpdateTimeReceived == 1)
974 {
964 {
975 if ( incomingTimecode != updateTime )
965 if ( incomingTimecode != updateTime )
976 {
966 {
977 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
967 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
978 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
968 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
979 }
969 }
980 }
970 }
981
971
982 // launch the timecode timer to detect missing or invalid timecodes
972 // launch the timecode timer to detect missing or invalid timecodes
983 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
973 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
984 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
974 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
985 if (status != RTEMS_SUCCESSFUL)
975 if (status != RTEMS_SUCCESSFUL)
986 {
976 {
987 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
977 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
988 }
978 }
989 }
979 }
990
980
991 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
981 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
992 {
982 {
993 static unsigned char initStep = 1;
983 static unsigned char initStep = 1;
994
984
995 unsigned char currentTimecodeCtr;
985 unsigned char currentTimecodeCtr;
996
986
997 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
987 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
998
988
999 if (initStep == 1)
989 if (initStep == 1)
1000 {
990 {
1001 if (currentTimecodeCtr == previousTimecodeCtr)
991 if (currentTimecodeCtr == previousTimecodeCtr)
1002 {
992 {
1003 //************************
993 //************************
1004 // HK_LFR_TIMECODE_MISSING
994 // HK_LFR_TIMECODE_MISSING
1005 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
995 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
996 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
997 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1008 }
998 }
1009 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
999 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1010 {
1000 {
1011 // the timecode value has changed and the value is valid, this is unexpected because
1001 // the timecode value has changed and the value is valid, this is unexpected because
1012 // the timer should not have fired, the timecode_irq_handler should have been raised
1002 // the timer should not have fired, the timecode_irq_handler should have been raised
1013 }
1003 }
1014 else
1004 else
1015 {
1005 {
1016 //************************
1006 //************************
1017 // HK_LFR_TIMECODE_INVALID
1007 // HK_LFR_TIMECODE_INVALID
1018 // the timecode value has changed and the value is not valid, no tickout has been generated
1008 // the timecode value has changed and the value is not valid, no tickout has been generated
1019 // this is why the timer has fired
1009 // this is why the timer has fired
1020 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1010 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1021 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1011 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1022 }
1012 }
1023 }
1013 }
1024 else
1014 else
1025 {
1015 {
1026 initStep = 1;
1016 initStep = 1;
1027 //************************
1017 //************************
1028 // HK_LFR_TIMECODE_MISSING
1018 // HK_LFR_TIMECODE_MISSING
1029 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1019 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1030 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1020 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1031 }
1021 }
1032
1022
1033 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1023 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1034 }
1024 }
1035
1025
1036 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1026 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1037 {
1027 {
1038 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1028 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1039 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1029 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1040 header->reserved = DEFAULT_RESERVED;
1030 header->reserved = DEFAULT_RESERVED;
1041 header->userApplication = CCSDS_USER_APP;
1031 header->userApplication = CCSDS_USER_APP;
1042 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1032 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1043 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1033 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1044 header->packetLength[0] = INIT_CHAR;
1034 header->packetLength[0] = INIT_CHAR;
1045 header->packetLength[1] = INIT_CHAR;
1035 header->packetLength[1] = INIT_CHAR;
1046 // DATA FIELD HEADER
1036 // DATA FIELD HEADER
1047 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1037 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1048 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1038 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1049 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1039 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1050 header->destinationID = TM_DESTINATION_ID_GROUND;
1040 header->destinationID = TM_DESTINATION_ID_GROUND;
1051 header->time[BYTE_0] = INIT_CHAR;
1041 header->time[BYTE_0] = INIT_CHAR;
1052 header->time[BYTE_1] = INIT_CHAR;
1042 header->time[BYTE_1] = INIT_CHAR;
1053 header->time[BYTE_2] = INIT_CHAR;
1043 header->time[BYTE_2] = INIT_CHAR;
1054 header->time[BYTE_3] = INIT_CHAR;
1044 header->time[BYTE_3] = INIT_CHAR;
1055 header->time[BYTE_4] = INIT_CHAR;
1045 header->time[BYTE_4] = INIT_CHAR;
1056 header->time[BYTE_5] = INIT_CHAR;
1046 header->time[BYTE_5] = INIT_CHAR;
1057 // AUXILIARY DATA HEADER
1047 // AUXILIARY DATA HEADER
1058 header->sid = INIT_CHAR;
1048 header->sid = INIT_CHAR;
1059 header->pa_bia_status_info = DEFAULT_HKBIA;
1049 header->pa_bia_status_info = DEFAULT_HKBIA;
1060 header->blkNr[0] = INIT_CHAR;
1050 header->blkNr[0] = INIT_CHAR;
1061 header->blkNr[1] = INIT_CHAR;
1051 header->blkNr[1] = INIT_CHAR;
1062 }
1052 }
1063
1053
1064 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1054 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1065 {
1055 {
1066 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1056 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1067 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1057 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1068 header->reserved = DEFAULT_RESERVED;
1058 header->reserved = DEFAULT_RESERVED;
1069 header->userApplication = CCSDS_USER_APP;
1059 header->userApplication = CCSDS_USER_APP;
1070 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1060 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1071 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1061 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1072 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1062 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1073 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1063 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1074 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1064 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1075 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1065 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1076 // DATA FIELD HEADER
1066 // DATA FIELD HEADER
1077 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1067 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1078 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1068 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1079 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1069 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1080 header->destinationID = TM_DESTINATION_ID_GROUND;
1070 header->destinationID = TM_DESTINATION_ID_GROUND;
1081 header->time[BYTE_0] = INIT_CHAR;
1071 header->time[BYTE_0] = INIT_CHAR;
1082 header->time[BYTE_1] = INIT_CHAR;
1072 header->time[BYTE_1] = INIT_CHAR;
1083 header->time[BYTE_2] = INIT_CHAR;
1073 header->time[BYTE_2] = INIT_CHAR;
1084 header->time[BYTE_3] = INIT_CHAR;
1074 header->time[BYTE_3] = INIT_CHAR;
1085 header->time[BYTE_4] = INIT_CHAR;
1075 header->time[BYTE_4] = INIT_CHAR;
1086 header->time[BYTE_5] = INIT_CHAR;
1076 header->time[BYTE_5] = INIT_CHAR;
1087 // AUXILIARY DATA HEADER
1077 // AUXILIARY DATA HEADER
1088 header->sid = INIT_CHAR;
1078 header->sid = INIT_CHAR;
1089 header->pa_bia_status_info = DEFAULT_HKBIA;
1079 header->pa_bia_status_info = DEFAULT_HKBIA;
1090 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1080 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1091 header->pktNr = INIT_CHAR;
1081 header->pktNr = INIT_CHAR;
1092 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1082 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1093 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1083 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1094 }
1084 }
1095
1085
1096 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1086 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1097 {
1087 {
1098 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1088 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1099 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1089 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1100 header->reserved = DEFAULT_RESERVED;
1090 header->reserved = DEFAULT_RESERVED;
1101 header->userApplication = CCSDS_USER_APP;
1091 header->userApplication = CCSDS_USER_APP;
1102 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1092 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1103 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1093 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1104 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1094 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1105 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1095 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1106 header->packetLength[0] = INIT_CHAR;
1096 header->packetLength[0] = INIT_CHAR;
1107 header->packetLength[1] = INIT_CHAR;
1097 header->packetLength[1] = INIT_CHAR;
1108 // DATA FIELD HEADER
1098 // DATA FIELD HEADER
1109 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1099 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1110 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1100 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1111 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1101 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1112 header->destinationID = TM_DESTINATION_ID_GROUND;
1102 header->destinationID = TM_DESTINATION_ID_GROUND;
1113 header->time[BYTE_0] = INIT_CHAR;
1103 header->time[BYTE_0] = INIT_CHAR;
1114 header->time[BYTE_1] = INIT_CHAR;
1104 header->time[BYTE_1] = INIT_CHAR;
1115 header->time[BYTE_2] = INIT_CHAR;
1105 header->time[BYTE_2] = INIT_CHAR;
1116 header->time[BYTE_3] = INIT_CHAR;
1106 header->time[BYTE_3] = INIT_CHAR;
1117 header->time[BYTE_4] = INIT_CHAR;
1107 header->time[BYTE_4] = INIT_CHAR;
1118 header->time[BYTE_5] = INIT_CHAR;
1108 header->time[BYTE_5] = INIT_CHAR;
1119 // AUXILIARY DATA HEADER
1109 // AUXILIARY DATA HEADER
1120 header->sid = INIT_CHAR;
1110 header->sid = INIT_CHAR;
1121 header->pa_bia_status_info = INIT_CHAR;
1111 header->pa_bia_status_info = INIT_CHAR;
1122 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1112 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1123 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1113 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1124 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1114 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1125 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1115 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1126 }
1116 }
1127
1117
1128 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1118 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1129 Header_TM_LFR_SCIENCE_CWF_t *header )
1119 Header_TM_LFR_SCIENCE_CWF_t *header )
1130 {
1120 {
1131 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1121 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1132 *
1122 *
1133 * @param waveform points to the buffer containing the data that will be send.
1123 * @param waveform points to the buffer containing the data that will be send.
1134 * @param sid is the source identifier of the data that will be sent.
1124 * @param sid is the source identifier of the data that will be sent.
1135 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1125 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1136 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1126 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1137 * contain information to setup the transmission of the data packets.
1127 * contain information to setup the transmission of the data packets.
1138 *
1128 *
1139 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1129 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1140 *
1130 *
1141 */
1131 */
1142
1132
1143 unsigned int i;
1133 unsigned int i;
1144 int ret;
1134 int ret;
1145 unsigned int coarseTime;
1135 unsigned int coarseTime;
1146 unsigned int fineTime;
1136 unsigned int fineTime;
1147 rtems_status_code status;
1137 rtems_status_code status;
1148 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1138 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1149 int *dataPtr;
1139 int *dataPtr;
1150 unsigned char sid;
1140 unsigned char sid;
1151
1141
1152 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1142 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1153 spw_ioctl_send_CWF.options = 0;
1143 spw_ioctl_send_CWF.options = 0;
1154
1144
1155 ret = LFR_DEFAULT;
1145 ret = LFR_DEFAULT;
1156 sid = (unsigned char) ring_node_to_send->sid;
1146 sid = (unsigned char) ring_node_to_send->sid;
1157
1147
1158 coarseTime = ring_node_to_send->coarseTime;
1148 coarseTime = ring_node_to_send->coarseTime;
1159 fineTime = ring_node_to_send->fineTime;
1149 fineTime = ring_node_to_send->fineTime;
1160 dataPtr = (int*) ring_node_to_send->buffer_address;
1150 dataPtr = (int*) ring_node_to_send->buffer_address;
1161
1151
1162 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1152 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1163 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1153 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1164 header->pa_bia_status_info = pa_bia_status_info;
1154 header->pa_bia_status_info = pa_bia_status_info;
1165 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1155 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1166 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1156 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1167 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1157 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1168
1158
1169 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1159 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1170 {
1160 {
1171 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1161 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1172 spw_ioctl_send_CWF.hdr = (char*) header;
1162 spw_ioctl_send_CWF.hdr = (char*) header;
1173 // BUILD THE DATA
1163 // BUILD THE DATA
1174 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1164 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1175
1165
1176 // SET PACKET SEQUENCE CONTROL
1166 // SET PACKET SEQUENCE CONTROL
1177 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1167 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1178
1168
1179 // SET SID
1169 // SET SID
1180 header->sid = sid;
1170 header->sid = sid;
1181
1171
1182 // SET PACKET TIME
1172 // SET PACKET TIME
1183 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1173 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1184 //
1174 //
1185 header->time[0] = header->acquisitionTime[0];
1175 header->time[0] = header->acquisitionTime[0];
1186 header->time[1] = header->acquisitionTime[1];
1176 header->time[1] = header->acquisitionTime[1];
1187 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1177 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1188 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1178 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1189 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1179 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1190 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1180 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1191
1181
1192 // SET PACKET ID
1182 // SET PACKET ID
1193 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1183 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1194 {
1184 {
1195 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1185 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1196 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1186 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1197 }
1187 }
1198 else
1188 else
1199 {
1189 {
1200 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1190 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1201 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1191 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1202 }
1192 }
1203
1193
1204 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1194 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1205 if (status != RTEMS_SUCCESSFUL) {
1195 if (status != RTEMS_SUCCESSFUL) {
1206 ret = LFR_DEFAULT;
1196 ret = LFR_DEFAULT;
1207 }
1197 }
1208 }
1198 }
1209
1199
1210 return ret;
1200 return ret;
1211 }
1201 }
1212
1202
1213 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1203 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1214 Header_TM_LFR_SCIENCE_SWF_t *header )
1204 Header_TM_LFR_SCIENCE_SWF_t *header )
1215 {
1205 {
1216 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1206 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1217 *
1207 *
1218 * @param waveform points to the buffer containing the data that will be send.
1208 * @param waveform points to the buffer containing the data that will be send.
1219 * @param sid is the source identifier of the data that will be sent.
1209 * @param sid is the source identifier of the data that will be sent.
1220 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1210 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1221 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1211 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1222 * contain information to setup the transmission of the data packets.
1212 * contain information to setup the transmission of the data packets.
1223 *
1213 *
1224 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1214 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1225 *
1215 *
1226 */
1216 */
1227
1217
1228 unsigned int i;
1218 unsigned int i;
1229 int ret;
1219 int ret;
1230 unsigned int coarseTime;
1220 unsigned int coarseTime;
1231 unsigned int fineTime;
1221 unsigned int fineTime;
1232 rtems_status_code status;
1222 rtems_status_code status;
1233 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1223 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1234 int *dataPtr;
1224 int *dataPtr;
1235 unsigned char sid;
1225 unsigned char sid;
1236
1226
1237 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1227 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1238 spw_ioctl_send_SWF.options = 0;
1228 spw_ioctl_send_SWF.options = 0;
1239
1229
1240 ret = LFR_DEFAULT;
1230 ret = LFR_DEFAULT;
1241
1231
1242 coarseTime = ring_node_to_send->coarseTime;
1232 coarseTime = ring_node_to_send->coarseTime;
1243 fineTime = ring_node_to_send->fineTime;
1233 fineTime = ring_node_to_send->fineTime;
1244 dataPtr = (int*) ring_node_to_send->buffer_address;
1234 dataPtr = (int*) ring_node_to_send->buffer_address;
1245 sid = ring_node_to_send->sid;
1235 sid = ring_node_to_send->sid;
1246
1236
1247 header->pa_bia_status_info = pa_bia_status_info;
1237 header->pa_bia_status_info = pa_bia_status_info;
1248 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1238 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1249
1239
1250 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1240 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1251 {
1241 {
1252 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1242 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1253 spw_ioctl_send_SWF.hdr = (char*) header;
1243 spw_ioctl_send_SWF.hdr = (char*) header;
1254
1244
1255 // SET PACKET SEQUENCE CONTROL
1245 // SET PACKET SEQUENCE CONTROL
1256 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1246 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1257
1247
1258 // SET PACKET LENGTH AND BLKNR
1248 // SET PACKET LENGTH AND BLKNR
1259 if (i == (PKTCNT_SWF-1))
1249 if (i == (PKTCNT_SWF-1))
1260 {
1250 {
1261 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1251 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1262 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1252 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1263 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1253 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1264 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1254 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1265 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1255 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1266 }
1256 }
1267 else
1257 else
1268 {
1258 {
1269 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1259 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1270 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1260 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1271 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1261 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1272 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1262 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1273 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1263 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1274 }
1264 }
1275
1265
1276 // SET PACKET TIME
1266 // SET PACKET TIME
1277 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1267 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1278 //
1268 //
1279 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1269 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1280 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1270 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1281 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1271 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1282 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1272 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1283 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1273 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1284 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1274 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1285
1275
1286 // SET SID
1276 // SET SID
1287 header->sid = sid;
1277 header->sid = sid;
1288
1278
1289 // SET PKTNR
1279 // SET PKTNR
1290 header->pktNr = i+1; // PKT_NR
1280 header->pktNr = i+1; // PKT_NR
1291
1281
1292 // SEND PACKET
1282 // SEND PACKET
1293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1283 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1294 if (status != RTEMS_SUCCESSFUL) {
1284 if (status != RTEMS_SUCCESSFUL) {
1295 ret = LFR_DEFAULT;
1285 ret = LFR_DEFAULT;
1296 }
1286 }
1297 }
1287 }
1298
1288
1299 return ret;
1289 return ret;
1300 }
1290 }
1301
1291
1302 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1292 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1303 Header_TM_LFR_SCIENCE_CWF_t *header )
1293 Header_TM_LFR_SCIENCE_CWF_t *header )
1304 {
1294 {
1305 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1295 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1306 *
1296 *
1307 * @param waveform points to the buffer containing the data that will be send.
1297 * @param waveform points to the buffer containing the data that will be send.
1308 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1298 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1309 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1299 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1310 * contain information to setup the transmission of the data packets.
1300 * contain information to setup the transmission of the data packets.
1311 *
1301 *
1312 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1302 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1313 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1303 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1314 *
1304 *
1315 */
1305 */
1316
1306
1317 unsigned int i;
1307 unsigned int i;
1318 int ret;
1308 int ret;
1319 unsigned int coarseTime;
1309 unsigned int coarseTime;
1320 unsigned int fineTime;
1310 unsigned int fineTime;
1321 rtems_status_code status;
1311 rtems_status_code status;
1322 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1312 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1323 char *dataPtr;
1313 char *dataPtr;
1324 unsigned char sid;
1314 unsigned char sid;
1325
1315
1326 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1316 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1327 spw_ioctl_send_CWF.options = 0;
1317 spw_ioctl_send_CWF.options = 0;
1328
1318
1329 ret = LFR_DEFAULT;
1319 ret = LFR_DEFAULT;
1330 sid = ring_node_to_send->sid;
1320 sid = ring_node_to_send->sid;
1331
1321
1332 coarseTime = ring_node_to_send->coarseTime;
1322 coarseTime = ring_node_to_send->coarseTime;
1333 fineTime = ring_node_to_send->fineTime;
1323 fineTime = ring_node_to_send->fineTime;
1334 dataPtr = (char*) ring_node_to_send->buffer_address;
1324 dataPtr = (char*) ring_node_to_send->buffer_address;
1335
1325
1336 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1326 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1337 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1327 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1338 header->pa_bia_status_info = pa_bia_status_info;
1328 header->pa_bia_status_info = pa_bia_status_info;
1339 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1329 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1340 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1330 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1341 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1331 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1342
1332
1343 //*********************
1333 //*********************
1344 // SEND CWF3_light DATA
1334 // SEND CWF3_light DATA
1345 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1335 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1346 {
1336 {
1347 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1337 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1348 spw_ioctl_send_CWF.hdr = (char*) header;
1338 spw_ioctl_send_CWF.hdr = (char*) header;
1349 // BUILD THE DATA
1339 // BUILD THE DATA
1350 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1340 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1351
1341
1352 // SET PACKET SEQUENCE COUNTER
1342 // SET PACKET SEQUENCE COUNTER
1353 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1343 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1354
1344
1355 // SET SID
1345 // SET SID
1356 header->sid = sid;
1346 header->sid = sid;
1357
1347
1358 // SET PACKET TIME
1348 // SET PACKET TIME
1359 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1349 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1360 //
1350 //
1361 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1351 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1362 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1352 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1363 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1353 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1364 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1354 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1365 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1355 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1366 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1356 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1367
1357
1368 // SET PACKET ID
1358 // SET PACKET ID
1369 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1359 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1370 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1360 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1371
1361
1372 // SEND PACKET
1362 // SEND PACKET
1373 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1363 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1374 if (status != RTEMS_SUCCESSFUL) {
1364 if (status != RTEMS_SUCCESSFUL) {
1375 ret = LFR_DEFAULT;
1365 ret = LFR_DEFAULT;
1376 }
1366 }
1377 }
1367 }
1378
1368
1379 return ret;
1369 return ret;
1380 }
1370 }
1381
1371
1382 void spw_send_asm_f0( ring_node *ring_node_to_send,
1372 void spw_send_asm_f0( ring_node *ring_node_to_send,
1383 Header_TM_LFR_SCIENCE_ASM_t *header )
1373 Header_TM_LFR_SCIENCE_ASM_t *header )
1384 {
1374 {
1385 unsigned int i;
1375 unsigned int i;
1386 unsigned int length = 0;
1376 unsigned int length = 0;
1387 rtems_status_code status;
1377 rtems_status_code status;
1388 unsigned int sid;
1378 unsigned int sid;
1389 float *spectral_matrix;
1379 float *spectral_matrix;
1390 int coarseTime;
1380 int coarseTime;
1391 int fineTime;
1381 int fineTime;
1392 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1382 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1393
1383
1394 sid = ring_node_to_send->sid;
1384 sid = ring_node_to_send->sid;
1395 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1385 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1396 coarseTime = ring_node_to_send->coarseTime;
1386 coarseTime = ring_node_to_send->coarseTime;
1397 fineTime = ring_node_to_send->fineTime;
1387 fineTime = ring_node_to_send->fineTime;
1398
1388
1399 header->pa_bia_status_info = pa_bia_status_info;
1389 header->pa_bia_status_info = pa_bia_status_info;
1400 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1390 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1401
1391
1402 for (i=0; i<PKTCNT_ASM; i++)
1392 for (i=0; i<PKTCNT_ASM; i++)
1403 {
1393 {
1404 if ((i==0) || (i==1))
1394 if ((i==0) || (i==1))
1405 {
1395 {
1406 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1396 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1407 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1397 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1398 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1409 ];
1399 ];
1410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1400 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1411 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1401 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1412 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1402 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1413 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1403 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1414 }
1404 }
1415 else
1405 else
1416 {
1406 {
1417 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1407 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1418 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1408 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1419 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1409 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1420 ];
1410 ];
1421 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1411 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1422 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1412 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1423 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1413 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1424 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1414 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1425 }
1415 }
1426
1416
1427 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1417 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1428 spw_ioctl_send_ASM.hdr = (char *) header;
1418 spw_ioctl_send_ASM.hdr = (char *) header;
1429 spw_ioctl_send_ASM.options = 0;
1419 spw_ioctl_send_ASM.options = 0;
1430
1420
1431 // (2) BUILD THE HEADER
1421 // (2) BUILD THE HEADER
1432 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1422 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1433 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1423 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1434 header->packetLength[1] = (unsigned char) (length);
1424 header->packetLength[1] = (unsigned char) (length);
1435 header->sid = (unsigned char) sid; // SID
1425 header->sid = (unsigned char) sid; // SID
1436 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1426 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1437 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1427 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1438
1428
1439 // (3) SET PACKET TIME
1429 // (3) SET PACKET TIME
1440 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1430 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1441 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1431 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1442 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1432 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1443 header->time[BYTE_3] = (unsigned char) (coarseTime);
1433 header->time[BYTE_3] = (unsigned char) (coarseTime);
1444 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1434 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1445 header->time[BYTE_5] = (unsigned char) (fineTime);
1435 header->time[BYTE_5] = (unsigned char) (fineTime);
1446 //
1436 //
1447 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1437 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1448 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1438 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1449 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1439 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1450 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1440 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1451 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1441 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1452 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1442 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1453
1443
1454 // (4) SEND PACKET
1444 // (4) SEND PACKET
1455 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1445 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1456 if (status != RTEMS_SUCCESSFUL) {
1446 if (status != RTEMS_SUCCESSFUL) {
1457 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1447 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1458 }
1448 }
1459 }
1449 }
1460 }
1450 }
1461
1451
1462 void spw_send_asm_f1( ring_node *ring_node_to_send,
1452 void spw_send_asm_f1( ring_node *ring_node_to_send,
1463 Header_TM_LFR_SCIENCE_ASM_t *header )
1453 Header_TM_LFR_SCIENCE_ASM_t *header )
1464 {
1454 {
1465 unsigned int i;
1455 unsigned int i;
1466 unsigned int length = 0;
1456 unsigned int length = 0;
1467 rtems_status_code status;
1457 rtems_status_code status;
1468 unsigned int sid;
1458 unsigned int sid;
1469 float *spectral_matrix;
1459 float *spectral_matrix;
1470 int coarseTime;
1460 int coarseTime;
1471 int fineTime;
1461 int fineTime;
1472 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1462 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1473
1463
1474 sid = ring_node_to_send->sid;
1464 sid = ring_node_to_send->sid;
1475 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1465 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1476 coarseTime = ring_node_to_send->coarseTime;
1466 coarseTime = ring_node_to_send->coarseTime;
1477 fineTime = ring_node_to_send->fineTime;
1467 fineTime = ring_node_to_send->fineTime;
1478
1468
1479 header->pa_bia_status_info = pa_bia_status_info;
1469 header->pa_bia_status_info = pa_bia_status_info;
1480 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1470 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1481
1471
1482 for (i=0; i<PKTCNT_ASM; i++)
1472 for (i=0; i<PKTCNT_ASM; i++)
1483 {
1473 {
1484 if ((i==0) || (i==1))
1474 if ((i==0) || (i==1))
1485 {
1475 {
1486 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1476 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1487 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1477 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1488 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1478 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1489 ];
1479 ];
1490 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1480 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1481 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1492 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1482 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1493 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1483 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1494 }
1484 }
1495 else
1485 else
1496 {
1486 {
1497 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1487 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1498 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1488 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1499 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1489 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1500 ];
1490 ];
1501 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1491 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1502 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1492 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1503 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1493 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1504 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1494 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1505 }
1495 }
1506
1496
1507 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1497 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1508 spw_ioctl_send_ASM.hdr = (char *) header;
1498 spw_ioctl_send_ASM.hdr = (char *) header;
1509 spw_ioctl_send_ASM.options = 0;
1499 spw_ioctl_send_ASM.options = 0;
1510
1500
1511 // (2) BUILD THE HEADER
1501 // (2) BUILD THE HEADER
1512 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1502 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1513 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1503 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1514 header->packetLength[1] = (unsigned char) (length);
1504 header->packetLength[1] = (unsigned char) (length);
1515 header->sid = (unsigned char) sid; // SID
1505 header->sid = (unsigned char) sid; // SID
1516 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1506 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1517 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1507 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1518
1508
1519 // (3) SET PACKET TIME
1509 // (3) SET PACKET TIME
1520 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1510 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1521 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1511 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1522 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1512 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1523 header->time[BYTE_3] = (unsigned char) (coarseTime);
1513 header->time[BYTE_3] = (unsigned char) (coarseTime);
1524 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1514 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1525 header->time[BYTE_5] = (unsigned char) (fineTime);
1515 header->time[BYTE_5] = (unsigned char) (fineTime);
1526 //
1516 //
1527 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1517 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1528 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1518 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1529 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1519 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1530 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1520 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1531 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1521 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1532 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1522 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1533
1523
1534 // (4) SEND PACKET
1524 // (4) SEND PACKET
1535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1525 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1536 if (status != RTEMS_SUCCESSFUL) {
1526 if (status != RTEMS_SUCCESSFUL) {
1537 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1527 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1538 }
1528 }
1539 }
1529 }
1540 }
1530 }
1541
1531
1532 /**
1533 * @brief spw_send_asm_f2 Sends an ASM packet at F2 over spacewire
1534 * @param ring_node_to_send node pointing to the actual buffer to send
1535 * @param header
1536 */
1542 void spw_send_asm_f2( ring_node *ring_node_to_send,
1537 void spw_send_asm_f2( ring_node *ring_node_to_send,
1543 Header_TM_LFR_SCIENCE_ASM_t *header )
1538 Header_TM_LFR_SCIENCE_ASM_t *header )
1544 {
1539 {
1545 unsigned int i;
1540 unsigned int i;
1546 unsigned int length = 0;
1541 unsigned int length = 0;
1547 rtems_status_code status;
1542 rtems_status_code status;
1548 unsigned int sid;
1543 unsigned int sid;
1549 float *spectral_matrix;
1544 float *spectral_matrix;
1550 int coarseTime;
1545 int coarseTime;
1551 int fineTime;
1546 int fineTime;
1552 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1547 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1553
1548
1554 sid = ring_node_to_send->sid;
1549 sid = ring_node_to_send->sid;
1555 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1550 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1556 coarseTime = ring_node_to_send->coarseTime;
1551 coarseTime = ring_node_to_send->coarseTime;
1557 fineTime = ring_node_to_send->fineTime;
1552 fineTime = ring_node_to_send->fineTime;
1558
1553
1559 header->pa_bia_status_info = pa_bia_status_info;
1554 header->pa_bia_status_info = pa_bia_status_info;
1560 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1555 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1561
1556
1562 for (i=0; i<PKTCNT_ASM; i++)
1557 for (i=0; i<PKTCNT_ASM; i++)
1563 {
1558 {
1564
1559
1565 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1560 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1566 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1561 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1567 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1562 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1568 ];
1563 ];
1569 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1564 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1570 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1565 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1571 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1566 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1572 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1567 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1573
1568
1574 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1569 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1575 spw_ioctl_send_ASM.hdr = (char *) header;
1570 spw_ioctl_send_ASM.hdr = (char *) header;
1576 spw_ioctl_send_ASM.options = 0;
1571 spw_ioctl_send_ASM.options = 0;
1577
1572
1578 // (2) BUILD THE HEADER
1573 // (2) BUILD THE HEADER
1579 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1574 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1580 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1575 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1581 header->packetLength[1] = (unsigned char) (length);
1576 header->packetLength[1] = (unsigned char) (length);
1582 header->sid = (unsigned char) sid; // SID
1577 header->sid = (unsigned char) sid; // SID
1583 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1578 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1584 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1579 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1585
1580
1586 // (3) SET PACKET TIME
1581 // (3) SET PACKET TIME
1587 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1582 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1588 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1583 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1589 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1584 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1590 header->time[BYTE_3] = (unsigned char) (coarseTime);
1585 header->time[BYTE_3] = (unsigned char) (coarseTime);
1591 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1586 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1592 header->time[BYTE_5] = (unsigned char) (fineTime);
1587 header->time[BYTE_5] = (unsigned char) (fineTime);
1593 //
1588 //
1594 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1589 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1595 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1590 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1596 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1591 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1597 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1592 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1598 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1593 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1599 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1594 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1600
1595
1601 // (4) SEND PACKET
1596 // (4) SEND PACKET
1602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1597 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1603 if (status != RTEMS_SUCCESSFUL) {
1598 if (status != RTEMS_SUCCESSFUL) {
1604 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1599 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1605 }
1600 }
1606 }
1601 }
1607 }
1602 }
1608
1603
1604 /**
1605 * @brief spw_send_k_dump Sends k coefficients dump packet over spacewire
1606 * @param ring_node_to_send node pointing to the actual buffer to send
1607 */
1609 void spw_send_k_dump( ring_node *ring_node_to_send )
1608 void spw_send_k_dump( ring_node *ring_node_to_send )
1610 {
1609 {
1611 rtems_status_code status;
1610 rtems_status_code status;
1612 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1611 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1613 unsigned int packetLength;
1612 unsigned int packetLength;
1614 unsigned int size;
1613 unsigned int size;
1615
1614
1616 PRINTF("spw_send_k_dump\n")
1615 PRINTF("spw_send_k_dump\n")
1617
1616
1618 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1617 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1619
1618
1620 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1619 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1621
1620
1622 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1621 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1623
1622
1624 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1623 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1625
1624
1626 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1625 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1627
1626
1628 if (status == -1){
1627 if (status == -1){
1629 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1628 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1630 }
1629 }
1631
1630
1632 ring_node_to_send->status = INIT_CHAR;
1631 ring_node_to_send->status = INIT_CHAR;
1633 }
1632 }
@@ -1,118 +1,69
1 /*
1 /*
2 * CPU Usage Reporter
2 * CPU Usage Reporter
3 *
3 *
4 * COPYRIGHT (c) 1989-2009
4 * COPYRIGHT (c) 1989-2009
5 * On-Line Applications Research Corporation (OAR).
5 * On-Line Applications Research Corporation (OAR).
6 *
6 *
7 * The license and distribution terms for this file may be
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.com/license/LICENSE.
9 * http://www.rtems.com/license/LICENSE.
10 *
10 *
11 * $Id$
11 * $Id$
12 */
12 */
13
13
14 #include "lfr_cpu_usage_report.h"
14 #include "lfr_cpu_usage_report.h"
15 #include "fsw_params.h"
16
17 extern rtems_id Task_id[];
15
18
16 unsigned char lfr_rtems_cpu_usage_report( void )
19 unsigned char lfr_rtems_cpu_usage_report( void )
17 {
20 {
18 uint32_t api_index;
21 uint32_t api_index;
22 uint32_t information_index;
19 Thread_Control *the_thread;
23 Thread_Control *the_thread;
20 Objects_Information *information;
24 Objects_Information *information;
21 uint32_t ival;
25 uint32_t ival;
22 uint32_t fval;
26 uint32_t fval;
23 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
27 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
24 Timestamp_Control uptime;
28 Timestamp_Control uptime;
25 Timestamp_Control total;
29 Timestamp_Control total;
26 Timestamp_Control ran;
30 Timestamp_Control ran;
31
27 #else
32 #else
28 uint32_t total_units = 0;
33 #error "Can't compute CPU usage using ticks on LFR"
29 #endif
34 #endif
30
35
31 unsigned char cpu_load;
36 unsigned char cpu_load;
32
37
33 ival = 0;
38 ival = 0;
34 cpu_load = 0;
39 cpu_load = 0;
35
40
36 /*
37 * When not using nanosecond CPU usage resolution, we have to count
38 * the number of "ticks" we gave credit for to give the user a rough
39 * guideline as to what each number means proportionally.
40 */
41 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
42 _TOD_Get_uptime( &uptime );
43 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
44 #else
45 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
46 if ( !_Objects_Information_table[ api_index ] ) { }
47 else
48 {
49 information = _Objects_Information_table[ api_index ][ 1 ];
50 if ( information != NULL )
51 {
52 for ( i=1 ; i <= information->maximum ; i++ ) {
53 the_thread = (Thread_Control *)information->local_table[ i ];
54
55 if ( the_thread != NULL ) {
56 total_units += the_thread->cpu_time_used; }
57 }
58 }
59 }
60 }
61 #endif
62
63 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
41 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
64 {
42 {
65 if ( !_Objects_Information_table[ api_index ] ) { }
43 if ( !_Objects_Information_table[ api_index ] ) { }
66 else
44 else
67 {
45 {
68 information = _Objects_Information_table[ api_index ][ 1 ];
46 information = _Objects_Information_table[ api_index ][ 1 ];
69 if ( information != NULL )
47 if ( information != NULL )
70 {
48 {
71 the_thread = (Thread_Control *)information->local_table[ 1 ];
49 for(information_index=1;information_index<=information->maximum;information_index++)
72
73 if ( the_thread == NULL ) { }
74 else
75 {
50 {
76 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
51 the_thread = (Thread_Control *)information->local_table[ information_index ];
77 /*
52
78 * If this is the currently executing thread, account for time
53 if ( the_thread == NULL) { }
79 * since the last context switch.
54 else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing
80 */
81 ran = the_thread->cpu_time_used;
82 if ( _Thread_Executing->Object.id == the_thread->Object.id )
83 {
55 {
84 Timestamp_Control used;
56 _TOD_Get_uptime( &uptime );
85 _Timestamp_Subtract(
57 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
86 &_Thread_Time_of_last_context_switch, &uptime, &used
58 ran = the_thread->cpu_time_used;
87 );
59 _Timestamp_Divide( &ran, &total, &ival, &fval);
88 _Timestamp_Add_to( &ran, &used );
60 cpu_load = (unsigned char)(CONST_255 - ((ival*CONST_10+fval/CONST_100)*CONST_256/CONST_1000));
89 }
61 }
90 _Timestamp_Divide( &ran, &total, &ival, &fval );
91
92 #else
93 if (total_units != 0)
94 {
95 uint64_t ival_64;
96
97 ival_64 = the_thread->cpu_time_used;
98 ival_64 *= CONST_100000;
99 ival = ival_64 / total_units;
100 }
101 else
102 {
103 ival = 0;
104 }
105
106 fval = ival % CONST_1000;
107 ival /= CONST_1000;
108 #endif
109 }
62 }
110 }
63 }
111 }
64 }
112 }
65 }
113 cpu_load = (unsigned char) (CONST_100 - ival);
114
115 return cpu_load;
66 return cpu_load;
116 }
67 }
117
68
118
69
@@ -1,423 +1,447
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf0_prc0.h"
34 #include "avf0_prc0.h"
11
35
12 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
36 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
13
37
14 //***
38 //***
15 // F0
39 // F0
16 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
40 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
41 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
18
42
19 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
43 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
20 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
44 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
21
45
22 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
46 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
47 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
48 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
25
49
26 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
50 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
27 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
51 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
28
52
29 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
53 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
30 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
54 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
31
55
32 //************
56 //************
33 // RTEMS TASKS
57 // RTEMS TASKS
34
58
35 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
59 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 {
60 {
37 int i;
61 int i;
38
62
39 rtems_event_set event_out;
63 rtems_event_set event_out;
40 rtems_status_code status;
64 rtems_status_code status;
41 rtems_id queue_id_prc0;
65 rtems_id queue_id_prc0;
42 asm_msg msgForPRC;
66 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
67 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
68 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
69 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 ring_node_asm *current_ring_node_asm_norm_f0;
70 ring_node_asm *current_ring_node_asm_norm_f0;
47
71
48 unsigned int nb_norm_bp1;
72 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
73 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
74 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
75 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
76 unsigned int nb_sbm_bp2;
53
77
54 nb_norm_bp1 = 0;
78 nb_norm_bp1 = 0;
55 nb_norm_bp2 = 0;
79 nb_norm_bp2 = 0;
56 nb_norm_asm = 0;
80 nb_norm_asm = 0;
57 nb_sbm_bp1 = 0;
81 nb_sbm_bp1 = 0;
58 nb_sbm_bp2 = 0;
82 nb_sbm_bp2 = 0;
59 event_out = EVENT_SETS_NONE_PENDING;
83 event_out = EVENT_SETS_NONE_PENDING;
60 queue_id_prc0 = RTEMS_ID_NONE;
84 queue_id_prc0 = RTEMS_ID_NONE;
61
85
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
86 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
87 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
88 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
89 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
90 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67
91
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
92 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
69
93
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
94 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 if (status != RTEMS_SUCCESSFUL)
95 if (status != RTEMS_SUCCESSFUL)
72 {
96 {
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
97 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 }
98 }
75
99
76 while(1){
100 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
101 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
102
79 //****************************************
103 //****************************************
80 // initialize the mesage for the MATR task
104 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
105 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
106 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
107 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 //
108 //
85 //****************************************
109 //****************************************
86
110
87 nodeForAveraging = getRingNodeForAveraging( 0 );
111 nodeForAveraging = getRingNodeForAveraging( 0 );
88
112
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
113 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
114 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 {
115 {
92 nodeForAveraging = nodeForAveraging->previous;
116 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
117 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
94 }
118 }
95
119
96 // compute the average and store it in the averaged_sm_f1 buffer
120 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f0->matrix,
121 SM_average( current_ring_node_asm_norm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
122 current_ring_node_asm_burst_sbm_f0->matrix,
99 ring_node_tab,
123 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
124 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC, 0 ); // 0 => frequency channel 0
125 &msgForPRC, 0 ); // 0 => frequency channel 0
102
126
103 // update nb_average
127 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
128 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
129 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
130 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
131 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
132 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109
133
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
134 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 {
135 {
112 nb_sbm_bp1 = 0;
136 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
137 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
138 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
139 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
140 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
141 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 }
142 }
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 {
144 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
145 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 }
146 }
123 }
147 }
124
148
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
149 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 {
150 {
127 nb_sbm_bp2 = 0;
151 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
152 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
153 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
154 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 }
155 }
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
157 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
158 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 }
159 }
136 }
160 }
137
161
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
162 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 {
163 {
140 nb_norm_bp1 = 0;
164 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
165 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
166 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
167 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
168 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
169 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
170 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 }
171 }
148 }
172 }
149
173
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
174 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 {
175 {
152 nb_norm_bp2 = 0;
176 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
177 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
178 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
179 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
180 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 }
181 }
158 }
182 }
159
183
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
184 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 {
185 {
162 nb_norm_asm = 0;
186 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
187 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
188 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
189 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
190 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 }
191 }
168 }
192 }
169
193
170 //*************************
194 //*************************
171 // send the message to PRC
195 // send the message to PRC
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
196 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 {
197 {
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
198 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 }
199 }
176
200
177 if (status != RTEMS_SUCCESSFUL) {
201 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
202 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 }
203 }
180 }
204 }
181 }
205 }
182
206
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
207 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 {
208 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
209 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
210 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
211 asm_msg *incomingMsg;
188 //
212 //
189 unsigned char sid;
213 unsigned char sid;
190 rtems_status_code status;
214 rtems_status_code status;
191 rtems_id queue_id;
215 rtems_id queue_id;
192 rtems_id queue_id_q_p0;
216 rtems_id queue_id_q_p0;
193 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
217 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
194 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
218 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
195 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
219 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
220 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f0;
221 ring_node *current_ring_node_to_send_asm_f0;
198 float nbSMInASMNORM;
222 float nbSMInASMNORM;
199 float nbSMInASMSBM;
223 float nbSMInASMSBM;
200
224
201 size = 0;
225 size = 0;
202 queue_id = RTEMS_ID_NONE;
226 queue_id = RTEMS_ID_NONE;
203 queue_id_q_p0 = RTEMS_ID_NONE;
227 queue_id_q_p0 = RTEMS_ID_NONE;
204 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
228 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
205 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
229 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
206 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
230 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
231 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
208
232
209 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
233 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
234 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
211 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
235 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
212
236
213 //*************
237 //*************
214 // NORM headers
238 // NORM headers
215 BP_init_header_with_spare( &packet_norm_bp1,
239 BP_init_header_with_spare( &packet_norm_bp1,
216 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
240 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
217 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
241 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
218 BP_init_header( &packet_norm_bp2,
242 BP_init_header( &packet_norm_bp2,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
243 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
244 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
221
245
222 //****************************
246 //****************************
223 // BURST SBM1 and SBM2 headers
247 // BURST SBM1 and SBM2 headers
224 if ( lfrRequestedMode == LFR_MODE_BURST )
248 if ( lfrRequestedMode == LFR_MODE_BURST )
225 {
249 {
226 BP_init_header( &packet_sbm_bp1,
250 BP_init_header( &packet_sbm_bp1,
227 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
251 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
252 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 BP_init_header( &packet_sbm_bp2,
253 BP_init_header( &packet_sbm_bp2,
230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
254 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
255 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 }
256 }
233 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
257 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
234 {
258 {
235 BP_init_header( &packet_sbm_bp1,
259 BP_init_header( &packet_sbm_bp1,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
260 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
261 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 BP_init_header( &packet_sbm_bp2,
262 BP_init_header( &packet_sbm_bp2,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
263 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
264 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 }
265 }
242 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
266 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
243 {
267 {
244 BP_init_header( &packet_sbm_bp1,
268 BP_init_header( &packet_sbm_bp1,
245 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
269 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
246 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
270 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
247 BP_init_header( &packet_sbm_bp2,
271 BP_init_header( &packet_sbm_bp2,
248 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
272 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
249 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
273 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
250 }
274 }
251 else
275 else
252 {
276 {
253 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
277 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
254 }
278 }
255
279
256 status = get_message_queue_id_send( &queue_id );
280 status = get_message_queue_id_send( &queue_id );
257 if (status != RTEMS_SUCCESSFUL)
281 if (status != RTEMS_SUCCESSFUL)
258 {
282 {
259 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
283 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
260 }
284 }
261 status = get_message_queue_id_prc0( &queue_id_q_p0);
285 status = get_message_queue_id_prc0( &queue_id_q_p0);
262 if (status != RTEMS_SUCCESSFUL)
286 if (status != RTEMS_SUCCESSFUL)
263 {
287 {
264 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
288 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
265 }
289 }
266
290
267 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
291 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
268
292
269 while(1){
293 while(1){
270 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
294 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
271 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
295 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
272
296
273 incomingMsg = (asm_msg*) incomingData;
297 incomingMsg = (asm_msg*) incomingData;
274
298
275 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
299 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
276 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
300 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
277
301
278 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
302 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
279 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
303 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
280
304
281 //****************
305 //****************
282 //****************
306 //****************
283 // BURST SBM1 SBM2
307 // BURST SBM1 SBM2
284 //****************
308 //****************
285 //****************
309 //****************
286 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
310 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
287 {
311 {
288 sid = getSID( incomingMsg->event );
312 sid = getSID( incomingMsg->event );
289 // 1) compress the matrix for Basic Parameters calculation
313 // 1) compress the matrix for Basic Parameters calculation
290 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
314 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
291 nbSMInASMSBM,
315 nbSMInASMSBM,
292 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
316 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
293 ASM_F0_INDICE_START, CHANNELF0);
317 ASM_F0_INDICE_START, CHANNELF0);
294 // 2) compute the BP1 set
318 // 2) compute the BP1 set
295 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
319 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
296 // 3) send the BP1 set
320 // 3) send the BP1 set
297 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
321 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
322 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
323 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
300 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
324 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
325 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
326 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
303 sid);
327 sid);
304 // 4) compute the BP2 set if needed
328 // 4) compute the BP2 set if needed
305 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
329 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
306 {
330 {
307 // 1) compute the BP2 set
331 // 1) compute the BP2 set
308 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
332 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
309 // 2) send the BP2 set
333 // 2) send the BP2 set
310 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
334 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
335 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
312 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
336 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
313 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
337 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
338 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
315 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
339 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
316 sid);
340 sid);
317 }
341 }
318 }
342 }
319
343
320 //*****
344 //*****
321 //*****
345 //*****
322 // NORM
346 // NORM
323 //*****
347 //*****
324 //*****
348 //*****
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
349 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
326 {
350 {
327 // 1) compress the matrix for Basic Parameters calculation
351 // 1) compress the matrix for Basic Parameters calculation
328 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
352 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
329 nbSMInASMNORM,
353 nbSMInASMNORM,
330 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
354 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
331 ASM_F0_INDICE_START, CHANNELF0 );
355 ASM_F0_INDICE_START, CHANNELF0 );
332 // 2) compute the BP1 set
356 // 2) compute the BP1 set
333 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
357 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
334 // 3) send the BP1 set
358 // 3) send the BP1 set
335 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
359 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
360 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
337 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
361 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
338 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
362 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
339 BP_send( (char *) &packet_norm_bp1, queue_id,
363 BP_send( (char *) &packet_norm_bp1, queue_id,
340 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
364 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
341 SID_NORM_BP1_F0 );
365 SID_NORM_BP1_F0 );
342 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
366 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
343 {
367 {
344 // 1) compute the BP2 set using the same ASM as the one used for BP1
368 // 1) compute the BP2 set using the same ASM as the one used for BP1
345 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
369 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
346 // 2) send the BP2 set
370 // 2) send the BP2 set
347 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
371 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
372 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
349 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
373 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
350 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
374 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
351 BP_send( (char *) &packet_norm_bp2, queue_id,
375 BP_send( (char *) &packet_norm_bp2, queue_id,
352 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
376 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
353 SID_NORM_BP2_F0);
377 SID_NORM_BP2_F0);
354 }
378 }
355 }
379 }
356
380
357 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
381 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
358 {
382 {
359 // 1) reorganize the ASM and divide
383 // 1) reorganize the ASM and divide
360 ASM_reorganize_and_divide( asm_f0_patched_norm,
384 ASM_reorganize_and_divide( asm_f0_patched_norm,
361 (float*) current_ring_node_to_send_asm_f0->buffer_address,
385 (float*) current_ring_node_to_send_asm_f0->buffer_address,
362 nbSMInASMNORM );
386 nbSMInASMNORM );
363 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
387 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
364 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
388 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
365 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
389 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
366
390
367 // 3) send the spectral matrix packets
391 // 3) send the spectral matrix packets
368 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
392 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
369
393
370 // change asm ring node
394 // change asm ring node
371 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
395 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
372 }
396 }
373
397
374 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
398 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
375
399
376 }
400 }
377 }
401 }
378
402
379 //**********
403 //**********
380 // FUNCTIONS
404 // FUNCTIONS
381
405
382 void reset_nb_sm_f0( unsigned char lfrMode )
406 void reset_nb_sm_f0( unsigned char lfrMode )
383 {
407 {
384 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
408 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
385 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
409 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
386 nb_sm_before_f0.norm_asm =
410 nb_sm_before_f0.norm_asm =
387 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
411 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
388 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
412 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
389 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
413 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
390 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
414 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
391 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
415 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
392 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
416 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
393 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
417 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
394
418
395 if (lfrMode == LFR_MODE_SBM1)
419 if (lfrMode == LFR_MODE_SBM1)
396 {
420 {
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
421 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
422 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
399 }
423 }
400 else if (lfrMode == LFR_MODE_SBM2)
424 else if (lfrMode == LFR_MODE_SBM2)
401 {
425 {
402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
426 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
427 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
404 }
428 }
405 else if (lfrMode == LFR_MODE_BURST)
429 else if (lfrMode == LFR_MODE_BURST)
406 {
430 {
407 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
431 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
408 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
432 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
409 }
433 }
410 else
434 else
411 {
435 {
412 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
436 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
413 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
437 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
414 }
438 }
415 }
439 }
416
440
417 void init_k_coefficients_prc0( void )
441 void init_k_coefficients_prc0( void )
418 {
442 {
419 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
443 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
420
444
421 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
445 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
422 }
446 }
423
447
@@ -1,407 +1,431
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf1_prc1.h"
34 #include "avf1_prc1.h"
11
35
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
36 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
13
37
14 //***
38 //***
15 // F1
39 // F1
16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
40 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
41 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
18
42
19 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
43 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
20 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
44 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
21
45
22 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
46 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
47 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
48 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
25
49
26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
50 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
51 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
28
52
29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
53 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
54 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
31
55
32 //************
56 //************
33 // RTEMS TASKS
57 // RTEMS TASKS
34
58
35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
59 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 {
60 {
37 int i;
61 int i;
38
62
39 rtems_event_set event_out;
63 rtems_event_set event_out;
40 rtems_status_code status;
64 rtems_status_code status;
41 rtems_id queue_id_prc1;
65 rtems_id queue_id_prc1;
42 asm_msg msgForPRC;
66 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
67 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
68 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
69 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 ring_node_asm *current_ring_node_asm_norm_f1;
70 ring_node_asm *current_ring_node_asm_norm_f1;
47
71
48 unsigned int nb_norm_bp1;
72 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
73 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
74 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
75 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
76 unsigned int nb_sbm_bp2;
53
77
54 event_out = EVENT_SETS_NONE_PENDING;
78 event_out = EVENT_SETS_NONE_PENDING;
55 queue_id_prc1 = RTEMS_ID_NONE;
79 queue_id_prc1 = RTEMS_ID_NONE;
56
80
57 nb_norm_bp1 = 0;
81 nb_norm_bp1 = 0;
58 nb_norm_bp2 = 0;
82 nb_norm_bp2 = 0;
59 nb_norm_asm = 0;
83 nb_norm_asm = 0;
60 nb_sbm_bp1 = 0;
84 nb_sbm_bp1 = 0;
61 nb_sbm_bp2 = 0;
85 nb_sbm_bp2 = 0;
62
86
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
87 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
88 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
89 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
90 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
91 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68
92
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
93 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70
94
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
95 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 if (status != RTEMS_SUCCESSFUL)
96 if (status != RTEMS_SUCCESSFUL)
73 {
97 {
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
98 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 }
99 }
76
100
77 while(1){
101 while(1){
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
102 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79
103
80 //****************************************
104 //****************************************
81 // initialize the mesage for the MATR task
105 // initialize the mesage for the MATR task
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
106 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
107 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
108 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
85 //
109 //
86 //****************************************
110 //****************************************
87
111
88 nodeForAveraging = getRingNodeForAveraging( 1 );
112 nodeForAveraging = getRingNodeForAveraging( 1 );
89
113
90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
114 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
115 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
92 {
116 {
93 nodeForAveraging = nodeForAveraging->previous;
117 nodeForAveraging = nodeForAveraging->previous;
94 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
118 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
95 }
119 }
96
120
97 // compute the average and store it in the averaged_sm_f1 buffer
121 // compute the average and store it in the averaged_sm_f1 buffer
98 SM_average( current_ring_node_asm_norm_f1->matrix,
122 SM_average( current_ring_node_asm_norm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
123 current_ring_node_asm_burst_sbm_f1->matrix,
100 ring_node_tab,
124 ring_node_tab,
101 nb_norm_bp1, nb_sbm_bp1,
125 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC, 1 ); // 1 => frequency channel 1
126 &msgForPRC, 1 ); // 1 => frequency channel 1
103
127
104 // update nb_average
128 // update nb_average
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
129 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
130 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
131 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
132 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
133 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
110
134
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
135 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 {
136 {
113 nb_sbm_bp1 = 0;
137 nb_sbm_bp1 = 0;
114 // set another ring for the ASM storage
138 // set another ring for the ASM storage
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
139 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
140 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
141 {
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
142 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 }
143 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
144 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
145 {
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 }
147 }
124 }
148 }
125
149
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
150 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 {
151 {
128 nb_sbm_bp2 = 0;
152 nb_sbm_bp2 = 0;
129 if ( lfrCurrentMode == LFR_MODE_BURST )
153 if ( lfrCurrentMode == LFR_MODE_BURST )
130 {
154 {
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
155 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 }
156 }
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
157 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 {
158 {
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
159 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 }
160 }
137 }
161 }
138
162
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
163 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 {
164 {
141 nb_norm_bp1 = 0;
165 nb_norm_bp1 = 0;
142 // set another ring for the ASM storage
166 // set another ring for the ASM storage
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
167 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
168 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
169 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
170 {
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
171 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 }
172 }
149 }
173 }
150
174
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
175 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 {
176 {
153 nb_norm_bp2 = 0;
177 nb_norm_bp2 = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
178 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
179 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
180 {
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
181 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 }
182 }
159 }
183 }
160
184
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
185 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 {
186 {
163 nb_norm_asm = 0;
187 nb_norm_asm = 0;
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
188 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
189 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 {
190 {
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
191 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 }
192 }
169 }
193 }
170
194
171 //*************************
195 //*************************
172 // send the message to PRC
196 // send the message to PRC
173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
197 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
174 {
198 {
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
199 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 }
200 }
177
201
178 if (status != RTEMS_SUCCESSFUL) {
202 if (status != RTEMS_SUCCESSFUL) {
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
203 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 }
204 }
181 }
205 }
182 }
206 }
183
207
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
208 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 {
209 {
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
210 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 size_t size; // size of the incoming TC packet
211 size_t size; // size of the incoming TC packet
188 asm_msg *incomingMsg;
212 asm_msg *incomingMsg;
189 //
213 //
190 unsigned char sid;
214 unsigned char sid;
191 rtems_status_code status;
215 rtems_status_code status;
192 rtems_id queue_id_send;
216 rtems_id queue_id_send;
193 rtems_id queue_id_q_p1;
217 rtems_id queue_id_q_p1;
194 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
218 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
195 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
219 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
220 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
197 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
221 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
198 ring_node *current_ring_node_to_send_asm_f1;
222 ring_node *current_ring_node_to_send_asm_f1;
199 float nbSMInASMNORM;
223 float nbSMInASMNORM;
200 float nbSMInASMSBM;
224 float nbSMInASMSBM;
201
225
202 size = 0;
226 size = 0;
203 queue_id_send = RTEMS_ID_NONE;
227 queue_id_send = RTEMS_ID_NONE;
204 queue_id_q_p1 = RTEMS_ID_NONE;
228 queue_id_q_p1 = RTEMS_ID_NONE;
205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
229 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
230 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
231 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
232 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
209
233
210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
234 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
211 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
235 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
212 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
236 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
213
237
214 //*************
238 //*************
215 // NORM headers
239 // NORM headers
216 BP_init_header_with_spare( &packet_norm_bp1,
240 BP_init_header_with_spare( &packet_norm_bp1,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
241 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
242 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
219 BP_init_header( &packet_norm_bp2,
243 BP_init_header( &packet_norm_bp2,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
244 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
245 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
222
246
223 //***********************
247 //***********************
224 // BURST and SBM2 headers
248 // BURST and SBM2 headers
225 if ( lfrRequestedMode == LFR_MODE_BURST )
249 if ( lfrRequestedMode == LFR_MODE_BURST )
226 {
250 {
227 BP_init_header( &packet_sbm_bp1,
251 BP_init_header( &packet_sbm_bp1,
228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
252 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
253 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 BP_init_header( &packet_sbm_bp2,
254 BP_init_header( &packet_sbm_bp2,
231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
255 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
256 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 }
257 }
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
258 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
235 {
259 {
236 BP_init_header( &packet_sbm_bp1,
260 BP_init_header( &packet_sbm_bp1,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
261 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
262 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
239 BP_init_header( &packet_sbm_bp2,
263 BP_init_header( &packet_sbm_bp2,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
264 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
265 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
242 }
266 }
243 else
267 else
244 {
268 {
245 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
269 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
246 }
270 }
247
271
248 status = get_message_queue_id_send( &queue_id_send );
272 status = get_message_queue_id_send( &queue_id_send );
249 if (status != RTEMS_SUCCESSFUL)
273 if (status != RTEMS_SUCCESSFUL)
250 {
274 {
251 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
275 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
252 }
276 }
253 status = get_message_queue_id_prc1( &queue_id_q_p1);
277 status = get_message_queue_id_prc1( &queue_id_q_p1);
254 if (status != RTEMS_SUCCESSFUL)
278 if (status != RTEMS_SUCCESSFUL)
255 {
279 {
256 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
280 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
257 }
281 }
258
282
259 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
283 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
260
284
261 while(1){
285 while(1){
262 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
286 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
287 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
264
288
265 incomingMsg = (asm_msg*) incomingData;
289 incomingMsg = (asm_msg*) incomingData;
266
290
267 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
291 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
292 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
269
293
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
294 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
295 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
296
273 //***********
297 //***********
274 //***********
298 //***********
275 // BURST SBM2
299 // BURST SBM2
276 //***********
300 //***********
277 //***********
301 //***********
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
302 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
279 {
303 {
280 sid = getSID( incomingMsg->event );
304 sid = getSID( incomingMsg->event );
281 // 1) compress the matrix for Basic Parameters calculation
305 // 1) compress the matrix for Basic Parameters calculation
282 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
306 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
283 nbSMInASMSBM,
307 nbSMInASMSBM,
284 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
308 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
285 ASM_F1_INDICE_START, CHANNELF1);
309 ASM_F1_INDICE_START, CHANNELF1);
286 // 2) compute the BP1 set
310 // 2) compute the BP1 set
287 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
311 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
288 // 3) send the BP1 set
312 // 3) send the BP1 set
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
313 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
314 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
315 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
316 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
317 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
318 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
295 sid );
319 sid );
296 // 4) compute the BP2 set if needed
320 // 4) compute the BP2 set if needed
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
321 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
298 {
322 {
299 // 1) compute the BP2 set
323 // 1) compute the BP2 set
300 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
324 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
301 // 2) send the BP2 set
325 // 2) send the BP2 set
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
326 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
327 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
328 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
329 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
330 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
331 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
308 sid );
332 sid );
309 }
333 }
310 }
334 }
311
335
312 //*****
336 //*****
313 //*****
337 //*****
314 // NORM
338 // NORM
315 //*****
339 //*****
316 //*****
340 //*****
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
341 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
318 {
342 {
319 // 1) compress the matrix for Basic Parameters calculation
343 // 1) compress the matrix for Basic Parameters calculation
320 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
344 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
321 nbSMInASMNORM,
345 nbSMInASMNORM,
322 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
346 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
323 ASM_F1_INDICE_START, CHANNELF1 );
347 ASM_F1_INDICE_START, CHANNELF1 );
324 // 2) compute the BP1 set
348 // 2) compute the BP1 set
325 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
349 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
326 // 3) send the BP1 set
350 // 3) send the BP1 set
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
351 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
352 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
353 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
354 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
331 BP_send( (char *) &packet_norm_bp1, queue_id_send,
355 BP_send( (char *) &packet_norm_bp1, queue_id_send,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
356 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
333 SID_NORM_BP1_F1 );
357 SID_NORM_BP1_F1 );
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
358 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
335 {
359 {
336 // 1) compute the BP2 set
360 // 1) compute the BP2 set
337 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
361 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
338 // 2) send the BP2 set
362 // 2) send the BP2 set
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
363 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
364 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
365 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
366 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
343 BP_send( (char *) &packet_norm_bp2, queue_id_send,
367 BP_send( (char *) &packet_norm_bp2, queue_id_send,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
368 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
345 SID_NORM_BP2_F1 );
369 SID_NORM_BP2_F1 );
346 }
370 }
347 }
371 }
348
372
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
373 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
350 {
374 {
351 // 1) reorganize the ASM and divide
375 // 1) reorganize the ASM and divide
352 ASM_reorganize_and_divide( asm_f1_patched_norm,
376 ASM_reorganize_and_divide( asm_f1_patched_norm,
353 (float*) current_ring_node_to_send_asm_f1->buffer_address,
377 (float*) current_ring_node_to_send_asm_f1->buffer_address,
354 nbSMInASMNORM );
378 nbSMInASMNORM );
355 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
379 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
356 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
380 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
357 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
381 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
358
382
359 // 3) send the spectral matrix packets
383 // 3) send the spectral matrix packets
360 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
384 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
361
385
362 // change asm ring node
386 // change asm ring node
363 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
387 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
364 }
388 }
365
389
366 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
390 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
367
391
368 }
392 }
369 }
393 }
370
394
371 //**********
395 //**********
372 // FUNCTIONS
396 // FUNCTIONS
373
397
374 void reset_nb_sm_f1( unsigned char lfrMode )
398 void reset_nb_sm_f1( unsigned char lfrMode )
375 {
399 {
376 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
400 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
377 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
401 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
378 nb_sm_before_f1.norm_asm =
402 nb_sm_before_f1.norm_asm =
379 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
403 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
380 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
404 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
381 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
405 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
382 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
406 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
383 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
407 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
384
408
385 if (lfrMode == LFR_MODE_SBM2)
409 if (lfrMode == LFR_MODE_SBM2)
386 {
410 {
387 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
411 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
388 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
412 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
389 }
413 }
390 else if (lfrMode == LFR_MODE_BURST)
414 else if (lfrMode == LFR_MODE_BURST)
391 {
415 {
392 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
416 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
393 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
417 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
394 }
418 }
395 else
419 else
396 {
420 {
397 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
421 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
398 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
422 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
399 }
423 }
400 }
424 }
401
425
402 void init_k_coefficients_prc1( void )
426 void init_k_coefficients_prc1( void )
403 {
427 {
404 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
428 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
405
429
406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
430 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
407 }
431 }
@@ -1,332 +1,356
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf2_prc2.h"
34 #include "avf2_prc2.h"
11
35
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
36 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
13
37
14 //***
38 //***
15 // F2
39 // F2
16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
40 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
17
41
18 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
42 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
19 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
43 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
20
44
21 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
45 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
46 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
23
47
24 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
48 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
25
49
26 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
50 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
27
51
28 //************
52 //************
29 // RTEMS TASKS
53 // RTEMS TASKS
30
54
31 //***
55 //***
32 // F2
56 // F2
33 rtems_task avf2_task( rtems_task_argument argument )
57 rtems_task avf2_task( rtems_task_argument argument )
34 {
58 {
35 rtems_event_set event_out;
59 rtems_event_set event_out;
36 rtems_status_code status;
60 rtems_status_code status;
37 rtems_id queue_id_prc2;
61 rtems_id queue_id_prc2;
38 asm_msg msgForPRC;
62 asm_msg msgForPRC;
39 ring_node *nodeForAveraging;
63 ring_node *nodeForAveraging;
40 ring_node_asm *current_ring_node_asm_norm_f2;
64 ring_node_asm *current_ring_node_asm_norm_f2;
41
65
42 unsigned int nb_norm_bp1;
66 unsigned int nb_norm_bp1;
43 unsigned int nb_norm_bp2;
67 unsigned int nb_norm_bp2;
44 unsigned int nb_norm_asm;
68 unsigned int nb_norm_asm;
45
69
46 event_out = EVENT_SETS_NONE_PENDING;
70 event_out = EVENT_SETS_NONE_PENDING;
47 queue_id_prc2 = RTEMS_ID_NONE;
71 queue_id_prc2 = RTEMS_ID_NONE;
48 nb_norm_bp1 = 0;
72 nb_norm_bp1 = 0;
49 nb_norm_bp2 = 0;
73 nb_norm_bp2 = 0;
50 nb_norm_asm = 0;
74 nb_norm_asm = 0;
51
75
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
76 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
77 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
78 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55
79
56 BOOT_PRINTF("in AVF2 ***\n")
80 BOOT_PRINTF("in AVF2 ***\n")
57
81
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
82 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 if (status != RTEMS_SUCCESSFUL)
83 if (status != RTEMS_SUCCESSFUL)
60 {
84 {
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
85 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 }
86 }
63
87
64 while(1){
88 while(1){
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
89 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66
90
67 //****************************************
91 //****************************************
68 // initialize the mesage for the MATR task
92 // initialize the mesage for the MATR task
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
93 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 msgForPRC.burst_sbm = NULL;
94 msgForPRC.burst_sbm = NULL;
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
95 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
72 //
96 //
73 //****************************************
97 //****************************************
74
98
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
99 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
76
100
77 // compute the average and store it in the averaged_sm_f2 buffer
101 // compute the average and store it in the averaged_sm_f2 buffer
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
102 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 nodeForAveraging,
103 nodeForAveraging,
80 nb_norm_bp1,
104 nb_norm_bp1,
81 &msgForPRC );
105 &msgForPRC );
82
106
83 // update nb_average
107 // update nb_average
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
108 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
109 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
110 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87
111
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
112 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 {
113 {
90 nb_norm_bp1 = 0;
114 nb_norm_bp1 = 0;
91 // set another ring for the ASM storage
115 // set another ring for the ASM storage
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
116 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
117 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
118 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 {
119 {
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
120 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 }
121 }
98 }
122 }
99
123
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
124 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 {
125 {
102 nb_norm_bp2 = 0;
126 nb_norm_bp2 = 0;
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
127 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
128 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 {
129 {
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 }
131 }
108 }
132 }
109
133
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
134 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 {
135 {
112 nb_norm_asm = 0;
136 nb_norm_asm = 0;
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
137 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
138 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 {
139 {
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
140 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 }
141 }
118 }
142 }
119
143
120 //*************************
144 //*************************
121 // send the message to PRC2
145 // send the message to PRC2
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
146 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
123 {
147 {
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
148 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 }
149 }
126
150
127 if (status != RTEMS_SUCCESSFUL) {
151 if (status != RTEMS_SUCCESSFUL) {
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
152 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 }
153 }
130 }
154 }
131 }
155 }
132
156
133 rtems_task prc2_task( rtems_task_argument argument )
157 rtems_task prc2_task( rtems_task_argument argument )
134 {
158 {
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
159 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 size_t size; // size of the incoming TC packet
160 size_t size; // size of the incoming TC packet
137 asm_msg *incomingMsg;
161 asm_msg *incomingMsg;
138 //
162 //
139 rtems_status_code status;
163 rtems_status_code status;
140 rtems_id queue_id_send;
164 rtems_id queue_id_send;
141 rtems_id queue_id_q_p2;
165 rtems_id queue_id_q_p2;
142 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
166 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
143 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
167 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
144 ring_node *current_ring_node_to_send_asm_f2;
168 ring_node *current_ring_node_to_send_asm_f2;
145 float nbSMInASMNORM;
169 float nbSMInASMNORM;
146
170
147 unsigned long long int localTime;
171 unsigned long long int localTime;
148
172
149 size = 0;
173 size = 0;
150 queue_id_send = RTEMS_ID_NONE;
174 queue_id_send = RTEMS_ID_NONE;
151 queue_id_q_p2 = RTEMS_ID_NONE;
175 queue_id_q_p2 = RTEMS_ID_NONE;
152 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
176 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
153 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
177 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
154
178
155 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
179 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
156 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
180 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
157 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
181 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
158
182
159 //*************
183 //*************
160 // NORM headers
184 // NORM headers
161 BP_init_header( &packet_norm_bp1,
185 BP_init_header( &packet_norm_bp1,
162 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
186 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
163 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
187 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
164 BP_init_header( &packet_norm_bp2,
188 BP_init_header( &packet_norm_bp2,
165 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
189 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
166 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
190 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
167
191
168 status = get_message_queue_id_send( &queue_id_send );
192 status = get_message_queue_id_send( &queue_id_send );
169 if (status != RTEMS_SUCCESSFUL)
193 if (status != RTEMS_SUCCESSFUL)
170 {
194 {
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
195 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
172 }
196 }
173 status = get_message_queue_id_prc2( &queue_id_q_p2);
197 status = get_message_queue_id_prc2( &queue_id_q_p2);
174 if (status != RTEMS_SUCCESSFUL)
198 if (status != RTEMS_SUCCESSFUL)
175 {
199 {
176 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
200 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
177 }
201 }
178
202
179 BOOT_PRINTF("in PRC2 ***\n")
203 BOOT_PRINTF("in PRC2 ***\n")
180
204
181 while(1){
205 while(1){
182 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
206 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
183 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
207 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
184
208
185 incomingMsg = (asm_msg*) incomingData;
209 incomingMsg = (asm_msg*) incomingData;
186
210
187 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
211 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
188
212
189 localTime = getTimeAsUnsignedLongLongInt( );
213 localTime = getTimeAsUnsignedLongLongInt( );
190
214
191 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
215 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
192
216
193 //*****
217 //*****
194 //*****
218 //*****
195 // NORM
219 // NORM
196 //*****
220 //*****
197 //*****
221 //*****
198 // 1) compress the matrix for Basic Parameters calculation
222 // 1) compress the matrix for Basic Parameters calculation
199 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
223 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
200 nbSMInASMNORM,
224 nbSMInASMNORM,
201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
225 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 ASM_F2_INDICE_START, CHANNELF2 );
226 ASM_F2_INDICE_START, CHANNELF2 );
203 // BP1_F2
227 // BP1_F2
204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
228 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
205 {
229 {
206 // 1) compute the BP1 set
230 // 1) compute the BP1 set
207 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
231 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 // 2) send the BP1 set
232 // 2) send the BP1 set
209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
233 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
234 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
235 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
212 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
236 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
213 BP_send( (char *) &packet_norm_bp1, queue_id_send,
237 BP_send( (char *) &packet_norm_bp1, queue_id_send,
214 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
238 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
215 SID_NORM_BP1_F2 );
239 SID_NORM_BP1_F2 );
216 }
240 }
217 // BP2_F2
241 // BP2_F2
218 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
242 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
219 {
243 {
220 // 1) compute the BP2 set
244 // 1) compute the BP2 set
221 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
245 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
222 // 2) send the BP2 set
246 // 2) send the BP2 set
223 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
247 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
224 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
248 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
225 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
249 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
226 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
250 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
251 BP_send( (char *) &packet_norm_bp2, queue_id_send,
228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
252 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
229 SID_NORM_BP2_F2 );
253 SID_NORM_BP2_F2 );
230 }
254 }
231
255
232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
256 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
233 {
257 {
234 // 1) reorganize the ASM and divide
258 // 1) reorganize the ASM and divide
235 ASM_reorganize_and_divide( asm_f2_patched_norm,
259 ASM_reorganize_and_divide( asm_f2_patched_norm,
236 (float*) current_ring_node_to_send_asm_f2->buffer_address,
260 (float*) current_ring_node_to_send_asm_f2->buffer_address,
237 nb_sm_before_f2.norm_bp1 );
261 nb_sm_before_f2.norm_bp1 );
238 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
262 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
239 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
263 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
240 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
264 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
241
265
242 // 3) send the spectral matrix packets
266 // 3) send the spectral matrix packets
243 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
267 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
244
268
245 // change asm ring node
269 // change asm ring node
246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
270 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
247 }
271 }
248
272
249 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
273 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
250
274
251 }
275 }
252 }
276 }
253
277
254 //**********
278 //**********
255 // FUNCTIONS
279 // FUNCTIONS
256
280
257 void reset_nb_sm_f2( void )
281 void reset_nb_sm_f2( void )
258 {
282 {
259 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
283 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
260 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
284 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
261 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
285 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
262 }
286 }
263
287
264 void SM_average_f2( float *averaged_spec_mat_f2,
288 void SM_average_f2( float *averaged_spec_mat_f2,
265 ring_node *ring_node,
289 ring_node *ring_node,
266 unsigned int nbAverageNormF2,
290 unsigned int nbAverageNormF2,
267 asm_msg *msgForMATR )
291 asm_msg *msgForMATR )
268 {
292 {
269 float sum;
293 float sum;
270 unsigned int i;
294 unsigned int i;
271 unsigned char keepMatrix;
295 unsigned char keepMatrix;
272
296
273 // test acquisitionTime validity
297 // test acquisitionTime validity
274 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
298 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
275
299
276 for(i=0; i<TOTAL_SIZE_SM; i++)
300 for(i=0; i<TOTAL_SIZE_SM; i++)
277 {
301 {
278 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
302 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
279 if ( (nbAverageNormF2 == 0) ) // average initialization
303 if ( (nbAverageNormF2 == 0) ) // average initialization
280 {
304 {
281 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
305 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
282 {
306 {
283 averaged_spec_mat_f2[ i ] = sum;
307 averaged_spec_mat_f2[ i ] = sum;
284 }
308 }
285 else // drop the matrix and initialize the average
309 else // drop the matrix and initialize the average
286 {
310 {
287 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
311 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
288 }
312 }
289 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
313 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
290 msgForMATR->fineTimeNORM = ring_node->fineTime;
314 msgForMATR->fineTimeNORM = ring_node->fineTime;
291 }
315 }
292 else
316 else
293 {
317 {
294 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
318 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
295 {
319 {
296 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
320 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
297 }
321 }
298 else
322 else
299 {
323 {
300 // nothing to do, the matrix is not valid
324 // nothing to do, the matrix is not valid
301 }
325 }
302 }
326 }
303 }
327 }
304
328
305 if (keepMatrix == 1)
329 if (keepMatrix == 1)
306 {
330 {
307 if ( (nbAverageNormF2 == 0) )
331 if ( (nbAverageNormF2 == 0) )
308 {
332 {
309 msgForMATR->numberOfSMInASMNORM = 1;
333 msgForMATR->numberOfSMInASMNORM = 1;
310 }
334 }
311 else
335 else
312 {
336 {
313 msgForMATR->numberOfSMInASMNORM++;
337 msgForMATR->numberOfSMInASMNORM++;
314 }
338 }
315 }
339 }
316 else
340 else
317 {
341 {
318 if ( (nbAverageNormF2 == 0) )
342 if ( (nbAverageNormF2 == 0) )
319 {
343 {
320 msgForMATR->numberOfSMInASMNORM = 0;
344 msgForMATR->numberOfSMInASMNORM = 0;
321 }
345 }
322 else
346 else
323 {
347 {
324 // nothing to do
348 // nothing to do
325 }
349 }
326 }
350 }
327 }
351 }
328
352
329 void init_k_coefficients_prc2( void )
353 void init_k_coefficients_prc2( void )
330 {
354 {
331 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
355 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
332 }
356 }
@@ -1,840 +1,898
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "fsw_processing.h"
34 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
35 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
36 #include "fsw_init.h"
13
37
14 unsigned int nb_sm_f0 = 0;
38 unsigned int nb_sm_f0 = 0;
15 unsigned int nb_sm_f0_aux_f1= 0;
39 unsigned int nb_sm_f0_aux_f1= 0;
16 unsigned int nb_sm_f1 = 0;
40 unsigned int nb_sm_f1 = 0;
17 unsigned int nb_sm_f0_aux_f2= 0;
41 unsigned int nb_sm_f0_aux_f2= 0;
18
42
19 typedef enum restartState_t
43 typedef enum restartState_t
20 {
44 {
21 WAIT_FOR_F2,
45 WAIT_FOR_F2,
22 WAIT_FOR_F1,
46 WAIT_FOR_F1,
23 WAIT_FOR_F0
47 WAIT_FOR_F0
24 } restartState;
48 } restartState;
25
49
26 //************************
50 //************************
27 // spectral matrices rings
51 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
52 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
53 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
54 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
31 ring_node *current_ring_node_sm_f0 = NULL;
55 ring_node *current_ring_node_sm_f0 = NULL;
32 ring_node *current_ring_node_sm_f1 = NULL;
56 ring_node *current_ring_node_sm_f1 = NULL;
33 ring_node *current_ring_node_sm_f2 = NULL;
57 ring_node *current_ring_node_sm_f2 = NULL;
34 ring_node *ring_node_for_averaging_sm_f0= NULL;
58 ring_node *ring_node_for_averaging_sm_f0= NULL;
35 ring_node *ring_node_for_averaging_sm_f1= NULL;
59 ring_node *ring_node_for_averaging_sm_f1= NULL;
36 ring_node *ring_node_for_averaging_sm_f2= NULL;
60 ring_node *ring_node_for_averaging_sm_f2= NULL;
37
61
38 //
62 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
63 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
64 {
41 ring_node *node;
65 ring_node *node;
42
66
43 node = NULL;
67 node = NULL;
44 switch ( frequencyChannel ) {
68 switch ( frequencyChannel ) {
45 case CHANNELF0:
69 case CHANNELF0:
46 node = ring_node_for_averaging_sm_f0;
70 node = ring_node_for_averaging_sm_f0;
47 break;
71 break;
48 case CHANNELF1:
72 case CHANNELF1:
49 node = ring_node_for_averaging_sm_f1;
73 node = ring_node_for_averaging_sm_f1;
50 break;
74 break;
51 case CHANNELF2:
75 case CHANNELF2:
52 node = ring_node_for_averaging_sm_f2;
76 node = ring_node_for_averaging_sm_f2;
53 break;
77 break;
54 default:
78 default:
55 break;
79 break;
56 }
80 }
57
81
58 return node;
82 return node;
59 }
83 }
60
84
61 //***********************************************************
85 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
86 // Interrupt Service Routine for spectral matrices processing
63
87
64 void spectral_matrices_isr_f0( int statusReg )
88 void spectral_matrices_isr_f0( int statusReg )
65 {
89 {
66 unsigned char status;
90 unsigned char status;
67 rtems_status_code status_code;
91 rtems_status_code status_code;
68 ring_node *full_ring_node;
92 ring_node *full_ring_node;
69
93
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
94 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
71
95
72 switch(status)
96 switch(status)
73 {
97 {
74 case 0:
98 case 0:
75 break;
99 break;
76 case BIT_READY_0_1:
100 case BIT_READY_0_1:
77 // UNEXPECTED VALUE
101 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
102 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
103 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
104 break;
81 case BIT_READY_0:
105 case BIT_READY_0:
82 full_ring_node = current_ring_node_sm_f0->previous;
106 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
107 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
108 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
109 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
110 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
111 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
112 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
113 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
90 {
114 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
115 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
116 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
117 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
118 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
119 }
96 nb_sm_f0 = 0;
120 nb_sm_f0 = 0;
97 }
121 }
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
122 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
99 break;
123 break;
100 case BIT_READY_1:
124 case BIT_READY_1:
101 full_ring_node = current_ring_node_sm_f0->previous;
125 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
126 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
127 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
128 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
129 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
130 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
131 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
132 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
109 {
133 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
134 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
135 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
136 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
138 }
115 nb_sm_f0 = 0;
139 nb_sm_f0 = 0;
116 }
140 }
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
141 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
118 break;
142 break;
119 default:
143 default:
120 break;
144 break;
121 }
145 }
122 }
146 }
123
147
124 void spectral_matrices_isr_f1( int statusReg )
148 void spectral_matrices_isr_f1( int statusReg )
125 {
149 {
126 rtems_status_code status_code;
150 rtems_status_code status_code;
127 unsigned char status;
151 unsigned char status;
128 ring_node *full_ring_node;
152 ring_node *full_ring_node;
129
153
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
154 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
131
155
132 switch(status)
156 switch(status)
133 {
157 {
134 case 0:
158 case 0:
135 break;
159 break;
136 case BIT_READY_0_1:
160 case BIT_READY_0_1:
137 // UNEXPECTED VALUE
161 // UNEXPECTED VALUE
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
162 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
163 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
140 break;
164 break;
141 case BIT_READY_0:
165 case BIT_READY_0:
142 full_ring_node = current_ring_node_sm_f1->previous;
166 full_ring_node = current_ring_node_sm_f1->previous;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
167 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
168 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
169 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
170 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
147 // if there are enough ring nodes ready, wake up an AVFx task
171 // if there are enough ring nodes ready, wake up an AVFx task
148 nb_sm_f1 = nb_sm_f1 + 1;
172 nb_sm_f1 = nb_sm_f1 + 1;
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
173 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
150 {
174 {
151 ring_node_for_averaging_sm_f1 = full_ring_node;
175 ring_node_for_averaging_sm_f1 = full_ring_node;
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
176 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
153 {
177 {
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
178 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
155 }
179 }
156 nb_sm_f1 = 0;
180 nb_sm_f1 = 0;
157 }
181 }
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
182 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
159 break;
183 break;
160 case BIT_READY_1:
184 case BIT_READY_1:
161 full_ring_node = current_ring_node_sm_f1->previous;
185 full_ring_node = current_ring_node_sm_f1->previous;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
186 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
187 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
188 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
189 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
166 // if there are enough ring nodes ready, wake up an AVFx task
190 // if there are enough ring nodes ready, wake up an AVFx task
167 nb_sm_f1 = nb_sm_f1 + 1;
191 nb_sm_f1 = nb_sm_f1 + 1;
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
192 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
169 {
193 {
170 ring_node_for_averaging_sm_f1 = full_ring_node;
194 ring_node_for_averaging_sm_f1 = full_ring_node;
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
195 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
172 {
196 {
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
197 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
174 }
198 }
175 nb_sm_f1 = 0;
199 nb_sm_f1 = 0;
176 }
200 }
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
201 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
178 break;
202 break;
179 default:
203 default:
180 break;
204 break;
181 }
205 }
182 }
206 }
183
207
184 void spectral_matrices_isr_f2( int statusReg )
208 void spectral_matrices_isr_f2( int statusReg )
185 {
209 {
186 unsigned char status;
210 unsigned char status;
187 rtems_status_code status_code;
211 rtems_status_code status_code;
188
212
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
213 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
190
214
191 switch(status)
215 switch(status)
192 {
216 {
193 case 0:
217 case 0:
194 break;
218 break;
195 case BIT_READY_0_1:
219 case BIT_READY_0_1:
196 // UNEXPECTED VALUE
220 // UNEXPECTED VALUE
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
221 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
222 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
199 break;
223 break;
200 case BIT_READY_0:
224 case BIT_READY_0:
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
225 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
226 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
227 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
228 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
229 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
230 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
231 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
208 {
232 {
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
233 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
210 }
234 }
211 break;
235 break;
212 case BIT_READY_1:
236 case BIT_READY_1:
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
237 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
238 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
239 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
240 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
241 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
242 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
243 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
220 {
244 {
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
245 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
222 }
246 }
223 break;
247 break;
224 default:
248 default:
225 break;
249 break;
226 }
250 }
227 }
251 }
228
252
229 void spectral_matrix_isr_error_handler( int statusReg )
253 void spectral_matrix_isr_error_handler( int statusReg )
230 {
254 {
231 // STATUS REGISTER
255 // STATUS REGISTER
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
233 // 10 9 8
257 // 10 9 8
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
258 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
235 // 7 6 5 4 3 2 1 0
259 // 7 6 5 4 3 2 1 0
236 // [bad_component_err] not defined in the last version of the VHDL code
260 // [bad_component_err] not defined in the last version of the VHDL code
237
261
238 rtems_status_code status_code;
262 rtems_status_code status_code;
239
263
240 //***************************************************
264 //***************************************************
241 // the ASM status register is copied in the HK packet
265 // the ASM status register is copied in the HK packet
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
266 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
243
267
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
268 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
245 {
269 {
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
270 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
247 }
271 }
248
272
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
273 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
250
274
251 }
275 }
252
276
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
277 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
254 {
278 {
255 // STATUS REGISTER
279 // STATUS REGISTER
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
280 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
257 // 10 9 8
281 // 10 9 8
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
282 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
259 // 7 6 5 4 3 2 1 0
283 // 7 6 5 4 3 2 1 0
260
284
261 int statusReg;
285 int statusReg;
262
286
263 static restartState state = WAIT_FOR_F2;
287 static restartState state = WAIT_FOR_F2;
264
288
265 statusReg = spectral_matrix_regs->status;
289 statusReg = spectral_matrix_regs->status;
266
290
267 if (thisIsAnASMRestart == 0)
291 if (thisIsAnASMRestart == 0)
268 { // this is not a restart sequence, process incoming matrices normally
292 { // this is not a restart sequence, process incoming matrices normally
269 spectral_matrices_isr_f0( statusReg );
293 spectral_matrices_isr_f0( statusReg );
270
294
271 spectral_matrices_isr_f1( statusReg );
295 spectral_matrices_isr_f1( statusReg );
272
296
273 spectral_matrices_isr_f2( statusReg );
297 spectral_matrices_isr_f2( statusReg );
274 }
298 }
275 else
299 else
276 { // a restart sequence has to be launched
300 { // a restart sequence has to be launched
277 switch (state) {
301 switch (state) {
278 case WAIT_FOR_F2:
302 case WAIT_FOR_F2:
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
303 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
280 {
304 {
281 state = WAIT_FOR_F1;
305 state = WAIT_FOR_F1;
282 }
306 }
283 break;
307 break;
284 case WAIT_FOR_F1:
308 case WAIT_FOR_F1:
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
309 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
286 {
310 {
287 state = WAIT_FOR_F0;
311 state = WAIT_FOR_F0;
288 }
312 }
289 break;
313 break;
290 case WAIT_FOR_F0:
314 case WAIT_FOR_F0:
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
315 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
292 {
316 {
293 state = WAIT_FOR_F2;
317 state = WAIT_FOR_F2;
294 thisIsAnASMRestart = 0;
318 thisIsAnASMRestart = 0;
295 }
319 }
296 break;
320 break;
297 default:
321 default:
298 break;
322 break;
299 }
323 }
300 reset_sm_status();
324 reset_sm_status();
301 }
325 }
302
326
303 spectral_matrix_isr_error_handler( statusReg );
327 spectral_matrix_isr_error_handler( statusReg );
304
328
305 }
329 }
306
330
307 //******************
331 //******************
308 // Spectral Matrices
332 // Spectral Matrices
309
333
310 void reset_nb_sm( void )
334 void reset_nb_sm( void )
311 {
335 {
312 nb_sm_f0 = 0;
336 nb_sm_f0 = 0;
313 nb_sm_f0_aux_f1 = 0;
337 nb_sm_f0_aux_f1 = 0;
314 nb_sm_f0_aux_f2 = 0;
338 nb_sm_f0_aux_f2 = 0;
315
339
316 nb_sm_f1 = 0;
340 nb_sm_f1 = 0;
317 }
341 }
318
342
319 void SM_init_rings( void )
343 void SM_init_rings( void )
320 {
344 {
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
345 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
346 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
347 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
324
348
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
349 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
350 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
351 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
352 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
353 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
354 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
331 }
355 }
332
356
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
357 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
334 {
358 {
335 unsigned char i;
359 unsigned char i;
336
360
337 ring[ nbNodes - 1 ].next
361 ring[ nbNodes - 1 ].next
338 = (ring_node_asm*) &ring[ 0 ];
362 = (ring_node_asm*) &ring[ 0 ];
339
363
340 for(i=0; i<nbNodes-1; i++)
364 for(i=0; i<nbNodes-1; i++)
341 {
365 {
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
366 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
343 }
367 }
344 }
368 }
345
369
346 void SM_reset_current_ring_nodes( void )
370 void SM_reset_current_ring_nodes( void )
347 {
371 {
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
372 current_ring_node_sm_f0 = sm_ring_f0[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
373 current_ring_node_sm_f1 = sm_ring_f1[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
374 current_ring_node_sm_f2 = sm_ring_f2[0].next;
351
375
352 ring_node_for_averaging_sm_f0 = NULL;
376 ring_node_for_averaging_sm_f0 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
377 ring_node_for_averaging_sm_f1 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
378 ring_node_for_averaging_sm_f2 = NULL;
355 }
379 }
356
380
357 //*****************
381 //*****************
358 // Basic Parameters
382 // Basic Parameters
359
383
360 void BP_init_header( bp_packet *packet,
384 void BP_init_header( bp_packet *packet,
361 unsigned int apid, unsigned char sid,
385 unsigned int apid, unsigned char sid,
362 unsigned int packetLength, unsigned char blkNr )
386 unsigned int packetLength, unsigned char blkNr )
363 {
387 {
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
388 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
389 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
366 packet->reserved = INIT_CHAR;
390 packet->reserved = INIT_CHAR;
367 packet->userApplication = CCSDS_USER_APP;
391 packet->userApplication = CCSDS_USER_APP;
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
392 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
369 packet->packetID[1] = (unsigned char) (apid);
393 packet->packetID[1] = (unsigned char) (apid);
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
394 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
371 packet->packetSequenceControl[1] = INIT_CHAR;
395 packet->packetSequenceControl[1] = INIT_CHAR;
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
396 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
373 packet->packetLength[1] = (unsigned char) (packetLength);
397 packet->packetLength[1] = (unsigned char) (packetLength);
374 // DATA FIELD HEADER
398 // DATA FIELD HEADER
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
399 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
400 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
401 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
402 packet->destinationID = TM_DESTINATION_ID_GROUND;
379 packet->time[BYTE_0] = INIT_CHAR;
403 packet->time[BYTE_0] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
404 packet->time[BYTE_1] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
405 packet->time[BYTE_2] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
406 packet->time[BYTE_3] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
407 packet->time[BYTE_4] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
408 packet->time[BYTE_5] = INIT_CHAR;
385 // AUXILIARY DATA HEADER
409 // AUXILIARY DATA HEADER
386 packet->sid = sid;
410 packet->sid = sid;
387 packet->pa_bia_status_info = INIT_CHAR;
411 packet->pa_bia_status_info = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
412 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
413 packet->sy_lfr_common_parameters = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
414 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
415 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
416 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
417 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
418 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
419 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
420 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
421 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
398 }
422 }
399
423
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
424 void BP_init_header_with_spare( bp_packet_with_spare *packet,
401 unsigned int apid, unsigned char sid,
425 unsigned int apid, unsigned char sid,
402 unsigned int packetLength , unsigned char blkNr)
426 unsigned int packetLength , unsigned char blkNr)
403 {
427 {
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
428 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
429 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
406 packet->reserved = INIT_CHAR;
430 packet->reserved = INIT_CHAR;
407 packet->userApplication = CCSDS_USER_APP;
431 packet->userApplication = CCSDS_USER_APP;
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
432 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
409 packet->packetID[1] = (unsigned char) (apid);
433 packet->packetID[1] = (unsigned char) (apid);
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
434 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
411 packet->packetSequenceControl[1] = INIT_CHAR;
435 packet->packetSequenceControl[1] = INIT_CHAR;
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
436 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
413 packet->packetLength[1] = (unsigned char) (packetLength);
437 packet->packetLength[1] = (unsigned char) (packetLength);
414 // DATA FIELD HEADER
438 // DATA FIELD HEADER
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
439 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
440 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
441 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
442 packet->destinationID = TM_DESTINATION_ID_GROUND;
419 // AUXILIARY DATA HEADER
443 // AUXILIARY DATA HEADER
420 packet->sid = sid;
444 packet->sid = sid;
421 packet->pa_bia_status_info = INIT_CHAR;
445 packet->pa_bia_status_info = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
446 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
447 packet->sy_lfr_common_parameters = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
448 packet->time[BYTE_0] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
449 packet->time[BYTE_1] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
450 packet->time[BYTE_2] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
451 packet->time[BYTE_3] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
452 packet->time[BYTE_4] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
453 packet->time[BYTE_5] = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
454 packet->source_data_spare = INIT_CHAR;
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
455 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
456 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
433 }
457 }
434
458
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
459 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
436 {
460 {
437 rtems_status_code status;
461 rtems_status_code status;
438
462
439 // SEND PACKET
463 // SEND PACKET
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
464 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
441 if (status != RTEMS_SUCCESSFUL)
465 if (status != RTEMS_SUCCESSFUL)
442 {
466 {
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
467 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
444 }
468 }
445 }
469 }
446
470
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
471 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
448 {
472 {
449 /** This function is used to send the BP paquets when needed.
473 /** This function is used to send the BP paquets when needed.
450 *
474 *
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
475 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
452 *
476 *
453 * @return void
477 * @return void
454 *
478 *
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
479 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
456 * BURST paquets are sent everytime.
480 * BURST paquets are sent everytime.
457 *
481 *
458 */
482 */
459
483
460 rtems_status_code status;
484 rtems_status_code status;
461
485
462 // SEND PACKET
486 // SEND PACKET
463 // before lastValidTransitionDate, the data are drops even if they are ready
487 // before lastValidTransitionDate, the data are drops even if they are ready
464 // this guarantees that no SBM packets will be received before the requested enter mode time
488 // this guarantees that no SBM packets will be received before the requested enter mode time
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
489 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
466 {
490 {
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
491 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
468 if (status != RTEMS_SUCCESSFUL)
492 if (status != RTEMS_SUCCESSFUL)
469 {
493 {
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
494 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
471 }
495 }
472 }
496 }
473 }
497 }
474
498
475 //******************
499 //******************
476 // general functions
500 // general functions
477
501
478 void reset_sm_status( void )
502 void reset_sm_status( void )
479 {
503 {
480 // error
504 // error
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
505 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
506 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
507 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
508 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
485
509
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
510 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
487 }
511 }
488
512
489 void reset_spectral_matrix_regs( void )
513 void reset_spectral_matrix_regs( void )
490 {
514 {
491 /** This function resets the spectral matrices module registers.
515 /** This function resets the spectral matrices module registers.
492 *
516 *
493 * The registers affected by this function are located at the following offset addresses:
517 * The registers affected by this function are located at the following offset addresses:
494 *
518 *
495 * - 0x00 config
519 * - 0x00 config
496 * - 0x04 status
520 * - 0x04 status
497 * - 0x08 matrixF0_Address0
521 * - 0x08 matrixF0_Address0
498 * - 0x10 matrixFO_Address1
522 * - 0x10 matrixFO_Address1
499 * - 0x14 matrixF1_Address
523 * - 0x14 matrixF1_Address
500 * - 0x18 matrixF2_Address
524 * - 0x18 matrixF2_Address
501 *
525 *
502 */
526 */
503
527
504 set_sm_irq_onError( 0 );
528 set_sm_irq_onError( 0 );
505
529
506 set_sm_irq_onNewMatrix( 0 );
530 set_sm_irq_onNewMatrix( 0 );
507
531
508 reset_sm_status();
532 reset_sm_status();
509
533
510 // F1
534 // F1
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
535 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
536 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
513 // F2
537 // F2
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
538 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
539 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
516 // F3
540 // F3
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
541 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
542 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
519
543
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
544 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
521 }
545 }
522
546
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
547 void set_time( unsigned char *time, unsigned char * timeInBuffer )
524 {
548 {
525 time[BYTE_0] = timeInBuffer[BYTE_0];
549 time[BYTE_0] = timeInBuffer[BYTE_0];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
550 time[BYTE_1] = timeInBuffer[BYTE_1];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
551 time[BYTE_2] = timeInBuffer[BYTE_2];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
552 time[BYTE_3] = timeInBuffer[BYTE_3];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
553 time[BYTE_4] = timeInBuffer[BYTE_6];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
554 time[BYTE_5] = timeInBuffer[BYTE_7];
531 }
555 }
532
556
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
557 unsigned long long int get_acquisition_time( unsigned char *timePtr )
534 {
558 {
535 unsigned long long int acquisitionTimeAslong;
559 unsigned long long int acquisitionTimeAslong;
536 acquisitionTimeAslong = INIT_CHAR;
560 acquisitionTimeAslong = INIT_CHAR;
537 acquisitionTimeAslong =
561 acquisitionTimeAslong =
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
562 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
563 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
564 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
565 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
566 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
543 + ( (unsigned long long int) timePtr[BYTE_7] );
567 + ( (unsigned long long int) timePtr[BYTE_7] );
544 return acquisitionTimeAslong;
568 return acquisitionTimeAslong;
545 }
569 }
546
570
547 unsigned char getSID( rtems_event_set event )
571 unsigned char getSID( rtems_event_set event )
548 {
572 {
549 unsigned char sid;
573 unsigned char sid;
550
574
551 rtems_event_set eventSetBURST;
575 rtems_event_set eventSetBURST;
552 rtems_event_set eventSetSBM;
576 rtems_event_set eventSetSBM;
553
577
554 sid = 0;
578 sid = 0;
555
579
556 //******
580 //******
557 // BURST
581 // BURST
558 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
582 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
559 | RTEMS_EVENT_BURST_BP1_F1
583 | RTEMS_EVENT_BURST_BP1_F1
560 | RTEMS_EVENT_BURST_BP2_F0
584 | RTEMS_EVENT_BURST_BP2_F0
561 | RTEMS_EVENT_BURST_BP2_F1;
585 | RTEMS_EVENT_BURST_BP2_F1;
562
586
563 //****
587 //****
564 // SBM
588 // SBM
565 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
589 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
566 | RTEMS_EVENT_SBM_BP1_F1
590 | RTEMS_EVENT_SBM_BP1_F1
567 | RTEMS_EVENT_SBM_BP2_F0
591 | RTEMS_EVENT_SBM_BP2_F0
568 | RTEMS_EVENT_SBM_BP2_F1;
592 | RTEMS_EVENT_SBM_BP2_F1;
569
593
570 if (event & eventSetBURST)
594 if (event & eventSetBURST)
571 {
595 {
572 sid = SID_BURST_BP1_F0;
596 sid = SID_BURST_BP1_F0;
573 }
597 }
574 else if (event & eventSetSBM)
598 else if (event & eventSetSBM)
575 {
599 {
576 sid = SID_SBM1_BP1_F0;
600 sid = SID_SBM1_BP1_F0;
577 }
601 }
578 else
602 else
579 {
603 {
580 sid = 0;
604 sid = 0;
581 }
605 }
582
606
583 return sid;
607 return sid;
584 }
608 }
585
609
610 /**
611 * @brief extractReImVectors converts a given ASM component from interleaved to split representation
612 * @param inputASM
613 * @param outputASM
614 * @param asmComponent
615 */
586 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
616 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
587 {
617 {
588 unsigned int i;
618 unsigned int i;
589 float re;
619 float re;
590 float im;
620 float im;
591
621
592 for (i=0; i<NB_BINS_PER_SM; i++){
622 for (i=0; i<NB_BINS_PER_SM; i++){
593 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
623 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
594 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
624 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
595 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
625 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
596 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
626 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
597 }
627 }
598 }
628 }
599
629
630 /**
631 * @brief copyReVectors copies real part of a given ASM from inputASM to outputASM
632 * @param inputASM
633 * @param outputASM
634 * @param asmComponent
635 */
600 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
636 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
601 {
637 {
602 unsigned int i;
638 unsigned int i;
603 float re;
639 float re;
604
640
605 for (i=0; i<NB_BINS_PER_SM; i++){
641 for (i=0; i<NB_BINS_PER_SM; i++){
606 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
642 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
607 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
643 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
608 }
644 }
609 }
645 }
610
646
647 /**
648 * @brief ASM_patch, converts ASM from interleaved to split representation
649 * @param inputASM
650 * @param outputASM
651 * @note inputASM and outputASM must be different, in other words this function can't do in place convertion
652 * @see extractReImVectors
653 */
611 void ASM_patch( float *inputASM, float *outputASM )
654 void ASM_patch( float *inputASM, float *outputASM )
612 {
655 {
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
656 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
657 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
658 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
659 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
660 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
661 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
662 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
620 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
663 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
621 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
664 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
622 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
665 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
623
666
624 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
667 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
625 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
668 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
626 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
669 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
627 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
670 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
628 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
671 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
629 }
672 }
630
673
631 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
674 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
632 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
675 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
633 unsigned char ASMIndexStart,
676 unsigned char ASMIndexStart,
634 unsigned char channel )
677 unsigned char channel )
635 {
678 {
636 //*************
679 //*************
637 // input format
680 // input format
638 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
681 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
639 //**************
682 //**************
640 // output format
683 // output format
641 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
684 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
642 //************
685 //************
643 // compression
686 // compression
644 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
687 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
645 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
688 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
646
689
647 int frequencyBin;
690 int frequencyBin;
648 int asmComponent;
691 int asmComponent;
649 int offsetASM;
692 int offsetASM;
650 int offsetCompressed;
693 int offsetCompressed;
651 int offsetFBin;
694 int offsetFBin;
652 int fBinMask;
695 int fBinMask;
653 int k;
696 int k;
654
697
655 // BUILD DATA
698 // BUILD DATA
656 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
699 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
657 {
700 {
658 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
701 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
659 {
702 {
660 offsetCompressed = // NO TIME OFFSET
703 offsetCompressed = // NO TIME OFFSET
661 (frequencyBin * NB_VALUES_PER_SM)
704 (frequencyBin * NB_VALUES_PER_SM)
662 + asmComponent;
705 + asmComponent;
663 offsetASM = // NO TIME OFFSET
706 offsetASM = // NO TIME OFFSET
664 (asmComponent * NB_BINS_PER_SM)
707 (asmComponent * NB_BINS_PER_SM)
665 + ASMIndexStart
708 + ASMIndexStart
666 + (frequencyBin * nbBinsToAverage);
709 + (frequencyBin * nbBinsToAverage);
667 offsetFBin = ASMIndexStart
710 offsetFBin = ASMIndexStart
668 + (frequencyBin * nbBinsToAverage);
711 + (frequencyBin * nbBinsToAverage);
669 compressed_spec_mat[ offsetCompressed ] = 0;
712 compressed_spec_mat[ offsetCompressed ] = 0;
670 for ( k = 0; k < nbBinsToAverage; k++ )
713 for ( k = 0; k < nbBinsToAverage; k++ )
671 {
714 {
672 fBinMask = getFBinMask( offsetFBin + k, channel );
715 fBinMask = getFBinMask( offsetFBin + k, channel );
673 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
716 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
674 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
717 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
675 }
718 }
676 if (divider != 0)
719 if (divider != 0)
677 {
720 {
678 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
721 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
679 }
722 }
680 else
723 else
681 {
724 {
682 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
725 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
683 }
726 }
684 }
727 }
685 }
728 }
686
729
687 }
730 }
688
731
689 int getFBinMask( int index, unsigned char channel )
732 int getFBinMask( int index, unsigned char channel )
690 {
733 {
691 unsigned int indexInChar;
734 unsigned int indexInChar;
692 unsigned int indexInTheChar;
735 unsigned int indexInTheChar;
693 int fbin;
736 int fbin;
694 unsigned char *sy_lfr_fbins_fx_word1;
737 unsigned char *sy_lfr_fbins_fx_word1;
695
738
696 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
739 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
697
740
698 switch(channel)
741 switch(channel)
699 {
742 {
700 case CHANNELF0:
743 case CHANNELF0:
701 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
744 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
702 break;
745 break;
703 case CHANNELF1:
746 case CHANNELF1:
704 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
747 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
705 break;
748 break;
706 case CHANNELF2:
749 case CHANNELF2:
707 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
750 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
708 break;
751 break;
709 default:
752 default:
710 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
753 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
711 }
754 }
712
755
713 indexInChar = index >> SHIFT_3_BITS;
756 indexInChar = index >> SHIFT_3_BITS;
714 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
757 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
715
758
716 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
759 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
717
760
718 return fbin;
761 return fbin;
719 }
762 }
720
763
764 /**
765 * @brief isPolluted returns MATRIX_IS_POLLUTED if there is any overlap between t0:t1 and tbad0:tbad1 ranges
766 * @param t0 Start acquisition time
767 * @param t1 End of acquisition time
768 * @param tbad0 Start time of poluting signal
769 * @param tbad1 End time of poluting signal
770 * @return
771 */
721 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 )
772 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 )
722 {
773 {
723 unsigned char polluted;
774 unsigned char polluted;
724
775
725 polluted = MATRIX_IS_NOT_POLLUTED;
776 polluted = MATRIX_IS_NOT_POLLUTED;
726
777
727 if ( ((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
778 if ( ((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
728 || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
779 || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
729 || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
780 || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
730 || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
781 || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
731 {
782 {
732 polluted = MATRIX_IS_POLLUTED;
783 polluted = MATRIX_IS_POLLUTED;
733 }
784 }
734
785
735 return polluted;
786 return polluted;
736 }
787 }
737
788
789 /**
790 * @brief acquisitionTimeIsValid checks if the given acquisition time is poluted by PAS
791 * @param coarseTime Coarse acquisition time of the given SM
792 * @param fineTime Fine acquisition time of the given ASM
793 * @param channel Frequency channel to check, will impact SM time footprint
794 * @return MATRIX_IS_POLLUTED if there is any time overlap between SM and PAS poluting signal
795 */
738 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
796 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
739 {
797 {
740 u_int64_t t0;
798 u_int64_t t0;
741 u_int64_t t1;
799 u_int64_t t1;
742 u_int64_t tc;
800 u_int64_t tc;
743 u_int64_t tbad0;
801 u_int64_t tbad0;
744 u_int64_t tbad1;
802 u_int64_t tbad1;
745
803
746 u_int64_t modulusInFineTime;
804 u_int64_t modulusInFineTime;
747 u_int64_t offsetInFineTime;
805 u_int64_t offsetInFineTime;
748 u_int64_t shiftInFineTime;
806 u_int64_t shiftInFineTime;
749 u_int64_t tbadInFineTime;
807 u_int64_t tbadInFineTime;
750
808
751 u_int64_t timecodeReference;
809 u_int64_t timecodeReference;
752
810
753 unsigned char pasFilteringIsEnabled;
811 unsigned char pasFilteringIsEnabled;
754 unsigned char ret;
812 unsigned char ret;
755
813
756 // compute acquisition time from caoarseTime and fineTime
814 // compute acquisition time from caoarseTime and fineTime
757 t0 = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES ) + (u_int64_t) fineTime;
815 t0 = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES ) + (u_int64_t) fineTime;
758 t1 = t0;
816 t1 = t0;
759 tc = t0;
817 tc = t0;
760 tbad0 = t0;
818 tbad0 = t0;
761 tbad1 = t0;
819 tbad1 = t0;
762
820
763 switch(channel)
821 switch(channel)
764 {
822 {
765 case CHANNELF0:
823 case CHANNELF0:
766 t1 = t0 + ACQUISITION_DURATION_F0;
824 t1 = t0 + ACQUISITION_DURATION_F0;
767 tc = t0 + HALF_ACQUISITION_DURATION_F0;
825 tc = t0 + HALF_ACQUISITION_DURATION_F0;
768 break;
826 break;
769 case CHANNELF1:
827 case CHANNELF1:
770 t1 = t0 + ACQUISITION_DURATION_F1;
828 t1 = t0 + ACQUISITION_DURATION_F1;
771 tc = t0 + HALF_ACQUISITION_DURATION_F1;
829 tc = t0 + HALF_ACQUISITION_DURATION_F1;
772 break;
830 break;
773 case CHANNELF2:
831 case CHANNELF2:
774 t1 = t0 + ACQUISITION_DURATION_F2;
832 t1 = t0 + ACQUISITION_DURATION_F2;
775 tc = t0 + HALF_ACQUISITION_DURATION_F2;
833 tc = t0 + HALF_ACQUISITION_DURATION_F2;
776 break;
834 break;
777 default:
835 default:
778 break;
836 break;
779 }
837 }
780
838
781 // compute the acquitionTime range
839 // compute the acquitionTime range
782 modulusInFineTime = filterPar.modulus_in_finetime;
840 modulusInFineTime = filterPar.modulus_in_finetime;
783 offsetInFineTime = filterPar.offset_in_finetime;
841 offsetInFineTime = filterPar.offset_in_finetime;
784 shiftInFineTime = filterPar.shift_in_finetime;
842 shiftInFineTime = filterPar.shift_in_finetime;
785 tbadInFineTime = filterPar.tbad_in_finetime;
843 tbadInFineTime = filterPar.tbad_in_finetime;
786 timecodeReference = INIT_INT;
844 timecodeReference = INIT_INT;
787
845
788 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
846 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
789 ret = MATRIX_IS_NOT_POLLUTED;
847 ret = MATRIX_IS_NOT_POLLUTED;
790
848
791 if ( (tbadInFineTime == 0) || (pasFilteringIsEnabled == 0) )
849 if ( (tbadInFineTime == 0) || (pasFilteringIsEnabled == 0) )
792 {
850 {
793 ret = MATRIX_IS_NOT_POLLUTED;
851 ret = MATRIX_IS_NOT_POLLUTED;
794 }
852 }
795 else
853 else
796 {
854 {
797 // INTERSECTION TEST #1
855 // INTERSECTION TEST #1
798 timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime ;
856 timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime ;
799 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
857 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
800 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
858 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
801 ret = isPolluted( t0, t1, tbad0, tbad1 );
859 ret = isPolluted( t0, t1, tbad0, tbad1 );
802
860
803 // INTERSECTION TEST #2
861 // INTERSECTION TEST #2
804 if (ret == MATRIX_IS_NOT_POLLUTED)
862 if (ret == MATRIX_IS_NOT_POLLUTED)
805 {
863 {
806 timecodeReference = (tc - (tc % modulusInFineTime)) ;
864 timecodeReference = (tc - (tc % modulusInFineTime)) ;
807 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
865 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
808 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
866 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
809 ret = isPolluted( t0, t1, tbad0, tbad1 );
867 ret = isPolluted( t0, t1, tbad0, tbad1 );
810 }
868 }
811
869
812 // INTERSECTION TEST #3
870 // INTERSECTION TEST #3
813 if (ret == MATRIX_IS_NOT_POLLUTED)
871 if (ret == MATRIX_IS_NOT_POLLUTED)
814 {
872 {
815 timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime ;
873 timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime ;
816 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
874 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
817 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
875 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
818 ret = isPolluted( t0, t1, tbad0, tbad1 );
876 ret = isPolluted( t0, t1, tbad0, tbad1 );
819 }
877 }
820 }
878 }
821
879
822 return ret;
880 return ret;
823 }
881 }
824
882
825 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
883 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
826 {
884 {
827 unsigned char bin;
885 unsigned char bin;
828 unsigned char kcoeff;
886 unsigned char kcoeff;
829
887
830 for (bin=0; bin<nb_bins_norm; bin++)
888 for (bin=0; bin<nb_bins_norm; bin++)
831 {
889 {
832 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
890 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
833 {
891 {
834 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
892 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
835 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
893 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
836 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
894 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
837 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
895 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
838 }
896 }
839 }
897 }
840 }
898 }
@@ -1,481 +1,504
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Functions related to TeleCommand acceptance.
24 /** Functions related to TeleCommand acceptance.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * A group of functions to handle TeleCommands parsing.\n
29 * A group of functions to handle TeleCommands parsing.\n
7 *
30 *
8 */
31 */
9
32
10 #include "tc_acceptance.h"
33 #include "tc_acceptance.h"
11 #include <stdio.h>
34 #include <stdio.h>
12
35
13 unsigned int lookUpTableForCRC[CONST_256] = {0};
36 unsigned int lookUpTableForCRC[CONST_256] = {0};
14
37
15 //**********************
38 //**********************
16 // GENERAL USE FUNCTIONS
39 // GENERAL USE FUNCTIONS
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
40 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
18 {
41 {
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
42 /** This function generate the CRC for one byte and returns the value of the new syndrome.
20 *
43 *
21 * @param D is the current byte of data.
44 * @param D is the current byte of data.
22 * @param Chk is the current syndrom value.
45 * @param Chk is the current syndrom value.
23 *
46 *
24 * @return the value of the new syndrome on two bytes.
47 * @return the value of the new syndrome on two bytes.
25 *
48 *
26 */
49 */
27
50
28 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
51 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
29 }
52 }
30
53
31 void initLookUpTableForCRC( void )
54 void initLookUpTableForCRC( void )
32 {
55 {
33 /** This function is used to initiates the look-up table for fast CRC computation.
56 /** This function is used to initiates the look-up table for fast CRC computation.
34 *
57 *
35 * The global table lookUpTableForCRC[256] is initiated.
58 * The global table lookUpTableForCRC[256] is initiated.
36 *
59 *
37 */
60 */
38
61
39 unsigned int i;
62 unsigned int i;
40 unsigned int tmp;
63 unsigned int tmp;
41
64
42 for (i=0; i<CONST_256; i++)
65 for (i=0; i<CONST_256; i++)
43 {
66 {
44 tmp = 0;
67 tmp = 0;
45 if((i & BIT_0) != 0) {
68 if((i & BIT_0) != 0) {
46 tmp = tmp ^ CONST_CRC_0;
69 tmp = tmp ^ CONST_CRC_0;
47 }
70 }
48 if((i & BIT_1) != 0) {
71 if((i & BIT_1) != 0) {
49 tmp = tmp ^ CONST_CRC_1;
72 tmp = tmp ^ CONST_CRC_1;
50 }
73 }
51 if((i & BIT_2) != 0) {
74 if((i & BIT_2) != 0) {
52 tmp = tmp ^ CONST_CRC_2;
75 tmp = tmp ^ CONST_CRC_2;
53 }
76 }
54 if((i & BIT_3) != 0) {
77 if((i & BIT_3) != 0) {
55 tmp = tmp ^ CONST_CRC_3;
78 tmp = tmp ^ CONST_CRC_3;
56 }
79 }
57 if((i & BIT_4) != 0) {
80 if((i & BIT_4) != 0) {
58 tmp = tmp ^ CONST_CRC_4;
81 tmp = tmp ^ CONST_CRC_4;
59 }
82 }
60 if((i & BIT_5) != 0) {
83 if((i & BIT_5) != 0) {
61 tmp = tmp ^ CONST_CRC_5;
84 tmp = tmp ^ CONST_CRC_5;
62 }
85 }
63 if((i & BIT_6) != 0) {
86 if((i & BIT_6) != 0) {
64 tmp = tmp ^ CONST_CRC_6;
87 tmp = tmp ^ CONST_CRC_6;
65 }
88 }
66 if((i & BIT_7) != 0) {
89 if((i & BIT_7) != 0) {
67 tmp = tmp ^ CONST_CRC_7;
90 tmp = tmp ^ CONST_CRC_7;
68 }
91 }
69 lookUpTableForCRC[i] = tmp;
92 lookUpTableForCRC[i] = tmp;
70 }
93 }
71 }
94 }
72
95
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
96 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
74 {
97 {
75 /** This function calculates a two bytes Cyclic Redundancy Code.
98 /** This function calculates a two bytes Cyclic Redundancy Code.
76 *
99 *
77 * @param data points to a buffer containing the data on which to compute the CRC.
100 * @param data points to a buffer containing the data on which to compute the CRC.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
101 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
102 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
80 *
103 *
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
104 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
82 *
105 *
83 */
106 */
84
107
85 unsigned int Chk;
108 unsigned int Chk;
86 int j;
109 int j;
87 Chk = CRC_RESET; // reset the syndrom to all ones
110 Chk = CRC_RESET; // reset the syndrom to all ones
88 for (j=0; j<sizeOfData; j++) {
111 for (j=0; j<sizeOfData; j++) {
89 Chk = Crc_opt(data[j], Chk);
112 Chk = Crc_opt(data[j], Chk);
90 }
113 }
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
114 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
115 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
93 }
116 }
94
117
95 //*********************
118 //*********************
96 // ACCEPTANCE FUNCTIONS
119 // ACCEPTANCE FUNCTIONS
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
120 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
98 {
121 {
99 /** This function parses TeleCommands.
122 /** This function parses TeleCommands.
100 *
123 *
101 * @param TC points to the TeleCommand that will be parsed.
124 * @param TC points to the TeleCommand that will be parsed.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
125 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
103 *
126 *
104 * @return Status code of the parsing.
127 * @return Status code of the parsing.
105 *
128 *
106 * The parsing checks:
129 * The parsing checks:
107 * - process id
130 * - process id
108 * - category
131 * - category
109 * - length: a global check is performed and a per subtype check also
132 * - length: a global check is performed and a per subtype check also
110 * - type
133 * - type
111 * - subtype
134 * - subtype
112 * - crc
135 * - crc
113 *
136 *
114 */
137 */
115
138
116 int status;
139 int status;
117 int status_crc;
140 int status_crc;
118 unsigned char pid;
141 unsigned char pid;
119 unsigned char category;
142 unsigned char category;
120 unsigned int packetLength;
143 unsigned int packetLength;
121 unsigned char packetType;
144 unsigned char packetType;
122 unsigned char packetSubtype;
145 unsigned char packetSubtype;
123 unsigned char sid;
146 unsigned char sid;
124
147
125 status = CCSDS_TM_VALID;
148 status = CCSDS_TM_VALID;
126
149
127 // APID check *** APID on 2 bytes
150 // APID check *** APID on 2 bytes
128 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
151 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
129 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
152 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
130 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
153 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
131 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
154 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
132 packetType = TCPacket->serviceType;
155 packetType = TCPacket->serviceType;
133 packetSubtype = TCPacket->serviceSubType;
156 packetSubtype = TCPacket->serviceSubType;
134 sid = TCPacket->sourceID;
157 sid = TCPacket->sourceID;
135
158
136 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
159 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
137 {
160 {
138 status = ILLEGAL_APID;
161 status = ILLEGAL_APID;
139 }
162 }
140 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
163 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
141 {
164 {
142 if ( category != CCSDS_PACKET_CATEGORY )
165 if ( category != CCSDS_PACKET_CATEGORY )
143 {
166 {
144 status = ILLEGAL_APID;
167 status = ILLEGAL_APID;
145 }
168 }
146 }
169 }
147 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
170 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
148 {
171 {
149 if (packetLength != estimatedPacketLength ) {
172 if (packetLength != estimatedPacketLength ) {
150 status = WRONG_LEN_PKT;
173 status = WRONG_LEN_PKT;
151 }
174 }
152 }
175 }
153 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
176 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
154 {
177 {
155 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
178 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
156 status = WRONG_LEN_PKT;
179 status = WRONG_LEN_PKT;
157 }
180 }
158 }
181 }
159 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
182 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
160 {
183 {
161 status = tc_check_type( packetType );
184 status = tc_check_type( packetType );
162 }
185 }
163 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
186 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
164 {
187 {
165 status = tc_check_type_subtype( packetType, packetSubtype );
188 status = tc_check_type_subtype( packetType, packetSubtype );
166 }
189 }
167 if (status == CCSDS_TM_VALID) // CHECK THE SID
190 if (status == CCSDS_TM_VALID) // CHECK THE SID
168 {
191 {
169 status = tc_check_sid( sid );
192 status = tc_check_sid( sid );
170 }
193 }
171 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
194 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
172 {
195 {
173 status = tc_check_length( packetSubtype, packetLength );
196 status = tc_check_length( packetSubtype, packetLength );
174 }
197 }
175 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
198 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
176 if (status == CCSDS_TM_VALID ) // CHECK CRC
199 if (status == CCSDS_TM_VALID ) // CHECK CRC
177 {
200 {
178 status = status_crc;
201 status = status_crc;
179 }
202 }
180
203
181 return status;
204 return status;
182 }
205 }
183
206
184 int tc_check_type( unsigned char packetType )
207 int tc_check_type( unsigned char packetType )
185 {
208 {
186 /** This function checks that the type of a TeleCommand is valid.
209 /** This function checks that the type of a TeleCommand is valid.
187 *
210 *
188 * @param packetType is the type to check.
211 * @param packetType is the type to check.
189 *
212 *
190 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
213 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
191 *
214 *
192 */
215 */
193
216
194 int status;
217 int status;
195
218
196 status = ILL_TYPE;
219 status = ILL_TYPE;
197
220
198 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
221 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
199 {
222 {
200 status = CCSDS_TM_VALID;
223 status = CCSDS_TM_VALID;
201 }
224 }
202 else
225 else
203 {
226 {
204 status = ILL_TYPE;
227 status = ILL_TYPE;
205 }
228 }
206
229
207 return status;
230 return status;
208 }
231 }
209
232
210 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
233 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
211 {
234 {
212 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
235 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
213 *
236 *
214 * @param packetType is the type of the TC.
237 * @param packetType is the type of the TC.
215 * @param packetSubType is the subtype to check.
238 * @param packetSubType is the subtype to check.
216 *
239 *
217 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
240 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
218 *
241 *
219 */
242 */
220
243
221 int status;
244 int status;
222
245
223 switch(packetType)
246 switch(packetType)
224 {
247 {
225 case TC_TYPE_GEN:
248 case TC_TYPE_GEN:
226 if ( (packetSubType == TC_SUBTYPE_RESET)
249 if ( (packetSubType == TC_SUBTYPE_RESET)
227 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
250 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
228 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
251 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
229 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
252 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
230 || (packetSubType == TC_SUBTYPE_DUMP)
253 || (packetSubType == TC_SUBTYPE_DUMP)
231 || (packetSubType == TC_SUBTYPE_ENTER)
254 || (packetSubType == TC_SUBTYPE_ENTER)
232 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
255 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
233 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
256 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
234 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
257 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
235 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
258 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
236 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
259 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
237 {
260 {
238 status = CCSDS_TM_VALID;
261 status = CCSDS_TM_VALID;
239 }
262 }
240 else
263 else
241 {
264 {
242 status = ILL_SUBTYPE;
265 status = ILL_SUBTYPE;
243 }
266 }
244 break;
267 break;
245
268
246 case TC_TYPE_TIME:
269 case TC_TYPE_TIME:
247 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
270 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
248 {
271 {
249 status = CCSDS_TM_VALID;
272 status = CCSDS_TM_VALID;
250 }
273 }
251 else
274 else
252 {
275 {
253 status = ILL_SUBTYPE;
276 status = ILL_SUBTYPE;
254 }
277 }
255 break;
278 break;
256
279
257 default:
280 default:
258 status = ILL_SUBTYPE;
281 status = ILL_SUBTYPE;
259 break;
282 break;
260 }
283 }
261
284
262 return status;
285 return status;
263 }
286 }
264
287
265 int tc_check_sid( unsigned char sid )
288 int tc_check_sid( unsigned char sid )
266 {
289 {
267 /** This function checks that the sid of a TeleCommand is valid.
290 /** This function checks that the sid of a TeleCommand is valid.
268 *
291 *
269 * @param sid is the sid to check.
292 * @param sid is the sid to check.
270 *
293 *
271 * @return Status code CCSDS_TM_VALID or CORRUPTED.
294 * @return Status code CCSDS_TM_VALID or CORRUPTED.
272 *
295 *
273 */
296 */
274
297
275 int status;
298 int status;
276
299
277 status = WRONG_SRC_ID;
300 status = WRONG_SRC_ID;
278
301
279 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
302 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
280 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
303 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
281 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
304 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
282 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
305 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
283 || (sid == SID_TC_RPW_INTERNAL))
306 || (sid == SID_TC_RPW_INTERNAL))
284 {
307 {
285 status = CCSDS_TM_VALID;
308 status = CCSDS_TM_VALID;
286 }
309 }
287 else
310 else
288 {
311 {
289 status = WRONG_SRC_ID;
312 status = WRONG_SRC_ID;
290 }
313 }
291
314
292 return status;
315 return status;
293 }
316 }
294
317
295 int tc_check_length( unsigned char packetSubType, unsigned int length )
318 int tc_check_length( unsigned char packetSubType, unsigned int length )
296 {
319 {
297 /** This function checks that the subtype and the length are compliant.
320 /** This function checks that the subtype and the length are compliant.
298 *
321 *
299 * @param packetSubType is the subtype to check.
322 * @param packetSubType is the subtype to check.
300 * @param length is the length to check.
323 * @param length is the length to check.
301 *
324 *
302 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
325 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
303 *
326 *
304 */
327 */
305
328
306 int status;
329 int status;
307
330
308 status = LFR_SUCCESSFUL;
331 status = LFR_SUCCESSFUL;
309
332
310 switch(packetSubType)
333 switch(packetSubType)
311 {
334 {
312 case TC_SUBTYPE_RESET:
335 case TC_SUBTYPE_RESET:
313 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
336 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
314 status = WRONG_LEN_PKT;
337 status = WRONG_LEN_PKT;
315 }
338 }
316 else {
339 else {
317 status = CCSDS_TM_VALID;
340 status = CCSDS_TM_VALID;
318 }
341 }
319 break;
342 break;
320 case TC_SUBTYPE_LOAD_COMM:
343 case TC_SUBTYPE_LOAD_COMM:
321 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
344 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
322 status = WRONG_LEN_PKT;
345 status = WRONG_LEN_PKT;
323 }
346 }
324 else {
347 else {
325 status = CCSDS_TM_VALID;
348 status = CCSDS_TM_VALID;
326 }
349 }
327 break;
350 break;
328 case TC_SUBTYPE_LOAD_NORM:
351 case TC_SUBTYPE_LOAD_NORM:
329 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
352 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
330 status = WRONG_LEN_PKT;
353 status = WRONG_LEN_PKT;
331 }
354 }
332 else {
355 else {
333 status = CCSDS_TM_VALID;
356 status = CCSDS_TM_VALID;
334 }
357 }
335 break;
358 break;
336 case TC_SUBTYPE_LOAD_BURST:
359 case TC_SUBTYPE_LOAD_BURST:
337 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
360 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
338 status = WRONG_LEN_PKT;
361 status = WRONG_LEN_PKT;
339 }
362 }
340 else {
363 else {
341 status = CCSDS_TM_VALID;
364 status = CCSDS_TM_VALID;
342 }
365 }
343 break;
366 break;
344 case TC_SUBTYPE_LOAD_SBM1:
367 case TC_SUBTYPE_LOAD_SBM1:
345 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
368 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
346 status = WRONG_LEN_PKT;
369 status = WRONG_LEN_PKT;
347 }
370 }
348 else {
371 else {
349 status = CCSDS_TM_VALID;
372 status = CCSDS_TM_VALID;
350 }
373 }
351 break;
374 break;
352 case TC_SUBTYPE_LOAD_SBM2:
375 case TC_SUBTYPE_LOAD_SBM2:
353 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
376 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
354 status = WRONG_LEN_PKT;
377 status = WRONG_LEN_PKT;
355 }
378 }
356 else {
379 else {
357 status = CCSDS_TM_VALID;
380 status = CCSDS_TM_VALID;
358 }
381 }
359 break;
382 break;
360 case TC_SUBTYPE_DUMP:
383 case TC_SUBTYPE_DUMP:
361 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
384 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
362 status = WRONG_LEN_PKT;
385 status = WRONG_LEN_PKT;
363 }
386 }
364 else {
387 else {
365 status = CCSDS_TM_VALID;
388 status = CCSDS_TM_VALID;
366 }
389 }
367 break;
390 break;
368 case TC_SUBTYPE_ENTER:
391 case TC_SUBTYPE_ENTER:
369 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
392 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
370 status = WRONG_LEN_PKT;
393 status = WRONG_LEN_PKT;
371 }
394 }
372 else {
395 else {
373 status = CCSDS_TM_VALID;
396 status = CCSDS_TM_VALID;
374 }
397 }
375 break;
398 break;
376 case TC_SUBTYPE_UPDT_INFO:
399 case TC_SUBTYPE_UPDT_INFO:
377 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
400 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
378 status = WRONG_LEN_PKT;
401 status = WRONG_LEN_PKT;
379 }
402 }
380 else {
403 else {
381 status = CCSDS_TM_VALID;
404 status = CCSDS_TM_VALID;
382 }
405 }
383 break;
406 break;
384 case TC_SUBTYPE_EN_CAL:
407 case TC_SUBTYPE_EN_CAL:
385 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
408 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
386 status = WRONG_LEN_PKT;
409 status = WRONG_LEN_PKT;
387 }
410 }
388 else {
411 else {
389 status = CCSDS_TM_VALID;
412 status = CCSDS_TM_VALID;
390 }
413 }
391 break;
414 break;
392 case TC_SUBTYPE_DIS_CAL:
415 case TC_SUBTYPE_DIS_CAL:
393 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
416 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
394 status = WRONG_LEN_PKT;
417 status = WRONG_LEN_PKT;
395 }
418 }
396 else {
419 else {
397 status = CCSDS_TM_VALID;
420 status = CCSDS_TM_VALID;
398 }
421 }
399 break;
422 break;
400 case TC_SUBTYPE_LOAD_K:
423 case TC_SUBTYPE_LOAD_K:
401 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
424 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
402 status = WRONG_LEN_PKT;
425 status = WRONG_LEN_PKT;
403 }
426 }
404 else {
427 else {
405 status = CCSDS_TM_VALID;
428 status = CCSDS_TM_VALID;
406 }
429 }
407 break;
430 break;
408 case TC_SUBTYPE_DUMP_K:
431 case TC_SUBTYPE_DUMP_K:
409 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
432 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
410 status = WRONG_LEN_PKT;
433 status = WRONG_LEN_PKT;
411 }
434 }
412 else {
435 else {
413 status = CCSDS_TM_VALID;
436 status = CCSDS_TM_VALID;
414 }
437 }
415 break;
438 break;
416 case TC_SUBTYPE_LOAD_FBINS:
439 case TC_SUBTYPE_LOAD_FBINS:
417 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
440 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
418 status = WRONG_LEN_PKT;
441 status = WRONG_LEN_PKT;
419 }
442 }
420 else {
443 else {
421 status = CCSDS_TM_VALID;
444 status = CCSDS_TM_VALID;
422 }
445 }
423 break;
446 break;
424 case TC_SUBTYPE_LOAD_FILTER_PAR:
447 case TC_SUBTYPE_LOAD_FILTER_PAR:
425 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
448 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
426 status = WRONG_LEN_PKT;
449 status = WRONG_LEN_PKT;
427 }
450 }
428 else {
451 else {
429 status = CCSDS_TM_VALID;
452 status = CCSDS_TM_VALID;
430 }
453 }
431 break;
454 break;
432 case TC_SUBTYPE_UPDT_TIME:
455 case TC_SUBTYPE_UPDT_TIME:
433 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
456 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
434 status = WRONG_LEN_PKT;
457 status = WRONG_LEN_PKT;
435 }
458 }
436 else {
459 else {
437 status = CCSDS_TM_VALID;
460 status = CCSDS_TM_VALID;
438 }
461 }
439 break;
462 break;
440 default: // if the subtype is not a legal value, return ILL_SUBTYPE
463 default: // if the subtype is not a legal value, return ILL_SUBTYPE
441 status = ILL_SUBTYPE;
464 status = ILL_SUBTYPE;
442 break ;
465 break ;
443 }
466 }
444
467
445 return status;
468 return status;
446 }
469 }
447
470
448 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
471 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
449 {
472 {
450 /** This function checks the CRC validity of the corresponding TeleCommand packet.
473 /** This function checks the CRC validity of the corresponding TeleCommand packet.
451 *
474 *
452 * @param TCPacket points to the TeleCommand packet to check.
475 * @param TCPacket points to the TeleCommand packet to check.
453 * @param length is the length of the TC packet.
476 * @param length is the length of the TC packet.
454 *
477 *
455 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
478 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
456 *
479 *
457 */
480 */
458
481
459 int status;
482 int status;
460 unsigned char * CCSDSContent;
483 unsigned char * CCSDSContent;
461
484
462 status = INCOR_CHECKSUM;
485 status = INCOR_CHECKSUM;
463
486
464 CCSDSContent = (unsigned char*) TCPacket->packetID;
487 CCSDSContent = (unsigned char*) TCPacket->packetID;
465 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
488 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
466
489
467 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
490 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
468 status = INCOR_CHECKSUM;
491 status = INCOR_CHECKSUM;
469 }
492 }
470 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
493 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
471 status = INCOR_CHECKSUM;
494 status = INCOR_CHECKSUM;
472 }
495 }
473 else {
496 else {
474 status = CCSDS_TM_VALID;
497 status = CCSDS_TM_VALID;
475 }
498 }
476
499
477 return status;
500 return status;
478 }
501 }
479
502
480
503
481
504
@@ -1,1673 +1,1696
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Functions and tasks related to TeleCommand handling.
24 /** Functions and tasks related to TeleCommand handling.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * A group of functions to handle TeleCommands:\n
29 * A group of functions to handle TeleCommands:\n
7 * action launching\n
30 * action launching\n
8 * TC parsing\n
31 * TC parsing\n
9 * ...
32 * ...
10 *
33 *
11 */
34 */
12
35
13 #include "tc_handler.h"
36 #include "tc_handler.h"
14 #include "math.h"
37 #include "math.h"
15
38
16 //***********
39 //***********
17 // RTEMS TASK
40 // RTEMS TASK
18
41
19 rtems_task actn_task( rtems_task_argument unused )
42 rtems_task actn_task( rtems_task_argument unused )
20 {
43 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
44 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
45 *
23 * @param unused is the starting argument of the RTEMS task
46 * @param unused is the starting argument of the RTEMS task
24 *
47 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
48 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
49 * on the incoming TeleCommand.
27 *
50 *
28 */
51 */
29
52
30 int result;
53 int result;
31 rtems_status_code status; // RTEMS status code
54 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
55 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
56 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
57 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
58 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
59 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
60 rtems_id queue_snd_id;
38
61
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
62 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
63 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
64 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
65 queue_snd_id = RTEMS_ID_NONE;
43
66
44 status = get_message_queue_id_recv( &queue_rcv_id );
67 status = get_message_queue_id_recv( &queue_rcv_id );
45 if (status != RTEMS_SUCCESSFUL)
68 if (status != RTEMS_SUCCESSFUL)
46 {
69 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
70 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 }
71 }
49
72
50 status = get_message_queue_id_send( &queue_snd_id );
73 status = get_message_queue_id_send( &queue_snd_id );
51 if (status != RTEMS_SUCCESSFUL)
74 if (status != RTEMS_SUCCESSFUL)
52 {
75 {
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
76 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 }
77 }
55
78
56 result = LFR_SUCCESSFUL;
79 result = LFR_SUCCESSFUL;
57 subtype = 0; // subtype of the current TC packet
80 subtype = 0; // subtype of the current TC packet
58
81
59 BOOT_PRINTF("in ACTN *** \n");
82 BOOT_PRINTF("in ACTN *** \n");
60
83
61 while(1)
84 while(1)
62 {
85 {
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
86 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
87 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 getTime( time ); // set time to the current time
88 getTime( time ); // set time to the current time
66 if (status!=RTEMS_SUCCESSFUL)
89 if (status!=RTEMS_SUCCESSFUL)
67 {
90 {
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
91 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 }
92 }
70 else
93 else
71 {
94 {
72 subtype = TC.serviceSubType;
95 subtype = TC.serviceSubType;
73 switch(subtype)
96 switch(subtype)
74 {
97 {
75 case TC_SUBTYPE_RESET:
98 case TC_SUBTYPE_RESET:
76 result = action_reset( &TC, queue_snd_id, time );
99 result = action_reset( &TC, queue_snd_id, time );
77 close_action( &TC, result, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
78 break;
101 break;
79 case TC_SUBTYPE_LOAD_COMM:
102 case TC_SUBTYPE_LOAD_COMM:
80 result = action_load_common_par( &TC );
103 result = action_load_common_par( &TC );
81 close_action( &TC, result, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
82 break;
105 break;
83 case TC_SUBTYPE_LOAD_NORM:
106 case TC_SUBTYPE_LOAD_NORM:
84 result = action_load_normal_par( &TC, queue_snd_id, time );
107 result = action_load_normal_par( &TC, queue_snd_id, time );
85 close_action( &TC, result, queue_snd_id );
108 close_action( &TC, result, queue_snd_id );
86 break;
109 break;
87 case TC_SUBTYPE_LOAD_BURST:
110 case TC_SUBTYPE_LOAD_BURST:
88 result = action_load_burst_par( &TC, queue_snd_id, time );
111 result = action_load_burst_par( &TC, queue_snd_id, time );
89 close_action( &TC, result, queue_snd_id );
112 close_action( &TC, result, queue_snd_id );
90 break;
113 break;
91 case TC_SUBTYPE_LOAD_SBM1:
114 case TC_SUBTYPE_LOAD_SBM1:
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
115 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 close_action( &TC, result, queue_snd_id );
116 close_action( &TC, result, queue_snd_id );
94 break;
117 break;
95 case TC_SUBTYPE_LOAD_SBM2:
118 case TC_SUBTYPE_LOAD_SBM2:
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
119 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 close_action( &TC, result, queue_snd_id );
120 close_action( &TC, result, queue_snd_id );
98 break;
121 break;
99 case TC_SUBTYPE_DUMP:
122 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( &TC, queue_snd_id );
123 result = action_dump_par( &TC, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
124 close_action( &TC, result, queue_snd_id );
102 break;
125 break;
103 case TC_SUBTYPE_ENTER:
126 case TC_SUBTYPE_ENTER:
104 result = action_enter_mode( &TC, queue_snd_id );
127 result = action_enter_mode( &TC, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
128 close_action( &TC, result, queue_snd_id );
106 break;
129 break;
107 case TC_SUBTYPE_UPDT_INFO:
130 case TC_SUBTYPE_UPDT_INFO:
108 result = action_update_info( &TC, queue_snd_id );
131 result = action_update_info( &TC, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
132 close_action( &TC, result, queue_snd_id );
110 break;
133 break;
111 case TC_SUBTYPE_EN_CAL:
134 case TC_SUBTYPE_EN_CAL:
112 result = action_enable_calibration( &TC, queue_snd_id, time );
135 result = action_enable_calibration( &TC, queue_snd_id, time );
113 close_action( &TC, result, queue_snd_id );
136 close_action( &TC, result, queue_snd_id );
114 break;
137 break;
115 case TC_SUBTYPE_DIS_CAL:
138 case TC_SUBTYPE_DIS_CAL:
116 result = action_disable_calibration( &TC, queue_snd_id, time );
139 result = action_disable_calibration( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
140 close_action( &TC, result, queue_snd_id );
118 break;
141 break;
119 case TC_SUBTYPE_LOAD_K:
142 case TC_SUBTYPE_LOAD_K:
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
143 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
144 close_action( &TC, result, queue_snd_id );
122 break;
145 break;
123 case TC_SUBTYPE_DUMP_K:
146 case TC_SUBTYPE_DUMP_K:
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
147 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
148 close_action( &TC, result, queue_snd_id );
126 break;
149 break;
127 case TC_SUBTYPE_LOAD_FBINS:
150 case TC_SUBTYPE_LOAD_FBINS:
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
151 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 close_action( &TC, result, queue_snd_id );
152 close_action( &TC, result, queue_snd_id );
130 break;
153 break;
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
154 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 result = action_load_filter_par( &TC, queue_snd_id, time );
155 result = action_load_filter_par( &TC, queue_snd_id, time );
133 close_action( &TC, result, queue_snd_id );
156 close_action( &TC, result, queue_snd_id );
134 break;
157 break;
135 case TC_SUBTYPE_UPDT_TIME:
158 case TC_SUBTYPE_UPDT_TIME:
136 result = action_update_time( &TC );
159 result = action_update_time( &TC );
137 close_action( &TC, result, queue_snd_id );
160 close_action( &TC, result, queue_snd_id );
138 break;
161 break;
139 default:
162 default:
140 break;
163 break;
141 }
164 }
142 }
165 }
143 }
166 }
144 }
167 }
145
168
146 //***********
169 //***********
147 // TC ACTIONS
170 // TC ACTIONS
148
171
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
172 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 {
173 {
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
174 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 *
175 *
153 * @param TC points to the TeleCommand packet that is being processed
176 * @param TC points to the TeleCommand packet that is being processed
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
177 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 *
178 *
156 */
179 */
157
180
158 PRINTF("this is the end!!!\n");
181 PRINTF("this is the end!!!\n");
159 exit(0);
182 exit(0);
160
183
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
184 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162
185
163 return LFR_DEFAULT;
186 return LFR_DEFAULT;
164 }
187 }
165
188
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
189 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 {
190 {
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
191 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 *
192 *
170 * @param TC points to the TeleCommand packet that is being processed
193 * @param TC points to the TeleCommand packet that is being processed
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
194 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 *
195 *
173 */
196 */
174
197
175 rtems_status_code status;
198 rtems_status_code status;
176 unsigned char requestedMode;
199 unsigned char requestedMode;
177 unsigned int transitionCoarseTime;
200 unsigned int transitionCoarseTime;
178 unsigned char * bytePosPtr;
201 unsigned char * bytePosPtr;
179
202
180 bytePosPtr = (unsigned char *) &TC->packetID;
203 bytePosPtr = (unsigned char *) &TC->packetID;
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
204 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
205 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
206 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
184 status = check_mode_value( requestedMode );
207 status = check_mode_value( requestedMode );
185
208
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
209 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
187 {
210 {
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
211 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
189 }
212 }
190
213
191 else // the mode value is valid, check the transition
214 else // the mode value is valid, check the transition
192 {
215 {
193 status = check_mode_transition(requestedMode);
216 status = check_mode_transition(requestedMode);
194 if (status != LFR_SUCCESSFUL)
217 if (status != LFR_SUCCESSFUL)
195 {
218 {
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
219 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
220 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
198 }
221 }
199 }
222 }
200
223
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
224 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
202 {
225 {
203 status = check_transition_date( transitionCoarseTime );
226 status = check_transition_date( transitionCoarseTime );
204 if (status != LFR_SUCCESSFUL)
227 if (status != LFR_SUCCESSFUL)
205 {
228 {
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
229 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
230 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
208 }
231 }
209 }
232 }
210
233
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
234 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
212 {
235 {
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
236 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
214
237
215 switch(requestedMode)
238 switch(requestedMode)
216 {
239 {
217 case LFR_MODE_STANDBY:
240 case LFR_MODE_STANDBY:
218 status = enter_mode_standby();
241 status = enter_mode_standby();
219 break;
242 break;
220 case LFR_MODE_NORMAL:
243 case LFR_MODE_NORMAL:
221 status = enter_mode_normal( transitionCoarseTime );
244 status = enter_mode_normal( transitionCoarseTime );
222 break;
245 break;
223 case LFR_MODE_BURST:
246 case LFR_MODE_BURST:
224 status = enter_mode_burst( transitionCoarseTime );
247 status = enter_mode_burst( transitionCoarseTime );
225 break;
248 break;
226 case LFR_MODE_SBM1:
249 case LFR_MODE_SBM1:
227 status = enter_mode_sbm1( transitionCoarseTime );
250 status = enter_mode_sbm1( transitionCoarseTime );
228 break;
251 break;
229 case LFR_MODE_SBM2:
252 case LFR_MODE_SBM2:
230 status = enter_mode_sbm2( transitionCoarseTime );
253 status = enter_mode_sbm2( transitionCoarseTime );
231 break;
254 break;
232 default:
255 default:
233 break;
256 break;
234 }
257 }
235
258
236 if (status != RTEMS_SUCCESSFUL)
259 if (status != RTEMS_SUCCESSFUL)
237 {
260 {
238 status = LFR_EXE_ERROR;
261 status = LFR_EXE_ERROR;
239 }
262 }
240 }
263 }
241
264
242 return status;
265 return status;
243 }
266 }
244
267
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
268 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
246 {
269 {
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
270 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
248 *
271 *
249 * @param TC points to the TeleCommand packet that is being processed
272 * @param TC points to the TeleCommand packet that is being processed
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
273 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
251 *
274 *
252 * @return LFR directive status code:
275 * @return LFR directive status code:
253 * - LFR_DEFAULT
276 * - LFR_DEFAULT
254 * - LFR_SUCCESSFUL
277 * - LFR_SUCCESSFUL
255 *
278 *
256 */
279 */
257
280
258 unsigned int val;
281 unsigned int val;
259 unsigned int status;
282 unsigned int status;
260 unsigned char mode;
283 unsigned char mode;
261 unsigned char * bytePosPtr;
284 unsigned char * bytePosPtr;
262 int pos;
285 int pos;
263 float value;
286 float value;
264
287
265 pos = INIT_CHAR;
288 pos = INIT_CHAR;
266 value = INIT_FLOAT;
289 value = INIT_FLOAT;
267
290
268 status = LFR_DEFAULT;
291 status = LFR_DEFAULT;
269
292
270 bytePosPtr = (unsigned char *) &TC->packetID;
293 bytePosPtr = (unsigned char *) &TC->packetID;
271
294
272 // check LFR mode
295 // check LFR mode
273 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
296 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
274 status = check_update_info_hk_lfr_mode( mode );
297 status = check_update_info_hk_lfr_mode( mode );
275 if (status == LFR_SUCCESSFUL) // check TDS mode
298 if (status == LFR_SUCCESSFUL) // check TDS mode
276 {
299 {
277 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
300 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
278 status = check_update_info_hk_tds_mode( mode );
301 status = check_update_info_hk_tds_mode( mode );
279 }
302 }
280 if (status == LFR_SUCCESSFUL) // check THR mode
303 if (status == LFR_SUCCESSFUL) // check THR mode
281 {
304 {
282 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
305 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
283 status = check_update_info_hk_thr_mode( mode );
306 status = check_update_info_hk_thr_mode( mode );
284 }
307 }
285 if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies
308 if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies
286 {
309 {
287 status = check_all_sy_lfr_rw_f(TC, &pos, &value);
310 status = check_all_sy_lfr_rw_f(TC, &pos, &value);
288 }
311 }
289
312
290 // if the parameters checking succeeds, udpate all parameters
313 // if the parameters checking succeeds, udpate all parameters
291 if (status == LFR_SUCCESSFUL)
314 if (status == LFR_SUCCESSFUL)
292 {
315 {
293 // pa_bia_status_info
316 // pa_bia_status_info
294 // => pa_bia_mode_mux_set 3 bits
317 // => pa_bia_mode_mux_set 3 bits
295 // => pa_bia_mode_hv_enabled 1 bit
318 // => pa_bia_mode_hv_enabled 1 bit
296 // => pa_bia_mode_bias1_enabled 1 bit
319 // => pa_bia_mode_bias1_enabled 1 bit
297 // => pa_bia_mode_bias2_enabled 1 bit
320 // => pa_bia_mode_bias2_enabled 1 bit
298 // => pa_bia_mode_bias3_enabled 1 bit
321 // => pa_bia_mode_bias3_enabled 1 bit
299 // => pa_bia_on_off (cp_dpu_bias_on_off)
322 // => pa_bia_on_off (cp_dpu_bias_on_off)
300 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
323 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
301 pa_bia_status_info = pa_bia_status_info
324 pa_bia_status_info = pa_bia_status_info
302 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
325 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
303
326
304 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
327 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
305 getReactionWheelsFrequencies( TC );
328 getReactionWheelsFrequencies( TC );
306 set_hk_lfr_sc_rw_f_flags();
329 set_hk_lfr_sc_rw_f_flags();
307 build_sy_lfr_rw_masks();
330 build_sy_lfr_rw_masks();
308
331
309 // once the masks are built, they have to be merged with the fbins_mask
332 // once the masks are built, they have to be merged with the fbins_mask
310 merge_fbins_masks();
333 merge_fbins_masks();
311
334
312 // increase the TC_LFR_UPDATE_INFO counter
335 // increase the TC_LFR_UPDATE_INFO counter
313 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
336 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
314 {
337 {
315 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
338 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
316 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
339 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
317 val++;
340 val++;
318 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
341 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
319 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
342 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
320 }
343 }
321 }
344 }
322
345
323 return status;
346 return status;
324 }
347 }
325
348
326 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
349 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
327 {
350 {
328 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
351 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
329 *
352 *
330 * @param TC points to the TeleCommand packet that is being processed
353 * @param TC points to the TeleCommand packet that is being processed
331 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
354 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
332 *
355 *
333 */
356 */
334
357
335 int result;
358 int result;
336
359
337 result = LFR_DEFAULT;
360 result = LFR_DEFAULT;
338
361
339 setCalibration( true );
362 setCalibration( true );
340
363
341 result = LFR_SUCCESSFUL;
364 result = LFR_SUCCESSFUL;
342
365
343 return result;
366 return result;
344 }
367 }
345
368
346 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
369 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
347 {
370 {
348 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
371 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
349 *
372 *
350 * @param TC points to the TeleCommand packet that is being processed
373 * @param TC points to the TeleCommand packet that is being processed
351 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
374 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
352 *
375 *
353 */
376 */
354
377
355 int result;
378 int result;
356
379
357 result = LFR_DEFAULT;
380 result = LFR_DEFAULT;
358
381
359 setCalibration( false );
382 setCalibration( false );
360
383
361 result = LFR_SUCCESSFUL;
384 result = LFR_SUCCESSFUL;
362
385
363 return result;
386 return result;
364 }
387 }
365
388
366 int action_update_time(ccsdsTelecommandPacket_t *TC)
389 int action_update_time(ccsdsTelecommandPacket_t *TC)
367 {
390 {
368 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
391 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
369 *
392 *
370 * @param TC points to the TeleCommand packet that is being processed
393 * @param TC points to the TeleCommand packet that is being processed
371 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
394 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
372 *
395 *
373 * @return LFR_SUCCESSFUL
396 * @return LFR_SUCCESSFUL
374 *
397 *
375 */
398 */
376
399
377 unsigned int val;
400 unsigned int val;
378
401
379 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
402 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
380 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
403 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
381 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
404 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
382 + TC->dataAndCRC[BYTE_3];
405 + TC->dataAndCRC[BYTE_3];
383
406
384 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
407 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
385 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
408 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
386 val++;
409 val++;
387 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
410 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
388 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
411 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
389
412
390 oneTcLfrUpdateTimeReceived = 1;
413 oneTcLfrUpdateTimeReceived = 1;
391
414
392 return LFR_SUCCESSFUL;
415 return LFR_SUCCESSFUL;
393 }
416 }
394
417
395 //*******************
418 //*******************
396 // ENTERING THE MODES
419 // ENTERING THE MODES
397 int check_mode_value( unsigned char requestedMode )
420 int check_mode_value( unsigned char requestedMode )
398 {
421 {
399 int status;
422 int status;
400
423
401 status = LFR_DEFAULT;
424 status = LFR_DEFAULT;
402
425
403 if ( (requestedMode != LFR_MODE_STANDBY)
426 if ( (requestedMode != LFR_MODE_STANDBY)
404 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
427 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
405 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
428 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
406 {
429 {
407 status = LFR_DEFAULT;
430 status = LFR_DEFAULT;
408 }
431 }
409 else
432 else
410 {
433 {
411 status = LFR_SUCCESSFUL;
434 status = LFR_SUCCESSFUL;
412 }
435 }
413
436
414 return status;
437 return status;
415 }
438 }
416
439
417 int check_mode_transition( unsigned char requestedMode )
440 int check_mode_transition( unsigned char requestedMode )
418 {
441 {
419 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
442 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
420 *
443 *
421 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
444 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
422 *
445 *
423 * @return LFR directive status codes:
446 * @return LFR directive status codes:
424 * - LFR_SUCCESSFUL - the transition is authorized
447 * - LFR_SUCCESSFUL - the transition is authorized
425 * - LFR_DEFAULT - the transition is not authorized
448 * - LFR_DEFAULT - the transition is not authorized
426 *
449 *
427 */
450 */
428
451
429 int status;
452 int status;
430
453
431 switch (requestedMode)
454 switch (requestedMode)
432 {
455 {
433 case LFR_MODE_STANDBY:
456 case LFR_MODE_STANDBY:
434 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
457 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
435 status = LFR_DEFAULT;
458 status = LFR_DEFAULT;
436 }
459 }
437 else
460 else
438 {
461 {
439 status = LFR_SUCCESSFUL;
462 status = LFR_SUCCESSFUL;
440 }
463 }
441 break;
464 break;
442 case LFR_MODE_NORMAL:
465 case LFR_MODE_NORMAL:
443 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
466 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
444 status = LFR_DEFAULT;
467 status = LFR_DEFAULT;
445 }
468 }
446 else {
469 else {
447 status = LFR_SUCCESSFUL;
470 status = LFR_SUCCESSFUL;
448 }
471 }
449 break;
472 break;
450 case LFR_MODE_BURST:
473 case LFR_MODE_BURST:
451 if ( lfrCurrentMode == LFR_MODE_BURST ) {
474 if ( lfrCurrentMode == LFR_MODE_BURST ) {
452 status = LFR_DEFAULT;
475 status = LFR_DEFAULT;
453 }
476 }
454 else {
477 else {
455 status = LFR_SUCCESSFUL;
478 status = LFR_SUCCESSFUL;
456 }
479 }
457 break;
480 break;
458 case LFR_MODE_SBM1:
481 case LFR_MODE_SBM1:
459 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
482 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
460 status = LFR_DEFAULT;
483 status = LFR_DEFAULT;
461 }
484 }
462 else {
485 else {
463 status = LFR_SUCCESSFUL;
486 status = LFR_SUCCESSFUL;
464 }
487 }
465 break;
488 break;
466 case LFR_MODE_SBM2:
489 case LFR_MODE_SBM2:
467 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
490 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
468 status = LFR_DEFAULT;
491 status = LFR_DEFAULT;
469 }
492 }
470 else {
493 else {
471 status = LFR_SUCCESSFUL;
494 status = LFR_SUCCESSFUL;
472 }
495 }
473 break;
496 break;
474 default:
497 default:
475 status = LFR_DEFAULT;
498 status = LFR_DEFAULT;
476 break;
499 break;
477 }
500 }
478
501
479 return status;
502 return status;
480 }
503 }
481
504
482 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
505 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
483 {
506 {
484 if (transitionCoarseTime == 0)
507 if (transitionCoarseTime == 0)
485 {
508 {
486 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
509 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
487 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
510 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
488 }
511 }
489 else
512 else
490 {
513 {
491 lastValidEnterModeTime = transitionCoarseTime;
514 lastValidEnterModeTime = transitionCoarseTime;
492 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
515 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
493 }
516 }
494 }
517 }
495
518
496 int check_transition_date( unsigned int transitionCoarseTime )
519 int check_transition_date( unsigned int transitionCoarseTime )
497 {
520 {
498 int status;
521 int status;
499 unsigned int localCoarseTime;
522 unsigned int localCoarseTime;
500 unsigned int deltaCoarseTime;
523 unsigned int deltaCoarseTime;
501
524
502 status = LFR_SUCCESSFUL;
525 status = LFR_SUCCESSFUL;
503
526
504 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
527 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
505 {
528 {
506 status = LFR_SUCCESSFUL;
529 status = LFR_SUCCESSFUL;
507 }
530 }
508 else
531 else
509 {
532 {
510 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
533 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
511
534
512 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
535 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
513
536
514 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
537 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
515 {
538 {
516 status = LFR_DEFAULT;
539 status = LFR_DEFAULT;
517 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
540 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
518 }
541 }
519
542
520 if (status == LFR_SUCCESSFUL)
543 if (status == LFR_SUCCESSFUL)
521 {
544 {
522 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
545 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
523 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
546 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
524 {
547 {
525 status = LFR_DEFAULT;
548 status = LFR_DEFAULT;
526 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
549 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
527 }
550 }
528 }
551 }
529 }
552 }
530
553
531 return status;
554 return status;
532 }
555 }
533
556
534 int restart_asm_activities( unsigned char lfrRequestedMode )
557 int restart_asm_activities( unsigned char lfrRequestedMode )
535 {
558 {
536 rtems_status_code status;
559 rtems_status_code status;
537
560
538 status = stop_spectral_matrices();
561 status = stop_spectral_matrices();
539
562
540 thisIsAnASMRestart = 1;
563 thisIsAnASMRestart = 1;
541
564
542 status = restart_asm_tasks( lfrRequestedMode );
565 status = restart_asm_tasks( lfrRequestedMode );
543
566
544 launch_spectral_matrix();
567 launch_spectral_matrix();
545
568
546 return status;
569 return status;
547 }
570 }
548
571
549 int stop_spectral_matrices( void )
572 int stop_spectral_matrices( void )
550 {
573 {
551 /** This function stops and restarts the current mode average spectral matrices activities.
574 /** This function stops and restarts the current mode average spectral matrices activities.
552 *
575 *
553 * @return RTEMS directive status codes:
576 * @return RTEMS directive status codes:
554 * - RTEMS_SUCCESSFUL - task restarted successfully
577 * - RTEMS_SUCCESSFUL - task restarted successfully
555 * - RTEMS_INVALID_ID - task id invalid
578 * - RTEMS_INVALID_ID - task id invalid
556 * - RTEMS_ALREADY_SUSPENDED - task already suspended
579 * - RTEMS_ALREADY_SUSPENDED - task already suspended
557 *
580 *
558 */
581 */
559
582
560 rtems_status_code status;
583 rtems_status_code status;
561
584
562 status = RTEMS_SUCCESSFUL;
585 status = RTEMS_SUCCESSFUL;
563
586
564 // (1) mask interruptions
587 // (1) mask interruptions
565 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
588 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
566
589
567 // (2) reset spectral matrices registers
590 // (2) reset spectral matrices registers
568 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
591 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
569 reset_sm_status();
592 reset_sm_status();
570
593
571 // (3) clear interruptions
594 // (3) clear interruptions
572 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
595 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
573
596
574 // suspend several tasks
597 // suspend several tasks
575 if (lfrCurrentMode != LFR_MODE_STANDBY) {
598 if (lfrCurrentMode != LFR_MODE_STANDBY) {
576 status = suspend_asm_tasks();
599 status = suspend_asm_tasks();
577 }
600 }
578
601
579 if (status != RTEMS_SUCCESSFUL)
602 if (status != RTEMS_SUCCESSFUL)
580 {
603 {
581 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
604 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
582 }
605 }
583
606
584 return status;
607 return status;
585 }
608 }
586
609
587 int stop_current_mode( void )
610 int stop_current_mode( void )
588 {
611 {
589 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
612 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
590 *
613 *
591 * @return RTEMS directive status codes:
614 * @return RTEMS directive status codes:
592 * - RTEMS_SUCCESSFUL - task restarted successfully
615 * - RTEMS_SUCCESSFUL - task restarted successfully
593 * - RTEMS_INVALID_ID - task id invalid
616 * - RTEMS_INVALID_ID - task id invalid
594 * - RTEMS_ALREADY_SUSPENDED - task already suspended
617 * - RTEMS_ALREADY_SUSPENDED - task already suspended
595 *
618 *
596 */
619 */
597
620
598 rtems_status_code status;
621 rtems_status_code status;
599
622
600 status = RTEMS_SUCCESSFUL;
623 status = RTEMS_SUCCESSFUL;
601
624
602 // (1) mask interruptions
625 // (1) mask interruptions
603 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
626 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
604 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
627 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
605
628
606 // (2) reset waveform picker registers
629 // (2) reset waveform picker registers
607 reset_wfp_burst_enable(); // reset burst and enable bits
630 reset_wfp_burst_enable(); // reset burst and enable bits
608 reset_wfp_status(); // reset all the status bits
631 reset_wfp_status(); // reset all the status bits
609
632
610 // (3) reset spectral matrices registers
633 // (3) reset spectral matrices registers
611 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
634 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
612 reset_sm_status();
635 reset_sm_status();
613
636
614 // reset lfr VHDL module
637 // reset lfr VHDL module
615 reset_lfr();
638 reset_lfr();
616
639
617 reset_extractSWF(); // reset the extractSWF flag to false
640 reset_extractSWF(); // reset the extractSWF flag to false
618
641
619 // (4) clear interruptions
642 // (4) clear interruptions
620 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
643 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
621 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
644 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
622
645
623 // suspend several tasks
646 // suspend several tasks
624 if (lfrCurrentMode != LFR_MODE_STANDBY) {
647 if (lfrCurrentMode != LFR_MODE_STANDBY) {
625 status = suspend_science_tasks();
648 status = suspend_science_tasks();
626 }
649 }
627
650
628 if (status != RTEMS_SUCCESSFUL)
651 if (status != RTEMS_SUCCESSFUL)
629 {
652 {
630 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
653 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
631 }
654 }
632
655
633 return status;
656 return status;
634 }
657 }
635
658
636 int enter_mode_standby( void )
659 int enter_mode_standby( void )
637 {
660 {
638 /** This function is used to put LFR in the STANDBY mode.
661 /** This function is used to put LFR in the STANDBY mode.
639 *
662 *
640 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
663 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
641 *
664 *
642 * @return RTEMS directive status codes:
665 * @return RTEMS directive status codes:
643 * - RTEMS_SUCCESSFUL - task restarted successfully
666 * - RTEMS_SUCCESSFUL - task restarted successfully
644 * - RTEMS_INVALID_ID - task id invalid
667 * - RTEMS_INVALID_ID - task id invalid
645 * - RTEMS_INCORRECT_STATE - task never started
668 * - RTEMS_INCORRECT_STATE - task never started
646 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
669 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
647 *
670 *
648 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
671 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
649 * is immediate.
672 * is immediate.
650 *
673 *
651 */
674 */
652
675
653 int status;
676 int status;
654
677
655 status = stop_current_mode(); // STOP THE CURRENT MODE
678 status = stop_current_mode(); // STOP THE CURRENT MODE
656
679
657 #ifdef PRINT_TASK_STATISTICS
680 #ifdef PRINT_TASK_STATISTICS
658 rtems_cpu_usage_report();
681 rtems_cpu_usage_report();
659 #endif
682 #endif
660
683
661 #ifdef PRINT_STACK_REPORT
684 #ifdef PRINT_STACK_REPORT
662 PRINTF("stack report selected\n")
685 PRINTF("stack report selected\n")
663 rtems_stack_checker_report_usage();
686 rtems_stack_checker_report_usage();
664 #endif
687 #endif
665
688
666 return status;
689 return status;
667 }
690 }
668
691
669 int enter_mode_normal( unsigned int transitionCoarseTime )
692 int enter_mode_normal( unsigned int transitionCoarseTime )
670 {
693 {
671 /** This function is used to start the NORMAL mode.
694 /** This function is used to start the NORMAL mode.
672 *
695 *
673 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
696 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
674 *
697 *
675 * @return RTEMS directive status codes:
698 * @return RTEMS directive status codes:
676 * - RTEMS_SUCCESSFUL - task restarted successfully
699 * - RTEMS_SUCCESSFUL - task restarted successfully
677 * - RTEMS_INVALID_ID - task id invalid
700 * - RTEMS_INVALID_ID - task id invalid
678 * - RTEMS_INCORRECT_STATE - task never started
701 * - RTEMS_INCORRECT_STATE - task never started
679 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
702 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
680 *
703 *
681 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
704 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
682 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
705 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
683 *
706 *
684 */
707 */
685
708
686 int status;
709 int status;
687
710
688 #ifdef PRINT_TASK_STATISTICS
711 #ifdef PRINT_TASK_STATISTICS
689 rtems_cpu_usage_reset();
712 rtems_cpu_usage_reset();
690 #endif
713 #endif
691
714
692 status = RTEMS_UNSATISFIED;
715 status = RTEMS_UNSATISFIED;
693
716
694 switch( lfrCurrentMode )
717 switch( lfrCurrentMode )
695 {
718 {
696 case LFR_MODE_STANDBY:
719 case LFR_MODE_STANDBY:
697 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
720 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
698 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
721 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
699 {
722 {
700 launch_spectral_matrix( );
723 launch_spectral_matrix( );
701 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
724 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
702 }
725 }
703 break;
726 break;
704 case LFR_MODE_BURST:
727 case LFR_MODE_BURST:
705 status = stop_current_mode(); // stop the current mode
728 status = stop_current_mode(); // stop the current mode
706 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
729 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
707 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
730 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
708 {
731 {
709 launch_spectral_matrix( );
732 launch_spectral_matrix( );
710 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
733 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
711 }
734 }
712 break;
735 break;
713 case LFR_MODE_SBM1:
736 case LFR_MODE_SBM1:
714 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
737 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
715 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
738 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
716 update_last_valid_transition_date( transitionCoarseTime );
739 update_last_valid_transition_date( transitionCoarseTime );
717 break;
740 break;
718 case LFR_MODE_SBM2:
741 case LFR_MODE_SBM2:
719 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
742 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
720 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
743 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
721 update_last_valid_transition_date( transitionCoarseTime );
744 update_last_valid_transition_date( transitionCoarseTime );
722 break;
745 break;
723 default:
746 default:
724 break;
747 break;
725 }
748 }
726
749
727 if (status != RTEMS_SUCCESSFUL)
750 if (status != RTEMS_SUCCESSFUL)
728 {
751 {
729 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
752 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
730 status = RTEMS_UNSATISFIED;
753 status = RTEMS_UNSATISFIED;
731 }
754 }
732
755
733 return status;
756 return status;
734 }
757 }
735
758
736 int enter_mode_burst( unsigned int transitionCoarseTime )
759 int enter_mode_burst( unsigned int transitionCoarseTime )
737 {
760 {
738 /** This function is used to start the BURST mode.
761 /** This function is used to start the BURST mode.
739 *
762 *
740 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
763 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
741 *
764 *
742 * @return RTEMS directive status codes:
765 * @return RTEMS directive status codes:
743 * - RTEMS_SUCCESSFUL - task restarted successfully
766 * - RTEMS_SUCCESSFUL - task restarted successfully
744 * - RTEMS_INVALID_ID - task id invalid
767 * - RTEMS_INVALID_ID - task id invalid
745 * - RTEMS_INCORRECT_STATE - task never started
768 * - RTEMS_INCORRECT_STATE - task never started
746 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
769 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
747 *
770 *
748 * The way the BURST mode is started does not depend on the LFR current mode.
771 * The way the BURST mode is started does not depend on the LFR current mode.
749 *
772 *
750 */
773 */
751
774
752
775
753 int status;
776 int status;
754
777
755 #ifdef PRINT_TASK_STATISTICS
778 #ifdef PRINT_TASK_STATISTICS
756 rtems_cpu_usage_reset();
779 rtems_cpu_usage_reset();
757 #endif
780 #endif
758
781
759 status = stop_current_mode(); // stop the current mode
782 status = stop_current_mode(); // stop the current mode
760 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
783 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
761 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
784 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
762 {
785 {
763 launch_spectral_matrix( );
786 launch_spectral_matrix( );
764 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
787 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
765 }
788 }
766
789
767 if (status != RTEMS_SUCCESSFUL)
790 if (status != RTEMS_SUCCESSFUL)
768 {
791 {
769 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
792 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
770 status = RTEMS_UNSATISFIED;
793 status = RTEMS_UNSATISFIED;
771 }
794 }
772
795
773 return status;
796 return status;
774 }
797 }
775
798
776 int enter_mode_sbm1( unsigned int transitionCoarseTime )
799 int enter_mode_sbm1( unsigned int transitionCoarseTime )
777 {
800 {
778 /** This function is used to start the SBM1 mode.
801 /** This function is used to start the SBM1 mode.
779 *
802 *
780 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
803 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
781 *
804 *
782 * @return RTEMS directive status codes:
805 * @return RTEMS directive status codes:
783 * - RTEMS_SUCCESSFUL - task restarted successfully
806 * - RTEMS_SUCCESSFUL - task restarted successfully
784 * - RTEMS_INVALID_ID - task id invalid
807 * - RTEMS_INVALID_ID - task id invalid
785 * - RTEMS_INCORRECT_STATE - task never started
808 * - RTEMS_INCORRECT_STATE - task never started
786 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
809 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
787 *
810 *
788 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
811 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
789 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
812 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
790 * cases, the acquisition is completely restarted.
813 * cases, the acquisition is completely restarted.
791 *
814 *
792 */
815 */
793
816
794 int status;
817 int status;
795
818
796 #ifdef PRINT_TASK_STATISTICS
819 #ifdef PRINT_TASK_STATISTICS
797 rtems_cpu_usage_reset();
820 rtems_cpu_usage_reset();
798 #endif
821 #endif
799
822
800 status = RTEMS_UNSATISFIED;
823 status = RTEMS_UNSATISFIED;
801
824
802 switch( lfrCurrentMode )
825 switch( lfrCurrentMode )
803 {
826 {
804 case LFR_MODE_STANDBY:
827 case LFR_MODE_STANDBY:
805 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
828 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
806 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
829 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
807 {
830 {
808 launch_spectral_matrix( );
831 launch_spectral_matrix( );
809 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
832 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
810 }
833 }
811 break;
834 break;
812 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
835 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
813 status = restart_asm_activities( LFR_MODE_SBM1 );
836 status = restart_asm_activities( LFR_MODE_SBM1 );
814 status = LFR_SUCCESSFUL;
837 status = LFR_SUCCESSFUL;
815 update_last_valid_transition_date( transitionCoarseTime );
838 update_last_valid_transition_date( transitionCoarseTime );
816 break;
839 break;
817 case LFR_MODE_BURST:
840 case LFR_MODE_BURST:
818 status = stop_current_mode(); // stop the current mode
841 status = stop_current_mode(); // stop the current mode
819 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
842 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
820 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
843 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
821 {
844 {
822 launch_spectral_matrix( );
845 launch_spectral_matrix( );
823 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
846 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
824 }
847 }
825 break;
848 break;
826 case LFR_MODE_SBM2:
849 case LFR_MODE_SBM2:
827 status = restart_asm_activities( LFR_MODE_SBM1 );
850 status = restart_asm_activities( LFR_MODE_SBM1 );
828 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
851 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
829 update_last_valid_transition_date( transitionCoarseTime );
852 update_last_valid_transition_date( transitionCoarseTime );
830 break;
853 break;
831 default:
854 default:
832 break;
855 break;
833 }
856 }
834
857
835 if (status != RTEMS_SUCCESSFUL)
858 if (status != RTEMS_SUCCESSFUL)
836 {
859 {
837 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
860 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
838 status = RTEMS_UNSATISFIED;
861 status = RTEMS_UNSATISFIED;
839 }
862 }
840
863
841 return status;
864 return status;
842 }
865 }
843
866
844 int enter_mode_sbm2( unsigned int transitionCoarseTime )
867 int enter_mode_sbm2( unsigned int transitionCoarseTime )
845 {
868 {
846 /** This function is used to start the SBM2 mode.
869 /** This function is used to start the SBM2 mode.
847 *
870 *
848 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
871 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
849 *
872 *
850 * @return RTEMS directive status codes:
873 * @return RTEMS directive status codes:
851 * - RTEMS_SUCCESSFUL - task restarted successfully
874 * - RTEMS_SUCCESSFUL - task restarted successfully
852 * - RTEMS_INVALID_ID - task id invalid
875 * - RTEMS_INVALID_ID - task id invalid
853 * - RTEMS_INCORRECT_STATE - task never started
876 * - RTEMS_INCORRECT_STATE - task never started
854 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
877 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
855 *
878 *
856 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
879 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
857 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
880 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
858 * cases, the acquisition is completely restarted.
881 * cases, the acquisition is completely restarted.
859 *
882 *
860 */
883 */
861
884
862 int status;
885 int status;
863
886
864 #ifdef PRINT_TASK_STATISTICS
887 #ifdef PRINT_TASK_STATISTICS
865 rtems_cpu_usage_reset();
888 rtems_cpu_usage_reset();
866 #endif
889 #endif
867
890
868 status = RTEMS_UNSATISFIED;
891 status = RTEMS_UNSATISFIED;
869
892
870 switch( lfrCurrentMode )
893 switch( lfrCurrentMode )
871 {
894 {
872 case LFR_MODE_STANDBY:
895 case LFR_MODE_STANDBY:
873 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
896 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
874 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
897 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
875 {
898 {
876 launch_spectral_matrix( );
899 launch_spectral_matrix( );
877 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
900 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
878 }
901 }
879 break;
902 break;
880 case LFR_MODE_NORMAL:
903 case LFR_MODE_NORMAL:
881 status = restart_asm_activities( LFR_MODE_SBM2 );
904 status = restart_asm_activities( LFR_MODE_SBM2 );
882 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
905 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
883 update_last_valid_transition_date( transitionCoarseTime );
906 update_last_valid_transition_date( transitionCoarseTime );
884 break;
907 break;
885 case LFR_MODE_BURST:
908 case LFR_MODE_BURST:
886 status = stop_current_mode(); // stop the current mode
909 status = stop_current_mode(); // stop the current mode
887 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
910 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
888 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
911 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
889 {
912 {
890 launch_spectral_matrix( );
913 launch_spectral_matrix( );
891 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
914 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
892 }
915 }
893 break;
916 break;
894 case LFR_MODE_SBM1:
917 case LFR_MODE_SBM1:
895 status = restart_asm_activities( LFR_MODE_SBM2 );
918 status = restart_asm_activities( LFR_MODE_SBM2 );
896 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
919 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
897 update_last_valid_transition_date( transitionCoarseTime );
920 update_last_valid_transition_date( transitionCoarseTime );
898 break;
921 break;
899 default:
922 default:
900 break;
923 break;
901 }
924 }
902
925
903 if (status != RTEMS_SUCCESSFUL)
926 if (status != RTEMS_SUCCESSFUL)
904 {
927 {
905 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
928 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
906 status = RTEMS_UNSATISFIED;
929 status = RTEMS_UNSATISFIED;
907 }
930 }
908
931
909 return status;
932 return status;
910 }
933 }
911
934
912 int restart_science_tasks( unsigned char lfrRequestedMode )
935 int restart_science_tasks( unsigned char lfrRequestedMode )
913 {
936 {
914 /** This function is used to restart all science tasks.
937 /** This function is used to restart all science tasks.
915 *
938 *
916 * @return RTEMS directive status codes:
939 * @return RTEMS directive status codes:
917 * - RTEMS_SUCCESSFUL - task restarted successfully
940 * - RTEMS_SUCCESSFUL - task restarted successfully
918 * - RTEMS_INVALID_ID - task id invalid
941 * - RTEMS_INVALID_ID - task id invalid
919 * - RTEMS_INCORRECT_STATE - task never started
942 * - RTEMS_INCORRECT_STATE - task never started
920 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
943 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
921 *
944 *
922 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
945 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
923 *
946 *
924 */
947 */
925
948
926 rtems_status_code status[NB_SCIENCE_TASKS];
949 rtems_status_code status[NB_SCIENCE_TASKS];
927 rtems_status_code ret;
950 rtems_status_code ret;
928
951
929 ret = RTEMS_SUCCESSFUL;
952 ret = RTEMS_SUCCESSFUL;
930
953
931 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
954 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
932 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
955 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
933 {
956 {
934 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
957 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
935 }
958 }
936
959
937 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
960 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
938 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
961 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
939 {
962 {
940 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
963 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
941 }
964 }
942
965
943 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
966 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
944 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
967 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
945 {
968 {
946 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
969 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
947 }
970 }
948
971
949 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
972 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
950 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
973 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
951 {
974 {
952 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
975 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
953 }
976 }
954
977
955 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
978 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
956 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
979 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
957 {
980 {
958 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
981 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
959 }
982 }
960
983
961 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
984 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
962 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
985 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
963 {
986 {
964 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
987 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
965 }
988 }
966
989
967 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
990 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
968 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
991 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
969 {
992 {
970 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
993 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
971 }
994 }
972
995
973 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
996 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
974 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
997 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
975 {
998 {
976 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
999 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
977 }
1000 }
978
1001
979 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1002 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
980 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
1003 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
981 {
1004 {
982 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
1005 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
983 }
1006 }
984
1007
985 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1008 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
986 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
1009 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
987 {
1010 {
988 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
1011 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
989 }
1012 }
990
1013
991 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1014 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
992 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1015 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
993 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
1016 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
994 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
1017 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
995 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
1018 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
996 {
1019 {
997 ret = RTEMS_UNSATISFIED;
1020 ret = RTEMS_UNSATISFIED;
998 }
1021 }
999
1022
1000 return ret;
1023 return ret;
1001 }
1024 }
1002
1025
1003 int restart_asm_tasks( unsigned char lfrRequestedMode )
1026 int restart_asm_tasks( unsigned char lfrRequestedMode )
1004 {
1027 {
1005 /** This function is used to restart average spectral matrices tasks.
1028 /** This function is used to restart average spectral matrices tasks.
1006 *
1029 *
1007 * @return RTEMS directive status codes:
1030 * @return RTEMS directive status codes:
1008 * - RTEMS_SUCCESSFUL - task restarted successfully
1031 * - RTEMS_SUCCESSFUL - task restarted successfully
1009 * - RTEMS_INVALID_ID - task id invalid
1032 * - RTEMS_INVALID_ID - task id invalid
1010 * - RTEMS_INCORRECT_STATE - task never started
1033 * - RTEMS_INCORRECT_STATE - task never started
1011 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1034 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1012 *
1035 *
1013 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1036 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1014 *
1037 *
1015 */
1038 */
1016
1039
1017 rtems_status_code status[NB_ASM_TASKS];
1040 rtems_status_code status[NB_ASM_TASKS];
1018 rtems_status_code ret;
1041 rtems_status_code ret;
1019
1042
1020 ret = RTEMS_SUCCESSFUL;
1043 ret = RTEMS_SUCCESSFUL;
1021
1044
1022 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1045 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1023 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1046 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1024 {
1047 {
1025 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1048 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1026 }
1049 }
1027
1050
1028 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1051 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1029 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1052 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1030 {
1053 {
1031 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1054 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1032 }
1055 }
1033
1056
1034 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1057 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1035 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1058 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1036 {
1059 {
1037 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1060 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1038 }
1061 }
1039
1062
1040 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1063 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1041 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1064 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1042 {
1065 {
1043 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1066 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1044 }
1067 }
1045
1068
1046 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1069 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1047 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1070 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1048 {
1071 {
1049 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1072 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1050 }
1073 }
1051
1074
1052 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1075 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1053 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1076 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1054 {
1077 {
1055 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1078 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1056 }
1079 }
1057
1080
1058 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1081 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1059 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1082 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1060 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1083 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1061 {
1084 {
1062 ret = RTEMS_UNSATISFIED;
1085 ret = RTEMS_UNSATISFIED;
1063 }
1086 }
1064
1087
1065 return ret;
1088 return ret;
1066 }
1089 }
1067
1090
1068 int suspend_science_tasks( void )
1091 int suspend_science_tasks( void )
1069 {
1092 {
1070 /** This function suspends the science tasks.
1093 /** This function suspends the science tasks.
1071 *
1094 *
1072 * @return RTEMS directive status codes:
1095 * @return RTEMS directive status codes:
1073 * - RTEMS_SUCCESSFUL - task restarted successfully
1096 * - RTEMS_SUCCESSFUL - task restarted successfully
1074 * - RTEMS_INVALID_ID - task id invalid
1097 * - RTEMS_INVALID_ID - task id invalid
1075 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1098 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1076 *
1099 *
1077 */
1100 */
1078
1101
1079 rtems_status_code status;
1102 rtems_status_code status;
1080
1103
1081 PRINTF("in suspend_science_tasks\n")
1104 PRINTF("in suspend_science_tasks\n")
1082
1105
1083 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1106 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1084 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1085 {
1108 {
1086 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1109 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1087 }
1110 }
1088 else
1111 else
1089 {
1112 {
1090 status = RTEMS_SUCCESSFUL;
1113 status = RTEMS_SUCCESSFUL;
1091 }
1114 }
1092 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1115 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1093 {
1116 {
1094 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1117 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1095 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1118 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1096 {
1119 {
1097 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1120 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1098 }
1121 }
1099 else
1122 else
1100 {
1123 {
1101 status = RTEMS_SUCCESSFUL;
1124 status = RTEMS_SUCCESSFUL;
1102 }
1125 }
1103 }
1126 }
1104 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1127 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1105 {
1128 {
1106 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1129 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1130 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1108 {
1131 {
1109 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1132 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1110 }
1133 }
1111 else
1134 else
1112 {
1135 {
1113 status = RTEMS_SUCCESSFUL;
1136 status = RTEMS_SUCCESSFUL;
1114 }
1137 }
1115 }
1138 }
1116 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1139 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1117 {
1140 {
1118 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1141 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1119 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1142 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1120 {
1143 {
1121 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1144 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1122 }
1145 }
1123 else
1146 else
1124 {
1147 {
1125 status = RTEMS_SUCCESSFUL;
1148 status = RTEMS_SUCCESSFUL;
1126 }
1149 }
1127 }
1150 }
1128 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1151 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1129 {
1152 {
1130 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1153 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1131 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1154 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1132 {
1155 {
1133 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1156 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1134 }
1157 }
1135 else
1158 else
1136 {
1159 {
1137 status = RTEMS_SUCCESSFUL;
1160 status = RTEMS_SUCCESSFUL;
1138 }
1161 }
1139 }
1162 }
1140 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1163 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1141 {
1164 {
1142 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1165 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1143 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1166 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1144 {
1167 {
1145 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1168 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1146 }
1169 }
1147 else
1170 else
1148 {
1171 {
1149 status = RTEMS_SUCCESSFUL;
1172 status = RTEMS_SUCCESSFUL;
1150 }
1173 }
1151 }
1174 }
1152 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1175 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1153 {
1176 {
1154 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1177 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1155 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1178 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1156 {
1179 {
1157 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1180 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1158 }
1181 }
1159 else
1182 else
1160 {
1183 {
1161 status = RTEMS_SUCCESSFUL;
1184 status = RTEMS_SUCCESSFUL;
1162 }
1185 }
1163 }
1186 }
1164 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1187 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1165 {
1188 {
1166 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1189 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1167 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1190 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1168 {
1191 {
1169 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1192 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1170 }
1193 }
1171 else
1194 else
1172 {
1195 {
1173 status = RTEMS_SUCCESSFUL;
1196 status = RTEMS_SUCCESSFUL;
1174 }
1197 }
1175 }
1198 }
1176 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1199 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1177 {
1200 {
1178 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1201 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1179 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1202 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1180 {
1203 {
1181 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1204 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1182 }
1205 }
1183 else
1206 else
1184 {
1207 {
1185 status = RTEMS_SUCCESSFUL;
1208 status = RTEMS_SUCCESSFUL;
1186 }
1209 }
1187 }
1210 }
1188 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1211 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1189 {
1212 {
1190 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1213 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1191 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1214 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1192 {
1215 {
1193 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1216 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1194 }
1217 }
1195 else
1218 else
1196 {
1219 {
1197 status = RTEMS_SUCCESSFUL;
1220 status = RTEMS_SUCCESSFUL;
1198 }
1221 }
1199 }
1222 }
1200
1223
1201 return status;
1224 return status;
1202 }
1225 }
1203
1226
1204 int suspend_asm_tasks( void )
1227 int suspend_asm_tasks( void )
1205 {
1228 {
1206 /** This function suspends the science tasks.
1229 /** This function suspends the science tasks.
1207 *
1230 *
1208 * @return RTEMS directive status codes:
1231 * @return RTEMS directive status codes:
1209 * - RTEMS_SUCCESSFUL - task restarted successfully
1232 * - RTEMS_SUCCESSFUL - task restarted successfully
1210 * - RTEMS_INVALID_ID - task id invalid
1233 * - RTEMS_INVALID_ID - task id invalid
1211 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1234 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1212 *
1235 *
1213 */
1236 */
1214
1237
1215 rtems_status_code status;
1238 rtems_status_code status;
1216
1239
1217 PRINTF("in suspend_science_tasks\n")
1240 PRINTF("in suspend_science_tasks\n")
1218
1241
1219 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1242 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1220 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1243 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1221 {
1244 {
1222 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1245 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1223 }
1246 }
1224 else
1247 else
1225 {
1248 {
1226 status = RTEMS_SUCCESSFUL;
1249 status = RTEMS_SUCCESSFUL;
1227 }
1250 }
1228
1251
1229 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1252 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1230 {
1253 {
1231 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1254 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1232 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1255 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1233 {
1256 {
1234 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1257 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1235 }
1258 }
1236 else
1259 else
1237 {
1260 {
1238 status = RTEMS_SUCCESSFUL;
1261 status = RTEMS_SUCCESSFUL;
1239 }
1262 }
1240 }
1263 }
1241
1264
1242 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1265 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1243 {
1266 {
1244 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1267 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1245 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1268 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1246 {
1269 {
1247 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1270 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1248 }
1271 }
1249 else
1272 else
1250 {
1273 {
1251 status = RTEMS_SUCCESSFUL;
1274 status = RTEMS_SUCCESSFUL;
1252 }
1275 }
1253 }
1276 }
1254
1277
1255 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1278 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1256 {
1279 {
1257 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1280 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1258 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1281 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1259 {
1282 {
1260 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1283 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1261 }
1284 }
1262 else
1285 else
1263 {
1286 {
1264 status = RTEMS_SUCCESSFUL;
1287 status = RTEMS_SUCCESSFUL;
1265 }
1288 }
1266 }
1289 }
1267
1290
1268 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1291 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1269 {
1292 {
1270 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1293 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1271 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1294 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1272 {
1295 {
1273 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1296 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1274 }
1297 }
1275 else
1298 else
1276 {
1299 {
1277 status = RTEMS_SUCCESSFUL;
1300 status = RTEMS_SUCCESSFUL;
1278 }
1301 }
1279 }
1302 }
1280
1303
1281 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1304 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1282 {
1305 {
1283 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1306 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1284 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1307 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1285 {
1308 {
1286 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1309 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1287 }
1310 }
1288 else
1311 else
1289 {
1312 {
1290 status = RTEMS_SUCCESSFUL;
1313 status = RTEMS_SUCCESSFUL;
1291 }
1314 }
1292 }
1315 }
1293
1316
1294 return status;
1317 return status;
1295 }
1318 }
1296
1319
1297 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1320 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1298 {
1321 {
1299
1322
1300 WFP_reset_current_ring_nodes();
1323 WFP_reset_current_ring_nodes();
1301
1324
1302 reset_waveform_picker_regs();
1325 reset_waveform_picker_regs();
1303
1326
1304 set_wfp_burst_enable_register( mode );
1327 set_wfp_burst_enable_register( mode );
1305
1328
1306 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1329 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1307 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1330 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1308
1331
1309 if (transitionCoarseTime == 0)
1332 if (transitionCoarseTime == 0)
1310 {
1333 {
1311 // instant transition means transition on the next valid date
1334 // instant transition means transition on the next valid date
1312 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1335 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1313 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1336 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1314 }
1337 }
1315 else
1338 else
1316 {
1339 {
1317 waveform_picker_regs->start_date = transitionCoarseTime;
1340 waveform_picker_regs->start_date = transitionCoarseTime;
1318 }
1341 }
1319
1342
1320 update_last_valid_transition_date(waveform_picker_regs->start_date);
1343 update_last_valid_transition_date(waveform_picker_regs->start_date);
1321
1344
1322 }
1345 }
1323
1346
1324 void launch_spectral_matrix( void )
1347 void launch_spectral_matrix( void )
1325 {
1348 {
1326 SM_reset_current_ring_nodes();
1349 SM_reset_current_ring_nodes();
1327
1350
1328 reset_spectral_matrix_regs();
1351 reset_spectral_matrix_regs();
1329
1352
1330 reset_nb_sm();
1353 reset_nb_sm();
1331
1354
1332 set_sm_irq_onNewMatrix( 1 );
1355 set_sm_irq_onNewMatrix( 1 );
1333
1356
1334 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1357 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1335 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1358 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1336
1359
1337 }
1360 }
1338
1361
1339 void set_sm_irq_onNewMatrix( unsigned char value )
1362 void set_sm_irq_onNewMatrix( unsigned char value )
1340 {
1363 {
1341 if (value == 1)
1364 if (value == 1)
1342 {
1365 {
1343 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1366 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1344 }
1367 }
1345 else
1368 else
1346 {
1369 {
1347 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1370 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1348 }
1371 }
1349 }
1372 }
1350
1373
1351 void set_sm_irq_onError( unsigned char value )
1374 void set_sm_irq_onError( unsigned char value )
1352 {
1375 {
1353 if (value == 1)
1376 if (value == 1)
1354 {
1377 {
1355 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1378 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1356 }
1379 }
1357 else
1380 else
1358 {
1381 {
1359 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1382 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1360 }
1383 }
1361 }
1384 }
1362
1385
1363 //*****************************
1386 //*****************************
1364 // CONFIGURE CALIBRATION SIGNAL
1387 // CONFIGURE CALIBRATION SIGNAL
1365 void setCalibrationPrescaler( unsigned int prescaler )
1388 void setCalibrationPrescaler( unsigned int prescaler )
1366 {
1389 {
1367 // prescaling of the master clock (25 MHz)
1390 // prescaling of the master clock (25 MHz)
1368 // master clock is divided by 2^prescaler
1391 // master clock is divided by 2^prescaler
1369 time_management_regs->calPrescaler = prescaler;
1392 time_management_regs->calPrescaler = prescaler;
1370 }
1393 }
1371
1394
1372 void setCalibrationDivisor( unsigned int divisionFactor )
1395 void setCalibrationDivisor( unsigned int divisionFactor )
1373 {
1396 {
1374 // division of the prescaled clock by the division factor
1397 // division of the prescaled clock by the division factor
1375 time_management_regs->calDivisor = divisionFactor;
1398 time_management_regs->calDivisor = divisionFactor;
1376 }
1399 }
1377
1400
1378 void setCalibrationData( void )
1401 void setCalibrationData( void )
1379 {
1402 {
1380 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1403 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1381 *
1404 *
1382 * @param void
1405 * @param void
1383 *
1406 *
1384 * @return void
1407 * @return void
1385 *
1408 *
1386 */
1409 */
1387
1410
1388 unsigned int k;
1411 unsigned int k;
1389 unsigned short data;
1412 unsigned short data;
1390 float val;
1413 float val;
1391 float Ts;
1414 float Ts;
1392
1415
1393 time_management_regs->calDataPtr = INIT_CHAR;
1416 time_management_regs->calDataPtr = INIT_CHAR;
1394
1417
1395 Ts = 1 / CAL_FS;
1418 Ts = 1 / CAL_FS;
1396
1419
1397 // build the signal for the SCM calibration
1420 // build the signal for the SCM calibration
1398 for (k = 0; k < CAL_NB_PTS; k++)
1421 for (k = 0; k < CAL_NB_PTS; k++)
1399 {
1422 {
1400 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1423 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1401 + CAL_A1 * sin( CAL_W1 * k * Ts );
1424 + CAL_A1 * sin( CAL_W1 * k * Ts );
1402 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1425 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1403 time_management_regs->calData = data & CAL_DATA_MASK;
1426 time_management_regs->calData = data & CAL_DATA_MASK;
1404 }
1427 }
1405 }
1428 }
1406
1429
1407 void setCalibrationDataInterleaved( void )
1430 void setCalibrationDataInterleaved( void )
1408 {
1431 {
1409 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1432 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1410 *
1433 *
1411 * @param void
1434 * @param void
1412 *
1435 *
1413 * @return void
1436 * @return void
1414 *
1437 *
1415 * In interleaved mode, one can store more values than in normal mode.
1438 * In interleaved mode, one can store more values than in normal mode.
1416 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1439 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1417 * T store 3 values, one need two write operations.
1440 * T store 3 values, one need two write operations.
1418 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1441 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1419 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1442 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1420 *
1443 *
1421 */
1444 */
1422
1445
1423 unsigned int k;
1446 unsigned int k;
1424 float val;
1447 float val;
1425 float Ts;
1448 float Ts;
1426 unsigned short data[CAL_NB_PTS_INTER];
1449 unsigned short data[CAL_NB_PTS_INTER];
1427 unsigned char *dataPtr;
1450 unsigned char *dataPtr;
1428
1451
1429 Ts = 1 / CAL_FS_INTER;
1452 Ts = 1 / CAL_FS_INTER;
1430
1453
1431 time_management_regs->calDataPtr = INIT_CHAR;
1454 time_management_regs->calDataPtr = INIT_CHAR;
1432
1455
1433 // build the signal for the SCM calibration
1456 // build the signal for the SCM calibration
1434 for (k=0; k<CAL_NB_PTS_INTER; k++)
1457 for (k=0; k<CAL_NB_PTS_INTER; k++)
1435 {
1458 {
1436 val = sin( 2 * pi * CAL_F0 * k * Ts )
1459 val = sin( 2 * pi * CAL_F0 * k * Ts )
1437 + sin( 2 * pi * CAL_F1 * k * Ts );
1460 + sin( 2 * pi * CAL_F1 * k * Ts );
1438 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1461 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1439 }
1462 }
1440
1463
1441 // write the signal in interleaved mode
1464 // write the signal in interleaved mode
1442 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1465 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1443 {
1466 {
1444 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1467 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1445 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1468 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1446 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1469 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1447 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1470 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1448 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1471 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1449 }
1472 }
1450 }
1473 }
1451
1474
1452 void setCalibrationReload( bool state)
1475 void setCalibrationReload( bool state)
1453 {
1476 {
1454 if (state == true)
1477 if (state == true)
1455 {
1478 {
1456 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1479 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1457 }
1480 }
1458 else
1481 else
1459 {
1482 {
1460 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1483 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1461 }
1484 }
1462 }
1485 }
1463
1486
1464 void setCalibrationEnable( bool state )
1487 void setCalibrationEnable( bool state )
1465 {
1488 {
1466 // this bit drives the multiplexer
1489 // this bit drives the multiplexer
1467 if (state == true)
1490 if (state == true)
1468 {
1491 {
1469 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1492 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1470 }
1493 }
1471 else
1494 else
1472 {
1495 {
1473 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1496 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1474 }
1497 }
1475 }
1498 }
1476
1499
1477 void setCalibrationInterleaved( bool state )
1500 void setCalibrationInterleaved( bool state )
1478 {
1501 {
1479 // this bit drives the multiplexer
1502 // this bit drives the multiplexer
1480 if (state == true)
1503 if (state == true)
1481 {
1504 {
1482 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1505 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1483 }
1506 }
1484 else
1507 else
1485 {
1508 {
1486 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1509 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1487 }
1510 }
1488 }
1511 }
1489
1512
1490 void setCalibration( bool state )
1513 void setCalibration( bool state )
1491 {
1514 {
1492 if (state == true)
1515 if (state == true)
1493 {
1516 {
1494 setCalibrationEnable( true );
1517 setCalibrationEnable( true );
1495 setCalibrationReload( false );
1518 setCalibrationReload( false );
1496 set_hk_lfr_calib_enable( true );
1519 set_hk_lfr_calib_enable( true );
1497 }
1520 }
1498 else
1521 else
1499 {
1522 {
1500 setCalibrationEnable( false );
1523 setCalibrationEnable( false );
1501 setCalibrationReload( true );
1524 setCalibrationReload( true );
1502 set_hk_lfr_calib_enable( false );
1525 set_hk_lfr_calib_enable( false );
1503 }
1526 }
1504 }
1527 }
1505
1528
1506 void configureCalibration( bool interleaved )
1529 void configureCalibration( bool interleaved )
1507 {
1530 {
1508 setCalibration( false );
1531 setCalibration( false );
1509 if ( interleaved == true )
1532 if ( interleaved == true )
1510 {
1533 {
1511 setCalibrationInterleaved( true );
1534 setCalibrationInterleaved( true );
1512 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1535 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1513 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1536 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1514 setCalibrationDataInterleaved();
1537 setCalibrationDataInterleaved();
1515 }
1538 }
1516 else
1539 else
1517 {
1540 {
1518 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1541 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1519 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1542 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1520 setCalibrationData();
1543 setCalibrationData();
1521 }
1544 }
1522 }
1545 }
1523
1546
1524 //****************
1547 //****************
1525 // CLOSING ACTIONS
1548 // CLOSING ACTIONS
1526 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1549 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1527 {
1550 {
1528 /** This function is used to update the HK packets statistics after a successful TC execution.
1551 /** This function is used to update the HK packets statistics after a successful TC execution.
1529 *
1552 *
1530 * @param TC points to the TC being processed
1553 * @param TC points to the TC being processed
1531 * @param time is the time used to date the TC execution
1554 * @param time is the time used to date the TC execution
1532 *
1555 *
1533 */
1556 */
1534
1557
1535 unsigned int val;
1558 unsigned int val;
1536
1559
1537 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1560 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1538 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1561 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1539 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1562 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1540 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1563 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1541 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1564 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1542 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1565 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1543 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1566 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1544 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1567 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1545 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1568 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1546 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1569 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1547 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1570 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1548 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1571 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1549
1572
1550 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1573 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1551 val++;
1574 val++;
1552 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1575 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1553 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1576 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1554 }
1577 }
1555
1578
1556 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1579 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1557 {
1580 {
1558 /** This function is used to update the HK packets statistics after a TC rejection.
1581 /** This function is used to update the HK packets statistics after a TC rejection.
1559 *
1582 *
1560 * @param TC points to the TC being processed
1583 * @param TC points to the TC being processed
1561 * @param time is the time used to date the TC rejection
1584 * @param time is the time used to date the TC rejection
1562 *
1585 *
1563 */
1586 */
1564
1587
1565 unsigned int val;
1588 unsigned int val;
1566
1589
1567 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1590 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1568 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1591 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1569 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1592 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1570 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1593 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1571 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1594 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1572 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1595 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1573 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1596 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1574 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1597 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1575 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1598 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1576 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1599 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1577 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1600 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1578 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1601 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1579
1602
1580 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1603 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1581 val++;
1604 val++;
1582 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1605 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1583 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1606 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1584 }
1607 }
1585
1608
1586 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1609 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1587 {
1610 {
1588 /** This function is the last step of the TC execution workflow.
1611 /** This function is the last step of the TC execution workflow.
1589 *
1612 *
1590 * @param TC points to the TC being processed
1613 * @param TC points to the TC being processed
1591 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1614 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1592 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1615 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1593 * @param time is the time used to date the TC execution
1616 * @param time is the time used to date the TC execution
1594 *
1617 *
1595 */
1618 */
1596
1619
1597 unsigned char requestedMode;
1620 unsigned char requestedMode;
1598
1621
1599 if (result == LFR_SUCCESSFUL)
1622 if (result == LFR_SUCCESSFUL)
1600 {
1623 {
1601 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1624 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1602 &
1625 &
1603 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1626 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1604 )
1627 )
1605 {
1628 {
1606 send_tm_lfr_tc_exe_success( TC, queue_id );
1629 send_tm_lfr_tc_exe_success( TC, queue_id );
1607 }
1630 }
1608 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1631 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1609 {
1632 {
1610 //**********************************
1633 //**********************************
1611 // UPDATE THE LFRMODE LOCAL VARIABLE
1634 // UPDATE THE LFRMODE LOCAL VARIABLE
1612 requestedMode = TC->dataAndCRC[1];
1635 requestedMode = TC->dataAndCRC[1];
1613 updateLFRCurrentMode( requestedMode );
1636 updateLFRCurrentMode( requestedMode );
1614 }
1637 }
1615 }
1638 }
1616 else if (result == LFR_EXE_ERROR)
1639 else if (result == LFR_EXE_ERROR)
1617 {
1640 {
1618 send_tm_lfr_tc_exe_error( TC, queue_id );
1641 send_tm_lfr_tc_exe_error( TC, queue_id );
1619 }
1642 }
1620 }
1643 }
1621
1644
1622 //***************************
1645 //***************************
1623 // Interrupt Service Routines
1646 // Interrupt Service Routines
1624 rtems_isr commutation_isr1( rtems_vector_number vector )
1647 rtems_isr commutation_isr1( rtems_vector_number vector )
1625 {
1648 {
1626 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1649 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1627 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1650 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1628 }
1651 }
1629 }
1652 }
1630
1653
1631 rtems_isr commutation_isr2( rtems_vector_number vector )
1654 rtems_isr commutation_isr2( rtems_vector_number vector )
1632 {
1655 {
1633 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1656 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1634 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1657 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1635 }
1658 }
1636 }
1659 }
1637
1660
1638 //****************
1661 //****************
1639 // OTHER FUNCTIONS
1662 // OTHER FUNCTIONS
1640 void updateLFRCurrentMode( unsigned char requestedMode )
1663 void updateLFRCurrentMode( unsigned char requestedMode )
1641 {
1664 {
1642 /** This function updates the value of the global variable lfrCurrentMode.
1665 /** This function updates the value of the global variable lfrCurrentMode.
1643 *
1666 *
1644 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1667 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1645 *
1668 *
1646 */
1669 */
1647
1670
1648 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1671 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1649 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1672 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1650 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1673 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1651 lfrCurrentMode = requestedMode;
1674 lfrCurrentMode = requestedMode;
1652 }
1675 }
1653
1676
1654 void set_lfr_soft_reset( unsigned char value )
1677 void set_lfr_soft_reset( unsigned char value )
1655 {
1678 {
1656 if (value == 1)
1679 if (value == 1)
1657 {
1680 {
1658 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1681 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1659 }
1682 }
1660 else
1683 else
1661 {
1684 {
1662 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1685 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1663 }
1686 }
1664 }
1687 }
1665
1688
1666 void reset_lfr( void )
1689 void reset_lfr( void )
1667 {
1690 {
1668 set_lfr_soft_reset( 1 );
1691 set_lfr_soft_reset( 1 );
1669
1692
1670 set_lfr_soft_reset( 0 );
1693 set_lfr_soft_reset( 0 );
1671
1694
1672 set_hk_lfr_sc_potential_flag( true );
1695 set_hk_lfr_sc_potential_flag( true );
1673 }
1696 }
@@ -1,2068 +1,2088
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions to load and dump parameters in the LFR registers.
25 /** Functions to load and dump parameters in the LFR registers.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
30 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
31 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
32 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
33 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
34 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
35 * TC_LFR_LOAD_SBM2_PAR\n
12 *
36 *
13 */
37 */
14
38
15 #include "tc_load_dump_parameters.h"
39 #include "tc_load_dump_parameters.h"
16
40
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
41 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
42 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 ring_node kcoefficient_node_1 = {0};
43 ring_node kcoefficient_node_1 = {0};
20 ring_node kcoefficient_node_2 = {0};
44 ring_node kcoefficient_node_2 = {0};
21
45
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
46 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
47 {
24 /** This function updates the LFR registers with the incoming common parameters.
48 /** This function updates the LFR registers with the incoming common parameters.
25 *
49 *
26 * @param TC points to the TeleCommand packet that is being processed
50 * @param TC points to the TeleCommand packet that is being processed
27 *
51 *
28 *
52 *
29 */
53 */
30
54
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
55 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
56 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
57 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
58 return LFR_SUCCESSFUL;
35 }
59 }
36
60
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
61 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
62 {
39 /** This function updates the LFR registers with the incoming normal parameters.
63 /** This function updates the LFR registers with the incoming normal parameters.
40 *
64 *
41 * @param TC points to the TeleCommand packet that is being processed
65 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
66 * @param queue_id is the id of the queue which handles TM related to this execution step
43 *
67 *
44 */
68 */
45
69
46 int result;
70 int result;
47 int flag;
71 int flag;
48 rtems_status_code status;
72 rtems_status_code status;
49
73
50 flag = LFR_SUCCESSFUL;
74 flag = LFR_SUCCESSFUL;
51
75
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
76 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
77 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
78 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
79 flag = LFR_DEFAULT;
56 }
80 }
57
81
58 // CHECK THE PARAMETERS SET CONSISTENCY
82 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
83 if (flag == LFR_SUCCESSFUL)
60 {
84 {
61 flag = check_normal_par_consistency( TC, queue_id );
85 flag = check_normal_par_consistency( TC, queue_id );
62 }
86 }
63
87
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
88 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
89 if (flag == LFR_SUCCESSFUL)
66 {
90 {
67 result = set_sy_lfr_n_swf_l( TC );
91 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
92 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
93 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
94 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
95 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
96 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
97 }
74
98
75 return flag;
99 return flag;
76 }
100 }
77
101
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
102 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
103 {
80 /** This function updates the LFR registers with the incoming burst parameters.
104 /** This function updates the LFR registers with the incoming burst parameters.
81 *
105 *
82 * @param TC points to the TeleCommand packet that is being processed
106 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
107 * @param queue_id is the id of the queue which handles TM related to this execution step
84 *
108 *
85 */
109 */
86
110
87 int flag;
111 int flag;
88 rtems_status_code status;
112 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
113 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
114 unsigned char sy_lfr_b_bp_p1;
91 float aux;
115 float aux;
92
116
93 flag = LFR_SUCCESSFUL;
117 flag = LFR_SUCCESSFUL;
94
118
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
119 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
120 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
121 flag = LFR_DEFAULT;
98 }
122 }
99
123
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
124 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
125 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
126
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
127 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
128 if (flag == LFR_SUCCESSFUL)
105 {
129 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
130 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
131 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
132 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
133 flag = WRONG_APP_DATA;
110 }
134 }
111 }
135 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
136 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
137 if (flag == LFR_SUCCESSFUL)
114 {
138 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
139 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
140 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
141 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
142 flag = WRONG_APP_DATA;
119 }
143 }
120 }
144 }
121 //****************************************************************
145 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
146 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
147 if (flag == LFR_SUCCESSFUL)
124 {
148 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
149 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
150 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
151 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 if (aux > FLOAT_EQUAL_ZERO)
152 if (aux > FLOAT_EQUAL_ZERO)
129 {
153 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
154 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
155 flag = LFR_DEFAULT;
132 }
156 }
133 }
157 }
134
158
135 // SET THE PARAMETERS
159 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
160 if (flag == LFR_SUCCESSFUL)
137 {
161 {
138 flag = set_sy_lfr_b_bp_p0( TC );
162 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
163 flag = set_sy_lfr_b_bp_p1( TC );
140 }
164 }
141
165
142 return flag;
166 return flag;
143 }
167 }
144
168
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
169 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
170 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
171 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
172 *
149 * @param TC points to the TeleCommand packet that is being processed
173 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
174 * @param queue_id is the id of the queue which handles TM related to this execution step
151 *
175 *
152 */
176 */
153
177
154 int flag;
178 int flag;
155 rtems_status_code status;
179 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
180 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
181 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
182 float aux;
159
183
160 flag = LFR_SUCCESSFUL;
184 flag = LFR_SUCCESSFUL;
161
185
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
186 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
187 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
188 flag = LFR_DEFAULT;
165 }
189 }
166
190
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
191 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
192 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
193
170 // sy_lfr_s1_bp_p0
194 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
195 if (flag == LFR_SUCCESSFUL)
172 {
196 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
197 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
198 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
199 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
200 flag = WRONG_APP_DATA;
177 }
201 }
178 }
202 }
179 // sy_lfr_s1_bp_p1
203 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
204 if (flag == LFR_SUCCESSFUL)
181 {
205 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
206 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
207 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
208 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
209 flag = WRONG_APP_DATA;
186 }
210 }
187 }
211 }
188 //******************************************************************
212 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
213 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
214 if (flag == LFR_SUCCESSFUL)
191 {
215 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
216 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
217 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 if (aux > FLOAT_EQUAL_ZERO)
218 if (aux > FLOAT_EQUAL_ZERO)
195 {
219 {
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
220 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 flag = LFR_DEFAULT;
221 flag = LFR_DEFAULT;
198 }
222 }
199 }
223 }
200
224
201 // SET THE PARAMETERS
225 // SET THE PARAMETERS
202 if (flag == LFR_SUCCESSFUL)
226 if (flag == LFR_SUCCESSFUL)
203 {
227 {
204 flag = set_sy_lfr_s1_bp_p0( TC );
228 flag = set_sy_lfr_s1_bp_p0( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
229 flag = set_sy_lfr_s1_bp_p1( TC );
206 }
230 }
207
231
208 return flag;
232 return flag;
209 }
233 }
210
234
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
235 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 {
236 {
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
237 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 *
238 *
215 * @param TC points to the TeleCommand packet that is being processed
239 * @param TC points to the TeleCommand packet that is being processed
216 * @param queue_id is the id of the queue which handles TM related to this execution step
240 * @param queue_id is the id of the queue which handles TM related to this execution step
217 *
241 *
218 */
242 */
219
243
220 int flag;
244 int flag;
221 rtems_status_code status;
245 rtems_status_code status;
222 unsigned char sy_lfr_s2_bp_p0;
246 unsigned char sy_lfr_s2_bp_p0;
223 unsigned char sy_lfr_s2_bp_p1;
247 unsigned char sy_lfr_s2_bp_p1;
224 float aux;
248 float aux;
225
249
226 flag = LFR_SUCCESSFUL;
250 flag = LFR_SUCCESSFUL;
227
251
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
252 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
253 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 flag = LFR_DEFAULT;
254 flag = LFR_DEFAULT;
231 }
255 }
232
256
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235
259
236 // sy_lfr_s2_bp_p0
260 // sy_lfr_s2_bp_p0
237 if (flag == LFR_SUCCESSFUL)
261 if (flag == LFR_SUCCESSFUL)
238 {
262 {
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
263 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 {
264 {
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
265 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 flag = WRONG_APP_DATA;
266 flag = WRONG_APP_DATA;
243 }
267 }
244 }
268 }
245 // sy_lfr_s2_bp_p1
269 // sy_lfr_s2_bp_p1
246 if (flag == LFR_SUCCESSFUL)
270 if (flag == LFR_SUCCESSFUL)
247 {
271 {
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
272 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 {
273 {
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
274 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 flag = WRONG_APP_DATA;
275 flag = WRONG_APP_DATA;
252 }
276 }
253 }
277 }
254 //******************************************************************
278 //******************************************************************
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
279 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 if (flag == LFR_SUCCESSFUL)
280 if (flag == LFR_SUCCESSFUL)
257 {
281 {
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
282 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
283 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
284 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 if (aux > FLOAT_EQUAL_ZERO)
285 if (aux > FLOAT_EQUAL_ZERO)
262 {
286 {
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
287 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 flag = LFR_DEFAULT;
288 flag = LFR_DEFAULT;
265 }
289 }
266 }
290 }
267
291
268 // SET THE PARAMETERS
292 // SET THE PARAMETERS
269 if (flag == LFR_SUCCESSFUL)
293 if (flag == LFR_SUCCESSFUL)
270 {
294 {
271 flag = set_sy_lfr_s2_bp_p0( TC );
295 flag = set_sy_lfr_s2_bp_p0( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
296 flag = set_sy_lfr_s2_bp_p1( TC );
273 }
297 }
274
298
275 return flag;
299 return flag;
276 }
300 }
277
301
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
302 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 {
303 {
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
304 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 *
305 *
282 * @param TC points to the TeleCommand packet that is being processed
306 * @param TC points to the TeleCommand packet that is being processed
283 * @param queue_id is the id of the queue which handles TM related to this execution step
307 * @param queue_id is the id of the queue which handles TM related to this execution step
284 *
308 *
285 */
309 */
286
310
287 int flag;
311 int flag;
288
312
289 flag = LFR_DEFAULT;
313 flag = LFR_DEFAULT;
290
314
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
315 flag = set_sy_lfr_kcoeff( TC, queue_id );
292
316
293 return flag;
317 return flag;
294 }
318 }
295
319
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
320 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 {
321 {
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
322 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 *
323 *
300 * @param TC points to the TeleCommand packet that is being processed
324 * @param TC points to the TeleCommand packet that is being processed
301 * @param queue_id is the id of the queue which handles TM related to this execution step
325 * @param queue_id is the id of the queue which handles TM related to this execution step
302 *
326 *
303 */
327 */
304
328
305 int flag;
329 int flag;
306
330
307 flag = LFR_DEFAULT;
331 flag = LFR_DEFAULT;
308
332
309 flag = set_sy_lfr_fbins( TC );
333 flag = set_sy_lfr_fbins( TC );
310
334
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
335 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 merge_fbins_masks();
336 merge_fbins_masks();
313
337
314 return flag;
338 return flag;
315 }
339 }
316
340
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
341 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
342 {
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
343 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 *
344 *
321 * @param TC points to the TeleCommand packet that is being processed
345 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM related to this execution step
346 * @param queue_id is the id of the queue which handles TM related to this execution step
323 *
347 *
324 */
348 */
325
349
326 int flag;
350 int flag;
327 unsigned char k;
351 unsigned char k;
328
352
329 flag = LFR_DEFAULT;
353 flag = LFR_DEFAULT;
330 k = INIT_CHAR;
354 k = INIT_CHAR;
331
355
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
356 flag = check_sy_lfr_filter_parameters( TC, queue_id );
333
357
334 if (flag == LFR_SUCCESSFUL)
358 if (flag == LFR_SUCCESSFUL)
335 {
359 {
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
360 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
361 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
362 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
363 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
364 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
365 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
366 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
367 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
368 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
369 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
370 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
372 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
373 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
374 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
351
375
352 //****************************
376 //****************************
353 // store PAS filter parameters
377 // store PAS filter parameters
354
378
355 // sy_lfr_pas_filter_enabled
379 // sy_lfr_pas_filter_enabled
356 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
380 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
357 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
381 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
358
382
359 // sy_lfr_pas_filter_modulus
383 // sy_lfr_pas_filter_modulus
360 filterPar.modulus_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_modulus) * CONST_65536;
384 filterPar.modulus_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_modulus) * CONST_65536;
361
385
362 // sy_lfr_pas_filter_tbad
386 // sy_lfr_pas_filter_tbad
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
364 parameter_dump_packet.sy_lfr_pas_filter_tbad );
388 parameter_dump_packet.sy_lfr_pas_filter_tbad );
365 filterPar.tbad_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_tbad * CONST_65536);
389 filterPar.tbad_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_tbad * CONST_65536);
366
390
367 // sy_lfr_pas_filter_offset
391 // sy_lfr_pas_filter_offset
368 filterPar.offset_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_offset) * CONST_65536;
392 filterPar.offset_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_offset) * CONST_65536;
369
393
370 // sy_lfr_pas_filter_shift
394 // sy_lfr_pas_filter_shift
371 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
372 parameter_dump_packet.sy_lfr_pas_filter_shift );
396 parameter_dump_packet.sy_lfr_pas_filter_shift );
373 filterPar.shift_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_shift * CONST_65536);
397 filterPar.shift_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_shift * CONST_65536);
374
398
375 //****************************************************
399 //****************************************************
376 // store the parameter sy_lfr_sc_rw_delta_f as a float
400 // store the parameter sy_lfr_sc_rw_delta_f as a float
377 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
401 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
378 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
402 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
379
403
380 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
404 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
381 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
405 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
382 {
406 {
383 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
407 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
384 }
408 }
385
409
386 //***********************************************
410 //***********************************************
387 // store the parameter sy_lfr_rw.._k.. as a float
411 // store the parameter sy_lfr_rw.._k.. as a float
388 // rw1_k
412 // rw1_k
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
413 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
414 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
391 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
415 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
416 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
393 // rw2_k
417 // rw2_k
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
418 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
419 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
396 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
420 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
421 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
398 // rw3_k
422 // rw3_k
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
423 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
424 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
401 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
425 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
402 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
426 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
403 // rw4_k
427 // rw4_k
404 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
428 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
405 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
429 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
406 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
430 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
407 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
431 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
408
432
409 }
433 }
410
434
411 return flag;
435 return flag;
412 }
436 }
413
437
414 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
438 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
415 {
439 {
416 /** This function updates the LFR registers with the incoming sbm2 parameters.
440 /** This function updates the LFR registers with the incoming sbm2 parameters.
417 *
441 *
418 * @param TC points to the TeleCommand packet that is being processed
442 * @param TC points to the TeleCommand packet that is being processed
419 * @param queue_id is the id of the queue which handles TM related to this execution step
443 * @param queue_id is the id of the queue which handles TM related to this execution step
420 *
444 *
421 */
445 */
422
446
423 unsigned int address;
447 unsigned int address;
424 rtems_status_code status;
448 rtems_status_code status;
425 unsigned int freq;
449 unsigned int freq;
426 unsigned int bin;
450 unsigned int bin;
427 unsigned int coeff;
451 unsigned int coeff;
428 unsigned char *kCoeffPtr;
452 unsigned char *kCoeffPtr;
429 unsigned char *kCoeffDumpPtr;
453 unsigned char *kCoeffDumpPtr;
430
454
431 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
455 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
432 // F0 => 11 bins
456 // F0 => 11 bins
433 // F1 => 13 bins
457 // F1 => 13 bins
434 // F2 => 12 bins
458 // F2 => 12 bins
435 // 36 bins to dump in two packets (30 bins max per packet)
459 // 36 bins to dump in two packets (30 bins max per packet)
436
460
437 //*********
461 //*********
438 // PACKET 1
462 // PACKET 1
439 // 11 F0 bins, 13 F1 bins and 6 F2 bins
463 // 11 F0 bins, 13 F1 bins and 6 F2 bins
440 kcoefficients_dump_1.destinationID = TC->sourceID;
464 kcoefficients_dump_1.destinationID = TC->sourceID;
441 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
465 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
442 for( freq = 0;
466 for( freq = 0;
443 freq < NB_BINS_COMPRESSED_SM_F0;
467 freq < NB_BINS_COMPRESSED_SM_F0;
444 freq++ )
468 freq++ )
445 {
469 {
446 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
470 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
447 bin = freq;
471 bin = freq;
448 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
449 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
472 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
450 {
473 {
451 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
474 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
452 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
475 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
453 ]; // 2 for the kcoeff_frequency
476 ]; // 2 for the kcoeff_frequency
454 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
477 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
455 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
478 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
456 }
479 }
457 }
480 }
458 for( freq = NB_BINS_COMPRESSED_SM_F0;
481 for( freq = NB_BINS_COMPRESSED_SM_F0;
459 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
482 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
460 freq++ )
483 freq++ )
461 {
484 {
462 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
485 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
463 bin = freq - NB_BINS_COMPRESSED_SM_F0;
486 bin = freq - NB_BINS_COMPRESSED_SM_F0;
464 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
487 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
466 {
488 {
467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
489 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
468 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
490 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
469 ]; // 2 for the kcoeff_frequency
491 ]; // 2 for the kcoeff_frequency
470 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
492 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
471 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
493 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
472 }
494 }
473 }
495 }
474 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
496 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
475 freq < KCOEFF_BLK_NR_PKT1 ;
497 freq < KCOEFF_BLK_NR_PKT1 ;
476 freq++ )
498 freq++ )
477 {
499 {
478 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
500 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
479 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
501 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
480 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
481 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
502 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
482 {
503 {
483 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
504 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
484 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
505 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
485 ]; // 2 for the kcoeff_frequency
506 ]; // 2 for the kcoeff_frequency
486 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
507 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
487 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
508 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
488 }
509 }
489 }
510 }
490 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
511 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
491 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
512 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
492 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
513 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
493 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
514 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
494 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
515 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
495 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
516 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
496 // SEND DATA
517 // SEND DATA
497 kcoefficient_node_1.status = 1;
518 kcoefficient_node_1.status = 1;
498 address = (unsigned int) &kcoefficient_node_1;
519 address = (unsigned int) &kcoefficient_node_1;
499 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
520 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
500 if (status != RTEMS_SUCCESSFUL) {
521 if (status != RTEMS_SUCCESSFUL) {
501 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
522 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
502 }
523 }
503
524
504 //********
525 //********
505 // PACKET 2
526 // PACKET 2
506 // 6 F2 bins
527 // 6 F2 bins
507 kcoefficients_dump_2.destinationID = TC->sourceID;
528 kcoefficients_dump_2.destinationID = TC->sourceID;
508 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
529 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
509 for( freq = 0;
530 for( freq = 0;
510 freq < KCOEFF_BLK_NR_PKT2;
531 freq < KCOEFF_BLK_NR_PKT2;
511 freq++ )
532 freq++ )
512 {
533 {
513 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
534 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
514 bin = freq + KCOEFF_BLK_NR_PKT2;
535 bin = freq + KCOEFF_BLK_NR_PKT2;
515 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
516 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
536 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
517 {
537 {
518 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
538 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
519 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
539 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
520 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
540 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
521 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
541 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
522 }
542 }
523 }
543 }
524 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
544 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
525 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
545 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
526 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
546 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
527 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
547 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
528 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
548 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
529 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
549 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
530 // SEND DATA
550 // SEND DATA
531 kcoefficient_node_2.status = 1;
551 kcoefficient_node_2.status = 1;
532 address = (unsigned int) &kcoefficient_node_2;
552 address = (unsigned int) &kcoefficient_node_2;
533 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
553 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
534 if (status != RTEMS_SUCCESSFUL) {
554 if (status != RTEMS_SUCCESSFUL) {
535 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
555 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
536 }
556 }
537
557
538 return status;
558 return status;
539 }
559 }
540
560
541 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
561 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
542 {
562 {
543 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
563 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
544 *
564 *
545 * @param queue_id is the id of the queue which handles TM related to this execution step.
565 * @param queue_id is the id of the queue which handles TM related to this execution step.
546 *
566 *
547 * @return RTEMS directive status codes:
567 * @return RTEMS directive status codes:
548 * - RTEMS_SUCCESSFUL - message sent successfully
568 * - RTEMS_SUCCESSFUL - message sent successfully
549 * - RTEMS_INVALID_ID - invalid queue id
569 * - RTEMS_INVALID_ID - invalid queue id
550 * - RTEMS_INVALID_SIZE - invalid message size
570 * - RTEMS_INVALID_SIZE - invalid message size
551 * - RTEMS_INVALID_ADDRESS - buffer is NULL
571 * - RTEMS_INVALID_ADDRESS - buffer is NULL
552 * - RTEMS_UNSATISFIED - out of message buffers
572 * - RTEMS_UNSATISFIED - out of message buffers
553 * - RTEMS_TOO_MANY - queue s limit has been reached
573 * - RTEMS_TOO_MANY - queue s limit has been reached
554 *
574 *
555 */
575 */
556
576
557 int status;
577 int status;
558
578
559 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
579 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
560 parameter_dump_packet.destinationID = TC->sourceID;
580 parameter_dump_packet.destinationID = TC->sourceID;
561
581
562 // UPDATE TIME
582 // UPDATE TIME
563 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
583 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
564 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
584 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
565 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
585 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
566 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
586 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
567 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
587 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
568 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
588 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
569 // SEND DATA
589 // SEND DATA
570 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
590 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
571 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
591 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
572 if (status != RTEMS_SUCCESSFUL) {
592 if (status != RTEMS_SUCCESSFUL) {
573 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
593 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
574 }
594 }
575
595
576 return status;
596 return status;
577 }
597 }
578
598
579 //***********************
599 //***********************
580 // NORMAL MODE PARAMETERS
600 // NORMAL MODE PARAMETERS
581
601
582 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
602 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
583 {
603 {
584 unsigned char msb;
604 unsigned char msb;
585 unsigned char lsb;
605 unsigned char lsb;
586 int flag;
606 int flag;
587 float aux;
607 float aux;
588 rtems_status_code status;
608 rtems_status_code status;
589
609
590 unsigned int sy_lfr_n_swf_l;
610 unsigned int sy_lfr_n_swf_l;
591 unsigned int sy_lfr_n_swf_p;
611 unsigned int sy_lfr_n_swf_p;
592 unsigned int sy_lfr_n_asm_p;
612 unsigned int sy_lfr_n_asm_p;
593 unsigned char sy_lfr_n_bp_p0;
613 unsigned char sy_lfr_n_bp_p0;
594 unsigned char sy_lfr_n_bp_p1;
614 unsigned char sy_lfr_n_bp_p1;
595 unsigned char sy_lfr_n_cwf_long_f3;
615 unsigned char sy_lfr_n_cwf_long_f3;
596
616
597 flag = LFR_SUCCESSFUL;
617 flag = LFR_SUCCESSFUL;
598
618
599 //***************
619 //***************
600 // get parameters
620 // get parameters
601 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
621 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
602 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
622 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
603 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
623 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
604
624
605 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
625 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
606 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
626 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
607 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
627 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
608
628
609 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
629 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
610 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
630 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
611 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
631 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
612
632
613 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
633 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
614
634
615 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
635 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
616
636
617 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
637 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
618
638
619 //******************
639 //******************
620 // check consistency
640 // check consistency
621 // sy_lfr_n_swf_l
641 // sy_lfr_n_swf_l
622 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
642 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
623 {
643 {
624 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
644 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
625 flag = WRONG_APP_DATA;
645 flag = WRONG_APP_DATA;
626 }
646 }
627 // sy_lfr_n_swf_p
647 // sy_lfr_n_swf_p
628 if (flag == LFR_SUCCESSFUL)
648 if (flag == LFR_SUCCESSFUL)
629 {
649 {
630 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
650 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
631 {
651 {
632 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
652 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
633 flag = WRONG_APP_DATA;
653 flag = WRONG_APP_DATA;
634 }
654 }
635 }
655 }
636 // sy_lfr_n_bp_p0
656 // sy_lfr_n_bp_p0
637 if (flag == LFR_SUCCESSFUL)
657 if (flag == LFR_SUCCESSFUL)
638 {
658 {
639 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
659 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
640 {
660 {
641 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
661 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
642 flag = WRONG_APP_DATA;
662 flag = WRONG_APP_DATA;
643 }
663 }
644 }
664 }
645 // sy_lfr_n_asm_p
665 // sy_lfr_n_asm_p
646 if (flag == LFR_SUCCESSFUL)
666 if (flag == LFR_SUCCESSFUL)
647 {
667 {
648 if (sy_lfr_n_asm_p == 0)
668 if (sy_lfr_n_asm_p == 0)
649 {
669 {
650 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
670 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
651 flag = WRONG_APP_DATA;
671 flag = WRONG_APP_DATA;
652 }
672 }
653 }
673 }
654 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
674 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
655 if (flag == LFR_SUCCESSFUL)
675 if (flag == LFR_SUCCESSFUL)
656 {
676 {
657 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
677 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
658 if (aux > FLOAT_EQUAL_ZERO)
678 if (aux > FLOAT_EQUAL_ZERO)
659 {
679 {
660 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
680 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
661 flag = WRONG_APP_DATA;
681 flag = WRONG_APP_DATA;
662 }
682 }
663 }
683 }
664 // sy_lfr_n_bp_p1
684 // sy_lfr_n_bp_p1
665 if (flag == LFR_SUCCESSFUL)
685 if (flag == LFR_SUCCESSFUL)
666 {
686 {
667 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
687 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
668 {
688 {
669 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
689 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
670 flag = WRONG_APP_DATA;
690 flag = WRONG_APP_DATA;
671 }
691 }
672 }
692 }
673 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
693 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
674 if (flag == LFR_SUCCESSFUL)
694 if (flag == LFR_SUCCESSFUL)
675 {
695 {
676 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
696 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
677 if (aux > FLOAT_EQUAL_ZERO)
697 if (aux > FLOAT_EQUAL_ZERO)
678 {
698 {
679 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
699 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
680 flag = LFR_DEFAULT;
700 flag = LFR_DEFAULT;
681 }
701 }
682 }
702 }
683 // sy_lfr_n_cwf_long_f3
703 // sy_lfr_n_cwf_long_f3
684
704
685 return flag;
705 return flag;
686 }
706 }
687
707
688 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
708 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
689 {
709 {
690 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
710 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
691 *
711 *
692 * @param TC points to the TeleCommand packet that is being processed
712 * @param TC points to the TeleCommand packet that is being processed
693 * @param queue_id is the id of the queue which handles TM related to this execution step
713 * @param queue_id is the id of the queue which handles TM related to this execution step
694 *
714 *
695 */
715 */
696
716
697 int result;
717 int result;
698
718
699 result = LFR_SUCCESSFUL;
719 result = LFR_SUCCESSFUL;
700
720
701 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
721 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
702 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
722 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
703
723
704 return result;
724 return result;
705 }
725 }
706
726
707 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
727 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
708 {
728 {
709 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
729 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
710 *
730 *
711 * @param TC points to the TeleCommand packet that is being processed
731 * @param TC points to the TeleCommand packet that is being processed
712 * @param queue_id is the id of the queue which handles TM related to this execution step
732 * @param queue_id is the id of the queue which handles TM related to this execution step
713 *
733 *
714 */
734 */
715
735
716 int result;
736 int result;
717
737
718 result = LFR_SUCCESSFUL;
738 result = LFR_SUCCESSFUL;
719
739
720 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
740 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
721 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
741 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
722
742
723 return result;
743 return result;
724 }
744 }
725
745
726 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
746 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
727 {
747 {
728 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
748 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
729 *
749 *
730 * @param TC points to the TeleCommand packet that is being processed
750 * @param TC points to the TeleCommand packet that is being processed
731 * @param queue_id is the id of the queue which handles TM related to this execution step
751 * @param queue_id is the id of the queue which handles TM related to this execution step
732 *
752 *
733 */
753 */
734
754
735 int result;
755 int result;
736
756
737 result = LFR_SUCCESSFUL;
757 result = LFR_SUCCESSFUL;
738
758
739 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
759 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
740 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
760 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
741
761
742 return result;
762 return result;
743 }
763 }
744
764
745 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
765 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
746 {
766 {
747 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
767 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
748 *
768 *
749 * @param TC points to the TeleCommand packet that is being processed
769 * @param TC points to the TeleCommand packet that is being processed
750 * @param queue_id is the id of the queue which handles TM related to this execution step
770 * @param queue_id is the id of the queue which handles TM related to this execution step
751 *
771 *
752 */
772 */
753
773
754 int status;
774 int status;
755
775
756 status = LFR_SUCCESSFUL;
776 status = LFR_SUCCESSFUL;
757
777
758 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
778 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
759
779
760 return status;
780 return status;
761 }
781 }
762
782
763 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
783 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
764 {
784 {
765 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
785 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
766 *
786 *
767 * @param TC points to the TeleCommand packet that is being processed
787 * @param TC points to the TeleCommand packet that is being processed
768 * @param queue_id is the id of the queue which handles TM related to this execution step
788 * @param queue_id is the id of the queue which handles TM related to this execution step
769 *
789 *
770 */
790 */
771
791
772 int status;
792 int status;
773
793
774 status = LFR_SUCCESSFUL;
794 status = LFR_SUCCESSFUL;
775
795
776 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
796 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
777
797
778 return status;
798 return status;
779 }
799 }
780
800
781 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
801 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
782 {
802 {
783 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
803 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
784 *
804 *
785 * @param TC points to the TeleCommand packet that is being processed
805 * @param TC points to the TeleCommand packet that is being processed
786 * @param queue_id is the id of the queue which handles TM related to this execution step
806 * @param queue_id is the id of the queue which handles TM related to this execution step
787 *
807 *
788 */
808 */
789
809
790 int status;
810 int status;
791
811
792 status = LFR_SUCCESSFUL;
812 status = LFR_SUCCESSFUL;
793
813
794 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
814 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
795
815
796 return status;
816 return status;
797 }
817 }
798
818
799 //**********************
819 //**********************
800 // BURST MODE PARAMETERS
820 // BURST MODE PARAMETERS
801
821
802 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
822 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
803 {
823 {
804 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
824 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
805 *
825 *
806 * @param TC points to the TeleCommand packet that is being processed
826 * @param TC points to the TeleCommand packet that is being processed
807 * @param queue_id is the id of the queue which handles TM related to this execution step
827 * @param queue_id is the id of the queue which handles TM related to this execution step
808 *
828 *
809 */
829 */
810
830
811 int status;
831 int status;
812
832
813 status = LFR_SUCCESSFUL;
833 status = LFR_SUCCESSFUL;
814
834
815 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
835 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
816
836
817 return status;
837 return status;
818 }
838 }
819
839
820 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
840 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
821 {
841 {
822 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
842 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
823 *
843 *
824 * @param TC points to the TeleCommand packet that is being processed
844 * @param TC points to the TeleCommand packet that is being processed
825 * @param queue_id is the id of the queue which handles TM related to this execution step
845 * @param queue_id is the id of the queue which handles TM related to this execution step
826 *
846 *
827 */
847 */
828
848
829 int status;
849 int status;
830
850
831 status = LFR_SUCCESSFUL;
851 status = LFR_SUCCESSFUL;
832
852
833 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
853 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
834
854
835 return status;
855 return status;
836 }
856 }
837
857
838 //*********************
858 //*********************
839 // SBM1 MODE PARAMETERS
859 // SBM1 MODE PARAMETERS
840
860
841 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
861 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
842 {
862 {
843 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
863 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
844 *
864 *
845 * @param TC points to the TeleCommand packet that is being processed
865 * @param TC points to the TeleCommand packet that is being processed
846 * @param queue_id is the id of the queue which handles TM related to this execution step
866 * @param queue_id is the id of the queue which handles TM related to this execution step
847 *
867 *
848 */
868 */
849
869
850 int status;
870 int status;
851
871
852 status = LFR_SUCCESSFUL;
872 status = LFR_SUCCESSFUL;
853
873
854 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
874 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
855
875
856 return status;
876 return status;
857 }
877 }
858
878
859 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
879 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
860 {
880 {
861 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
881 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
862 *
882 *
863 * @param TC points to the TeleCommand packet that is being processed
883 * @param TC points to the TeleCommand packet that is being processed
864 * @param queue_id is the id of the queue which handles TM related to this execution step
884 * @param queue_id is the id of the queue which handles TM related to this execution step
865 *
885 *
866 */
886 */
867
887
868 int status;
888 int status;
869
889
870 status = LFR_SUCCESSFUL;
890 status = LFR_SUCCESSFUL;
871
891
872 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
892 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
873
893
874 return status;
894 return status;
875 }
895 }
876
896
877 //*********************
897 //*********************
878 // SBM2 MODE PARAMETERS
898 // SBM2 MODE PARAMETERS
879
899
880 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
900 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
881 {
901 {
882 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
902 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
883 *
903 *
884 * @param TC points to the TeleCommand packet that is being processed
904 * @param TC points to the TeleCommand packet that is being processed
885 * @param queue_id is the id of the queue which handles TM related to this execution step
905 * @param queue_id is the id of the queue which handles TM related to this execution step
886 *
906 *
887 */
907 */
888
908
889 int status;
909 int status;
890
910
891 status = LFR_SUCCESSFUL;
911 status = LFR_SUCCESSFUL;
892
912
893 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
913 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
894
914
895 return status;
915 return status;
896 }
916 }
897
917
898 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
918 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
899 {
919 {
900 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
920 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
901 *
921 *
902 * @param TC points to the TeleCommand packet that is being processed
922 * @param TC points to the TeleCommand packet that is being processed
903 * @param queue_id is the id of the queue which handles TM related to this execution step
923 * @param queue_id is the id of the queue which handles TM related to this execution step
904 *
924 *
905 */
925 */
906
926
907 int status;
927 int status;
908
928
909 status = LFR_SUCCESSFUL;
929 status = LFR_SUCCESSFUL;
910
930
911 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
931 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
912
932
913 return status;
933 return status;
914 }
934 }
915
935
916 //*******************
936 //*******************
917 // TC_LFR_UPDATE_INFO
937 // TC_LFR_UPDATE_INFO
918
938
919 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
939 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
920 {
940 {
921 unsigned int status;
941 unsigned int status;
922
942
923 status = LFR_DEFAULT;
943 status = LFR_DEFAULT;
924
944
925 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
945 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
926 || (mode == LFR_MODE_BURST)
946 || (mode == LFR_MODE_BURST)
927 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
947 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
928 {
948 {
929 status = LFR_SUCCESSFUL;
949 status = LFR_SUCCESSFUL;
930 }
950 }
931 else
951 else
932 {
952 {
933 status = LFR_DEFAULT;
953 status = LFR_DEFAULT;
934 }
954 }
935
955
936 return status;
956 return status;
937 }
957 }
938
958
939 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
959 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
940 {
960 {
941 unsigned int status;
961 unsigned int status;
942
962
943 status = LFR_DEFAULT;
963 status = LFR_DEFAULT;
944
964
945 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
965 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
946 || (mode == TDS_MODE_BURST)
966 || (mode == TDS_MODE_BURST)
947 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
967 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
948 || (mode == TDS_MODE_LFM))
968 || (mode == TDS_MODE_LFM))
949 {
969 {
950 status = LFR_SUCCESSFUL;
970 status = LFR_SUCCESSFUL;
951 }
971 }
952 else
972 else
953 {
973 {
954 status = LFR_DEFAULT;
974 status = LFR_DEFAULT;
955 }
975 }
956
976
957 return status;
977 return status;
958 }
978 }
959
979
960 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
980 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
961 {
981 {
962 unsigned int status;
982 unsigned int status;
963
983
964 status = LFR_DEFAULT;
984 status = LFR_DEFAULT;
965
985
966 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
986 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
967 || (mode == THR_MODE_BURST))
987 || (mode == THR_MODE_BURST))
968 {
988 {
969 status = LFR_SUCCESSFUL;
989 status = LFR_SUCCESSFUL;
970 }
990 }
971 else
991 else
972 {
992 {
973 status = LFR_DEFAULT;
993 status = LFR_DEFAULT;
974 }
994 }
975
995
976 return status;
996 return status;
977 }
997 }
978
998
979 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
999 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
980 {
1000 {
981 unsigned char flag;
1001 unsigned char flag;
982 unsigned char flagPosInByte;
1002 unsigned char flagPosInByte;
983 unsigned char newFlag;
1003 unsigned char newFlag;
984 unsigned char flagMask;
1004 unsigned char flagMask;
985
1005
986 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
1006 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
987 if (isnan(value))
1007 if (isnan(value))
988 {
1008 {
989 flag = FLAG_NAN;
1009 flag = FLAG_NAN;
990 }
1010 }
991 else
1011 else
992 {
1012 {
993 flag = FLAG_IAN;
1013 flag = FLAG_IAN;
994 }
1014 }
995
1015
996 switch(wheel)
1016 switch(wheel)
997 {
1017 {
998 case WHEEL_1:
1018 case WHEEL_1:
999 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1019 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1000 flagMask = ~(1 << flagPosInByte);
1020 flagMask = ~(1 << flagPosInByte);
1001 newFlag = flag << flagPosInByte;
1021 newFlag = flag << flagPosInByte;
1002 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1022 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1003 break;
1023 break;
1004 case WHEEL_2:
1024 case WHEEL_2:
1005 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1025 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1006 flagMask = ~(1 << flagPosInByte);
1026 flagMask = ~(1 << flagPosInByte);
1007 newFlag = flag << flagPosInByte;
1027 newFlag = flag << flagPosInByte;
1008 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1028 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1009 break;
1029 break;
1010 case WHEEL_3:
1030 case WHEEL_3:
1011 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1031 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1012 flagMask = ~(1 << flagPosInByte);
1032 flagMask = ~(1 << flagPosInByte);
1013 newFlag = flag << flagPosInByte;
1033 newFlag = flag << flagPosInByte;
1014 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1034 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1015 break;
1035 break;
1016 case WHEEL_4:
1036 case WHEEL_4:
1017 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1037 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1018 flagMask = ~(1 << flagPosInByte);
1038 flagMask = ~(1 << flagPosInByte);
1019 newFlag = flag << flagPosInByte;
1039 newFlag = flag << flagPosInByte;
1020 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1040 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1021 break;
1041 break;
1022 default:
1042 default:
1023 break;
1043 break;
1024 }
1044 }
1025 }
1045 }
1026
1046
1027 void set_hk_lfr_sc_rw_f_flags( void )
1047 void set_hk_lfr_sc_rw_f_flags( void )
1028 {
1048 {
1029 // RW1
1049 // RW1
1030 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1050 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1031 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1051 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1052 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1033 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1053 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1034
1054
1035 // RW2
1055 // RW2
1036 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1056 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1037 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1057 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1058 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1039 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1059 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1040
1060
1041 // RW3
1061 // RW3
1042 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1062 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1043 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1063 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1044 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1064 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1045 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1065 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1046
1066
1047 // RW4
1067 // RW4
1048 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1068 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1049 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1069 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1050 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1070 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1051 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1071 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1052 }
1072 }
1053
1073
1054 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1074 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1055 {
1075 {
1056 float rw_k;
1076 float rw_k;
1057 int ret;
1077 int ret;
1058
1078
1059 ret = LFR_SUCCESSFUL;
1079 ret = LFR_SUCCESSFUL;
1060 rw_k = INIT_FLOAT;
1080 rw_k = INIT_FLOAT;
1061
1081
1062 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->packetID[ offset ] );
1082 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->packetID[ offset ] );
1063
1083
1064 *pos = offset;
1084 *pos = offset;
1065 *value = rw_k;
1085 *value = rw_k;
1066
1086
1067 if (rw_k < MIN_SY_LFR_RW_F)
1087 if (rw_k < MIN_SY_LFR_RW_F)
1068 {
1088 {
1069 ret = WRONG_APP_DATA;
1089 ret = WRONG_APP_DATA;
1070 }
1090 }
1071
1091
1072 return ret;
1092 return ret;
1073 }
1093 }
1074
1094
1075 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1095 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1076 {
1096 {
1077 int ret;
1097 int ret;
1078
1098
1079 ret = LFR_SUCCESSFUL;
1099 ret = LFR_SUCCESSFUL;
1080
1100
1081 //****
1101 //****
1082 //****
1102 //****
1083 // RW1
1103 // RW1
1084 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1, pos, value ); // F1
1104 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1, pos, value ); // F1
1085 if (ret == LFR_SUCCESSFUL) // F2
1105 if (ret == LFR_SUCCESSFUL) // F2
1086 {
1106 {
1087 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2, pos, value );
1107 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2, pos, value );
1088 }
1108 }
1089 if (ret == LFR_SUCCESSFUL) // F3
1109 if (ret == LFR_SUCCESSFUL) // F3
1090 {
1110 {
1091 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3, pos, value );
1111 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3, pos, value );
1092 }
1112 }
1093 if (ret == LFR_SUCCESSFUL) // F4
1113 if (ret == LFR_SUCCESSFUL) // F4
1094 {
1114 {
1095 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4, pos, value );
1115 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4, pos, value );
1096 }
1116 }
1097
1117
1098 //****
1118 //****
1099 //****
1119 //****
1100 // RW2
1120 // RW2
1101 if (ret == LFR_SUCCESSFUL) // F1
1121 if (ret == LFR_SUCCESSFUL) // F1
1102 {
1122 {
1103 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1, pos, value );
1123 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1, pos, value );
1104 }
1124 }
1105 if (ret == LFR_SUCCESSFUL) // F2
1125 if (ret == LFR_SUCCESSFUL) // F2
1106 {
1126 {
1107 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2, pos, value );
1127 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2, pos, value );
1108 }
1128 }
1109 if (ret == LFR_SUCCESSFUL) // F3
1129 if (ret == LFR_SUCCESSFUL) // F3
1110 {
1130 {
1111 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3, pos, value );
1131 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3, pos, value );
1112 }
1132 }
1113 if (ret == LFR_SUCCESSFUL) // F4
1133 if (ret == LFR_SUCCESSFUL) // F4
1114 {
1134 {
1115 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4, pos, value );
1135 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4, pos, value );
1116 }
1136 }
1117
1137
1118 //****
1138 //****
1119 //****
1139 //****
1120 // RW3
1140 // RW3
1121 if (ret == LFR_SUCCESSFUL) // F1
1141 if (ret == LFR_SUCCESSFUL) // F1
1122 {
1142 {
1123 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1, pos, value );
1143 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1, pos, value );
1124 }
1144 }
1125 if (ret == LFR_SUCCESSFUL) // F2
1145 if (ret == LFR_SUCCESSFUL) // F2
1126 {
1146 {
1127 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2, pos, value );
1147 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2, pos, value );
1128 }
1148 }
1129 if (ret == LFR_SUCCESSFUL) // F3
1149 if (ret == LFR_SUCCESSFUL) // F3
1130 {
1150 {
1131 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3, pos, value );
1151 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3, pos, value );
1132 }
1152 }
1133 if (ret == LFR_SUCCESSFUL) // F4
1153 if (ret == LFR_SUCCESSFUL) // F4
1134 {
1154 {
1135 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4, pos, value );
1155 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4, pos, value );
1136 }
1156 }
1137
1157
1138 //****
1158 //****
1139 //****
1159 //****
1140 // RW4
1160 // RW4
1141 if (ret == LFR_SUCCESSFUL) // F1
1161 if (ret == LFR_SUCCESSFUL) // F1
1142 {
1162 {
1143 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1, pos, value );
1163 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1, pos, value );
1144 }
1164 }
1145 if (ret == LFR_SUCCESSFUL) // F2
1165 if (ret == LFR_SUCCESSFUL) // F2
1146 {
1166 {
1147 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2, pos, value );
1167 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2, pos, value );
1148 }
1168 }
1149 if (ret == LFR_SUCCESSFUL) // F3
1169 if (ret == LFR_SUCCESSFUL) // F3
1150 {
1170 {
1151 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3, pos, value );
1171 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3, pos, value );
1152 }
1172 }
1153 if (ret == LFR_SUCCESSFUL) // F4
1173 if (ret == LFR_SUCCESSFUL) // F4
1154 {
1174 {
1155 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4, pos, value );
1175 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4, pos, value );
1156 }
1176 }
1157
1177
1158 return ret;
1178 return ret;
1159 }
1179 }
1160
1180
1161 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1181 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1162 {
1182 {
1163 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1183 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1164 *
1184 *
1165 * @param TC points to the TeleCommand packet that is being processed
1185 * @param TC points to the TeleCommand packet that is being processed
1166 *
1186 *
1167 */
1187 */
1168
1188
1169 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1189 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1170
1190
1171 bytePosPtr = (unsigned char *) &TC->packetID;
1191 bytePosPtr = (unsigned char *) &TC->packetID;
1172
1192
1173 // rw1_f
1193 // rw1_f
1174 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1194 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1175 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1195 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1176 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1196 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1177 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1197 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1178
1198
1179 // rw2_f
1199 // rw2_f
1180 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1200 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1181 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1201 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1182 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1202 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1183 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1203 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1184
1204
1185 // rw3_f
1205 // rw3_f
1186 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1206 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1187 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1207 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1188 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1208 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1189 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1209 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1190
1210
1191 // rw4_f
1211 // rw4_f
1192 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1212 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1193 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1213 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1194 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1214 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1195 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1215 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1196
1216
1197 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1217 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1198
1218
1199 }
1219 }
1200
1220
1201 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1221 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1202 {
1222 {
1203 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1223 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1204 *
1224 *
1205 * @param fbins_mask
1225 * @param fbins_mask
1206 * @param rw_f is the reaction wheel frequency to filter
1226 * @param rw_f is the reaction wheel frequency to filter
1207 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1227 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1208 * @param flag [true] filtering enabled [false] filtering disabled
1228 * @param flag [true] filtering enabled [false] filtering disabled
1209 *
1229 *
1210 * @return void
1230 * @return void
1211 *
1231 *
1212 */
1232 */
1213
1233
1214 float f_RW_min;
1234 float f_RW_min;
1215 float f_RW_MAX;
1235 float f_RW_MAX;
1216 float fi_min;
1236 float fi_min;
1217 float fi_MAX;
1237 float fi_MAX;
1218 float fi;
1238 float fi;
1219 float deltaBelow;
1239 float deltaBelow;
1220 float deltaAbove;
1240 float deltaAbove;
1221 float freqToFilterOut;
1241 float freqToFilterOut;
1222 int binBelow;
1242 int binBelow;
1223 int binAbove;
1243 int binAbove;
1224 int closestBin;
1244 int closestBin;
1225 unsigned int whichByte;
1245 unsigned int whichByte;
1226 int selectedByte;
1246 int selectedByte;
1227 int bin;
1247 int bin;
1228 int binToRemove[NB_BINS_TO_REMOVE];
1248 int binToRemove[NB_BINS_TO_REMOVE];
1229 int k;
1249 int k;
1230 bool filteringSet;
1250 bool filteringSet;
1231
1251
1232 closestBin = 0;
1252 closestBin = 0;
1233 whichByte = 0;
1253 whichByte = 0;
1234 bin = 0;
1254 bin = 0;
1235 filteringSet = false;
1255 filteringSet = false;
1236
1256
1237 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1257 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1238 {
1258 {
1239 binToRemove[k] = -1;
1259 binToRemove[k] = -1;
1240 }
1260 }
1241
1261
1242 if (!isnan(rw_f))
1262 if (!isnan(rw_f))
1243 {
1263 {
1244 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1264 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1245 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1265 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1246 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1266 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1247
1267
1248 freqToFilterOut = f_RW_min;
1268 freqToFilterOut = f_RW_min;
1249 while ( filteringSet == false )
1269 while ( filteringSet == false )
1250 {
1270 {
1251 // compute the index of the frequency bin immediately below rw_f
1271 // compute the index of the frequency bin immediately below rw_f
1252 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1272 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1253 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1273 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1254
1274
1255 // compute the index of the frequency bin immediately above rw_f
1275 // compute the index of the frequency bin immediately above rw_f
1256 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1276 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1257 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1277 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1258
1278
1259 // search the closest bin
1279 // search the closest bin
1260 if (deltaAbove > deltaBelow)
1280 if (deltaAbove > deltaBelow)
1261 {
1281 {
1262 closestBin = binBelow;
1282 closestBin = binBelow;
1263 }
1283 }
1264 else
1284 else
1265 {
1285 {
1266 closestBin = binAbove;
1286 closestBin = binAbove;
1267 }
1287 }
1268
1288
1269 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1289 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1270 fi = closestBin * deltaFreq;
1290 fi = closestBin * deltaFreq;
1271 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1291 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1272 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1292 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1273
1293
1274 //**************************************************************************************
1294 //**************************************************************************************
1275 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1295 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1276 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1296 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1277 //**************************************************************************************
1297 //**************************************************************************************
1278
1298
1279 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1299 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1280 // => remove f_(i), f_(i-1) and f_(i+1)
1300 // => remove f_(i), f_(i-1) and f_(i+1)
1281 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1301 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1282 {
1302 {
1283 binToRemove[0] = (closestBin - 1) - 1;
1303 binToRemove[0] = (closestBin - 1) - 1;
1284 binToRemove[1] = (closestBin) - 1;
1304 binToRemove[1] = (closestBin) - 1;
1285 binToRemove[2] = (closestBin + 1) - 1;
1305 binToRemove[2] = (closestBin + 1) - 1;
1286 }
1306 }
1287 // 2. ELSE
1307 // 2. ELSE
1288 // => remove the two f_(i) which are around f_RW
1308 // => remove the two f_(i) which are around f_RW
1289 else
1309 else
1290 {
1310 {
1291 binToRemove[0] = (binBelow) - 1;
1311 binToRemove[0] = (binBelow) - 1;
1292 binToRemove[1] = (binAbove) - 1;
1312 binToRemove[1] = (binAbove) - 1;
1293 binToRemove[2] = (-1);
1313 binToRemove[2] = (-1);
1294 }
1314 }
1295
1315
1296 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1316 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1297 {
1317 {
1298 bin = binToRemove[k];
1318 bin = binToRemove[k];
1299 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1319 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1300 {
1320 {
1301 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1321 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1302 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1322 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1303 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1323 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1304 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1324 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1305
1325
1306 }
1326 }
1307 }
1327 }
1308
1328
1309 // update freqToFilterOut
1329 // update freqToFilterOut
1310 if ( freqToFilterOut == f_RW_MAX )
1330 if ( freqToFilterOut == f_RW_MAX )
1311 {
1331 {
1312 filteringSet = true; // end of the loop
1332 filteringSet = true; // end of the loop
1313 }
1333 }
1314 else
1334 else
1315 {
1335 {
1316 freqToFilterOut = freqToFilterOut + deltaFreq;
1336 freqToFilterOut = freqToFilterOut + deltaFreq;
1317 }
1337 }
1318
1338
1319 if ( freqToFilterOut > f_RW_MAX)
1339 if ( freqToFilterOut > f_RW_MAX)
1320 {
1340 {
1321 freqToFilterOut = f_RW_MAX;
1341 freqToFilterOut = f_RW_MAX;
1322 }
1342 }
1323 }
1343 }
1324 }
1344 }
1325 }
1345 }
1326
1346
1327 void build_sy_lfr_rw_mask( unsigned int channel )
1347 void build_sy_lfr_rw_mask( unsigned int channel )
1328 {
1348 {
1329 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1349 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1330 unsigned char *maskPtr;
1350 unsigned char *maskPtr;
1331 double deltaF;
1351 double deltaF;
1332 unsigned k;
1352 unsigned k;
1333
1353
1334 maskPtr = NULL;
1354 maskPtr = NULL;
1335 deltaF = DELTAF_F2;
1355 deltaF = DELTAF_F2;
1336
1356
1337 switch (channel)
1357 switch (channel)
1338 {
1358 {
1339 case CHANNELF0:
1359 case CHANNELF0:
1340 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1360 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1341 deltaF = DELTAF_F0;
1361 deltaF = DELTAF_F0;
1342 break;
1362 break;
1343 case CHANNELF1:
1363 case CHANNELF1:
1344 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1364 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1345 deltaF = DELTAF_F1;
1365 deltaF = DELTAF_F1;
1346 break;
1366 break;
1347 case CHANNELF2:
1367 case CHANNELF2:
1348 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1368 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1349 deltaF = DELTAF_F2;
1369 deltaF = DELTAF_F2;
1350 break;
1370 break;
1351 default:
1371 default:
1352 break;
1372 break;
1353 }
1373 }
1354
1374
1355 for (k = 0; k < BYTES_PER_MASK; k++)
1375 for (k = 0; k < BYTES_PER_MASK; k++)
1356 {
1376 {
1357 local_rw_fbins_mask[k] = INT8_ALL_F;
1377 local_rw_fbins_mask[k] = INT8_ALL_F;
1358 }
1378 }
1359
1379
1360 // RW1
1380 // RW1
1361 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1381 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1362 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1382 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1363 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1383 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1364 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1384 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1365
1385
1366 // RW2
1386 // RW2
1367 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1387 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1368 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1388 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1369 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1389 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1370 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1390 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1371
1391
1372 // RW3
1392 // RW3
1373 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1393 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1374 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1394 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1375 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1395 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1376 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1396 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1377
1397
1378 // RW4
1398 // RW4
1379 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1399 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1380 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1400 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1381 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1401 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1382 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1402 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1383
1403
1384 // update the value of the fbins related to reaction wheels frequency filtering
1404 // update the value of the fbins related to reaction wheels frequency filtering
1385 if (maskPtr != NULL)
1405 if (maskPtr != NULL)
1386 {
1406 {
1387 for (k = 0; k < BYTES_PER_MASK; k++)
1407 for (k = 0; k < BYTES_PER_MASK; k++)
1388 {
1408 {
1389 maskPtr[k] = local_rw_fbins_mask[k];
1409 maskPtr[k] = local_rw_fbins_mask[k];
1390 }
1410 }
1391 }
1411 }
1392 }
1412 }
1393
1413
1394 void build_sy_lfr_rw_masks( void )
1414 void build_sy_lfr_rw_masks( void )
1395 {
1415 {
1396 build_sy_lfr_rw_mask( CHANNELF0 );
1416 build_sy_lfr_rw_mask( CHANNELF0 );
1397 build_sy_lfr_rw_mask( CHANNELF1 );
1417 build_sy_lfr_rw_mask( CHANNELF1 );
1398 build_sy_lfr_rw_mask( CHANNELF2 );
1418 build_sy_lfr_rw_mask( CHANNELF2 );
1399 }
1419 }
1400
1420
1401 void merge_fbins_masks( void )
1421 void merge_fbins_masks( void )
1402 {
1422 {
1403 unsigned char k;
1423 unsigned char k;
1404
1424
1405 unsigned char *fbins_f0;
1425 unsigned char *fbins_f0;
1406 unsigned char *fbins_f1;
1426 unsigned char *fbins_f1;
1407 unsigned char *fbins_f2;
1427 unsigned char *fbins_f2;
1408 unsigned char *rw_mask_f0;
1428 unsigned char *rw_mask_f0;
1409 unsigned char *rw_mask_f1;
1429 unsigned char *rw_mask_f1;
1410 unsigned char *rw_mask_f2;
1430 unsigned char *rw_mask_f2;
1411
1431
1412 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1432 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1413 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1433 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1414 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1434 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1415 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1435 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1416 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1436 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1417 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1437 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1418
1438
1419 for( k=0; k < BYTES_PER_MASK; k++ )
1439 for( k=0; k < BYTES_PER_MASK; k++ )
1420 {
1440 {
1421 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1441 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1422 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1442 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1423 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1443 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1424 }
1444 }
1425 }
1445 }
1426
1446
1427 //***********
1447 //***********
1428 // FBINS MASK
1448 // FBINS MASK
1429
1449
1430 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1450 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1431 {
1451 {
1432 int status;
1452 int status;
1433 unsigned int k;
1453 unsigned int k;
1434 unsigned char *fbins_mask_dump;
1454 unsigned char *fbins_mask_dump;
1435 unsigned char *fbins_mask_TC;
1455 unsigned char *fbins_mask_TC;
1436
1456
1437 status = LFR_SUCCESSFUL;
1457 status = LFR_SUCCESSFUL;
1438
1458
1439 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1459 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1440 fbins_mask_TC = TC->dataAndCRC;
1460 fbins_mask_TC = TC->dataAndCRC;
1441
1461
1442 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1462 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1443 {
1463 {
1444 fbins_mask_dump[k] = fbins_mask_TC[k];
1464 fbins_mask_dump[k] = fbins_mask_TC[k];
1445 }
1465 }
1446
1466
1447 return status;
1467 return status;
1448 }
1468 }
1449
1469
1450 //***************************
1470 //***************************
1451 // TC_LFR_LOAD_PAS_FILTER_PAR
1471 // TC_LFR_LOAD_PAS_FILTER_PAR
1452
1472
1453 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1473 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1454 {
1474 {
1455 float rw_k;
1475 float rw_k;
1456 int ret;
1476 int ret;
1457
1477
1458 ret = LFR_SUCCESSFUL;
1478 ret = LFR_SUCCESSFUL;
1459 rw_k = INIT_FLOAT;
1479 rw_k = INIT_FLOAT;
1460
1480
1461 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1481 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1462
1482
1463 *pos = offset;
1483 *pos = offset;
1464 *value = rw_k;
1484 *value = rw_k;
1465
1485
1466 if (rw_k < MIN_SY_LFR_RW_F)
1486 if (rw_k < MIN_SY_LFR_RW_F)
1467 {
1487 {
1468 ret = WRONG_APP_DATA;
1488 ret = WRONG_APP_DATA;
1469 }
1489 }
1470
1490
1471 return ret;
1491 return ret;
1472 }
1492 }
1473
1493
1474 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float *value )
1494 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float *value )
1475 {
1495 {
1476 int ret;
1496 int ret;
1477
1497
1478 ret = LFR_SUCCESSFUL;
1498 ret = LFR_SUCCESSFUL;
1479
1499
1480 //****
1500 //****
1481 //****
1501 //****
1482 // RW1
1502 // RW1
1483 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1503 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1484 if (ret == LFR_SUCCESSFUL) // K2
1504 if (ret == LFR_SUCCESSFUL) // K2
1485 {
1505 {
1486 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1506 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1487 }
1507 }
1488 if (ret == LFR_SUCCESSFUL) // K3
1508 if (ret == LFR_SUCCESSFUL) // K3
1489 {
1509 {
1490 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1510 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1491 }
1511 }
1492 if (ret == LFR_SUCCESSFUL) // K4
1512 if (ret == LFR_SUCCESSFUL) // K4
1493 {
1513 {
1494 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1514 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1495 }
1515 }
1496
1516
1497 //****
1517 //****
1498 //****
1518 //****
1499 // RW2
1519 // RW2
1500 if (ret == LFR_SUCCESSFUL) // K1
1520 if (ret == LFR_SUCCESSFUL) // K1
1501 {
1521 {
1502 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1522 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1503 }
1523 }
1504 if (ret == LFR_SUCCESSFUL) // K2
1524 if (ret == LFR_SUCCESSFUL) // K2
1505 {
1525 {
1506 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1526 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1507 }
1527 }
1508 if (ret == LFR_SUCCESSFUL) // K3
1528 if (ret == LFR_SUCCESSFUL) // K3
1509 {
1529 {
1510 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1530 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1511 }
1531 }
1512 if (ret == LFR_SUCCESSFUL) // K4
1532 if (ret == LFR_SUCCESSFUL) // K4
1513 {
1533 {
1514 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1534 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1515 }
1535 }
1516
1536
1517 //****
1537 //****
1518 //****
1538 //****
1519 // RW3
1539 // RW3
1520 if (ret == LFR_SUCCESSFUL) // K1
1540 if (ret == LFR_SUCCESSFUL) // K1
1521 {
1541 {
1522 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1542 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1523 }
1543 }
1524 if (ret == LFR_SUCCESSFUL) // K2
1544 if (ret == LFR_SUCCESSFUL) // K2
1525 {
1545 {
1526 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1546 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1527 }
1547 }
1528 if (ret == LFR_SUCCESSFUL) // K3
1548 if (ret == LFR_SUCCESSFUL) // K3
1529 {
1549 {
1530 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1550 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1531 }
1551 }
1532 if (ret == LFR_SUCCESSFUL) // K4
1552 if (ret == LFR_SUCCESSFUL) // K4
1533 {
1553 {
1534 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1554 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1535 }
1555 }
1536
1556
1537 //****
1557 //****
1538 //****
1558 //****
1539 // RW4
1559 // RW4
1540 if (ret == LFR_SUCCESSFUL) // K1
1560 if (ret == LFR_SUCCESSFUL) // K1
1541 {
1561 {
1542 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1562 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1543 }
1563 }
1544 if (ret == LFR_SUCCESSFUL) // K2
1564 if (ret == LFR_SUCCESSFUL) // K2
1545 {
1565 {
1546 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1566 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1547 }
1567 }
1548 if (ret == LFR_SUCCESSFUL) // K3
1568 if (ret == LFR_SUCCESSFUL) // K3
1549 {
1569 {
1550 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1570 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1551 }
1571 }
1552 if (ret == LFR_SUCCESSFUL) // K4
1572 if (ret == LFR_SUCCESSFUL) // K4
1553 {
1573 {
1554 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1574 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1555 }
1575 }
1556
1576
1557 return ret;
1577 return ret;
1558 }
1578 }
1559
1579
1560 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1580 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1561 {
1581 {
1562 int flag;
1582 int flag;
1563 rtems_status_code status;
1583 rtems_status_code status;
1564
1584
1565 unsigned char sy_lfr_pas_filter_enabled;
1585 unsigned char sy_lfr_pas_filter_enabled;
1566 unsigned char sy_lfr_pas_filter_modulus;
1586 unsigned char sy_lfr_pas_filter_modulus;
1567 float sy_lfr_pas_filter_tbad;
1587 float sy_lfr_pas_filter_tbad;
1568 unsigned char sy_lfr_pas_filter_offset;
1588 unsigned char sy_lfr_pas_filter_offset;
1569 float sy_lfr_pas_filter_shift;
1589 float sy_lfr_pas_filter_shift;
1570 float sy_lfr_sc_rw_delta_f;
1590 float sy_lfr_sc_rw_delta_f;
1571 char *parPtr;
1591 char *parPtr;
1572 int datafield_pos;
1592 int datafield_pos;
1573 float rw_k;
1593 float rw_k;
1574
1594
1575 flag = LFR_SUCCESSFUL;
1595 flag = LFR_SUCCESSFUL;
1576 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1596 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1577 sy_lfr_pas_filter_shift = INIT_FLOAT;
1597 sy_lfr_pas_filter_shift = INIT_FLOAT;
1578 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1598 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1579 parPtr = NULL;
1599 parPtr = NULL;
1580 datafield_pos = INIT_INT;
1600 datafield_pos = INIT_INT;
1581 rw_k = INIT_FLOAT;
1601 rw_k = INIT_FLOAT;
1582
1602
1583 //***************
1603 //***************
1584 // get parameters
1604 // get parameters
1585 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1605 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1586 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1606 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1587 copyFloatByChar(
1607 copyFloatByChar(
1588 (unsigned char*) &sy_lfr_pas_filter_tbad,
1608 (unsigned char*) &sy_lfr_pas_filter_tbad,
1589 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1609 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1590 );
1610 );
1591 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1611 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1592 copyFloatByChar(
1612 copyFloatByChar(
1593 (unsigned char*) &sy_lfr_pas_filter_shift,
1613 (unsigned char*) &sy_lfr_pas_filter_shift,
1594 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1614 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1595 );
1615 );
1596 copyFloatByChar(
1616 copyFloatByChar(
1597 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1617 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1598 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1618 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1599 );
1619 );
1600
1620
1601 //******************
1621 //******************
1602 // CHECK CONSISTENCY
1622 // CHECK CONSISTENCY
1603
1623
1604 //**************************
1624 //**************************
1605 // sy_lfr_pas_filter_enabled
1625 // sy_lfr_pas_filter_enabled
1606 // nothing to check, value is 0 or 1
1626 // nothing to check, value is 0 or 1
1607
1627
1608 //**************************
1628 //**************************
1609 // sy_lfr_pas_filter_modulus
1629 // sy_lfr_pas_filter_modulus
1610 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1630 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1611 {
1631 {
1612 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1632 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1613 flag = WRONG_APP_DATA;
1633 flag = WRONG_APP_DATA;
1614 }
1634 }
1615
1635
1616 //***********************
1636 //***********************
1617 // sy_lfr_pas_filter_tbad
1637 // sy_lfr_pas_filter_tbad
1618 if (flag == LFR_SUCCESSFUL)
1638 if (flag == LFR_SUCCESSFUL)
1619 {
1639 {
1620 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1640 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1621 {
1641 {
1622 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1642 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1623 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1624 flag = WRONG_APP_DATA;
1644 flag = WRONG_APP_DATA;
1625 }
1645 }
1626 }
1646 }
1627
1647
1628 //*************************
1648 //*************************
1629 // sy_lfr_pas_filter_offset
1649 // sy_lfr_pas_filter_offset
1630 if (flag == LFR_SUCCESSFUL)
1650 if (flag == LFR_SUCCESSFUL)
1631 {
1651 {
1632 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1652 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1633 {
1653 {
1634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1654 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1635 flag = WRONG_APP_DATA;
1655 flag = WRONG_APP_DATA;
1636 }
1656 }
1637 }
1657 }
1638
1658
1639 //************************
1659 //************************
1640 // sy_lfr_pas_filter_shift
1660 // sy_lfr_pas_filter_shift
1641 if (flag == LFR_SUCCESSFUL)
1661 if (flag == LFR_SUCCESSFUL)
1642 {
1662 {
1643 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1663 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1644 {
1664 {
1645 parPtr = (char*) &sy_lfr_pas_filter_shift;
1665 parPtr = (char*) &sy_lfr_pas_filter_shift;
1646 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1666 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1647 flag = WRONG_APP_DATA;
1667 flag = WRONG_APP_DATA;
1648 }
1668 }
1649 }
1669 }
1650
1670
1651 //*************************************
1671 //*************************************
1652 // check global coherency of the values
1672 // check global coherency of the values
1653 if (flag == LFR_SUCCESSFUL)
1673 if (flag == LFR_SUCCESSFUL)
1654 {
1674 {
1655 if ( (sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) >= sy_lfr_pas_filter_modulus )
1675 if ( (sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) >= sy_lfr_pas_filter_modulus )
1656 {
1676 {
1657 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1677 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1658 flag = WRONG_APP_DATA;
1678 flag = WRONG_APP_DATA;
1659 }
1679 }
1660 }
1680 }
1661
1681
1662 //*********************
1682 //*********************
1663 // sy_lfr_sc_rw_delta_f
1683 // sy_lfr_sc_rw_delta_f
1664 if (flag == LFR_SUCCESSFUL)
1684 if (flag == LFR_SUCCESSFUL)
1665 {
1685 {
1666 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1686 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1667 {
1687 {
1668 parPtr = (char*) &sy_lfr_sc_rw_delta_f;
1688 parPtr = (char*) &sy_lfr_sc_rw_delta_f;
1669 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1689 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1670 flag = WRONG_APP_DATA;
1690 flag = WRONG_APP_DATA;
1671 }
1691 }
1672 }
1692 }
1673
1693
1674 //************
1694 //************
1675 // sy_lfr_rw_k
1695 // sy_lfr_rw_k
1676 if (flag == LFR_SUCCESSFUL)
1696 if (flag == LFR_SUCCESSFUL)
1677 {
1697 {
1678 flag = check_all_sy_lfr_rw_k( TC, &datafield_pos, &rw_k );
1698 flag = check_all_sy_lfr_rw_k( TC, &datafield_pos, &rw_k );
1679 if (flag != LFR_SUCCESSFUL)
1699 if (flag != LFR_SUCCESSFUL)
1680 {
1700 {
1681 parPtr = (char*) &sy_lfr_pas_filter_shift;
1701 parPtr = (char*) &sy_lfr_pas_filter_shift;
1682 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, datafield_pos + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1702 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, datafield_pos + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1683 }
1703 }
1684 }
1704 }
1685
1705
1686 return flag;
1706 return flag;
1687 }
1707 }
1688
1708
1689 //**************
1709 //**************
1690 // KCOEFFICIENTS
1710 // KCOEFFICIENTS
1691 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1711 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1692 {
1712 {
1693 unsigned int kcoeff;
1713 unsigned int kcoeff;
1694 unsigned short sy_lfr_kcoeff_frequency;
1714 unsigned short sy_lfr_kcoeff_frequency;
1695 unsigned short bin;
1715 unsigned short bin;
1696 float *kcoeffPtr_norm;
1716 float *kcoeffPtr_norm;
1697 float *kcoeffPtr_sbm;
1717 float *kcoeffPtr_sbm;
1698 int status;
1718 int status;
1699 unsigned char *kcoeffLoadPtr;
1719 unsigned char *kcoeffLoadPtr;
1700 unsigned char *kcoeffNormPtr;
1720 unsigned char *kcoeffNormPtr;
1701 unsigned char *kcoeffSbmPtr_a;
1721 unsigned char *kcoeffSbmPtr_a;
1702 unsigned char *kcoeffSbmPtr_b;
1722 unsigned char *kcoeffSbmPtr_b;
1703
1723
1704 sy_lfr_kcoeff_frequency = 0;
1724 sy_lfr_kcoeff_frequency = 0;
1705 bin = 0;
1725 bin = 0;
1706 kcoeffPtr_norm = NULL;
1726 kcoeffPtr_norm = NULL;
1707 kcoeffPtr_sbm = NULL;
1727 kcoeffPtr_sbm = NULL;
1708 status = LFR_SUCCESSFUL;
1728 status = LFR_SUCCESSFUL;
1709
1729
1710 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1730 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1711 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1731 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1712
1732
1713
1733
1714 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1734 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1715 {
1735 {
1716 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1736 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1717 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET,
1737 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET,
1718 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1738 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1719 status = LFR_DEFAULT;
1739 status = LFR_DEFAULT;
1720 }
1740 }
1721 else
1741 else
1722 {
1742 {
1723 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1743 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1724 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1744 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1725 {
1745 {
1726 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1746 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1727 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1747 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1728 bin = sy_lfr_kcoeff_frequency;
1748 bin = sy_lfr_kcoeff_frequency;
1729 }
1749 }
1730 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1750 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1731 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1751 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1732 {
1752 {
1733 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1753 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1734 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1754 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1735 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1755 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1736 }
1756 }
1737 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1757 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1738 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1758 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1739 {
1759 {
1740 kcoeffPtr_norm = k_coeff_intercalib_f2;
1760 kcoeffPtr_norm = k_coeff_intercalib_f2;
1741 kcoeffPtr_sbm = NULL;
1761 kcoeffPtr_sbm = NULL;
1742 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1762 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1743 }
1763 }
1744 }
1764 }
1745
1765
1746 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1766 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1747 {
1767 {
1748 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1768 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1749 {
1769 {
1750 // destination
1770 // destination
1751 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1771 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1752 // source
1772 // source
1753 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1773 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1754 // copy source to destination
1774 // copy source to destination
1755 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1775 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1756 }
1776 }
1757 }
1777 }
1758
1778
1759 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1779 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1760 {
1780 {
1761 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1781 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1762 {
1782 {
1763 // destination
1783 // destination
1764 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1784 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1765 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1785 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1766 // source
1786 // source
1767 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1787 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1768 // copy source to destination
1788 // copy source to destination
1769 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1789 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1770 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1790 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1771 }
1791 }
1772 }
1792 }
1773
1793
1774 // print_k_coeff();
1794 // print_k_coeff();
1775
1795
1776 return status;
1796 return status;
1777 }
1797 }
1778
1798
1779 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1799 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1780 {
1800 {
1781 destination[BYTE_0] = source[BYTE_0];
1801 destination[BYTE_0] = source[BYTE_0];
1782 destination[BYTE_1] = source[BYTE_1];
1802 destination[BYTE_1] = source[BYTE_1];
1783 destination[BYTE_2] = source[BYTE_2];
1803 destination[BYTE_2] = source[BYTE_2];
1784 destination[BYTE_3] = source[BYTE_3];
1804 destination[BYTE_3] = source[BYTE_3];
1785 }
1805 }
1786
1806
1787 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1807 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1788 {
1808 {
1789 destination[BYTE_0] = source[BYTE_0];
1809 destination[BYTE_0] = source[BYTE_0];
1790 destination[BYTE_1] = source[BYTE_1];
1810 destination[BYTE_1] = source[BYTE_1];
1791 destination[BYTE_2] = source[BYTE_2];
1811 destination[BYTE_2] = source[BYTE_2];
1792 destination[BYTE_3] = source[BYTE_3];
1812 destination[BYTE_3] = source[BYTE_3];
1793 }
1813 }
1794
1814
1795 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1815 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1796 {
1816 {
1797 destination[BYTE_0] = source[BYTE_0];
1817 destination[BYTE_0] = source[BYTE_0];
1798 destination[BYTE_1] = source[BYTE_1];
1818 destination[BYTE_1] = source[BYTE_1];
1799 }
1819 }
1800
1820
1801 void floatToChar( float value, unsigned char* ptr)
1821 void floatToChar( float value, unsigned char* ptr)
1802 {
1822 {
1803 unsigned char* valuePtr;
1823 unsigned char* valuePtr;
1804
1824
1805 valuePtr = (unsigned char*) &value;
1825 valuePtr = (unsigned char*) &value;
1806
1826
1807 ptr[BYTE_0] = valuePtr[BYTE_0];
1827 ptr[BYTE_0] = valuePtr[BYTE_0];
1808 ptr[BYTE_1] = valuePtr[BYTE_1];
1828 ptr[BYTE_1] = valuePtr[BYTE_1];
1809 ptr[BYTE_2] = valuePtr[BYTE_2];
1829 ptr[BYTE_2] = valuePtr[BYTE_2];
1810 ptr[BYTE_3] = valuePtr[BYTE_3];
1830 ptr[BYTE_3] = valuePtr[BYTE_3];
1811 }
1831 }
1812
1832
1813 //**********
1833 //**********
1814 // init dump
1834 // init dump
1815
1835
1816 void init_parameter_dump( void )
1836 void init_parameter_dump( void )
1817 {
1837 {
1818 /** This function initialize the parameter_dump_packet global variable with default values.
1838 /** This function initialize the parameter_dump_packet global variable with default values.
1819 *
1839 *
1820 */
1840 */
1821
1841
1822 unsigned int k;
1842 unsigned int k;
1823
1843
1824 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1844 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1825 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1845 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1826 parameter_dump_packet.reserved = CCSDS_RESERVED;
1846 parameter_dump_packet.reserved = CCSDS_RESERVED;
1827 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1847 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1828 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1848 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1829 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1849 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1830 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1850 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1831 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1851 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1832 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1852 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1833 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1853 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1834 // DATA FIELD HEADER
1854 // DATA FIELD HEADER
1835 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1855 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1836 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1856 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1837 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1857 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1838 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1858 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1839 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1859 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1840 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1860 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1841 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1861 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1842 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1862 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1843 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1863 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1844 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1864 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1845 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1865 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1846
1866
1847 //******************
1867 //******************
1848 // COMMON PARAMETERS
1868 // COMMON PARAMETERS
1849 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1869 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1850 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1870 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1851
1871
1852 //******************
1872 //******************
1853 // NORMAL PARAMETERS
1873 // NORMAL PARAMETERS
1854 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1874 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1855 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1875 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1856 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1876 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1857 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1877 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1858 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1878 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1859 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1879 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1860 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1880 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1861 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1881 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1862 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1882 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1863
1883
1864 //*****************
1884 //*****************
1865 // BURST PARAMETERS
1885 // BURST PARAMETERS
1866 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1886 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1867 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1887 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1868
1888
1869 //****************
1889 //****************
1870 // SBM1 PARAMETERS
1890 // SBM1 PARAMETERS
1871 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1891 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1872 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1892 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1873
1893
1874 //****************
1894 //****************
1875 // SBM2 PARAMETERS
1895 // SBM2 PARAMETERS
1876 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1896 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1877 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1897 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1878
1898
1879 //************
1899 //************
1880 // FBINS MASKS
1900 // FBINS MASKS
1881 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1901 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1882 {
1902 {
1883 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1903 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1884 }
1904 }
1885
1905
1886 // PAS FILTER PARAMETERS
1906 // PAS FILTER PARAMETERS
1887 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1907 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1888 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1908 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1889 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1909 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1890 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1910 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1891 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1911 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1892 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1912 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1893 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1913 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1894
1914
1895 // RW1_K
1915 // RW1_K
1896 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1916 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1897 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1917 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1898 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1918 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1899 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1919 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1900 // RW2_K
1920 // RW2_K
1901 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1921 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1902 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1922 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1903 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1923 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1904 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1924 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1905 // RW3_K
1925 // RW3_K
1906 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1926 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1907 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1927 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1908 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1928 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1909 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1929 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1910 // RW4_K
1930 // RW4_K
1911 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1931 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1912 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1932 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1913 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1933 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1914 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1934 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1915
1935
1916 // LFR_RW_MASK
1936 // LFR_RW_MASK
1917 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1937 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1918 {
1938 {
1919 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1939 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1920 }
1940 }
1921
1941
1922 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1942 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1923 merge_fbins_masks();
1943 merge_fbins_masks();
1924 }
1944 }
1925
1945
1926 void init_kcoefficients_dump( void )
1946 void init_kcoefficients_dump( void )
1927 {
1947 {
1928 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1948 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1929 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1949 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1930
1950
1931 kcoefficient_node_1.previous = NULL;
1951 kcoefficient_node_1.previous = NULL;
1932 kcoefficient_node_1.next = NULL;
1952 kcoefficient_node_1.next = NULL;
1933 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1953 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1934 kcoefficient_node_1.coarseTime = INIT_CHAR;
1954 kcoefficient_node_1.coarseTime = INIT_CHAR;
1935 kcoefficient_node_1.fineTime = INIT_CHAR;
1955 kcoefficient_node_1.fineTime = INIT_CHAR;
1936 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1956 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1937 kcoefficient_node_1.status = INIT_CHAR;
1957 kcoefficient_node_1.status = INIT_CHAR;
1938
1958
1939 kcoefficient_node_2.previous = NULL;
1959 kcoefficient_node_2.previous = NULL;
1940 kcoefficient_node_2.next = NULL;
1960 kcoefficient_node_2.next = NULL;
1941 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1961 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1942 kcoefficient_node_2.coarseTime = INIT_CHAR;
1962 kcoefficient_node_2.coarseTime = INIT_CHAR;
1943 kcoefficient_node_2.fineTime = INIT_CHAR;
1963 kcoefficient_node_2.fineTime = INIT_CHAR;
1944 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1964 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1945 kcoefficient_node_2.status = INIT_CHAR;
1965 kcoefficient_node_2.status = INIT_CHAR;
1946 }
1966 }
1947
1967
1948 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1968 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1949 {
1969 {
1950 unsigned int k;
1970 unsigned int k;
1951 unsigned int packetLength;
1971 unsigned int packetLength;
1952
1972
1953 packetLength =
1973 packetLength =
1954 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1974 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1955
1975
1956 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1976 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1957 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1977 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1958 kcoefficients_dump->reserved = CCSDS_RESERVED;
1978 kcoefficients_dump->reserved = CCSDS_RESERVED;
1959 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1979 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1960 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1980 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1961 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1981 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1962 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1982 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1963 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1983 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1964 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1984 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1965 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1985 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1966 // DATA FIELD HEADER
1986 // DATA FIELD HEADER
1967 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1987 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1968 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1988 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1969 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1989 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1970 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1990 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1971 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1991 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1972 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1992 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1973 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1993 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1974 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1994 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1975 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1995 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1976 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1996 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1977 kcoefficients_dump->sid = SID_K_DUMP;
1997 kcoefficients_dump->sid = SID_K_DUMP;
1978
1998
1979 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1999 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1980 kcoefficients_dump->pkt_nr = PKTNR_1;
2000 kcoefficients_dump->pkt_nr = PKTNR_1;
1981 kcoefficients_dump->blk_nr = blk_nr;
2001 kcoefficients_dump->blk_nr = blk_nr;
1982
2002
1983 //******************
2003 //******************
1984 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
2004 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1985 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
2005 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1986 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
2006 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1987 {
2007 {
1988 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
2008 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1989 }
2009 }
1990 }
2010 }
1991
2011
1992 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
2012 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1993 {
2013 {
1994 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
2014 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1995 *
2015 *
1996 * @param packet_sequence_control points to the packet sequence control which will be incremented
2016 * @param packet_sequence_control points to the packet sequence control which will be incremented
1997 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
2017 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1998 *
2018 *
1999 * If the destination ID is not known, a dedicated counter is incremented.
2019 * If the destination ID is not known, a dedicated counter is incremented.
2000 *
2020 *
2001 */
2021 */
2002
2022
2003 unsigned short sequence_cnt;
2023 unsigned short sequence_cnt;
2004 unsigned short segmentation_grouping_flag;
2024 unsigned short segmentation_grouping_flag;
2005 unsigned short new_packet_sequence_control;
2025 unsigned short new_packet_sequence_control;
2006 unsigned char i;
2026 unsigned char i;
2007
2027
2008 switch (destination_id)
2028 switch (destination_id)
2009 {
2029 {
2010 case SID_TC_GROUND:
2030 case SID_TC_GROUND:
2011 i = GROUND;
2031 i = GROUND;
2012 break;
2032 break;
2013 case SID_TC_MISSION_TIMELINE:
2033 case SID_TC_MISSION_TIMELINE:
2014 i = MISSION_TIMELINE;
2034 i = MISSION_TIMELINE;
2015 break;
2035 break;
2016 case SID_TC_TC_SEQUENCES:
2036 case SID_TC_TC_SEQUENCES:
2017 i = TC_SEQUENCES;
2037 i = TC_SEQUENCES;
2018 break;
2038 break;
2019 case SID_TC_RECOVERY_ACTION_CMD:
2039 case SID_TC_RECOVERY_ACTION_CMD:
2020 i = RECOVERY_ACTION_CMD;
2040 i = RECOVERY_ACTION_CMD;
2021 break;
2041 break;
2022 case SID_TC_BACKUP_MISSION_TIMELINE:
2042 case SID_TC_BACKUP_MISSION_TIMELINE:
2023 i = BACKUP_MISSION_TIMELINE;
2043 i = BACKUP_MISSION_TIMELINE;
2024 break;
2044 break;
2025 case SID_TC_DIRECT_CMD:
2045 case SID_TC_DIRECT_CMD:
2026 i = DIRECT_CMD;
2046 i = DIRECT_CMD;
2027 break;
2047 break;
2028 case SID_TC_SPARE_GRD_SRC1:
2048 case SID_TC_SPARE_GRD_SRC1:
2029 i = SPARE_GRD_SRC1;
2049 i = SPARE_GRD_SRC1;
2030 break;
2050 break;
2031 case SID_TC_SPARE_GRD_SRC2:
2051 case SID_TC_SPARE_GRD_SRC2:
2032 i = SPARE_GRD_SRC2;
2052 i = SPARE_GRD_SRC2;
2033 break;
2053 break;
2034 case SID_TC_OBCP:
2054 case SID_TC_OBCP:
2035 i = OBCP;
2055 i = OBCP;
2036 break;
2056 break;
2037 case SID_TC_SYSTEM_CONTROL:
2057 case SID_TC_SYSTEM_CONTROL:
2038 i = SYSTEM_CONTROL;
2058 i = SYSTEM_CONTROL;
2039 break;
2059 break;
2040 case SID_TC_AOCS:
2060 case SID_TC_AOCS:
2041 i = AOCS;
2061 i = AOCS;
2042 break;
2062 break;
2043 case SID_TC_RPW_INTERNAL:
2063 case SID_TC_RPW_INTERNAL:
2044 i = RPW_INTERNAL;
2064 i = RPW_INTERNAL;
2045 break;
2065 break;
2046 default:
2066 default:
2047 i = GROUND;
2067 i = GROUND;
2048 break;
2068 break;
2049 }
2069 }
2050
2070
2051 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
2071 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
2052 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
2072 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
2053
2073
2054 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
2074 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
2055
2075
2056 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
2076 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
2057 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
2077 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
2058
2078
2059 // increment the sequence counter
2079 // increment the sequence counter
2060 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
2080 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
2061 {
2081 {
2062 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
2082 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
2063 }
2083 }
2064 else
2084 else
2065 {
2085 {
2066 sequenceCounters_TM_DUMP[ i ] = 0;
2086 sequenceCounters_TM_DUMP[ i ] = 0;
2067 }
2087 }
2068 }
2088 }
@@ -1,514 +1,536
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions to send TM packets related to TC parsing and execution.
25 /** Functions to send TM packets related to TC parsing and execution.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to send appropriate TM packets after parsing and execution:
30 * A group of functions to send appropriate TM packets after parsing and execution:
7 * - TM_LFR_TC_EXE_SUCCESS
31 * - TM_LFR_TC_EXE_SUCCESS
8 * - TM_LFR_TC_EXE_INCONSISTENT
32 * - TM_LFR_TC_EXE_INCONSISTENT
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
33 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
34 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 * - TM_LFR_TC_EXE_ERROR
35 * - TM_LFR_TC_EXE_ERROR
12 * - TM_LFR_TC_EXE_CORRUPTED
36 * - TM_LFR_TC_EXE_CORRUPTED
13 *
37 *
14 */
38 */
15
39
16 #include "tm_lfr_tc_exe.h"
40 #include "tm_lfr_tc_exe.h"
17
41
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
42 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 {
43 {
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
44 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 *
45 *
22 * @param TC points to the TeleCommand packet that is being processed
46 * @param TC points to the TeleCommand packet that is being processed
23 * @param queue_id is the id of the queue which handles TM
47 * @param queue_id is the id of the queue which handles TM
24 *
48 *
25 * @return RTEMS directive status code:
49 * @return RTEMS directive status code:
26 * - RTEMS_SUCCESSFUL - message sent successfully
50 * - RTEMS_SUCCESSFUL - message sent successfully
27 * - RTEMS_INVALID_ID - invalid queue id
51 * - RTEMS_INVALID_ID - invalid queue id
28 * - RTEMS_INVALID_SIZE - invalid message size
52 * - RTEMS_INVALID_SIZE - invalid message size
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
53 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 * - RTEMS_UNSATISFIED - out of message buffers
54 * - RTEMS_UNSATISFIED - out of message buffers
31 * - RTEMS_TOO_MANY - queue s limit has been reached
55 * - RTEMS_TOO_MANY - queue s limit has been reached
32 *
56 *
33 */
57 */
34
58
35 rtems_status_code status;
59 rtems_status_code status;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
60 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 unsigned char messageSize;
61 unsigned char messageSize;
38
62
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
63 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
64 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 TM.reserved = DEFAULT_RESERVED;
65 TM.reserved = DEFAULT_RESERVED;
42 TM.userApplication = CCSDS_USER_APP;
66 TM.userApplication = CCSDS_USER_APP;
43 // PACKET HEADER
67 // PACKET HEADER
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
68 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
69 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
70 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
71 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
72 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 // DATA FIELD HEADER
73 // DATA FIELD HEADER
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
74 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 TM.serviceType = TM_TYPE_TC_EXE;
75 TM.serviceType = TM_TYPE_TC_EXE;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
76 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 TM.destinationID = TC->sourceID;
77 TM.destinationID = TC->sourceID;
54 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
78 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
55 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
79 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
56 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
80 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
57 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
81 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
58 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
82 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
59 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
83 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
60 //
84 //
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
85 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
86 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
87 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
88 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65
89
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
90 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67
91
68 // SEND DATA
92 // SEND DATA
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
93 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 if (status != RTEMS_SUCCESSFUL) {
94 if (status != RTEMS_SUCCESSFUL) {
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
95 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 }
96 }
73
97
74 // UPDATE HK FIELDS
98 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
99 update_last_TC_exe( TC, TM.time );
76
100
77 return status;
101 return status;
78 }
102 }
79
103
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
104 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
81 unsigned char byte_position, unsigned char rcv_value )
105 unsigned char byte_position, unsigned char rcv_value )
82 {
106 {
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
107 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
84 *
108 *
85 * @param TC points to the TeleCommand packet that is being processed
109 * @param TC points to the TeleCommand packet that is being processed
86 * @param queue_id is the id of the queue which handles TM
110 * @param queue_id is the id of the queue which handles TM
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
111 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
112 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
89 *
113 *
90 * @return RTEMS directive status code:
114 * @return RTEMS directive status code:
91 * - RTEMS_SUCCESSFUL - message sent successfully
115 * - RTEMS_SUCCESSFUL - message sent successfully
92 * - RTEMS_INVALID_ID - invalid queue id
116 * - RTEMS_INVALID_ID - invalid queue id
93 * - RTEMS_INVALID_SIZE - invalid message size
117 * - RTEMS_INVALID_SIZE - invalid message size
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
118 * - RTEMS_INVALID_ADDRESS - buffer is NULL
95 * - RTEMS_UNSATISFIED - out of message buffers
119 * - RTEMS_UNSATISFIED - out of message buffers
96 * - RTEMS_TOO_MANY - queue s limit has been reached
120 * - RTEMS_TOO_MANY - queue s limit has been reached
97 *
121 *
98 */
122 */
99
123
100 rtems_status_code status;
124 rtems_status_code status;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
125 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
102 unsigned char messageSize;
126 unsigned char messageSize;
103
127
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
128 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
129 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
106 TM.reserved = DEFAULT_RESERVED;
130 TM.reserved = DEFAULT_RESERVED;
107 TM.userApplication = CCSDS_USER_APP;
131 TM.userApplication = CCSDS_USER_APP;
108 // PACKET HEADER
132 // PACKET HEADER
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
133 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
134 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
135 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
136 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
137 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
114 // DATA FIELD HEADER
138 // DATA FIELD HEADER
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
139 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
116 TM.serviceType = TM_TYPE_TC_EXE;
140 TM.serviceType = TM_TYPE_TC_EXE;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
141 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
118 TM.destinationID = TC->sourceID;
142 TM.destinationID = TC->sourceID;
119 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
143 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
120 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
144 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
121 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
145 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
122 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
146 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
123 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
147 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
124 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
148 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
125 //
149 //
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
150 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
151 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
152 TM.telecommand_pkt_id[0] = TC->packetID[0];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
153 TM.telecommand_pkt_id[1] = TC->packetID[1];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
154 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
155 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
132 TM.tc_service = TC->serviceType; // type of the rejected TC
156 TM.tc_service = TC->serviceType; // type of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
157 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
134 TM.byte_position = byte_position;
158 TM.byte_position = byte_position;
135 TM.rcv_value = (unsigned char) rcv_value;
159 TM.rcv_value = (unsigned char) rcv_value;
136
160
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
161 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
138
162
139 // SEND DATA
163 // SEND DATA
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
164 status = rtems_message_queue_send( queue_id, &TM, messageSize);
141 if (status != RTEMS_SUCCESSFUL) {
165 if (status != RTEMS_SUCCESSFUL) {
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
166 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
143 }
167 }
144
168
145 // UPDATE HK FIELDS
169 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
170 update_last_TC_rej( TC, TM.time );
147
171
148 return status;
172 return status;
149 }
173 }
150
174
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
175 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
152 {
176 {
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
177 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
154 *
178 *
155 * @param TC points to the TeleCommand packet that is being processed
179 * @param TC points to the TeleCommand packet that is being processed
156 * @param queue_id is the id of the queue which handles TM
180 * @param queue_id is the id of the queue which handles TM
157 *
181 *
158 * @return RTEMS directive status code:
182 * @return RTEMS directive status code:
159 * - RTEMS_SUCCESSFUL - message sent successfully
183 * - RTEMS_SUCCESSFUL - message sent successfully
160 * - RTEMS_INVALID_ID - invalid queue id
184 * - RTEMS_INVALID_ID - invalid queue id
161 * - RTEMS_INVALID_SIZE - invalid message size
185 * - RTEMS_INVALID_SIZE - invalid message size
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
186 * - RTEMS_INVALID_ADDRESS - buffer is NULL
163 * - RTEMS_UNSATISFIED - out of message buffers
187 * - RTEMS_UNSATISFIED - out of message buffers
164 * - RTEMS_TOO_MANY - queue s limit has been reached
188 * - RTEMS_TOO_MANY - queue s limit has been reached
165 *
189 *
166 */
190 */
167
191
168 rtems_status_code status;
192 rtems_status_code status;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
193 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
170 unsigned char messageSize;
194 unsigned char messageSize;
171
195
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
196 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
197 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
174 TM.reserved = DEFAULT_RESERVED;
198 TM.reserved = DEFAULT_RESERVED;
175 TM.userApplication = CCSDS_USER_APP;
199 TM.userApplication = CCSDS_USER_APP;
176 // PACKET HEADER
200 // PACKET HEADER
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
201 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
202 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
203 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
204 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
205 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
182 // DATA FIELD HEADER
206 // DATA FIELD HEADER
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
207 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
184 TM.serviceType = TM_TYPE_TC_EXE;
208 TM.serviceType = TM_TYPE_TC_EXE;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
209 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
186 TM.destinationID = TC->sourceID; // default destination id
210 TM.destinationID = TC->sourceID; // default destination id
187 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
211 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
188 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
212 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
189 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
213 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
190 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
214 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
191 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
215 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
192 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
216 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
193 //
217 //
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
218 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
219 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
220 TM.telecommand_pkt_id[0] = TC->packetID[0];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
221 TM.telecommand_pkt_id[1] = TC->packetID[1];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
222 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
223 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
200 TM.tc_service = TC->serviceType; // type of the rejected TC
224 TM.tc_service = TC->serviceType; // type of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
225 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
226 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
227 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
204
228
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
229 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
206
230
207 // SEND DATA
231 // SEND DATA
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
232 status = rtems_message_queue_send( queue_id, &TM, messageSize);
209 if (status != RTEMS_SUCCESSFUL) {
233 if (status != RTEMS_SUCCESSFUL) {
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
234 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
211 }
235 }
212
236
213 // UPDATE HK FIELDS
237 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
238 update_last_TC_rej( TC, TM.time );
215
239
216 return status;
240 return status;
217 }
241 }
218
242
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
243 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
220 {
244 {
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
245 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
222 *
246 *
223 * @param TC points to the TeleCommand packet that is being processed
247 * @param TC points to the TeleCommand packet that is being processed
224 * @param queue_id is the id of the queue which handles TM
248 * @param queue_id is the id of the queue which handles TM
225 *
249 *
226 * @return RTEMS directive status code:
250 * @return RTEMS directive status code:
227 * - RTEMS_SUCCESSFUL - message sent successfully
251 * - RTEMS_SUCCESSFUL - message sent successfully
228 * - RTEMS_INVALID_ID - invalid queue id
252 * - RTEMS_INVALID_ID - invalid queue id
229 * - RTEMS_INVALID_SIZE - invalid message size
253 * - RTEMS_INVALID_SIZE - invalid message size
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
254 * - RTEMS_INVALID_ADDRESS - buffer is NULL
231 * - RTEMS_UNSATISFIED - out of message buffers
255 * - RTEMS_UNSATISFIED - out of message buffers
232 * - RTEMS_TOO_MANY - queue s limit has been reached
256 * - RTEMS_TOO_MANY - queue s limit has been reached
233 *
257 *
234 */
258 */
235
259
236 rtems_status_code status;
260 rtems_status_code status;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
261 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
238 unsigned char messageSize;
262 unsigned char messageSize;
239
263
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
264 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
265 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
242 TM.reserved = DEFAULT_RESERVED;
266 TM.reserved = DEFAULT_RESERVED;
243 TM.userApplication = CCSDS_USER_APP;
267 TM.userApplication = CCSDS_USER_APP;
244 // PACKET HEADER
268 // PACKET HEADER
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
269 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
270 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
271 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
272 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
273 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
250 // DATA FIELD HEADER
274 // DATA FIELD HEADER
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
275 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
252 TM.serviceType = TM_TYPE_TC_EXE;
276 TM.serviceType = TM_TYPE_TC_EXE;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
277 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
254 TM.destinationID = TC->sourceID; // default destination id
278 TM.destinationID = TC->sourceID; // default destination id
255 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
279 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
256 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
280 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
257 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
281 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
258 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
282 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
259 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
283 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
260 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
284 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
261 //
285 //
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
286 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
287 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
288 TM.telecommand_pkt_id[0] = TC->packetID[0];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
289 TM.telecommand_pkt_id[1] = TC->packetID[1];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
290 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
291 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
268 TM.tc_service = TC->serviceType; // type of the rejected TC
292 TM.tc_service = TC->serviceType; // type of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
293 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
270
294
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
295 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
272
296
273 // SEND DATA
297 // SEND DATA
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
298 status = rtems_message_queue_send( queue_id, &TM, messageSize);
275 if (status != RTEMS_SUCCESSFUL) {
299 if (status != RTEMS_SUCCESSFUL) {
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
300 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
277 }
301 }
278
302
279 // UPDATE HK FIELDS
303 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
304 update_last_TC_rej( TC, TM.time );
281
305
282 return status;
306 return status;
283 }
307 }
284
308
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
309 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
286 {
310 {
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
311 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
288 *
312 *
289 * @param TC points to the TeleCommand packet that is being processed
313 * @param TC points to the TeleCommand packet that is being processed
290 * @param queue_id is the id of the queue which handles TM
314 * @param queue_id is the id of the queue which handles TM
291 *
315 *
292 * @return RTEMS directive status code:
316 * @return RTEMS directive status code:
293 * - RTEMS_SUCCESSFUL - message sent successfully
317 * - RTEMS_SUCCESSFUL - message sent successfully
294 * - RTEMS_INVALID_ID - invalid queue id
318 * - RTEMS_INVALID_ID - invalid queue id
295 * - RTEMS_INVALID_SIZE - invalid message size
319 * - RTEMS_INVALID_SIZE - invalid message size
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
320 * - RTEMS_INVALID_ADDRESS - buffer is NULL
297 * - RTEMS_UNSATISFIED - out of message buffers
321 * - RTEMS_UNSATISFIED - out of message buffers
298 * - RTEMS_TOO_MANY - queue s limit has been reached
322 * - RTEMS_TOO_MANY - queue s limit has been reached
299 *
323 *
300 */
324 */
301
325
302 rtems_status_code status;
326 rtems_status_code status;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
327 Packet_TM_LFR_TC_EXE_ERROR_t TM;
304 unsigned char messageSize;
328 unsigned char messageSize;
305
329
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
330 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
331 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
308 TM.reserved = DEFAULT_RESERVED;
332 TM.reserved = DEFAULT_RESERVED;
309 TM.userApplication = CCSDS_USER_APP;
333 TM.userApplication = CCSDS_USER_APP;
310 // PACKET HEADER
334 // PACKET HEADER
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
335 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
336 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
337 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
338 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
339 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
316 // DATA FIELD HEADER
340 // DATA FIELD HEADER
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
341 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
318 TM.serviceType = TM_TYPE_TC_EXE;
342 TM.serviceType = TM_TYPE_TC_EXE;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
343 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
320 TM.destinationID = TC->sourceID; // default destination id
344 TM.destinationID = TC->sourceID; // default destination id
321 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
345 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
322 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
346 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
323 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
347 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
324 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
348 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
325 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
349 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
326 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
350 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
327 //
351 //
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
352 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
353 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
354 TM.telecommand_pkt_id[0] = TC->packetID[0];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
355 TM.telecommand_pkt_id[1] = TC->packetID[1];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
356 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
357 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
334 TM.tc_service = TC->serviceType; // type of the rejected TC
358 TM.tc_service = TC->serviceType; // type of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
359 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
336
360
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
361 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
338
362
339 // SEND DATA
363 // SEND DATA
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
364 status = rtems_message_queue_send( queue_id, &TM, messageSize);
341 if (status != RTEMS_SUCCESSFUL) {
365 if (status != RTEMS_SUCCESSFUL) {
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
366 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
343 }
367 }
344
368
345 // UPDATE HK FIELDS
369 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
370 update_last_TC_rej( TC, TM.time );
347
371
348 return status;
372 return status;
349 }
373 }
350
374
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
375 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
376 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
353 unsigned char destinationID )
377 unsigned char destinationID )
354 {
378 {
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
379 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
356 *
380 *
357 * @param TC points to the TeleCommand packet that is being processed
381 * @param TC points to the TeleCommand packet that is being processed
358 * @param queue_id is the id of the queue which handles TM
382 * @param queue_id is the id of the queue which handles TM
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
383 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
384 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
361 *
385 *
362 * @return RTEMS directive status code:
386 * @return RTEMS directive status code:
363 * - RTEMS_SUCCESSFUL - message sent successfully
387 * - RTEMS_SUCCESSFUL - message sent successfully
364 * - RTEMS_INVALID_ID - invalid queue id
388 * - RTEMS_INVALID_ID - invalid queue id
365 * - RTEMS_INVALID_SIZE - invalid message size
389 * - RTEMS_INVALID_SIZE - invalid message size
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
390 * - RTEMS_INVALID_ADDRESS - buffer is NULL
367 * - RTEMS_UNSATISFIED - out of message buffers
391 * - RTEMS_UNSATISFIED - out of message buffers
368 * - RTEMS_TOO_MANY - queue s limit has been reached
392 * - RTEMS_TOO_MANY - queue s limit has been reached
369 *
393 *
370 */
394 */
371
395
372 rtems_status_code status;
396 rtems_status_code status;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
397 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
374 unsigned char messageSize;
398 unsigned char messageSize;
375 unsigned int packetLength;
399 unsigned int packetLength;
376 unsigned int estimatedPacketLength;
400 unsigned int estimatedPacketLength;
377 unsigned char *packetDataField;
401 unsigned char *packetDataField;
378
402
379 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
403 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
380 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
404 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
405 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
382
406
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
407 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
408 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
385 TM.reserved = DEFAULT_RESERVED;
409 TM.reserved = DEFAULT_RESERVED;
386 TM.userApplication = CCSDS_USER_APP;
410 TM.userApplication = CCSDS_USER_APP;
387 // PACKET HEADER
411 // PACKET HEADER
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
412 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
413 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
414 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
415 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
416 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
393 // DATA FIELD HEADER
417 // DATA FIELD HEADER
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
418 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
395 TM.serviceType = TM_TYPE_TC_EXE;
419 TM.serviceType = TM_TYPE_TC_EXE;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
420 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
397 TM.destinationID = destinationID;
421 TM.destinationID = destinationID;
398 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
422 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
399 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
423 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
400 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
424 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
401 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
425 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
402 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
426 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
403 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
427 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
404 //
428 //
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
429 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
430 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
431 TM.telecommand_pkt_id[0] = TC->packetID[0];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
432 TM.telecommand_pkt_id[1] = TC->packetID[1];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
433 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
434 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
411 TM.tc_service = TC->serviceType; // type of the rejected TC
435 TM.tc_service = TC->serviceType; // type of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
436 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
437 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
438 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
439 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
440 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
417 // TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
418 // TM.rcv_crc[1] = packetDataField[ packetLength ];
419 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
441 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
420 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
442 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
421 TM.computed_crc[0] = computed_CRC[0];
443 TM.computed_crc[0] = computed_CRC[0];
422 TM.computed_crc[1] = computed_CRC[1];
444 TM.computed_crc[1] = computed_CRC[1];
423
445
424 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
446 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
425
447
426 // SEND DATA
448 // SEND DATA
427 status = rtems_message_queue_send( queue_id, &TM, messageSize);
449 status = rtems_message_queue_send( queue_id, &TM, messageSize);
428 if (status != RTEMS_SUCCESSFUL) {
450 if (status != RTEMS_SUCCESSFUL) {
429 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
451 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
430 }
452 }
431
453
432 // UPDATE HK FIELDS
454 // UPDATE HK FIELDS
433 update_last_TC_rej( TC, TM.time );
455 update_last_TC_rej( TC, TM.time );
434
456
435 return status;
457 return status;
436 }
458 }
437
459
438 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
460 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
439 {
461 {
440 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
462 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
441 *
463 *
442 * @param packet_sequence_control points to the packet sequence control which will be incremented
464 * @param packet_sequence_control points to the packet sequence control which will be incremented
443 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
465 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
444 *
466 *
445 * If the destination ID is not known, a dedicated counter is incremented.
467 * If the destination ID is not known, a dedicated counter is incremented.
446 *
468 *
447 */
469 */
448
470
449 unsigned short sequence_cnt;
471 unsigned short sequence_cnt;
450 unsigned short segmentation_grouping_flag;
472 unsigned short segmentation_grouping_flag;
451 unsigned short new_packet_sequence_control;
473 unsigned short new_packet_sequence_control;
452 unsigned char i;
474 unsigned char i;
453
475
454 switch (destination_id)
476 switch (destination_id)
455 {
477 {
456 case SID_TC_GROUND:
478 case SID_TC_GROUND:
457 i = GROUND;
479 i = GROUND;
458 break;
480 break;
459 case SID_TC_MISSION_TIMELINE:
481 case SID_TC_MISSION_TIMELINE:
460 i = MISSION_TIMELINE;
482 i = MISSION_TIMELINE;
461 break;
483 break;
462 case SID_TC_TC_SEQUENCES:
484 case SID_TC_TC_SEQUENCES:
463 i = TC_SEQUENCES;
485 i = TC_SEQUENCES;
464 break;
486 break;
465 case SID_TC_RECOVERY_ACTION_CMD:
487 case SID_TC_RECOVERY_ACTION_CMD:
466 i = RECOVERY_ACTION_CMD;
488 i = RECOVERY_ACTION_CMD;
467 break;
489 break;
468 case SID_TC_BACKUP_MISSION_TIMELINE:
490 case SID_TC_BACKUP_MISSION_TIMELINE:
469 i = BACKUP_MISSION_TIMELINE;
491 i = BACKUP_MISSION_TIMELINE;
470 break;
492 break;
471 case SID_TC_DIRECT_CMD:
493 case SID_TC_DIRECT_CMD:
472 i = DIRECT_CMD;
494 i = DIRECT_CMD;
473 break;
495 break;
474 case SID_TC_SPARE_GRD_SRC1:
496 case SID_TC_SPARE_GRD_SRC1:
475 i = SPARE_GRD_SRC1;
497 i = SPARE_GRD_SRC1;
476 break;
498 break;
477 case SID_TC_SPARE_GRD_SRC2:
499 case SID_TC_SPARE_GRD_SRC2:
478 i = SPARE_GRD_SRC2;
500 i = SPARE_GRD_SRC2;
479 break;
501 break;
480 case SID_TC_OBCP:
502 case SID_TC_OBCP:
481 i = OBCP;
503 i = OBCP;
482 break;
504 break;
483 case SID_TC_SYSTEM_CONTROL:
505 case SID_TC_SYSTEM_CONTROL:
484 i = SYSTEM_CONTROL;
506 i = SYSTEM_CONTROL;
485 break;
507 break;
486 case SID_TC_AOCS:
508 case SID_TC_AOCS:
487 i = AOCS;
509 i = AOCS;
488 break;
510 break;
489 case SID_TC_RPW_INTERNAL:
511 case SID_TC_RPW_INTERNAL:
490 i = RPW_INTERNAL;
512 i = RPW_INTERNAL;
491 break;
513 break;
492 default:
514 default:
493 i = GROUND;
515 i = GROUND;
494 break;
516 break;
495 }
517 }
496
518
497 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
519 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
498 sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK;
520 sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK;
499
521
500 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
522 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
501
523
502 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
524 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
503 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
525 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
504
526
505 // increment the sequence counter
527 // increment the sequence counter
506 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
528 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
507 {
529 {
508 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
530 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
509 }
531 }
510 else
532 else
511 {
533 {
512 sequenceCounters_TC_EXE[ i ] = 0;
534 sequenceCounters_TC_EXE[ i ] = 0;
513 }
535 }
514 }
536 }
@@ -1,1343 +1,1366
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions and tasks related to waveform packet generation.
25 /** Functions and tasks related to waveform packet generation.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
30 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
31 *
8 */
32 */
9
33
10 #include "wf_handler.h"
34 #include "wf_handler.h"
11
35
12 //***************
36 //***************
13 // waveform rings
37 // waveform rings
14 // F0
38 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
39 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
16 ring_node *current_ring_node_f0 = NULL;
40 ring_node *current_ring_node_f0 = NULL;
17 ring_node *ring_node_to_send_swf_f0 = NULL;
41 ring_node *ring_node_to_send_swf_f0 = NULL;
18 // F1
42 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
43 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
20 ring_node *current_ring_node_f1 = NULL;
44 ring_node *current_ring_node_f1 = NULL;
21 ring_node *ring_node_to_send_swf_f1 = NULL;
45 ring_node *ring_node_to_send_swf_f1 = NULL;
22 ring_node *ring_node_to_send_cwf_f1 = NULL;
46 ring_node *ring_node_to_send_cwf_f1 = NULL;
23 // F2
47 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
48 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
25 ring_node *current_ring_node_f2 = NULL;
49 ring_node *current_ring_node_f2 = NULL;
26 ring_node *ring_node_to_send_swf_f2 = NULL;
50 ring_node *ring_node_to_send_swf_f2 = NULL;
27 ring_node *ring_node_to_send_cwf_f2 = NULL;
51 ring_node *ring_node_to_send_cwf_f2 = NULL;
28 // F3
52 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
53 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
30 ring_node *current_ring_node_f3 = NULL;
54 ring_node *current_ring_node_f3 = NULL;
31 ring_node *ring_node_to_send_cwf_f3 = NULL;
55 ring_node *ring_node_to_send_cwf_f3 = NULL;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
56 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
33
57
34 bool extractSWF1 = false;
58 bool extractSWF1 = false;
35 bool extractSWF2 = false;
59 bool extractSWF2 = false;
36 bool swf0_ready_flag_f1 = false;
60 bool swf0_ready_flag_f1 = false;
37 bool swf0_ready_flag_f2 = false;
61 bool swf0_ready_flag_f2 = false;
38 bool swf1_ready = false;
62 bool swf1_ready = false;
39 bool swf2_ready = false;
63 bool swf2_ready = false;
40
64
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
65 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
66 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
43 ring_node ring_node_swf1_extracted = {0};
67 ring_node ring_node_swf1_extracted = {0};
44 ring_node ring_node_swf2_extracted = {0};
68 ring_node ring_node_swf2_extracted = {0};
45
69
46 typedef enum resynchro_state_t
70 typedef enum resynchro_state_t
47 {
71 {
48 MEASURE,
72 MEASURE,
49 CORRECTION
73 CORRECTION
50 } resynchro_state;
74 } resynchro_state;
51
75
52 //*********************
76 //*********************
53 // Interrupt SubRoutine
77 // Interrupt SubRoutine
54
78
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
79 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 {
80 {
57 ring_node *node;
81 ring_node *node;
58
82
59 node = NULL;
83 node = NULL;
60 switch ( frequencyChannel ) {
84 switch ( frequencyChannel ) {
61 case CHANNELF1:
85 case CHANNELF1:
62 node = ring_node_to_send_cwf_f1;
86 node = ring_node_to_send_cwf_f1;
63 break;
87 break;
64 case CHANNELF2:
88 case CHANNELF2:
65 node = ring_node_to_send_cwf_f2;
89 node = ring_node_to_send_cwf_f2;
66 break;
90 break;
67 case CHANNELF3:
91 case CHANNELF3:
68 node = ring_node_to_send_cwf_f3;
92 node = ring_node_to_send_cwf_f3;
69 break;
93 break;
70 default:
94 default:
71 break;
95 break;
72 }
96 }
73
97
74 return node;
98 return node;
75 }
99 }
76
100
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
101 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 {
102 {
79 ring_node *node;
103 ring_node *node;
80
104
81 node = NULL;
105 node = NULL;
82 switch ( frequencyChannel ) {
106 switch ( frequencyChannel ) {
83 case CHANNELF0:
107 case CHANNELF0:
84 node = ring_node_to_send_swf_f0;
108 node = ring_node_to_send_swf_f0;
85 break;
109 break;
86 case CHANNELF1:
110 case CHANNELF1:
87 node = ring_node_to_send_swf_f1;
111 node = ring_node_to_send_swf_f1;
88 break;
112 break;
89 case CHANNELF2:
113 case CHANNELF2:
90 node = ring_node_to_send_swf_f2;
114 node = ring_node_to_send_swf_f2;
91 break;
115 break;
92 default:
116 default:
93 break;
117 break;
94 }
118 }
95
119
96 return node;
120 return node;
97 }
121 }
98
122
99 void reset_extractSWF( void )
123 void reset_extractSWF( void )
100 {
124 {
101 extractSWF1 = false;
125 extractSWF1 = false;
102 extractSWF2 = false;
126 extractSWF2 = false;
103 swf0_ready_flag_f1 = false;
127 swf0_ready_flag_f1 = false;
104 swf0_ready_flag_f2 = false;
128 swf0_ready_flag_f2 = false;
105 swf1_ready = false;
129 swf1_ready = false;
106 swf2_ready = false;
130 swf2_ready = false;
107 }
131 }
108
132
109 inline void waveforms_isr_f3( void )
133 inline void waveforms_isr_f3( void )
110 {
134 {
111 rtems_status_code spare_status;
135 rtems_status_code spare_status;
112
136
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
137 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
138 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
139 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 //***
140 //***
117 // F3
141 // F3
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
142 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
143 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 current_ring_node_f3 = current_ring_node_f3->next;
144 current_ring_node_f3 = current_ring_node_f3->next;
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
145 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
146 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
147 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
148 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
149 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 }
150 }
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
151 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
152 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
153 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
154 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
155 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 }
156 }
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
157 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 }
159 }
136 }
160 }
137 }
161 }
138 }
162 }
139
163
140 inline void waveforms_isr_burst( void )
164 inline void waveforms_isr_burst( void )
141 {
165 {
142 unsigned char status;
166 unsigned char status;
143 rtems_status_code spare_status;
167 rtems_status_code spare_status;
144
168
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
169 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146
170
147 switch(status)
171 switch(status)
148 {
172 {
149 case BIT_WFP_BUFFER_0:
173 case BIT_WFP_BUFFER_0:
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
174 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
175 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
176 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
177 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
154 current_ring_node_f2 = current_ring_node_f2->next;
178 current_ring_node_f2 = current_ring_node_f2->next;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
179 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
180 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
181 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 }
182 }
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
183 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
160 break;
184 break;
161 case BIT_WFP_BUFFER_1:
185 case BIT_WFP_BUFFER_1:
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
186 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
187 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
188 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
189 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
166 current_ring_node_f2 = current_ring_node_f2->next;
190 current_ring_node_f2 = current_ring_node_f2->next;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
191 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
192 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
193 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
170 }
194 }
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
195 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
172 break;
196 break;
173 default:
197 default:
174 break;
198 break;
175 }
199 }
176 }
200 }
177
201
178 inline void waveform_isr_normal_sbm1_sbm2( void )
202 inline void waveform_isr_normal_sbm1_sbm2( void )
179 {
203 {
180 rtems_status_code status;
204 rtems_status_code status;
181
205
182 //***
206 //***
183 // F0
207 // F0
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
208 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
185 {
209 {
186 swf0_ready_flag_f1 = true;
210 swf0_ready_flag_f1 = true;
187 swf0_ready_flag_f2 = true;
211 swf0_ready_flag_f2 = true;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
212 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
189 current_ring_node_f0 = current_ring_node_f0->next;
213 current_ring_node_f0 = current_ring_node_f0->next;
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
214 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
191 {
215 {
192
216
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
217 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
218 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
219 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
197 }
221 }
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
199 {
223 {
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
224 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
225 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
226 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
204 }
228 }
205 // send an event to the WFRM task for resynchro activities
229 // send an event to the WFRM task for resynchro activities
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
230 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
231 status = rtems_event_send( Task_id[TASKID_CALI], RTEMS_EVENT_CAL_SWEEP_WAKE );
207 }
232 }
208
233
209 //***
234 //***
210 // F1
235 // F1
211 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
236 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
212 // (1) change the receiving buffer for the waveform picker
237 // (1) change the receiving buffer for the waveform picker
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
238 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
214 current_ring_node_f1 = current_ring_node_f1->next;
239 current_ring_node_f1 = current_ring_node_f1->next;
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
216 {
241 {
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
242 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
243 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
244 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
221 }
246 }
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
223 {
248 {
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
249 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
250 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
251 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
228 }
253 }
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
254 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
255 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
231 }
256 }
232
257
233 //***
258 //***
234 // F2
259 // F2
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
260 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
236 // (1) change the receiving buffer for the waveform picker
261 // (1) change the receiving buffer for the waveform picker
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
262 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
263 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
239 current_ring_node_f2 = current_ring_node_f2->next;
264 current_ring_node_f2 = current_ring_node_f2->next;
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
265 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
241 {
266 {
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
267 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
268 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
269 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
270 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
246 }
271 }
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
272 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
248 {
273 {
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
274 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
275 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
276 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
277 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
253 }
278 }
254 // (2) send an event for the waveforms transmission
279 // (2) send an event for the waveforms transmission
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
280 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
256 }
281 }
257 }
282 }
258
283
259 rtems_isr waveforms_isr( rtems_vector_number vector )
284 rtems_isr waveforms_isr( rtems_vector_number vector )
260 {
285 {
261 /** This is the interrupt sub routine called by the waveform picker core.
286 /** This is the interrupt sub routine called by the waveform picker core.
262 *
287 *
263 * This ISR launch different actions depending mainly on two pieces of information:
288 * This ISR launch different actions depending mainly on two pieces of information:
264 * 1. the values read in the registers of the waveform picker.
289 * 1. the values read in the registers of the waveform picker.
265 * 2. the current LFR mode.
290 * 2. the current LFR mode.
266 *
291 *
267 */
292 */
268
293
269 // STATUS
294 // STATUS
270 // new error error buffer full
295 // new error error buffer full
271 // 15 14 13 12 11 10 9 8
296 // 15 14 13 12 11 10 9 8
272 // f3 f2 f1 f0 f3 f2 f1 f0
297 // f3 f2 f1 f0 f3 f2 f1 f0
273 //
298 //
274 // ready buffer
299 // ready buffer
275 // 7 6 5 4 3 2 1 0
300 // 7 6 5 4 3 2 1 0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
301 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
277
302
278 rtems_status_code spare_status;
303 rtems_status_code spare_status;
279
304
280 waveforms_isr_f3();
305 waveforms_isr_f3();
281
306
282 //*************************************************
307 //*************************************************
283 // copy the status bits in the housekeeping packets
308 // copy the status bits in the housekeeping packets
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
309 housekeeping_packet.hk_lfr_vhdl_iir_cal =
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
310 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
286
311
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
312 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
288 {
313 {
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
314 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
290 }
315 }
291
316
292 switch(lfrCurrentMode)
317 switch(lfrCurrentMode)
293 {
318 {
294 //********
319 //********
295 // STANDBY
320 // STANDBY
296 case LFR_MODE_STANDBY:
321 case LFR_MODE_STANDBY:
297 break;
322 break;
298 //**************************
323 //**************************
299 // LFR NORMAL, SBM1 and SBM2
324 // LFR NORMAL, SBM1 and SBM2
300 case LFR_MODE_NORMAL:
325 case LFR_MODE_NORMAL:
301 case LFR_MODE_SBM1:
326 case LFR_MODE_SBM1:
302 case LFR_MODE_SBM2:
327 case LFR_MODE_SBM2:
303 waveform_isr_normal_sbm1_sbm2();
328 waveform_isr_normal_sbm1_sbm2();
304 break;
329 break;
305 //******
330 //******
306 // BURST
331 // BURST
307 case LFR_MODE_BURST:
332 case LFR_MODE_BURST:
308 waveforms_isr_burst();
333 waveforms_isr_burst();
309 break;
334 break;
310 //********
335 //********
311 // DEFAULT
336 // DEFAULT
312 default:
337 default:
313 break;
338 break;
314 }
339 }
315 }
340 }
316
341
317 //************
342 //************
318 // RTEMS TASKS
343 // RTEMS TASKS
319
344
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
345 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
321 {
346 {
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
347 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
323 *
348 *
324 * @param unused is the starting argument of the RTEMS task
349 * @param unused is the starting argument of the RTEMS task
325 *
350 *
326 * The following data packets are sent by this task:
351 * The following data packets are sent by this task:
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
352 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
353 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
354 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
330 *
355 *
331 */
356 */
332
357
333 rtems_event_set event_out;
358 rtems_event_set event_out;
334 rtems_id queue_id;
359 rtems_id queue_id;
335 rtems_status_code status;
360 rtems_status_code status;
336 ring_node *ring_node_swf1_extracted_ptr;
361 ring_node *ring_node_swf1_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
362 ring_node *ring_node_swf2_extracted_ptr;
338
363
339 event_out = EVENT_SETS_NONE_PENDING;
364 event_out = EVENT_SETS_NONE_PENDING;
340 queue_id = RTEMS_ID_NONE;
365 queue_id = RTEMS_ID_NONE;
341
366
342 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
367 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
343 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
368 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
344
369
345 status = get_message_queue_id_send( &queue_id );
370 status = get_message_queue_id_send( &queue_id );
346 if (status != RTEMS_SUCCESSFUL)
371 if (status != RTEMS_SUCCESSFUL)
347 {
372 {
348 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
373 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
349 }
374 }
350
375
351 BOOT_PRINTF("in WFRM ***\n");
376 BOOT_PRINTF("in WFRM ***\n");
352
377
353 while(1){
378 while(1){
354 // wait for an RTEMS_EVENT
379 // wait for an RTEMS_EVENT
355 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
380 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
356 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
381 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
357
382
358 if (event_out == RTEMS_EVENT_MODE_NORMAL)
383 if (event_out == RTEMS_EVENT_MODE_NORMAL)
359 {
384 {
360 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
385 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
361 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
386 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
362 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
387 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
363 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
388 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
364 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
389 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
365 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
390 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
366 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
391 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
367 }
392 }
368 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
393 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
369 {
394 {
370 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
395 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
371 }
396 }
372 }
397 }
373 }
398 }
374
399
375 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
400 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
376 {
401 {
377 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
402 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
378 *
403 *
379 * @param unused is the starting argument of the RTEMS task
404 * @param unused is the starting argument of the RTEMS task
380 *
405 *
381 * The following data packet is sent by this task:
406 * The following data packet is sent by this task:
382 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
407 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
383 *
408 *
384 */
409 */
385
410
386 rtems_event_set event_out;
411 rtems_event_set event_out;
387 rtems_id queue_id;
412 rtems_id queue_id;
388 rtems_status_code status;
413 rtems_status_code status;
389 ring_node ring_node_cwf3_light;
414 ring_node ring_node_cwf3_light;
390 ring_node *ring_node_to_send_cwf;
415 ring_node *ring_node_to_send_cwf;
391
416
392 event_out = EVENT_SETS_NONE_PENDING;
417 event_out = EVENT_SETS_NONE_PENDING;
393 queue_id = RTEMS_ID_NONE;
418 queue_id = RTEMS_ID_NONE;
394
419
395 status = get_message_queue_id_send( &queue_id );
420 status = get_message_queue_id_send( &queue_id );
396 if (status != RTEMS_SUCCESSFUL)
421 if (status != RTEMS_SUCCESSFUL)
397 {
422 {
398 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
423 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
399 }
424 }
400
425
401 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
426 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
402
427
403 // init the ring_node_cwf3_light structure
428 // init the ring_node_cwf3_light structure
404 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
429 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
405 ring_node_cwf3_light.coarseTime = INIT_CHAR;
430 ring_node_cwf3_light.coarseTime = INIT_CHAR;
406 ring_node_cwf3_light.fineTime = INIT_CHAR;
431 ring_node_cwf3_light.fineTime = INIT_CHAR;
407 ring_node_cwf3_light.next = NULL;
432 ring_node_cwf3_light.next = NULL;
408 ring_node_cwf3_light.previous = NULL;
433 ring_node_cwf3_light.previous = NULL;
409 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
434 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
410 ring_node_cwf3_light.status = INIT_CHAR;
435 ring_node_cwf3_light.status = INIT_CHAR;
411
436
412 BOOT_PRINTF("in CWF3 ***\n");
437 BOOT_PRINTF("in CWF3 ***\n");
413
438
414 while(1){
439 while(1){
415 // wait for an RTEMS_EVENT
440 // wait for an RTEMS_EVENT
416 rtems_event_receive( RTEMS_EVENT_0,
441 rtems_event_receive( RTEMS_EVENT_0,
417 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
442 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
418 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
443 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
419 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
444 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
420 {
445 {
421 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
446 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
422 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
447 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
423 {
448 {
424 PRINTF("send CWF_LONG_F3\n");
449 PRINTF("send CWF_LONG_F3\n");
425 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
450 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
426 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
451 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
427 }
452 }
428 else
453 else
429 {
454 {
430 PRINTF("send CWF_F3 (light)\n");
455 PRINTF("send CWF_F3 (light)\n");
431 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
456 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
432 }
457 }
433
458
434 }
459 }
435 else
460 else
436 {
461 {
437 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
462 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
438 }
463 }
439 }
464 }
440 }
465 }
441
466
442 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
467 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
443 {
468 {
444 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
469 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
445 *
470 *
446 * @param unused is the starting argument of the RTEMS task
471 * @param unused is the starting argument of the RTEMS task
447 *
472 *
448 * The following data packet is sent by this function:
473 * The following data packet is sent by this function:
449 * - TM_LFR_SCIENCE_BURST_CWF_F2
474 * - TM_LFR_SCIENCE_BURST_CWF_F2
450 * - TM_LFR_SCIENCE_SBM2_CWF_F2
475 * - TM_LFR_SCIENCE_SBM2_CWF_F2
451 *
476 *
452 */
477 */
453
478
454 rtems_event_set event_out;
479 rtems_event_set event_out;
455 rtems_id queue_id;
480 rtems_id queue_id;
456 rtems_status_code status;
481 rtems_status_code status;
457 ring_node *ring_node_to_send;
482 ring_node *ring_node_to_send;
458 unsigned long long int acquisitionTimeF0_asLong;
483 unsigned long long int acquisitionTimeF0_asLong;
459
484
460 event_out = EVENT_SETS_NONE_PENDING;
485 event_out = EVENT_SETS_NONE_PENDING;
461 queue_id = RTEMS_ID_NONE;
486 queue_id = RTEMS_ID_NONE;
462
487
463 acquisitionTimeF0_asLong = INIT_CHAR;
488 acquisitionTimeF0_asLong = INIT_CHAR;
464
489
465 status = get_message_queue_id_send( &queue_id );
490 status = get_message_queue_id_send( &queue_id );
466 if (status != RTEMS_SUCCESSFUL)
491 if (status != RTEMS_SUCCESSFUL)
467 {
492 {
468 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
493 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
469 }
494 }
470
495
471 BOOT_PRINTF("in CWF2 ***\n");
496 BOOT_PRINTF("in CWF2 ***\n");
472
497
473 while(1){
498 while(1){
474 // wait for an RTEMS_EVENT// send the snapshot when built
499 // wait for an RTEMS_EVENT// send the snapshot when built
475 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
500 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
476 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
501 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
477 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
502 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
478 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
503 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
479 if (event_out == RTEMS_EVENT_MODE_BURST)
504 if (event_out == RTEMS_EVENT_MODE_BURST)
480 { // data are sent whatever the transition time
505 { // data are sent whatever the transition time
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
506 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
482 }
507 }
483 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
508 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
484 {
509 {
485 if ( lfrCurrentMode == LFR_MODE_SBM2 )
510 if ( lfrCurrentMode == LFR_MODE_SBM2 )
486 {
511 {
487 // data are sent depending on the transition time
512 // data are sent depending on the transition time
488 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
513 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
489 {
514 {
490 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
515 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
491 }
516 }
492 }
517 }
493 // launch snapshot extraction if needed
518 // launch snapshot extraction if needed
494 if (extractSWF2 == true)
519 if (extractSWF2 == true)
495 {
520 {
496 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
521 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
497 // extract the snapshot
522 // extract the snapshot
498 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
523 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
499 &ring_node_swf2_extracted, swf2_extracted );
524 &ring_node_swf2_extracted, swf2_extracted );
500 extractSWF2 = false;
525 extractSWF2 = false;
501 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
526 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
502 }
527 }
503 if (swf0_ready_flag_f2 == true)
528 if (swf0_ready_flag_f2 == true)
504 {
529 {
505 extractSWF2 = true;
530 extractSWF2 = true;
506 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
531 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
507 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
532 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
508 swf0_ready_flag_f2 = false;
533 swf0_ready_flag_f2 = false;
509 }
534 }
510 }
535 }
511 }
536 }
512 }
537 }
513
538
514 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
539 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
515 {
540 {
516 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
541 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
517 *
542 *
518 * @param unused is the starting argument of the RTEMS task
543 * @param unused is the starting argument of the RTEMS task
519 *
544 *
520 * The following data packet is sent by this function:
545 * The following data packet is sent by this function:
521 * - TM_LFR_SCIENCE_SBM1_CWF_F1
546 * - TM_LFR_SCIENCE_SBM1_CWF_F1
522 *
547 *
523 */
548 */
524
549
525 rtems_event_set event_out;
550 rtems_event_set event_out;
526 rtems_id queue_id;
551 rtems_id queue_id;
527 rtems_status_code status;
552 rtems_status_code status;
528
553
529 ring_node *ring_node_to_send_cwf;
554 ring_node *ring_node_to_send_cwf;
530
555
531 event_out = EVENT_SETS_NONE_PENDING;
556 event_out = EVENT_SETS_NONE_PENDING;
532 queue_id = RTEMS_ID_NONE;
557 queue_id = RTEMS_ID_NONE;
533
558
534 status = get_message_queue_id_send( &queue_id );
559 status = get_message_queue_id_send( &queue_id );
535 if (status != RTEMS_SUCCESSFUL)
560 if (status != RTEMS_SUCCESSFUL)
536 {
561 {
537 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
562 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
538 }
563 }
539
564
540 BOOT_PRINTF("in CWF1 ***\n");
565 BOOT_PRINTF("in CWF1 ***\n");
541
566
542 while(1){
567 while(1){
543 // wait for an RTEMS_EVENT
568 // wait for an RTEMS_EVENT
544 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
569 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
545 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
570 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
546 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
571 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
547 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
572 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
548 if (lfrCurrentMode == LFR_MODE_SBM1)
573 if (lfrCurrentMode == LFR_MODE_SBM1)
549 {
574 {
550 // data are sent depending on the transition time
575 // data are sent depending on the transition time
551 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
576 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
552 {
577 {
553 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
578 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
554 }
579 }
555 }
580 }
556 // launch snapshot extraction if needed
581 // launch snapshot extraction if needed
557 if (extractSWF1 == true)
582 if (extractSWF1 == true)
558 {
583 {
559 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
584 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
560 // launch the snapshot extraction
585 // launch the snapshot extraction
561 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
586 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
562 extractSWF1 = false;
587 extractSWF1 = false;
563 }
588 }
564 if (swf0_ready_flag_f1 == true)
589 if (swf0_ready_flag_f1 == true)
565 {
590 {
566 extractSWF1 = true;
591 extractSWF1 = true;
567 swf0_ready_flag_f1 = false; // this step shall be executed only one time
592 swf0_ready_flag_f1 = false; // this step shall be executed only one time
568 }
593 }
569 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
594 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
570 {
595 {
571 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
596 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
572 swf1_ready = false;
597 swf1_ready = false;
573 swf2_ready = false;
598 swf2_ready = false;
574 }
599 }
575 }
600 }
576 }
601 }
577
602
578 rtems_task swbd_task(rtems_task_argument argument)
603 rtems_task swbd_task(rtems_task_argument argument)
579 {
604 {
580 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
605 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
581 *
606 *
582 * @param unused is the starting argument of the RTEMS task
607 * @param unused is the starting argument of the RTEMS task
583 *
608 *
584 */
609 */
585
610
586 rtems_event_set event_out;
611 rtems_event_set event_out;
587 unsigned long long int acquisitionTimeF0_asLong;
612 unsigned long long int acquisitionTimeF0_asLong;
588
613
589 event_out = EVENT_SETS_NONE_PENDING;
614 event_out = EVENT_SETS_NONE_PENDING;
590 acquisitionTimeF0_asLong = INIT_CHAR;
615 acquisitionTimeF0_asLong = INIT_CHAR;
591
616
592 BOOT_PRINTF("in SWBD ***\n")
617 BOOT_PRINTF("in SWBD ***\n")
593
618
594 while(1){
619 while(1){
595 // wait for an RTEMS_EVENT
620 // wait for an RTEMS_EVENT
596 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
621 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
597 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
622 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
598 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
623 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
599 {
624 {
600 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
625 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
601 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
626 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
602 &ring_node_swf1_extracted, swf1_extracted );
627 &ring_node_swf1_extracted, swf1_extracted );
603 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
628 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
604 }
629 }
605 else
630 else
606 {
631 {
607 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
632 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
608 }
633 }
609 }
634 }
610 }
635 }
611
636
612 //******************
637 //******************
613 // general functions
638 // general functions
614
639
615 void WFP_init_rings( void )
640 void WFP_init_rings( void )
616 {
641 {
617 // F0 RING
642 // F0 RING
618 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
643 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
619 // F1 RING
644 // F1 RING
620 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
645 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
621 // F2 RING
646 // F2 RING
622 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
647 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
623 // F3 RING
648 // F3 RING
624 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
649 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
625
650
626 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
651 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
627 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
652 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
628
653
629 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
654 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
630 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
655 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
631 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
656 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
632 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
657 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
633 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
658 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
634 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
659 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
635 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
660 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
636 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
661 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
637
662
638 }
663 }
639
664
640 void WFP_reset_current_ring_nodes( void )
665 void WFP_reset_current_ring_nodes( void )
641 {
666 {
642 current_ring_node_f0 = waveform_ring_f0[0].next;
667 current_ring_node_f0 = waveform_ring_f0[0].next;
643 current_ring_node_f1 = waveform_ring_f1[0].next;
668 current_ring_node_f1 = waveform_ring_f1[0].next;
644 current_ring_node_f2 = waveform_ring_f2[0].next;
669 current_ring_node_f2 = waveform_ring_f2[0].next;
645 current_ring_node_f3 = waveform_ring_f3[0].next;
670 current_ring_node_f3 = waveform_ring_f3[0].next;
646
671
647 ring_node_to_send_swf_f0 = waveform_ring_f0;
672 ring_node_to_send_swf_f0 = waveform_ring_f0;
648 ring_node_to_send_swf_f1 = waveform_ring_f1;
673 ring_node_to_send_swf_f1 = waveform_ring_f1;
649 ring_node_to_send_swf_f2 = waveform_ring_f2;
674 ring_node_to_send_swf_f2 = waveform_ring_f2;
650
675
651 ring_node_to_send_cwf_f1 = waveform_ring_f1;
676 ring_node_to_send_cwf_f1 = waveform_ring_f1;
652 ring_node_to_send_cwf_f2 = waveform_ring_f2;
677 ring_node_to_send_cwf_f2 = waveform_ring_f2;
653 ring_node_to_send_cwf_f3 = waveform_ring_f3;
678 ring_node_to_send_cwf_f3 = waveform_ring_f3;
654 }
679 }
655
680
656 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
681 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
657 {
682 {
658 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
683 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
659 *
684 *
660 * @param waveform points to the buffer containing the data that will be send.
685 * @param waveform points to the buffer containing the data that will be send.
661 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
686 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
662 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
687 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
663 * contain information to setup the transmission of the data packets.
688 * contain information to setup the transmission of the data packets.
664 *
689 *
665 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
690 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
666 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
691 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
667 *
692 *
668 */
693 */
669
694
670 unsigned int i;
695 unsigned int i;
671 unsigned int j;
696 unsigned int j;
672 int ret;
697 int ret;
673 rtems_status_code status;
698 rtems_status_code status;
674
699
675 char *sample;
700 char *sample;
676 int *dataPtr;
701 int *dataPtr;
677
702
678 ret = LFR_DEFAULT;
703 ret = LFR_DEFAULT;
679
704
680 dataPtr = (int*) ring_node_to_send->buffer_address;
705 dataPtr = (int*) ring_node_to_send->buffer_address;
681
706
682 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
707 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
683 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
708 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
684
709
685 //**********************
710 //**********************
686 // BUILD CWF3_light DATA
711 // BUILD CWF3_light DATA
687 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
712 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
688 {
713 {
689 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
714 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
690 for (j=0; j < CWF_BLK_SIZE; j++)
715 for (j=0; j < CWF_BLK_SIZE; j++)
691 {
716 {
692 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
717 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
693 }
718 }
694 }
719 }
695
720
696 // SEND PACKET
721 // SEND PACKET
697 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
722 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
698 if (status != RTEMS_SUCCESSFUL) {
723 if (status != RTEMS_SUCCESSFUL) {
699 ret = LFR_DEFAULT;
724 ret = LFR_DEFAULT;
700 }
725 }
701
726
702 return ret;
727 return ret;
703 }
728 }
704
729
705 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
730 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
706 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
731 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
707 {
732 {
708 unsigned long long int acquisitionTimeAsLong;
733 unsigned long long int acquisitionTimeAsLong;
709 unsigned char localAcquisitionTime[BYTES_PER_TIME];
734 unsigned char localAcquisitionTime[BYTES_PER_TIME];
710 double deltaT;
735 double deltaT;
711
736
712 deltaT = INIT_FLOAT;
737 deltaT = INIT_FLOAT;
713
738
714 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
739 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
715 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
740 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
716 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
741 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
717 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
742 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
718 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
743 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
719 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
744 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
720
745
721 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
746 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
722 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
747 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
723 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
748 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
724 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
749 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
725 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
750 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
726 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
751 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
727
752
728 switch( sid )
753 switch( sid )
729 {
754 {
730 case SID_NORM_SWF_F0:
755 case SID_NORM_SWF_F0:
731 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
756 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
732 break;
757 break;
733
758
734 case SID_NORM_SWF_F1:
759 case SID_NORM_SWF_F1:
735 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
760 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
736 break;
761 break;
737
762
738 case SID_NORM_SWF_F2:
763 case SID_NORM_SWF_F2:
739 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
764 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
740 break;
765 break;
741
766
742 case SID_SBM1_CWF_F1:
767 case SID_SBM1_CWF_F1:
743 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
768 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
744 break;
769 break;
745
770
746 case SID_SBM2_CWF_F2:
771 case SID_SBM2_CWF_F2:
747 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
772 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
748 break;
773 break;
749
774
750 case SID_BURST_CWF_F2:
775 case SID_BURST_CWF_F2:
751 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
776 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
752 break;
777 break;
753
778
754 case SID_NORM_CWF_F3:
779 case SID_NORM_CWF_F3:
755 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
780 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
756 break;
781 break;
757
782
758 case SID_NORM_CWF_LONG_F3:
783 case SID_NORM_CWF_LONG_F3:
759 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
784 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
760 break;
785 break;
761
786
762 default:
787 default:
763 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
788 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
764 deltaT = 0.;
789 deltaT = 0.;
765 break;
790 break;
766 }
791 }
767
792
768 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
793 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
769 //
794 //
770 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
795 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
771 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
796 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
772 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
797 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
773 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
798 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
774 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
799 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
775 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
800 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
776
801
777 }
802 }
778
803
779 void build_snapshot_from_ring( ring_node *ring_node_to_send,
804 void build_snapshot_from_ring( ring_node *ring_node_to_send,
780 unsigned char frequencyChannel,
805 unsigned char frequencyChannel,
781 unsigned long long int acquisitionTimeF0_asLong,
806 unsigned long long int acquisitionTimeF0_asLong,
782 ring_node *ring_node_swf_extracted,
807 ring_node *ring_node_swf_extracted,
783 int *swf_extracted)
808 int *swf_extracted)
784 {
809 {
785 unsigned int i;
810 unsigned int i;
786 unsigned int node;
811 unsigned int node;
787 unsigned long long int centerTime_asLong;
812 unsigned long long int centerTime_asLong;
788 unsigned long long int acquisitionTime_asLong;
813 unsigned long long int acquisitionTime_asLong;
789 unsigned long long int bufferAcquisitionTime_asLong;
814 unsigned long long int bufferAcquisitionTime_asLong;
790 unsigned char *ptr1;
815 unsigned char *ptr1;
791 unsigned char *ptr2;
816 unsigned char *ptr2;
792 unsigned char *timeCharPtr;
817 unsigned char *timeCharPtr;
793 unsigned char nb_ring_nodes;
818 unsigned char nb_ring_nodes;
794 unsigned long long int frequency_asLong;
819 unsigned long long int frequency_asLong;
795 unsigned long long int nbTicksPerSample_asLong;
820 unsigned long long int nbTicksPerSample_asLong;
796 unsigned long long int nbSamplesPart1_asLong;
821 unsigned long long int nbSamplesPart1_asLong;
797 unsigned long long int sampleOffset_asLong;
822 unsigned long long int sampleOffset_asLong;
798
823
799 unsigned int deltaT_F0;
824 unsigned int deltaT_F0;
800 unsigned int deltaT_F1;
825 unsigned int deltaT_F1;
801 unsigned long long int deltaT_F2;
826 unsigned long long int deltaT_F2;
802
827
803 deltaT_F0 = DELTAT_F0;
828 deltaT_F0 = DELTAT_F0;
804 deltaT_F1 = DELTAT_F1;
829 deltaT_F1 = DELTAT_F1;
805 deltaT_F2 = DELTAT_F2;
830 deltaT_F2 = DELTAT_F2;
806 sampleOffset_asLong = INIT_CHAR;
831 sampleOffset_asLong = INIT_CHAR;
807
832
808 // (1) get the f0 acquisition time => the value is passed in argument
833 // (1) get the f0 acquisition time => the value is passed in argument
809
834
810 // (2) compute the central reference time
835 // (2) compute the central reference time
811 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
836 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
812 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
837 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
813 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
838 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
814 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
839 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
815
840
816 // (3) compute the acquisition time of the current snapshot
841 // (3) compute the acquisition time of the current snapshot
817 switch(frequencyChannel)
842 switch(frequencyChannel)
818 {
843 {
819 case CHANNELF1: // 1 is for F1 = 4096 Hz
844 case CHANNELF1: // 1 is for F1 = 4096 Hz
820 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
845 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
821 nb_ring_nodes = NB_RING_NODES_F1;
846 nb_ring_nodes = NB_RING_NODES_F1;
822 frequency_asLong = FREQ_F1;
847 frequency_asLong = FREQ_F1;
823 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
848 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
824 break;
849 break;
825 case CHANNELF2: // 2 is for F2 = 256 Hz
850 case CHANNELF2: // 2 is for F2 = 256 Hz
826 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
851 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
827 nb_ring_nodes = NB_RING_NODES_F2;
852 nb_ring_nodes = NB_RING_NODES_F2;
828 frequency_asLong = FREQ_F2;
853 frequency_asLong = FREQ_F2;
829 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
854 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
830 break;
855 break;
831 default:
856 default:
832 acquisitionTime_asLong = centerTime_asLong;
857 acquisitionTime_asLong = centerTime_asLong;
833 nb_ring_nodes = 0;
858 nb_ring_nodes = 0;
834 frequency_asLong = FREQ_F2;
859 frequency_asLong = FREQ_F2;
835 nbTicksPerSample_asLong = TICKS_PER_T2;
860 nbTicksPerSample_asLong = TICKS_PER_T2;
836 break;
861 break;
837 }
862 }
838
863
839 //*****************************************************************************
864 //*****************************************************************************
840 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
865 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
841 node = 0;
866 node = 0;
842 while ( node < nb_ring_nodes)
867 while ( node < nb_ring_nodes)
843 {
868 {
844 //PRINTF1("%d ... ", node);
845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
869 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
870 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
847 {
871 {
848 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
849 node = nb_ring_nodes;
872 node = nb_ring_nodes;
850 }
873 }
851 else
874 else
852 {
875 {
853 node = node + 1;
876 node = node + 1;
854 ring_node_to_send = ring_node_to_send->previous;
877 ring_node_to_send = ring_node_to_send->previous;
855 }
878 }
856 }
879 }
857
880
858 // (5) compute the number of samples to take in the current buffer
881 // (5) compute the number of samples to take in the current buffer
859 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
882 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
860 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
883 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
861 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
862
884
863 // (6) compute the final acquisition time
885 // (6) compute the final acquisition time
864 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
886 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
865 (sampleOffset_asLong * nbTicksPerSample_asLong);
887 (sampleOffset_asLong * nbTicksPerSample_asLong);
866
888
867 // (7) copy the acquisition time at the beginning of the extrated snapshot
889 // (7) copy the acquisition time at the beginning of the extrated snapshot
868 ptr1 = (unsigned char*) &acquisitionTime_asLong;
890 ptr1 = (unsigned char*) &acquisitionTime_asLong;
869 // fine time
891 // fine time
870 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
892 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
871 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
893 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
872 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
894 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
873 // coarse time
895 // coarse time
874 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
896 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
875 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
897 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
876 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
898 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
877 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
899 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
878 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
900 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
879
901
880 // re set the synchronization bit
902 // re set the synchronization bit
881 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
903 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
882 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
904 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
883
905
884 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
906 if ( (nbSamplesPart1_asLong > NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
885 {
907 {
886 nbSamplesPart1_asLong = 0;
908 nbSamplesPart1_asLong = 0;
887 }
909 }
888 // copy the part 1 of the snapshot in the extracted buffer
910 // copy the part 1 of the snapshot in the extracted buffer
889 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
911 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
890 {
912 {
891 swf_extracted[i] =
913 swf_extracted[i] =
892 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
914 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
893 }
915 }
894 // copy the part 2 of the snapshot in the extracted buffer
916 // copy the part 2 of the snapshot in the extracted buffer
895 ring_node_to_send = ring_node_to_send->next;
917 ring_node_to_send = ring_node_to_send->next;
896 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
918 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
897 {
919 {
898 swf_extracted[i] =
920 swf_extracted[i] =
899 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
921 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
900 }
922 }
901 }
923 }
902
924
903 double computeCorrection( unsigned char *timePtr )
925 double computeCorrection( unsigned char *timePtr )
904 {
926 {
905 unsigned long long int acquisitionTime;
927 unsigned long long int acquisitionTime;
906 unsigned long long int centerTime;
928 unsigned long long int centerTime;
907 unsigned long long int previousTick;
929 unsigned long long int previousTick;
908 unsigned long long int nextTick;
930 unsigned long long int nextTick;
909 unsigned long long int deltaPreviousTick;
931 unsigned long long int deltaPreviousTick;
910 unsigned long long int deltaNextTick;
932 unsigned long long int deltaNextTick;
911 double deltaPrevious_ms;
933 double deltaPrevious_ms;
912 double deltaNext_ms;
934 double deltaNext_ms;
913 double correctionInF2;
935 double correctionInF2;
914
936
915 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
937 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
916
938
917 // get acquisition time in fine time ticks
939 // get acquisition time in fine time ticks
918 acquisitionTime = get_acquisition_time( timePtr );
940 acquisitionTime = get_acquisition_time( timePtr );
919
941
920 // compute center time
942 // compute center time
921 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
943 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
922 previousTick = centerTime - (centerTime & INT16_ALL_F);
944 previousTick = centerTime - (centerTime & INT16_ALL_F);
923 nextTick = previousTick + TICKS_PER_S;
945 nextTick = previousTick + TICKS_PER_S;
924
946
925 deltaPreviousTick = centerTime - previousTick;
947 deltaPreviousTick = centerTime - previousTick;
926 deltaNextTick = nextTick - centerTime;
948 deltaNextTick = nextTick - centerTime;
927
949
928 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
950 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
929 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
951 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
930
952
931 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
953 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
932
954
933 // which tick is the closest?
955 // which tick is the closest?
934 if (deltaPreviousTick > deltaNextTick)
956 if (deltaPreviousTick > deltaNextTick)
935 {
957 {
936 // the snapshot center is just before the second => increase delta_snapshot
958 // the snapshot center is just before the second => increase delta_snapshot
937 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
959 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
938 }
960 }
939 else
961 else
940 {
962 {
941 // the snapshot center is just after the second => decrease delta_snapshot
963 // the snapshot center is just after the second => decrease delta_snapshot
942 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
964 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
943 }
965 }
944
966
945 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
967 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
946
968
947 return correctionInF2;
969 return correctionInF2;
948 }
970 }
949
971
950 void applyCorrection( double correction )
972 void applyCorrection( double correction )
951 {
973 {
952 int correctionInt;
974 int correctionInt;
953
975
954 correctionInt = 0;
976 correctionInt = 0;
955
977
956 if (correction >= 0.)
978 if (correction >= 0.)
957 {
979 {
958 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
980 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
959 {
981 {
960 correctionInt = ONE_TICK_CORR;
982 correctionInt = ONE_TICK_CORR;
961 }
983 }
962 else
984 else
963 {
985 {
964 correctionInt = CORR_MULT * floor(correction);
986 correctionInt = CORR_MULT * floor(correction);
965 }
987 }
966 }
988 }
967 else
989 else
968 {
990 {
969 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
991 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
970 {
992 {
971 correctionInt = -ONE_TICK_CORR;
993 correctionInt = -ONE_TICK_CORR;
972 }
994 }
973 else
995 else
974 {
996 {
975 correctionInt = CORR_MULT * ceil(correction);
997 correctionInt = CORR_MULT * ceil(correction);
976 }
998 }
977 }
999 }
978 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
1000 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
979 }
1001 }
980
1002
981 void snapshot_resynchronization( unsigned char *timePtr )
1003 void snapshot_resynchronization( unsigned char *timePtr )
982 {
1004 {
983 /** This function compute a correction to apply on delta_snapshot.
1005 /** This function compute a correction to apply on delta_snapshot.
984 *
1006 *
985 *
1007 *
986 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
1008 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
987 *
1009 *
988 * @return void
1010 * @return void
989 *
1011 *
990 */
1012 */
991
1013
992 static double correction = INIT_FLOAT;
1014 static double correction = INIT_FLOAT;
993 static resynchro_state state = MEASURE;
1015 static resynchro_state state = MEASURE;
994 static unsigned int nbSnapshots = 0;
1016 static unsigned int nbSnapshots = 0;
995
1017
996 int correctionInt;
1018 int correctionInt;
997
1019
998 correctionInt = 0;
1020 correctionInt = 0;
999
1021
1000 switch (state)
1022 switch (state)
1001 {
1023 {
1002
1024
1003 case MEASURE:
1025 case MEASURE:
1004 // ********
1026 // ********
1005 PRINTF1("MEASURE === %d\n", nbSnapshots);
1027 PRINTF1("MEASURE === %d\n", nbSnapshots);
1006 state = CORRECTION;
1028 state = CORRECTION;
1007 correction = computeCorrection( timePtr );
1029 correction = computeCorrection( timePtr );
1008 PRINTF1("MEASURE === correction = %.2f\n", correction );
1030 PRINTF1("MEASURE === correction = %.2f\n", correction );
1009 applyCorrection( correction );
1031 applyCorrection( correction );
1010 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1032 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1011 //****
1033 //****
1012 break;
1034 break;
1013
1035
1014 case CORRECTION:
1036 case CORRECTION:
1015 //************
1037 //************
1016 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1038 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1017 state = MEASURE;
1039 state = MEASURE;
1018 computeCorrection( timePtr );
1040 computeCorrection( timePtr );
1019 set_wfp_delta_snapshot();
1041 set_wfp_delta_snapshot();
1020 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1042 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1021 //****
1043 //****
1022 break;
1044 break;
1023
1045
1024 default:
1046 default:
1025 break;
1047 break;
1026
1048
1027 }
1049 }
1028
1050
1029 nbSnapshots++;
1051 nbSnapshots++;
1030 }
1052 }
1031
1053
1032 //**************
1054 //**************
1033 // wfp registers
1055 // wfp registers
1034 void reset_wfp_burst_enable( void )
1056 void reset_wfp_burst_enable( void )
1035 {
1057 {
1036 /** This function resets the waveform picker burst_enable register.
1058 /** This function resets the waveform picker burst_enable register.
1037 *
1059 *
1038 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1060 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1039 *
1061 *
1040 */
1062 */
1041
1063
1042 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1064 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1043 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1065 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1044 }
1066 }
1045
1067
1046 void reset_wfp_status( void )
1068 void reset_wfp_status( void )
1047 {
1069 {
1048 /** This function resets the waveform picker status register.
1070 /** This function resets the waveform picker status register.
1049 *
1071 *
1050 * All status bits are set to 0 [new_err full_err full].
1072 * All status bits are set to 0 [new_err full_err full].
1051 *
1073 *
1052 */
1074 */
1053
1075
1054 waveform_picker_regs->status = INT16_ALL_F;
1076 waveform_picker_regs->status = INT16_ALL_F;
1055 }
1077 }
1056
1078
1057 void reset_wfp_buffer_addresses( void )
1079 void reset_wfp_buffer_addresses( void )
1058 {
1080 {
1059 // F0
1081 // F0
1060 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1082 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1061 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1083 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1062 // F1
1084 // F1
1063 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1085 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1064 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1086 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1065 // F2
1087 // F2
1066 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1088 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1067 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1089 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1068 // F3
1090 // F3
1069 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1091 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1070 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1092 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1071 }
1093 }
1072
1094
1073 void reset_waveform_picker_regs( void )
1095 void reset_waveform_picker_regs( void )
1074 {
1096 {
1075 /** This function resets the waveform picker module registers.
1097 /** This function resets the waveform picker module registers.
1076 *
1098 *
1077 * The registers affected by this function are located at the following offset addresses:
1099 * The registers affected by this function are located at the following offset addresses:
1078 * - 0x00 data_shaping
1100 * - 0x00 data_shaping
1079 * - 0x04 run_burst_enable
1101 * - 0x04 run_burst_enable
1080 * - 0x08 addr_data_f0
1102 * - 0x08 addr_data_f0
1081 * - 0x0C addr_data_f1
1103 * - 0x0C addr_data_f1
1082 * - 0x10 addr_data_f2
1104 * - 0x10 addr_data_f2
1083 * - 0x14 addr_data_f3
1105 * - 0x14 addr_data_f3
1084 * - 0x18 status
1106 * - 0x18 status
1085 * - 0x1C delta_snapshot
1107 * - 0x1C delta_snapshot
1086 * - 0x20 delta_f0
1108 * - 0x20 delta_f0
1087 * - 0x24 delta_f0_2
1109 * - 0x24 delta_f0_2
1088 * - 0x28 delta_f1 (obsolet parameter)
1110 * - 0x28 delta_f1 (obsolet parameter)
1089 * - 0x2c delta_f2
1111 * - 0x2c delta_f2
1090 * - 0x30 nb_data_by_buffer
1112 * - 0x30 nb_data_by_buffer
1091 * - 0x34 nb_snapshot_param
1113 * - 0x34 nb_snapshot_param
1092 * - 0x38 start_date
1114 * - 0x38 start_date
1093 * - 0x3c nb_word_in_buffer
1115 * - 0x3c nb_word_in_buffer
1094 *
1116 *
1095 */
1117 */
1096
1118
1097 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1119 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1098
1120
1099 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1121 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1100
1122
1101 reset_wfp_buffer_addresses();
1123 reset_wfp_buffer_addresses();
1102
1124
1103 reset_wfp_status(); // 0x18
1125 reset_wfp_status(); // 0x18
1104
1126
1105 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1127 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1106
1128
1107 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1129 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1108
1130
1109 //the parameter delta_f1 [0x28] is not used anymore
1131 //the parameter delta_f1 [0x28] is not used anymore
1110
1132
1111 set_wfp_delta_f2(); // 0x2c
1133 set_wfp_delta_f2(); // 0x2c
1112
1134
1113 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1135 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1114 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1136 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1115 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1137 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1116 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1138 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1117 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1139 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1118 // 2688 = 8 * 336
1140 // 2688 = 8 * 336
1119 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1141 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1120 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1142 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1121 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1143 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1122 //
1144 //
1123 // coarse time and fine time registers are not initialized, they are volatile
1145 // coarse time and fine time registers are not initialized, they are volatile
1124 //
1146 //
1125 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1147 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1126 }
1148 }
1127
1149
1128 void set_wfp_data_shaping( void )
1150 void set_wfp_data_shaping( void )
1129 {
1151 {
1130 /** This function sets the data_shaping register of the waveform picker module.
1152 /** This function sets the data_shaping register of the waveform picker module.
1131 *
1153 *
1132 * The value is read from one field of the parameter_dump_packet structure:\n
1154 * The value is read from one field of the parameter_dump_packet structure:\n
1133 * bw_sp0_sp1_r0_r1
1155 * bw_sp0_sp1_r0_r1
1134 *
1156 *
1135 */
1157 */
1136
1158
1137 unsigned char data_shaping;
1159 unsigned char data_shaping;
1138
1160
1139 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1161 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1140 // waveform picker : [R1 R0 SP1 SP0 BW]
1162 // waveform picker : [R1 R0 SP1 SP0 BW]
1141
1163
1142 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1164 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1143
1165
1144 waveform_picker_regs->data_shaping =
1166 waveform_picker_regs->data_shaping =
1145 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1167 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1146 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1168 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1147 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1169 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1148 + ( (data_shaping & BIT_2) << 1 ) // R0
1170 + ( (data_shaping & BIT_2) << 1 ) // R0
1149 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1171 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1150 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1172 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1151 }
1173 }
1152
1174
1153 void set_wfp_burst_enable_register( unsigned char mode )
1175 void set_wfp_burst_enable_register( unsigned char mode )
1154 {
1176 {
1155 /** This function sets the waveform picker burst_enable register depending on the mode.
1177 /** This function sets the waveform picker burst_enable register depending on the mode.
1156 *
1178 *
1157 * @param mode is the LFR mode to launch.
1179 * @param mode is the LFR mode to launch.
1158 *
1180 *
1159 * The burst bits shall be before the enable bits.
1181 * The burst bits shall be before the enable bits.
1160 *
1182 *
1161 */
1183 */
1162
1184
1163 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1185 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1164 // the burst bits shall be set first, before the enable bits
1186 // the burst bits shall be set first, before the enable bits
1165 switch(mode) {
1187 switch(mode) {
1166 case LFR_MODE_NORMAL:
1188 case LFR_MODE_NORMAL:
1167 case LFR_MODE_SBM1:
1189 case LFR_MODE_SBM1:
1168 case LFR_MODE_SBM2:
1190 case LFR_MODE_SBM2:
1169 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1191 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1170 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0
1192 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0
1171 break;
1193 break;
1172 case LFR_MODE_BURST:
1194 case LFR_MODE_BURST:
1173 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1195 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1174 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2
1196 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2
1175 break;
1197 break;
1176 default:
1198 default:
1177 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1199 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1178 break;
1200 break;
1179 }
1201 }
1180 }
1202 }
1181
1203
1182 void set_wfp_delta_snapshot( void )
1204 void set_wfp_delta_snapshot( void )
1183 {
1205 {
1184 /** This function sets the delta_snapshot register of the waveform picker module.
1206 /** This function sets the delta_snapshot register of the waveform picker module.
1185 *
1207 *
1186 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1208 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1187 * - sy_lfr_n_swf_p[0]
1209 * - sy_lfr_n_swf_p[0]
1188 * - sy_lfr_n_swf_p[1]
1210 * - sy_lfr_n_swf_p[1]
1189 *
1211 *
1190 */
1212 */
1191
1213
1192 unsigned int delta_snapshot;
1214 unsigned int delta_snapshot;
1193 unsigned int delta_snapshot_in_T2;
1215 unsigned int delta_snapshot_in_T2;
1194
1216
1195 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1217 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1196 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1218 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1197
1219
1198 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1220 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1199 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1221 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1200 }
1222 }
1201
1223
1202 void set_wfp_delta_f0_f0_2( void )
1224 void set_wfp_delta_f0_f0_2( void )
1203 {
1225 {
1204 unsigned int delta_snapshot;
1226 unsigned int delta_snapshot;
1205 unsigned int nb_samples_per_snapshot;
1227 unsigned int nb_samples_per_snapshot;
1206 float delta_f0_in_float;
1228 float delta_f0_in_float;
1207
1229
1208 delta_snapshot = waveform_picker_regs->delta_snapshot;
1230 delta_snapshot = waveform_picker_regs->delta_snapshot;
1209 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1231 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1210 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1232 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1211
1233
1212 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1234 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1213 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2;
1235 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2;
1214 }
1236 }
1215
1237
1216 void set_wfp_delta_f1( void )
1238 void set_wfp_delta_f1( void )
1217 {
1239 {
1218 /** Sets the value of the delta_f1 parameter
1240 /** Sets the value of the delta_f1 parameter
1219 *
1241 *
1220 * @param void
1242 * @param void
1221 *
1243 *
1222 * @return void
1244 * @return void
1223 *
1245 *
1224 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1246 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1225 *
1247 *
1226 */
1248 */
1227
1249
1228 unsigned int delta_snapshot;
1250 unsigned int delta_snapshot;
1229 unsigned int nb_samples_per_snapshot;
1251 unsigned int nb_samples_per_snapshot;
1230 float delta_f1_in_float;
1252 float delta_f1_in_float;
1231
1253
1232 delta_snapshot = waveform_picker_regs->delta_snapshot;
1254 delta_snapshot = waveform_picker_regs->delta_snapshot;
1233 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1255 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1234 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1256 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1235
1257
1236 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1258 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1237 }
1259 }
1238
1260
1239 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1261 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1240 {
1262 {
1241 /** Sets the value of the delta_f2 parameter
1263 /** Sets the value of the delta_f2 parameter
1242 *
1264 *
1243 * @param void
1265 * @param void
1244 *
1266 *
1245 * @return void
1267 * @return void
1246 *
1268 *
1247 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1269 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1248 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1270 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1249 *
1271 *
1250 */
1272 */
1251
1273
1252 unsigned int delta_snapshot;
1274 unsigned int delta_snapshot;
1253 unsigned int nb_samples_per_snapshot;
1275 unsigned int nb_samples_per_snapshot;
1254
1276
1255 delta_snapshot = waveform_picker_regs->delta_snapshot;
1277 delta_snapshot = waveform_picker_regs->delta_snapshot;
1256 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1278 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1257
1279
1258 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1280 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1259 }
1281 }
1260
1282
1261 //*****************
1283 //*****************
1262 // local parameters
1284 // local parameters
1263
1285
1264 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1286 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1265 {
1287 {
1266 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1288 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1267 *
1289 *
1268 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1290 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1269 * @param sid is the source identifier of the packet being updated.
1291 * @param sid is the source identifier of the packet being updated.
1270 *
1292 *
1271 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1293 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1272 * The sequence counters shall wrap around from 2^14 to zero.
1294 * The sequence counters shall wrap around from 2^14 to zero.
1273 * The sequence counter shall start at zero at startup.
1295 * The sequence counter shall start at zero at startup.
1274 *
1296 *
1275 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1297 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1276 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1298 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1277 *
1299 *
1278 */
1300 */
1279
1301
1280 unsigned short *sequence_cnt;
1302 unsigned short *sequence_cnt;
1281 unsigned short segmentation_grouping_flag;
1303 unsigned short segmentation_grouping_flag;
1282 unsigned short new_packet_sequence_control;
1304 unsigned short new_packet_sequence_control;
1283 rtems_mode initial_mode_set;
1305 rtems_mode initial_mode_set;
1284 rtems_mode current_mode_set;
1306 rtems_mode current_mode_set;
1285 rtems_status_code status;
1307 rtems_status_code status;
1286
1308
1287 initial_mode_set = RTEMS_DEFAULT_MODES;
1309 initial_mode_set = RTEMS_DEFAULT_MODES;
1288 current_mode_set = RTEMS_DEFAULT_MODES;
1310 current_mode_set = RTEMS_DEFAULT_MODES;
1289 sequence_cnt = NULL;
1311 sequence_cnt = NULL;
1290
1312
1291 //******************************************
1313 //******************************************
1292 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1314 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1293 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1315 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1294
1316
1295 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1317 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1296 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1318 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1297 || (sid == SID_BURST_CWF_F2)
1319 || (sid == SID_BURST_CWF_F2)
1298 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1320 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1299 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1321 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1300 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1322 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1301 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1323 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1302 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1324 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1303 {
1325 {
1304 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1326 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1305 }
1327 }
1306 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1328 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1307 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1329 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1308 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1330 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1309 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1331 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1310 {
1332 {
1311 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1333 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1312 }
1334 }
1313 else
1335 else
1314 {
1336 {
1315 sequence_cnt = (unsigned short *) NULL;
1337 sequence_cnt = (unsigned short *) NULL;
1316 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1338 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1317 }
1339 }
1318
1340
1319 if (sequence_cnt != NULL)
1341 if (sequence_cnt != NULL)
1320 {
1342 {
1321 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1343 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1322 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1344 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1323
1345
1324 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1346 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1325
1347
1326 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1348 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1327 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1349 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1328
1350
1329 // increment the sequence counter
1351 // increment the sequence counter
1330 if ( *sequence_cnt < SEQ_CNT_MAX)
1352 if ( *sequence_cnt < SEQ_CNT_MAX)
1331 {
1353 {
1332 *sequence_cnt = *sequence_cnt + 1;
1354 *sequence_cnt = *sequence_cnt + 1;
1333 }
1355 }
1334 else
1356 else
1335 {
1357 {
1336 *sequence_cnt = 0;
1358 *sequence_cnt = 0;
1337 }
1359 }
1338 }
1360 }
1339
1361
1340 //*************************************
1362 //*************************************
1341 // RESTORE THE MODE OF THE CALLING TASK
1363 // RESTORE THE MODE OF THE CALLING TASK
1342 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1364 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1343 }
1365 }
1366
@@ -1,94 +1,117
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 #define NB_VALUES_PER_SM 25
25 #define NB_VALUES_PER_SM 25
2 #define NB_BINS_PER_SM 128
26 #define NB_BINS_PER_SM 128
3
27
4 #define NB_BINS_COMPRESSED_SM_F0 11
28 #define NB_BINS_COMPRESSED_SM_F0 11
5 #define ASM_F0_INDICE_START 17 // 88 bins
29 #define ASM_F0_INDICE_START 17 // 88 bins
6 #define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins
7 #define NB_BINS_TO_AVERAGE_ASM_F0 8
30 #define NB_BINS_TO_AVERAGE_ASM_F0 8
8
31
9 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
32 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
10 {
33 {
11 int frequencyBin;
34 int frequencyBin;
12 int asmComponent;
35 int asmComponent;
13 unsigned int offsetASM;
36 unsigned int offsetASM;
14 unsigned int offsetASMReorganized;
37 unsigned int offsetASMReorganized;
15
38
16 // BUILD DATA
39 // BUILD DATA
17 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
40 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
18 {
41 {
19 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
42 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
20 {
43 {
21 offsetASMReorganized =
44 offsetASMReorganized =
22 frequencyBin * NB_VALUES_PER_SM
45 frequencyBin * NB_VALUES_PER_SM
23 + asmComponent;
46 + asmComponent;
24 offsetASM =
47 offsetASM =
25 asmComponent * NB_BINS_PER_SM
48 asmComponent * NB_BINS_PER_SM
26 + frequencyBin;
49 + frequencyBin;
27 averaged_spec_mat_reorganized[offsetASMReorganized ] =
50 averaged_spec_mat_reorganized[offsetASMReorganized ] =
28 averaged_spec_mat[ offsetASM ] / divider;
51 averaged_spec_mat[ offsetASM ] / divider;
29 }
52 }
30 }
53 }
31 }
54 }
32
55
33 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
56 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
34 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
57 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
35 {
58 {
36 int frequencyBin;
59 int frequencyBin;
37 int asmComponent;
60 int asmComponent;
38 int offsetASM;
61 int offsetASM;
39 int offsetCompressed;
62 int offsetCompressed;
40 int k;
63 int k;
41
64
42 // BUILD DATA
65 // BUILD DATA
43 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
66 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
44 {
67 {
45 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
68 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
46 {
69 {
47 offsetCompressed = // NO TIME OFFSET
70 offsetCompressed = // NO TIME OFFSET
48 frequencyBin * NB_VALUES_PER_SM
71 frequencyBin * NB_VALUES_PER_SM
49 + asmComponent;
72 + asmComponent;
50 offsetASM = // NO TIME OFFSET
73 offsetASM = // NO TIME OFFSET
51 asmComponent * NB_BINS_PER_SM
74 asmComponent * NB_BINS_PER_SM
52 + ASMIndexStart
75 + ASMIndexStart
53 + frequencyBin * nbBinsToAverage;
76 + frequencyBin * nbBinsToAverage;
54 compressed_spec_mat[ offsetCompressed ] = 0;
77 compressed_spec_mat[ offsetCompressed ] = 0;
55 for ( k = 0; k < nbBinsToAverage; k++ )
78 for ( k = 0; k < nbBinsToAverage; k++ )
56 {
79 {
57 compressed_spec_mat[offsetCompressed ] =
80 compressed_spec_mat[offsetCompressed ] =
58 ( compressed_spec_mat[ offsetCompressed ]
81 ( compressed_spec_mat[ offsetCompressed ]
59 + averaged_spec_mat[ offsetASM + k ] );
82 + averaged_spec_mat[ offsetASM + k ] );
60 }
83 }
61 compressed_spec_mat[ offsetCompressed ] =
84 compressed_spec_mat[ offsetCompressed ] =
62 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
85 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
63 }
86 }
64 }
87 }
65 }
88 }
66
89
67 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
90 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
68 {
91 {
69 unsigned int i;
92 unsigned int i;
70 float re;
93 float re;
71 float im;
94 float im;
72
95
73 for (i=0; i<NB_BINS_PER_SM; i++){
96 for (i=0; i<NB_BINS_PER_SM; i++){
74 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
97 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
75 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
98 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
76 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
99 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
77 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
100 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
78 }
101 }
79
102
80 }
103 }
81
104
82 void ASM_patch( float *inputASM, float *outputASM )
105 void ASM_patch( float *inputASM, float *outputASM )
83 {
106 {
84 extractReImVectors( inputASM, outputASM, 1); // b1b2
107 extractReImVectors( inputASM, outputASM, 1); // b1b2
85 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
108 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
86 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
109 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
87 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
110 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
88 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
111 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
89 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
112 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
90 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
113 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
91 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
114 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
92 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
115 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
93 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
116 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
94 }
117 }
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (665 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (728 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (696 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (510 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1323 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now