##// END OF EJS Templates
Sync
paul -
r147:8abc460aa11b VHDLib206
parent child
Show More
@@ -1,273 +1,273
1 1 #############################################################################
2 2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Jun 12 08:10:29 2014
3 # Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Jun 12 15:33:39 2014
4 4 # Project: fsw-qt.pro
5 5 # Template: app
6 6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
7 7 #############################################################################
8 8
9 9 ####### Compiler, tools and options
10 10
11 11 CC = sparc-rtems-gcc
12 12 CXX = sparc-rtems-g++
13 13 DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=9 -DPRINT_MESSAGES_ON_CONSOLE
14 14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
15 15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
16 16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header -I../header/processing -I../src/LFR_basic-parameters
17 17 LINK = sparc-rtems-g++
18 18 LFLAGS =
19 19 LIBS = $(SUBLIBS)
20 20 AR = sparc-rtems-ar rcs
21 21 RANLIB =
22 22 QMAKE = /usr/bin/qmake-qt4
23 23 TAR = tar -cf
24 24 COMPRESS = gzip -9f
25 25 COPY = cp -f
26 26 SED = sed
27 27 COPY_FILE = $(COPY)
28 28 COPY_DIR = $(COPY) -r
29 29 STRIP = sparc-rtems-strip
30 30 INSTALL_FILE = install -m 644 -p
31 31 INSTALL_DIR = $(COPY_DIR)
32 32 INSTALL_PROGRAM = install -m 755 -p
33 33 DEL_FILE = rm -f
34 34 SYMLINK = ln -f -s
35 35 DEL_DIR = rmdir
36 36 MOVE = mv -f
37 37 CHK_DIR_EXISTS= test -d
38 38 MKDIR = mkdir -p
39 39
40 40 ####### Output directory
41 41
42 42 OBJECTS_DIR = obj/
43 43
44 44 ####### Files
45 45
46 46 SOURCES = ../src/wf_handler.c \
47 47 ../src/tc_handler.c \
48 48 ../src/fsw_misc.c \
49 49 ../src/fsw_init.c \
50 50 ../src/fsw_globals.c \
51 51 ../src/fsw_spacewire.c \
52 52 ../src/tc_load_dump_parameters.c \
53 53 ../src/tm_lfr_tc_exe.c \
54 54 ../src/tc_acceptance.c \
55 55 ../src/processing/fsw_processing.c \
56 56 ../src/processing/avf0_prc0.c \
57 57 ../src/processing/avf1_prc1.c \
58 58 ../src/processing/avf2_prc2.c \
59 59 ../src/lfr_cpu_usage_report.c \
60 60 ../src/LFR_basic-parameters/basic_parameters.c
61 61 OBJECTS = obj/wf_handler.o \
62 62 obj/tc_handler.o \
63 63 obj/fsw_misc.o \
64 64 obj/fsw_init.o \
65 65 obj/fsw_globals.o \
66 66 obj/fsw_spacewire.o \
67 67 obj/tc_load_dump_parameters.o \
68 68 obj/tm_lfr_tc_exe.o \
69 69 obj/tc_acceptance.o \
70 70 obj/fsw_processing.o \
71 71 obj/avf0_prc0.o \
72 72 obj/avf1_prc1.o \
73 73 obj/avf2_prc2.o \
74 74 obj/lfr_cpu_usage_report.o \
75 75 obj/basic_parameters.o
76 76 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
77 77 /usr/lib64/qt4/mkspecs/common/linux.conf \
78 78 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
79 79 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
80 80 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
81 81 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
82 82 /usr/lib64/qt4/mkspecs/qconfig.pri \
83 83 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
84 84 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
85 85 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
86 86 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
87 87 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
88 88 sparc.pri \
89 89 /usr/lib64/qt4/mkspecs/features/release.prf \
90 90 /usr/lib64/qt4/mkspecs/features/default_post.prf \
91 91 /usr/lib64/qt4/mkspecs/features/shared.prf \
92 92 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
93 93 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
94 94 /usr/lib64/qt4/mkspecs/features/resources.prf \
95 95 /usr/lib64/qt4/mkspecs/features/uic.prf \
96 96 /usr/lib64/qt4/mkspecs/features/yacc.prf \
97 97 /usr/lib64/qt4/mkspecs/features/lex.prf \
98 98 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf \
99 99 fsw-qt.pro
100 100 QMAKE_TARGET = fsw
101 101 DESTDIR = bin/
102 102 TARGET = bin/fsw
103 103
104 104 first: all
105 105 ####### Implicit rules
106 106
107 107 .SUFFIXES: .o .c .cpp .cc .cxx .C
108 108
109 109 .cpp.o:
110 110 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
111 111
112 112 .cc.o:
113 113 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
114 114
115 115 .cxx.o:
116 116 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
117 117
118 118 .C.o:
119 119 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
120 120
121 121 .c.o:
122 122 $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
123 123
124 124 ####### Build rules
125 125
126 126 all: Makefile $(TARGET)
127 127
128 128 $(TARGET): $(OBJECTS)
129 129 @$(CHK_DIR_EXISTS) bin/ || $(MKDIR) bin/
130 130 $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
131 131
132 132 Makefile: fsw-qt.pro /usr/lib64/qt4/mkspecs/linux-g++/qmake.conf /usr/lib64/qt4/mkspecs/common/unix.conf \
133 133 /usr/lib64/qt4/mkspecs/common/linux.conf \
134 134 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
135 135 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
136 136 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
137 137 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
138 138 /usr/lib64/qt4/mkspecs/qconfig.pri \
139 139 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
140 140 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
141 141 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
142 142 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
143 143 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
144 144 sparc.pri \
145 145 /usr/lib64/qt4/mkspecs/features/release.prf \
146 146 /usr/lib64/qt4/mkspecs/features/default_post.prf \
147 147 /usr/lib64/qt4/mkspecs/features/shared.prf \
148 148 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
149 149 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
150 150 /usr/lib64/qt4/mkspecs/features/resources.prf \
151 151 /usr/lib64/qt4/mkspecs/features/uic.prf \
152 152 /usr/lib64/qt4/mkspecs/features/yacc.prf \
153 153 /usr/lib64/qt4/mkspecs/features/lex.prf \
154 154 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf
155 155 $(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
156 156 /usr/lib64/qt4/mkspecs/common/unix.conf:
157 157 /usr/lib64/qt4/mkspecs/common/linux.conf:
158 158 /usr/lib64/qt4/mkspecs/common/gcc-base.conf:
159 159 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf:
160 160 /usr/lib64/qt4/mkspecs/common/g++-base.conf:
161 161 /usr/lib64/qt4/mkspecs/common/g++-unix.conf:
162 162 /usr/lib64/qt4/mkspecs/qconfig.pri:
163 163 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri:
164 164 /usr/lib64/qt4/mkspecs/features/qt_functions.prf:
165 165 /usr/lib64/qt4/mkspecs/features/qt_config.prf:
166 166 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf:
167 167 /usr/lib64/qt4/mkspecs/features/default_pre.prf:
168 168 sparc.pri:
169 169 /usr/lib64/qt4/mkspecs/features/release.prf:
170 170 /usr/lib64/qt4/mkspecs/features/default_post.prf:
171 171 /usr/lib64/qt4/mkspecs/features/shared.prf:
172 172 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
173 173 /usr/lib64/qt4/mkspecs/features/warn_on.prf:
174 174 /usr/lib64/qt4/mkspecs/features/resources.prf:
175 175 /usr/lib64/qt4/mkspecs/features/uic.prf:
176 176 /usr/lib64/qt4/mkspecs/features/yacc.prf:
177 177 /usr/lib64/qt4/mkspecs/features/lex.prf:
178 178 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf:
179 179 qmake: FORCE
180 180 @$(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
181 181
182 182 dist:
183 183 @$(CHK_DIR_EXISTS) obj/fsw1.0.0 || $(MKDIR) obj/fsw1.0.0
184 184 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/fsw1.0.0/ && (cd `dirname obj/fsw1.0.0` && $(TAR) fsw1.0.0.tar fsw1.0.0 && $(COMPRESS) fsw1.0.0.tar) && $(MOVE) `dirname obj/fsw1.0.0`/fsw1.0.0.tar.gz . && $(DEL_FILE) -r obj/fsw1.0.0
185 185
186 186
187 187 clean:compiler_clean
188 188 -$(DEL_FILE) $(OBJECTS)
189 189 -$(DEL_FILE) *~ core *.core
190 190
191 191
192 192 ####### Sub-libraries
193 193
194 194 distclean: clean
195 195 -$(DEL_FILE) $(TARGET)
196 196 -$(DEL_FILE) Makefile
197 197
198 198
199 199 grmon:
200 200 cd bin && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
201 201
202 202 check: first
203 203
204 204 compiler_rcc_make_all:
205 205 compiler_rcc_clean:
206 206 compiler_uic_make_all:
207 207 compiler_uic_clean:
208 208 compiler_image_collection_make_all: qmake_image_collection.cpp
209 209 compiler_image_collection_clean:
210 210 -$(DEL_FILE) qmake_image_collection.cpp
211 211 compiler_yacc_decl_make_all:
212 212 compiler_yacc_decl_clean:
213 213 compiler_yacc_impl_make_all:
214 214 compiler_yacc_impl_clean:
215 215 compiler_lex_make_all:
216 216 compiler_lex_clean:
217 217 compiler_clean:
218 218
219 219 ####### Compile
220 220
221 221 obj/wf_handler.o: ../src/wf_handler.c
222 222 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/wf_handler.o ../src/wf_handler.c
223 223
224 224 obj/tc_handler.o: ../src/tc_handler.c
225 225 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_handler.o ../src/tc_handler.c
226 226
227 227 obj/fsw_misc.o: ../src/fsw_misc.c
228 228 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_misc.o ../src/fsw_misc.c
229 229
230 230 obj/fsw_init.o: ../src/fsw_init.c ../src/fsw_config.c
231 231 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_init.o ../src/fsw_init.c
232 232
233 233 obj/fsw_globals.o: ../src/fsw_globals.c
234 234 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_globals.o ../src/fsw_globals.c
235 235
236 236 obj/fsw_spacewire.o: ../src/fsw_spacewire.c
237 237 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_spacewire.o ../src/fsw_spacewire.c
238 238
239 239 obj/tc_load_dump_parameters.o: ../src/tc_load_dump_parameters.c
240 240 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_load_dump_parameters.o ../src/tc_load_dump_parameters.c
241 241
242 242 obj/tm_lfr_tc_exe.o: ../src/tm_lfr_tc_exe.c
243 243 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tm_lfr_tc_exe.o ../src/tm_lfr_tc_exe.c
244 244
245 245 obj/tc_acceptance.o: ../src/tc_acceptance.c
246 246 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_acceptance.o ../src/tc_acceptance.c
247 247
248 248 obj/fsw_processing.o: ../src/processing/fsw_processing.c
249 249 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_processing.o ../src/processing/fsw_processing.c
250 250
251 251 obj/avf0_prc0.o: ../src/processing/avf0_prc0.c
252 252 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/avf0_prc0.o ../src/processing/avf0_prc0.c
253 253
254 254 obj/avf1_prc1.o: ../src/processing/avf1_prc1.c
255 255 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/avf1_prc1.o ../src/processing/avf1_prc1.c
256 256
257 257 obj/avf2_prc2.o: ../src/processing/avf2_prc2.c
258 258 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/avf2_prc2.o ../src/processing/avf2_prc2.c
259 259
260 260 obj/lfr_cpu_usage_report.o: ../src/lfr_cpu_usage_report.c
261 261 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/lfr_cpu_usage_report.o ../src/lfr_cpu_usage_report.c
262 262
263 263 obj/basic_parameters.o: ../src/LFR_basic-parameters/basic_parameters.c
264 264 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/basic_parameters.o ../src/LFR_basic-parameters/basic_parameters.c
265 265
266 266 ####### Install
267 267
268 268 install: FORCE
269 269
270 270 uninstall: FORCE
271 271
272 272 FORCE:
273 273
@@ -1,578 +1,632
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "fsw_processing.h"
11 11 #include "fsw_processing_globals.c"
12 12
13 13 unsigned int nb_sm_f0;
14 14 unsigned int nb_sm_f0_aux_f1;
15 15 unsigned int nb_sm_f1;
16 16 unsigned int nb_sm_f0_aux_f2;
17 17
18 18 //************************
19 19 // spectral matrices rings
20 20 ring_node_sm sm_ring_f0[ NB_RING_NODES_SM_F0 ];
21 21 ring_node_sm sm_ring_f1[ NB_RING_NODES_SM_F1 ];
22 22 ring_node_sm sm_ring_f2[ NB_RING_NODES_SM_F2 ];
23 23 ring_node_sm *current_ring_node_sm_f0;
24 24 ring_node_sm *current_ring_node_sm_f1;
25 25 ring_node_sm *current_ring_node_sm_f2;
26 26 ring_node_sm *ring_node_for_averaging_sm_f0;
27 27 ring_node_sm *ring_node_for_averaging_sm_f1;
28 28 ring_node_sm *ring_node_for_averaging_sm_f2;
29 29
30 30 //***********************************************************
31 31 // Interrupt Service Routine for spectral matrices processing
32 32
33 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
33 void spectral_matrices_isr_f0( void )
34 34 {
35 35 unsigned char status;
36 36 unsigned long long int time_0;
37 37 unsigned long long int time_1;
38 // STATUS REGISTER
39 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
40 // 10 9 8
41 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
42 // 7 6 5 4 3 2 1 0
43 38
44 //***
45 // F0
46 39 status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits
40
47 41 switch(status)
48 42 {
49 43 case 0:
50 44 break;
51 45 case 3:
52 46 time_0 = get_acquisition_time( (unsigned char *) spectral_matrix_regs->f0_0_coarse_time );
53 47 time_1 = get_acquisition_time( (unsigned char *) spectral_matrix_regs->f0_1_coarse_time );
54 48 if ( time_0 < time_1 )
55 49 {
56 50 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
57 51 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
58 52 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
59 53 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
60 54 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
61 55 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
62 56 }
63 57 else
64 58 {
65 59 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
66 60 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
67 61 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
68 62 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
69 63 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
70 64 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
71 65 }
72 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffc; // [1100]
66 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x03; // [0011]
73 67 break;
74 68 case 1:
75 69 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
76 70 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
77 71 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
78 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffe; // [1110]
72 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x01; // [0001]
79 73 break;
80 74 case 2:
81 75 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], ring_node_for_averaging_sm_f0, current_ring_node_sm_f0->previous);
82 76 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
83 77 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
84 spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffd; // [1101]
78 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x02; // [0010]
79 break;
80 }
81 }
82
83 void spectral_matrices_isr_f1( void )
84 {
85 unsigned char status;
86 unsigned long long int time_0;
87 unsigned long long int time_1;
88
89 status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
90
91 switch(status)
92 {
93 case 0:
94 break;
95 case 3:
96 time_0 = get_acquisition_time( (unsigned char *) spectral_matrix_regs->f1_0_coarse_time );
97 time_1 = get_acquisition_time( (unsigned char *) spectral_matrix_regs->f1_1_coarse_time );
98 if ( time_0 < time_1 )
99 {
100 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
101 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
102 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
103 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
104 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
105 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
106 }
107 else
108 {
109 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
110 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
111 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
112 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
113 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
114 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
115 }
116 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x0c; // [1100]
117 break;
118 case 1:
119 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
120 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
121 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
122 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x07; // [0100]
123 break;
124 case 2:
125 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], ring_node_for_averaging_sm_f1, current_ring_node_sm_f1->previous);
126 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
127 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
128 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x08; // [1000]
129 break;
130 }
131 }
132
133 void spectral_matrices_isr_f2( void )
134 {
135 unsigned char status;
136
137 status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
138
139 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
140
141 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
142
143 switch(status)
144 {
145 case 0:
146 case 3:
147 break;
148 case 1:
149 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
150 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x10; // [0001 0000]
151 break;
152 case 2:
153 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
154 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x20; // [0010 0000]
85 155 break;
86 156 }
87 157
88 //***
89 // F1
90 // if ( (spectral_matrix_regs->status & 0x4) == 0x04) // check the status_ready_matrix_f1 bit
91 // {
92 // nb_sm_f1 = nb_sm_f1 + 1;
93 // if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
94 // {
95 // ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
96 // current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
97 // spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
98 // if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
99 // {
100 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
101 // }
102 // nb_sm_f1 = 0;
103 // }
104 // spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffffb; // 1011
105 // }
158 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
159 {
160 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
161 }
162 }
163
164 void spectral_matrix_isr_error_handler( void )
165 {
166 spectral_matrix_regs->status = 0x7c0; // [0111 1100 0000]
167 }
106 168
107 //***
108 // F2
109 // if ( (spectral_matrix_regs->status & 0x8) == 0x08) // check the status_ready_matrix_f2 bit
110 // {
169 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
170 {
171 // STATUS REGISTER
172 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
173 // 10 9 8
174 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
175 // 7 6 5 4 3 2 1 0
111 176
112 // ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
113 // current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
114 // spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
115 // if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
116 // {
117 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
118 // }
119 // spectral_matrix_regs->status = spectral_matrix_regs->status & 0xfffffff7; // 0111
120 // }
177 spectral_matrices_isr_f0();
178
179 spectral_matrices_isr_f1();
121 180
122 //************************
123 // reset status error bits
124 // if ( (spectral_matrix_regs->status & 0x3e0) != 0x00) // [0011 1110 0000] check the status bits
125 // {
126 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
127 // spectral_matrix_regs->status = spectral_matrix_regs->status | 0xfffffc1f; // [1100 0001 1111]
128 // }
181 spectral_matrices_isr_f2();
129 182
183 spectral_matrix_isr_error_handler();
130 184 }
131 185
132 186 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
133 187 {
134 188 //***
135 189 // F0
136 190 nb_sm_f0 = nb_sm_f0 + 1;
137 191 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
138 192 {
139 193 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
140 194 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
141 195 {
142 196 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
143 197 }
144 198 nb_sm_f0 = 0;
145 199 }
146 200
147 201 //***
148 202 // F1
149 203 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
150 204 if (nb_sm_f0_aux_f1 == 6)
151 205 {
152 206 nb_sm_f0_aux_f1 = 0;
153 207 nb_sm_f1 = nb_sm_f1 + 1;
154 208 }
155 209 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
156 210 {
157 211 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
158 212 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
159 213 {
160 214 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
161 215 }
162 216 nb_sm_f1 = 0;
163 217 }
164 218
165 219 //***
166 220 // F2
167 221 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
168 222 if (nb_sm_f0_aux_f2 == 96)
169 223 {
170 224 nb_sm_f0_aux_f2 = 0;
171 225 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
172 226 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
173 227 {
174 228 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
175 229 }
176 230 }
177 231 }
178 232
179 233 //******************
180 234 // Spectral Matrices
181 235
182 236 void reset_nb_sm( void )
183 237 {
184 238 nb_sm_f0 = 0;
185 239 nb_sm_f0_aux_f1 = 0;
186 240 nb_sm_f0_aux_f2 = 0;
187 241
188 242 nb_sm_f1 = 0;
189 243 }
190 244
191 245 void SM_init_rings( void )
192 246 {
193 247 unsigned char i;
194 248
195 249 // F0 RING
196 250 sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1];
197 251 sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1];
198 252 sm_ring_f0[0].buffer_address =
199 253 (int) &sm_f0[ 0 ];
200 254
201 255 sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0];
202 256 sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2];
203 257 sm_ring_f0[NB_RING_NODES_SM_F0-1].buffer_address =
204 258 (int) &sm_f0[ (NB_RING_NODES_SM_F0-1) * TOTAL_SIZE_SM ];
205 259
206 260 for(i=1; i<NB_RING_NODES_SM_F0-1; i++)
207 261 {
208 262 sm_ring_f0[i].next = (ring_node_sm*) &sm_ring_f0[i+1];
209 263 sm_ring_f0[i].previous = (ring_node_sm*) &sm_ring_f0[i-1];
210 264 sm_ring_f0[i].buffer_address =
211 265 (int) &sm_f0[ i * TOTAL_SIZE_SM ];
212 266 }
213 267
214 268 // F1 RING
215 269 sm_ring_f1[0].next = (ring_node_sm*) &sm_ring_f1[1];
216 270 sm_ring_f1[0].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-1];
217 271 sm_ring_f1[0].buffer_address =
218 272 (int) &sm_f1[ 0 ];
219 273
220 274 sm_ring_f1[NB_RING_NODES_SM_F1-1].next = (ring_node_sm*) &sm_ring_f1[0];
221 275 sm_ring_f1[NB_RING_NODES_SM_F1-1].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-2];
222 276 sm_ring_f1[NB_RING_NODES_SM_F1-1].buffer_address =
223 277 (int) &sm_f1[ (NB_RING_NODES_SM_F1-1) * TOTAL_SIZE_SM ];
224 278
225 279 for(i=1; i<NB_RING_NODES_SM_F1-1; i++)
226 280 {
227 281 sm_ring_f1[i].next = (ring_node_sm*) &sm_ring_f1[i+1];
228 282 sm_ring_f1[i].previous = (ring_node_sm*) &sm_ring_f1[i-1];
229 283 sm_ring_f1[i].buffer_address =
230 284 (int) &sm_f1[ i * TOTAL_SIZE_SM ];
231 285 }
232 286
233 287 // F2 RING
234 288 sm_ring_f2[0].next = (ring_node_sm*) &sm_ring_f2[1];
235 289 sm_ring_f2[0].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-1];
236 290 sm_ring_f2[0].buffer_address =
237 291 (int) &sm_f2[ 0 ];
238 292
239 293 sm_ring_f2[NB_RING_NODES_SM_F2-1].next = (ring_node_sm*) &sm_ring_f2[0];
240 294 sm_ring_f2[NB_RING_NODES_SM_F2-1].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-2];
241 295 sm_ring_f2[NB_RING_NODES_SM_F2-1].buffer_address =
242 296 (int) &sm_f2[ (NB_RING_NODES_SM_F2-1) * TOTAL_SIZE_SM ];
243 297
244 298 for(i=1; i<NB_RING_NODES_SM_F2-1; i++)
245 299 {
246 300 sm_ring_f2[i].next = (ring_node_sm*) &sm_ring_f2[i+1];
247 301 sm_ring_f2[i].previous = (ring_node_sm*) &sm_ring_f2[i-1];
248 302 sm_ring_f2[i].buffer_address =
249 303 (int) &sm_f2[ i * TOTAL_SIZE_SM ];
250 304 }
251 305
252 306 DEBUG_PRINTF1("asm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
253 307 DEBUG_PRINTF1("asm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
254 308 DEBUG_PRINTF1("asm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
255 309
256 310 spectral_matrix_regs->f0_0_address = sm_ring_f0[0].buffer_address;
257 311 DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->f0_0_address)
258 312 }
259 313
260 314 void SM_generic_init_ring( ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] )
261 315 {
262 316 unsigned char i;
263 317
264 318 //***************
265 319 // BUFFER ADDRESS
266 320 for(i=0; i<nbNodes; i++)
267 321 {
268 322 ring[ i ].buffer_address = (int) &sm_f[ i * TOTAL_SIZE_SM ];
269 323 }
270 324
271 325 //*****
272 326 // NEXT
273 327 ring[ nbNodes - 1 ].next = (ring_node_sm*) &ring[ 0 ];
274 328 for(i=0; i<nbNodes-1; i++)
275 329 {
276 330 ring[ i ].next = (ring_node_sm*) &ring[ i + 1 ];
277 331 }
278 332
279 333 //*********
280 334 // PREVIOUS
281 335 ring[ 0 ].previous = (ring_node_sm*) &ring[ nbNodes -1 ];
282 336 for(i=1; i<nbNodes; i++)
283 337 {
284 338 ring[ i ].previous = (ring_node_sm*) &ring[ i - 1 ];
285 339 }
286 340 }
287 341
288 342 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
289 343 {
290 344 unsigned char i;
291 345
292 346 ring[ nbNodes - 1 ].next
293 347 = (ring_node_asm*) &ring[ 0 ];
294 348
295 349 for(i=0; i<nbNodes-1; i++)
296 350 {
297 351 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
298 352 }
299 353 }
300 354
301 355 void SM_reset_current_ring_nodes( void )
302 356 {
303 357 current_ring_node_sm_f0 = sm_ring_f0[0].next;
304 358 current_ring_node_sm_f1 = sm_ring_f1[0].next;
305 359 current_ring_node_sm_f2 = sm_ring_f2[0].next;
306 360
307 361 ring_node_for_averaging_sm_f0 = sm_ring_f0;
308 362 ring_node_for_averaging_sm_f1 = sm_ring_f1;
309 363 ring_node_for_averaging_sm_f2 = sm_ring_f2;
310 364 }
311 365
312 366 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header)
313 367 {
314 368 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
315 369 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
316 370 header->reserved = 0x00;
317 371 header->userApplication = CCSDS_USER_APP;
318 372 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
319 373 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
320 374 header->packetSequenceControl[0] = 0xc0;
321 375 header->packetSequenceControl[1] = 0x00;
322 376 header->packetLength[0] = 0x00;
323 377 header->packetLength[1] = 0x00;
324 378 // DATA FIELD HEADER
325 379 header->spare1_pusVersion_spare2 = 0x10;
326 380 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
327 381 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
328 382 header->destinationID = TM_DESTINATION_ID_GROUND;
329 383 // AUXILIARY DATA HEADER
330 384 header->sid = 0x00;
331 385 header->biaStatusInfo = 0x00;
332 386 header->pa_lfr_pkt_cnt_asm = 0x00;
333 387 header->pa_lfr_pkt_nr_asm = 0x00;
334 388 header->time[0] = 0x00;
335 389 header->time[0] = 0x00;
336 390 header->time[0] = 0x00;
337 391 header->time[0] = 0x00;
338 392 header->time[0] = 0x00;
339 393 header->time[0] = 0x00;
340 394 header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB
341 395 header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB
342 396 }
343 397
344 398 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
345 399 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id)
346 400 {
347 401 unsigned int i;
348 402 unsigned int length = 0;
349 403 rtems_status_code status;
350 404
351 405 for (i=0; i<2; i++)
352 406 {
353 407 // (1) BUILD THE DATA
354 408 switch(sid)
355 409 {
356 410 case SID_NORM_ASM_F0:
357 411 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent
358 412 spw_ioctl_send->data = &spectral_matrix[
359 413 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2
360 414 ];
361 415 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0;
362 416 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB
363 417 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB
364 418 break;
365 419 case SID_NORM_ASM_F1:
366 420 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent
367 421 spw_ioctl_send->data = &spectral_matrix[
368 422 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2
369 423 ];
370 424 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1;
371 425 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB
372 426 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB
373 427 break;
374 428 case SID_NORM_ASM_F2:
375 429 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent
376 430 spw_ioctl_send->data = &spectral_matrix[
377 431 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2
378 432 ];
379 433 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
380 434 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
381 435 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
382 436 break;
383 437 default:
384 438 PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid)
385 439 break;
386 440 }
387 441 spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES;
388 442 spw_ioctl_send->hdr = (char *) header;
389 443 spw_ioctl_send->options = 0;
390 444
391 445 // (2) BUILD THE HEADER
392 446 increment_seq_counter_source_id( header->packetSequenceControl, sid );
393 447 header->packetLength[0] = (unsigned char) (length>>8);
394 448 header->packetLength[1] = (unsigned char) (length);
395 449 header->sid = (unsigned char) sid; // SID
396 450 header->pa_lfr_pkt_cnt_asm = 2;
397 451 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
398 452
399 453 // (3) SET PACKET TIME
400 454 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
401 455 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
402 456 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
403 457 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
404 458 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
405 459 header->time[5] = (unsigned char) (time_management_regs->fine_time);
406 460 //
407 461 header->acquisitionTime[0] = header->time[0];
408 462 header->acquisitionTime[1] = header->time[1];
409 463 header->acquisitionTime[2] = header->time[2];
410 464 header->acquisitionTime[3] = header->time[3];
411 465 header->acquisitionTime[4] = header->time[4];
412 466 header->acquisitionTime[5] = header->time[5];
413 467
414 468 // (4) SEND PACKET
415 469 status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
416 470 if (status != RTEMS_SUCCESSFUL) {
417 471 printf("in ASM_send *** ERR %d\n", (int) status);
418 472 }
419 473 }
420 474 }
421 475
422 476 //*****************
423 477 // Basic Parameters
424 478
425 479 void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header,
426 480 unsigned int apid, unsigned char sid,
427 481 unsigned int packetLength, unsigned char blkNr )
428 482 {
429 483 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
430 484 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
431 485 header->reserved = 0x00;
432 486 header->userApplication = CCSDS_USER_APP;
433 487 header->packetID[0] = (unsigned char) (apid >> 8);
434 488 header->packetID[1] = (unsigned char) (apid);
435 489 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
436 490 header->packetSequenceControl[1] = 0x00;
437 491 header->packetLength[0] = (unsigned char) (packetLength >> 8);
438 492 header->packetLength[1] = (unsigned char) (packetLength);
439 493 // DATA FIELD HEADER
440 494 header->spare1_pusVersion_spare2 = 0x10;
441 495 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
442 496 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
443 497 header->destinationID = TM_DESTINATION_ID_GROUND;
444 498 // AUXILIARY DATA HEADER
445 499 header->sid = sid;
446 500 header->biaStatusInfo = 0x00;
447 501 header->time[0] = 0x00;
448 502 header->time[0] = 0x00;
449 503 header->time[0] = 0x00;
450 504 header->time[0] = 0x00;
451 505 header->time[0] = 0x00;
452 506 header->time[0] = 0x00;
453 507 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
454 508 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
455 509 }
456 510
457 511 void BP_init_header_with_spare(Header_TM_LFR_SCIENCE_BP_with_spare_t *header,
458 512 unsigned int apid, unsigned char sid,
459 513 unsigned int packetLength , unsigned char blkNr)
460 514 {
461 515 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
462 516 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
463 517 header->reserved = 0x00;
464 518 header->userApplication = CCSDS_USER_APP;
465 519 header->packetID[0] = (unsigned char) (apid >> 8);
466 520 header->packetID[1] = (unsigned char) (apid);
467 521 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
468 522 header->packetSequenceControl[1] = 0x00;
469 523 header->packetLength[0] = (unsigned char) (packetLength >> 8);
470 524 header->packetLength[1] = (unsigned char) (packetLength);
471 525 // DATA FIELD HEADER
472 526 header->spare1_pusVersion_spare2 = 0x10;
473 527 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
474 528 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
475 529 header->destinationID = TM_DESTINATION_ID_GROUND;
476 530 // AUXILIARY DATA HEADER
477 531 header->sid = sid;
478 532 header->biaStatusInfo = 0x00;
479 533 header->time[0] = 0x00;
480 534 header->time[0] = 0x00;
481 535 header->time[0] = 0x00;
482 536 header->time[0] = 0x00;
483 537 header->time[0] = 0x00;
484 538 header->time[0] = 0x00;
485 539 header->source_data_spare = 0x00;
486 540 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
487 541 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
488 542 }
489 543
490 544 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
491 545 {
492 546 rtems_status_code status;
493 547
494 548 // SET THE SEQUENCE_CNT PARAMETER
495 549 increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid );
496 550 // SEND PACKET
497 551 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
498 552 if (status != RTEMS_SUCCESSFUL)
499 553 {
500 554 printf("ERR *** in BP_send *** ERR %d\n", (int) status);
501 555 }
502 556 }
503 557
504 558 //******************
505 559 // general functions
506 560
507 561 void reset_spectral_matrix_regs( void )
508 562 {
509 563 /** This function resets the spectral matrices module registers.
510 564 *
511 565 * The registers affected by this function are located at the following offset addresses:
512 566 *
513 567 * - 0x00 config
514 568 * - 0x04 status
515 569 * - 0x08 matrixF0_Address0
516 570 * - 0x10 matrixFO_Address1
517 571 * - 0x14 matrixF1_Address
518 572 * - 0x18 matrixF2_Address
519 573 *
520 574 */
521 575
522 576 spectral_matrix_regs->config = 0x00;
523 577 spectral_matrix_regs->status = 0x00;
524 578
525 579 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
526 580 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
527 581 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
528 582 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
529 583 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
530 584 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
531 585 }
532 586
533 587 void set_time( unsigned char *time, unsigned char * timeInBuffer )
534 588 {
535 589 // time[0] = timeInBuffer[2];
536 590 // time[1] = timeInBuffer[3];
537 591 // time[2] = timeInBuffer[0];
538 592 // time[3] = timeInBuffer[1];
539 593 // time[4] = timeInBuffer[6];
540 594 // time[5] = timeInBuffer[7];
541 595
542 596 time[0] = timeInBuffer[0];
543 597 time[1] = timeInBuffer[1];
544 598 time[2] = timeInBuffer[2];
545 599 time[3] = timeInBuffer[3];
546 600 time[4] = timeInBuffer[6];
547 601 time[5] = timeInBuffer[7];
548 602 }
549 603
550 604 unsigned long long int get_acquisition_time( unsigned char *timePtr )
551 605 {
552 606 unsigned long long int acquisitionTimeAslong;
553 607 acquisitionTimeAslong = 0x00;
554 608 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
555 609 + ( (unsigned long long int) timePtr[1] << 32 )
556 610 + ( timePtr[2] << 24 )
557 611 + ( timePtr[3] << 16 )
558 612 + ( timePtr[4] << 8 )
559 613 + ( timePtr[5] );
560 614 return acquisitionTimeAslong;
561 615 }
562 616
563 617 void close_matrix_actions( unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id task_id,
564 618 ring_node_sm *node_for_averaging, ring_node_sm *ringNode )
565 619 {
566 620 *nb_sm = *nb_sm + 1;
567 621 if (*nb_sm == nb_sm_before_avf)
568 622 {
569 623 node_for_averaging = ringNode;
570 624 if (rtems_event_send( task_id, RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
571 625 {
572 626 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
573 627 }
574 628 *nb_sm = 0;
575 629 }
576 630 }
577 631
578 632
@@ -1,949 +1,949
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14
15 15 //***********
16 16 // RTEMS TASK
17 17
18 18 rtems_task actn_task( rtems_task_argument unused )
19 19 {
20 20 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 21 *
22 22 * @param unused is the starting argument of the RTEMS task
23 23 *
24 24 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 25 * on the incoming TeleCommand.
26 26 *
27 27 */
28 28
29 29 int result;
30 30 rtems_status_code status; // RTEMS status code
31 31 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 32 size_t size; // size of the incoming TC packet
33 33 unsigned char subtype; // subtype of the current TC packet
34 34 unsigned char time[6];
35 35 rtems_id queue_rcv_id;
36 36 rtems_id queue_snd_id;
37 37
38 38 status = get_message_queue_id_recv( &queue_rcv_id );
39 39 if (status != RTEMS_SUCCESSFUL)
40 40 {
41 41 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 42 }
43 43
44 44 status = get_message_queue_id_send( &queue_snd_id );
45 45 if (status != RTEMS_SUCCESSFUL)
46 46 {
47 47 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 48 }
49 49
50 50 result = LFR_SUCCESSFUL;
51 51 subtype = 0; // subtype of the current TC packet
52 52
53 53 BOOT_PRINTF("in ACTN *** \n")
54 54
55 55 while(1)
56 56 {
57 57 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 58 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 59 getTime( time ); // set time to the current time
60 60 if (status!=RTEMS_SUCCESSFUL)
61 61 {
62 62 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 63 }
64 64 else
65 65 {
66 66 subtype = TC.serviceSubType;
67 67 switch(subtype)
68 68 {
69 69 case TC_SUBTYPE_RESET:
70 70 result = action_reset( &TC, queue_snd_id, time );
71 71 close_action( &TC, result, queue_snd_id );
72 72 break;
73 73 //
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id );
77 77 break;
78 78 //
79 79 case TC_SUBTYPE_LOAD_NORM:
80 80 result = action_load_normal_par( &TC, queue_snd_id, time );
81 81 close_action( &TC, result, queue_snd_id );
82 82 break;
83 83 //
84 84 case TC_SUBTYPE_LOAD_BURST:
85 85 result = action_load_burst_par( &TC, queue_snd_id, time );
86 86 close_action( &TC, result, queue_snd_id );
87 87 break;
88 88 //
89 89 case TC_SUBTYPE_LOAD_SBM1:
90 90 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 91 close_action( &TC, result, queue_snd_id );
92 92 break;
93 93 //
94 94 case TC_SUBTYPE_LOAD_SBM2:
95 95 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 96 close_action( &TC, result, queue_snd_id );
97 97 break;
98 98 //
99 99 case TC_SUBTYPE_DUMP:
100 100 result = action_dump_par( queue_snd_id );
101 101 close_action( &TC, result, queue_snd_id );
102 102 break;
103 103 //
104 104 case TC_SUBTYPE_ENTER:
105 105 result = action_enter_mode( &TC, queue_snd_id );
106 106 close_action( &TC, result, queue_snd_id );
107 107 break;
108 108 //
109 109 case TC_SUBTYPE_UPDT_INFO:
110 110 result = action_update_info( &TC, queue_snd_id );
111 111 close_action( &TC, result, queue_snd_id );
112 112 break;
113 113 //
114 114 case TC_SUBTYPE_EN_CAL:
115 115 result = action_enable_calibration( &TC, queue_snd_id, time );
116 116 close_action( &TC, result, queue_snd_id );
117 117 break;
118 118 //
119 119 case TC_SUBTYPE_DIS_CAL:
120 120 result = action_disable_calibration( &TC, queue_snd_id, time );
121 121 close_action( &TC, result, queue_snd_id );
122 122 break;
123 123 //
124 124 case TC_SUBTYPE_UPDT_TIME:
125 125 result = action_update_time( &TC );
126 126 close_action( &TC, result, queue_snd_id );
127 127 break;
128 128 //
129 129 default:
130 130 break;
131 131 }
132 132 }
133 133 }
134 134 }
135 135
136 136 //***********
137 137 // TC ACTIONS
138 138
139 139 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 140 {
141 141 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 142 *
143 143 * @param TC points to the TeleCommand packet that is being processed
144 144 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 145 *
146 146 */
147 147
148 148 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
149 149 return LFR_DEFAULT;
150 150 }
151 151
152 152 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
153 153 {
154 154 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
155 155 *
156 156 * @param TC points to the TeleCommand packet that is being processed
157 157 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
158 158 *
159 159 */
160 160
161 161 rtems_status_code status;
162 162 unsigned char requestedMode;
163 163 unsigned int *transitionCoarseTime_ptr;
164 164 unsigned int transitionCoarseTime;
165 165 unsigned char * bytePosPtr;
166 166
167 167 bytePosPtr = (unsigned char *) &TC->packetID;
168 168
169 169 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
170 170 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
171 171 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
172 172
173 173 status = check_mode_value( requestedMode );
174 174
175 175 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
176 176 {
177 177 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
178 178 }
179 179 else // the mode value is consistent, check the transition
180 180 {
181 181 status = check_mode_transition(requestedMode);
182 182 if (status != LFR_SUCCESSFUL)
183 183 {
184 184 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
185 185 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
186 186 }
187 187 }
188 188
189 189 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
190 190 {
191 191 status = check_transition_date( transitionCoarseTime );
192 192 if (status != LFR_SUCCESSFUL)
193 193 {
194 194 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
195 195 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
196 196 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
197 197 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
198 198 }
199 199 }
200 200
201 201 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
202 202 {
203 203 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
204 204 status = enter_mode( requestedMode, transitionCoarseTime );
205 205 }
206 206
207 207 return status;
208 208 }
209 209
210 210 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
211 211 {
212 212 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
213 213 *
214 214 * @param TC points to the TeleCommand packet that is being processed
215 215 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
216 216 *
217 217 * @return LFR directive status code:
218 218 * - LFR_DEFAULT
219 219 * - LFR_SUCCESSFUL
220 220 *
221 221 */
222 222
223 223 unsigned int val;
224 224 int result;
225 225 unsigned int status;
226 226 unsigned char mode;
227 227 unsigned char * bytePosPtr;
228 228
229 229 bytePosPtr = (unsigned char *) &TC->packetID;
230 230
231 231 // check LFR mode
232 232 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
233 233 status = check_update_info_hk_lfr_mode( mode );
234 234 if (status == LFR_SUCCESSFUL) // check TDS mode
235 235 {
236 236 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
237 237 status = check_update_info_hk_tds_mode( mode );
238 238 }
239 239 if (status == LFR_SUCCESSFUL) // check THR mode
240 240 {
241 241 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
242 242 status = check_update_info_hk_thr_mode( mode );
243 243 }
244 244 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
245 245 {
246 246 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
247 247 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
248 248 val++;
249 249 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
250 250 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
251 251 }
252 252
253 253 result = status;
254 254
255 255 return result;
256 256 }
257 257
258 258 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
259 259 {
260 260 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
261 261 *
262 262 * @param TC points to the TeleCommand packet that is being processed
263 263 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
264 264 *
265 265 */
266 266
267 267 int result;
268 268 unsigned char lfrMode;
269 269
270 270 result = LFR_DEFAULT;
271 271 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
272 272
273 273 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
274 274 result = LFR_DEFAULT;
275 275
276 276 return result;
277 277 }
278 278
279 279 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
280 280 {
281 281 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
282 282 *
283 283 * @param TC points to the TeleCommand packet that is being processed
284 284 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
285 285 *
286 286 */
287 287
288 288 int result;
289 289 unsigned char lfrMode;
290 290
291 291 result = LFR_DEFAULT;
292 292 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
293 293
294 294 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
295 295 result = LFR_DEFAULT;
296 296
297 297 return result;
298 298 }
299 299
300 300 int action_update_time(ccsdsTelecommandPacket_t *TC)
301 301 {
302 302 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
303 303 *
304 304 * @param TC points to the TeleCommand packet that is being processed
305 305 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
306 306 *
307 307 * @return LFR_SUCCESSFUL
308 308 *
309 309 */
310 310
311 311 unsigned int val;
312 312
313 313 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
314 314 + (TC->dataAndCRC[1] << 16)
315 315 + (TC->dataAndCRC[2] << 8)
316 316 + TC->dataAndCRC[3];
317 317
318 318 PRINTF1("time received: %x\n", time_management_regs->coarse_time_load)
319 319
320 320 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 321 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 322 val++;
323 323 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
324 324 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325 325 // time_management_regs->ctrl = time_management_regs->ctrl | 1; // force tick
326 326
327 327 return LFR_SUCCESSFUL;
328 328 }
329 329
330 330 //*******************
331 331 // ENTERING THE MODES
332 332 int check_mode_value( unsigned char requestedMode )
333 333 {
334 334 int status;
335 335
336 336 if ( (requestedMode != LFR_MODE_STANDBY)
337 337 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
338 338 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
339 339 {
340 340 status = LFR_DEFAULT;
341 341 }
342 342 else
343 343 {
344 344 status = LFR_SUCCESSFUL;
345 345 }
346 346
347 347 return status;
348 348 }
349 349
350 350 int check_mode_transition( unsigned char requestedMode )
351 351 {
352 352 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
353 353 *
354 354 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
355 355 *
356 356 * @return LFR directive status codes:
357 357 * - LFR_SUCCESSFUL - the transition is authorized
358 358 * - LFR_DEFAULT - the transition is not authorized
359 359 *
360 360 */
361 361
362 362 int status;
363 363
364 364 switch (requestedMode)
365 365 {
366 366 case LFR_MODE_STANDBY:
367 367 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
368 368 status = LFR_DEFAULT;
369 369 }
370 370 else
371 371 {
372 372 status = LFR_SUCCESSFUL;
373 373 }
374 374 break;
375 375 case LFR_MODE_NORMAL:
376 376 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
377 377 status = LFR_DEFAULT;
378 378 }
379 379 else {
380 380 status = LFR_SUCCESSFUL;
381 381 }
382 382 break;
383 383 case LFR_MODE_BURST:
384 384 if ( lfrCurrentMode == LFR_MODE_BURST ) {
385 385 status = LFR_DEFAULT;
386 386 }
387 387 else {
388 388 status = LFR_SUCCESSFUL;
389 389 }
390 390 break;
391 391 case LFR_MODE_SBM1:
392 392 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
393 393 status = LFR_DEFAULT;
394 394 }
395 395 else {
396 396 status = LFR_SUCCESSFUL;
397 397 }
398 398 break;
399 399 case LFR_MODE_SBM2:
400 400 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
401 401 status = LFR_DEFAULT;
402 402 }
403 403 else {
404 404 status = LFR_SUCCESSFUL;
405 405 }
406 406 break;
407 407 default:
408 408 status = LFR_DEFAULT;
409 409 break;
410 410 }
411 411
412 412 return status;
413 413 }
414 414
415 415 int check_transition_date( unsigned int transitionCoarseTime )
416 416 {
417 417 int status;
418 418 unsigned int localCoarseTime;
419 419 unsigned int deltaCoarseTime;
420 420
421 421 status = LFR_SUCCESSFUL;
422 422
423 423 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
424 424 {
425 425 status = LFR_SUCCESSFUL;
426 426 }
427 427 else
428 428 {
429 429 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
430 430
431 431 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
432 432 {
433 433 status = LFR_DEFAULT;
434 434 PRINTF2("ERR *** in check_transition_date *** transition = %x, local = %x\n", transitionCoarseTime, localCoarseTime)
435 435 }
436 436
437 437 if (status == LFR_SUCCESSFUL)
438 438 {
439 439 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
440 440 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
441 441 {
442 442 status = LFR_DEFAULT;
443 443 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
444 444 }
445 445 }
446 446 }
447 447
448 448 return status;
449 449 }
450 450
451 451 int stop_current_mode( void )
452 452 {
453 453 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
454 454 *
455 455 * @return RTEMS directive status codes:
456 456 * - RTEMS_SUCCESSFUL - task restarted successfully
457 457 * - RTEMS_INVALID_ID - task id invalid
458 458 * - RTEMS_ALREADY_SUSPENDED - task already suspended
459 459 *
460 460 */
461 461
462 462 rtems_status_code status;
463 463
464 464 status = RTEMS_SUCCESSFUL;
465 465
466 466 // (1) mask interruptions
467 467 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
468 468 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
469 469
470 470 // (2) clear interruptions
471 471 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
472 472 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
473 473
474 474 // (3) reset waveform picker registers
475 475 reset_wfp_burst_enable(); // reset burst and enable bits
476 476 reset_wfp_status(); // reset all the status bits
477 477
478 478 // (4) reset spectral matrices registers
479 479 set_irq_on_new_ready_matrix( 0 ); // stop the spectral matrices
480 480 set_run_matrix_spectral( 0 ); // run_matrix_spectral is set to 0
481 481 reset_extractSWF(); // reset the extractSWF flag to false
482 482
483 483 // <Spectral Matrices simulator>
484 484 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
485 485 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
486 486 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
487 487 // </Spectral Matrices simulator>
488 488
489 489 // suspend several tasks
490 490 if (lfrCurrentMode != LFR_MODE_STANDBY) {
491 491 status = suspend_science_tasks();
492 492 }
493 493
494 494 if (status != RTEMS_SUCCESSFUL)
495 495 {
496 496 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
497 497 }
498 498
499 499 return status;
500 500 }
501 501
502 502 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
503 503 {
504 504 /** This function is launched after a mode transition validation.
505 505 *
506 506 * @param mode is the mode in which LFR will be put.
507 507 *
508 508 * @return RTEMS directive status codes:
509 509 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
510 510 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
511 511 *
512 512 */
513 513
514 514 rtems_status_code status;
515 515
516 516 //**********************
517 517 // STOP THE CURRENT MODE
518 518 status = stop_current_mode();
519 519 if (status != RTEMS_SUCCESSFUL)
520 520 {
521 521 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
522 522 }
523 523
524 524 //*************************
525 525 // ENTER THE REQUESTED MODE
526 526 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
527 527 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
528 528 {
529 529 #ifdef PRINT_TASK_STATISTICS
530 530 rtems_cpu_usage_reset();
531 531 maxCount = 0;
532 532 #endif
533 533 status = restart_science_tasks( mode );
534 534 launch_waveform_picker( mode, transitionCoarseTime );
535 535 // launch_spectral_matrix( );
536 launch_spectral_matrix_simu( );
536 // launch_spectral_matrix_simu( );
537 537 }
538 538 else if ( mode == LFR_MODE_STANDBY )
539 539 {
540 540 #ifdef PRINT_TASK_STATISTICS
541 541 rtems_cpu_usage_report();
542 542 #endif
543 543
544 544 #ifdef PRINT_STACK_REPORT
545 545 PRINTF("stack report selected\n")
546 546 rtems_stack_checker_report_usage();
547 547 #endif
548 548 PRINTF1("maxCount = %d\n", maxCount)
549 549 }
550 550 else
551 551 {
552 552 status = RTEMS_UNSATISFIED;
553 553 }
554 554
555 555 if (status != RTEMS_SUCCESSFUL)
556 556 {
557 557 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
558 558 status = RTEMS_UNSATISFIED;
559 559 }
560 560
561 561 return status;
562 562 }
563 563
564 564 int restart_science_tasks(unsigned char lfrRequestedMode )
565 565 {
566 566 /** This function is used to restart all science tasks.
567 567 *
568 568 * @return RTEMS directive status codes:
569 569 * - RTEMS_SUCCESSFUL - task restarted successfully
570 570 * - RTEMS_INVALID_ID - task id invalid
571 571 * - RTEMS_INCORRECT_STATE - task never started
572 572 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
573 573 *
574 574 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
575 575 *
576 576 */
577 577
578 578 rtems_status_code status[10];
579 579 rtems_status_code ret;
580 580
581 581 ret = RTEMS_SUCCESSFUL;
582 582
583 583 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
584 584 if (status[0] != RTEMS_SUCCESSFUL)
585 585 {
586 586 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
587 587 }
588 588
589 589 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
590 590 if (status[1] != RTEMS_SUCCESSFUL)
591 591 {
592 592 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
593 593 }
594 594
595 595 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
596 596 if (status[2] != RTEMS_SUCCESSFUL)
597 597 {
598 598 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
599 599 }
600 600
601 601 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
602 602 if (status[3] != RTEMS_SUCCESSFUL)
603 603 {
604 604 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
605 605 }
606 606
607 607 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
608 608 if (status[4] != RTEMS_SUCCESSFUL)
609 609 {
610 610 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
611 611 }
612 612
613 613 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
614 614 if (status[5] != RTEMS_SUCCESSFUL)
615 615 {
616 616 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
617 617 }
618 618
619 619 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
620 620 if (status[6] != RTEMS_SUCCESSFUL)
621 621 {
622 622 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
623 623 }
624 624
625 625 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
626 626 if (status[7] != RTEMS_SUCCESSFUL)
627 627 {
628 628 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
629 629 }
630 630
631 631 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
632 632 if (status[8] != RTEMS_SUCCESSFUL)
633 633 {
634 634 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
635 635 }
636 636
637 637 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
638 638 if (status[9] != RTEMS_SUCCESSFUL)
639 639 {
640 640 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
641 641 }
642 642
643 643 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
644 644 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
645 645 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
646 646 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
647 647 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
648 648 {
649 649 ret = RTEMS_UNSATISFIED;
650 650 }
651 651
652 652 return ret;
653 653 }
654 654
655 655 int suspend_science_tasks()
656 656 {
657 657 /** This function suspends the science tasks.
658 658 *
659 659 * @return RTEMS directive status codes:
660 660 * - RTEMS_SUCCESSFUL - task restarted successfully
661 661 * - RTEMS_INVALID_ID - task id invalid
662 662 * - RTEMS_ALREADY_SUSPENDED - task already suspended
663 663 *
664 664 */
665 665
666 666 rtems_status_code status;
667 667
668 668 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
669 669 if (status != RTEMS_SUCCESSFUL)
670 670 {
671 671 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
672 672 }
673 673 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
674 674 {
675 675 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
676 676 if (status != RTEMS_SUCCESSFUL)
677 677 {
678 678 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
679 679 }
680 680 }
681 681 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
682 682 {
683 683 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
684 684 if (status != RTEMS_SUCCESSFUL)
685 685 {
686 686 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
687 687 }
688 688 }
689 689 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
690 690 {
691 691 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
692 692 if (status != RTEMS_SUCCESSFUL)
693 693 {
694 694 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
695 695 }
696 696 }
697 697 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
698 698 {
699 699 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
700 700 if (status != RTEMS_SUCCESSFUL)
701 701 {
702 702 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
703 703 }
704 704 }
705 705 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
706 706 {
707 707 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
708 708 if (status != RTEMS_SUCCESSFUL)
709 709 {
710 710 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
711 711 }
712 712 }
713 713 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
714 714 {
715 715 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
716 716 if (status != RTEMS_SUCCESSFUL)
717 717 {
718 718 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
719 719 }
720 720 }
721 721 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
722 722 {
723 723 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
724 724 if (status != RTEMS_SUCCESSFUL)
725 725 {
726 726 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
727 727 }
728 728 }
729 729 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
730 730 {
731 731 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
732 732 if (status != RTEMS_SUCCESSFUL)
733 733 {
734 734 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
735 735 }
736 736 }
737 737 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
738 738 {
739 739 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
740 740 if (status != RTEMS_SUCCESSFUL)
741 741 {
742 742 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
743 743 }
744 744 }
745 745
746 746 return status;
747 747 }
748 748
749 749 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
750 750 {
751 751 WFP_reset_current_ring_nodes();
752 752 reset_waveform_picker_regs();
753 753 set_wfp_burst_enable_register( mode );
754 754
755 755 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
756 756 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
757 757
758 758 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x80; // [1000 0000]
759 759 if (transitionCoarseTime == 0)
760 760 {
761 761 waveform_picker_regs->start_date = time_management_regs->coarse_time;
762 762 }
763 763 else
764 764 {
765 765 waveform_picker_regs->start_date = transitionCoarseTime;
766 766 }
767 767 }
768 768
769 769 void launch_spectral_matrix( void )
770 770 {
771 771 SM_reset_current_ring_nodes();
772 772 reset_spectral_matrix_regs();
773 773 reset_nb_sm();
774 774
775 775 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
776 776 grgpio_regs->io_port_direction_register =
777 777 grgpio_regs->io_port_direction_register | 0x01; // [0000 0001], 0 = output disabled, 1 = output enabled
778 778 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xfffffffe; // set the bit 0 to 0
779 779 set_irq_on_new_ready_matrix( 1 );
780 780 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
781 781 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
782 782 set_run_matrix_spectral( 1 );
783 783
784 784 }
785 785
786 786 void launch_spectral_matrix_simu( void )
787 787 {
788 788 SM_reset_current_ring_nodes();
789 789 reset_spectral_matrix_regs();
790 790 reset_nb_sm();
791 791
792 792 // Spectral Matrices simulator
793 793 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
794 794 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
795 795 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
796 796 }
797 797
798 798 void set_irq_on_new_ready_matrix( unsigned char value )
799 799 {
800 800 if (value == 1)
801 801 {
802 802 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
803 803 }
804 804 else
805 805 {
806 806 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
807 807 }
808 808 }
809 809
810 810 void set_run_matrix_spectral( unsigned char value )
811 811 {
812 812 if (value == 1)
813 813 {
814 814 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // [0100] set run_matrix spectral to 1
815 815 }
816 816 else
817 817 {
818 818 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // [1011] set run_matrix spectral to 0
819 819 }
820 820 }
821 821
822 822 //****************
823 823 // CLOSING ACTIONS
824 824 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
825 825 {
826 826 /** This function is used to update the HK packets statistics after a successful TC execution.
827 827 *
828 828 * @param TC points to the TC being processed
829 829 * @param time is the time used to date the TC execution
830 830 *
831 831 */
832 832
833 833 unsigned int val;
834 834
835 835 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
836 836 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
837 837 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
838 838 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
839 839 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
840 840 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
841 841 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
842 842 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
843 843 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
844 844 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
845 845 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
846 846 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
847 847
848 848 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
849 849 val++;
850 850 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
851 851 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
852 852 }
853 853
854 854 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
855 855 {
856 856 /** This function is used to update the HK packets statistics after a TC rejection.
857 857 *
858 858 * @param TC points to the TC being processed
859 859 * @param time is the time used to date the TC rejection
860 860 *
861 861 */
862 862
863 863 unsigned int val;
864 864
865 865 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
866 866 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
867 867 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
868 868 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
869 869 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
870 870 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
871 871 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
872 872 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
873 873 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
874 874 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
875 875 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
876 876 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
877 877
878 878 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
879 879 val++;
880 880 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
881 881 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
882 882 }
883 883
884 884 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
885 885 {
886 886 /** This function is the last step of the TC execution workflow.
887 887 *
888 888 * @param TC points to the TC being processed
889 889 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
890 890 * @param queue_id is the id of the RTEMS message queue used to send TM packets
891 891 * @param time is the time used to date the TC execution
892 892 *
893 893 */
894 894
895 895 unsigned char requestedMode;
896 896
897 897 if (result == LFR_SUCCESSFUL)
898 898 {
899 899 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
900 900 &
901 901 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
902 902 )
903 903 {
904 904 send_tm_lfr_tc_exe_success( TC, queue_id );
905 905 }
906 906 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
907 907 {
908 908 //**********************************
909 909 // UPDATE THE LFRMODE LOCAL VARIABLE
910 910 requestedMode = TC->dataAndCRC[1];
911 911 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
912 912 updateLFRCurrentMode();
913 913 }
914 914 }
915 915 else if (result == LFR_EXE_ERROR)
916 916 {
917 917 send_tm_lfr_tc_exe_error( TC, queue_id );
918 918 }
919 919 }
920 920
921 921 //***************************
922 922 // Interrupt Service Routines
923 923 rtems_isr commutation_isr1( rtems_vector_number vector )
924 924 {
925 925 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
926 926 printf("In commutation_isr1 *** Error sending event to DUMB\n");
927 927 }
928 928 }
929 929
930 930 rtems_isr commutation_isr2( rtems_vector_number vector )
931 931 {
932 932 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
933 933 printf("In commutation_isr2 *** Error sending event to DUMB\n");
934 934 }
935 935 }
936 936
937 937 //****************
938 938 // OTHER FUNCTIONS
939 939 void updateLFRCurrentMode()
940 940 {
941 941 /** This function updates the value of the global variable lfrCurrentMode.
942 942 *
943 943 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
944 944 *
945 945 */
946 946 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
947 947 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
948 948 }
949 949
@@ -1,1392 +1,1398
1 1 /** Functions and tasks related to waveform packet generation.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 7 *
8 8 */
9 9
10 10 #include "wf_handler.h"
11 11
12 12 //*****************
13 13 // waveform headers
14 14 // SWF
15 15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
16 16 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
17 17 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
18 18 // CWF
19 19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ];
20 20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ];
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ];
22 22 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ];
23 23 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ];
24 24
25 25 //**************
26 26 // waveform ring
27 27 ring_node waveform_ring_f0[NB_RING_NODES_F0];
28 28 ring_node waveform_ring_f1[NB_RING_NODES_F1];
29 29 ring_node waveform_ring_f2[NB_RING_NODES_F2];
30 30 ring_node waveform_ring_f3[NB_RING_NODES_F3];
31 31 ring_node *current_ring_node_f0;
32 32 ring_node *ring_node_to_send_swf_f0;
33 33 ring_node *current_ring_node_f1;
34 34 ring_node *ring_node_to_send_swf_f1;
35 35 ring_node *ring_node_to_send_cwf_f1;
36 36 ring_node *current_ring_node_f2;
37 37 ring_node *ring_node_to_send_swf_f2;
38 38 ring_node *ring_node_to_send_cwf_f2;
39 39 ring_node *current_ring_node_f3;
40 40 ring_node *ring_node_to_send_cwf_f3;
41 41
42 42 bool extractSWF = false;
43 43 bool swf_f0_ready = false;
44 44 bool swf_f1_ready = false;
45 45 bool swf_f2_ready = false;
46 46
47 47 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
48 48
49 49 //*********************
50 50 // Interrupt SubRoutine
51 51
52 52 void reset_extractSWF( void )
53 53 {
54 54 extractSWF = false;
55 55 swf_f0_ready = false;
56 56 swf_f1_ready = false;
57 57 swf_f2_ready = false;
58 58 }
59 59
60 60 rtems_isr waveforms_isr( rtems_vector_number vector )
61 61 {
62 62 /** This is the interrupt sub routine called by the waveform picker core.
63 63 *
64 64 * This ISR launch different actions depending mainly on two pieces of information:
65 65 * 1. the values read in the registers of the waveform picker.
66 66 * 2. the current LFR mode.
67 67 *
68 68 */
69 69
70 70 rtems_status_code status;
71 71
72 72 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
73 73 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
74 74 { // in modes other than STANDBY and BURST, send the CWF_F3 data
75 75 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
76 76 // (1) change the receiving buffer for the waveform picker
77 77 ring_node_to_send_cwf_f3 = current_ring_node_f3;
78 78 current_ring_node_f3 = current_ring_node_f3->next;
79 79 waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address;
80 80 // (2) send an event for the waveforms transmission
81 81 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
82 82 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
83 83 }
84 84 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2);
85 85 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
86 86 }
87 87 }
88 88
89 89 switch(lfrCurrentMode)
90 90 {
91 91 //********
92 92 // STANDBY
93 93 case(LFR_MODE_STANDBY):
94 94 break;
95 95
96 96 //******
97 97 // NORMAL
98 98 case(LFR_MODE_NORMAL):
99 99 if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits
100 100 {
101 101 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
102 102 }
103 103 if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits
104 104 {
105 105 // change F0 ring node
106 106 ring_node_to_send_swf_f0 = current_ring_node_f0;
107 107 current_ring_node_f0 = current_ring_node_f0->next;
108 108 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address;
109 109 // change F1 ring node
110 110 ring_node_to_send_swf_f1 = current_ring_node_f1;
111 111 current_ring_node_f1 = current_ring_node_f1->next;
112 112 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
113 113 // change F2 ring node
114 114 ring_node_to_send_swf_f2 = current_ring_node_f2;
115 115 current_ring_node_f2 = current_ring_node_f2->next;
116 116 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
117 117 //
118 118 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL)
119 119 {
120 120 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
121 121 }
122 122 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000]
123 123 }
124 124 break;
125 125
126 126 //******
127 127 // BURST
128 128 case(LFR_MODE_BURST):
129 129 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
130 130 // (1) change the receiving buffer for the waveform picker
131 131 ring_node_to_send_cwf_f2 = current_ring_node_f2;
132 132 current_ring_node_f2 = current_ring_node_f2->next;
133 133 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
134 134 // (2) send an event for the waveforms transmission
135 135 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
136 136 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
137 137 }
138 138 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
139 139 }
140 140 break;
141 141
142 142 //*****
143 143 // SBM1
144 144 case(LFR_MODE_SBM1):
145 145 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
146 146 // (1) change the receiving buffer for the waveform picker
147 147 ring_node_to_send_cwf_f1 = current_ring_node_f1;
148 148 current_ring_node_f1 = current_ring_node_f1->next;
149 149 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
150 150 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
151 151 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
152 152 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0
153 153 }
154 154 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
155 155 swf_f0_ready = true;
156 156 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
157 157 }
158 158 if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit
159 159 swf_f2_ready = true;
160 160 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0
161 161 }
162 162 break;
163 163
164 164 //*****
165 165 // SBM2
166 166 case(LFR_MODE_SBM2):
167 167 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
168 168 // (1) change the receiving buffer for the waveform picker
169 169 ring_node_to_send_cwf_f2 = current_ring_node_f2;
170 170 current_ring_node_f2 = current_ring_node_f2->next;
171 171 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
172 172 // (2) send an event for the waveforms transmission
173 173 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
174 174 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
175 175 }
176 176 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
177 177 swf_f0_ready = true;
178 178 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
179 179 }
180 180 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
181 181 swf_f1_ready = true;
182 182 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0
183 183 }
184 184 break;
185 185
186 186 //********
187 187 // DEFAULT
188 188 default:
189 189 break;
190 190 }
191 191 }
192 192
193 193 //************
194 194 // RTEMS TASKS
195 195
196 196 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
197 197 {
198 198 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
199 199 *
200 200 * @param unused is the starting argument of the RTEMS task
201 201 *
202 202 * The following data packets are sent by this task:
203 203 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
204 204 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
205 205 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
206 206 *
207 207 */
208 208
209 209 rtems_event_set event_out;
210 210 rtems_id queue_id;
211 211 rtems_status_code status;
212 212
213 213 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
214 214 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
215 215 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
216 216
217 217 status = get_message_queue_id_send( &queue_id );
218 218 if (status != RTEMS_SUCCESSFUL)
219 219 {
220 220 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
221 221 }
222 222
223 223 BOOT_PRINTF("in WFRM ***\n")
224 224
225 225 while(1){
226 226 // wait for an RTEMS_EVENT
227 227 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
228 228 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
229 229 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
230 230 if (event_out == RTEMS_EVENT_MODE_NORMAL)
231 231 {
232 232 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
233 233 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
234 234 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
235 235 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
236 236 }
237 237 if (event_out == RTEMS_EVENT_MODE_SBM1)
238 238 {
239 239 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
240 240 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
241 241 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id);
242 242 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
243 243 }
244 244 if (event_out == RTEMS_EVENT_MODE_SBM2)
245 245 {
246 246 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
247 247 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
248 248 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
249 249 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id);
250 250 }
251 251 }
252 252 }
253 253
254 254 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
255 255 {
256 256 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
257 257 *
258 258 * @param unused is the starting argument of the RTEMS task
259 259 *
260 260 * The following data packet is sent by this task:
261 261 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
262 262 *
263 263 */
264 264
265 265 rtems_event_set event_out;
266 266 rtems_id queue_id;
267 267 rtems_status_code status;
268 268
269 269 init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 );
270 270 init_header_continuous_cwf3_light_table( headerCWF_F3_light );
271 271
272 272 status = get_message_queue_id_send( &queue_id );
273 273 if (status != RTEMS_SUCCESSFUL)
274 274 {
275 275 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
276 276 }
277 277
278 278 BOOT_PRINTF("in CWF3 ***\n")
279 279
280 280 while(1){
281 281 // wait for an RTEMS_EVENT
282 282 rtems_event_receive( RTEMS_EVENT_0,
283 283 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
284 284 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
285 285 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
286 286 {
287 287 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
288 288 {
289 289 PRINTF("send CWF_LONG_F3\n")
290 290 send_waveform_CWF(
291 291 (volatile int*) current_ring_node_f3->buffer_address,
292 292 SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
293 293 }
294 294 else
295 295 {
296 296 PRINTF("send CWF_F3 (light)\n")
297 297 send_waveform_CWF3_light(
298 298 (volatile int*) current_ring_node_f3->buffer_address,
299 299 headerCWF_F3_light, queue_id );
300 300 }
301 301
302 302 }
303 303 else
304 304 {
305 305 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
306 306 }
307 307 }
308 308 }
309 309
310 310 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
311 311 {
312 312 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
313 313 *
314 314 * @param unused is the starting argument of the RTEMS task
315 315 *
316 316 * The following data packet is sent by this function:
317 317 * - TM_LFR_SCIENCE_BURST_CWF_F2
318 318 * - TM_LFR_SCIENCE_SBM2_CWF_F2
319 319 *
320 320 */
321 321
322 322 rtems_event_set event_out;
323 323 rtems_id queue_id;
324 324 rtems_status_code status;
325 325
326 326 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
327 327 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
328 328
329 329 status = get_message_queue_id_send( &queue_id );
330 330 if (status != RTEMS_SUCCESSFUL)
331 331 {
332 332 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
333 333 }
334 334
335 335 BOOT_PRINTF("in CWF2 ***\n")
336 336
337 337 while(1){
338 338 // wait for an RTEMS_EVENT
339 339 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
340 340 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
341 341 if (event_out == RTEMS_EVENT_MODE_BURST)
342 342 {
343 343 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
344 344 }
345 345 if (event_out == RTEMS_EVENT_MODE_SBM2)
346 346 {
347 347 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
348 348 // launch snapshot extraction if needed
349 349 if (extractSWF == true)
350 350 {
351 351 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
352 352 // extract the snapshot
353 353 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 );
354 354 // send the snapshot when built
355 355 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
356 356 extractSWF = false;
357 357 }
358 358 if (swf_f0_ready && swf_f1_ready)
359 359 {
360 360 extractSWF = true;
361 361 swf_f0_ready = false;
362 362 swf_f1_ready = false;
363 363 }
364 364 }
365 365 }
366 366 }
367 367
368 368 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
369 369 {
370 370 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
371 371 *
372 372 * @param unused is the starting argument of the RTEMS task
373 373 *
374 374 * The following data packet is sent by this function:
375 375 * - TM_LFR_SCIENCE_SBM1_CWF_F1
376 376 *
377 377 */
378 378
379 379 rtems_event_set event_out;
380 380 rtems_id queue_id;
381 381 rtems_status_code status;
382 382
383 383 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
384 384
385 385 status = get_message_queue_id_send( &queue_id );
386 386 if (status != RTEMS_SUCCESSFUL)
387 387 {
388 388 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
389 389 }
390 390
391 391 BOOT_PRINTF("in CWF1 ***\n")
392 392
393 393 while(1){
394 394 // wait for an RTEMS_EVENT
395 395 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
396 396 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
397 397 send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
398 398 // launch snapshot extraction if needed
399 399 if (extractSWF == true)
400 400 {
401 401 ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1;
402 402 // launch the snapshot extraction
403 403 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
404 404 extractSWF = false;
405 405 }
406 406 if (swf_f0_ready == true)
407 407 {
408 408 extractSWF = true;
409 409 swf_f0_ready = false; // this step shall be executed only one time
410 410 }
411 411 if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction
412 412 {
413 413 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
414 414 swf_f1_ready = false;
415 415 swf_f2_ready = false;
416 416 }
417 417 }
418 418 }
419 419
420 420 rtems_task swbd_task(rtems_task_argument argument)
421 421 {
422 422 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
423 423 *
424 424 * @param unused is the starting argument of the RTEMS task
425 425 *
426 426 */
427 427
428 428 rtems_event_set event_out;
429 429
430 430 BOOT_PRINTF("in SWBD ***\n")
431 431
432 432 while(1){
433 433 // wait for an RTEMS_EVENT
434 434 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
435 435 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
436 436 if (event_out == RTEMS_EVENT_MODE_SBM1)
437 437 {
438 438 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 );
439 439 swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent
440 440 }
441 441 else
442 442 {
443 443 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
444 444 }
445 445 }
446 446 }
447 447
448 448 //******************
449 449 // general functions
450 450
451 451 void WFP_init_rings( void )
452 452 {
453 453 // F0 RING
454 454 init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 );
455 455 // F1 RING
456 456 init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 );
457 457 // F2 RING
458 458 init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 );
459 459 // F3 RING
460 460 init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 );
461 461
462 462 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
463 463 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
464 464 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
465 465 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
466 466 }
467 467
468 468 void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] )
469 469 {
470 470 unsigned char i;
471 471
472 472 waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ];
473 473 waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ];
474 474 waveform_ring[0].buffer_address = (int) &wfrm[0];
475 475
476 476 waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ];
477 477 waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ];
478 478 waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ];
479 479
480 480 for(i=1; i<nbNodes-1; i++)
481 481 {
482 482 waveform_ring[i].next = (ring_node*) &waveform_ring[ i + 1 ];
483 483 waveform_ring[i].previous = (ring_node*) &waveform_ring[ i - 1 ];
484 484 waveform_ring[i].buffer_address = (int) &wfrm[ i * WFRM_BUFFER ];
485 485 }
486 486 }
487 487
488 488 void WFP_reset_current_ring_nodes( void )
489 489 {
490 490 current_ring_node_f0 = waveform_ring_f0;
491 491 ring_node_to_send_swf_f0 = waveform_ring_f0;
492 492
493 493 current_ring_node_f1 = waveform_ring_f1;
494 494 ring_node_to_send_cwf_f1 = waveform_ring_f1;
495 495 ring_node_to_send_swf_f1 = waveform_ring_f1;
496 496
497 497 current_ring_node_f2 = waveform_ring_f2;
498 498 ring_node_to_send_cwf_f2 = waveform_ring_f2;
499 499 ring_node_to_send_swf_f2 = waveform_ring_f2;
500 500
501 501 current_ring_node_f3 = waveform_ring_f3;
502 502 ring_node_to_send_cwf_f3 = waveform_ring_f3;
503 503 }
504 504
505 505 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
506 506 {
507 507 unsigned char i;
508 508
509 509 for (i=0; i<7; i++)
510 510 {
511 511 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
512 512 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
513 513 headerSWF[ i ].reserved = DEFAULT_RESERVED;
514 514 headerSWF[ i ].userApplication = CCSDS_USER_APP;
515 515 headerSWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
516 516 headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
517 517 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
518 518 if (i == 6)
519 519 {
520 520 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
521 521 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
522 522 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
523 523 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 );
524 524 }
525 525 else
526 526 {
527 527 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
528 528 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
529 529 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
530 530 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 );
531 531 }
532 532 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
533 533 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
534 534 headerSWF[ i ].pktNr = i+1; // PKT_NR
535 535 // DATA FIELD HEADER
536 536 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
537 537 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
538 538 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
539 539 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
540 540 // AUXILIARY DATA HEADER
541 541 headerSWF[ i ].time[0] = 0x00;
542 542 headerSWF[ i ].time[0] = 0x00;
543 543 headerSWF[ i ].time[0] = 0x00;
544 544 headerSWF[ i ].time[0] = 0x00;
545 545 headerSWF[ i ].time[0] = 0x00;
546 546 headerSWF[ i ].time[0] = 0x00;
547 547 headerSWF[ i ].sid = sid;
548 548 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
549 549 }
550 550 return LFR_SUCCESSFUL;
551 551 }
552 552
553 553 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
554 554 {
555 555 unsigned int i;
556 556
557 557 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++)
558 558 {
559 559 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
560 560 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
561 561 headerCWF[ i ].reserved = DEFAULT_RESERVED;
562 562 headerCWF[ i ].userApplication = CCSDS_USER_APP;
563 563 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
564 564 {
565 565 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
566 566 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
567 567 }
568 568 else
569 569 {
570 570 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
571 571 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
572 572 }
573 573 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
574 574 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
575 575 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
576 576 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
577 577 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF );
578 578 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
579 579 // DATA FIELD HEADER
580 580 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
581 581 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
582 582 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
583 583 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
584 584 // AUXILIARY DATA HEADER
585 585 headerCWF[ i ].sid = sid;
586 586 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
587 587 headerCWF[ i ].time[0] = 0x00;
588 588 headerCWF[ i ].time[0] = 0x00;
589 589 headerCWF[ i ].time[0] = 0x00;
590 590 headerCWF[ i ].time[0] = 0x00;
591 591 headerCWF[ i ].time[0] = 0x00;
592 592 headerCWF[ i ].time[0] = 0x00;
593 593 }
594 594 return LFR_SUCCESSFUL;
595 595 }
596 596
597 597 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
598 598 {
599 599 unsigned int i;
600 600
601 601 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++)
602 602 {
603 603 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
604 604 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
605 605 headerCWF[ i ].reserved = DEFAULT_RESERVED;
606 606 headerCWF[ i ].userApplication = CCSDS_USER_APP;
607 607
608 608 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
609 609 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
610 610
611 611 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
612 612 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
613 613 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
614 614 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
615 615 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
616 616
617 617 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
618 618 // DATA FIELD HEADER
619 619 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
620 620 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
621 621 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
622 622 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
623 623 // AUXILIARY DATA HEADER
624 624 headerCWF[ i ].sid = SID_NORM_CWF_F3;
625 625 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
626 626 headerCWF[ i ].time[0] = 0x00;
627 627 headerCWF[ i ].time[0] = 0x00;
628 628 headerCWF[ i ].time[0] = 0x00;
629 629 headerCWF[ i ].time[0] = 0x00;
630 630 headerCWF[ i ].time[0] = 0x00;
631 631 headerCWF[ i ].time[0] = 0x00;
632 632 }
633 633 return LFR_SUCCESSFUL;
634 634 }
635 635
636 636 int send_waveform_SWF( volatile int *waveform, unsigned int sid,
637 637 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
638 638 {
639 639 /** This function sends SWF CCSDS packets (F2, F1 or F0).
640 640 *
641 641 * @param waveform points to the buffer containing the data that will be send.
642 642 * @param sid is the source identifier of the data that will be sent.
643 643 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
644 644 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
645 645 * contain information to setup the transmission of the data packets.
646 646 *
647 647 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
648 648 *
649 649 */
650 650
651 651 unsigned int i;
652 652 int ret;
653 653 unsigned int coarseTime;
654 654 unsigned int fineTime;
655 655 rtems_status_code status;
656 656 spw_ioctl_pkt_send spw_ioctl_send_SWF;
657 657
658 658 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
659 659 spw_ioctl_send_SWF.options = 0;
660 660
661 661 ret = LFR_DEFAULT;
662 662
663 663 coarseTime = waveform[0];
664 664 fineTime = waveform[1];
665 665
666 666 for (i=0; i<7; i++) // send waveform
667 667 {
668 668 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET];
669 669 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
670 670 // BUILD THE DATA
671 671 if (i==6) {
672 672 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
673 673 }
674 674 else {
675 675 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
676 676 }
677 677 // SET PACKET SEQUENCE COUNTER
678 678 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
679 679 // SET PACKET TIME
680 680 compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime );
681 681 //
682 682 headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0];
683 683 headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1];
684 684 headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2];
685 685 headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3];
686 686 headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4];
687 687 headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5];
688 688 // SEND PACKET
689 689 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
690 690 if (status != RTEMS_SUCCESSFUL) {
691 691 printf("%d-%d, ERR %d\n", sid, i, (int) status);
692 692 ret = LFR_DEFAULT;
693 693 }
694 694 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
695 695 }
696 696
697 697 return ret;
698 698 }
699 699
700 700 int send_waveform_CWF(volatile int *waveform, unsigned int sid,
701 701 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
702 702 {
703 703 /** This function sends CWF CCSDS packets (F2, F1 or F0).
704 704 *
705 705 * @param waveform points to the buffer containing the data that will be send.
706 706 * @param sid is the source identifier of the data that will be sent.
707 707 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
708 708 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
709 709 * contain information to setup the transmission of the data packets.
710 710 *
711 711 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
712 712 *
713 713 */
714 714
715 715 unsigned int i;
716 716 int ret;
717 717 unsigned int coarseTime;
718 718 unsigned int fineTime;
719 719 rtems_status_code status;
720 720 spw_ioctl_pkt_send spw_ioctl_send_CWF;
721 721
722 722 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
723 723 spw_ioctl_send_CWF.options = 0;
724 724
725 725 ret = LFR_DEFAULT;
726 726
727 727 coarseTime = waveform[0];
728 728 fineTime = waveform[1];
729 729
730 730 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
731 731 {
732 732 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) + TIME_OFFSET];
733 733 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
734 734 // BUILD THE DATA
735 735 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
736 736 // SET PACKET SEQUENCE COUNTER
737 737 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
738 738 // SET PACKET TIME
739 739 compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime);
740 740 //
741 741 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
742 742 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
743 743 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
744 744 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
745 745 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
746 746 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
747 747 // SEND PACKET
748 748 if (sid == SID_NORM_CWF_LONG_F3)
749 749 {
750 750 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
751 751 if (status != RTEMS_SUCCESSFUL) {
752 752 printf("%d-%d, ERR %d\n", sid, i, (int) status);
753 753 ret = LFR_DEFAULT;
754 754 }
755 755 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
756 756 }
757 757 else
758 758 {
759 759 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
760 760 if (status != RTEMS_SUCCESSFUL) {
761 761 printf("%d-%d, ERR %d\n", sid, i, (int) status);
762 762 ret = LFR_DEFAULT;
763 763 }
764 764 }
765 765 }
766 766
767 767 return ret;
768 768 }
769 769
770 770 int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
771 771 {
772 772 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
773 773 *
774 774 * @param waveform points to the buffer containing the data that will be send.
775 775 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
776 776 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
777 777 * contain information to setup the transmission of the data packets.
778 778 *
779 779 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
780 780 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
781 781 *
782 782 */
783 783
784 784 unsigned int i;
785 785 int ret;
786 786 unsigned int coarseTime;
787 787 unsigned int fineTime;
788 788 rtems_status_code status;
789 789 spw_ioctl_pkt_send spw_ioctl_send_CWF;
790 790 char *sample;
791 791
792 792 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
793 793 spw_ioctl_send_CWF.options = 0;
794 794
795 795 ret = LFR_DEFAULT;
796 796
797 797 //**********************
798 798 // BUILD CWF3_light DATA
799 799 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
800 800 {
801 801 sample = (char*) &waveform[ (i * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
802 802 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES ] = sample[ 0 ];
803 803 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 + TIME_OFFSET_IN_BYTES ] = sample[ 1 ];
804 804 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 + TIME_OFFSET_IN_BYTES ] = sample[ 2 ];
805 805 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 + TIME_OFFSET_IN_BYTES ] = sample[ 3 ];
806 806 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 + TIME_OFFSET_IN_BYTES ] = sample[ 4 ];
807 807 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ];
808 808 }
809 809
810 810 coarseTime = waveform[0];
811 811 fineTime = waveform[1];
812 812
813 813 //*********************
814 814 // SEND CWF3_light DATA
815 815 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
816 816 {
817 817 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES];
818 818 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
819 819 // BUILD THE DATA
820 820 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
821 821 // SET PACKET SEQUENCE COUNTER
822 822 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
823 823 // SET PACKET TIME
824 824 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime );
825 825 //
826 826 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
827 827 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
828 828 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
829 829 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
830 830 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
831 831 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
832 832 // SEND PACKET
833 833 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
834 834 if (status != RTEMS_SUCCESSFUL) {
835 835 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
836 836 ret = LFR_DEFAULT;
837 837 }
838 838 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
839 839 }
840 840
841 841 return ret;
842 842 }
843 843
844 844 void compute_acquisition_time_old( unsigned int coarseTime, unsigned int fineTime,
845 845 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
846 846 {
847 847 unsigned long long int acquisitionTimeAsLong;
848 848 unsigned char localAcquisitionTime[6];
849 849 double deltaT;
850 850
851 851 deltaT = 0.;
852 852
853 853 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 8 );
854 854 localAcquisitionTime[1] = (unsigned char) ( coarseTime );
855 855 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 24 );
856 856 localAcquisitionTime[3] = (unsigned char) ( coarseTime >> 16 );
857 857 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 24 );
858 858 localAcquisitionTime[5] = (unsigned char) ( fineTime >> 16 );
859 859
860 860 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
861 861 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
862 862 + ( localAcquisitionTime[2] << 24 )
863 863 + ( localAcquisitionTime[3] << 16 )
864 864 + ( localAcquisitionTime[4] << 8 )
865 865 + ( localAcquisitionTime[5] );
866 866
867 867 switch( sid )
868 868 {
869 869 case SID_NORM_SWF_F0:
870 870 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
871 871 break;
872 872
873 873 case SID_NORM_SWF_F1:
874 874 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
875 875 break;
876 876
877 877 case SID_NORM_SWF_F2:
878 878 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
879 879 break;
880 880
881 881 case SID_SBM1_CWF_F1:
882 882 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
883 883 break;
884 884
885 885 case SID_SBM2_CWF_F2:
886 886 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
887 887 break;
888 888
889 889 case SID_BURST_CWF_F2:
890 890 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
891 891 break;
892 892
893 893 case SID_NORM_CWF_F3:
894 894 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
895 895 break;
896 896
897 897 case SID_NORM_CWF_LONG_F3:
898 898 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
899 899 break;
900 900
901 901 default:
902 902 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid)
903 903 deltaT = 0.;
904 904 break;
905 905 }
906 906
907 907 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
908 908 //
909 909 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
910 910 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
911 911 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
912 912 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
913 913 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
914 914 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
915 915
916 916 }
917 917
918 918 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
919 919 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
920 920 {
921 921 unsigned long long int acquisitionTimeAsLong;
922 922 unsigned char localAcquisitionTime[6];
923 923 double deltaT;
924 924
925 925 deltaT = 0.;
926 926
927 927 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
928 928 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
929 929 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
930 930 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
931 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 24 );
932 localAcquisitionTime[5] = (unsigned char) ( fineTime >> 16 );
931 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
932 localAcquisitionTime[5] = (unsigned char) ( fineTime );
933 933
934 934 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
935 935 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
936 936 + ( localAcquisitionTime[2] << 24 )
937 937 + ( localAcquisitionTime[3] << 16 )
938 938 + ( localAcquisitionTime[4] << 8 )
939 939 + ( localAcquisitionTime[5] );
940 940
941 941 switch( sid )
942 942 {
943 943 case SID_NORM_SWF_F0:
944 944 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
945 945 break;
946 946
947 947 case SID_NORM_SWF_F1:
948 948 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
949 949 break;
950 950
951 951 case SID_NORM_SWF_F2:
952 952 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
953 953 break;
954 954
955 955 case SID_SBM1_CWF_F1:
956 956 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
957 957 break;
958 958
959 959 case SID_SBM2_CWF_F2:
960 960 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
961 961 break;
962 962
963 963 case SID_BURST_CWF_F2:
964 964 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
965 965 break;
966 966
967 967 case SID_NORM_CWF_F3:
968 968 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
969 969 break;
970 970
971 971 case SID_NORM_CWF_LONG_F3:
972 972 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
973 973 break;
974 974
975 975 default:
976 976 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid)
977 977 deltaT = 0.;
978 978 break;
979 979 }
980 980
981 981 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
982 982 //
983 983 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
984 984 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
985 985 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
986 986 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
987 987 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
988 988 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
989 989
990 990 }
991 991
992 992 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel )
993 993 {
994 994 unsigned int i;
995 995 unsigned long long int centerTime_asLong;
996 996 unsigned long long int acquisitionTimeF0_asLong;
997 997 unsigned long long int acquisitionTime_asLong;
998 998 unsigned long long int bufferAcquisitionTime_asLong;
999 999 unsigned char *ptr1;
1000 1000 unsigned char *ptr2;
1001 unsigned char *timeCharPtr;
1001 1002 unsigned char nb_ring_nodes;
1002 1003 unsigned long long int frequency_asLong;
1003 1004 unsigned long long int nbTicksPerSample_asLong;
1004 1005 unsigned long long int nbSamplesPart1_asLong;
1005 1006 unsigned long long int sampleOffset_asLong;
1006 1007
1007 1008 unsigned int deltaT_F0;
1008 1009 unsigned int deltaT_F1;
1009 1010 unsigned long long int deltaT_F2;
1010 1011
1011 1012 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1012 1013 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
1013 1014 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
1014 1015 sampleOffset_asLong = 0x00;
1015 1016
1016 1017 // (1) get the f0 acquisition time
1017 1018 build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 );
1018 1019
1019 1020 // (2) compute the central reference time
1020 1021 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
1021 1022
1022 1023 // (3) compute the acquisition time of the current snapshot
1023 1024 switch(frequencyChannel)
1024 1025 {
1025 1026 case 1: // 1 is for F1 = 4096 Hz
1026 1027 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
1027 1028 nb_ring_nodes = NB_RING_NODES_F1;
1028 1029 frequency_asLong = 4096;
1029 1030 nbTicksPerSample_asLong = 16; // 65536 / 4096;
1030 1031 break;
1031 1032 case 2: // 2 is for F2 = 256 Hz
1032 1033 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
1033 1034 nb_ring_nodes = NB_RING_NODES_F2;
1034 1035 frequency_asLong = 256;
1035 1036 nbTicksPerSample_asLong = 256; // 65536 / 256;
1036 1037 break;
1037 1038 default:
1038 1039 acquisitionTime_asLong = centerTime_asLong;
1039 1040 frequency_asLong = 256;
1040 1041 nbTicksPerSample_asLong = 256;
1041 1042 break;
1042 1043 }
1043 1044
1044 1045 //****************************************************************************
1045 1046 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
1046 1047 for (i=0; i<nb_ring_nodes; i++)
1047 1048 {
1048 1049 PRINTF1("%d ... ", i)
1049 1050 build_acquisition_time( &bufferAcquisitionTime_asLong, ring_node_to_send );
1050 1051 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
1051 1052 {
1052 1053 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
1053 1054 break;
1054 1055 }
1055 1056 ring_node_to_send = ring_node_to_send->previous;
1056 1057 }
1057 1058
1058 1059 // (5) compute the number of samples to take in the current buffer
1059 1060 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
1060 1061 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
1061 PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1062 PRINTF2("sampleOffset_asLong = %llx, nbSamplesPart1_asLong = %llx\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1062 1063
1063 1064 // (6) compute the final acquisition time
1064 1065 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
1065 1066 sampleOffset_asLong * nbTicksPerSample_asLong;
1066 1067
1067 1068 // (7) copy the acquisition time at the beginning of the extrated snapshot
1068 1069 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1069 1070 ptr2 = (unsigned char*) wf_snap_extracted;
1070 ptr2[0] = ptr1[ 2 + 2 ];
1071 ptr2[1] = ptr1[ 3 + 2 ];
1072 ptr2[2] = ptr1[ 0 + 2 ];
1073 ptr2[3] = ptr1[ 1 + 2 ];
1074 ptr2[4] = ptr1[ 4 + 2 ];
1075 ptr2[5] = ptr1[ 5 + 2 ];
1071 ptr2[0] = ptr1[ 0 + 2 ];
1072 ptr2[1] = ptr1[ 1 + 2 ];
1073 ptr2[2] = ptr1[ 2 + 2 ];
1074 ptr2[3] = ptr1[ 3 + 2 ];
1075 ptr2[6] = ptr1[ 4 + 2 ];
1076 ptr2[7] = ptr1[ 5 + 2 ];
1076 1077
1077 1078 // re set the synchronization bit
1079 timeCharPtr = (unsigned char*) ring_node_to_send->buffer_address;
1080 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
1078 1081
1079
1082 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
1083 {
1084 nbSamplesPart1_asLong = 0;
1085 }
1080 1086 // copy the part 1 of the snapshot in the extracted buffer
1081 1087 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1082 1088 {
1083 1089 wf_snap_extracted[i + TIME_OFFSET] =
1084 1090 ((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET];
1085 1091 }
1086 1092 // copy the part 2 of the snapshot in the extracted buffer
1087 1093 ring_node_to_send = ring_node_to_send->next;
1088 1094 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1089 1095 {
1090 1096 wf_snap_extracted[i + TIME_OFFSET] =
1091 1097 ((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET];
1092 1098 }
1093 1099 }
1094 1100
1095 1101 void build_acquisition_time_old( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node )
1096 1102 {
1097 1103 unsigned char *acquisitionTimeCharPtr;
1098 1104
1099 1105 acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address;
1100 1106
1101 1107 *acquisitionTimeAslong = 0x00;
1102 1108 *acquisitionTimeAslong = ( acquisitionTimeCharPtr[0] << 24 )
1103 1109 + ( acquisitionTimeCharPtr[1] << 16 )
1104 1110 + ( (unsigned long long int) (acquisitionTimeCharPtr[2] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
1105 1111 + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 32 )
1106 1112 + ( acquisitionTimeCharPtr[4] << 8 )
1107 1113 + ( acquisitionTimeCharPtr[5] );
1108 1114 }
1109 1115
1110 1116 void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node )
1111 1117 {
1112 1118 unsigned char *acquisitionTimeCharPtr;
1113 1119
1114 1120 acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address;
1115 1121
1116 1122 *acquisitionTimeAslong = 0x00;
1117 1123 *acquisitionTimeAslong = ( (unsigned long long int) (acquisitionTimeCharPtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
1118 1124 + ( (unsigned long long int) acquisitionTimeCharPtr[1] << 32 )
1119 1125 + ( acquisitionTimeCharPtr[2] << 24 )
1120 1126 + ( acquisitionTimeCharPtr[3] << 16 )
1121 + ( acquisitionTimeCharPtr[4] << 8 )
1122 + ( acquisitionTimeCharPtr[5] );
1127 + ( acquisitionTimeCharPtr[6] << 8 )
1128 + ( acquisitionTimeCharPtr[7] );
1123 1129 }
1124 1130
1125 1131 //**************
1126 1132 // wfp registers
1127 1133 void reset_wfp_burst_enable(void)
1128 1134 {
1129 1135 /** This function resets the waveform picker burst_enable register.
1130 1136 *
1131 1137 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1132 1138 *
1133 1139 */
1134 1140
1135 1141 waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1136 1142 }
1137 1143
1138 1144 void reset_wfp_status( void )
1139 1145 {
1140 1146 /** This function resets the waveform picker status register.
1141 1147 *
1142 1148 * All status bits are set to 0 [new_err full_err full].
1143 1149 *
1144 1150 */
1145 1151
1146 1152 waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1147 1153 }
1148 1154
1149 1155 void reset_waveform_picker_regs(void)
1150 1156 {
1151 1157 /** This function resets the waveform picker module registers.
1152 1158 *
1153 1159 * The registers affected by this function are located at the following offset addresses:
1154 1160 * - 0x00 data_shaping
1155 1161 * - 0x04 run_burst_enable
1156 1162 * - 0x08 addr_data_f0
1157 1163 * - 0x0C addr_data_f1
1158 1164 * - 0x10 addr_data_f2
1159 1165 * - 0x14 addr_data_f3
1160 1166 * - 0x18 status
1161 1167 * - 0x1C delta_snapshot
1162 1168 * - 0x20 delta_f0
1163 1169 * - 0x24 delta_f0_2
1164 1170 * - 0x28 delta_f1
1165 1171 * - 0x2c delta_f2
1166 1172 * - 0x30 nb_data_by_buffer
1167 1173 * - 0x34 nb_snapshot_param
1168 1174 * - 0x38 start_date
1169 1175 * - 0x3c nb_word_in_buffer
1170 1176 *
1171 1177 */
1172 1178
1173 1179 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1174 1180 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1175 1181 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08
1176 1182 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c
1177 1183 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10
1178 1184 waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; // 0x14
1179 1185 reset_wfp_status(); // 0x18
1180 1186 //
1181 1187 set_wfp_delta_snapshot(); // 0x1c
1182 1188 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1183 1189 set_wfp_delta_f1(); // 0x28
1184 1190 set_wfp_delta_f2(); // 0x2c
1185 1191 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1186 1192 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1187 1193 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1188 1194 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1189 1195 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1190 1196 // 2688 = 8 * 336
1191 1197 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1192 1198 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1193 1199 waveform_picker_regs->start_date = 0x00; // 0x38
1194 1200 waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066
1195 1201 }
1196 1202
1197 1203 void set_wfp_data_shaping( void )
1198 1204 {
1199 1205 /** This function sets the data_shaping register of the waveform picker module.
1200 1206 *
1201 1207 * The value is read from one field of the parameter_dump_packet structure:\n
1202 1208 * bw_sp0_sp1_r0_r1
1203 1209 *
1204 1210 */
1205 1211
1206 1212 unsigned char data_shaping;
1207 1213
1208 1214 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1209 1215 // waveform picker : [R1 R0 SP1 SP0 BW]
1210 1216
1211 1217 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
1212 1218
1213 1219 waveform_picker_regs->data_shaping =
1214 1220 ( (data_shaping & 0x10) >> 4 ) // BW
1215 1221 + ( (data_shaping & 0x08) >> 2 ) // SP0
1216 1222 + ( (data_shaping & 0x04) ) // SP1
1217 1223 + ( (data_shaping & 0x02) << 2 ) // R0
1218 1224 + ( (data_shaping & 0x01) << 4 ); // R1
1219 1225 }
1220 1226
1221 1227 void set_wfp_burst_enable_register( unsigned char mode )
1222 1228 {
1223 1229 /** This function sets the waveform picker burst_enable register depending on the mode.
1224 1230 *
1225 1231 * @param mode is the LFR mode to launch.
1226 1232 *
1227 1233 * The burst bits shall be before the enable bits.
1228 1234 *
1229 1235 */
1230 1236
1231 1237 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1232 1238 // the burst bits shall be set first, before the enable bits
1233 1239 switch(mode) {
1234 1240 case(LFR_MODE_NORMAL):
1235 1241 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1236 1242 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1237 1243 break;
1238 1244 case(LFR_MODE_BURST):
1239 1245 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1240 1246 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1241 1247 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2
1242 1248 break;
1243 1249 case(LFR_MODE_SBM1):
1244 1250 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1245 1251 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1246 1252 break;
1247 1253 case(LFR_MODE_SBM2):
1248 1254 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1249 1255 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1250 1256 break;
1251 1257 default:
1252 1258 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1253 1259 break;
1254 1260 }
1255 1261 }
1256 1262
1257 1263 void set_wfp_delta_snapshot( void )
1258 1264 {
1259 1265 /** This function sets the delta_snapshot register of the waveform picker module.
1260 1266 *
1261 1267 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1262 1268 * - sy_lfr_n_swf_p[0]
1263 1269 * - sy_lfr_n_swf_p[1]
1264 1270 *
1265 1271 */
1266 1272
1267 1273 unsigned int delta_snapshot;
1268 1274 unsigned int delta_snapshot_in_T2;
1269 1275
1270 1276 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1271 1277 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1272 1278
1273 1279 delta_snapshot_in_T2 = delta_snapshot * 256;
1274 1280 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2; // max 4 bytes
1275 1281 }
1276 1282
1277 1283 void set_wfp_delta_f0_f0_2( void )
1278 1284 {
1279 1285 unsigned int delta_snapshot;
1280 1286 unsigned int nb_samples_per_snapshot;
1281 1287 float delta_f0_in_float;
1282 1288
1283 1289 delta_snapshot = waveform_picker_regs->delta_snapshot;
1284 1290 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1285 1291 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1286 1292
1287 1293 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1288 1294 waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits
1289 1295 }
1290 1296
1291 1297 void set_wfp_delta_f1( void )
1292 1298 {
1293 1299 unsigned int delta_snapshot;
1294 1300 unsigned int nb_samples_per_snapshot;
1295 1301 float delta_f1_in_float;
1296 1302
1297 1303 delta_snapshot = waveform_picker_regs->delta_snapshot;
1298 1304 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1299 1305 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1300 1306
1301 1307 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1302 1308 }
1303 1309
1304 1310 void set_wfp_delta_f2()
1305 1311 {
1306 1312 unsigned int delta_snapshot;
1307 1313 unsigned int nb_samples_per_snapshot;
1308 1314
1309 1315 delta_snapshot = waveform_picker_regs->delta_snapshot;
1310 1316 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1311 1317
1312 1318 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1313 1319 }
1314 1320
1315 1321 //*****************
1316 1322 // local parameters
1317 1323
1318 1324 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1319 1325 {
1320 1326 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1321 1327 *
1322 1328 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1323 1329 * @param sid is the source identifier of the packet being updated.
1324 1330 *
1325 1331 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1326 1332 * The sequence counters shall wrap around from 2^14 to zero.
1327 1333 * The sequence counter shall start at zero at startup.
1328 1334 *
1329 1335 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1330 1336 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1331 1337 *
1332 1338 */
1333 1339
1334 1340 unsigned short *sequence_cnt;
1335 1341 unsigned short segmentation_grouping_flag;
1336 1342 unsigned short new_packet_sequence_control;
1337 1343 rtems_mode initial_mode_set;
1338 1344 rtems_mode current_mode_set;
1339 1345 rtems_status_code status;
1340 1346
1341 1347 //******************************************
1342 1348 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1343 1349 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1344 1350
1345 1351 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1346 1352 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1347 1353 || (sid == SID_BURST_CWF_F2)
1348 1354 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1349 1355 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1350 1356 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1351 1357 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1352 1358 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1353 1359 {
1354 1360 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1355 1361 }
1356 1362 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1357 1363 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1358 1364 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1359 1365 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1360 1366 {
1361 1367 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1362 1368 }
1363 1369 else
1364 1370 {
1365 1371 sequence_cnt = (unsigned short *) NULL;
1366 1372 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1367 1373 }
1368 1374
1369 1375 if (sequence_cnt != NULL)
1370 1376 {
1371 1377 // increment the sequence counter
1372 1378 if ( *sequence_cnt < SEQ_CNT_MAX)
1373 1379 {
1374 1380 *sequence_cnt = *sequence_cnt + 1;
1375 1381 }
1376 1382 else
1377 1383 {
1378 1384 *sequence_cnt = 0;
1379 1385 }
1380 1386 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1381 1387 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1382 1388
1383 1389 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1384 1390
1385 1391 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1386 1392 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1387 1393 }
1388 1394
1389 1395 //***********************************
1390 1396 // RESET THE MODE OF THE CALLING TASK
1391 1397 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1392 1398 }
General Comments 0
You need to be logged in to leave comments. Login now