##// END OF EJS Templates
3.0.0.13
paul -
r250:0e4f9f3e6a3f R3a
parent child
Show More
@@ -1,1412 +1,1422
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_compute_stats_offsets();
70 70 status = spacewire_reset_link( );
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 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
98 98 }
99 99 // wake the WTDG task up to wait for the link recovery
100 100 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
101 101 status = rtems_task_suspend( RTEMS_SELF );
102 102 }
103 103 }
104 104 }
105 105
106 106 rtems_task recv_task( rtems_task_argument unused )
107 107 {
108 108 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
109 109 *
110 110 * @param unused is the starting argument of the RTEMS task
111 111 *
112 112 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
113 113 * 1. It reads the incoming data.
114 114 * 2. Launches the acceptance procedure.
115 115 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
116 116 *
117 117 */
118 118
119 119 int len;
120 120 ccsdsTelecommandPacket_t currentTC;
121 121 unsigned char computed_CRC[ 2 ];
122 122 unsigned char currentTC_LEN_RCV[ 2 ];
123 123 unsigned char destinationID;
124 124 unsigned int estimatedPacketLength;
125 125 unsigned int parserCode;
126 126 rtems_status_code status;
127 127 rtems_id queue_recv_id;
128 128 rtems_id queue_send_id;
129 129
130 130 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
131 131
132 132 status = get_message_queue_id_recv( &queue_recv_id );
133 133 if (status != RTEMS_SUCCESSFUL)
134 134 {
135 135 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
136 136 }
137 137
138 138 status = get_message_queue_id_send( &queue_send_id );
139 139 if (status != RTEMS_SUCCESSFUL)
140 140 {
141 141 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
142 142 }
143 143
144 144 BOOT_PRINTF("in RECV *** \n")
145 145
146 146 while(1)
147 147 {
148 148 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
149 149 if (len == -1){ // error during the read call
150 150 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
151 151 }
152 152 else {
153 153 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
154 154 PRINTF("in RECV *** packet lenght too short\n")
155 155 }
156 156 else {
157 157 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
158 158 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
159 159 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
160 160 // CHECK THE TC
161 161 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
162 162 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
163 163 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
164 164 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
165 165 || (parserCode == WRONG_SRC_ID) )
166 166 { // send TM_LFR_TC_EXE_CORRUPTED
167 167 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
168 168 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
169 169 &&
170 170 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
171 171 )
172 172 {
173 173 if ( parserCode == WRONG_SRC_ID )
174 174 {
175 175 destinationID = SID_TC_GROUND;
176 176 }
177 177 else
178 178 {
179 179 destinationID = currentTC.sourceID;
180 180 }
181 181 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
182 182 computed_CRC, currentTC_LEN_RCV,
183 183 destinationID );
184 184 }
185 185 }
186 186 else
187 187 { // send valid TC to the action launcher
188 188 status = rtems_message_queue_send( queue_recv_id, &currentTC,
189 189 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
190 190 }
191 191 }
192 192 }
193 193
194 194 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
195 195
196 196 }
197 197 }
198 198
199 199 rtems_task send_task( rtems_task_argument argument)
200 200 {
201 201 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
202 202 *
203 203 * @param unused is the starting argument of the RTEMS task
204 204 *
205 205 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
206 206 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
207 207 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
208 208 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
209 209 * data it contains.
210 210 *
211 211 */
212 212
213 213 rtems_status_code status; // RTEMS status code
214 214 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
215 215 ring_node *incomingRingNodePtr;
216 216 int ring_node_address;
217 217 char *charPtr;
218 218 spw_ioctl_pkt_send *spw_ioctl_send;
219 219 size_t size; // size of the incoming TC packet
220 220 rtems_id queue_send_id;
221 221 unsigned int sid;
222 222 unsigned char sidAsUnsignedChar;
223 223 unsigned char type;
224 224
225 225 incomingRingNodePtr = NULL;
226 226 ring_node_address = 0;
227 227 charPtr = (char *) &ring_node_address;
228 228 sid = 0;
229 229 sidAsUnsignedChar = 0;
230 230
231 231 init_header_cwf( &headerCWF );
232 232 init_header_swf( &headerSWF );
233 233 init_header_asm( &headerASM );
234 234
235 235 status = get_message_queue_id_send( &queue_send_id );
236 236 if (status != RTEMS_SUCCESSFUL)
237 237 {
238 238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 239 }
240 240
241 241 BOOT_PRINTF("in SEND *** \n")
242 242
243 243 while(1)
244 244 {
245 245 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
246 246 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
247 247
248 248 if (status!=RTEMS_SUCCESSFUL)
249 249 {
250 250 PRINTF1("in SEND *** (1) ERR = %d\n", status)
251 251 }
252 252 else
253 253 {
254 254 if ( size == sizeof(ring_node*) )
255 255 {
256 256 charPtr[0] = incomingData[0];
257 257 charPtr[1] = incomingData[1];
258 258 charPtr[2] = incomingData[2];
259 259 charPtr[3] = incomingData[3];
260 260 incomingRingNodePtr = (ring_node*) ring_node_address;
261 261 sid = incomingRingNodePtr->sid;
262 262 if ( (sid==SID_NORM_CWF_LONG_F3)
263 263 || (sid==SID_BURST_CWF_F2 )
264 264 || (sid==SID_SBM1_CWF_F1 )
265 265 || (sid==SID_SBM2_CWF_F2 ))
266 266 {
267 267 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
268 268 }
269 269 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
270 270 {
271 271 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
272 272 }
273 273 else if ( (sid==SID_NORM_CWF_F3) )
274 274 {
275 275 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
276 276 }
277 277 else if (sid==SID_NORM_ASM_F0)
278 278 {
279 279 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
280 280 }
281 281 else if (sid==SID_NORM_ASM_F1)
282 282 {
283 283 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
284 284 }
285 285 else if (sid==SID_NORM_ASM_F2)
286 286 {
287 287 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
288 288 }
289 289 else if ( sid==TM_CODE_K_DUMP )
290 290 {
291 291 spw_send_k_dump( incomingRingNodePtr );
292 292 }
293 293 else
294 294 {
295 295 PRINTF1("unexpected sid = %d\n", sid);
296 296 }
297 297 }
298 298 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
299 299 {
300 300 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
301 301 sid = sidAsUnsignedChar;
302 302 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
303 303 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
304 304 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
305 305 {
306 306 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
307 307 }
308 308
309 309 status = write( fdSPW, incomingData, size );
310 310 if (status == -1){
311 311 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
312 312 }
313 313 }
314 314 else // the incoming message is a spw_ioctl_pkt_send structure
315 315 {
316 316 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
317 317 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
318 318 if (status == -1){
319 319 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
320 320 }
321 321 }
322 322 }
323 323
324 324 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
325 325
326 326 }
327 327 }
328 328
329 329 rtems_task wtdg_task( rtems_task_argument argument )
330 330 {
331 331 rtems_event_set event_out;
332 332 rtems_status_code status;
333 333 int linkStatus;
334 334
335 335 BOOT_PRINTF("in WTDG ***\n")
336 336
337 337 while(1)
338 338 {
339 339 // wait for an RTEMS_EVENT
340 340 rtems_event_receive( RTEMS_EVENT_0,
341 341 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
342 342 PRINTF("in WTDG *** wait for the link\n")
343 343 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
344 344 while( linkStatus != 5) // wait for the link
345 345 {
346 346 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
347 347 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 348 }
349 349
350 350 status = spacewire_stop_and_start_link( fdSPW );
351 351
352 352 if (status != RTEMS_SUCCESSFUL)
353 353 {
354 354 PRINTF1("in WTDG *** ERR link not started %d\n", status)
355 355 }
356 356 else
357 357 {
358 358 PRINTF("in WTDG *** OK link started\n")
359 359 }
360 360
361 361 // restart the SPIQ task
362 362 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
363 363 if ( status != RTEMS_SUCCESSFUL ) {
364 364 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
365 365 }
366 366
367 367 // restart RECV and SEND
368 368 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
369 369 if ( status != RTEMS_SUCCESSFUL ) {
370 370 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
371 371 }
372 372 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
373 373 if ( status != RTEMS_SUCCESSFUL ) {
374 374 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
375 375 }
376 376 }
377 377 }
378 378
379 379 //****************
380 380 // OTHER FUNCTIONS
381 381 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
382 382 {
383 383 /** This function opens the SpaceWire link.
384 384 *
385 385 * @return a valid file descriptor in case of success, -1 in case of a failure
386 386 *
387 387 */
388 388 rtems_status_code status;
389 389
390 390 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
391 391 if ( fdSPW < 0 ) {
392 392 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
393 393 }
394 394 else
395 395 {
396 396 status = RTEMS_SUCCESSFUL;
397 397 }
398 398
399 399 return status;
400 400 }
401 401
402 402 int spacewire_start_link( int fd )
403 403 {
404 404 rtems_status_code status;
405 405
406 406 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
407 407 // -1 default hardcoded driver timeout
408 408
409 409 return status;
410 410 }
411 411
412 412 int spacewire_stop_and_start_link( int fd )
413 413 {
414 414 rtems_status_code status;
415 415
416 416 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
417 417 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
418 418 // -1 default hardcoded driver timeout
419 419
420 420 return status;
421 421 }
422 422
423 423 int spacewire_configure_link( int fd )
424 424 {
425 425 /** This function configures the SpaceWire link.
426 426 *
427 427 * @return GR-RTEMS-DRIVER directive status codes:
428 428 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
429 429 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
430 430 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
431 431 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
432 432 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
433 433 * - 5 EIO - Error when writing to grswp hardware registers.
434 434 * - 2 ENOENT - No such file or directory
435 435 */
436 436
437 437 rtems_status_code status;
438 438
439 439 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
440 440 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
441 441
442 442 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
443 443 if (status!=RTEMS_SUCCESSFUL) {
444 444 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
445 445 }
446 446 //
447 447 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
448 448 if (status!=RTEMS_SUCCESSFUL) {
449 449 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
450 450 }
451 451 //
452 452 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
453 453 if (status!=RTEMS_SUCCESSFUL) {
454 454 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
455 455 }
456 456 //
457 457 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
458 458 if (status!=RTEMS_SUCCESSFUL) {
459 459 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
460 460 }
461 461 //
462 462 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
463 463 if (status!=RTEMS_SUCCESSFUL) {
464 464 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
465 465 }
466 466 //
467 467 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
468 468 if (status!=RTEMS_SUCCESSFUL) {
469 469 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
470 470 }
471 471 //
472 472 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
473 473 if (status!=RTEMS_SUCCESSFUL) {
474 474 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
475 475 }
476 476
477 477 return status;
478 478 }
479 479
480 480 int spacewire_reset_link( void )
481 481 {
482 482 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
483 483 *
484 484 * @return RTEMS directive status code:
485 485 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
486 486 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
487 487 *
488 488 */
489 489
490 490 rtems_status_code status_spw;
491 491 rtems_status_code status;
492 492 int i;
493 493
494 494 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
495 495 {
496 496 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
497 497
498 498 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
499 499
500 500 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
501 501
502 502 status_spw = spacewire_stop_and_start_link( fdSPW );
503 503 if ( status_spw != RTEMS_SUCCESSFUL )
504 504 {
505 505 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
506 506 }
507 507
508 508 if ( status_spw == RTEMS_SUCCESSFUL)
509 509 {
510 510 break;
511 511 }
512 512 }
513 513
514 514 return status_spw;
515 515 }
516 516
517 517 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
518 518 {
519 519 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
520 520 *
521 521 * @param val is the value, 0 or 1, used to set the value of the NP bit.
522 522 * @param regAddr is the address of the GRSPW control register.
523 523 *
524 524 * NP is the bit 20 of the GRSPW control register.
525 525 *
526 526 */
527 527
528 528 unsigned int *spwptr = (unsigned int*) regAddr;
529 529
530 530 if (val == 1) {
531 531 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
532 532 }
533 533 if (val== 0) {
534 534 *spwptr = *spwptr & 0xffdfffff;
535 535 }
536 536 }
537 537
538 538 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
539 539 {
540 540 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
541 541 *
542 542 * @param val is the value, 0 or 1, used to set the value of the RE bit.
543 543 * @param regAddr is the address of the GRSPW control register.
544 544 *
545 545 * RE is the bit 16 of the GRSPW control register.
546 546 *
547 547 */
548 548
549 549 unsigned int *spwptr = (unsigned int*) regAddr;
550 550
551 551 if (val == 1)
552 552 {
553 553 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
554 554 }
555 555 if (val== 0)
556 556 {
557 557 *spwptr = *spwptr & 0xfffdffff;
558 558 }
559 559 }
560 560
561 561 void spacewire_compute_stats_offsets( void )
562 562 {
563 563 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
564 564 *
565 565 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
566 566 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
567 567 * during the open systel call).
568 568 *
569 569 */
570 570
571 571 spw_stats spacewire_stats_grspw;
572 572 rtems_status_code status;
573 573
574 574 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
575 575
576 576 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
577 577 + spacewire_stats.packets_received;
578 578 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
579 579 + spacewire_stats.packets_sent;
580 580 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
581 581 + spacewire_stats.parity_err;
582 582 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
583 583 + spacewire_stats.disconnect_err;
584 584 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
585 585 + spacewire_stats.escape_err;
586 586 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
587 587 + spacewire_stats.credit_err;
588 588 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
589 589 + spacewire_stats.write_sync_err;
590 590 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
591 591 + spacewire_stats.rx_rmap_header_crc_err;
592 592 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
593 593 + spacewire_stats.rx_rmap_data_crc_err;
594 594 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
595 595 + spacewire_stats.early_ep;
596 596 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
597 597 + spacewire_stats.invalid_address;
598 598 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
599 599 + spacewire_stats.rx_eep_err;
600 600 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
601 601 + spacewire_stats.rx_truncated;
602 602 }
603 603
604 604 void spacewire_update_statistics( void )
605 605 {
606 606 rtems_status_code status;
607 607 spw_stats spacewire_stats_grspw;
608 608
609 609 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
610 610
611 611 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
612 612 + spacewire_stats_grspw.packets_received;
613 613 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
614 614 + spacewire_stats_grspw.packets_sent;
615 615 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
616 616 + spacewire_stats_grspw.parity_err;
617 617 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
618 618 + spacewire_stats_grspw.disconnect_err;
619 619 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
620 620 + spacewire_stats_grspw.escape_err;
621 621 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
622 622 + spacewire_stats_grspw.credit_err;
623 623 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
624 624 + spacewire_stats_grspw.write_sync_err;
625 625 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
626 626 + spacewire_stats_grspw.rx_rmap_header_crc_err;
627 627 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
628 628 + spacewire_stats_grspw.rx_rmap_data_crc_err;
629 629 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
630 630 + spacewire_stats_grspw.early_ep;
631 631 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
632 632 + spacewire_stats_grspw.invalid_address;
633 633 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
634 634 + spacewire_stats_grspw.rx_eep_err;
635 635 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
636 636 + spacewire_stats_grspw.rx_truncated;
637 637 //spacewire_stats.tx_link_err;
638 638
639 639 //****************************
640 640 // DPU_SPACEWIRE_IF_STATISTICS
641 641 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
642 642 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
643 643 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
644 644 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
645 645 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
646 646 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
647 647
648 648 //******************************************
649 649 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
650 650 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
651 651 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
652 652 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
653 653 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
654 654 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
655 655
656 656 //*********************************************
657 657 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
658 658 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
659 659 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
660 660 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
661 661 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
662 662 }
663 663
664 664 void increase_unsigned_char_counter( unsigned char *counter )
665 665 {
666 666 // update the number of valid timecodes that have been received
667 667 if (*counter == 255)
668 668 {
669 669 *counter = 0;
670 670 }
671 671 else
672 672 {
673 673 *counter = *counter + 1;
674 674 }
675 675 }
676 676
677 677 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
678 678 {
679 679
680 680 unsigned char currentTimecodeCtr;
681 681
682 682 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
683 683
684 684 if (currentTimecodeCtr == previousTimecodeCtr)
685 685 {
686 686 //************************
687 687 // HK_LFR_TIMECODE_MISSING
688 688 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
689 689 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
690 690 }
691 691 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
692 692 {
693 693 // the timecode value has changed and the value is valid, this is unexpected because
694 694 // the timer should not have fired, the timecode_irq_handler should have been raised
695 695 }
696 696 else
697 697 {
698 698 //************************
699 699 // HK_LFR_TIMECODE_INVALID
700 700 // the timecode value has changed and the value is not valid, no tickout has been generated
701 701 // this is why the timer has fired
702 702 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
703 703 }
704 704
705 705 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
706 706 }
707 707
708 708 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
709 709 {
710 /** This function checks the coherency between the incoming timecode and the last valid timecode.
711 *
712 * @param currentTimecodeCtr is the incoming timecode
713 *
714 * @return returned codes::
715 * - LFR_DEFAULT
716 * - LFR_SUCCESSFUL
717 *
718 */
719
710 720 static unsigned char firstTickout = 1;
711 721 unsigned char ret;
712 722
713 723 ret = LFR_DEFAULT;
714 724
715 725 if (firstTickout == 0)
716 726 {
717 727 if (currentTimecodeCtr == 0)
718 728 {
719 729 if (previousTimecodeCtr == 63)
720 730 {
721 731 ret = LFR_SUCCESSFUL;
722 732 }
723 733 else
724 734 {
725 735 ret = LFR_DEFAULT;
726 736 }
727 737 }
728 738 else
729 739 {
730 740 if (currentTimecodeCtr == (previousTimecodeCtr +1))
731 741 {
732 742 ret = LFR_SUCCESSFUL;
733 743 }
734 744 else
735 745 {
736 746 ret = LFR_DEFAULT;
737 747 }
738 748 }
739 749 }
740 750 else
741 751 {
742 752 firstTickout = 0;
743 753 ret = LFR_SUCCESSFUL;
744 754 }
745 755
746 756 return ret;
747 757 }
748 758
749 759 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
750 760 {
751 761 unsigned int ret;
752 762
753 763 ret = LFR_DEFAULT;
754 764
755 765 if (timecode == internalTime)
756 766 {
757 767 ret = LFR_SUCCESSFUL;
758 768 }
759 769 else
760 770 {
761 771 ret = LFR_DEFAULT;
762 772 }
763 773
764 774 return ret;
765 775 }
766 776
767 777 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
768 778 {
769 779 // a tickout has been emitted, perform actions on the incoming timecode
770 780
771 781 unsigned char incomingTimecode;
772 782 unsigned char updateTime;
773 783 unsigned char internalTime;
774 784 rtems_status_code status;
775 785
776 786 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
777 787 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
778 788 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
779 789
780 790 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
781 791
782 792 // update the number of tickout that have been generated
783 793 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
784 794
785 795 //**************************
786 796 // HK_LFR_TIMECODE_ERRONEOUS
787 797 // MISSING and INVALID are handled by the timecode_timer_routine service routine
788 798 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
789 799 {
790 800 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
791 801 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
792 802 }
793 803
794 804 //************************
795 805 // HK_LFR_TIME_TIMECODE_IT
796 806 // check the coherency between the SpaceWire timecode and the Internal Time
797 807 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
798 808 {
799 809 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
800 810 }
801 811
802 812 //********************
803 813 // HK_LFR_TIMECODE_CTR
804 814 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
805 815 if (incomingTimecode != updateTime)
806 816 {
807 817 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
808 818 }
809 819
810 820 // launch the timecode timer to detect missing or invalid timecodes
811 821 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
812 822 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
813 823 }
814 824
815 825 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
816 826 {
817 827 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
818 828 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
819 829 header->reserved = DEFAULT_RESERVED;
820 830 header->userApplication = CCSDS_USER_APP;
821 831 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
822 832 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
823 833 header->packetLength[0] = 0x00;
824 834 header->packetLength[1] = 0x00;
825 835 // DATA FIELD HEADER
826 836 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
827 837 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
828 838 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
829 839 header->destinationID = TM_DESTINATION_ID_GROUND;
830 840 header->time[0] = 0x00;
831 841 header->time[0] = 0x00;
832 842 header->time[0] = 0x00;
833 843 header->time[0] = 0x00;
834 844 header->time[0] = 0x00;
835 845 header->time[0] = 0x00;
836 846 // AUXILIARY DATA HEADER
837 847 header->sid = 0x00;
838 848 header->hkBIA = DEFAULT_HKBIA;
839 849 header->blkNr[0] = 0x00;
840 850 header->blkNr[1] = 0x00;
841 851 }
842 852
843 853 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
844 854 {
845 855 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
846 856 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
847 857 header->reserved = DEFAULT_RESERVED;
848 858 header->userApplication = CCSDS_USER_APP;
849 859 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
850 860 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
851 861 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
852 862 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
853 863 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
854 864 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
855 865 // DATA FIELD HEADER
856 866 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
857 867 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
858 868 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
859 869 header->destinationID = TM_DESTINATION_ID_GROUND;
860 870 header->time[0] = 0x00;
861 871 header->time[0] = 0x00;
862 872 header->time[0] = 0x00;
863 873 header->time[0] = 0x00;
864 874 header->time[0] = 0x00;
865 875 header->time[0] = 0x00;
866 876 // AUXILIARY DATA HEADER
867 877 header->sid = 0x00;
868 878 header->hkBIA = DEFAULT_HKBIA;
869 879 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
870 880 header->pktNr = 0x00;
871 881 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
872 882 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
873 883 }
874 884
875 885 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
876 886 {
877 887 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
878 888 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
879 889 header->reserved = DEFAULT_RESERVED;
880 890 header->userApplication = CCSDS_USER_APP;
881 891 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
882 892 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
883 893 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
884 894 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
885 895 header->packetLength[0] = 0x00;
886 896 header->packetLength[1] = 0x00;
887 897 // DATA FIELD HEADER
888 898 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
889 899 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
890 900 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
891 901 header->destinationID = TM_DESTINATION_ID_GROUND;
892 902 header->time[0] = 0x00;
893 903 header->time[0] = 0x00;
894 904 header->time[0] = 0x00;
895 905 header->time[0] = 0x00;
896 906 header->time[0] = 0x00;
897 907 header->time[0] = 0x00;
898 908 // AUXILIARY DATA HEADER
899 909 header->sid = 0x00;
900 910 header->biaStatusInfo = 0x00;
901 911 header->pa_lfr_pkt_cnt_asm = 0x00;
902 912 header->pa_lfr_pkt_nr_asm = 0x00;
903 913 header->pa_lfr_asm_blk_nr[0] = 0x00;
904 914 header->pa_lfr_asm_blk_nr[1] = 0x00;
905 915 }
906 916
907 917 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
908 918 Header_TM_LFR_SCIENCE_CWF_t *header )
909 919 {
910 920 /** This function sends CWF CCSDS packets (F2, F1 or F0).
911 921 *
912 922 * @param waveform points to the buffer containing the data that will be send.
913 923 * @param sid is the source identifier of the data that will be sent.
914 924 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
915 925 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
916 926 * contain information to setup the transmission of the data packets.
917 927 *
918 928 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
919 929 *
920 930 */
921 931
922 932 unsigned int i;
923 933 int ret;
924 934 unsigned int coarseTime;
925 935 unsigned int fineTime;
926 936 rtems_status_code status;
927 937 spw_ioctl_pkt_send spw_ioctl_send_CWF;
928 938 int *dataPtr;
929 939 unsigned char sid;
930 940
931 941 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
932 942 spw_ioctl_send_CWF.options = 0;
933 943
934 944 ret = LFR_DEFAULT;
935 945 sid = (unsigned char) ring_node_to_send->sid;
936 946
937 947 coarseTime = ring_node_to_send->coarseTime;
938 948 fineTime = ring_node_to_send->fineTime;
939 949 dataPtr = (int*) ring_node_to_send->buffer_address;
940 950
941 951 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
942 952 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
943 953 header->hkBIA = pa_bia_status_info;
944 954 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
945 955 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
946 956 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
947 957
948 958 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
949 959 {
950 960 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
951 961 spw_ioctl_send_CWF.hdr = (char*) header;
952 962 // BUILD THE DATA
953 963 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
954 964
955 965 // SET PACKET SEQUENCE CONTROL
956 966 increment_seq_counter_source_id( header->packetSequenceControl, sid );
957 967
958 968 // SET SID
959 969 header->sid = sid;
960 970
961 971 // SET PACKET TIME
962 972 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
963 973 //
964 974 header->time[0] = header->acquisitionTime[0];
965 975 header->time[1] = header->acquisitionTime[1];
966 976 header->time[2] = header->acquisitionTime[2];
967 977 header->time[3] = header->acquisitionTime[3];
968 978 header->time[4] = header->acquisitionTime[4];
969 979 header->time[5] = header->acquisitionTime[5];
970 980
971 981 // SET PACKET ID
972 982 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
973 983 {
974 984 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
975 985 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
976 986 }
977 987 else
978 988 {
979 989 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
980 990 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
981 991 }
982 992
983 993 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
984 994 if (status != RTEMS_SUCCESSFUL) {
985 995 ret = LFR_DEFAULT;
986 996 }
987 997 }
988 998
989 999 return ret;
990 1000 }
991 1001
992 1002 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
993 1003 Header_TM_LFR_SCIENCE_SWF_t *header )
994 1004 {
995 1005 /** This function sends SWF CCSDS packets (F2, F1 or F0).
996 1006 *
997 1007 * @param waveform points to the buffer containing the data that will be send.
998 1008 * @param sid is the source identifier of the data that will be sent.
999 1009 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1000 1010 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1001 1011 * contain information to setup the transmission of the data packets.
1002 1012 *
1003 1013 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1004 1014 *
1005 1015 */
1006 1016
1007 1017 unsigned int i;
1008 1018 int ret;
1009 1019 unsigned int coarseTime;
1010 1020 unsigned int fineTime;
1011 1021 rtems_status_code status;
1012 1022 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1013 1023 int *dataPtr;
1014 1024 unsigned char sid;
1015 1025
1016 1026 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1017 1027 spw_ioctl_send_SWF.options = 0;
1018 1028
1019 1029 ret = LFR_DEFAULT;
1020 1030
1021 1031 coarseTime = ring_node_to_send->coarseTime;
1022 1032 fineTime = ring_node_to_send->fineTime;
1023 1033 dataPtr = (int*) ring_node_to_send->buffer_address;
1024 1034 sid = ring_node_to_send->sid;
1025 1035
1026 1036 header->hkBIA = pa_bia_status_info;
1027 1037 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1028 1038
1029 1039 for (i=0; i<7; i++) // send waveform
1030 1040 {
1031 1041 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1032 1042 spw_ioctl_send_SWF.hdr = (char*) header;
1033 1043
1034 1044 // SET PACKET SEQUENCE CONTROL
1035 1045 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1036 1046
1037 1047 // SET PACKET LENGTH AND BLKNR
1038 1048 if (i == 6)
1039 1049 {
1040 1050 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1041 1051 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1042 1052 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1043 1053 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1044 1054 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1045 1055 }
1046 1056 else
1047 1057 {
1048 1058 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1049 1059 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1050 1060 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1051 1061 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1052 1062 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1053 1063 }
1054 1064
1055 1065 // SET PACKET TIME
1056 1066 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1057 1067 //
1058 1068 header->time[0] = header->acquisitionTime[0];
1059 1069 header->time[1] = header->acquisitionTime[1];
1060 1070 header->time[2] = header->acquisitionTime[2];
1061 1071 header->time[3] = header->acquisitionTime[3];
1062 1072 header->time[4] = header->acquisitionTime[4];
1063 1073 header->time[5] = header->acquisitionTime[5];
1064 1074
1065 1075 // SET SID
1066 1076 header->sid = sid;
1067 1077
1068 1078 // SET PKTNR
1069 1079 header->pktNr = i+1; // PKT_NR
1070 1080
1071 1081 // SEND PACKET
1072 1082 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1073 1083 if (status != RTEMS_SUCCESSFUL) {
1074 1084 ret = LFR_DEFAULT;
1075 1085 }
1076 1086 }
1077 1087
1078 1088 return ret;
1079 1089 }
1080 1090
1081 1091 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1082 1092 Header_TM_LFR_SCIENCE_CWF_t *header )
1083 1093 {
1084 1094 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1085 1095 *
1086 1096 * @param waveform points to the buffer containing the data that will be send.
1087 1097 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1088 1098 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1089 1099 * contain information to setup the transmission of the data packets.
1090 1100 *
1091 1101 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1092 1102 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1093 1103 *
1094 1104 */
1095 1105
1096 1106 unsigned int i;
1097 1107 int ret;
1098 1108 unsigned int coarseTime;
1099 1109 unsigned int fineTime;
1100 1110 rtems_status_code status;
1101 1111 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1102 1112 char *dataPtr;
1103 1113 unsigned char sid;
1104 1114
1105 1115 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1106 1116 spw_ioctl_send_CWF.options = 0;
1107 1117
1108 1118 ret = LFR_DEFAULT;
1109 1119 sid = ring_node_to_send->sid;
1110 1120
1111 1121 coarseTime = ring_node_to_send->coarseTime;
1112 1122 fineTime = ring_node_to_send->fineTime;
1113 1123 dataPtr = (char*) ring_node_to_send->buffer_address;
1114 1124
1115 1125 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1116 1126 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1117 1127 header->hkBIA = pa_bia_status_info;
1118 1128 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1119 1129 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1120 1130 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1121 1131
1122 1132 //*********************
1123 1133 // SEND CWF3_light DATA
1124 1134 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1125 1135 {
1126 1136 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1127 1137 spw_ioctl_send_CWF.hdr = (char*) header;
1128 1138 // BUILD THE DATA
1129 1139 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1130 1140
1131 1141 // SET PACKET SEQUENCE COUNTER
1132 1142 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1133 1143
1134 1144 // SET SID
1135 1145 header->sid = sid;
1136 1146
1137 1147 // SET PACKET TIME
1138 1148 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1139 1149 //
1140 1150 header->time[0] = header->acquisitionTime[0];
1141 1151 header->time[1] = header->acquisitionTime[1];
1142 1152 header->time[2] = header->acquisitionTime[2];
1143 1153 header->time[3] = header->acquisitionTime[3];
1144 1154 header->time[4] = header->acquisitionTime[4];
1145 1155 header->time[5] = header->acquisitionTime[5];
1146 1156
1147 1157 // SET PACKET ID
1148 1158 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1149 1159 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1150 1160
1151 1161 // SEND PACKET
1152 1162 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1153 1163 if (status != RTEMS_SUCCESSFUL) {
1154 1164 ret = LFR_DEFAULT;
1155 1165 }
1156 1166 }
1157 1167
1158 1168 return ret;
1159 1169 }
1160 1170
1161 1171 void spw_send_asm_f0( ring_node *ring_node_to_send,
1162 1172 Header_TM_LFR_SCIENCE_ASM_t *header )
1163 1173 {
1164 1174 unsigned int i;
1165 1175 unsigned int length = 0;
1166 1176 rtems_status_code status;
1167 1177 unsigned int sid;
1168 1178 float *spectral_matrix;
1169 1179 int coarseTime;
1170 1180 int fineTime;
1171 1181 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1172 1182
1173 1183 sid = ring_node_to_send->sid;
1174 1184 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1175 1185 coarseTime = ring_node_to_send->coarseTime;
1176 1186 fineTime = ring_node_to_send->fineTime;
1177 1187
1178 1188 header->biaStatusInfo = pa_bia_status_info;
1179 1189 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1180 1190
1181 1191 for (i=0; i<3; i++)
1182 1192 {
1183 1193 if ((i==0) || (i==1))
1184 1194 {
1185 1195 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1186 1196 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1187 1197 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1188 1198 ];
1189 1199 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1190 1200 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1191 1201 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1192 1202 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1193 1203 }
1194 1204 else
1195 1205 {
1196 1206 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1197 1207 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1198 1208 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1199 1209 ];
1200 1210 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1201 1211 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1202 1212 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1203 1213 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1204 1214 }
1205 1215
1206 1216 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1207 1217 spw_ioctl_send_ASM.hdr = (char *) header;
1208 1218 spw_ioctl_send_ASM.options = 0;
1209 1219
1210 1220 // (2) BUILD THE HEADER
1211 1221 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1212 1222 header->packetLength[0] = (unsigned char) (length>>8);
1213 1223 header->packetLength[1] = (unsigned char) (length);
1214 1224 header->sid = (unsigned char) sid; // SID
1215 1225 header->pa_lfr_pkt_cnt_asm = 3;
1216 1226 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1217 1227
1218 1228 // (3) SET PACKET TIME
1219 1229 header->time[0] = (unsigned char) (coarseTime>>24);
1220 1230 header->time[1] = (unsigned char) (coarseTime>>16);
1221 1231 header->time[2] = (unsigned char) (coarseTime>>8);
1222 1232 header->time[3] = (unsigned char) (coarseTime);
1223 1233 header->time[4] = (unsigned char) (fineTime>>8);
1224 1234 header->time[5] = (unsigned char) (fineTime);
1225 1235 //
1226 1236 header->acquisitionTime[0] = header->time[0];
1227 1237 header->acquisitionTime[1] = header->time[1];
1228 1238 header->acquisitionTime[2] = header->time[2];
1229 1239 header->acquisitionTime[3] = header->time[3];
1230 1240 header->acquisitionTime[4] = header->time[4];
1231 1241 header->acquisitionTime[5] = header->time[5];
1232 1242
1233 1243 // (4) SEND PACKET
1234 1244 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1235 1245 if (status != RTEMS_SUCCESSFUL) {
1236 1246 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1237 1247 }
1238 1248 }
1239 1249 }
1240 1250
1241 1251 void spw_send_asm_f1( ring_node *ring_node_to_send,
1242 1252 Header_TM_LFR_SCIENCE_ASM_t *header )
1243 1253 {
1244 1254 unsigned int i;
1245 1255 unsigned int length = 0;
1246 1256 rtems_status_code status;
1247 1257 unsigned int sid;
1248 1258 float *spectral_matrix;
1249 1259 int coarseTime;
1250 1260 int fineTime;
1251 1261 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1252 1262
1253 1263 sid = ring_node_to_send->sid;
1254 1264 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1255 1265 coarseTime = ring_node_to_send->coarseTime;
1256 1266 fineTime = ring_node_to_send->fineTime;
1257 1267
1258 1268 header->biaStatusInfo = pa_bia_status_info;
1259 1269 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1260 1270
1261 1271 for (i=0; i<3; i++)
1262 1272 {
1263 1273 if ((i==0) || (i==1))
1264 1274 {
1265 1275 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1266 1276 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1267 1277 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1268 1278 ];
1269 1279 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1270 1280 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1271 1281 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1272 1282 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1273 1283 }
1274 1284 else
1275 1285 {
1276 1286 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1277 1287 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1278 1288 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1279 1289 ];
1280 1290 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1281 1291 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1282 1292 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1283 1293 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1284 1294 }
1285 1295
1286 1296 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1287 1297 spw_ioctl_send_ASM.hdr = (char *) header;
1288 1298 spw_ioctl_send_ASM.options = 0;
1289 1299
1290 1300 // (2) BUILD THE HEADER
1291 1301 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1292 1302 header->packetLength[0] = (unsigned char) (length>>8);
1293 1303 header->packetLength[1] = (unsigned char) (length);
1294 1304 header->sid = (unsigned char) sid; // SID
1295 1305 header->pa_lfr_pkt_cnt_asm = 3;
1296 1306 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1297 1307
1298 1308 // (3) SET PACKET TIME
1299 1309 header->time[0] = (unsigned char) (coarseTime>>24);
1300 1310 header->time[1] = (unsigned char) (coarseTime>>16);
1301 1311 header->time[2] = (unsigned char) (coarseTime>>8);
1302 1312 header->time[3] = (unsigned char) (coarseTime);
1303 1313 header->time[4] = (unsigned char) (fineTime>>8);
1304 1314 header->time[5] = (unsigned char) (fineTime);
1305 1315 //
1306 1316 header->acquisitionTime[0] = header->time[0];
1307 1317 header->acquisitionTime[1] = header->time[1];
1308 1318 header->acquisitionTime[2] = header->time[2];
1309 1319 header->acquisitionTime[3] = header->time[3];
1310 1320 header->acquisitionTime[4] = header->time[4];
1311 1321 header->acquisitionTime[5] = header->time[5];
1312 1322
1313 1323 // (4) SEND PACKET
1314 1324 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1315 1325 if (status != RTEMS_SUCCESSFUL) {
1316 1326 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1317 1327 }
1318 1328 }
1319 1329 }
1320 1330
1321 1331 void spw_send_asm_f2( ring_node *ring_node_to_send,
1322 1332 Header_TM_LFR_SCIENCE_ASM_t *header )
1323 1333 {
1324 1334 unsigned int i;
1325 1335 unsigned int length = 0;
1326 1336 rtems_status_code status;
1327 1337 unsigned int sid;
1328 1338 float *spectral_matrix;
1329 1339 int coarseTime;
1330 1340 int fineTime;
1331 1341 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1332 1342
1333 1343 sid = ring_node_to_send->sid;
1334 1344 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1335 1345 coarseTime = ring_node_to_send->coarseTime;
1336 1346 fineTime = ring_node_to_send->fineTime;
1337 1347
1338 1348 header->biaStatusInfo = pa_bia_status_info;
1339 1349 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1340 1350
1341 1351 for (i=0; i<3; i++)
1342 1352 {
1343 1353
1344 1354 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1345 1355 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1346 1356 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1347 1357 ];
1348 1358 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1349 1359 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1350 1360 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1351 1361 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1352 1362
1353 1363 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1354 1364 spw_ioctl_send_ASM.hdr = (char *) header;
1355 1365 spw_ioctl_send_ASM.options = 0;
1356 1366
1357 1367 // (2) BUILD THE HEADER
1358 1368 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1359 1369 header->packetLength[0] = (unsigned char) (length>>8);
1360 1370 header->packetLength[1] = (unsigned char) (length);
1361 1371 header->sid = (unsigned char) sid; // SID
1362 1372 header->pa_lfr_pkt_cnt_asm = 3;
1363 1373 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1364 1374
1365 1375 // (3) SET PACKET TIME
1366 1376 header->time[0] = (unsigned char) (coarseTime>>24);
1367 1377 header->time[1] = (unsigned char) (coarseTime>>16);
1368 1378 header->time[2] = (unsigned char) (coarseTime>>8);
1369 1379 header->time[3] = (unsigned char) (coarseTime);
1370 1380 header->time[4] = (unsigned char) (fineTime>>8);
1371 1381 header->time[5] = (unsigned char) (fineTime);
1372 1382 //
1373 1383 header->acquisitionTime[0] = header->time[0];
1374 1384 header->acquisitionTime[1] = header->time[1];
1375 1385 header->acquisitionTime[2] = header->time[2];
1376 1386 header->acquisitionTime[3] = header->time[3];
1377 1387 header->acquisitionTime[4] = header->time[4];
1378 1388 header->acquisitionTime[5] = header->time[5];
1379 1389
1380 1390 // (4) SEND PACKET
1381 1391 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1382 1392 if (status != RTEMS_SUCCESSFUL) {
1383 1393 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1384 1394 }
1385 1395 }
1386 1396 }
1387 1397
1388 1398 void spw_send_k_dump( ring_node *ring_node_to_send )
1389 1399 {
1390 1400 rtems_status_code status;
1391 1401 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1392 1402 unsigned int packetLength;
1393 1403 unsigned int size;
1394 1404
1395 1405 PRINTF("spw_send_k_dump\n")
1396 1406
1397 1407 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1398 1408
1399 1409 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1400 1410
1401 1411 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1402 1412
1403 1413 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1404 1414
1405 1415 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1406 1416
1407 1417 if (status == -1){
1408 1418 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1409 1419 }
1410 1420
1411 1421 ring_node_to_send->status = 0x00;
1412 1422 }
General Comments 0
You need to be logged in to leave comments. Login now