|
@@
-1,652
+1,656
|
|
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
|
#include "fsw_init.h"
|
|
13
|
13
|
|
|
14
|
14
|
unsigned int nb_sm_f0;
|
|
15
|
15
|
unsigned int nb_sm_f0_aux_f1;
|
|
16
|
16
|
unsigned int nb_sm_f1;
|
|
17
|
17
|
unsigned int nb_sm_f0_aux_f2;
|
|
18
|
18
|
|
|
19
|
19
|
//************************
|
|
20
|
20
|
// spectral matrices rings
|
|
21
|
21
|
ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
|
|
22
|
22
|
ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
|
|
23
|
23
|
ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
|
|
24
|
24
|
ring_node *current_ring_node_sm_f0;
|
|
25
|
25
|
ring_node *current_ring_node_sm_f1;
|
|
26
|
26
|
ring_node *current_ring_node_sm_f2;
|
|
27
|
27
|
ring_node *ring_node_for_averaging_sm_f0;
|
|
28
|
28
|
ring_node *ring_node_for_averaging_sm_f1;
|
|
29
|
29
|
ring_node *ring_node_for_averaging_sm_f2;
|
|
30
|
30
|
|
|
31
|
31
|
//
|
|
32
|
32
|
ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
|
|
33
|
33
|
{
|
|
34
|
34
|
ring_node *node;
|
|
35
|
35
|
|
|
36
|
36
|
node = NULL;
|
|
37
|
37
|
switch ( frequencyChannel ) {
|
|
38
|
38
|
case 0:
|
|
39
|
39
|
node = ring_node_for_averaging_sm_f0;
|
|
40
|
40
|
break;
|
|
41
|
41
|
case 1:
|
|
42
|
42
|
node = ring_node_for_averaging_sm_f1;
|
|
43
|
43
|
break;
|
|
44
|
44
|
case 2:
|
|
45
|
45
|
node = ring_node_for_averaging_sm_f2;
|
|
46
|
46
|
break;
|
|
47
|
47
|
default:
|
|
48
|
48
|
break;
|
|
49
|
49
|
}
|
|
50
|
50
|
|
|
51
|
51
|
return node;
|
|
52
|
52
|
}
|
|
53
|
53
|
|
|
54
|
54
|
//***********************************************************
|
|
55
|
55
|
// Interrupt Service Routine for spectral matrices processing
|
|
56
|
56
|
|
|
57
|
57
|
void spectral_matrices_isr_f0( unsigned char statusReg )
|
|
58
|
58
|
{
|
|
59
|
59
|
unsigned char status;
|
|
60
|
60
|
rtems_status_code status_code;
|
|
61
|
61
|
ring_node *full_ring_node;
|
|
62
|
62
|
|
|
63
|
63
|
status = statusReg & 0x03; // [0011] get the status_ready_matrix_f0_x bits
|
|
64
|
64
|
|
|
65
|
65
|
switch(status)
|
|
66
|
66
|
{
|
|
67
|
67
|
case 0:
|
|
68
|
68
|
break;
|
|
69
|
69
|
case 3:
|
|
70
|
70
|
// UNEXPECTED VALUE
|
|
71
|
71
|
spectral_matrix_regs->status = 0x03; // [0011]
|
|
72
|
72
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
|
|
73
|
73
|
break;
|
|
74
|
74
|
case 1:
|
|
75
|
75
|
full_ring_node = current_ring_node_sm_f0->previous;
|
|
76
|
76
|
full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
|
|
77
|
77
|
full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
|
|
78
|
78
|
current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
|
|
79
|
79
|
spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
|
|
80
|
80
|
// if there are enough ring nodes ready, wake up an AVFx task
|
|
81
|
81
|
nb_sm_f0 = nb_sm_f0 + 1;
|
|
82
|
82
|
if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
|
|
83
|
83
|
{
|
|
84
|
84
|
ring_node_for_averaging_sm_f0 = full_ring_node;
|
|
85
|
85
|
if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
86
|
86
|
{
|
|
87
|
87
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
88
|
88
|
}
|
|
89
|
89
|
nb_sm_f0 = 0;
|
|
90
|
90
|
}
|
|
91
|
91
|
spectral_matrix_regs->status = 0x01; // [0000 0001]
|
|
92
|
92
|
break;
|
|
93
|
93
|
case 2:
|
|
94
|
94
|
full_ring_node = current_ring_node_sm_f0->previous;
|
|
95
|
95
|
full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
|
|
96
|
96
|
full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
|
|
97
|
97
|
current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
|
|
98
|
98
|
spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
|
|
99
|
99
|
// if there are enough ring nodes ready, wake up an AVFx task
|
|
100
|
100
|
nb_sm_f0 = nb_sm_f0 + 1;
|
|
101
|
101
|
if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
|
|
102
|
102
|
{
|
|
103
|
103
|
ring_node_for_averaging_sm_f0 = full_ring_node;
|
|
104
|
104
|
if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
105
|
105
|
{
|
|
106
|
106
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
107
|
107
|
}
|
|
108
|
108
|
nb_sm_f0 = 0;
|
|
109
|
109
|
}
|
|
110
|
110
|
spectral_matrix_regs->status = 0x02; // [0000 0010]
|
|
111
|
111
|
break;
|
|
112
|
112
|
}
|
|
113
|
113
|
}
|
|
114
|
114
|
|
|
115
|
115
|
void spectral_matrices_isr_f1( unsigned char statusReg )
|
|
116
|
116
|
{
|
|
117
|
117
|
rtems_status_code status_code;
|
|
118
|
118
|
unsigned char status;
|
|
119
|
119
|
ring_node *full_ring_node;
|
|
120
|
120
|
|
|
121
|
121
|
status = (statusReg & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
|
|
122
|
122
|
|
|
123
|
123
|
switch(status)
|
|
124
|
124
|
{
|
|
125
|
125
|
case 0:
|
|
126
|
126
|
break;
|
|
127
|
127
|
case 3:
|
|
128
|
128
|
// UNEXPECTED VALUE
|
|
129
|
129
|
spectral_matrix_regs->status = 0xc0; // [1100]
|
|
130
|
130
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
|
|
131
|
131
|
break;
|
|
132
|
132
|
case 1:
|
|
133
|
133
|
full_ring_node = current_ring_node_sm_f1->previous;
|
|
134
|
134
|
full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
|
|
135
|
135
|
full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
|
|
136
|
136
|
current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
|
|
137
|
137
|
spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
|
|
138
|
138
|
// if there are enough ring nodes ready, wake up an AVFx task
|
|
139
|
139
|
nb_sm_f1 = nb_sm_f1 + 1;
|
|
140
|
140
|
if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
|
|
141
|
141
|
{
|
|
142
|
142
|
ring_node_for_averaging_sm_f1 = full_ring_node;
|
|
143
|
143
|
if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
144
|
144
|
{
|
|
145
|
145
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
146
|
146
|
}
|
|
147
|
147
|
nb_sm_f1 = 0;
|
|
148
|
148
|
}
|
|
149
|
149
|
spectral_matrix_regs->status = 0x04; // [0000 0100]
|
|
150
|
150
|
break;
|
|
151
|
151
|
case 2:
|
|
152
|
152
|
full_ring_node = current_ring_node_sm_f1->previous;
|
|
153
|
153
|
full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
|
|
154
|
154
|
full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
|
|
155
|
155
|
current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
|
|
156
|
156
|
spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
|
|
157
|
157
|
// if there are enough ring nodes ready, wake up an AVFx task
|
|
158
|
158
|
nb_sm_f1 = nb_sm_f1 + 1;
|
|
159
|
159
|
if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
|
|
160
|
160
|
{
|
|
161
|
161
|
ring_node_for_averaging_sm_f1 = full_ring_node;
|
|
162
|
162
|
if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
163
|
163
|
{
|
|
164
|
164
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
165
|
165
|
}
|
|
166
|
166
|
nb_sm_f1 = 0;
|
|
167
|
167
|
}
|
|
168
|
168
|
spectral_matrix_regs->status = 0x08; // [1000 0000]
|
|
169
|
169
|
break;
|
|
170
|
170
|
}
|
|
171
|
171
|
}
|
|
172
|
172
|
|
|
173
|
173
|
void spectral_matrices_isr_f2( unsigned char statusReg )
|
|
174
|
174
|
{
|
|
175
|
175
|
unsigned char status;
|
|
176
|
176
|
rtems_status_code status_code;
|
|
177
|
177
|
|
|
178
|
178
|
status = (statusReg & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
|
|
179
|
179
|
|
|
180
|
180
|
switch(status)
|
|
181
|
181
|
{
|
|
182
|
182
|
case 0:
|
|
183
|
183
|
break;
|
|
184
|
184
|
case 3:
|
|
185
|
185
|
// UNEXPECTED VALUE
|
|
186
|
186
|
spectral_matrix_regs->status = 0x30; // [0011 0000]
|
|
187
|
187
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
|
|
188
|
188
|
break;
|
|
189
|
189
|
case 1:
|
|
190
|
190
|
ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
|
|
191
|
191
|
current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
|
|
192
|
192
|
ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
|
|
193
|
193
|
ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
|
|
194
|
194
|
spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
|
|
195
|
195
|
spectral_matrix_regs->status = 0x10; // [0001 0000]
|
|
196
|
196
|
if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
197
|
197
|
{
|
|
198
|
198
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
199
|
199
|
}
|
|
200
|
200
|
break;
|
|
201
|
201
|
case 2:
|
|
202
|
202
|
ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
|
|
203
|
203
|
current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
|
|
204
|
204
|
ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
|
|
205
|
205
|
ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
|
|
206
|
206
|
spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
|
|
207
|
207
|
spectral_matrix_regs->status = 0x20; // [0010 0000]
|
|
208
|
208
|
if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
209
|
209
|
{
|
|
210
|
210
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
211
|
211
|
}
|
|
212
|
212
|
break;
|
|
213
|
213
|
}
|
|
214
|
214
|
}
|
|
215
|
215
|
|
|
216
|
216
|
void spectral_matrix_isr_error_handler( unsigned char statusReg )
|
|
217
|
217
|
{
|
|
218
|
218
|
rtems_status_code status_code;
|
|
219
|
219
|
|
|
220
|
220
|
if (statusReg & 0x7c0) // [0111 1100 0000]
|
|
221
|
221
|
{
|
|
222
|
222
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
|
|
223
|
223
|
}
|
|
224
|
224
|
|
|
225
|
225
|
spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
|
|
226
|
226
|
}
|
|
227
|
227
|
|
|
228
|
228
|
rtems_isr spectral_matrices_isr( rtems_vector_number vector )
|
|
229
|
229
|
{
|
|
230
|
230
|
// STATUS REGISTER
|
|
231
|
231
|
// input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
|
|
232
|
232
|
// 10 9 8
|
|
233
|
233
|
// buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
|
|
234
|
234
|
// 7 6 5 4 3 2 1 0
|
|
235
|
235
|
|
|
236
|
236
|
unsigned char statusReg;
|
|
237
|
237
|
|
|
238
|
238
|
statusReg = spectral_matrix_regs->status;
|
|
239
|
239
|
|
|
240
|
240
|
spectral_matrices_isr_f0( statusReg );
|
|
241
|
241
|
|
|
242
|
242
|
spectral_matrices_isr_f1( statusReg );
|
|
243
|
243
|
|
|
244
|
244
|
spectral_matrices_isr_f2( statusReg );
|
|
245
|
245
|
|
|
246
|
246
|
spectral_matrix_isr_error_handler( statusReg );
|
|
247
|
247
|
}
|
|
248
|
248
|
|
|
249
|
249
|
rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
|
|
250
|
250
|
{
|
|
251
|
251
|
rtems_status_code status_code;
|
|
252
|
252
|
|
|
253
|
253
|
//***
|
|
254
|
254
|
// F0
|
|
255
|
255
|
nb_sm_f0 = nb_sm_f0 + 1;
|
|
256
|
256
|
if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
|
|
257
|
257
|
{
|
|
258
|
258
|
ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
|
|
259
|
259
|
if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
260
|
260
|
{
|
|
261
|
261
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
262
|
262
|
}
|
|
263
|
263
|
nb_sm_f0 = 0;
|
|
264
|
264
|
}
|
|
265
|
265
|
|
|
266
|
266
|
//***
|
|
267
|
267
|
// F1
|
|
268
|
268
|
nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
|
|
269
|
269
|
if (nb_sm_f0_aux_f1 == 6)
|
|
270
|
270
|
{
|
|
271
|
271
|
nb_sm_f0_aux_f1 = 0;
|
|
272
|
272
|
nb_sm_f1 = nb_sm_f1 + 1;
|
|
273
|
273
|
}
|
|
274
|
274
|
if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
|
|
275
|
275
|
{
|
|
276
|
276
|
ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
|
|
277
|
277
|
if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
278
|
278
|
{
|
|
279
|
279
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
280
|
280
|
}
|
|
281
|
281
|
nb_sm_f1 = 0;
|
|
282
|
282
|
}
|
|
283
|
283
|
|
|
284
|
284
|
//***
|
|
285
|
285
|
// F2
|
|
286
|
286
|
nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
|
|
287
|
287
|
if (nb_sm_f0_aux_f2 == 96)
|
|
288
|
288
|
{
|
|
289
|
289
|
nb_sm_f0_aux_f2 = 0;
|
|
290
|
290
|
ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
|
|
291
|
291
|
if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
|
|
292
|
292
|
{
|
|
293
|
293
|
status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
|
|
294
|
294
|
}
|
|
295
|
295
|
}
|
|
296
|
296
|
}
|
|
297
|
297
|
|
|
298
|
298
|
//******************
|
|
299
|
299
|
// Spectral Matrices
|
|
300
|
300
|
|
|
301
|
301
|
void reset_nb_sm( void )
|
|
302
|
302
|
{
|
|
303
|
303
|
nb_sm_f0 = 0;
|
|
304
|
304
|
nb_sm_f0_aux_f1 = 0;
|
|
305
|
305
|
nb_sm_f0_aux_f2 = 0;
|
|
306
|
306
|
|
|
307
|
307
|
nb_sm_f1 = 0;
|
|
308
|
308
|
}
|
|
309
|
309
|
|
|
310
|
310
|
void SM_init_rings( void )
|
|
311
|
311
|
{
|
|
312
|
312
|
init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
|
|
313
|
313
|
init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
|
|
314
|
314
|
init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
|
|
315
|
315
|
|
|
316
|
316
|
DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
|
|
317
|
317
|
DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
|
|
318
|
318
|
DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
|
|
319
|
319
|
DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
|
|
320
|
320
|
DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
|
|
321
|
321
|
DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
|
|
322
|
322
|
}
|
|
323
|
323
|
|
|
324
|
324
|
void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
|
|
325
|
325
|
{
|
|
326
|
326
|
unsigned char i;
|
|
327
|
327
|
|
|
328
|
328
|
ring[ nbNodes - 1 ].next
|
|
329
|
329
|
= (ring_node_asm*) &ring[ 0 ];
|
|
330
|
330
|
|
|
331
|
331
|
for(i=0; i<nbNodes-1; i++)
|
|
332
|
332
|
{
|
|
333
|
333
|
ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
|
|
334
|
334
|
}
|
|
335
|
335
|
}
|
|
336
|
336
|
|
|
337
|
337
|
void SM_reset_current_ring_nodes( void )
|
|
338
|
338
|
{
|
|
339
|
339
|
current_ring_node_sm_f0 = sm_ring_f0[0].next;
|
|
340
|
340
|
current_ring_node_sm_f1 = sm_ring_f1[0].next;
|
|
341
|
341
|
current_ring_node_sm_f2 = sm_ring_f2[0].next;
|
|
342
|
342
|
|
|
343
|
343
|
ring_node_for_averaging_sm_f0 = NULL;
|
|
344
|
344
|
ring_node_for_averaging_sm_f1 = NULL;
|
|
345
|
345
|
ring_node_for_averaging_sm_f2 = NULL;
|
|
346
|
346
|
}
|
|
347
|
347
|
|
|
348
|
348
|
//*****************
|
|
349
|
349
|
// Basic Parameters
|
|
350
|
350
|
|
|
351
|
351
|
void BP_init_header( bp_packet *packet,
|
|
352
|
352
|
unsigned int apid, unsigned char sid,
|
|
353
|
353
|
unsigned int packetLength, unsigned char blkNr )
|
|
354
|
354
|
{
|
|
355
|
355
|
packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
|
|
356
|
356
|
packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
|
|
357
|
357
|
packet->reserved = 0x00;
|
|
358
|
358
|
packet->userApplication = CCSDS_USER_APP;
|
|
359
|
359
|
packet->packetID[0] = (unsigned char) (apid >> 8);
|
|
360
|
360
|
packet->packetID[1] = (unsigned char) (apid);
|
|
361
|
361
|
packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
|
|
362
|
362
|
packet->packetSequenceControl[1] = 0x00;
|
|
363
|
363
|
packet->packetLength[0] = (unsigned char) (packetLength >> 8);
|
|
364
|
364
|
packet->packetLength[1] = (unsigned char) (packetLength);
|
|
365
|
365
|
// DATA FIELD HEADER
|
|
366
|
366
|
packet->spare1_pusVersion_spare2 = 0x10;
|
|
367
|
367
|
packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
|
|
368
|
368
|
packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
|
|
369
|
369
|
packet->destinationID = TM_DESTINATION_ID_GROUND;
|
|
370
|
370
|
packet->time[0] = 0x00;
|
|
371
|
371
|
packet->time[1] = 0x00;
|
|
372
|
372
|
packet->time[2] = 0x00;
|
|
373
|
373
|
packet->time[3] = 0x00;
|
|
374
|
374
|
packet->time[4] = 0x00;
|
|
375
|
375
|
packet->time[5] = 0x00;
|
|
376
|
376
|
// AUXILIARY DATA HEADER
|
|
377
|
377
|
packet->sid = sid;
|
|
378
|
378
|
packet->biaStatusInfo = 0x00;
|
|
|
379
|
packet->sy_lfr_common_parameters_spare = 0x00;
|
|
|
380
|
packet->sy_lfr_common_parameters = 0x00;
|
|
379
|
381
|
packet->acquisitionTime[0] = 0x00;
|
|
380
|
382
|
packet->acquisitionTime[1] = 0x00;
|
|
381
|
383
|
packet->acquisitionTime[2] = 0x00;
|
|
382
|
384
|
packet->acquisitionTime[3] = 0x00;
|
|
383
|
385
|
packet->acquisitionTime[4] = 0x00;
|
|
384
|
386
|
packet->acquisitionTime[5] = 0x00;
|
|
385
|
387
|
packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
|
|
386
|
388
|
packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
|
|
387
|
389
|
}
|
|
388
|
390
|
|
|
389
|
391
|
void BP_init_header_with_spare( bp_packet_with_spare *packet,
|
|
390
|
392
|
unsigned int apid, unsigned char sid,
|
|
391
|
393
|
unsigned int packetLength , unsigned char blkNr)
|
|
392
|
394
|
{
|
|
393
|
395
|
packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
|
|
394
|
396
|
packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
|
|
395
|
397
|
packet->reserved = 0x00;
|
|
396
|
398
|
packet->userApplication = CCSDS_USER_APP;
|
|
397
|
399
|
packet->packetID[0] = (unsigned char) (apid >> 8);
|
|
398
|
400
|
packet->packetID[1] = (unsigned char) (apid);
|
|
399
|
401
|
packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
|
|
400
|
402
|
packet->packetSequenceControl[1] = 0x00;
|
|
401
|
403
|
packet->packetLength[0] = (unsigned char) (packetLength >> 8);
|
|
402
|
404
|
packet->packetLength[1] = (unsigned char) (packetLength);
|
|
403
|
405
|
// DATA FIELD HEADER
|
|
404
|
406
|
packet->spare1_pusVersion_spare2 = 0x10;
|
|
405
|
407
|
packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
|
|
406
|
408
|
packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
|
|
407
|
409
|
packet->destinationID = TM_DESTINATION_ID_GROUND;
|
|
408
|
410
|
// AUXILIARY DATA HEADER
|
|
409
|
411
|
packet->sid = sid;
|
|
410
|
412
|
packet->biaStatusInfo = 0x00;
|
|
|
413
|
packet->sy_lfr_common_parameters_spare = 0x00;
|
|
|
414
|
packet->sy_lfr_common_parameters = 0x00;
|
|
411
|
415
|
packet->time[0] = 0x00;
|
|
412
|
416
|
packet->time[0] = 0x00;
|
|
413
|
417
|
packet->time[0] = 0x00;
|
|
414
|
418
|
packet->time[0] = 0x00;
|
|
415
|
419
|
packet->time[0] = 0x00;
|
|
416
|
420
|
packet->time[0] = 0x00;
|
|
417
|
421
|
packet->source_data_spare = 0x00;
|
|
418
|
422
|
packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
|
|
419
|
423
|
packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
|
|
420
|
424
|
}
|
|
421
|
425
|
|
|
422
|
426
|
void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
|
|
423
|
427
|
{
|
|
424
|
428
|
rtems_status_code status;
|
|
425
|
429
|
|
|
426
|
430
|
// SET THE SEQUENCE_CNT PARAMETER
|
|
427
|
431
|
increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid );
|
|
428
|
432
|
// SEND PACKET
|
|
429
|
433
|
status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
|
|
430
|
434
|
if (status != RTEMS_SUCCESSFUL)
|
|
431
|
435
|
{
|
|
432
|
436
|
printf("ERR *** in BP_send *** ERR %d\n", (int) status);
|
|
433
|
437
|
}
|
|
434
|
438
|
}
|
|
435
|
439
|
|
|
436
|
440
|
//******************
|
|
437
|
441
|
// general functions
|
|
438
|
442
|
|
|
439
|
443
|
void reset_sm_status( void )
|
|
440
|
444
|
{
|
|
441
|
445
|
// error
|
|
442
|
446
|
// 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
|
|
443
|
447
|
// input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
|
|
444
|
448
|
// ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
|
|
445
|
449
|
// ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
|
|
446
|
450
|
|
|
447
|
451
|
spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
|
|
448
|
452
|
}
|
|
449
|
453
|
|
|
450
|
454
|
void reset_spectral_matrix_regs( void )
|
|
451
|
455
|
{
|
|
452
|
456
|
/** This function resets the spectral matrices module registers.
|
|
453
|
457
|
*
|
|
454
|
458
|
* The registers affected by this function are located at the following offset addresses:
|
|
455
|
459
|
*
|
|
456
|
460
|
* - 0x00 config
|
|
457
|
461
|
* - 0x04 status
|
|
458
|
462
|
* - 0x08 matrixF0_Address0
|
|
459
|
463
|
* - 0x10 matrixFO_Address1
|
|
460
|
464
|
* - 0x14 matrixF1_Address
|
|
461
|
465
|
* - 0x18 matrixF2_Address
|
|
462
|
466
|
*
|
|
463
|
467
|
*/
|
|
464
|
468
|
|
|
465
|
469
|
set_sm_irq_onError( 0 );
|
|
466
|
470
|
|
|
467
|
471
|
set_sm_irq_onNewMatrix( 0 );
|
|
468
|
472
|
|
|
469
|
473
|
reset_sm_status();
|
|
470
|
474
|
|
|
471
|
475
|
// F1
|
|
472
|
476
|
spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
|
|
473
|
477
|
spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
|
|
474
|
478
|
// F2
|
|
475
|
479
|
spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
|
|
476
|
480
|
spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
|
|
477
|
481
|
// F3
|
|
478
|
482
|
spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
|
|
479
|
483
|
spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
|
|
480
|
484
|
|
|
481
|
485
|
spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
|
|
482
|
486
|
}
|
|
483
|
487
|
|
|
484
|
488
|
void set_time( unsigned char *time, unsigned char * timeInBuffer )
|
|
485
|
489
|
{
|
|
486
|
490
|
time[0] = timeInBuffer[0];
|
|
487
|
491
|
time[1] = timeInBuffer[1];
|
|
488
|
492
|
time[2] = timeInBuffer[2];
|
|
489
|
493
|
time[3] = timeInBuffer[3];
|
|
490
|
494
|
time[4] = timeInBuffer[6];
|
|
491
|
495
|
time[5] = timeInBuffer[7];
|
|
492
|
496
|
}
|
|
493
|
497
|
|
|
494
|
498
|
unsigned long long int get_acquisition_time( unsigned char *timePtr )
|
|
495
|
499
|
{
|
|
496
|
500
|
unsigned long long int acquisitionTimeAslong;
|
|
497
|
501
|
acquisitionTimeAslong = 0x00;
|
|
498
|
502
|
acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
|
|
499
|
503
|
+ ( (unsigned long long int) timePtr[1] << 32 )
|
|
500
|
504
|
+ ( (unsigned long long int) timePtr[2] << 24 )
|
|
501
|
505
|
+ ( (unsigned long long int) timePtr[3] << 16 )
|
|
502
|
506
|
+ ( (unsigned long long int) timePtr[6] << 8 )
|
|
503
|
507
|
+ ( (unsigned long long int) timePtr[7] );
|
|
504
|
508
|
return acquisitionTimeAslong;
|
|
505
|
509
|
}
|
|
506
|
510
|
|
|
507
|
511
|
unsigned char getSID( rtems_event_set event )
|
|
508
|
512
|
{
|
|
509
|
513
|
unsigned char sid;
|
|
510
|
514
|
|
|
511
|
515
|
rtems_event_set eventSetBURST;
|
|
512
|
516
|
rtems_event_set eventSetSBM;
|
|
513
|
517
|
|
|
514
|
518
|
//******
|
|
515
|
519
|
// BURST
|
|
516
|
520
|
eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
|
|
517
|
521
|
| RTEMS_EVENT_BURST_BP1_F1
|
|
518
|
522
|
| RTEMS_EVENT_BURST_BP2_F0
|
|
519
|
523
|
| RTEMS_EVENT_BURST_BP2_F1;
|
|
520
|
524
|
|
|
521
|
525
|
//****
|
|
522
|
526
|
// SBM
|
|
523
|
527
|
eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
|
|
524
|
528
|
| RTEMS_EVENT_SBM_BP1_F1
|
|
525
|
529
|
| RTEMS_EVENT_SBM_BP2_F0
|
|
526
|
530
|
| RTEMS_EVENT_SBM_BP2_F1;
|
|
527
|
531
|
|
|
528
|
532
|
if (event & eventSetBURST)
|
|
529
|
533
|
{
|
|
530
|
534
|
sid = SID_BURST_BP1_F0;
|
|
531
|
535
|
}
|
|
532
|
536
|
else if (event & eventSetSBM)
|
|
533
|
537
|
{
|
|
534
|
538
|
sid = SID_SBM1_BP1_F0;
|
|
535
|
539
|
}
|
|
536
|
540
|
else
|
|
537
|
541
|
{
|
|
538
|
542
|
sid = 0;
|
|
539
|
543
|
}
|
|
540
|
544
|
|
|
541
|
545
|
return sid;
|
|
542
|
546
|
}
|
|
543
|
547
|
|
|
544
|
548
|
void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
|
|
545
|
549
|
{
|
|
546
|
550
|
unsigned int i;
|
|
547
|
551
|
float re;
|
|
548
|
552
|
float im;
|
|
549
|
553
|
|
|
550
|
554
|
for (i=0; i<NB_BINS_PER_SM; i++){
|
|
551
|
555
|
re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
|
|
552
|
556
|
im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
|
|
553
|
557
|
outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
|
|
554
|
558
|
outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
|
|
555
|
559
|
}
|
|
556
|
560
|
}
|
|
557
|
561
|
|
|
558
|
562
|
void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
|
|
559
|
563
|
{
|
|
560
|
564
|
unsigned int i;
|
|
561
|
565
|
float re;
|
|
562
|
566
|
|
|
563
|
567
|
for (i=0; i<NB_BINS_PER_SM; i++){
|
|
564
|
568
|
re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
|
|
565
|
569
|
outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
|
|
566
|
570
|
}
|
|
567
|
571
|
}
|
|
568
|
572
|
|
|
569
|
573
|
void ASM_patch( float *inputASM, float *outputASM )
|
|
570
|
574
|
{
|
|
571
|
575
|
extractReImVectors( inputASM, outputASM, 1); // b1b2
|
|
572
|
576
|
extractReImVectors( inputASM, outputASM, 3 ); // b1b3
|
|
573
|
577
|
extractReImVectors( inputASM, outputASM, 5 ); // b1e1
|
|
574
|
578
|
extractReImVectors( inputASM, outputASM, 7 ); // b1e2
|
|
575
|
579
|
extractReImVectors( inputASM, outputASM, 10 ); // b2b3
|
|
576
|
580
|
extractReImVectors( inputASM, outputASM, 12 ); // b2e1
|
|
577
|
581
|
extractReImVectors( inputASM, outputASM, 14 ); // b2e2
|
|
578
|
582
|
extractReImVectors( inputASM, outputASM, 17 ); // b3e1
|
|
579
|
583
|
extractReImVectors( inputASM, outputASM, 19 ); // b3e2
|
|
580
|
584
|
extractReImVectors( inputASM, outputASM, 22 ); // e1e2
|
|
581
|
585
|
|
|
582
|
586
|
copyReVectors(inputASM, outputASM, 0 ); // b1b1
|
|
583
|
587
|
copyReVectors(inputASM, outputASM, 9 ); // b2b2
|
|
584
|
588
|
copyReVectors(inputASM, outputASM, 16); // b3b3
|
|
585
|
589
|
copyReVectors(inputASM, outputASM, 21); // e1e1
|
|
586
|
590
|
copyReVectors(inputASM, outputASM, 24); // e2e2
|
|
587
|
591
|
}
|
|
588
|
592
|
|
|
589
|
593
|
void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
|
|
590
|
594
|
unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
|
|
591
|
595
|
{
|
|
592
|
596
|
//*************
|
|
593
|
597
|
// input format
|
|
594
|
598
|
// component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
|
|
595
|
599
|
//**************
|
|
596
|
600
|
// output format
|
|
597
|
601
|
// matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
|
|
598
|
602
|
//************
|
|
599
|
603
|
// compression
|
|
600
|
604
|
// matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
|
|
601
|
605
|
// matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
|
|
602
|
606
|
|
|
603
|
607
|
int frequencyBin;
|
|
604
|
608
|
int asmComponent;
|
|
605
|
609
|
int offsetASM;
|
|
606
|
610
|
int offsetCompressed;
|
|
607
|
611
|
int offsetFBin;
|
|
608
|
612
|
int fBinMask;
|
|
609
|
613
|
int k;
|
|
610
|
614
|
|
|
611
|
615
|
// BUILD DATA
|
|
612
|
616
|
for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
|
|
613
|
617
|
{
|
|
614
|
618
|
for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
|
|
615
|
619
|
{
|
|
616
|
620
|
offsetCompressed = // NO TIME OFFSET
|
|
617
|
621
|
frequencyBin * NB_VALUES_PER_SM
|
|
618
|
622
|
+ asmComponent;
|
|
619
|
623
|
offsetASM = // NO TIME OFFSET
|
|
620
|
624
|
asmComponent * NB_BINS_PER_SM
|
|
621
|
625
|
+ ASMIndexStart
|
|
622
|
626
|
+ frequencyBin * nbBinsToAverage;
|
|
623
|
627
|
offsetFBin = ASMIndexStart
|
|
624
|
628
|
+ frequencyBin * nbBinsToAverage;
|
|
625
|
629
|
compressed_spec_mat[ offsetCompressed ] = 0;
|
|
626
|
630
|
for ( k = 0; k < nbBinsToAverage; k++ )
|
|
627
|
631
|
{
|
|
628
|
632
|
fBinMask = getFBinMask( offsetFBin + k );
|
|
629
|
633
|
compressed_spec_mat[offsetCompressed ] =
|
|
630
|
634
|
( compressed_spec_mat[ offsetCompressed ]
|
|
631
|
635
|
+ averaged_spec_mat[ offsetASM + k ] * fBinMask );
|
|
632
|
636
|
}
|
|
633
|
637
|
compressed_spec_mat[ offsetCompressed ] =
|
|
634
|
638
|
compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
|
|
635
|
639
|
}
|
|
636
|
640
|
}
|
|
637
|
641
|
|
|
638
|
642
|
}
|
|
639
|
643
|
|
|
640
|
644
|
int getFBinMask( int index )
|
|
641
|
645
|
{
|
|
642
|
646
|
unsigned int indexInChar;
|
|
643
|
647
|
unsigned int indexInTheChar;
|
|
644
|
648
|
int fbin;
|
|
645
|
649
|
|
|
646
|
650
|
indexInChar = index >> 3;
|
|
647
|
651
|
indexInTheChar = index - indexInChar * 8;
|
|
648
|
652
|
|
|
649
|
653
|
fbin = (int) ((parameter_dump_packet.sy_lfr_fbins_f0_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
|
|
650
|
654
|
|
|
651
|
655
|
return fbin;
|
|
652
|
656
|
}
|