##// END OF EJS Templates
New version of the waveform picker packet transmission...
paul -
r172:ddd72945217c VHDL_0_1_28
parent child
Show More
@@ -1,6 +1,6
1 #############################################################################
1 #############################################################################
2 # Makefile for building: bin/fsw
2 # Makefile for building: bin/fsw
3 # Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Nov 6 16:03:39 2014
3 # Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Nov 13 07:59:00 2014
4 # Project: fsw-qt.pro
4 # Project: fsw-qt.pro
5 # Template: app
5 # Template: app
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
6 # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro
@@ -10,7 +10,7
10
10
11 CC = sparc-rtems-gcc
11 CC = sparc-rtems-gcc
12 CXX = sparc-rtems-g++
12 CXX = sparc-rtems-g++
13 DEFINES = -DSW_VERSION_N1=2 -DSW_VERSION_N2=0 -DSW_VERSION_N3=1 -DSW_VERSION_N4=1 -DLPP_DPU_DESTID -DPRINT_MESSAGES_ON_CONSOLE -DPRINT_TASK_STATISTICS
13 DEFINES = -DSW_VERSION_N1=2 -DSW_VERSION_N2=0 -DSW_VERSION_N3=1 -DSW_VERSION_N4=1 -DLPP_DPU_DESTID -DPRINT_MESSAGES_ON_CONSOLE
14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
14 CFLAGS = -pipe -O3 -Wall $(DEFINES)
15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
15 CXXFLAGS = -pipe -O3 -Wall $(DEFINES)
16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header -I../header/processing -I../src/LFR_basic-parameters
16 INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header -I../header/processing -I../src/LFR_basic-parameters
@@ -2,7 +2,7 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 # lpp_dpu_destid
4 # lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
5 CONFIG += console verbose lpp_dpu_destid
6 CONFIG -= qt
6 CONFIG -= qt
7
7
8 include(./sparc.pri)
8 include(./sparc.pri)
@@ -1,6 +1,6
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE QtCreatorProject>
2 <!DOCTYPE QtCreatorProject>
3 <!-- Written by QtCreator 3.2.1, 2014-11-05T17:29:44. -->
3 <!-- Written by QtCreator 3.2.1, 2014-11-12T16:01:52. -->
4 <qtcreator>
4 <qtcreator>
5 <data>
5 <data>
6 <variable>EnvironmentId</variable>
6 <variable>EnvironmentId</variable>
@@ -34,7 +34,6 void getTime( unsigned char *time);
34 unsigned long long int getTimeAsUnsignedLongLongInt( );
34 unsigned long long int getTimeAsUnsignedLongLongInt( );
35 void send_dumb_hk( void );
35 void send_dumb_hk( void );
36 void get_v_e1_e2_f3(unsigned char *spacecraft_potential);
36 void get_v_e1_e2_f3(unsigned char *spacecraft_potential);
37 void get_v_e1_e2_f3_alt(unsigned char *spacecraft_potential);
38 void get_cpu_load( unsigned char *resource_statistics );
37 void get_cpu_load( unsigned char *resource_statistics );
39
38
40 extern int sched_yield( void );
39 extern int sched_yield( void );
@@ -14,6 +14,7 typedef struct ring_node
14 {
14 {
15 struct ring_node *previous;
15 struct ring_node *previous;
16 struct ring_node *next;
16 struct ring_node *next;
17 unsigned int sid;
17 unsigned int coarseTime;
18 unsigned int coarseTime;
18 unsigned int fineTime;
19 unsigned int fineTime;
19 int buffer_address;
20 int buffer_address;
@@ -12,6 +12,7
12 #define NB_RING_NODES_SM_F0 12 // AT LEAST 8 due to the way the averaging is done
12 #define NB_RING_NODES_SM_F0 12 // AT LEAST 8 due to the way the averaging is done
13 #define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3
13 #define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3
14 #define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3
14 #define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3
15 #define NB_RING_NODES_ASM_F0 3 // AT LEAST 3
15 #define NB_RING_NODES_SM_F1 12 // AT LEAST 8 due to the way the averaging is done
16 #define NB_RING_NODES_SM_F1 12 // AT LEAST 8 due to the way the averaging is done
16 #define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3
17 #define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3
17 #define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3
18 #define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3
@@ -31,6 +31,14 void spacewire_set_RE( unsigned char val
31 void spacewire_compute_stats_offsets( void );
31 void spacewire_compute_stats_offsets( void );
32 void spacewire_update_statistics( void );
32 void spacewire_update_statistics( void );
33
33
34 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header );
35 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header );
36 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header );
37 int spw_send_waveform_CWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
38 int spw_send_waveform_SWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_SWF_t *header );
39 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
40 void spw_send_asm( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
41
34 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
42 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
35 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data );
43 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data );
36
44
@@ -18,7 +18,7 rtems_task prc2_task( rtems_task_argumen
18 // FUNCTIONS
18 // FUNCTIONS
19
19
20 void reset_nb_sm_f2( void );
20 void reset_nb_sm_f2( void );
21 void SM_average_f2( float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 );
21 void SM_average_f2(float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 );
22
22
23 //*******
23 //*******
24 // EXTERN
24 // EXTERN
@@ -13,12 +13,12
13
13
14 typedef struct ring_node_sm
14 typedef struct ring_node_sm
15 {
15 {
16 struct ring_node_sm *previous;
16 struct ring_node_sm *previous;
17 struct ring_node_sm *next;
17 struct ring_node_sm *next;
18 int buffer_address;
18 int buffer_address;
19 unsigned int status;
19 unsigned int status;
20 unsigned int coarseTime;
20 unsigned int coarseTime;
21 unsigned int fineTime;
21 unsigned int fineTime;
22 } ring_node_sm;
22 } ring_node_sm;
23
23
24 typedef struct ring_node_asm
24 typedef struct ring_node_asm
@@ -73,7 +73,6 void reset_nb_sm( void );
73 // SM
73 // SM
74 void SM_init_rings( void );
74 void SM_init_rings( void );
75 void SM_reset_current_ring_nodes( void );
75 void SM_reset_current_ring_nodes( void );
76 void SM_generic_init_ring(ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] );
77 // ASM
76 // ASM
78 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
77 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
79 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header);
78 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header);
@@ -100,8 +99,8 void reset_sm_status( void );
100 void reset_spectral_matrix_regs( void );
99 void reset_spectral_matrix_regs( void );
101 void set_time(unsigned char *time, unsigned char *timeInBuffer );
100 void set_time(unsigned char *time, unsigned char *timeInBuffer );
102 unsigned long long int get_acquisition_time( unsigned char *timePtr );
101 unsigned long long int get_acquisition_time( unsigned char *timePtr );
103 void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
102 void close_matrix_actions( unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
104 ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time);
103 ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time );
105 unsigned char getSID( rtems_event_set event );
104 unsigned char getSID( rtems_event_set event );
106
105
107 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
106 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
@@ -109,7 +108,10 extern rtems_status_code get_message_que
109
108
110 //***************************************
109 //***************************************
111 // DEFINITIONS OF STATIC INLINE FUNCTIONS
110 // DEFINITIONS OF STATIC INLINE FUNCTIONS
112 static inline void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
111 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
112 ring_node_sm *ring_node_tab[],
113 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
114 static inline void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
113 ring_node_sm *ring_node_tab[],
115 ring_node_sm *ring_node_tab[],
114 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
116 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
115 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
117 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
@@ -119,7 +121,7 static inline void ASM_compress_reorgani
119 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
121 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
120 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
122 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
121
123
122 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
124 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
123 ring_node_sm *ring_node_tab[],
125 ring_node_sm *ring_node_tab[],
124 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
126 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
125 {
127 {
@@ -159,6 +161,39 void SM_average( float *averaged_spec_ma
159 }
161 }
160 }
162 }
161
163
164 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
165 ring_node_sm *ring_node_tab[],
166 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
167 {
168 float sum;
169 unsigned int i;
170
171 for(i=0; i<TOTAL_SIZE_SM; i++)
172 {
173 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
174
175 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
176 {
177 averaged_spec_mat_NORM[ i ] = sum;
178 averaged_spec_mat_SBM[ i ] = sum;
179 }
180 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
181 {
182 averaged_spec_mat_NORM[ i ] = sum;
183 averaged_spec_mat_SBM[ i ] = sum;
184 }
185 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
186 {
187 averaged_spec_mat_NORM[ i ] = sum;
188 averaged_spec_mat_SBM[ i ] = sum;
189 }
190 else
191 {
192 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
193 }
194 }
195 }
196
162 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
197 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
163 {
198 {
164 int frequencyBin;
199 int frequencyBin;
@@ -17,10 +17,10 extern int fdSPW;
17
17
18 //*****************
18 //*****************
19 // waveform buffers
19 // waveform buffers
20 extern volatile int wf_snap_f0[ ];
20 extern volatile int wf_buffer_f0[ ];
21 extern volatile int wf_snap_f1[ ];
21 extern volatile int wf_buffer_f1[ ];
22 extern volatile int wf_snap_f2[ ];
22 extern volatile int wf_buffer_f2[ ];
23 extern volatile int wf_cont_f3[ ];
23 extern volatile int wf_buffer_f3[ ];
24 extern char wf_cont_f3_light[ ];
24 extern char wf_cont_f3_light[ ];
25
25
26 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
26 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
@@ -52,17 +52,12 rtems_task swbd_task( rtems_task_argumen
52 //******************
52 //******************
53 // general functions
53 // general functions
54 void WFP_init_rings( void );
54 void WFP_init_rings( void );
55 void init_waveform_ring( ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] );
55 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
56 void WFP_reset_current_ring_nodes( void );
56 void WFP_reset_current_ring_nodes( void );
57 //
57 //
58 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF );
59 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
60 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
58 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
61 //
59 //
62 int send_waveform_SWF( ring_node *ring_node_to_send, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
60 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
63 int send_waveform_CWF( ring_node *ring_node_to_send, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
64 int send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
65 int send_ring_node_CWF( ring_node *ring_node_to_send );
66 //
61 //
67 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
62 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
68 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
63 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
@@ -37,10 +37,10 unsigned char lfrCurrentMode;
37 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
37 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
38 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
38 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
39 // F0 F1 F2 F3
39 // F0 F1 F2 F3
40 volatile int wf_snap_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
40 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_snap_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_snap_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_cont_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100)));
44 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100)));
45
45
46 //***********************************
46 //***********************************
@@ -321,7 +321,7 int create_all_tasks( void ) // create a
321 status = rtems_task_create(
321 status = rtems_task_create(
322 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
322 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
323 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
323 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
324 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
324 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
325 );
325 );
326 }
326 }
327 if (status == RTEMS_SUCCESSFUL) // WTDG
327 if (status == RTEMS_SUCCESSFUL) // WTDG
@@ -225,11 +225,11 rtems_task hous_task(rtems_task_argument
225
225
226 spacewire_update_statistics();
226 spacewire_update_statistics();
227
227
228 // get_v_e1_e2_f3_alt( housekeeping_packet.hk_lfr_sc_v_f3 );
228 // get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
229 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
229 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
230
230
231 // SEND PACKET
231 // SEND PACKET
232 status = rtems_message_queue_urgent( queue_id, &housekeeping_packet,
232 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
233 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
233 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
234 if (status != RTEMS_SUCCESSFUL) {
234 if (status != RTEMS_SUCCESSFUL) {
235 PRINTF1("in HOUS *** ERR send: %d\n", status)
235 PRINTF1("in HOUS *** ERR send: %d\n", status)
@@ -437,73 +437,12 void send_dumb_hk( void )
437
437
438 get_message_queue_id_send( &queue_id );
438 get_message_queue_id_send( &queue_id );
439
439
440 rtems_message_queue_urgent( queue_id, &dummy_hk_packet,
440 rtems_message_queue_send( queue_id, &dummy_hk_packet,
441 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
441 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
442 }
442 }
443
443
444 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
444 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
445 {
445 {
446 unsigned int coarseTime;
447 unsigned int acquisitionTime;
448 unsigned int deltaT = 0;
449 unsigned char *bufferPtr;
450
451 unsigned int offset_in_samples;
452 unsigned int offset_in_bytes;
453 unsigned char f3 = 16; // v, e1 and e2 will be picked up each second, f3 = 16 Hz
454
455 bufferPtr = NULL;
456
457 if (lfrCurrentMode == LFR_MODE_STANDBY)
458 {
459 spacecraft_potential[0] = 0x00;
460 spacecraft_potential[1] = 0x00;
461 spacecraft_potential[2] = 0x00;
462 spacecraft_potential[3] = 0x00;
463 spacecraft_potential[4] = 0x00;
464 spacecraft_potential[5] = 0x00;
465 }
466 else
467 {
468 coarseTime = time_management_regs->coarse_time & 0x7fffffff;
469 bufferPtr = (unsigned char*) current_ring_node_f3->buffer_address;
470 acquisitionTime = (unsigned int) ( ( bufferPtr[0] & 0x7f ) << 24 )
471 + (unsigned int) ( bufferPtr[1] << 16 )
472 + (unsigned int) ( bufferPtr[2] << 8 )
473 + (unsigned int) ( bufferPtr[3] );
474 if ( coarseTime > acquisitionTime )
475 {
476 deltaT = coarseTime - acquisitionTime;
477 offset_in_samples = (deltaT-1) * f3 ;
478 }
479 else if( coarseTime == acquisitionTime )
480 {
481 bufferPtr = (unsigned char*) current_ring_node_f3->previous->buffer_address; // pick up v e1 and e2 in the previous f3 buffer
482 offset_in_samples = NB_SAMPLES_PER_SNAPSHOT-1;
483 }
484 else
485 {
486 offset_in_samples = 0;
487 // PRINTF2("ERR *** in get_v_e1_e2_f3 *** coarseTime = %x, acquisitionTime = %x\n", coarseTime, acquisitionTime)
488 }
489
490 if ( offset_in_samples > (NB_SAMPLES_PER_SNAPSHOT - 1) )
491 {
492 // PRINTF1("ERR *** in get_v_e1_e2_f3 *** trying to read out of the buffer, counter = %d\n", offset_in_samples)
493 offset_in_samples = NB_SAMPLES_PER_SNAPSHOT -1;
494 }
495 offset_in_bytes = TIME_OFFSET_IN_BYTES + offset_in_samples * NB_WORDS_SWF_BLK * 4;
496 spacecraft_potential[0] = bufferPtr[ offset_in_bytes + 0];
497 spacecraft_potential[1] = bufferPtr[ offset_in_bytes + 1];
498 spacecraft_potential[2] = bufferPtr[ offset_in_bytes + 2];
499 spacecraft_potential[3] = bufferPtr[ offset_in_bytes + 3];
500 spacecraft_potential[4] = bufferPtr[ offset_in_bytes + 4];
501 spacecraft_potential[5] = bufferPtr[ offset_in_bytes + 5];
502 }
503 }
504
505 void get_v_e1_e2_f3_alt( unsigned char *spacecraft_potential )
506 {
507 unsigned long long int localTime_asLong;
446 unsigned long long int localTime_asLong;
508 unsigned long long int f3_0_AcquisitionTime_asLong;
447 unsigned long long int f3_0_AcquisitionTime_asLong;
509 unsigned long long int f3_1_AcquisitionTime_asLong;
448 unsigned long long int f3_1_AcquisitionTime_asLong;
@@ -16,6 +16,12
16 rtems_name semq_name;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
19 //***********
25 //***********
20 // RTEMS TASK
26 // RTEMS TASK
21 rtems_task spiq_task(rtems_task_argument unused)
27 rtems_task spiq_task(rtems_task_argument unused)
@@ -204,10 +210,23 rtems_task send_task( rtems_task_argumen
204
210
205 rtems_status_code status; // RTEMS status code
211 rtems_status_code status; // RTEMS status code
206 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
212 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
213 ring_node *incomingRingNodePtr;
214 int ring_node_address;
215 char *charPtr;
207 spw_ioctl_pkt_send *spw_ioctl_send;
216 spw_ioctl_pkt_send *spw_ioctl_send;
208 size_t size; // size of the incoming TC packet
217 size_t size; // size of the incoming TC packet
209 u_int32_t count;
218 u_int32_t count;
210 rtems_id queue_id;
219 rtems_id queue_id;
220 unsigned char sid;
221
222 incomingRingNodePtr = NULL;
223 ring_node_address = 0;
224 charPtr = (char *) &ring_node_address;
225 sid = 0;
226
227 init_header_cwf( &headerCWF );
228 init_header_swf( &headerSWF );
229 init_header_asm( &headerASM );
211
230
212 status = get_message_queue_id_send( &queue_id );
231 status = get_message_queue_id_send( &queue_id );
213 if (status != RTEMS_SUCCESSFUL)
232 if (status != RTEMS_SUCCESSFUL)
@@ -228,7 +247,40 rtems_task send_task( rtems_task_argumen
228 }
247 }
229 else
248 else
230 {
249 {
231 if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
250 if ( size == sizeof(ring_node*) )
251 {
252 charPtr[0] = incomingData[0];
253 charPtr[1] = incomingData[1];
254 charPtr[2] = incomingData[2];
255 charPtr[3] = incomingData[3];
256 incomingRingNodePtr = (ring_node*) ring_node_address;
257 sid = incomingRingNodePtr->sid;
258 // printf("sid = %d\n", incomingRingNodePtr->sid);
259 if ( (sid==SID_NORM_CWF_LONG_F3)
260 || (sid==SID_BURST_CWF_F2 )
261 || (sid==SID_SBM1_CWF_F1 )
262 || (sid==SID_SBM2_CWF_F2 ))
263 {
264 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
265 }
266 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
267 {
268 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
269 }
270 else if ( (sid==SID_NORM_CWF_F3) )
271 {
272 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
273 }
274 else if ( (sid==SID_NORM_ASM_F0) || (SID_NORM_ASM_F1) || (SID_NORM_ASM_F2) )
275 {
276 spw_send_asm( incomingRingNodePtr, &headerASM );
277 }
278 else
279 {
280 printf("unexpected sid = %d\n", sid);
281 }
282 }
283 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
232 {
284 {
233 status = write( fdSPW, incomingData, size );
285 status = write( fdSPW, incomingData, size );
234 if (status == -1){
286 if (status == -1){
@@ -240,6 +292,13 rtems_task send_task( rtems_task_argumen
240 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
292 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
241 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
242 if (status == -1){
294 if (status == -1){
295 printf("size = %d, %x, %x, %x, %x, %x\n",
296 size,
297 incomingData[0],
298 incomingData[1],
299 incomingData[2],
300 incomingData[3],
301 incomingData[4]);
243 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
302 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
244 }
303 }
245 }
304 }
@@ -393,7 +452,7 int spacewire_configure_link( int fd )
393 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
452 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
394 }
453 }
395 //
454 //
396 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
455 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
397 if (status!=RTEMS_SUCCESSFUL) {
456 if (status!=RTEMS_SUCCESSFUL) {
398 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
457 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
399 }
458 }
@@ -622,3 +681,423 rtems_timer_service_routine user_routine
622 status = RTEMS_SUCCESSFUL;
681 status = RTEMS_SUCCESSFUL;
623 }
682 }
624 }
683 }
684
685 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
686 {
687 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
688 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
689 header->reserved = DEFAULT_RESERVED;
690 header->userApplication = CCSDS_USER_APP;
691 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
692 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
693 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
694 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
695 // DATA FIELD HEADER
696 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
697 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
698 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
699 header->destinationID = TM_DESTINATION_ID_GROUND;
700 header->time[0] = 0x00;
701 header->time[0] = 0x00;
702 header->time[0] = 0x00;
703 header->time[0] = 0x00;
704 header->time[0] = 0x00;
705 header->time[0] = 0x00;
706 // AUXILIARY DATA HEADER
707 header->sid = 0x00;
708 header->hkBIA = DEFAULT_HKBIA;
709 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
710 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
711 }
712
713 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
714 {
715 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
716 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
717 header->reserved = DEFAULT_RESERVED;
718 header->userApplication = CCSDS_USER_APP;
719 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
720 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
721 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
722 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
723 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
724 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
725 // DATA FIELD HEADER
726 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
727 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
728 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
729 header->destinationID = TM_DESTINATION_ID_GROUND;
730 header->time[0] = 0x00;
731 header->time[0] = 0x00;
732 header->time[0] = 0x00;
733 header->time[0] = 0x00;
734 header->time[0] = 0x00;
735 header->time[0] = 0x00;
736 // AUXILIARY DATA HEADER
737 header->sid = 0x00;
738 header->hkBIA = DEFAULT_HKBIA;
739 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
740 header->pktNr = 0x00;
741 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
742 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
743 }
744
745 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
746 {
747 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
748 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
749 header->reserved = DEFAULT_RESERVED;
750 header->userApplication = CCSDS_USER_APP;
751 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
752 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
753 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
754 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
755 header->packetLength[0] = 0x00;
756 header->packetLength[1] = 0x00;
757 // DATA FIELD HEADER
758 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
759 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
760 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
761 header->destinationID = TM_DESTINATION_ID_GROUND;
762 header->time[0] = 0x00;
763 header->time[0] = 0x00;
764 header->time[0] = 0x00;
765 header->time[0] = 0x00;
766 header->time[0] = 0x00;
767 header->time[0] = 0x00;
768 // AUXILIARY DATA HEADER
769 header->sid = 0x00;
770 header->biaStatusInfo = 0x00;
771 header->pa_lfr_pkt_cnt_asm = 0x00;
772 header->pa_lfr_pkt_nr_asm = 0x00;
773 header->pa_lfr_asm_blk_nr[0] = 0x00;
774 header->pa_lfr_asm_blk_nr[1] = 0x00;
775 }
776
777 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
778 Header_TM_LFR_SCIENCE_CWF_t *header )
779 {
780 /** This function sends CWF CCSDS packets (F2, F1 or F0).
781 *
782 * @param waveform points to the buffer containing the data that will be send.
783 * @param sid is the source identifier of the data that will be sent.
784 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
785 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
786 * contain information to setup the transmission of the data packets.
787 *
788 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
789 *
790 */
791
792 unsigned int i;
793 int ret;
794 unsigned int coarseTime;
795 unsigned int fineTime;
796 rtems_status_code status;
797 spw_ioctl_pkt_send spw_ioctl_send_CWF;
798 int *dataPtr;
799 unsigned char sid;
800
801 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
802 spw_ioctl_send_CWF.options = 0;
803
804 ret = LFR_DEFAULT;
805 sid = (unsigned char) ring_node_to_send->sid;
806
807 coarseTime = ring_node_to_send->coarseTime;
808 fineTime = ring_node_to_send->fineTime;
809 dataPtr = (int*) ring_node_to_send->buffer_address;
810
811 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
812 {
813 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
814 spw_ioctl_send_CWF.hdr = (char*) header;
815 // BUILD THE DATA
816 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
817
818 // SET PACKET SEQUENCE CONTROL
819 increment_seq_counter_source_id( header->packetSequenceControl, sid );
820
821 // SET SID
822 header->sid = sid;
823
824 // SET PACKET TIME
825 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
826 //
827 header->time[0] = header->acquisitionTime[0];
828 header->time[1] = header->acquisitionTime[1];
829 header->time[2] = header->acquisitionTime[2];
830 header->time[3] = header->acquisitionTime[3];
831 header->time[4] = header->acquisitionTime[4];
832 header->time[5] = header->acquisitionTime[5];
833
834 // SET PACKET ID
835 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
836 {
837 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
838 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
839 }
840 else
841 {
842 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
843 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
844 }
845
846 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
847 if (status != RTEMS_SUCCESSFUL) {
848 printf("%d-%d, ERR %d\n", sid, i, (int) status);
849 ret = LFR_DEFAULT;
850 }
851 }
852
853 return ret;
854 }
855
856 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
857 Header_TM_LFR_SCIENCE_SWF_t *header )
858 {
859 /** This function sends SWF CCSDS packets (F2, F1 or F0).
860 *
861 * @param waveform points to the buffer containing the data that will be send.
862 * @param sid is the source identifier of the data that will be sent.
863 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
864 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
865 * contain information to setup the transmission of the data packets.
866 *
867 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
868 *
869 */
870
871 unsigned int i;
872 int ret;
873 unsigned int coarseTime;
874 unsigned int fineTime;
875 rtems_status_code status;
876 spw_ioctl_pkt_send spw_ioctl_send_SWF;
877 int *dataPtr;
878 unsigned char sid;
879
880 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
881 spw_ioctl_send_SWF.options = 0;
882
883 ret = LFR_DEFAULT;
884
885 coarseTime = ring_node_to_send->coarseTime;
886 fineTime = ring_node_to_send->fineTime;
887 dataPtr = (int*) ring_node_to_send->buffer_address;
888 sid = ring_node_to_send->sid;
889
890 for (i=0; i<7; i++) // send waveform
891 {
892 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
893 spw_ioctl_send_SWF.hdr = (char*) header;
894
895 // SET PACKET SEQUENCE CONTROL
896 increment_seq_counter_source_id( header->packetSequenceControl, sid );
897
898 // SET PACKET LENGTH AND BLKNR
899 if (i == 6)
900 {
901 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
902 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
903 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
904 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
905 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
906 }
907 else
908 {
909 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
910 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
911 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
912 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
913 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
914 }
915
916 // SET PACKET TIME
917 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
918 //
919 header->time[0] = header->acquisitionTime[0];
920 header->time[1] = header->acquisitionTime[1];
921 header->time[2] = header->acquisitionTime[2];
922 header->time[3] = header->acquisitionTime[3];
923 header->time[4] = header->acquisitionTime[4];
924 header->time[5] = header->acquisitionTime[5];
925
926 // SET SID
927 header->sid = sid;
928
929 // SET PKTNR
930 header->pktNr = i+1; // PKT_NR
931
932 // SEND PACKET
933 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
934 if (status != RTEMS_SUCCESSFUL) {
935 printf("%d-%d, ERR %d\n", sid, i, (int) status);
936 ret = LFR_DEFAULT;
937 }
938 }
939
940 return ret;
941 }
942