##// END OF EJS Templates
All modes implemented for the waveforms...
paul@pc-solar1.lab-lpp.local -
r23:af9a6b32a71f default
parent child
Show More
@@ -1,6 +1,6
1 #############################################################################
1 #############################################################################
2 # Makefile for building: bin/fsw-gsa
2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.4) on: Tue Jun 18 14:00:55 2013
3 # Generated by qmake (2.01a) (Qt 4.8.4) on: Fri Jun 28 07:59:21 2013
4 # Project: fsw-qt.pro
4 # Project: fsw-qt.pro
5 # Template: app
5 # Template: app
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
@@ -10,7 +10,7
10
10
11 CC = sparc-rtems-gcc
11 CC = sparc-rtems-gcc
12 CXX = sparc-rtems-g++
12 CXX = sparc-rtems-g++
13 DEFINES = -DSW_VERSION_N1=0 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=5 -DPRINT_MESSAGES_ON_CONSOLE -DGSA
13 DEFINES = -DSW_VERSION_N1=0 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=5 -DPRINT_MESSAGES_ON_CONSOLE
14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header
16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header
@@ -78,9 +78,9 DIST = /usr/lib64/qt4/mkspecs/c
78 /usr/lib64/qt4/mkspecs/features/lex.prf \
78 /usr/lib64/qt4/mkspecs/features/lex.prf \
79 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf \
79 /usr/lib64/qt4/mkspecs/features/include_source_dir.prf \
80 fsw-qt.pro
80 fsw-qt.pro
81 QMAKE_TARGET = fsw-gsa
81 QMAKE_TARGET = fsw
82 DESTDIR = bin/
82 DESTDIR = bin/
83 TARGET = bin/fsw-gsa
83 TARGET = bin/fsw
84
84
85 first: all
85 first: all
86 ####### Implicit rules
86 ####### Implicit rules
@@ -159,8 +159,8 qmake: FORCE
159 @$(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
159 @$(QMAKE) -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
160
160
161 dist:
161 dist:
162 @$(CHK_DIR_EXISTS) obj/fsw-gsa1.0.0 || $(MKDIR) obj/fsw-gsa1.0.0
162 @$(CHK_DIR_EXISTS) obj/fsw1.0.0 || $(MKDIR) obj/fsw1.0.0
163 $(COPY_FILE) --parents $(SOURCES) $(DIST) obj/fsw-gsa1.0.0/ && (cd `dirname obj/fsw-gsa1.0.0` && $(TAR) fsw-gsa1.0.0.tar fsw-gsa1.0.0 && $(COMPRESS) fsw-gsa1.0.0.tar) && $(MOVE) `dirname obj/fsw-gsa1.0.0`/fsw-gsa1.0.0.tar.gz . && $(DEL_FILE) -r obj/fsw-gsa1.0.0
163 $(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
164
164
165
165
166 clean:compiler_clean
166 clean:compiler_clean
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,7 +1,7
1 TEMPLATE = app
1 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options = verbose *** cpu_usage_report *** gsa
3 # CONFIG options = verbose *** cpu_usage_report *** gsa
4 CONFIG += console verbose gsa
4 CONFIG += console verbose
5 CONFIG -= qt
5 CONFIG -= qt
6
6
7 include(./sparc.pri)
7 include(./sparc.pri)
@@ -1,6 +1,6
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE QtCreatorProject>
2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by Qt Creator 2.4.1, 2013-06-18T14:38:28. -->
3 <!-- Written by Qt Creator 2.4.1, 2013-06-28T14:26:12. -->
4 <qtcreator>
4 <qtcreator>
5 <data>
5 <data>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -10,11 +10,34
10 #define CCSDS_PROCESS_ID 76
10 #define CCSDS_PROCESS_ID 76
11 #define CCSDS_PACKET_CATEGORY 12
11 #define CCSDS_PACKET_CATEGORY 12
12 #define CCSDS_NODE_ADDRESS 0xfe
12 #define CCSDS_NODE_ADDRESS 0xfe
13
14 // PACKET IDs
15 #define TM_PACKET_ID_TC_EXE 0x0cc1 // PID 76 CAT 1
16 #define TM_PACKET_ID_HK 0x0cc4 // PID 76 CAT 4
17 #define TM_PACKET_ID_PARAMETER_DUMP 0x0cc9 // PID 76 CAT 9
18 #define TM_PACKET_ID_SCIENCE_NORMAL 0x0ccc // PID 76 CAT 12
19 #define TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2 0x0cfc // PID 79 CAT 12
20
21 // FAILURE CODES
22 #define FAILURE_CODE_INCONSISTENT 5 // 0x00 0x05
23 #define FAILURE_CODE_NOT_EXECUTABLE 40000 // 0x9c 0x40
24 #define FAILURE_CODE_NOT_IMPLEMENTED 40002 // 0x9c 0x42
25 #define FAILURE_CODE_ERROR 40003 // 0x9c 0x43
26 #define FAILURE_CODE_CORRUPTED 40005 // 0x9c 0x45
13 //
27 //
14 #define CCSDS_DESTINATION_ID_GROUND 0x00
28 #define TM_DESTINATION_ID_GROUND 0
29 #define TM_DESTINATION_ID_MISSION_TIMELINE 110
30 #define TM_DESTINATION_ID_TC_SEQUENCES 111
31 #define TM_DESTINATION_ID_RECOVERY_ACTION_COMMAND 112
32 #define TM_DESTINATION_ID_BACKUP_MISSION_TIMELINE 113
33 #define TM_DESTINATION_ID_DIRECT_CMD 120
34 #define TM_DESTINATION_ID_SPARE_GRD_SRC1 121
35 #define TM_DESTINATION_ID_SPARE_GRD_SRC2 122
36 #define TM_DESTINATION_ID_OBCP 15
37 #define TM_DESTINATION_ID_SYSTEM_CONTROL 14
38 #define TM_DESTINATION_ID_AOCS 11
39
15 #define CCSDS_DESTINATION_ID 0x01
40 #define CCSDS_DESTINATION_ID 0x01
16 #define CCSDS_DESTINATION_ID_DPU 0x01
17 //
18 #define CCSDS_PROTOCOLE_ID 0x02
41 #define CCSDS_PROTOCOLE_ID 0x02
19 #define CCSDS_USER_APP 0x00
42 #define CCSDS_USER_APP 0x00
20
43
@@ -64,8 +87,9
64 #define TC_LEN_UPDT_TIME 18
87 #define TC_LEN_UPDT_TIME 18
65
88
66 // TM TYPES
89 // TM TYPES
90 #define TM_TYPE_TC_EXE 1
91 #define TM_TYPE_HK 3
67 #define TM_TYPE_LFR_SCIENCE 21
92 #define TM_TYPE_LFR_SCIENCE 21
68 #define TM_TYPE_HK 3
69
93
70 // TM SUBTYPES
94 // TM SUBTYPES
71 #define TM_SUBTYPE_EXE_OK 7
95 #define TM_SUBTYPE_EXE_OK 7
@@ -111,22 +135,26
111 #define SID_SBM1_BP2_F1 33
135 #define SID_SBM1_BP2_F1 33
112
136
113 // LENGTH (BYTES)
137 // LENGTH (BYTES)
138 #define LENGTH_TM_LFR_TC_EXE_MAX 32
114 #define LENGTH_TM_LFR_HK 126
139 #define LENGTH_TM_LFR_HK 126
115 #define LENGTH_TM_LFR_TC_EXE_MAX 32
140 // PACKET_LENGTH
116 #define LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX 4102
141 #define PACKET_LENGTH_TC_EXE_SUCCESS 20 - CCSDS_TC_TM_PACKET_OFFSET
117 //
142 #define PACKET_LENGTH_TC_EXE_INCONSISTENT 26 - CCSDS_TC_TM_PACKET_OFFSET
118 #define TM_LEN_EXE 20 - CCSDS_TC_TM_PACKET_OFFSET
143 #define PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE 26 - CCSDS_TC_TM_PACKET_OFFSET
119 #define TM_LEN_NOT_EXE 26 - CCSDS_TC_TM_PACKET_OFFSET
144 #define PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED 24 - CCSDS_TC_TM_PACKET_OFFSET
120 #define TM_LEN_NOT_IMP 24 - CCSDS_TC_TM_PACKET_OFFSET
145 #define PACKET_LENGTH_TC_EXE_ERROR 24 - CCSDS_TC_TM_PACKET_OFFSET
121 #define TM_LEN_EXE_ERR 24 - CCSDS_TC_TM_PACKET_OFFSET
146 #define PACKET_LENGTH_TC_EXE_CORRUPTED 32 - CCSDS_TC_TM_PACKET_OFFSET
122 #define TM_LEN_EXE_CORR 32 - CCSDS_TC_TM_PACKET_OFFSET
147 #define PACKET_LENGTH_HK 126 - CCSDS_TC_TM_PACKET_OFFSET
148 #define PACKET_LENGTH_PARAMETER_DUMP 28 - CCSDS_TC_TM_PACKET_OFFSET
123 #define TM_HEADER_LEN 16
149 #define TM_HEADER_LEN 16
124
150
125 #define LEN_TM_LFR_HK 126 + 4
151 #define LEN_TM_LFR_HK 126 + 4
126 #define LEN_TM_LFR_TC_EXE_NOT_IMP 24 +4
152 #define LEN_TM_LFR_TC_EXE_NOT_IMP 24 +4
127
153
128 #define TM_LEN_SCI_NORM_SWF_340 340 * 12 + 6 + 10 - 1
154 #define TM_LEN_SCI_SWF_340 340 * 12 + 10 + 12 - 1
129 #define TM_LEN_SCI_NORM_SWF_8 8 * 12 + 6 + 10 - 1
155 #define TM_LEN_SCI_SWF_8 8 * 12 + 10 + 12 - 1
156 #define TM_LEN_SCI_CWF_340 340 * 12 + 10 + 10 - 1
157 #define TM_LEN_SCI_CWF_8 8 * 12 + 10 + 10 - 1
130
158
131 enum TM_TYPE{
159 enum TM_TYPE{
132 TM_LFR_TC_EXE_OK,
160 TM_LFR_TC_EXE_OK,
@@ -146,7 +174,12 struct TMHeader_str
146 volatile unsigned char packetID[2];
174 volatile unsigned char packetID[2];
147 volatile unsigned char packetSequenceControl[2];
175 volatile unsigned char packetSequenceControl[2];
148 volatile unsigned char packetLength[2];
176 volatile unsigned char packetLength[2];
149 volatile unsigned char dataFieldHeader[10];
177 // DATA FIELD HEADER
178 volatile unsigned char spare1_pusVersion_spare2;
179 volatile unsigned char serviceType;
180 volatile unsigned char serviceSubType;
181 volatile unsigned char destinationID;
182 volatile unsigned char time[6];
150 };
183 };
151 typedef struct TMHeader_str TMHeader_t;
184 typedef struct TMHeader_str TMHeader_t;
152
185
@@ -159,12 +192,17 struct Packet_TM_LFR_TC_EXE_str
159 volatile unsigned char packetID[2];
192 volatile unsigned char packetID[2];
160 volatile unsigned char packetSequenceControl[2];
193 volatile unsigned char packetSequenceControl[2];
161 volatile unsigned char packetLength[2];
194 volatile unsigned char packetLength[2];
162 volatile unsigned char dataFieldHeader[10];
195 // DATA FIELD HEADER
196 volatile unsigned char spare1_pusVersion_spare2;
197 volatile unsigned char serviceType;
198 volatile unsigned char serviceSubType;
199 volatile unsigned char destinationID;
200 volatile unsigned char time[6];
163 volatile unsigned char data[LENGTH_TM_LFR_TC_EXE_MAX - 10 + 1];
201 volatile unsigned char data[LENGTH_TM_LFR_TC_EXE_MAX - 10 + 1];
164 };
202 };
165 typedef struct Packet_TM_LFR_TC_EXE_str Packet_TM_LFR_TC_EXE_t;
203 typedef struct Packet_TM_LFR_TC_EXE_str Packet_TM_LFR_TC_EXE_t;
166
204
167 struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str
205 struct Header_TM_LFR_SCIENCE_SWF_str
168 {
206 {
169 volatile unsigned char targetLogicalAddress;
207 volatile unsigned char targetLogicalAddress;
170 volatile unsigned char protocolIdentifier;
208 volatile unsigned char protocolIdentifier;
@@ -173,13 +211,23 struct Packet_TM_LFR_SCIENCE_NORMAL_WF_s
173 volatile unsigned char packetID[2];
211 volatile unsigned char packetID[2];
174 volatile unsigned char packetSequenceControl[2];
212 volatile unsigned char packetSequenceControl[2];
175 volatile unsigned char packetLength[2];
213 volatile unsigned char packetLength[2];
176 volatile unsigned char dataFieldHeader[10];
214 // DATA FIELD HEADER
177 volatile unsigned char auxiliaryHeader[6];
215 volatile unsigned char spare1_pusVersion_spare2;
178 volatile unsigned char data[LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX - 10 + 1];
216 volatile unsigned char serviceType;
217 volatile unsigned char serviceSubType;
218 volatile unsigned char destinationID;
219 volatile unsigned char time[6];
220 // AUXILIARY HEADER
221 volatile unsigned char sid;
222 volatile unsigned char hkBIA;
223 volatile unsigned char pktCnt;
224 volatile unsigned char pktNr;
225 volatile unsigned char acquisitionTime[6];
226 volatile unsigned char blkNr[2];
179 };
227 };
180 typedef struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str Packet_TM_LFR_SCIENCE_NORMAL_WF_t;
228 typedef struct Header_TM_LFR_SCIENCE_SWF_str Header_TM_LFR_SCIENCE_SWF_t;
181
229
182 struct ExtendedTMHeader_str
230 struct Header_TM_LFR_SCIENCE_CWF_str
183 {
231 {
184 volatile unsigned char targetLogicalAddress;
232 volatile unsigned char targetLogicalAddress;
185 volatile unsigned char protocolIdentifier;
233 volatile unsigned char protocolIdentifier;
@@ -188,10 +236,19 struct ExtendedTMHeader_str
188 volatile unsigned char packetID[2];
236 volatile unsigned char packetID[2];
189 volatile unsigned char packetSequenceControl[2];
237 volatile unsigned char packetSequenceControl[2];
190 volatile unsigned char packetLength[2];
238 volatile unsigned char packetLength[2];
191 volatile unsigned char dataFieldHeader[10];
239 // DATA FIELD HEADER
192 volatile unsigned char auxiliaryHeader[6];
240 volatile unsigned char spare1_pusVersion_spare2;
241 volatile unsigned char serviceType;
242 volatile unsigned char serviceSubType;
243 volatile unsigned char destinationID;
244 volatile unsigned char time[6];
245 // AUXILIARY DATA HEADER
246 volatile unsigned char sid;
247 volatile unsigned char hkBIA;
248 volatile unsigned char acquisitionTime[6];
249 volatile unsigned char blkNr[2];
193 };
250 };
194 typedef struct ExtendedTMHeader_str ExtendedTMHeader_t;
251 typedef struct Header_TM_LFR_SCIENCE_CWF_str Header_TM_LFR_SCIENCE_CWF_t;
195
252
196 struct ccsdsTelecommandPacket_str
253 struct ccsdsTelecommandPacket_str
197 {
254 {
@@ -202,7 +259,11 struct ccsdsTelecommandPacket_str
202 volatile unsigned char packetID[2];
259 volatile unsigned char packetID[2];
203 volatile unsigned char packetSequenceControl[2];
260 volatile unsigned char packetSequenceControl[2];
204 volatile unsigned char packetLength[2];
261 volatile unsigned char packetLength[2];
205 volatile unsigned char dataFieldHeader[4];
262 // DATA FIELD HEADER
263 volatile unsigned char headerFlag_pusVersion_Ack;
264 volatile unsigned char serviceType;
265 volatile unsigned char serviceSubType;
266 volatile unsigned char sourceID;
206 volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
267 volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
207 };
268 };
208 typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
269 typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
@@ -28,6 +28,7 extern int fdUART; // uart file descrip
28 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
28 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
29
29
30 // MODE PARAMETERS
30 // MODE PARAMETERS
31 extern struct param_local_str param_local;
31 extern struct param_common_str param_common;
32 extern struct param_common_str param_common;
32 extern struct param_norm_str param_norm;
33 extern struct param_norm_str param_norm;
33 extern struct param_burst_str param_burst;
34 extern struct param_burst_str param_burst;
@@ -51,9 +52,11 int create_message_queue( void );
51 void init_default_mode_parameters( void );
52 void init_default_mode_parameters( void );
52 void init_housekeeping_parameters( void );
53 void init_housekeeping_parameters( void );
53
54
54 int configure_spw_link( void );
55 int spacewire_configure_link( void );
55 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
56 int spacewire_try_to_start(void);
56 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
57 void spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
58 void spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
59 void spacewire_compute_stats_offsets();
57
60
58 extern int rtems_cpu_usage_report( void );
61 extern int rtems_cpu_usage_report( void );
59 extern int rtems_cpu_usage_reset( void );
62 extern int rtems_cpu_usage_reset( void );
@@ -12,10 +12,12
12
12
13 rtems_name HK_name; // name of the HK rate monotonic
13 rtems_name HK_name; // name of the HK rate monotonic
14 rtems_id HK_id; // id of the HK rate monotonic period
14 rtems_id HK_id; // id of the HK rate monotonic period
15 extern spw_stats spacewire_stats;
16 extern spw_stats spacewire_stats_backup;
15
17
16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
18 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
19 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
18 void print_statistics(spw_stats *stats);
20 void update_spacewire_statistics();
19
21
20 // SERIAL LINK
22 // SERIAL LINK
21 int send_console_outputs_on_serial_port( void );
23 int send_console_outputs_on_serial_port( void );
@@ -22,6 +22,24
22 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
22 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
23 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
23 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
24
24
25 //****************************
26 // LFR DEFAULT MODE PARAMETERS
27 // NORM
28 #define DEFAULT_SY_LFR_N_SWF_L 2048 // nb sample
29 #define DEFAULT_SY_LFR_N_SWF_P 16 // sec
30 #define DEFAULT_SY_LFR_N_ASM_P 3600 // sec
31 #define DEFAULT_SY_LFR_N_BP_P0 4 // sec
32 #define DEFAULT_SY_LFR_N_BP_P1 20 // sec
33 // BURST
34 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
35 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
36 // SBM1
37 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
38 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
39 // SBM2
40 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
41 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
42
25 //*****************************
43 //*****************************
26 // APB REGISTERS BASE ADDRESSES
44 // APB REGISTERS BASE ADDRESSES
27 #define REGS_ADDR_APBUART 0x80000100
45 #define REGS_ADDR_APBUART 0x80000100
@@ -119,6 +137,13
119 #define SEQ_CNT_DST_ID_SYSTEM_CONTROL 9
137 #define SEQ_CNT_DST_ID_SYSTEM_CONTROL 9
120 #define SEQ_CNT_DST_ID_AOCS 10
138 #define SEQ_CNT_DST_ID_AOCS 10
121
139
140 struct param_local_str{
141 unsigned int local_sbm1_nb_cwf_sent;
142 unsigned int local_sbm1_nb_cwf_max;
143 unsigned int local_sbm2_nb_cwf_sent;
144 unsigned int local_sbm2_nb_cwf_max;
145 };
146
122 struct param_common_str{
147 struct param_common_str{
123 unsigned char sy_lfr_common0;
148 unsigned char sy_lfr_common0;
124 unsigned char sy_lfr_common1;
149 unsigned char sy_lfr_common1;
@@ -36,12 +36,12 void GetCRCAsTwoBytes(unsigned char* dat
36
36
37 //*********************
37 //*********************
38 // ACCEPTANCE FUNCTIONS
38 // ACCEPTANCE FUNCTIONS
39 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv);
39 int TC_acceptance(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV);
40 unsigned char TC_parser(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV);
40
41
41 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
42 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
42 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader);
43 TMHeader_t *TMHeader, unsigned char tc_sid);
43 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC);
44 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC);
44 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV);
45
45
46 //***********
46 //***********
47 // RTEMS TASK
47 // RTEMS TASK
@@ -53,22 +53,33 int create_message_queue( void );
53 //***********
53 //***********
54 // TC ACTIONS
54 // TC ACTIONS
55 int action_default(ccsdsTelecommandPacket_t *TC);
55 int action_default(ccsdsTelecommandPacket_t *TC);
56 int action_default_alt(ccsdsTelecommandPacket_t *TC);
56 int action_enter(ccsdsTelecommandPacket_t *TC);
57 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC);
57 int action_updt_info(ccsdsTelecommandPacket_t *TC);
58 //
58 int action_enable_calibration(ccsdsTelecommandPacket_t *TC);
59 int action_disable_calibration(ccsdsTelecommandPacket_t *TC);
60 int action_updt_time(ccsdsTelecommandPacket_t *TC);
61 // mode transition
62 int transition_validation(unsigned char requestedMode);
59 int stop_current_mode();
63 int stop_current_mode();
60 int enter_normal_mode();
64 int enter_mode(unsigned char mode, ccsdsTelecommandPacket_t *TC);
61 int enter_burst_mode();
65 int enter_standby_mode(ccsdsTelecommandPacket_t *TC);
62 int enter_sbm1_mode();
66 int enter_normal_mode(ccsdsTelecommandPacket_t *TC);
63 int enter_sbm2_mode();
67 int enter_burst_mode(ccsdsTelecommandPacket_t *TC);
68 int enter_sbm1_mode(ccsdsTelecommandPacket_t *TC);
69 int enter_sbm2_mode(ccsdsTelecommandPacket_t *TC);
70 // parameters loading
64 int action_load_comm(ccsdsTelecommandPacket_t *TC);
71 int action_load_comm(ccsdsTelecommandPacket_t *TC);
65 int action_load_norm(ccsdsTelecommandPacket_t *TC);
72 int action_load_norm(ccsdsTelecommandPacket_t *TC);
66 int action_enter(ccsdsTelecommandPacket_t *TC);
73 int action_load_burst(ccsdsTelecommandPacket_t *TC);
67 int action_updt_time(ccsdsTelecommandPacket_t *TC);
74 int action_load_sbm1(ccsdsTelecommandPacket_t *TC);
68 //
75 int action_load_sbm2(ccsdsTelecommandPacket_t *TC);
76 // other functions
69 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC);
77 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC);
70 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC);
78 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC);
71 void close_action(ccsdsTelecommandPacket_t *TC, int result);
79 void close_action(ccsdsTelecommandPacket_t *TC, int result);
80 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC);
81 int send_tm_lfr_tc_exe_not_executable(ccsdsTelecommandPacket_t *TC);
82 int send_tm_lfr_tc_exe_not_implemented(ccsdsTelecommandPacket_t *TC);
72
83
73 #endif // TC_HANDLER_H_INCLUDED
84 #endif // TC_HANDLER_H_INCLUDED
74
85
@@ -31,10 +31,25 rtems_task wfrm_task(rtems_task_argument
31 //******************
31 //******************
32 // general functions
32 // general functions
33 void init_waveforms( void );
33 void init_waveforms( void );
34 void init_header_snapshot_wf( Header_TM_LFR_SCIENCE_SWF_t *header );
35 void init_header_continuous_wf( Header_TM_LFR_SCIENCE_CWF_t *header );
34 void reset_waveforms( void );
36 void reset_waveforms( void );
35 void send_waveform( ExtendedTMHeader_t *header, volatile int *waveform, unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send);
37 void send_waveform_norm(Header_TM_LFR_SCIENCE_SWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send);
36 void init_waveform_picker_regs();
38 void send_waveform_burst(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send);
37 void set_data_shaping_parameters(unsigned char parameters);
39 void send_waveform_sbm1(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send);
40 void send_waveform_sbm2(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send);
41 void send_waveform_SWF( Header_TM_LFR_SCIENCE_SWF_t *header, volatile int *waveform,
42 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send);
43 void send_waveform_CWF( Header_TM_LFR_SCIENCE_CWF_t *header, volatile int *waveform,
44 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send);
45
46 //**************
47 // wfp registers
48 void set_wfp_data_shaping(unsigned char data_shaping);
49 void set_wfp_delta_snapshot(unsigned int delta_snapshot);
50 void reset_wfp_burst_enable();
51 void reset_wfp_regs();
52 //
38 int build_value(int value1, int value0);
53 int build_value(int value1, int value0);
39
54
40 #endif // WF_HANDLER_H_INCLUDED
55 #endif // WF_HANDLER_H_INCLUDED
@@ -2,12 +2,12
2
2
3 // GRSPW0 resources
3 // GRSPW0 resources
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
5 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
5 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+6}}, // 6 is for the auxiliary header, when needed
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+12}}, // 12 is for the auxiliary header, when needed
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}},
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}},
10 KEY_EMPTY
10 KEY_EMPTY
11 };
11 };
12
12
13 #if 0
13 #if 0
@@ -50,6 +50,6 struct drvmgr_bus_res grlib_drv_resource
50 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
50 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
51 RES_EMPTY /* Mark end of device resource array */
51 RES_EMPTY /* Mark end of device resource array */
52 }
52 }
53 };
53 };
54
55
54
55
@@ -1,5 +1,6
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <rtems.h>
2 #include <rtems.h>
3 #include <grspw.h>
3 #include <ccsds_types.h>
4 #include <ccsds_types.h>
4
5
5 // RTEMS GLOBAL VARIABLES
6 // RTEMS GLOBAL VARIABLES
@@ -39,6 +40,7 float averaged_spec_mat_f0[ TOTAL_SIZE_S
39 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
40 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
40
41
41 // MODE PARAMETERS
42 // MODE PARAMETERS
43 struct param_local_str param_local;
42 struct param_common_str param_common;
44 struct param_common_str param_common;
43 struct param_norm_str param_norm;
45 struct param_norm_str param_norm;
44 struct param_burst_str param_burst;
46 struct param_burst_str param_burst;
@@ -47,7 +49,10 struct param_sbm2_str param_sbm2;
47
49
48 // HK PACKETS
50 // HK PACKETS
49 Packet_TM_LFR_HK_t housekeeping_packet;
51 Packet_TM_LFR_HK_t housekeeping_packet;
52 // sequence counters are incremented by APID (PID + CAT) and destination ID
50 unsigned short sequenceCounters[SEQ_CNT_NB_PID][SEQ_CNT_NB_CAT][SEQ_CNT_NB_DEST_ID];
53 unsigned short sequenceCounters[SEQ_CNT_NB_PID][SEQ_CNT_NB_CAT][SEQ_CNT_NB_DEST_ID];
54 spw_stats spacewire_stats;
55 spw_stats spacewire_stats_backup;
51
56
52 // BASIC PARAMETERS GLOBAL VARIABLES
57 // BASIC PARAMETERS GLOBAL VARIABLES
53 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
58 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
@@ -78,7 +78,7 rtems_task Init( rtems_task_argument ign
78
78
79 grspw_timecode_callback = &timecode_irq_handler;
79 grspw_timecode_callback = &timecode_irq_handler;
80
80
81 configure_spw_link();
81 spacewire_configure_link();
82
82
83 //****************************
83 //****************************
84 // Spectral Matrices simulator
84 // Spectral Matrices simulator
@@ -94,7 +94,7 rtems_task Init( rtems_task_argument ign
94 IRQ_SPARC_WF, waveforms_simulator_isr );
94 IRQ_SPARC_WF, waveforms_simulator_isr );
95 #else
95 #else
96 // configure the registers of the waveform picker
96 // configure the registers of the waveform picker
97 init_waveform_picker_regs();
97 reset_wfp_regs();
98 // configure the waveform picker interrupt service routine
98 // configure the waveform picker interrupt service routine
99 status = rtems_interrupt_catch( waveforms_isr,
99 status = rtems_interrupt_catch( waveforms_isr,
100 IRQ_SPARC_WAVEFORM_PICKER,
100 IRQ_SPARC_WAVEFORM_PICKER,
@@ -137,11 +137,18 rtems_task spiq_task(rtems_task_argument
137 {
137 {
138 rtems_event_set event_out;
138 rtems_event_set event_out;
139 rtems_status_code status;
139 rtems_status_code status;
140 unsigned char lfrMode;
140
141
141 while(true){
142 while(true){
142 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
143 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
143 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
144 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
144
145
146 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; // get the current mode
147
148 //****************
149 // STOP THE SYSTEM
150 spacewire_compute_stats_offsets();
151 stop_current_mode();
145 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) { // suspend RECV task
152 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) { // suspend RECV task
146 PRINTF("in SPIQ *** Error suspending RECV Task\n")
153 PRINTF("in SPIQ *** Error suspending RECV Task\n")
147 }
154 }
@@ -149,16 +156,24 rtems_task spiq_task(rtems_task_argument
149 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
156 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
150 }
157 }
151
158
152 configure_spw_link();
159 //***************************
160 // RESTART THE SPACEWIRE LINK
161 status = spacewire_try_to_start();
162 if (status != RTEMS_SUCCESSFUL) {
163 spacewire_configure_link();
164 }
153
165
166 //*******************
167 // RESTART THE SYSTEM
168 //ioctl(fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS); // clear statistics
154 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
169 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
155 if (status!=RTEMS_SUCCESSFUL) {
170 if (status != RTEMS_SUCCESSFUL) {
156 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
171 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
157 }
172 }
158
173 if (rtems_task_restart(Task_id[TASKID_RECV], 1) != RTEMS_SUCCESSFUL) { // restart RECV task
159 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) { // restart RECV task
160 PRINTF("in SPIQ *** Error restarting RECV Task\n")
174 PRINTF("in SPIQ *** Error restarting RECV Task\n")
161 }
175 }
176 //enter_mode(lfrMode, NULL); // enter the mode that was running before the SpaceWire interruption
162 }
177 }
163 }
178 }
164
179
@@ -167,21 +182,37 void init_default_mode_parameters(void)
167 // COMMON PARAMETERS
182 // COMMON PARAMETERS
168 param_common.sy_lfr_common0 = 0x00;
183 param_common.sy_lfr_common0 = 0x00;
169 param_common.sy_lfr_common1 = 0x10; // default value 0 0 0 1 0 0 0 0
184 param_common.sy_lfr_common1 = 0x10; // default value 0 0 0 1 0 0 0 0
185
170 // NORMAL MODE
186 // NORMAL MODE
171 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
187 param_norm.sy_lfr_n_swf_l = DEFAULT_SY_LFR_N_SWF_L; // nb sample
172 param_norm.sy_lfr_n_swf_p = 300; // sec
188 param_norm.sy_lfr_n_swf_p = DEFAULT_SY_LFR_N_SWF_P; // sec
173 param_norm.sy_lfr_n_asm_p = 3600; // sec
189 param_norm.sy_lfr_n_asm_p = DEFAULT_SY_LFR_N_ASM_P; // sec
174 param_norm.sy_lfr_n_bp_p0 = 4; // sec
190 param_norm.sy_lfr_n_bp_p0 = DEFAULT_SY_LFR_N_BP_P0; // sec
175 param_norm.sy_lfr_n_bp_p1 = 20; // sec
191 param_norm.sy_lfr_n_bp_p1 = DEFAULT_SY_LFR_N_BP_P1; // sec
192
176 // BURST MODE
193 // BURST MODE
177 param_burst.sy_lfr_b_bp_p0 = 1; // sec
194 param_burst.sy_lfr_b_bp_p0 = DEFAULT_SY_LFR_B_BP_P0; // sec
178 param_burst.sy_lfr_b_bp_p1 = 5; // sec
195 param_burst.sy_lfr_b_bp_p1 = DEFAULT_SY_LFR_B_BP_P1; // sec
196
179 // SBM1 MODE
197 // SBM1 MODE
180 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
198 param_sbm1.sy_lfr_s1_bp_p0 = DEFAULT_SY_LFR_S1_BP_P0; // sec
181 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
199 param_sbm1.sy_lfr_s1_bp_p1 = DEFAULT_SY_LFR_B_BP_P1; // sec
200
182 // SBM2 MODE
201 // SBM2 MODE
183 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
202 param_sbm2.sy_lfr_s2_bp_p0 = DEFAULT_SY_LFR_S2_BP_P0; // sec
184 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
203 param_sbm2.sy_lfr_s2_bp_p1 = DEFAULT_SY_LFR_S2_BP_P1; // sec
204
205 // LOCAL PARAMETERS
206 // (2 snapshots of 2048 points per seconds) * (period of the NORM snashots)
207 param_local.local_sbm1_nb_cwf_max = 2 * param_norm.sy_lfr_n_swf_p;
208 // (period of the NORM snashots) / (8 seconds per snapshot at f2 = 256 Hz)
209 param_local.local_sbm2_nb_cwf_max = param_norm.sy_lfr_n_swf_p / 8;
210
211 PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
212 PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
213
214 param_local.local_sbm1_nb_cwf_sent = 0;
215 param_local.local_sbm2_nb_cwf_sent = 0;
185 }
216 }
186
217
187 void init_housekeeping_parameters(void)
218 void init_housekeeping_parameters(void)
@@ -249,7 +280,7 int create_all_tasks( void )
249 );
280 );
250 // ACTN
281 // ACTN
251 status = rtems_task_create(
282 status = rtems_task_create(
252 Task_name[TASKID_ACTN], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
283 Task_name[TASKID_ACTN], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
253 RTEMS_DEFAULT_MODES,
284 RTEMS_DEFAULT_MODES,
254 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_ACTN]
285 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_ACTN]
255 );
286 );
@@ -285,7 +316,7 int create_all_tasks( void )
285 );
316 );
286 // WFRM
317 // WFRM
287 status = rtems_task_create(
318 status = rtems_task_create(
288 Task_name[TASKID_WFRM], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
319 Task_name[TASKID_WFRM], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
289 RTEMS_DEFAULT_MODES,
320 RTEMS_DEFAULT_MODES,
290 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
321 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
291 );
322 );
@@ -362,40 +393,48 int start_all_tasks( void )
362 return 0;
393 return 0;
363 }
394 }
364
395
365 int configure_spw_link( void )
396 int spacewire_configure_link( void )
366 {
397 {
367 rtems_status_code status;
398 rtems_status_code status;
368
399
369 close(fdSPW); // close the device if it is already open
400 close(fdSPW); // close the device if it is already open
370 PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
401 PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
371 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
402 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
372 if (fdSPW<0) PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
403 if ( fdSPW<0 ) {
373 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
404 PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
405 }
406
407 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, -1) != RTEMS_SUCCESSFUL){
374 PRINTF(".")
408 PRINTF(".")
375 fflush(stdout);
409 fflush( stdout );
376 close(fdSPW); // close the device
410 close( fdSPW ); // close the device
377 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
411 fdSPW = open( GRSPW_DEVICE_NAME, O_RDWR ); // open the device. the open call reset the hardware
378 if (fdSPW<0) PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
412 if (fdSPW<0) {
413 PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
414 }
379 rtems_task_wake_after(100);
415 rtems_task_wake_after(100);
380 }
416 }
381
417
382 PRINTF("OK *** In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
418 PRINTF("OK *** In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
383
419
384 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
420 spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
385 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
421 spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
386
422
387 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
423 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
388 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
424 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
389 //
425 //
390 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
426 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
391 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
427 //if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
392 //
428 //
393 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
429 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
394 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
430 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
395 //
431 //
396 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
432 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
397 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
433 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
398 //
434 //
435 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
436 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
437 //
399 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 0); // transmission blocks on full
438 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 0); // transmission blocks on full
400 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
439 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
401 //
440 //
@@ -407,7 +446,29 int configure_spw_link( void )
407 return RTEMS_SUCCESSFUL;
446 return RTEMS_SUCCESSFUL;
408 }
447 }
409
448
410 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // [N]o [P]ort force
449 int spacewire_try_to_start(void)
450 {
451 unsigned int i;
452 int linkStatus;
453 rtems_status_code status = RTEMS_UNSATISFIED;
454
455 for(i = 0; i< 10; i++){
456 PRINTF(".")
457 fflush( stdout );
458 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
459 PRINTF1("in spacewire_try_to_start *** link status is: %s\n", lstates[linkStatus])
460 if ( linkStatus == 5) {
461 PRINTF("in spacewire_try_to_start *** link is running\n")
462 status = RTEMS_SUCCESSFUL;
463 break;
464 }
465 rtems_task_wake_after(100);
466 }
467
468 return status;
469 }
470
471 void spacewire_set_NP(unsigned char val, unsigned int regAddr) // [N]o [P]ort force
411 {
472 {
412 unsigned int *spwptr = (unsigned int*) regAddr;
473 unsigned int *spwptr = (unsigned int*) regAddr;
413
474
@@ -419,7 +480,7 void configure_spacewire_set_NP(unsigned
419 }
480 }
420 }
481 }
421
482
422 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // [R]MAP [E]nable
483 void spacewire_set_RE(unsigned char val, unsigned int regAddr) // [R]MAP [E]nable
423 {
484 {
424 unsigned int *spwptr = (unsigned int*) regAddr;
485 unsigned int *spwptr = (unsigned int*) regAddr;
425
486
@@ -433,10 +494,48 void configure_spacewire_set_RE(unsigned
433 }
494 }
434 }
495 }
435
496
497 void spacewire_compute_stats_offsets()
498 {
499 spw_stats spacewire_stats_grspw;
500 rtems_status_code status;
501
502 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
503
504 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
505 + spacewire_stats.packets_received;
506 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
507 + spacewire_stats.packets_sent;
508 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
509 + spacewire_stats.parity_err;
510 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
511 + spacewire_stats.disconnect_err;
512 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
513 + spacewire_stats.escape_err;
514 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
515 + spacewire_stats.credit_err;
516 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
517 + spacewire_stats.write_sync_err;
518 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
519 + spacewire_stats.rx_rmap_header_crc_err;
520 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
521 + spacewire_stats.rx_rmap_data_crc_err;
522 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
523 + spacewire_stats.early_ep;
524 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
525 + spacewire_stats.invalid_address;
526 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
527 + spacewire_stats.rx_eep_err;
528 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
529 + spacewire_stats.rx_truncated;
530 }
531
436 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
532 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
437 {
533 {
438 rtems_status_code status;
534 rtems_status_code status;
439 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
536 if (status != RTEMS_SUCCESSFUL){
537 //PRINTF1("ERR *** in write_spw *** write operation failed with code: %d\n", status)
538 }
440 return status;
539 return status;
441 }
540 }
442
541
@@ -446,4 +545,3 void timecode_irq_handler(void *pDev, vo
446 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
545 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
447 }
546 }
448 }
547 }
449
@@ -26,23 +26,69 int configure_timer(gptimer_regs_t *gpti
26 return 1;
26 return 1;
27 }
27 }
28
28
29 void print_statistics(spw_stats *stats)
29 void update_spacewire_statistics()
30 {
30 {
31 //printf(" ******** STATISTICS ******** \n");
31 rtems_status_code status;
32 printf("Transmit link errors: %i\n", stats->tx_link_err);
32 spw_stats spacewire_stats_grspw;
33 printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err);
33
34 printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err);
34 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
35 printf("Receiver EEP errors: %i\n", stats->rx_eep_err);
35
36 printf("Receiver truncation errors: %i\n", stats->rx_truncated);
36 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
37 printf("Parity errors: %i\n", stats->parity_err);
37 + spacewire_stats_grspw.packets_received;
38 printf("Escape errors: %i\n", stats->escape_err);
38 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
39 printf("Credit errors: %i\n", stats->credit_err);
39 + spacewire_stats_grspw.packets_sent;
40 printf("Disconnect errors: %i\n", stats->disconnect_err);
40 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
41 printf("Write synchronization errors: %i\n", stats->write_sync_err);
41 + spacewire_stats_grspw.parity_err;
42 printf("Early EOP/EEP: %i\n", stats->early_ep);
42 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
43 printf("Invalid Node Address: %i\n", stats->invalid_address);
43 + spacewire_stats_grspw.disconnect_err;
44 printf("Packets transmitted: %i\n", stats->packets_sent);
44 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
45 printf("Packets received: %i\n", stats->packets_received);
45 + spacewire_stats_grspw.escape_err;
46 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
47 + spacewire_stats_grspw.credit_err;
48 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
49 + spacewire_stats_grspw.write_sync_err;
50 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
51 + spacewire_stats_grspw.rx_rmap_header_crc_err;
52 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
53 + spacewire_stats_grspw.rx_rmap_data_crc_err;
54 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
55 + spacewire_stats_grspw.early_ep;
56 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
57 + spacewire_stats_grspw.invalid_address;
58 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
59 + spacewire_stats_grspw.rx_eep_err;
60 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
61 + spacewire_stats_grspw.rx_truncated;
62 //spacewire_stats.tx_link_err;
63
64 //****************************
65 // DPU_SPACEWIRE_IF_STATISTICS
66 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
67 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
68 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
69 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
70 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
71 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
72
73 //******************************************
74 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
75 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
76 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
77 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
78 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
79 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
80 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb;
81 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb;
82 housekeeping_packet.hk_lfr_dpu_spw_header_crc = (unsigned char) spacewire_stats.rx_rmap_header_crc_err;
83 housekeeping_packet.hk_lfr_dpu_spw_data_crc = (unsigned char) spacewire_stats.rx_rmap_data_crc_err;
84
85 //*********************************************
86 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
87 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
88 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
89 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
90 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
91
46 }
92 }
47
93
48 int send_console_outputs_on_serial_port( void ) // Send the console outputs on the serial port
94 int send_console_outputs_on_serial_port( void ) // Send the console outputs on the serial port
@@ -105,11 +151,11 rtems_task hous_task(rtems_task_argument
105 }
151 }
106
152
107 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
153 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
108 housekeeping_packet.protocolIdentifier = 0x02;
154 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
109 housekeeping_packet.reserved = 0x00;
155 housekeeping_packet.reserved = 0x00;
110 housekeeping_packet.userApplication = 0x00;
156 housekeeping_packet.userApplication = 0x00;
111 housekeeping_packet.packetID[0] = 0x0c;
157 housekeeping_packet.packetID[0] = (unsigned char) (TM_PACKET_ID_HK >> 8);
112 housekeeping_packet.packetID[1] = 0xc4;
158 housekeeping_packet.packetID[1] = (unsigned char) (TM_PACKET_ID_HK);
113 housekeeping_packet.packetSequenceControl[0] = 0xc0;
159 housekeeping_packet.packetSequenceControl[0] = 0xc0;
114 housekeeping_packet.packetSequenceControl[1] = 0x00;
160 housekeeping_packet.packetSequenceControl[1] = 0x00;
115 housekeeping_packet.packetLength[0] = 0x00;
161 housekeeping_packet.packetLength[0] = 0x00;
@@ -117,31 +163,34 rtems_task hous_task(rtems_task_argument
117 housekeeping_packet.dataFieldHeader[0] = 0x10;
163 housekeeping_packet.dataFieldHeader[0] = 0x10;
118 housekeeping_packet.dataFieldHeader[1] = TM_TYPE_HK;
164 housekeeping_packet.dataFieldHeader[1] = TM_TYPE_HK;
119 housekeeping_packet.dataFieldHeader[2] = TM_SUBTYPE_HK;
165 housekeeping_packet.dataFieldHeader[2] = TM_SUBTYPE_HK;
120 housekeeping_packet.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
166 housekeeping_packet.dataFieldHeader[3] = TM_DESTINATION_ID_GROUND;
121
167
122 status = rtems_rate_monotonic_cancel(HK_id);
168 status = rtems_rate_monotonic_cancel(HK_id);
123 if( status != RTEMS_SUCCESSFUL )
169 if( status != RTEMS_SUCCESSFUL ) {
124 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
170 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
125 else
171 }
126 PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
172 else {
173 PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
174 }
127
175
128 while(1){ // launch the rate monotonic task
176 while(1){ // launch the rate monotonic task
129 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
177 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
130 if ( status != RTEMS_SUCCESSFUL ){
178 if ( status != RTEMS_SUCCESSFUL ) {
131 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_period *** code %d\n", status);
179 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_period *** code %d\n", status);
132 }
180 }
133 else
181 else {
134 {
135 housekeeping_packet.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
182 housekeeping_packet.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
136 housekeeping_packet.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
183 housekeeping_packet.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
137 housekeeping_packet.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
184 housekeeping_packet.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
138 housekeeping_packet.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
185 housekeeping_packet.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
139 housekeeping_packet.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
186 housekeeping_packet.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
140 housekeeping_packet.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
187 housekeeping_packet.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
141 housekeeping_packet.sid = CCSDS_DESTINATION_ID_DPU;
188 housekeeping_packet.sid = SID_HK;
189
190 update_spacewire_statistics();
191
142 result = write ( fdSPW, &housekeeping_packet, LEN_TM_LFR_HK);
192 result = write ( fdSPW, &housekeeping_packet, LEN_TM_LFR_HK);
143 if (result==-1)
193 if (result==-1) {
144 {
145 PRINTF("ERR *** in HOUS *** HK send\n");
194 PRINTF("ERR *** in HOUS *** HK send\n");
146 }
195 }
147 }
196 }
This diff has been collapsed as it changes many lines, (606 lines changed) Show them Hide them
@@ -3,359 +3,361
3
3
4 #include <fsw_processing_globals.c>
4 #include <fsw_processing_globals.c>
5
5
6 //***********************************************************
6 //***********************************************************
7 // Interrupt Service Routine for spectral matrices processing
7 // Interrupt Service Routine for spectral matrices processing
8 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
8 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
9 {
9 {
10 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
10 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
11 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
11 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_4 );
12 }
12 }
13 }
13 }
14
14
15 //************
15 //************
16 // RTEMS TASKS
16 // RTEMS TASKS
17 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
17 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
18 {
18 {
19 rtems_event_set event_out;
19 rtems_event_set event_out;
20 unsigned char nb_interrupt_f0 = 0;
20 unsigned char nb_interrupt_f0 = 0;
21
21
22 PRINTF("in SMIQ *** \n")
22 PRINTF("in SMIQ *** \n")
23
23
24 while(1){
24 while(1){
25 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
25 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
26 nb_interrupt_f0 = nb_interrupt_f0 + 1;
26 nb_interrupt_f0 = nb_interrupt_f0 + 1;
27 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
27 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
28 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
28 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
29 printf("in SMIQ *** Error sending event to AVF0\n");
29 {
30 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
31 }
30 nb_interrupt_f0 = 0;
32 nb_interrupt_f0 = 0;
31 }
33 }
32 }
34 }
33 }
35 }
34
36
35 rtems_task spw_bppr_task(rtems_task_argument argument)
37 rtems_task spw_bppr_task(rtems_task_argument argument)
36 {
38 {
37 rtems_status_code status;
39 rtems_status_code status;
38 rtems_event_set event_out;
40 rtems_event_set event_out;
39 static int Nb_average_f0 = 0;
41 static int Nb_average_f0 = 0;
40 //static int nb_average_f1 = 0;
42 //static int nb_average_f1 = 0;
41 //static int nb_average_f2 = 0;
43 //static int nb_average_f2 = 0;
42
44
43 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
45 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
44 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
46 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
45 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
47 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
46
48
47 printf("in BPPR ***\n");
49 printf("in BPPR ***\n");
48
50
49 while(true){ // wait for an event to begin with the processing
51 while(true){ // wait for an event to begin with the processing
50 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
52 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
51 if (status == RTEMS_SUCCESSFUL) {
53 if (status == RTEMS_SUCCESSFUL) {
52 if ((spectral_matrices_regs->ctrl & 0x00000001)==1) {
54 if ((spectral_matrices_regs->ctrl & 0x00000001)==1) {
53 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
55 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
54 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
56 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
55 //printf("f0_a\n");
57 //printf("f0_a\n");
56 Nb_average_f0++;
58 Nb_average_f0++;
57 }
59 }
58 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1) {
60 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1) {
59 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
61 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
60 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
62 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
61 //printf("f0_b\n");
63 //printf("f0_b\n");
62 Nb_average_f0++;
64 Nb_average_f0++;
63 }
65 }
64 if (Nb_average_f0 == NB_AVERAGE_NORMAL_f0) {
66 if (Nb_average_f0 == NB_AVERAGE_NORMAL_f0) {
65 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
67 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
66 //printf("f0 compressed\n");
68 //printf("f0 compressed\n");
67 Nb_average_f0 = 0;
69 Nb_average_f0 = 0;
68 matrix_reset(averaged_spec_mat_f0);
70 matrix_reset(averaged_spec_mat_f0);
69 }
71 }
70 }
72 }
71 }
73 }
72 }
74 }
73
75
74 rtems_task avf0_task(rtems_task_argument argument){
76 rtems_task avf0_task(rtems_task_argument argument){
75 int i;
77 int i;
76 static int nb_average;
78 static int nb_average;
77 rtems_event_set event_out;
79 rtems_event_set event_out;
78 rtems_status_code status;
80 rtems_status_code status;
79
81
80 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
82 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
81 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
83 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
82 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
84 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
83
85
84 nb_average = 0;
86 nb_average = 0;
85
87
86 PRINTF("in AVFO *** \n")
88 PRINTF("in AVFO *** \n")
87
89
88 while(1){
90 while(1){
89 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
91 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
90 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
92 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
91 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
93 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
92 + spec_mat_f0_b[i]
94 + spec_mat_f0_b[i]
93 + spec_mat_f0_c[i]
95 + spec_mat_f0_c[i]
94 + spec_mat_f0_d[i]
96 + spec_mat_f0_d[i]
95 + spec_mat_f0_e[i]
97 + spec_mat_f0_e[i]
96 + spec_mat_f0_f[i]
98 + spec_mat_f0_f[i]
97 + spec_mat_f0_g[i]
99 + spec_mat_f0_g[i]
98 + spec_mat_f0_h[i];
100 + spec_mat_f0_h[i];
99 }
101 }
100 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
102 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
101 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
103 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
102 if (nb_average == NB_AVERAGE_NORMAL_f0) {
104 if (nb_average == NB_AVERAGE_NORMAL_f0) {
103 nb_average = 0;
105 nb_average = 0;
104 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
106 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
105 if (status != RTEMS_SUCCESSFUL) {
107 if (status != RTEMS_SUCCESSFUL) {
106 printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
108 printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
107 }
109 }
108 }
110 }
109 }
111 }
110 }
112 }
111
113
112 rtems_task bpf0_task(rtems_task_argument argument){
114 rtems_task bpf0_task(rtems_task_argument argument){
113 rtems_event_set event_out;
115 rtems_event_set event_out;
114
116
115 PRINTF("in BPFO *** \n")
117 PRINTF("in BPFO *** \n")
116
118
117 while(1){
119 while(1){
118 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
120 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
119 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
121 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
120 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
122 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
121 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
123 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
122 }
124 }
123 }
125 }
124
126
125 //*****************************
127 //*****************************
126 // Spectral matrices processing
128 // Spectral matrices processing
127 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
129 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
128 {
130 {
129 int i;
131 int i;
130 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
132 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
131 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
133 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
132 + spec_mat_f0_b[i]
134 + spec_mat_f0_b[i]
133 + spec_mat_f0_c[i]
135 + spec_mat_f0_c[i]
134 + spec_mat_f0_d[i]
136 + spec_mat_f0_d[i]
135 + spec_mat_f0_e[i]
137 + spec_mat_f0_e[i]
136 + spec_mat_f0_f[i]
138 + spec_mat_f0_f[i]
137 + spec_mat_f0_g[i]
139 + spec_mat_f0_g[i]
138 + spec_mat_f0_h[i];
140 + spec_mat_f0_h[i];
139 }
141 }
140 }
142 }
141
143
142 void matrix_reset(float *averaged_spec_mat)
144 void matrix_reset(float *averaged_spec_mat)
143 {
145 {
144 int i;
146 int i;
145 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
147 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
146 averaged_spec_mat_f0[i] = 0;
148 averaged_spec_mat_f0[i] = 0;
147 }
149 }
148 }
150 }
149
151
150 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
152 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
151 {
153 {
152 int i;
154 int i;
153 int j;
155 int j;
154 switch (fChannel){
156 switch (fChannel){
155 case 0:
157 case 0:
156 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
158 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
157 j = 17 + (i * 8);
159 j = 17 + (i * 8);
158 compressed_spec_mat[i] = (averaged_spec_mat[j]
160 compressed_spec_mat[i] = (averaged_spec_mat[j]
159 + averaged_spec_mat[j+1]
161 + averaged_spec_mat[j+1]
160 + averaged_spec_mat[j+2]
162 + averaged_spec_mat[j+2]
161 + averaged_spec_mat[j+3]
163 + averaged_spec_mat[j+3]
162 + averaged_spec_mat[j+4]
164 + averaged_spec_mat[j+4]
163 + averaged_spec_mat[j+5]
165 + averaged_spec_mat[j+5]
164 + averaged_spec_mat[j+6]
166 + averaged_spec_mat[j+6]
165 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
167 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
166 }
168 }
167 break;
169 break;
168 case 1:
170 case 1:
169 // case fChannel = f1 to be completed later
171 // case fChannel = f1 to be completed later
170 break;
172 break;
171 case 2:
173 case 2:
172 // case fChannel = f1 to be completed later
174 // case fChannel = f1 to be completed later
173 break;
175 break;
174 default:
176 default:
175 break;
177 break;
176 }
178 }
177 }
179 }
178
180
179 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
181 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
180 int i;
182 int i;
181 int j;
183 int j;
182 unsigned char tmp_u_char;
184 unsigned char tmp_u_char;
183 unsigned char * pt_char = NULL;
185 unsigned char * pt_char = NULL;
184 float PSDB, PSDE;
186 float PSDB, PSDE;
185 float NVEC_V0;
187 float NVEC_V0;
186 float NVEC_V1;
188 float NVEC_V1;
187 float NVEC_V2;
189 float NVEC_V2;
188 //float significand;
190 //float significand;
189 //int exponent;
191 //int exponent;
190 float aux;
192 float aux;
191 float tr_SB_SB;
193 float tr_SB_SB;
192 float tmp;
194 float tmp;
193 float sx_re;
195 float sx_re;
194 float sx_im;
196 float sx_im;
195 float nebx_re = 0;
197 float nebx_re = 0;
196 float nebx_im = 0;
198 float nebx_im = 0;
197 float ny = 0;
199 float ny = 0;
198 float nz = 0;
200 float nz = 0;
199 float bx_bx_star = 0;
201 float bx_bx_star = 0;
200 for(i=0; i<nb_bins_compressed_spec_mat; i++){
202 for(i=0; i<nb_bins_compressed_spec_mat; i++){
201 //==============================================
203 //==============================================
202 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
204 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
203 PSDB = compressed_spec_mat[i*30] // S11
205 PSDB = compressed_spec_mat[i*30] // S11
204 + compressed_spec_mat[(i*30) + 10] // S22
206 + compressed_spec_mat[(i*30) + 10] // S22
205 + compressed_spec_mat[(i*30) + 18]; // S33
207 + compressed_spec_mat[(i*30) + 18]; // S33
206 //significand = frexp(PSDB, &exponent);
208 //significand = frexp(PSDB, &exponent);
207 pt_char = (unsigned char*) &PSDB;
209 pt_char = (unsigned char*) &PSDB;
208 LFR_BP1[(i*9) + 2] = pt_char[0]; // bits 31 downto 24 of the float
210 LFR_BP1[(i*9) + 2] = pt_char[0]; // bits 31 downto 24 of the float
209 LFR_BP1[(i*9) + 3] = pt_char[1]; // bits 23 downto 16 of the float
211 LFR_BP1[(i*9) + 3] = pt_char[1]; // bits 23 downto 16 of the float
210 //==============================================
212 //==============================================
211 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
213 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
212 PSDE = compressed_spec_mat[(i*30) + 24] * K44_pe // S44
214 PSDE = compressed_spec_mat[(i*30) + 24] * K44_pe // S44
213 + compressed_spec_mat[(i*30) + 28] * K55_pe // S55
215 + compressed_spec_mat[(i*30) + 28] * K55_pe // S55
214 + compressed_spec_mat[(i*30) + 26] * K45_pe_re // S45
216 + compressed_spec_mat[(i*30) + 26] * K45_pe_re // S45
215 - compressed_spec_mat[(i*30) + 27] * K45_pe_im; // S45
217 - compressed_spec_mat[(i*30) + 27] * K45_pe_im; // S45
216 pt_char = (unsigned char*) &PSDE;
218 pt_char = (unsigned char*) &PSDE;
217 LFR_BP1[(i*9) + 0] = pt_char[0]; // bits 31 downto 24 of the float
219 LFR_BP1[(i*9) + 0] = pt_char[0]; // bits 31 downto 24 of the float
218 LFR_BP1[(i*9) + 1] = pt_char[1]; // bits 23 downto 16 of the float
220 LFR_BP1[(i*9) + 1] = pt_char[1]; // bits 23 downto 16 of the float
219 //==============================================================================
221 //==============================================================================
220 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
222 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
221 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
223 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
222 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
224 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
223 tmp = sqrt(
225 tmp = sqrt(
224 compressed_spec_mat[(i*30) + 3]*compressed_spec_mat[(i*30) + 3] //Im S12
226 compressed_spec_mat[(i*30) + 3]*compressed_spec_mat[(i*30) + 3] //Im S12
225 +compressed_spec_mat[(i*30) + 5]*compressed_spec_mat[(i*30) + 5] //Im S13
227 +compressed_spec_mat[(i*30) + 5]*compressed_spec_mat[(i*30) + 5] //Im S13
226 +compressed_spec_mat[(i*30) + 13]*compressed_spec_mat[(i*30) + 13] //Im S23
228 +compressed_spec_mat[(i*30) + 13]*compressed_spec_mat[(i*30) + 13] //Im S23
227 );
229 );
228 NVEC_V0 = compressed_spec_mat[(i*30) + 13] / tmp; // Im S23
230 NVEC_V0 = compressed_spec_mat[(i*30) + 13] / tmp; // Im S23
229 NVEC_V1 = -compressed_spec_mat[(i*30) + 5] / tmp; // Im S13
231 NVEC_V1 = -compressed_spec_mat[(i*30) + 5] / tmp; // Im S13
230 NVEC_V2 = compressed_spec_mat[(i*30) + 3] / tmp; // Im S12
232 NVEC_V2 = compressed_spec_mat[(i*30) + 3] / tmp; // Im S12
231 LFR_BP1[(i*9) + 4] = (char) (NVEC_V0*127);
233 LFR_BP1[(i*9) + 4] = (char) (NVEC_V0*127);
232 LFR_BP1[(i*9) + 5] = (char) (NVEC_V1*127);
234 LFR_BP1[(i*9) + 5] = (char) (NVEC_V1*127);
233 pt_char = (unsigned char*) &NVEC_V2;
235 pt_char = (unsigned char*) &NVEC_V2;
234 LFR_BP1[(i*9) + 6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
236 LFR_BP1[(i*9) + 6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
235 //=======================================================
237 //=======================================================
236 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
238 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
237 aux = 2*tmp / PSDB; // compute the ellipticity
239 aux = 2*tmp / PSDB; // compute the ellipticity
238 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
240 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
239 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
241 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
240 //==============================================================
242 //==============================================================
241 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
243 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
242 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
244 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
243 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
245 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
244 + compressed_spec_mat[(i*30) + 10] * compressed_spec_mat[(i*30) + 10]
246 + compressed_spec_mat[(i*30) + 10] * compressed_spec_mat[(i*30) + 10]
245 + compressed_spec_mat[(i*30) + 18] * compressed_spec_mat[(i*30) + 18]
247 + compressed_spec_mat[(i*30) + 18] * compressed_spec_mat[(i*30) + 18]
246 + 2 * compressed_spec_mat[(i*30) + 2] * compressed_spec_mat[(i*30) + 2]
248 + 2 * compressed_spec_mat[(i*30) + 2] * compressed_spec_mat[(i*30) + 2]
247 + 2 * compressed_spec_mat[(i*30) + 3] * compressed_spec_mat[(i*30) + 3]
249 + 2 * compressed_spec_mat[(i*30) + 3] * compressed_spec_mat[(i*30) + 3]
248 + 2 * compressed_spec_mat[(i*30) + 4] * compressed_spec_mat[(i*30) + 4]
250 + 2 * compressed_spec_mat[(i*30) + 4] * compressed_spec_mat[(i*30) + 4]
249 + 2 * compressed_spec_mat[(i*30) + 5] * compressed_spec_mat[(i*30) + 5]
251 + 2 * compressed_spec_mat[(i*30) + 5] * compressed_spec_mat[(i*30) + 5]
250 + 2 * compressed_spec_mat[(i*30) + 12] * compressed_spec_mat[(i*30) + 12]
252 + 2 * compressed_spec_mat[(i*30) + 12] * compressed_spec_mat[(i*30) + 12]
251 + 2 * compressed_spec_mat[(i*30) + 13] * compressed_spec_mat[(i*30) + 13];
253 + 2 * compressed_spec_mat[(i*30) + 13] * compressed_spec_mat[(i*30) + 13];
252 }
254 }
253 aux = PSDB*PSDB;
255 aux = PSDB*PSDB;
254 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
256 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
255 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
257 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
256 LFR_BP1[(i*9) + 6] = LFR_BP1[(i*9) + 6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
258 LFR_BP1[(i*9) + 6] = LFR_BP1[(i*9) + 6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
257 //=======================================================================================
259 //=======================================================================================
258 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
260 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
259 sx_re = compressed_spec_mat[(i*30) + 20] * K34_sx_re
261 sx_re = compressed_spec_mat[(i*30) + 20] * K34_sx_re
260 + compressed_spec_mat[(i*30) + 6] * K14_sx_re
262 + compressed_spec_mat[(i*30) + 6] * K14_sx_re
261 + compressed_spec_mat[(i*30) + 8] * K15_sx_re
263 + compressed_spec_mat[(i*30) + 8] * K15_sx_re
262 + compressed_spec_mat[(i*30) + 14] * K24_sx_re
264 + compressed_spec_mat[(i*30) + 14] * K24_sx_re
263 + compressed_spec_mat[(i*30) + 16] * K25_sx_re
265 + compressed_spec_mat[(i*30) + 16] * K25_sx_re
264 + compressed_spec_mat[(i*30) + 22] * K35_sx_re;
266 + compressed_spec_mat[(i*30) + 22] * K35_sx_re;
265 sx_im = compressed_spec_mat[(i*30) + 21] * K34_sx_im
267 sx_im = compressed_spec_mat[(i*30) + 21] * K34_sx_im
266 + compressed_spec_mat[(i*30) + 7] * K14_sx_im
268 + compressed_spec_mat[(i*30) + 7] * K14_sx_im
267 + compressed_spec_mat[(i*30) + 9] * K15_sx_im
269 + compressed_spec_mat[(i*30) + 9] * K15_sx_im
268 + compressed_spec_mat[(i*30) + 15] * K24_sx_im
270 + compressed_spec_mat[(i*30) + 15] * K24_sx_im
269 + compressed_spec_mat[(i*30) + 17] * K25_sx_im
271 + compressed_spec_mat[(i*30) + 17] * K25_sx_im
270 + compressed_spec_mat[(i*30) + 23] * K35_sx_im;
272 + compressed_spec_mat[(i*30) + 23] * K35_sx_im;
271 LFR_BP1[(i*9) + 7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
273 LFR_BP1[(i*9) + 7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
272 if ( abs(sx_re) > abs(sx_im) ) {
274 if ( abs(sx_re) > abs(sx_im) ) {
273 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] | (0x80); // extract the sector of sx
275 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] | (0x80); // extract the sector of sx
274 }
276 }
275 else {
277 else {
276 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] & (0x7f); // extract the sector of sx
278 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] & (0x7f); // extract the sector of sx
277 }
279 }
278 //======================================================================
280 //======================================================================
279 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
281 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
280 ny = sin(Alpha_M)*NVEC_V1 + cos(Alpha_M)*NVEC_V2;
282 ny = sin(Alpha_M)*NVEC_V1 + cos(Alpha_M)*NVEC_V2;
281 nz = NVEC_V0;
283 nz = NVEC_V0;
282 bx_bx_star = cos(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+10] // re S22
284 bx_bx_star = cos(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+10] // re S22
283 + sin(Alpha_M) * sin(Alpha_M) * compressed_spec_mat[i*30+18] // re S33
285 + sin(Alpha_M) * sin(Alpha_M) * compressed_spec_mat[i*30+18] // re S33
284 - 2 * sin(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+12]; // re S23
286 - 2 * sin(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+12]; // re S23
285 nebx_re = ny * (compressed_spec_mat[(i*30) + 14] * K24_ny_re
287 nebx_re = ny * (compressed_spec_mat[(i*30) + 14] * K24_ny_re
286 +compressed_spec_mat[(i*30) + 16] * K25_ny_re
288 +compressed_spec_mat[(i*30) + 16] * K25_ny_re
287 +compressed_spec_mat[(i*30) + 20] * K34_ny_re
289 +compressed_spec_mat[(i*30) + 20] * K34_ny_re
288 +compressed_spec_mat[(i*30) + 22] * K35_ny_re)
290 +compressed_spec_mat[(i*30) + 22] * K35_ny_re)
289 + nz * (compressed_spec_mat[(i*30) + 14] * K24_nz_re
291 + nz * (compressed_spec_mat[(i*30) + 14] * K24_nz_re
290 +compressed_spec_mat[(i*30) + 16] * K25_nz_re
292 +compressed_spec_mat[(i*30) + 16] * K25_nz_re
291 +compressed_spec_mat[(i*30) + 20] * K34_nz_re
293 +compressed_spec_mat[(i*30) + 20] * K34_nz_re
292 +compressed_spec_mat[(i*30) + 22] * K35_nz_re);
294 +compressed_spec_mat[(i*30) + 22] * K35_nz_re);
293 nebx_im = ny * (compressed_spec_mat[(i*30) + 15]*K24_ny_re
295 nebx_im = ny * (compressed_spec_mat[(i*30) + 15]*K24_ny_re
294 +compressed_spec_mat[(i*30) + 17] * K25_ny_re
296 +compressed_spec_mat[(i*30) + 17] * K25_ny_re
295 +compressed_spec_mat[(i*30) + 21] * K34_ny_re
297 +compressed_spec_mat[(i*30) + 21] * K34_ny_re
296 +compressed_spec_mat[(i*30) + 23] * K35_ny_re)
298 +compressed_spec_mat[(i*30) + 23] * K35_ny_re)
297 + nz * (compressed_spec_mat[(i*30) + 15] * K24_nz_im
299 + nz * (compressed_spec_mat[(i*30) + 15] * K24_nz_im
298 +compressed_spec_mat[(i*30) + 17] * K25_nz_im
300 +compressed_spec_mat[(i*30) + 17] * K25_nz_im
299 +compressed_spec_mat[(i*30) + 21] * K34_nz_im
301 +compressed_spec_mat[(i*30) + 21] * K34_nz_im
300 +compressed_spec_mat[(i*30) + 23] * K35_nz_im);
302 +compressed_spec_mat[(i*30) + 23] * K35_nz_im);
301 tmp = nebx_re / bx_bx_star;
303 tmp = nebx_re / bx_bx_star;
302 LFR_BP1[(i*9) + 8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
304 LFR_BP1[(i*9) + 8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
303 if ( abs(nebx_re) > abs(nebx_im) ) {
305 if ( abs(nebx_re) > abs(nebx_im) ) {
304 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] | (0x80); // extract the sector of nebx
306 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] | (0x80); // extract the sector of nebx
305 }
307 }
306 else {
308 else {
307 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] & (0x7f); // extract the sector of nebx
309 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] & (0x7f); // extract the sector of nebx
308 }
310 }
309 }
311 }
310
312
311 }
313 }
312
314
313 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
315 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
314 // BP2 autocorrelation
316 // BP2 autocorrelation
315 int i;
317 int i;
316 int aux = 0;
318 int aux = 0;
317
318 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
319 // S12
320 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 10]);
321 compressed_spec_mat[(i*30) + 2] = compressed_spec_mat[(i*30) + 2] / aux;
322 compressed_spec_mat[(i*30) + 3] = compressed_spec_mat[(i*30) + 3] / aux;
323 // S13
324 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 18]);
325 compressed_spec_mat[(i*30) + 4] = compressed_spec_mat[(i*30) + 4] / aux;
326 compressed_spec_mat[(i*30) + 5] = compressed_spec_mat[(i*30) + 5] / aux;
327 // S23
328 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[(i*30) + 18]);
329 compressed_spec_mat[(i*30) + 12] = compressed_spec_mat[(i*30) + 12] / aux;
330 compressed_spec_mat[(i*30) + 13] = compressed_spec_mat[(i*30) + 13] / aux;
331 // S45
332 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[(i*30) + 28]);
333 compressed_spec_mat[(i*30) + 26] = compressed_spec_mat[(i*30) + 26] / aux;
334 compressed_spec_mat[(i*30) + 27] = compressed_spec_mat[(i*30) + 27] / aux;
335 // S14
336 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) +24]);
337 compressed_spec_mat[(i*30) + 6] = compressed_spec_mat[(i*30) + 6] / aux;
338 compressed_spec_mat[(i*30) + 7] = compressed_spec_mat[(i*30) + 7] / aux;
339 // S15
340 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 28]);
341 compressed_spec_mat[(i*30) + 8] = compressed_spec_mat[(i*30) + 8] / aux;
342 compressed_spec_mat[(i*30) + 9] = compressed_spec_mat[(i*30) + 9] / aux;
343 // S24
344 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 24]);
345 compressed_spec_mat[(i*30) + 14] = compressed_spec_mat[(i*30) + 14] / aux;
346 compressed_spec_mat[(i*30) + 15] = compressed_spec_mat[(i*30) + 15] / aux;
347 // S25
348 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 28]);
349 compressed_spec_mat[(i*30) + 16] = compressed_spec_mat[(i*30) + 16] / aux;
350 compressed_spec_mat[(i*30) + 17] = compressed_spec_mat[(i*30) + 17] / aux;
351 // S34
352 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 24]);
353 compressed_spec_mat[(i*30) + 20] = compressed_spec_mat[(i*30) + 20] / aux;
354 compressed_spec_mat[(i*30) + 21] = compressed_spec_mat[(i*30) + 21] / aux;
355 // S35
356 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 28]);
357 compressed_spec_mat[(i*30) + 22] = compressed_spec_mat[(i*30) + 22] / aux;
358 compressed_spec_mat[(i*30) + 23] = compressed_spec_mat[(i*30) + 23] / aux;
359 }
360 }
361
319
320 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
321 // S12
322 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 10]);
323 compressed_spec_mat[(i*30) + 2] = compressed_spec_mat[(i*30) + 2] / aux;
324 compressed_spec_mat[(i*30) + 3] = compressed_spec_mat[(i*30) + 3] / aux;
325 // S13
326 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 18]);
327 compressed_spec_mat[(i*30) + 4] = compressed_spec_mat[(i*30) + 4] / aux;
328 compressed_spec_mat[(i*30) + 5] = compressed_spec_mat[(i*30) + 5] / aux;
329 // S23
330 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[(i*30) + 18]);
331 compressed_spec_mat[(i*30) + 12] = compressed_spec_mat[(i*30) + 12] / aux;
332 compressed_spec_mat[(i*30) + 13] = compressed_spec_mat[(i*30) + 13] / aux;
333 // S45
334 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[(i*30) + 28]);
335 compressed_spec_mat[(i*30) + 26] = compressed_spec_mat[(i*30) + 26] / aux;
336 compressed_spec_mat[(i*30) + 27] = compressed_spec_mat[(i*30) + 27] / aux;
337 // S14
338 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) +24]);
339 compressed_spec_mat[(i*30) + 6] = compressed_spec_mat[(i*30) + 6] / aux;
340 compressed_spec_mat[(i*30) + 7] = compressed_spec_mat[(i*30) + 7] / aux;
341 // S15
342 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 28]);
343 compressed_spec_mat[(i*30) + 8] = compressed_spec_mat[(i*30) + 8] / aux;
344 compressed_spec_mat[(i*30) + 9] = compressed_spec_mat[(i*30) + 9] / aux;
345 // S24
346 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 24]);
347 compressed_spec_mat[(i*30) + 14] = compressed_spec_mat[(i*30) + 14] / aux;
348 compressed_spec_mat[(i*30) + 15] = compressed_spec_mat[(i*30) + 15] / aux;
349 // S25
350 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 28]);
351 compressed_spec_mat[(i*30) + 16] = compressed_spec_mat[(i*30) + 16] / aux;
352 compressed_spec_mat[(i*30) + 17] = compressed_spec_mat[(i*30) + 17] / aux;
353 // S34
354 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 24]);
355 compressed_spec_mat[(i*30) + 20] = compressed_spec_mat[(i*30) + 20] / aux;
356 compressed_spec_mat[(i*30) + 21] = compressed_spec_mat[(i*30) + 21] / aux;
357 // S35
358 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 28]);
359 compressed_spec_mat[(i*30) + 22] = compressed_spec_mat[(i*30) + 22] / aux;
360 compressed_spec_mat[(i*30) + 23] = compressed_spec_mat[(i*30) + 23] / aux;
361 }
362 }
363
This diff has been collapsed as it changes many lines, (869 lines changed) Show them Hide them
@@ -1,11 +1,11
1 #include <tc_handler.h>
1 #include <tc_handler.h>
2 #include <fsw_params.h>
2 #include <fsw_params.h>
3
3
4 char *DumbMessages[5] = {"in DUMB *** default",
4 char *DumbMessages[5] = {"in DUMB *** default", // RTEMS_EVENT_0
5 "in DUMB *** timecode_irq_handler",
5 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
6 "in DUMB *** waveforms_isr",
6 "in DUMB *** waveforms_isr", // RTEMS_EVENT_2
7 "",
7 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
8 ""
8 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ" // RTEMS_EVENT_4
9 };
9 };
10
10
11 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
11 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
@@ -73,7 +73,7 void GetCRCAsTwoBytes(unsigned char* dat
73
73
74 //*********************
74 //*********************
75 // ACCEPTANCE FUNCTIONS
75 // ACCEPTANCE FUNCTIONS
76 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
76 int TC_acceptance(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
77 {
77 {
78 int ret = 0;
78 int ret = 0;
79 rtems_status_code status;
79 rtems_status_code status;
@@ -81,15 +81,16 int TC_checker(ccsdsTelecommandPacket_t
81 TMHeader_t TM_header;
81 TMHeader_t TM_header;
82 unsigned int code = 0;
82 unsigned int code = 0;
83 unsigned char computed_CRC[2];
83 unsigned char computed_CRC[2];
84 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
84 char data[ PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
85
85
86 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
86 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
87 code = acceptTM( TC, tc_len_recv ) ;
87 code = TC_parser( TC, tc_len_recv ) ;
88 if ( (code == ILLEGAL_APID) | (code == WRONG_LEN_PACKET) | (code == INCOR_CHECKSUM)
88 if ( (code == ILLEGAL_APID) | (code == WRONG_LEN_PACKET) | (code == INCOR_CHECKSUM)
89 | (code == ILL_TYPE) | (code == ILL_SUBTYPE) | (code == WRONG_APP_DATA) )
89 | (code == ILL_TYPE) | (code == ILL_SUBTYPE) | (code == WRONG_APP_DATA) )
90 { // generate TM_LFR_TC_EXE_CORRUPTED
90 { // generate TM_LFR_TC_EXE_CORRUPTED
91 // BUILD HEADER
91 // BUILD HEADER
92 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
92 TM_build_header( TM_LFR_TC_EXE_ERR, PACKET_LENGTH_TC_EXE_CORRUPTED,
93 &TM_header, TC->sourceID); // TC source ID
93 // BUILD DATA
94 // BUILD DATA
94 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
95 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
95 // PREPARE TM SENDING
96 // PREPARE TM SENDING
@@ -98,7 +99,7 int TC_checker(ccsdsTelecommandPacket_t
98 spw_ioctl_send.dlen = 16;
99 spw_ioctl_send.dlen = 16;
99 spw_ioctl_send.data = data;
100 spw_ioctl_send.data = data;
100 // SEND PACKET
101 // SEND PACKET
101 write_spw(&spw_ioctl_send);
102 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send );
102 }
103 }
103 else { // send valid TC to the action launcher
104 else { // send valid TC to the action launcher
104 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
105 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
@@ -107,7 +108,7 int TC_checker(ccsdsTelecommandPacket_t
107 return ret;
108 return ret;
108 }
109 }
109
110
110 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
111 unsigned char TC_parser(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
111 {
112 {
112 unsigned char ret = 0;
113 unsigned char ret = 0;
113 unsigned char pid = 0;
114 unsigned char pid = 0;
@@ -121,22 +122,22 unsigned char acceptTM(ccsdsTelecommandP
121 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
122 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
122 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
123 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
123 length = (TMPacket->packetLength[0] * 256) + TMPacket->packetLength[1];
124 length = (TMPacket->packetLength[0] * 256) + TMPacket->packetLength[1];
124 packetType = TMPacket->dataFieldHeader[1];
125 packetType = TMPacket->serviceType;
125 packetSubtype = TMPacket->dataFieldHeader[2];
126 packetSubtype = TMPacket->serviceSubType;
126
127
127 if (pid!=CCSDS_PROCESS_ID) {
128 if ( pid != CCSDS_PROCESS_ID ) {
128 ret = ILLEGAL_APID;
129 ret = ILLEGAL_APID;
129 }
130 }
130 else if (category!=CCSDS_PACKET_CATEGORY) {
131 else if ( category != CCSDS_PACKET_CATEGORY ) {
131 ret = ILLEGAL_APID;
132 ret = ILLEGAL_APID;
132 }
133 }
133 else if (length != TC_LEN_RCV ) { // packet length check
134 else if (length != TC_LEN_RCV ) { // packet length check
134 ret = WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
135 ret = WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
135 }
136 }
136 else if (length >= CCSDS_TC_PKT_MAX_SIZE) {
137 else if ( length >= CCSDS_TC_PKT_MAX_SIZE ) {
137 ret = WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
138 ret = WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
138 }
139 }
139 else if (packetType == TC_TYPE_GEN){ // service type, subtype and packet length check
140 else if ( packetType == TC_TYPE_GEN ){ // service type, subtype and packet length check
140 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
141 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
141 case TC_SUBTYPE_RESET:
142 case TC_SUBTYPE_RESET:
142 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
143 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
@@ -231,7 +232,7 unsigned char acceptTM(ccsdsTelecommandP
231 break;
232 break;
232 }
233 }
233 }
234 }
234 else if (packetType == TC_TYPE_TIME){
235 else if ( packetType == TC_TYPE_TIME ){
235 if (packetSubtype!=TC_SUBTYPE_UPDT_TIME) {
236 if (packetSubtype!=TC_SUBTYPE_UPDT_TIME) {
236 ret = ILL_SUBTYPE;
237 ret = ILL_SUBTYPE;
237 }
238 }
@@ -267,10 +268,10 unsigned char acceptTM(ccsdsTelecommandP
267 }
268 }
268
269
269 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
270 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
270 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
271 TMHeader_t *TMHeader, unsigned char tc_sid)
271 {
272 {
272 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
273 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
273 TMHeader->protocolIdentifier = 0x02;
274 TMHeader->protocolIdentifier = CCSDS_PROTOCOLE_ID;
274 TMHeader->reserved = 0x00;
275 TMHeader->reserved = 0x00;
275 TMHeader->userApplication = 0x00;
276 TMHeader->userApplication = 0x00;
276 TMHeader->packetID[0] = 0x0c;
277 TMHeader->packetID[0] = 0x0c;
@@ -278,107 +279,51 unsigned char TM_build_header( enum TM_T
278 TMHeader->packetSequenceControl[1] = 0x00;
279 TMHeader->packetSequenceControl[1] = 0x00;
279 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
280 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
280 TMHeader->packetLength[1] = (unsigned char) packetLength;
281 TMHeader->packetLength[1] = (unsigned char) packetLength;
281 TMHeader->dataFieldHeader[0] = 0x10;
282 TMHeader->spare1_pusVersion_spare2 = 0x10;
282 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
283 TMHeader->destinationID = CCSDS_DESTINATION_ID; // default destination id
283 switch (tm_type){
284 switch (tm_type){
284 case(TM_LFR_TC_EXE_OK):
285 case(TM_LFR_TC_EXE_OK):
285 TMHeader->packetID[1] = 0xc1;
286 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_TC_EXE;
286 TMHeader->dataFieldHeader[1] = 1; // type
287 TMHeader->serviceType = TM_TYPE_TC_EXE; // type
287 TMHeader->dataFieldHeader[2] = 7; // subtype
288 TMHeader->serviceSubType = TM_SUBTYPE_EXE_OK; // subtype
289 TMHeader->destinationID = tc_sid; // destination id
288 break;
290 break;
289 case(TM_LFR_TC_EXE_ERR):
291 case(TM_LFR_TC_EXE_ERR):
290 TMHeader->packetID[1] = 0xc1;
292 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_TC_EXE;
291 TMHeader->dataFieldHeader[1] = 1; // type
293 TMHeader->serviceType = TM_TYPE_TC_EXE; // type
292 TMHeader->dataFieldHeader[2] = 8; // subtype
294 TMHeader->serviceSubType = TM_SUBTYPE_EXE_NOK; // subtype
293 break;
295 break;
294 case(TM_LFR_HK):
296 case(TM_LFR_HK):
295 TMHeader->packetID[1] = 0xc4;
297 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_HK;
296 TMHeader->dataFieldHeader[1] = 3; // type
298 TMHeader->serviceType = TM_TYPE_HK; // type
297 TMHeader->dataFieldHeader[2] = 25; // subtype
299 TMHeader->serviceSubType = TM_SUBTYPE_HK; // subtype
298 break;
300 break;
299 case(TM_LFR_SCI):
301 case(TM_LFR_SCI):
300 TMHeader->packetID[1] = 0xcc;
302 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_SCIENCE_NORMAL;
301 TMHeader->dataFieldHeader[1] = 21; // type
303 TMHeader->serviceType = TM_TYPE_LFR_SCIENCE; // type
302 TMHeader->dataFieldHeader[2] = 3; // subtype
304 TMHeader->serviceSubType = TM_SUBTYPE_SCIENCE; // subtype
303 break;
305 break;
304 case(TM_LFR_SCI_SBM):
306 case(TM_LFR_SCI_SBM):
305 TMHeader->packetID[1] = 0xfc;
307 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2;
306 TMHeader->dataFieldHeader[1] = 21; // type
308 TMHeader->serviceType = TM_TYPE_LFR_SCIENCE; // type
307 TMHeader->dataFieldHeader[2] = 3; // subtype
309 TMHeader->serviceSubType = TM_SUBTYPE_SCIENCE; // subtype
308 break;
310 break;
309 case(TM_LFR_PAR_DUMP):
311 case(TM_LFR_PAR_DUMP):
310 TMHeader->packetID[1] = 0xc9;
312 TMHeader->packetID[1] = (unsigned char) TM_PACKET_ID_PARAMETER_DUMP;
311 TMHeader->dataFieldHeader[1] = 181; // type
313 TMHeader->serviceType = TM_TYPE_HK; // type
312 TMHeader->dataFieldHeader[2] = 31; // subtype
314 TMHeader->serviceSubType = TM_SUBTYPE_HK; // subtype
313 break;
315 break;
314 default:
316 default:
315 return 0;
317 return 0;
316 }
318 }
317 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
319 TMHeader->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
318 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
320 TMHeader->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
319 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
321 TMHeader->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
320 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
322 TMHeader->time[3] = (unsigned char) (time_management_regs->coarse_time);
321 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
323 TMHeader->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
322 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
324 TMHeader->time[5] = (unsigned char) (time_management_regs->fine_time);
323 return 1;
324 }
325
326 unsigned char TM_build_header_bis( enum TM_TYPE tm_type, unsigned int packetLength,
327 unsigned int coarseTime, unsigned int fineTime, Packet_TM_LFR_TC_EXE_t *packet)
328 {
329
325
330 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
326 return LFR_SUCCESSFUL;
331 packet->protocolIdentifier = 0x02;
332 packet->reserved = 0x00;
333 packet->userApplication = 0x00;
334 packet->packetID[0] = 0x0c;
335 packet->packetSequenceControl[0] = 0xc0;
336 packet->packetSequenceControl[1] = 0x00;
337 packet->packetLength[0] = (unsigned char) (packetLength>>8);
338 packet->packetLength[1] = (unsigned char) packetLength;
339 packet->dataFieldHeader[0] = 0x10;
340 packet->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
341 switch (tm_type){
342 case(TM_LFR_TC_EXE_OK):
343 packet->packetID[1] = 0xc1;
344 packet->dataFieldHeader[1] = 1; // type
345 packet->dataFieldHeader[2] = 7; // subtype
346 break;
347 case(TM_LFR_TC_EXE_ERR):
348 packet->packetID[1] = 0xc1;
349 packet->dataFieldHeader[1] = 1; // type
350 packet->dataFieldHeader[2] = 8; // subtype
351 break;
352 case(TM_LFR_HK):
353 packet->packetID[1] = 0xc4;
354 packet->dataFieldHeader[1] = 3; // type
355 packet->dataFieldHeader[2] = 25; // subtype
356 break;
357 case(TM_LFR_SCI):
358 packet->packetID[1] = 0xcc;
359 packet->dataFieldHeader[1] = 21; // type
360 packet->dataFieldHeader[2] = 3; // subtype
361 break;
362 case(TM_LFR_SCI_SBM):
363 packet->packetID[1] = 0xfc;
364 packet->dataFieldHeader[1] = 21; // type
365 packet->dataFieldHeader[2] = 3; // subtype
366 break;
367 case(TM_LFR_PAR_DUMP):
368 packet->packetID[1] = 0xc9;
369 packet->dataFieldHeader[1] = 181; // type
370 packet->dataFieldHeader[2] = 31; // subtype
371 break;
372 default:
373 return 0;
374 }
375 packet->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
376 packet->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
377 packet->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
378 packet->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
379 packet->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
380 packet->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
381 return 1;
382 }
327 }
383
328
384 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
329 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
@@ -395,8 +340,8 unsigned char TM_build_data(ccsdsTelecom
395 data[3] = TC->packetID[1];
340 data[3] = TC->packetID[1];
396 data[4] = TC->packetSequenceControl[0];
341 data[4] = TC->packetSequenceControl[0];
397 data[5] = TC->packetSequenceControl[1];
342 data[5] = TC->packetSequenceControl[1];
398 data[6] = TC->dataFieldHeader[1]; // type
343 data[6] = TC->serviceType; // type
399 data[7] = TC->dataFieldHeader[2]; // subtype
344 data[7] = TC->serviceSubType; // subtype
400 break;
345 break;
401 case (SID_EXE_ERR):
346 case (SID_EXE_ERR):
402 break;
347 break;
@@ -407,8 +352,8 unsigned char TM_build_data(ccsdsTelecom
407 data[3] = TC->packetID[1];
352 data[3] = TC->packetID[1];
408 data[4] = TC->packetSequenceControl[0];
353 data[4] = TC->packetSequenceControl[0];
409 data[5] = TC->packetSequenceControl[1];
354 data[5] = TC->packetSequenceControl[1];
410 data[6] = TC->dataFieldHeader[1]; // type
355 data[6] = TC->serviceType; // type
411 data[7] = TC->dataFieldHeader[2]; // subtype
356 data[7] = TC->serviceSubType; // subtype
412 data[8] = currentTC_LEN_RCV[0];
357 data[8] = currentTC_LEN_RCV[0];
413 data[9] = currentTC_LEN_RCV[1];
358 data[9] = currentTC_LEN_RCV[1];
414 data[10] = TC->packetLength[0];
359 data[10] = TC->packetLength[0];
@@ -456,12 +401,12 rtems_task recv_task( rtems_task_argumen
456 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
401 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
457 if (len == -1){ // error during the read call
402 if (len == -1){ // error during the read call
458 PRINTF("In RECV *** last read call returned -1\n")
403 PRINTF("In RECV *** last read call returned -1\n")
459 if (rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) {
404 //if (rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) {
460 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
405 // PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
461 }
406 //}
462 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) {
407 //if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) {
463 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
408 // PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
464 }
409 //}
465 }
410 }
466 else {
411 else {
467 PRINTF1("Got pck of length %d\n", len+1)
412 PRINTF1("Got pck of length %d\n", len+1)
@@ -473,7 +418,7 rtems_task recv_task( rtems_task_argumen
473 currentTC_LEN_RCV[1] = (unsigned char) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // build the corresponding packet size field
418 currentTC_LEN_RCV[1] = (unsigned char) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // build the corresponding packet size field
474 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
419 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
475 // CHECK THE TC AND BUILD THE APPROPRIATE TM
420 // CHECK THE TC AND BUILD THE APPROPRIATE TM
476 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
421 data_length = TC_acceptance(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
477 if (data_length!=-1)
422 if (data_length!=-1)
478 {
423 {
479 }
424 }
@@ -484,12 +429,14 rtems_task recv_task( rtems_task_argumen
484
429
485 rtems_task actn_task( rtems_task_argument unused )
430 rtems_task actn_task( rtems_task_argument unused )
486 {
431 {
487 int result = 0;
432 int result;
488 unsigned int val;
433 rtems_status_code status; // RTEMS status code
489 rtems_status_code status; // RTEMS status code
434 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
490 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
435 size_t size; // size of the incoming TC packet
491 size_t size; // size of the incoming TC packet
436 unsigned char subtype; // subtype of the current TC packet
492 unsigned char subtype = 0; // subtype of the current TC packet
437
438 result = LFR_SUCCESSFUL;
439 subtype = 0; // subtype of the current TC packet
493
440
494 PRINTF("in ACTN *** \n")
441 PRINTF("in ACTN *** \n")
495
442
@@ -500,7 +447,7 rtems_task actn_task( rtems_task_argumen
500 if (status!=RTEMS_SUCCESSFUL) PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
447 if (status!=RTEMS_SUCCESSFUL) PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
501 else
448 else
502 {
449 {
503 subtype = TC.dataFieldHeader[2];
450 subtype = TC.serviceSubType;
504 switch(subtype)
451 switch(subtype)
505 {
452 {
506 case TC_SUBTYPE_RESET:
453 case TC_SUBTYPE_RESET:
@@ -538,42 +485,27 rtems_task actn_task( rtems_task_argumen
538 break;
485 break;
539 //
486 //
540 case TC_SUBTYPE_ENTER:
487 case TC_SUBTYPE_ENTER:
541 if ( (housekeeping_packet.lfr_status_word[0] & 0xf0) != LFR_MODE_STANDBY)
542 {
543 status = stop_current_mode();
544 }
545 if (status != RTEMS_SUCCESSFUL)
546 {
547 PRINTF("ERR *** in task ACTN *** TC_SUBTYPE_ENTER *** stop_current_mode\n")
548 }
549 result = action_enter( &TC );
488 result = action_enter( &TC );
550 close_action( &TC, result );
489 close_action( &TC, result );
551 break;
490 break;
552 //
491 //
553 case TC_SUBTYPE_UPDT_INFO:
492 case TC_SUBTYPE_UPDT_INFO:
554 result = action_default( &TC );
493 result = action_updt_info( &TC );
555 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
494 close_action( &TC, result );
556 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
557 val++;
558 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
559 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
560 break;
495 break;
561 //
496 //
562 case TC_SUBTYPE_EN_CAL:
497 case TC_SUBTYPE_EN_CAL:
563 result = action_default( &TC );
498 result = action_enable_calibration( &TC );
499 close_action( &TC, result );
564 break;
500 break;
565 //
501 //
566 case TC_SUBTYPE_DIS_CAL:
502 case TC_SUBTYPE_DIS_CAL:
567 result = action_default( &TC );
503 result = action_disable_calibration( &TC );
504 close_action( &TC, result );
568 break;
505 break;
569 //
506 //
570 case TC_SUBTYPE_UPDT_TIME:
507 case TC_SUBTYPE_UPDT_TIME:
571 result = action_updt_time( &TC );
508 result = action_updt_time( &TC );
572 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
573 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
574 val++;
575 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
576 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
577 break;
509 break;
578 //
510 //
579 default:
511 default:
@@ -585,10 +517,10 rtems_task actn_task( rtems_task_argumen
585
517
586 rtems_task dumb_task( rtems_task_argument unused )
518 rtems_task dumb_task( rtems_task_argument unused )
587 {
519 {
520 unsigned int i;
521 unsigned int intEventOut;
588 unsigned int coarse_time = 0;
522 unsigned int coarse_time = 0;
589 unsigned int fine_time = 0;
523 unsigned int fine_time = 0;
590 unsigned int indice = 0;
591 unsigned int shiftedIndice = 0;
592 rtems_event_set event_out;
524 rtems_event_set event_out;
593
525
594 PRINTF("in DUMB *** \n")
526 PRINTF("in DUMB *** \n")
@@ -596,16 +528,17 rtems_task dumb_task( rtems_task_argumen
596 while(1){
528 while(1){
597 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4,
529 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4,
598 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
530 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
599 indice = 0;
531 intEventOut = (unsigned int) event_out;
600 shiftedIndice = (unsigned int) event_out;
532 PRINTF1("in DUMB *** event_out %x\n", (int) event_out)
601 while(!(shiftedIndice & 0x0001))
533 for ( i=0; i<32; i++)
602 {
534 {
603 shiftedIndice = shiftedIndice >> 1;
535 if ( ((intEventOut >> i) & 0x0001) != 0)
604 indice++;
536 {
537 coarse_time = time_management_regs->coarse_time;
538 fine_time = time_management_regs->fine_time;
539 printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
540 }
605 }
541 }
606 coarse_time = time_management_regs->coarse_time;
607 fine_time = time_management_regs->fine_time;
608 printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[indice]);
609 }
542 }
610 }
543 }
611
544
@@ -614,23 +547,34 rtems_task dumb_task( rtems_task_argumen
614
547
615 int action_default(ccsdsTelecommandPacket_t *TC)
548 int action_default(ccsdsTelecommandPacket_t *TC)
616 {
549 {
617 Packet_TM_LFR_TC_EXE_t packet;
550 rtems_status_code status;
551 TMHeader_t header;
552 spw_ioctl_pkt_send spw_ioctl_send;
553 unsigned char data[10];
618
554
619 TM_build_header_bis( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
555 TM_build_header( TM_LFR_TC_EXE_ERR, PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED,
620 time_management_regs->coarse_time, time_management_regs->fine_time, &packet);
556 &header, TC->sourceID);
621
557
622 packet.data[0] = 0x9c;
558 spw_ioctl_send.hlen = TM_HEADER_LEN + 4;
623 packet.data[1] = 0x42;
559 spw_ioctl_send.hdr = (char *) &header;
624 packet.data[2] = TC->packetID[0];
560 spw_ioctl_send.dlen = 8;
625 packet.data[3] = TC->packetID[1];
561 spw_ioctl_send.data = (char *) data;
626 packet.data[4] = TC->packetSequenceControl[0];
562 spw_ioctl_send.options = 0;
627 packet.data[5] = TC->packetSequenceControl[1];
563
628 packet.data[6] = TC->dataFieldHeader[1]; // type
564 data[0] = (char) (FAILURE_CODE_NOT_IMPLEMENTED >> 8);
629 packet.data[7] = TC->dataFieldHeader[2]; // subtype
565 data[1] = (char) FAILURE_CODE_NOT_IMPLEMENTED;
566 data[2] = TC->packetID[0];
567 data[3] = TC->packetID[1];
568 data[4] = TC->packetSequenceControl[0];
569 data[5] = TC->packetSequenceControl[1];
570 data[6] = TC->serviceType; // type
571 data[7] = TC->serviceSubType; // subtype
630
572
631 // SEND DATA
573 // SEND DATA
632 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1) {
574 status = write_spw(&spw_ioctl_send);
633 PRINTF("ERR *** in action_default *** send TM packet\n");
575 if (status != RTEMS_SUCCESSFUL)
576 {
577 PRINTF("ERR *** in action_default *** send TM packet\n")
634 }
578 }
635
579
636 return LFR_DEFAULT;
580 return LFR_DEFAULT;
@@ -638,69 +582,278 int action_default(ccsdsTelecommandPacke
638
582
639 int action_enter(ccsdsTelecommandPacket_t *TC)
583 int action_enter(ccsdsTelecommandPacket_t *TC)
640 {
584 {
641 rtems_status_code status = RTEMS_SUCCESSFUL;
585 rtems_status_code status;
642 unsigned char lfr_mode = TC->dataAndCRC[1];
586 unsigned char requestedMode;
643 printf("enter mode %d\n", lfr_mode);
587
644 switch(lfr_mode)
588 requestedMode = TC->dataAndCRC[1];
589
590 printf("try to enter mode %d\n", requestedMode);
591
592 status = transition_validation(requestedMode);
593
594 if ( status == LFR_SUCCESSFUL ) {
595 if ( (housekeeping_packet.lfr_status_word[0] & 0xf0) != LFR_MODE_STANDBY)
596 {
597 status = stop_current_mode();
598 }
599 if (status != RTEMS_SUCCESSFUL)
600 {
601 PRINTF("ERR *** in action_enter *** stop_current_mode\n")
602 }
603 status = enter_mode(requestedMode, TC);
604 }
605 else
645 {
606 {
646 //********
607 PRINTF("ERR *** in action_enter *** transition rejected\n")
647 // STANDBY
608 send_tm_lfr_tc_exe_not_executable( TC );
648 case(LFR_MODE_STANDBY):
609 }
649 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_STANDBY << 4) + 0x0d);
610
650 break;
611 return status;
612 }
613
614 int action_load_comm(ccsdsTelecommandPacket_t *TC)
615 {
616 param_common.sy_lfr_common0 = TC->dataAndCRC[0];
617 param_common.sy_lfr_common1 = TC->dataAndCRC[1];
618
619 set_wfp_data_shaping(param_common.sy_lfr_common1);
620
621 return LFR_SUCCESSFUL;
622 }
623
624 int action_load_norm(ccsdsTelecommandPacket_t *TC)
625 {
626 int result;
627 unsigned char lfrMode;
628
629 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
630
631 if ( lfrMode == LFR_MODE_NORMAL ) {
632 send_tm_lfr_tc_exe_not_executable( TC );
633 result = LFR_DEFAULT;
634 }
635 else {
636 param_norm.sy_lfr_n_swf_l = (TC->dataAndCRC[0] * 256) + TC->dataAndCRC[1];
637 param_norm.sy_lfr_n_swf_p = (TC->dataAndCRC[2] * 256) + TC->dataAndCRC[3];
638 param_norm.sy_lfr_n_asm_p = (TC->dataAndCRC[4] * 256) + TC->dataAndCRC[5];
639 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
640 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
641 result = LFR_SUCCESSFUL;
642 }
643
644 return result;
645 }
646
647 int action_load_burst(ccsdsTelecommandPacket_t *TC)
648 {
649 int result;
650 unsigned char lfrMode;
651
652 result = LFR_DEFAULT;
653 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
651
654
652 //******
655 if ( lfrMode == LFR_MODE_BURST ) {
653 // NORMAL
656 send_tm_lfr_tc_exe_not_executable( TC );
654 case(LFR_MODE_NORMAL):
657 result = LFR_DEFAULT;
655 status = enter_normal_mode();
658 }
656 if (status == RTEMS_SUCCESSFUL)
659 else {
657 {
660 send_tm_lfr_tc_exe_not_implemented( TC );
658 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_NORMAL << 4) + 0x0d);
661 result = LFR_DEFAULT;
659 }
662 }
660 break;
663
664 return result;
665 }
666
667 int action_load_sbm1(ccsdsTelecommandPacket_t *TC)
668 {
669 int result;
670 unsigned char lfrMode;
671
672 result = LFR_DEFAULT;
673 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
674
675 if ( (lfrMode == LFR_MODE_SBM1) | (lfrMode == LFR_MODE_SBM2) ) {
676 send_tm_lfr_tc_exe_not_executable( TC );
677 result = LFR_DEFAULT;
678 }
679 else {
680 send_tm_lfr_tc_exe_not_implemented( TC );
681 result = LFR_DEFAULT;
682 }
683
684 return result;
685 }
686
687 int action_load_sbm2(ccsdsTelecommandPacket_t *TC)
688 {
689 int result;
690 unsigned char lfrMode;
691
692 result = LFR_DEFAULT;
693 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
694
695 if ( (lfrMode == LFR_MODE_SBM1) | (lfrMode == LFR_MODE_SBM2) ) {
696 send_tm_lfr_tc_exe_not_executable( TC );
697 result = LFR_DEFAULT;
698 }
699 else {
700 send_tm_lfr_tc_exe_not_implemented( TC );
701 result = LFR_DEFAULT;
702 }
703
704 return result;
705 }
706
707 int action_updt_info(ccsdsTelecommandPacket_t *TC) {
708 unsigned int val;
709 int result;
710 unsigned char lfrMode;
711
712 result = LFR_DEFAULT;
713 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
661
714
662 //******
715 if ( (lfrMode == LFR_MODE_STANDBY) ) {
663 // BURST
716 send_tm_lfr_tc_exe_not_executable( TC );
664 case(LFR_MODE_BURST):
717 result = LFR_DEFAULT;
665 status = enter_burst_mode();
718 }
666 if (status == RTEMS_SUCCESSFUL)
719 else {
667 {
720 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
668 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_BURST << 4) + 0x0d);
721 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
669 }
722 val++;
670 break;
723 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
724 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
725 result = LFR_SUCCESSFUL;
726 }
727
728 return result;
729 }
730
731 int action_enable_calibration(ccsdsTelecommandPacket_t *TC)
732 {
733 int result;
734 unsigned char lfrMode;
735
736 result = LFR_DEFAULT;
737 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
738
739 if ( (lfrMode == LFR_MODE_STANDBY) | (lfrMode == LFR_MODE_BURST) | (lfrMode == LFR_MODE_SBM2) ) {
740 send_tm_lfr_tc_exe_not_executable( TC );
741 result = LFR_DEFAULT;
742 }
743 else {
744 send_tm_lfr_tc_exe_not_implemented( TC );
745 result = LFR_DEFAULT;
746 }
747 return result;
748 }
749
750 int action_disable_calibration(ccsdsTelecommandPacket_t *TC)
751 {
752 int result;
753 unsigned char lfrMode;
754
755 result = LFR_DEFAULT;
756 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
757
758 if ( (lfrMode == LFR_MODE_STANDBY) | (lfrMode == LFR_MODE_BURST) | (lfrMode == LFR_MODE_SBM2) ) {
759 send_tm_lfr_tc_exe_not_executable( TC );
760 result = LFR_DEFAULT;
761 }
762 else {
763 send_tm_lfr_tc_exe_not_implemented( TC );
764 result = LFR_DEFAULT;
765 }
766 return result;
767 }
768
769 int action_updt_time(ccsdsTelecommandPacket_t *TC)
770 {
771 unsigned int val;
671
772
672 //*****
773 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
673 // SBM1
774 + (TC->dataAndCRC[1] << 16)
674 case(LFR_MODE_SBM1):
775 + (TC->dataAndCRC[2] << 8)
675 status = enter_sbm1_mode();
776 + TC->dataAndCRC[3];
676 if (status == RTEMS_SUCCESSFUL)
777 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
677 {
778 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
678 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_SBM1 << 4) + 0x0d);
779 val++;
679 }
780 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
680 break;
781 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
782 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
783
784 return LFR_SUCCESSFUL;
785 }
786
787 //*******************
788 // ENTERING THE MODES
789
790 int transition_validation(unsigned char requestedMode)
791 {
792 int status;
793 unsigned char lfrMode;
794
795 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
681
796
682 //*****
797 switch (requestedMode)
683 // SBM2
798 {
684 case(LFR_MODE_SBM2):
799 case LFR_MODE_STANDBY:
685 status = enter_sbm2_mode();
800 if ( (lfrMode == LFR_MODE_STANDBY) ) {
686 if (status == RTEMS_SUCCESSFUL)
801 status = LFR_DEFAULT;
687 {
802 }
688 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_SBM2 << 4) + 0x0d);
803 else
689 }
804 {
690 break;
805 status = LFR_SUCCESSFUL;
806 }
807 break;
808 case LFR_MODE_NORMAL:
809 if ( (lfrMode == LFR_MODE_NORMAL) ) {
810 status = LFR_DEFAULT;
811 }
812 else {
813 status = LFR_SUCCESSFUL;
814 }
815 break;
816 case LFR_MODE_BURST:
817 if ( (lfrMode == LFR_MODE_STANDBY) | (lfrMode == LFR_MODE_BURST)
818 | (lfrMode == LFR_MODE_SBM2) ) {
819 status = LFR_DEFAULT;
820 }
821 else {
822 status = LFR_SUCCESSFUL;
823 }
824 break;
825 case LFR_MODE_SBM1:
826 if ( (lfrMode == LFR_MODE_STANDBY) | (lfrMode == LFR_MODE_SBM1) ) {
827 status = LFR_DEFAULT;
828 }
829 else {
830 status = LFR_SUCCESSFUL;
831 }
832 break;
833 case LFR_MODE_SBM2:
834 if ( (lfrMode == LFR_MODE_STANDBY) | (lfrMode == LFR_MODE_NORMAL)
835 | (lfrMode == LFR_MODE_BURST) | (lfrMode == LFR_MODE_SBM2) ) {
836 status = LFR_DEFAULT;
837 }
838 else {
839 status = LFR_SUCCESSFUL;
840 }
841 break;
842 default:
843 status = LFR_DEFAULT;
844 break;
845 }
691
846
692 //********
693 // DEFAULT
694 default:
695 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((LFR_MODE_STANDBY << 4) + 0x0d);
696 break;
697 }
698 return status;
847 return status;
699 }
848 }
700
849
701 int stop_current_mode()
850 int stop_current_mode()
702 {
851 {
703 rtems_status_code status;
852 rtems_status_code status;
853 unsigned char lfrMode;
854
855 status = RTEMS_SUCCESSFUL;
856 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; // get the current mode
704
857
705 // mask all IRQ lines related to signal processing
858 // mask all IRQ lines related to signal processing
706 LEON_Mask_interrupt( IRQ_WF ); // mask waveform interrupt (coming from the timer VHDL IP)
859 LEON_Mask_interrupt( IRQ_WF ); // mask waveform interrupt (coming from the timer VHDL IP)
@@ -714,12 +867,14 int stop_current_mode()
714
867
715 // suspend several tasks
868 // suspend several tasks
716
869
717 status = rtems_task_suspend( Task_id[TASKID_AVF0] );
870 if (lfrMode != LFR_MODE_STANDBY) {
718 if (status == RTEMS_SUCCESSFUL) {
871 status = rtems_task_suspend( Task_id[TASKID_AVF0] );
719 status = rtems_task_suspend( Task_id[TASKID_BPF0] );
872 if (status == RTEMS_SUCCESSFUL) {
720 if (status == RTEMS_SUCCESSFUL) {
873 status = rtems_task_suspend( Task_id[TASKID_BPF0] );
721 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
874 if (status == RTEMS_SUCCESSFUL) {
722 }
875 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
876 }
877 }
723 }
878 }
724
879
725 if (status != RTEMS_SUCCESSFUL)
880 if (status != RTEMS_SUCCESSFUL)
@@ -733,59 +888,44 int stop_current_mode()
733 return status;
888 return status;
734 }
889 }
735
890
736 int enter_normal_mode()
891 int enter_mode(unsigned char mode, ccsdsTelecommandPacket_t *TC )
737 {
892 {
738 rtems_status_code status;
893 rtems_status_code status;
739
894
740 status = rtems_task_restart( Task_id[TASKID_AVF0], 0 );
895 switch(mode){
741 if (status == RTEMS_SUCCESSFUL) {
896 case LFR_MODE_STANDBY:
742 status = rtems_task_restart( Task_id[TASKID_BPF0], 0 );
897 status = enter_standby_mode( TC );
743 if (status == RTEMS_SUCCESSFUL) {
898 break;
744 status = rtems_task_restart( Task_id[TASKID_WFRM], 0 );
899 case LFR_MODE_NORMAL:
745 }
900 status = enter_normal_mode( TC );
901 break;
902 case LFR_MODE_BURST:
903 status = enter_burst_mode( TC );
904 break;
905 case LFR_MODE_SBM1:
906 status = enter_sbm1_mode( TC );
907 break;
908 case LFR_MODE_SBM2:
909 status = enter_sbm2_mode( TC );
910 break;
911 default:
912 status = RTEMS_UNSATISFIED;
746 }
913 }
747
914
748 #ifdef GSA
915 if (status == RTEMS_SUCCESSFUL)
749 LEON_Unmask_interrupt( IRQ_WF );
916 {
750 #else
917 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d);
751 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
918 }
752 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
753 waveform_picker_regs->burst_enable = 0x07;
754 waveform_picker_regs->addr_data_f1 = (int) wf_snap_f1;
755 waveform_picker_regs->status = 0x00;
756 #endif
757 LEON_Unmask_interrupt( IRQ_SM );
758
919
759 return status;
920 return status;
760 }
921 }
761
922
762 int enter_burst_mode()
923 int enter_standby_mode(ccsdsTelecommandPacket_t *TC)
763 {
924 {
764 rtems_status_code status;
925 return LFR_SUCCESSFUL;
765
766 status = rtems_task_restart( Task_id[TASKID_AVF0], 0 );
767 if (status == RTEMS_SUCCESSFUL) {
768 status = rtems_task_restart( Task_id[TASKID_BPF0], 0 );
769 if (status == RTEMS_SUCCESSFUL) {
770 status = rtems_task_restart( Task_id[TASKID_WFRM], 0 );
771 }
772 }
773
774 #ifdef GSA
775 #else
776 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
777 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
778 waveform_picker_regs->addr_data_f2 = (int) wf_snap_f2;
779 waveform_picker_regs->burst_enable = 0x40; // [0100 0000] burst f2, f1, f0 enable f3 f2 f1 f0
780 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x04;
781 waveform_picker_regs->status = 0x00;
782 #endif
783
784 LEON_Unmask_interrupt( IRQ_SM );
785 return status;
786 }
926 }
787
927
788 int enter_sbm1_mode()
928 int enter_normal_mode( ccsdsTelecommandPacket_t *TC )
789 {
929 {
790 rtems_status_code status;
930 rtems_status_code status;
791
931
@@ -798,20 +938,50 int enter_sbm1_mode()
798 }
938 }
799
939
800 #ifdef GSA
940 #ifdef GSA
941 LEON_Unmask_interrupt( IRQ_WF );
801 #else
942 #else
802 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
943 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
803 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
944 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
804 waveform_picker_regs->addr_data_f1 = (int) wf_snap_f1;
945 waveform_picker_regs->burst_enable = 0x07;
805 waveform_picker_regs->burst_enable = 0x20; // [0010 0000] burst f2, f1, f0 enable f3 f2 f1 f0
946 waveform_picker_regs->addr_data_f1 = (int) wf_snap_f1;
806 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x02;
947 waveform_picker_regs->status = 0x00;
807 waveform_picker_regs->status = 0x00;
948 #endif
949 LEON_Unmask_interrupt( IRQ_SM );
950
951 return status;
952 }
953
954 int enter_burst_mode(ccsdsTelecommandPacket_t *TC)
955 {
956 rtems_status_code status;
957 unsigned char lfrMode;
958
959 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
960
961 status = rtems_task_restart( Task_id[TASKID_AVF0], 0 );
962 if (status == RTEMS_SUCCESSFUL) {
963 status = rtems_task_restart( Task_id[TASKID_BPF0], 0 );
964 if (status == RTEMS_SUCCESSFUL) {
965 status = rtems_task_restart( Task_id[TASKID_WFRM], 0 );
966 }
967 }
968
969 #ifdef GSA
970 #else
971 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
972 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
973 waveform_picker_regs->addr_data_f2 = (int) wf_snap_f2;
974 waveform_picker_regs->burst_enable = 0x40; // [0100 0000] burst f2, f1, f0 enable f3 f2 f1 f0
975 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x04;
976 waveform_picker_regs->status = 0x00;
808 #endif
977 #endif
809
978
810 LEON_Unmask_interrupt( IRQ_SM );
979 LEON_Unmask_interrupt( IRQ_SM );
980
811 return status;
981 return status;
812 }
982 }
813
983
814 int enter_sbm2_mode()
984 int enter_sbm1_mode(ccsdsTelecommandPacket_t *TC)
815 {
985 {
816 rtems_status_code status;
986 rtems_status_code status;
817
987
@@ -823,6 +993,39 int enter_sbm2_mode()
823 }
993 }
824 }
994 }
825
995
996 // at the beginning of the mode, the parameter local_sbm1_nb_cwf_max has a specific value
997 param_local.local_sbm1_nb_cwf_max = 2 * param_norm.sy_lfr_n_swf_p / 4;
998
999 #ifdef GSA
1000 #else
1001 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1002 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1003 waveform_picker_regs->addr_data_f1 = (int) wf_snap_f1;
1004 waveform_picker_regs->burst_enable = 0x20; // [0010 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1005 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x07; // [0111] enable f3 f2 f1 f0
1006 waveform_picker_regs->status = 0x00;
1007 #endif
1008
1009 LEON_Unmask_interrupt( IRQ_SM );
1010
1011 return status;
1012 }
1013
1014 int enter_sbm2_mode(ccsdsTelecommandPacket_t *TC)
1015 {
1016 rtems_status_code status;
1017
1018 status = rtems_task_restart( Task_id[TASKID_AVF0], 0 );
1019 if (status == RTEMS_SUCCESSFUL) {
1020 status = rtems_task_restart( Task_id[TASKID_BPF0], 0 );
1021 if (status == RTEMS_SUCCESSFUL) {
1022 status = rtems_task_restart( Task_id[TASKID_WFRM], 0 );
1023 }
1024 }
1025
1026 // at the beginning of the mode, the parameter local_sbm2_nb_cwf_max has a specific value
1027 param_local.local_sbm1_nb_cwf_max = param_norm.sy_lfr_n_swf_p / 16;
1028
826 #ifdef GSA
1029 #ifdef GSA
827 #else
1030 #else
828 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1031 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
@@ -834,48 +1037,23 int enter_sbm2_mode()
834 #endif
1037 #endif
835
1038
836 LEON_Unmask_interrupt( IRQ_SM );
1039 LEON_Unmask_interrupt( IRQ_SM );
1040
837 return status;
1041 return status;
838 }
1042 }
839
1043
840 int action_load_norm(ccsdsTelecommandPacket_t *TC)
1044 //****************
841 {
1045 // CLOSING ACTIONS
842 param_norm.sy_lfr_n_swf_l = (TC->dataAndCRC[0] * 256) + TC->dataAndCRC[1];
843 param_norm.sy_lfr_n_swf_p = (TC->dataAndCRC[2] * 256) + TC->dataAndCRC[3];
844 param_norm.sy_lfr_n_asm_p = (TC->dataAndCRC[4] * 256) + TC->dataAndCRC[5];
845 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
846 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
847
848 return LFR_SUCCESSFUL;
849 }
850
851 int action_load_comm(ccsdsTelecommandPacket_t *TC)
852 {
853 param_common.sy_lfr_common0 = TC->dataAndCRC[0];
854 param_common.sy_lfr_common1 = TC->dataAndCRC[1];
855
856 set_data_shaping_parameters(param_common.sy_lfr_common1);
857
858 return LFR_SUCCESSFUL;
859 }
860
861 int action_updt_time(ccsdsTelecommandPacket_t *TC)
862 {
863 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
864 + (TC->dataAndCRC[1] << 16)
865 + (TC->dataAndCRC[2] << 8)
866 + TC->dataAndCRC[3];
867 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
868 return 0;
869 }
870
1046
871 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
1047 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
872 {
1048 {
1049 rtems_status_code status;
873 TMHeader_t TM_header;
1050 TMHeader_t TM_header;
874 char data[4];
1051 char data[4];
875 spw_ioctl_pkt_send spw_ioctl_send;
1052 spw_ioctl_pkt_send spw_ioctl_send;
876
1053
877 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
1054 TM_build_header( TM_LFR_TC_EXE_OK, PACKET_LENGTH_TC_EXE_SUCCESS,
878 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
1055 &TM_header,
1056 TC->sourceID); // TC source ID
879
1057
880 data[0] = TC->packetID[0];
1058 data[0] = TC->packetID[0];
881 data[1] = TC->packetID[1];
1059 data[1] = TC->packetID[1];
@@ -883,15 +1061,84 int send_tm_lfr_tc_exe_success(ccsdsTele
883 data[3] = TC->packetSequenceControl[1];
1061 data[3] = TC->packetSequenceControl[1];
884
1062
885 // filling the structure for the spacewire transmission
1063 // filling the structure for the spacewire transmission
886 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
1064 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
887 spw_ioctl_send.hdr = (char*) &TM_header;
1065 spw_ioctl_send.hdr = (char*) &TM_header;
888 spw_ioctl_send.dlen = 3;
1066 spw_ioctl_send.dlen = 4;
889 spw_ioctl_send.data = data;
1067 spw_ioctl_send.data = data;
1068 spw_ioctl_send.options = 0;
890
1069
891 // SEND DATA
1070 // SEND DATA
892 write_spw(&spw_ioctl_send);
1071 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send );
1072
1073 return LFR_SUCCESSFUL;
1074 }
1075
1076 int send_tm_lfr_tc_exe_not_executable(ccsdsTelecommandPacket_t *TC)
1077 {
1078 rtems_status_code status;
1079 TMHeader_t TM_header;
1080 char data[10];
1081 spw_ioctl_pkt_send spw_ioctl_send;
1082
1083 TM_build_header( TM_LFR_TC_EXE_ERR, PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE,
1084 &TM_header,
1085 TC->sourceID); // TC source ID
1086
1087 data[0] = (char) (FAILURE_CODE_NOT_EXECUTABLE >> 8);
1088 data[1] = (char) FAILURE_CODE_NOT_EXECUTABLE;
1089 data[2] = TC->packetID[0];
1090 data[3] = TC->packetID[1];
1091 data[4] = TC->packetSequenceControl[0];
1092 data[5] = TC->packetSequenceControl[1];
1093 data[6] = TC->serviceType; // type of the rejected TC
1094 data[7] = TC->serviceSubType; // subtype of the rejected TC
1095 data[8] = housekeeping_packet.lfr_status_word[0];
1096 data[6] = housekeeping_packet.lfr_status_word[1];
1097
1098 // filling the structure for the spacewire transmission
1099 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
1100 spw_ioctl_send.hdr = (char*) &TM_header;
1101 spw_ioctl_send.dlen = 10;
1102 spw_ioctl_send.data = data;
1103 spw_ioctl_send.options = 0;
893
1104
894 return 0;
1105 // SEND DATA
1106 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send );
1107
1108 return LFR_SUCCESSFUL;
1109 }
1110
1111 int send_tm_lfr_tc_exe_not_implemented(ccsdsTelecommandPacket_t *TC)
1112 {
1113 rtems_status_code status;
1114 TMHeader_t TM_header;
1115 char data[8];
1116 spw_ioctl_pkt_send spw_ioctl_send;
1117
1118 TM_build_header( TM_LFR_TC_EXE_ERR, PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED,
1119 &TM_header,
1120 TC->sourceID); // TC source ID
1121
1122 data[0] = (char) (FAILURE_CODE_NOT_IMPLEMENTED >> 8);
1123 data[1] = (char) FAILURE_CODE_NOT_IMPLEMENTED;
1124 data[2] = TC->packetID[0];
1125 data[3] = TC->packetID[1];
1126 data[4] = TC->packetSequenceControl[0];
1127 data[5] = TC->packetSequenceControl[1];
1128 data[6] = TC->serviceType; // type of the rejected TC
1129 data[7] = TC->serviceSubType; // subtype of the rejected TC
1130
1131 // filling the structure for the spacewire transmission
1132 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
1133 spw_ioctl_send.hdr = (char*) &TM_header;
1134 spw_ioctl_send.dlen = 8;
1135 spw_ioctl_send.data = data;
1136 spw_ioctl_send.options = 0;
1137
1138 // SEND DATA
1139 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send );
1140
1141 return LFR_SUCCESSFUL;
895 }
1142 }
896
1143
897 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC)
1144 void update_last_TC_exe(ccsdsTelecommandPacket_t *TC)
@@ -899,9 +1146,9 void update_last_TC_exe(ccsdsTelecommand
899 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1146 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
900 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1147 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
901 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1148 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
902 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->dataFieldHeader[1];
1149 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
903 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1150 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
904 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->dataFieldHeader[2];
1151 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
905 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1152 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
906 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1153 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
907 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1154 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
@@ -915,9 +1162,9 void update_last_TC_rej(ccsdsTelecommand
915 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1162 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
916 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1163 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
917 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1164 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
918 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->dataFieldHeader[1];
1165 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
919 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1166 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
920 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->dataFieldHeader[2];
1167 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
921 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1168 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
922 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1169 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
923 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1170 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
This diff has been collapsed as it changes many lines, (552 lines changed) Show them Hide them
@@ -39,33 +39,6 rtems_isr waveforms_isr( rtems_vector_nu
39 //******
39 //******
40 // BURST
40 // BURST
41 case(LFR_MODE_BURST):
41 case(LFR_MODE_BURST):
42 break;
43
44 //*****
45 // SBM1
46 case(LFR_MODE_SBM1):
47 #ifdef GSA
48 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
49 #else
50 if (waveform_picker_regs->burst_enable == 0x22) {
51 if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
52 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_bis);
53 }
54 else {
55 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1);
56 }
57 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) {
58 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
59 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
60 }
61 }
62 waveform_picker_regs->status = 0x00;
63 #endif
64 break;
65
66 //*****
67 // SBM2
68 case(LFR_MODE_SBM2):
69 #ifdef GSA
42 #ifdef GSA
70 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
43 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
71 #else
44 #else
@@ -76,7 +49,7 rtems_isr waveforms_isr( rtems_vector_nu
76 else {
49 else {
77 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
50 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
78 }
51 }
79 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
52 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
80 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
53 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
81 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
54 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
82 }
55 }
@@ -85,6 +58,70 rtems_isr waveforms_isr( rtems_vector_nu
85 #endif
58 #endif
86 break;
59 break;
87
60
61 //*****
62 // SBM1
63 case(LFR_MODE_SBM1):
64 #ifdef GSA
65 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
66 #else
67 if ((waveform_picker_regs->status & 0x02) == 0x02){ // check the f1 full bit
68 // (1) change the receiving buffer for the waveform picker
69 if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
70 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_bis);
71 }
72 else {
73 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1);
74 }
75 // (2) send an event for the waveforms transmission
76 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) {
77 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
78 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
79 }
80 waveform_picker_regs->status = waveform_picker_regs->status & 0x000d; // reset the f1 full bit to 0
81 }
82 if ( ( (waveform_picker_regs->status & 0x05) == 0x05 ) ) { // [0101] f3 f2 f1 f0, check the f2 and f0 full bit
83 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
84 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
85 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
86 }
87 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x05; // [0101] // enable f2 and f0
88 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffaaa; // set to 0 the bits related to f2 and f0
89 }
90 #endif
91 break;
92
93 //*****
94 // SBM2
95 case(LFR_MODE_SBM2):
96 #ifdef GSA
97 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
98 #else
99 if ((waveform_picker_regs->status & 0x04) == 0x04){ // check the f2 full bit
100 // (1) change the receiving buffer for the waveform picker
101 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
102 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_bis);
103 }
104 else {
105 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
106 }
107 // (2) send an event for the waveforms transmission
108 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
109 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
110 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
111 }
112 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1011]
113 }
114 if ( ( (waveform_picker_regs->status & 0x03) == 0x03 ) ) { // [0011] f3 f2 f1 f0, check the f2 and f0 full bit
115 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
116 PRINTF("in waveforms_isr *** Error sending event to WFRM\n")
117 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
118 }
119 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x03; // [0011] // enable f2 and f0
120 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffccc; // set to 0 the bits related to f1 and f0
121 }
122 #endif
123 break;
124
88 //********
125 //********
89 // DEFAULT
126 // DEFAULT
90 default:
127 default:
@@ -136,35 +173,25 rtems_isr waveforms_simulator_isr( rtems
136
173
137 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
174 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
138 {
175 {
139 spw_ioctl_pkt_send spw_ioctl_send;
176 unsigned int i;
177 unsigned int intEventOut;
178 spw_ioctl_pkt_send spw_ioctl_send_SWF;
179 spw_ioctl_pkt_send spw_ioctl_send_CWF;
140 rtems_event_set event_out;
180 rtems_event_set event_out;
141 ExtendedTMHeader_t header;
181 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
182 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
142
183
143 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
184 init_header_snapshot_wf( &headerSWF );
144 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
185 init_header_continuous_wf( &headerCWF );
145 header.reserved = 0x00;
146 header.userApplication = CCSDS_USER_APP;
147 header.packetID[0] = 0x0c;
148 header.packetID[1] = 0xcc;
149 header.packetSequenceControl[0] = 0x00;
150 header.packetSequenceControl[1] = 0x00;
151 header.packetLength[0] = 0x00;
152 header.packetLength[1] = 0x00;
153 header.dataFieldHeader[0] = 0x10;
154 header.dataFieldHeader[1] = TM_TYPE_LFR_SCIENCE; // service type
155 header.dataFieldHeader[2] = TM_SUBTYPE_LFR_SCIENCE; // service subtype
156 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
157
186
158 header.auxiliaryHeader[0] = 0x00;
187 // BUILD THE PACKET HEADERS
159 header.auxiliaryHeader[1] = 0x1f;
188 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
160 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
189 spw_ioctl_send_SWF.hdr = (char*) &headerSWF;
161 header.auxiliaryHeader[3] = 0x00; // PKT_NR
190 spw_ioctl_send_SWF.options = 0;
162 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
163 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
164
191
165 // BUILD THE PACKET HEADER
192 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
166 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
193 spw_ioctl_send_CWF.hdr = (char*) &headerCWF;
167 spw_ioctl_send.hdr = (char*) &header;
194 spw_ioctl_send_CWF.options = 0;
168
195
169 init_waveforms();
196 init_waveforms();
170
197
@@ -174,69 +201,46 rtems_task wfrm_task(rtems_task_argument
174 // wait for an RTEMS_EVENT
201 // wait for an RTEMS_EVENT
175 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4,
202 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | RTEMS_EVENT_4,
176 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
203 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
177 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
204 intEventOut = (unsigned int) event_out;
178 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
205 for (i = 0; i< 5; i++) {
179 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
206 if ( ( (intEventOut >> i) & 0x0001) != 0 ) {
180 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
207 switch(i) {
181 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
208 case(LFR_MODE_NORMAL):
182 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
209 send_waveform_norm( &headerSWF, &spw_ioctl_send_SWF);
183
210 break;
184 switch(event_out)
211 case(LFR_MODE_BURST):
185 {
212 send_waveform_burst( &headerCWF, &spw_ioctl_send_CWF);
186 //********
213 break;
187 // STANDBY
214 case(LFR_MODE_SBM1):
188 case(RTEMS_EVENT_MODE_STANDBY):
215 send_waveform_sbm1( &headerCWF, &spw_ioctl_send_CWF);
189 break;
216 param_local.local_sbm1_nb_cwf_sent ++;
190
217 if ( param_local.local_sbm1_nb_cwf_sent == (param_local.local_sbm1_nb_cwf_max-1) ) {
191 //*******
218 // send the f1 buffer as a NORM snapshot
192 // NORMAL
219 if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
193 case(RTEMS_EVENT_MODE_NORMAL):
220 send_waveform_SWF( &headerSWF, wf_snap_f1_bis, SID_NORM_SWF_F1, &spw_ioctl_send_SWF );
194 //***************
221 }
195 // send snapshots
222 else {
196 // F0
223 send_waveform_SWF( &headerSWF, wf_snap_f1, SID_NORM_SWF_F1, &spw_ioctl_send_SWF );
197 send_waveform( &header, wf_snap_f0, SID_NORM_SWF_F0, &spw_ioctl_send);
224 }
198 // F1
225 }
199 send_waveform( &header, wf_snap_f1, SID_NORM_SWF_F1, &spw_ioctl_send);
226 break;
200 // F2
227 case(LFR_MODE_SBM2):
201 send_waveform( &header, wf_snap_f2, SID_NORM_SWF_F2, &spw_ioctl_send);
228 send_waveform_sbm2( &headerCWF, &spw_ioctl_send_CWF);
202 #ifdef GSA
229 param_local.local_sbm2_nb_cwf_sent ++;
203 // irq processed, reset the related register of the timer unit
230 if ( param_local.local_sbm2_nb_cwf_sent == (param_local.local_sbm2_nb_cwf_max-1) ) {
204 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
231 // send the f2 buffer as a NORM snapshot
205 #else
232 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
206 // irq processed, reset the related register of the waveform picker
233 send_waveform_SWF( &headerSWF, wf_snap_f2_bis, SID_NORM_SWF_F2, &spw_ioctl_send_SWF );
207 waveform_picker_regs->status = 0x00;
234 }
208 waveform_picker_regs->burst_enable = 0x07;
235 else {
209 #endif
236 send_waveform_SWF( &headerSWF, wf_snap_f2, SID_NORM_SWF_F2, &spw_ioctl_send_SWF );
210 break;
237 }
211
238 }
212 //*****
239 break;
213 // SBM1
240 default:
214 case(RTEMS_EVENT_MODE_SBM1):
241 break;
215 // F1
216 if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
217 send_waveform( &header, wf_snap_f1_bis, SID_NORM_SWF_F1, &spw_ioctl_send);
218 }
242 }
219 else {
243 }
220 send_waveform( &header, wf_snap_f1, SID_NORM_SWF_F1, &spw_ioctl_send);
221 }
222 break;
223
224 //*****
225 // SBM2
226 case(RTEMS_EVENT_MODE_SBM2):
227 // F2
228 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
229 send_waveform( &header, wf_snap_f2_bis, SID_NORM_SWF_F2, &spw_ioctl_send);
230 }
231 else {
232 send_waveform( &header, wf_snap_f2, SID_NORM_SWF_F2, &spw_ioctl_send);
233 }
234 break;
235
236 //********
237 // DEFAULT
238 default:
239 break;
240 }
244 }
241 }
245 }
242 }
246 }
@@ -275,30 +279,66 void init_waveforms( void )
275 }
279 }
276 }
280 }
277
281
278 void init_waveform_header( ExtendedTMHeader_t * header, unsigned int sid )
282 void init_header_snapshot_wf( Header_TM_LFR_SCIENCE_SWF_t *header)
279 {
283 {
280
281 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
284 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
282 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
285 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
283 header->reserved = 0x00;
286 header->reserved = 0x00;
284 header->userApplication = CCSDS_USER_APP;
287 header->userApplication = CCSDS_USER_APP;
285 header->packetID[0] = 0x0c;
288 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL >> 8);
286 header->packetID[1] = 0xcc;
289 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL);
287 header->packetSequenceControl[0] = 0x00;
290 header->packetSequenceControl[0] = 0xc0;
288 header->packetSequenceControl[1] = 0x00;
291 header->packetSequenceControl[1] = 0x00;
289 header->packetLength[0] = 0x00;
292 header->packetLength[0] = 0x00;
290 header->packetLength[1] = 0x00;
293 header->packetLength[1] = 0x00;
291 header->dataFieldHeader[0] = 0x10;
294 // DATA FIELD HEADER
292 header->dataFieldHeader[1] = TM_TYPE_LFR_SCIENCE; // service type
295 header->spare1_pusVersion_spare2 = 0x10;
293 header->dataFieldHeader[2] = TM_SUBTYPE_LFR_SCIENCE; // service subtype
296 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
294 header->dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
297 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
298 header->destinationID = TM_DESTINATION_ID_GROUND;
299 // AUXILIARY DATA HEADER
300 header->sid = 0x00;
301 header->hkBIA = 0x1f;
302 header->pktCnt = 0x07; // PKT_CNT
303 header->pktNr = 0x00; // PKT_NR
304 header->time[0] = 0x00;
305 header->time[0] = 0x00;
306 header->time[0] = 0x00;
307 header->time[0] = 0x00;
308 header->time[0] = 0x00;
309 header->time[0] = 0x00;
310 header->blkNr[0] = 0x00; // BLK_NR MSB
311 header->blkNr[1] = 0x00; // BLK_NR LSB
312 }
295
313
296 header->auxiliaryHeader[0] = sid;
314 void init_header_continuous_wf( Header_TM_LFR_SCIENCE_CWF_t *header)
297 header->auxiliaryHeader[1] = 0x1f;
315 {
298 header->auxiliaryHeader[2] = 0x07; // PKT_CNT
316 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
299 header->auxiliaryHeader[3] = 0x00; // PKT_NR
317 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
300 header->auxiliaryHeader[4] = 0x00; // BLK_NR MSB
318 header->reserved = 0x00;
301 header->auxiliaryHeader[5] = 0x00; // BLK_NR LSB
319 header->userApplication = CCSDS_USER_APP;
320 header->packetID[0] = 0x00;
321 header->packetID[1] = 0x00;
322 header->packetSequenceControl[0] = 0xc0;
323 header->packetSequenceControl[1] = 0x00;
324 header->packetLength[0] = 0x00;
325 header->packetLength[1] = 0x00;
326 // DATA FIELD HEADER
327 header->spare1_pusVersion_spare2 = 0x10;
328 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
329 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
330 header->destinationID = TM_DESTINATION_ID_GROUND;
331 // AUXILIARY DATA HEADER
332 header->sid = 0x00;
333 header->hkBIA = 0x1f;
334 header->time[0] = 0x00;
335 header->time[0] = 0x00;
336 header->time[0] = 0x00;
337 header->time[0] = 0x00;
338 header->time[0] = 0x00;
339 header->time[0] = 0x00;
340 header->blkNr[0] = 0x00; // BLK_NR MSB
341 header->blkNr[1] = 0x00; // BLK_NR LSB
302 }
342 }
303
343
304 void reset_waveforms( void )
344 void reset_waveforms( void )
@@ -331,45 +371,89 void reset_waveforms( void )
331 }
371 }
332 }
372 }
333
373
334 void send_waveform( ExtendedTMHeader_t *header, volatile int *waveform,
374 void send_waveform_SWF( Header_TM_LFR_SCIENCE_SWF_t *header, volatile int *waveform,
335 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send)
375 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send)
336 {
376 {
337 unsigned int i = 0;
377 unsigned int i = 0;
338 unsigned int length = 0;
378 unsigned int length = 0;
339 rtems_status_code status;
379 rtems_status_code status;
340
380
381 header->sid = (unsigned char) sid;
382
341 for (i=0; i<7; i++) // send waveform
383 for (i=0; i<7; i++) // send waveform
342 {
384 {
343 header->auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
385 header->pktNr = (unsigned char) i+1; // PKT_NR
344 // BUILD THE DATA
386 // BUILD THE DATA
345 if (i==6) {
387 if (i==6) {
346 spw_ioctl_send->dlen = 8 * NB_BYTES_SWF_BLK;
388 spw_ioctl_send->dlen = 8 * NB_BYTES_SWF_BLK;
347 length = TM_LEN_SCI_NORM_SWF_8;
389 length = TM_LEN_SCI_SWF_8;
348 header->auxiliaryHeader[4] = 0x00; // BLK_NR MSB
390 header->blkNr[0] = 0x00; // BLK_NR MSB
349 header->auxiliaryHeader[5] = 0x08; // BLK_NR LSB
391 header->blkNr[1] = 0x08; // BLK_NR LSB
350 }
392 }
351 else {
393 else {
352 spw_ioctl_send->dlen = 340 * NB_BYTES_SWF_BLK;
394 spw_ioctl_send->dlen = 340 * NB_BYTES_SWF_BLK;
353 length = TM_LEN_SCI_NORM_SWF_340;
395 length = TM_LEN_SCI_SWF_340;
354 header->auxiliaryHeader[4] = 0x01; // BLK_NR MSB
396 header->blkNr[0] = 0x01; // BLK_NR MSB
355 header->auxiliaryHeader[5] = 0x54; // BLK_NR LSB
397 header->blkNr[1] = 0x54; // BLK_NR LSB
356 }
357 if (sid == SID_NORM_SWF_F0) {
358 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (1 * TIME_OFFSET) ];
359 }
398 }
360 else if (sid == SID_NORM_SWF_F1) {
399 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
361 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (1 * TIME_OFFSET) ];
362 }
363 else if (sid == SID_NORM_SWF_F2) {
364 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (1 * TIME_OFFSET) ];
365 }
366 else {
367 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
368 }
369 // BUILD THE HEADER
400 // BUILD THE HEADER
370 header->packetLength[0] = (unsigned char) (length>>8);
401 header->packetLength[0] = (unsigned char) (length>>8);
371 header->packetLength[1] = (unsigned char) (length);
402 header->packetLength[1] = (unsigned char) (length);
372 header->auxiliaryHeader[0] = sid; // SID
403 header->sid = (unsigned char) sid; // SID
404 // SET PACKET TIME
405 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
406 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
407 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
408 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
409 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
410 header->time[5] = (unsigned char) (time_management_regs->fine_time);
411 // SEND PACKET
412 status = write_spw(spw_ioctl_send);
413 if (status != RTEMS_SUCCESSFUL) {
414 while (true) {
415 if (status != RTEMS_SUCCESSFUL) {
416 status = write_spw(spw_ioctl_send);
417 //PRINTF1("%d", i)
418 sched_yield();
419 }
420 else {
421 //PRINTF("\n")
422 break;
423 }
424 }
425 }
426 }
427 }
428
429 void send_waveform_CWF( Header_TM_LFR_SCIENCE_CWF_t *header, volatile int *waveform,
430 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send)
431 {
432 unsigned int i = 0;
433 unsigned int length = 0;
434 rtems_status_code status;
435
436 header->sid = (unsigned char) sid;
437
438 for (i=0; i<7; i++) // send waveform
439 {
440 // BUILD THE DATA
441 if (i==6) {
442 spw_ioctl_send->dlen = 8 * NB_BYTES_SWF_BLK;
443 length = TM_LEN_SCI_CWF_8;
444 header->blkNr[0] = 0x00; // BLK_NR MSB
445 header->blkNr[1] = 0x08; // BLK_NR LSB
446 }
447 else {
448 spw_ioctl_send->dlen = 340 * NB_BYTES_SWF_BLK;
449 length = TM_LEN_SCI_CWF_340;
450 header->blkNr[0] = 0x01; // BLK_NR MSB
451 header->blkNr[1] = 0x54; // BLK_NR LSB
452 }
453 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
454 // BUILD THE HEADER
455 header->packetLength[0] = (unsigned char) (length>>8);
456 header->packetLength[1] = (unsigned char) (length);
373 // SEND PACKET
457 // SEND PACKET
374 status = write_spw(spw_ioctl_send);
458 status = write_spw(spw_ioctl_send);
375 if (status != RTEMS_SUCCESSFUL) {
459 if (status != RTEMS_SUCCESSFUL) {
@@ -418,16 +502,156 int build_value(int value1, int value0)
418 return aux;
502 return aux;
419 }
503 }
420
504
421 void init_waveform_picker_regs()
505 void send_waveform_norm(Header_TM_LFR_SCIENCE_SWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send)
506 {
507 unsigned char lfrMode;
508 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
509
510 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL >> 8);
511 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL);
512 // TIME
513 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
514 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
515 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
516 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
517 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
518 header->time[5] = (unsigned char) (time_management_regs->fine_time);
519
520 //***************
521 // send snapshots
522 // F0
523 send_waveform_SWF( header, wf_snap_f0, SID_NORM_SWF_F0, spw_ioctl_send);
524 // F1
525 if (lfrMode == LFR_MODE_NORMAL) // in SBM1 mode, the snapshot is sent by the send_waveform_sbm1 function
526 {
527 send_waveform_SWF( header, wf_snap_f1, SID_NORM_SWF_F1, spw_ioctl_send);
528 }
529 // F2
530 send_waveform_SWF( header, wf_snap_f2, SID_NORM_SWF_F2, spw_ioctl_send);
531 #ifdef GSA
532 // irq processed, reset the related register of the timer unit
533 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
534 #else
535 // irq processed, reset the related register of the waveform picker
536 if (lfrMode == LFR_MODE_SBM1) {
537 param_local.local_sbm1_nb_cwf_sent = 0;
538 // after the first transmission of the swf at F1, the period is set to local_sbm1_nb_cwf_max
539 param_local.local_sbm1_nb_cwf_max = 2 * param_norm.sy_lfr_n_swf_p;
540 }
541 else if (lfrMode == LFR_MODE_SBM2) {
542 param_local.local_sbm2_nb_cwf_sent = 0;
543 // after the first transmission of the swf at F2, the period is set to local_sbm2_nb_cwf_max
544 param_local.local_sbm2_nb_cwf_max = param_norm.sy_lfr_n_swf_p / 8;
545 }
546 else {
547 waveform_picker_regs->status = waveform_picker_regs->status & 0x00;
548 waveform_picker_regs->burst_enable = 0x07; // [0111] enable f2 f1 f0
549 }
550
551 #endif
552 }
553
554 void send_waveform_burst(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send)
422 {
555 {
423 set_data_shaping_parameters(param_common.sy_lfr_common1);
556 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2 >> 8);
557 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2);
558 // TIME
559 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
560 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
561 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
562 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
563 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
564 header->time[5] = (unsigned char) (time_management_regs->fine_time);
565 // ACQUISITION TIME
566
567 // F2
568 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
569 send_waveform_CWF( header, wf_snap_f2_bis, SID_BURST_CWF_F2, spw_ioctl_send);
570 }
571 else {
572 send_waveform_CWF( header, wf_snap_f2, SID_BURST_CWF_F2, spw_ioctl_send);
573 }
574 }
575
576 void send_waveform_sbm1(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send)
577 {
578 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2 >> 8);
579 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2);
580 // TIME
581 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
582 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
583 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
584 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
585 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
586 header->time[5] = (unsigned char) (time_management_regs->fine_time);
587
588 // F1
589 if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
590 send_waveform_CWF( header, wf_snap_f1_bis, SID_SBM1_CWF_F1, spw_ioctl_send );
591 }
592 else {
593 send_waveform_CWF( header, wf_snap_f1, SID_SBM1_CWF_F1, spw_ioctl_send );
594 }
595 }
596
597 void send_waveform_sbm2(Header_TM_LFR_SCIENCE_CWF_t *header, spw_ioctl_pkt_send *spw_ioctl_send)
598 {
599 header->packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2 >> 8);
600 header->packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_BURST_SBM1_SBM2);
601 // TIME
602 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
603 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
604 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
605 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
606 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
607 header->time[5] = (unsigned char) (time_management_regs->fine_time);
608
609 // F2
610 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
611 send_waveform_CWF( header, wf_snap_f2_bis, SID_SBM2_CWF_F2, spw_ioctl_send);
612 }
613 else {
614 send_waveform_CWF( header, wf_snap_f2, SID_SBM2_CWF_F2, spw_ioctl_send);
615 }
616 }
617
618 //**************
619 // wfp registers
620 void set_wfp_data_shaping(unsigned char data_shaping)
621 {
622 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
623 // waveform picker : [R1 R0 SP1 SP0 BW]
624 waveform_picker_regs->data_shaping =
625 ( (data_shaping & 0x10) >> 4 ) // BW
626 + ( (data_shaping & 0x08) >> 2 ) // SP0
627 + ( (data_shaping & 0x04) ) // SP1
628 + ( (data_shaping & 0x02) << 2 ) // R0
629 + ( (data_shaping & 0x01) << 4 ); // R1
630 }
631
632 void set_wfp_delta_snapshot(unsigned int delta_snapshot)
633 {
634 unsigned char aux = 0;
635 aux = delta_snapshot / 2 ;
636 waveform_picker_regs->delta_snapshot = aux; // max 2 bytes
637 //waveform_picker_regs->delta_snapshot = 0x5; // max 2 bytes
638 }
639
640 void reset_wfp_burst_enable()
641 {
424 waveform_picker_regs->burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
642 waveform_picker_regs->burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
425 waveform_picker_regs->addr_data_f0 = (int) (wf_snap_f0); //
643 }
426 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); //
644
427 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); //
645 void reset_wfp_regs()
428 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); //
646 {
647 set_wfp_data_shaping(param_common.sy_lfr_common1);
648 reset_wfp_burst_enable();
649 waveform_picker_regs->addr_data_f0 = (int) (wf_snap_f0); //
650 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); //
651 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); //
652 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); //
429 waveform_picker_regs->status = 0x00; //
653 waveform_picker_regs->status = 0x00; //
430 waveform_picker_regs->delta_snapshot = 0x5; // max 2 bytes
654 set_wfp_delta_snapshot( param_norm.sy_lfr_n_swf_p ); // time in seconds between two snapshots
431 waveform_picker_regs->delta_f2_f1 = 0xffff; // max 4 bytes
655 waveform_picker_regs->delta_f2_f1 = 0xffff; // max 4 bytes
432 waveform_picker_regs->delta_f2_f0 = 0x17c00; // max 5 bytes
656 waveform_picker_regs->delta_f2_f0 = 0x17c00; // max 5 bytes
433 waveform_picker_regs->nb_burst_available = 0x180; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
657 waveform_picker_regs->nb_burst_available = 0x180; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
@@ -438,15 +662,3 void init_waveform_picker_regs()
438 //waveform_picker_regs->nb_burst_available = 0x30; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
662 //waveform_picker_regs->nb_burst_available = 0x30; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
439 //waveform_picker_regs->nb_snapshot_param = 0xff; // max 3 octets, 256 - 1
663 //waveform_picker_regs->nb_snapshot_param = 0xff; // max 3 octets, 256 - 1
440 }
664 }
441
442 void set_data_shaping_parameters(unsigned char parameters)
443 {
444 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
445 // waveform picker : [R1 R0 SP1 SP0 BW]
446 waveform_picker_regs->data_shaping =
447 ( (parameters & 0x10) >> 4 ) // BW
448 + ( (parameters & 0x08) >> 2 ) // SP0
449 + ( (parameters & 0x04) ) // SP1
450 + ( (parameters & 0x02) << 2 ) // R0
451 + ( (parameters & 0x01) << 4 ); // R1
452 }
General Comments 0
You need to be logged in to leave comments. Login now