##// END OF EJS Templates
New version of the waveform picker packet transmission...
paul -
r172:ddd72945217c VHDL_0_1_28
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 Nov 6 16:03:39 2014
3 # Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Nov 13 07:59:00 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 DEFINES = -DSW_VERSION_N1=2 -DSW_VERSION_N2=0 -DSW_VERSION_N3=1 -DSW_VERSION_N4=1 -DLPP_DPU_DESTID -DPRINT_MESSAGES_ON_CONSOLE -DPRINT_TASK_STATISTICS
13 DEFINES = -DSW_VERSION_N1=2 -DSW_VERSION_N2=0 -DSW_VERSION_N3=1 -DSW_VERSION_N4=1 -DLPP_DPU_DESTID -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,107 +1,107
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 4 # lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
5 CONFIG += console verbose lpp_dpu_destid
6 6 CONFIG -= qt
7 7
8 8 include(./sparc.pri)
9 9
10 10 # flight software version
11 11 SWVERSION=-1-0
12 12 DEFINES += SW_VERSION_N1=2 # major
13 13 DEFINES += SW_VERSION_N2=0 # minor
14 14 DEFINES += SW_VERSION_N3=1 # patch
15 15 DEFINES += SW_VERSION_N4=1 # internal
16 16
17 17 # <GCOV>
18 18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
20 20 # </GCOV>
21 21
22 22 # <CHANGE BEFORE FLIGHT>
23 23 contains( CONFIG, lpp_dpu_destid ) {
24 24 DEFINES += LPP_DPU_DESTID
25 25 }
26 26 # </CHANGE BEFORE FLIGHT>
27 27
28 28 contains( CONFIG, debug_tch ) {
29 29 DEFINES += DEBUG_TCH
30 30 }
31 31
32 32 contains( CONFIG, vhdl_dev ) {
33 33 DEFINES += VHDL_DEV
34 34 }
35 35
36 36 contains( CONFIG, verbose ) {
37 37 DEFINES += PRINT_MESSAGES_ON_CONSOLE
38 38 }
39 39
40 40 contains( CONFIG, debug_messages ) {
41 41 DEFINES += DEBUG_MESSAGES
42 42 }
43 43
44 44 contains( CONFIG, cpu_usage_report ) {
45 45 DEFINES += PRINT_TASK_STATISTICS
46 46 }
47 47
48 48 contains( CONFIG, stack_report ) {
49 49 DEFINES += PRINT_STACK_REPORT
50 50 }
51 51
52 52 contains( CONFIG, boot_messages ) {
53 53 DEFINES += BOOT_MESSAGES
54 54 }
55 55
56 56 #doxygen.target = doxygen
57 57 #doxygen.commands = doxygen ../doc/Doxyfile
58 58 #QMAKE_EXTRA_TARGETS += doxygen
59 59
60 60 TARGET = fsw
61 61
62 62 INCLUDEPATH += \
63 63 ../src \
64 64 ../header \
65 65 ../header/processing \
66 66 ../src/LFR_basic-parameters
67 67
68 68 SOURCES += \
69 69 ../src/wf_handler.c \
70 70 ../src/tc_handler.c \
71 71 ../src/fsw_misc.c \
72 72 ../src/fsw_init.c \
73 73 ../src/fsw_globals.c \
74 74 ../src/fsw_spacewire.c \
75 75 ../src/tc_load_dump_parameters.c \
76 76 ../src/tm_lfr_tc_exe.c \
77 77 ../src/tc_acceptance.c \
78 78 ../src/processing/fsw_processing.c \
79 79 ../src/processing/avf0_prc0.c \
80 80 ../src/processing/avf1_prc1.c \
81 81 ../src/processing/avf2_prc2.c \
82 82 ../src/lfr_cpu_usage_report.c \
83 83 ../src/LFR_basic-parameters/basic_parameters.c
84 84
85 85 HEADERS += \
86 86 ../header/wf_handler.h \
87 87 ../header/tc_handler.h \
88 88 ../header/grlib_regs.h \
89 89 ../header/fsw_params.h \
90 90 ../header/fsw_misc.h \
91 91 ../header/fsw_init.h \
92 92 ../header/ccsds_types.h \
93 93 ../header/fsw_spacewire.h \
94 94 ../header/tc_load_dump_parameters.h \
95 95 ../header/tm_lfr_tc_exe.h \
96 96 ../header/tc_acceptance.h \
97 97 ../header/fsw_params_nb_bytes.h \
98 98 ../header/fsw_params_processing.h \
99 99 ../header/processing/fsw_processing.h \
100 100 ../header/processing/avf0_prc0.h \
101 101 ../header/processing/avf1_prc1.h \
102 102 ../header/processing/avf2_prc2.h \
103 103 ../header/fsw_params_wf_handler.h \
104 104 ../header/lfr_cpu_usage_report.h \
105 105 ../src/LFR_basic-parameters/basic_parameters.h \
106 106 ../src/LFR_basic-parameters/basic_parameters_params.h
107 107
@@ -1,208 +1,208
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by QtCreator 3.2.1, 2014-11-05T17:29:44. -->
3 <!-- Written by QtCreator 3.2.1, 2014-11-12T16:01:52. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>EnvironmentId</variable>
7 7 <value type="QByteArray">{2e58a81f-9962-4bba-ae6b-760177f0656c}</value>
8 8 </data>
9 9 <data>
10 10 <variable>ProjectExplorer.Project.ActiveTarget</variable>
11 11 <value type="int">0</value>
12 12 </data>
13 13 <data>
14 14 <variable>ProjectExplorer.Project.EditorSettings</variable>
15 15 <valuemap type="QVariantMap">
16 16 <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
17 17 <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
18 18 <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
19 19 <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
20 20 <value type="QString" key="language">Cpp</value>
21 21 <valuemap type="QVariantMap" key="value">
22 22 <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
23 23 </valuemap>
24 24 </valuemap>
25 25 <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
26 26 <value type="QString" key="language">QmlJS</value>
27 27 <valuemap type="QVariantMap" key="value">
28 28 <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
29 29 </valuemap>
30 30 </valuemap>
31 31 <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
32 32 <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
33 33 <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
34 34 <value type="int" key="EditorConfiguration.IndentSize">4</value>
35 35 <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
36 36 <value type="int" key="EditorConfiguration.MarginColumn">80</value>
37 37 <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
38 38 <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
39 39 <value type="int" key="EditorConfiguration.PaddingMode">1</value>
40 40 <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
41 41 <value type="bool" key="EditorConfiguration.ShowMargin">false</value>
42 42 <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
43 43 <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
44 44 <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
45 45 <value type="int" key="EditorConfiguration.TabSize">8</value>
46 46 <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
47 47 <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
48 48 <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
49 49 <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
50 50 <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
51 51 <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
52 52 </valuemap>
53 53 </data>
54 54 <data>
55 55 <variable>ProjectExplorer.Project.PluginSettings</variable>
56 56 <valuemap type="QVariantMap"/>
57 57 </data>
58 58 <data>
59 59 <variable>ProjectExplorer.Project.Target.0</variable>
60 60 <valuemap type="QVariantMap">
61 61 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop-Qt 4.8.2 in PATH (System)</value>
62 62 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop-Qt 4.8.2 in PATH (System)</value>
63 63 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{5289e843-9ef2-45ce-88c6-ad27d8e08def}</value>
64 64 <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
65 65 <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
66 66 <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
67 67 <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
68 68 <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory"></value>
69 69 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
70 70 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
71 71 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
72 72 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
73 73 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
74 74 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
75 75 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
76 76 <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">false</value>
77 77 <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
78 78 <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
79 79 </valuemap>
80 80 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
81 81 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
82 82 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
83 83 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
84 84 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
85 85 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
86 86 <value type="QString">-w</value>
87 87 <value type="QString">-r</value>
88 88 </valuelist>
89 89 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
90 90 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
91 91 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
92 92 </valuemap>
93 93 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
94 94 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
95 95 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
96 96 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
97 97 </valuemap>
98 98 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
99 99 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
100 100 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
101 101 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
102 102 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
103 103 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
104 104 <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
105 105 <value type="QString">-w</value>
106 106 <value type="QString">-r</value>
107 107 </valuelist>
108 108 <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
109 109 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
110 110 <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
111 111 </valuemap>
112 112 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
113 113 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
114 114 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
115 115 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
116 116 </valuemap>
117 117 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
118 118 <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
119 119 <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
120 120 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
121 121 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
122 122 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
123 123 <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
124 124 <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
125 125 </valuemap>
126 126 <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
127 127 <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
128 128 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
129 129 <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
130 130 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
131 131 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
132 132 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
133 133 </valuemap>
134 134 <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
135 135 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
136 136 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
137 137 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
138 138 </valuemap>
139 139 <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
140 140 <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
141 141 <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
142 142 <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
143 143 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
144 144 <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
145 145 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
146 146 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
147 147 <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
148 148 <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
149 149 <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
150 150 <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
151 151 <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
152 152 <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
153 153 <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
154 154 <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
155 155 <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
156 156 <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
157 157 <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
158 158 <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
159 159 <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
160 160 <value type="int">0</value>
161 161 <value type="int">1</value>
162 162 <value type="int">2</value>
163 163 <value type="int">3</value>
164 164 <value type="int">4</value>
165 165 <value type="int">5</value>
166 166 <value type="int">6</value>
167 167 <value type="int">7</value>
168 168 <value type="int">8</value>
169 169 <value type="int">9</value>
170 170 <value type="int">10</value>
171 171 <value type="int">11</value>
172 172 <value type="int">12</value>
173 173 <value type="int">13</value>
174 174 <value type="int">14</value>
175 175 </valuelist>
176 176 <value type="int" key="PE.EnvironmentAspect.Base">2</value>
177 177 <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
178 178 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">fsw-qt</value>
179 179 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
180 180 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/opt/DEV_PLE/FSW-qt/fsw-qt.pro</value>
181 181 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
182 182 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">fsw-qt.pro</value>
183 183 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
184 184 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
185 185 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
186 186 <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
187 187 <value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
188 188 <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
189 189 <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
190 190 <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
191 191 <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
192 192 </valuemap>
193 193 <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
194 194 </valuemap>
195 195 </data>
196 196 <data>
197 197 <variable>ProjectExplorer.Project.TargetCount</variable>
198 198 <value type="int">1</value>
199 199 </data>
200 200 <data>
201 201 <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
202 202 <value type="int">16</value>
203 203 </data>
204 204 <data>
205 205 <variable>Version</variable>
206 206 <value type="int">16</value>
207 207 </data>
208 208 </qtcreator>
@@ -1,47 +1,46
1 1 #ifndef FSW_MISC_H_INCLUDED
2 2 #define FSW_MISC_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6 #include <grspw.h>
7 7
8 8 #include "fsw_params.h"
9 9 #include "fsw_spacewire.h"
10 10 #include "lfr_cpu_usage_report.h"
11 11
12 12 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
13 13 rtems_id HK_id; // id of the HK rate monotonic period
14 14
15 15 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
16 16 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
17 17 void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
18 18 void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
19 19 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
20 20
21 21 // SERIAL LINK
22 22 int send_console_outputs_on_apbuart_port( void );
23 23 int enable_apbuart_transmitter( void );
24 24 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
25 25
26 26 // RTEMS TASKS
27 27 rtems_task stat_task( rtems_task_argument argument );
28 28 rtems_task hous_task( rtems_task_argument argument );
29 29 rtems_task dumb_task( rtems_task_argument unused );
30 30
31 31 void init_housekeeping_parameters( void );
32 32 void increment_seq_counter(unsigned short *packetSequenceControl);
33 33 void getTime( unsigned char *time);
34 34 unsigned long long int getTimeAsUnsignedLongLongInt( );
35 35 void send_dumb_hk( void );
36 36 void get_v_e1_e2_f3(unsigned char *spacecraft_potential);
37 void get_v_e1_e2_f3_alt(unsigned char *spacecraft_potential);
38 37 void get_cpu_load( unsigned char *resource_statistics );
39 38
40 39 extern int sched_yield( void );
41 40 extern void rtems_cpu_usage_reset();
42 41 extern ring_node *current_ring_node_f3;
43 42 extern ring_node *ring_node_to_send_cwf_f3;
44 43 extern ring_node waveform_ring_f3[];
45 44 extern unsigned short sequenceCounterHK;
46 45
47 46 #endif // FSW_MISC_H_INCLUDED
@@ -1,259 +1,260
1 1 #ifndef FSW_PARAMS_H_INCLUDED
2 2 #define FSW_PARAMS_H_INCLUDED
3 3
4 4 #include "grlib_regs.h"
5 5 #include "fsw_params_processing.h"
6 6 #include "fsw_params_nb_bytes.h"
7 7 #include "tm_byte_positions.h"
8 8 #include "ccsds_types.h"
9 9
10 10 #define GRSPW_DEVICE_NAME "/dev/grspw0"
11 11 #define UART_DEVICE_NAME "/dev/console"
12 12
13 13 typedef struct ring_node
14 14 {
15 15 struct ring_node *previous;
16 16 struct ring_node *next;
17 unsigned int sid;
17 18 unsigned int coarseTime;
18 19 unsigned int fineTime;
19 20 int buffer_address;
20 21 unsigned int status;
21 22 } ring_node;
22 23
23 24 //************************
24 25 // flight software version
25 26 // this parameters is handled by the Qt project options
26 27
27 28 #define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk
28 29 #define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk
29 30 #define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688
30 31 #define TIME_OFFSET 2
31 32 #define TIME_OFFSET_IN_BYTES 8
32 33 //#define WAVEFORM_EXTENDED_HEADER_OFFSET 22
33 34 #define NB_BYTES_SWF_BLK (2 * 6)
34 35 #define NB_WORDS_SWF_BLK 3
35 36 #define NB_BYTES_CWF3_LIGHT_BLK 6
36 37 //#define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8
37 38 #define NB_RING_NODES_F0 3 // AT LEAST 3
38 39 #define NB_RING_NODES_F1 5 // AT LEAST 3
39 40 #define NB_RING_NODES_F2 5 // AT LEAST 3
40 41 #define NB_RING_NODES_F3 3 // AT LEAST 3
41 42
42 43 //**********
43 44 // LFR MODES
44 45 #define LFR_MODE_STANDBY 0
45 46 #define LFR_MODE_NORMAL 1
46 47 #define LFR_MODE_BURST 2
47 48 #define LFR_MODE_SBM1 3
48 49 #define LFR_MODE_SBM2 4
49 50
50 51 #define TDS_MODE_LFM 5
51 52 #define TDS_MODE_STANDBY 0
52 53 #define TDS_MODE_NORMAL 1
53 54 #define TDS_MODE_BURST 2
54 55 #define TDS_MODE_SBM1 3
55 56 #define TDS_MODE_SBM2 4
56 57
57 58 #define THR_MODE_STANDBY 0
58 59 #define THR_MODE_NORMAL 1
59 60 #define THR_MODE_BURST 2
60 61
61 62 #define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0
62 63 #define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1
63 64 #define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2
64 65 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
65 66 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
66 67 #define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5
67 68 #define RTEMS_EVENT_NORM_BP1_F0 RTEMS_EVENT_6
68 69 #define RTEMS_EVENT_NORM_BP2_F0 RTEMS_EVENT_7
69 70 #define RTEMS_EVENT_NORM_ASM_F0 RTEMS_EVENT_8 // ASM only in NORM mode
70 71 #define RTEMS_EVENT_NORM_BP1_F1 RTEMS_EVENT_9
71 72 #define RTEMS_EVENT_NORM_BP2_F1 RTEMS_EVENT_10
72 73 #define RTEMS_EVENT_NORM_ASM_F1 RTEMS_EVENT_11 // ASM only in NORM mode
73 74 #define RTEMS_EVENT_NORM_BP1_F2 RTEMS_EVENT_12
74 75 #define RTEMS_EVENT_NORM_BP2_F2 RTEMS_EVENT_13
75 76 #define RTEMS_EVENT_NORM_ASM_F2 RTEMS_EVENT_14 // ASM only in NORM mode
76 77 #define RTEMS_EVENT_SBM_BP1_F0 RTEMS_EVENT_15
77 78 #define RTEMS_EVENT_SBM_BP2_F0 RTEMS_EVENT_16
78 79 #define RTEMS_EVENT_SBM_BP1_F1 RTEMS_EVENT_17
79 80 #define RTEMS_EVENT_SBM_BP2_F1 RTEMS_EVENT_18
80 81 #define RTEMS_EVENT_BURST_BP1_F0 RTEMS_EVENT_19
81 82 #define RTEMS_EVENT_BURST_BP2_F0 RTEMS_EVENT_20
82 83 #define RTEMS_EVENT_BURST_BP1_F1 RTEMS_EVENT_21
83 84 #define RTEMS_EVENT_BURST_BP2_F1 RTEMS_EVENT_22
84 85
85 86 //****************************
86 87 // LFR DEFAULT MODE PARAMETERS
87 88 // COMMON
88 89 #define DEFAULT_SY_LFR_COMMON0 0x00
89 90 #define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0
90 91 // NORM
91 92 #define DFLT_SY_LFR_N_SWF_L 2048 // nb sample
92 93 #define DFLT_SY_LFR_N_SWF_P 300 // sec
93 94 #define DFLT_SY_LFR_N_ASM_P 3600 // sec
94 95 #define DFLT_SY_LFR_N_BP_P0 4 // sec
95 96 #define DFLT_SY_LFR_N_BP_P1 20 // sec
96 97 #define DFLT_SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3
97 98 #define MIN_DELTA_SNAPSHOT 16 // sec
98 99 // BURST
99 100 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
100 101 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
101 102 // SBM1
102 103 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
103 104 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
104 105 // SBM2
105 106 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
106 107 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
107 108 // ADDITIONAL PARAMETERS
108 109 #define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms
109 110 #define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s
110 111 // STATUS WORD
111 112 #define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits
112 113 #define DEFAULT_STATUS_WORD_BYTE1 0x00
113 114 //
114 115 #define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s
115 116 #define SY_LFR_DPU_CONNECT_ATTEMPT 3
116 117 //****************************
117 118
118 119 //*****************************
119 120 // APB REGISTERS BASE ADDRESSES
120 121 #define REGS_ADDR_APBUART 0x80000100
121 122 #define REGS_ADDR_GPTIMER 0x80000300
122 123 #define REGS_ADDR_GRSPW 0x80000500
123 124 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
124 125 #define REGS_ADDR_GRGPIO 0x80000b00
125 126
126 127 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
127 128 //#define REGS_ADDR_WAVEFORM_PICKER 0x80000f50
128 129 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f54 // PDB >= 0.1.28
129 130 #define REGS_ADDR_VHDL_VERSION 0x80000ff0
130 131
131 132 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
132 133 #define APBUART_CTRL_REG_MASK_TE 0x00000002
133 134 // scaler value = system_clock_frequency / ( baud_rate * 8 ) - 1
134 135 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
135 136
136 137 //**********
137 138 // IRQ LINES
138 139 #define IRQ_SM_SIMULATOR 9
139 140 #define IRQ_SPARC_SM_SIMULATOR 0x19 // see sparcv8.pdf p.76 for interrupt levels
140 141 #define IRQ_WAVEFORM_PICKER 14
141 142 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
142 143 #define IRQ_SPECTRAL_MATRIX 6
143 144 #define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels
144 145
145 146 //*****
146 147 // TIME
147 148 #define CLKDIV_SM_SIMULATOR (10416 - 1) // 10 ms => nominal is 1/96 = 0.010416667, 10417 - 1 = 10416
148 149 #define TIMER_SM_SIMULATOR 1
149 150 #define HK_PERIOD 100 // 100 * 10ms => 1s
150 151 #define SY_LFR_TIME_SYN_TIMEOUT_in_ms 2000
151 152 #define SY_LFR_TIME_SYN_TIMEOUT_in_ticks 200 // 200 * 10 ms = 2 s
152 153
153 154 //**********
154 155 // LPP CODES
155 156 #define LFR_SUCCESSFUL 0
156 157 #define LFR_DEFAULT 1
157 158 #define LFR_EXE_ERROR 2
158 159
159 160 //******
160 161 // RTEMS
161 162 #define TASKID_RECV 1
162 163 #define TASKID_ACTN 2
163 164 #define TASKID_SPIQ 3
164 165 #define TASKID_STAT 4
165 166 #define TASKID_AVF0 5
166 167 #define TASKID_SWBD 6
167 168 #define TASKID_WFRM 7
168 169 #define TASKID_DUMB 8
169 170 #define TASKID_HOUS 9
170 171 #define TASKID_PRC0 10
171 172 #define TASKID_CWF3 11
172 173 #define TASKID_CWF2 12
173 174 #define TASKID_CWF1 13
174 175 #define TASKID_SEND 14
175 176 #define TASKID_WTDG 15
176 177 #define TASKID_AVF1 16
177 178 #define TASKID_PRC1 17
178 179 #define TASKID_AVF2 18
179 180 #define TASKID_PRC2 19
180 181
181 182 #define TASK_PRIORITY_SPIQ 5
182 183 #define TASK_PRIORITY_WTDG 20
183 184 #define TASK_PRIORITY_HOUS 30
184 185 #define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together
185 186 #define TASK_PRIORITY_CWF2 35 //
186 187 #define TASK_PRIORITY_SWBD 37 // SWBD has a lower priority than WFRM, this is to extract the snapshot before sending it
187 188 #define TASK_PRIORITY_WFRM 40
188 189 #define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1
189 190 #define TASK_PRIORITY_SEND 45
190 191 #define TASK_PRIORITY_RECV 50
191 192 #define TASK_PRIORITY_ACTN 50
192 193 #define TASK_PRIORITY_AVF0 60
193 194 #define TASK_PRIORITY_AVF1 70
194 195 #define TASK_PRIORITY_PRC0 100
195 196 #define TASK_PRIORITY_PRC1 100
196 197 #define TASK_PRIORITY_AVF2 110
197 198 #define TASK_PRIORITY_PRC2 110
198 199 #define TASK_PRIORITY_STAT 200
199 200 #define TASK_PRIORITY_DUMB 200
200 201
201 202 #define MSG_QUEUE_COUNT_RECV 10
202 203 #define MSG_QUEUE_COUNT_SEND 50
203 204 #define MSG_QUEUE_COUNT_PRC0 10
204 205 #define MSG_QUEUE_COUNT_PRC1 10
205 206 #define MSG_QUEUE_COUNT_PRC2 5
206 207 #define MSG_QUEUE_SIZE_SEND 810 // 806 + 4 => TM_LFR_SCIENCE_BURST_BP2_F1
207 208 #define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options
208 209 #define MSG_QUEUE_SIZE_PRC0 20 // two pointers and one rtems_event + 2 integers
209 210 #define MSG_QUEUE_SIZE_PRC1 20 // two pointers and one rtems_event + 2 integers
210 211 #define MSG_QUEUE_SIZE_PRC2 20 // two pointers and one rtems_event + 2 integers
211 212
212 213 #define QUEUE_RECV 0
213 214 #define QUEUE_SEND 1
214 215 #define QUEUE_PRC0 2
215 216 #define QUEUE_PRC1 3
216 217 #define QUEUE_PRC2 4
217 218
218 219 //*******
219 220 // MACROS
220 221 #ifdef PRINT_MESSAGES_ON_CONSOLE
221 222 #define PRINTF(x) printf(x);
222 223 #define PRINTF1(x,y) printf(x,y);
223 224 #define PRINTF2(x,y,z) printf(x,y,z);
224 225 #else
225 226 #define PRINTF(x) ;
226 227 #define PRINTF1(x,y) ;
227 228 #define PRINTF2(x,y,z) ;
228 229 #endif
229 230
230 231 #ifdef BOOT_MESSAGES
231 232 #define BOOT_PRINTF(x) printf(x);
232 233 #define BOOT_PRINTF1(x,y) printf(x,y);
233 234 #define BOOT_PRINTF2(x,y,z) printf(x,y,z);
234 235 #else
235 236 #define BOOT_PRINTF(x) ;
236 237 #define BOOT_PRINTF1(x,y) ;
237 238 #define BOOT_PRINTF2(x,y,z) ;
238 239 #endif
239 240
240 241 #ifdef DEBUG_MESSAGES
241 242 #define DEBUG_PRINTF(x) printf(x);
242 243 #define DEBUG_PRINTF1(x,y) printf(x,y);
243 244 #define DEBUG_PRINTF2(x,y,z) printf(x,y,z);
244 245 #else
245 246 #define DEBUG_PRINTF(x) ;
246 247 #define DEBUG_PRINTF1(x,y) ;
247 248 #define DEBUG_PRINTF2(x,y,z) ;
248 249 #endif
249 250
250 251 #define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period
251 252
252 253 struct param_local_str{
253 254 unsigned int local_sbm1_nb_cwf_sent;
254 255 unsigned int local_sbm1_nb_cwf_max;
255 256 unsigned int local_sbm2_nb_cwf_sent;
256 257 unsigned int local_sbm2_nb_cwf_max;
257 258 };
258 259
259 260 #endif // FSW_PARAMS_H_INCLUDED
@@ -1,70 +1,71
1 1 #ifndef FSW_PARAMS_PROCESSING_H
2 2 #define FSW_PARAMS_PROCESSING_H
3 3
4 4 #define NB_BINS_PER_SM 128
5 5 #define NB_VALUES_PER_SM 25
6 6 #define TOTAL_SIZE_SM 3200 // 25 * 128 = 0xC80
7 7 #define TOTAL_SIZE_NORM_BP1_F0 99 // 11 * 9 = 99
8 8 #define TOTAL_SIZE_NORM_BP1_F1 117 // 13 * 9 = 117
9 9 #define TOTAL_SIZE_NORM_BP1_F2 108 // 12 * 9 = 108
10 10 #define TOTAL_SIZE_SBM1_BP1_F0 198 // 22 * 9 = 198
11 11 //
12 12 #define NB_RING_NODES_SM_F0 12 // AT LEAST 8 due to the way the averaging is done
13 13 #define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3
14 14 #define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3
15 #define NB_RING_NODES_ASM_F0 3 // AT LEAST 3
15 16 #define NB_RING_NODES_SM_F1 12 // AT LEAST 8 due to the way the averaging is done
16 17 #define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3
17 18 #define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3
18 19 #define NB_RING_NODES_SM_F2 3 // AT LEAST 3
19 20 #define NB_RING_NODES_ASM_BURST_SBM_F2 3 // AT LEAST 3
20 21 #define NB_RING_NODES_ASM_NORM_F2 3 // AT LEAST 3
21 22 //
22 23 #define NB_BINS_PER_ASM_F0 88
23 24 #define NB_BINS_PER_PKT_ASM_F0 44
24 25 #define TOTAL_SIZE_ASM_F0_IN_BYTES 4400 // 25 * 88 * 2
25 26 #define ASM_F0_INDICE_START 17 // 88 bins
26 27 #define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins
27 28 //
28 29 #define NB_BINS_PER_ASM_F1 104
29 30 #define NB_BINS_PER_PKT_ASM_F1 52
30 31 #define TOTAL_SIZE_ASM_F1_IN_BYTES 5200 // 25 * 104 * 2
31 32 #define ASM_F1_INDICE_START 6 // 104 bins
32 33 #define ASM_F1_INDICE_STOP 109 // 2 packets of 52 bins
33 34 //
34 35 #define NB_BINS_PER_ASM_F2 96
35 36 #define NB_BINS_PER_PKT_ASM_F2 48
36 37 #define TOTAL_SIZE_ASM_F2_IN_BYTES 4800 // 25 * 96 * 2
37 38 #define ASM_F2_INDICE_START 7 // 96 bins
38 39 #define ASM_F2_INDICE_STOP 102 // 2 packets of 48 bins
39 40 //
40 41 #define NB_BINS_COMPRESSED_SM_F0 11
41 42 #define NB_BINS_COMPRESSED_SM_F1 13
42 43 #define NB_BINS_COMPRESSED_SM_F2 12
43 44 #define NB_BINS_COMPRESSED_SM_SBM_F0 22
44 45 #define NB_BINS_COMPRESSED_SM_SBM_F1 26
45 46 #define NB_BINS_COMPRESSED_SM_SBM_F2 24
46 47 //
47 48 #define NB_BYTES_PER_BP1 9
48 49 //
49 50 #define NB_BINS_TO_AVERAGE_ASM_F0 8
50 51 #define NB_BINS_TO_AVERAGE_ASM_F1 8
51 52 #define NB_BINS_TO_AVERAGE_ASM_F2 8
52 53 #define NB_BINS_TO_AVERAGE_ASM_SBM_F0 4
53 54 #define NB_BINS_TO_AVERAGE_ASM_SBM_F1 4
54 55 #define NB_BINS_TO_AVERAGE_ASM_SBM_F2 4
55 56 //
56 57 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F0 275 // 11 * 25 WORDS
57 58 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F1 325 // 13 * 25 WORDS
58 59 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F2 300 // 12 * 25 WORDS
59 60 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 550 // 22 * 25 WORDS
60 61 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 650 // 26 * 25 WORDS
61 62 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 600 // 24 * 25 WORDS
62 63 #define TOTAL_SIZE_BP1_NORM_F0 99 // 9 * 11 UNSIGNED CHAR
63 64 #define TOTAL_SIZE_BP1_SBM_F0 198 // 9 * 22 UNSIGNED CHAR
64 65 // GENERAL
65 66 #define NB_SM_BEFORE_AVF0 8 // must be 8 due to the SM_average() function
66 67 #define NB_SM_BEFORE_AVF1 8 // must be 8 due to the SM_average() function
67 68 #define NB_SM_BEFORE_AVF2 1 // must be 1 due to the SM_average_f2() function
68 69
69 70 #endif // FSW_PARAMS_PROCESSING_H
70 71
@@ -1,39 +1,47
1 1 #ifndef FSW_SPACEWIRE_H_INCLUDED
2 2 #define FSW_SPACEWIRE_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6
7 7 #include <fcntl.h> // for O_RDWR
8 8 #include <unistd.h> // for the read call
9 9 #include <sys/ioctl.h> // for the ioctl call
10 10 #include <errno.h>
11 11
12 12 #include "fsw_params.h"
13 13 #include "tc_handler.h"
14 14
15 15 extern spw_stats spacewire_stats;
16 16 extern spw_stats spacewire_stats_backup;
17 17
18 18 // RTEMS TASK
19 19 rtems_task spiq_task( rtems_task_argument argument );
20 20 rtems_task recv_task( rtems_task_argument unused );
21 21 rtems_task send_task( rtems_task_argument argument );
22 22 rtems_task wtdg_task( rtems_task_argument argument );
23 23
24 24 int spacewire_open_link( void );
25 25 int spacewire_start_link( int fd );
26 26 int spacewire_stop_and_start_link( int fd );
27 27 int spacewire_configure_link(int fd );
28 28 int spacewire_reset_link( void );
29 29 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
30 30 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
31 31 void spacewire_compute_stats_offsets( void );
32 32 void spacewire_update_statistics( void );
33 33
34 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header );
35 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header );
36 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header );
37 int spw_send_waveform_CWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
38 int spw_send_waveform_SWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_SWF_t *header );
39 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
40 void spw_send_asm( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
41
34 42 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
35 43 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data );
36 44
37 45 void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc );
38 46
39 47 #endif // FSW_SPACEWIRE_H_INCLUDED
@@ -1,28 +1,28
1 1 #ifndef AVF2_PRC2_H
2 2 #define AVF2_PRC2_H
3 3
4 4 #include "fsw_processing.h"
5 5
6 6 typedef struct {
7 7 unsigned int norm_bp1;
8 8 unsigned int norm_bp2;
9 9 unsigned int norm_asm;
10 10 } nb_sm_before_bp_asm_f2;
11 11
12 12 //************
13 13 // RTEMS TASKS
14 14 rtems_task avf2_task( rtems_task_argument lfrRequestedMode );
15 15 rtems_task prc2_task( rtems_task_argument lfrRequestedMode );
16 16
17 17 //**********
18 18 // FUNCTIONS
19 19
20 20 void reset_nb_sm_f2( void );
21 void SM_average_f2( float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 );
21 void SM_average_f2(float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 );
22 22
23 23 //*******
24 24 // EXTERN
25 25 extern struct ring_node_sm *ring_node_for_averaging_sm_f2;
26 26 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
27 27
28 28 #endif // AVF2_PRC2_H
@@ -1,244 +1,279
1 1 #ifndef FSW_PROCESSING_H_INCLUDED
2 2 #define FSW_PROCESSING_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <math.h>
7 7 #include <stdlib.h> // abs() is in the stdlib
8 8 #include <stdio.h> // printf()
9 9 #include <math.h>
10 10
11 11 #include "fsw_params.h"
12 12 #include "fsw_spacewire.h"
13 13
14 14 typedef struct ring_node_sm
15 15 {
16 struct ring_node_sm *previous;
17 struct ring_node_sm *next;
18 int buffer_address;
19 unsigned int status;
20 unsigned int coarseTime;
21 unsigned int fineTime;
16 struct ring_node_sm *previous;
17 struct ring_node_sm *next;
18 int buffer_address;
19 unsigned int status;
20 unsigned int coarseTime;
21 unsigned int fineTime;
22 22 } ring_node_sm;
23 23
24 24 typedef struct ring_node_asm
25 25 {
26 26 struct ring_node_asm *next;
27 27 float matrix[ TOTAL_SIZE_SM ];
28 28 unsigned int status;
29 29 } ring_node_asm;
30 30
31 31 typedef struct
32 32 {
33 33 Header_TM_LFR_SCIENCE_BP_t header;
34 34 unsigned char data[ 30 * 22 ]; // MAX size is 22 * 30 [TM_LFR_SCIENCE_BURST_BP2_F1]
35 35 } bp_packet;
36 36
37 37 typedef struct
38 38 {
39 39 Header_TM_LFR_SCIENCE_BP_with_spare_t header;
40 40 unsigned char data[ 9 * 13 ]; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
41 41 } bp_packet_with_spare;
42 42
43 43 typedef struct
44 44 {
45 45 ring_node_asm *norm;
46 46 ring_node_asm *burst_sbm;
47 47 rtems_event_set event;
48 48 unsigned int coarseTime;
49 49 unsigned int fineTime;
50 50 } asm_msg;
51 51
52 52 extern volatile int sm_f0[ ];
53 53 extern volatile int sm_f1[ ];
54 54 extern volatile int sm_f2[ ];
55 55
56 56 // parameters
57 57 extern struct param_local_str param_local;
58 58
59 59 // registers
60 60 extern time_management_regs_t *time_management_regs;
61 61 extern spectral_matrix_regs_t *spectral_matrix_regs;
62 62
63 63 extern rtems_name misc_name[5];
64 64 extern rtems_id Task_id[20]; /* array of task ids */
65 65
66 66 // ISR
67 67 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
68 68 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
69 69
70 70 //******************
71 71 // Spectral Matrices
72 72 void reset_nb_sm( void );
73 73 // SM
74 74 void SM_init_rings( void );
75 75 void SM_reset_current_ring_nodes( void );
76 void SM_generic_init_ring(ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] );
77 76 // ASM
78 77 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
79 78 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header);
80 79 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
81 80 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id);
82 81
83 82 //*****************
84 83 // Basic Parameters
85 84
86 85 void BP_reset_current_ring_nodes( void );
87 86 void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header,
88 87 unsigned int apid, unsigned char sid,
89 88 unsigned int packetLength , unsigned char blkNr);
90 89 void BP_init_header_with_spare( Header_TM_LFR_SCIENCE_BP_with_spare_t *header,
91 90 unsigned int apid, unsigned char sid,
92 91 unsigned int packetLength, unsigned char blkNr );
93 92 void BP_send( char *data,
94 93 rtems_id queue_id ,
95 94 unsigned int nbBytesToSend , unsigned int sid );
96 95
97 96 //******************
98 97 // general functions
99 98 void reset_sm_status( void );
100 99 void reset_spectral_matrix_regs( void );
101 100 void set_time(unsigned char *time, unsigned char *timeInBuffer );
102 101 unsigned long long int get_acquisition_time( unsigned char *timePtr );
103 void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
104 ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time);
102 void close_matrix_actions( unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
103 ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time );
105 104 unsigned char getSID( rtems_event_set event );
106 105
107 106 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
108 107 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
109 108
110 109 //***************************************
111 110 // DEFINITIONS OF STATIC INLINE FUNCTIONS
112 static inline void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
111 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
112 ring_node_sm *ring_node_tab[],
113 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
114 static inline void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
113 115 ring_node_sm *ring_node_tab[],
114 116 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
115 117 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
116 118 float divider );
117 119 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
118 120 float divider,
119 121 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
120 122 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
121 123
122 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
124 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
123 125 ring_node_sm *ring_node_tab[],
124 126 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
125 127 {
126 128 float sum;
127 129 unsigned int i;
128 130
129 131 for(i=0; i<TOTAL_SIZE_SM; i++)
130 132 {
131 133 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
132 134 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
133 135 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
134 136 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
135 137 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
136 138 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
137 139 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
138 140 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
139 141
140 142 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
141 143 {
142 144 averaged_spec_mat_NORM[ i ] = sum;
143 145 averaged_spec_mat_SBM[ i ] = sum;
144 146 }
145 147 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
146 148 {
147 149 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
148 150 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
149 151 }
150 152 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
151 153 {
152 154 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
153 155 averaged_spec_mat_SBM[ i ] = sum;
154 156 }
155 157 else
156 158 {
157 159 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
158 160 }
159 161 }
160 162 }
161 163
164 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
165 ring_node_sm *ring_node_tab[],
166 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
167 {
168 float sum;
169 unsigned int i;
170
171 for(i=0; i<TOTAL_SIZE_SM; i++)
172 {
173 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
174
175 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
176 {
177 averaged_spec_mat_NORM[ i ] = sum;
178 averaged_spec_mat_SBM[ i ] = sum;
179 }
180 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
181 {
182 averaged_spec_mat_NORM[ i ] = sum;
183 averaged_spec_mat_SBM[ i ] = sum;
184 }
185 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
186 {
187 averaged_spec_mat_NORM[ i ] = sum;
188 averaged_spec_mat_SBM[ i ] = sum;
189 }
190 else
191 {
192 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
193 }
194 }
195 }
196
162 197 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
163 198 {
164 199 int frequencyBin;
165 200 int asmComponent;
166 201 unsigned int offsetAveragedSpecMatReorganized;
167 202 unsigned int offsetAveragedSpecMat;
168 203
169 204 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
170 205 {
171 206 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
172 207 {
173 208 offsetAveragedSpecMatReorganized =
174 209 frequencyBin * NB_VALUES_PER_SM
175 210 + asmComponent;
176 211 offsetAveragedSpecMat =
177 212 asmComponent * NB_BINS_PER_SM
178 213 + frequencyBin;
179 214 averaged_spec_mat_reorganized[offsetAveragedSpecMatReorganized ] =
180 215 averaged_spec_mat[ offsetAveragedSpecMat ] / divider;
181 216 }
182 217 }
183 218 }
184 219
185 220 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
186 221 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
187 222 {
188 223 int frequencyBin;
189 224 int asmComponent;
190 225 int offsetASM;
191 226 int offsetCompressed;
192 227 int k;
193 228
194 229 // build data
195 230 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
196 231 {
197 232 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
198 233 {
199 234 offsetCompressed = // NO TIME OFFSET
200 235 frequencyBin * NB_VALUES_PER_SM
201 236 + asmComponent;
202 237 offsetASM = // NO TIME OFFSET
203 238 asmComponent * NB_BINS_PER_SM
204 239 + ASMIndexStart
205 240 + frequencyBin * nbBinsToAverage;
206 241 compressed_spec_mat[ offsetCompressed ] = 0;
207 242 for ( k = 0; k < nbBinsToAverage; k++ )
208 243 {
209 244 compressed_spec_mat[offsetCompressed ] =
210 245 ( compressed_spec_mat[ offsetCompressed ]
211 246 + averaged_spec_mat[ offsetASM + k ] ) / (divider * nbBinsToAverage);
212 247 }
213 248 }
214 249 }
215 250 }
216 251
217 252 void ASM_convert( volatile float *input_matrix, char *output_matrix)
218 253 {
219 254 unsigned int frequencyBin;
220 255 unsigned int asmComponent;
221 256 char * pt_char_input;
222 257 char * pt_char_output;
223 258 unsigned int offsetInput;
224 259 unsigned int offsetOutput;
225 260
226 261 pt_char_input = (char*) &input_matrix;
227 262 pt_char_output = (char*) &output_matrix;
228 263
229 264 // convert all other data
230 265 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
231 266 {
232 267 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
233 268 {
234 269 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
235 270 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
236 271 pt_char_input = (char*) &input_matrix [ offsetInput ];
237 272 pt_char_output = (char*) &output_matrix[ offsetOutput ];
238 273 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
239 274 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
240 275 }
241 276 }
242 277 }
243 278
244 279 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,93 +1,88
1 1 #ifndef WF_HANDLER_H_INCLUDED
2 2 #define WF_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <stdio.h>
7 7 #include <math.h>
8 8
9 9 #include "fsw_params.h"
10 10 #include "fsw_spacewire.h"
11 11 #include "fsw_misc.h"
12 12 #include "fsw_params_wf_handler.h"
13 13
14 14 #define pi 3.1415
15 15
16 16 extern int fdSPW;
17 17
18 18 //*****************
19 19 // waveform buffers
20 extern volatile int wf_snap_f0[ ];
21 extern volatile int wf_snap_f1[ ];
22 extern volatile int wf_snap_f2[ ];
23 extern volatile int wf_cont_f3[ ];
20 extern volatile int wf_buffer_f0[ ];
21 extern volatile int wf_buffer_f1[ ];
22 extern volatile int wf_buffer_f2[ ];
23 extern volatile int wf_buffer_f3[ ];
24 24 extern char wf_cont_f3_light[ ];
25 25
26 26 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
27 27 extern time_management_regs_t *time_management_regs;
28 28 extern Packet_TM_LFR_HK_t housekeeping_packet;
29 29 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
30 30 extern struct param_local_str param_local;
31 31
32 32 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
33 33 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
34 34
35 35 extern rtems_id Task_id[20]; /* array of task ids */
36 36
37 37 extern unsigned char lfrCurrentMode;
38 38
39 39 //**********
40 40 // RTEMS_ISR
41 41 void reset_extractSWF( void );
42 42 rtems_isr waveforms_isr( rtems_vector_number vector );
43 43
44 44 //***********
45 45 // RTEMS_TASK
46 46 rtems_task wfrm_task( rtems_task_argument argument );
47 47 rtems_task cwf3_task( rtems_task_argument argument );
48 48 rtems_task cwf2_task( rtems_task_argument argument );
49 49 rtems_task cwf1_task( rtems_task_argument argument );
50 50 rtems_task swbd_task( rtems_task_argument argument );
51 51
52 52 //******************
53 53 // general functions
54 54 void WFP_init_rings( void );
55 void init_waveform_ring( ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] );
55 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
56 56 void WFP_reset_current_ring_nodes( void );
57 57 //
58 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF );
59 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
60 58 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
61 59 //
62 int send_waveform_SWF( ring_node *ring_node_to_send, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
63 int send_waveform_CWF( ring_node *ring_node_to_send, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
64 int send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
65 int send_ring_node_CWF( ring_node *ring_node_to_send );
60 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
66 61 //
67 62 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
68 63 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
69 64 void build_snapshot_from_ring(ring_node *ring_node_to_send , unsigned char frequencyChannel );
70 65 void snapshot_resynchronization( unsigned char *timePtr );
71 66 //
72 67 rtems_id get_pkts_queue_id( void );
73 68
74 69 //**************
75 70 // wfp registers
76 71 // RESET
77 72 void reset_wfp_burst_enable( void );
78 73 void reset_wfp_status( void );
79 74 void reset_wfp_buffer_addresses( void );
80 75 void reset_waveform_picker_regs( void );
81 76 // SET
82 77 void set_wfp_data_shaping(void);
83 78 void set_wfp_burst_enable_register( unsigned char mode );
84 79 void set_wfp_delta_snapshot( void );
85 80 void set_wfp_delta_f0_f0_2( void );
86 81 void set_wfp_delta_f1( void );
87 82 void set_wfp_delta_f2( void );
88 83
89 84 //*****************
90 85 // local parameters
91 86 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
92 87
93 88 #endif // WF_HANDLER_H_INCLUDED
@@ -1,75 +1,75
1 1 /** Global variables of the LFR flight software.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * Among global variables, there are:
7 7 * - RTEMS names and id.
8 8 * - APB configuration registers.
9 9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 10 * - spectral matrices buffesr, used by the hardware module to store data.
11 11 * - variable related to LFR modes parameters.
12 12 * - the global HK packet buffer.
13 13 * - the global dump parameter buffer.
14 14 *
15 15 */
16 16
17 17 #include <rtems.h>
18 18 #include <grspw.h>
19 19
20 20 #include "ccsds_types.h"
21 21 #include "grlib_regs.h"
22 22 #include "fsw_params.h"
23 23 #include "fsw_params_wf_handler.h"
24 24
25 25 // RTEMS GLOBAL VARIABLES
26 26 rtems_name misc_name[5];
27 27 rtems_id misc_id[5];
28 28 rtems_name Task_name[20]; /* array of task names */
29 29 rtems_id Task_id[20]; /* array of task ids */
30 30 unsigned int maxCount;
31 31 int fdSPW = 0;
32 32 int fdUART = 0;
33 33 unsigned char lfrCurrentMode;
34 34
35 35 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
36 36 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
37 37 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
38 38 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
39 39 // F0 F1 F2 F3
40 volatile int wf_snap_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_snap_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_snap_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_cont_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
40 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 44 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100)));
45 45
46 46 //***********************************
47 47 // SPECTRAL MATRICES GLOBAL VARIABLES
48 48
49 49 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
50 50 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
51 51 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
52 52 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
53 53
54 54 // APB CONFIGURATION REGISTERS
55 55 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
56 56 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
57 57 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
58 58 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
59 59
60 60 // MODE PARAMETERS
61 61 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
62 62 struct param_local_str param_local;
63 63
64 64 // HK PACKETS
65 65 Packet_TM_LFR_HK_t housekeeping_packet;
66 66 // sequence counters are incremented by APID (PID + CAT) and destination ID
67 67 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
68 68 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
69 69 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
70 70 unsigned short sequenceCounterHK;
71 71 unsigned short sequenceCounterParameterDump;
72 72 spw_stats spacewire_stats;
73 73 spw_stats spacewire_stats_backup;
74 74
75 75
@@ -1,782 +1,782
1 1 /** This is the RTEMS initialization module.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * This module contains two very different information:
7 7 * - specific instructions to configure the compilation of the RTEMS executive
8 8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 9 *
10 10 */
11 11
12 12 //*************************
13 13 // GPL reminder to be added
14 14 //*************************
15 15
16 16 #include <rtems.h>
17 17
18 18 /* configuration information */
19 19
20 20 #define CONFIGURE_INIT
21 21
22 22 #include <bsp.h> /* for device driver prototypes */
23 23
24 24 /* configuration information */
25 25
26 26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28 28
29 29 #define CONFIGURE_MAXIMUM_TASKS 20
30 30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
39 39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 40 #ifdef PRINT_STACK_REPORT
41 41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 42 #endif
43 43
44 44 #include <rtems/confdefs.h>
45 45
46 46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 47 #ifdef RTEMS_DRVMGR_STARTUP
48 48 #ifdef LEON3
49 49 /* Add Timer and UART Driver */
50 50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 52 #endif
53 53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 55 #endif
56 56 #endif
57 57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 58 #include <drvmgr/drvmgr_confdefs.h>
59 59 #endif
60 60
61 61 #include "fsw_init.h"
62 62 #include "fsw_config.c"
63 63
64 64 rtems_task Init( rtems_task_argument ignored )
65 65 {
66 66 /** This is the RTEMS INIT taks, it the first task launched by the system.
67 67 *
68 68 * @param unused is the starting argument of the RTEMS task
69 69 *
70 70 * The INIT task create and run all other RTEMS tasks.
71 71 *
72 72 */
73 73
74 74 unsigned char *vhdlVersion;
75 75
76 76 reset_lfr();
77 77
78 78 reset_local_time();
79 79
80 80 rtems_cpu_usage_reset();
81 81
82 82 rtems_status_code status;
83 83 rtems_status_code status_spw;
84 84 rtems_isr_entry old_isr_handler;
85 85
86 86 // UART settings
87 87 send_console_outputs_on_apbuart_port();
88 88 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
89 89 enable_apbuart_transmitter();
90 90 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
91 91
92 92 PRINTF("\n\n\n\n\n")
93 93 PRINTF("*************************\n")
94 94 PRINTF("** LFR Flight Software **\n")
95 95 PRINTF1("** %d.", SW_VERSION_N1)
96 96 PRINTF1("%d." , SW_VERSION_N2)
97 97 PRINTF1("%d." , SW_VERSION_N3)
98 98 PRINTF1("%d **\n", SW_VERSION_N4)
99 99
100 100 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
101 101 PRINTF("** VHDL **\n")
102 102 PRINTF1("** %d.", vhdlVersion[1])
103 103 PRINTF1("%d." , vhdlVersion[2])
104 104 PRINTF1("%d **\n", vhdlVersion[3])
105 105 PRINTF("*************************\n")
106 106 PRINTF("\n\n")
107 107
108 108 init_parameter_dump();
109 109 init_local_mode_parameters();
110 110 init_housekeeping_parameters();
111 111
112 112 // waveform picker initialization
113 113 WFP_init_rings(); // initialize the waveform rings
114 114 WFP_reset_current_ring_nodes();
115 115 reset_waveform_picker_regs();
116 116
117 117 // spectral matrices initialization
118 118 SM_init_rings(); // initialize spectral matrices rings
119 119 SM_reset_current_ring_nodes();
120 120 reset_spectral_matrix_regs();
121 121
122 122 updateLFRCurrentMode();
123 123
124 124 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
125 125
126 126 create_names(); // create all names
127 127
128 128 status = create_message_queues(); // create message queues
129 129 if (status != RTEMS_SUCCESSFUL)
130 130 {
131 131 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
132 132 }
133 133
134 134 status = create_all_tasks(); // create all tasks
135 135 if (status != RTEMS_SUCCESSFUL)
136 136 {
137 137 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
138 138 }
139 139
140 140 // **************************
141 141 // <SPACEWIRE INITIALIZATION>
142 142 grspw_timecode_callback = &timecode_irq_handler;
143 143
144 144 status_spw = spacewire_open_link(); // (1) open the link
145 145 if ( status_spw != RTEMS_SUCCESSFUL )
146 146 {
147 147 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
148 148 }
149 149
150 150 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
151 151 {
152 152 status_spw = spacewire_configure_link( fdSPW );
153 153 if ( status_spw != RTEMS_SUCCESSFUL )
154 154 {
155 155 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
156 156 }
157 157 }
158 158
159 159 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
160 160 {
161 161 status_spw = spacewire_start_link( fdSPW );
162 162 if ( status_spw != RTEMS_SUCCESSFUL )
163 163 {
164 164 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
165 165 }
166 166 }
167 167 // </SPACEWIRE INITIALIZATION>
168 168 // ***************************
169 169
170 170 status = start_all_tasks(); // start all tasks
171 171 if (status != RTEMS_SUCCESSFUL)
172 172 {
173 173 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
174 174 }
175 175
176 176 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
177 177 status = start_recv_send_tasks();
178 178 if ( status != RTEMS_SUCCESSFUL )
179 179 {
180 180 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
181 181 }
182 182
183 183 // suspend science tasks, they will be restarted later depending on the mode
184 184 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
185 185 if (status != RTEMS_SUCCESSFUL)
186 186 {
187 187 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
188 188 }
189 189
190 190 //******************************
191 191 // <SPECTRAL MATRICES SIMULATOR>
192 192 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
193 193 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
194 194 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
195 195 // </SPECTRAL MATRICES SIMULATOR>
196 196 //*******************************
197 197
198 198 // configure IRQ handling for the waveform picker unit
199 199 status = rtems_interrupt_catch( waveforms_isr,
200 200 IRQ_SPARC_WAVEFORM_PICKER,
201 201 &old_isr_handler) ;
202 202 // configure IRQ handling for the spectral matrices unit
203 203 status = rtems_interrupt_catch( spectral_matrices_isr,
204 204 IRQ_SPARC_SPECTRAL_MATRIX,
205 205 &old_isr_handler) ;
206 206
207 207 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
208 208 if ( status_spw != RTEMS_SUCCESSFUL )
209 209 {
210 210 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
211 211 if ( status != RTEMS_SUCCESSFUL ) {
212 212 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
213 213 }
214 214 }
215 215
216 216 BOOT_PRINTF("delete INIT\n")
217 217
218 218 status = rtems_task_delete(RTEMS_SELF);
219 219
220 220 }
221 221
222 222 void init_local_mode_parameters( void )
223 223 {
224 224 /** This function initialize the param_local global variable with default values.
225 225 *
226 226 */
227 227
228 228 unsigned int i;
229 229
230 230 // LOCAL PARAMETERS
231 231
232 232 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
233 233 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
234 234 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
235 235
236 236 // init sequence counters
237 237
238 238 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
239 239 {
240 240 sequenceCounters_TC_EXE[i] = 0x00;
241 241 }
242 242 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
243 243 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
244 244 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
245 245 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
246 246 }
247 247
248 248 void reset_local_time( void )
249 249 {
250 250 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
251 251 }
252 252
253 253 void create_names( void ) // create all names for tasks and queues
254 254 {
255 255 /** This function creates all RTEMS names used in the software for tasks and queues.
256 256 *
257 257 * @return RTEMS directive status codes:
258 258 * - RTEMS_SUCCESSFUL - successful completion
259 259 *
260 260 */
261 261
262 262 // task names
263 263 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
264 264 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
265 265 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
266 266 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
267 267 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
268 268 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
269 269 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
270 270 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
271 271 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
272 272 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
273 273 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
274 274 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
275 275 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
276 276 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
277 277 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
278 278 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
279 279 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
280 280 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
281 281 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
282 282
283 283 // rate monotonic period names
284 284 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
285 285
286 286 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
287 287 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
288 288 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
289 289 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
290 290 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
291 291 }
292 292
293 293 int create_all_tasks( void ) // create all tasks which run in the software
294 294 {
295 295 /** This function creates all RTEMS tasks used in the software.
296 296 *
297 297 * @return RTEMS directive status codes:
298 298 * - RTEMS_SUCCESSFUL - task created successfully
299 299 * - RTEMS_INVALID_ADDRESS - id is NULL
300 300 * - RTEMS_INVALID_NAME - invalid task name
301 301 * - RTEMS_INVALID_PRIORITY - invalid task priority
302 302 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
303 303 * - RTEMS_TOO_MANY - too many tasks created
304 304 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
305 305 * - RTEMS_TOO_MANY - too many global objects
306 306 *
307 307 */
308 308
309 309 rtems_status_code status;
310 310
311 311 //**********
312 312 // SPACEWIRE
313 313 // RECV
314 314 status = rtems_task_create(
315 315 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
316 316 RTEMS_DEFAULT_MODES,
317 317 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
318 318 );
319 319 if (status == RTEMS_SUCCESSFUL) // SEND
320 320 {
321 321 status = rtems_task_create(
322 322 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
323 323 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
324 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
324 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
325 325 );
326 326 }
327 327 if (status == RTEMS_SUCCESSFUL) // WTDG
328 328 {
329 329 status = rtems_task_create(
330 330 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
331 331 RTEMS_DEFAULT_MODES,
332 332 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
333 333 );
334 334 }
335 335 if (status == RTEMS_SUCCESSFUL) // ACTN
336 336 {
337 337 status = rtems_task_create(
338 338 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
339 339 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
340 340 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
341 341 );
342 342 }
343 343 if (status == RTEMS_SUCCESSFUL) // SPIQ
344 344 {
345 345 status = rtems_task_create(
346 346 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
347 347 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
348 348 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
349 349 );
350 350 }
351 351
352 352 //******************
353 353 // SPECTRAL MATRICES
354 354 if (status == RTEMS_SUCCESSFUL) // AVF0
355 355 {
356 356 status = rtems_task_create(
357 357 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
358 358 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
359 359 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
360 360 );
361 361 }
362 362 if (status == RTEMS_SUCCESSFUL) // PRC0
363 363 {
364 364 status = rtems_task_create(
365 365 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
366 366 RTEMS_DEFAULT_MODES,
367 367 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
368 368 );
369 369 }
370 370 if (status == RTEMS_SUCCESSFUL) // AVF1
371 371 {
372 372 status = rtems_task_create(
373 373 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
374 374 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
375 375 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
376 376 );
377 377 }
378 378 if (status == RTEMS_SUCCESSFUL) // PRC1
379 379 {
380 380 status = rtems_task_create(
381 381 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
382 382 RTEMS_DEFAULT_MODES,
383 383 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
384 384 );
385 385 }
386 386 if (status == RTEMS_SUCCESSFUL) // AVF2
387 387 {
388 388 status = rtems_task_create(
389 389 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
390 390 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
391 391 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
392 392 );
393 393 }
394 394 if (status == RTEMS_SUCCESSFUL) // PRC2
395 395 {
396 396 status = rtems_task_create(
397 397 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
398 398 RTEMS_DEFAULT_MODES,
399 399 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
400 400 );
401 401 }
402 402
403 403 //****************
404 404 // WAVEFORM PICKER
405 405 if (status == RTEMS_SUCCESSFUL) // WFRM
406 406 {
407 407 status = rtems_task_create(
408 408 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
409 409 RTEMS_DEFAULT_MODES,
410 410 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
411 411 );
412 412 }
413 413 if (status == RTEMS_SUCCESSFUL) // CWF3
414 414 {
415 415 status = rtems_task_create(
416 416 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
417 417 RTEMS_DEFAULT_MODES,
418 418 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
419 419 );
420 420 }
421 421 if (status == RTEMS_SUCCESSFUL) // CWF2
422 422 {
423 423 status = rtems_task_create(
424 424 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
425 425 RTEMS_DEFAULT_MODES,
426 426 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
427 427 );
428 428 }
429 429 if (status == RTEMS_SUCCESSFUL) // CWF1
430 430 {
431 431 status = rtems_task_create(
432 432 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
433 433 RTEMS_DEFAULT_MODES,
434 434 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
435 435 );
436 436 }
437 437 if (status == RTEMS_SUCCESSFUL) // SWBD
438 438 {
439 439 status = rtems_task_create(
440 440 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
441 441 RTEMS_DEFAULT_MODES,
442 442 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
443 443 );
444 444 }
445 445
446 446 //*****
447 447 // MISC
448 448 if (status == RTEMS_SUCCESSFUL) // STAT
449 449 {
450 450 status = rtems_task_create(
451 451 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
452 452 RTEMS_DEFAULT_MODES,
453 453 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
454 454 );
455 455 }
456 456 if (status == RTEMS_SUCCESSFUL) // DUMB
457 457 {
458 458 status = rtems_task_create(
459 459 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
460 460 RTEMS_DEFAULT_MODES,
461 461 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
462 462 );
463 463 }
464 464 if (status == RTEMS_SUCCESSFUL) // HOUS
465 465 {
466 466 status = rtems_task_create(
467 467 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
468 468 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
469 469 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
470 470 );
471 471 }
472 472
473 473 return status;
474 474 }
475 475
476 476 int start_recv_send_tasks( void )
477 477 {
478 478 rtems_status_code status;
479 479
480 480 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
481 481 if (status!=RTEMS_SUCCESSFUL) {
482 482 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
483 483 }
484 484
485 485 if (status == RTEMS_SUCCESSFUL) // SEND
486 486 {
487 487 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
488 488 if (status!=RTEMS_SUCCESSFUL) {
489 489 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
490 490 }
491 491 }
492 492
493 493 return status;
494 494 }
495 495
496 496 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
497 497 {
498 498 /** This function starts all RTEMS tasks used in the software.
499 499 *
500 500 * @return RTEMS directive status codes:
501 501 * - RTEMS_SUCCESSFUL - ask started successfully
502 502 * - RTEMS_INVALID_ADDRESS - invalid task entry point
503 503 * - RTEMS_INVALID_ID - invalid task id
504 504 * - RTEMS_INCORRECT_STATE - task not in the dormant state
505 505 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
506 506 *
507 507 */
508 508 // starts all the tasks fot eh flight software
509 509
510 510 rtems_status_code status;
511 511
512 512 //**********
513 513 // SPACEWIRE
514 514 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
515 515 if (status!=RTEMS_SUCCESSFUL) {
516 516 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
517 517 }
518 518
519 519 if (status == RTEMS_SUCCESSFUL) // WTDG
520 520 {
521 521 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
522 522 if (status!=RTEMS_SUCCESSFUL) {
523 523 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
524 524 }
525 525 }
526 526
527 527 if (status == RTEMS_SUCCESSFUL) // ACTN
528 528 {
529 529 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
530 530 if (status!=RTEMS_SUCCESSFUL) {
531 531 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
532 532 }
533 533 }
534 534
535 535 //******************
536 536 // SPECTRAL MATRICES
537 537 if (status == RTEMS_SUCCESSFUL) // AVF0
538 538 {
539 539 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
540 540 if (status!=RTEMS_SUCCESSFUL) {
541 541 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
542 542 }
543 543 }
544 544 if (status == RTEMS_SUCCESSFUL) // PRC0
545 545 {
546 546 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
547 547 if (status!=RTEMS_SUCCESSFUL) {
548 548 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
549 549 }
550 550 }
551 551 if (status == RTEMS_SUCCESSFUL) // AVF1
552 552 {
553 553 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
554 554 if (status!=RTEMS_SUCCESSFUL) {
555 555 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
556 556 }
557 557 }
558 558 if (status == RTEMS_SUCCESSFUL) // PRC1
559 559 {
560 560 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
561 561 if (status!=RTEMS_SUCCESSFUL) {
562 562 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
563 563 }
564 564 }
565 565 if (status == RTEMS_SUCCESSFUL) // AVF2
566 566 {
567 567 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
568 568 if (status!=RTEMS_SUCCESSFUL) {
569 569 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
570 570 }
571 571 }
572 572 if (status == RTEMS_SUCCESSFUL) // PRC2
573 573 {
574 574 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
575 575 if (status!=RTEMS_SUCCESSFUL) {
576 576 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
577 577 }
578 578 }
579 579
580 580 //****************
581 581 // WAVEFORM PICKER
582 582 if (status == RTEMS_SUCCESSFUL) // WFRM
583 583 {
584 584 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
585 585 if (status!=RTEMS_SUCCESSFUL) {
586 586 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
587 587 }
588 588 }
589 589 if (status == RTEMS_SUCCESSFUL) // CWF3
590 590 {
591 591 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
592 592 if (status!=RTEMS_SUCCESSFUL) {
593 593 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
594 594 }
595 595 }
596 596 if (status == RTEMS_SUCCESSFUL) // CWF2
597 597 {
598 598 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
599 599 if (status!=RTEMS_SUCCESSFUL) {
600 600 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
601 601 }
602 602 }
603 603 if (status == RTEMS_SUCCESSFUL) // CWF1
604 604 {
605 605 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
606 606 if (status!=RTEMS_SUCCESSFUL) {
607 607 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
608 608 }
609 609 }
610 610 if (status == RTEMS_SUCCESSFUL) // SWBD
611 611 {
612 612 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
613 613 if (status!=RTEMS_SUCCESSFUL) {
614 614 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
615 615 }
616 616 }
617 617
618 618 //*****
619 619 // MISC
620 620 if (status == RTEMS_SUCCESSFUL) // HOUS
621 621 {
622 622 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
623 623 if (status!=RTEMS_SUCCESSFUL) {
624 624 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
625 625 }
626 626 }
627 627 if (status == RTEMS_SUCCESSFUL) // DUMB
628 628 {
629 629 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
630 630 if (status!=RTEMS_SUCCESSFUL) {
631 631 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
632 632 }
633 633 }
634 634 if (status == RTEMS_SUCCESSFUL) // STAT
635 635 {
636 636 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
637 637 if (status!=RTEMS_SUCCESSFUL) {
638 638 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
639 639 }
640 640 }
641 641
642 642 return status;
643 643 }
644 644
645 645 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
646 646 {
647 647 rtems_status_code status_recv;
648 648 rtems_status_code status_send;
649 649 rtems_status_code status_q_p0;
650 650 rtems_status_code status_q_p1;
651 651 rtems_status_code status_q_p2;
652 652 rtems_status_code ret;
653 653 rtems_id queue_id;
654 654
655 655 //****************************************
656 656 // create the queue for handling valid TCs
657 657 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
658 658 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
659 659 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
660 660 if ( status_recv != RTEMS_SUCCESSFUL ) {
661 661 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
662 662 }
663 663
664 664 //************************************************
665 665 // create the queue for handling TM packet sending
666 666 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
667 667 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
668 668 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
669 669 if ( status_send != RTEMS_SUCCESSFUL ) {
670 670 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
671 671 }
672 672
673 673 //*****************************************************************************
674 674 // create the queue for handling averaged spectral matrices for processing @ f0
675 675 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
676 676 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
677 677 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
678 678 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
679 679 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
680 680 }
681 681
682 682 //*****************************************************************************
683 683 // create the queue for handling averaged spectral matrices for processing @ f1
684 684 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
685 685 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
686 686 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
687 687 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
688 688 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
689 689 }
690 690
691 691 //*****************************************************************************
692 692 // create the queue for handling averaged spectral matrices for processing @ f2
693 693 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
694 694 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
695 695 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
696 696 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
697 697 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
698 698 }
699 699
700 700 if ( status_recv != RTEMS_SUCCESSFUL )
701 701 {
702 702 ret = status_recv;
703 703 }
704 704 else if( status_send != RTEMS_SUCCESSFUL )
705 705 {
706 706 ret = status_send;
707 707 }
708 708 else if( status_q_p0 != RTEMS_SUCCESSFUL )
709 709 {
710 710 ret = status_q_p0;
711 711 }
712 712 else if( status_q_p1 != RTEMS_SUCCESSFUL )
713 713 {
714 714 ret = status_q_p1;
715 715 }
716 716 else
717 717 {
718 718 ret = status_q_p2;
719 719 }
720 720
721 721 return ret;
722 722 }
723 723
724 724 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
725 725 {
726 726 rtems_status_code status;
727 727 rtems_name queue_name;
728 728
729 729 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
730 730
731 731 status = rtems_message_queue_ident( queue_name, 0, queue_id );
732 732
733 733 return status;
734 734 }
735 735
736 736 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
737 737 {
738 738 rtems_status_code status;
739 739 rtems_name queue_name;
740 740
741 741 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
742 742
743 743 status = rtems_message_queue_ident( queue_name, 0, queue_id );
744 744
745 745 return status;
746 746 }
747 747
748 748 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
749 749 {
750 750 rtems_status_code status;
751 751 rtems_name queue_name;
752 752
753 753 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
754 754
755 755 status = rtems_message_queue_ident( queue_name, 0, queue_id );
756 756
757 757 return status;
758 758 }
759 759
760 760 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
761 761 {
762 762 rtems_status_code status;
763 763 rtems_name queue_name;
764 764
765 765 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
766 766
767 767 status = rtems_message_queue_ident( queue_name, 0, queue_id );
768 768
769 769 return status;
770 770 }
771 771
772 772 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
773 773 {
774 774 rtems_status_code status;
775 775 rtems_name queue_name;
776 776
777 777 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
778 778
779 779 status = rtems_message_queue_ident( queue_name, 0, queue_id );
780 780
781 781 return status;
782 782 }
@@ -1,635 +1,574
1 1 /** General usage functions and RTEMS tasks.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 */
7 7
8 8 #include "fsw_misc.h"
9 9
10 10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 12 {
13 13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 14 *
15 15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 18 * @param interrupt_level is the interrupt level that the timer drives.
19 19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 20 *
21 21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 22 *
23 23 */
24 24
25 25 rtems_status_code status;
26 26 rtems_isr_entry old_isr_handler;
27 27
28 28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29 29
30 30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 31 if (status!=RTEMS_SUCCESSFUL)
32 32 {
33 33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 34 }
35 35
36 36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 37 }
38 38
39 39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 40 {
41 41 /** This function starts a GPTIMER timer.
42 42 *
43 43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 45 *
46 46 */
47 47
48 48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 53 }
54 54
55 55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 56 {
57 57 /** This function stops a GPTIMER timer.
58 58 *
59 59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 61 *
62 62 */
63 63
64 64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 67 }
68 68
69 69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 70 {
71 71 /** This function sets the clock divider of a GPTIMER timer.
72 72 *
73 73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 76 *
77 77 */
78 78
79 79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 80 }
81 81
82 82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 83 {
84 84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85 85
86 86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87 87
88 88 return 0;
89 89 }
90 90
91 91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 92 {
93 93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94 94
95 95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96 96
97 97 return 0;
98 98 }
99 99
100 100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 101 {
102 102 /** This function sets the scaler reload register of the apbuart module
103 103 *
104 104 * @param regs is the address of the apbuart registers in memory
105 105 * @param value is the value that will be stored in the scaler register
106 106 *
107 107 * The value shall be set by the software to get data on the serial interface.
108 108 *
109 109 */
110 110
111 111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112 112
113 113 apbuart_regs->scaler = value;
114 114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 115 }
116 116
117 117 //************
118 118 // RTEMS TASKS
119 119
120 120 rtems_task stat_task(rtems_task_argument argument)
121 121 {
122 122 int i;
123 123 int j;
124 124 i = 0;
125 125 j = 0;
126 126 BOOT_PRINTF("in STAT *** \n")
127 127 while(1){
128 128 rtems_task_wake_after(1000);
129 129 PRINTF1("%d\n", j)
130 130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 131 // #ifdef PRINT_TASK_STATISTICS
132 132 // rtems_cpu_usage_report();
133 133 // rtems_cpu_usage_reset();
134 134 // #endif
135 135 i = 0;
136 136 }
137 137 else i++;
138 138 j++;
139 139 }
140 140 }
141 141
142 142 rtems_task hous_task(rtems_task_argument argument)
143 143 {
144 144 rtems_status_code status;
145 145 rtems_status_code spare_status;
146 146 rtems_id queue_id;
147 147 rtems_rate_monotonic_period_status period_status;
148 148
149 149 status = get_message_queue_id_send( &queue_id );
150 150 if (status != RTEMS_SUCCESSFUL)
151 151 {
152 152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 153 }
154 154
155 155 BOOT_PRINTF("in HOUS ***\n")
156 156
157 157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 159 if( status != RTEMS_SUCCESSFUL ) {
160 160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 161 }
162 162 }
163 163
164 164 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
165 165 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
166 166 housekeeping_packet.reserved = DEFAULT_RESERVED;
167 167 housekeeping_packet.userApplication = CCSDS_USER_APP;
168 168 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
169 169 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
170 170 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
171 171 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
172 172 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
173 173 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
174 174 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
175 175 housekeeping_packet.serviceType = TM_TYPE_HK;
176 176 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
177 177 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
178 178 housekeeping_packet.sid = SID_HK;
179 179
180 180 status = rtems_rate_monotonic_cancel(HK_id);
181 181 if( status != RTEMS_SUCCESSFUL ) {
182 182 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
183 183 }
184 184 else {
185 185 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
186 186 }
187 187
188 188 // startup phase
189 189 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
190 190 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
191 191 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
192 192 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
193 193 {
194 194 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
195 195 {
196 196 break; // break if LFR is synchronized
197 197 }
198 198 else
199 199 {
200 200 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
201 201 // sched_yield();
202 202 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
203 203 }
204 204 }
205 205 status = rtems_rate_monotonic_cancel(HK_id);
206 206 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
207 207
208 208 while(1){ // launch the rate monotonic task
209 209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
210 210 if ( status != RTEMS_SUCCESSFUL ) {
211 211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
212 212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
213 213 }
214 214 else {
215 215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
216 216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
217 217 increment_seq_counter( &sequenceCounterHK );
218 218
219 219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
220 220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
221 221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
222 222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
223 223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
224 224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
225 225
226 226 spacewire_update_statistics();
227 227
228 // get_v_e1_e2_f3_alt( housekeeping_packet.hk_lfr_sc_v_f3 );
228 // get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
229 229 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
230 230
231 231 // SEND PACKET
232 status = rtems_message_queue_urgent( queue_id, &housekeeping_packet,
232 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
233 233 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
234 234 if (status != RTEMS_SUCCESSFUL) {
235 235 PRINTF1("in HOUS *** ERR send: %d\n", status)
236 236 }
237 237 }
238 238 }
239 239
240 240 PRINTF("in HOUS *** deleting task\n")
241 241
242 242 status = rtems_task_delete( RTEMS_SELF ); // should not return
243 243 printf( "rtems_task_delete returned with status of %d.\n", status );
244 244 return;
245 245 }
246 246
247 247 rtems_task dumb_task( rtems_task_argument unused )
248 248 {
249 249 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
250 250 *
251 251 * @param unused is the starting argument of the RTEMS task
252 252 *
253 253 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
254 254 *
255 255 */
256 256
257 257 unsigned int i;
258 258 unsigned int intEventOut;
259 259 unsigned int coarse_time = 0;
260 260 unsigned int fine_time = 0;
261 261 rtems_event_set event_out;
262 262
263 263 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
264 264 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
265 265 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
266 266 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
267 267 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
268 268 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
269 269 "ERR HK", // RTEMS_EVENT_6
270 270 "ready for dump", // RTEMS_EVENT_7
271 271 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
272 272 "tick", // RTEMS_EVENT_9
273 273 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
274 274 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
275 275 };
276 276
277 277 BOOT_PRINTF("in DUMB *** \n")
278 278
279 279 while(1){
280 280 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
281 281 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
282 282 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
283 283 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
284 284 intEventOut = (unsigned int) event_out;
285 285 for ( i=0; i<32; i++)
286 286 {
287 287 if ( ((intEventOut >> i) & 0x0001) != 0)
288 288 {
289 289 coarse_time = time_management_regs->coarse_time;
290 290 fine_time = time_management_regs->fine_time;
291 291 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
292 292 if (i==8)
293 293 {
294 294 }
295 295 if (i==10)
296 296 {
297 297 }
298 298 }
299 299 }
300 300 }
301 301 }
302 302
303 303 //*****************************
304 304 // init housekeeping parameters
305 305
306 306 void init_housekeeping_parameters( void )
307 307 {
308 308 /** This function initialize the housekeeping_packet global variable with default values.
309 309 *
310 310 */
311 311
312 312 unsigned int i = 0;
313 313 unsigned char *parameters;
314 314
315 315 parameters = (unsigned char*) &housekeeping_packet.lfr_status_word;
316 316 for(i = 0; i< SIZE_HK_PARAMETERS; i++)
317 317 {
318 318 parameters[i] = 0x00;
319 319 }
320 320 // init status word
321 321 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
322 322 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
323 323 // init software version
324 324 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
325 325 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
326 326 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
327 327 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
328 328 // init fpga version
329 329 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
330 330 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
331 331 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
332 332 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
333 333 }
334 334
335 335 void increment_seq_counter( unsigned short *packetSequenceControl )
336 336 {
337 337 /** This function increment the sequence counter psased in argument.
338 338 *
339 339 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
340 340 *
341 341 */
342 342
343 343 unsigned short segmentation_grouping_flag;
344 344 unsigned short sequence_cnt;
345 345
346 346 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
347 347 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
348 348
349 349 if ( sequence_cnt < SEQ_CNT_MAX)
350 350 {
351 351 sequence_cnt = sequence_cnt + 1;
352 352 }
353 353 else
354 354 {
355 355 sequence_cnt = 0;
356 356 }
357 357
358 358 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
359 359 }
360 360
361 361 void getTime( unsigned char *time)
362 362 {
363 363 /** This function write the current local time in the time buffer passed in argument.
364 364 *
365 365 */
366 366
367 367 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
368 368 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
369 369 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
370 370 time[3] = (unsigned char) (time_management_regs->coarse_time);
371 371 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
372 372 time[5] = (unsigned char) (time_management_regs->fine_time);
373 373 }
374 374
375 375 unsigned long long int getTimeAsUnsignedLongLongInt( )
376 376 {
377 377 /** This function write the current local time in the time buffer passed in argument.
378 378 *
379 379 */
380 380 unsigned long long int time;
381 381
382 382 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
383 383 + time_management_regs->fine_time;
384 384
385 385 return time;
386 386 }
387 387
388 388 void send_dumb_hk( void )
389 389 {
390 390 Packet_TM_LFR_HK_t dummy_hk_packet;
391 391 unsigned char *parameters;
392 392 unsigned int i;
393 393 rtems_id queue_id;
394 394
395 395 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
396 396 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
397 397 dummy_hk_packet.reserved = DEFAULT_RESERVED;
398 398 dummy_hk_packet.userApplication = CCSDS_USER_APP;
399 399 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
400 400 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
401 401 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
402 402 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
403 403 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
404 404 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
405 405 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
406 406 dummy_hk_packet.serviceType = TM_TYPE_HK;
407 407 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
408 408 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
409 409 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
410 410 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
411 411 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
412 412 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
413 413 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
414 414 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
415 415 dummy_hk_packet.sid = SID_HK;
416 416
417 417 // init status word
418 418 dummy_hk_packet.lfr_status_word[0] = 0xff;
419 419 dummy_hk_packet.lfr_status_word[1] = 0xff;
420 420 // init software version
421 421 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
422 422 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
423 423 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
424 424 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
425 425 // init fpga version
426 426 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
427 427 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
428 428 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
429 429 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
430 430
431 431 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
432 432
433 433 for (i=0; i<100; i++)
434 434 {
435 435 parameters[i] = 0xff;
436 436 }
437 437
438 438 get_message_queue_id_send( &queue_id );
439 439
440 rtems_message_queue_urgent( queue_id, &dummy_hk_packet,
440 rtems_message_queue_send( queue_id, &dummy_hk_packet,
441 441 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
442 442 }
443 443
444 444 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
445 445 {
446 unsigned int coarseTime;
447 unsigned int acquisitionTime;
448 unsigned int deltaT = 0;
449 unsigned char *bufferPtr;
450
451 unsigned int offset_in_samples;
452 unsigned int offset_in_bytes;
453 unsigned char f3 = 16; // v, e1 and e2 will be picked up each second, f3 = 16 Hz
454
455 bufferPtr = NULL;
456
457 if (lfrCurrentMode == LFR_MODE_STANDBY)
458 {
459 spacecraft_potential[0] = 0x00;
460 spacecraft_potential[1] = 0x00;
461 spacecraft_potential[2] = 0x00;
462 spacecraft_potential[3] = 0x00;
463 spacecraft_potential[4] = 0x00;
464 spacecraft_potential[5] = 0x00;
465 }
466 else
467 {
468 coarseTime = time_management_regs->coarse_time & 0x7fffffff;
469 bufferPtr = (unsigned char*) current_ring_node_f3->buffer_address;
470 acquisitionTime = (unsigned int) ( ( bufferPtr[0] & 0x7f ) << 24 )
471 + (unsigned int) ( bufferPtr[1] << 16 )
472 + (unsigned int) ( bufferPtr[2] << 8 )
473 + (unsigned int) ( bufferPtr[3] );
474 if ( coarseTime > acquisitionTime )
475 {
476 deltaT = coarseTime - acquisitionTime;
477 offset_in_samples = (deltaT-1) * f3 ;
478 }
479 else if( coarseTime == acquisitionTime )
480 {
481 bufferPtr = (unsigned char*) current_ring_node_f3->previous->buffer_address; // pick up v e1 and e2 in the previous f3 buffer
482 offset_in_samples = NB_SAMPLES_PER_SNAPSHOT-1;
483 }
484 else
485 {
486 offset_in_samples = 0;
487 // PRINTF2("ERR *** in get_v_e1_e2_f3 *** coarseTime = %x, acquisitionTime = %x\n", coarseTime, acquisitionTime)
488 }
489
490 if ( offset_in_samples > (NB_SAMPLES_PER_SNAPSHOT - 1) )
491 {
492 // PRINTF1("ERR *** in get_v_e1_e2_f3 *** trying to read out of the buffer, counter = %d\n", offset_in_samples)
493 offset_in_samples = NB_SAMPLES_PER_SNAPSHOT -1;
494 }
495 offset_in_bytes = TIME_OFFSET_IN_BYTES + offset_in_samples * NB_WORDS_SWF_BLK * 4;
496 spacecraft_potential[0] = bufferPtr[ offset_in_bytes + 0];
497 spacecraft_potential[1] = bufferPtr[ offset_in_bytes + 1];
498 spacecraft_potential[2] = bufferPtr[ offset_in_bytes + 2];
499 spacecraft_potential[3] = bufferPtr[ offset_in_bytes + 3];
500 spacecraft_potential[4] = bufferPtr[ offset_in_bytes + 4];
501 spacecraft_potential[5] = bufferPtr[ offset_in_bytes + 5];
502 }
503 }
504
505 void get_v_e1_e2_f3_alt( unsigned char *spacecraft_potential )
506 {
507 446 unsigned long long int localTime_asLong;
508 447 unsigned long long int f3_0_AcquisitionTime_asLong;
509 448 unsigned long long int f3_1_AcquisitionTime_asLong;
510 449 unsigned long long int deltaT;
511 450 unsigned long long int deltaT_f3_0;
512 451 unsigned long long int deltaT_f3_1;
513 452 unsigned char *bufferPtr;
514 453
515 454 unsigned int offset_in_samples;
516 455 unsigned int offset_in_bytes;
517 456 unsigned char f3;
518 457
519 458 bufferPtr = NULL;
520 459 deltaT = 0;
521 460 deltaT_f3_0 = 0xffffffff;
522 461 deltaT_f3_1 = 0xffffffff;
523 462 f3 = 16; // v, e1 and e2 will be picked up each second, f3 = 16 Hz
524 463
525 464 if (lfrCurrentMode == LFR_MODE_STANDBY)
526 465 {
527 466 spacecraft_potential[0] = 0x00;
528 467 spacecraft_potential[1] = 0x00;
529 468 spacecraft_potential[2] = 0x00;
530 469 spacecraft_potential[3] = 0x00;
531 470 spacecraft_potential[4] = 0x00;
532 471 spacecraft_potential[5] = 0x00;
533 472 }
534 473 else
535 474 {
536 475 localTime_asLong = get_acquisition_time( (unsigned char *) &time_management_regs->coarse_time );
537 476 f3_0_AcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &waveform_picker_regs->f3_0_coarse_time );
538 477 f3_1_AcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &waveform_picker_regs->f3_1_coarse_time );
539 478 printf("localTime 0x%llx, f3_0 0x%llx, f3_1 0x%llx\n",
540 479 localTime_asLong,
541 480 f3_0_AcquisitionTime_asLong,
542 481 f3_1_AcquisitionTime_asLong);
543 482
544 483 if ( localTime_asLong >= f3_0_AcquisitionTime_asLong )
545 484 {
546 485 deltaT_f3_0 = localTime_asLong - f3_0_AcquisitionTime_asLong;
547 486 }
548 487
549 488 if ( localTime_asLong > f3_1_AcquisitionTime_asLong )
550 489 {
551 490 deltaT_f3_1 = localTime_asLong - f3_1_AcquisitionTime_asLong;
552 491 }
553 492
554 493 if ( (deltaT_f3_0 != 0xffffffff) && (deltaT_f3_1 != 0xffffffff) )
555 494 {
556 495 if ( deltaT_f3_0 > deltaT_f3_1 )
557 496 {
558 497 deltaT = deltaT_f3_1;
559 498 bufferPtr = (unsigned char*) waveform_picker_regs->addr_data_f3_1;
560 499 }
561 500 else
562 501 {
563 502 deltaT = deltaT_f3_0;
564 503 bufferPtr = (unsigned char*) waveform_picker_regs->addr_data_f3_0;
565 504 }
566 505 }
567 506 else if ( (deltaT_f3_0 == 0xffffffff) && (deltaT_f3_1 != 0xffffffff) )
568 507 {
569 508 deltaT = deltaT_f3_1;
570 509 bufferPtr = (unsigned char*) waveform_picker_regs->addr_data_f3_1;
571 510 }
572 511 else if ( (deltaT_f3_0 != 0xffffffff) && (deltaT_f3_1 == 0xffffffff) )
573 512 {
574 513 deltaT = deltaT_f3_0;
575 514 bufferPtr = (unsigned char*) waveform_picker_regs->addr_data_f3_1;
576 515 }
577 516 else
578 517 {
579 518 deltaT = 0xffffffff;
580 519 }
581 520
582 521 if ( deltaT == 0xffffffff )
583 522 {
584 523 spacecraft_potential[0] = 0x00;
585 524 spacecraft_potential[1] = 0x00;
586 525 spacecraft_potential[2] = 0x00;
587 526 spacecraft_potential[3] = 0x00;
588 527 spacecraft_potential[4] = 0x00;
589 528 spacecraft_potential[5] = 0x00;
590 529 }
591 530 else
592 531 {
593 532 offset_in_samples = ( (double) deltaT ) / 65536. * f3;
594 533 if ( offset_in_samples > (NB_SAMPLES_PER_SNAPSHOT - 1) )
595 534 {
596 535 PRINTF1("ERR *** in get_v_e1_e2_f3 *** trying to read out of the buffer, counter = %d\n", offset_in_samples)
597 536 offset_in_samples = NB_SAMPLES_PER_SNAPSHOT - 1;
598 537 }
599 538 offset_in_bytes = offset_in_samples * NB_WORDS_SWF_BLK * 4;
600 539 spacecraft_potential[0] = bufferPtr[ offset_in_bytes + 0];
601 540 spacecraft_potential[1] = bufferPtr[ offset_in_bytes + 1];
602 541 spacecraft_potential[2] = bufferPtr[ offset_in_bytes + 2];
603 542 spacecraft_potential[3] = bufferPtr[ offset_in_bytes + 3];
604 543 spacecraft_potential[4] = bufferPtr[ offset_in_bytes + 4];
605 544 spacecraft_potential[5] = bufferPtr[ offset_in_bytes + 5];
606 545 }
607 546 }
608 547 }
609 548
610 549 void get_cpu_load( unsigned char *resource_statistics )
611 550 {
612 551 unsigned char cpu_load;
613 552
614 553 cpu_load = lfr_rtems_cpu_usage_report();
615 554
616 555 // HK_LFR_CPU_LOAD
617 556 resource_statistics[0] = cpu_load;
618 557
619 558 // HK_LFR_CPU_LOAD_MAX
620 559 if (cpu_load > resource_statistics[1])
621 560 {
622 561 resource_statistics[1] = cpu_load;
623 562 }
624 563
625 564 // CPU_LOAD_AVE
626 565 resource_statistics[2] = 0;
627 566
628 567 #ifndef PRINT_TASK_STATISTICS
629 568 rtems_cpu_usage_reset();
630 569 #endif
631 570
632 571 }
633 572
634 573
635 574
@@ -1,624 +1,1103
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 rtems_name semq_name;
17 17 rtems_id semq_id;
18 18
19 //*****************
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
19 25 //***********
20 26 // RTEMS TASK
21 27 rtems_task spiq_task(rtems_task_argument unused)
22 28 {
23 29 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
24 30 *
25 31 * @param unused is the starting argument of the RTEMS task
26 32 *
27 33 */
28 34
29 35 rtems_event_set event_out;
30 36 rtems_status_code status;
31 37 int linkStatus;
32 38
33 39 BOOT_PRINTF("in SPIQ *** \n")
34 40
35 41 while(true){
36 42 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
37 43 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
38 44
39 45 // [0] SUSPEND RECV AND SEND TASKS
40 46 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
41 47 if ( status != RTEMS_SUCCESSFUL ) {
42 48 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
43 49 }
44 50 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
45 51 if ( status != RTEMS_SUCCESSFUL ) {
46 52 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
47 53 }
48 54
49 55 // [1] CHECK THE LINK
50 56 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
51 57 if ( linkStatus != 5) {
52 58 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
53 59 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
54 60 }
55 61
56 62 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
57 63 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
58 64 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
59 65 {
60 66 spacewire_compute_stats_offsets();
61 67 status = spacewire_reset_link( );
62 68 }
63 69 else // [2.b] in run state, start the link
64 70 {
65 71 status = spacewire_stop_and_start_link( fdSPW ); // start the link
66 72 if ( status != RTEMS_SUCCESSFUL)
67 73 {
68 74 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
69 75 }
70 76 }
71 77
72 78 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
73 79 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
74 80 {
75 81 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
76 82 if ( status != RTEMS_SUCCESSFUL ) {
77 83 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
78 84 }
79 85 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
80 86 if ( status != RTEMS_SUCCESSFUL ) {
81 87 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
82 88 }
83 89 }
84 90 else // [3.b] the link is not in run state, go in STANDBY mode
85 91 {
86 92 status = stop_current_mode();
87 93 if ( status != RTEMS_SUCCESSFUL ) {
88 94 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
89 95 }
90 96 status = enter_mode( LFR_MODE_STANDBY, 0 );
91 97 if ( status != RTEMS_SUCCESSFUL ) {
92 98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
93 99 }
94 100 // wake the WTDG task up to wait for the link recovery
95 101 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
96 102 status = rtems_task_suspend( RTEMS_SELF );
97 103 }
98 104 }
99 105 }
100 106
101 107 rtems_task recv_task( rtems_task_argument unused )
102 108 {
103 109 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
104 110 *
105 111 * @param unused is the starting argument of the RTEMS task
106 112 *
107 113 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
108 114 * 1. It reads the incoming data.
109 115 * 2. Launches the acceptance procedure.
110 116 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
111 117 *
112 118 */
113 119
114 120 int len;
115 121 ccsdsTelecommandPacket_t currentTC;
116 122 unsigned char computed_CRC[ 2 ];
117 123 unsigned char currentTC_LEN_RCV[ 2 ];
118 124 unsigned char destinationID;
119 125 unsigned int estimatedPacketLength;
120 126 unsigned int parserCode;
121 127 rtems_status_code status;
122 128 rtems_id queue_recv_id;
123 129 rtems_id queue_send_id;
124 130
125 131 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
126 132
127 133 status = get_message_queue_id_recv( &queue_recv_id );
128 134 if (status != RTEMS_SUCCESSFUL)
129 135 {
130 136 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
131 137 }
132 138
133 139 status = get_message_queue_id_send( &queue_send_id );
134 140 if (status != RTEMS_SUCCESSFUL)
135 141 {
136 142 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
137 143 }
138 144
139 145 BOOT_PRINTF("in RECV *** \n")
140 146
141 147 while(1)
142 148 {
143 149 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
144 150 if (len == -1){ // error during the read call
145 151 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
146 152 }
147 153 else {
148 154 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
149 155 PRINTF("in RECV *** packet lenght too short\n")
150 156 }
151 157 else {
152 158 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
153 159 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
154 160 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
155 161 // CHECK THE TC
156 162 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
157 163 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
158 164 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
159 165 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
160 166 || (parserCode == WRONG_SRC_ID) )
161 167 { // send TM_LFR_TC_EXE_CORRUPTED
162 168 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
163 169 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
164 170 &&
165 171 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
166 172 )
167 173 {
168 174 if ( parserCode == WRONG_SRC_ID )
169 175 {
170 176 destinationID = SID_TC_GROUND;
171 177 }
172 178 else
173 179 {
174 180 destinationID = currentTC.sourceID;
175 181 }
176 182 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
177 183 computed_CRC, currentTC_LEN_RCV,
178 184 destinationID );
179 185 }
180 186 }
181 187 else
182 188 { // send valid TC to the action launcher
183 189 status = rtems_message_queue_send( queue_recv_id, &currentTC,
184 190 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
185 191 }
186 192 }
187 193 }
188 194 }
189 195 }
190 196
191 197 rtems_task send_task( rtems_task_argument argument)
192 198 {
193 199 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
194 200 *
195 201 * @param unused is the starting argument of the RTEMS task
196 202 *
197 203 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
198 204 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
199 205 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
200 206 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
201 207 * data it contains.
202 208 *
203 209 */
204 210
205 211 rtems_status_code status; // RTEMS status code
206 212 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
213 ring_node *incomingRingNodePtr;
214 int ring_node_address;
215 char *charPtr;
207 216 spw_ioctl_pkt_send *spw_ioctl_send;
208 217 size_t size; // size of the incoming TC packet
209 218 u_int32_t count;
210 219 rtems_id queue_id;
220 unsigned char sid;
221
222 incomingRingNodePtr = NULL;
223 ring_node_address = 0;
224 charPtr = (char *) &ring_node_address;
225 sid = 0;
226
227 init_header_cwf( &headerCWF );
228 init_header_swf( &headerSWF );
229 init_header_asm( &headerASM );
211 230
212 231 status = get_message_queue_id_send( &queue_id );
213 232 if (status != RTEMS_SUCCESSFUL)
214 233 {
215 234 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
216 235 }
217 236
218 237 BOOT_PRINTF("in SEND *** \n")
219 238
220 239 while(1)
221 240 {
222 241 status = rtems_message_queue_receive( queue_id, incomingData, &size,
223 242 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
224 243
225 244 if (status!=RTEMS_SUCCESSFUL)
226 245 {
227 246 PRINTF1("in SEND *** (1) ERR = %d\n", status)
228 247 }
229 248 else
230 249 {
231 if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
250 if ( size == sizeof(ring_node*) )
251 {
252 charPtr[0] = incomingData[0];
253 charPtr[1] = incomingData[1];
254 charPtr[2] = incomingData[2];
255 charPtr[3] = incomingData[3];
256 incomingRingNodePtr = (ring_node*) ring_node_address;
257 sid = incomingRingNodePtr->sid;
258 // printf("sid = %d\n", incomingRingNodePtr->sid);
259 if ( (sid==SID_NORM_CWF_LONG_F3)
260 || (sid==SID_BURST_CWF_F2 )
261 || (sid==SID_SBM1_CWF_F1 )
262 || (sid==SID_SBM2_CWF_F2 ))
263 {
264 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
265 }
266 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
267 {
268 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
269 }
270 else if ( (sid==SID_NORM_CWF_F3) )
271 {
272 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
273 }
274 else if ( (sid==SID_NORM_ASM_F0) || (SID_NORM_ASM_F1) || (SID_NORM_ASM_F2) )
275 {
276 spw_send_asm( incomingRingNodePtr, &headerASM );
277 }
278 else
279 {
280 printf("unexpected sid = %d\n", sid);
281 }
282 }
283 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
232 284 {
233 285 status = write( fdSPW, incomingData, size );
234 286 if (status == -1){
235 287 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
236 288 }
237 289 }
238 290 else // the incoming message is a spw_ioctl_pkt_send structure
239 291 {
240 292 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
241 293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
242 294 if (status == -1){
295 printf("size = %d, %x, %x, %x, %x, %x\n",
296 size,
297 incomingData[0],
298 incomingData[1],
299 incomingData[2],
300 incomingData[3],
301 incomingData[4]);
243 302 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
244 303 }
245 304 }
246 305 }
247 306
248 307 status = rtems_message_queue_get_number_pending( queue_id, &count );
249 308 if (status != RTEMS_SUCCESSFUL)
250 309 {
251 310 PRINTF1("in SEND *** (3) ERR = %d\n", status)
252 311 }
253 312 else
254 313 {
255 314 if (count > maxCount)
256 315 {
257 316 maxCount = count;
258 317 }
259 318 }
260 319 }
261 320 }
262 321
263 322 rtems_task wtdg_task( rtems_task_argument argument )
264 323 {
265 324 rtems_event_set event_out;
266 325 rtems_status_code status;
267 326 int linkStatus;
268 327
269 328 BOOT_PRINTF("in WTDG ***\n")
270 329
271 330 while(1)
272 331 {
273 332 // wait for an RTEMS_EVENT
274 333 rtems_event_receive( RTEMS_EVENT_0,
275 334 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
276 335 PRINTF("in WTDG *** wait for the link\n")
277 336 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
278 337 while( linkStatus != 5) // wait for the link
279 338 {
280 339 rtems_task_wake_after( 10 );
281 340 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
282 341 }
283 342
284 343 status = spacewire_stop_and_start_link( fdSPW );
285 344
286 345 if (status != RTEMS_SUCCESSFUL)
287 346 {
288 347 PRINTF1("in WTDG *** ERR link not started %d\n", status)
289 348 }
290 349 else
291 350 {
292 351 PRINTF("in WTDG *** OK link started\n")
293 352 }
294 353
295 354 // restart the SPIQ task
296 355 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
297 356 if ( status != RTEMS_SUCCESSFUL ) {
298 357 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
299 358 }
300 359
301 360 // restart RECV and SEND
302 361 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
303 362 if ( status != RTEMS_SUCCESSFUL ) {
304 363 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
305 364 }
306 365 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
307 366 if ( status != RTEMS_SUCCESSFUL ) {
308 367 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
309 368 }
310 369 }
311 370 }
312 371
313 372 //****************
314 373 // OTHER FUNCTIONS
315 374 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
316 375 {
317 376 /** This function opens the SpaceWire link.
318 377 *
319 378 * @return a valid file descriptor in case of success, -1 in case of a failure
320 379 *
321 380 */
322 381 rtems_status_code status;
323 382
324 383 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
325 384 if ( fdSPW < 0 ) {
326 385 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
327 386 }
328 387 else
329 388 {
330 389 status = RTEMS_SUCCESSFUL;
331 390 }
332 391
333 392 return status;
334 393 }
335 394
336 395 int spacewire_start_link( int fd )
337 396 {
338 397 rtems_status_code status;
339 398
340 399 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
341 400 // -1 default hardcoded driver timeout
342 401
343 402 return status;
344 403 }
345 404
346 405 int spacewire_stop_and_start_link( int fd )
347 406 {
348 407 rtems_status_code status;
349 408
350 409 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
351 410 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
352 411 // -1 default hardcoded driver timeout
353 412
354 413 return status;
355 414 }
356 415
357 416 int spacewire_configure_link( int fd )
358 417 {
359 418 /** This function configures the SpaceWire link.
360 419 *
361 420 * @return GR-RTEMS-DRIVER directive status codes:
362 421 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
363 422 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
364 423 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
365 424 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
366 425 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
367 426 * - 5 EIO - Error when writing to grswp hardware registers.
368 427 * - 2 ENOENT - No such file or directory
369 428 */
370 429
371 430 rtems_status_code status;
372 431
373 432 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
374 433 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
375 434
376 435 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
377 436 if (status!=RTEMS_SUCCESSFUL) {
378 437 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
379 438 }
380 439 //
381 440 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
382 441 if (status!=RTEMS_SUCCESSFUL) {
383 442 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
384 443 }
385 444 //
386 445 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
387 446 if (status!=RTEMS_SUCCESSFUL) {
388 447 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
389 448 }
390 449 //
391 450 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
392 451 if (status!=RTEMS_SUCCESSFUL) {
393 452 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
394 453 }
395 454 //
396 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
455 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
397 456 if (status!=RTEMS_SUCCESSFUL) {
398 457 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
399 458 }
400 459 //
401 460 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
402 461 if (status!=RTEMS_SUCCESSFUL) {
403 462 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
404 463 }
405 464 //
406 465 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
407 466 if (status!=RTEMS_SUCCESSFUL) {
408 467 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
409 468 }
410 469
411 470 return status;
412 471 }
413 472
414 473 int spacewire_reset_link( void )
415 474 {
416 475 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
417 476 *
418 477 * @return RTEMS directive status code:
419 478 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
420 479 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
421 480 *
422 481 */
423 482
424 483 rtems_status_code status_spw;
425 484 int i;
426 485
427 486 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
428 487 {
429 488 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
430 489
431 490 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
432 491
433 492 status_spw = spacewire_stop_and_start_link( fdSPW );
434 493 if ( status_spw != RTEMS_SUCCESSFUL )
435 494 {
436 495 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
437 496 }
438 497
439 498 if ( status_spw == RTEMS_SUCCESSFUL)
440 499 {
441 500 break;
442 501 }
443 502 }
444 503
445 504 return status_spw;
446 505 }
447 506
448 507 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
449 508 {
450 509 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
451 510 *
452 511 * @param val is the value, 0 or 1, used to set the value of the NP bit.
453 512 * @param regAddr is the address of the GRSPW control register.
454 513 *
455 514 * NP is the bit 20 of the GRSPW control register.
456 515 *
457 516 */
458 517
459 518 unsigned int *spwptr = (unsigned int*) regAddr;
460 519
461 520 if (val == 1) {
462 521 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
463 522 }
464 523 if (val== 0) {
465 524 *spwptr = *spwptr & 0xffdfffff;
466 525 }
467 526 }
468 527
469 528 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
470 529 {
471 530 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
472 531 *
473 532 * @param val is the value, 0 or 1, used to set the value of the RE bit.
474 533 * @param regAddr is the address of the GRSPW control register.
475 534 *
476 535 * RE is the bit 16 of the GRSPW control register.
477 536 *
478 537 */
479 538
480 539 unsigned int *spwptr = (unsigned int*) regAddr;
481 540
482 541 if (val == 1)
483 542 {
484 543 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
485 544 }
486 545 if (val== 0)
487 546 {
488 547 *spwptr = *spwptr & 0xfffdffff;
489 548 }
490 549 }
491 550
492 551 void spacewire_compute_stats_offsets( void )
493 552 {
494 553 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
495 554 *
496 555 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
497 556 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
498 557 * during the open systel call).
499 558 *
500 559 */
501 560
502 561 spw_stats spacewire_stats_grspw;
503 562 rtems_status_code status;
504 563
505 564 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
506 565
507 566 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
508 567 + spacewire_stats.packets_received;
509 568 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
510 569 + spacewire_stats.packets_sent;
511 570 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
512 571 + spacewire_stats.parity_err;
513 572 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
514 573 + spacewire_stats.disconnect_err;
515 574 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
516 575 + spacewire_stats.escape_err;
517 576 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
518 577 + spacewire_stats.credit_err;
519 578 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
520 579 + spacewire_stats.write_sync_err;
521 580 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
522 581 + spacewire_stats.rx_rmap_header_crc_err;
523 582 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
524 583 + spacewire_stats.rx_rmap_data_crc_err;
525 584 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
526 585 + spacewire_stats.early_ep;
527 586 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
528 587 + spacewire_stats.invalid_address;
529 588 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
530 589 + spacewire_stats.rx_eep_err;
531 590 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
532 591 + spacewire_stats.rx_truncated;
533 592 }
534 593
535 594 void spacewire_update_statistics( void )
536 595 {
537 596 rtems_status_code status;
538 597 spw_stats spacewire_stats_grspw;
539 598
540 599 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
541 600
542 601 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
543 602 + spacewire_stats_grspw.packets_received;
544 603 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
545 604 + spacewire_stats_grspw.packets_sent;
546 605 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
547 606 + spacewire_stats_grspw.parity_err;
548 607 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
549 608 + spacewire_stats_grspw.disconnect_err;
550 609 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
551 610 + spacewire_stats_grspw.escape_err;
552 611 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
553 612 + spacewire_stats_grspw.credit_err;
554 613 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
555 614 + spacewire_stats_grspw.write_sync_err;
556 615 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
557 616 + spacewire_stats_grspw.rx_rmap_header_crc_err;
558 617 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
559 618 + spacewire_stats_grspw.rx_rmap_data_crc_err;
560 619 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
561 620 + spacewire_stats_grspw.early_ep;
562 621 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
563 622 + spacewire_stats_grspw.invalid_address;
564 623 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
565 624 + spacewire_stats_grspw.rx_eep_err;
566 625 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
567 626 + spacewire_stats_grspw.rx_truncated;
568 627 //spacewire_stats.tx_link_err;
569 628
570 629 //****************************
571 630 // DPU_SPACEWIRE_IF_STATISTICS
572 631 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
573 632 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
574 633 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
575 634 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
576 635 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
577 636 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
578 637
579 638 //******************************************
580 639 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
581 640 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
582 641 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
583 642 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
584 643 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
585 644 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
586 645
587 646 //*********************************************
588 647 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
589 648 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
590 649 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
591 650 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
592 651 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
593 652 }
594 653
595 654 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
596 655 {
597 656 // rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_9 );
598 657 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
599 658
600 659 grgpio_regs->io_port_direction_register =
601 660 grgpio_regs->io_port_direction_register | 0x04; // [0000 0100], 0 = output disabled, 1 = output enabled
602 661
603 662 if ( (grgpio_regs->io_port_output_register & 0x04) == 0x04 )
604 663 {
605 664 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xfb; // [1111 1011]
606 665 }
607 666 else
608 667 {
609 668 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x04; // [0000 0100]
610 669 }
611 670 }
612 671
613 672 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
614 673 {
615 674 int linkStatus;
616 675 rtems_status_code status;
617 676
618 677 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
619 678
620 679 if ( linkStatus == 5) {
621 680 PRINTF("in spacewire_reset_link *** link is running\n")
622 681 status = RTEMS_SUCCESSFUL;
623 682 }
624 683 }
684
685 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
686 {
687 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
688 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
689 header->reserved = DEFAULT_RESERVED;
690 header->userApplication = CCSDS_USER_APP;
691 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
692 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
693 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
694 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
695 // DATA FIELD HEADER
696 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
697 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
698 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
699 header->destinationID = TM_DESTINATION_ID_GROUND;
700 header->time[0] = 0x00;
701 header->time[0] = 0x00;
702 header->time[0] = 0x00;
703 header->time[0] = 0x00;
704 header->time[0] = 0x00;
705 header->time[0] = 0x00;
706 // AUXILIARY DATA HEADER
707 header->sid = 0x00;
708 header->hkBIA = DEFAULT_HKBIA;
709 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
710 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
711 }
712
713 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
714 {
715 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
716 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
717 header->reserved = DEFAULT_RESERVED;
718 header->userApplication = CCSDS_USER_APP;
719 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
720 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
721 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
722 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
723 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
724 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
725 // DATA FIELD HEADER
726 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
727 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
728 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
729 header->destinationID = TM_DESTINATION_ID_GROUND;
730 header->time[0] = 0x00;
731 header->time[0] = 0x00;
732 header->time[0] = 0x00;
733 header->time[0] = 0x00;
734 header->time[0] = 0x00;
735 header->time[0] = 0x00;
736 // AUXILIARY DATA HEADER
737 header->sid = 0x00;
738 header->hkBIA = DEFAULT_HKBIA;
739 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
740 header->pktNr = 0x00;
741 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
742 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
743 }
744
745 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
746 {
747 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
748 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
749 header->reserved = DEFAULT_RESERVED;
750 header->userApplication = CCSDS_USER_APP;
751 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
752 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
753 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
754 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
755 header->packetLength[0] = 0x00;
756 header->packetLength[1] = 0x00;
757 // DATA FIELD HEADER
758 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
759 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
760 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
761 header->destinationID = TM_DESTINATION_ID_GROUND;
762 header->time[0] = 0x00;
763 header->time[0] = 0x00;
764 header->time[0] = 0x00;
765 header->time[0] = 0x00;
766 header->time[0] = 0x00;
767 header->time[0] = 0x00;
768 // AUXILIARY DATA HEADER
769 header->sid = 0x00;
770 header->biaStatusInfo = 0x00;
771 header->pa_lfr_pkt_cnt_asm = 0x00;
772 header->pa_lfr_pkt_nr_asm = 0x00;
773 header->pa_lfr_asm_blk_nr[0] = 0x00;
774 header->pa_lfr_asm_blk_nr[1] = 0x00;
775 }
776
777 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
778 Header_TM_LFR_SCIENCE_CWF_t *header )
779 {
780 /** This function sends CWF CCSDS packets (F2, F1 or F0).
781 *
782 * @param waveform points to the buffer containing the data that will be send.
783 * @param sid is the source identifier of the data that will be sent.
784 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
785 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
786 * contain information to setup the transmission of the data packets.
787 *
788 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
789 *
790 */
791
792 unsigned int i;
793 int ret;
794 unsigned int coarseTime;
795 unsigned int fineTime;
796 rtems_status_code status;
797 spw_ioctl_pkt_send spw_ioctl_send_CWF;
798 int *dataPtr;
799 unsigned char sid;
800
801 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
802 spw_ioctl_send_CWF.options = 0;
803
804 ret = LFR_DEFAULT;
805 sid = (unsigned char) ring_node_to_send->sid;
806
807 coarseTime = ring_node_to_send->coarseTime;
808 fineTime = ring_node_to_send->fineTime;
809 dataPtr = (int*) ring_node_to_send->buffer_address;
810
811 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
812 {
813 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
814 spw_ioctl_send_CWF.hdr = (char*) header;
815 // BUILD THE DATA
816 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
817
818 // SET PACKET SEQUENCE CONTROL
819 increment_seq_counter_source_id( header->packetSequenceControl, sid );
820
821 // SET SID
822 header->sid = sid;
823
824 // SET PACKET TIME
825 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
826 //
827 header->time[0] = header->acquisitionTime[0];
828 header->time[1] = header->acquisitionTime[1];
829 header->time[2] = header->acquisitionTime[2];
830 header->time[3] = header->acquisitionTime[3];
831 header->time[4] = header->acquisitionTime[4];
832 header->time[5] = header->acquisitionTime[5];
833
834 // SET PACKET ID
835 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
836 {
837 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
838 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
839 }
840 else
841 {
842 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
843 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
844 }
845
846 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
847 if (status != RTEMS_SUCCESSFUL) {
848 printf("%d-%d, ERR %d\n", sid, i, (int) status);
849 ret = LFR_DEFAULT;
850 }
851 }
852
853 return ret;
854 }
855
856 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
857 Header_TM_LFR_SCIENCE_SWF_t *header )
858 {
859 /** This function sends SWF CCSDS packets (F2, F1 or F0).
860 *
861 * @param waveform points to the buffer containing the data that will be send.
862 * @param sid is the source identifier of the data that will be sent.
863 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
864 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
865 * contain information to setup the transmission of the data packets.
866 *
867 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
868 *
869 */
870
871 unsigned int i;
872 int ret;
873 unsigned int coarseTime;
874 unsigned int fineTime;
875 rtems_status_code status;
876 spw_ioctl_pkt_send spw_ioctl_send_SWF;
877 int *dataPtr;
878 unsigned char sid;
879
880 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
881 spw_ioctl_send_SWF.options = 0;
882
883 ret = LFR_DEFAULT;
884
885 coarseTime = ring_node_to_send->coarseTime;
886 fineTime = ring_node_to_send->fineTime;
887 dataPtr = (int*) ring_node_to_send->buffer_address;
888 sid = ring_node_to_send->sid;
889
890 for (i=0; i<7; i++) // send waveform
891 {
892 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
893 spw_ioctl_send_SWF.hdr = (char*) header;
894
895 // SET PACKET SEQUENCE CONTROL
896 increment_seq_counter_source_id( header->packetSequenceControl, sid );
897
898 // SET PACKET LENGTH AND BLKNR
899 if (i == 6)
900 {
901 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
902 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
903 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
904 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
905 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
906 }
907 else
908 {
909 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
910 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
911 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
912 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
913 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
914 }
915
916 // SET PACKET TIME
917 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
918 //
919 header->time[0] = header->acquisitionTime[0];
920 header->time[1] = header->acquisitionTime[1];
921 header->time[2] = header->acquisitionTime[2];
922 header->time[3] = header->acquisitionTime[3];
923 header->time[4] = header->acquisitionTime[4];
924 header->time[5] = header->acquisitionTime[5];
925
926 // SET SID
927 header->sid = sid;
928
929 // SET PKTNR
930 header->pktNr = i+1; // PKT_NR
931
932 // SEND PACKET
933 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
934 if (status != RTEMS_SUCCESSFUL) {
935 printf("%d-%d, ERR %d\n", sid, i, (int) status);
936 ret = LFR_DEFAULT;
937 }
938 }
939
940 return ret;
941 }
942
943 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
944 Header_TM_LFR_SCIENCE_CWF_t *header )
945 {
946 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
947 *
948 * @param waveform points to the buffer containing the data that will be send.
949 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
950 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
951 * contain information to setup the transmission of the data packets.
952 *
953 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
954 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
955 *
956 */
957
958 unsigned int i;
959 int ret;
960 unsigned int coarseTime;
961 unsigned int fineTime;
962 rtems_status_code status;
963 spw_ioctl_pkt_send spw_ioctl_send_CWF;
964 char *dataPtr;
965 unsigned char sid;
966
967 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
968 spw_ioctl_send_CWF.options = 0;
969
970 ret = LFR_DEFAULT;
971 sid = ring_node_to_send->sid;
972
973 coarseTime = ring_node_to_send->coarseTime;
974 fineTime = ring_node_to_send->fineTime;
975 dataPtr = (char*) ring_node_to_send->buffer_address;
976
977 //*********************
978 // SEND CWF3_light DATA
979 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
980 {
981 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
982 spw_ioctl_send_CWF.hdr = (char*) header;
983 // BUILD THE DATA
984 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
985
986 // SET PACKET SEQUENCE COUNTER
987 increment_seq_counter_source_id( header->packetSequenceControl, sid );
988
989 // SET SID
990 header->sid = sid;
991
992 // SET PACKET TIME
993 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
994 //
995 header->time[0] = header->acquisitionTime[0];
996 header->time[1] = header->acquisitionTime[1];
997 header->time[2] = header->acquisitionTime[2];
998 header->time[3] = header->acquisitionTime[3];
999 header->time[4] = header->acquisitionTime[4];
1000 header->time[5] = header->acquisitionTime[5];
1001
1002 // SET PACKET ID
1003 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1004 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1005
1006 // SEND PACKET
1007 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1008 if (status != RTEMS_SUCCESSFUL) {
1009 printf("%d-%d, ERR %d\n", sid, i, (int) status);
1010 ret = LFR_DEFAULT;
1011 }
1012 }
1013
1014 return ret;
1015 }
1016
1017 void spw_send_asm( ring_node *ring_node_to_send,
1018 Header_TM_LFR_SCIENCE_ASM_t *header )
1019 {
1020 unsigned int i;
1021 unsigned int length = 0;
1022 rtems_status_code status;
1023 unsigned int sid;
1024 char *spectral_matrix;
1025 int coarseTime;
1026 int fineTime;
1027 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1028
1029 sid = ring_node_to_send->sid;
1030 spectral_matrix = (char*) ring_node_to_send->buffer_address;
1031 coarseTime = ring_node_to_send->coarseTime;
1032 fineTime = ring_node_to_send->fineTime;
1033
1034 for (i=0; i<2; i++)
1035 {
1036 // (1) BUILD THE DATA
1037 switch(sid)
1038 {
1039 case SID_NORM_ASM_F0:
1040 spw_ioctl_send_ASM.dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent
1041 spw_ioctl_send_ASM.data = &spectral_matrix[
1042 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2
1043 ];
1044 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0;
1045 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB
1046 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB
1047 break;
1048 case SID_NORM_ASM_F1:
1049 spw_ioctl_send_ASM.dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent
1050 spw_ioctl_send_ASM.data = &spectral_matrix[
1051 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2
1052 ];
1053 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1;
1054 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB
1055 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB
1056 break;
1057 case SID_NORM_ASM_F2:
1058 spw_ioctl_send_ASM.dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent
1059 spw_ioctl_send_ASM.data = &spectral_matrix[
1060 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2
1061 ];
1062 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1063 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1064 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1065 break;
1066 default:
1067 PRINTF1("ERR *** in spw_send_asm *** unexpected sid %d\n", sid)
1068 break;
1069 }
1070 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES;
1071 spw_ioctl_send_ASM.hdr = (char *) header;
1072 spw_ioctl_send_ASM.options = 0;
1073
1074 // (2) BUILD THE HEADER
1075 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1076 header->packetLength[0] = (unsigned char) (length>>8);
1077 header->packetLength[1] = (unsigned char) (length);
1078 header->sid = (unsigned char) sid; // SID
1079 header->pa_lfr_pkt_cnt_asm = 2;
1080 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1081
1082 // (3) SET PACKET TIME
1083 header->time[0] = (unsigned char) (coarseTime>>24);
1084 header->time[1] = (unsigned char) (coarseTime>>16);
1085 header->time[2] = (unsigned char) (coarseTime>>8);
1086 header->time[3] = (unsigned char) (coarseTime);
1087 header->time[4] = (unsigned char) (fineTime>>8);
1088 header->time[5] = (unsigned char) (fineTime);
1089 //
1090 header->acquisitionTime[0] = header->time[0];
1091 header->acquisitionTime[1] = header->time[1];
1092 header->acquisitionTime[2] = header->time[2];
1093 header->acquisitionTime[3] = header->time[3];
1094 header->acquisitionTime[4] = header->time[4];
1095 header->acquisitionTime[5] = header->time[5];
1096
1097 // (4) SEND PACKET
1098 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1099 if (status != RTEMS_SUCCESSFUL) {
1100 printf("in ASM_send *** ERR %d\n", (int) status);
1101 }
1102 }
1103 }
@@ -1,380 +1,401
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 "avf0_prc0.h"
11 11 #include "fsw_processing.h"
12 12
13 13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14 14
15 15 //***
16 16 // F0
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0[ NB_RING_NODES_ASM_BURST_SBM_F0 ];
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 char buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
19 22
20 23 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
21 24 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
22 25 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
23 26 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
24 27 //unsigned char bp1_norm_f0 [ TOTAL_SIZE_BP1_NORM_F0 ];
25 28 //unsigned char bp1_sbm_f0 [ TOTAL_SIZE_BP1_SBM_F0 ];
26 29
27 30 //************
28 31 // RTEMS TASKS
29 32
30 33 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
31 34 {
32 35 int i;
33 36
34 37 rtems_event_set event_out;
35 38 rtems_status_code status;
36 39 rtems_id queue_id_prc0;
37 40 asm_msg msgForMATR;
38 41 ring_node_sm *ring_node_tab[8];
39 42 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
40 43 ring_node_asm *current_ring_node_asm_norm_f0;
41 44
42 45 unsigned int nb_norm_bp1;
43 46 unsigned int nb_norm_bp2;
44 47 unsigned int nb_norm_asm;
45 48 unsigned int nb_sbm_bp1;
46 49 unsigned int nb_sbm_bp2;
47 50
48 51 nb_norm_bp1 = 0;
49 52 nb_norm_bp2 = 0;
50 53 nb_norm_asm = 0;
51 54 nb_sbm_bp1 = 0;
52 55 nb_sbm_bp2 = 0;
53 56
54 57 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
55 58 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
56 59 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
57 60 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
58 61 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
59 62
60 63 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
61 64
62 65 status = get_message_queue_id_prc0( &queue_id_prc0 );
63 66 if (status != RTEMS_SUCCESSFUL)
64 67 {
65 68 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
66 69 }
67 70
68 71 while(1){
69 72 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
70 73
71 74 //****************************************
72 75 // initialize the mesage for the MATR task
73 76 msgForMATR.norm = current_ring_node_asm_norm_f0;
74 77 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0;
75 78 msgForMATR.event = 0x00; // this composite event will be sent to the MATR task
76 79 msgForMATR.coarseTime = ring_node_for_averaging_sm_f0->coarseTime;
77 80 msgForMATR.fineTime = ring_node_for_averaging_sm_f0->fineTime;
78 81 //
79 82 //****************************************
80 83
81 84 ring_node_tab[NB_SM_BEFORE_AVF0-1] = ring_node_for_averaging_sm_f0;
82 85 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
83 86 {
84 87 ring_node_for_averaging_sm_f0 = ring_node_for_averaging_sm_f0->previous;
85 88 ring_node_tab[NB_SM_BEFORE_AVF0-i] = ring_node_for_averaging_sm_f0;
86 89 }
87 90
88 91 // compute the average and store it in the averaged_sm_f1 buffer
89 92 SM_average( current_ring_node_asm_norm_f0->matrix,
90 93 current_ring_node_asm_burst_sbm_f0->matrix,
91 94 ring_node_tab,
92 95 nb_norm_bp1, nb_sbm_bp1 );
93 96
94 97 // update nb_average
95 98 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
96 99 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
97 100 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
98 101 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
99 102 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
100 103
101 104 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
102 105 {
103 106 nb_sbm_bp1 = 0;
104 107 // set another ring for the ASM storage
105 108 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
106 109 if ( lfrCurrentMode == LFR_MODE_BURST )
107 110 {
108 111 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0;
109 112 }
110 113 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
111 114 {
112 115 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0;
113 116 }
114 117 }
115 118
116 119 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
117 120 {
118 121 nb_sbm_bp2 = 0;
119 122 if ( lfrCurrentMode == LFR_MODE_BURST )
120 123 {
121 124 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0;
122 125 }
123 126 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
124 127 {
125 128 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0;
126 129 }
127 130 }
128 131
129 132 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
130 133 {
131 134 nb_norm_bp1 = 0;
132 135 // set another ring for the ASM storage
133 136 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
134 137 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
135 138 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
136 139 {
137 140 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0;
138 141 }
139 142 }
140 143
141 144 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
142 145 {
143 146 nb_norm_bp2 = 0;
144 147 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 148 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 149 {
147 150 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0;
148 151 }
149 152 }
150 153
151 154 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
152 155 {
153 156 nb_norm_asm = 0;
154 157 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 158 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 159 {
157 160 // PRINTF1("%lld\n", localTime)
158 161 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0;
159 162 }
160 163 }
161 164
162 165 //*************************
163 166 // send the message to MATR
164 167 if (msgForMATR.event != 0x00)
165 168 {
166 169 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0);
167 170 }
168 171
169 172 if (status != RTEMS_SUCCESSFUL) {
170 173 printf("in AVF0 *** Error sending message to MATR, code %d\n", status);
171 174 }
172 175 }
173 176 }
174 177
175 178 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
176 179 {
177 180 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
178 181 size_t size; // size of the incoming TC packet
179 182 asm_msg *incomingMsg;
180 183 //
181 184 unsigned char sid;
182 185 spw_ioctl_pkt_send spw_ioctl_send_ASM;
183 186 rtems_status_code status;
184 187 rtems_id queue_id;
185 188 rtems_id queue_id_q_p0;
186 189 Header_TM_LFR_SCIENCE_ASM_t headerASM;
187 190 bp_packet_with_spare packet_norm_bp1_f0;
188 191 bp_packet packet_norm_bp2_f0;
189 192 bp_packet packet_sbm_bp1_f0;
190 193 bp_packet packet_sbm_bp2_f0;
194 ring_node *current_ring_node_to_send_asm_f0;
191 195
192 196 unsigned long long int localTime;
193 197
194 198 ASM_init_header( &headerASM );
195 199
200 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
201 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
202 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
203
196 204 //*************
197 205 // NORM headers
198 206 BP_init_header_with_spare( &packet_norm_bp1_f0.header,
199 207 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
200 208 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
201 209 BP_init_header( &packet_norm_bp2_f0.header,
202 210 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
203 211 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
204 212
205 213 //****************************
206 214 // BURST SBM1 and SBM2 headers
207 215 if ( lfrRequestedMode == LFR_MODE_BURST )
208 216 {
209 217 BP_init_header( &packet_sbm_bp1_f0.header,
210 218 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
211 219 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
212 220 BP_init_header( &packet_sbm_bp2_f0.header,
213 221 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
214 222 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
215 223 }
216 224 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
217 225 {
218 226 BP_init_header( &packet_sbm_bp1_f0.header,
219 227 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
220 228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
221 229 BP_init_header( &packet_sbm_bp2_f0.header,
222 230 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
223 231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
224 232 }
225 233 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
226 234 {
227 235 BP_init_header( &packet_sbm_bp1_f0.header,
228 236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
229 237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
230 238 BP_init_header( &packet_sbm_bp2_f0.header,
231 239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
232 240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
233 241 }
234 242 else
235 243 {
236 244 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
237 245 }
238 246
239 247 status = get_message_queue_id_send( &queue_id );
240 248 if (status != RTEMS_SUCCESSFUL)
241 249 {
242 250 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
243 251 }
244 252 status = get_message_queue_id_prc0( &queue_id_q_p0);
245 253 if (status != RTEMS_SUCCESSFUL)
246 254 {
247 255 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
248 256 }
249 257
250 258 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
251 259
252 260 while(1){
253 261 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
254 262 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
255 263
256 264 incomingMsg = (asm_msg*) incomingData;
257 265
258 266 localTime = getTimeAsUnsignedLongLongInt( );
259 267
260 268 //****************
261 269 //****************
262 270 // BURST SBM1 SBM2
263 271 //****************
264 272 //****************
265 273 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
266 274 {
267 275 sid = getSID( incomingMsg->event );
268 276 // 1) compress the matrix for Basic Parameters calculation
269 277 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f0,
270 278 nb_sm_before_f0.burst_sbm_bp1,
271 279 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
272 280 ASM_F0_INDICE_START);
273 281 // 2) compute the BP1 set
274 282 // BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, bp1_sbm_f0 );
275 283 // 3) send the BP1 set
276 284 set_time( packet_sbm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
277 285 set_time( packet_sbm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
278 286 BP_send( (char *) &packet_sbm_bp1_f0, queue_id,
279 287 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
280 288 sid);
281 289 // 4) compute the BP2 set if needed
282 290 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
283 291 {
284 292 // 1) compute the BP2 set
285 293
286 294 // 2) send the BP2 set
287 295 set_time( packet_sbm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
288 296 set_time( packet_sbm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
289 297 BP_send( (char *) &packet_sbm_bp2_f0, queue_id,
290 298 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
291 299 sid);
292 300 }
293 301 }
294 302
295 303 //*****
296 304 //*****
297 305 // NORM
298 306 //*****
299 307 //*****
300 308 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
301 309 {
302 310 // 1) compress the matrix for Basic Parameters calculation
303 311 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f0,
304 312 nb_sm_before_f0.norm_bp1,
305 313 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
306 314 ASM_F0_INDICE_START );
307 315 // 2) compute the BP1 set
308 316 // BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, bp1_norm_f0 );
309 317 // 3) send the BP1 set
310 318 set_time( packet_norm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
311 319 set_time( packet_norm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
312 320 BP_send( (char *) &packet_norm_bp1_f0, queue_id,
313 321 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
314 322 SID_NORM_BP1_F0 );
315 323 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
316 324 {
317 325 // 1) compute the BP2 set using the same ASM as the one used for BP1
318 326
319 327 // 2) send the BP2 set
320 328 set_time( packet_norm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
321 329 set_time( packet_norm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
322 330 BP_send( (char *) &packet_norm_bp2_f0, queue_id,
323 331 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
324 332 SID_NORM_BP2_F0);
325 333 }
326 334 }
327 335
328 336 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
329 337 {
338 // // 1) reorganize the ASM and divide
339 // ASM_reorganize_and_divide( incomingMsg->norm->matrix,
340 // asm_f0_reorganized,
341 // nb_sm_before_f0.norm_bp1 );
342 // // 2) convert the float array in a char array
343 // ASM_convert( asm_f0_reorganized, (char*) current_ring_node_to_send_asm_f0->buffer_address );
344 // current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTime;
345 // current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTime;
346 // current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
347 // // 3) send the spectral matrix packets
348 // status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
349 // // change asm ring node
350 // current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
330 351 // 1) reorganize the ASM and divide
331 352 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
332 asm_f0_reorganized,
333 nb_sm_before_f0.norm_bp1 );
353 asm_f0_reorganized,
354 nb_sm_before_f0.norm_bp1 );
334 355 // 2) convert the float array in a char array
335 356 ASM_convert( asm_f0_reorganized, asm_f0_char);
336 357 // 3) send the spectral matrix packets
337 set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime );
358 set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime );
338 359 set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
339 360 ASM_send( &headerASM, asm_f0_char, SID_NORM_ASM_F0, &spw_ioctl_send_ASM, queue_id);
340 361 }
341 362
342 363 }
343 364 }
344 365
345 366 //**********
346 367 // FUNCTIONS
347 368
348 369 void reset_nb_sm_f0( unsigned char lfrMode )
349 370 {
350 371 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
351 372 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
352 373 nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96;
353 374 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
354 375 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
355 376 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
356 377 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
357 378 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
358 379 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
359 380
360 381 if (lfrMode == LFR_MODE_SBM1)
361 382 {
362 383 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
363 384 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
364 385 }
365 386 else if (lfrMode == LFR_MODE_SBM2)
366 387 {
367 388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
368 389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
369 390 }
370 391 else if (lfrMode == LFR_MODE_BURST)
371 392 {
372 393 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
373 394 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
374 395 }
375 396 else
376 397 {
377 398 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
378 399 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
379 400 }
380 401 }
@@ -1,712 +1,688
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 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 38 unsigned long long int syncBit0;
39 39 unsigned long long int syncBit1;
40 40
41 41 status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits
42 42
43 43 time_0 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_0_coarse_time );
44 44 time_1 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_1_coarse_time );
45 45 syncBit0 = ( (unsigned long long int) (spectral_matrix_regs->f0_0_coarse_time & 0x80000000) ) << 16;
46 46 syncBit1 = ( (unsigned long long int) (spectral_matrix_regs->f0_1_coarse_time & 0x80000000) ) << 16;
47 47
48 48 switch(status)
49 49 {
50 50 case 0:
51 51 break;
52 52 case 3:
53 53 if ( time_0 < time_1 )
54 54 {
55 55 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
56 56 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
57 57 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
58 58 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
59 59 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
60 60 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
61 61 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
62 62 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
63 63 }
64 64 else
65 65 {
66 66 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
67 67 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
68 68 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
69 69 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
70 70 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
71 71 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
72 72 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
73 73 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
74 74 }
75 75 spectral_matrix_regs->status = 0x03; // [0011]
76 76 break;
77 77 case 1:
78 78 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
79 79 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
80 80 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
81 81 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
82 82 spectral_matrix_regs->status = 0x01; // [0001]
83 83 break;
84 84 case 2:
85 85 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
86 86 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
87 87 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
88 88 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
89 89 spectral_matrix_regs->status = 0x02; // [0010]
90 90 break;
91 91 }
92 92 }
93 93
94 94 void spectral_matrices_isr_f1( void )
95 95 {
96 96 unsigned char status;
97 97 unsigned long long int time;
98 98 unsigned long long int syncBit;
99 99 rtems_status_code status_code;
100 100
101 101 status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
102 102
103 103 switch(status)
104 104 {
105 105 case 0:
106 106 break;
107 107 case 3:
108 108 // UNEXPECTED VALUE
109 109 spectral_matrix_regs->status = 0xc0; // [1100]
110 110 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
111 111 break;
112 112 case 1:
113 113 time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_0_coarse_time );
114 114 syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_0_coarse_time & 0x80000000) ) << 16;
115 115 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1],
116 116 ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit);
117 117 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
118 118 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
119 119 spectral_matrix_regs->status = 0x04; // [0100]
120 120 break;
121 121 case 2:
122 122 time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_1_coarse_time );
123 123 syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_1_coarse_time & 0x80000000) ) << 16;
124 124 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1],
125 125 ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit);
126 126 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
127 127 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
128 128 spectral_matrix_regs->status = 0x08; // [1000]
129 129 break;
130 130 }
131 131 }
132 132
133 133 void spectral_matrices_isr_f2( void )
134 134 {
135 135 unsigned char status;
136 136 rtems_status_code status_code;
137 137
138 138 status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
139 139
140 140 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
141 141
142 142 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
143 143
144 144 switch(status)
145 145 {
146 146 case 0:
147 147 break;
148 148 case 3:
149 149 // UNEXPECTED VALUE
150 150 spectral_matrix_regs->status = 0x30; // [0011 0000]
151 151 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
152 152 break;
153 153 case 1:
154 154 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
155 155 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
156 156 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
157 157 spectral_matrix_regs->status = 0x10; // [0001 0000]
158 158 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
159 159 {
160 160 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
161 161 }
162 162 break;
163 163 case 2:
164 164 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
165 165 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
166 166 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
167 167 spectral_matrix_regs->status = 0x20; // [0010 0000]
168 168 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
169 169 {
170 170 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
171 171 }
172 172 break;
173 173 }
174 174 }
175 175
176 176 void spectral_matrix_isr_error_handler( void )
177 177 {
178 178 rtems_status_code status_code;
179 179
180 180 if (spectral_matrix_regs->status & 0x7c0) // [0111 1100 0000]
181 181 {
182 182 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
183 183 }
184 184 }
185 185
186 186 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
187 187 {
188 188 // STATUS REGISTER
189 189 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
190 190 // 10 9 8
191 191 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
192 192 // 7 6 5 4 3 2 1 0
193 193
194 194 spectral_matrices_isr_f0();
195 195
196 196 spectral_matrices_isr_f1();
197 197
198 198 spectral_matrices_isr_f2();
199 199
200 200 // spectral_matrix_isr_error_handler();
201 201 }
202 202
203 203 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
204 204 {
205 205 rtems_status_code status_code;
206 206
207 207 //***
208 208 // F0
209 209 nb_sm_f0 = nb_sm_f0 + 1;
210 210 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
211 211 {
212 212 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
213 213 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
214 214 {
215 215 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
216 216 }
217 217 nb_sm_f0 = 0;
218 218 }
219 219
220 220 //***
221 221 // F1
222 222 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
223 223 if (nb_sm_f0_aux_f1 == 6)
224 224 {
225 225 nb_sm_f0_aux_f1 = 0;
226 226 nb_sm_f1 = nb_sm_f1 + 1;
227 227 }
228 228 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
229 229 {
230 230 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
231 231 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
232 232 {
233 233 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
234 234 }
235 235 nb_sm_f1 = 0;
236 236 }
237 237
238 238 //***
239 239 // F2
240 240 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
241 241 if (nb_sm_f0_aux_f2 == 96)
242 242 {
243 243 nb_sm_f0_aux_f2 = 0;
244 244 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
245 245 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
246 246 {
247 247 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
248 248 }
249 249 }
250 250 }
251 251
252 252 //******************
253 253 // Spectral Matrices
254 254
255 255 void reset_nb_sm( void )
256 256 {
257 257 nb_sm_f0 = 0;
258 258 nb_sm_f0_aux_f1 = 0;
259 259 nb_sm_f0_aux_f2 = 0;
260 260
261 261 nb_sm_f1 = 0;
262 262 }
263 263
264 //void SM_init_rings_alt( void )
265 //{
266 // init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
267 // init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f0, TOTAL_SIZE_SM );
268 // init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f0, TOTAL_SIZE_SM );
269
270 // DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
271 // DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
272 // DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
273 // DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
274 // DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
275 // DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
276 //}
277
264 278 void SM_init_rings( void )
265 279 {
266 280 unsigned char i;
267
268 281 // F0 RING
269 sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1];
270 sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1];
271 sm_ring_f0[0].buffer_address =
282 sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1];
283 sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1];
284 sm_ring_f0[0].buffer_address =
272 285 (int) &sm_f0[ 0 ];
273
274 sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0];
275 sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2];
286 sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0];
287 sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2];
276 288 sm_ring_f0[NB_RING_NODES_SM_F0-1].buffer_address =
277 289 (int) &sm_f0[ (NB_RING_NODES_SM_F0-1) * TOTAL_SIZE_SM ];
278
279 290 for(i=1; i<NB_RING_NODES_SM_F0-1; i++)
280 291 {
281 sm_ring_f0[i].next = (ring_node_sm*) &sm_ring_f0[i+1];
282 sm_ring_f0[i].previous = (ring_node_sm*) &sm_ring_f0[i-1];
283 sm_ring_f0[i].buffer_address =
292 sm_ring_f0[i].next = (ring_node_sm*) &sm_ring_f0[i+1];
293 sm_ring_f0[i].previous = (ring_node_sm*) &sm_ring_f0[i-1];
294 sm_ring_f0[i].buffer_address =
284 295 (int) &sm_f0[ i * TOTAL_SIZE_SM ];
285 296 }
286
287 297 // F1 RING
288 sm_ring_f1[0].next = (ring_node_sm*) &sm_ring_f1[1];
289 sm_ring_f1[0].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-1];
290 sm_ring_f1[0].buffer_address =
298 sm_ring_f1[0].next = (ring_node_sm*) &sm_ring_f1[1];
299 sm_ring_f1[0].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-1];
300 sm_ring_f1[0].buffer_address =
291 301 (int) &sm_f1[ 0 ];
292
293 sm_ring_f1[NB_RING_NODES_SM_F1-1].next = (ring_node_sm*) &sm_ring_f1[0];
294 sm_ring_f1[NB_RING_NODES_SM_F1-1].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-2];
302 sm_ring_f1[NB_RING_NODES_SM_F1-1].next = (ring_node_sm*) &sm_ring_f1[0];
303 sm_ring_f1[NB_RING_NODES_SM_F1-1].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-2];
295 304 sm_ring_f1[NB_RING_NODES_SM_F1-1].buffer_address =
296 305 (int) &sm_f1[ (NB_RING_NODES_SM_F1-1) * TOTAL_SIZE_SM ];
297
298 306 for(i=1; i<NB_RING_NODES_SM_F1-1; i++)
299 307 {
300 sm_ring_f1[i].next = (ring_node_sm*) &sm_ring_f1[i+1];
301 sm_ring_f1[i].previous = (ring_node_sm*) &sm_ring_f1[i-1];
302 sm_ring_f1[i].buffer_address =
308 sm_ring_f1[i].next = (ring_node_sm*) &sm_ring_f1[i+1];
309 sm_ring_f1[i].previous = (ring_node_sm*) &sm_ring_f1[i-1];
310 sm_ring_f1[i].buffer_address =
303 311 (int) &sm_f1[ i * TOTAL_SIZE_SM ];
304 312 }
305
306 313 // F2 RING
307 sm_ring_f2[0].next = (ring_node_sm*) &sm_ring_f2[1];
308 sm_ring_f2[0].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-1];
309 sm_ring_f2[0].buffer_address =
314 sm_ring_f2[0].next = (ring_node_sm*) &sm_ring_f2[1];
315 sm_ring_f2[0].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-1];
316 sm_ring_f2[0].buffer_address =
310 317 (int) &sm_f2[ 0 ];
311
312 sm_ring_f2[NB_RING_NODES_SM_F2-1].next = (ring_node_sm*) &sm_ring_f2[0];
313 sm_ring_f2[NB_RING_NODES_SM_F2-1].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-2];
318 sm_ring_f2[NB_RING_NODES_SM_F2-1].next = (ring_node_sm*) &sm_ring_f2[0];
319 sm_ring_f2[NB_RING_NODES_SM_F2-1].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-2];
314 320 sm_ring_f2[NB_RING_NODES_SM_F2-1].buffer_address =
315 321 (int) &sm_f2[ (NB_RING_NODES_SM_F2-1) * TOTAL_SIZE_SM ];
316
317 322 for(i=1; i<NB_RING_NODES_SM_F2-1; i++)
318 323 {
319 sm_ring_f2[i].next = (ring_node_sm*) &sm_ring_f2[i+1];
320 sm_ring_f2[i].previous = (ring_node_sm*) &sm_ring_f2[i-1];
321 sm_ring_f2[i].buffer_address =
324 sm_ring_f2[i].next = (ring_node_sm*) &sm_ring_f2[i+1];
325 sm_ring_f2[i].previous = (ring_node_sm*) &sm_ring_f2[i-1];
326 sm_ring_f2[i].buffer_address =
322 327 (int) &sm_f2[ i * TOTAL_SIZE_SM ];
323 328 }
324
325 329 DEBUG_PRINTF1("asm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("asm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("asm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328
329 spectral_matrix_regs->f0_0_address = sm_ring_f0[0].buffer_address;
330 DEBUG_PRINTF1("asm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
331 DEBUG_PRINTF1("asm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
332 spectral_matrix_regs->f0_0_address = sm_ring_f0[0].buffer_address;
330 333 DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->f0_0_address)
331 334 }
332 335
333 void SM_generic_init_ring( ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] )
334 {
335 unsigned char i;
336
337 //***************
338 // BUFFER ADDRESS
339 for(i=0; i<nbNodes; i++)
340 {
341 ring[ i ].buffer_address = (int) &sm_f[ i * TOTAL_SIZE_SM ];
342 }
343
344 //*****
345 // NEXT
346 ring[ nbNodes - 1 ].next = (ring_node_sm*) &ring[ 0 ];
347 for(i=0; i<nbNodes-1; i++)
348 {
349 ring[ i ].next = (ring_node_sm*) &ring[ i + 1 ];
350 }
351
352 //*********
353 // PREVIOUS
354 ring[ 0 ].previous = (ring_node_sm*) &ring[ nbNodes -1 ];
355 for(i=1; i<nbNodes; i++)
356 {
357 ring[ i ].previous = (ring_node_sm*) &ring[ i - 1 ];
358 }
359 }
360 336
361 337 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
362 338 {
363 339 unsigned char i;
364 340
365 341 ring[ nbNodes - 1 ].next
366 342 = (ring_node_asm*) &ring[ 0 ];
367 343
368 344 for(i=0; i<nbNodes-1; i++)
369 345 {
370 346 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
371 347 }
372 348 }
373 349
374 350 void SM_reset_current_ring_nodes( void )
375 351 {
376 352 current_ring_node_sm_f0 = sm_ring_f0[0].next;
377 353 current_ring_node_sm_f1 = sm_ring_f1[0].next;
378 354 current_ring_node_sm_f2 = sm_ring_f2[0].next;
379 355
380 356 ring_node_for_averaging_sm_f0 = sm_ring_f0;
381 357 ring_node_for_averaging_sm_f1 = sm_ring_f1;
382 358 ring_node_for_averaging_sm_f2 = sm_ring_f2;
383 359 }
384 360
385 361 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header)
386 362 {
387 363 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
388 364 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
389 365 header->reserved = 0x00;
390 366 header->userApplication = CCSDS_USER_APP;
391 367 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
392 368 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
393 369 header->packetSequenceControl[0] = 0xc0;
394 370 header->packetSequenceControl[1] = 0x00;
395 371 header->packetLength[0] = 0x00;
396 372 header->packetLength[1] = 0x00;
397 373 // DATA FIELD HEADER
398 374 header->spare1_pusVersion_spare2 = 0x10;
399 375 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
400 376 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
401 377 header->destinationID = TM_DESTINATION_ID_GROUND;
402 // AUXILIARY DATA HEADER
403 header->sid = 0x00;
404 header->biaStatusInfo = 0x00;
405 header->pa_lfr_pkt_cnt_asm = 0x00;
406 header->pa_lfr_pkt_nr_asm = 0x00;
407 378 header->time[0] = 0x00;
408 379 header->time[0] = 0x00;
409 380 header->time[0] = 0x00;
410 381 header->time[0] = 0x00;
411 382 header->time[0] = 0x00;
412 383 header->time[0] = 0x00;
384 // AUXILIARY DATA HEADER
385 header->sid = 0x00;
386 header->biaStatusInfo = 0x00;
387 header->pa_lfr_pkt_cnt_asm = 0x00;
388 header->pa_lfr_pkt_nr_asm = 0x00;
413 389 header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB
414 390 header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB
415 391 }
416 392
417 393 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
418 394 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id)
419 395 {
420 396 unsigned int i;
421 397 unsigned int length = 0;
422 398 rtems_status_code status;
423 399
424 400 for (i=0; i<2; i++)
425 401 {
426 402 // (1) BUILD THE DATA
427 403 switch(sid)
428 404 {
429 405 case SID_NORM_ASM_F0:
430 406 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent
431 407 spw_ioctl_send->data = &spectral_matrix[
432 408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2
433 409 ];
434 410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0;
435 411 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB
436 412 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB
437 413 break;
438 414 case SID_NORM_ASM_F1:
439 415 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent
440 416 spw_ioctl_send->data = &spectral_matrix[
441 417 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2
442 418 ];
443 419 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1;
444 420 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB
445 421 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB
446 422 break;
447 423 case SID_NORM_ASM_F2:
448 424 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent
449 425 spw_ioctl_send->data = &spectral_matrix[
450 426 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2
451 427 ];
452 428 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
453 429 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
454 430 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
455 431 break;
456 432 default:
457 433 PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid)
458 434 break;
459 435 }
460 436 spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES;
461 437 spw_ioctl_send->hdr = (char *) header;
462 438 spw_ioctl_send->options = 0;
463 439
464 440 // (2) BUILD THE HEADER
465 441 increment_seq_counter_source_id( header->packetSequenceControl, sid );
466 442 header->packetLength[0] = (unsigned char) (length>>8);
467 443 header->packetLength[1] = (unsigned char) (length);
468 444 header->sid = (unsigned char) sid; // SID
469 445 header->pa_lfr_pkt_cnt_asm = 2;
470 446 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
471 447
472 448 // (3) SET PACKET TIME
473 449 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
474 450 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
475 451 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
476 452 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
477 453 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
478 454 header->time[5] = (unsigned char) (time_management_regs->fine_time);
479 455 //
480 456 header->acquisitionTime[0] = header->time[0];
481 457 header->acquisitionTime[1] = header->time[1];
482 458 header->acquisitionTime[2] = header->time[2];
483 459 header->acquisitionTime[3] = header->time[3];
484 460 header->acquisitionTime[4] = header->time[4];
485 461 header->acquisitionTime[5] = header->time[5];
486 462
487 463 // (4) SEND PACKET
488 464 status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
489 465 if (status != RTEMS_SUCCESSFUL) {
490 466 printf("in ASM_send *** ERR %d\n", (int) status);
491 467 }
492 468 }
493 469 }
494 470
495 471 //*****************
496 472 // Basic Parameters
497 473
498 474 void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header,
499 475 unsigned int apid, unsigned char sid,
500 476 unsigned int packetLength, unsigned char blkNr )
501 477 {
502 478 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
503 479 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
504 480 header->reserved = 0x00;
505 481 header->userApplication = CCSDS_USER_APP;
506 482 header->packetID[0] = (unsigned char) (apid >> 8);
507 483 header->packetID[1] = (unsigned char) (apid);
508 484 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
509 485 header->packetSequenceControl[1] = 0x00;
510 486 header->packetLength[0] = (unsigned char) (packetLength >> 8);
511 487 header->packetLength[1] = (unsigned char) (packetLength);
512 488 // DATA FIELD HEADER
513 489 header->spare1_pusVersion_spare2 = 0x10;
514 490 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
515 491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
516 492 header->destinationID = TM_DESTINATION_ID_GROUND;
517 493 // AUXILIARY DATA HEADER
518 494 header->sid = sid;
519 495 header->biaStatusInfo = 0x00;
520 496 header->time[0] = 0x00;
521 497 header->time[0] = 0x00;
522 498 header->time[0] = 0x00;
523 499 header->time[0] = 0x00;
524 500 header->time[0] = 0x00;
525 501 header->time[0] = 0x00;
526 502 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
527 503 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
528 504 }
529 505
530 506 void BP_init_header_with_spare(Header_TM_LFR_SCIENCE_BP_with_spare_t *header,
531 507 unsigned int apid, unsigned char sid,
532 508 unsigned int packetLength , unsigned char blkNr)
533 509 {
534 510 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
535 511 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
536 512 header->reserved = 0x00;
537 513 header->userApplication = CCSDS_USER_APP;
538 514 header->packetID[0] = (unsigned char) (apid >> 8);
539 515 header->packetID[1] = (unsigned char) (apid);
540 516 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
541 517 header->packetSequenceControl[1] = 0x00;
542 518 header->packetLength[0] = (unsigned char) (packetLength >> 8);
543 519 header->packetLength[1] = (unsigned char) (packetLength);
544 520 // DATA FIELD HEADER
545 521 header->spare1_pusVersion_spare2 = 0x10;
546 522 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
547 523 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
548 524 header->destinationID = TM_DESTINATION_ID_GROUND;
549 525 // AUXILIARY DATA HEADER
550 526 header->sid = sid;
551 527 header->biaStatusInfo = 0x00;
552 528 header->time[0] = 0x00;
553 529 header->time[0] = 0x00;
554 530 header->time[0] = 0x00;
555 531 header->time[0] = 0x00;
556 532 header->time[0] = 0x00;
557 533 header->time[0] = 0x00;
558 534 header->source_data_spare = 0x00;
559 535 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
560 536 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
561 537 }
562 538
563 539 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
564 540 {
565 541 rtems_status_code status;
566 542
567 543 // SET THE SEQUENCE_CNT PARAMETER
568 544 increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid );
569 545 // SEND PACKET
570 546 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
571 547 if (status != RTEMS_SUCCESSFUL)
572 548 {
573 549 printf("ERR *** in BP_send *** ERR %d\n", (int) status);
574 550 }
575 551 }
576 552
577 553 //******************
578 554 // general functions
579 555
580 556 void reset_sm_status( void )
581 557 {
582 558 // error
583 559 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
584 560 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
585 561 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
586 562 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
587 563
588 564 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
589 565 }
590 566
591 567 void reset_spectral_matrix_regs( void )
592 568 {
593 569 /** This function resets the spectral matrices module registers.
594 570 *
595 571 * The registers affected by this function are located at the following offset addresses:
596 572 *
597 573 * - 0x00 config
598 574 * - 0x04 status
599 575 * - 0x08 matrixF0_Address0
600 576 * - 0x10 matrixFO_Address1
601 577 * - 0x14 matrixF1_Address
602 578 * - 0x18 matrixF2_Address
603 579 *
604 580 */
605 581
606 582 set_sm_irq_onError( 0 );
607 583
608 584 set_sm_irq_onNewMatrix( 0 );
609 585
610 586 reset_sm_status();
611 587
612 588 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
613 589 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
614 590 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
615 591 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
616 592 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
617 593 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
618 594
619 595 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
620 596 }
621 597
622 598 void set_time( unsigned char *time, unsigned char * timeInBuffer )
623 599 {
624 600 time[0] = timeInBuffer[0];
625 601 time[1] = timeInBuffer[1];
626 602 time[2] = timeInBuffer[2];
627 603 time[3] = timeInBuffer[3];
628 604 time[4] = timeInBuffer[6];
629 605 time[5] = timeInBuffer[7];
630 606 }
631 607
632 608 unsigned long long int get_acquisition_time( unsigned char *timePtr )
633 609 {
634 610 unsigned long long int acquisitionTimeAslong;
635 611 acquisitionTimeAslong = 0x00;
636 612 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
637 613 + ( (unsigned long long int) timePtr[1] << 32 )
638 614 + ( (unsigned long long int) timePtr[2] << 24 )
639 615 + ( (unsigned long long int) timePtr[3] << 16 )
640 616 + ( (unsigned long long int) timePtr[6] << 8 )
641 617 + ( (unsigned long long int) timePtr[7] );
642 618 return acquisitionTimeAslong;
643 619 }
644 620
645 621 void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
646 622 ring_node_sm *node_for_averaging, ring_node_sm *ringNode,
647 623 unsigned long long int time )
648 624 {
649 625 unsigned char *timePtr;
650 626 unsigned char *coarseTimePtr;
651 627 unsigned char *fineTimePtr;
652 628 rtems_status_code status_code;
653 629
654 630 timePtr = (unsigned char *) &time;
655 631 coarseTimePtr = (unsigned char *) &node_for_averaging->coarseTime;
656 632 fineTimePtr = (unsigned char *) &node_for_averaging->fineTime;
657 633
658 634 *nb_sm = *nb_sm + 1;
659 635 if (*nb_sm == nb_sm_before_avf)
660 636 {
661 637 node_for_averaging = ringNode;
662 638 coarseTimePtr[0] = timePtr[2];
663 639 coarseTimePtr[1] = timePtr[3];
664 640 coarseTimePtr[2] = timePtr[4];
665 641 coarseTimePtr[3] = timePtr[5];
666 642 fineTimePtr[2] = timePtr[6];
667 643 fineTimePtr[3] = timePtr[7];
668 644 if (rtems_event_send( avf_task_id, RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
669 645 {
670 646 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
671 647 }
672 648 *nb_sm = 0;
673 649 }
674 650 }
675 651
676 652 unsigned char getSID( rtems_event_set event )
677 653 {
678 654 unsigned char sid;
679 655
680 656 rtems_event_set eventSetBURST;
681 657 rtems_event_set eventSetSBM;
682 658
683 659 //******
684 660 // BURST
685 661 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
686 662 | RTEMS_EVENT_BURST_BP1_F1
687 663 | RTEMS_EVENT_BURST_BP2_F0
688 664 | RTEMS_EVENT_BURST_BP2_F1;
689 665
690 666 //****
691 667 // SBM
692 668 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
693 669 | RTEMS_EVENT_SBM_BP1_F1
694 670 | RTEMS_EVENT_SBM_BP2_F0
695 671 | RTEMS_EVENT_SBM_BP2_F1;
696 672
697 673 if (event & eventSetBURST)
698 674 {
699 675 sid = SID_BURST_BP1_F0;
700 676 }
701 677 else if (event & eventSetSBM)
702 678 {
703 679 sid = SID_SBM1_BP1_F0;
704 680 }
705 681 else
706 682 {
707 683 sid = 0;
708 684 }
709 685
710 686 return sid;
711 687 }
712 688
@@ -1,1643 +1,1347
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 //*****************
13 // waveform headers
14 // SWF
15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
16 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
17 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
18 // CWF
19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ];
20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ];
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ];
22 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ];
23 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ];
24
25 12 //***************
26 13 // waveform rings
27 14 // F0
28 15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
29 16 ring_node *current_ring_node_f0;
30 17 ring_node *ring_node_to_send_swf_f0;
31 18 // F1
32 19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
33 20 ring_node *current_ring_node_f1;
34 21 ring_node *ring_node_to_send_swf_f1;
35 22 ring_node *ring_node_to_send_cwf_f1;
36 23 // F2
37 24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
38 25 ring_node *current_ring_node_f2;
39 26 ring_node *ring_node_to_send_swf_f2;
40 27 ring_node *ring_node_to_send_cwf_f2;
41 28 // F3
42 29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
43 30 ring_node *current_ring_node_f3;
44 31 ring_node *ring_node_to_send_cwf_f3;
45 32
46 33 bool extractSWF = false;
47 34 bool swf_f0_ready = false;
48 35 bool swf_f1_ready = false;
49 36 bool swf_f2_ready = false;
50 37
51 38 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
52 39 ring_node ring_node_wf_snap_extracted;
53 40
54 41 //*********************
55 42 // Interrupt SubRoutine
56 43
57 44 void reset_extractSWF( void )
58 45 {
59 46 extractSWF = false;
60 47 swf_f0_ready = false;
61 48 swf_f1_ready = false;
62 49 swf_f2_ready = false;
63 50 }
64 51
65 void waveforms_isr_f3( void )
52 inline void waveforms_isr_f3( void )
66 53 {
67 54 rtems_status_code spare_status;
68 55
69 56 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
70 57 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
71 58 { // in modes other than STANDBY and BURST, send the CWF_F3 data
72 59 //***
73 60 // F3
74 61 if ( (waveform_picker_regs->status & 0xc0) != 0x00 ) { // [1100 0000] check the f3 full bits
75 62 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
76 63 current_ring_node_f3 = current_ring_node_f3->next;
77 64 if ((waveform_picker_regs->status & 0x40) == 0x40){ // [0100 0000] f3 buffer 0 is full
78 65 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
79 66 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
80 67 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
81 68 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008840; // [1000 1000 0100 0000]
82 69 }
83 70 else if ((waveform_picker_regs->status & 0x80) == 0x80){ // [1000 0000] f3 buffer 1 is full
84 71 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
85 72 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
86 73 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
87 74 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008880; // [1000 1000 1000 0000]
88 75 }
89 76 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
90 77 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
91 78 }
92 79 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2);
93 80 }
94 81 }
95 82 }
96 83
97 void waveforms_isr_normal( void )
84 inline void waveforms_isr_normal( void )
98 85 {
99 86 rtems_status_code status;
100 87
101 88 if ( ( (waveform_picker_regs->status & 0x30) != 0x00 ) // [0011 0000] check the f2 full bits
102 89 && ( (waveform_picker_regs->status & 0x0c) != 0x00 ) // [0000 1100] check the f1 full bits
103 90 && ( (waveform_picker_regs->status & 0x03) != 0x00 )) // [0000 0011] check the f0 full bits
104 91 {
105 92 //***
106 93 // F0
107 94 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
108 95 current_ring_node_f0 = current_ring_node_f0->next;
109 96 if ( (waveform_picker_regs->status & 0x01) == 0x01)
110 97 {
111 98
112 99 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
113 100 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
114 101 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
115 102 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
116 103 }
117 104 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
118 105 {
119 106 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
120 107 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
121 108 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
122 109 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
123 110 }
124 111
125 112 //***
126 113 // F1
127 114 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
128 115 current_ring_node_f1 = current_ring_node_f1->next;
129 116 if ( (waveform_picker_regs->status & 0x04) == 0x04)
130 117 {
131 118 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
132 119 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
133 120 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
134 121 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
135 122 }
136 123 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
137 124 {
138 125 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
139 126 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
140 127 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
141 128 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
142 129 }
143 130
144 131 //***
145 132 // F2
146 133 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
147 134 current_ring_node_f2 = current_ring_node_f2->next;
148 135 if ( (waveform_picker_regs->status & 0x10) == 0x10)
149 136 {
150 137 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
151 138 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
152 139 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
153 140 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
154 141 }
155 142 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
156 143 {
157 144 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
158 145 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
159 146 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
160 147 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
161 148 }
162 149 //
163 150 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
164 151 if ( status != RTEMS_SUCCESSFUL)
165 152 {
166 153 status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
167 154 }
168 155 }
169 156 }
170 157
171 void waveforms_isr_burst( void )
158 inline void waveforms_isr_burst( void )
172 159 {
173 160 rtems_status_code spare_status;
174 161
175 162 if ( (waveform_picker_regs->status & 0x30) != 0 ){ // [0100] check the f2 full bit
176 163 // (1) change the receiving buffer for the waveform picker
177 164 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
178 165 current_ring_node_f2 = current_ring_node_f2->next;
179 166 if ( (waveform_picker_regs->status & 0x10) == 0x10)
180 167 {
181 168 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
182 169 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
183 170 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
184 171 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
185 172 }
186 173 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
187 174 {
188 175 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
189 176 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
190 177 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
191 178 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
192 179 }
193 180 // (2) send an event for the waveforms transmission
194 181 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
195 182 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
196 183 }
197 184 }
198 185 }
199 186
200 void waveforms_isr_sbm1( void )
187 inline void waveforms_isr_sbm1( void )
201 188 {
202 189 rtems_status_code status;
203 rtems_status_code spare_status;
204 190
205 191 //***
206 192 // F1
207 193 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bits
208 194 // (1) change the receiving buffer for the waveform picker
209 195 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
210 196 current_ring_node_f1 = current_ring_node_f1->next;
211 197 if ( (waveform_picker_regs->status & 0x04) == 0x04)
212 198 {
213 199 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
214 200 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
215 201 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
216 202 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
217 203 }
218 204 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
219 205 {
220 206 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
221 207 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
222 208 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
223 209 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
224 210 }
225 211 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
226 212 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
227 213 }
228 214
229 215 //***
230 216 // F0
231 217 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bits
232 218 swf_f0_ready = true;
233 219 // change f0 buffer
234 220 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
235 221 current_ring_node_f0 = current_ring_node_f0->next;
236 222 if ( (waveform_picker_regs->status & 0x01) == 0x01)
237 223 {
238 224
239 225 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
240 226 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
241 227 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
242 228 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
243 229 }
244 230 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
245 231 {
246 232 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
247 233 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
248 234 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
249 235 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
250 236 }
251 237 }
252 238
253 239 //***
254 240 // F2
255 241 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bits
256 242 swf_f2_ready = true;
257 243 // change f2 buffer
258 244 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
259 245 current_ring_node_f2 = current_ring_node_f2->next;
260 246 if ( (waveform_picker_regs->status & 0x10) == 0x10)
261 247 {
262 248 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
263 249 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
264 250 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
265 251 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
266 252 }
267 253 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
268 254 {
269 255 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
270 256 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
271 257 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
272 258 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
273 259 }
274 // start the snapshots transmission
275 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL)
276 {
277 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
278 }
279 260 }
280 261 }
281 262
282 void waveforms_isr_sbm2( void )
263 inline void waveforms_isr_sbm2( void )
283 264 {
284 265 rtems_status_code status;
285 266
286 267 //***
287 268 // F2
288 269 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bit
289 270 // (1) change the receiving buffer for the waveform picker
290 271 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
291 272 current_ring_node_f2 = current_ring_node_f2->next;
292 273 if ( (waveform_picker_regs->status & 0x10) == 0x10)
293 274 {
294 275 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
295 276 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
296 277 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
297 278 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
298 279 }
299 280 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
300 281 {
301 282 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
302 283 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
303 284 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
304 285 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
305 286 }
306 287 // (2) send an event for the waveforms transmission
307 288 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
308 289 }
309 290
310 291 //***
311 292 // F0
312 293 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bit
313 294 swf_f0_ready = true;
314 295 // change f0 buffer
315 296 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
316 297 current_ring_node_f0 = current_ring_node_f0->next;
317 298 if ( (waveform_picker_regs->status & 0x01) == 0x01)
318 299 {
319 300
320 301 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
321 302 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
322 303 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
323 304 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
324 305 }
325 306 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
326 307 {
327 308 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
328 309 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
329 310 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
330 311 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
331 312 }
332 313 }
333 314
334 315 //***
335 316 // F1
336 317 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bit
337 318 swf_f1_ready = true;
338 319 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
339 320 current_ring_node_f1 = current_ring_node_f1->next;
340 321 if ( (waveform_picker_regs->status & 0x04) == 0x04)
341 322 {
342 323 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
343 324 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
344 325 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
345 326 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
346 327 }
347 328 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
348 329 {
349 330 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
350 331 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
351 332 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
352 333 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
353 334 }
354 335 }
355 336 }
356 337
357 338 rtems_isr waveforms_isr( rtems_vector_number vector )
358 339 {
359 340 /** This is the interrupt sub routine called by the waveform picker core.
360 341 *
361 342 * This ISR launch different actions depending mainly on two pieces of information:
362 343 * 1. the values read in the registers of the waveform picker.
363 344 * 2. the current LFR mode.
364 345 *
365 346 */
366 347
367 348 // STATUS
368 349 // new error error buffer full
369 350 // 15 14 13 12 11 10 9 8
370 351 // f3 f2 f1 f0 f3 f2 f1 f0
371 352 //
372 353 // ready buffer
373 354 // 7 6 5 4 3 2 1 0
374 355 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
375 356
376 357 rtems_status_code spare_status;
377 358
378 359 waveforms_isr_f3();
379 360
380 361 if ( (waveform_picker_regs->status & 0xff00) != 0x00) // [1111 1111 0000 0000] check the error bits
381 362 {
382 363 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
383 364 }
384 365
385 366 switch(lfrCurrentMode)
386 367 {
387 368 //********
388 369 // STANDBY
389 370 case(LFR_MODE_STANDBY):
390 371 break;
391 372
392 373 //******
393 374 // NORMAL
394 375 case(LFR_MODE_NORMAL):
395 376 waveforms_isr_normal();
396 377 break;
397 378
398 379 //******
399 380 // BURST
400 381 case(LFR_MODE_BURST):
401 382 waveforms_isr_burst();
402 383 break;
403 384
404 385 //*****
405 386 // SBM1
406 387 case(LFR_MODE_SBM1):
407 388 waveforms_isr_sbm1();
408 389 break;
409 390
410 391 //*****
411 392 // SBM2
412 393 case(LFR_MODE_SBM2):
413 394 waveforms_isr_sbm2();
414 395 break;
415 396
416 397 //********
417 398 // DEFAULT
418 399 default:
419 400 break;
420 401 }
421 402 }
422 403
423 404 //************
424 405 // RTEMS TASKS
425 406
426 407 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
427 408 {
428 409 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
429 410 *
430 411 * @param unused is the starting argument of the RTEMS task
431 412 *
432 413 * The following data packets are sent by this task:
433 414 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
434 415 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
435 416 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
436 417 *
437 418 */
438 419
439 420 rtems_event_set event_out;
440 421 rtems_id queue_id;
441 422 rtems_status_code status;
442 423 bool resynchronisationEngaged;
424 ring_node *ring_node_wf_snap_extracted_ptr;
425
426 ring_node_wf_snap_extracted_ptr = (ring_node *) &ring_node_wf_snap_extracted;
443 427
444 428 resynchronisationEngaged = false;
445 429
446 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
447 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
448 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
449
450 430 status = get_message_queue_id_send( &queue_id );
451 431 if (status != RTEMS_SUCCESSFUL)
452 432 {
453 433 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
454 434 }
455 435
456 436 BOOT_PRINTF("in WFRM ***\n")
457 437
458 438 while(1){
459 439 // wait for an RTEMS_EVENT
460 440 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
461 441 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
462 442 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
463 443 if(resynchronisationEngaged == false)
464 444 { // engage resynchronisation
465 snapshot_resynchronization( (unsigned char *) ring_node_to_send_swf_f0->buffer_address);
445 snapshot_resynchronization( (unsigned char *) ring_node_to_send_swf_f0->coarseTime );
466 446 resynchronisationEngaged = true;
467 447 }
468 448 else
469 449 { // reset delta_snapshot to the nominal value
470 450 PRINTF("no resynchronisation, reset delta_snapshot to the nominal value\n")
471 451 set_wfp_delta_snapshot();
472 452 resynchronisationEngaged = false;
473 453 }
474 454 //
475 455
476 456 if (event_out == RTEMS_EVENT_MODE_NORMAL)
477 457 {
478 458 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
479 send_waveform_SWF( ring_node_to_send_swf_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
480 send_waveform_SWF( ring_node_to_send_swf_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
481 send_waveform_SWF( ring_node_to_send_swf_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
459 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
460 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
461 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
462 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
463 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
464 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
482 465 }
483 466 if (event_out == RTEMS_EVENT_MODE_SBM1)
484 467 {
485 468 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
486 send_waveform_SWF( ring_node_to_send_swf_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
487 send_waveform_SWF( &ring_node_wf_snap_extracted, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
488 send_waveform_SWF( ring_node_to_send_swf_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
469 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
470 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F1;
471 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
472 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
473 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
474 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
489 475 }
490 476 if (event_out == RTEMS_EVENT_MODE_SBM2)
491 477 {
492 478 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
493 send_waveform_SWF( ring_node_to_send_swf_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
494 send_waveform_SWF( ring_node_to_send_swf_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
495 send_waveform_SWF( &ring_node_wf_snap_extracted, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
479 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
480 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
481 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F2;
482 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
483 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
484 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
496 485 }
497 486 }
498 487 }
499 488
500 489 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
501 490 {
502 491 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
503 492 *
504 493 * @param unused is the starting argument of the RTEMS task
505 494 *
506 495 * The following data packet is sent by this task:
507 496 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
508 497 *
509 498 */
510 499
511 500 rtems_event_set event_out;
512 501 rtems_id queue_id;
513 502 rtems_status_code status;
514
515 init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 );
516 init_header_continuous_cwf3_light_table( headerCWF_F3_light );
503 ring_node ring_node_cwf3_light;
517 504
518 505 status = get_message_queue_id_send( &queue_id );
519 506 if (status != RTEMS_SUCCESSFUL)
520 507 {
521 508 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
522 509 }
523 510
511 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
512
513 // init the ring_node_cwf3_light structure
514 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
515 ring_node_cwf3_light.coarseTime = 0x00;
516 ring_node_cwf3_light.fineTime = 0x00;
517 ring_node_cwf3_light.next = NULL;
518 ring_node_cwf3_light.previous = NULL;
519 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
520 ring_node_cwf3_light.status = 0x00;
521
524 522 BOOT_PRINTF("in CWF3 ***\n")
525 523
526 524 while(1){
527 525 // wait for an RTEMS_EVENT
528 526 rtems_event_receive( RTEMS_EVENT_0,
529 527 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
530 528 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
531 529 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
532 530 {
533 531 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
534 532 {
535 533 PRINTF("send CWF_LONG_F3\n")
536 send_waveform_CWF( ring_node_to_send_cwf_f3,
537 SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
534 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
535 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf_f2, sizeof( ring_node* ) );
538 536 }
539 537 else
540 538 {
541 539 PRINTF("send CWF_F3 (light)\n")
542 send_waveform_CWF3_light( ring_node_to_send_cwf_f3,
543 headerCWF_F3_light, queue_id );
540 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_F3;
541 send_waveform_CWF3_light( ring_node_to_send_cwf_f3, &ring_node_cwf3_light, queue_id );
544 542 }
545 543
546 544 }
547 545 else
548 546 {
549 547 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
550 548 }
551 549 }
552 550 }
553 551
554 552 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
555 553 {
556 554 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
557 555 *
558 556 * @param unused is the starting argument of the RTEMS task
559 557 *
560 558 * The following data packet is sent by this function:
561 559 * - TM_LFR_SCIENCE_BURST_CWF_F2
562 560 * - TM_LFR_SCIENCE_SBM2_CWF_F2
563 561 *
564 562 */
565 563
566 564 rtems_event_set event_out;
567 565 rtems_id queue_id;
568 566 rtems_status_code status;
569 567
570 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
571 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
572
573 568 status = get_message_queue_id_send( &queue_id );
574 569 if (status != RTEMS_SUCCESSFUL)
575 570 {
576 571 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
577 572 }
578 573
579 574 BOOT_PRINTF("in CWF2 ***\n")
580 575
581 576 while(1){
582 577 // wait for an RTEMS_EVENT
583 578 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
584 579 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
585 580 if (event_out == RTEMS_EVENT_MODE_BURST)
586 581 {
587 send_waveform_CWF( ring_node_to_send_cwf_f2, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
582 // send_waveform_CWF( ring_node_to_send_cwf_f2, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
583 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
584 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf_f2, sizeof( ring_node* ) );
588 585 }
589 586 if (event_out == RTEMS_EVENT_MODE_SBM2)
590 587 {
591 send_waveform_CWF( ring_node_to_send_cwf_f2, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
588 // send_waveform_CWF( ring_node_to_send_cwf_f2, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
589 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
590 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf_f2, sizeof( ring_node* ) );
592 591 // launch snapshot extraction if needed
593 592 if (extractSWF == true)
594 593 {
595 594 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
596 595 // extract the snapshot
597 596 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 );
598 597 // send the snapshot when built
599 598 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
600 599 extractSWF = false;
601 600 }
602 601 if (swf_f0_ready && swf_f1_ready)
603 602 {
604 603 extractSWF = true;
605 604 swf_f0_ready = false;
606 605 swf_f1_ready = false;
607 606 }
608 607 }
609 608 }
610 609 }
611 610
612 611 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
613 612 {
614 613 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
615 614 *
616 615 * @param unused is the starting argument of the RTEMS task
617 616 *
618 617 * The following data packet is sent by this function:
619 618 * - TM_LFR_SCIENCE_SBM1_CWF_F1
620 619 *
621 620 */
622 621
623 622 rtems_event_set event_out;
624 623 rtems_id queue_id;
625 624 rtems_status_code status;
626 625
627 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
626 // init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
628 627
629 628 status = get_message_queue_id_send( &queue_id );
630 629 if (status != RTEMS_SUCCESSFUL)
631 630 {
632 631 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
633 632 }
634 633
635 634 BOOT_PRINTF("in CWF1 ***\n")
636 635
637 636 while(1){
638 637 // wait for an RTEMS_EVENT
639 638 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
640 639 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
641 send_waveform_CWF( ring_node_to_send_cwf_f1, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
640 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
641 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf_f1, sizeof( ring_node* ) );
642 642 // launch snapshot extraction if needed
643 643 if (extractSWF == true)
644 644 {
645 645 ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1;
646 646 // launch the snapshot extraction
647 647 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
648 648 extractSWF = false;
649 649 }
650 650 if (swf_f0_ready == true)
651 651 {
652 652 extractSWF = true;
653 653 swf_f0_ready = false; // this step shall be executed only one time
654 654 }
655 655 if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction
656 656 {
657 657 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
658 658 swf_f1_ready = false;
659 659 swf_f2_ready = false;
660 660 }
661 661 }
662 662 }
663 663
664 664 rtems_task swbd_task(rtems_task_argument argument)
665 665 {
666 666 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
667 667 *
668 668 * @param unused is the starting argument of the RTEMS task
669 669 *
670 670 */
671 671
672 672 rtems_event_set event_out;
673 673
674 674 BOOT_PRINTF("in SWBD ***\n")
675 675
676 676 while(1){
677 677 // wait for an RTEMS_EVENT
678 678 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
679 679 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
680 680 if (event_out == RTEMS_EVENT_MODE_SBM1)
681 681 {
682 682 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 );
683 683 swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent
684 684 }
685 685 else
686 686 {
687 687 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
688 688 }
689 689 }
690 690 }
691 691
692 692 //******************
693 693 // general functions
694 694
695 695 void WFP_init_rings( void )
696 696 {
697 697 // F0 RING
698 init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 );
698 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
699 699 // F1 RING
700 init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 );
700 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
701 701 // F2 RING
702 init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 );
702 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
703 703 // F3 RING
704 init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 );
704 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
705 705
706 706 ring_node_wf_snap_extracted.buffer_address = (int) wf_snap_extracted;
707 707
708 708 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
709 709 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
710 710 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
711 711 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
712 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
713 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
714 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
715 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
716
712 717 }
713 718
714 void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] )
719 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
715 720 {
716 721 unsigned char i;
717 722
718 waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ];
719 waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ];
720 waveform_ring[0].buffer_address = (int) &wfrm[0];
723 //***************
724 // BUFFER ADDRESS
725 for(i=0; i<nbNodes; i++)
726 {
727 ring[i].coarseTime = 0x00;
728 ring[i].fineTime = 0x00;
729 ring[i].sid = 0x00;
730 ring[i].status = 0x00;
731 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
732 }
721 733
722 waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ];
723 waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ];
724 waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ];
734 //*****
735 // NEXT
736 ring[nbNodes-1].next = (ring_node*) &ring[ 0 ];
737 for(i=0; i<nbNodes-1; i++)
738 {
739 ring[i].next = (ring_node*) &ring[ i + 1 ];
740 }
725 741
726 for(i=1; i<nbNodes-1; i++)
742 //*********
743 // PREVIOUS
744 ring[0].previous = (ring_node*) &ring[ nbNodes - 1 ];
745 for(i=1; i<nbNodes; i++)
727 746 {
728 waveform_ring[i].next = (ring_node*) &waveform_ring[ i + 1 ];
729 waveform_ring[i].previous = (ring_node*) &waveform_ring[ i - 1 ];
730 waveform_ring[i].buffer_address = (int) &wfrm[ i * WFRM_BUFFER ];
747 ring[i].previous = (ring_node*) &ring[ i - 1 ];
731 748 }
732 749 }
733 750
734 751 void WFP_reset_current_ring_nodes( void )
735 752 {
736 753 current_ring_node_f0 = waveform_ring_f0;
737 754 ring_node_to_send_swf_f0 = waveform_ring_f0;
738 755
739 756 current_ring_node_f1 = waveform_ring_f1;
740 757 ring_node_to_send_cwf_f1 = waveform_ring_f1;
741 758 ring_node_to_send_swf_f1 = waveform_ring_f1;
742 759
743 760 current_ring_node_f2 = waveform_ring_f2;
744 761 ring_node_to_send_cwf_f2 = waveform_ring_f2;
745 762 ring_node_to_send_swf_f2 = waveform_ring_f2;
746 763
747 764 current_ring_node_f3 = waveform_ring_f3;
748 765 ring_node_to_send_cwf_f3 = waveform_ring_f3;
749 766 }
750 767
751 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
752 {
753 unsigned char i;
754 int return_value;
755
756 return_value = LFR_SUCCESSFUL;
757
758 for (i=0; i<7; i++)
759 {
760 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
761 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
762 headerSWF[ i ].reserved = DEFAULT_RESERVED;
763 headerSWF[ i ].userApplication = CCSDS_USER_APP;
764 headerSWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
765 headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
766 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
767 if (i == 6)
768 {
769 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
770 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
771 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
772 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 );
773 }
774 else
775 {
776 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
777 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
778 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
779 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 );
780 }
781 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
782 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
783 headerSWF[ i ].pktNr = i+1; // PKT_NR
784 // DATA FIELD HEADER
785 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
786 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
787 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
788 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
789 // AUXILIARY DATA HEADER
790 headerSWF[ i ].time[0] = 0x00;
791 headerSWF[ i ].time[0] = 0x00;
792 headerSWF[ i ].time[0] = 0x00;
793 headerSWF[ i ].time[0] = 0x00;
794 headerSWF[ i ].time[0] = 0x00;
795 headerSWF[ i ].time[0] = 0x00;
796 headerSWF[ i ].sid = sid;
797 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
798 }
799
800 return return_value;
801 }
802
803 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
804 {
805 unsigned int i;
806 int return_value;
807
808 return_value = LFR_SUCCESSFUL;
809
810 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++)
811 {
812 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
813 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
814 headerCWF[ i ].reserved = DEFAULT_RESERVED;
815 headerCWF[ i ].userApplication = CCSDS_USER_APP;
816 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
817 {
818 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
819 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
820 }
821 else
822 {
823 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
824 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
825 }
826 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
827 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
828 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
829 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
830 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF );
831 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
832 // DATA FIELD HEADER
833 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
834 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
835 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
836 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
837 // AUXILIARY DATA HEADER
838 headerCWF[ i ].sid = sid;
839 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
840 headerCWF[ i ].time[0] = 0x00;
841 headerCWF[ i ].time[0] = 0x00;
842 headerCWF[ i ].time[0] = 0x00;
843 headerCWF[ i ].time[0] = 0x00;
844 headerCWF[ i ].time[0] = 0x00;
845 headerCWF[ i ].time[0] = 0x00;
846 }
847
848 return return_value;
849 }
850
851 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
852 {
853 unsigned int i;
854 int return_value;
855
856 return_value = LFR_SUCCESSFUL;
857
858 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++)
859 {
860 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
861 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
862 headerCWF[ i ].reserved = DEFAULT_RESERVED;
863 headerCWF[ i ].userApplication = CCSDS_USER_APP;
864
865 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
866 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
867
868 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
869 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
870 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
871 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
872 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
873
874 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
875 // DATA FIELD HEADER
876 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
877 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
878 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
879 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
880 // AUXILIARY DATA HEADER
881 headerCWF[ i ].sid = SID_NORM_CWF_F3;
882 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
883 headerCWF[ i ].time[0] = 0x00;
884 headerCWF[ i ].time[0] = 0x00;
885 headerCWF[ i ].time[0] = 0x00;
886 headerCWF[ i ].time[0] = 0x00;
887 headerCWF[ i ].time[0] = 0x00;
888 headerCWF[ i ].time[0] = 0x00;
889 }
890
891 return return_value;
892 }
893
894 int send_waveform_SWF( ring_node *ring_node_to_send, unsigned int sid,
895 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
896 {
897 /** This function sends SWF CCSDS packets (F2, F1 or F0).
898 *
899 * @param waveform points to the buffer containing the data that will be send.
900 * @param sid is the source identifier of the data that will be sent.
901 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
902 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
903 * contain information to setup the transmission of the data packets.
904 *
905 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
906 *
907 */
908
909 unsigned int i;
910 int ret;
911 unsigned int coarseTime;
912 unsigned int fineTime;
913 rtems_status_code status;
914 spw_ioctl_pkt_send spw_ioctl_send_SWF;
915 int *dataPtr;
916
917 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
918 spw_ioctl_send_SWF.options = 0;
919
920 ret = LFR_DEFAULT;
921
922 coarseTime = ring_node_to_send->coarseTime;
923 fineTime = ring_node_to_send->fineTime;
924 dataPtr = (int*) ring_node_to_send->buffer_address;
925
926 for (i=0; i<7; i++) // send waveform
927 {
928 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
929 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
930 // BUILD THE DATA
931 if (i==6) {
932 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
933 }
934 else {
935 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
936 }
937 // SET PACKET SEQUENCE COUNTER
938 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
939 // SET PACKET TIME
940 compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime );
941 //
942 headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0];
943 headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1];
944 headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2];
945 headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3];
946 headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4];
947 headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5];
948 // SEND PACKET
949 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
950 if (status != RTEMS_SUCCESSFUL) {
951 printf("%d-%d, ERR %d\n", sid, i, (int) status);
952 ret = LFR_DEFAULT;
953 }
954 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
955 }
956
957 return ret;
958 }
959
960 int send_waveform_CWF(ring_node *ring_node_to_send, unsigned int sid,
961 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
962 {
963 /** This function sends CWF CCSDS packets (F2, F1 or F0).
964 *
965 * @param waveform points to the buffer containing the data that will be send.
966 * @param sid is the source identifier of the data that will be sent.
967 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
968 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
969 * contain information to setup the transmission of the data packets.
970 *
971 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
972 *
973 */
974
975 unsigned int i;
976 int ret;
977 unsigned int coarseTime;
978 unsigned int fineTime;
979 rtems_status_code status;
980 spw_ioctl_pkt_send spw_ioctl_send_CWF;
981 int *dataPtr;
982
983 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
984 spw_ioctl_send_CWF.options = 0;
985
986 ret = LFR_DEFAULT;
987
988 coarseTime = ring_node_to_send->coarseTime;
989 fineTime = ring_node_to_send->fineTime;
990 dataPtr = (int*) ring_node_to_send->buffer_address;
991
992 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
993 {
994 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
995 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
996 // BUILD THE DATA
997 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
998 // SET PACKET SEQUENCE COUNTER
999 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
1000 // SET PACKET TIME
1001 compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime);
1002 //
1003 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
1004 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
1005 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
1006 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
1007 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
1008 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
1009 // SEND PACKET
1010 if (sid == SID_NORM_CWF_LONG_F3)
1011 {
1012 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
1013 if (status != RTEMS_SUCCESSFUL) {
1014 printf("%d-%d, ERR %d\n", sid, i, (int) status);
1015 ret = LFR_DEFAULT;
1016 }
1017 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
1018 }
1019 else
1020 {
1021 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
1022 if (status != RTEMS_SUCCESSFUL) {
1023 printf("%d-%d, ERR %d\n", sid, i, (int) status);
1024 ret = LFR_DEFAULT;
1025 }
1026 }
1027 }
1028
1029 return ret;
1030 }
1031
1032 int send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id )
768 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
1033 769 {
1034 770 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1035 771 *
1036 772 * @param waveform points to the buffer containing the data that will be send.
1037 773 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1038 774 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1039 775 * contain information to setup the transmission of the data packets.
1040 776 *
1041 777 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1042 778 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1043 779 *
1044 780 */
1045 781
1046 782 unsigned int i;
1047 783 int ret;
1048 unsigned int coarseTime;
1049 unsigned int fineTime;
1050 784 rtems_status_code status;
1051 785 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1052 786 char *sample;
1053 787 int *dataPtr;
1054 788
1055 789 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
1056 790 spw_ioctl_send_CWF.options = 0;
1057 791
1058 792 ret = LFR_DEFAULT;
1059 793
1060 coarseTime = ring_node_to_send->coarseTime;
1061 fineTime = ring_node_to_send->fineTime;
1062 794 dataPtr = (int*) ring_node_to_send->buffer_address;
1063 795
796 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
797 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
798
1064 799 //**********************
1065 800 // BUILD CWF3_light DATA
1066 801 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
1067 802 {
1068 803 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
1069 804 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
1070 805 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
1071 806 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
1072 807 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
1073 808 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
1074 809 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
1075 810 }
1076 811
1077 //*********************
1078 // SEND CWF3_light DATA
1079 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1080 {
1081 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1082 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
1083 // BUILD THE DATA
1084 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1085 // SET PACKET SEQUENCE COUNTER
1086 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
1087 // SET PACKET TIME
1088 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime );
1089 //
1090 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
1091 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
1092 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
1093 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
1094 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
1095 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
1096 // SEND PACKET
1097 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
1098 if (status != RTEMS_SUCCESSFUL) {
1099 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
1100 ret = LFR_DEFAULT;
1101 }
1102 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
812 // SEND PACKET
813 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
814 if (status != RTEMS_SUCCESSFUL) {
815 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
816 ret = LFR_DEFAULT;
1103 817 }
1104 818
1105 819 return ret;
1106 820 }
1107 821
1108 int send_ring_node_CWF( ring_node *ring_node_to_send )
1109 {
1110 int status;
1111
1112 status = LFR_SUCCESSFUL;
1113 // status = rtems_message_queue_send( queue_id, ring_node_to_send, 4 );
1114
1115 return status;
1116 }
1117
1118 822 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
1119 823 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
1120 824 {
1121 825 unsigned long long int acquisitionTimeAsLong;
1122 826 unsigned char localAcquisitionTime[6];
1123 827 double deltaT;
1124 828
1125 829 deltaT = 0.;
1126 830
1127 831 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
1128 832 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
1129 833 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
1130 834 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
1131 835 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
1132 836 localAcquisitionTime[5] = (unsigned char) ( fineTime );
1133 837
1134 838 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
1135 839 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
1136 840 + ( (unsigned long long int) localAcquisitionTime[2] << 24 )
1137 841 + ( (unsigned long long int) localAcquisitionTime[3] << 16 )
1138 842 + ( (unsigned long long int) localAcquisitionTime[4] << 8 )
1139 843 + ( (unsigned long long int) localAcquisitionTime[5] );
1140 844
1141 845 switch( sid )
1142 846 {
1143 847 case SID_NORM_SWF_F0:
1144 848 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
1145 849 break;
1146 850
1147 851 case SID_NORM_SWF_F1:
1148 852 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
1149 853 break;
1150 854
1151 855 case SID_NORM_SWF_F2:
1152 856 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
1153 857 break;
1154 858
1155 859 case SID_SBM1_CWF_F1:
1156 860 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
1157 861 break;
1158 862
1159 863 case SID_SBM2_CWF_F2:
1160 864 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
1161 865 break;
1162 866
1163 867 case SID_BURST_CWF_F2:
1164 868 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
1165 869 break;
1166 870
1167 871 case SID_NORM_CWF_F3:
1168 872 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
1169 873 break;
1170 874
1171 875 case SID_NORM_CWF_LONG_F3:
1172 876 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
1173 877 break;
1174 878
1175 879 default:
1176 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid)
880 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
1177 881 deltaT = 0.;
1178 882 break;
1179 883 }
1180 884
1181 885 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
1182 886 //
1183 887 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
1184 888 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
1185 889 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
1186 890 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
1187 891 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
1188 892 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
1189 893
1190 894 }
1191 895
1192 896 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel )
1193 897 {
1194 898 unsigned int i;
1195 899 unsigned long long int centerTime_asLong;
1196 900 unsigned long long int acquisitionTimeF0_asLong;
1197 901 unsigned long long int acquisitionTime_asLong;
1198 902 unsigned long long int bufferAcquisitionTime_asLong;
1199 903 unsigned char *ptr1;
1200 904 unsigned char *ptr2;
1201 905 unsigned char *timeCharPtr;
1202 906 unsigned char nb_ring_nodes;
1203 907 unsigned long long int frequency_asLong;
1204 908 unsigned long long int nbTicksPerSample_asLong;
1205 909 unsigned long long int nbSamplesPart1_asLong;
1206 910 unsigned long long int sampleOffset_asLong;
1207 911
1208 912 unsigned int deltaT_F0;
1209 913 unsigned int deltaT_F1;
1210 914 unsigned long long int deltaT_F2;
1211 915
1212 916 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1213 917 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
1214 918 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
1215 919 sampleOffset_asLong = 0x00;
1216 920
1217 921 // (1) get the f0 acquisition time
1218 922 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
1219 923
1220 924 // (2) compute the central reference time
1221 925 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
1222 926
1223 927 // (3) compute the acquisition time of the current snapshot
1224 928 switch(frequencyChannel)
1225 929 {
1226 930 case 1: // 1 is for F1 = 4096 Hz
1227 931 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
1228 932 nb_ring_nodes = NB_RING_NODES_F1;
1229 933 frequency_asLong = 4096;
1230 934 nbTicksPerSample_asLong = 16; // 65536 / 4096;
1231 935 break;
1232 936 case 2: // 2 is for F2 = 256 Hz
1233 937 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
1234 938 nb_ring_nodes = NB_RING_NODES_F2;
1235 939 frequency_asLong = 256;
1236 940 nbTicksPerSample_asLong = 256; // 65536 / 256;
1237 941 break;
1238 942 default:
1239 943 acquisitionTime_asLong = centerTime_asLong;
1240 944 frequency_asLong = 256;
1241 945 nbTicksPerSample_asLong = 256;
1242 946 break;
1243 947 }
1244 948
1245 949 //****************************************************************************
1246 950 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
1247 951 for (i=0; i<nb_ring_nodes; i++)
1248 952 {
1249 953 PRINTF1("%d ... ", i)
1250 954 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) ring_node_to_send->coarseTime );
1251 955 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
1252 956 {
1253 957 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
1254 958 break;
1255 959 }
1256 960 ring_node_to_send = ring_node_to_send->previous;
1257 961 }
1258 962
1259 963 // (5) compute the number of samples to take in the current buffer
1260 964 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
1261 965 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
1262 966 PRINTF2("sampleOffset_asLong = %llx, nbSamplesPart1_asLong = %llx\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1263 967
1264 968 // (6) compute the final acquisition time
1265 969 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
1266 970 sampleOffset_asLong * nbTicksPerSample_asLong;
1267 971
1268 972 // (7) copy the acquisition time at the beginning of the extrated snapshot
1269 973 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1270 974 // fine time
1271 975 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.fineTime;
1272 976 ptr2[2] = ptr1[ 4 + 2 ];
1273 977 ptr2[3] = ptr1[ 5 + 2 ];
1274 978 // coarse time
1275 979 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.coarseTime;
1276 980 ptr2[0] = ptr1[ 0 + 2 ];
1277 981 ptr2[1] = ptr1[ 1 + 2 ];
1278 982 ptr2[2] = ptr1[ 2 + 2 ];
1279 983 ptr2[3] = ptr1[ 3 + 2 ];
1280 984
1281 985 // re set the synchronization bit
1282 986 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
1283 987 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
1284 988
1285 989 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
1286 990 {
1287 991 nbSamplesPart1_asLong = 0;
1288 992 }
1289 993 // copy the part 1 of the snapshot in the extracted buffer
1290 994 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1291 995 {
1292 996 wf_snap_extracted[i] =
1293 997 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
1294 998 }
1295 999 // copy the part 2 of the snapshot in the extracted buffer
1296 1000 ring_node_to_send = ring_node_to_send->next;
1297 1001 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1298 1002 {
1299 1003 wf_snap_extracted[i] =
1300 1004 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
1301 1005 }
1302 1006 }
1303 1007
1304 1008 void snapshot_resynchronization( unsigned char *timePtr )
1305 1009 {
1306 1010 unsigned long long int acquisitionTime;
1307 1011 unsigned long long int centerTime;
1308 1012 unsigned long long int previousTick;
1309 1013 unsigned long long int nextTick;
1310 1014 unsigned long long int deltaPreviousTick;
1311 1015 unsigned long long int deltaNextTick;
1312 1016 unsigned int deltaTickInF2;
1313 1017 double deltaPrevious;
1314 1018 double deltaNext;
1315 1019
1316 1020 acquisitionTime = get_acquisition_time( timePtr );
1317 1021
1318 1022 // compute center time
1319 1023 centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1320 1024 previousTick = centerTime - (centerTime & 0xffff);
1321 1025 nextTick = previousTick + 65536;
1322 1026
1323 1027 deltaPreviousTick = centerTime - previousTick;
1324 1028 deltaNextTick = nextTick - centerTime;
1325 1029
1326 1030 deltaPrevious = ((double) deltaPreviousTick) / 65536. * 1000.;
1327 1031 deltaNext = ((double) deltaNextTick) / 65536. * 1000.;
1328 1032
1329 1033 printf("delta previous = %f ms, delta next = %f ms\n", deltaPrevious, deltaNext);
1330 1034 printf("delta previous = %llu, delta next = %llu\n", deltaPreviousTick, deltaNextTick);
1331 1035
1332 1036 // which tick is the closest
1333 1037 if (deltaPreviousTick > deltaNextTick)
1334 1038 {
1335 1039 deltaTickInF2 = floor( (deltaNext * 256. / 1000.) ); // the division by 2 is important here
1336 1040 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + deltaTickInF2;
1337 1041 printf("correction of = + %u\n", deltaTickInF2);
1338 1042 }
1339 1043 else
1340 1044 {
1341 1045 deltaTickInF2 = floor( (deltaPrevious * 256. / 1000.) ); // the division by 2 is important here
1342 1046 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot - deltaTickInF2;
1343 1047 printf("correction of = - %u\n", deltaTickInF2);
1344 1048 }
1345 1049 }
1346 1050
1347 1051 //**************
1348 1052 // wfp registers
1349 1053 void reset_wfp_burst_enable( void )
1350 1054 {
1351 1055 /** This function resets the waveform picker burst_enable register.
1352 1056 *
1353 1057 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1354 1058 *
1355 1059 */
1356 1060
1357 1061 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1358 1062 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & 0x80;
1359 1063 }
1360 1064
1361 1065 void reset_wfp_status( void )
1362 1066 {
1363 1067 /** This function resets the waveform picker status register.
1364 1068 *
1365 1069 * All status bits are set to 0 [new_err full_err full].
1366 1070 *
1367 1071 */
1368 1072
1369 1073 waveform_picker_regs->status = 0xffff;
1370 1074 }
1371 1075
1372 1076 void reset_wfp_buffer_addresses( void )
1373 1077 {
1374 1078 // F0
1375 1079 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address; // 0x08
1376 1080 current_ring_node_f0 = current_ring_node_f0->next;
1377 1081 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1378 1082 // F1
1379 1083 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address; // 0x10
1380 1084 current_ring_node_f1 = current_ring_node_f1->next;
1381 1085 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1382 1086 // F2
1383 1087 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; // 0x18
1384 1088 current_ring_node_f2 = current_ring_node_f2->next;
1385 1089 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1386 1090 // F3
1387 1091 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address; // 0x20
1388 1092 current_ring_node_f3 = current_ring_node_f3->next;
1389 1093 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1390 1094 }
1391 1095
1392 1096 void reset_waveform_picker_regs( void )
1393 1097 {
1394 1098 /** This function resets the waveform picker module registers.
1395 1099 *
1396 1100 * The registers affected by this function are located at the following offset addresses:
1397 1101 * - 0x00 data_shaping
1398 1102 * - 0x04 run_burst_enable
1399 1103 * - 0x08 addr_data_f0
1400 1104 * - 0x0C addr_data_f1
1401 1105 * - 0x10 addr_data_f2
1402 1106 * - 0x14 addr_data_f3
1403 1107 * - 0x18 status
1404 1108 * - 0x1C delta_snapshot
1405 1109 * - 0x20 delta_f0
1406 1110 * - 0x24 delta_f0_2
1407 1111 * - 0x28 delta_f1
1408 1112 * - 0x2c delta_f2
1409 1113 * - 0x30 nb_data_by_buffer
1410 1114 * - 0x34 nb_snapshot_param
1411 1115 * - 0x38 start_date
1412 1116 * - 0x3c nb_word_in_buffer
1413 1117 *
1414 1118 */
1415 1119
1416 1120 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1417 1121
1418 1122 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1419 1123
1420 1124 reset_wfp_buffer_addresses();
1421 1125
1422 1126 reset_wfp_status(); // 0x18
1423 1127
1424 1128 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1425 1129
1426 1130 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1427 1131
1428 1132 set_wfp_delta_f1(); // 0x28
1429 1133
1430 1134 set_wfp_delta_f2(); // 0x2c
1431 1135
1432 1136 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1433 1137 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1434 1138 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1435 1139 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1436 1140 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1437 1141 // 2688 = 8 * 336
1438 1142 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1439 1143 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1440 1144 waveform_picker_regs->start_date = 0x7fffffff; // 0x38
1441 1145 //
1442 1146 // coarse time and fine time registers are not initialized, they are volatile
1443 1147 //
1444 1148 waveform_picker_regs->buffer_length = 0x1f8;// buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1445 1149 }
1446 1150
1447 1151 void set_wfp_data_shaping( void )
1448 1152 {
1449 1153 /** This function sets the data_shaping register of the waveform picker module.
1450 1154 *
1451 1155 * The value is read from one field of the parameter_dump_packet structure:\n
1452 1156 * bw_sp0_sp1_r0_r1
1453 1157 *
1454 1158 */
1455 1159
1456 1160 unsigned char data_shaping;
1457 1161
1458 1162 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1459 1163 // waveform picker : [R1 R0 SP1 SP0 BW]
1460 1164
1461 1165 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
1462 1166
1463 1167 waveform_picker_regs->data_shaping =
1464 1168 ( (data_shaping & 0x10) >> 4 ) // BW
1465 1169 + ( (data_shaping & 0x08) >> 2 ) // SP0
1466 1170 + ( (data_shaping & 0x04) ) // SP1
1467 1171 + ( (data_shaping & 0x02) << 2 ) // R0
1468 1172 + ( (data_shaping & 0x01) << 4 ); // R1
1469 1173 }
1470 1174
1471 1175 void set_wfp_burst_enable_register( unsigned char mode )
1472 1176 {
1473 1177 /** This function sets the waveform picker burst_enable register depending on the mode.
1474 1178 *
1475 1179 * @param mode is the LFR mode to launch.
1476 1180 *
1477 1181 * The burst bits shall be before the enable bits.
1478 1182 *
1479 1183 */
1480 1184
1481 1185 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1482 1186 // the burst bits shall be set first, before the enable bits
1483 1187 switch(mode) {
1484 1188 case(LFR_MODE_NORMAL):
1485 1189 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1486 1190 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1487 1191 break;
1488 1192 case(LFR_MODE_BURST):
1489 1193 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1490 1194 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1491 1195 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2
1492 1196 break;
1493 1197 case(LFR_MODE_SBM1):
1494 1198 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1495 1199 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1496 1200 break;
1497 1201 case(LFR_MODE_SBM2):
1498 1202 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1499 1203 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1500 1204 break;
1501 1205 default:
1502 1206 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1503 1207 break;
1504 1208 }
1505 1209 }
1506 1210
1507 1211 void set_wfp_delta_snapshot( void )
1508 1212 {
1509 1213 /** This function sets the delta_snapshot register of the waveform picker module.
1510 1214 *
1511 1215 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1512 1216 * - sy_lfr_n_swf_p[0]
1513 1217 * - sy_lfr_n_swf_p[1]
1514 1218 *
1515 1219 */
1516 1220
1517 1221 unsigned int delta_snapshot;
1518 1222 unsigned int delta_snapshot_in_T2;
1519 1223
1520 1224 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1521 1225 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1522 1226
1523 1227 delta_snapshot_in_T2 = delta_snapshot * 256;
1524 1228 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1525 1229 }
1526 1230
1527 1231 void set_wfp_delta_f0_f0_2( void )
1528 1232 {
1529 1233 unsigned int delta_snapshot;
1530 1234 unsigned int nb_samples_per_snapshot;
1531 1235 float delta_f0_in_float;
1532 1236
1533 1237 delta_snapshot = waveform_picker_regs->delta_snapshot;
1534 1238 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1535 1239 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1536 1240
1537 1241 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1538 1242 waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits
1539 1243 }
1540 1244
1541 1245 void set_wfp_delta_f1( void )
1542 1246 {
1543 1247 unsigned int delta_snapshot;
1544 1248 unsigned int nb_samples_per_snapshot;
1545 1249 float delta_f1_in_float;
1546 1250
1547 1251 delta_snapshot = waveform_picker_regs->delta_snapshot;
1548 1252 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1549 1253 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1550 1254
1551 1255 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1552 1256 }
1553 1257
1554 1258 void set_wfp_delta_f2()
1555 1259 {
1556 1260 unsigned int delta_snapshot;
1557 1261 unsigned int nb_samples_per_snapshot;
1558 1262
1559 1263 delta_snapshot = waveform_picker_regs->delta_snapshot;
1560 1264 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1561 1265
1562 1266 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1563 1267 }
1564 1268
1565 1269 //*****************
1566 1270 // local parameters
1567 1271
1568 1272 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1569 1273 {
1570 1274 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1571 1275 *
1572 1276 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1573 1277 * @param sid is the source identifier of the packet being updated.
1574 1278 *
1575 1279 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1576 1280 * The sequence counters shall wrap around from 2^14 to zero.
1577 1281 * The sequence counter shall start at zero at startup.
1578 1282 *
1579 1283 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1580 1284 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1581 1285 *
1582 1286 */
1583 1287
1584 1288 unsigned short *sequence_cnt;
1585 1289 unsigned short segmentation_grouping_flag;
1586 1290 unsigned short new_packet_sequence_control;
1587 1291 rtems_mode initial_mode_set;
1588 1292 rtems_mode current_mode_set;
1589 1293 rtems_status_code status;
1590 1294
1591 1295 //******************************************
1592 1296 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1593 1297 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1594 1298
1595 1299 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1596 1300 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1597 1301 || (sid == SID_BURST_CWF_F2)
1598 1302 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1599 1303 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1600 1304 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1601 1305 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1602 1306 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1603 1307 {
1604 1308 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1605 1309 }
1606 1310 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1607 1311 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1608 1312 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1609 1313 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1610 1314 {
1611 1315 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1612 1316 }
1613 1317 else
1614 1318 {
1615 1319 sequence_cnt = (unsigned short *) NULL;
1616 1320 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1617 1321 }
1618 1322
1619 1323 if (sequence_cnt != NULL)
1620 1324 {
1621 1325 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1622 1326 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1623 1327
1624 1328 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1625 1329
1626 1330 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1627 1331 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1628 1332
1629 1333 // increment the sequence counter
1630 1334 if ( *sequence_cnt < SEQ_CNT_MAX)
1631 1335 {
1632 1336 *sequence_cnt = *sequence_cnt + 1;
1633 1337 }
1634 1338 else
1635 1339 {
1636 1340 *sequence_cnt = 0;
1637 1341 }
1638 1342 }
1639 1343
1640 1344 //***********************************
1641 1345 // RESET THE MODE OF THE CALLING TASK
1642 1346 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1643 1347 }
General Comments 0
You need to be logged in to leave comments. Login now