##// END OF EJS Templates
sync
paul -
r182:4c7c1d90c7d1 VHDL_0_1_28
parent child
Show More
@@ -1,2 +1,2
1 a0aa2c6f13574ae69c8645af2a2afa5d448e6c76 LFR_basic-parameters
2 a8668a35669295aaba22432d247158626f00a52a header/lfr_common_headers
1 0f2eb26d750be2b6d8a3f5dee479b4575d3b93be LFR_basic-parameters
2 95a8d83f1d0c59f28a679e66e23464f21c12dd8a header/lfr_common_headers
@@ -1,47 +1,48
1 1 #ifndef FSW_MISC_H_INCLUDED
2 2 #define FSW_MISC_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6 #include <grspw.h>
7 7 #include <grlib_regs.h>
8 8
9 9 #include "fsw_params.h"
10 10 #include "fsw_spacewire.h"
11 11 #include "lfr_cpu_usage_report.h"
12 12
13 13 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
14 14 rtems_id HK_id; // id of the HK rate monotonic period
15 15
16 16 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
17 17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
18 18 void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
19 19 void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
20 20 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
21 21
22 22 // SERIAL LINK
23 23 int send_console_outputs_on_apbuart_port( void );
24 24 int enable_apbuart_transmitter( void );
25 25 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
26 26
27 27 // RTEMS TASKS
28 28 rtems_task stat_task( rtems_task_argument argument );
29 29 rtems_task hous_task( rtems_task_argument argument );
30 30 rtems_task dumb_task( rtems_task_argument unused );
31 31
32 32 void init_housekeeping_parameters( void );
33 33 void increment_seq_counter(unsigned short *packetSequenceControl);
34 34 void getTime( unsigned char *time);
35 35 unsigned long long int getTimeAsUnsignedLongLongInt( );
36 36 void send_dumb_hk( void );
37 void get_v_e1_e2_f3(unsigned char *spacecraft_potential);
37 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
38 void get_temperatures( unsigned char *temperatures );
38 39 void get_cpu_load( unsigned char *resource_statistics );
39 40
40 41 extern int sched_yield( void );
41 42 extern void rtems_cpu_usage_reset();
42 43 extern ring_node *current_ring_node_f3;
43 44 extern ring_node *ring_node_to_send_cwf_f3;
44 45 extern ring_node waveform_ring_f3[];
45 46 extern unsigned short sequenceCounterHK;
46 47
47 48 #endif // FSW_MISC_H_INCLUDED
@@ -1,128 +1,131
1 1 #ifndef GRLIB_REGS_H_INCLUDED
2 2 #define GRLIB_REGS_H_INCLUDED
3 3
4 4 #define NB_GPTIMER 3
5 5
6 6 struct apbuart_regs_str{
7 7 volatile unsigned int data;
8 8 volatile unsigned int status;
9 9 volatile unsigned int ctrl;
10 10 volatile unsigned int scaler;
11 11 volatile unsigned int fifoDebug;
12 12 };
13 13
14 14 struct grgpio_regs_str{
15 15 volatile int io_port_data_register;
16 16 int io_port_output_register;
17 17 int io_port_direction_register;
18 18 int interrupt_mak_register;
19 19 int interrupt_polarity_register;
20 20 int interrupt_edge_register;
21 21 int bypass_register;
22 22 int reserved;
23 23 // 0x20-0x3c interrupt map register(s)
24 24 };
25 25
26 26 typedef struct {
27 27 volatile unsigned int counter;
28 28 volatile unsigned int reload;
29 29 volatile unsigned int ctrl;
30 30 volatile unsigned int unused;
31 31 } timer_regs_t;
32 32
33 33 typedef struct {
34 34 volatile unsigned int scaler_value;
35 35 volatile unsigned int scaler_reload;
36 36 volatile unsigned int conf;
37 37 volatile unsigned int unused0;
38 38 timer_regs_t timer[NB_GPTIMER];
39 39 } gptimer_regs_t;
40 40
41 41 typedef struct {
42 42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 43 // bit 1 is the soft reset for the time management module
44 44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
45 45 volatile int coarse_time_load;
46 46 volatile int coarse_time;
47 47 volatile int fine_time;
48 volatile int temp_scm;
49 volatile int temp_pcb;
50 volatile int temp_fpga;
48 51 } time_management_regs_t;
49 52
50 53 // PDB >= 0.1.28
51 54 typedef struct{
52 55 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
53 56 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
54 57 int addr_data_f0_0; // 0x08
55 58 int addr_data_f0_1; // 0x0c
56 59 int addr_data_f1_0; // 0x10
57 60 int addr_data_f1_1; // 0x14
58 61 int addr_data_f2_0; // 0x18
59 62 int addr_data_f2_1; // 0x1c
60 63 int addr_data_f3_0; // 0x20
61 64 int addr_data_f3_1; // 0x24
62 65 volatile int status; // 0x28
63 66 int delta_snapshot; // 0x2c
64 67 int delta_f0; // 0x30
65 68 int delta_f0_2; // 0x34
66 69 int delta_f1; // 0x38
67 70 int delta_f2; // 0x3c
68 71 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
69 72 int snapshot_param; // 0x44
70 73 int start_date; // 0x48
71 74 //
72 75 volatile unsigned int f0_0_coarse_time; // 0x4c
73 76 volatile unsigned int f0_0_fine_time; // 0x50
74 77 volatile unsigned int f0_1_coarse_time; // 0x54
75 78 volatile unsigned int f0_1_fine_time; // 0x58
76 79 //
77 80 volatile unsigned int f1_0_coarse_time; // 0x5c
78 81 volatile unsigned int f1_0_fine_time; // 0x60
79 82 volatile unsigned int f1_1_coarse_time; // 0x64
80 83 volatile unsigned int f1_1_fine_time; // 0x68
81 84 //
82 85 volatile unsigned int f2_0_coarse_time; // 0x6c
83 86 volatile unsigned int f2_0_fine_time; // 0x70
84 87 volatile unsigned int f2_1_coarse_time; // 0x74
85 88 volatile unsigned int f2_1_fine_time; // 0x78
86 89 //
87 90 volatile unsigned int f3_0_coarse_time; // 0x7c
88 91 volatile unsigned int f3_0_fine_time; // 0x80
89 92 volatile unsigned int f3_1_coarse_time; // 0x84
90 93 volatile unsigned int f3_1_fine_time; // 0x88
91 94 //
92 95 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
93 96 //
94 97 volatile unsigned int v; // 0x90
95 98 volatile unsigned int e1; // 0x94
96 99 volatile unsigned int e2; // 0x98
97 100 } waveform_picker_regs_0_1_18_t;
98 101
99 102 typedef struct {
100 103 volatile int config; // 0x00
101 104 volatile int status; // 0x04
102 105 volatile int f0_0_address; // 0x08
103 106 volatile int f0_1_address; // 0x0C
104 107 //
105 108 volatile int f1_0_address; // 0x10
106 109 volatile int f1_1_address; // 0x14
107 110 volatile int f2_0_address; // 0x18
108 111 volatile int f2_1_address; // 0x1C
109 112 //
110 113 volatile unsigned int f0_0_coarse_time; // 0x20
111 114 volatile unsigned int f0_0_fine_time; // 0x24
112 115 volatile unsigned int f0_1_coarse_time; // 0x28
113 116 volatile unsigned int f0_1_fine_time; // 0x2C
114 117 //
115 118 volatile unsigned int f1_0_coarse_time; // 0x30
116 119 volatile unsigned int f1_0_fine_time; // 0x34
117 120 volatile unsigned int f1_1_coarse_time; // 0x38
118 121 volatile unsigned int f1_1_fine_time; // 0x3C
119 122 //
120 123 volatile unsigned int f2_0_coarse_time; // 0x40
121 124 volatile unsigned int f2_0_fine_time; // 0x44
122 125 volatile unsigned int f2_1_coarse_time; // 0x48
123 126 volatile unsigned int f2_1_fine_time; // 0x4C
124 127 //
125 128 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
126 129 } spectral_matrix_regs_t;
127 130
128 131 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,317 +1,321
1 1 #ifndef FSW_PROCESSING_H_INCLUDED
2 2 #define FSW_PROCESSING_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <math.h>
7 7 #include <stdlib.h> // abs() is in the stdlib
8 8 #include <stdio.h> // printf()
9 9 #include <math.h>
10 10 #include <grlib_regs.h>
11 11
12 12 #include "fsw_params.h"
13 13 #include "fsw_spacewire.h"
14 14
15 15 typedef struct ring_node_asm
16 16 {
17 17 struct ring_node_asm *next;
18 18 float matrix[ TOTAL_SIZE_SM ];
19 19 unsigned int status;
20 20 } ring_node_asm;
21 21
22 22 typedef struct
23 23 {
24 24 unsigned char targetLogicalAddress;
25 25 unsigned char protocolIdentifier;
26 26 unsigned char reserved;
27 27 unsigned char userApplication;
28 28 unsigned char packetID[2];
29 29 unsigned char packetSequenceControl[2];
30 30 unsigned char packetLength[2];
31 31 // DATA FIELD HEADER
32 32 unsigned char spare1_pusVersion_spare2;
33 33 unsigned char serviceType;
34 34 unsigned char serviceSubType;
35 35 unsigned char destinationID;
36 36 unsigned char time[6];
37 37 // AUXILIARY HEADER
38 38 unsigned char sid;
39 39 unsigned char biaStatusInfo;
40 40 unsigned char acquisitionTime[6];
41 41 unsigned char pa_lfr_bp_blk_nr[2];
42 42 // SOURCE DATA
43 43 unsigned char data[ 780 ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
44 44 } bp_packet;
45 45
46 46 typedef struct
47 47 {
48 48 unsigned char targetLogicalAddress;
49 49 unsigned char protocolIdentifier;
50 50 unsigned char reserved;
51 51 unsigned char userApplication;
52 52 unsigned char packetID[2];
53 53 unsigned char packetSequenceControl[2];
54 54 unsigned char packetLength[2];
55 55 // DATA FIELD HEADER
56 56 unsigned char spare1_pusVersion_spare2;
57 57 unsigned char serviceType;
58 58 unsigned char serviceSubType;
59 59 unsigned char destinationID;
60 60 unsigned char time[6];
61 61 // AUXILIARY HEADER
62 62 unsigned char sid;
63 63 unsigned char biaStatusInfo;
64 64 unsigned char acquisitionTime[6];
65 65 unsigned char source_data_spare;
66 66 unsigned char pa_lfr_bp_blk_nr[2];
67 67 // SOURCE DATA
68 68 unsigned char data[ 117 ]; // 13 bins * 9 Bytes only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
69 69 } bp_packet_with_spare;
70 70
71 71 typedef struct
72 72 {
73 73 ring_node_asm *norm;
74 74 ring_node_asm *burst_sbm;
75 75 rtems_event_set event;
76 76 unsigned int coarseTimeNORM;
77 77 unsigned int fineTimeNORM;
78 78 unsigned int coarseTimeSBM;
79 79 unsigned int fineTimeSBM;
80 80 } asm_msg;
81 81
82 82 extern volatile int sm_f0[ ];
83 83 extern volatile int sm_f1[ ];
84 84 extern volatile int sm_f2[ ];
85 85
86 86 // parameters
87 87 extern struct param_local_str param_local;
88 88
89 89 // registers
90 90 extern time_management_regs_t *time_management_regs;
91 91 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
92 92
93 93 extern rtems_name misc_name[5];
94 94 extern rtems_id Task_id[20]; /* array of task ids */
95 95
96 96 //
97 97 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
98 98 // ISR
99 99 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
100 100 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
101 101
102 102 //******************
103 103 // Spectral Matrices
104 104 void reset_nb_sm( void );
105 105 // SM
106 106 void SM_init_rings( void );
107 107 void SM_reset_current_ring_nodes( void );
108 108 // ASM
109 109 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
110 110
111 111 //*****************
112 112 // Basic Parameters
113 113
114 114 void BP_reset_current_ring_nodes( void );
115 115 void BP_init_header(bp_packet *packet,
116 116 unsigned int apid, unsigned char sid,
117 117 unsigned int packetLength , unsigned char blkNr);
118 118 void BP_init_header_with_spare(bp_packet_with_spare *packet,
119 119 unsigned int apid, unsigned char sid,
120 120 unsigned int packetLength, unsigned char blkNr );
121 121 void BP_send( char *data,
122 122 rtems_id queue_id ,
123 123 unsigned int nbBytesToSend , unsigned int sid );
124 124
125 125 //******************
126 126 // general functions
127 127 void reset_sm_status( void );
128 128 void reset_spectral_matrix_regs( void );
129 129 void set_time(unsigned char *time, unsigned char *timeInBuffer );
130 130 unsigned long long int get_acquisition_time( unsigned char *timePtr );
131 131 unsigned char getSID( rtems_event_set event );
132 132
133 133 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
134 134 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
135 135
136 136 //***************************************
137 137 // DEFINITIONS OF STATIC INLINE FUNCTIONS
138 138 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
139 139 ring_node *ring_node_tab[],
140 140 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
141 141 asm_msg *msgForMATR );
142 142 static inline void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
143 143 ring_node *ring_node_tab[],
144 144 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
145
146 void ASM_patch( float *inputASM, float *outputASM );
147 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
148
145 149 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
146 150 float divider );
147 151 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
148 152 float divider,
149 153 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
150 154 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
151 155
152 156 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
153 157 ring_node *ring_node_tab[],
154 158 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
155 159 asm_msg *msgForMATR )
156 160 {
157 161 float sum;
158 162 unsigned int i;
159 163
160 164 for(i=0; i<TOTAL_SIZE_SM; i++)
161 165 {
162 166 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
163 167 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
164 168 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
165 169 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
166 170 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
167 171 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
168 172 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
169 173 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
170 174
171 175 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
172 176 {
173 177 averaged_spec_mat_NORM[ i ] = sum;
174 178 averaged_spec_mat_SBM[ i ] = sum;
175 179 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
176 180 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
177 181 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
178 182 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
179 183 }
180 184 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
181 185 {
182 186 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
183 187 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
184 188 }
185 189 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
186 190 {
187 191 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
188 192 averaged_spec_mat_SBM[ i ] = sum;
189 193 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
190 194 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
191 195 }
192 196 else
193 197 {
194 198 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
195 199 }
196 200 }
197 201 }
198 202
199 203 void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
200 204 ring_node *ring_node_tab[],
201 205 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
202 206 {
203 207 float sum;
204 208 unsigned int i;
205 209
206 210 for(i=0; i<TOTAL_SIZE_SM; i++)
207 211 {
208 212 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ];
209 213
210 214 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
211 215 {
212 216 averaged_spec_mat_NORM[ i ] = sum;
213 217 averaged_spec_mat_SBM[ i ] = sum;
214 218 }
215 219 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
216 220 {
217 221 averaged_spec_mat_NORM[ i ] = sum;
218 222 averaged_spec_mat_SBM[ i ] = sum;
219 223 }
220 224 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
221 225 {
222 226 averaged_spec_mat_NORM[ i ] = sum;
223 227 averaged_spec_mat_SBM[ i ] = sum;
224 228 }
225 229 else
226 230 {
227 231 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
228 232 }
229 233 }
230 234 }
231 235
232 236 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
233 237 {
234 238 int frequencyBin;
235 239 int asmComponent;
236 240 unsigned int offsetASM;
237 241 unsigned int offsetASMReorganized;
238 242
239 243 // BUILD DATA
240 244 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
241 245 {
242 246 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
243 247 {
244 248 offsetASMReorganized =
245 249 frequencyBin * NB_VALUES_PER_SM
246 250 + asmComponent;
247 251 offsetASM =
248 252 asmComponent * NB_BINS_PER_SM
249 253 + frequencyBin;
250 254 averaged_spec_mat_reorganized[offsetASMReorganized ] =
251 255 averaged_spec_mat[ offsetASM ] / divider;
252 256 }
253 257 }
254 258 }
255 259
256 260 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
257 261 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
258 262 {
259 263 int frequencyBin;
260 264 int asmComponent;
261 265 int offsetASM;
262 266 int offsetCompressed;
263 267 int k;
264 268
265 269 // BUILD DATA
266 270 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
267 271 {
268 272 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
269 273 {
270 274 offsetCompressed = // NO TIME OFFSET
271 275 frequencyBin * NB_VALUES_PER_SM
272 276 + asmComponent;
273 277 offsetASM = // NO TIME OFFSET
274 278 asmComponent * NB_BINS_PER_SM
275 279 + ASMIndexStart
276 280 + frequencyBin * nbBinsToAverage;
277 281 compressed_spec_mat[ offsetCompressed ] = 0;
278 282 for ( k = 0; k < nbBinsToAverage; k++ )
279 283 {
280 284 compressed_spec_mat[offsetCompressed ] =
281 285 ( compressed_spec_mat[ offsetCompressed ]
282 286 + averaged_spec_mat[ offsetASM + k ] );
283 287 }
284 288 compressed_spec_mat[ offsetCompressed ] =
285 289 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
286 290 }
287 291 }
288 292 }
289 293
290 294 void ASM_convert( volatile float *input_matrix, char *output_matrix)
291 295 {
292 296 unsigned int frequencyBin;
293 297 unsigned int asmComponent;
294 298 char * pt_char_input;
295 299 char * pt_char_output;
296 300 unsigned int offsetInput;
297 301 unsigned int offsetOutput;
298 302
299 303 pt_char_input = (char*) &input_matrix;
300 304 pt_char_output = (char*) &output_matrix;
301 305
302 306 // convert all other data
303 307 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
304 308 {
305 309 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
306 310 {
307 311 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
308 312 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
309 313 pt_char_input = (char*) &input_matrix [ offsetInput ];
310 314 pt_char_output = (char*) &output_matrix[ offsetOutput ];
311 315 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
312 316 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
313 317 }
314 318 }
315 319 }
316 320
317 321 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,810 +1,810
1 1 /** This is the RTEMS initialization module.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * This module contains two very different information:
7 7 * - specific instructions to configure the compilation of the RTEMS executive
8 8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 9 *
10 10 */
11 11
12 12 //*************************
13 13 // GPL reminder to be added
14 14 //*************************
15 15
16 16 #include <rtems.h>
17 17
18 18 /* configuration information */
19 19
20 20 #define CONFIGURE_INIT
21 21
22 22 #include <bsp.h> /* for device driver prototypes */
23 23
24 24 /* configuration information */
25 25
26 26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28 28
29 29 #define CONFIGURE_MAXIMUM_TASKS 20
30 30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
39 39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 40 #ifdef PRINT_STACK_REPORT
41 41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 42 #endif
43 43
44 44 #include <rtems/confdefs.h>
45 45
46 46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 47 #ifdef RTEMS_DRVMGR_STARTUP
48 48 #ifdef LEON3
49 49 /* Add Timer and UART Driver */
50 50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 52 #endif
53 53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 55 #endif
56 56 #endif
57 57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 58 #include <drvmgr/drvmgr_confdefs.h>
59 59 #endif
60 60
61 61 #include "fsw_init.h"
62 62 #include "fsw_config.c"
63 63
64 64 void initCache()
65 65 {
66 66 // unsigned int cacheControlRegister;
67 67
68 68 // cacheControlRegister = getCacheControlRegister();
69 69 // printf("(0) cacheControlRegister = %x\n", cacheControlRegister);
70 70
71 71 enableInstructionCache();
72 72 enableDataCache();
73 73 enableInstructionBurstFetch();
74 74
75 75 // cacheControlRegister = getCacheControlRegister();
76 76 // printf("(1) cacheControlRegister = %x\n", cacheControlRegister);
77 77 }
78 78
79 79 rtems_task Init( rtems_task_argument ignored )
80 80 {
81 81 /** This is the RTEMS INIT taks, it the first task launched by the system.
82 82 *
83 83 * @param unused is the starting argument of the RTEMS task
84 84 *
85 85 * The INIT task create and run all other RTEMS tasks.
86 86 *
87 87 */
88 88
89 89 //***********
90 90 // INIT CACHE
91 91
92 92 unsigned char *vhdlVersion;
93 93
94 94 reset_lfr();
95 95
96 96 reset_local_time();
97 97
98 98 rtems_cpu_usage_reset();
99 99
100 100 rtems_status_code status;
101 101 rtems_status_code status_spw;
102 102 rtems_isr_entry old_isr_handler;
103 103
104 104 // UART settings
105 105 send_console_outputs_on_apbuart_port();
106 106 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
107 107 enable_apbuart_transmitter();
108 108
109 109 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
110 110
111 111
112 112 PRINTF("\n\n\n\n\n")
113 113
114 114 initCache();
115 115
116 116 PRINTF("*************************\n")
117 117 PRINTF("** LFR Flight Software **\n")
118 118 PRINTF1("** %d.", SW_VERSION_N1)
119 119 PRINTF1("%d." , SW_VERSION_N2)
120 120 PRINTF1("%d." , SW_VERSION_N3)
121 121 PRINTF1("%d **\n", SW_VERSION_N4)
122 122
123 123 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
124 124 PRINTF("** VHDL **\n")
125 125 PRINTF1("** %d.", vhdlVersion[1])
126 126 PRINTF1("%d." , vhdlVersion[2])
127 127 PRINTF1("%d **\n", vhdlVersion[3])
128 128 PRINTF("*************************\n")
129 129 PRINTF("\n\n")
130 130
131 131 init_parameter_dump();
132 132 init_local_mode_parameters();
133 133 init_housekeeping_parameters();
134 134 init_k_coefficients_f0();
135 135 init_k_coefficients_f1();
136 136 init_k_coefficients_f2();
137 137
138 138 // waveform picker initialization
139 139 WFP_init_rings(); // initialize the waveform rings
140 140 WFP_reset_current_ring_nodes();
141 141 reset_waveform_picker_regs();
142 142
143 143 // spectral matrices initialization
144 144 SM_init_rings(); // initialize spectral matrices rings
145 145 SM_reset_current_ring_nodes();
146 146 reset_spectral_matrix_regs();
147 147
148 148 updateLFRCurrentMode();
149 149
150 150 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
151 151
152 152 create_names(); // create all names
153 153
154 154 status = create_message_queues(); // create message queues
155 155 if (status != RTEMS_SUCCESSFUL)
156 156 {
157 157 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
158 158 }
159 159
160 160 status = create_all_tasks(); // create all tasks
161 161 if (status != RTEMS_SUCCESSFUL)
162 162 {
163 163 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
164 164 }
165 165
166 166 // **************************
167 167 // <SPACEWIRE INITIALIZATION>
168 168 grspw_timecode_callback = &timecode_irq_handler;
169 169
170 170 status_spw = spacewire_open_link(); // (1) open the link
171 171 if ( status_spw != RTEMS_SUCCESSFUL )
172 172 {
173 173 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
174 174 }
175 175
176 176 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
177 177 {
178 178 status_spw = spacewire_configure_link( fdSPW );
179 179 if ( status_spw != RTEMS_SUCCESSFUL )
180 180 {
181 181 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
182 182 }
183 183 }
184 184
185 185 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
186 186 {
187 187 status_spw = spacewire_start_link( fdSPW );
188 188 if ( status_spw != RTEMS_SUCCESSFUL )
189 189 {
190 190 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
191 191 }
192 192 }
193 193 // </SPACEWIRE INITIALIZATION>
194 194 // ***************************
195 195
196 196 status = start_all_tasks(); // start all tasks
197 197 if (status != RTEMS_SUCCESSFUL)
198 198 {
199 199 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
200 200 }
201 201
202 202 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
203 203 status = start_recv_send_tasks();
204 204 if ( status != RTEMS_SUCCESSFUL )
205 205 {
206 206 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
207 207 }
208 208
209 209 // suspend science tasks, they will be restarted later depending on the mode
210 210 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
211 211 if (status != RTEMS_SUCCESSFUL)
212 212 {
213 213 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
214 214 }
215 215
216 216 //******************************
217 217 // <SPECTRAL MATRICES SIMULATOR>
218 218 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
219 219 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
220 220 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
221 221 // </SPECTRAL MATRICES SIMULATOR>
222 222 //*******************************
223 223
224 224 // configure IRQ handling for the waveform picker unit
225 225 status = rtems_interrupt_catch( waveforms_isr,
226 226 IRQ_SPARC_WAVEFORM_PICKER,
227 227 &old_isr_handler) ;
228 228 // configure IRQ handling for the spectral matrices unit
229 229 status = rtems_interrupt_catch( spectral_matrices_isr,
230 230 IRQ_SPARC_SPECTRAL_MATRIX,
231 231 &old_isr_handler) ;
232 232
233 233 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
234 234 if ( status_spw != RTEMS_SUCCESSFUL )
235 235 {
236 236 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
237 237 if ( status != RTEMS_SUCCESSFUL ) {
238 238 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
239 239 }
240 240 }
241 241
242 242 BOOT_PRINTF("delete INIT\n")
243 243
244 244 // test_TCH();
245 245
246 246 status = rtems_task_delete(RTEMS_SELF);
247 247
248 248 }
249 249
250 250 void init_local_mode_parameters( void )
251 251 {
252 252 /** This function initialize the param_local global variable with default values.
253 253 *
254 254 */
255 255
256 256 unsigned int i;
257 257
258 258 // LOCAL PARAMETERS
259 259
260 260 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
261 261 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
262 262 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
263 263
264 264 // init sequence counters
265 265
266 266 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
267 267 {
268 268 sequenceCounters_TC_EXE[i] = 0x00;
269 269 }
270 270 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
271 271 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
272 272 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
273 273 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
274 274 }
275 275
276 276 void reset_local_time( void )
277 277 {
278 278 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
279 279 }
280 280
281 281 void create_names( void ) // create all names for tasks and queues
282 282 {
283 283 /** This function creates all RTEMS names used in the software for tasks and queues.
284 284 *
285 285 * @return RTEMS directive status codes:
286 286 * - RTEMS_SUCCESSFUL - successful completion
287 287 *
288 288 */
289 289
290 290 // task names
291 291 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
292 292 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
293 293 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
294 294 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
295 295 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
296 296 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
297 297 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
298 298 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
299 299 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
300 300 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
301 301 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
302 302 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
303 303 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
304 304 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
305 305 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
306 306 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
307 307 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
308 308 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
309 309 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
310 310
311 311 // rate monotonic period names
312 312 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
313 313
314 314 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
315 315 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
316 316 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
317 317 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
318 318 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
319 319 }
320 320
321 321 int create_all_tasks( void ) // create all tasks which run in the software
322 322 {
323 323 /** This function creates all RTEMS tasks used in the software.
324 324 *
325 325 * @return RTEMS directive status codes:
326 326 * - RTEMS_SUCCESSFUL - task created successfully
327 327 * - RTEMS_INVALID_ADDRESS - id is NULL
328 328 * - RTEMS_INVALID_NAME - invalid task name
329 329 * - RTEMS_INVALID_PRIORITY - invalid task priority
330 330 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
331 331 * - RTEMS_TOO_MANY - too many tasks created
332 332 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
333 333 * - RTEMS_TOO_MANY - too many global objects
334 334 *
335 335 */
336 336
337 337 rtems_status_code status;
338 338
339 339 //**********
340 340 // SPACEWIRE
341 341 // RECV
342 342 status = rtems_task_create(
343 343 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
344 344 RTEMS_DEFAULT_MODES,
345 345 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
346 346 );
347 347 if (status == RTEMS_SUCCESSFUL) // SEND
348 348 {
349 349 status = rtems_task_create(
350 350 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
351 351 RTEMS_DEFAULT_MODES,
352 352 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
353 353 );
354 354 }
355 355 if (status == RTEMS_SUCCESSFUL) // WTDG
356 356 {
357 357 status = rtems_task_create(
358 358 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
359 359 RTEMS_DEFAULT_MODES,
360 360 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
361 361 );
362 362 }
363 363 if (status == RTEMS_SUCCESSFUL) // ACTN
364 364 {
365 365 status = rtems_task_create(
366 366 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
367 367 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
368 368 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
369 369 );
370 370 }
371 371 if (status == RTEMS_SUCCESSFUL) // SPIQ
372 372 {
373 373 status = rtems_task_create(
374 374 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
375 375 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
376 376 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
377 377 );
378 378 }
379 379
380 380 //******************
381 381 // SPECTRAL MATRICES
382 382 if (status == RTEMS_SUCCESSFUL) // AVF0
383 383 {
384 384 status = rtems_task_create(
385 385 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
386 386 RTEMS_DEFAULT_MODES,
387 387 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
388 388 );
389 389 }
390 390 if (status == RTEMS_SUCCESSFUL) // PRC0
391 391 {
392 392 status = rtems_task_create(
393 393 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
394 RTEMS_DEFAULT_MODES,
394 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
395 395 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
396 396 );
397 397 }
398 398 if (status == RTEMS_SUCCESSFUL) // AVF1
399 399 {
400 400 status = rtems_task_create(
401 401 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
402 402 RTEMS_DEFAULT_MODES,
403 403 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
404 404 );
405 405 }
406 406 if (status == RTEMS_SUCCESSFUL) // PRC1
407 407 {
408 408 status = rtems_task_create(
409 409 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
410 RTEMS_DEFAULT_MODES,
410 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
411 411 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
412 412 );
413 413 }
414 414 if (status == RTEMS_SUCCESSFUL) // AVF2
415 415 {
416 416 status = rtems_task_create(
417 417 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
418 418 RTEMS_DEFAULT_MODES,
419 419 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
420 420 );
421 421 }
422 422 if (status == RTEMS_SUCCESSFUL) // PRC2
423 423 {
424 424 status = rtems_task_create(
425 425 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
426 RTEMS_DEFAULT_MODES,
426 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
427 427 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
428 428 );
429 429 }
430 430
431 431 //****************
432 432 // WAVEFORM PICKER
433 433 if (status == RTEMS_SUCCESSFUL) // WFRM
434 434 {
435 435 status = rtems_task_create(
436 436 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
437 437 RTEMS_DEFAULT_MODES,
438 438 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
439 439 );
440 440 }
441 441 if (status == RTEMS_SUCCESSFUL) // CWF3
442 442 {
443 443 status = rtems_task_create(
444 444 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
445 445 RTEMS_DEFAULT_MODES,
446 446 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
447 447 );
448 448 }
449 449 if (status == RTEMS_SUCCESSFUL) // CWF2
450 450 {
451 451 status = rtems_task_create(
452 452 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
453 453 RTEMS_DEFAULT_MODES,
454 454 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
455 455 );
456 456 }
457 457 if (status == RTEMS_SUCCESSFUL) // CWF1
458 458 {
459 459 status = rtems_task_create(
460 460 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
461 461 RTEMS_DEFAULT_MODES,
462 462 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
463 463 );
464 464 }
465 465 if (status == RTEMS_SUCCESSFUL) // SWBD
466 466 {
467 467 status = rtems_task_create(
468 468 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
469 469 RTEMS_DEFAULT_MODES,
470 470 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
471 471 );
472 472 }
473 473
474 474 //*****
475 475 // MISC
476 476 if (status == RTEMS_SUCCESSFUL) // STAT
477 477 {
478 478 status = rtems_task_create(
479 479 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
480 480 RTEMS_DEFAULT_MODES,
481 481 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
482 482 );
483 483 }
484 484 if (status == RTEMS_SUCCESSFUL) // DUMB
485 485 {
486 486 status = rtems_task_create(
487 487 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
488 488 RTEMS_DEFAULT_MODES,
489 489 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
490 490 );
491 491 }
492 492 if (status == RTEMS_SUCCESSFUL) // HOUS
493 493 {
494 494 status = rtems_task_create(
495 495 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
496 496 RTEMS_DEFAULT_MODES,
497 497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
498 498 );
499 499 }
500 500
501 501 return status;
502 502 }
503 503
504 504 int start_recv_send_tasks( void )
505 505 {
506 506 rtems_status_code status;
507 507
508 508 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
509 509 if (status!=RTEMS_SUCCESSFUL) {
510 510 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
511 511 }
512 512
513 513 if (status == RTEMS_SUCCESSFUL) // SEND
514 514 {
515 515 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
516 516 if (status!=RTEMS_SUCCESSFUL) {
517 517 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
518 518 }
519 519 }
520 520
521 521 return status;
522 522 }
523 523
524 524 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
525 525 {
526 526 /** This function starts all RTEMS tasks used in the software.
527 527 *
528 528 * @return RTEMS directive status codes:
529 529 * - RTEMS_SUCCESSFUL - ask started successfully
530 530 * - RTEMS_INVALID_ADDRESS - invalid task entry point
531 531 * - RTEMS_INVALID_ID - invalid task id
532 532 * - RTEMS_INCORRECT_STATE - task not in the dormant state
533 533 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
534 534 *
535 535 */
536 536 // starts all the tasks fot eh flight software
537 537
538 538 rtems_status_code status;
539 539
540 540 //**********
541 541 // SPACEWIRE
542 542 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
543 543 if (status!=RTEMS_SUCCESSFUL) {
544 544 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
545 545 }
546 546
547 547 if (status == RTEMS_SUCCESSFUL) // WTDG
548 548 {
549 549 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
550 550 if (status!=RTEMS_SUCCESSFUL) {
551 551 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
552 552 }
553 553 }
554 554
555 555 if (status == RTEMS_SUCCESSFUL) // ACTN
556 556 {
557 557 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
558 558 if (status!=RTEMS_SUCCESSFUL) {
559 559 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
560 560 }
561 561 }
562 562
563 563 //******************
564 564 // SPECTRAL MATRICES
565 565 if (status == RTEMS_SUCCESSFUL) // AVF0
566 566 {
567 567 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
568 568 if (status!=RTEMS_SUCCESSFUL) {
569 569 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
570 570 }
571 571 }
572 572 if (status == RTEMS_SUCCESSFUL) // PRC0
573 573 {
574 574 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
575 575 if (status!=RTEMS_SUCCESSFUL) {
576 576 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
577 577 }
578 578 }
579 579 if (status == RTEMS_SUCCESSFUL) // AVF1
580 580 {
581 581 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
582 582 if (status!=RTEMS_SUCCESSFUL) {
583 583 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
584 584 }
585 585 }
586 586 if (status == RTEMS_SUCCESSFUL) // PRC1
587 587 {
588 588 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
589 589 if (status!=RTEMS_SUCCESSFUL) {
590 590 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
591 591 }
592 592 }
593 593 if (status == RTEMS_SUCCESSFUL) // AVF2
594 594 {
595 595 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
596 596 if (status!=RTEMS_SUCCESSFUL) {
597 597 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
598 598 }
599 599 }
600 600 if (status == RTEMS_SUCCESSFUL) // PRC2
601 601 {
602 602 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
603 603 if (status!=RTEMS_SUCCESSFUL) {
604 604 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
605 605 }
606 606 }
607 607
608 608 //****************
609 609 // WAVEFORM PICKER
610 610 if (status == RTEMS_SUCCESSFUL) // WFRM
611 611 {
612 612 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
613 613 if (status!=RTEMS_SUCCESSFUL) {
614 614 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
615 615 }
616 616 }
617 617 if (status == RTEMS_SUCCESSFUL) // CWF3
618 618 {
619 619 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
620 620 if (status!=RTEMS_SUCCESSFUL) {
621 621 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
622 622 }
623 623 }
624 624 if (status == RTEMS_SUCCESSFUL) // CWF2
625 625 {
626 626 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
627 627 if (status!=RTEMS_SUCCESSFUL) {
628 628 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
629 629 }
630 630 }
631 631 if (status == RTEMS_SUCCESSFUL) // CWF1
632 632 {
633 633 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
634 634 if (status!=RTEMS_SUCCESSFUL) {
635 635 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
636 636 }
637 637 }
638 638 if (status == RTEMS_SUCCESSFUL) // SWBD
639 639 {
640 640 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
641 641 if (status!=RTEMS_SUCCESSFUL) {
642 642 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
643 643 }
644 644 }
645 645
646 646 //*****
647 647 // MISC
648 648 if (status == RTEMS_SUCCESSFUL) // HOUS
649 649 {
650 650 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
651 651 if (status!=RTEMS_SUCCESSFUL) {
652 652 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
653 653 }
654 654 }
655 655 if (status == RTEMS_SUCCESSFUL) // DUMB
656 656 {
657 657 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
658 658 if (status!=RTEMS_SUCCESSFUL) {
659 659 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
660 660 }
661 661 }
662 662 if (status == RTEMS_SUCCESSFUL) // STAT
663 663 {
664 664 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
665 665 if (status!=RTEMS_SUCCESSFUL) {
666 666 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
667 667 }
668 668 }
669 669
670 670 return status;
671 671 }
672 672
673 673 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
674 674 {
675 675 rtems_status_code status_recv;
676 676 rtems_status_code status_send;
677 677 rtems_status_code status_q_p0;
678 678 rtems_status_code status_q_p1;
679 679 rtems_status_code status_q_p2;
680 680 rtems_status_code ret;
681 681 rtems_id queue_id;
682 682
683 683 //****************************************
684 684 // create the queue for handling valid TCs
685 685 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
686 686 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
687 687 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
688 688 if ( status_recv != RTEMS_SUCCESSFUL ) {
689 689 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
690 690 }
691 691
692 692 //************************************************
693 693 // create the queue for handling TM packet sending
694 694 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
695 695 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
696 696 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
697 697 if ( status_send != RTEMS_SUCCESSFUL ) {
698 698 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
699 699 }
700 700
701 701 //*****************************************************************************
702 702 // create the queue for handling averaged spectral matrices for processing @ f0
703 703 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
704 704 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
705 705 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
706 706 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
707 707 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
708 708 }
709 709
710 710 //*****************************************************************************
711 711 // create the queue for handling averaged spectral matrices for processing @ f1
712 712 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
713 713 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
714 714 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
715 715 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
716 716 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
717 717 }
718 718
719 719 //*****************************************************************************
720 720 // create the queue for handling averaged spectral matrices for processing @ f2
721 721 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
722 722 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
723 723 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
724 724 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
725 725 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
726 726 }
727 727
728 728 if ( status_recv != RTEMS_SUCCESSFUL )
729 729 {
730 730 ret = status_recv;
731 731 }
732 732 else if( status_send != RTEMS_SUCCESSFUL )
733 733 {
734 734 ret = status_send;
735 735 }
736 736 else if( status_q_p0 != RTEMS_SUCCESSFUL )
737 737 {
738 738 ret = status_q_p0;
739 739 }
740 740 else if( status_q_p1 != RTEMS_SUCCESSFUL )
741 741 {
742 742 ret = status_q_p1;
743 743 }
744 744 else
745 745 {
746 746 ret = status_q_p2;
747 747 }
748 748
749 749 return ret;
750 750 }
751 751
752 752 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
753 753 {
754 754 rtems_status_code status;
755 755 rtems_name queue_name;
756 756
757 757 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
758 758
759 759 status = rtems_message_queue_ident( queue_name, 0, queue_id );
760 760
761 761 return status;
762 762 }
763 763
764 764 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
765 765 {
766 766 rtems_status_code status;
767 767 rtems_name queue_name;
768 768
769 769 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
770 770
771 771 status = rtems_message_queue_ident( queue_name, 0, queue_id );
772 772
773 773 return status;
774 774 }
775 775
776 776 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
777 777 {
778 778 rtems_status_code status;
779 779 rtems_name queue_name;
780 780
781 781 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
782 782
783 783 status = rtems_message_queue_ident( queue_name, 0, queue_id );
784 784
785 785 return status;
786 786 }
787 787
788 788 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
789 789 {
790 790 rtems_status_code status;
791 791 rtems_name queue_name;
792 792
793 793 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
794 794
795 795 status = rtems_message_queue_ident( queue_name, 0, queue_id );
796 796
797 797 return status;
798 798 }
799 799
800 800 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
801 801 {
802 802 rtems_status_code status;
803 803 rtems_name queue_name;
804 804
805 805 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
806 806
807 807 status = rtems_message_queue_ident( queue_name, 0, queue_id );
808 808
809 809 return status;
810 810 }
@@ -1,487 +1,506
1 1 /** General usage functions and RTEMS tasks.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 */
7 7
8 8 #include "fsw_misc.h"
9 9
10 10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 12 {
13 13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 14 *
15 15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 18 * @param interrupt_level is the interrupt level that the timer drives.
19 19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 20 *
21 21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 22 *
23 23 */
24 24
25 25 rtems_status_code status;
26 26 rtems_isr_entry old_isr_handler;
27 27
28 28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29 29
30 30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 31 if (status!=RTEMS_SUCCESSFUL)
32 32 {
33 33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 34 }
35 35
36 36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 37 }
38 38
39 39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 40 {
41 41 /** This function starts a GPTIMER timer.
42 42 *
43 43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 45 *
46 46 */
47 47
48 48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 53 }
54 54
55 55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 56 {
57 57 /** This function stops a GPTIMER timer.
58 58 *
59 59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 61 *
62 62 */
63 63
64 64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 67 }
68 68
69 69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 70 {
71 71 /** This function sets the clock divider of a GPTIMER timer.
72 72 *
73 73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 76 *
77 77 */
78 78
79 79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 80 }
81 81
82 82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 83 {
84 84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85 85
86 86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87 87
88 88 return 0;
89 89 }
90 90
91 91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 92 {
93 93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94 94
95 95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96 96
97 97 return 0;
98 98 }
99 99
100 100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 101 {
102 102 /** This function sets the scaler reload register of the apbuart module
103 103 *
104 104 * @param regs is the address of the apbuart registers in memory
105 105 * @param value is the value that will be stored in the scaler register
106 106 *
107 107 * The value shall be set by the software to get data on the serial interface.
108 108 *
109 109 */
110 110
111 111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112 112
113 113 apbuart_regs->scaler = value;
114 114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 115 }
116 116
117 117 //************
118 118 // RTEMS TASKS
119 119
120 120 rtems_task stat_task(rtems_task_argument argument)
121 121 {
122 122 int i;
123 123 int j;
124 124 i = 0;
125 125 j = 0;
126 126 BOOT_PRINTF("in STAT *** \n")
127 127 while(1){
128 128 rtems_task_wake_after(1000);
129 129 PRINTF1("%d\n", j)
130 130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 131 // #ifdef PRINT_TASK_STATISTICS
132 132 // rtems_cpu_usage_report();
133 133 // rtems_cpu_usage_reset();
134 134 // #endif
135 135 i = 0;
136 136 }
137 137 else i++;
138 138 j++;
139 139 }
140 140 }
141 141
142 142 rtems_task hous_task(rtems_task_argument argument)
143 143 {
144 144 rtems_status_code status;
145 145 rtems_status_code spare_status;
146 146 rtems_id queue_id;
147 147 rtems_rate_monotonic_period_status period_status;
148 148
149 149 status = get_message_queue_id_send( &queue_id );
150 150 if (status != RTEMS_SUCCESSFUL)
151 151 {
152 152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 153 }
154 154
155 155 BOOT_PRINTF("in HOUS ***\n")
156 156
157 157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 159 if( status != RTEMS_SUCCESSFUL ) {
160 160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 161 }
162 162 }
163 163
164 164 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
165 165 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
166 166 housekeeping_packet.reserved = DEFAULT_RESERVED;
167 167 housekeeping_packet.userApplication = CCSDS_USER_APP;
168 168 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
169 169 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
170 170 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
171 171 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
172 172 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
173 173 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
174 174 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
175 175 housekeeping_packet.serviceType = TM_TYPE_HK;
176 176 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
177 177 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
178 178 housekeeping_packet.sid = SID_HK;
179 179
180 180 status = rtems_rate_monotonic_cancel(HK_id);
181 181 if( status != RTEMS_SUCCESSFUL ) {
182 182 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
183 183 }
184 184 else {
185 185 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
186 186 }
187 187
188 188 // startup phase
189 189 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
190 190 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
191 191 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
192 192 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
193 193 {
194 194 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
195 195 {
196 196 break; // break if LFR is synchronized
197 197 }
198 198 else
199 199 {
200 200 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
201 201 // sched_yield();
202 202 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
203 203 }
204 204 }
205 205 status = rtems_rate_monotonic_cancel(HK_id);
206 206 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
207 207
208 208 while(1){ // launch the rate monotonic task
209 209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
210 210 if ( status != RTEMS_SUCCESSFUL ) {
211 211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
212 212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
213 213 }
214 214 else {
215 215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
216 216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
217 217 increment_seq_counter( &sequenceCounterHK );
218 218
219 219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
220 220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
221 221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
222 222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
223 223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
224 224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
225 225
226 226 spacewire_update_statistics();
227 227
228 228 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
229 get_temperatures( housekeeping_packet.hk_lfr_temp_scm);
229 230 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
230 231
231 232 // SEND PACKET
232 233 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
233 234 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
234 235 if (status != RTEMS_SUCCESSFUL) {
235 236 PRINTF1("in HOUS *** ERR send: %d\n", status)
236 237 }
237 238 }
238 239 }
239 240
240 241 PRINTF("in HOUS *** deleting task\n")
241 242
242 243 status = rtems_task_delete( RTEMS_SELF ); // should not return
243 244 printf( "rtems_task_delete returned with status of %d.\n", status );
244 245 return;
245 246 }
246 247
247 248 rtems_task dumb_task( rtems_task_argument unused )
248 249 {
249 250 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
250 251 *
251 252 * @param unused is the starting argument of the RTEMS task
252 253 *
253 254 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
254 255 *
255 256 */
256 257
257 258 unsigned int i;
258 259 unsigned int intEventOut;
259 260 unsigned int coarse_time = 0;
260 261 unsigned int fine_time = 0;
261 262 rtems_event_set event_out;
262 263
263 264 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
264 265 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
265 266 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
266 267 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
267 268 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
268 269 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
269 270 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
270 271 "ready for dump", // RTEMS_EVENT_7
271 272 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
272 273 "tick", // RTEMS_EVENT_9
273 274 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
274 275 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
275 276 };
276 277
277 278 BOOT_PRINTF("in DUMB *** \n")
278 279
279 280 while(1){
280 281 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
281 282 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
282 283 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
283 284 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
284 285 intEventOut = (unsigned int) event_out;
285 286 for ( i=0; i<32; i++)
286 287 {
287 288 if ( ((intEventOut >> i) & 0x0001) != 0)
288 289 {
289 290 coarse_time = time_management_regs->coarse_time;
290 291 fine_time = time_management_regs->fine_time;
291 292 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
292 293 if (i==8)
293 294 {
294 295 }
295 296 if (i==10)
296 297 {
297 298 }
298 299 }
299 300 }
300 301 }
301 302 }
302 303
303 304 //*****************************
304 305 // init housekeeping parameters
305 306
306 307 void init_housekeeping_parameters( void )
307 308 {
308 309 /** This function initialize the housekeeping_packet global variable with default values.
309 310 *
310 311 */
311 312
312 313 unsigned int i = 0;
313 314 unsigned char *parameters;
314 315
315 316 parameters = (unsigned char*) &housekeeping_packet.lfr_status_word;
316 317 for(i = 0; i< SIZE_HK_PARAMETERS; i++)
317 318 {
318 319 parameters[i] = 0x00;
319 320 }
320 321 // init status word
321 322 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
322 323 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
323 324 // init software version
324 325 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
325 326 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
326 327 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
327 328 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
328 329 // init fpga version
329 330 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
330 331 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
331 332 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
332 333 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
333 334 }
334 335
335 336 void increment_seq_counter( unsigned short *packetSequenceControl )
336 337 {
337 338 /** This function increment the sequence counter psased in argument.
338 339 *
339 340 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
340 341 *
341 342 */
342 343
343 344 unsigned short segmentation_grouping_flag;
344 345 unsigned short sequence_cnt;
345 346
346 347 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
347 348 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
348 349
349 350 if ( sequence_cnt < SEQ_CNT_MAX)
350 351 {
351 352 sequence_cnt = sequence_cnt + 1;
352 353 }
353 354 else
354 355 {
355 356 sequence_cnt = 0;
356 357 }
357 358
358 359 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
359 360 }
360 361
361 362 void getTime( unsigned char *time)
362 363 {
363 364 /** This function write the current local time in the time buffer passed in argument.
364 365 *
365 366 */
366 367
367 368 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
368 369 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
369 370 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
370 371 time[3] = (unsigned char) (time_management_regs->coarse_time);
371 372 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
372 373 time[5] = (unsigned char) (time_management_regs->fine_time);
373 374 }
374 375
375 376 unsigned long long int getTimeAsUnsignedLongLongInt( )
376 377 {
377 378 /** This function write the current local time in the time buffer passed in argument.
378 379 *
379 380 */
380 381 unsigned long long int time;
381 382
382 383 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
383 384 + time_management_regs->fine_time;
384 385
385 386 return time;
386 387 }
387 388
388 389 void send_dumb_hk( void )
389 390 {
390 391 Packet_TM_LFR_HK_t dummy_hk_packet;
391 392 unsigned char *parameters;
392 393 unsigned int i;
393 394 rtems_id queue_id;
394 395
395 396 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
396 397 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
397 398 dummy_hk_packet.reserved = DEFAULT_RESERVED;
398 399 dummy_hk_packet.userApplication = CCSDS_USER_APP;
399 400 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
400 401 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
401 402 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
402 403 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
403 404 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
404 405 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
405 406 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
406 407 dummy_hk_packet.serviceType = TM_TYPE_HK;
407 408 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
408 409 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
409 410 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
410 411 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
411 412 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
412 413 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
413 414 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
414 415 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
415 416 dummy_hk_packet.sid = SID_HK;
416 417
417 418 // init status word
418 419 dummy_hk_packet.lfr_status_word[0] = 0xff;
419 420 dummy_hk_packet.lfr_status_word[1] = 0xff;
420 421 // init software version
421 422 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
422 423 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
423 424 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
424 425 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
425 426 // init fpga version
426 427 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
427 428 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
428 429 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
429 430 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
430 431
431 432 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
432 433
433 434 for (i=0; i<100; i++)
434 435 {
435 436 parameters[i] = 0xff;
436 437 }
437 438
438 439 get_message_queue_id_send( &queue_id );
439 440
440 441 rtems_message_queue_send( queue_id, &dummy_hk_packet,
441 442 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
442 443 }
443 444
444 445 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
445 446 {
446 447 unsigned char* v_ptr;
447 448 unsigned char* e1_ptr;
448 449 unsigned char* e2_ptr;
449 450
450 451 v_ptr = (unsigned char *) &waveform_picker_regs->v;
451 452 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
452 453 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
453 454
454 455 spacecraft_potential[0] = v_ptr[2];
455 456 spacecraft_potential[1] = v_ptr[3];
456 457 spacecraft_potential[2] = e1_ptr[2];
457 458 spacecraft_potential[3] = e1_ptr[3];
458 459 spacecraft_potential[4] = e2_ptr[2];
459 460 spacecraft_potential[5] = e2_ptr[3];
460 461 }
461 462
463 void get_temperatures( unsigned char *temperatures )
464 {
465 unsigned char* temp_scm_ptr;
466 unsigned char* temp_pcb_ptr;
467 unsigned char* temp_fpga_ptr;
468
469 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
470 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
471 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
472
473 temperatures[0] = temp_scm_ptr[2];
474 temperatures[1] = temp_scm_ptr[3];
475 temperatures[2] = temp_pcb_ptr[2];
476 temperatures[3] = temp_pcb_ptr[3];
477 temperatures[4] = temp_fpga_ptr[2];
478 temperatures[5] = temp_fpga_ptr[3];
479 }
480
462 481 void get_cpu_load( unsigned char *resource_statistics )
463 482 {
464 483 unsigned char cpu_load;
465 484
466 485 cpu_load = lfr_rtems_cpu_usage_report();
467 486
468 487 // HK_LFR_CPU_LOAD
469 488 resource_statistics[0] = cpu_load;
470 489
471 490 // HK_LFR_CPU_LOAD_MAX
472 491 if (cpu_load > resource_statistics[1])
473 492 {
474 493 resource_statistics[1] = cpu_load;
475 494 }
476 495
477 496 // CPU_LOAD_AVE
478 497 resource_statistics[2] = 0;
479 498
480 499 #ifndef PRINT_TASK_STATISTICS
481 500 rtems_cpu_usage_reset();
482 501 #endif
483 502
484 503 }
485 504
486 505
487 506
@@ -1,391 +1,397
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf0_prc0.h"
11 11 #include "fsw_processing.h"
12 12
13 13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14 14
15 15 //***
16 16 // F0
17 17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19 19
20 20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
22 22
23 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
26
24 27 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
25 28 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
26 29 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
27 30
28 31 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
29 32 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
30 33
31 34 //************
32 35 // RTEMS TASKS
33 36
34 37 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
35 38 {
36 39 int i;
37 40
38 41 rtems_event_set event_out;
39 42 rtems_status_code status;
40 43 rtems_id queue_id_prc0;
41 44 asm_msg msgForMATR;
42 45 ring_node *nodeForAveraging;
43 46 ring_node *ring_node_tab[8];
44 47 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
45 48 ring_node_asm *current_ring_node_asm_norm_f0;
46 49
47 50 unsigned int nb_norm_bp1;
48 51 unsigned int nb_norm_bp2;
49 52 unsigned int nb_norm_asm;
50 53 unsigned int nb_sbm_bp1;
51 54 unsigned int nb_sbm_bp2;
52 55
53 56 nb_norm_bp1 = 0;
54 57 nb_norm_bp2 = 0;
55 58 nb_norm_asm = 0;
56 59 nb_sbm_bp1 = 0;
57 60 nb_sbm_bp2 = 0;
58 61
59 62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
60 63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
61 64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
62 65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
63 66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
64 67
65 68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
66 69
67 70 status = get_message_queue_id_prc0( &queue_id_prc0 );
68 71 if (status != RTEMS_SUCCESSFUL)
69 72 {
70 73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
71 74 }
72 75
73 76 while(1){
74 77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
75 78
76 79 //****************************************
77 80 // initialize the mesage for the MATR task
78 81 msgForMATR.norm = current_ring_node_asm_norm_f0;
79 82 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0;
80 83 msgForMATR.event = 0x00; // this composite event will be sent to the PRC0 task
81 84 //
82 85 //****************************************
83 86
84 87 nodeForAveraging = getRingNodeForAveraging( 0 );
85 88
86 89 ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging;
87 90 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
88 91 {
89 92 nodeForAveraging = nodeForAveraging->previous;
90 93 ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging;
91 94 }
92 95
93 96 // compute the average and store it in the averaged_sm_f1 buffer
94 97 SM_average( current_ring_node_asm_norm_f0->matrix,
95 98 current_ring_node_asm_burst_sbm_f0->matrix,
96 99 ring_node_tab,
97 100 nb_norm_bp1, nb_sbm_bp1,
98 101 &msgForMATR );
99 102
100 103 // update nb_average
101 104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
102 105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
103 106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
104 107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
105 108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
106 109
107 110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
108 111 {
109 112 nb_sbm_bp1 = 0;
110 113 // set another ring for the ASM storage
111 114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
112 115 if ( lfrCurrentMode == LFR_MODE_BURST )
113 116 {
114 117 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0;
115 118 }
116 119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
117 120 {
118 121 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0;
119 122 }
120 123 }
121 124
122 125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
123 126 {
124 127 nb_sbm_bp2 = 0;
125 128 if ( lfrCurrentMode == LFR_MODE_BURST )
126 129 {
127 130 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0;
128 131 }
129 132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
130 133 {
131 134 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0;
132 135 }
133 136 }
134 137
135 138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
136 139 {
137 140 nb_norm_bp1 = 0;
138 141 // set another ring for the ASM storage
139 142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
140 143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
141 144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
142 145 {
143 146 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0;
144 147 }
145 148 }
146 149
147 150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
148 151 {
149 152 nb_norm_bp2 = 0;
150 153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
151 154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
152 155 {
153 156 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0;
154 157 }
155 158 }
156 159
157 160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
158 161 {
159 162 nb_norm_asm = 0;
160 163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
161 164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
162 165 {
163 166 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0;
164 167 }
165 168 }
166 169
167 170 //*************************
168 171 // send the message to MATR
169 172 if (msgForMATR.event != 0x00)
170 173 {
171 174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0);
172 175 }
173 176
174 177 if (status != RTEMS_SUCCESSFUL) {
175 178 printf("in AVF0 *** Error sending message to MATR, code %d\n", status);
176 179 }
177 180 }
178 181 }
179 182
180 183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
181 184 {
182 185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
183 186 size_t size; // size of the incoming TC packet
184 187 asm_msg *incomingMsg;
185 188 //
186 189 unsigned char sid;
187 190 rtems_status_code status;
188 191 rtems_id queue_id;
189 192 rtems_id queue_id_q_p0;
190 193 bp_packet_with_spare packet_norm_bp1;
191 194 bp_packet packet_norm_bp2;
192 195 bp_packet packet_sbm_bp1;
193 196 bp_packet packet_sbm_bp2;
194 197 ring_node *current_ring_node_to_send_asm_f0;
195 198
196 199 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
197 200 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
198 201 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
199 202
200 203 //*************
201 204 // NORM headers
202 205 BP_init_header_with_spare( &packet_norm_bp1,
203 206 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
204 207 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
205 208 BP_init_header( &packet_norm_bp2,
206 209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
207 210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
208 211
209 212 //****************************
210 213 // BURST SBM1 and SBM2 headers
211 214 if ( lfrRequestedMode == LFR_MODE_BURST )
212 215 {
213 216 BP_init_header( &packet_sbm_bp1,
214 217 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
215 218 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
216 219 BP_init_header( &packet_sbm_bp2,
217 220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
218 221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
219 222 }
220 223 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
221 224 {
222 225 BP_init_header( &packet_sbm_bp1,
223 226 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
224 227 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
225 228 BP_init_header( &packet_sbm_bp2,
226 229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
227 230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
228 231 }
229 232 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
230 233 {
231 234 BP_init_header( &packet_sbm_bp1,
232 235 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
233 236 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
234 237 BP_init_header( &packet_sbm_bp2,
235 238 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
236 239 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
237 240 }
238 241 else
239 242 {
240 243 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
241 244 }
242 245
243 246 status = get_message_queue_id_send( &queue_id );
244 247 if (status != RTEMS_SUCCESSFUL)
245 248 {
246 249 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
247 250 }
248 251 status = get_message_queue_id_prc0( &queue_id_q_p0);
249 252 if (status != RTEMS_SUCCESSFUL)
250 253 {
251 254 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
252 255 }
253 256
254 257 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
255 258
256 259 while(1){
257 260 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
258 261 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
259 262
260 263 incomingMsg = (asm_msg*) incomingData;
261 264
265 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
266 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
267
262 268 //****************
263 269 //****************
264 270 // BURST SBM1 SBM2
265 271 //****************
266 272 //****************
267 273 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
268 274 {
269 275 sid = getSID( incomingMsg->event );
270 276 // 1) compress the matrix for Basic Parameters calculation
271 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f0,
277 ASM_compress_reorganize_and_divide( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
272 278 nb_sm_before_f0.burst_sbm_bp1,
273 279 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
274 280 ASM_F0_INDICE_START);
275 281 // 2) compute the BP1 set
276 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
282 // BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
277 283 // 3) send the BP1 set
278 284 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
279 285 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
280 286 BP_send( (char *) &packet_sbm_bp1, queue_id,
281 287 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
282 288 sid);
283 289 // 4) compute the BP2 set if needed
284 290 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
285 291 {
286 292 // 1) compute the BP2 set
287 293 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
288 294 // 2) send the BP2 set
289 295 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 296 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 297 BP_send( (char *) &packet_sbm_bp2, queue_id,
292 298 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
293 299 sid);
294 300 }
295 301 }
296 302
297 303 //*****
298 304 //*****
299 305 // NORM
300 306 //*****
301 307 //*****
302 308 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
303 309 {
304 310 // 1) compress the matrix for Basic Parameters calculation
305 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f0,
311 ASM_compress_reorganize_and_divide( asm_f0_patched_norm, compressed_sm_norm_f0,
306 312 nb_sm_before_f0.norm_bp1,
307 313 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
308 314 ASM_F0_INDICE_START );
309 315 // 2) compute the BP1 set
310 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
316 // BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
311 317 // 3) send the BP1 set
312 318 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
313 319 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
314 320 BP_send( (char *) &packet_norm_bp1, queue_id,
315 321 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
316 322 SID_NORM_BP1_F0 );
317 323 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
318 324 {
319 325 // 1) compute the BP2 set using the same ASM as the one used for BP1
320 326 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
321 327 // 2) send the BP2 set
322 328 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
323 329 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
324 330 BP_send( (char *) &packet_norm_bp2, queue_id,
325 331 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
326 332 SID_NORM_BP2_F0);
327 333 }
328 334 }
329 335
330 336 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
331 337 {
332 338 // 1) reorganize the ASM and divide
333 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
339 ASM_reorganize_and_divide( asm_f0_patched_norm,
334 340 asm_f0_reorganized,
335 341 nb_sm_before_f0.norm_bp1 );
336 342 // 2) convert the float array in a char array
337 343 ASM_convert( asm_f0_reorganized, (char*) current_ring_node_to_send_asm_f0->buffer_address );
338 344 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
339 345 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
340 346 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
341 347
342 348 // 3) send the spectral matrix packets
343 349 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
344 350 // change asm ring node
345 351 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
346 352 }
347 353 }
348 354 }
349 355
350 356 //**********
351 357 // FUNCTIONS
352 358
353 359 void reset_nb_sm_f0( unsigned char lfrMode )
354 360 {
355 361 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
356 362 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
357 363 nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96;
358 364 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
359 365 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
360 366 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
361 367 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
362 368 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
363 369 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
364 370
365 371 if (lfrMode == LFR_MODE_SBM1)
366 372 {
367 373 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
368 374 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
369 375 }
370 376 else if (lfrMode == LFR_MODE_SBM2)
371 377 {
372 378 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
373 379 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
374 380 }
375 381 else if (lfrMode == LFR_MODE_BURST)
376 382 {
377 383 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
378 384 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
379 385 }
380 386 else
381 387 {
382 388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
383 389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
384 390 }
385 391 }
386 392
387 393 void init_k_coefficients_f0( void )
388 394 {
389 395 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
390 396 init_k_coefficients( k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0);
391 397 }
@@ -1,379 +1,379
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf1_prc1.h"
11 11
12 12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13 13
14 14 extern ring_node sm_ring_f1[ ];
15 15
16 16 //***
17 17 // F1
18 18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
19 19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
20 20
21 21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
22 22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
23 23
24 24 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
25 char asm_f1_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
25 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
26 26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
27 27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
28 28
29 29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
30 30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
31 31
32 32 //************
33 33 // RTEMS TASKS
34 34
35 35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 36 {
37 37 int i;
38 38
39 39 rtems_event_set event_out;
40 40 rtems_status_code status;
41 41 rtems_id queue_id_prc1;
42 42 asm_msg msgForMATR;
43 43 ring_node *nodeForAveraging;
44 44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
45 45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 46 ring_node_asm *current_ring_node_asm_norm_f1;
47 47
48 48 unsigned int nb_norm_bp1;
49 49 unsigned int nb_norm_bp2;
50 50 unsigned int nb_norm_asm;
51 51 unsigned int nb_sbm_bp1;
52 52 unsigned int nb_sbm_bp2;
53 53
54 54 nb_norm_bp1 = 0;
55 55 nb_norm_bp2 = 0;
56 56 nb_norm_asm = 0;
57 57 nb_sbm_bp1 = 0;
58 58 nb_sbm_bp2 = 0;
59 59
60 60 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
61 61 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
62 62 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
63 63 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
64 64 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
65 65
66 66 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
67 67
68 68 status = get_message_queue_id_prc1( &queue_id_prc1 );
69 69 if (status != RTEMS_SUCCESSFUL)
70 70 {
71 71 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
72 72 }
73 73
74 74 while(1){
75 75 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
76 76
77 77 //****************************************
78 78 // initialize the mesage for the MATR task
79 79 msgForMATR.norm = current_ring_node_asm_norm_f1;
80 80 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1;
81 81 msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task
82 82 //
83 83 //****************************************
84 84
85 85 nodeForAveraging = getRingNodeForAveraging( 1 );
86 86
87 87 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
88 88 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
89 89 {
90 90 nodeForAveraging = nodeForAveraging->previous;
91 91 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
92 92 }
93 93
94 94 // compute the average and store it in the averaged_sm_f1 buffer
95 95 SM_average( current_ring_node_asm_norm_f1->matrix,
96 96 current_ring_node_asm_burst_sbm_f1->matrix,
97 97 ring_node_tab,
98 98 nb_norm_bp1, nb_sbm_bp1,
99 99 &msgForMATR );
100 100
101 101 // update nb_average
102 102 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
103 103 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
104 104 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
105 105 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
106 106 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
107 107
108 108 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
109 109 {
110 110 nb_sbm_bp1 = 0;
111 111 // set another ring for the ASM storage
112 112 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
113 113 if ( lfrCurrentMode == LFR_MODE_BURST )
114 114 {
115 115 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1;
116 116 }
117 117 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
118 118 {
119 119 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1;
120 120 }
121 121 }
122 122
123 123 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
124 124 {
125 125 nb_sbm_bp2 = 0;
126 126 if ( lfrCurrentMode == LFR_MODE_BURST )
127 127 {
128 128 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1;
129 129 }
130 130 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
131 131 {
132 132 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1;
133 133 }
134 134 }
135 135
136 136 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
137 137 {
138 138 nb_norm_bp1 = 0;
139 139 // set another ring for the ASM storage
140 140 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
141 141 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
142 142 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 143 {
144 144 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1;
145 145 }
146 146 }
147 147
148 148 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
149 149 {
150 150 nb_norm_bp2 = 0;
151 151 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
152 152 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
153 153 {
154 154 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1;
155 155 }
156 156 }
157 157
158 158 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
159 159 {
160 160 nb_norm_asm = 0;
161 161 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
162 162 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
163 163 {
164 164 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1;
165 165 }
166 166 }
167 167
168 168 //*************************
169 169 // send the message to MATR
170 170 if (msgForMATR.event != 0x00)
171 171 {
172 172 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1);
173 173 }
174 174
175 175 if (status != RTEMS_SUCCESSFUL) {
176 176 printf("in AVF1 *** Error sending message to PRC1, code %d\n", status);
177 177 }
178 178 }
179 179 }
180 180
181 181 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
182 182 {
183 183 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
184 184 size_t size; // size of the incoming TC packet
185 185 asm_msg *incomingMsg;
186 186 //
187 187 unsigned char sid;
188 188 rtems_status_code status;
189 189 rtems_id queue_id_send;
190 190 rtems_id queue_id_q_p1;
191 191 bp_packet_with_spare packet_norm_bp1;
192 192 bp_packet packet_norm_bp2;
193 193 bp_packet packet_sbm_bp1;
194 194 bp_packet packet_sbm_bp2;
195 195 ring_node *current_ring_node_to_send_asm_f1;
196 196
197 197 unsigned long long int localTime;
198 198
199 199 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 200 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
201 201 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
202 202
203 203 //*************
204 204 // NORM headers
205 205 BP_init_header_with_spare( &packet_norm_bp1,
206 206 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
207 207 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
208 208 BP_init_header( &packet_norm_bp2,
209 209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
210 210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
211 211
212 212 //***********************
213 213 // BURST and SBM2 headers
214 214 if ( lfrRequestedMode == LFR_MODE_BURST )
215 215 {
216 216 BP_init_header( &packet_sbm_bp1,
217 217 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
218 218 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
219 219 BP_init_header( &packet_sbm_bp2,
220 220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
221 221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
222 222 }
223 223 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
224 224 {
225 225 BP_init_header( &packet_sbm_bp1,
226 226 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
227 227 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
228 228 BP_init_header( &packet_sbm_bp2,
229 229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
230 230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 231 }
232 232 else
233 233 {
234 234 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
235 235 }
236 236
237 237 status = get_message_queue_id_send( &queue_id_send );
238 238 if (status != RTEMS_SUCCESSFUL)
239 239 {
240 240 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
241 241 }
242 242 status = get_message_queue_id_prc1( &queue_id_q_p1);
243 243 if (status != RTEMS_SUCCESSFUL)
244 244 {
245 245 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
246 246 }
247 247
248 248 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
249 249
250 250 while(1){
251 251 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
252 252 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
253 253
254 254 incomingMsg = (asm_msg*) incomingData;
255 255
256 256 localTime = getTimeAsUnsignedLongLongInt( );
257 257 //***********
258 258 //***********
259 259 // BURST SBM2
260 260 //***********
261 261 //***********
262 262 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
263 263 {
264 264 sid = getSID( incomingMsg->event );
265 265 // 1) compress the matrix for Basic Parameters calculation
266 266 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f1,
267 267 nb_sm_before_f1.burst_sbm_bp1,
268 268 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
269 269 ASM_F1_INDICE_START);
270 270 // 2) compute the BP1 set
271 271 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
272 272 // 3) send the BP1 set
273 273 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
274 274 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
275 275 BP_send( (char *) &packet_sbm_bp1, queue_id_send,
276 276 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
277 277 sid );
278 278 // 4) compute the BP2 set if needed
279 279 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
280 280 {
281 281 // 1) compute the BP2 set
282 282 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_norm_bp2.data );
283 283 // 2) send the BP2 set
284 284 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
285 285 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
286 286 BP_send( (char *) &packet_sbm_bp2, queue_id_send,
287 287 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
288 288 sid );
289 289 }
290 290 }
291 291
292 292 //*****
293 293 //*****
294 294 // NORM
295 295 //*****
296 296 //*****
297 297 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
298 298 {
299 299 // 1) compress the matrix for Basic Parameters calculation
300 300 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f1,
301 301 nb_sm_before_f1.norm_bp1,
302 302 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
303 303 ASM_F1_INDICE_START );
304 304 // 2) compute the BP1 set
305 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
305 // BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
306 306 // 3) send the BP1 set
307 307 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
308 308 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
309 309 BP_send( (char *) &packet_norm_bp1, queue_id_send,
310 310 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
311 311 SID_NORM_BP1_F1 );
312 312 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
313 313 {
314 314 // 1) compute the BP2 set
315 315 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
316 316 // 2) send the BP2 set
317 317 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
318 318 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 319 BP_send( (char *) &packet_norm_bp2, queue_id_send,
320 320 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
321 321 SID_NORM_BP2_F1 );
322 322 }
323 323 }
324 324
325 325 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
326 326 {
327 327 // 1) reorganize the ASM and divide
328 328 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
329 329 asm_f1_reorganized,
330 330 nb_sm_before_f1.norm_bp1 );
331 331 // 2) convert the float array in a char array
332 332 ASM_convert( asm_f1_reorganized, (char*) current_ring_node_to_send_asm_f1->buffer_address );
333 333 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
334 334 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
335 335 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
336 336 // 3) send the spectral matrix packets
337 337 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
338 338 // change asm ring node
339 339 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
340 340 }
341 341
342 342 }
343 343 }
344 344
345 345 //**********
346 346 // FUNCTIONS
347 347
348 348 void reset_nb_sm_f1( unsigned char lfrMode )
349 349 {
350 350 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
351 351 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
352 352 nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16;
353 353 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
354 354 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
355 355 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
356 356 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
357 357
358 358 if (lfrMode == LFR_MODE_SBM2)
359 359 {
360 360 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
361 361 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
362 362 }
363 363 else if (lfrMode == LFR_MODE_BURST)
364 364 {
365 365 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
366 366 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
367 367 }
368 368 else
369 369 {
370 370 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
371 371 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
372 372 }
373 373 }
374 374
375 375 void init_k_coefficients_f1( void )
376 376 {
377 377 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
378 378 init_k_coefficients( k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1);
379 379 }
@@ -1,283 +1,285
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf2_prc2.h"
11 11
12 12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13 13
14 14 extern ring_node sm_ring_f2[ ];
15 15
16 16 //***
17 17 // F2
18 18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
19 19
20 20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
21 21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
22 22
23 23 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
24 24 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
25 25 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
26 26
27 27 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
28 28
29 29 //************
30 30 // RTEMS TASKS
31 31
32 32 //***
33 33 // F2
34 34 rtems_task avf2_task( rtems_task_argument argument )
35 35 {
36 36 rtems_event_set event_out;
37 37 rtems_status_code status;
38 38 rtems_id queue_id_prc2;
39 39 asm_msg msgForMATR;
40 40 ring_node *nodeForAveraging;
41 41 ring_node_asm *current_ring_node_asm_norm_f2;
42 42
43 43 unsigned int nb_norm_bp1;
44 44 unsigned int nb_norm_bp2;
45 45 unsigned int nb_norm_asm;
46 46
47 47 nb_norm_bp1 = 0;
48 48 nb_norm_bp2 = 0;
49 49 nb_norm_asm = 0;
50 50
51 51 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
52 52 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
53 53 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
54 54
55 55 BOOT_PRINTF("in AVF2 ***\n")
56 56
57 57 status = get_message_queue_id_prc2( &queue_id_prc2 );
58 58 if (status != RTEMS_SUCCESSFUL)
59 59 {
60 60 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
61 61 }
62 62
63 63 while(1){
64 64 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
65 65
66 66 //****************************************
67 67 // initialize the mesage for the MATR task
68 68 msgForMATR.norm = current_ring_node_asm_norm_f2;
69 69 msgForMATR.burst_sbm = NULL;
70 70 msgForMATR.event = 0x00; // this composite event will be sent to the PRC2 task
71 71 //
72 72 //****************************************
73 73
74 74 nodeForAveraging = getRingNodeForAveraging( 2 );
75 75
76 76 // printf(" **0** %x . %x", sm_ring_f2[0].coarseTime, sm_ring_f2[0].fineTime);
77 77 // printf(" **1** %x . %x", sm_ring_f2[1].coarseTime, sm_ring_f2[1].fineTime);
78 78 // printf(" **2** %x . %x", sm_ring_f2[2].coarseTime, sm_ring_f2[2].fineTime);
79 79 // printf(" **3** %x . %x", sm_ring_f2[3].coarseTime, sm_ring_f2[3].fineTime);
80 80 // printf(" **4** %x . %x", sm_ring_f2[4].coarseTime, sm_ring_f2[4].fineTime);
81 81 // printf(" **5** %x . %x", sm_ring_f2[5].coarseTime, sm_ring_f2[5].fineTime);
82 82 // printf(" **6** %x . %x", sm_ring_f2[6].coarseTime, sm_ring_f2[6].fineTime);
83 83 // printf(" **7** %x . %x", sm_ring_f2[7].coarseTime, sm_ring_f2[7].fineTime);
84 84 // printf(" **8** %x . %x", sm_ring_f2[8].coarseTime, sm_ring_f2[8].fineTime);
85 85 // printf(" **9** %x . %x", sm_ring_f2[9].coarseTime, sm_ring_f2[9].fineTime);
86 86 // printf(" **10** %x . %x\n", sm_ring_f2[10].coarseTime, sm_ring_f2[10].fineTime);
87 87
88 88 // compute the average and store it in the averaged_sm_f2 buffer
89 89 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
90 90 nodeForAveraging,
91 91 nb_norm_bp1,
92 92 &msgForMATR );
93 93
94 94 // update nb_average
95 95 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
96 96 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
97 97 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
98 98
99 99 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
100 100 {
101 101 nb_norm_bp1 = 0;
102 102 // set another ring for the ASM storage
103 103 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
104 104 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 105 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 106 {
107 107 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2;
108 108 }
109 109 }
110 110
111 111 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
112 112 {
113 113 nb_norm_bp2 = 0;
114 114 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 115 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 116 {
117 117 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2;
118 118 }
119 119 }
120 120
121 121 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
122 122 {
123 123 nb_norm_asm = 0;
124 124 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
125 125 || (lfrCurrentMode == LFR_MODE_SBM2) )
126 126 {
127 127 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2;
128 128 }
129 129 }
130 130
131 131 //*************************
132 132 // send the message to MATR
133 133 if (msgForMATR.event != 0x00)
134 134 {
135 135 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC2);
136 136 }
137 137
138 138 if (status != RTEMS_SUCCESSFUL) {
139 139 printf("in AVF2 *** Error sending message to MATR, code %d\n", status);
140 140 }
141 141 }
142 142 }
143 143
144 144 rtems_task prc2_task( rtems_task_argument argument )
145 145 {
146 146 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
147 147 size_t size; // size of the incoming TC packet
148 148 asm_msg *incomingMsg;
149 149 //
150 150 rtems_status_code status;
151 151 rtems_id queue_id_send;
152 152 rtems_id queue_id_q_p2;
153 153 bp_packet packet_norm_bp1;
154 154 bp_packet packet_norm_bp2;
155 155 ring_node *current_ring_node_to_send_asm_f2;
156 156
157 157 unsigned long long int localTime;
158 158
159 159 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
160 160 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
161 161 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
162 162
163 163 //*************
164 164 // NORM headers
165 165 BP_init_header( &packet_norm_bp1,
166 166 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
167 167 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
168 168 BP_init_header( &packet_norm_bp2,
169 169 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
170 170 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
171 171
172 172 status = get_message_queue_id_send( &queue_id_send );
173 173 if (status != RTEMS_SUCCESSFUL)
174 174 {
175 175 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
176 176 }
177 177 status = get_message_queue_id_prc2( &queue_id_q_p2);
178 178 if (status != RTEMS_SUCCESSFUL)
179 179 {
180 180 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
181 181 }
182 182
183 183 BOOT_PRINTF("in PRC2 ***\n")
184 184
185 185 while(1){
186 186 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
187 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
187 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
188 188
189 189 incomingMsg = (asm_msg*) incomingData;
190 190
191 191 localTime = getTimeAsUnsignedLongLongInt( );
192 192
193 193 //*****
194 194 //*****
195 195 // NORM
196 196 //*****
197 197 //*****
198 // 1) compress the matrix for Basic Parameters calculation
199 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2,
200 nb_sm_before_f2.norm_bp1,
201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 ASM_F2_INDICE_START );
203 // BP1_F2
198 204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
199 205 {
200 // 1) compress the matrix for Basic Parameters calculation
201 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2,
202 nb_sm_before_f2.norm_bp1,
203 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
204 ASM_F2_INDICE_START );
205 // 2) compute the BP1 set
206 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
207 // 3) send the BP1 set
206 // 1) compute the BP1 set
207 // BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 // 2) send the BP1 set
208 209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
209 210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 211 BP_send( (char *) &packet_norm_bp1, queue_id_send,
211 212 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
212 213 SID_NORM_BP1_F2 );
213 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
214 {
215 // 1) compute the BP2 set using the same ASM as the one used for BP1
216 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
217 // 2) send the BP2 set
218 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
219 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
220 BP_send( (char *) &packet_norm_bp2, queue_id_send,
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
222 SID_NORM_BP2_F2 );
223 }
214 }
215 // BP2_F2
216 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
217 {
218 // 1) compute the BP2 set
219 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
220 // 2) send the BP2 set
221 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
222 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
223 BP_send( (char *) &packet_norm_bp2, queue_id_send,
224 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
225 SID_NORM_BP2_F2 );
224 226 }
225 227
226 228 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
227 229 {
228 230 // 1) reorganize the ASM and divide
229 231 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
230 232 asm_f2_reorganized,
231 233 nb_sm_before_f2.norm_bp1 );
232 234 // 2) convert the float array in a char array
233 235 ASM_convert( asm_f2_reorganized, (char*) current_ring_node_to_send_asm_f2->buffer_address );
234 236 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
235 237 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
236 238 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
237 239 // 3) send the spectral matrix packets
238 240 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
239 241 // change asm ring node
240 242 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
241 243 }
242 244
243 245 }
244 246 }
245 247
246 248 //**********
247 249 // FUNCTIONS
248 250
249 251 void reset_nb_sm_f2( void )
250 252 {
251 253 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
252 254 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
253 255 nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1];
254 256 }
255 257
256 258 void SM_average_f2( float *averaged_spec_mat_f2,
257 259 ring_node *ring_node,
258 260 unsigned int nbAverageNormF2,
259 261 asm_msg *msgForMATR )
260 262 {
261 263 float sum;
262 264 unsigned int i;
263 265
264 266 for(i=0; i<TOTAL_SIZE_SM; i++)
265 267 {
266 268 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
267 269 if ( (nbAverageNormF2 == 0) )
268 270 {
269 271 averaged_spec_mat_f2[ i ] = sum;
270 272 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
271 273 msgForMATR->fineTimeNORM = ring_node->fineTime;
272 274 }
273 275 else
274 276 {
275 277 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
276 278 }
277 279 }
278 280 }
279 281
280 282 void init_k_coefficients_f2( void )
281 283 {
282 284 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
283 285 }
@@ -1,538 +1,586
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "fsw_processing.h"
11 11 #include "fsw_processing_globals.c"
12 12
13 13 unsigned int nb_sm_f0;
14 14 unsigned int nb_sm_f0_aux_f1;
15 15 unsigned int nb_sm_f1;
16 16 unsigned int nb_sm_f0_aux_f2;
17 17
18 18 //************************
19 19 // spectral matrices rings
20 20 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
21 21 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
22 22 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
23 23 ring_node *current_ring_node_sm_f0;
24 24 ring_node *current_ring_node_sm_f1;
25 25 ring_node *current_ring_node_sm_f2;
26 26 ring_node *ring_node_for_averaging_sm_f0;
27 27 ring_node *ring_node_for_averaging_sm_f1;
28 28 ring_node *ring_node_for_averaging_sm_f2;
29 29
30 30 //
31 31 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
32 32 {
33 33 ring_node *node;
34 34
35 35 node = NULL;
36 36 switch ( frequencyChannel ) {
37 37 case 0:
38 38 node = ring_node_for_averaging_sm_f0;
39 39 break;
40 40 case 1:
41 41 node = ring_node_for_averaging_sm_f1;
42 42 break;
43 43 case 2:
44 44 node = ring_node_for_averaging_sm_f2;
45 45 break;
46 46 default:
47 47 break;
48 48 }
49 49
50 50 return node;
51 51 }
52 52
53 53 //***********************************************************
54 54 // Interrupt Service Routine for spectral matrices processing
55 55
56 void spectral_matrices_isr_f0( void )
56 void spectral_matrices_isr_f0( unsigned char statusReg )
57 57 {
58 58 unsigned char status;
59 59 rtems_status_code status_code;
60 60 ring_node *full_ring_node;
61 61
62 status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits
62 status = statusReg & 0x03; // [0011] get the status_ready_matrix_f0_x bits
63 63
64 64 switch(status)
65 65 {
66 66 case 0:
67 67 break;
68 68 case 3:
69 69 // UNEXPECTED VALUE
70 70 spectral_matrix_regs->status = 0x03; // [0011]
71 71 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
72 72 break;
73 73 case 1:
74 74 full_ring_node = current_ring_node_sm_f0->previous;
75 75 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
76 76 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
77 77 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
78 78 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
79 79 // if there are enough ring nodes ready, wake up an AVFx task
80 80 nb_sm_f0 = nb_sm_f0 + 1;
81 81 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
82 82 {
83 83 ring_node_for_averaging_sm_f0 = full_ring_node;
84 84 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
85 85 {
86 86 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
87 87 }
88 88 nb_sm_f0 = 0;
89 89 }
90 90 spectral_matrix_regs->status = 0x01; // [0000 0001]
91 91 break;
92 92 case 2:
93 93 full_ring_node = current_ring_node_sm_f0->previous;
94 94 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
95 95 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
96 96 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
97 97 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
98 98 // if there are enough ring nodes ready, wake up an AVFx task
99 99 nb_sm_f0 = nb_sm_f0 + 1;
100 100 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
101 101 {
102 102 ring_node_for_averaging_sm_f0 = full_ring_node;
103 103 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
104 104 {
105 105 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
106 106 }
107 107 nb_sm_f0 = 0;
108 108 }
109 109 spectral_matrix_regs->status = 0x02; // [0000 0010]
110 110 break;
111 111 }
112 112 }
113 113
114 void spectral_matrices_isr_f1( void )
114 void spectral_matrices_isr_f1( unsigned char statusReg )
115 115 {
116 116 rtems_status_code status_code;
117 117 unsigned char status;
118 118 ring_node *full_ring_node;
119 119
120 status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
120 status = (statusReg & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
121 121
122 122 switch(status)
123 123 {
124 124 case 0:
125 125 break;
126 126 case 3:
127 127 // UNEXPECTED VALUE
128 128 spectral_matrix_regs->status = 0xc0; // [1100]
129 129 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
130 130 break;
131 131 case 1:
132 132 full_ring_node = current_ring_node_sm_f1->previous;
133 133 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
134 134 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
135 135 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
136 136 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
137 137 // if there are enough ring nodes ready, wake up an AVFx task
138 138 nb_sm_f1 = nb_sm_f1 + 1;
139 139 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
140 140 {
141 141 ring_node_for_averaging_sm_f1 = full_ring_node;
142 142 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
143 143 {
144 144 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
145 145 }
146 146 nb_sm_f1 = 0;
147 147 }
148 148 spectral_matrix_regs->status = 0x04; // [0000 0100]
149 149 break;
150 150 case 2:
151 151 full_ring_node = current_ring_node_sm_f1->previous;
152 152 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
153 153 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
154 154 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
155 155 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
156 156 // if there are enough ring nodes ready, wake up an AVFx task
157 157 nb_sm_f1 = nb_sm_f1 + 1;
158 158 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
159 159 {
160 160 ring_node_for_averaging_sm_f1 = full_ring_node;
161 161 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
162 162 {
163 163 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
164 164 }
165 165 nb_sm_f1 = 0;
166 166 }
167 167 spectral_matrix_regs->status = 0x08; // [1000 0000]
168 168 break;
169 169 }
170 170 }
171 171
172 void spectral_matrices_isr_f2( void )
172 void spectral_matrices_isr_f2( unsigned char statusReg )
173 173 {
174 174 unsigned char status;
175 175 rtems_status_code status_code;
176 176
177 status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
177 status = (statusReg & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
178 178
179 179 switch(status)
180 180 {
181 181 case 0:
182 182 break;
183 183 case 3:
184 184 // UNEXPECTED VALUE
185 185 spectral_matrix_regs->status = 0x30; // [0011 0000]
186 186 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
187 187 break;
188 188 case 1:
189 189 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
190 190 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
191 191 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
192 192 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
193 193 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
194 194 spectral_matrix_regs->status = 0x10; // [0001 0000]
195 195 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
196 196 {
197 197 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
198 198 }
199 199 break;
200 200 case 2:
201 201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
202 202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
203 203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
204 204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
205 205 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
206 206 spectral_matrix_regs->status = 0x20; // [0010 0000]
207 207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
208 208 {
209 209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
210 210 }
211 211 break;
212 212 }
213 213 }
214 214
215 void spectral_matrix_isr_error_handler( void )
215 void spectral_matrix_isr_error_handler( unsigned char statusReg )
216 216 {
217 217 rtems_status_code status_code;
218 218
219 if (spectral_matrix_regs->status & 0x7c0) // [0111 1100 0000]
219 if (statusReg & 0x7c0) // [0111 1100 0000]
220 220 {
221 221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
222 222 }
223 223
224 224 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
225 225 }
226 226
227 227 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
228 228 {
229 229 // STATUS REGISTER
230 230 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
231 231 // 10 9 8
232 232 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
233 233 // 7 6 5 4 3 2 1 0
234 234
235 spectral_matrices_isr_f0();
235 unsigned char statusReg;
236 236
237 spectral_matrices_isr_f1();
237 statusReg = spectral_matrix_regs->status;
238
239 spectral_matrices_isr_f0( statusReg );
238 240
239 spectral_matrices_isr_f2();
241 spectral_matrices_isr_f1( statusReg );
240 242
241 spectral_matrix_isr_error_handler();
243 spectral_matrices_isr_f2( statusReg );
244
245 spectral_matrix_isr_error_handler( statusReg );
242 246 }
243 247
244 248 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
245 249 {
246 250 rtems_status_code status_code;
247 251
248 252 //***
249 253 // F0
250 254 nb_sm_f0 = nb_sm_f0 + 1;
251 255 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
252 256 {
253 257 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
254 258 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
255 259 {
256 260 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
257 261 }
258 262 nb_sm_f0 = 0;
259 263 }
260 264
261 265 //***
262 266 // F1
263 267 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
264 268 if (nb_sm_f0_aux_f1 == 6)
265 269 {
266 270 nb_sm_f0_aux_f1 = 0;
267 271 nb_sm_f1 = nb_sm_f1 + 1;
268 272 }
269 273 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
270 274 {
271 275 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
272 276 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
273 277 {
274 278 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
275 279 }
276 280 nb_sm_f1 = 0;
277 281 }
278 282
279 283 //***
280 284 // F2
281 285 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
282 286 if (nb_sm_f0_aux_f2 == 96)
283 287 {
284 288 nb_sm_f0_aux_f2 = 0;
285 289 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
286 290 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
287 291 {
288 292 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
289 293 }
290 294 }
291 295 }
292 296
293 297 //******************
294 298 // Spectral Matrices
295 299
296 300 void reset_nb_sm( void )
297 301 {
298 302 nb_sm_f0 = 0;
299 303 nb_sm_f0_aux_f1 = 0;
300 304 nb_sm_f0_aux_f2 = 0;
301 305
302 306 nb_sm_f1 = 0;
303 307 }
304 308
305 309 void SM_init_rings( void )
306 310 {
307 311 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
308 312 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
309 313 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
310 314
311 315 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
312 316 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
313 317 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
314 318 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
315 319 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
316 320 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
317 321 }
318 322
319 323 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
320 324 {
321 325 unsigned char i;
322 326
323 327 ring[ nbNodes - 1 ].next
324 328 = (ring_node_asm*) &ring[ 0 ];
325 329
326 330 for(i=0; i<nbNodes-1; i++)
327 331 {
328 332 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
329 333 }
330 334 }
331 335
332 336 void SM_reset_current_ring_nodes( void )
333 337 {
334 338 current_ring_node_sm_f0 = sm_ring_f0[0].next;
335 339 current_ring_node_sm_f1 = sm_ring_f1[0].next;
336 340 current_ring_node_sm_f2 = sm_ring_f2[0].next;
337 341
338 342 ring_node_for_averaging_sm_f0 = NULL;
339 343 ring_node_for_averaging_sm_f1 = NULL;
340 344 ring_node_for_averaging_sm_f2 = NULL;
341 345 }
342 346
343 347 //*****************
344 348 // Basic Parameters
345 349
346 350 void BP_init_header( bp_packet *packet,
347 351 unsigned int apid, unsigned char sid,
348 352 unsigned int packetLength, unsigned char blkNr )
349 353 {
350 354 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
351 355 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
352 356 packet->reserved = 0x00;
353 357 packet->userApplication = CCSDS_USER_APP;
354 358 packet->packetID[0] = (unsigned char) (apid >> 8);
355 359 packet->packetID[1] = (unsigned char) (apid);
356 360 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
357 361 packet->packetSequenceControl[1] = 0x00;
358 362 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
359 363 packet->packetLength[1] = (unsigned char) (packetLength);
360 364 // DATA FIELD HEADER
361 365 packet->spare1_pusVersion_spare2 = 0x10;
362 366 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
363 367 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
364 368 packet->destinationID = TM_DESTINATION_ID_GROUND;
365 369 packet->time[0] = 0x00;
366 370 packet->time[1] = 0x00;
367 371 packet->time[2] = 0x00;
368 372 packet->time[3] = 0x00;
369 373 packet->time[4] = 0x00;
370 374 packet->time[5] = 0x00;
371 375 // AUXILIARY DATA HEADER
372 376 packet->sid = sid;
373 377 packet->biaStatusInfo = 0x00;
374 378 packet->acquisitionTime[0] = 0x00;
375 379 packet->acquisitionTime[1] = 0x00;
376 380 packet->acquisitionTime[2] = 0x00;
377 381 packet->acquisitionTime[3] = 0x00;
378 382 packet->acquisitionTime[4] = 0x00;
379 383 packet->acquisitionTime[5] = 0x00;
380 384 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
381 385 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
382 386 }
383 387
384 388 void BP_init_header_with_spare( bp_packet_with_spare *packet,
385 389 unsigned int apid, unsigned char sid,
386 390 unsigned int packetLength , unsigned char blkNr)
387 391 {
388 392 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
389 393 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
390 394 packet->reserved = 0x00;
391 395 packet->userApplication = CCSDS_USER_APP;
392 396 packet->packetID[0] = (unsigned char) (apid >> 8);
393 397 packet->packetID[1] = (unsigned char) (apid);
394 398 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
395 399 packet->packetSequenceControl[1] = 0x00;
396 400 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
397 401 packet->packetLength[1] = (unsigned char) (packetLength);
398 402 // DATA FIELD HEADER
399 403 packet->spare1_pusVersion_spare2 = 0x10;
400 404 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
401 405 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
402 406 packet->destinationID = TM_DESTINATION_ID_GROUND;
403 407 // AUXILIARY DATA HEADER
404 408 packet->sid = sid;
405 409 packet->biaStatusInfo = 0x00;
406 410 packet->time[0] = 0x00;
407 411 packet->time[0] = 0x00;
408 412 packet->time[0] = 0x00;
409 413 packet->time[0] = 0x00;
410 414 packet->time[0] = 0x00;
411 415 packet->time[0] = 0x00;
412 416 packet->source_data_spare = 0x00;
413 417 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
414 418 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
415 419 }
416 420
417 421 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
418 422 {
419 423 rtems_status_code status;
420 424
421 425 // SET THE SEQUENCE_CNT PARAMETER
422 426 increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid );
423 427 // SEND PACKET
424 428 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
425 429 if (status != RTEMS_SUCCESSFUL)
426 430 {
427 431 printf("ERR *** in BP_send *** ERR %d\n", (int) status);
428 432 }
429 433 }
430 434
431 435 //******************
432 436 // general functions
433 437
434 438 void reset_sm_status( void )
435 439 {
436 440 // error
437 441 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
438 442 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
439 443 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
440 444 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
441 445
442 446 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
443 447 }
444 448
445 449 void reset_spectral_matrix_regs( void )
446 450 {
447 451 /** This function resets the spectral matrices module registers.
448 452 *
449 453 * The registers affected by this function are located at the following offset addresses:
450 454 *
451 455 * - 0x00 config
452 456 * - 0x04 status
453 457 * - 0x08 matrixF0_Address0
454 458 * - 0x10 matrixFO_Address1
455 459 * - 0x14 matrixF1_Address
456 460 * - 0x18 matrixF2_Address
457 461 *
458 462 */
459 463
460 464 set_sm_irq_onError( 0 );
461 465
462 466 set_sm_irq_onNewMatrix( 0 );
463 467
464 468 reset_sm_status();
465 469
466 470 // F1
467 471 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
468 472 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
469 473 // F2
470 474 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
471 475 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
472 476 // F3
473 477 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
474 478 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
475 479
476 480 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
477 481 }
478 482
479 483 void set_time( unsigned char *time, unsigned char * timeInBuffer )
480 484 {
481 485 time[0] = timeInBuffer[0];
482 486 time[1] = timeInBuffer[1];
483 487 time[2] = timeInBuffer[2];
484 488 time[3] = timeInBuffer[3];
485 489 time[4] = timeInBuffer[6];
486 490 time[5] = timeInBuffer[7];
487 491 }
488 492
489 493 unsigned long long int get_acquisition_time( unsigned char *timePtr )
490 494 {
491 495 unsigned long long int acquisitionTimeAslong;
492 496 acquisitionTimeAslong = 0x00;
493 497 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
494 498 + ( (unsigned long long int) timePtr[1] << 32 )
495 499 + ( (unsigned long long int) timePtr[2] << 24 )
496 500 + ( (unsigned long long int) timePtr[3] << 16 )
497 501 + ( (unsigned long long int) timePtr[6] << 8 )
498 502 + ( (unsigned long long int) timePtr[7] );
499 503 return acquisitionTimeAslong;
500 504 }
501 505
502 506 unsigned char getSID( rtems_event_set event )
503 507 {
504 508 unsigned char sid;
505 509
506 510 rtems_event_set eventSetBURST;
507 511 rtems_event_set eventSetSBM;
508 512
509 513 //******
510 514 // BURST
511 515 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
512 516 | RTEMS_EVENT_BURST_BP1_F1
513 517 | RTEMS_EVENT_BURST_BP2_F0
514 518 | RTEMS_EVENT_BURST_BP2_F1;
515 519
516 520 //****
517 521 // SBM
518 522 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
519 523 | RTEMS_EVENT_SBM_BP1_F1
520 524 | RTEMS_EVENT_SBM_BP2_F0
521 525 | RTEMS_EVENT_SBM_BP2_F1;
522 526
523 527 if (event & eventSetBURST)
524 528 {
525 529 sid = SID_BURST_BP1_F0;
526 530 }
527 531 else if (event & eventSetSBM)
528 532 {
529 533 sid = SID_SBM1_BP1_F0;
530 534 }
531 535 else
532 536 {
533 537 sid = 0;
534 538 }
535 539
536 540 return sid;
537 541 }
538 542
543 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
544 {
545 unsigned int i;
546 float re;
547 float im;
548
549 for (i=0; i<NB_BINS_PER_SM; i++){
550 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
551 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
552 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
553 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
554 }
555 }
556
557 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
558 {
559 unsigned int i;
560 float re;
561
562 for (i=0; i<NB_BINS_PER_SM; i++){
563 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
564 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
565 }
566 }
567
568 void ASM_patch( float *inputASM, float *outputASM )
569 {
570 extractReImVectors( inputASM, outputASM, 1); // b1b2
571 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
572 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
573 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
574 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
575 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
576 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
577 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
578 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
579 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
580
581 copyReVectors(inputASM, outputASM, 0 ); // b1b1
582 copyReVectors(inputASM, outputASM, 9 ); // b2b2
583 copyReVectors(inputASM, outputASM, 16); // b3b3
584 copyReVectors(inputASM, outputASM, 21); // e1e1
585 copyReVectors(inputASM, outputASM, 24); // e2e2
586 }
@@ -1,65 +1,94
1 1 #define NB_VALUES_PER_SM 25
2 2 #define NB_BINS_PER_SM 128
3 3
4 4 #define NB_BINS_COMPRESSED_SM_F0 11
5 5 #define ASM_F0_INDICE_START 17 // 88 bins
6 6 #define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins
7 7 #define NB_BINS_TO_AVERAGE_ASM_F0 8
8 8
9 9 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
10 10 {
11 11 int frequencyBin;
12 12 int asmComponent;
13 13 unsigned int offsetASM;
14 14 unsigned int offsetASMReorganized;
15 15
16 16 // BUILD DATA
17 17 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
18 18 {
19 19 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
20 20 {
21 21 offsetASMReorganized =
22 22 frequencyBin * NB_VALUES_PER_SM
23 23 + asmComponent;
24 24 offsetASM =
25 25 asmComponent * NB_BINS_PER_SM
26 26 + frequencyBin;
27 27 averaged_spec_mat_reorganized[offsetASMReorganized ] =
28 28 averaged_spec_mat[ offsetASM ] / divider;
29 29 }
30 30 }
31 31 }
32 32
33 33 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
34 34 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
35 35 {
36 36 int frequencyBin;
37 37 int asmComponent;
38 38 int offsetASM;
39 39 int offsetCompressed;
40 40 int k;
41 41
42 42 // BUILD DATA
43 43 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
44 44 {
45 45 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
46 46 {
47 47 offsetCompressed = // NO TIME OFFSET
48 48 frequencyBin * NB_VALUES_PER_SM
49 49 + asmComponent;
50 50 offsetASM = // NO TIME OFFSET
51 51 asmComponent * NB_BINS_PER_SM
52 52 + ASMIndexStart
53 53 + frequencyBin * nbBinsToAverage;
54 54 compressed_spec_mat[ offsetCompressed ] = 0;
55 55 for ( k = 0; k < nbBinsToAverage; k++ )
56 56 {
57 57 compressed_spec_mat[offsetCompressed ] =
58 58 ( compressed_spec_mat[ offsetCompressed ]
59 59 + averaged_spec_mat[ offsetASM + k ] );
60 60 }
61 61 compressed_spec_mat[ offsetCompressed ] =
62 62 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
63 63 }
64 64 }
65 65 }
66
67 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
68 {
69 unsigned int i;
70 float re;
71 float im;
72
73 for (i=0; i<NB_BINS_PER_SM; i++){
74 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
75 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
76 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
77 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
78 }
79
80 }
81
82 void ASM_patch( float *inputASM, float *outputASM )
83 {
84 extractReImVectors( inputASM, outputASM, 1); // b1b2
85 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
86 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
87 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
88 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
89 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
90 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
91 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
92 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
93 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
94 }
@@ -1,64 +1,69
1 1 #include <stdio.h>
2 2
3 3 #include "functions.h"
4 4
5 5 int main(void)
6 6 {
7 7 printf("Hello World!\n");
8 8
9 9 unsigned int asmComponent;
10 10 unsigned int frequencyBin;
11 11 unsigned int offset_input_ASM;
12 12
13 13 float input_ASM [ NB_VALUES_PER_SM * NB_BINS_PER_SM ];
14 14 float output_ASM [ NB_VALUES_PER_SM * NB_BINS_PER_SM ];
15 float patched_ASM [ NB_VALUES_PER_SM * NB_BINS_PER_SM ];
15 16 float output_ASM_compressed [ NB_VALUES_PER_SM * NB_BINS_COMPRESSED_SM_F0 ];
16 17
17 18 //*******
18 19 // TEST 1
19 20
20 21 offset_input_ASM = 0;
21 22
22 23 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
23 24 {
24 25 for (frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++)
25 26 {
26 27 offset_input_ASM = asmComponent * NB_BINS_PER_SM + frequencyBin;
27 28 input_ASM[ offset_input_ASM ] = asmComponent;
28 29 }
29 30 }
30 31
32 ASM_patch( input_ASM, patched_ASM );
33
31 34 ASM_reorganize_and_divide( input_ASM, output_ASM,
32 35 1 ); // divider
33 36
34 37 ASM_compress_reorganize_and_divide( input_ASM, output_ASM_compressed,
35 38 1, // divider
36 39 NB_BINS_COMPRESSED_SM_F0,
37 40 NB_BINS_TO_AVERAGE_ASM_F0,
38 41 ASM_F0_INDICE_START);
39 42
40 43 //*******
41 44 // TEST 2
42 45 offset_input_ASM = 0;
43 46
44 47 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
45 48 {
46 49 for (frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++)
47 50 {
48 51 offset_input_ASM = asmComponent * NB_BINS_PER_SM + frequencyBin;
49 52 input_ASM[ offset_input_ASM ] = asmComponent * NB_BINS_PER_SM + frequencyBin;
50 53 }
51 54 }
52 55
53 56 ASM_reorganize_and_divide( input_ASM, output_ASM,
54 57 1 ); // divider
55 58
56 59 ASM_compress_reorganize_and_divide( input_ASM, output_ASM_compressed,
57 60 10, // divider
58 61 NB_BINS_COMPRESSED_SM_F0,
59 62 NB_BINS_TO_AVERAGE_ASM_F0,
60 63 ASM_F0_INDICE_START);
61 64
65 ASM_patch( input_ASM, patched_ASM );
66
62 67 return 0;
63 68 }
64 69
General Comments 0
You need to be logged in to leave comments. Login now