##// END OF EJS Templates
rev 1.0.0.1
paul -
r98:b527b5cbc22e VHDLib206
parent child
Show More
@@ -1,253 +1,253
1 1 #############################################################################
2 # Makefile for building: bin/fsw-vhdl-dev
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Thu Feb 13 07:43:27 2014
2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.5) on: Mon Feb 17 07:55:25 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=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=1 -DPRINT_MESSAGES_ON_CONSOLE -DDEBUG_MESSAGES -DPRINT_TASK_STATISTICS -DVHDL_DEV
13 DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=1 -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../../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_processing.c \
49 49 ../src/fsw_misc.c \
50 50 ../src/fsw_init.c \
51 51 ../src/fsw_globals.c \
52 52 ../src/fsw_spacewire.c \
53 53 ../src/tc_load_dump_parameters.c \
54 54 ../src/tm_lfr_tc_exe.c \
55 55 ../src/tc_acceptance.c \
56 56 ../../LFR_basic-parameters/basic_parameters.c
57 57 OBJECTS = obj/wf_handler.o \
58 58 obj/tc_handler.o \
59 59 obj/fsw_processing.o \
60 60 obj/fsw_misc.o \
61 61 obj/fsw_init.o \
62 62 obj/fsw_globals.o \
63 63 obj/fsw_spacewire.o \
64 64 obj/tc_load_dump_parameters.o \
65 65 obj/tm_lfr_tc_exe.o \
66 66 obj/tc_acceptance.o \
67 67 obj/basic_parameters.o
68 68 DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \
69 69 /usr/lib64/qt4/mkspecs/common/linux.conf \
70 70 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
71 71 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
72 72 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
73 73 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
74 74 /usr/lib64/qt4/mkspecs/qconfig.pri \
75 75 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
76 76 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
77 77 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
78 78 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
79 79 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
80 80 sparc.pri \
81 81 /usr/lib64/qt4/mkspecs/features/release.prf \
82 82 /usr/lib64/qt4/mkspecs/features/default_post.prf \
83 83 /usr/lib64/qt4/mkspecs/features/shared.prf \
84 84 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
85 85 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
86 86 /usr/lib64/qt4/mkspecs/features/resources.prf \
87 87 /usr/lib64/qt4/mkspecs/features/uic.prf \
88 88 /usr/lib64/qt4/mkspecs/features/yacc.prf \
89 89 /usr/lib64/qt4/mkspecs/features/lex.prf \
90 90 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf \
91 91 fsw-qt.pro
92 QMAKE_TARGET = fsw-vhdl-dev
92 QMAKE_TARGET = fsw
93 93 DESTDIR = bin/
94 TARGET = bin/fsw-vhdl-dev
94 TARGET = bin/fsw
95 95
96 96 first: all
97 97 ####### Implicit rules
98 98
99 99 .SUFFIXES: .o .c .cpp .cc .cxx .C
100 100
101 101 .cpp.o:
102 102 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
103 103
104 104 .cc.o:
105 105 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
106 106
107 107 .cxx.o:
108 108 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
109 109
110 110 .C.o:
111 111 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
112 112
113 113 .c.o:
114 114 $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
115 115
116 116 ####### Build rules
117 117
118 118 all: Makefile $(TARGET)
119 119
120 120 $(TARGET): $(OBJECTS)
121 121 @$(CHK_DIR_EXISTS) bin/ || $(MKDIR) bin/
122 122 $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
123 123
124 124 Makefile: fsw-qt.pro /usr/lib64/qt4/mkspecs/linux-g++/qmake.conf /usr/lib64/qt4/mkspecs/common/unix.conf \
125 125 /usr/lib64/qt4/mkspecs/common/linux.conf \
126 126 /usr/lib64/qt4/mkspecs/common/gcc-base.conf \
127 127 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \
128 128 /usr/lib64/qt4/mkspecs/common/g++-base.conf \
129 129 /usr/lib64/qt4/mkspecs/common/g++-unix.conf \
130 130 /usr/lib64/qt4/mkspecs/qconfig.pri \
131 131 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri \
132 132 /usr/lib64/qt4/mkspecs/features/qt_functions.prf \
133 133 /usr/lib64/qt4/mkspecs/features/qt_config.prf \
134 134 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \
135 135 /usr/lib64/qt4/mkspecs/features/default_pre.prf \
136 136 sparc.pri \
137 137 /usr/lib64/qt4/mkspecs/features/release.prf \
138 138 /usr/lib64/qt4/mkspecs/features/default_post.prf \
139 139 /usr/lib64/qt4/mkspecs/features/shared.prf \
140 140 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
141 141 /usr/lib64/qt4/mkspecs/features/warn_on.prf \
142 142 /usr/lib64/qt4/mkspecs/features/resources.prf \
143 143 /usr/lib64/qt4/mkspecs/features/uic.prf \
144 144 /usr/lib64/qt4/mkspecs/features/yacc.prf \
145 145 /usr/lib64/qt4/mkspecs/features/lex.prf \
146 146 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf
147 147 $(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
148 148 /usr/lib64/qt4/mkspecs/common/unix.conf:
149 149 /usr/lib64/qt4/mkspecs/common/linux.conf:
150 150 /usr/lib64/qt4/mkspecs/common/gcc-base.conf:
151 151 /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf:
152 152 /usr/lib64/qt4/mkspecs/common/g++-base.conf:
153 153 /usr/lib64/qt4/mkspecs/common/g++-unix.conf:
154 154 /usr/lib64/qt4/mkspecs/qconfig.pri:
155 155 /usr/lib64/qt4/mkspecs/modules/qt_webkit.pri:
156 156 /usr/lib64/qt4/mkspecs/features/qt_functions.prf:
157 157 /usr/lib64/qt4/mkspecs/features/qt_config.prf:
158 158 /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf:
159 159 /usr/lib64/qt4/mkspecs/features/default_pre.prf:
160 160 sparc.pri:
161 161 /usr/lib64/qt4/mkspecs/features/release.prf:
162 162 /usr/lib64/qt4/mkspecs/features/default_post.prf:
163 163 /usr/lib64/qt4/mkspecs/features/shared.prf:
164 164 /usr/lib64/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
165 165 /usr/lib64/qt4/mkspecs/features/warn_on.prf:
166 166 /usr/lib64/qt4/mkspecs/features/resources.prf:
167 167 /usr/lib64/qt4/mkspecs/features/uic.prf:
168 168 /usr/lib64/qt4/mkspecs/features/yacc.prf:
169 169 /usr/lib64/qt4/mkspecs/features/lex.prf:
170 170 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf:
171 171 qmake: FORCE
172 172 @$(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
173 173
174 174 dist:
175 @$(CHK_DIR_EXISTS) obj/fsw-vhdl-dev1.0.0 || $(MKDIR) obj/fsw-vhdl-dev1.0.0
176 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/fsw-vhdl-dev1.0.0/ && (cd `dirname obj/fsw-vhdl-dev1.0.0` && $(TAR) fsw-vhdl-dev1.0.0.tar fsw-vhdl-dev1.0.0 && $(COMPRESS) fsw-vhdl-dev1.0.0.tar) && $(MOVE) `dirname obj/fsw-vhdl-dev1.0.0`/fsw-vhdl-dev1.0.0.tar.gz . && $(DEL_FILE) -r obj/fsw-vhdl-dev1.0.0
175 @$(CHK_DIR_EXISTS) obj/fsw1.0.0 || $(MKDIR) obj/fsw1.0.0
176 $(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
177 177
178 178
179 179 clean:compiler_clean
180 180 -$(DEL_FILE) $(OBJECTS)
181 181 -$(DEL_FILE) *~ core *.core
182 182
183 183
184 184 ####### Sub-libraries
185 185
186 186 distclean: clean
187 187 -$(DEL_FILE) $(TARGET)
188 188 -$(DEL_FILE) Makefile
189 189
190 190
191 191 grmon:
192 192 cd bin && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
193 193
194 194 check: first
195 195
196 196 compiler_rcc_make_all:
197 197 compiler_rcc_clean:
198 198 compiler_uic_make_all:
199 199 compiler_uic_clean:
200 200 compiler_image_collection_make_all: qmake_image_collection.cpp
201 201 compiler_image_collection_clean:
202 202 -$(DEL_FILE) qmake_image_collection.cpp
203 203 compiler_yacc_decl_make_all:
204 204 compiler_yacc_decl_clean:
205 205 compiler_yacc_impl_make_all:
206 206 compiler_yacc_impl_clean:
207 207 compiler_lex_make_all:
208 208 compiler_lex_clean:
209 209 compiler_clean:
210 210
211 211 ####### Compile
212 212
213 213 obj/wf_handler.o: ../src/wf_handler.c
214 214 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/wf_handler.o ../src/wf_handler.c
215 215
216 216 obj/tc_handler.o: ../src/tc_handler.c
217 217 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_handler.o ../src/tc_handler.c
218 218
219 219 obj/fsw_processing.o: ../src/fsw_processing.c ../src/fsw_processing_globals.c
220 220 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_processing.o ../src/fsw_processing.c
221 221
222 222 obj/fsw_misc.o: ../src/fsw_misc.c
223 223 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_misc.o ../src/fsw_misc.c
224 224
225 225 obj/fsw_init.o: ../src/fsw_init.c ../src/fsw_config.c
226 226 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_init.o ../src/fsw_init.c
227 227
228 228 obj/fsw_globals.o: ../src/fsw_globals.c
229 229 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_globals.o ../src/fsw_globals.c
230 230
231 231 obj/fsw_spacewire.o: ../src/fsw_spacewire.c
232 232 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/fsw_spacewire.o ../src/fsw_spacewire.c
233 233
234 234 obj/tc_load_dump_parameters.o: ../src/tc_load_dump_parameters.c
235 235 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_load_dump_parameters.o ../src/tc_load_dump_parameters.c
236 236
237 237 obj/tm_lfr_tc_exe.o: ../src/tm_lfr_tc_exe.c
238 238 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tm_lfr_tc_exe.o ../src/tm_lfr_tc_exe.c
239 239
240 240 obj/tc_acceptance.o: ../src/tc_acceptance.c
241 241 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/tc_acceptance.o ../src/tc_acceptance.c
242 242
243 243 obj/basic_parameters.o: ../../LFR_basic-parameters/basic_parameters.c ../../LFR_basic-parameters/basic_parameters.h
244 244 $(CC) -c $(CFLAGS) $(INCPATH) -o obj/basic_parameters.o ../../LFR_basic-parameters/basic_parameters.c
245 245
246 246 ####### Install
247 247
248 248 install: FORCE
249 249
250 250 uninstall: FORCE
251 251
252 252 FORCE:
253 253
@@ -1,13 +1,13
1 1 #!/usr/bin/lppmon -e
2 2
3 3 proxy.loadSysDriver("RMAPPlugin","RMAPplugin0");
4 4 proxy.loadSysDriverToParent("dsu3plugin","RMAPplugin0");
5 5
6 6 #BUTTON_selectStarDundee.click()
7 7 BUTTON_selectGRESB.click()
8 8
9 9 BUTTON_rmapOpenCommunication.click()
10 dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw-vhdl-dev")
10 dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw")
11 11 dsu3plugin0.loadFile()
12 12 dsu3plugin0.run()
13 13
@@ -1,6 +1,6
1 1 #!/usr/bin/lppmon -e
2 2
3 dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw-vhdl-dev")
3 dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw")
4 4 dsu3plugin0.loadFile()
5 5 dsu3plugin0.run()
6 6
@@ -1,88 +1,78
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** gsa *** vhdl_dev
4 CONFIG += console verbose debug_messages vhdl_dev cpu_usage_report
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report
4 CONFIG += console verbose
5 5 CONFIG -= qt
6 6
7 7 include(./sparc.pri)
8 8
9 9 # flight software version
10 10 SWVERSION=-1-0
11 11 DEFINES += SW_VERSION_N1=1 # major
12 12 DEFINES += SW_VERSION_N2=0 # minor
13 13 DEFINES += SW_VERSION_N3=0 # patch
14 14 DEFINES += SW_VERSION_N4=1 # internal
15 15
16 16 contains( CONFIG, verbose ) {
17 17 DEFINES += PRINT_MESSAGES_ON_CONSOLE
18 18 }
19 19
20 20 contains( CONFIG, debug_messages ) {
21 21 DEFINES += DEBUG_MESSAGES
22 22 }
23 23
24 24 contains( CONFIG, cpu_usage_report ) {
25 25 DEFINES += PRINT_TASK_STATISTICS
26 26 }
27 27
28 28 contains( CONFIG, stack_report ) {
29 29 DEFINES += PRINT_STACK_REPORT
30 30 }
31 31
32 32 contains( CONFIG, boot_messages ) {
33 33 DEFINES += BOOT_MESSAGES
34 34 }
35 35
36 36 #doxygen.target = doxygen
37 37 #doxygen.commands = doxygen ../doc/Doxyfile
38 38 #QMAKE_EXTRA_TARGETS += doxygen
39 39
40 40 TARGET = fsw
41 contains( CONFIG, gsa ) {
42 DEFINES += GSA
43 TARGET = fsw-gsa
44 }
45
46 TARGET = fsw
47 contains( CONFIG, vhdl_dev ) {
48 DEFINES += VHDL_DEV
49 TARGET = fsw-vhdl-dev
50 }
51 41
52 42 INCLUDEPATH += \
53 43 ../src \
54 44 ../header \
55 45 ../../LFR_basic-parameters
56 46
57 47 SOURCES += \
58 48 ../src/wf_handler.c \
59 49 ../src/tc_handler.c \
60 50 ../src/fsw_processing.c \
61 51 ../src/fsw_misc.c \
62 52 ../src/fsw_init.c \
63 53 ../src/fsw_globals.c \
64 54 ../src/fsw_spacewire.c \
65 55 ../src/tc_load_dump_parameters.c \
66 56 ../src/tm_lfr_tc_exe.c \
67 57 ../src/tc_acceptance.c \
68 58 ../../LFR_basic-parameters/basic_parameters.c
69 59
70 60
71 61 HEADERS += \
72 62 ../header/wf_handler.h \
73 63 ../header/tc_handler.h \
74 64 ../header/grlib_regs.h \
75 65 ../header/fsw_processing.h \
76 66 ../header/fsw_params.h \
77 67 ../header/fsw_misc.h \
78 68 ../header/fsw_init.h \
79 69 ../header/ccsds_types.h \
80 70 ../header/fsw_params_processing.h \
81 71 ../header/fsw_spacewire.h \
82 72 ../header/tm_byte_positions.h \
83 73 ../header/tc_load_dump_parameters.h \
84 74 ../header/tm_lfr_tc_exe.h \
85 75 ../header/tc_acceptance.h \
86 76 ../header/fsw_params_nb_bytes.h \
87 77 ../../LFR_basic-parameters/basic_parameters.h
88 78
@@ -1,230 +1,228
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 "tm_byte_positions.h"
7 7 #include "ccsds_types.h"
8 8
9 9 #define GRSPW_DEVICE_NAME "/dev/grspw0"
10 10 #define UART_DEVICE_NAME "/dev/console"
11 11
12 12 typedef struct ring_node
13 13 {
14 14 struct ring_node *previous;
15 15 int buffer_address;
16 16 struct ring_node *next;
17 17 unsigned int status;
18 18 } ring_node;
19 19
20 20 typedef struct ring_node_sm
21 21 {
22 22 struct ring_node *previous;
23 23 volatile int *buffer_address;
24 24 struct ring_node *next;
25 25 unsigned int status;
26 26 } ring_node_sm;
27 27
28 28 //************************
29 29 // flight software version
30 30 // this parameters is handled by the Qt project options
31 31
32 //#define NB_SAMPLES_PER_SNAPSHOT 2048
33 #define NB_SAMPLES_PER_SNAPSHOT 2352 // 336 * 7 = 2352
32 #define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk
33 #define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk
34 #define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688
34 35 #define TIME_OFFSET 2
35 36 #define TIME_OFFSET_IN_BYTES 8
36 37 #define WAVEFORM_EXTENDED_HEADER_OFFSET 22
37 38 #define NB_BYTES_SWF_BLK (2 * 6)
38 39 #define NB_WORDS_SWF_BLK 3
39 40 #define NB_BYTES_CWF3_LIGHT_BLK 6
40 41 #define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8
41 42 #define NB_RING_NODES_F0 3 // AT LEAST 3
42 43 #define NB_RING_NODES_F1 5 // AT LEAST 3
43 44 #define NB_RING_NODES_F2 5 // AT LEAST 3
44 45 #define NB_RING_NODES_ASM_F0 12 // AT LEAST 3
45 46 #define NB_RING_NODES_ASM_F1 2 // AT LEAST 3
46 47 #define NB_RING_NODES_ASM_F2 2 // AT LEAST 3
47 48
48 49 //**********
49 50 // LFR MODES
50 51 #define LFR_MODE_STANDBY 0
51 52 #define LFR_MODE_NORMAL 1
52 53 #define LFR_MODE_BURST 2
53 54 #define LFR_MODE_SBM1 3
54 55 #define LFR_MODE_SBM2 4
55 56 #define LFR_MODE_NORMAL_CWF_F3 5
56 57
57 58 #define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0
58 59 #define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1
59 60 #define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2
60 61 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
61 62 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
62 63 #define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5
63 64 #define RTEMS_EVENT_MODE_NORMAL_SWF_F0 RTEMS_EVENT_6
64 65 #define RTEMS_EVENT_MODE_NORMAL_SWF_F1 RTEMS_EVENT_7
65 66 #define RTEMS_EVENT_MODE_NORMAL_SWF_F2 RTEMS_EVENT_8
66 67
67 68 //****************************
68 69 // LFR DEFAULT MODE PARAMETERS
69 70 // COMMON
70 71 #define DEFAULT_SY_LFR_COMMON0 0x00
71 72 #define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0
72 73 // NORM
73 74 #define SY_LFR_N_SWF_L 2048 // nb sample
74 75 #define SY_LFR_N_SWF_P 300 // sec
75 76 #define SY_LFR_N_ASM_P 3600 // sec
76 77 #define SY_LFR_N_BP_P0 4 // sec
77 78 #define SY_LFR_N_BP_P1 20 // sec
79 #define SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3
78 80 #define MIN_DELTA_SNAPSHOT 16 // sec
79 81 // BURST
80 82 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
81 83 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
82 84 // SBM1
83 85 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
84 86 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
85 87 // SBM2
86 88 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
87 89 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
88 90 // ADDITIONAL PARAMETERS
89 91 #define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms
90 92 #define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s
91 93 // STATUS WORD
92 94 #define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits
93 95 #define DEFAULT_STATUS_WORD_BYTE1 0x00
94 96 //
95 97 #define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s
96 98 #define SY_LFR_DPU_CONNECT_ATTEMPT 3
97 99 //****************************
98 100
99 101 //*****************************
100 102 // APB REGISTERS BASE ADDRESSES
101 #define REGS_ADDR_APBUART 0x80000100
102 #define REGS_ADDR_GPTIMER 0x80000300
103 #define REGS_ADDR_GRSPW 0x80000500
104 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
105 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
103 #define REGS_ADDR_APBUART 0x80000100
104 #define REGS_ADDR_GPTIMER 0x80000300
105 #define REGS_ADDR_GRSPW 0x80000500
106 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
107 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
108 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f20
106 109
107 #ifdef GSA
108 #else
109 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f20
110 #endif
111
112 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
113 #define APBUART_CTRL_REG_MASK_TE 0x00000002
110 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
111 #define APBUART_CTRL_REG_MASK_TE 0x00000002
114 112 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50)
115 113
116 114 //**********
117 115 // IRQ LINES
118 116 #define IRQ_SM 9
119 117 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
120 118 #define IRQ_WF 10
121 119 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
122 120 #define IRQ_TIME1 12
123 121 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
124 122 #define IRQ_TIME2 13
125 123 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
126 124 #define IRQ_WAVEFORM_PICKER 14
127 125 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
128 126 #define IRQ_SPECTRAL_MATRIX 6
129 127 #define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels
130 128
131 129 //*****
132 130 // TIME
133 131 #define CLKDIV_SM_SIMULATOR (10000 - 1) // 10 ms
134 132 #define CLKDIV_WF_SIMULATOR (10000000 - 1) // 10 000 000 * 1 us = 10 s
135 133 #define TIMER_SM_SIMULATOR 1
136 134 #define TIMER_WF_SIMULATOR 2
137 135 #define HK_PERIOD 100 // 100 * 10ms => 1sec
138 136
139 137 //**********
140 138 // LPP CODES
141 139 #define LFR_SUCCESSFUL 0
142 140 #define LFR_DEFAULT 1
143 141
144 142 //******
145 143 // RTEMS
146 144 #define TASKID_RECV 1
147 145 #define TASKID_ACTN 2
148 146 #define TASKID_SPIQ 3
149 147 #define TASKID_SMIQ 4
150 148 #define TASKID_STAT 5
151 149 #define TASKID_AVF0 6
152 150 #define TASKID_BPF0 7
153 151 #define TASKID_WFRM 8
154 152 #define TASKID_DUMB 9
155 153 #define TASKID_HOUS 10
156 154 #define TASKID_MATR 11
157 155 #define TASKID_CWF3 12
158 156 #define TASKID_CWF2 13
159 157 #define TASKID_CWF1 14
160 158 #define TASKID_SEND 15
161 159 #define TASKID_WTDG 16
162 160
163 161 #define TASK_PRIORITY_SPIQ 5
164 162 #define TASK_PRIORITY_SMIQ 10
165 163 #define TASK_PRIORITY_WTDG 20
166 164 #define TASK_PRIORITY_HOUS 30
167 165 #define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together
168 166 #define TASK_PRIORITY_CWF2 35 //
169 167 #define TASK_PRIORITY_WFRM 40
170 168 #define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1
171 169 #define TASK_PRIORITY_SEND 45
172 170 #define TASK_PRIORITY_RECV 50
173 171 #define TASK_PRIORITY_ACTN 50
174 172 #define TASK_PRIORITY_AVF0 60
175 173 #define TASK_PRIORITY_BPF0 60
176 174 #define TASK_PRIORITY_MATR 100
177 175 #define TASK_PRIORITY_STAT 200
178 176 #define TASK_PRIORITY_DUMB 200
179 177
180 178 #define ACTION_MSG_QUEUE_COUNT 10
181 179 #define ACTION_MSG_PKTS_COUNT 50
182 180 #define ACTION_MSG_PKTS_MAX_SIZE (PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES)
183 181 #define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options
184 182
185 183 #define QUEUE_RECV 0
186 184 #define QUEUE_SEND 1
187 185
188 186 //*******
189 187 // MACROS
190 188 #ifdef PRINT_MESSAGES_ON_CONSOLE
191 189 #define PRINTF(x) printf(x);
192 190 #define PRINTF1(x,y) printf(x,y);
193 191 #define PRINTF2(x,y,z) printf(x,y,z);
194 192 #else
195 193 #define PRINTF(x) ;
196 194 #define PRINTF1(x,y) ;
197 195 #define PRINTF2(x,y,z) ;
198 196 #endif
199 197
200 198 #ifdef BOOT_MESSAGES
201 199 #define BOOT_PRINTF(x) printf(x);
202 200 #define BOOT_PRINTF1(x,y) printf(x,y);
203 201 #define BOOT_PRINTF2(x,y,z) printf(x,y,z);
204 202 #else
205 203 #define BOOT_PRINTF(x) ;
206 204 #define BOOT_PRINTF1(x,y) ;
207 205 #define BOOT_PRINTF2(x,y,z) ;
208 206 #endif
209 207
210 208 #ifdef DEBUG_MESSAGES
211 209 #define DEBUG_PRINTF(x) printf(x);
212 210 #define DEBUG_PRINTF1(x,y) printf(x,y);
213 211 #define DEBUG_PRINTF2(x,y,z) printf(x,y,z);
214 212 #else
215 213 #define DEBUG_PRINTF(x) ;
216 214 #define DEBUG_PRINTF1(x,y) ;
217 215 #define DEBUG_PRINTF2(x,y,z) ;
218 216 #endif
219 217
220 218 #define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period
221 219
222 220 struct param_local_str{
223 221 unsigned int local_sbm1_nb_cwf_sent;
224 222 unsigned int local_sbm1_nb_cwf_max;
225 223 unsigned int local_sbm2_nb_cwf_sent;
226 224 unsigned int local_sbm2_nb_cwf_max;
227 225 unsigned int local_nb_interrupt_f0_MAX;
228 226 };
229 227
230 228 #endif // FSW_PARAMS_H_INCLUDED
@@ -1,60 +1,55
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 // MODE PARAMETERS
14 14 extern unsigned int maxCount;
15 15
16 16 //****
17 17 // ISR
18 18 rtems_isr commutation_isr1( rtems_vector_number vector );
19 19 rtems_isr commutation_isr2( rtems_vector_number vector );
20 20
21 21 //***********
22 22 // RTEMS TASK
23 23 rtems_task actn_task( rtems_task_argument unused );
24 24
25 25 //***********
26 26 // TC ACTIONS
27 27 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
28 28 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
29 29 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
30 30 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
31 31 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
32 32 int action_update_time(ccsdsTelecommandPacket_t *TC);
33 33
34 34 // mode transition
35 35 int transition_validation(unsigned char requestedMode);
36 int stop_current_mode();
36 int stop_current_mode( void );
37 37 int enter_mode(unsigned char mode);
38 int enter_standby_mode();
39 int enter_normal_mode();
40 int enter_burst_mode();
41 int enter_sbm1_mode();
42 int enter_sbm2_mode();
43 38 int restart_science_tasks();
44 39 int suspend_science_tasks();
45 40 void launch_waveform_picker( unsigned char mode );
46 41 void launch_spectral_matrix( unsigned char mode );
47 42
48 43 // other functions
49 44 void updateLFRCurrentMode();
50 45 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC, unsigned char *time);
51 46 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char *time);
52 47 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id, unsigned char *time);
53 48
54 49 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
55 50 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
56 51
57 52 #endif // TC_HANDLER_H_INCLUDED
58 53
59 54
60 55
@@ -1,93 +1,90
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
13 13 #define pi 3.1415
14 14
15 15 extern int fdSPW;
16 16
17 17 //*****************
18 18 // waveform buffers
19 19 // F0
20 20 //extern volatile int wf_snap_f0[ ];
21 21 // F1 F2
22 22 extern volatile int wf_snap_f0[ ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ];
23 23 extern volatile int wf_snap_f1[ ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ];
24 24 extern volatile int wf_snap_f2[ ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ];
25 25 // F3
26 26 extern volatile int wf_cont_f3_a[ ];
27 27 extern volatile int wf_cont_f3_b[ ];
28 28 extern char wf_cont_f3_light[ ];
29 29
30 #ifdef VHDL_DEV
31 30 extern waveform_picker_regs_new_t *waveform_picker_regs;
32 #else
33 extern waveform_picker_regs_t *waveform_picker_regs;
34 #endif
35 31 extern time_management_regs_t *time_management_regs;
36 32 extern Packet_TM_LFR_HK_t housekeeping_packet;
37 33 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
38 34 extern struct param_local_str param_local;
39 35
40 36 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
41 37 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
42 38
43 39 extern rtems_id Task_id[20]; /* array of task ids */
44 40
45 41 extern unsigned char lfrCurrentMode;
46 42
47 43 rtems_isr waveforms_isr( rtems_vector_number vector );
48 44 rtems_isr waveforms_isr_alt( rtems_vector_number vector );
49 45 rtems_task wfrm_task( rtems_task_argument argument );
50 46 rtems_task cwf3_task( rtems_task_argument argument );
51 47 rtems_task cwf2_task( rtems_task_argument argument );
52 48 rtems_task cwf1_task( rtems_task_argument argument );
53 49
54 50 //******************
55 51 // general functions
56 52 void init_waveforms( void );
57 53 void init_waveform_rings( void );
58 54 void reset_current_ring_nodes( void );
59 55 //
60 56 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF );
61 57 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
62 58 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
63 59 //
64 60 int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
65 61 int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
66 62 int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
67 63 int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
68 64 //
69 void compute_acquisition_time(unsigned int *coarseTime, unsigned int *fineTime, unsigned int sid, unsigned char pa_lfr_pkt_nr );
65 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
66 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
70 67 //
71 68 rtems_id get_pkts_queue_id( void );
72 69
73 70 //**************
74 71 // wfp registers
75 72 // RESET
76 73 void reset_wfp_burst_enable( void );
77 74 void reset_wfp_status(void);
78 75 void reset_waveform_picker_regs( void );
79 76 // SET
80 77 void set_wfp_data_shaping(void);
81 78 void set_wfp_burst_enable_register( unsigned char mode );
82 79 void set_wfp_delta_snapshot( void );
83 80 void set_wfp_delta_f0_f0_2( void );
84 81 void set_wfp_delta_f1( void );
85 82 void set_wfp_delta_f2( void );
86 83
87 84 //*****************
88 85 // local parameters
89 86 void set_local_nb_interrupt_f0_MAX( void );
90 87
91 88 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
92 89
93 90 #endif // WF_HANDLER_H_INCLUDED
@@ -1,75 +1,70
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
24 24 // RTEMS GLOBAL VARIABLES
25 25 rtems_name misc_name[5];
26 26 rtems_id misc_id[5];
27 27 rtems_name Task_name[20]; /* array of task names */
28 28 rtems_id Task_id[20]; /* array of task ids */
29 29 unsigned int maxCount;
30 30 int fdSPW = 0;
31 31 int fdUART = 0;
32 32 unsigned char lfrCurrentMode;
33 33
34 34 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes
35 35 // F0
36 36 //volatile int wf_snap_f0 [ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ] __attribute__((aligned(0x100)));
37 37 volatile int wf_snap_f0[ NB_RING_NODES_F0 ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ] __attribute__((aligned(0x100)));
38 38 // F1 F2
39 39 volatile int wf_snap_f1[ NB_RING_NODES_F1 ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ] __attribute__((aligned(0x100)));
40 40 volatile int wf_snap_f2[ NB_RING_NODES_F2 ][ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 46 ] __attribute__((aligned(0x100)));
41 41 // F3
42 42 volatile int wf_cont_f3_a [ (NB_SAMPLES_PER_SNAPSHOT) * NB_WORDS_SWF_BLK + TIME_OFFSET ] __attribute__((aligned(0x100)));
43 43 volatile int wf_cont_f3_b [ (NB_SAMPLES_PER_SNAPSHOT) * NB_WORDS_SWF_BLK + TIME_OFFSET ] __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 // SPECTRAL MATRICES GLOBAL VARIABLES
47 47 volatile int sm_f0[ NB_RING_NODES_ASM_F0 ][ SM_HEADER + TOTAL_SIZE_SM ];
48 48 volatile int sm_f1[ NB_RING_NODES_ASM_F1 ][ SM_HEADER + TOTAL_SIZE_SM ];
49 49 volatile int sm_f2[ NB_RING_NODES_ASM_F2 ][ SM_HEADER + TOTAL_SIZE_SM ];
50 50
51 51 // APB CONFIGURATION REGISTERS
52 52 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
53 53 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
54
55 #ifdef VHDL_DEV
56 54 waveform_picker_regs_new_t *waveform_picker_regs = (waveform_picker_regs_new_t*) REGS_ADDR_WAVEFORM_PICKER;
57 #else
58 waveform_picker_regs_t *waveform_picker_regs = (waveform_picker_regs_t*) REGS_ADDR_WAVEFORM_PICKER;
59 #endif
60 55 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
61 56
62 57 // MODE PARAMETERS
63 58 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
64 59 struct param_local_str param_local;
65 60
66 61 // HK PACKETS
67 62 Packet_TM_LFR_HK_t housekeeping_packet;
68 63 // sequence counters are incremented by APID (PID + CAT) and destination ID
69 64 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
70 65 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
71 66 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
72 67 spw_stats spacewire_stats;
73 68 spw_stats spacewire_stats_backup;
74 69
75 70
@@ -1,610 +1,611
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_MAXIMUM_DRIVERS 16
36 36 #define CONFIGURE_MAXIMUM_PERIODS 5
37 37 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
38 38 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 2
39 39 #ifdef PRINT_STACK_REPORT
40 40 #define CONFIGURE_STACK_CHECKER_ENABLED
41 41 #endif
42 42
43 43 #include <rtems/confdefs.h>
44 44
45 45 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 46 #ifdef RTEMS_DRVMGR_STARTUP
47 47 #ifdef LEON3
48 48 /* Add Timer and UART Driver */
49 49 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
50 50 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
51 51 #endif
52 52 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
53 53 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
54 54 #endif
55 55 #endif
56 56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
57 57 #include <drvmgr/drvmgr_confdefs.h>
58 58 #endif
59 59
60 60 #include "fsw_init.h"
61 61 #include "fsw_config.c"
62 62
63 63 rtems_task Init( rtems_task_argument ignored )
64 64 {
65 65 /** This is the RTEMS INIT taks, it the first task launched by the system.
66 66 *
67 67 * @param unused is the starting argument of the RTEMS task
68 68 *
69 69 * The INIT task create and run all other RTEMS tasks.
70 70 *
71 71 */
72 72
73 73
74 74 rtems_status_code status;
75 75 rtems_status_code status_spw;
76 76 rtems_isr_entry old_isr_handler;
77 77
78 78 // UART settings
79 79 send_console_outputs_on_apbuart_port();
80 80 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
81 81 enable_apbuart_transmitter();
82 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
82 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
83 83
84 BOOT_PRINTF("\n\n\n\n\n")
85 BOOT_PRINTF("***************************\n")
86 BOOT_PRINTF("** START Flight Software **\n")
87 #ifdef VHDL_DEV
88 PRINTF("/!\\ this is the VHDL_DEV flight software /!\\ \n")
89 #endif
90 BOOT_PRINTF("***************************\n")
91 BOOT_PRINTF("\n\n")
84 PRINTF("\n\n\n\n\n")
85 PRINTF("*************************\n")
86 PRINTF("** LFR Flight Software **\n")
87 PRINTF1("** %d.", SW_VERSION_N1)
88 PRINTF1("%d.", SW_VERSION_N2)
89 PRINTF1("%d.", SW_VERSION_N3)
90 PRINTF1("%d\n", SW_VERSION_N4)
91 PRINTF("*************************\n")
92 PRINTF("\n\n")
92 93
93 94 reset_wfp_burst_enable(); // stop the waveform picker if it was running
94 95 init_waveform_rings(); // initialize the waveform rings
95 96 init_sm_rings();
96 97
97 98 init_parameter_dump();
98 99 init_local_mode_parameters();
99 100 init_housekeeping_parameters();
100 101
101 102 updateLFRCurrentMode();
102 103
103 104 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
104 105
105 106 create_names(); // create all names
106 107
107 108 status = create_message_queues(); // create message queues
108 109 if (status != RTEMS_SUCCESSFUL)
109 110 {
110 111 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
111 112 }
112 113
113 114 status = create_all_tasks(); // create all tasks
114 115 if (status != RTEMS_SUCCESSFUL)
115 116 {
116 117 PRINTF1("in INIT *** ERR in create_all_tasks, code %d", status)
117 118 }
118 119
119 120 // **************************
120 121 // <SPACEWIRE INITIALIZATION>
121 122 grspw_timecode_callback = &timecode_irq_handler;
122 123
123 124 status_spw = spacewire_open_link(); // (1) open the link
124 125 if ( status_spw != RTEMS_SUCCESSFUL )
125 126 {
126 127 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
127 128 }
128 129
129 130 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
130 131 {
131 132 status_spw = spacewire_configure_link( fdSPW );
132 133 if ( status_spw != RTEMS_SUCCESSFUL )
133 134 {
134 135 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
135 136 }
136 137 }
137 138
138 139 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
139 140 {
140 141 status_spw = spacewire_start_link( fdSPW );
141 142 if ( status_spw != RTEMS_SUCCESSFUL )
142 143 {
143 144 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
144 145 }
145 146 }
146 147 // </SPACEWIRE INITIALIZATION>
147 148 // ***************************
148 149
149 150 status = start_all_tasks(); // start all tasks
150 151 if (status != RTEMS_SUCCESSFUL)
151 152 {
152 153 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
153 154 }
154 155
155 156 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
156 157 status = start_recv_send_tasks();
157 158 if ( status != RTEMS_SUCCESSFUL )
158 159 {
159 160 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
160 161 }
161 162
162 163 // suspend science tasks. they will be restarted later depending on the mode
163 164 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
164 165 if (status != RTEMS_SUCCESSFUL)
165 166 {
166 167 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
167 168 }
168 169
169 170
170 171 //******************************
171 172 // <SPECTRAL MATRICES SIMULATOR>
172 173 LEON_Mask_interrupt( IRQ_SM );
173 174 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
174 175 IRQ_SPARC_SM, spectral_matrices_isr_simu );
175 176 // </SPECTRAL MATRICES SIMULATOR>
176 177 //*******************************
177 178
178 179 // configure IRQ handling for the waveform picker unit
179 180 status = rtems_interrupt_catch( waveforms_isr,
180 181 IRQ_SPARC_WAVEFORM_PICKER,
181 182 &old_isr_handler) ;
182 183
183 184 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
184 185 if ( status_spw != RTEMS_SUCCESSFUL )
185 186 {
186 187 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
187 188 if ( status != RTEMS_SUCCESSFUL ) {
188 189 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
189 190 }
190 191 }
191 192
192 193 BOOT_PRINTF("delete INIT\n")
193 194
194 195 status = rtems_task_delete(RTEMS_SELF);
195 196
196 197 }
197 198
198 199 void init_local_mode_parameters( void )
199 200 {
200 201 /** This function initialize the param_local global variable with default values.
201 202 *
202 203 */
203 204
204 205 unsigned int i;
205 206
206 207 // LOCAL PARAMETERS
207 208 set_local_nb_interrupt_f0_MAX();
208 209
209 210 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
210 211 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
211 212 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
212 213
213 214 // init sequence counters
214 215
215 216 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
216 217 {
217 218 sequenceCounters_TC_EXE[i] = 0x00;
218 219 }
219 220 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
220 221 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
221 222 }
222 223
223 224 void create_names( void ) // create all names for tasks and queues
224 225 {
225 226 /** This function creates all RTEMS names used in the software for tasks and queues.
226 227 *
227 228 * @return RTEMS directive status codes:
228 229 * - RTEMS_SUCCESSFUL - successful completion
229 230 *
230 231 */
231 232
232 233 // task names
233 234 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
234 235 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
235 236 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
236 237 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
237 238 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
238 239 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
239 240 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
240 241 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
241 242 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
242 243 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
243 244 Task_name[TASKID_MATR] = rtems_build_name( 'M', 'A', 'T', 'R' );
244 245 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
245 246 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
246 247 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
247 248 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
248 249 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
249 250
250 251 // rate monotonic period names
251 252 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
252 253
253 254 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
254 255 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
255 256 }
256 257
257 258 int create_all_tasks( void ) // create all tasks which run in the software
258 259 {
259 260 /** This function creates all RTEMS tasks used in the software.
260 261 *
261 262 * @return RTEMS directive status codes:
262 263 * - RTEMS_SUCCESSFUL - task created successfully
263 264 * - RTEMS_INVALID_ADDRESS - id is NULL
264 265 * - RTEMS_INVALID_NAME - invalid task name
265 266 * - RTEMS_INVALID_PRIORITY - invalid task priority
266 267 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
267 268 * - RTEMS_TOO_MANY - too many tasks created
268 269 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
269 270 * - RTEMS_TOO_MANY - too many global objects
270 271 *
271 272 */
272 273
273 274 rtems_status_code status;
274 275
275 276 // RECV
276 277 status = rtems_task_create(
277 278 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
278 279 RTEMS_DEFAULT_MODES,
279 280 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
280 281 );
281 282
282 283 if (status == RTEMS_SUCCESSFUL) // ACTN
283 284 {
284 285 status = rtems_task_create(
285 286 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
286 287 RTEMS_DEFAULT_MODES,
287 288 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
288 289 );
289 290 }
290 291 if (status == RTEMS_SUCCESSFUL) // SPIQ
291 292 {
292 293 status = rtems_task_create(
293 294 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
294 295 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
295 296 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
296 297 );
297 298 }
298 299 if (status == RTEMS_SUCCESSFUL) // SMIQ
299 300 {
300 301 status = rtems_task_create(
301 302 Task_name[TASKID_SMIQ], TASK_PRIORITY_SMIQ, RTEMS_MINIMUM_STACK_SIZE,
302 303 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
303 304 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SMIQ]
304 305 );
305 306 }
306 307 if (status == RTEMS_SUCCESSFUL) // STAT
307 308 {
308 309 status = rtems_task_create(
309 310 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
310 311 RTEMS_DEFAULT_MODES,
311 312 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
312 313 );
313 314 }
314 315 if (status == RTEMS_SUCCESSFUL) // AVF0
315 316 {
316 317 status = rtems_task_create(
317 318 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
318 319 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
319 320 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
320 321 );
321 322 }
322 323 if (status == RTEMS_SUCCESSFUL) // BPF0
323 324 {
324 325 status = rtems_task_create(
325 326 Task_name[TASKID_BPF0], TASK_PRIORITY_BPF0, RTEMS_MINIMUM_STACK_SIZE,
326 327 RTEMS_DEFAULT_MODES,
327 328 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_BPF0]
328 329 );
329 330 }
330 331 if (status == RTEMS_SUCCESSFUL) // WFRM
331 332 {
332 333 status = rtems_task_create(
333 334 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
334 335 RTEMS_DEFAULT_MODES,
335 336 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
336 337 );
337 338 }
338 339 if (status == RTEMS_SUCCESSFUL) // DUMB
339 340 {
340 341 status = rtems_task_create(
341 342 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
342 343 RTEMS_DEFAULT_MODES,
343 344 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
344 345 );
345 346 }
346 347 if (status == RTEMS_SUCCESSFUL) // HOUS
347 348 {
348 349 status = rtems_task_create(
349 350 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
350 351 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
351 352 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
352 353 );
353 354 }
354 355 if (status == RTEMS_SUCCESSFUL) // MATR
355 356 {
356 357 status = rtems_task_create(
357 358 Task_name[TASKID_MATR], TASK_PRIORITY_MATR, RTEMS_MINIMUM_STACK_SIZE,
358 359 RTEMS_DEFAULT_MODES,
359 360 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_MATR]
360 361 );
361 362 }
362 363 if (status == RTEMS_SUCCESSFUL) // CWF3
363 364 {
364 365 status = rtems_task_create(
365 366 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
366 367 RTEMS_DEFAULT_MODES,
367 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF3]
368 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
368 369 );
369 370 }
370 371 if (status == RTEMS_SUCCESSFUL) // CWF2
371 372 {
372 373 status = rtems_task_create(
373 374 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
374 375 RTEMS_DEFAULT_MODES,
375 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF2]
376 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
376 377 );
377 378 }
378 379 if (status == RTEMS_SUCCESSFUL) // CWF1
379 380 {
380 381 status = rtems_task_create(
381 382 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
382 383 RTEMS_DEFAULT_MODES,
383 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF1]
384 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
384 385 );
385 386 }
386 387 if (status == RTEMS_SUCCESSFUL) // SEND
387 388 {
388 389 status = rtems_task_create(
389 390 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
390 391 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
391 392 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
392 393 );
393 394 }
394 395 if (status == RTEMS_SUCCESSFUL) // WTDG
395 396 {
396 397 status = rtems_task_create(
397 398 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
398 399 RTEMS_DEFAULT_MODES,
399 400 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
400 401 );
401 402 }
402 403
403 404 return status;
404 405 }
405 406
406 407 int start_recv_send_tasks( void )
407 408 {
408 409 rtems_status_code status;
409 410
410 411 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
411 412 if (status!=RTEMS_SUCCESSFUL) {
412 413 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
413 414 }
414 415
415 416 if (status == RTEMS_SUCCESSFUL) // SEND
416 417 {
417 418 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
418 419 if (status!=RTEMS_SUCCESSFUL) {
419 420 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
420 421 }
421 422 }
422 423
423 424 return status;
424 425 }
425 426
426 427 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
427 428 {
428 429 /** This function starts all RTEMS tasks used in the software.
429 430 *
430 431 * @return RTEMS directive status codes:
431 432 * - RTEMS_SUCCESSFUL - ask started successfully
432 433 * - RTEMS_INVALID_ADDRESS - invalid task entry point
433 434 * - RTEMS_INVALID_ID - invalid task id
434 435 * - RTEMS_INCORRECT_STATE - task not in the dormant state
435 436 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
436 437 *
437 438 */
438 439 // starts all the tasks fot eh flight software
439 440
440 441 rtems_status_code status;
441 442
442 443 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
443 444 if (status!=RTEMS_SUCCESSFUL) {
444 445 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
445 446 }
446 447
447 448 if (status == RTEMS_SUCCESSFUL) // WTDG
448 449 {
449 450 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
450 451 if (status!=RTEMS_SUCCESSFUL) {
451 452 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
452 453 }
453 454 }
454 455
455 456 if (status == RTEMS_SUCCESSFUL) // SMIQ
456 457 {
457 458 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
458 459 if (status!=RTEMS_SUCCESSFUL) {
459 460 BOOT_PRINTF("in INIT *** Error starting TASK_BPPR\n")
460 461 }
461 462 }
462 463
463 464 if (status == RTEMS_SUCCESSFUL) // ACTN
464 465 {
465 466 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
466 467 if (status!=RTEMS_SUCCESSFUL) {
467 468 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
468 469 }
469 470 }
470 471
471 472 if (status == RTEMS_SUCCESSFUL) // STAT
472 473 {
473 474 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
474 475 if (status!=RTEMS_SUCCESSFUL) {
475 476 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
476 477 }
477 478 }
478 479
479 480 if (status == RTEMS_SUCCESSFUL) // AVF0
480 481 {
481 482 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
482 483 if (status!=RTEMS_SUCCESSFUL) {
483 484 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
484 485 }
485 486 }
486 487
487 488 if (status == RTEMS_SUCCESSFUL) // BPF0
488 489 {
489 490 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
490 491 if (status!=RTEMS_SUCCESSFUL) {
491 492 BOOT_PRINTF("in INIT *** Error starting TASK_BPF0\n")
492 493 }
493 494 }
494 495
495 496 if (status == RTEMS_SUCCESSFUL) // WFRM
496 497 {
497 498 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
498 499 if (status!=RTEMS_SUCCESSFUL) {
499 500 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
500 501 }
501 502 }
502 503
503 504 if (status == RTEMS_SUCCESSFUL) // DUMB
504 505 {
505 506 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
506 507 if (status!=RTEMS_SUCCESSFUL) {
507 508 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
508 509 }
509 510 }
510 511
511 512 if (status == RTEMS_SUCCESSFUL) // HOUS
512 513 {
513 514 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
514 515 if (status!=RTEMS_SUCCESSFUL) {
515 516 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
516 517 }
517 518 }
518 519
519 520 if (status == RTEMS_SUCCESSFUL) // MATR
520 521 {
521 522 status = rtems_task_start( Task_id[TASKID_MATR], matr_task, 1 );
522 523 if (status!=RTEMS_SUCCESSFUL) {
523 524 BOOT_PRINTF("in INIT *** Error starting TASK_MATR\n")
524 525 }
525 526 }
526 527
527 528 if (status == RTEMS_SUCCESSFUL) // CWF3
528 529 {
529 530 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
530 531 if (status!=RTEMS_SUCCESSFUL) {
531 532 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
532 533 }
533 534 }
534 535
535 536 if (status == RTEMS_SUCCESSFUL) // CWF2
536 537 {
537 538 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
538 539 if (status!=RTEMS_SUCCESSFUL) {
539 540 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
540 541 }
541 542 }
542 543
543 544 if (status == RTEMS_SUCCESSFUL) // CWF1
544 545 {
545 546 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
546 547 if (status!=RTEMS_SUCCESSFUL) {
547 548 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
548 549 }
549 550 }
550 551 return status;
551 552 }
552 553
553 554 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
554 555 {
555 556 rtems_status_code status_recv;
556 557 rtems_status_code status_send;
557 558 rtems_status_code ret;
558 559 rtems_id queue_id;
559 560
560 561 // create the queue for handling valid TCs
561 562 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
562 563 ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
563 564 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
564 565 if ( status_recv != RTEMS_SUCCESSFUL ) {
565 566 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
566 567 }
567 568
568 569 // create the queue for handling TM packet sending
569 570 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
570 571 ACTION_MSG_PKTS_COUNT, ACTION_MSG_PKTS_MAX_SIZE,
571 572 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
572 573 if ( status_send != RTEMS_SUCCESSFUL ) {
573 574 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
574 575 }
575 576
576 577 if ( status_recv != RTEMS_SUCCESSFUL )
577 578 {
578 579 ret = status_recv;
579 580 }
580 581 else
581 582 {
582 583 ret = status_send;
583 584 }
584 585
585 586 return ret;
586 587 }
587 588
588 589 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
589 590 {
590 591 rtems_status_code status;
591 592 rtems_name queue_name;
592 593
593 594 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
594 595
595 596 status = rtems_message_queue_ident( queue_name, 0, queue_id );
596 597
597 598 return status;
598 599 }
599 600
600 601 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
601 602 {
602 603 rtems_status_code status;
603 604 rtems_name queue_name;
604 605
605 606 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
606 607
607 608 status = rtems_message_queue_ident( queue_name, 0, queue_id );
608 609
609 610 return status;
610 611 }
@@ -1,601 +1,601
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 19 //***********
20 20 // RTEMS TASK
21 21 rtems_task spiq_task(rtems_task_argument unused)
22 22 {
23 23 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
24 24 *
25 25 * @param unused is the starting argument of the RTEMS task
26 26 *
27 27 */
28 28
29 29 rtems_event_set event_out;
30 30 rtems_status_code status;
31 31 int linkStatus;
32 32
33 33 BOOT_PRINTF("in SPIQ *** \n")
34 34
35 35 while(true){
36 36 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
37 37 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
38 38
39 39 // [0] SUSPEND RECV AND SEND TASKS
40 40 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
41 41 if ( status != RTEMS_SUCCESSFUL ) {
42 42 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
43 43 }
44 44 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
45 45 if ( status != RTEMS_SUCCESSFUL ) {
46 46 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
47 47 }
48 48
49 49 // [1] CHECK THE LINK
50 50 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
51 51 if ( linkStatus != 5) {
52 52 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
53 53 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
54 54 }
55 55
56 56 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
57 57 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
58 58 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
59 59 {
60 60 spacewire_compute_stats_offsets();
61 61 status = spacewire_reset_link( );
62 62 }
63 63 else // [2.b] in run state, start the link
64 64 {
65 65 status = spacewire_stop_start_link( fdSPW ); // start the link
66 66 if ( status != RTEMS_SUCCESSFUL)
67 67 {
68 68 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
69 69 }
70 70 }
71 71
72 72 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
73 73 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
74 74 {
75 75 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
76 76 if ( status != RTEMS_SUCCESSFUL ) {
77 77 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
78 78 }
79 79 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
80 80 if ( status != RTEMS_SUCCESSFUL ) {
81 81 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
82 82 }
83 83 }
84 84 else // [3.b] the link is not in run state, go in STANDBY mode
85 85 {
86 86 status = stop_current_mode();
87 87 if ( status != RTEMS_SUCCESSFUL ) {
88 88 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
89 89 }
90 status = enter_standby_mode();
90 status = enter_mode( LFR_MODE_STANDBY );
91 91 if ( status != RTEMS_SUCCESSFUL ) {
92 92 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
93 93 }
94 94 // wake the WTDG task up to wait for the link recovery
95 95 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
96 96 status = rtems_task_suspend( RTEMS_SELF );
97 97 }
98 98 }
99 99 }
100 100
101 101 rtems_task recv_task( rtems_task_argument unused )
102 102 {
103 103 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
104 104 *
105 105 * @param unused is the starting argument of the RTEMS task
106 106 *
107 107 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
108 108 * 1. It reads the incoming data.
109 109 * 2. Launches the acceptance procedure.
110 110 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
111 111 *
112 112 */
113 113
114 114 int len;
115 115 ccsdsTelecommandPacket_t currentTC;
116 116 unsigned char computed_CRC[ 2 ];
117 117 unsigned char currentTC_LEN_RCV[ 2 ];
118 118 unsigned char destinationID;
119 119 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
120 120 unsigned int parserCode;
121 121 unsigned char time[6];
122 122 rtems_status_code status;
123 123 rtems_id queue_recv_id;
124 124 rtems_id queue_send_id;
125 125
126 126 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
127 127
128 128 status = get_message_queue_id_recv( &queue_recv_id );
129 129 if (status != RTEMS_SUCCESSFUL)
130 130 {
131 131 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
132 132 }
133 133
134 134 status = get_message_queue_id_send( &queue_send_id );
135 135 if (status != RTEMS_SUCCESSFUL)
136 136 {
137 137 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
138 138 }
139 139
140 140 BOOT_PRINTF("in RECV *** \n")
141 141
142 142 while(1)
143 143 {
144 144 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
145 145 if (len == -1){ // error during the read call
146 146 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
147 147 }
148 148 else {
149 149 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
150 150 PRINTF("in RECV *** packet lenght too short\n")
151 151 }
152 152 else {
153 153 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
154 154 currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8);
155 155 currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt );
156 156 // CHECK THE TC
157 157 parserCode = tc_parser( &currentTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ;
158 158 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
159 159 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
160 160 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
161 161 || (parserCode == WRONG_SRC_ID) )
162 162 { // send TM_LFR_TC_EXE_CORRUPTED
163 163 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
164 164 &&
165 165 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
166 166 )
167 167 {
168 168 if ( parserCode == WRONG_SRC_ID )
169 169 {
170 170 destinationID = SID_TC_GROUND;
171 171 }
172 172 else
173 173 {
174 174 destinationID = currentTC.sourceID;
175 175 }
176 176 getTime( time );
177 177 close_action( &currentTC, LFR_DEFAULT, queue_send_id, time);
178 178 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
179 179 computed_CRC, currentTC_LEN_RCV,
180 180 destinationID, time );
181 181 }
182 182 }
183 183 else
184 184 { // send valid TC to the action launcher
185 185 status = rtems_message_queue_send( queue_recv_id, &currentTC,
186 186 currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3);
187 187 }
188 188 }
189 189 }
190 190 }
191 191 }
192 192
193 193 rtems_task send_task( rtems_task_argument argument)
194 194 {
195 195 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
196 196 *
197 197 * @param unused is the starting argument of the RTEMS task
198 198 *
199 199 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
200 200 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
201 201 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
202 202 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
203 203 * data it contains.
204 204 *
205 205 */
206 206
207 207 rtems_status_code status; // RTEMS status code
208 208 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
209 209 spw_ioctl_pkt_send *spw_ioctl_send;
210 210 size_t size; // size of the incoming TC packet
211 211 u_int32_t count;
212 212 rtems_id queue_id;
213 213
214 214 status = get_message_queue_id_send( &queue_id );
215 215 if (status != RTEMS_SUCCESSFUL)
216 216 {
217 217 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
218 218 }
219 219
220 220 BOOT_PRINTF("in SEND *** \n")
221 221
222 222 while(1)
223 223 {
224 224 status = rtems_message_queue_receive( queue_id, incomingData, &size,
225 225 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
226 226
227 227 if (status!=RTEMS_SUCCESSFUL)
228 228 {
229 229 PRINTF1("in SEND *** (1) ERR = %d\n", status)
230 230 }
231 231 else
232 232 {
233 233 if ( incomingData[0] == CCSDS_DESTINATION_ID) // the incoming message is a ccsds packet
234 234 {
235 235 status = write( fdSPW, incomingData, size );
236 236 if (status == -1){
237 237 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
238 238 }
239 239 }
240 240 else // the incoming message is a spw_ioctl_pkt_send structure
241 241 {
242 242 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
243 243 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
244 244 if (status == -1){
245 245 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
246 246 }
247 247 }
248 248 }
249 249
250 250 status = rtems_message_queue_get_number_pending( queue_id, &count );
251 251 if (status != RTEMS_SUCCESSFUL)
252 252 {
253 253 PRINTF1("in SEND *** (3) ERR = %d\n", status)
254 254 }
255 255 else
256 256 {
257 257 if (count > maxCount)
258 258 {
259 259 maxCount = count;
260 260 }
261 261 }
262 262 }
263 263 }
264 264
265 265 rtems_task wtdg_task( rtems_task_argument argument )
266 266 {
267 267 rtems_event_set event_out;
268 268 rtems_status_code status;
269 269 int linkStatus;
270 270
271 271 BOOT_PRINTF("in WTDG ***\n")
272 272
273 273 while(1)
274 274 {
275 275 // wait for an RTEMS_EVENT
276 276 rtems_event_receive( RTEMS_EVENT_0,
277 277 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
278 278 PRINTF("in WTDG *** wait for the link\n")
279 279 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
280 280 while( linkStatus != 5) // wait for the link
281 281 {
282 282 rtems_task_wake_after( 10 );
283 283 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
284 284 }
285 285
286 286 status = spacewire_stop_start_link( fdSPW );
287 287
288 288 if (status != RTEMS_SUCCESSFUL)
289 289 {
290 290 PRINTF1("in WTDG *** ERR link not started %d\n", status)
291 291 }
292 292 else
293 293 {
294 294 PRINTF("in WTDG *** OK link started\n")
295 295 }
296 296
297 297 // restart the SPIQ task
298 298 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
299 299 if ( status != RTEMS_SUCCESSFUL ) {
300 300 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
301 301 }
302 302
303 303 // restart RECV and SEND
304 304 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
305 305 if ( status != RTEMS_SUCCESSFUL ) {
306 306 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
307 307 }
308 308 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
309 309 if ( status != RTEMS_SUCCESSFUL ) {
310 310 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
311 311 }
312 312 }
313 313 }
314 314
315 315 //****************
316 316 // OTHER FUNCTIONS
317 317 int spacewire_open_link( void )
318 318 {
319 319 /** This function opens the SpaceWire link.
320 320 *
321 321 * @return a valid file descriptor in case of success, -1 in case of a failure
322 322 *
323 323 */
324 324 rtems_status_code status;
325 325
326 326 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
327 327 if ( fdSPW < 0 ) {
328 328 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
329 329 }
330 330 else
331 331 {
332 332 status = RTEMS_SUCCESSFUL;
333 333 }
334 334
335 335 return status;
336 336 }
337 337
338 338 int spacewire_start_link( int fd )
339 339 {
340 340 rtems_status_code status;
341 341
342 342 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
343 343 // -1 default hardcoded driver timeout
344 344
345 345 return status;
346 346 }
347 347
348 348 int spacewire_stop_start_link( int fd )
349 349 {
350 350 rtems_status_code status;
351 351
352 352 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
353 353 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
354 354 // -1 default hardcoded driver timeout
355 355
356 356 return status;
357 357 }
358 358
359 359 int spacewire_configure_link( int fd )
360 360 {
361 361 /** This function configures the SpaceWire link.
362 362 *
363 363 * @return GR-RTEMS-DRIVER directive status codes:
364 364 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
365 365 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
366 366 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
367 367 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
368 368 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
369 369 * - 5 EIO - Error when writing to grswp hardware registers.
370 370 * - 2 ENOENT - No such file or directory
371 371 */
372 372
373 373 rtems_status_code status;
374 374
375 375 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
376 376 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
377 377
378 378 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
379 379 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
380 380 //
381 381 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 382 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
383 383 //
384 384 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
385 385 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
386 386 //
387 387 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
388 388 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
389 389 //
390 390 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
391 391 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
392 392 //
393 393 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
394 394 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
395 395 //
396 396 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
397 397 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
398 398
399 399 return status;
400 400 }
401 401
402 402 int spacewire_reset_link( void )
403 403 {
404 404 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
405 405 *
406 406 * @return RTEMS directive status code:
407 407 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
408 408 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
409 409 *
410 410 */
411 411
412 412 rtems_status_code status_spw;
413 413 int i;
414 414
415 415 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
416 416 {
417 417 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
418 418
419 419 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
420 420
421 421 status_spw = spacewire_stop_start_link( fdSPW );
422 422 if ( status_spw != RTEMS_SUCCESSFUL )
423 423 {
424 424 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
425 425 }
426 426
427 427 if ( status_spw == RTEMS_SUCCESSFUL)
428 428 {
429 429 break;
430 430 }
431 431 }
432 432
433 433 return status_spw;
434 434 }
435 435
436 436 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
437 437 {
438 438 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
439 439 *
440 440 * @param val is the value, 0 or 1, used to set the value of the NP bit.
441 441 * @param regAddr is the address of the GRSPW control register.
442 442 *
443 443 * NP is the bit 20 of the GRSPW control register.
444 444 *
445 445 */
446 446
447 447 unsigned int *spwptr = (unsigned int*) regAddr;
448 448
449 449 if (val == 1) {
450 450 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
451 451 }
452 452 if (val== 0) {
453 453 *spwptr = *spwptr & 0xffdfffff;
454 454 }
455 455 }
456 456
457 457 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
458 458 {
459 459 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
460 460 *
461 461 * @param val is the value, 0 or 1, used to set the value of the RE bit.
462 462 * @param regAddr is the address of the GRSPW control register.
463 463 *
464 464 * RE is the bit 16 of the GRSPW control register.
465 465 *
466 466 */
467 467
468 468 unsigned int *spwptr = (unsigned int*) regAddr;
469 469
470 470 if (val == 1)
471 471 {
472 472 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
473 473 }
474 474 if (val== 0)
475 475 {
476 476 *spwptr = *spwptr & 0xfffdffff;
477 477 }
478 478 }
479 479
480 480 void spacewire_compute_stats_offsets( void )
481 481 {
482 482 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
483 483 *
484 484 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
485 485 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
486 486 * during the open systel call).
487 487 *
488 488 */
489 489
490 490 spw_stats spacewire_stats_grspw;
491 491 rtems_status_code status;
492 492
493 493 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
494 494
495 495 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
496 496 + spacewire_stats.packets_received;
497 497 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
498 498 + spacewire_stats.packets_sent;
499 499 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
500 500 + spacewire_stats.parity_err;
501 501 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
502 502 + spacewire_stats.disconnect_err;
503 503 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
504 504 + spacewire_stats.escape_err;
505 505 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
506 506 + spacewire_stats.credit_err;
507 507 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
508 508 + spacewire_stats.write_sync_err;
509 509 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
510 510 + spacewire_stats.rx_rmap_header_crc_err;
511 511 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
512 512 + spacewire_stats.rx_rmap_data_crc_err;
513 513 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
514 514 + spacewire_stats.early_ep;
515 515 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
516 516 + spacewire_stats.invalid_address;
517 517 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
518 518 + spacewire_stats.rx_eep_err;
519 519 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
520 520 + spacewire_stats.rx_truncated;
521 521 }
522 522
523 523 void spacewire_update_statistics( void )
524 524 {
525 525 rtems_status_code status;
526 526 spw_stats spacewire_stats_grspw;
527 527
528 528 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
529 529
530 530 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
531 531 + spacewire_stats_grspw.packets_received;
532 532 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
533 533 + spacewire_stats_grspw.packets_sent;
534 534 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
535 535 + spacewire_stats_grspw.parity_err;
536 536 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
537 537 + spacewire_stats_grspw.disconnect_err;
538 538 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
539 539 + spacewire_stats_grspw.escape_err;
540 540 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
541 541 + spacewire_stats_grspw.credit_err;
542 542 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
543 543 + spacewire_stats_grspw.write_sync_err;
544 544 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
545 545 + spacewire_stats_grspw.rx_rmap_header_crc_err;
546 546 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
547 547 + spacewire_stats_grspw.rx_rmap_data_crc_err;
548 548 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
549 549 + spacewire_stats_grspw.early_ep;
550 550 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
551 551 + spacewire_stats_grspw.invalid_address;
552 552 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
553 553 + spacewire_stats_grspw.rx_eep_err;
554 554 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
555 555 + spacewire_stats_grspw.rx_truncated;
556 556 //spacewire_stats.tx_link_err;
557 557
558 558 //****************************
559 559 // DPU_SPACEWIRE_IF_STATISTICS
560 560 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
561 561 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
562 562 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
563 563 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
564 564 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
565 565 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
566 566
567 567 //******************************************
568 568 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
569 569 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
570 570 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
571 571 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
572 572 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
573 573 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
574 574
575 575 //*********************************************
576 576 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
577 577 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
578 578 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
579 579 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
580 580 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
581 581 }
582 582
583 583 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
584 584 {
585 585 //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
586 586 // printf("In timecode_irq_handler *** Error sending event to DUMB\n");
587 587 //}
588 588 }
589 589
590 590 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
591 591 {
592 592 int linkStatus;
593 593 rtems_status_code status;
594 594
595 595 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
596 596
597 597 if ( linkStatus == 5) {
598 598 PRINTF("in spacewire_reset_link *** link is running\n")
599 599 status = RTEMS_SUCCESSFUL;
600 600 }
601 601 }
@@ -1,837 +1,748
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14
15 15 //***********
16 16 // RTEMS TASK
17 17
18 18 rtems_task actn_task( rtems_task_argument unused )
19 19 {
20 20 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 21 *
22 22 * @param unused is the starting argument of the RTEMS task
23 23 *
24 24 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 25 * on the incoming TeleCommand.
26 26 *
27 27 */
28 28
29 29 int result;
30 30 rtems_status_code status; // RTEMS status code
31 31 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 32 size_t size; // size of the incoming TC packet
33 33 unsigned char subtype; // subtype of the current TC packet
34 34 unsigned char time[6];
35 35 rtems_id queue_rcv_id;
36 36 rtems_id queue_snd_id;
37 37
38 38 status = get_message_queue_id_recv( &queue_rcv_id );
39 39 if (status != RTEMS_SUCCESSFUL)
40 40 {
41 41 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 42 }
43 43
44 44 status = get_message_queue_id_send( &queue_snd_id );
45 45 if (status != RTEMS_SUCCESSFUL)
46 46 {
47 47 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 48 }
49 49
50 50 result = LFR_SUCCESSFUL;
51 51 subtype = 0; // subtype of the current TC packet
52 52
53 53 BOOT_PRINTF("in ACTN *** \n")
54 54
55 55 while(1)
56 56 {
57 57 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 58 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 59 getTime( time ); // set time to the current time
60 60 if (status!=RTEMS_SUCCESSFUL)
61 61 {
62 62 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 63 }
64 64 else
65 65 {
66 66 subtype = TC.serviceSubType;
67 67 switch(subtype)
68 68 {
69 69 case TC_SUBTYPE_RESET:
70 70 result = action_reset( &TC, queue_snd_id, time );
71 71 close_action( &TC, result, queue_snd_id, time );
72 72 break;
73 73 //
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id, time );
77 77 break;
78 78 //
79 79 case TC_SUBTYPE_LOAD_NORM:
80 80 result = action_load_normal_par( &TC, queue_snd_id, time );
81 81 close_action( &TC, result, queue_snd_id, time );
82 82 break;
83 83 //
84 84 case TC_SUBTYPE_LOAD_BURST:
85 85 result = action_load_burst_par( &TC, queue_snd_id, time );
86 86 close_action( &TC, result, queue_snd_id, time );
87 87 break;
88 88 //
89 89 case TC_SUBTYPE_LOAD_SBM1:
90 90 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 91 close_action( &TC, result, queue_snd_id, time );
92 92 break;
93 93 //
94 94 case TC_SUBTYPE_LOAD_SBM2:
95 95 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 96 close_action( &TC, result, queue_snd_id, time );
97 97 break;
98 98 //
99 99 case TC_SUBTYPE_DUMP:
100 100 result = action_dump_par( queue_snd_id );
101 101 close_action( &TC, result, queue_snd_id, time );
102 102 break;
103 103 //
104 104 case TC_SUBTYPE_ENTER:
105 105 result = action_enter_mode( &TC, queue_snd_id, time );
106 106 close_action( &TC, result, queue_snd_id, time );
107 107 break;
108 108 //
109 109 case TC_SUBTYPE_UPDT_INFO:
110 110 result = action_update_info( &TC, queue_snd_id );
111 111 close_action( &TC, result, queue_snd_id, time );
112 112 break;
113 113 //
114 114 case TC_SUBTYPE_EN_CAL:
115 115 result = action_enable_calibration( &TC, queue_snd_id, time );
116 116 close_action( &TC, result, queue_snd_id, time );
117 117 break;
118 118 //
119 119 case TC_SUBTYPE_DIS_CAL:
120 120 result = action_disable_calibration( &TC, queue_snd_id, time );
121 121 close_action( &TC, result, queue_snd_id, time );
122 122 break;
123 123 //
124 124 case TC_SUBTYPE_UPDT_TIME:
125 125 result = action_update_time( &TC );
126 126 close_action( &TC, result, queue_snd_id, time );
127 127 break;
128 128 //
129 129 default:
130 130 break;
131 131 }
132 132 }
133 133 }
134 134 }
135 135
136 136 //***********
137 137 // TC ACTIONS
138 138
139 139 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 140 {
141 141 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 142 *
143 143 * @param TC points to the TeleCommand packet that is being processed
144 144 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 145 *
146 146 */
147 147
148 148 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
149 149 return LFR_DEFAULT;
150 150 }
151 151
152 152 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
153 153 {
154 154 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
155 155 *
156 156 * @param TC points to the TeleCommand packet that is being processed
157 157 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
158 158 *
159 159 */
160 160
161 161 rtems_status_code status;
162 162 unsigned char requestedMode;
163 163
164 164 requestedMode = TC->dataAndCRC[1];
165 165
166 166 if ( (requestedMode != LFR_MODE_STANDBY)
167 167 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
168 168 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
169 169 {
170 170 status = RTEMS_UNSATISFIED;
171 171 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_LFR_MODE, requestedMode, time );
172 172 }
173 173 else
174 174 {
175 175 printf("in action_enter_mode *** enter mode %d\n", requestedMode);
176 176
177 177 #ifdef PRINT_TASK_STATISTICS
178 178 if (requestedMode != LFR_MODE_STANDBY)
179 179 {
180 180 rtems_cpu_usage_reset();
181 181 maxCount = 0;
182 182 }
183 183 #endif
184 184
185 185 status = transition_validation(requestedMode);
186 186
187 187 if ( status == LFR_SUCCESSFUL ) {
188 188 if ( lfrCurrentMode != LFR_MODE_STANDBY)
189 189 {
190 190 status = stop_current_mode();
191 191 }
192 192 if (status != RTEMS_SUCCESSFUL)
193 193 {
194 194 PRINTF("ERR *** in action_enter *** stop_current_mode\n")
195 195 }
196 196 status = enter_mode( requestedMode );
197 197 }
198 198 else
199 199 {
200 200 PRINTF("ERR *** in action_enter *** transition rejected\n")
201 201 send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
202 202 }
203 203 }
204 204
205 205 return status;
206 206 }
207 207
208 208 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
209 209 {
210 210 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
211 211 *
212 212 * @param TC points to the TeleCommand packet that is being processed
213 213 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
214 214 *
215 215 * @return LFR directive status code:
216 216 * - LFR_DEFAULT
217 217 * - LFR_SUCCESSFUL
218 218 *
219 219 */
220 220
221 221 unsigned int val;
222 222 int result;
223 223
224 224 result = LFR_SUCCESSFUL;
225 225
226 226 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
227 227 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
228 228 val++;
229 229 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
230 230 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
231 231
232 232 return result;
233 233 }
234 234
235 235 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
236 236 {
237 237 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
238 238 *
239 239 * @param TC points to the TeleCommand packet that is being processed
240 240 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
241 241 *
242 242 */
243 243
244 244 int result;
245 245 unsigned char lfrMode;
246 246
247 247 result = LFR_DEFAULT;
248 248 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
249 249
250 250 if ( (lfrMode == LFR_MODE_STANDBY) || (lfrMode == LFR_MODE_BURST) || (lfrMode == LFR_MODE_SBM2) ) {
251 251 send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
252 252 result = LFR_DEFAULT;
253 253 }
254 254 else {
255 255 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
256 256 result = LFR_DEFAULT;
257 257 }
258 258 return result;
259 259 }
260 260
261 261 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
262 262 {
263 263 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
264 264 *
265 265 * @param TC points to the TeleCommand packet that is being processed
266 266 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
267 267 *
268 268 */
269 269
270 270 int result;
271 271 unsigned char lfrMode;
272 272
273 273 result = LFR_DEFAULT;
274 274 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
275 275
276 276 if ( (lfrMode == LFR_MODE_STANDBY) || (lfrMode == LFR_MODE_BURST) || (lfrMode == LFR_MODE_SBM2) ) {
277 277 send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
278 278 result = LFR_DEFAULT;
279 279 }
280 280 else {
281 281 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
282 282 result = LFR_DEFAULT;
283 283 }
284 284 return result;
285 285 }
286 286
287 287 int action_update_time(ccsdsTelecommandPacket_t *TC)
288 288 {
289 289 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
290 290 *
291 291 * @param TC points to the TeleCommand packet that is being processed
292 292 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
293 293 *
294 294 * @return LFR_SUCCESSFUL
295 295 *
296 296 */
297 297
298 298 unsigned int val;
299 299
300 300 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
301 301 + (TC->dataAndCRC[1] << 16)
302 302 + (TC->dataAndCRC[2] << 8)
303 303 + TC->dataAndCRC[3];
304 304 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
305 305 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
306 306 val++;
307 307 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
308 308 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
309 309 time_management_regs->ctrl = time_management_regs->ctrl | 1;
310 310
311 311 return LFR_SUCCESSFUL;
312 312 }
313 313
314 314 //*******************
315 315 // ENTERING THE MODES
316 316
317 317 int transition_validation(unsigned char requestedMode)
318 318 {
319 319 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
320 320 *
321 321 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
322 322 *
323 323 * @return LFR directive status codes:
324 324 * - LFR_SUCCESSFUL - the transition is authorized
325 325 * - LFR_DEFAULT - the transition is not authorized
326 326 *
327 327 */
328 328
329 329 int status;
330 330
331 331 switch (requestedMode)
332 332 {
333 333 case LFR_MODE_STANDBY:
334 334 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
335 335 status = LFR_DEFAULT;
336 336 }
337 337 else
338 338 {
339 339 status = LFR_SUCCESSFUL;
340 340 }
341 341 break;
342 342 case LFR_MODE_NORMAL:
343 343 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
344 344 status = LFR_DEFAULT;
345 345 }
346 346 else {
347 347 status = LFR_SUCCESSFUL;
348 348 }
349 349 break;
350 350 case LFR_MODE_BURST:
351 351 if ( lfrCurrentMode == LFR_MODE_BURST ) {
352 352 status = LFR_DEFAULT;
353 353 }
354 354 else {
355 355 status = LFR_SUCCESSFUL;
356 356 }
357 357 break;
358 358 case LFR_MODE_SBM1:
359 359 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
360 360 status = LFR_DEFAULT;
361 361 }
362 362 else {
363 363 status = LFR_SUCCESSFUL;
364 364 }
365 365 break;
366 366 case LFR_MODE_SBM2:
367 367 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
368 368 status = LFR_DEFAULT;
369 369 }
370 370 else {
371 371 status = LFR_SUCCESSFUL;
372 372 }
373 373 break;
374 374 default:
375 375 status = LFR_DEFAULT;
376 376 break;
377 377 }
378 378
379 379 return status;
380 380 }
381 381
382 int stop_current_mode()
382 int stop_current_mode(void)
383 383 {
384 384 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
385 385 *
386 386 * @return RTEMS directive status codes:
387 387 * - RTEMS_SUCCESSFUL - task restarted successfully
388 388 * - RTEMS_INVALID_ID - task id invalid
389 389 * - RTEMS_ALREADY_SUSPENDED - task already suspended
390 390 *
391 391 */
392 392
393 393 rtems_status_code status;
394 394
395 395 status = RTEMS_SUCCESSFUL;
396 396
397 397 // mask interruptions
398 398 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
399 399 //LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
400 400 LEON_Mask_interrupt( IRQ_SM ); // mask spectral matrix interrupt simulator
401 401 // reset registers
402 402 reset_wfp_burst_enable(); // reset burst and enable bits
403 403 reset_wfp_status(); // reset all the status bits
404 404 // clear interruptions
405 405 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
406 406 //LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
407 407 LEON_Clear_interrupt( IRQ_SM ); // clear spectral matrix interrupt simulator
408 408 //**********************
409 409 // suspend several tasks
410 410 if (lfrCurrentMode != LFR_MODE_STANDBY) {
411 411 status = suspend_science_tasks();
412 412 }
413 413
414 414 if (status != RTEMS_SUCCESSFUL)
415 415 {
416 416 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
417 417 }
418 418
419 419 return status;
420 420 }
421 421
422 422 int enter_mode(unsigned char mode )
423 423 {
424 424 /** This function is launched after a mode transition validation.
425 425 *
426 426 * @param mode is the mode in which LFR will be put.
427 427 *
428 428 * @return RTEMS directive status codes:
429 429 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
430 430 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
431 431 *
432 432 */
433 433
434 434 rtems_status_code status;
435 435
436 436 status = RTEMS_UNSATISFIED;
437 437
438 438 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d);
439 439 updateLFRCurrentMode();
440 440
441 switch(mode){
442 case LFR_MODE_STANDBY:
443 status = enter_standby_mode( );
444 break;
445 case LFR_MODE_NORMAL:
446 status = enter_normal_mode( );
447 break;
448 case LFR_MODE_BURST:
449 status = enter_burst_mode( );
450 break;
451 case LFR_MODE_SBM1:
452 status = enter_sbm1_mode( );
453 break;
454 case LFR_MODE_SBM2:
455 status = enter_sbm2_mode( );
456 break;
457 default:
441 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
442 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
443 {
444 status = restart_science_tasks();
445 launch_waveform_picker( mode );
446 // launch_spectral_matrix( mode );
447 }
448 else if ( mode == LFR_MODE_STANDBY )
449 {
450 status = stop_current_mode();
451 }
452 else
453 {
458 454 status = RTEMS_UNSATISFIED;
459 455 }
460 456
457 if (mode == LFR_MODE_STANDBY)
458 {
459 PRINTF1("maxCount = %d\n", maxCount)
460 #ifdef PRINT_TASK_STATISTICS
461 rtems_cpu_usage_report();
462 #endif
463
464 #ifdef PRINT_STACK_REPORT
465 rtems_stack_checker_report_usage();
466 #endif
467 }
468
461 469 if (status != RTEMS_SUCCESSFUL)
462 470 {
463 PRINTF("in enter_mode *** ERR\n")
471 PRINTF1("in enter_mode *** ERR = %d\n", status)
464 472 status = RTEMS_UNSATISFIED;
465 473 }
466 474
467 475 return status;
468 476 }
469 477
470 int enter_standby_mode()
471 {
472 /** This function is used to enter the STANDBY mode.
473 *
474 * @return RTEMS directive status codes:
475 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
476 *
477 */
478
479 PRINTF1("maxCount = %d\n", maxCount)
480
481 #ifdef PRINT_TASK_STATISTICS
482 rtems_cpu_usage_report();
483 #endif
484
485 #ifdef PRINT_STACK_REPORT
486 rtems_stack_checker_report_usage();
487 #endif
488
489 return LFR_SUCCESSFUL;
490 }
491
492 int enter_normal_mode()
493 {
494 rtems_status_code status;
495
496 status = restart_science_tasks();
497
498 launch_waveform_picker( LFR_MODE_NORMAL );
499 // launch_spectral_matrix( LFR_MODE_NORMAL );
500
501 return status;
502 }
503
504 int enter_burst_mode()
505 {
506 /** This function is used to enter the STANDBY mode.
507 *
508 * @return RTEMS directive status codes:
509 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
510 * - RTEMS_INVALID_ID - task id invalid
511 * - RTEMS_INCORRECT_STATE - task never started
512 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
513 *
514 */
515
516 rtems_status_code status;
517
518 status = restart_science_tasks();
519
520 launch_waveform_picker( LFR_MODE_BURST );
521
522 return status;
523 }
524
525 int enter_sbm1_mode()
526 {
527 /** This function is used to enter the SBM1 mode.
528 *
529 * @return RTEMS directive status codes:
530 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
531 * - RTEMS_INVALID_ID - task id invalid
532 * - RTEMS_INCORRECT_STATE - task never started
533 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
534 *
535 */
536
537 rtems_status_code status;
538
539 status = restart_science_tasks();
540
541 launch_waveform_picker( LFR_MODE_SBM1 );
542
543 return status;
544 }
545
546 int enter_sbm2_mode()
547 {
548 /** This function is used to enter the SBM2 mode.
549 *
550 * @return RTEMS directive status codes:
551 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
552 * - RTEMS_INVALID_ID - task id invalid
553 * - RTEMS_INCORRECT_STATE - task never started
554 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
555 *
556 */
557
558 rtems_status_code status;
559
560 status = restart_science_tasks();
561
562 launch_waveform_picker( LFR_MODE_SBM2 );
563
564 return status;
565 }
566
567 478 int restart_science_tasks()
568 479 {
569 480 /** This function is used to restart all science tasks.
570 481 *
571 482 * @return RTEMS directive status codes:
572 483 * - RTEMS_SUCCESSFUL - task restarted successfully
573 484 * - RTEMS_INVALID_ID - task id invalid
574 485 * - RTEMS_INCORRECT_STATE - task never started
575 486 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 487 *
577 488 * Science tasks are AVF0, BPF0, WFRM, CWF3, CW2, CWF1
578 489 *
579 490 */
580 491
581 492 rtems_status_code status[6];
582 493 rtems_status_code ret;
583 494
584 495 ret = RTEMS_SUCCESSFUL;
585 496
586 497 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], 1 );
587 498 if (status[0] != RTEMS_SUCCESSFUL)
588 499 {
589 500 PRINTF1("in restart_science_task *** 0 ERR %d\n", status[0])
590 501 }
591 502
592 503 status[1] = rtems_task_restart( Task_id[TASKID_BPF0],1 );
593 504 if (status[1] != RTEMS_SUCCESSFUL)
594 505 {
595 506 PRINTF1("in restart_science_task *** 1 ERR %d\n", status[1])
596 507 }
597 508
598 509 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 510 if (status[2] != RTEMS_SUCCESSFUL)
600 511 {
601 512 PRINTF1("in restart_science_task *** 2 ERR %d\n", status[2])
602 513 }
603 514
604 515 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 516 if (status[3] != RTEMS_SUCCESSFUL)
606 517 {
607 518 PRINTF1("in restart_science_task *** 3 ERR %d\n", status[3])
608 519 }
609 520
610 521 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 522 if (status[4] != RTEMS_SUCCESSFUL)
612 523 {
613 524 PRINTF1("in restart_science_task *** 4 ERR %d\n", status[4])
614 525 }
615 526
616 527 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 528 if (status[5] != RTEMS_SUCCESSFUL)
618 529 {
619 530 PRINTF1("in restart_science_task *** 5 ERR %d\n", status[5])
620 531 }
621 532
622 533 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || (status[2] != RTEMS_SUCCESSFUL) ||
623 534 (status[3] != RTEMS_SUCCESSFUL) || (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) )
624 535 {
625 536 ret = RTEMS_UNSATISFIED;
626 537 }
627 538
628 539 return ret;
629 540 }
630 541
631 542 int suspend_science_tasks()
632 543 {
633 544 /** This function suspends the science tasks.
634 545 *
635 546 * @return RTEMS directive status codes:
636 547 * - RTEMS_SUCCESSFUL - task restarted successfully
637 548 * - RTEMS_INVALID_ID - task id invalid
638 549 * - RTEMS_ALREADY_SUSPENDED - task already suspended
639 550 *
640 551 */
641 552
642 553 rtems_status_code status;
643 554
644 555 status = rtems_task_suspend( Task_id[TASKID_AVF0] );
645 556 if (status != RTEMS_SUCCESSFUL)
646 557 {
647 558 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
648 559 }
649 560
650 561 if (status == RTEMS_SUCCESSFUL) // suspend BPF0
651 562 {
652 563 status = rtems_task_suspend( Task_id[TASKID_BPF0] );
653 564 if (status != RTEMS_SUCCESSFUL)
654 565 {
655 566 PRINTF1("in suspend_science_task *** BPF0 ERR %d\n", status)
656 567 }
657 568 }
658 569
659 570 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
660 571 {
661 572 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
662 573 if (status != RTEMS_SUCCESSFUL)
663 574 {
664 575 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
665 576 }
666 577 }
667 578
668 579 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
669 580 {
670 581 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
671 582 if (status != RTEMS_SUCCESSFUL)
672 583 {
673 584 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
674 585 }
675 586 }
676 587
677 588 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
678 589 {
679 590 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
680 591 if (status != RTEMS_SUCCESSFUL)
681 592 {
682 593 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
683 594 }
684 595 }
685 596
686 597 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
687 598 {
688 599 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
689 600 if (status != RTEMS_SUCCESSFUL)
690 601 {
691 602 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
692 603 }
693 604 }
694 605
695 606 return status;
696 607 }
697 608
698 609 void launch_waveform_picker( unsigned char mode )
699 610 {
700 611 int startDate;
701 612
702 613 reset_current_ring_nodes();
703 614 reset_waveform_picker_regs();
704 615 set_wfp_burst_enable_register( mode );
705 616 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
706 617 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
707 618 startDate = time_management_regs->coarse_time + 2;
708 619 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x80; // [1000 0000]
709 620 waveform_picker_regs->start_date = startDate;
710 621 }
711 622
712 623 void launch_spectral_matrix( unsigned char mode )
713 624 {
714 625 reset_current_sm_ring_nodes();
715 626 reset_spectral_matrix_regs();
716 627 // Spectral Matrices simulator
717 628 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
718 629 set_local_nb_interrupt_f0_MAX();
719 630 LEON_Clear_interrupt( IRQ_SM );
720 631 LEON_Unmask_interrupt( IRQ_SM );
721 632 }
722 633
723 634 //****************
724 635 // CLOSING ACTIONS
725 636 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC, unsigned char *time)
726 637 {
727 638 /** This function is used to update the HK packets statistics after a successful TC execution.
728 639 *
729 640 * @param TC points to the TC being processed
730 641 * @param time is the time used to date the TC execution
731 642 *
732 643 */
733 644
734 645 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
735 646 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
736 647 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
737 648 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
738 649 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
739 650 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
740 651 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
741 652 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
742 653 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
743 654 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
744 655 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
745 656 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
746 657 }
747 658
748 659 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char *time)
749 660 {
750 661 /** This function is used to update the HK packets statistics after a TC rejection.
751 662 *
752 663 * @param TC points to the TC being processed
753 664 * @param time is the time used to date the TC rejection
754 665 *
755 666 */
756 667
757 668 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
758 669 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
759 670 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
760 671 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
761 672 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
762 673 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
763 674 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
764 675 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
765 676 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
766 677 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
767 678 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
768 679 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
769 680 }
770 681
771 682 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id, unsigned char *time)
772 683 {
773 684 /** This function is the last step of the TC execution workflow.
774 685 *
775 686 * @param TC points to the TC being processed
776 687 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
777 688 * @param queue_id is the id of the RTEMS message queue used to send TM packets
778 689 * @param time is the time used to date the TC execution
779 690 *
780 691 */
781 692
782 693 unsigned int val = 0;
783 694
784 695 if (result == LFR_SUCCESSFUL)
785 696 {
786 697 if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
787 698 &&
788 699 !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
789 700 )
790 701 {
791 702 send_tm_lfr_tc_exe_success( TC, queue_id, time );
792 703 }
793 704 update_last_TC_exe( TC, time );
794 705 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
795 706 val++;
796 707 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
797 708 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
798 709 }
799 710 else
800 711 {
801 712 update_last_TC_rej( TC, time );
802 713 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
803 714 val++;
804 715 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
805 716 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
806 717 }
807 718 }
808 719
809 720 //***************************
810 721 // Interrupt Service Routines
811 722 rtems_isr commutation_isr1( rtems_vector_number vector )
812 723 {
813 724 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
814 725 printf("In commutation_isr1 *** Error sending event to DUMB\n");
815 726 }
816 727 }
817 728
818 729 rtems_isr commutation_isr2( rtems_vector_number vector )
819 730 {
820 731 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
821 732 printf("In commutation_isr2 *** Error sending event to DUMB\n");
822 733 }
823 734 }
824 735
825 736 //****************
826 737 // OTHER FUNCTIONS
827 738 void updateLFRCurrentMode()
828 739 {
829 740 /** This function updates the value of the global variable lfrCurrentMode.
830 741 *
831 742 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
832 743 *
833 744 */
834 745 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
835 746 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
836 747 }
837 748
@@ -1,482 +1,483
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
18 18 {
19 19 /** This function updates the LFR registers with the incoming common parameters.
20 20 *
21 21 * @param TC points to the TeleCommand packet that is being processed
22 22 *
23 23 *
24 24 */
25 25
26 26 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
27 27 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
28 28 set_wfp_data_shaping( );
29 29 return LFR_SUCCESSFUL;
30 30 }
31 31
32 32 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
33 33 {
34 34 /** This function updates the LFR registers with the incoming normal parameters.
35 35 *
36 36 * @param TC points to the TeleCommand packet that is being processed
37 37 * @param queue_id is the id of the queue which handles TM related to this execution step
38 38 *
39 39 */
40 40
41 41 int result;
42 42 int flag;
43 43 rtems_status_code status;
44 44
45 45 flag = LFR_SUCCESSFUL;
46 46
47 47 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
48 48 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
49 49 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
50 50 flag = LFR_DEFAULT;
51 51 }
52 52
53 53 //***************
54 54 // sy_lfr_n_swf_l
55 55 if (flag == LFR_SUCCESSFUL)
56 56 {
57 57 result = set_sy_lfr_n_swf_l( TC, queue_id, time );
58 58 if (result != LFR_SUCCESSFUL)
59 59 {
60 60 flag = LFR_DEFAULT;
61 61 }
62 62 }
63 63
64 64 //***************
65 65 // sy_lfr_n_swf_p
66 66 if (flag == LFR_SUCCESSFUL)
67 67 {
68 68 result = set_sy_lfr_n_swf_p( TC, queue_id, time );
69 69 if (result != LFR_SUCCESSFUL)
70 70 {
71 71 flag = LFR_DEFAULT;
72 72 }
73 73 }
74 74
75 75 //***************
76 // SY_LFR_N_ASM_P
76 // sy_lfr_n_asm_p
77 77 if (flag == LFR_SUCCESSFUL)
78 78 {
79 79 result = set_sy_lfr_n_asm_p( TC, queue_id );
80 80 if (result != LFR_SUCCESSFUL)
81 81 {
82 82 flag = LFR_DEFAULT;
83 83 }
84 84 }
85 85
86 86 //***************
87 // SY_LFR_N_BP_P0
87 // sy_lfr_n_bp_p0
88 88 if (flag == LFR_SUCCESSFUL)
89 89 {
90 90 result = set_sy_lfr_n_bp_p0( TC, queue_id );
91 91 if (result != LFR_SUCCESSFUL)
92 92 {
93 93 flag = LFR_DEFAULT;
94 94 }
95 95 }
96 96
97 97 //***************
98 98 // sy_lfr_n_bp_p1
99 99 if (flag == LFR_SUCCESSFUL)
100 100 {
101 101 result = set_sy_lfr_n_bp_p1( TC, queue_id );
102 102 if (result != LFR_SUCCESSFUL)
103 103 {
104 104 flag = LFR_DEFAULT;
105 105 }
106 106 }
107 107
108 108 //*********************
109 109 // sy_lfr_n_cwf_long_f3
110 110 if (flag == LFR_SUCCESSFUL)
111 111 {
112 112 result = set_sy_lfr_n_cwf_long_f3( TC, queue_id );
113 113 if (result != LFR_SUCCESSFUL)
114 114 {
115 115 flag = LFR_DEFAULT;
116 116 }
117 117 }
118 118
119 119 return flag;
120 120 }
121 121
122 122 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
123 123 {
124 124 /** This function updates the LFR registers with the incoming burst parameters.
125 125 *
126 126 * @param TC points to the TeleCommand packet that is being processed
127 127 * @param queue_id is the id of the queue which handles TM related to this execution step
128 128 *
129 129 */
130 130
131 131 int result;
132 132 unsigned char lfrMode;
133 133 rtems_status_code status;
134 134
135 135 result = LFR_DEFAULT;
136 136 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
137 137
138 138 if ( lfrMode == LFR_MODE_BURST ) {
139 139 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
140 140 result = LFR_DEFAULT;
141 141 }
142 142 else {
143 143 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[0];
144 144 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[1];
145 145
146 146 result = LFR_SUCCESSFUL;
147 147 }
148 148
149 149 return result;
150 150 }
151 151
152 152 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
153 153 {
154 154 /** This function updates the LFR registers with the incoming sbm1 parameters.
155 155 *
156 156 * @param TC points to the TeleCommand packet that is being processed
157 157 * @param queue_id is the id of the queue which handles TM related to this execution step
158 158 *
159 159 */
160 160 int result;
161 161 unsigned char lfrMode;
162 162 rtems_status_code status;
163 163
164 164 result = LFR_DEFAULT;
165 165 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
166 166
167 167 if ( (lfrMode == LFR_MODE_SBM1) || (lfrMode == LFR_MODE_SBM2) ) {
168 168 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
169 169 result = LFR_DEFAULT;
170 170 }
171 171 else {
172 172 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[0];
173 173 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[1];
174 174
175 175 result = LFR_SUCCESSFUL;
176 176 }
177 177
178 178 return result;
179 179 }
180 180
181 181 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
182 182 {
183 183 /** This function updates the LFR registers with the incoming sbm2 parameters.
184 184 *
185 185 * @param TC points to the TeleCommand packet that is being processed
186 186 * @param queue_id is the id of the queue which handles TM related to this execution step
187 187 *
188 188 */
189 189
190 190 int result;
191 191 unsigned char lfrMode;
192 192 rtems_status_code status;
193 193
194 194 result = LFR_DEFAULT;
195 195 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
196 196
197 197 if ( (lfrMode == LFR_MODE_SBM2) || (lfrMode == LFR_MODE_SBM2) ) {
198 198 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id, time );
199 199 result = LFR_DEFAULT;
200 200 }
201 201 else {
202 202 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[0];
203 203 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[1];
204 204
205 205 result = LFR_SUCCESSFUL;
206 206 }
207 207
208 208 return result;
209 209 }
210 210
211 211 int action_dump_par( rtems_id queue_id )
212 212 {
213 213 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
214 214 *
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step.
216 216 *
217 217 * @return RTEMS directive status codes:
218 218 * - RTEMS_SUCCESSFUL - message sent successfully
219 219 * - RTEMS_INVALID_ID - invalid queue id
220 220 * - RTEMS_INVALID_SIZE - invalid message size
221 221 * - RTEMS_INVALID_ADDRESS - buffer is NULL
222 222 * - RTEMS_UNSATISFIED - out of message buffers
223 223 * - RTEMS_TOO_MANY - queue s limit has been reached
224 224 *
225 225 */
226 226
227 227 int status;
228 228
229 229 // UPDATE TIME
230 230 increment_seq_counter( parameter_dump_packet.packetSequenceControl );
231 231 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
232 232 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
233 233 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
234 234 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
235 235 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
236 236 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
237 237 // SEND DATA
238 238 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
239 239 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
240 240 if (status != RTEMS_SUCCESSFUL) {
241 241 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
242 242 }
243 243
244 244 return status;
245 245 }
246 246
247 247 //***********************
248 248 // NORMAL MODE PARAMETERS
249 249
250 250 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
251 251 {
252 252 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
253 253 *
254 254 * @param TC points to the TeleCommand packet that is being processed
255 255 * @param queue_id is the id of the queue which handles TM related to this execution step
256 256 *
257 257 */
258 258
259 259 unsigned int tmp;
260 260 int result;
261 261 unsigned char msb;
262 262 unsigned char lsb;
263 263 rtems_status_code status;
264 264
265 265 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L ];
266 266 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L+1 ];
267 267
268 268 tmp = ( unsigned int ) floor(
269 269 ( ( msb*256 ) + lsb ) / 16
270 270 ) * 16;
271 271
272 272 if ( (tmp < 16) || (tmp > 2048) ) // the snapshot period is a multiple of 16
273 273 { // 2048 is the maximum limit due to the size of the buffers
274 274 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_L+10, lsb, time );
275 275 result = WRONG_APP_DATA;
276 276 }
277 277 else if (tmp != 2048)
278 278 {
279 279 status = send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
280 280 result = FUNCT_NOT_IMPL;
281 281 }
282 282 else
283 283 {
284 284 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (tmp >> 8);
285 285 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (tmp );
286 286 result = LFR_SUCCESSFUL;
287 287 }
288 288
289 289 return result;
290 290 }
291 291
292 292 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time)
293 293 {
294 294 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
295 295 *
296 296 * @param TC points to the TeleCommand packet that is being processed
297 297 * @param queue_id is the id of the queue which handles TM related to this execution step
298 298 *
299 299 */
300 300
301 301 unsigned int tmp;
302 302 int result;
303 303 unsigned char msb;
304 304 unsigned char lsb;
305 305 rtems_status_code status;
306 306
307 307 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P ];
308 308 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P+1 ];
309 309
310 310 tmp = msb * 256 + lsb;
311 311
312 312 if ( tmp < 16 )
313 313 {
314 314 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_P+10, lsb, time );
315 315 result = WRONG_APP_DATA;
316 316 }
317 317 else
318 318 {
319 319 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (tmp >> 8);
320 320 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (tmp );
321 321 result = LFR_SUCCESSFUL;
322 322 }
323 323
324 324 return result;
325 325 }
326 326
327 327 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
328 328 {
329 329 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
330 330 *
331 331 * @param TC points to the TeleCommand packet that is being processed
332 332 * @param queue_id is the id of the queue which handles TM related to this execution step
333 333 *
334 334 */
335 335
336 336 int result;
337 337 unsigned char msb;
338 338 unsigned char lsb;
339 339
340 340 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P ];
341 341 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P+1 ];
342 342
343 343 parameter_dump_packet.sy_lfr_n_asm_p[0] = msb;
344 344 parameter_dump_packet.sy_lfr_n_asm_p[1] = lsb;
345 345 result = LFR_SUCCESSFUL;
346 346
347 347 return result;
348 348 }
349 349
350 350 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
351 351 {
352 352 /** This function sets the time between two basic parameter sets, in s (SY_LFR_N_BP_P0).
353 353 *
354 354 * @param TC points to the TeleCommand packet that is being processed
355 355 * @param queue_id is the id of the queue which handles TM related to this execution step
356 356 *
357 357 */
358 358
359 359 int status;
360 360
361 361 status = LFR_SUCCESSFUL;
362 362
363 363 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P0 ];
364 364
365 365 return status;
366 366 }
367 367
368 368 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
369 369 {
370 370 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
371 371 *
372 372 * @param TC points to the TeleCommand packet that is being processed
373 373 * @param queue_id is the id of the queue which handles TM related to this execution step
374 374 *
375 375 */
376 376
377 377 int status;
378 378
379 379 status = LFR_SUCCESSFUL;
380 380
381 381 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P1 ];
382 382
383 383 return status;
384 384 }
385 385
386 386 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
387 387 {
388 388 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
389 389 *
390 390 * @param TC points to the TeleCommand packet that is being processed
391 391 * @param queue_id is the id of the queue which handles TM related to this execution step
392 392 *
393 393 */
394 394
395 395 int status;
396 396
397 397 status = LFR_SUCCESSFUL;
398 398
399 399 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_CWF_LONG_F3 ];
400 400
401 401 return status;
402 402 }
403 403
404 404 //**********************
405 405 // BURST MODE PARAMETERS
406 406
407 407 //*********************
408 408 // SBM1 MODE PARAMETERS
409 409
410 410 //*********************
411 411 // SBM2 MODE PARAMETERS
412 412
413 413 //**********
414 414 // init dump
415 415
416 416 void init_parameter_dump( void )
417 417 {
418 418 /** This function initialize the parameter_dump_packet global variable with default values.
419 419 *
420 420 */
421 421
422 422 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
423 423 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
424 424 parameter_dump_packet.reserved = CCSDS_RESERVED;
425 425 parameter_dump_packet.userApplication = CCSDS_USER_APP;
426 426 parameter_dump_packet.packetID[0] = (unsigned char) (TM_PACKET_ID_PARAMETER_DUMP >> 8);
427 427 parameter_dump_packet.packetID[1] = (unsigned char) TM_PACKET_ID_PARAMETER_DUMP;
428 428 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
429 429 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
430 430 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
431 431 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
432 432 // DATA FIELD HEADER
433 433 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
434 434 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
435 435 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
436 436 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
437 437 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
438 438 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
439 439 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
440 440 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
441 441 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
442 442 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
443 443 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
444 444
445 445 //******************
446 446 // COMMON PARAMETERS
447 447 parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0;
448 448 parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1;
449 449
450 450 //******************
451 451 // NORMAL PARAMETERS
452 452 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (SY_LFR_N_SWF_L >> 8);
453 453 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (SY_LFR_N_SWF_L );
454 454 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (SY_LFR_N_SWF_P >> 8);
455 455 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (SY_LFR_N_SWF_P );
456 456 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (SY_LFR_N_ASM_P >> 8);
457 457 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (SY_LFR_N_ASM_P );
458 458 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) SY_LFR_N_BP_P0;
459 459 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) SY_LFR_N_BP_P1;
460 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) SY_LFR_N_CWF_LONG_F3;
460 461
461 462 //*****************
462 463 // BURST PARAMETERS
463 464 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
464 465 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
465 466
466 467 //****************
467 468 // SBM1 PARAMETERS
468 469 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
469 470 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
470 471
471 472 //****************
472 473 // SBM2 PARAMETERS
473 474 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
474 475 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
475 476 }
476 477
477 478
478 479
479 480
480 481
481 482
482 483
@@ -1,1350 +1,1300
1 1 /** Functions and tasks related to waveform packet generation.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 7 *
8 8 */
9 9
10 10 #include "wf_handler.h"
11 11
12 12 //*****************
13 13 // waveform headers
14 14 // SWF
15 15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
16 16 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
17 17 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
18 18 // CWF
19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[7];
20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[7];
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[7];
22 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[7];
23 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[7];
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 24
25 25 //**************
26 26 // waveform ring
27 27 ring_node waveform_ring_f0[NB_RING_NODES_F0];
28 28 ring_node waveform_ring_f1[NB_RING_NODES_F1];
29 29 ring_node waveform_ring_f2[NB_RING_NODES_F2];
30 30 ring_node *current_ring_node_f0;
31 31 ring_node *ring_node_to_send_swf_f0;
32 32 ring_node *current_ring_node_f1;
33 33 ring_node *ring_node_to_send_swf_f1;
34 34 ring_node *ring_node_to_send_cwf_f1;
35 35 ring_node *current_ring_node_f2;
36 36 ring_node *ring_node_to_send_swf_f2;
37 37 ring_node *ring_node_to_send_cwf_f2;
38 38
39 39 rtems_isr waveforms_isr( rtems_vector_number vector )
40 40 {
41 41 /** This is the interrupt sub routine called by the waveform picker core.
42 42 *
43 43 * This ISR launch different actions depending mainly on two pieces of information:
44 44 * 1. the values read in the registers of the waveform picker.
45 45 * 2. the current LFR mode.
46 46 *
47 47 */
48 48
49 49 static unsigned char nb_swf = 0;
50 50
51 51 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
52 52 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
53 53 { // in modes other than STANDBY and BURST, send the CWF_F3 data
54 54 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
55 55 // (1) change the receiving buffer for the waveform picker
56 56 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3_a) {
57 57 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_b);
58 58 }
59 59 else {
60 60 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_a);
61 61 }
62 62 // (2) send an event for the waveforms transmission
63 63 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
64 64 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
65 65 }
66 66 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
67 67 }
68 68 }
69 69
70 70 switch(lfrCurrentMode)
71 71 {
72 72 //********
73 73 // STANDBY
74 74 case(LFR_MODE_STANDBY):
75 75 break;
76 76
77 77 //******
78 78 // NORMAL
79 79 case(LFR_MODE_NORMAL):
80 80 if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits
81 81 {
82 82 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
83 83 }
84 84 if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits
85 85 {
86 86 // change F0 ring node
87 87 ring_node_to_send_swf_f0 = current_ring_node_f0;
88 88 current_ring_node_f0 = current_ring_node_f0->next;
89 89 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address;
90 90 // change F1 ring node
91 91 ring_node_to_send_swf_f1 = current_ring_node_f1;
92 92 current_ring_node_f1 = current_ring_node_f1->next;
93 93 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
94 94 // change F2 ring node
95 95 ring_node_to_send_swf_f2 = current_ring_node_f2;
96 96 current_ring_node_f2 = current_ring_node_f2->next;
97 97 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
98 98 //
99 99 // if (nb_swf < 2)
100 100 if (true)
101 101 {
102 102 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
103 103 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
104 104 }
105 105 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000]
106 106 nb_swf = nb_swf + 1;
107 107 }
108 108 else
109 109 {
110 110 reset_wfp_burst_enable();
111 111 nb_swf = 0;
112 112 }
113 113
114 114 }
115 115
116 116 break;
117 117
118 118 //******
119 119 // BURST
120 120 case(LFR_MODE_BURST):
121 121 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
122 122 // (1) change the receiving buffer for the waveform picker
123 123 ring_node_to_send_cwf_f2 = current_ring_node_f2;
124 124 current_ring_node_f2 = current_ring_node_f2->next;
125 125 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
126 126 // (2) send an event for the waveforms transmission
127 127 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
128 128 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
129 129 }
130 130 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
131 131 }
132 132 break;
133 133
134 134 //*****
135 135 // SBM1
136 136 case(LFR_MODE_SBM1):
137 137 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
138 138 // (1) change the receiving buffer for the waveform picker
139 139 ring_node_to_send_cwf_f1 = current_ring_node_f1;
140 140 current_ring_node_f1 = current_ring_node_f1->next;
141 141 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
142 142 // (2) send an event for the waveforms transmission
143 143 if (rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) {
144 144 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
145 145 }
146 146 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bit = 0
147 147 }
148 148 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
149 149 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
150 150 }
151 151 if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit
152 152 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
153 153 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
154 154 }
155 155 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2 and f0 bits = 0
156 156 }
157 157 break;
158 158
159 159 //*****
160 160 // SBM2
161 161 case(LFR_MODE_SBM2):
162 162 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
163 163 // (1) change the receiving buffer for the waveform picker
164 164 ring_node_to_send_cwf_f2 = current_ring_node_f2;
165 165 current_ring_node_f2 = current_ring_node_f2->next;
166 166 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
167 167 // (2) send an event for the waveforms transmission
168 168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
169 169 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
170 170 }
171 171 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
172 172 }
173 173 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
174 174 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
175 175 }
176 176 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
177 177 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
178 178 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
179 179 }
180 180 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0
181 181 }
182 182 break;
183 183
184 184 //********
185 185 // DEFAULT
186 186 default:
187 187 break;
188 188 }
189 189 }
190 190
191 191 rtems_isr waveforms_isr_alt( rtems_vector_number vector )
192 192 {
193 193 /** This is the interrupt sub routine called by the waveform picker core.
194 194 *
195 195 * This ISR launch different actions depending mainly on two pieces of information:
196 196 * 1. the values read in the registers of the waveform picker.
197 197 * 2. the current LFR mode.
198 198 *
199 199 */
200 200
201 201 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
202 202 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
203 203 { // in modes other than STANDBY and BURST, send the CWF_F3 data
204 204 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
205 205 // (1) change the receiving buffer for the waveform picker
206 206 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3_a) {
207 207 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_b);
208 208 }
209 209 else {
210 210 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_a);
211 211 }
212 212 // (2) send an event for the waveforms transmission
213 213 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
214 214 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
215 215 }
216 216 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
217 217 }
218 218 }
219 219
220 220 switch(lfrCurrentMode)
221 221 {
222 222 //********
223 223 // STANDBY
224 224 case(LFR_MODE_STANDBY):
225 225 break;
226 226
227 227 //******
228 228 // NORMAL
229 229 case(LFR_MODE_NORMAL):
230 230 if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits
231 231 {
232 232 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
233 233 }
234 234 if ( (waveform_picker_regs->status & 0x01) == 0x01) // [0001] check the f0 full bit
235 235 {
236 236 // change F0 ring node
237 237 ring_node_to_send_swf_f0 = current_ring_node_f0;
238 238 current_ring_node_f0 = current_ring_node_f0->next;
239 239 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address;
240 240 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1110 1110 1110]
241 241 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL_SWF_F0 ) != RTEMS_SUCCESSFUL) {
242 242 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
243 243 }
244 244 }
245 245 if ( (waveform_picker_regs->status & 0x02) == 0x02) // [0010] check the f1 full bit
246 246 {
247 247 // change F1 ring node
248 248 ring_node_to_send_swf_f1 = current_ring_node_f1;
249 249 current_ring_node_f1 = current_ring_node_f1->next;
250 250 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
251 251 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1101 1101 1101]
252 252 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL_SWF_F1 ) != RTEMS_SUCCESSFUL) {
253 253 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
254 254 }
255 255 }
256 256 if ( (waveform_picker_regs->status & 0x04) == 0x04) // [0100] check the f2 full bit
257 257 {
258 258 // change F2 ring node
259 259 ring_node_to_send_swf_f2 = current_ring_node_f2;
260 260 current_ring_node_f2 = current_ring_node_f2->next;
261 261 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
262 262 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1011 1011 1011]
263 263 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL_SWF_F2 ) != RTEMS_SUCCESSFUL) {
264 264 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
265 265 }
266 266 }
267 267 break;
268 268
269 269 //******
270 270 // BURST
271 271 case(LFR_MODE_BURST):
272 272 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
273 273 // (1) change the receiving buffer for the waveform picker
274 274 ring_node_to_send_cwf_f2 = current_ring_node_f2;
275 275 current_ring_node_f2 = current_ring_node_f2->next;
276 276 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
277 277 // (2) send an event for the waveforms transmission
278 278 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
279 279 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
280 280 }
281 281 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
282 282 }
283 283 break;
284 284
285 285 //*****
286 286 // SBM1
287 287 case(LFR_MODE_SBM1):
288 288 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
289 289 // (1) change the receiving buffer for the waveform picker
290 290 ring_node_to_send_cwf_f1 = current_ring_node_f1;
291 291 current_ring_node_f1 = current_ring_node_f1->next;
292 292 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
293 293 // (2) send an event for the waveforms transmission
294 294 if (rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) {
295 295 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
296 296 }
297 297 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bit = 0
298 298 }
299 299 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
300 300 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
301 301 }
302 302 if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit
303 303 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
304 304 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
305 305 }
306 306 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2 and f0 bits = 0
307 307 }
308 308 break;
309 309
310 310 //*****
311 311 // SBM2
312 312 case(LFR_MODE_SBM2):
313 313 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
314 314 // (1) change the receiving buffer for the waveform picker
315 315 ring_node_to_send_cwf_f2 = current_ring_node_f2;
316 316 current_ring_node_f2 = current_ring_node_f2->next;
317 317 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
318 318 // (2) send an event for the waveforms transmission
319 319 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
320 320 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
321 321 }
322 322 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
323 323 }
324 324 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
325 325 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
326 326 }
327 327 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
328 328 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
329 329 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
330 330 }
331 331 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0
332 332 }
333 333 break;
334 334
335 335 //********
336 336 // DEFAULT
337 337 default:
338 338 break;
339 339 }
340 340 }
341 341
342 342 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
343 343 {
344 344 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
345 345 *
346 346 * @param unused is the starting argument of the RTEMS task
347 347 *
348 348 * The following data packets are sent by this task:
349 349 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
350 350 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
351 351 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
352 352 *
353 353 */
354 354
355 355 rtems_event_set event_out;
356 356 rtems_id queue_id;
357 357 rtems_status_code status;
358 358
359 359 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
360 360 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
361 361 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
362 362
363 363 init_waveforms();
364 364
365 365 status = get_message_queue_id_send( &queue_id );
366 366 if (status != RTEMS_SUCCESSFUL)
367 367 {
368 368 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
369 369 }
370 370
371 371 BOOT_PRINTF("in WFRM ***\n")
372 372
373 373 while(1){
374 374 // wait for an RTEMS_EVENT
375 375 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
376 376 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM
377 377 | RTEMS_EVENT_MODE_NORMAL_SWF_F0
378 378 | RTEMS_EVENT_MODE_NORMAL_SWF_F1
379 379 | RTEMS_EVENT_MODE_NORMAL_SWF_F2,
380 380 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
381 381 if (event_out == RTEMS_EVENT_MODE_NORMAL)
382 382 {
383 383 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
384 384 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
385 385 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
386 386 }
387 387 if ( (event_out & RTEMS_EVENT_MODE_NORMAL_SWF_F0) == RTEMS_EVENT_MODE_NORMAL_SWF_F0)
388 388 {
389 389 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
390 390 }
391 391 if ( (event_out & RTEMS_EVENT_MODE_NORMAL_SWF_F1) == RTEMS_EVENT_MODE_NORMAL_SWF_F1)
392 392 {
393 393 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
394 394 }
395 395 if ( (event_out & RTEMS_EVENT_MODE_NORMAL_SWF_F2) == RTEMS_EVENT_MODE_NORMAL_SWF_F2)
396 396 {
397 397 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
398 398 }
399 399 }
400 400 }
401 401
402 402 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
403 403 {
404 404 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
405 405 *
406 406 * @param unused is the starting argument of the RTEMS task
407 407 *
408 408 * The following data packet is sent by this task:
409 409 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
410 410 *
411 411 */
412 412
413 413 rtems_event_set event_out;
414 414 rtems_id queue_id;
415 415 rtems_status_code status;
416 416
417 417 init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 );
418 418 init_header_continuous_cwf3_light_table( headerCWF_F3_light );
419 419
420 420 status = get_message_queue_id_send( &queue_id );
421 421 if (status != RTEMS_SUCCESSFUL)
422 422 {
423 423 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
424 424 }
425 425
426 426 BOOT_PRINTF("in CWF3 ***\n")
427 427
428 428 while(1){
429 429 // wait for an RTEMS_EVENT
430 430 rtems_event_receive( RTEMS_EVENT_0,
431 431 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
432 PRINTF("send CWF F3 \n")
432 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
433 {
434 PRINTF("send CWF_LONG_F3\n")
435 }
436 else
437 {
438 PRINTF("send CWF_F3 (light)\n")
439 }
433 440 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3_a) {
434 441 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
435 442 {
436 443 send_waveform_CWF( wf_cont_f3_b, SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
437 444 }
438 445 else
439 446 {
440 447 send_waveform_CWF3_light( wf_cont_f3_b, headerCWF_F3_light, queue_id );
441 448 }
442 449 }
443 450 else
444 451 {
445 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x00)
452 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
446 453 {
447 454 send_waveform_CWF( wf_cont_f3_a, SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
448 455 }
449 456 else
450 457 {
451 458 send_waveform_CWF3_light( wf_cont_f3_a, headerCWF_F3_light, queue_id );
452 459 }
453 460
454 461 }
455 462 }
456 463 }
457 464
458 465 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
459 466 {
460 467 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
461 468 *
462 469 * @param unused is the starting argument of the RTEMS task
463 470 *
464 471 * The following data packet is sent by this function:
465 472 * - TM_LFR_SCIENCE_BURST_CWF_F2
466 473 * - TM_LFR_SCIENCE_SBM2_CWF_F2
467 474 *
468 475 */
469 476
470 477 rtems_event_set event_out;
471 478 rtems_id queue_id;
472 479 rtems_status_code status;
473 480
474 481 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
475 482 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
476 483
477 484 status = get_message_queue_id_send( &queue_id );
478 485 if (status != RTEMS_SUCCESSFUL)
479 486 {
480 487 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
481 488 }
482 489
483 490 BOOT_PRINTF("in CWF2 ***\n")
484 491
485 492 while(1){
486 493 // wait for an RTEMS_EVENT
487 494 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
488 495 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
489 496 if (event_out == RTEMS_EVENT_MODE_BURST)
490 497 {
491 498 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
492 499 }
493 500 if (event_out == RTEMS_EVENT_MODE_SBM2)
494 501 {
495 502 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
496 503 }
497 504 }
498 505 }
499 506
500 507 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
501 508 {
502 509 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
503 510 *
504 511 * @param unused is the starting argument of the RTEMS task
505 512 *
506 513 * The following data packet is sent by this function:
507 514 * - TM_LFR_SCIENCE_SBM1_CWF_F1
508 515 *
509 516 */
510 517
511 518 rtems_event_set event_out;
512 519 rtems_id queue_id;
513 520 rtems_status_code status;
514 521
515 522 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
516 523
517 524 status = get_message_queue_id_send( &queue_id );
518 525 if (status != RTEMS_SUCCESSFUL)
519 526 {
520 527 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
521 528 }
522 529
523 530 BOOT_PRINTF("in CWF1 ***\n")
524 531
525 532 while(1){
526 533 // wait for an RTEMS_EVENT
527 534 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
528 535 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
529 536 send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
530 537 }
531 538 }
532 539
533 540 //******************
534 541 // general functions
535 542 void init_waveforms( void )
536 543 {
537 544 int i = 0;
538 545
539 546 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
540 547 {
541 548 //***
542 549 // F0
543 550 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x88887777; //
544 551 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; //
545 552 // wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0x44443333; //
546 553
547 554 //***
548 555 // F1
549 556 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x22221111;
550 557 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x44443333;
551 558 // wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
552 559
553 560 //***
554 561 // F2
555 562 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x44443333;
556 563 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111;
557 564 // wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
558 565
559 566 //***
560 567 // F3
561 568 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 0 ] = val1;
562 569 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 1 ] = val2;
563 570 // wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 2 ] = 0xaaaa0000;
564 571 }
565 572 }
566 573
567 574 void init_waveform_rings( void )
568 575 {
569 576 unsigned char i;
570 577
571 578 // F0 RING
572 579 waveform_ring_f0[0].next = (ring_node*) &waveform_ring_f0[1];
573 580 waveform_ring_f0[0].previous = (ring_node*) &waveform_ring_f0[NB_RING_NODES_F0-1];
574 581 waveform_ring_f0[0].buffer_address = (int) &wf_snap_f0[0][0];
575 582
576 583 waveform_ring_f0[NB_RING_NODES_F0-1].next = (ring_node*) &waveform_ring_f0[0];
577 584 waveform_ring_f0[NB_RING_NODES_F0-1].previous = (ring_node*) &waveform_ring_f0[NB_RING_NODES_F0-2];
578 585 waveform_ring_f0[NB_RING_NODES_F0-1].buffer_address = (int) &wf_snap_f0[NB_RING_NODES_F0-1][0];
579 586
580 587 for(i=1; i<NB_RING_NODES_F0-1; i++)
581 588 {
582 589 waveform_ring_f0[i].next = (ring_node*) &waveform_ring_f0[i+1];
583 590 waveform_ring_f0[i].previous = (ring_node*) &waveform_ring_f0[i-1];
584 591 waveform_ring_f0[i].buffer_address = (int) &wf_snap_f0[i][0];
585 592 }
586 593
587 594 // F1 RING
588 595 waveform_ring_f1[0].next = (ring_node*) &waveform_ring_f1[1];
589 596 waveform_ring_f1[0].previous = (ring_node*) &waveform_ring_f1[NB_RING_NODES_F1-1];
590 597 waveform_ring_f1[0].buffer_address = (int) &wf_snap_f1[0][0];
591 598
592 599 waveform_ring_f1[NB_RING_NODES_F1-1].next = (ring_node*) &waveform_ring_f1[0];
593 600 waveform_ring_f1[NB_RING_NODES_F1-1].previous = (ring_node*) &waveform_ring_f1[NB_RING_NODES_F1-2];
594 601 waveform_ring_f1[NB_RING_NODES_F1-1].buffer_address = (int) &wf_snap_f1[NB_RING_NODES_F1-1][0];
595 602
596 603 for(i=1; i<NB_RING_NODES_F1-1; i++)
597 604 {
598 605 waveform_ring_f1[i].next = (ring_node*) &waveform_ring_f1[i+1];
599 606 waveform_ring_f1[i].previous = (ring_node*) &waveform_ring_f1[i-1];
600 607 waveform_ring_f1[i].buffer_address = (int) &wf_snap_f1[i][0];
601 608 }
602 609
603 610 // F2 RING
604 611 waveform_ring_f2[0].next = (ring_node*) &waveform_ring_f2[1];
605 612 waveform_ring_f2[0].previous = (ring_node*) &waveform_ring_f2[NB_RING_NODES_F2-1];
606 613 waveform_ring_f2[0].buffer_address = (int) &wf_snap_f2[0][0];
607 614
608 615 waveform_ring_f2[NB_RING_NODES_F2-1].next = (ring_node*) &waveform_ring_f2[0];
609 616 waveform_ring_f2[NB_RING_NODES_F2-1].previous = (ring_node*) &waveform_ring_f2[NB_RING_NODES_F2-2];
610 617 waveform_ring_f2[NB_RING_NODES_F2-1].buffer_address = (int) &wf_snap_f2[NB_RING_NODES_F2-1][0];
611 618
612 619 for(i=1; i<NB_RING_NODES_F2-1; i++)
613 620 {
614 621 waveform_ring_f2[i].next = (ring_node*) &waveform_ring_f2[i+1];
615 622 waveform_ring_f2[i].previous = (ring_node*) &waveform_ring_f2[i-1];
616 623 waveform_ring_f2[i].buffer_address = (int) &wf_snap_f2[i][0];
617 624 }
618 625
619 626 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
620 627 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
621 628 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
622 629
623 630 }
624 631
625 632 void reset_current_ring_nodes( void )
626 633 {
627 634 current_ring_node_f0 = waveform_ring_f0;
628 635 ring_node_to_send_swf_f0 = waveform_ring_f0;
629 636
630 637 current_ring_node_f1 = waveform_ring_f1;
631 638 ring_node_to_send_cwf_f1 = waveform_ring_f1;
632 639 ring_node_to_send_swf_f1 = waveform_ring_f1;
633 640
634 641 current_ring_node_f2 = waveform_ring_f2;
635 642 ring_node_to_send_cwf_f2 = waveform_ring_f2;
636 643 ring_node_to_send_swf_f2 = waveform_ring_f2;
637 644 }
638 645
639 646 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
640 647 {
641 648 unsigned char i;
642 649
643 650 for (i=0; i<7; i++)
644 651 {
645 652 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
646 653 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
647 654 headerSWF[ i ].reserved = DEFAULT_RESERVED;
648 655 headerSWF[ i ].userApplication = CCSDS_USER_APP;
649 656 headerSWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
650 657 headerSWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
651 658 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
652 659 if (i == 6)
653 660 {
654 661 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
655 662 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
656 663 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
657 664 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 );
658 665 }
659 666 else
660 667 {
661 668 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
662 669 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
663 670 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
664 671 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 );
665 672 }
666 673 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
667 674 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
668 675 headerSWF[ i ].pktNr = i+1; // PKT_NR
669 676 // DATA FIELD HEADER
670 677 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
671 678 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
672 679 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
673 680 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
674 681 // AUXILIARY DATA HEADER
675 682 headerSWF[ i ].time[0] = 0x00;
676 683 headerSWF[ i ].time[0] = 0x00;
677 684 headerSWF[ i ].time[0] = 0x00;
678 685 headerSWF[ i ].time[0] = 0x00;
679 686 headerSWF[ i ].time[0] = 0x00;
680 687 headerSWF[ i ].time[0] = 0x00;
681 688 headerSWF[ i ].sid = sid;
682 689 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
683 690 }
684 691 return LFR_SUCCESSFUL;
685 692 }
686 693
687 694 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
688 695 {
689 696 unsigned int i;
690 697
691 for (i=0; i<7; i++)
698 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++)
692 699 {
693 700 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
694 701 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
695 702 headerCWF[ i ].reserved = DEFAULT_RESERVED;
696 703 headerCWF[ i ].userApplication = CCSDS_USER_APP;
697 704 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
698 705 {
699 706 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2 >> 8);
700 707 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2);
701 708 }
702 709 else
703 710 {
704 711 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
705 712 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
706 713 }
707 714 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
708 715 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
709 716 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
710 717 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
711 718 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF );
712 719 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
713 720 // DATA FIELD HEADER
714 721 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
715 722 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
716 723 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
717 724 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
718 725 // AUXILIARY DATA HEADER
719 726 headerCWF[ i ].sid = sid;
720 727 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
721 728 headerCWF[ i ].time[0] = 0x00;
722 729 headerCWF[ i ].time[0] = 0x00;
723 730 headerCWF[ i ].time[0] = 0x00;
724 731 headerCWF[ i ].time[0] = 0x00;
725 732 headerCWF[ i ].time[0] = 0x00;
726 733 headerCWF[ i ].time[0] = 0x00;
727 734 }
728 735 return LFR_SUCCESSFUL;
729 736 }
730 737
731 738 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
732 739 {
733 740 unsigned int i;
734 741
735 for (i=0; i<7; i++)
742 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++)
736 743 {
737 744 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
738 745 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
739 746 headerCWF[ i ].reserved = DEFAULT_RESERVED;
740 747 headerCWF[ i ].userApplication = CCSDS_USER_APP;
741 748
742 749 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
743 750 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
744 751
745 752 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
746 753 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
747 754 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
748 755 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
749 756 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
750 757
751 758 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
752 759 // DATA FIELD HEADER
753 760 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
754 761 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
755 762 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
756 763 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
757 764 // AUXILIARY DATA HEADER
758 765 headerCWF[ i ].sid = SID_NORM_CWF_F3;
759 766 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
760 767 headerCWF[ i ].time[0] = 0x00;
761 768 headerCWF[ i ].time[0] = 0x00;
762 769 headerCWF[ i ].time[0] = 0x00;
763 770 headerCWF[ i ].time[0] = 0x00;
764 771 headerCWF[ i ].time[0] = 0x00;
765 772 headerCWF[ i ].time[0] = 0x00;
766 773 }
767 774 return LFR_SUCCESSFUL;
768 775 }
769 776
770 777 int send_waveform_SWF( volatile int *waveform, unsigned int sid,
771 778 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
772 779 {
773 780 /** This function sends SWF CCSDS packets (F2, F1 or F0).
774 781 *
775 782 * @param waveform points to the buffer containing the data that will be send.
776 783 * @param sid is the source identifier of the data that will be sent.
777 784 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
778 785 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
779 786 * contain information to setup the transmission of the data packets.
780 787 *
781 788 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
782 789 *
783 790 */
784 791
785 792 unsigned int i;
786 793 int ret;
787 794 unsigned int coarseTime;
788 795 unsigned int fineTime;
789 796 rtems_status_code status;
790 797 spw_ioctl_pkt_send spw_ioctl_send_SWF;
791 798
792 799 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
793 800 spw_ioctl_send_SWF.options = 0;
794 801
795 802 ret = LFR_DEFAULT;
796 803
797 PRINTF1("sid = %d, ", sid)
798 PRINTF2("coarse = %x, fine = %x\n", waveform[0], waveform[1])
804 DEBUG_PRINTF1("sid = %d, ", sid)
805 DEBUG_PRINTF2("coarse = %x, fine = %x\n", waveform[0], waveform[1])
806
807 coarseTime = waveform[0];
808 fineTime = waveform[1];
799 809
800 810 for (i=0; i<7; i++) // send waveform
801 811 {
802 #ifdef VHDL_DEV
803 812 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET];
804 #else
805 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
806 #endif
807 813 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
808 814 // BUILD THE DATA
809 815 if (i==6) {
810 816 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
811 817 }
812 818 else {
813 819 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
814 820 }
815 821 // SET PACKET SEQUENCE COUNTER
816 822 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
817 823 // SET PACKET TIME
818 #ifdef VHDL_DEV
819 coarseTime = waveform[0];
820 fineTime = waveform[1];
821 compute_acquisition_time( &coarseTime, &fineTime, sid, i);
822
823 headerSWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime >> 24 );
824 headerSWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime >> 16 );
825 headerSWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime >> 8 );
826 headerSWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime );
827 headerSWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime >> 8 );
828 headerSWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime );
829 #else
830 headerSWF[ i ].acquisitionTime[0] = (unsigned char) (time_management_regs->coarse_time>>24);
831 headerSWF[ i ].acquisitionTime[1] = (unsigned char) (time_management_regs->coarse_time>>16);
832 headerSWF[ i ].acquisitionTime[2] = (unsigned char) (time_management_regs->coarse_time>>8);
833 headerSWF[ i ].acquisitionTime[3] = (unsigned char) (time_management_regs->coarse_time);
834 headerSWF[ i ].acquisitionTime[4] = (unsigned char) (time_management_regs->fine_time>>8);
835 headerSWF[ i ].acquisitionTime[5] = (unsigned char) (time_management_regs->fine_time);
836 #endif
824 compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime );
825 //
837 826 headerSWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
838 827 headerSWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
839 828 headerSWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
840 829 headerSWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
841 830 headerSWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
842 831 headerSWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
843 832 // SEND PACKET
844 833 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
845 834 if (status != RTEMS_SUCCESSFUL) {
846 835 printf("%d-%d, ERR %d\n", sid, i, (int) status);
847 836 ret = LFR_DEFAULT;
848 837 }
849 // rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
838 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
850 839 }
851 840
852 841 return ret;
853 842 }
854 843
855 844 int send_waveform_CWF(volatile int *waveform, unsigned int sid,
856 845 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
857 846 {
858 847 /** This function sends CWF CCSDS packets (F2, F1 or F0).
859 848 *
860 849 * @param waveform points to the buffer containing the data that will be send.
861 850 * @param sid is the source identifier of the data that will be sent.
862 851 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
863 852 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
864 853 * contain information to setup the transmission of the data packets.
865 854 *
866 855 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
867 856 *
868 857 */
869 858
870 859 unsigned int i;
871 860 int ret;
872 unsigned char *coarseTimePtr;
873 unsigned char *fineTimePtr;
861 unsigned int coarseTime;
862 unsigned int fineTime;
874 863 rtems_status_code status;
875 864 spw_ioctl_pkt_send spw_ioctl_send_CWF;
876 865
877 866 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
878 867 spw_ioctl_send_CWF.options = 0;
879 868
880 869 ret = LFR_DEFAULT;
881 870
882 for (i=0; i<7; i++) // send waveform
871 coarseTime = waveform[0];
872 fineTime = waveform[1];
873
874 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
883 875 {
884 int coarseTime = 0x00;
885 int fineTime = 0x00;
886 #ifdef VHDL_DEV
887 876 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) + TIME_OFFSET];
888 #else
889 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
890 #endif
891 877 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
892 878 // BUILD THE DATA
893 879 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
894 880 // SET PACKET SEQUENCE COUNTER
895 881 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
896 882 // SET PACKET TIME
897 #ifdef VHDL_DEV
898 coarseTimePtr = (unsigned char *) &waveform;
899 fineTimePtr = (unsigned char *) &waveform[1];
900 headerCWF[ i ].acquisitionTime[0] = coarseTimePtr[2];
901 headerCWF[ i ].acquisitionTime[1] = coarseTimePtr[3];
902 headerCWF[ i ].acquisitionTime[2] = coarseTimePtr[0];
903 headerCWF[ i ].acquisitionTime[3] = coarseTimePtr[1];
904 headerCWF[ i ].acquisitionTime[4] = fineTimePtr[0];
905 headerCWF[ i ].acquisitionTime[5] = fineTimePtr[1];
906 #else
907 coarseTime = time_management_regs->coarse_time;
908 fineTime = time_management_regs->fine_time;
909 headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24);
910 headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16);
911 headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8);
912 headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime);
913 headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8);
914 headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime);
915 #endif
916
917 headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24);
918 headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16);
919 headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8);
920 headerCWF[ i ].time[3] = (unsigned char) (coarseTime);
921 headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8);
922 headerCWF[ i ].time[5] = (unsigned char) (fineTime);
883 compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime);
884 //
885 headerCWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
886 headerCWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
887 headerCWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
888 headerCWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
889 headerCWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
890 headerCWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
923 891 // SEND PACKET
924 892 if (sid == SID_NORM_CWF_LONG_F3)
925 893 {
926 894 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
927 895 if (status != RTEMS_SUCCESSFUL) {
928 896 printf("%d-%d, ERR %d\n", sid, i, (int) status);
929 897 ret = LFR_DEFAULT;
930 898 }
931 899 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
932 900 }
933 901 else
934 902 {
935 903 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
936 904 if (status != RTEMS_SUCCESSFUL) {
937 905 printf("%d-%d, ERR %d\n", sid, i, (int) status);
938 906 ret = LFR_DEFAULT;
939 907 }
940 908 }
941 909 }
942 910
943 911 return ret;
944 912 }
945 913
946 914 int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
947 915 {
948 916 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
949 917 *
950 918 * @param waveform points to the buffer containing the data that will be send.
951 919 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
952 920 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
953 921 * contain information to setup the transmission of the data packets.
954 922 *
955 923 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
956 924 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
957 925 *
958 926 */
959 927
960 928 unsigned int i;
961 929 int ret;
962 unsigned char *coarseTimePtr;
963 unsigned char *fineTimePtr;
930 unsigned int coarseTime;
931 unsigned int fineTime;
964 932 rtems_status_code status;
965 933 spw_ioctl_pkt_send spw_ioctl_send_CWF;
966 934 char *sample;
967 935
968 936 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
969 937 spw_ioctl_send_CWF.options = 0;
970 938
971 939 ret = LFR_DEFAULT;
972 940
973 941 //**********************
974 942 // BUILD CWF3_light DATA
975 943 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
976 944 {
977 #ifdef VHDL_DEV
978 945 sample = (char*) &waveform[ (i * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
979 946 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES ] = sample[ 0 ];
980 947 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 + TIME_OFFSET_IN_BYTES ] = sample[ 1 ];
981 948 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 + TIME_OFFSET_IN_BYTES ] = sample[ 2 ];
982 949 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 + TIME_OFFSET_IN_BYTES ] = sample[ 3 ];
983 950 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 + TIME_OFFSET_IN_BYTES ] = sample[ 4 ];
984 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ];
985 #else
986 sample = (char*) &waveform[ i * NB_WORDS_SWF_BLK ];
987 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
988 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
989 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
990 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
991 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
992 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
993 #endif
951 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ];
994 952 }
995 953
954 coarseTime = waveform[0];
955 fineTime = waveform[1];
956
996 957 //*********************
997 958 // SEND CWF3_light DATA
998
999 for (i=0; i<7; i++) // send waveform
959 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1000 960 {
1001 int coarseTime = 0x00;
1002 int fineTime = 0x00;
1003
1004 #ifdef VHDL_DEV
1005 961 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES];
1006 #else
1007 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1008 #endif
1009 962 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
1010 963 // BUILD THE DATA
1011 964 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1012 965 // SET PACKET SEQUENCE COUNTER
1013 966 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
1014 967 // SET PACKET TIME
1015 #ifdef VHDL_DEV
1016 coarseTimePtr = (unsigned char *) &waveform;
1017 fineTimePtr = (unsigned char *) &waveform[1];
1018 headerCWF[ i ].acquisitionTime[0] = coarseTimePtr[2];
1019 headerCWF[ i ].acquisitionTime[1] = coarseTimePtr[3];
1020 headerCWF[ i ].acquisitionTime[2] = coarseTimePtr[0];
1021 headerCWF[ i ].acquisitionTime[3] = coarseTimePtr[1];
1022 headerCWF[ i ].acquisitionTime[4] = fineTimePtr[0];
1023 headerCWF[ i ].acquisitionTime[5] = fineTimePtr[1];
1024 #else
1025 coarseTime = time_management_regs->coarse_time;
1026 fineTime = time_management_regs->fine_time;
1027 headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24);
1028 headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16);
1029 headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8);
1030 headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime);
1031 headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8);
1032 headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime);
1033 #endif
1034 headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24);
1035 headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16);
1036 headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8);
1037 headerCWF[ i ].time[3] = (unsigned char) (coarseTime);
1038 headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8);
1039 headerCWF[ i ].time[5] = (unsigned char) (fineTime);
968 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime );
969 //
970 headerCWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
971 headerCWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
972 headerCWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
973 headerCWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
974 headerCWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
975 headerCWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
1040 976 // SEND PACKET
1041 977 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
1042 978 if (status != RTEMS_SUCCESSFUL) {
1043 979 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
1044 980 ret = LFR_DEFAULT;
1045 981 }
1046 982 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
1047 983 }
1048 984
1049 985 return ret;
1050 986 }
1051 987
1052 void compute_acquisition_time( unsigned int *coarseTime, unsigned int *fineTime, unsigned int sid, unsigned char pa_lfr_pkt_nr )
988 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
989 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
1053 990 {
1054 991 unsigned long long int acquisitionTimeAsLong;
1055 unsigned char acquisitionTime[6];
1056 float deltaT = 0.;
992 unsigned char localAcquisitionTime[6];
993 double deltaT = 0.;
1057 994
1058 acquisitionTime[0] = (unsigned char) ( *coarseTime >> 8 );
1059 acquisitionTime[1] = (unsigned char) ( *coarseTime );
1060 acquisitionTime[2] = (unsigned char) ( *coarseTime >> 24 );
1061 acquisitionTime[3] = (unsigned char) ( *coarseTime >> 16 );
1062 acquisitionTime[4] = (unsigned char) ( *fineTime >> 24 );
1063 acquisitionTime[5] = (unsigned char) ( *fineTime >> 16 );
995 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 8 );
996 localAcquisitionTime[1] = (unsigned char) ( coarseTime );
997 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 24 );
998 localAcquisitionTime[3] = (unsigned char) ( coarseTime >> 16 );
999 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 24 );
1000 localAcquisitionTime[5] = (unsigned char) ( fineTime >> 16 );
1064 1001
1065 acquisitionTimeAsLong = ( (unsigned long long int) acquisitionTime[0] << 40 )
1066 + ( (unsigned long long int) acquisitionTime[1] << 32 )
1067 + ( acquisitionTime[2] << 24 )
1068 + ( acquisitionTime[3] << 16 )
1069 + ( acquisitionTime[4] << 8 )
1070 + ( acquisitionTime[5] );
1002 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
1003 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
1004 + ( localAcquisitionTime[2] << 24 )
1005 + ( localAcquisitionTime[3] << 16 )
1006 + ( localAcquisitionTime[4] << 8 )
1007 + ( localAcquisitionTime[5] );
1071 1008
1072 1009 switch( sid )
1073 1010 {
1074 1011 case SID_NORM_SWF_F0:
1075 deltaT = ( (float ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
1076 break;
1012 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
1013 break;
1077 1014
1078 1015 case SID_NORM_SWF_F1:
1079 deltaT = ( (float ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
1080 break;
1016 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
1017 break;
1018
1019 case SID_SBM1_CWF_F1:
1020 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
1021 break;
1081 1022
1082 1023 case SID_NORM_SWF_F2:
1083 deltaT = ( (float ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
1084 break;
1024 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
1025 break;
1026
1027 case SID_SBM2_CWF_F2:
1028 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
1029 break;
1030
1031 case SID_NORM_CWF_F3:
1032 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
1033 break;
1034
1035 case SID_NORM_CWF_LONG_F3:
1036 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
1037 break;
1085 1038
1086 1039 default:
1087 1040 deltaT = 0.;
1088 1041 break;
1089 1042 }
1090 1043
1091 1044 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
1092
1093 *coarseTime = (unsigned int) (acquisitionTimeAsLong >> 16);
1094 *fineTime = (unsigned int) (acquisitionTimeAsLong & 0xffff);
1045 //
1046 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
1047 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
1048 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
1049 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
1050 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
1051 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
1095 1052 }
1096 1053
1097 1054 //**************
1098 1055 // wfp registers
1099 1056 void reset_wfp_burst_enable(void)
1100 1057 {
1101 1058 /** This function resets the waveform picker burst_enable register.
1102 1059 *
1103 1060 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1104 1061 *
1105 1062 */
1106 1063
1107 #ifdef VHDL_DEV
1108 1064 waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1109 #else
1110 waveform_picker_regs->burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1111 #endif
1112 1065 }
1113 1066
1114 1067 void reset_wfp_status( void )
1115 1068 {
1116 1069 /** This function resets the waveform picker status register.
1117 1070 *
1118 1071 * All status bits are set to 0 [new_err full_err full].
1119 1072 *
1120 1073 */
1121 1074
1122 #ifdef GSA
1123 #else
1124 1075 waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1125 #endif
1126 1076 }
1127 1077
1128 1078 void reset_waveform_picker_regs(void)
1129 1079 {
1130 1080 /** This function resets the waveform picker module registers.
1131 1081 *
1132 1082 * The registers affected by this function are located at the following offset addresses:
1133 1083 * - 0x00 data_shaping
1134 1084 * - 0x04 run_burst_enable
1135 1085 * - 0x08 addr_data_f0
1136 1086 * - 0x0C addr_data_f1
1137 1087 * - 0x10 addr_data_f2
1138 1088 * - 0x14 addr_data_f3
1139 1089 * - 0x18 status
1140 1090 * - 0x1C delta_snapshot
1141 1091 * - 0x20 delta_f0
1142 1092 * - 0x24 delta_f0_2
1143 1093 * - 0x28 delta_f1
1144 1094 * - 0x2c delta_f2
1145 1095 * - 0x30 nb_data_by_buffer
1146 1096 * - 0x34 nb_snapshot_param
1147 1097 * - 0x38 start_date
1148 1098 * - 0x3c nb_word_in_buffer
1149 1099 *
1150 1100 */
1151 1101
1152 1102 waveform_picker_regs->data_shaping = 0x01; // 0x00 *** R1 R0 SP1 SP0 BW
1153 1103 waveform_picker_regs->run_burst_enable = 0x00; // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1154 1104 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08
1155 1105 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c
1156 1106 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10
1157 1107 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_a); // 0x14
1158 1108 waveform_picker_regs->status = 0x00; // 0x18
1159 1109 //
1160 1110 set_wfp_delta_snapshot(); // 0x1c
1161 1111 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1162 1112 set_wfp_delta_f1(); // 0x28
1163 1113 set_wfp_delta_f2(); // 0x2c
1164 1114 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1165 1115 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1166 1116 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1167 1117 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1168 1118 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1169 // 2352 = 7 * 336
1170 waveform_picker_regs->nb_data_by_buffer = 0x92f; // 0x30 *** 2352 - 1 => nb samples -1
1171 waveform_picker_regs->snapshot_param = 0x930; // 0x34 *** 2352 => nb samples
1119 // 2688 = 8 * 336
1120 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1121 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1172 1122 waveform_picker_regs->start_date = 0x00; // 0x38
1173 waveform_picker_regs->nb_word_in_buffer = 0x1b92; // 0x3c *** 2352 * 3 + 2 = 7058
1123 waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066
1174 1124 }
1175 1125
1176 1126 void set_wfp_data_shaping( void )
1177 1127 {
1178 1128 /** This function sets the data_shaping register of the waveform picker module.
1179 1129 *
1180 1130 * The value is read from one field of the parameter_dump_packet structure:\n
1181 1131 * bw_sp0_sp1_r0_r1
1182 1132 *
1183 1133 */
1184 1134
1185 1135 unsigned char data_shaping;
1186 1136
1187 1137 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1188 1138 // waveform picker : [R1 R0 SP1 SP0 BW]
1189 1139
1190 1140 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
1191 1141
1192 1142 waveform_picker_regs->data_shaping =
1193 1143 ( (data_shaping & 0x10) >> 4 ) // BW
1194 1144 + ( (data_shaping & 0x08) >> 2 ) // SP0
1195 1145 + ( (data_shaping & 0x04) ) // SP1
1196 1146 + ( (data_shaping & 0x02) << 2 ) // R0
1197 1147 + ( (data_shaping & 0x01) << 4 ); // R1
1198 1148 }
1199 1149
1200 1150 void set_wfp_burst_enable_register( unsigned char mode )
1201 1151 {
1202 1152 /** This function sets the waveform picker burst_enable register depending on the mode.
1203 1153 *
1204 1154 * @param mode is the LFR mode to launch.
1205 1155 *
1206 1156 * The burst bits shall be before the enable bits.
1207 1157 *
1208 1158 */
1209 1159
1210 1160 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1211 1161 // the burst bits shall be set first, before the enable bits
1212 1162 switch(mode) {
1213 1163 case(LFR_MODE_NORMAL):
1214 1164 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1215 1165 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1216 1166 break;
1217 1167 case(LFR_MODE_BURST):
1218 1168 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1219 1169 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1220 1170 break;
1221 1171 case(LFR_MODE_SBM1):
1222 1172 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1223 1173 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1224 1174 break;
1225 1175 case(LFR_MODE_SBM2):
1226 1176 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1227 1177 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1228 1178 break;
1229 1179 default:
1230 1180 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1231 1181 break;
1232 1182 }
1233 1183 }
1234 1184
1235 1185 void set_wfp_delta_snapshot( void )
1236 1186 {
1237 1187 /** This function sets the delta_snapshot register of the waveform picker module.
1238 1188 *
1239 1189 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1240 1190 * - sy_lfr_n_swf_p[0]
1241 1191 * - sy_lfr_n_swf_p[1]
1242 1192 *
1243 1193 */
1244 1194
1245 1195 unsigned int delta_snapshot;
1246 1196 unsigned int delta_snapshot_in_T2;
1247 1197
1248 1198 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1249 1199 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1250 1200
1251 1201 delta_snapshot_in_T2 = delta_snapshot * 256;
1252 1202 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2; // max 4 bytes
1253 1203 }
1254 1204
1255 1205 void set_wfp_delta_f0_f0_2( void )
1256 1206 {
1257 1207 unsigned int delta_snapshot;
1258 1208 unsigned int nb_samples_per_snapshot;
1259 1209 float delta_f0_in_float;
1260 1210
1261 1211 delta_snapshot = waveform_picker_regs->delta_snapshot;
1262 1212 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1263 1213 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1264 1214
1265 1215 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1266 1216 waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits
1267 1217 }
1268 1218
1269 1219 void set_wfp_delta_f1( void )
1270 1220 {
1271 1221 unsigned int delta_snapshot;
1272 1222 unsigned int nb_samples_per_snapshot;
1273 1223 float delta_f1_in_float;
1274 1224
1275 1225 delta_snapshot = waveform_picker_regs->delta_snapshot;
1276 1226 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1277 1227 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1278 1228
1279 1229 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1280 1230 }
1281 1231
1282 1232 void set_wfp_delta_f2()
1283 1233 {
1284 1234 unsigned int delta_snapshot;
1285 1235 unsigned int nb_samples_per_snapshot;
1286 1236
1287 1237 delta_snapshot = waveform_picker_regs->delta_snapshot;
1288 1238 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1289 1239
1290 1240 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1291 1241 }
1292 1242
1293 1243 //*****************
1294 1244 // local parameters
1295 1245 void set_local_nb_interrupt_f0_MAX( void )
1296 1246 {
1297 1247 /** This function sets the value of the nb_interrupt_f0_MAX local parameter.
1298 1248 *
1299 1249 * This parameter is used for the SM validation only.\n
1300 1250 * The software waits param_local.local_nb_interrupt_f0_MAX interruptions from the spectral matrices
1301 1251 * module before launching a basic processing.
1302 1252 *
1303 1253 */
1304 1254
1305 1255 param_local.local_nb_interrupt_f0_MAX = ( (parameter_dump_packet.sy_lfr_n_asm_p[0]) * 256
1306 1256 + parameter_dump_packet.sy_lfr_n_asm_p[1] ) * 100;
1307 1257 }
1308 1258
1309 1259 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1310 1260 {
1311 1261 unsigned short *sequence_cnt;
1312 1262 unsigned short segmentation_grouping_flag;
1313 1263 unsigned short new_packet_sequence_control;
1314 1264
1315 1265 if ( (sid ==SID_NORM_SWF_F0) || (sid ==SID_NORM_SWF_F1) || (sid ==SID_NORM_SWF_F2)
1316 1266 || (sid ==SID_NORM_CWF_F3) || (sid==SID_NORM_CWF_LONG_F3) || (sid ==SID_BURST_CWF_F2) )
1317 1267 {
1318 1268 sequence_cnt = &sequenceCounters_SCIENCE_NORMAL_BURST;
1319 1269 }
1320 1270 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) )
1321 1271 {
1322 1272 sequence_cnt = &sequenceCounters_SCIENCE_SBM1_SBM2;
1323 1273 }
1324 1274 else
1325 1275 {
1326 1276 sequence_cnt = NULL;
1327 1277 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1328 1278 }
1329 1279
1330 1280 if (sequence_cnt != NULL)
1331 1281 {
1332 1282 segmentation_grouping_flag = (packet_sequence_control[ 0 ] & 0xc0) << 8;
1333 1283 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1334 1284
1335 1285 new_packet_sequence_control = segmentation_grouping_flag | *sequence_cnt ;
1336 1286
1337 1287 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1338 1288 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1339 1289
1340 1290 // increment the sequence counter for the next packet
1341 1291 if ( *sequence_cnt < SEQ_CNT_MAX)
1342 1292 {
1343 1293 *sequence_cnt = *sequence_cnt + 1;
1344 1294 }
1345 1295 else
1346 1296 {
1347 1297 *sequence_cnt = 0;
1348 1298 }
1349 1299 }
1350 1300 }
General Comments 0
You need to be logged in to leave comments. Login now