##// END OF EJS Templates
3.1.0.3...
paul -
r296:fb16b781e584 R3_plus draft
parent child
Show More
@@ -1,125 +1,125
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options =
4 4 # verbose
5 5 # boot_messages
6 6 # debug_messages
7 7 # cpu_usage_report
8 8 # stack_report
9 9 # vhdl_dev
10 10 # debug_tch
11 11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 12 # debug_watchdog
13 13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 14 CONFIG -= qt
15 15
16 16 include(./sparc.pri)
17 17
18 18 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
19 19
20 20 # flight software version
21 21 SWVERSION=-1-0
22 22 DEFINES += SW_VERSION_N1=3 # major
23 23 DEFINES += SW_VERSION_N2=1 # minor
24 24 DEFINES += SW_VERSION_N3=0 # patch
25 DEFINES += SW_VERSION_N4=2 # internal
25 DEFINES += SW_VERSION_N4=3 # internal
26 26
27 27 # <GCOV>
28 28 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
29 29 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
30 30 # </GCOV>
31 31
32 32 # <CHANGE BEFORE FLIGHT>
33 33 contains( CONFIG, lpp_dpu_destid ) {
34 34 DEFINES += LPP_DPU_DESTID
35 35 }
36 36 # </CHANGE BEFORE FLIGHT>
37 37
38 38 contains( CONFIG, debug_tch ) {
39 39 DEFINES += DEBUG_TCH
40 40 }
41 41 DEFINES += MSB_FIRST_TCH
42 42
43 43 contains( CONFIG, vhdl_dev ) {
44 44 DEFINES += VHDL_DEV
45 45 }
46 46
47 47 contains( CONFIG, verbose ) {
48 48 DEFINES += PRINT_MESSAGES_ON_CONSOLE
49 49 }
50 50
51 51 contains( CONFIG, debug_messages ) {
52 52 DEFINES += DEBUG_MESSAGES
53 53 }
54 54
55 55 contains( CONFIG, cpu_usage_report ) {
56 56 DEFINES += PRINT_TASK_STATISTICS
57 57 }
58 58
59 59 contains( CONFIG, stack_report ) {
60 60 DEFINES += PRINT_STACK_REPORT
61 61 }
62 62
63 63 contains( CONFIG, boot_messages ) {
64 64 DEFINES += BOOT_MESSAGES
65 65 }
66 66
67 67 contains( CONFIG, debug_watchdog ) {
68 68 DEFINES += DEBUG_WATCHDOG
69 69 }
70 70
71 71 #doxygen.target = doxygen
72 72 #doxygen.commands = doxygen ../doc/Doxyfile
73 73 #QMAKE_EXTRA_TARGETS += doxygen
74 74
75 75 TARGET = fsw
76 76
77 77 INCLUDEPATH += \
78 78 $${PWD}/../src \
79 79 $${PWD}/../header \
80 80 $${PWD}/../header/lfr_common_headers \
81 81 $${PWD}/../header/processing \
82 82 $${PWD}/../LFR_basic-parameters
83 83
84 84 SOURCES += \
85 85 ../src/wf_handler.c \
86 86 ../src/tc_handler.c \
87 87 ../src/fsw_misc.c \
88 88 ../src/fsw_init.c \
89 89 ../src/fsw_globals.c \
90 90 ../src/fsw_spacewire.c \
91 91 ../src/tc_load_dump_parameters.c \
92 92 ../src/tm_lfr_tc_exe.c \
93 93 ../src/tc_acceptance.c \
94 94 ../src/processing/fsw_processing.c \
95 95 ../src/processing/avf0_prc0.c \
96 96 ../src/processing/avf1_prc1.c \
97 97 ../src/processing/avf2_prc2.c \
98 98 ../src/lfr_cpu_usage_report.c \
99 99 ../LFR_basic-parameters/basic_parameters.c
100 100
101 101 HEADERS += \
102 102 ../header/wf_handler.h \
103 103 ../header/tc_handler.h \
104 104 ../header/grlib_regs.h \
105 105 ../header/fsw_misc.h \
106 106 ../header/fsw_init.h \
107 107 ../header/fsw_spacewire.h \
108 108 ../header/tc_load_dump_parameters.h \
109 109 ../header/tm_lfr_tc_exe.h \
110 110 ../header/tc_acceptance.h \
111 111 ../header/processing/fsw_processing.h \
112 112 ../header/processing/avf0_prc0.h \
113 113 ../header/processing/avf1_prc1.h \
114 114 ../header/processing/avf2_prc2.h \
115 115 ../header/fsw_params_wf_handler.h \
116 116 ../header/lfr_cpu_usage_report.h \
117 117 ../header/lfr_common_headers/ccsds_types.h \
118 118 ../header/lfr_common_headers/fsw_params.h \
119 119 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
120 120 ../header/lfr_common_headers/fsw_params_processing.h \
121 121 ../header/lfr_common_headers/tm_byte_positions.h \
122 122 ../LFR_basic-parameters/basic_parameters.h \
123 123 ../LFR_basic-parameters/basic_parameters_params.h \
124 124 ../header/GscMemoryLPP.hpp
125 125
@@ -1,1599 +1,1599
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 rtems_name semq_name;
17 17 rtems_id semq_id;
18 18
19 19 //*****************
20 20 // waveform headers
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24 24
25 25 unsigned char previousTimecodeCtr = 0;
26 26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27 27
28 28 //***********
29 29 // RTEMS TASK
30 30 rtems_task spiq_task(rtems_task_argument unused)
31 31 {
32 32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 33 *
34 34 * @param unused is the starting argument of the RTEMS task
35 35 *
36 36 */
37 37
38 38 rtems_event_set event_out;
39 39 rtems_status_code status;
40 40 int linkStatus;
41 41
42 42 BOOT_PRINTF("in SPIQ *** \n")
43 43
44 44 while(true){
45 45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47 47
48 48 // [0] SUSPEND RECV AND SEND TASKS
49 49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 50 if ( status != RTEMS_SUCCESSFUL ) {
51 51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 52 }
53 53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 54 if ( status != RTEMS_SUCCESSFUL ) {
55 55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 56 }
57 57
58 58 // [1] CHECK THE LINK
59 59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 60 if ( linkStatus != 5) {
61 61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 63 }
64 64
65 65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
68 68 {
69 69 spacewire_read_statistics();
70 70 status = spacewire_several_connect_attemps( );
71 71 }
72 72 else // [2.b] in run state, start the link
73 73 {
74 74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 75 if ( status != RTEMS_SUCCESSFUL)
76 76 {
77 77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 78 }
79 79 }
80 80
81 81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 83 {
84 84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 85 if ( status != RTEMS_SUCCESSFUL ) {
86 86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 87 }
88 88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 89 if ( status != RTEMS_SUCCESSFUL ) {
90 90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 91 }
92 92 }
93 93 else // [3.b] the link is not in run state, go in STANDBY mode
94 94 {
95 95 status = enter_mode_standby();
96 96 if ( status != RTEMS_SUCCESSFUL )
97 97 {
98 98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 99 }
100 100 {
101 101 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 102 }
103 103 // wake the LINK task up to wait for the link recovery
104 104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 105 status = rtems_task_suspend( RTEMS_SELF );
106 106 }
107 107 }
108 108 }
109 109
110 110 rtems_task recv_task( rtems_task_argument unused )
111 111 {
112 112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 113 *
114 114 * @param unused is the starting argument of the RTEMS task
115 115 *
116 116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 117 * 1. It reads the incoming data.
118 118 * 2. Launches the acceptance procedure.
119 119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 120 *
121 121 */
122 122
123 123 int len;
124 124 ccsdsTelecommandPacket_t currentTC;
125 125 unsigned char computed_CRC[ 2 ];
126 126 unsigned char currentTC_LEN_RCV[ 2 ];
127 127 unsigned char destinationID;
128 128 unsigned int estimatedPacketLength;
129 129 unsigned int parserCode;
130 130 rtems_status_code status;
131 131 rtems_id queue_recv_id;
132 132 rtems_id queue_send_id;
133 133
134 134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135 135
136 136 status = get_message_queue_id_recv( &queue_recv_id );
137 137 if (status != RTEMS_SUCCESSFUL)
138 138 {
139 139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 140 }
141 141
142 142 status = get_message_queue_id_send( &queue_send_id );
143 143 if (status != RTEMS_SUCCESSFUL)
144 144 {
145 145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 146 }
147 147
148 148 BOOT_PRINTF("in RECV *** \n")
149 149
150 150 while(1)
151 151 {
152 152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 153 if (len == -1){ // error during the read call
154 154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 155 }
156 156 else {
157 157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 158 PRINTF("in RECV *** packet lenght too short\n")
159 159 }
160 160 else {
161 PRINTF1("incoming TC with len: %d\n", len);
161 // PRINTF1("incoming TC with len: %d\n", len);
162 162 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
163 163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
164 164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
165 165 // CHECK THE TC
166 166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
167 167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
168 168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
169 169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
170 170 || (parserCode == WRONG_SRC_ID) )
171 171 { // send TM_LFR_TC_EXE_CORRUPTED
172 172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
173 173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
174 174 &&
175 175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
176 176 )
177 177 {
178 178 if ( parserCode == WRONG_SRC_ID )
179 179 {
180 180 destinationID = SID_TC_GROUND;
181 181 }
182 182 else
183 183 {
184 184 destinationID = currentTC.sourceID;
185 185 }
186 186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
187 187 computed_CRC, currentTC_LEN_RCV,
188 188 destinationID );
189 189 }
190 190 }
191 191 else
192 192 { // send valid TC to the action launcher
193 193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
194 194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
195 195 }
196 196 }
197 197 }
198 198
199 199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
200 200
201 201 }
202 202 }
203 203
204 204 rtems_task send_task( rtems_task_argument argument)
205 205 {
206 206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
207 207 *
208 208 * @param unused is the starting argument of the RTEMS task
209 209 *
210 210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
211 211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
212 212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
213 213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
214 214 * data it contains.
215 215 *
216 216 */
217 217
218 218 rtems_status_code status; // RTEMS status code
219 219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
220 220 ring_node *incomingRingNodePtr;
221 221 int ring_node_address;
222 222 char *charPtr;
223 223 spw_ioctl_pkt_send *spw_ioctl_send;
224 224 size_t size; // size of the incoming TC packet
225 225 rtems_id queue_send_id;
226 226 unsigned int sid;
227 227 unsigned char sidAsUnsignedChar;
228 228 unsigned char type;
229 229
230 230 incomingRingNodePtr = NULL;
231 231 ring_node_address = 0;
232 232 charPtr = (char *) &ring_node_address;
233 233 sid = 0;
234 234 sidAsUnsignedChar = 0;
235 235
236 236 init_header_cwf( &headerCWF );
237 237 init_header_swf( &headerSWF );
238 238 init_header_asm( &headerASM );
239 239
240 240 status = get_message_queue_id_send( &queue_send_id );
241 241 if (status != RTEMS_SUCCESSFUL)
242 242 {
243 243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
244 244 }
245 245
246 246 BOOT_PRINTF("in SEND *** \n")
247 247
248 248 while(1)
249 249 {
250 250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
251 251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
252 252
253 253 if (status!=RTEMS_SUCCESSFUL)
254 254 {
255 255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
256 256 }
257 257 else
258 258 {
259 259 if ( size == sizeof(ring_node*) )
260 260 {
261 261 charPtr[0] = incomingData[0];
262 262 charPtr[1] = incomingData[1];
263 263 charPtr[2] = incomingData[2];
264 264 charPtr[3] = incomingData[3];
265 265 incomingRingNodePtr = (ring_node*) ring_node_address;
266 266 sid = incomingRingNodePtr->sid;
267 267 if ( (sid==SID_NORM_CWF_LONG_F3)
268 268 || (sid==SID_BURST_CWF_F2 )
269 269 || (sid==SID_SBM1_CWF_F1 )
270 270 || (sid==SID_SBM2_CWF_F2 ))
271 271 {
272 272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
273 273 }
274 274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
275 275 {
276 276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
277 277 }
278 278 else if ( (sid==SID_NORM_CWF_F3) )
279 279 {
280 280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
281 281 }
282 282 else if (sid==SID_NORM_ASM_F0)
283 283 {
284 284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
285 285 }
286 286 else if (sid==SID_NORM_ASM_F1)
287 287 {
288 288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
289 289 }
290 290 else if (sid==SID_NORM_ASM_F2)
291 291 {
292 292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
293 293 }
294 294 else if ( sid==TM_CODE_K_DUMP )
295 295 {
296 296 spw_send_k_dump( incomingRingNodePtr );
297 297 }
298 298 else
299 299 {
300 300 PRINTF1("unexpected sid = %d\n", sid);
301 301 }
302 302 }
303 303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
304 304 {
305 305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
306 306 sid = sidAsUnsignedChar;
307 307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
308 308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
309 309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
310 310 {
311 311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
312 312 }
313 313
314 314 status = write( fdSPW, incomingData, size );
315 315 if (status == -1){
316 316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
317 317 }
318 318 }
319 319 else // the incoming message is a spw_ioctl_pkt_send structure
320 320 {
321 321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
322 322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
323 323 if (status == -1){
324 324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
325 325 }
326 326 }
327 327 }
328 328
329 329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
330 330
331 331 }
332 332 }
333 333
334 334 rtems_task link_task( rtems_task_argument argument )
335 335 {
336 336 rtems_event_set event_out;
337 337 rtems_status_code status;
338 338 int linkStatus;
339 339
340 340 BOOT_PRINTF("in LINK ***\n")
341 341
342 342 while(1)
343 343 {
344 344 // wait for an RTEMS_EVENT
345 345 rtems_event_receive( RTEMS_EVENT_0,
346 346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
347 347 PRINTF("in LINK *** wait for the link\n")
348 348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
349 349 while( linkStatus != 5) // wait for the link
350 350 {
351 351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
352 352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
353 353 watchdog_reload();
354 354 }
355 355
356 356 spacewire_read_statistics();
357 357 status = spacewire_stop_and_start_link( fdSPW );
358 358
359 359 if (status != RTEMS_SUCCESSFUL)
360 360 {
361 361 PRINTF1("in LINK *** ERR link not started %d\n", status)
362 362 }
363 363 else
364 364 {
365 365 PRINTF("in LINK *** OK link started\n")
366 366 }
367 367
368 368 // restart the SPIQ task
369 369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
370 370 if ( status != RTEMS_SUCCESSFUL ) {
371 371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
372 372 }
373 373
374 374 // restart RECV and SEND
375 375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
376 376 if ( status != RTEMS_SUCCESSFUL ) {
377 377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
378 378 }
379 379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
380 380 if ( status != RTEMS_SUCCESSFUL ) {
381 381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
382 382 }
383 383 }
384 384 }
385 385
386 386 //****************
387 387 // OTHER FUNCTIONS
388 388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
389 389 {
390 390 /** This function opens the SpaceWire link.
391 391 *
392 392 * @return a valid file descriptor in case of success, -1 in case of a failure
393 393 *
394 394 */
395 395 rtems_status_code status;
396 396
397 397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
398 398 if ( fdSPW < 0 ) {
399 399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
400 400 }
401 401 else
402 402 {
403 403 status = RTEMS_SUCCESSFUL;
404 404 }
405 405
406 406 return status;
407 407 }
408 408
409 409 int spacewire_start_link( int fd )
410 410 {
411 411 rtems_status_code status;
412 412
413 413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
414 414 // -1 default hardcoded driver timeout
415 415
416 416 return status;
417 417 }
418 418
419 419 int spacewire_stop_and_start_link( int fd )
420 420 {
421 421 rtems_status_code status;
422 422
423 423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
424 424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
425 425 // -1 default hardcoded driver timeout
426 426
427 427 return status;
428 428 }
429 429
430 430 int spacewire_configure_link( int fd )
431 431 {
432 432 /** This function configures the SpaceWire link.
433 433 *
434 434 * @return GR-RTEMS-DRIVER directive status codes:
435 435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
436 436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
437 437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
438 438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
439 439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
440 440 * - 5 EIO - Error when writing to grswp hardware registers.
441 441 * - 2 ENOENT - No such file or directory
442 442 */
443 443
444 444 rtems_status_code status;
445 445
446 446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
447 447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
448 448
449 449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
450 450 if (status!=RTEMS_SUCCESSFUL) {
451 451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
452 452 }
453 453 //
454 454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
455 455 if (status!=RTEMS_SUCCESSFUL) {
456 456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
457 457 }
458 458 //
459 459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
460 460 if (status!=RTEMS_SUCCESSFUL) {
461 461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
462 462 }
463 463 //
464 464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
465 465 if (status!=RTEMS_SUCCESSFUL) {
466 466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
467 467 }
468 468 //
469 469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
470 470 if (status!=RTEMS_SUCCESSFUL) {
471 471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
472 472 }
473 473 //
474 474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
475 475 if (status!=RTEMS_SUCCESSFUL) {
476 476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
477 477 }
478 478 //
479 479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
480 480 if (status!=RTEMS_SUCCESSFUL) {
481 481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
482 482 }
483 483
484 484 return status;
485 485 }
486 486
487 487 int spacewire_several_connect_attemps( void )
488 488 {
489 489 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
490 490 *
491 491 * @return RTEMS directive status code:
492 492 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
493 493 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
494 494 *
495 495 */
496 496
497 497 rtems_status_code status_spw;
498 498 rtems_status_code status;
499 499 int i;
500 500
501 501 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
502 502 {
503 503 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
504 504
505 505 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
506 506
507 507 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
508 508
509 509 status_spw = spacewire_stop_and_start_link( fdSPW );
510 510
511 511 if ( status_spw != RTEMS_SUCCESSFUL )
512 512 {
513 513 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
514 514 }
515 515
516 516 if ( status_spw == RTEMS_SUCCESSFUL)
517 517 {
518 518 break;
519 519 }
520 520 }
521 521
522 522 return status_spw;
523 523 }
524 524
525 525 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
526 526 {
527 527 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
528 528 *
529 529 * @param val is the value, 0 or 1, used to set the value of the NP bit.
530 530 * @param regAddr is the address of the GRSPW control register.
531 531 *
532 532 * NP is the bit 20 of the GRSPW control register.
533 533 *
534 534 */
535 535
536 536 unsigned int *spwptr = (unsigned int*) regAddr;
537 537
538 538 if (val == 1) {
539 539 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
540 540 }
541 541 if (val== 0) {
542 542 *spwptr = *spwptr & 0xffdfffff;
543 543 }
544 544 }
545 545
546 546 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
547 547 {
548 548 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
549 549 *
550 550 * @param val is the value, 0 or 1, used to set the value of the RE bit.
551 551 * @param regAddr is the address of the GRSPW control register.
552 552 *
553 553 * RE is the bit 16 of the GRSPW control register.
554 554 *
555 555 */
556 556
557 557 unsigned int *spwptr = (unsigned int*) regAddr;
558 558
559 559 if (val == 1)
560 560 {
561 561 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
562 562 }
563 563 if (val== 0)
564 564 {
565 565 *spwptr = *spwptr & 0xfffdffff;
566 566 }
567 567 }
568 568
569 569 void spacewire_read_statistics( void )
570 570 {
571 571 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
572 572 *
573 573 * @param void
574 574 *
575 575 * @return void
576 576 *
577 577 * Once they are read, the counters are stored in a global variable used during the building of the
578 578 * HK packets.
579 579 *
580 580 */
581 581
582 582 rtems_status_code status;
583 583 spw_stats current;
584 584
585 585 spacewire_get_last_error();
586 586
587 587 // read the current statistics
588 588 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
589 589
590 590 // clear the counters
591 591 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
592 592
593 593 // typedef struct {
594 594 // unsigned int tx_link_err; // NOT IN HK
595 595 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
596 596 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
597 597 // unsigned int rx_eep_err;
598 598 // unsigned int rx_truncated;
599 599 // unsigned int parity_err;
600 600 // unsigned int escape_err;
601 601 // unsigned int credit_err;
602 602 // unsigned int write_sync_err;
603 603 // unsigned int disconnect_err;
604 604 // unsigned int early_ep;
605 605 // unsigned int invalid_address;
606 606 // unsigned int packets_sent;
607 607 // unsigned int packets_received;
608 608 // } spw_stats;
609 609
610 610 // rx_eep_err
611 611 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
612 612 // rx_truncated
613 613 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
614 614 // parity_err
615 615 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
616 616 // escape_err
617 617 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
618 618 // credit_err
619 619 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
620 620 // write_sync_err
621 621 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
622 622 // disconnect_err
623 623 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
624 624 // early_ep
625 625 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
626 626 // invalid_address
627 627 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
628 628 // packets_sent
629 629 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
630 630 // packets_received
631 631 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
632 632
633 633 }
634 634
635 635 void spacewire_get_last_error( void )
636 636 {
637 637 static spw_stats previous;
638 638 spw_stats current;
639 639 rtems_status_code status;
640 640
641 641 unsigned int hk_lfr_last_er_rid;
642 642 unsigned char hk_lfr_last_er_code;
643 643 int coarseTime;
644 644 int fineTime;
645 645 unsigned char update_hk_lfr_last_er;
646 646
647 647 update_hk_lfr_last_er = 0;
648 648
649 649 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
650 650
651 651 // get current time
652 652 coarseTime = time_management_regs->coarse_time;
653 653 fineTime = time_management_regs->fine_time;
654 654
655 655 // typedef struct {
656 656 // unsigned int tx_link_err; // NOT IN HK
657 657 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
658 658 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
659 659 // unsigned int rx_eep_err;
660 660 // unsigned int rx_truncated;
661 661 // unsigned int parity_err;
662 662 // unsigned int escape_err;
663 663 // unsigned int credit_err;
664 664 // unsigned int write_sync_err;
665 665 // unsigned int disconnect_err;
666 666 // unsigned int early_ep;
667 667 // unsigned int invalid_address;
668 668 // unsigned int packets_sent;
669 669 // unsigned int packets_received;
670 670 // } spw_stats;
671 671
672 672 // tx_link_err *** no code associated to this field
673 673 // rx_rmap_header_crc_err *** LE *** in HK
674 674 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
675 675 {
676 676 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
677 677 hk_lfr_last_er_code = CODE_HEADER_CRC;
678 678 update_hk_lfr_last_er = 1;
679 679 }
680 680 // rx_rmap_data_crc_err *** LE *** NOT IN HK
681 681 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
682 682 {
683 683 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
684 684 hk_lfr_last_er_code = CODE_DATA_CRC;
685 685 update_hk_lfr_last_er = 1;
686 686 }
687 687 // rx_eep_err
688 688 if (previous.rx_eep_err != current.rx_eep_err)
689 689 {
690 690 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
691 691 hk_lfr_last_er_code = CODE_EEP;
692 692 update_hk_lfr_last_er = 1;
693 693 }
694 694 // rx_truncated
695 695 if (previous.rx_truncated != current.rx_truncated)
696 696 {
697 697 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
698 698 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
699 699 update_hk_lfr_last_er = 1;
700 700 }
701 701 // parity_err
702 702 if (previous.parity_err != current.parity_err)
703 703 {
704 704 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
705 705 hk_lfr_last_er_code = CODE_PARITY;
706 706 update_hk_lfr_last_er = 1;
707 707 }
708 708 // escape_err
709 709 if (previous.parity_err != current.parity_err)
710 710 {
711 711 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
712 712 hk_lfr_last_er_code = CODE_ESCAPE;
713 713 update_hk_lfr_last_er = 1;
714 714 }
715 715 // credit_err
716 716 if (previous.credit_err != current.credit_err)
717 717 {
718 718 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
719 719 hk_lfr_last_er_code = CODE_CREDIT;
720 720 update_hk_lfr_last_er = 1;
721 721 }
722 722 // write_sync_err
723 723 if (previous.write_sync_err != current.write_sync_err)
724 724 {
725 725 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
726 726 hk_lfr_last_er_code = CODE_WRITE_SYNC;
727 727 update_hk_lfr_last_er = 1;
728 728 }
729 729 // disconnect_err
730 730 if (previous.disconnect_err != current.disconnect_err)
731 731 {
732 732 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
733 733 hk_lfr_last_er_code = CODE_DISCONNECT;
734 734 update_hk_lfr_last_er = 1;
735 735 }
736 736 // early_ep
737 737 if (previous.early_ep != current.early_ep)
738 738 {
739 739 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
740 740 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
741 741 update_hk_lfr_last_er = 1;
742 742 }
743 743 // invalid_address
744 744 if (previous.invalid_address != current.invalid_address)
745 745 {
746 746 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
747 747 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
748 748 update_hk_lfr_last_er = 1;
749 749 }
750 750
751 751 // if a field has changed, update the hk_last_er fields
752 752 if (update_hk_lfr_last_er == 1)
753 753 {
754 754 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
755 755 }
756 756
757 757 previous = current;
758 758 }
759 759
760 760 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
761 761 {
762 762 unsigned char *coarseTimePtr;
763 763 unsigned char *fineTimePtr;
764 764
765 765 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
766 766 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
767 767
768 768 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
769 769 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
770 770 housekeeping_packet.hk_lfr_last_er_code = code;
771 771 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
772 772 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
773 773 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
774 774 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
775 775 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
776 776 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
777 777 }
778 778
779 779 void update_hk_with_grspw_stats( void )
780 780 {
781 781 //****************************
782 782 // DPU_SPACEWIRE_IF_STATISTICS
783 783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
784 784 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
785 785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
786 786 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
787 787
788 788 //******************************************
789 789 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
790 790 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
791 791 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
792 792 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
793 793 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
794 794 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
795 795
796 796 //*********************************************
797 797 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
798 798 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
799 799 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
800 800 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
801 801 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
802 802 }
803 803
804 804 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
805 805 {
806 806 unsigned int *statusRegisterPtr;
807 807 unsigned char linkState;
808 808
809 809 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
810 810 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
811 811
812 812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
813 813
814 814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
815 815 }
816 816
817 817 void increase_unsigned_char_counter( unsigned char *counter )
818 818 {
819 819 // update the number of valid timecodes that have been received
820 820 if (*counter == 255)
821 821 {
822 822 *counter = 0;
823 823 }
824 824 else
825 825 {
826 826 *counter = *counter + 1;
827 827 }
828 828 }
829 829
830 830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
831 831 {
832 832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
833 833 *
834 834 * @param currentTimecodeCtr is the incoming timecode
835 835 *
836 836 * @return returned codes::
837 837 * - LFR_DEFAULT
838 838 * - LFR_SUCCESSFUL
839 839 *
840 840 */
841 841
842 842 static unsigned char firstTickout = 1;
843 843 unsigned char ret;
844 844
845 845 ret = LFR_DEFAULT;
846 846
847 847 if (firstTickout == 0)
848 848 {
849 849 if (currentTimecodeCtr == 0)
850 850 {
851 851 if (previousTimecodeCtr == 63)
852 852 {
853 853 ret = LFR_SUCCESSFUL;
854 854 }
855 855 else
856 856 {
857 857 ret = LFR_DEFAULT;
858 858 }
859 859 }
860 860 else
861 861 {
862 862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
863 863 {
864 864 ret = LFR_SUCCESSFUL;
865 865 }
866 866 else
867 867 {
868 868 ret = LFR_DEFAULT;
869 869 }
870 870 }
871 871 }
872 872 else
873 873 {
874 874 firstTickout = 0;
875 875 ret = LFR_SUCCESSFUL;
876 876 }
877 877
878 878 return ret;
879 879 }
880 880
881 881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
882 882 {
883 883 unsigned int ret;
884 884
885 885 ret = LFR_DEFAULT;
886 886
887 887 if (timecode == internalTime)
888 888 {
889 889 ret = LFR_SUCCESSFUL;
890 890 }
891 891 else
892 892 {
893 893 ret = LFR_DEFAULT;
894 894 }
895 895
896 896 return ret;
897 897 }
898 898
899 899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
900 900 {
901 901 // a tickout has been emitted, perform actions on the incoming timecode
902 902
903 903 unsigned char incomingTimecode;
904 904 unsigned char updateTime;
905 905 unsigned char internalTime;
906 906 rtems_status_code status;
907 907
908 908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
909 909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
910 910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
911 911
912 912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
913 913
914 914 // update the number of tickout that have been generated
915 915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
916 916
917 917 //**************************
918 918 // HK_LFR_TIMECODE_ERRONEOUS
919 919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
920 920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
921 921 {
922 922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
923 923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
924 924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
925 925 }
926 926
927 927 //************************
928 928 // HK_LFR_TIME_TIMECODE_IT
929 929 // check the coherency between the SpaceWire timecode and the Internal Time
930 930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
931 931 {
932 932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
933 933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
934 934 }
935 935
936 936 //********************
937 937 // HK_LFR_TIMECODE_CTR
938 938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
939 939 if (oneTcLfrUpdateTimeReceived == 1)
940 940 {
941 941 if ( incomingTimecode != updateTime )
942 942 {
943 943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
944 944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
945 945 }
946 946 }
947 947
948 948 // launch the timecode timer to detect missing or invalid timecodes
949 949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
950 950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
951 951 if (status != RTEMS_SUCCESSFUL)
952 952 {
953 953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
954 954 }
955 955 }
956 956
957 957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
958 958 {
959 959 static unsigned char initStep = 1;
960 960
961 961 unsigned char currentTimecodeCtr;
962 962
963 963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
964 964
965 965 if (initStep == 1)
966 966 {
967 967 if (currentTimecodeCtr == previousTimecodeCtr)
968 968 {
969 969 //************************
970 970 // HK_LFR_TIMECODE_MISSING
971 971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
972 972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
973 973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
974 974 }
975 975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
976 976 {
977 977 // the timecode value has changed and the value is valid, this is unexpected because
978 978 // the timer should not have fired, the timecode_irq_handler should have been raised
979 979 }
980 980 else
981 981 {
982 982 //************************
983 983 // HK_LFR_TIMECODE_INVALID
984 984 // the timecode value has changed and the value is not valid, no tickout has been generated
985 985 // this is why the timer has fired
986 986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
987 987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
988 988 }
989 989 }
990 990 else
991 991 {
992 992 initStep = 1;
993 993 //************************
994 994 // HK_LFR_TIMECODE_MISSING
995 995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
996 996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
997 997 }
998 998
999 999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1000 1000 }
1001 1001
1002 1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1003 1003 {
1004 1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1005 1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1006 1006 header->reserved = DEFAULT_RESERVED;
1007 1007 header->userApplication = CCSDS_USER_APP;
1008 1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1009 1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1010 1010 header->packetLength[0] = 0x00;
1011 1011 header->packetLength[1] = 0x00;
1012 1012 // DATA FIELD HEADER
1013 1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1014 1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1015 1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1016 1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1017 1017 header->time[0] = 0x00;
1018 1018 header->time[0] = 0x00;
1019 1019 header->time[0] = 0x00;
1020 1020 header->time[0] = 0x00;
1021 1021 header->time[0] = 0x00;
1022 1022 header->time[0] = 0x00;
1023 1023 // AUXILIARY DATA HEADER
1024 1024 header->sid = 0x00;
1025 1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1026 1026 header->blkNr[0] = 0x00;
1027 1027 header->blkNr[1] = 0x00;
1028 1028 }
1029 1029
1030 1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1031 1031 {
1032 1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1033 1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1034 1034 header->reserved = DEFAULT_RESERVED;
1035 1035 header->userApplication = CCSDS_USER_APP;
1036 1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1037 1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1038 1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1039 1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1040 1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1041 1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1042 1042 // DATA FIELD HEADER
1043 1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1044 1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1045 1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1046 1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1047 1047 header->time[0] = 0x00;
1048 1048 header->time[0] = 0x00;
1049 1049 header->time[0] = 0x00;
1050 1050 header->time[0] = 0x00;
1051 1051 header->time[0] = 0x00;
1052 1052 header->time[0] = 0x00;
1053 1053 // AUXILIARY DATA HEADER
1054 1054 header->sid = 0x00;
1055 1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1056 1056 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1057 1057 header->pktNr = 0x00;
1058 1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1059 1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1060 1060 }
1061 1061
1062 1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1063 1063 {
1064 1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1065 1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1066 1066 header->reserved = DEFAULT_RESERVED;
1067 1067 header->userApplication = CCSDS_USER_APP;
1068 1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1069 1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1070 1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1071 1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1072 1072 header->packetLength[0] = 0x00;
1073 1073 header->packetLength[1] = 0x00;
1074 1074 // DATA FIELD HEADER
1075 1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1076 1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1077 1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1078 1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1079 1079 header->time[0] = 0x00;
1080 1080 header->time[0] = 0x00;
1081 1081 header->time[0] = 0x00;
1082 1082 header->time[0] = 0x00;
1083 1083 header->time[0] = 0x00;
1084 1084 header->time[0] = 0x00;
1085 1085 // AUXILIARY DATA HEADER
1086 1086 header->sid = 0x00;
1087 1087 header->pa_bia_status_info = 0x00;
1088 1088 header->pa_lfr_pkt_cnt_asm = 0x00;
1089 1089 header->pa_lfr_pkt_nr_asm = 0x00;
1090 1090 header->pa_lfr_asm_blk_nr[0] = 0x00;
1091 1091 header->pa_lfr_asm_blk_nr[1] = 0x00;
1092 1092 }
1093 1093
1094 1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1095 1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1096 1096 {
1097 1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1098 1098 *
1099 1099 * @param waveform points to the buffer containing the data that will be send.
1100 1100 * @param sid is the source identifier of the data that will be sent.
1101 1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1102 1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1103 1103 * contain information to setup the transmission of the data packets.
1104 1104 *
1105 1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1106 1106 *
1107 1107 */
1108 1108
1109 1109 unsigned int i;
1110 1110 int ret;
1111 1111 unsigned int coarseTime;
1112 1112 unsigned int fineTime;
1113 1113 rtems_status_code status;
1114 1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1115 1115 int *dataPtr;
1116 1116 unsigned char sid;
1117 1117
1118 1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1119 1119 spw_ioctl_send_CWF.options = 0;
1120 1120
1121 1121 ret = LFR_DEFAULT;
1122 1122 sid = (unsigned char) ring_node_to_send->sid;
1123 1123
1124 1124 coarseTime = ring_node_to_send->coarseTime;
1125 1125 fineTime = ring_node_to_send->fineTime;
1126 1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1127 1127
1128 1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1129 1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1130 1130 header->pa_bia_status_info = pa_bia_status_info;
1131 1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1132 1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1133 1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1134 1134
1135 1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1136 1136 {
1137 1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1138 1138 spw_ioctl_send_CWF.hdr = (char*) header;
1139 1139 // BUILD THE DATA
1140 1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1141 1141
1142 1142 // SET PACKET SEQUENCE CONTROL
1143 1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1144 1144
1145 1145 // SET SID
1146 1146 header->sid = sid;
1147 1147
1148 1148 // SET PACKET TIME
1149 1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1150 1150 //
1151 1151 header->time[0] = header->acquisitionTime[0];
1152 1152 header->time[1] = header->acquisitionTime[1];
1153 1153 header->time[2] = header->acquisitionTime[2];
1154 1154 header->time[3] = header->acquisitionTime[3];
1155 1155 header->time[4] = header->acquisitionTime[4];
1156 1156 header->time[5] = header->acquisitionTime[5];
1157 1157
1158 1158 // SET PACKET ID
1159 1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1160 1160 {
1161 1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1162 1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1163 1163 }
1164 1164 else
1165 1165 {
1166 1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1167 1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1168 1168 }
1169 1169
1170 1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1171 1171 if (status != RTEMS_SUCCESSFUL) {
1172 1172 ret = LFR_DEFAULT;
1173 1173 }
1174 1174 }
1175 1175
1176 1176 return ret;
1177 1177 }
1178 1178
1179 1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1180 1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1181 1181 {
1182 1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1183 1183 *
1184 1184 * @param waveform points to the buffer containing the data that will be send.
1185 1185 * @param sid is the source identifier of the data that will be sent.
1186 1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1187 1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1188 1188 * contain information to setup the transmission of the data packets.
1189 1189 *
1190 1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1191 1191 *
1192 1192 */
1193 1193
1194 1194 unsigned int i;
1195 1195 int ret;
1196 1196 unsigned int coarseTime;
1197 1197 unsigned int fineTime;
1198 1198 rtems_status_code status;
1199 1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1200 1200 int *dataPtr;
1201 1201 unsigned char sid;
1202 1202
1203 1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1204 1204 spw_ioctl_send_SWF.options = 0;
1205 1205
1206 1206 ret = LFR_DEFAULT;
1207 1207
1208 1208 coarseTime = ring_node_to_send->coarseTime;
1209 1209 fineTime = ring_node_to_send->fineTime;
1210 1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1211 1211 sid = ring_node_to_send->sid;
1212 1212
1213 1213 header->pa_bia_status_info = pa_bia_status_info;
1214 1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1215 1215
1216 1216 for (i=0; i<7; i++) // send waveform
1217 1217 {
1218 1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1219 1219 spw_ioctl_send_SWF.hdr = (char*) header;
1220 1220
1221 1221 // SET PACKET SEQUENCE CONTROL
1222 1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1223 1223
1224 1224 // SET PACKET LENGTH AND BLKNR
1225 1225 if (i == 6)
1226 1226 {
1227 1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1228 1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1229 1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1230 1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1231 1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1232 1232 }
1233 1233 else
1234 1234 {
1235 1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1236 1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1237 1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1238 1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1239 1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1240 1240 }
1241 1241
1242 1242 // SET PACKET TIME
1243 1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1244 1244 //
1245 1245 header->time[0] = header->acquisitionTime[0];
1246 1246 header->time[1] = header->acquisitionTime[1];
1247 1247 header->time[2] = header->acquisitionTime[2];
1248 1248 header->time[3] = header->acquisitionTime[3];
1249 1249 header->time[4] = header->acquisitionTime[4];
1250 1250 header->time[5] = header->acquisitionTime[5];
1251 1251
1252 1252 // SET SID
1253 1253 header->sid = sid;
1254 1254
1255 1255 // SET PKTNR
1256 1256 header->pktNr = i+1; // PKT_NR
1257 1257
1258 1258 // SEND PACKET
1259 1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1260 1260 if (status != RTEMS_SUCCESSFUL) {
1261 1261 ret = LFR_DEFAULT;
1262 1262 }
1263 1263 }
1264 1264
1265 1265 return ret;
1266 1266 }
1267 1267
1268 1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1269 1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1270 1270 {
1271 1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1272 1272 *
1273 1273 * @param waveform points to the buffer containing the data that will be send.
1274 1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1275 1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1276 1276 * contain information to setup the transmission of the data packets.
1277 1277 *
1278 1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1279 1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1280 1280 *
1281 1281 */
1282 1282
1283 1283 unsigned int i;
1284 1284 int ret;
1285 1285 unsigned int coarseTime;
1286 1286 unsigned int fineTime;
1287 1287 rtems_status_code status;
1288 1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1289 1289 char *dataPtr;
1290 1290 unsigned char sid;
1291 1291
1292 1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1293 1293 spw_ioctl_send_CWF.options = 0;
1294 1294
1295 1295 ret = LFR_DEFAULT;
1296 1296 sid = ring_node_to_send->sid;
1297 1297
1298 1298 coarseTime = ring_node_to_send->coarseTime;
1299 1299 fineTime = ring_node_to_send->fineTime;
1300 1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1301 1301
1302 1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1303 1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1304 1304 header->pa_bia_status_info = pa_bia_status_info;
1305 1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1306 1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1307 1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1308 1308
1309 1309 //*********************
1310 1310 // SEND CWF3_light DATA
1311 1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1312 1312 {
1313 1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1314 1314 spw_ioctl_send_CWF.hdr = (char*) header;
1315 1315 // BUILD THE DATA
1316 1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1317 1317
1318 1318 // SET PACKET SEQUENCE COUNTER
1319 1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1320 1320
1321 1321 // SET SID
1322 1322 header->sid = sid;
1323 1323
1324 1324 // SET PACKET TIME
1325 1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1326 1326 //
1327 1327 header->time[0] = header->acquisitionTime[0];
1328 1328 header->time[1] = header->acquisitionTime[1];
1329 1329 header->time[2] = header->acquisitionTime[2];
1330 1330 header->time[3] = header->acquisitionTime[3];
1331 1331 header->time[4] = header->acquisitionTime[4];
1332 1332 header->time[5] = header->acquisitionTime[5];
1333 1333
1334 1334 // SET PACKET ID
1335 1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1336 1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1337 1337
1338 1338 // SEND PACKET
1339 1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1340 1340 if (status != RTEMS_SUCCESSFUL) {
1341 1341 ret = LFR_DEFAULT;
1342 1342 }
1343 1343 }
1344 1344
1345 1345 return ret;
1346 1346 }
1347 1347
1348 1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1349 1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1350 1350 {
1351 1351 unsigned int i;
1352 1352 unsigned int length = 0;
1353 1353 rtems_status_code status;
1354 1354 unsigned int sid;
1355 1355 float *spectral_matrix;
1356 1356 int coarseTime;
1357 1357 int fineTime;
1358 1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1359 1359
1360 1360 sid = ring_node_to_send->sid;
1361 1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1362 1362 coarseTime = ring_node_to_send->coarseTime;
1363 1363 fineTime = ring_node_to_send->fineTime;
1364 1364
1365 1365 header->pa_bia_status_info = pa_bia_status_info;
1366 1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1367 1367
1368 1368 for (i=0; i<3; i++)
1369 1369 {
1370 1370 if ((i==0) || (i==1))
1371 1371 {
1372 1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1373 1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1374 1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1375 1375 ];
1376 1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1377 1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1378 1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1379 1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1380 1380 }
1381 1381 else
1382 1382 {
1383 1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1384 1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1385 1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1386 1386 ];
1387 1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1388 1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1389 1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1390 1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1391 1391 }
1392 1392
1393 1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1394 1394 spw_ioctl_send_ASM.hdr = (char *) header;
1395 1395 spw_ioctl_send_ASM.options = 0;
1396 1396
1397 1397 // (2) BUILD THE HEADER
1398 1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1399 1399 header->packetLength[0] = (unsigned char) (length>>8);
1400 1400 header->packetLength[1] = (unsigned char) (length);
1401 1401 header->sid = (unsigned char) sid; // SID
1402 1402 header->pa_lfr_pkt_cnt_asm = 3;
1403 1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1404 1404
1405 1405 // (3) SET PACKET TIME
1406 1406 header->time[0] = (unsigned char) (coarseTime>>24);
1407 1407 header->time[1] = (unsigned char) (coarseTime>>16);
1408 1408 header->time[2] = (unsigned char) (coarseTime>>8);
1409 1409 header->time[3] = (unsigned char) (coarseTime);
1410 1410 header->time[4] = (unsigned char) (fineTime>>8);
1411 1411 header->time[5] = (unsigned char) (fineTime);
1412 1412 //
1413 1413 header->acquisitionTime[0] = header->time[0];
1414 1414 header->acquisitionTime[1] = header->time[1];
1415 1415 header->acquisitionTime[2] = header->time[2];
1416 1416 header->acquisitionTime[3] = header->time[3];
1417 1417 header->acquisitionTime[4] = header->time[4];
1418 1418 header->acquisitionTime[5] = header->time[5];
1419 1419
1420 1420 // (4) SEND PACKET
1421 1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1422 1422 if (status != RTEMS_SUCCESSFUL) {
1423 1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1424 1424 }
1425 1425 }
1426 1426 }
1427 1427
1428 1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1429 1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1430 1430 {
1431 1431 unsigned int i;
1432 1432 unsigned int length = 0;
1433 1433 rtems_status_code status;
1434 1434 unsigned int sid;
1435 1435 float *spectral_matrix;
1436 1436 int coarseTime;
1437 1437 int fineTime;
1438 1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1439 1439
1440 1440 sid = ring_node_to_send->sid;
1441 1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1442 1442 coarseTime = ring_node_to_send->coarseTime;
1443 1443 fineTime = ring_node_to_send->fineTime;
1444 1444
1445 1445 header->pa_bia_status_info = pa_bia_status_info;
1446 1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1447 1447
1448 1448 for (i=0; i<3; i++)
1449 1449 {
1450 1450 if ((i==0) || (i==1))
1451 1451 {
1452 1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1453 1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1454 1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1455 1455 ];
1456 1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1457 1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1458 1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1459 1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1460 1460 }
1461 1461 else
1462 1462 {
1463 1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1464 1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1465 1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1466 1466 ];
1467 1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1468 1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1469 1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1470 1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1471 1471 }
1472 1472
1473 1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1474 1474 spw_ioctl_send_ASM.hdr = (char *) header;
1475 1475 spw_ioctl_send_ASM.options = 0;
1476 1476
1477 1477 // (2) BUILD THE HEADER
1478 1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1479 1479 header->packetLength[0] = (unsigned char) (length>>8);
1480 1480 header->packetLength[1] = (unsigned char) (length);
1481 1481 header->sid = (unsigned char) sid; // SID
1482 1482 header->pa_lfr_pkt_cnt_asm = 3;
1483 1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1484 1484
1485 1485 // (3) SET PACKET TIME
1486 1486 header->time[0] = (unsigned char) (coarseTime>>24);
1487 1487 header->time[1] = (unsigned char) (coarseTime>>16);
1488 1488 header->time[2] = (unsigned char) (coarseTime>>8);
1489 1489 header->time[3] = (unsigned char) (coarseTime);
1490 1490 header->time[4] = (unsigned char) (fineTime>>8);
1491 1491 header->time[5] = (unsigned char) (fineTime);
1492 1492 //
1493 1493 header->acquisitionTime[0] = header->time[0];
1494 1494 header->acquisitionTime[1] = header->time[1];
1495 1495 header->acquisitionTime[2] = header->time[2];
1496 1496 header->acquisitionTime[3] = header->time[3];
1497 1497 header->acquisitionTime[4] = header->time[4];
1498 1498 header->acquisitionTime[5] = header->time[5];
1499 1499
1500 1500 // (4) SEND PACKET
1501 1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1502 1502 if (status != RTEMS_SUCCESSFUL) {
1503 1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1504 1504 }
1505 1505 }
1506 1506 }
1507 1507
1508 1508 void spw_send_asm_f2( ring_node *ring_node_to_send,
1509 1509 Header_TM_LFR_SCIENCE_ASM_t *header )
1510 1510 {
1511 1511 unsigned int i;
1512 1512 unsigned int length = 0;
1513 1513 rtems_status_code status;
1514 1514 unsigned int sid;
1515 1515 float *spectral_matrix;
1516 1516 int coarseTime;
1517 1517 int fineTime;
1518 1518 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1519 1519
1520 1520 sid = ring_node_to_send->sid;
1521 1521 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1522 1522 coarseTime = ring_node_to_send->coarseTime;
1523 1523 fineTime = ring_node_to_send->fineTime;
1524 1524
1525 1525 header->pa_bia_status_info = pa_bia_status_info;
1526 1526 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1527 1527
1528 1528 for (i=0; i<3; i++)
1529 1529 {
1530 1530
1531 1531 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1532 1532 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1533 1533 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1534 1534 ];
1535 1535 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1536 1536 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1537 1537 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1538 1538 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1539 1539
1540 1540 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1541 1541 spw_ioctl_send_ASM.hdr = (char *) header;
1542 1542 spw_ioctl_send_ASM.options = 0;
1543 1543
1544 1544 // (2) BUILD THE HEADER
1545 1545 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1546 1546 header->packetLength[0] = (unsigned char) (length>>8);
1547 1547 header->packetLength[1] = (unsigned char) (length);
1548 1548 header->sid = (unsigned char) sid; // SID
1549 1549 header->pa_lfr_pkt_cnt_asm = 3;
1550 1550 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1551 1551
1552 1552 // (3) SET PACKET TIME
1553 1553 header->time[0] = (unsigned char) (coarseTime>>24);
1554 1554 header->time[1] = (unsigned char) (coarseTime>>16);
1555 1555 header->time[2] = (unsigned char) (coarseTime>>8);
1556 1556 header->time[3] = (unsigned char) (coarseTime);
1557 1557 header->time[4] = (unsigned char) (fineTime>>8);
1558 1558 header->time[5] = (unsigned char) (fineTime);
1559 1559 //
1560 1560 header->acquisitionTime[0] = header->time[0];
1561 1561 header->acquisitionTime[1] = header->time[1];
1562 1562 header->acquisitionTime[2] = header->time[2];
1563 1563 header->acquisitionTime[3] = header->time[3];
1564 1564 header->acquisitionTime[4] = header->time[4];
1565 1565 header->acquisitionTime[5] = header->time[5];
1566 1566
1567 1567 // (4) SEND PACKET
1568 1568 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1569 1569 if (status != RTEMS_SUCCESSFUL) {
1570 1570 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1571 1571 }
1572 1572 }
1573 1573 }
1574 1574
1575 1575 void spw_send_k_dump( ring_node *ring_node_to_send )
1576 1576 {
1577 1577 rtems_status_code status;
1578 1578 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1579 1579 unsigned int packetLength;
1580 1580 unsigned int size;
1581 1581
1582 1582 PRINTF("spw_send_k_dump\n")
1583 1583
1584 1584 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1585 1585
1586 1586 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1587 1587
1588 1588 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1589 1589
1590 1590 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1591 1591
1592 1592 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1593 1593
1594 1594 if (status == -1){
1595 1595 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1596 1596 }
1597 1597
1598 1598 ring_node_to_send->status = 0x00;
1599 1599 }
@@ -1,1567 +1,1642
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 19 ring_node kcoefficient_node_1;
20 20 ring_node kcoefficient_node_2;
21 21
22 22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 23 {
24 24 /** This function updates the LFR registers with the incoming common parameters.
25 25 *
26 26 * @param TC points to the TeleCommand packet that is being processed
27 27 *
28 28 *
29 29 */
30 30
31 31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 33 set_wfp_data_shaping( );
34 34 return LFR_SUCCESSFUL;
35 35 }
36 36
37 37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 38 {
39 39 /** This function updates the LFR registers with the incoming normal parameters.
40 40 *
41 41 * @param TC points to the TeleCommand packet that is being processed
42 42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 43 *
44 44 */
45 45
46 46 int result;
47 47 int flag;
48 48 rtems_status_code status;
49 49
50 50 flag = LFR_SUCCESSFUL;
51 51
52 52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 55 flag = LFR_DEFAULT;
56 56 }
57 57
58 58 // CHECK THE PARAMETERS SET CONSISTENCY
59 59 if (flag == LFR_SUCCESSFUL)
60 60 {
61 61 flag = check_normal_par_consistency( TC, queue_id );
62 62 }
63 63
64 64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_l( TC );
68 68 result = set_sy_lfr_n_swf_p( TC );
69 69 result = set_sy_lfr_n_bp_p0( TC );
70 70 result = set_sy_lfr_n_bp_p1( TC );
71 71 result = set_sy_lfr_n_asm_p( TC );
72 72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 73 }
74 74
75 75 return flag;
76 76 }
77 77
78 78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 79 {
80 80 /** This function updates the LFR registers with the incoming burst parameters.
81 81 *
82 82 * @param TC points to the TeleCommand packet that is being processed
83 83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 84 *
85 85 */
86 86
87 87 int flag;
88 88 rtems_status_code status;
89 89 unsigned char sy_lfr_b_bp_p0;
90 90 unsigned char sy_lfr_b_bp_p1;
91 91 float aux;
92 92
93 93 flag = LFR_SUCCESSFUL;
94 94
95 95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 97 flag = LFR_DEFAULT;
98 98 }
99 99
100 100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102 102
103 103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 104 if (flag == LFR_SUCCESSFUL)
105 105 {
106 106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 107 {
108 108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 113 if (flag == LFR_SUCCESSFUL)
114 114 {
115 115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 116 {
117 117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
118 118 flag = WRONG_APP_DATA;
119 119 }
120 120 }
121 121 //****************************************************************
122 122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 123 if (flag == LFR_SUCCESSFUL)
124 124 {
125 125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 128 if (aux > FLOAT_EQUAL_ZERO)
129 129 {
130 130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET THE PARAMETERS
136 136 if (flag == LFR_SUCCESSFUL)
137 137 {
138 138 flag = set_sy_lfr_b_bp_p0( TC );
139 139 flag = set_sy_lfr_b_bp_p1( TC );
140 140 }
141 141
142 142 return flag;
143 143 }
144 144
145 145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 146 {
147 147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 148 *
149 149 * @param TC points to the TeleCommand packet that is being processed
150 150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 151 *
152 152 */
153 153
154 154 int flag;
155 155 rtems_status_code status;
156 156 unsigned char sy_lfr_s1_bp_p0;
157 157 unsigned char sy_lfr_s1_bp_p1;
158 158 float aux;
159 159
160 160 flag = LFR_SUCCESSFUL;
161 161
162 162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 164 flag = LFR_DEFAULT;
165 165 }
166 166
167 167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169 169
170 170 // sy_lfr_s1_bp_p0
171 171 if (flag == LFR_SUCCESSFUL)
172 172 {
173 173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 174 {
175 175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
176 176 flag = WRONG_APP_DATA;
177 177 }
178 178 }
179 179 // sy_lfr_s1_bp_p1
180 180 if (flag == LFR_SUCCESSFUL)
181 181 {
182 182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 183 {
184 184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
185 185 flag = WRONG_APP_DATA;
186 186 }
187 187 }
188 188 //******************************************************************
189 189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 190 if (flag == LFR_SUCCESSFUL)
191 191 {
192 192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
193 193 if (aux > FLOAT_EQUAL_ZERO)
194 194 {
195 195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 196 flag = LFR_DEFAULT;
197 197 }
198 198 }
199 199
200 200 // SET THE PARAMETERS
201 201 if (flag == LFR_SUCCESSFUL)
202 202 {
203 203 flag = set_sy_lfr_s1_bp_p0( TC );
204 204 flag = set_sy_lfr_s1_bp_p1( TC );
205 205 }
206 206
207 207 return flag;
208 208 }
209 209
210 210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 211 {
212 212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 213 *
214 214 * @param TC points to the TeleCommand packet that is being processed
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 216 *
217 217 */
218 218
219 219 int flag;
220 220 rtems_status_code status;
221 221 unsigned char sy_lfr_s2_bp_p0;
222 222 unsigned char sy_lfr_s2_bp_p1;
223 223 float aux;
224 224
225 225 flag = LFR_SUCCESSFUL;
226 226
227 227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 229 flag = LFR_DEFAULT;
230 230 }
231 231
232 232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 234
235 235 // sy_lfr_s2_bp_p0
236 236 if (flag == LFR_SUCCESSFUL)
237 237 {
238 238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 239 {
240 240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 241 flag = WRONG_APP_DATA;
242 242 }
243 243 }
244 244 // sy_lfr_s2_bp_p1
245 245 if (flag == LFR_SUCCESSFUL)
246 246 {
247 247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 248 {
249 249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 250 flag = WRONG_APP_DATA;
251 251 }
252 252 }
253 253 //******************************************************************
254 254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 255 if (flag == LFR_SUCCESSFUL)
256 256 {
257 257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 260 if (aux > FLOAT_EQUAL_ZERO)
261 261 {
262 262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 263 flag = LFR_DEFAULT;
264 264 }
265 265 }
266 266
267 267 // SET THE PARAMETERS
268 268 if (flag == LFR_SUCCESSFUL)
269 269 {
270 270 flag = set_sy_lfr_s2_bp_p0( TC );
271 271 flag = set_sy_lfr_s2_bp_p1( TC );
272 272 }
273 273
274 274 return flag;
275 275 }
276 276
277 277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 278 {
279 279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 280 *
281 281 * @param TC points to the TeleCommand packet that is being processed
282 282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 283 *
284 284 */
285 285
286 286 int flag;
287 287
288 288 flag = LFR_DEFAULT;
289 289
290 290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 291
292 292 return flag;
293 293 }
294 294
295 295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 296 {
297 297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 298 *
299 299 * @param TC points to the TeleCommand packet that is being processed
300 300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 301 *
302 302 */
303 303
304 304 int flag;
305 305
306 306 flag = LFR_DEFAULT;
307 307
308 308 flag = set_sy_lfr_fbins( TC );
309 309
310 310 return flag;
311 311 }
312 312
313 313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 314 {
315 315 /** This function updates the LFR registers with the incoming sbm2 parameters.
316 316 *
317 317 * @param TC points to the TeleCommand packet that is being processed
318 318 * @param queue_id is the id of the queue which handles TM related to this execution step
319 319 *
320 320 */
321 321
322 322 int flag;
323 323
324 324 flag = LFR_DEFAULT;
325 325
326 326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
327 327
328 328 if (flag == LFR_SUCCESSFUL)
329 329 {
330 330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
331 331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
332 332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
333 333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
334 334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
335 335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
336 336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
337 337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
338 338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
339 339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
340 340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
341 341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
342 342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
343 343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
344 344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
345 345
346 346 //****************************
347 347 // store PAS filter parameters
348 348 // sy_lfr_pas_filter_enabled
349 349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
350 350 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
351 351 // sy_lfr_pas_filter_modulus
352 352 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
353 353 // sy_lfr_pas_filter_tbad
354 354 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
355 355 parameter_dump_packet.sy_lfr_pas_filter_tbad );
356 356 // sy_lfr_pas_filter_offset
357 357 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
358 358 // sy_lfr_pas_filter_shift
359 359 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
360 360 parameter_dump_packet.sy_lfr_pas_filter_shift );
361 361
362 362 //****************************************************
363 363 // store the parameter sy_lfr_sc_rw_delta_f as a float
364 364 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
365 365 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
366 366 }
367 367
368 368 return flag;
369 369 }
370 370
371 371 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
372 372 {
373 373 /** This function updates the LFR registers with the incoming sbm2 parameters.
374 374 *
375 375 * @param TC points to the TeleCommand packet that is being processed
376 376 * @param queue_id is the id of the queue which handles TM related to this execution step
377 377 *
378 378 */
379 379
380 380 unsigned int address;
381 381 rtems_status_code status;
382 382 unsigned int freq;
383 383 unsigned int bin;
384 384 unsigned int coeff;
385 385 unsigned char *kCoeffPtr;
386 386 unsigned char *kCoeffDumpPtr;
387 387
388 388 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
389 389 // F0 => 11 bins
390 390 // F1 => 13 bins
391 391 // F2 => 12 bins
392 392 // 36 bins to dump in two packets (30 bins max per packet)
393 393
394 394 //*********
395 395 // PACKET 1
396 396 // 11 F0 bins, 13 F1 bins and 6 F2 bins
397 397 kcoefficients_dump_1.destinationID = TC->sourceID;
398 398 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
399 399 for( freq=0;
400 400 freq<NB_BINS_COMPRESSED_SM_F0;
401 401 freq++ )
402 402 {
403 403 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
404 404 bin = freq;
405 405 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
406 406 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
407 407 {
408 408 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
409 409 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
410 410 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
411 411 }
412 412 }
413 413 for( freq=NB_BINS_COMPRESSED_SM_F0;
414 414 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
415 415 freq++ )
416 416 {
417 417 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
418 418 bin = freq - NB_BINS_COMPRESSED_SM_F0;
419 419 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
420 420 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
421 421 {
422 422 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
423 423 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
424 424 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
425 425 }
426 426 }
427 427 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
428 428 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
429 429 freq++ )
430 430 {
431 431 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
432 432 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
433 433 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
434 434 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
435 435 {
436 436 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
437 437 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
438 438 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
439 439 }
440 440 }
441 441 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
442 442 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
443 443 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
444 444 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
445 445 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
446 446 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
447 447 // SEND DATA
448 448 kcoefficient_node_1.status = 1;
449 449 address = (unsigned int) &kcoefficient_node_1;
450 450 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
451 451 if (status != RTEMS_SUCCESSFUL) {
452 452 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
453 453 }
454 454
455 455 //********
456 456 // PACKET 2
457 457 // 6 F2 bins
458 458 kcoefficients_dump_2.destinationID = TC->sourceID;
459 459 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
460 460 for( freq=0; freq<6; freq++ )
461 461 {
462 462 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
463 463 bin = freq + 6;
464 464 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
465 465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
466 466 {
467 467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
468 468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
469 469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
470 470 }
471 471 }
472 472 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
473 473 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
474 474 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
475 475 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
476 476 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
477 477 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
478 478 // SEND DATA
479 479 kcoefficient_node_2.status = 1;
480 480 address = (unsigned int) &kcoefficient_node_2;
481 481 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
482 482 if (status != RTEMS_SUCCESSFUL) {
483 483 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
484 484 }
485 485
486 486 return status;
487 487 }
488 488
489 489 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
490 490 {
491 491 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
492 492 *
493 493 * @param queue_id is the id of the queue which handles TM related to this execution step.
494 494 *
495 495 * @return RTEMS directive status codes:
496 496 * - RTEMS_SUCCESSFUL - message sent successfully
497 497 * - RTEMS_INVALID_ID - invalid queue id
498 498 * - RTEMS_INVALID_SIZE - invalid message size
499 499 * - RTEMS_INVALID_ADDRESS - buffer is NULL
500 500 * - RTEMS_UNSATISFIED - out of message buffers
501 501 * - RTEMS_TOO_MANY - queue s limit has been reached
502 502 *
503 503 */
504 504
505 505 int status;
506 506
507 507 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
508 508 parameter_dump_packet.destinationID = TC->sourceID;
509 509
510 510 // UPDATE TIME
511 511 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
512 512 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
513 513 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
514 514 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
515 515 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
516 516 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
517 517 // SEND DATA
518 518 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
519 519 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
520 520 if (status != RTEMS_SUCCESSFUL) {
521 521 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
522 522 }
523 523
524 524 return status;
525 525 }
526 526
527 527 //***********************
528 528 // NORMAL MODE PARAMETERS
529 529
530 530 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
531 531 {
532 532 unsigned char msb;
533 533 unsigned char lsb;
534 534 int flag;
535 535 float aux;
536 536 rtems_status_code status;
537 537
538 538 unsigned int sy_lfr_n_swf_l;
539 539 unsigned int sy_lfr_n_swf_p;
540 540 unsigned int sy_lfr_n_asm_p;
541 541 unsigned char sy_lfr_n_bp_p0;
542 542 unsigned char sy_lfr_n_bp_p1;
543 543 unsigned char sy_lfr_n_cwf_long_f3;
544 544
545 545 flag = LFR_SUCCESSFUL;
546 546
547 547 //***************
548 548 // get parameters
549 549 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
550 550 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
551 551 sy_lfr_n_swf_l = msb * 256 + lsb;
552 552
553 553 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
554 554 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
555 555 sy_lfr_n_swf_p = msb * 256 + lsb;
556 556
557 557 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
558 558 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
559 559 sy_lfr_n_asm_p = msb * 256 + lsb;
560 560
561 561 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
562 562
563 563 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
564 564
565 565 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
566 566
567 567 //******************
568 568 // check consistency
569 569 // sy_lfr_n_swf_l
570 570 if (sy_lfr_n_swf_l != 2048)
571 571 {
572 572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
573 573 flag = WRONG_APP_DATA;
574 574 }
575 575 // sy_lfr_n_swf_p
576 576 if (flag == LFR_SUCCESSFUL)
577 577 {
578 578 if ( sy_lfr_n_swf_p < 22 )
579 579 {
580 580 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
581 581 flag = WRONG_APP_DATA;
582 582 }
583 583 }
584 584 // sy_lfr_n_bp_p0
585 585 if (flag == LFR_SUCCESSFUL)
586 586 {
587 587 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
588 588 {
589 589 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
590 590 flag = WRONG_APP_DATA;
591 591 }
592 592 }
593 593 // sy_lfr_n_asm_p
594 594 if (flag == LFR_SUCCESSFUL)
595 595 {
596 596 if (sy_lfr_n_asm_p == 0)
597 597 {
598 598 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
599 599 flag = WRONG_APP_DATA;
600 600 }
601 601 }
602 602 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
603 603 if (flag == LFR_SUCCESSFUL)
604 604 {
605 605 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
606 606 if (aux > FLOAT_EQUAL_ZERO)
607 607 {
608 608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
609 609 flag = WRONG_APP_DATA;
610 610 }
611 611 }
612 612 // sy_lfr_n_bp_p1
613 613 if (flag == LFR_SUCCESSFUL)
614 614 {
615 615 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
616 616 {
617 617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
618 618 flag = WRONG_APP_DATA;
619 619 }
620 620 }
621 621 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
622 622 if (flag == LFR_SUCCESSFUL)
623 623 {
624 624 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
625 625 if (aux > FLOAT_EQUAL_ZERO)
626 626 {
627 627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
628 628 flag = LFR_DEFAULT;
629 629 }
630 630 }
631 631 // sy_lfr_n_cwf_long_f3
632 632
633 633 return flag;
634 634 }
635 635
636 636 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
637 637 {
638 638 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
639 639 *
640 640 * @param TC points to the TeleCommand packet that is being processed
641 641 * @param queue_id is the id of the queue which handles TM related to this execution step
642 642 *
643 643 */
644 644
645 645 int result;
646 646
647 647 result = LFR_SUCCESSFUL;
648 648
649 649 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
650 650 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
651 651
652 652 return result;
653 653 }
654 654
655 655 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
656 656 {
657 657 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
658 658 *
659 659 * @param TC points to the TeleCommand packet that is being processed
660 660 * @param queue_id is the id of the queue which handles TM related to this execution step
661 661 *
662 662 */
663 663
664 664 int result;
665 665
666 666 result = LFR_SUCCESSFUL;
667 667
668 668 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
669 669 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
670 670
671 671 return result;
672 672 }
673 673
674 674 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
675 675 {
676 676 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
677 677 *
678 678 * @param TC points to the TeleCommand packet that is being processed
679 679 * @param queue_id is the id of the queue which handles TM related to this execution step
680 680 *
681 681 */
682 682
683 683 int result;
684 684
685 685 result = LFR_SUCCESSFUL;
686 686
687 687 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
688 688 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
689 689
690 690 return result;
691 691 }
692 692
693 693 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
694 694 {
695 695 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
696 696 *
697 697 * @param TC points to the TeleCommand packet that is being processed
698 698 * @param queue_id is the id of the queue which handles TM related to this execution step
699 699 *
700 700 */
701 701
702 702 int status;
703 703
704 704 status = LFR_SUCCESSFUL;
705 705
706 706 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
707 707
708 708 return status;
709 709 }
710 710
711 711 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
712 712 {
713 713 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
714 714 *
715 715 * @param TC points to the TeleCommand packet that is being processed
716 716 * @param queue_id is the id of the queue which handles TM related to this execution step
717 717 *
718 718 */
719 719
720 720 int status;
721 721
722 722 status = LFR_SUCCESSFUL;
723 723
724 724 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
725 725
726 726 return status;
727 727 }
728 728
729 729 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
730 730 {
731 731 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
732 732 *
733 733 * @param TC points to the TeleCommand packet that is being processed
734 734 * @param queue_id is the id of the queue which handles TM related to this execution step
735 735 *
736 736 */
737 737
738 738 int status;
739 739
740 740 status = LFR_SUCCESSFUL;
741 741
742 742 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
743 743
744 744 return status;
745 745 }
746 746
747 747 //**********************
748 748 // BURST MODE PARAMETERS
749 749 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
750 750 {
751 751 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
752 752 *
753 753 * @param TC points to the TeleCommand packet that is being processed
754 754 * @param queue_id is the id of the queue which handles TM related to this execution step
755 755 *
756 756 */
757 757
758 758 int status;
759 759
760 760 status = LFR_SUCCESSFUL;
761 761
762 762 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
763 763
764 764 return status;
765 765 }
766 766
767 767 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
768 768 {
769 769 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
770 770 *
771 771 * @param TC points to the TeleCommand packet that is being processed
772 772 * @param queue_id is the id of the queue which handles TM related to this execution step
773 773 *
774 774 */
775 775
776 776 int status;
777 777
778 778 status = LFR_SUCCESSFUL;
779 779
780 780 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
781 781
782 782 return status;
783 783 }
784 784
785 785 //*********************
786 786 // SBM1 MODE PARAMETERS
787 787 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
788 788 {
789 789 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
790 790 *
791 791 * @param TC points to the TeleCommand packet that is being processed
792 792 * @param queue_id is the id of the queue which handles TM related to this execution step
793 793 *
794 794 */
795 795
796 796 int status;
797 797
798 798 status = LFR_SUCCESSFUL;
799 799
800 800 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
801 801
802 802 return status;
803 803 }
804 804
805 805 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
806 806 {
807 807 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
808 808 *
809 809 * @param TC points to the TeleCommand packet that is being processed
810 810 * @param queue_id is the id of the queue which handles TM related to this execution step
811 811 *
812 812 */
813 813
814 814 int status;
815 815
816 816 status = LFR_SUCCESSFUL;
817 817
818 818 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
819 819
820 820 return status;
821 821 }
822 822
823 823 //*********************
824 824 // SBM2 MODE PARAMETERS
825 825 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
826 826 {
827 827 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
828 828 *
829 829 * @param TC points to the TeleCommand packet that is being processed
830 830 * @param queue_id is the id of the queue which handles TM related to this execution step
831 831 *
832 832 */
833 833
834 834 int status;
835 835
836 836 status = LFR_SUCCESSFUL;
837 837
838 838 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
839 839
840 840 return status;
841 841 }
842 842
843 843 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
844 844 {
845 845 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
846 846 *
847 847 * @param TC points to the TeleCommand packet that is being processed
848 848 * @param queue_id is the id of the queue which handles TM related to this execution step
849 849 *
850 850 */
851 851
852 852 int status;
853 853
854 854 status = LFR_SUCCESSFUL;
855 855
856 856 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
857 857
858 858 return status;
859 859 }
860 860
861 861 //*******************
862 862 // TC_LFR_UPDATE_INFO
863 863 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
864 864 {
865 865 unsigned int status;
866 866
867 867 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
868 868 || (mode == LFR_MODE_BURST)
869 869 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
870 870 {
871 871 status = LFR_SUCCESSFUL;
872 872 }
873 873 else
874 874 {
875 875 status = LFR_DEFAULT;
876 876 }
877 877
878 878 return status;
879 879 }
880 880
881 881 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
882 882 {
883 883 unsigned int status;
884 884
885 885 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
886 886 || (mode == TDS_MODE_BURST)
887 887 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
888 888 || (mode == TDS_MODE_LFM))
889 889 {
890 890 status = LFR_SUCCESSFUL;
891 891 }
892 892 else
893 893 {
894 894 status = LFR_DEFAULT;
895 895 }
896 896
897 897 return status;
898 898 }
899 899
900 900 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
901 901 {
902 902 unsigned int status;
903 903
904 904 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
905 905 || (mode == THR_MODE_BURST))
906 906 {
907 907 status = LFR_SUCCESSFUL;
908 908 }
909 909 else
910 910 {
911 911 status = LFR_DEFAULT;
912 912 }
913 913
914 914 return status;
915 915 }
916 916
917 917 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
918 918 {
919 919 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
920 920 *
921 921 * @param TC points to the TeleCommand packet that is being processed
922 922 *
923 923 */
924 924
925 925 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
926 926
927 927 bytePosPtr = (unsigned char *) &TC->packetID;
928 928
929 929 // cp_rpw_sc_rw1_f1
930 930 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
931 931 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
932 932
933 933 // cp_rpw_sc_rw1_f2
934 934 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
935 935 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
936 936
937 937 // cp_rpw_sc_rw2_f1
938 938 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
939 939 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
940 940
941 941 // cp_rpw_sc_rw2_f2
942 942 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
943 943 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
944 944
945 945 // cp_rpw_sc_rw3_f1
946 946 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
947 947 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
948 948
949 949 // cp_rpw_sc_rw3_f2
950 950 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
951 951 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
952 952
953 953 // cp_rpw_sc_rw4_f1
954 954 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
955 955 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
956 956
957 957 // cp_rpw_sc_rw4_f2
958 958 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
959 959 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
960 960 }
961 961
962 962 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
963 963 {
964 964 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
965 965 *
966 966 * @param fbins_mask
967 967 * @param rw_f is the reaction wheel frequency to filter
968 968 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
969 969 * @param flag [true] filtering enabled [false] filtering disabled
970 970 *
971 971 * @return void
972 972 *
973 973 */
974 974
975 float fmin;
976 float fMAX;
975 float f_RW_min;
976 float f_RW_MAX;
977 float fi_min;
978 float fi_MAX;
979 float fi;
980 float deltaBelow;
981 float deltaAbove;
977 982 int binBelow;
978 983 int binAbove;
984 int closestBin;
979 985 unsigned int whichByte;
980 unsigned char selectedByte;
986 int selectedByte;
981 987 int bin;
988 int binToRemove[3];
989 int k;
982 990
983 991 whichByte = 0;
984 992 bin = 0;
985 993
994 binToRemove[0] = -1;
995 binToRemove[1] = -1;
996 binToRemove[2] = -1;
997
986 998 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
987 fmin = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
988 fMAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
999 f_RW_min = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
1000 f_RW_MAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
1001
1002 // compute the index of the frequency bin immediately below rw_f
1003 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1004 deltaBelow = rw_f - binBelow * deltaFreq;
1005
1006 // compute the index of the frequency bin immediately above rw_f
1007 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1008 deltaAbove = binAbove * deltaFreq - rw_f;
989 1009
990 // compute the index of the frequency bin immediately below fmin
991 binBelow = (int) ( floor( ((double) fmin) / ((double) deltaFreq)) );
1010 // search the closest bin
1011 if (deltaAbove > deltaBelow)
1012 {
1013 closestBin = binBelow;
1014 }
1015 else
1016 {
1017 closestBin = binAbove;
1018 }
1019
1020 // compute the fi interval [fi - Delta_f * 0.285, fi + Delta_f * 0.285]
1021 fi = closestBin * deltaFreq;
992 1022
993 // compute the index of the frequency bin immediately above fMAX
994 binAbove = (int) ( floor( ((double) fMAX) / ((double) deltaFreq)) );
1023 fi_min = fi - (deltaFreq * 0.285);
1024 if ( fi_min < 0 )
1025 {
1026 fi_min = 0;
1027 }
1028 else if ( fi_min > (deltaFreq*127) )
1029 {
1030 fi_min = -1;
1031 }
1032
1033 fi_MAX = fi + (deltaFreq * 0.285);
1034 if ( fi_MAX > (deltaFreq*127) )
1035 {
1036 fi_MAX = -1;
1037 }
995 1038
996 for (bin = binBelow; bin <= binAbove; bin++)
1039 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1040 // => remove f_(i), f_(i-1) and f_(i+1)
1041 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
997 1042 {
998 if ( (bin >= 0) && (bin<=127) )
1043 binToRemove[0] = closestBin - 1;
1044 binToRemove[1] = closestBin;
1045 binToRemove[2] = closestBin + 1;
1046 }
1047 // 2. ELSE
1048 // => remove the two f_(i) which are around f_RW
1049 else
1050 {
1051 binToRemove[0] = binBelow;
1052 binToRemove[1] = binAbove;
1053 binToRemove[2] = -1;
1054 }
1055
1056 for (k = 0; k <= 3; k++)
1057 {
1058 bin = binToRemove[k];
1059 if ( (bin >= 0) && (bin <= 127) )
999 1060 {
1000 1061 if (flag == 1)
1001 1062 {
1002 whichByte = bin >> 3; // division by 8
1003 selectedByte = (unsigned char) ( 1 << (bin - (whichByte * 8)) );
1004 fbins_mask[whichByte] = fbins_mask[whichByte] & (~selectedByte);
1063 whichByte = (bin >> 3); // division by 8
1064 selectedByte = ( 1 << (bin - (whichByte * 8)) );
1065
1066 printf("whichByte = %d, bin = %d, selectedByte = %x (%x)\n", whichByte, bin, selectedByte, ~selectedByte);
1067
1068 fbins_mask[15 - whichByte] = fbins_mask[15 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1005 1069 }
1006 1070 }
1007 1071 }
1072
1073 if (flag == 1)
1074 {
1075 printf("fi = %f, fi_min = %f, fi_MAX = %f\n", fi, fi_min, fi_MAX);
1076 printf("deltaFreq = %d, flag = %d, rw_f = %f, f_RW_min = %f, f_RW_MAX = %f\n", deltaFreq, flag, rw_f, f_RW_min, f_RW_MAX);
1077 printf("%x %x %x %x ** %x %x %x %x ** %x %x %x %x ** %x %x %x %x\n\n", fbins_mask[0], fbins_mask[1], fbins_mask[2], fbins_mask[3],
1078 fbins_mask[4], fbins_mask[5], fbins_mask[6], fbins_mask[7],
1079 fbins_mask[8], fbins_mask[9], fbins_mask[10], fbins_mask[11],
1080 fbins_mask[12], fbins_mask[13], fbins_mask[14], fbins_mask[15]);
1081 }
1082
1008 1083 }
1009 1084
1010 1085 void build_sy_lfr_rw_mask( unsigned int channel )
1011 1086 {
1012 1087 unsigned char local_rw_fbins_mask[16];
1013 1088 unsigned char *maskPtr;
1014 1089 double deltaF;
1015 1090 unsigned k;
1016 1091
1017 1092 k = 0;
1018 1093
1019 1094 maskPtr = NULL;
1020 1095 deltaF = 1.;
1021 1096
1022 1097 switch (channel)
1023 1098 {
1024 1099 case 0:
1025 1100 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1026 1101 deltaF = 96.;
1027 1102 break;
1028 1103 case 1:
1029 1104 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1030 1105 deltaF = 16.;
1031 1106 break;
1032 1107 case 2:
1033 1108 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1034 1109 deltaF = 1.;
1035 1110 break;
1036 1111 default:
1037 1112 break;
1038 1113 }
1039 1114
1040 1115 for (k = 0; k < 16; k++)
1041 1116 {
1042 1117 local_rw_fbins_mask[k] = 0xff;
1043 1118 }
1044 1119
1045 1120 // RW1 F1
1046 1121 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1047 1122
1048 1123 // RW1 F2
1049 1124 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1050 1125
1051 1126 // RW2 F1
1052 1127 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1053 1128
1054 1129 // RW2 F2
1055 1130 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1056 1131
1057 1132 // RW3 F1
1058 1133 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1059 1134
1060 1135 // RW3 F2
1061 1136 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1062 1137
1063 1138 // RW4 F1
1064 1139 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1065 1140
1066 1141 // RW4 F2
1067 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1142 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1068 1143
1069 1144 // update the value of the fbins related to reaction wheels frequency filtering
1070 1145 if (maskPtr != NULL)
1071 1146 {
1072 1147 for (k = 0; k < 16; k++)
1073 1148 {
1074 1149 maskPtr[k] = local_rw_fbins_mask[k];
1075 1150 }
1076 1151 }
1077 1152 }
1078 1153
1079 1154 void build_sy_lfr_rw_masks( void )
1080 1155 {
1081 1156 build_sy_lfr_rw_mask( 0 );
1082 1157 build_sy_lfr_rw_mask( 1 );
1083 1158 build_sy_lfr_rw_mask( 2 );
1084 1159
1085 1160 merge_fbins_masks();
1086 1161 }
1087 1162
1088 1163 void merge_fbins_masks( void )
1089 1164 {
1090 1165 unsigned char k;
1091 1166
1092 1167 unsigned char *fbins_f0;
1093 1168 unsigned char *fbins_f1;
1094 1169 unsigned char *fbins_f2;
1095 1170 unsigned char *rw_mask_f0;
1096 1171 unsigned char *rw_mask_f1;
1097 1172 unsigned char *rw_mask_f2;
1098 1173
1099 1174 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1100 1175 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1101 1176 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1102 1177 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1103 1178 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1104 1179 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1105 1180
1106 1181 for( k=0; k < 16; k++ )
1107 1182 {
1108 1183 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1109 1184 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1110 1185 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1111 1186 }
1112 1187 }
1113 1188
1114 1189 //***********
1115 1190 // FBINS MASK
1116 1191
1117 1192 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1118 1193 {
1119 1194 int status;
1120 1195 unsigned int k;
1121 1196 unsigned char *fbins_mask_dump;
1122 1197 unsigned char *fbins_mask_TC;
1123 1198
1124 1199 status = LFR_SUCCESSFUL;
1125 1200
1126 1201 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1127 1202 fbins_mask_TC = TC->dataAndCRC;
1128 1203
1129 1204 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1130 1205 {
1131 1206 fbins_mask_dump[k] = fbins_mask_TC[k];
1132 1207 }
1133 1208
1134 1209 return status;
1135 1210 }
1136 1211
1137 1212 //***************************
1138 1213 // TC_LFR_LOAD_PAS_FILTER_PAR
1139 1214
1140 1215 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1141 1216 {
1142 1217 int flag;
1143 1218 rtems_status_code status;
1144 1219
1145 1220 unsigned char sy_lfr_pas_filter_enabled;
1146 1221 unsigned char sy_lfr_pas_filter_modulus;
1147 1222 float sy_lfr_pas_filter_tbad;
1148 1223 unsigned char sy_lfr_pas_filter_offset;
1149 1224 float sy_lfr_pas_filter_shift;
1150 1225 float sy_lfr_sc_rw_delta_f;
1151 1226 char *parPtr;
1152 1227
1153 1228 flag = LFR_SUCCESSFUL;
1154 1229 sy_lfr_pas_filter_tbad = 0.0;
1155 1230 sy_lfr_pas_filter_shift = 0.0;
1156 1231 sy_lfr_sc_rw_delta_f = 0.0;
1157 1232 parPtr = NULL;
1158 1233
1159 1234 //***************
1160 1235 // get parameters
1161 1236 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1162 1237 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1163 1238 copyFloatByChar(
1164 1239 (unsigned char*) &sy_lfr_pas_filter_tbad,
1165 1240 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1166 1241 );
1167 1242 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1168 1243 copyFloatByChar(
1169 1244 (unsigned char*) &sy_lfr_pas_filter_shift,
1170 1245 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1171 1246 );
1172 1247 copyFloatByChar(
1173 1248 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1174 1249 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1175 1250 );
1176 1251
1177 1252 //******************
1178 1253 // CHECK CONSISTENCY
1179 1254
1180 1255 //**************************
1181 1256 // sy_lfr_pas_filter_enabled
1182 1257 // nothing to check, value is 0 or 1
1183 1258
1184 1259 //**************************
1185 1260 // sy_lfr_pas_filter_modulus
1186 1261 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1187 1262 {
1188 1263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1189 1264 flag = WRONG_APP_DATA;
1190 1265 }
1191 1266
1192 1267 //***********************
1193 1268 // sy_lfr_pas_filter_tbad
1194 1269 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1195 1270 {
1196 1271 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1197 1272 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1198 1273 flag = WRONG_APP_DATA;
1199 1274 }
1200 1275
1201 1276 //*************************
1202 1277 // sy_lfr_pas_filter_offset
1203 1278 if (flag == LFR_SUCCESSFUL)
1204 1279 {
1205 1280 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1206 1281 {
1207 1282 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1208 1283 flag = WRONG_APP_DATA;
1209 1284 }
1210 1285 }
1211 1286
1212 1287 //************************
1213 1288 // sy_lfr_pas_filter_shift
1214 1289 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1215 1290 {
1216 1291 parPtr = (char*) &sy_lfr_pas_filter_shift;
1217 1292 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1218 1293 flag = WRONG_APP_DATA;
1219 1294 }
1220 1295
1221 1296 //*********************
1222 1297 // sy_lfr_sc_rw_delta_f
1223 1298 // nothing to check, no default value in the ICD
1224 1299
1225 1300 return flag;
1226 1301 }
1227 1302
1228 1303 //**************
1229 1304 // KCOEFFICIENTS
1230 1305 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1231 1306 {
1232 1307 unsigned int kcoeff;
1233 1308 unsigned short sy_lfr_kcoeff_frequency;
1234 1309 unsigned short bin;
1235 1310 unsigned short *freqPtr;
1236 1311 float *kcoeffPtr_norm;
1237 1312 float *kcoeffPtr_sbm;
1238 1313 int status;
1239 1314 unsigned char *kcoeffLoadPtr;
1240 1315 unsigned char *kcoeffNormPtr;
1241 1316 unsigned char *kcoeffSbmPtr_a;
1242 1317 unsigned char *kcoeffSbmPtr_b;
1243 1318
1244 1319 status = LFR_SUCCESSFUL;
1245 1320
1246 1321 kcoeffPtr_norm = NULL;
1247 1322 kcoeffPtr_sbm = NULL;
1248 1323 bin = 0;
1249 1324
1250 1325 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1251 1326 sy_lfr_kcoeff_frequency = *freqPtr;
1252 1327
1253 1328 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1254 1329 {
1255 1330 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1256 1331 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1257 1332 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1258 1333 status = LFR_DEFAULT;
1259 1334 }
1260 1335 else
1261 1336 {
1262 1337 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1263 1338 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1264 1339 {
1265 1340 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1266 1341 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1267 1342 bin = sy_lfr_kcoeff_frequency;
1268 1343 }
1269 1344 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1270 1345 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1271 1346 {
1272 1347 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1273 1348 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1274 1349 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1275 1350 }
1276 1351 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1277 1352 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1278 1353 {
1279 1354 kcoeffPtr_norm = k_coeff_intercalib_f2;
1280 1355 kcoeffPtr_sbm = NULL;
1281 1356 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1282 1357 }
1283 1358 }
1284 1359
1285 1360 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1286 1361 {
1287 1362 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1288 1363 {
1289 1364 // destination
1290 1365 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1291 1366 // source
1292 1367 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1293 1368 // copy source to destination
1294 1369 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1295 1370 }
1296 1371 }
1297 1372
1298 1373 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1299 1374 {
1300 1375 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1301 1376 {
1302 1377 // destination
1303 1378 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1304 1379 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1305 1380 // source
1306 1381 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1307 1382 // copy source to destination
1308 1383 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1309 1384 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1310 1385 }
1311 1386 }
1312 1387
1313 1388 // print_k_coeff();
1314 1389
1315 1390 return status;
1316 1391 }
1317 1392
1318 1393 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1319 1394 {
1320 1395 destination[0] = source[0];
1321 1396 destination[1] = source[1];
1322 1397 destination[2] = source[2];
1323 1398 destination[3] = source[3];
1324 1399 }
1325 1400
1326 1401 void floatToChar( float value, unsigned char* ptr)
1327 1402 {
1328 1403 unsigned char* valuePtr;
1329 1404
1330 1405 valuePtr = (unsigned char*) &value;
1331 1406 ptr[0] = valuePtr[0];
1332 1407 ptr[1] = valuePtr[0];
1333 1408 ptr[2] = valuePtr[0];
1334 1409 ptr[3] = valuePtr[0];
1335 1410 }
1336 1411
1337 1412 //**********
1338 1413 // init dump
1339 1414
1340 1415 void init_parameter_dump( void )
1341 1416 {
1342 1417 /** This function initialize the parameter_dump_packet global variable with default values.
1343 1418 *
1344 1419 */
1345 1420
1346 1421 unsigned int k;
1347 1422
1348 1423 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1349 1424 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1350 1425 parameter_dump_packet.reserved = CCSDS_RESERVED;
1351 1426 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1352 1427 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1353 1428 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1354 1429 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1355 1430 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1356 1431 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1357 1432 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1358 1433 // DATA FIELD HEADER
1359 1434 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1360 1435 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1361 1436 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1362 1437 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1363 1438 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1364 1439 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1365 1440 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1366 1441 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1367 1442 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1368 1443 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1369 1444 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1370 1445
1371 1446 //******************
1372 1447 // COMMON PARAMETERS
1373 1448 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1374 1449 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1375 1450
1376 1451 //******************
1377 1452 // NORMAL PARAMETERS
1378 1453 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1379 1454 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1380 1455 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1381 1456 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1382 1457 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1383 1458 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1384 1459 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1385 1460 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1386 1461 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1387 1462
1388 1463 //*****************
1389 1464 // BURST PARAMETERS
1390 1465 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1391 1466 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1392 1467
1393 1468 //****************
1394 1469 // SBM1 PARAMETERS
1395 1470 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1396 1471 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1397 1472
1398 1473 //****************
1399 1474 // SBM2 PARAMETERS
1400 1475 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1401 1476 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1402 1477
1403 1478 //************
1404 1479 // FBINS MASKS
1405 1480 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1406 1481 {
1407 1482 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1408 1483 }
1409 1484
1410 1485 // PAS FILTER PARAMETERS
1411 1486 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1412 1487 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1413 1488 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1414 1489 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1415 1490 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1416 1491 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1417 1492 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1418 1493
1419 1494 // LFR_RW_MASK
1420 1495 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1421 1496 {
1422 1497 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1423 1498 }
1424 1499 }
1425 1500
1426 1501 void init_kcoefficients_dump( void )
1427 1502 {
1428 1503 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1429 1504 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1430 1505
1431 1506 kcoefficient_node_1.previous = NULL;
1432 1507 kcoefficient_node_1.next = NULL;
1433 1508 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1434 1509 kcoefficient_node_1.coarseTime = 0x00;
1435 1510 kcoefficient_node_1.fineTime = 0x00;
1436 1511 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1437 1512 kcoefficient_node_1.status = 0x00;
1438 1513
1439 1514 kcoefficient_node_2.previous = NULL;
1440 1515 kcoefficient_node_2.next = NULL;
1441 1516 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1442 1517 kcoefficient_node_2.coarseTime = 0x00;
1443 1518 kcoefficient_node_2.fineTime = 0x00;
1444 1519 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1445 1520 kcoefficient_node_2.status = 0x00;
1446 1521 }
1447 1522
1448 1523 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1449 1524 {
1450 1525 unsigned int k;
1451 1526 unsigned int packetLength;
1452 1527
1453 1528 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1454 1529
1455 1530 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1456 1531 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1457 1532 kcoefficients_dump->reserved = CCSDS_RESERVED;
1458 1533 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1459 1534 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1460 1535 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1461 1536 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1462 1537 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1463 1538 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1464 1539 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1465 1540 // DATA FIELD HEADER
1466 1541 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1467 1542 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1468 1543 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1469 1544 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1470 1545 kcoefficients_dump->time[0] = 0x00;
1471 1546 kcoefficients_dump->time[1] = 0x00;
1472 1547 kcoefficients_dump->time[2] = 0x00;
1473 1548 kcoefficients_dump->time[3] = 0x00;
1474 1549 kcoefficients_dump->time[4] = 0x00;
1475 1550 kcoefficients_dump->time[5] = 0x00;
1476 1551 kcoefficients_dump->sid = SID_K_DUMP;
1477 1552
1478 1553 kcoefficients_dump->pkt_cnt = 2;
1479 1554 kcoefficients_dump->pkt_nr = pkt_nr;
1480 1555 kcoefficients_dump->blk_nr = blk_nr;
1481 1556
1482 1557 //******************
1483 1558 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1484 1559 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1485 1560 for (k=0; k<3900; k++)
1486 1561 {
1487 1562 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1488 1563 }
1489 1564 }
1490 1565
1491 1566 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1492 1567 {
1493 1568 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1494 1569 *
1495 1570 * @param packet_sequence_control points to the packet sequence control which will be incremented
1496 1571 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1497 1572 *
1498 1573 * If the destination ID is not known, a dedicated counter is incremented.
1499 1574 *
1500 1575 */
1501 1576
1502 1577 unsigned short sequence_cnt;
1503 1578 unsigned short segmentation_grouping_flag;
1504 1579 unsigned short new_packet_sequence_control;
1505 1580 unsigned char i;
1506 1581
1507 1582 switch (destination_id)
1508 1583 {
1509 1584 case SID_TC_GROUND:
1510 1585 i = GROUND;
1511 1586 break;
1512 1587 case SID_TC_MISSION_TIMELINE:
1513 1588 i = MISSION_TIMELINE;
1514 1589 break;
1515 1590 case SID_TC_TC_SEQUENCES:
1516 1591 i = TC_SEQUENCES;
1517 1592 break;
1518 1593 case SID_TC_RECOVERY_ACTION_CMD:
1519 1594 i = RECOVERY_ACTION_CMD;
1520 1595 break;
1521 1596 case SID_TC_BACKUP_MISSION_TIMELINE:
1522 1597 i = BACKUP_MISSION_TIMELINE;
1523 1598 break;
1524 1599 case SID_TC_DIRECT_CMD:
1525 1600 i = DIRECT_CMD;
1526 1601 break;
1527 1602 case SID_TC_SPARE_GRD_SRC1:
1528 1603 i = SPARE_GRD_SRC1;
1529 1604 break;
1530 1605 case SID_TC_SPARE_GRD_SRC2:
1531 1606 i = SPARE_GRD_SRC2;
1532 1607 break;
1533 1608 case SID_TC_OBCP:
1534 1609 i = OBCP;
1535 1610 break;
1536 1611 case SID_TC_SYSTEM_CONTROL:
1537 1612 i = SYSTEM_CONTROL;
1538 1613 break;
1539 1614 case SID_TC_AOCS:
1540 1615 i = AOCS;
1541 1616 break;
1542 1617 case SID_TC_RPW_INTERNAL:
1543 1618 i = RPW_INTERNAL;
1544 1619 break;
1545 1620 default:
1546 1621 i = GROUND;
1547 1622 break;
1548 1623 }
1549 1624
1550 1625 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1551 1626 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1552 1627
1553 1628 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1554 1629
1555 1630 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1556 1631 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1557 1632
1558 1633 // increment the sequence counter
1559 1634 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1560 1635 {
1561 1636 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1562 1637 }
1563 1638 else
1564 1639 {
1565 1640 sequenceCounters_TM_DUMP[ i ] = 0;
1566 1641 }
1567 1642 }
General Comments 0
You need to be logged in to leave comments. Login now