##// END OF EJS Templates
union usage removed from the sources (897 Don_ArtVariables)...
paul -
r324:dc3755493cce R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 d4a9a4d748d56d86427bfe03a6777fae4cfe3ae1 header/lfr_common_headers
2 7c46de6059673d3239fcc7103e16510727f35923 header/lfr_common_headers
@@ -1,231 +1,233
1 #ifndef GRLIB_REGS_H_INCLUDED
1 #ifndef GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
3
3
4 #define NB_GPTIMER 3
4 #define NB_GPTIMER 3
5
5
6 struct apbuart_regs_str{
6 struct apbuart_regs_str{
7 volatile unsigned int data;
7 volatile unsigned int data;
8 volatile unsigned int status;
8 volatile unsigned int status;
9 volatile unsigned int ctrl;
9 volatile unsigned int ctrl;
10 volatile unsigned int scaler;
10 volatile unsigned int scaler;
11 volatile unsigned int fifoDebug;
11 volatile unsigned int fifoDebug;
12 };
12 };
13
13
14 struct grgpio_regs_str{
14 struct grgpio_regs_str{
15 volatile int io_port_data_register;
15 volatile int io_port_data_register;
16 int io_port_output_register;
16 int io_port_output_register;
17 int io_port_direction_register;
17 int io_port_direction_register;
18 int interrupt_mak_register;
18 int interrupt_mak_register;
19 int interrupt_polarity_register;
19 int interrupt_polarity_register;
20 int interrupt_edge_register;
20 int interrupt_edge_register;
21 int bypass_register;
21 int bypass_register;
22 int reserved;
22 int reserved;
23 // 0x20-0x3c interrupt map register(s)
23 // 0x20-0x3c interrupt map register(s)
24 };
24 };
25
25
26 typedef struct {
26 typedef struct {
27 volatile unsigned int counter;
27 volatile unsigned int counter;
28 volatile unsigned int reload;
28 volatile unsigned int reload;
29 volatile unsigned int ctrl;
29 volatile unsigned int ctrl;
30 volatile unsigned int unused;
30 volatile unsigned int unused;
31 } timer_regs_t;
31 } timer_regs_t;
32
32
33 //*************
33 //*************
34 //*************
34 //*************
35 // GPTIMER_REGS
35 // GPTIMER_REGS
36
36
37 #define GPTIMER_CLEAR_IRQ 0x00000010 // clear pending IRQ if any
37 #define GPTIMER_CLEAR_IRQ 0x00000010 // clear pending IRQ if any
38 #define GPTIMER_LD 0x00000004 // LD load value from the reload register
38 #define GPTIMER_LD 0x00000004 // LD load value from the reload register
39 #define GPTIMER_EN 0x00000001 // EN enable the timer
39 #define GPTIMER_EN 0x00000001 // EN enable the timer
40 #define GPTIMER_EN_MASK 0xfffffffe // EN enable the timer
40 #define GPTIMER_EN_MASK 0xfffffffe // EN enable the timer
41 #define GPTIMER_RS 0x00000002 // RS restart
41 #define GPTIMER_RS 0x00000002 // RS restart
42 #define GPTIMER_IE 0x00000008 // IE interrupt enable
42 #define GPTIMER_IE 0x00000008 // IE interrupt enable
43 #define GPTIMER_IE_MASK 0xffffffef // IE interrupt enable
43 #define GPTIMER_IE_MASK 0xffffffef // IE interrupt enable
44
44
45 typedef struct {
45 typedef struct {
46 volatile unsigned int scaler_value;
46 volatile unsigned int scaler_value;
47 volatile unsigned int scaler_reload;
47 volatile unsigned int scaler_reload;
48 volatile unsigned int conf;
48 volatile unsigned int conf;
49 volatile unsigned int unused0;
49 volatile unsigned int unused0;
50 timer_regs_t timer[NB_GPTIMER];
50 timer_regs_t timer[NB_GPTIMER];
51 } gptimer_regs_t;
51 } gptimer_regs_t;
52
52
53 //*********************
53 //*********************
54 //*********************
54 //*********************
55 // TIME_MANAGEMENT_REGS
55 // TIME_MANAGEMENT_REGS
56
56
57 #define VAL_SOFTWARE_RESET 0x02 // [0010] software reset
57 #define VAL_SOFTWARE_RESET 0x02 // [0010] software reset
58 #define VAL_LFR_SYNCHRONIZED 0x80000000
58 #define VAL_LFR_SYNCHRONIZED 0x80000000
59 #define BIT_SYNCHRONIZATION 31
59 #define BIT_SYNCHRONIZATION 31
60 #define COARSE_TIME_MASK 0x7fffffff
60 #define COARSE_TIME_MASK 0x7fffffff
61 #define SYNC_BIT_MASK 0x7f
61 #define SYNC_BIT_MASK 0x7f
62 #define SYNC_BIT 0x80
62 #define SYNC_BIT 0x80
63 #define BIT_CAL_RELOAD 0x00000010
63 #define BIT_CAL_RELOAD 0x00000010
64 #define MASK_CAL_RELOAD 0xffffffef // [1110 1111]
64 #define MASK_CAL_RELOAD 0xffffffef // [1110 1111]
65 #define BIT_CAL_ENABLE 0x00000040
65 #define BIT_CAL_ENABLE 0x00000040
66 #define MASK_CAL_ENABLE 0xffffffbf // [1011 1111]
66 #define MASK_CAL_ENABLE 0xffffffbf // [1011 1111]
67 #define BIT_SET_INTERLEAVED 0x00000020 // [0010 0000]
67 #define BIT_SET_INTERLEAVED 0x00000020 // [0010 0000]
68 #define MASK_SET_INTERLEAVED 0xffffffdf // [1101 1111]
68 #define MASK_SET_INTERLEAVED 0xffffffdf // [1101 1111]
69 #define BIT_SOFT_RESET 0x00000004 // [0100]
69 #define BIT_SOFT_RESET 0x00000004 // [0100]
70 #define MASK_SOFT_RESET 0xfffffffb // [1011]
70 #define MASK_SOFT_RESET 0xfffffffb // [1011]
71
71
72 typedef struct {
72 typedef struct {
73 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
73 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
74 // bit 1 is the soft reset for the time management module
74 // bit 1 is the soft reset for the time management module
75 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
75 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
76 volatile int coarse_time_load;
76 volatile int coarse_time_load;
77 volatile int coarse_time;
77 volatile int coarse_time;
78 volatile int fine_time;
78 volatile int fine_time;
79 // TEMPERATURES
79 // TEMPERATURES
80 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
80 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
81 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
81 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
82 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
82 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
83 // CALIBRATION
83 // CALIBRATION
84 volatile unsigned int calDACCtrl;
84 volatile unsigned int calDACCtrl;
85 volatile unsigned int calPrescaler;
85 volatile unsigned int calPrescaler;
86 volatile unsigned int calDivisor;
86 volatile unsigned int calDivisor;
87 volatile unsigned int calDataPtr;
87 volatile unsigned int calDataPtr;
88 volatile unsigned int calData;
88 volatile unsigned int calData;
89 } time_management_regs_t;
89 } time_management_regs_t;
90
90
91 //*********************
91 //*********************
92 //*********************
92 //*********************
93 // WAVEFORM_PICKER_REGS
93 // WAVEFORM_PICKER_REGS
94
94
95 #define BITS_WFP_STATUS_F3 0xc0 // [1100 0000] check the f3 full bits
95 #define BITS_WFP_STATUS_F3 0xc0 // [1100 0000] check the f3 full bits
96 #define BIT_WFP_BUF_F3_0 0x40 // [0100 0000] f3 buffer 0 is full
96 #define BIT_WFP_BUF_F3_0 0x40 // [0100 0000] f3 buffer 0 is full
97 #define BIT_WFP_BUF_F3_1 0x80 // [1000 0000] f3 buffer 1 is full
97 #define BIT_WFP_BUF_F3_1 0x80 // [1000 0000] f3 buffer 1 is full
98 #define RST_WFP_F3_0 0x00008840 // [1000 1000 0100 0000]
98 #define RST_WFP_F3_0 0x00008840 // [1000 1000 0100 0000]
99 #define RST_WFP_F3_1 0x00008880 // [1000 1000 1000 0000]
99 #define RST_WFP_F3_1 0x00008880 // [1000 1000 1000 0000]
100
100
101 #define BITS_WFP_STATUS_F2 0x30 // [0011 0000] get the status bits for f2
101 #define BITS_WFP_STATUS_F2 0x30 // [0011 0000] get the status bits for f2
102 #define SHIFT_WFP_STATUS_F2 4
102 #define SHIFT_WFP_STATUS_F2 4
103 #define BIT_WFP_BUF_F2_0 0x10 // [0001 0000] f2 buffer 0 is full
103 #define BIT_WFP_BUF_F2_0 0x10 // [0001 0000] f2 buffer 0 is full
104 #define BIT_WFP_BUF_F2_1 0x20 // [0010 0000] f2 buffer 1 is full
104 #define BIT_WFP_BUF_F2_1 0x20 // [0010 0000] f2 buffer 1 is full
105 #define RST_WFP_F2_0 0x00004410 // [0100 0100 0001 0000]
105 #define RST_WFP_F2_0 0x00004410 // [0100 0100 0001 0000]
106 #define RST_WFP_F2_1 0x00004420 // [0100 0100 0010 0000]
106 #define RST_WFP_F2_1 0x00004420 // [0100 0100 0010 0000]
107
107
108 #define BITS_WFP_STATUS_F1 0x0c // [0000 1100] check the f1 full bits
108 #define BITS_WFP_STATUS_F1 0x0c // [0000 1100] check the f1 full bits
109 #define BIT_WFP_BUF_F1_0 0x04 // [0000 0100] f1 buffer 0 is full
109 #define BIT_WFP_BUF_F1_0 0x04 // [0000 0100] f1 buffer 0 is full
110 #define BIT_WFP_BUF_F1_1 0x08 // [0000 1000] f1 buffer 1 is full
110 #define BIT_WFP_BUF_F1_1 0x08 // [0000 1000] f1 buffer 1 is full
111 #define RST_WFP_F1_0 0x00002204 // [0010 0010 0000 0100] f1 bits = 0
111 #define RST_WFP_F1_0 0x00002204 // [0010 0010 0000 0100] f1 bits = 0
112 #define RST_WFP_F1_1 0x00002208 // [0010 0010 0000 1000] f1 bits = 0
112 #define RST_WFP_F1_1 0x00002208 // [0010 0010 0000 1000] f1 bits = 0
113
113
114 #define BITS_WFP_STATUS_F0 0x03 // [0000 0011] check the f0 full bits
114 #define BITS_WFP_STATUS_F0 0x03 // [0000 0011] check the f0 full bits
115 #define RST_WFP_F0_0 0x00001101 // [0001 0001 0000 0001]
115 #define RST_WFP_F0_0 0x00001101 // [0001 0001 0000 0001]
116 #define RST_WFP_F0_1 0x00001102 // [0001 0001 0000 0010]
116 #define RST_WFP_F0_1 0x00001102 // [0001 0001 0000 0010]
117
117
118 #define BIT_WFP_BUFFER_0 0x01
118 #define BIT_WFP_BUFFER_0 0x01
119 #define BIT_WFP_BUFFER_1 0x02
119 #define BIT_WFP_BUFFER_1 0x02
120
120
121 #define RST_BITS_RUN_BURST_EN 0x80 // [1000 0000] burst f2, f1, f0 enable f3, f2, f1, f0
121 #define RST_BITS_RUN_BURST_EN 0x80 // [1000 0000] burst f2, f1, f0 enable f3, f2, f1, f0
122 #define BITS_WFP_ENABLE_ALL 0x0f // [0000 1111] enable f3, f2, f1, f0
123 #define BITS_WFP_ENABLE_BURST 0x0c // [0000 1100] enable f3, f2
122 #define RUN_BURST_ENABLE_SBM2 0x60 // [0110 0000] enable f2 and f1 burst
124 #define RUN_BURST_ENABLE_SBM2 0x60 // [0110 0000] enable f2 and f1 burst
123 #define RUN_BURST_ENABLE_BURST 0x40 // [0100 0000] f2 burst enabled
125 #define RUN_BURST_ENABLE_BURST 0x40 // [0100 0000] f2 burst enabled
124
126
125 #define DFLT_WFP_NB_DATA_BY_BUFFER 0xa7f // 0x30 *** 2688 - 1 => nb samples -1
127 #define DFLT_WFP_NB_DATA_BY_BUFFER 0xa7f // 0x30 *** 2688 - 1 => nb samples -1
126 #define DFLT_WFP_SNAPSHOT_PARAM 0xa80 // 0x34 *** 2688 => nb samples
128 #define DFLT_WFP_SNAPSHOT_PARAM 0xa80 // 0x34 *** 2688 => nb samples
127 #define DFLT_WFP_BUFFER_LENGTH 0x1f8 // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
129 #define DFLT_WFP_BUFFER_LENGTH 0x1f8 // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
128 #define DFLT_WFP_DELTA_F0_2 0x30 // 48 = 11 0000, max 7 bits
130 #define DFLT_WFP_DELTA_F0_2 0x30 // 48 = 11 0000, max 7 bits
129
131
130 // PDB >= 0.1.28, 0x80000f54
132 // PDB >= 0.1.28, 0x80000f54
131 typedef struct{
133 typedef struct{
132 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
134 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
133 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
135 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
134 int addr_data_f0_0; // 0x08
136 int addr_data_f0_0; // 0x08
135 int addr_data_f0_1; // 0x0c
137 int addr_data_f0_1; // 0x0c
136 int addr_data_f1_0; // 0x10
138 int addr_data_f1_0; // 0x10
137 int addr_data_f1_1; // 0x14
139 int addr_data_f1_1; // 0x14
138 int addr_data_f2_0; // 0x18
140 int addr_data_f2_0; // 0x18
139 int addr_data_f2_1; // 0x1c
141 int addr_data_f2_1; // 0x1c
140 int addr_data_f3_0; // 0x20
142 int addr_data_f3_0; // 0x20
141 int addr_data_f3_1; // 0x24
143 int addr_data_f3_1; // 0x24
142 volatile int status; // 0x28
144 volatile int status; // 0x28
143 volatile int delta_snapshot; // 0x2c
145 volatile int delta_snapshot; // 0x2c
144 int delta_f0; // 0x30
146 int delta_f0; // 0x30
145 int delta_f0_2; // 0x34
147 int delta_f0_2; // 0x34
146 int delta_f1; // 0x38
148 int delta_f1; // 0x38
147 int delta_f2; // 0x3c
149 int delta_f2; // 0x3c
148 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
150 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
149 int snapshot_param; // 0x44
151 int snapshot_param; // 0x44
150 int start_date; // 0x48
152 int start_date; // 0x48
151 //
153 //
152 volatile unsigned int f0_0_coarse_time; // 0x4c
154 volatile unsigned int f0_0_coarse_time; // 0x4c
153 volatile unsigned int f0_0_fine_time; // 0x50
155 volatile unsigned int f0_0_fine_time; // 0x50
154 volatile unsigned int f0_1_coarse_time; // 0x54
156 volatile unsigned int f0_1_coarse_time; // 0x54
155 volatile unsigned int f0_1_fine_time; // 0x58
157 volatile unsigned int f0_1_fine_time; // 0x58
156 //
158 //
157 volatile unsigned int f1_0_coarse_time; // 0x5c
159 volatile unsigned int f1_0_coarse_time; // 0x5c
158 volatile unsigned int f1_0_fine_time; // 0x60
160 volatile unsigned int f1_0_fine_time; // 0x60
159 volatile unsigned int f1_1_coarse_time; // 0x64
161 volatile unsigned int f1_1_coarse_time; // 0x64
160 volatile unsigned int f1_1_fine_time; // 0x68
162 volatile unsigned int f1_1_fine_time; // 0x68
161 //
163 //
162 volatile unsigned int f2_0_coarse_time; // 0x6c
164 volatile unsigned int f2_0_coarse_time; // 0x6c
163 volatile unsigned int f2_0_fine_time; // 0x70
165 volatile unsigned int f2_0_fine_time; // 0x70
164 volatile unsigned int f2_1_coarse_time; // 0x74
166 volatile unsigned int f2_1_coarse_time; // 0x74
165 volatile unsigned int f2_1_fine_time; // 0x78
167 volatile unsigned int f2_1_fine_time; // 0x78
166 //
168 //
167 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
169 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
168 volatile unsigned int f3_0_fine_time; // 0x80
170 volatile unsigned int f3_0_fine_time; // 0x80
169 volatile unsigned int f3_1_coarse_time; // 0x84
171 volatile unsigned int f3_1_coarse_time; // 0x84
170 volatile unsigned int f3_1_fine_time; // 0x88
172 volatile unsigned int f3_1_fine_time; // 0x88
171 //
173 //
172 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
174 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
173 //
175 //
174 volatile unsigned int v; // 0x90
176 volatile unsigned int v; // 0x90
175 volatile unsigned int e1; // 0x94
177 volatile unsigned int e1; // 0x94
176 volatile unsigned int e2; // 0x98
178 volatile unsigned int e2; // 0x98
177 } waveform_picker_regs_0_1_18_t;
179 } waveform_picker_regs_0_1_18_t;
178
180
179 //*********************
181 //*********************
180 //*********************
182 //*********************
181 // SPECTRAL_MATRIX_REGS
183 // SPECTRAL_MATRIX_REGS
182
184
183 #define BITS_STATUS_F0 0x03 // [0011]
185 #define BITS_STATUS_F0 0x03 // [0011]
184 #define BITS_STATUS_F1 0x0c // [1100]
186 #define BITS_STATUS_F1 0x0c // [1100]
185 #define BITS_STATUS_F2 0x30 // [0011 0000]
187 #define BITS_STATUS_F2 0x30 // [0011 0000]
186 #define BITS_HK_AA_SM 0x780 // [0111 1000 0000]
188 #define BITS_HK_AA_SM 0x780 // [0111 1000 0000]
187 #define BITS_SM_ERR 0x7c0 // [0111 1100 0000]
189 #define BITS_SM_ERR 0x7c0 // [0111 1100 0000]
188 #define BITS_STATUS_REG 0x7ff // [0111 1111 1111]
190 #define BITS_STATUS_REG 0x7ff // [0111 1111 1111]
189 #define BIT_READY_0 0x1 // [01]
191 #define BIT_READY_0 0x1 // [01]
190 #define BIT_READY_1 0x2 // [10]
192 #define BIT_READY_1 0x2 // [10]
191 #define BIT_READY_0_1 0x3 // [11]
193 #define BIT_READY_0_1 0x3 // [11]
192 #define BIT_STATUS_F1_0 0x04 // [0100]
194 #define BIT_STATUS_F1_0 0x04 // [0100]
193 #define BIT_STATUS_F1_1 0x08 // [1000]
195 #define BIT_STATUS_F1_1 0x08 // [1000]
194 #define BIT_STATUS_F2_0 0x10 // [0001 0000]
196 #define BIT_STATUS_F2_0 0x10 // [0001 0000]
195 #define BIT_STATUS_F2_1 0x20 // [0010 0000]
197 #define BIT_STATUS_F2_1 0x20 // [0010 0000]
196 #define DEFAULT_MATRIX_LENGTH 0xc8 // 25 * 128 / 16 = 200 = 0xc8
198 #define DEFAULT_MATRIX_LENGTH 0xc8 // 25 * 128 / 16 = 200 = 0xc8
197 #define BIT_IRQ_ON_NEW_MATRIX 0x01
199 #define BIT_IRQ_ON_NEW_MATRIX 0x01
198 #define MASK_IRQ_ON_NEW_MATRIX 0xfffffffe
200 #define MASK_IRQ_ON_NEW_MATRIX 0xfffffffe
199 #define BIT_IRQ_ON_ERROR 0x02
201 #define BIT_IRQ_ON_ERROR 0x02
200 #define MASK_IRQ_ON_ERROR 0xfffffffd
202 #define MASK_IRQ_ON_ERROR 0xfffffffd
201
203
202 typedef struct {
204 typedef struct {
203 volatile int config; // 0x00
205 volatile int config; // 0x00
204 volatile int status; // 0x04
206 volatile int status; // 0x04
205 volatile int f0_0_address; // 0x08
207 volatile int f0_0_address; // 0x08
206 volatile int f0_1_address; // 0x0C
208 volatile int f0_1_address; // 0x0C
207 //
209 //
208 volatile int f1_0_address; // 0x10
210 volatile int f1_0_address; // 0x10
209 volatile int f1_1_address; // 0x14
211 volatile int f1_1_address; // 0x14
210 volatile int f2_0_address; // 0x18
212 volatile int f2_0_address; // 0x18
211 volatile int f2_1_address; // 0x1C
213 volatile int f2_1_address; // 0x1C
212 //
214 //
213 volatile unsigned int f0_0_coarse_time; // 0x20
215 volatile unsigned int f0_0_coarse_time; // 0x20
214 volatile unsigned int f0_0_fine_time; // 0x24
216 volatile unsigned int f0_0_fine_time; // 0x24
215 volatile unsigned int f0_1_coarse_time; // 0x28
217 volatile unsigned int f0_1_coarse_time; // 0x28
216 volatile unsigned int f0_1_fine_time; // 0x2C
218 volatile unsigned int f0_1_fine_time; // 0x2C
217 //
219 //
218 volatile unsigned int f1_0_coarse_time; // 0x30
220 volatile unsigned int f1_0_coarse_time; // 0x30
219 volatile unsigned int f1_0_fine_time; // 0x34
221 volatile unsigned int f1_0_fine_time; // 0x34
220 volatile unsigned int f1_1_coarse_time; // 0x38
222 volatile unsigned int f1_1_coarse_time; // 0x38
221 volatile unsigned int f1_1_fine_time; // 0x3C
223 volatile unsigned int f1_1_fine_time; // 0x3C
222 //
224 //
223 volatile unsigned int f2_0_coarse_time; // 0x40
225 volatile unsigned int f2_0_coarse_time; // 0x40
224 volatile unsigned int f2_0_fine_time; // 0x44
226 volatile unsigned int f2_0_fine_time; // 0x44
225 volatile unsigned int f2_1_coarse_time; // 0x48
227 volatile unsigned int f2_1_coarse_time; // 0x48
226 volatile unsigned int f2_1_fine_time; // 0x4C
228 volatile unsigned int f2_1_fine_time; // 0x4C
227 //
229 //
228 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
230 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
229 } spectral_matrix_regs_t;
231 } spectral_matrix_regs_t;
230
232
231 #endif // GRLIB_REGS_H_INCLUDED
233 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,371 +1,380
1 #ifndef FSW_PROCESSING_H_INCLUDED
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <math.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h>
8 #include <stdio.h>
9 #include <math.h>
9 #include <math.h>
10 #include <grlib_regs.h>
10 #include <grlib_regs.h>
11
11
12 #include "fsw_params.h"
12 #include "fsw_params.h"
13
13
14 #define SBM_COEFF_PER_NORM_COEFF 2
14 #define SBM_COEFF_PER_NORM_COEFF 2
15 #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
15 #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
16 #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes
16 #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes
17
17
18 #define NODE_0 0
19 #define NODE_1 1
20 #define NODE_2 2
21 #define NODE_3 3
22 #define NODE_4 4
23 #define NODE_5 5
24 #define NODE_6 6
25 #define NODE_7 7
26
18 typedef struct ring_node_asm
27 typedef struct ring_node_asm
19 {
28 {
20 struct ring_node_asm *next;
29 struct ring_node_asm *next;
21 float matrix[ TOTAL_SIZE_SM ];
30 float matrix[ TOTAL_SIZE_SM ];
22 unsigned int status;
31 unsigned int status;
23 } ring_node_asm;
32 } ring_node_asm;
24
33
25 typedef struct
34 typedef struct
26 {
35 {
27 unsigned char targetLogicalAddress;
36 unsigned char targetLogicalAddress;
28 unsigned char protocolIdentifier;
37 unsigned char protocolIdentifier;
29 unsigned char reserved;
38 unsigned char reserved;
30 unsigned char userApplication;
39 unsigned char userApplication;
31 unsigned char packetID[BYTES_PER_PACKETID];
40 unsigned char packetID[BYTES_PER_PACKETID];
32 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
41 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
33 unsigned char packetLength[BYTES_PER_PKT_LEN];
42 unsigned char packetLength[BYTES_PER_PKT_LEN];
34 // DATA FIELD HEADER
43 // DATA FIELD HEADER
35 unsigned char spare1_pusVersion_spare2;
44 unsigned char spare1_pusVersion_spare2;
36 unsigned char serviceType;
45 unsigned char serviceType;
37 unsigned char serviceSubType;
46 unsigned char serviceSubType;
38 unsigned char destinationID;
47 unsigned char destinationID;
39 unsigned char time[BYTES_PER_TIME];
48 unsigned char time[BYTES_PER_TIME];
40 // AUXILIARY HEADER
49 // AUXILIARY HEADER
41 unsigned char sid;
50 unsigned char sid;
42 unsigned char pa_bia_status_info;
51 unsigned char pa_bia_status_info;
43 unsigned char sy_lfr_common_parameters_spare;
52 unsigned char sy_lfr_common_parameters_spare;
44 unsigned char sy_lfr_common_parameters;
53 unsigned char sy_lfr_common_parameters;
45 unsigned char acquisitionTime[BYTES_PER_TIME];
54 unsigned char acquisitionTime[BYTES_PER_TIME];
46 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
55 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
47 // SOURCE DATA
56 // SOURCE DATA
48 unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
57 unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
49 } bp_packet;
58 } bp_packet;
50
59
51 typedef struct
60 typedef struct
52 {
61 {
53 unsigned char targetLogicalAddress;
62 unsigned char targetLogicalAddress;
54 unsigned char protocolIdentifier;
63 unsigned char protocolIdentifier;
55 unsigned char reserved;
64 unsigned char reserved;
56 unsigned char userApplication;
65 unsigned char userApplication;
57 unsigned char packetID[BYTES_PER_PACKETID];
66 unsigned char packetID[BYTES_PER_PACKETID];
58 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
67 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
59 unsigned char packetLength[BYTES_PER_PKT_LEN];
68 unsigned char packetLength[BYTES_PER_PKT_LEN];
60 // DATA FIELD HEADER
69 // DATA FIELD HEADER
61 unsigned char spare1_pusVersion_spare2;
70 unsigned char spare1_pusVersion_spare2;
62 unsigned char serviceType;
71 unsigned char serviceType;
63 unsigned char serviceSubType;
72 unsigned char serviceSubType;
64 unsigned char destinationID;
73 unsigned char destinationID;
65 unsigned char time[BYTES_PER_TIME];
74 unsigned char time[BYTES_PER_TIME];
66 // AUXILIARY HEADER
75 // AUXILIARY HEADER
67 unsigned char sid;
76 unsigned char sid;
68 unsigned char pa_bia_status_info;
77 unsigned char pa_bia_status_info;
69 unsigned char sy_lfr_common_parameters_spare;
78 unsigned char sy_lfr_common_parameters_spare;
70 unsigned char sy_lfr_common_parameters;
79 unsigned char sy_lfr_common_parameters;
71 unsigned char acquisitionTime[BYTES_PER_TIME];
80 unsigned char acquisitionTime[BYTES_PER_TIME];
72 unsigned char source_data_spare;
81 unsigned char source_data_spare;
73 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
82 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
74 // SOURCE DATA
83 // SOURCE DATA
75 unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes
84 unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes
76 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
85 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
77
86
78 typedef struct asm_msg
87 typedef struct asm_msg
79 {
88 {
80 ring_node_asm *norm;
89 ring_node_asm *norm;
81 ring_node_asm *burst_sbm;
90 ring_node_asm *burst_sbm;
82 rtems_event_set event;
91 rtems_event_set event;
83 unsigned int coarseTimeNORM;
92 unsigned int coarseTimeNORM;
84 unsigned int fineTimeNORM;
93 unsigned int fineTimeNORM;
85 unsigned int coarseTimeSBM;
94 unsigned int coarseTimeSBM;
86 unsigned int fineTimeSBM;
95 unsigned int fineTimeSBM;
87 unsigned int numberOfSMInASMNORM;
96 unsigned int numberOfSMInASMNORM;
88 unsigned int numberOfSMInASMSBM;
97 unsigned int numberOfSMInASMSBM;
89 } asm_msg;
98 } asm_msg;
90
99
91 extern unsigned char thisIsAnASMRestart;
100 extern unsigned char thisIsAnASMRestart;
92
101
93 extern volatile int sm_f0[ ];
102 extern volatile int sm_f0[ ];
94 extern volatile int sm_f1[ ];
103 extern volatile int sm_f1[ ];
95 extern volatile int sm_f2[ ];
104 extern volatile int sm_f2[ ];
96 extern unsigned int acquisitionDurations[];
105 extern unsigned int acquisitionDurations[];
97
106
98 // parameters
107 // parameters
99 extern struct param_local_str param_local;
108 extern struct param_local_str param_local;
100 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
109 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
101
110
102 // registers
111 // registers
103 extern time_management_regs_t *time_management_regs;
112 extern time_management_regs_t *time_management_regs;
104 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
113 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
105
114
106 extern rtems_name misc_name[];
115 extern rtems_name misc_name[];
107 extern rtems_id Task_id[]; /* array of task ids */
116 extern rtems_id Task_id[]; /* array of task ids */
108
117
109 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
118 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
110 // ISR
119 // ISR
111 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
120 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
112
121
113 //******************
122 //******************
114 // Spectral Matrices
123 // Spectral Matrices
115 void reset_nb_sm( void );
124 void reset_nb_sm( void );
116 // SM
125 // SM
117 void SM_init_rings( void );
126 void SM_init_rings( void );
118 void SM_reset_current_ring_nodes( void );
127 void SM_reset_current_ring_nodes( void );
119 // ASM
128 // ASM
120 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
129 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
121
130
122 //*****************
131 //*****************
123 // Basic Parameters
132 // Basic Parameters
124
133
125 void BP_reset_current_ring_nodes( void );
134 void BP_reset_current_ring_nodes( void );
126 void BP_init_header(bp_packet *packet,
135 void BP_init_header(bp_packet *packet,
127 unsigned int apid, unsigned char sid,
136 unsigned int apid, unsigned char sid,
128 unsigned int packetLength , unsigned char blkNr);
137 unsigned int packetLength , unsigned char blkNr);
129 void BP_init_header_with_spare(bp_packet_with_spare *packet,
138 void BP_init_header_with_spare(bp_packet_with_spare *packet,
130 unsigned int apid, unsigned char sid,
139 unsigned int apid, unsigned char sid,
131 unsigned int packetLength, unsigned char blkNr );
140 unsigned int packetLength, unsigned char blkNr );
132 void BP_send( char *data,
141 void BP_send( char *data,
133 rtems_id queue_id,
142 rtems_id queue_id,
134 unsigned int nbBytesToSend , unsigned int sid );
143 unsigned int nbBytesToSend , unsigned int sid );
135 void BP_send_s1_s2(char *data,
144 void BP_send_s1_s2(char *data,
136 rtems_id queue_id,
145 rtems_id queue_id,
137 unsigned int nbBytesToSend, unsigned int sid );
146 unsigned int nbBytesToSend, unsigned int sid );
138
147
139 //******************
148 //******************
140 // general functions
149 // general functions
141 void reset_sm_status( void );
150 void reset_sm_status( void );
142 void reset_spectral_matrix_regs( void );
151 void reset_spectral_matrix_regs( void );
143 void set_time(unsigned char *time, unsigned char *timeInBuffer );
152 void set_time(unsigned char *time, unsigned char *timeInBuffer );
144 unsigned long long int get_acquisition_time( unsigned char *timePtr );
153 unsigned long long int get_acquisition_time( unsigned char *timePtr );
145 unsigned char getSID( rtems_event_set event );
154 unsigned char getSID( rtems_event_set event );
146
155
147 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
156 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
148 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
157 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
149
158
150 //***************************************
159 //***************************************
151 // DEFINITIONS OF STATIC INLINE FUNCTIONS
160 // DEFINITIONS OF STATIC INLINE FUNCTIONS
152 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
161 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
153 ring_node *ring_node_tab[],
162 ring_node *ring_node_tab[],
154 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
163 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
155 asm_msg *msgForMATR , unsigned char channel);
164 asm_msg *msgForMATR , unsigned char channel);
156
165
157 void ASM_patch( float *inputASM, float *outputASM );
166 void ASM_patch( float *inputASM, float *outputASM );
158
167
159 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
168 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
160
169
161 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
170 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
162 float divider );
171 float divider );
163
172
164 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
173 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
165 float divider,
174 float divider,
166 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
175 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
167
176
168 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
177 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
169
178
170 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
179 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
171
180
172 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
181 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
173 ring_node *ring_node_tab[],
182 ring_node *ring_node_tab[],
174 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
183 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
175 asm_msg *msgForMATR, unsigned char channel )
184 asm_msg *msgForMATR, unsigned char channel )
176 {
185 {
177 float sum;
186 float sum;
178 unsigned int i;
187 unsigned int i;
179 unsigned int k;
188 unsigned int k;
180 unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1];
189 unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1];
181 unsigned int numberOfValidSM;
190 unsigned int numberOfValidSM;
182 unsigned char isValid;
191 unsigned char isValid;
183
192
184 //**************
193 //**************
185 // PAS FILTERING
194 // PAS FILTERING
186 // check acquisitionTime of the incoming data
195 // check acquisitionTime of the incoming data
187 numberOfValidSM = 0;
196 numberOfValidSM = 0;
188 for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++)
197 for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++)
189 {
198 {
190 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
199 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
191 incomingSMIsValid[k] = isValid;
200 incomingSMIsValid[k] = isValid;
192 numberOfValidSM = numberOfValidSM + isValid;
201 numberOfValidSM = numberOfValidSM + isValid;
193 }
202 }
194
203
195 //************************
204 //************************
196 // AVERAGE SPECTRAL MATRIX
205 // AVERAGE SPECTRAL MATRIX
197 for(i=0; i<TOTAL_SIZE_SM; i++)
206 for(i=0; i<TOTAL_SIZE_SM; i++)
198 {
207 {
199 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
208 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
200 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
209 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
201 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
210 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
202 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
211 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
203 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
212 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
204 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
213 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
205 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
214 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
206 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
215 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
207
216
208 sum = ( incomingSMIsValid[0] * ((int *)(ring_node_tab[0]->buffer_address) )[ i ] )
217 sum = ( incomingSMIsValid[BYTE_0] * ((int *)(ring_node_tab[NODE_0]->buffer_address) )[ i ] )
209 + ( incomingSMIsValid[1] * ((int *)(ring_node_tab[1]->buffer_address) )[ i ] )
218 + ( incomingSMIsValid[BYTE_1] * ((int *)(ring_node_tab[NODE_1]->buffer_address) )[ i ] )
210 + ( incomingSMIsValid[2] * ((int *)(ring_node_tab[2]->buffer_address) )[ i ] )
219 + ( incomingSMIsValid[BYTE_2] * ((int *)(ring_node_tab[NODE_2]->buffer_address) )[ i ] )
211 + ( incomingSMIsValid[3] * ((int *)(ring_node_tab[3]->buffer_address) )[ i ] )
220 + ( incomingSMIsValid[BYTE_3] * ((int *)(ring_node_tab[NODE_3]->buffer_address) )[ i ] )
212 + ( incomingSMIsValid[4] * ((int *)(ring_node_tab[4]->buffer_address) )[ i ] )
221 + ( incomingSMIsValid[BYTE_4] * ((int *)(ring_node_tab[NODE_4]->buffer_address) )[ i ] )
213 + ( incomingSMIsValid[5] * ((int *)(ring_node_tab[5]->buffer_address) )[ i ] )
222 + ( incomingSMIsValid[BYTE_5] * ((int *)(ring_node_tab[NODE_5]->buffer_address) )[ i ] )
214 + ( incomingSMIsValid[6] * ((int *)(ring_node_tab[6]->buffer_address) )[ i ] )
223 + ( incomingSMIsValid[BYTE_6] * ((int *)(ring_node_tab[NODE_6]->buffer_address) )[ i ] )
215 + ( incomingSMIsValid[7] * ((int *)(ring_node_tab[7]->buffer_address) )[ i ] );
224 + ( incomingSMIsValid[BYTE_7] * ((int *)(ring_node_tab[NODE_7]->buffer_address) )[ i ] );
216
225
217 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
226 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
218 {
227 {
219 averaged_spec_mat_NORM[ i ] = sum;
228 averaged_spec_mat_NORM[ i ] = sum;
220 averaged_spec_mat_SBM[ i ] = sum;
229 averaged_spec_mat_SBM[ i ] = sum;
221 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
230 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
222 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
231 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
223 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
232 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
224 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
233 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
225 }
234 }
226 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
235 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
227 {
236 {
228 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
237 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
229 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
238 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
230 }
239 }
231 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
240 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
232 {
241 {
233 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
242 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
234 averaged_spec_mat_SBM[ i ] = sum;
243 averaged_spec_mat_SBM[ i ] = sum;
235 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
244 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
236 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
245 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
237 }
246 }
238 else
247 else
239 {
248 {
240 averaged_spec_mat_NORM[ i ] = sum;
249 averaged_spec_mat_NORM[ i ] = sum;
241 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
250 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
242 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
251 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
243 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
252 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
244 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
253 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
245 }
254 }
246 }
255 }
247
256
248 //*******************
257 //*******************
249 // UPDATE SM COUNTERS
258 // UPDATE SM COUNTERS
250 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
259 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
251 {
260 {
252 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
261 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
253 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
262 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
254 }
263 }
255 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
264 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
256 {
265 {
257 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
266 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
258 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
267 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
259 }
268 }
260 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
269 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
261 {
270 {
262 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
271 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
263 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
272 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
264 }
273 }
265 else
274 else
266 {
275 {
267 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
276 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
268 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
277 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
269 }
278 }
270 }
279 }
271
280
272 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
281 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
273 {
282 {
274 int frequencyBin;
283 int frequencyBin;
275 int asmComponent;
284 int asmComponent;
276 unsigned int offsetASM;
285 unsigned int offsetASM;
277 unsigned int offsetASMReorganized;
286 unsigned int offsetASMReorganized;
278
287
279 // BUILD DATA
288 // BUILD DATA
280 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
289 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
281 {
290 {
282 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
291 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
283 {
292 {
284 offsetASMReorganized =
293 offsetASMReorganized =
285 (frequencyBin * NB_VALUES_PER_SM)
294 (frequencyBin * NB_VALUES_PER_SM)
286 + asmComponent;
295 + asmComponent;
287 offsetASM =
296 offsetASM =
288 (asmComponent * NB_BINS_PER_SM)
297 (asmComponent * NB_BINS_PER_SM)
289 + frequencyBin;
298 + frequencyBin;
290 if ( divider != INIT_FLOAT )
299 if ( divider != INIT_FLOAT )
291 {
300 {
292 averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider;
301 averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider;
293 }
302 }
294 else
303 else
295 {
304 {
296 averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT;
305 averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT;
297 }
306 }
298 }
307 }
299 }
308 }
300 }
309 }
301
310
302 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
311 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
303 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
312 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
304 {
313 {
305 int frequencyBin;
314 int frequencyBin;
306 int asmComponent;
315 int asmComponent;
307 int offsetASM;
316 int offsetASM;
308 int offsetCompressed;
317 int offsetCompressed;
309 int k;
318 int k;
310
319
311 // BUILD DATA
320 // BUILD DATA
312 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
321 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
313 {
322 {
314 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
323 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
315 {
324 {
316 offsetCompressed = // NO TIME OFFSET
325 offsetCompressed = // NO TIME OFFSET
317 (frequencyBin * NB_VALUES_PER_SM)
326 (frequencyBin * NB_VALUES_PER_SM)
318 + asmComponent;
327 + asmComponent;
319 offsetASM = // NO TIME OFFSET
328 offsetASM = // NO TIME OFFSET
320 (asmComponent * NB_BINS_PER_SM)
329 (asmComponent * NB_BINS_PER_SM)
321 + ASMIndexStart
330 + ASMIndexStart
322 + (frequencyBin * nbBinsToAverage);
331 + (frequencyBin * nbBinsToAverage);
323 compressed_spec_mat[ offsetCompressed ] = 0;
332 compressed_spec_mat[ offsetCompressed ] = 0;
324 for ( k = 0; k < nbBinsToAverage; k++ )
333 for ( k = 0; k < nbBinsToAverage; k++ )
325 {
334 {
326 compressed_spec_mat[offsetCompressed ] =
335 compressed_spec_mat[offsetCompressed ] =
327 ( compressed_spec_mat[ offsetCompressed ]
336 ( compressed_spec_mat[ offsetCompressed ]
328 + averaged_spec_mat[ offsetASM + k ] );
337 + averaged_spec_mat[ offsetASM + k ] );
329 }
338 }
330 compressed_spec_mat[ offsetCompressed ] =
339 compressed_spec_mat[ offsetCompressed ] =
331 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
340 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
332 }
341 }
333 }
342 }
334 }
343 }
335
344
336 void ASM_convert( volatile float *input_matrix, char *output_matrix)
345 void ASM_convert( volatile float *input_matrix, char *output_matrix)
337 {
346 {
338 unsigned int frequencyBin;
347 unsigned int frequencyBin;
339 unsigned int asmComponent;
348 unsigned int asmComponent;
340 char * pt_char_input;
349 char * pt_char_input;
341 char * pt_char_output;
350 char * pt_char_output;
342 unsigned int offsetInput;
351 unsigned int offsetInput;
343 unsigned int offsetOutput;
352 unsigned int offsetOutput;
344
353
345 pt_char_input = (char*) &input_matrix;
354 pt_char_input = (char*) &input_matrix;
346 pt_char_output = (char*) &output_matrix;
355 pt_char_output = (char*) &output_matrix;
347
356
348 // convert all other data
357 // convert all other data
349 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
358 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
350 {
359 {
351 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
360 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
352 {
361 {
353 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
362 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
354 offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
363 offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
355 pt_char_input = (char*) &input_matrix [ offsetInput ];
364 pt_char_input = (char*) &input_matrix [ offsetInput ];
356 pt_char_output = (char*) &output_matrix[ offsetOutput ];
365 pt_char_output = (char*) &output_matrix[ offsetOutput ];
357 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
366 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
358 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
367 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
359 }
368 }
360 }
369 }
361 }
370 }
362
371
363 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
372 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
364 float divider,
373 float divider,
365 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
374 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
366
375
367 int getFBinMask(int k, unsigned char channel);
376 int getFBinMask(int k, unsigned char channel);
368
377
369 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
378 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
370
379
371 #endif // FSW_PROCESSING_H_INCLUDED
380 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,106 +1,106
1 /** Global variables of the LFR flight software.
1 /** Global variables of the LFR flight software.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * Among global variables, there are:
6 * Among global variables, there are:
7 * - RTEMS names and id.
7 * - RTEMS names and id.
8 * - APB configuration registers.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
13 * - the global dump parameter buffer.
14 *
14 *
15 */
15 */
16
16
17 #include <rtems.h>
17 #include <rtems.h>
18 #include <grspw.h>
18 #include <grspw.h>
19
19
20 #include "ccsds_types.h"
20 #include "ccsds_types.h"
21 #include "grlib_regs.h"
21 #include "grlib_regs.h"
22 #include "fsw_params.h"
22 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
23 #include "fsw_params_wf_handler.h"
24
24
25 #define NB_OF_TASKS 20
25 #define NB_OF_TASKS 20
26 #define NB_OF_MISC_NAMES 5
26 #define NB_OF_MISC_NAMES 5
27
27
28 // RTEMS GLOBAL VARIABLES
28 // RTEMS GLOBAL VARIABLES
29 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
29 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
30 rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */
30 rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */
31 rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */
31 rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */
32 rtems_name timecode_timer_name = 0;
32 rtems_name timecode_timer_name = 0;
33 rtems_id timecode_timer_id = RTEMS_ID_NONE;
33 rtems_id timecode_timer_id = RTEMS_ID_NONE;
34 rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic
34 rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic
35 rtems_id HK_id = RTEMS_ID_NONE;// id of the HK rate monotonic period
35 rtems_id HK_id = RTEMS_ID_NONE;// id of the HK rate monotonic period
36 rtems_name name_avgv_rate_monotonic = 0; // name of the AVGV rate monotonic
36 rtems_name name_avgv_rate_monotonic = 0; // name of the AVGV rate monotonic
37 rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period
37 rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period
38 int fdSPW = 0;
38 int fdSPW = 0;
39 int fdUART = 0;
39 int fdUART = 0;
40 unsigned char lfrCurrentMode = 0;
40 unsigned char lfrCurrentMode = 0;
41 unsigned char pa_bia_status_info = 0;
41 unsigned char pa_bia_status_info = 0;
42 unsigned char thisIsAnASMRestart = 0;
42 unsigned char thisIsAnASMRestart = 0;
43 unsigned char oneTcLfrUpdateTimeReceived = 0;
43 unsigned char oneTcLfrUpdateTimeReceived = 0;
44
44
45 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
45 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
46 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
46 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
47 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
47 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
48 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
48 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
49 // F0 F1 F2 F3
49 // F0 F1 F2 F3
50 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
50 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
51 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
51 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
52 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
52 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
53 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
53 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
54
54
55 //***********************************
55 //***********************************
56 // SPECTRAL MATRICES GLOBAL VARIABLES
56 // SPECTRAL MATRICES GLOBAL VARIABLES
57
57
58 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
58 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
59 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
59 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
60 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
60 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
61 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
61 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
62
62
63 // APB CONFIGURATION REGISTERS
63 // APB CONFIGURATION REGISTERS
64 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
64 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
65 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
65 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
66 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
66 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
67 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
67 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
68
68
69 // MODE PARAMETERS
69 // MODE PARAMETERS
70 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
70 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
71 struct param_local_str param_local = {0};
71 struct param_local_str param_local = {0};
72 unsigned int lastValidEnterModeTime = {0};
72 unsigned int lastValidEnterModeTime = {0};
73
73
74 // HK PACKETS
74 // HK PACKETS
75 Packet_TM_LFR_HK_t housekeeping_packet = {0};
75 Packet_TM_LFR_HK_t housekeeping_packet = {0};
76 unsigned char cp_rpw_sc_rw_f_flags = 0;
76 unsigned char cp_rpw_sc_rw_f_flags = 0;
77 // message queues occupancy
77 // message queues occupancy
78 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
78 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
79 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
79 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
82 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
82 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
83 // sequence counters are incremented by APID (PID + CAT) and destination ID
83 // sequence counters are incremented by APID (PID + CAT) and destination ID
84 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST = 0;
84 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST = 0;
85 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 = 0;
85 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 = 0;
86 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] = {0};
86 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] = {0};
87 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] = {0};
87 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] = {0};
88 unsigned short sequenceCounterHK;
88 unsigned short sequenceCounterHK = {0};
89 spw_stats grspw_stats = {0};
89 spw_stats grspw_stats = {0};
90
90
91 // TC_LFR_UPDATE_INFO
91 // TC_LFR_UPDATE_INFO
92 float cp_rpw_sc_rw1_f1 = INIT_FLOAT;
92 float cp_rpw_sc_rw1_f1 = INIT_FLOAT;
93 float cp_rpw_sc_rw1_f2 = INIT_FLOAT;
93 float cp_rpw_sc_rw1_f2 = INIT_FLOAT;
94 float cp_rpw_sc_rw2_f1 = INIT_FLOAT;
94 float cp_rpw_sc_rw2_f1 = INIT_FLOAT;
95 float cp_rpw_sc_rw2_f2 = INIT_FLOAT;
95 float cp_rpw_sc_rw2_f2 = INIT_FLOAT;
96 float cp_rpw_sc_rw3_f1 = INIT_FLOAT;
96 float cp_rpw_sc_rw3_f1 = INIT_FLOAT;
97 float cp_rpw_sc_rw3_f2 = INIT_FLOAT;
97 float cp_rpw_sc_rw3_f2 = INIT_FLOAT;
98 float cp_rpw_sc_rw4_f1 = INIT_FLOAT;
98 float cp_rpw_sc_rw4_f1 = INIT_FLOAT;
99 float cp_rpw_sc_rw4_f2 = INIT_FLOAT;
99 float cp_rpw_sc_rw4_f2 = INIT_FLOAT;
100
100
101 // TC_LFR_LOAD_FILTER_PAR
101 // TC_LFR_LOAD_FILTER_PAR
102 filterPar_t filterPar = {0};
102 filterPar_t filterPar = {0};
103
103
104 fbins_masks_t fbins_masks = {0};
104 fbins_masks_t fbins_masks = {0};
105 unsigned int acquisitionDurations[NB_ACQUISITION_DURATION]
105 unsigned int acquisitionDurations[NB_ACQUISITION_DURATION]
106 = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
106 = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
@@ -1,995 +1,988
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 old_isr_handler = NULL;
28 old_isr_handler = NULL;
29
29
30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
31
31
32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
33 if (status!=RTEMS_SUCCESSFUL)
33 if (status!=RTEMS_SUCCESSFUL)
34 {
34 {
35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
36 }
36 }
37
37
38 timer_set_clock_divider( timer, clock_divider);
38 timer_set_clock_divider( timer, clock_divider);
39 }
39 }
40
40
41 void timer_start(unsigned char timer)
41 void timer_start(unsigned char timer)
42 {
42 {
43 /** This function starts a GPTIMER timer.
43 /** This function starts a GPTIMER timer.
44 *
44 *
45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
47 *
47 *
48 */
48 */
49
49
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
55 }
55 }
56
56
57 void timer_stop(unsigned char timer)
57 void timer_stop(unsigned char timer)
58 {
58 {
59 /** This function stops a GPTIMER timer.
59 /** This function stops a GPTIMER timer.
60 *
60 *
61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
63 *
63 *
64 */
64 */
65
65
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
69 }
69 }
70
70
71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
72 {
72 {
73 /** This function sets the clock divider of a GPTIMER timer.
73 /** This function sets the clock divider of a GPTIMER timer.
74 *
74 *
75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
78 *
78 *
79 */
79 */
80
80
81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
82 }
82 }
83
83
84 // WATCHDOG
84 // WATCHDOG
85
85
86 rtems_isr watchdog_isr( rtems_vector_number vector )
86 rtems_isr watchdog_isr( rtems_vector_number vector )
87 {
87 {
88 rtems_status_code status_code;
88 rtems_status_code status_code;
89
89
90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
91
91
92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
93
93
94 exit(0);
94 exit(0);
95 }
95 }
96
96
97 void watchdog_configure(void)
97 void watchdog_configure(void)
98 {
98 {
99 /** This function configure the watchdog.
99 /** This function configure the watchdog.
100 *
100 *
101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
103 *
103 *
104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
105 *
105 *
106 */
106 */
107
107
108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
109
109
110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
111
111
112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
113 }
113 }
114
114
115 void watchdog_stop(void)
115 void watchdog_stop(void)
116 {
116 {
117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
118 timer_stop( TIMER_WATCHDOG );
118 timer_stop( TIMER_WATCHDOG );
119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
120 }
120 }
121
121
122 void watchdog_reload(void)
122 void watchdog_reload(void)
123 {
123 {
124 /** This function reloads the watchdog timer counter with the timer reload value.
124 /** This function reloads the watchdog timer counter with the timer reload value.
125 *
125 *
126 * @param void
126 * @param void
127 *
127 *
128 * @return void
128 * @return void
129 *
129 *
130 */
130 */
131
131
132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
133 }
133 }
134
134
135 void watchdog_start(void)
135 void watchdog_start(void)
136 {
136 {
137 /** This function starts the watchdog timer.
137 /** This function starts the watchdog timer.
138 *
138 *
139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
141 *
141 *
142 */
142 */
143
143
144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
145
145
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
150
150
151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
152
152
153 }
153 }
154
154
155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
156 {
156 {
157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
158
158
159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
160
160
161 return 0;
161 return 0;
162 }
162 }
163
163
164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
165 {
165 {
166 /** This function sets the scaler reload register of the apbuart module
166 /** This function sets the scaler reload register of the apbuart module
167 *
167 *
168 * @param regs is the address of the apbuart registers in memory
168 * @param regs is the address of the apbuart registers in memory
169 * @param value is the value that will be stored in the scaler register
169 * @param value is the value that will be stored in the scaler register
170 *
170 *
171 * The value shall be set by the software to get data on the serial interface.
171 * The value shall be set by the software to get data on the serial interface.
172 *
172 *
173 */
173 */
174
174
175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
176
176
177 apbuart_regs->scaler = value;
177 apbuart_regs->scaler = value;
178
178
179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
180 }
180 }
181
181
182 //************
182 //************
183 // RTEMS TASKS
183 // RTEMS TASKS
184
184
185 rtems_task load_task(rtems_task_argument argument)
185 rtems_task load_task(rtems_task_argument argument)
186 {
186 {
187 BOOT_PRINTF("in LOAD *** \n")
187 BOOT_PRINTF("in LOAD *** \n")
188
188
189 rtems_status_code status;
189 rtems_status_code status;
190 unsigned int i;
190 unsigned int i;
191 unsigned int j;
191 unsigned int j;
192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
194
194
195 watchdog_period_id = RTEMS_ID_NONE;
195 watchdog_period_id = RTEMS_ID_NONE;
196
196
197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
198
198
199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
200 if( status != RTEMS_SUCCESSFUL ) {
200 if( status != RTEMS_SUCCESSFUL ) {
201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
202 }
202 }
203
203
204 i = 0;
204 i = 0;
205 j = 0;
205 j = 0;
206
206
207 watchdog_configure();
207 watchdog_configure();
208
208
209 watchdog_start();
209 watchdog_start();
210
210
211 set_sy_lfr_watchdog_enabled( true );
211 set_sy_lfr_watchdog_enabled( true );
212
212
213 while(1){
213 while(1){
214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
215 watchdog_reload();
215 watchdog_reload();
216 i = i + 1;
216 i = i + 1;
217 if ( i == WATCHDOG_LOOP_PRINTF )
217 if ( i == WATCHDOG_LOOP_PRINTF )
218 {
218 {
219 i = 0;
219 i = 0;
220 j = j + 1;
220 j = j + 1;
221 PRINTF1("%d\n", j)
221 PRINTF1("%d\n", j)
222 }
222 }
223 #ifdef DEBUG_WATCHDOG
223 #ifdef DEBUG_WATCHDOG
224 if (j == WATCHDOG_LOOP_DEBUG )
224 if (j == WATCHDOG_LOOP_DEBUG )
225 {
225 {
226 status = rtems_task_delete(RTEMS_SELF);
226 status = rtems_task_delete(RTEMS_SELF);
227 }
227 }
228 #endif
228 #endif
229 }
229 }
230 }
230 }
231
231
232 rtems_task hous_task(rtems_task_argument argument)
232 rtems_task hous_task(rtems_task_argument argument)
233 {
233 {
234 rtems_status_code status;
234 rtems_status_code status;
235 rtems_status_code spare_status;
235 rtems_status_code spare_status;
236 rtems_id queue_id;
236 rtems_id queue_id;
237 rtems_rate_monotonic_period_status period_status;
237 rtems_rate_monotonic_period_status period_status;
238 bool isSynchronized;
238 bool isSynchronized;
239
239
240 queue_id = RTEMS_ID_NONE;
240 queue_id = RTEMS_ID_NONE;
241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
242 isSynchronized = false;
242 isSynchronized = false;
243
243
244 status = get_message_queue_id_send( &queue_id );
244 status = get_message_queue_id_send( &queue_id );
245 if (status != RTEMS_SUCCESSFUL)
245 if (status != RTEMS_SUCCESSFUL)
246 {
246 {
247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
248 }
248 }
249
249
250 BOOT_PRINTF("in HOUS ***\n");
250 BOOT_PRINTF("in HOUS ***\n");
251
251
252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
254 if( status != RTEMS_SUCCESSFUL ) {
254 if( status != RTEMS_SUCCESSFUL ) {
255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
256 }
256 }
257 }
257 }
258
258
259 status = rtems_rate_monotonic_cancel(HK_id);
259 status = rtems_rate_monotonic_cancel(HK_id);
260 if( status != RTEMS_SUCCESSFUL ) {
260 if( status != RTEMS_SUCCESSFUL ) {
261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
262 }
262 }
263 else {
263 else {
264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
265 }
265 }
266
266
267 // startup phase
267 // startup phase
268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
273 {
273 {
274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
275 {
275 {
276 isSynchronized = true;
276 isSynchronized = true;
277 }
277 }
278 else
278 else
279 {
279 {
280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
281
281
282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
283 }
283 }
284 }
284 }
285 status = rtems_rate_monotonic_cancel(HK_id);
285 status = rtems_rate_monotonic_cancel(HK_id);
286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
287
287
288 set_hk_lfr_reset_cause( POWER_ON );
288 set_hk_lfr_reset_cause( POWER_ON );
289
289
290 while(1){ // launch the rate monotonic task
290 while(1){ // launch the rate monotonic task
291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
292 if ( status != RTEMS_SUCCESSFUL ) {
292 if ( status != RTEMS_SUCCESSFUL ) {
293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
295 }
295 }
296 else {
296 else {
297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
299 increment_seq_counter( &sequenceCounterHK );
299 increment_seq_counter( &sequenceCounterHK );
300
300
301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
307
307
308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
309
309
310 spacewire_read_statistics();
310 spacewire_read_statistics();
311
311
312 update_hk_with_grspw_stats();
312 update_hk_with_grspw_stats();
313
313
314 set_hk_lfr_time_not_synchro();
314 set_hk_lfr_time_not_synchro();
315
315
316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
321
321
322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
327
327
328 hk_lfr_le_me_he_update();
328 hk_lfr_le_me_he_update();
329
329
330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
331
331
332 // SEND PACKET
332 // SEND PACKET
333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
335 if (status != RTEMS_SUCCESSFUL) {
335 if (status != RTEMS_SUCCESSFUL) {
336 PRINTF1("in HOUS *** ERR send: %d\n", status)
336 PRINTF1("in HOUS *** ERR send: %d\n", status)
337 }
337 }
338 }
338 }
339 }
339 }
340
340
341 PRINTF("in HOUS *** deleting task\n")
341 PRINTF("in HOUS *** deleting task\n")
342
342
343 status = rtems_task_delete( RTEMS_SELF ); // should not return
343 status = rtems_task_delete( RTEMS_SELF ); // should not return
344
344
345 return;
345 return;
346 }
346 }
347
347
348 rtems_task avgv_task(rtems_task_argument argument)
348 rtems_task avgv_task(rtems_task_argument argument)
349 {
349 {
350 #define MOVING_AVERAGE 16
350 #define MOVING_AVERAGE 16
351 rtems_status_code status;
351 rtems_status_code status;
352 unsigned int v[MOVING_AVERAGE];
352 static unsigned int v[MOVING_AVERAGE] = {0};
353 unsigned int e1[MOVING_AVERAGE];
353 static unsigned int e1[MOVING_AVERAGE] = {0};
354 unsigned int e2[MOVING_AVERAGE];
354 static unsigned int e2[MOVING_AVERAGE] = {0};
355 float average_v;
355 float average_v;
356 float average_e1;
356 float average_e1;
357 float average_e2;
357 float average_e2;
358 unsigned char k;
358 unsigned char k;
359 unsigned char indexOfOldValue;
359 unsigned char indexOfOldValue;
360
360
361 BOOT_PRINTF("in AVGV ***\n");
361 BOOT_PRINTF("in AVGV ***\n");
362
362
363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
365 if( status != RTEMS_SUCCESSFUL ) {
365 if( status != RTEMS_SUCCESSFUL ) {
366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
367 }
367 }
368 }
368 }
369
369
370 status = rtems_rate_monotonic_cancel(AVGV_id);
370 status = rtems_rate_monotonic_cancel(AVGV_id);
371 if( status != RTEMS_SUCCESSFUL ) {
371 if( status != RTEMS_SUCCESSFUL ) {
372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
373 }
373 }
374 else {
374 else {
375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
376 }
376 }
377
377
378 // initialize values
378 // initialize values
379 k = 0;
380 indexOfOldValue = MOVING_AVERAGE - 1;
379 indexOfOldValue = MOVING_AVERAGE - 1;
381 for (k = 0; k < MOVING_AVERAGE; k++)
380 average_v = 0.;
382 {
381 average_e1 = 0.;
383 v[k] = 0;
382 average_e2 = 0.;
384 e1[k] = 0;
385 e2[k] = 0;
386 average_v = 0.;
387 average_e1 = 0.;
388 average_e2 = 0.;
389 }
390
383
391 k = 0;
384 k = 0;
392
385
393 while(1){ // launch the rate monotonic task
386 while(1){ // launch the rate monotonic task
394 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
387 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
395 if ( status != RTEMS_SUCCESSFUL ) {
388 if ( status != RTEMS_SUCCESSFUL ) {
396 PRINTF1( "in AVGV *** ERR period: %d\n", status);
389 PRINTF1( "in AVGV *** ERR period: %d\n", status);
397 }
390 }
398 else {
391 else {
399 // store new value in buffer
392 // store new value in buffer
400 v[k] = waveform_picker_regs->v;
393 v[k] = waveform_picker_regs->v;
401 e1[k] = waveform_picker_regs->e1;
394 e1[k] = waveform_picker_regs->e1;
402 e2[k] = waveform_picker_regs->e2;
395 e2[k] = waveform_picker_regs->e2;
403 if (k == (MOVING_AVERAGE - 1))
396 if (k == (MOVING_AVERAGE - 1))
404 {
397 {
405 indexOfOldValue = 0;
398 indexOfOldValue = 0;
406 }
399 }
407 else
400 else
408 {
401 {
409 indexOfOldValue = k + 1;
402 indexOfOldValue = k + 1;
410 }
403 }
411 average_v = average_v + v[k] - v[indexOfOldValue];
404 average_v = average_v + v[k] - v[indexOfOldValue];
412 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
405 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
413 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
406 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
414 }
407 }
415 if (k == (MOVING_AVERAGE-1))
408 if (k == (MOVING_AVERAGE-1))
416 {
409 {
417 k = 0;
410 k = 0;
418 printf("tick\n");
411 printf("tick\n");
419 }
412 }
420 else
413 else
421 {
414 {
422 k++;
415 k++;
423 }
416 }
424 }
417 }
425
418
426 PRINTF("in AVGV *** deleting task\n")
419 PRINTF("in AVGV *** deleting task\n")
427
420
428 status = rtems_task_delete( RTEMS_SELF ); // should not return
421 status = rtems_task_delete( RTEMS_SELF ); // should not return
429
422
430 return;
423 return;
431 }
424 }
432
425
433 rtems_task dumb_task( rtems_task_argument unused )
426 rtems_task dumb_task( rtems_task_argument unused )
434 {
427 {
435 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
428 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
436 *
429 *
437 * @param unused is the starting argument of the RTEMS task
430 * @param unused is the starting argument of the RTEMS task
438 *
431 *
439 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
432 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
440 *
433 *
441 */
434 */
442
435
443 unsigned int i;
436 unsigned int i;
444 unsigned int intEventOut;
437 unsigned int intEventOut;
445 unsigned int coarse_time = 0;
438 unsigned int coarse_time = 0;
446 unsigned int fine_time = 0;
439 unsigned int fine_time = 0;
447 rtems_event_set event_out;
440 rtems_event_set event_out;
448
441
449 event_out = EVENT_SETS_NONE_PENDING;
442 event_out = EVENT_SETS_NONE_PENDING;
450
443
451 BOOT_PRINTF("in DUMB *** \n")
444 BOOT_PRINTF("in DUMB *** \n")
452
445
453 while(1){
446 while(1){
454 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
447 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
455 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
448 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
456 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
449 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
457 | RTEMS_EVENT_14,
450 | RTEMS_EVENT_14,
458 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
451 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
459 intEventOut = (unsigned int) event_out;
452 intEventOut = (unsigned int) event_out;
460 for ( i=0; i<NB_RTEMS_EVENTS; i++)
453 for ( i=0; i<NB_RTEMS_EVENTS; i++)
461 {
454 {
462 if ( ((intEventOut >> i) & 1) != 0)
455 if ( ((intEventOut >> i) & 1) != 0)
463 {
456 {
464 coarse_time = time_management_regs->coarse_time;
457 coarse_time = time_management_regs->coarse_time;
465 fine_time = time_management_regs->fine_time;
458 fine_time = time_management_regs->fine_time;
466 if (i==EVENT_12)
459 if (i==EVENT_12)
467 {
460 {
468 PRINTF1("%s\n", DUMB_MESSAGE_12)
461 PRINTF1("%s\n", DUMB_MESSAGE_12)
469 }
462 }
470 if (i==EVENT_13)
463 if (i==EVENT_13)
471 {
464 {
472 PRINTF1("%s\n", DUMB_MESSAGE_13)
465 PRINTF1("%s\n", DUMB_MESSAGE_13)
473 }
466 }
474 if (i==EVENT_14)
467 if (i==EVENT_14)
475 {
468 {
476 PRINTF1("%s\n", DUMB_MESSAGE_1)
469 PRINTF1("%s\n", DUMB_MESSAGE_1)
477 }
470 }
478 }
471 }
479 }
472 }
480 }
473 }
481 }
474 }
482
475
483 //*****************************
476 //*****************************
484 // init housekeeping parameters
477 // init housekeeping parameters
485
478
486 void init_housekeeping_parameters( void )
479 void init_housekeeping_parameters( void )
487 {
480 {
488 /** This function initialize the housekeeping_packet global variable with default values.
481 /** This function initialize the housekeeping_packet global variable with default values.
489 *
482 *
490 */
483 */
491
484
492 unsigned int i = 0;
485 unsigned int i = 0;
493 unsigned char *parameters;
486 unsigned char *parameters;
494 unsigned char sizeOfHK;
487 unsigned char sizeOfHK;
495
488
496 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
489 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
497
490
498 parameters = (unsigned char*) &housekeeping_packet;
491 parameters = (unsigned char*) &housekeeping_packet;
499
492
500 for(i = 0; i< sizeOfHK; i++)
493 for(i = 0; i< sizeOfHK; i++)
501 {
494 {
502 parameters[i] = INIT_CHAR;
495 parameters[i] = INIT_CHAR;
503 }
496 }
504
497
505 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
498 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
506 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
499 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
507 housekeeping_packet.reserved = DEFAULT_RESERVED;
500 housekeeping_packet.reserved = DEFAULT_RESERVED;
508 housekeeping_packet.userApplication = CCSDS_USER_APP;
501 housekeeping_packet.userApplication = CCSDS_USER_APP;
509 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
502 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
510 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
503 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
511 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
504 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
512 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
505 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
513 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
506 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
514 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
507 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
515 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
508 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
516 housekeeping_packet.serviceType = TM_TYPE_HK;
509 housekeeping_packet.serviceType = TM_TYPE_HK;
517 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
510 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
518 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
511 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
519 housekeeping_packet.sid = SID_HK;
512 housekeeping_packet.sid = SID_HK;
520
513
521 // init status word
514 // init status word
522 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
515 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
523 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
516 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
524 // init software version
517 // init software version
525 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
518 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
526 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
519 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
527 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
520 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
528 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
521 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
529 // init fpga version
522 // init fpga version
530 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
523 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
531 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
524 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
532 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
525 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
533 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
526 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
534
527
535 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
528 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
536 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
529 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
537 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
530 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
538 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
531 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
539 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
532 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
540 }
533 }
541
534
542 void increment_seq_counter( unsigned short *packetSequenceControl )
535 void increment_seq_counter( unsigned short *packetSequenceControl )
543 {
536 {
544 /** This function increment the sequence counter passes in argument.
537 /** This function increment the sequence counter passes in argument.
545 *
538 *
546 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
539 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
547 *
540 *
548 */
541 */
549
542
550 unsigned short segmentation_grouping_flag;
543 unsigned short segmentation_grouping_flag;
551 unsigned short sequence_cnt;
544 unsigned short sequence_cnt;
552
545
553 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
546 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
554 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
547 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
555
548
556 if ( sequence_cnt < SEQ_CNT_MAX)
549 if ( sequence_cnt < SEQ_CNT_MAX)
557 {
550 {
558 sequence_cnt = sequence_cnt + 1;
551 sequence_cnt = sequence_cnt + 1;
559 }
552 }
560 else
553 else
561 {
554 {
562 sequence_cnt = 0;
555 sequence_cnt = 0;
563 }
556 }
564
557
565 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
558 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
566 }
559 }
567
560
568 void getTime( unsigned char *time)
561 void getTime( unsigned char *time)
569 {
562 {
570 /** This function write the current local time in the time buffer passed in argument.
563 /** This function write the current local time in the time buffer passed in argument.
571 *
564 *
572 */
565 */
573
566
574 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
567 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
575 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
568 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
576 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
569 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
577 time[3] = (unsigned char) (time_management_regs->coarse_time);
570 time[3] = (unsigned char) (time_management_regs->coarse_time);
578 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
571 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
579 time[5] = (unsigned char) (time_management_regs->fine_time);
572 time[5] = (unsigned char) (time_management_regs->fine_time);
580 }
573 }
581
574
582 unsigned long long int getTimeAsUnsignedLongLongInt( )
575 unsigned long long int getTimeAsUnsignedLongLongInt( )
583 {
576 {
584 /** This function write the current local time in the time buffer passed in argument.
577 /** This function write the current local time in the time buffer passed in argument.
585 *
578 *
586 */
579 */
587 unsigned long long int time;
580 unsigned long long int time;
588
581
589 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
582 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
590 + time_management_regs->fine_time;
583 + time_management_regs->fine_time;
591
584
592 return time;
585 return time;
593 }
586 }
594
587
595 void send_dumb_hk( void )
588 void send_dumb_hk( void )
596 {
589 {
597 Packet_TM_LFR_HK_t dummy_hk_packet;
590 Packet_TM_LFR_HK_t dummy_hk_packet;
598 unsigned char *parameters;
591 unsigned char *parameters;
599 unsigned int i;
592 unsigned int i;
600 rtems_id queue_id;
593 rtems_id queue_id;
601
594
602 queue_id = RTEMS_ID_NONE;
595 queue_id = RTEMS_ID_NONE;
603
596
604 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
597 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
605 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
598 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
606 dummy_hk_packet.reserved = DEFAULT_RESERVED;
599 dummy_hk_packet.reserved = DEFAULT_RESERVED;
607 dummy_hk_packet.userApplication = CCSDS_USER_APP;
600 dummy_hk_packet.userApplication = CCSDS_USER_APP;
608 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
601 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
609 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
602 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
610 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
603 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
611 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
604 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
612 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
605 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
613 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
606 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
614 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
607 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
615 dummy_hk_packet.serviceType = TM_TYPE_HK;
608 dummy_hk_packet.serviceType = TM_TYPE_HK;
616 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
609 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
617 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
610 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
618 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
611 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
619 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
612 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
620 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
613 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
621 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
614 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
622 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
615 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
623 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
616 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
624 dummy_hk_packet.sid = SID_HK;
617 dummy_hk_packet.sid = SID_HK;
625
618
626 // init status word
619 // init status word
627 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
620 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
628 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
621 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
629 // init software version
622 // init software version
630 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
623 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
631 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
624 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
632 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
625 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
633 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
626 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
634 // init fpga version
627 // init fpga version
635 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
628 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
636 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
629 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
637 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
630 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
638 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
631 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
639
632
640 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
633 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
641
634
642 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
635 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
643 {
636 {
644 parameters[i] = INT8_ALL_F;
637 parameters[i] = INT8_ALL_F;
645 }
638 }
646
639
647 get_message_queue_id_send( &queue_id );
640 get_message_queue_id_send( &queue_id );
648
641
649 rtems_message_queue_send( queue_id, &dummy_hk_packet,
642 rtems_message_queue_send( queue_id, &dummy_hk_packet,
650 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
643 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
651 }
644 }
652
645
653 void get_temperatures( unsigned char *temperatures )
646 void get_temperatures( unsigned char *temperatures )
654 {
647 {
655 unsigned char* temp_scm_ptr;
648 unsigned char* temp_scm_ptr;
656 unsigned char* temp_pcb_ptr;
649 unsigned char* temp_pcb_ptr;
657 unsigned char* temp_fpga_ptr;
650 unsigned char* temp_fpga_ptr;
658
651
659 // SEL1 SEL0
652 // SEL1 SEL0
660 // 0 0 => PCB
653 // 0 0 => PCB
661 // 0 1 => FPGA
654 // 0 1 => FPGA
662 // 1 0 => SCM
655 // 1 0 => SCM
663
656
664 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
657 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
665 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
658 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
666 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
659 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
667
660
668 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
661 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
669 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
662 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
670 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
663 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
671 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
664 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
672 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
665 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
673 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
666 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
674 }
667 }
675
668
676 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
669 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
677 {
670 {
678 unsigned char* v_ptr;
671 unsigned char* v_ptr;
679 unsigned char* e1_ptr;
672 unsigned char* e1_ptr;
680 unsigned char* e2_ptr;
673 unsigned char* e2_ptr;
681
674
682 v_ptr = (unsigned char *) &waveform_picker_regs->v;
675 v_ptr = (unsigned char *) &waveform_picker_regs->v;
683 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
676 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
684 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
677 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
685
678
686 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
679 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
687 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
680 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
688 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
681 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
689 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
682 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
690 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
683 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
691 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
684 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
692 }
685 }
693
686
694 void get_cpu_load( unsigned char *resource_statistics )
687 void get_cpu_load( unsigned char *resource_statistics )
695 {
688 {
696 unsigned char cpu_load;
689 unsigned char cpu_load;
697
690
698 cpu_load = lfr_rtems_cpu_usage_report();
691 cpu_load = lfr_rtems_cpu_usage_report();
699
692
700 // HK_LFR_CPU_LOAD
693 // HK_LFR_CPU_LOAD
701 resource_statistics[0] = cpu_load;
694 resource_statistics[0] = cpu_load;
702
695
703 // HK_LFR_CPU_LOAD_MAX
696 // HK_LFR_CPU_LOAD_MAX
704 if (cpu_load > resource_statistics[1])
697 if (cpu_load > resource_statistics[1])
705 {
698 {
706 resource_statistics[1] = cpu_load;
699 resource_statistics[1] = cpu_load;
707 }
700 }
708
701
709 // CPU_LOAD_AVE
702 // CPU_LOAD_AVE
710 resource_statistics[BYTE_2] = 0;
703 resource_statistics[BYTE_2] = 0;
711
704
712 #ifndef PRINT_TASK_STATISTICS
705 #ifndef PRINT_TASK_STATISTICS
713 rtems_cpu_usage_reset();
706 rtems_cpu_usage_reset();
714 #endif
707 #endif
715
708
716 }
709 }
717
710
718 void set_hk_lfr_sc_potential_flag( bool state )
711 void set_hk_lfr_sc_potential_flag( bool state )
719 {
712 {
720 if (state == true)
713 if (state == true)
721 {
714 {
722 housekeeping_packet.lfr_status_word[1] =
715 housekeeping_packet.lfr_status_word[1] =
723 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
716 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
724 }
717 }
725 else
718 else
726 {
719 {
727 housekeeping_packet.lfr_status_word[1] =
720 housekeeping_packet.lfr_status_word[1] =
728 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
721 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
729 }
722 }
730 }
723 }
731
724
732 void set_sy_lfr_pas_filter_enabled( bool state )
725 void set_sy_lfr_pas_filter_enabled( bool state )
733 {
726 {
734 if (state == true)
727 if (state == true)
735 {
728 {
736 housekeeping_packet.lfr_status_word[1] =
729 housekeeping_packet.lfr_status_word[1] =
737 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
738 }
731 }
739 else
732 else
740 {
733 {
741 housekeeping_packet.lfr_status_word[1] =
734 housekeeping_packet.lfr_status_word[1] =
742 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
743 }
736 }
744 }
737 }
745
738
746 void set_sy_lfr_watchdog_enabled( bool state )
739 void set_sy_lfr_watchdog_enabled( bool state )
747 {
740 {
748 if (state == true)
741 if (state == true)
749 {
742 {
750 housekeeping_packet.lfr_status_word[1] =
743 housekeeping_packet.lfr_status_word[1] =
751 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
744 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
752 }
745 }
753 else
746 else
754 {
747 {
755 housekeeping_packet.lfr_status_word[1] =
748 housekeeping_packet.lfr_status_word[1] =
756 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
749 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
757 }
750 }
758 }
751 }
759
752
760 void set_hk_lfr_calib_enable( bool state )
753 void set_hk_lfr_calib_enable( bool state )
761 {
754 {
762 if (state == true)
755 if (state == true)
763 {
756 {
764 housekeeping_packet.lfr_status_word[1] =
757 housekeeping_packet.lfr_status_word[1] =
765 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
758 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
766 }
759 }
767 else
760 else
768 {
761 {
769 housekeeping_packet.lfr_status_word[1] =
762 housekeeping_packet.lfr_status_word[1] =
770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
763 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
771 }
764 }
772 }
765 }
773
766
774 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
767 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
775 {
768 {
776 housekeeping_packet.lfr_status_word[1] =
769 housekeeping_packet.lfr_status_word[1] =
777 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
778
771
779 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
772 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
780 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
773 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
781
774
782 }
775 }
783
776
784 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
777 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
785 {
778 {
786 int delta;
779 int delta;
787
780
788 delta = 0;
781 delta = 0;
789
782
790 if (newValue >= oldValue)
783 if (newValue >= oldValue)
791 {
784 {
792 delta = newValue - oldValue;
785 delta = newValue - oldValue;
793 }
786 }
794 else
787 else
795 {
788 {
796 delta = 255 - oldValue + newValue;
789 delta = (255 - oldValue) + newValue;
797 }
790 }
798
791
799 *counter = *counter + delta;
792 *counter = *counter + delta;
800 }
793 }
801
794
802 void hk_lfr_le_update( void )
795 void hk_lfr_le_update( void )
803 {
796 {
804 static hk_lfr_le_t old_hk_lfr_le = {0};
797 static hk_lfr_le_t old_hk_lfr_le = {0};
805 hk_lfr_le_t new_hk_lfr_le;
798 hk_lfr_le_t new_hk_lfr_le;
806 unsigned int counter;
799 unsigned int counter;
807
800
808 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
801 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
809
802
810 // DPU
803 // DPU
811 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
804 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
812 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
805 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
813 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
806 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
814 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
807 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
815 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
808 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
816 // TIMECODE
809 // TIMECODE
817 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
810 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
818 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
811 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
819 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
812 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
820 // TIME
813 // TIME
821 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
814 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
822 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
815 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
823 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
816 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
824 //AHB
817 //AHB
825 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
818 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
826 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
819 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
827 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
820 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
828
821
829 // update the le counter
822 // update the le counter
830 // DPU
823 // DPU
831 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
824 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
832 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
825 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
833 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
826 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
834 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
827 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
835 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
828 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
836 // TIMECODE
829 // TIMECODE
837 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
830 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
838 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
831 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
839 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
832 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
840 // TIME
833 // TIME
841 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
834 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
842 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
835 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
843 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
836 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
844 // AHB
837 // AHB
845 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
838 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
846
839
847 // DPU
840 // DPU
848 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
841 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
849 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
842 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
850 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
843 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
851 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
844 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
852 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
845 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
853 // TIMECODE
846 // TIMECODE
854 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
847 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
855 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
848 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
856 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
849 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
857 // TIME
850 // TIME
858 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
851 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
859 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
852 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
860 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
853 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
861 //AHB
854 //AHB
862 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
855 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
863 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
856 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
864 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
857 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
865
858
866 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
859 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
867 // LE
860 // LE
868 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
861 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
869 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
862 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
870 }
863 }
871
864
872 void hk_lfr_me_update( void )
865 void hk_lfr_me_update( void )
873 {
866 {
874 static hk_lfr_me_t old_hk_lfr_me = {0};
867 static hk_lfr_me_t old_hk_lfr_me = {0};
875 hk_lfr_me_t new_hk_lfr_me;
868 hk_lfr_me_t new_hk_lfr_me;
876 unsigned int counter;
869 unsigned int counter;
877
870
878 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
871 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
879
872
880 // get the current values
873 // get the current values
881 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
874 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
882 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
875 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
883 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
876 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
884 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
877 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
885
878
886 // update the me counter
879 // update the me counter
887 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
880 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
888 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
881 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
889 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
882 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
890 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
883 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
891
884
892 // store the counters for the next time
885 // store the counters for the next time
893 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
886 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
894 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
887 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
895 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
888 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
896 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
889 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
897
890
898 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
891 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
899 // ME
892 // ME
900 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
893 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
901 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
894 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
902 }
895 }
903
896
904 void hk_lfr_le_me_he_update()
897 void hk_lfr_le_me_he_update()
905 {
898 {
906
899
907 unsigned int hk_lfr_he_cnt;
900 unsigned int hk_lfr_he_cnt;
908
901
909 hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
902 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
910
903
911 //update the low severity error counter
904 //update the low severity error counter
912 hk_lfr_le_update( );
905 hk_lfr_le_update( );
913
906
914 //update the medium severity error counter
907 //update the medium severity error counter
915 hk_lfr_me_update();
908 hk_lfr_me_update();
916
909
917 //update the high severity error counter
910 //update the high severity error counter
918 hk_lfr_he_cnt = 0;
911 hk_lfr_he_cnt = 0;
919
912
920 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
913 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
921 // HE
914 // HE
922 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
915 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
923 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
916 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
924
917
925 }
918 }
926
919
927 void set_hk_lfr_time_not_synchro()
920 void set_hk_lfr_time_not_synchro()
928 {
921 {
929 static unsigned char synchroLost = 1;
922 static unsigned char synchroLost = 1;
930 int synchronizationBit;
923 int synchronizationBit;
931
924
932 // get the synchronization bit
925 // get the synchronization bit
933 synchronizationBit =
926 synchronizationBit =
934 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
927 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
935
928
936 switch (synchronizationBit)
929 switch (synchronizationBit)
937 {
930 {
938 case 0:
931 case 0:
939 if (synchroLost == 1)
932 if (synchroLost == 1)
940 {
933 {
941 synchroLost = 0;
934 synchroLost = 0;
942 }
935 }
943 break;
936 break;
944 case 1:
937 case 1:
945 if (synchroLost == 0 )
938 if (synchroLost == 0 )
946 {
939 {
947 synchroLost = 1;
940 synchroLost = 1;
948 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
941 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
949 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
942 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
950 }
943 }
951 break;
944 break;
952 default:
945 default:
953 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
946 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
954 break;
947 break;
955 }
948 }
956
949
957 }
950 }
958
951
959 void set_hk_lfr_ahb_correctable() // CRITICITY L
952 void set_hk_lfr_ahb_correctable() // CRITICITY L
960 {
953 {
961 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
954 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
962 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
955 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
963 * detected errors in the cache, in the integer unit and in the floating point unit.
956 * detected errors in the cache, in the integer unit and in the floating point unit.
964 *
957 *
965 * @param void
958 * @param void
966 *
959 *
967 * @return void
960 * @return void
968 *
961 *
969 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
962 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
970 *
963 *
971 */
964 */
972
965
973 unsigned int ahb_correctable;
966 unsigned int ahb_correctable;
974 unsigned int instructionErrorCounter;
967 unsigned int instructionErrorCounter;
975 unsigned int dataErrorCounter;
968 unsigned int dataErrorCounter;
976 unsigned int fprfErrorCounter;
969 unsigned int fprfErrorCounter;
977 unsigned int iurfErrorCounter;
970 unsigned int iurfErrorCounter;
978
971
979 instructionErrorCounter = 0;
972 instructionErrorCounter = 0;
980 dataErrorCounter = 0;
973 dataErrorCounter = 0;
981 fprfErrorCounter = 0;
974 fprfErrorCounter = 0;
982 iurfErrorCounter = 0;
975 iurfErrorCounter = 0;
983
976
984 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
977 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
985 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
978 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
986
979
987 ahb_correctable = instructionErrorCounter
980 ahb_correctable = instructionErrorCounter
988 + dataErrorCounter
981 + dataErrorCounter
989 + fprfErrorCounter
982 + fprfErrorCounter
990 + iurfErrorCounter
983 + iurfErrorCounter
991 + housekeeping_packet.hk_lfr_ahb_correctable;
984 + housekeeping_packet.hk_lfr_ahb_correctable;
992
985
993 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
986 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
994
987
995 }
988 }
@@ -1,46 +1,48
1 /** Global variables used by the processing functions.
1 /** Global variables used by the processing functions.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
8 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
9 // SX 12 coefficients
9 // SX 12 coefficients
10 float K14_sx_re = 1;
10 float K14_sx_re = 1;
11 float K14_sx_im = 1;
11 float K14_sx_im = 1;
12 float K15_sx_re = 1;
12 float K15_sx_re = 1;
13 float K15_sx_im = 1;
13 float K15_sx_im = 1;
14 float K24_sx_re = 1;
14 float K24_sx_re = 1;
15 float K24_sx_im = 1;
15 float K24_sx_im = 1;
16 float K25_sx_re = 1;
16 float K25_sx_re = 1;
17 float K25_sx_im = 1;
17 float K25_sx_im = 1;
18 float K34_sx_re = 1;
18 float K34_sx_re = 1;
19 float K34_sx_im = 1;
19 float K34_sx_im = 1;
20 float K35_sx_re = 1;
20 float K35_sx_re = 1;
21 float K35_sx_im = 1;
21 float K35_sx_im = 1;
22 // NY 8 coefficients
22 // NY 8 coefficients
23 float K24_ny_re = 1;
23 float K24_ny_re = 1;
24 float K24_ny_im = 1;
24 float K24_ny_im = 1;
25 float K25_ny_re = 1;
25 float K25_ny_re = 1;
26 float K25_ny_im = 1;
26 float K25_ny_im = 1;
27 float K34_ny_re = 1;
27 float K34_ny_re = 1;
28 float K34_ny_im = 1;
28 float K34_ny_im = 1;
29 float K35_ny_re = 1;
29 float K35_ny_re = 1;
30 float K35_ny_im = 1;
30 float K35_ny_im = 1;
31 // NZ 8 coefficients
31 // NZ 8 coefficients
32 float K24_nz_re = 1;
32 float K24_nz_re = 1;
33 float K24_nz_im = 1;
33 float K24_nz_im = 1;
34 float K25_nz_re = 1;
34 float K25_nz_re = 1;
35 float K25_nz_im = 1;
35 float K25_nz_im = 1;
36 float K34_nz_re = 1;
36 float K34_nz_re = 1;
37 float K34_nz_im = 1;
37 float K34_nz_im = 1;
38 float K35_nz_re = 1;
38 float K35_nz_re = 1;
39 float K35_nz_im = 1;
39 float K35_nz_im = 1;
40 // PE 4 coefficients
40 // PE 4 coefficients
41 float K44_pe = 1;
41 float K44_pe = 1;
42 float K55_pe = 1;
42 float K55_pe = 1;
43 float K45_pe_re = 1;
43 float K45_pe_re = 1;
44 float K45_pe_im = 1;
44 float K45_pe_im = 1;
45
45
46 float Alpha_M = M_PI/4;
46 #define ALPHA_M (M_PI / 4)
47
48 float Alpha_M = ALPHA_M;
@@ -1,1631 +1,1633
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name = 0;
16 rtems_name semq_name = 0;
17 rtems_id semq_id = RTEMS_ID_NONE;
17 rtems_id semq_id = RTEMS_ID_NONE;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
24
24
25 unsigned char previousTimecodeCtr = 0;
25 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
27
28 //***********
28 //***********
29 // RTEMS TASK
29 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
30 rtems_task spiq_task(rtems_task_argument unused)
31 {
31 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
33 *
34 * @param unused is the starting argument of the RTEMS task
34 * @param unused is the starting argument of the RTEMS task
35 *
35 *
36 */
36 */
37
37
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 int linkStatus;
40 int linkStatus;
41
41
42 event_out = EVENT_SETS_NONE_PENDING;
42 event_out = EVENT_SETS_NONE_PENDING;
43 linkStatus = 0;
43 linkStatus = 0;
44
44
45 BOOT_PRINTF("in SPIQ *** \n")
45 BOOT_PRINTF("in SPIQ *** \n")
46
46
47 while(true){
47 while(true){
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
50
50
51 // [0] SUSPEND RECV AND SEND TASKS
51 // [0] SUSPEND RECV AND SEND TASKS
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
53 if ( status != RTEMS_SUCCESSFUL ) {
53 if ( status != RTEMS_SUCCESSFUL ) {
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
55 }
55 }
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
57 if ( status != RTEMS_SUCCESSFUL ) {
57 if ( status != RTEMS_SUCCESSFUL ) {
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
59 }
59 }
60
60
61 // [1] CHECK THE LINK
61 // [1] CHECK THE LINK
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
63 if ( linkStatus != SPW_LINK_OK) {
63 if ( linkStatus != SPW_LINK_OK) {
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
66 }
66 }
67
67
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
71 {
71 {
72 spacewire_read_statistics();
72 spacewire_read_statistics();
73 status = spacewire_several_connect_attemps( );
73 status = spacewire_several_connect_attemps( );
74 }
74 }
75 else // [2.b] in run state, start the link
75 else // [2.b] in run state, start the link
76 {
76 {
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
78 if ( status != RTEMS_SUCCESSFUL)
78 if ( status != RTEMS_SUCCESSFUL)
79 {
79 {
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
81 }
81 }
82 }
82 }
83
83
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
86 {
86 {
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
88 if ( status != RTEMS_SUCCESSFUL ) {
88 if ( status != RTEMS_SUCCESSFUL ) {
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
90 }
90 }
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
92 if ( status != RTEMS_SUCCESSFUL ) {
92 if ( status != RTEMS_SUCCESSFUL ) {
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
94 }
94 }
95 }
95 }
96 else // [3.b] the link is not in run state, go in STANDBY mode
96 else // [3.b] the link is not in run state, go in STANDBY mode
97 {
97 {
98 status = enter_mode_standby();
98 status = enter_mode_standby();
99 if ( status != RTEMS_SUCCESSFUL )
99 if ( status != RTEMS_SUCCESSFUL )
100 {
100 {
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
102 }
102 }
103 {
103 {
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
105 }
105 }
106 // wake the LINK task up to wait for the link recovery
106 // wake the LINK task up to wait for the link recovery
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
108 status = rtems_task_suspend( RTEMS_SELF );
108 status = rtems_task_suspend( RTEMS_SELF );
109 }
109 }
110 }
110 }
111 }
111 }
112
112
113 rtems_task recv_task( rtems_task_argument unused )
113 rtems_task recv_task( rtems_task_argument unused )
114 {
114 {
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
116 *
116 *
117 * @param unused is the starting argument of the RTEMS task
117 * @param unused is the starting argument of the RTEMS task
118 *
118 *
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
120 * 1. It reads the incoming data.
120 * 1. It reads the incoming data.
121 * 2. Launches the acceptance procedure.
121 * 2. Launches the acceptance procedure.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
123 *
123 *
124 */
124 */
125
125
126 int len;
126 int len;
127 ccsdsTelecommandPacket_t currentTC;
127 ccsdsTelecommandPacket_t currentTC;
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
130 unsigned char destinationID;
130 unsigned char destinationID;
131 unsigned int estimatedPacketLength;
131 unsigned int estimatedPacketLength;
132 unsigned int parserCode;
132 unsigned int parserCode;
133 rtems_status_code status;
133 rtems_status_code status;
134 rtems_id queue_recv_id;
134 rtems_id queue_recv_id;
135 rtems_id queue_send_id;
135 rtems_id queue_send_id;
136
136
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 destinationID = 0;
138 destinationID = 0;
139 queue_recv_id = RTEMS_ID_NONE;
139 queue_recv_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
141
141
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
143
143
144 status = get_message_queue_id_recv( &queue_recv_id );
144 status = get_message_queue_id_recv( &queue_recv_id );
145 if (status != RTEMS_SUCCESSFUL)
145 if (status != RTEMS_SUCCESSFUL)
146 {
146 {
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
148 }
148 }
149
149
150 status = get_message_queue_id_send( &queue_send_id );
150 status = get_message_queue_id_send( &queue_send_id );
151 if (status != RTEMS_SUCCESSFUL)
151 if (status != RTEMS_SUCCESSFUL)
152 {
152 {
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
154 }
154 }
155
155
156 BOOT_PRINTF("in RECV *** \n")
156 BOOT_PRINTF("in RECV *** \n")
157
157
158 while(1)
158 while(1)
159 {
159 {
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
161 if (len == -1){ // error during the read call
161 if (len == -1){ // error during the read call
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
163 }
163 }
164 else {
164 else {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
166 PRINTF("in RECV *** packet lenght too short\n")
166 PRINTF("in RECV *** packet lenght too short\n")
167 }
167 }
168 else {
168 else {
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
173 // CHECK THE TC
173 // CHECK THE TC
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
178 || (parserCode == WRONG_SRC_ID) )
178 || (parserCode == WRONG_SRC_ID) )
179 { // send TM_LFR_TC_EXE_CORRUPTED
179 { // send TM_LFR_TC_EXE_CORRUPTED
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
182 &&
182 &&
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
184 )
184 )
185 {
185 {
186 if ( parserCode == WRONG_SRC_ID )
186 if ( parserCode == WRONG_SRC_ID )
187 {
187 {
188 destinationID = SID_TC_GROUND;
188 destinationID = SID_TC_GROUND;
189 }
189 }
190 else
190 else
191 {
191 {
192 destinationID = currentTC.sourceID;
192 destinationID = currentTC.sourceID;
193 }
193 }
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
195 computed_CRC, currentTC_LEN_RCV,
195 computed_CRC, currentTC_LEN_RCV,
196 destinationID );
196 destinationID );
197 }
197 }
198 }
198 }
199 else
199 else
200 { // send valid TC to the action launcher
200 { // send valid TC to the action launcher
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
203 }
203 }
204 }
204 }
205 }
205 }
206
206
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
208
208
209 }
209 }
210 }
210 }
211
211
212 rtems_task send_task( rtems_task_argument argument)
212 rtems_task send_task( rtems_task_argument argument)
213 {
213 {
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
215 *
215 *
216 * @param unused is the starting argument of the RTEMS task
216 * @param unused is the starting argument of the RTEMS task
217 *
217 *
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
222 * data it contains.
222 * data it contains.
223 *
223 *
224 */
224 */
225
225
226 rtems_status_code status; // RTEMS status code
226 rtems_status_code status; // RTEMS status code
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
228 ring_node *incomingRingNodePtr;
228 ring_node *incomingRingNodePtr;
229 int ring_node_address;
229 int ring_node_address;
230 char *charPtr;
230 char *charPtr;
231 spw_ioctl_pkt_send *spw_ioctl_send;
231 spw_ioctl_pkt_send *spw_ioctl_send;
232 size_t size; // size of the incoming TC packet
232 size_t size; // size of the incoming TC packet
233 rtems_id queue_send_id;
233 rtems_id queue_send_id;
234 unsigned int sid;
234 unsigned int sid;
235 unsigned char sidAsUnsignedChar;
235 unsigned char sidAsUnsignedChar;
236 unsigned char type;
236 unsigned char type;
237
237
238 incomingRingNodePtr = NULL;
238 incomingRingNodePtr = NULL;
239 ring_node_address = 0;
239 ring_node_address = 0;
240 charPtr = (char *) &ring_node_address;
240 charPtr = (char *) &ring_node_address;
241 size = 0;
241 size = 0;
242 queue_send_id = RTEMS_ID_NONE;
242 queue_send_id = RTEMS_ID_NONE;
243 sid = 0;
243 sid = 0;
244 sidAsUnsignedChar = 0;
244 sidAsUnsignedChar = 0;
245
245
246 init_header_cwf( &headerCWF );
246 init_header_cwf( &headerCWF );
247 init_header_swf( &headerSWF );
247 init_header_swf( &headerSWF );
248 init_header_asm( &headerASM );
248 init_header_asm( &headerASM );
249
249
250 status = get_message_queue_id_send( &queue_send_id );
250 status = get_message_queue_id_send( &queue_send_id );
251 if (status != RTEMS_SUCCESSFUL)
251 if (status != RTEMS_SUCCESSFUL)
252 {
252 {
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
254 }
254 }
255
255
256 BOOT_PRINTF("in SEND *** \n")
256 BOOT_PRINTF("in SEND *** \n")
257
257
258 while(1)
258 while(1)
259 {
259 {
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
262
262
263 if (status!=RTEMS_SUCCESSFUL)
263 if (status!=RTEMS_SUCCESSFUL)
264 {
264 {
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
266 }
266 }
267 else
267 else
268 {
268 {
269 if ( size == sizeof(ring_node*) )
269 if ( size == sizeof(ring_node*) )
270 {
270 {
271 charPtr[0] = incomingData[0];
271 charPtr[0] = incomingData[0];
272 charPtr[1] = incomingData[1];
272 charPtr[1] = incomingData[1];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
275 incomingRingNodePtr = (ring_node*) ring_node_address;
275 incomingRingNodePtr = (ring_node*) ring_node_address;
276 sid = incomingRingNodePtr->sid;
276 sid = incomingRingNodePtr->sid;
277 if ( (sid==SID_NORM_CWF_LONG_F3)
277 if ( (sid==SID_NORM_CWF_LONG_F3)
278 || (sid==SID_BURST_CWF_F2 )
278 || (sid==SID_BURST_CWF_F2 )
279 || (sid==SID_SBM1_CWF_F1 )
279 || (sid==SID_SBM1_CWF_F1 )
280 || (sid==SID_SBM2_CWF_F2 ))
280 || (sid==SID_SBM2_CWF_F2 ))
281 {
281 {
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
283 }
283 }
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
285 {
285 {
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
287 }
287 }
288 else if ( (sid==SID_NORM_CWF_F3) )
288 else if ( (sid==SID_NORM_CWF_F3) )
289 {
289 {
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
291 }
291 }
292 else if (sid==SID_NORM_ASM_F0)
292 else if (sid==SID_NORM_ASM_F0)
293 {
293 {
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
295 }
295 }
296 else if (sid==SID_NORM_ASM_F1)
296 else if (sid==SID_NORM_ASM_F1)
297 {
297 {
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
299 }
299 }
300 else if (sid==SID_NORM_ASM_F2)
300 else if (sid==SID_NORM_ASM_F2)
301 {
301 {
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
303 }
303 }
304 else if ( sid==TM_CODE_K_DUMP )
304 else if ( sid==TM_CODE_K_DUMP )
305 {
305 {
306 spw_send_k_dump( incomingRingNodePtr );
306 spw_send_k_dump( incomingRingNodePtr );
307 }
307 }
308 else
308 else
309 {
309 {
310 PRINTF1("unexpected sid = %d\n", sid);
310 PRINTF1("unexpected sid = %d\n", sid);
311 }
311 }
312 }
312 }
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
314 {
314 {
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
316 sid = sidAsUnsignedChar;
316 sid = sidAsUnsignedChar;
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
320 {
320 {
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
322 }
322 }
323
323
324 status = write( fdSPW, incomingData, size );
324 status = write( fdSPW, incomingData, size );
325 if (status == -1){
325 if (status == -1){
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
327 }
327 }
328 }
328 }
329 else // the incoming message is a spw_ioctl_pkt_send structure
329 else // the incoming message is a spw_ioctl_pkt_send structure
330 {
330 {
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
333 if (status == -1){
333 if (status == -1){
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
335 }
335 }
336 }
336 }
337 }
337 }
338
338
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
340
340
341 }
341 }
342 }
342 }
343
343
344 rtems_task link_task( rtems_task_argument argument )
344 rtems_task link_task( rtems_task_argument argument )
345 {
345 {
346 rtems_event_set event_out;
346 rtems_event_set event_out;
347 rtems_status_code status;
347 rtems_status_code status;
348 int linkStatus;
348 int linkStatus;
349
349
350 event_out = EVENT_SETS_NONE_PENDING;
350 event_out = EVENT_SETS_NONE_PENDING;
351 linkStatus = 0;
351 linkStatus = 0;
352
352
353 BOOT_PRINTF("in LINK ***\n")
353 BOOT_PRINTF("in LINK ***\n")
354
354
355 while(1)
355 while(1)
356 {
356 {
357 // wait for an RTEMS_EVENT
357 // wait for an RTEMS_EVENT
358 rtems_event_receive( RTEMS_EVENT_0,
358 rtems_event_receive( RTEMS_EVENT_0,
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
360 PRINTF("in LINK *** wait for the link\n")
360 PRINTF("in LINK *** wait for the link\n")
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
362 while( linkStatus != SPW_LINK_OK) // wait for the link
362 while( linkStatus != SPW_LINK_OK) // wait for the link
363 {
363 {
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
366 watchdog_reload();
366 watchdog_reload();
367 }
367 }
368
368
369 spacewire_read_statistics();
369 spacewire_read_statistics();
370 status = spacewire_stop_and_start_link( fdSPW );
370 status = spacewire_stop_and_start_link( fdSPW );
371
371
372 if (status != RTEMS_SUCCESSFUL)
372 if (status != RTEMS_SUCCESSFUL)
373 {
373 {
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
375 }
375 }
376 else
376 else
377 {
377 {
378 PRINTF("in LINK *** OK link started\n")
378 PRINTF("in LINK *** OK link started\n")
379 }
379 }
380
380
381 // restart the SPIQ task
381 // restart the SPIQ task
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
383 if ( status != RTEMS_SUCCESSFUL ) {
383 if ( status != RTEMS_SUCCESSFUL ) {
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
385 }
385 }
386
386
387 // restart RECV and SEND
387 // restart RECV and SEND
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
389 if ( status != RTEMS_SUCCESSFUL ) {
389 if ( status != RTEMS_SUCCESSFUL ) {
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
391 }
391 }
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
393 if ( status != RTEMS_SUCCESSFUL ) {
393 if ( status != RTEMS_SUCCESSFUL ) {
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
395 }
395 }
396 }
396 }
397 }
397 }
398
398
399 //****************
399 //****************
400 // OTHER FUNCTIONS
400 // OTHER FUNCTIONS
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
402 {
402 {
403 /** This function opens the SpaceWire link.
403 /** This function opens the SpaceWire link.
404 *
404 *
405 * @return a valid file descriptor in case of success, -1 in case of a failure
405 * @return a valid file descriptor in case of success, -1 in case of a failure
406 *
406 *
407 */
407 */
408 rtems_status_code status;
408 rtems_status_code status;
409
409
410 status = RTEMS_SUCCESSFUL;
410 status = RTEMS_SUCCESSFUL;
411
411
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
413 if ( fdSPW < 0 ) {
413 if ( fdSPW < 0 ) {
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
415 }
415 }
416 else
416 else
417 {
417 {
418 status = RTEMS_SUCCESSFUL;
418 status = RTEMS_SUCCESSFUL;
419 }
419 }
420
420
421 return status;
421 return status;
422 }
422 }
423
423
424 int spacewire_start_link( int fd )
424 int spacewire_start_link( int fd )
425 {
425 {
426 rtems_status_code status;
426 rtems_status_code status;
427
427
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
429 // -1 default hardcoded driver timeout
429 // -1 default hardcoded driver timeout
430
430
431 return status;
431 return status;
432 }
432 }
433
433
434 int spacewire_stop_and_start_link( int fd )
434 int spacewire_stop_and_start_link( int fd )
435 {
435 {
436 rtems_status_code status;
436 rtems_status_code status;
437
437
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
440 // -1 default hardcoded driver timeout
440 // -1 default hardcoded driver timeout
441
441
442 return status;
442 return status;
443 }
443 }
444
444
445 int spacewire_configure_link( int fd )
445 int spacewire_configure_link( int fd )
446 {
446 {
447 /** This function configures the SpaceWire link.
447 /** This function configures the SpaceWire link.
448 *
448 *
449 * @return GR-RTEMS-DRIVER directive status codes:
449 * @return GR-RTEMS-DRIVER directive status codes:
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
455 * - 5 EIO - Error when writing to grswp hardware registers.
456 * - 2 ENOENT - No such file or directory
456 * - 2 ENOENT - No such file or directory
457 */
457 */
458
458
459 rtems_status_code status;
459 rtems_status_code status;
460
460
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
463 spw_ioctl_packetsize packetsize;
463 spw_ioctl_packetsize packetsize;
464
464
465 packetsize.rxsize = SPW_RXSIZE;
465 packetsize.rxsize = SPW_RXSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
468
468
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
470 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
472 }
472 }
473 //
473 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
475 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
477 }
477 }
478 //
478 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
480 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
482 }
482 }
483 //
483 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
485 if (status!=RTEMS_SUCCESSFUL) {
485 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
487 }
487 }
488 //
488 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
490 if (status!=RTEMS_SUCCESSFUL) {
490 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
492 }
492 }
493 //
493 //
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
495 if (status!=RTEMS_SUCCESSFUL) {
495 if (status!=RTEMS_SUCCESSFUL) {
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
497 }
497 }
498 //
498 //
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
500 if (status!=RTEMS_SUCCESSFUL) {
500 if (status!=RTEMS_SUCCESSFUL) {
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
502 }
502 }
503 //
503 //
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
505 if (status!=RTEMS_SUCCESSFUL) {
505 if (status!=RTEMS_SUCCESSFUL) {
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
507 }
507 }
508
508
509 return status;
509 return status;
510 }
510 }
511
511
512 int spacewire_several_connect_attemps( void )
512 int spacewire_several_connect_attemps( void )
513 {
513 {
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
515 *
515 *
516 * @return RTEMS directive status code:
516 * @return RTEMS directive status code:
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
519 *
519 *
520 */
520 */
521
521
522 rtems_status_code status_spw;
522 rtems_status_code status_spw;
523 rtems_status_code status;
523 rtems_status_code status;
524 int i;
524 int i;
525
525
526 status_spw = RTEMS_SUCCESSFUL;
526 status_spw = RTEMS_SUCCESSFUL;
527
527
528 i = 0;
528 i = 0;
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
530 {
530 {
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
532
532
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
534
534
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
536
536
537 status_spw = spacewire_stop_and_start_link( fdSPW );
537 status_spw = spacewire_stop_and_start_link( fdSPW );
538
538
539 if ( status_spw != RTEMS_SUCCESSFUL )
539 if ( status_spw != RTEMS_SUCCESSFUL )
540 {
540 {
541 i = i + 1;
541 i = i + 1;
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
543 }
543 }
544 else
544 else
545 {
545 {
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
547 }
547 }
548 }
548 }
549
549
550 return status_spw;
550 return status_spw;
551 }
551 }
552
552
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
554 {
554 {
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
556 *
556 *
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
558 * @param regAddr is the address of the GRSPW control register.
558 * @param regAddr is the address of the GRSPW control register.
559 *
559 *
560 * NP is the bit 20 of the GRSPW control register.
560 * NP is the bit 20 of the GRSPW control register.
561 *
561 *
562 */
562 */
563
563
564 unsigned int *spwptr = (unsigned int*) regAddr;
564 unsigned int *spwptr = (unsigned int*) regAddr;
565
565
566 if (val == 1) {
566 if (val == 1) {
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
568 }
568 }
569 if (val== 0) {
569 if (val== 0) {
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
571 }
571 }
572 }
572 }
573
573
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
575 {
575 {
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
577 *
577 *
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
579 * @param regAddr is the address of the GRSPW control register.
579 * @param regAddr is the address of the GRSPW control register.
580 *
580 *
581 * RE is the bit 16 of the GRSPW control register.
581 * RE is the bit 16 of the GRSPW control register.
582 *
582 *
583 */
583 */
584
584
585 unsigned int *spwptr = (unsigned int*) regAddr;
585 unsigned int *spwptr = (unsigned int*) regAddr;
586
586
587 if (val == 1)
587 if (val == 1)
588 {
588 {
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
590 }
590 }
591 if (val== 0)
591 if (val== 0)
592 {
592 {
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
594 }
594 }
595 }
595 }
596
596
597 void spacewire_read_statistics( void )
597 void spacewire_read_statistics( void )
598 {
598 {
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
600 *
600 *
601 * @param void
601 * @param void
602 *
602 *
603 * @return void
603 * @return void
604 *
604 *
605 * Once they are read, the counters are stored in a global variable used during the building of the
605 * Once they are read, the counters are stored in a global variable used during the building of the
606 * HK packets.
606 * HK packets.
607 *
607 *
608 */
608 */
609
609
610 rtems_status_code status;
610 rtems_status_code status;
611 spw_stats current;
611 spw_stats current;
612
612
613 memset(&current, 0, sizeof(spw_stats));
613 memset(&current, 0, sizeof(spw_stats));
614
614
615 spacewire_get_last_error();
615 spacewire_get_last_error();
616
616
617 // read the current statistics
617 // read the current statistics
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
619
619
620 // clear the counters
620 // clear the counters
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
622
622
623 // typedef struct {
623 // typedef struct {
624 // unsigned int tx_link_err; // NOT IN HK
624 // unsigned int tx_link_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
627 // unsigned int rx_eep_err;
627 // unsigned int rx_eep_err;
628 // unsigned int rx_truncated;
628 // unsigned int rx_truncated;
629 // unsigned int parity_err;
629 // unsigned int parity_err;
630 // unsigned int escape_err;
630 // unsigned int escape_err;
631 // unsigned int credit_err;
631 // unsigned int credit_err;
632 // unsigned int write_sync_err;
632 // unsigned int write_sync_err;
633 // unsigned int disconnect_err;
633 // unsigned int disconnect_err;
634 // unsigned int early_ep;
634 // unsigned int early_ep;
635 // unsigned int invalid_address;
635 // unsigned int invalid_address;
636 // unsigned int packets_sent;
636 // unsigned int packets_sent;
637 // unsigned int packets_received;
637 // unsigned int packets_received;
638 // } spw_stats;
638 // } spw_stats;
639
639
640 // rx_eep_err
640 // rx_eep_err
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
642 // rx_truncated
642 // rx_truncated
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
644 // parity_err
644 // parity_err
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
646 // escape_err
646 // escape_err
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
648 // credit_err
648 // credit_err
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
650 // write_sync_err
650 // write_sync_err
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
652 // disconnect_err
652 // disconnect_err
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
654 // early_ep
654 // early_ep
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
656 // invalid_address
656 // invalid_address
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
658 // packets_sent
658 // packets_sent
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
660 // packets_received
660 // packets_received
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
662
662
663 }
663 }
664
664
665 void spacewire_get_last_error( void )
665 void spacewire_get_last_error( void )
666 {
666 {
667 static spw_stats previous = {0};
667 static spw_stats previous = {0};
668 spw_stats current;
668 spw_stats current;
669 rtems_status_code status;
669 rtems_status_code status;
670
670
671 unsigned int hk_lfr_last_er_rid;
671 unsigned int hk_lfr_last_er_rid;
672 unsigned char hk_lfr_last_er_code;
672 unsigned char hk_lfr_last_er_code;
673 int coarseTime;
673 int coarseTime;
674 int fineTime;
674 int fineTime;
675 unsigned char update_hk_lfr_last_er;
675 unsigned char update_hk_lfr_last_er;
676
676
677 memset(&current, 0, sizeof(spw_stats));
677 memset(&current, 0, sizeof(spw_stats));
678 update_hk_lfr_last_er = 0;
678 hk_lfr_last_er_rid = INIT_CHAR;
679 hk_lfr_last_er_code = INIT_CHAR;
680 update_hk_lfr_last_er = INIT_CHAR;
679
681
680 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
682 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
681
683
682 // get current time
684 // get current time
683 coarseTime = time_management_regs->coarse_time;
685 coarseTime = time_management_regs->coarse_time;
684 fineTime = time_management_regs->fine_time;
686 fineTime = time_management_regs->fine_time;
685
687
686 // typedef struct {
688 // typedef struct {
687 // unsigned int tx_link_err; // NOT IN HK
689 // unsigned int tx_link_err; // NOT IN HK
688 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
690 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
689 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
691 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
690 // unsigned int rx_eep_err;
692 // unsigned int rx_eep_err;
691 // unsigned int rx_truncated;
693 // unsigned int rx_truncated;
692 // unsigned int parity_err;
694 // unsigned int parity_err;
693 // unsigned int escape_err;
695 // unsigned int escape_err;
694 // unsigned int credit_err;
696 // unsigned int credit_err;
695 // unsigned int write_sync_err;
697 // unsigned int write_sync_err;
696 // unsigned int disconnect_err;
698 // unsigned int disconnect_err;
697 // unsigned int early_ep;
699 // unsigned int early_ep;
698 // unsigned int invalid_address;
700 // unsigned int invalid_address;
699 // unsigned int packets_sent;
701 // unsigned int packets_sent;
700 // unsigned int packets_received;
702 // unsigned int packets_received;
701 // } spw_stats;
703 // } spw_stats;
702
704
703 // tx_link_err *** no code associated to this field
705 // tx_link_err *** no code associated to this field
704 // rx_rmap_header_crc_err *** LE *** in HK
706 // rx_rmap_header_crc_err *** LE *** in HK
705 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
707 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
706 {
708 {
707 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
709 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
708 hk_lfr_last_er_code = CODE_HEADER_CRC;
710 hk_lfr_last_er_code = CODE_HEADER_CRC;
709 update_hk_lfr_last_er = 1;
711 update_hk_lfr_last_er = 1;
710 }
712 }
711 // rx_rmap_data_crc_err *** LE *** NOT IN HK
713 // rx_rmap_data_crc_err *** LE *** NOT IN HK
712 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
714 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
713 {
715 {
714 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
716 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
715 hk_lfr_last_er_code = CODE_DATA_CRC;
717 hk_lfr_last_er_code = CODE_DATA_CRC;
716 update_hk_lfr_last_er = 1;
718 update_hk_lfr_last_er = 1;
717 }
719 }
718 // rx_eep_err
720 // rx_eep_err
719 if (previous.rx_eep_err != current.rx_eep_err)
721 if (previous.rx_eep_err != current.rx_eep_err)
720 {
722 {
721 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
723 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
722 hk_lfr_last_er_code = CODE_EEP;
724 hk_lfr_last_er_code = CODE_EEP;
723 update_hk_lfr_last_er = 1;
725 update_hk_lfr_last_er = 1;
724 }
726 }
725 // rx_truncated
727 // rx_truncated
726 if (previous.rx_truncated != current.rx_truncated)
728 if (previous.rx_truncated != current.rx_truncated)
727 {
729 {
728 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
730 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
729 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
731 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
730 update_hk_lfr_last_er = 1;
732 update_hk_lfr_last_er = 1;
731 }
733 }
732 // parity_err
734 // parity_err
733 if (previous.parity_err != current.parity_err)
735 if (previous.parity_err != current.parity_err)
734 {
736 {
735 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
737 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
736 hk_lfr_last_er_code = CODE_PARITY;
738 hk_lfr_last_er_code = CODE_PARITY;
737 update_hk_lfr_last_er = 1;
739 update_hk_lfr_last_er = 1;
738 }
740 }
739 // escape_err
741 // escape_err
740 if (previous.parity_err != current.parity_err)
742 if (previous.parity_err != current.parity_err)
741 {
743 {
742 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
744 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
743 hk_lfr_last_er_code = CODE_ESCAPE;
745 hk_lfr_last_er_code = CODE_ESCAPE;
744 update_hk_lfr_last_er = 1;
746 update_hk_lfr_last_er = 1;
745 }
747 }
746 // credit_err
748 // credit_err
747 if (previous.credit_err != current.credit_err)
749 if (previous.credit_err != current.credit_err)
748 {
750 {
749 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
751 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
750 hk_lfr_last_er_code = CODE_CREDIT;
752 hk_lfr_last_er_code = CODE_CREDIT;
751 update_hk_lfr_last_er = 1;
753 update_hk_lfr_last_er = 1;
752 }
754 }
753 // write_sync_err
755 // write_sync_err
754 if (previous.write_sync_err != current.write_sync_err)
756 if (previous.write_sync_err != current.write_sync_err)
755 {
757 {
756 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
758 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
757 hk_lfr_last_er_code = CODE_WRITE_SYNC;
759 hk_lfr_last_er_code = CODE_WRITE_SYNC;
758 update_hk_lfr_last_er = 1;
760 update_hk_lfr_last_er = 1;
759 }
761 }
760 // disconnect_err
762 // disconnect_err
761 if (previous.disconnect_err != current.disconnect_err)
763 if (previous.disconnect_err != current.disconnect_err)
762 {
764 {
763 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
765 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
764 hk_lfr_last_er_code = CODE_DISCONNECT;
766 hk_lfr_last_er_code = CODE_DISCONNECT;
765 update_hk_lfr_last_er = 1;
767 update_hk_lfr_last_er = 1;
766 }
768 }
767 // early_ep
769 // early_ep
768 if (previous.early_ep != current.early_ep)
770 if (previous.early_ep != current.early_ep)
769 {
771 {
770 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
772 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
771 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
773 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
772 update_hk_lfr_last_er = 1;
774 update_hk_lfr_last_er = 1;
773 }
775 }
774 // invalid_address
776 // invalid_address
775 if (previous.invalid_address != current.invalid_address)
777 if (previous.invalid_address != current.invalid_address)
776 {
778 {
777 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
779 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
778 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
780 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
779 update_hk_lfr_last_er = 1;
781 update_hk_lfr_last_er = 1;
780 }
782 }
781
783
782 // if a field has changed, update the hk_last_er fields
784 // if a field has changed, update the hk_last_er fields
783 if (update_hk_lfr_last_er == 1)
785 if (update_hk_lfr_last_er == 1)
784 {
786 {
785 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
787 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
786 }
788 }
787
789
788 previous = current;
790 previous = current;
789 }
791 }
790
792
791 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
793 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
792 {
794 {
793 unsigned char *coarseTimePtr;
795 unsigned char *coarseTimePtr;
794 unsigned char *fineTimePtr;
796 unsigned char *fineTimePtr;
795
797
796 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
798 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
797 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
799 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
798
800
799 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
801 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
800 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
802 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
801 housekeeping_packet.hk_lfr_last_er_code = code;
803 housekeeping_packet.hk_lfr_last_er_code = code;
802 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
804 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
803 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
805 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
804 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
805 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
806 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
808 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
807 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
809 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
808 }
810 }
809
811
810 void update_hk_with_grspw_stats( void )
812 void update_hk_with_grspw_stats( void )
811 {
813 {
812 //****************************
814 //****************************
813 // DPU_SPACEWIRE_IF_STATISTICS
815 // DPU_SPACEWIRE_IF_STATISTICS
814 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
815 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
816 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
818 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
817 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
819 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
818
820
819 //******************************************
821 //******************************************
820 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
822 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
821 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
823 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
822 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
824 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
823 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
825 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
824 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
826 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
825 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
827 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
826
828
827 //*********************************************
829 //*********************************************
828 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
830 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
829 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
831 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
830 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
832 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
831 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
833 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
832 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
834 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
833 }
835 }
834
836
835 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
837 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
836 {
838 {
837 unsigned int *statusRegisterPtr;
839 unsigned int *statusRegisterPtr;
838 unsigned char linkState;
840 unsigned char linkState;
839
841
840 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
842 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
841 linkState =
843 linkState =
842 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
844 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
843
845
844 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
845
847
846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
848 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
847 }
849 }
848
850
849 void increase_unsigned_char_counter( unsigned char *counter )
851 void increase_unsigned_char_counter( unsigned char *counter )
850 {
852 {
851 // update the number of valid timecodes that have been received
853 // update the number of valid timecodes that have been received
852 if (*counter == UINT8_MAX)
854 if (*counter == UINT8_MAX)
853 {
855 {
854 *counter = 0;
856 *counter = 0;
855 }
857 }
856 else
858 else
857 {
859 {
858 *counter = *counter + 1;
860 *counter = *counter + 1;
859 }
861 }
860 }
862 }
861
863
862 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
864 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
863 {
865 {
864 /** This function checks the coherency between the incoming timecode and the last valid timecode.
866 /** This function checks the coherency between the incoming timecode and the last valid timecode.
865 *
867 *
866 * @param currentTimecodeCtr is the incoming timecode
868 * @param currentTimecodeCtr is the incoming timecode
867 *
869 *
868 * @return returned codes::
870 * @return returned codes::
869 * - LFR_DEFAULT
871 * - LFR_DEFAULT
870 * - LFR_SUCCESSFUL
872 * - LFR_SUCCESSFUL
871 *
873 *
872 */
874 */
873
875
874 static unsigned char firstTickout = 1;
876 static unsigned char firstTickout = 1;
875 unsigned char ret;
877 unsigned char ret;
876
878
877 ret = LFR_DEFAULT;
879 ret = LFR_DEFAULT;
878
880
879 if (firstTickout == 0)
881 if (firstTickout == 0)
880 {
882 {
881 if (currentTimecodeCtr == 0)
883 if (currentTimecodeCtr == 0)
882 {
884 {
883 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
885 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
884 {
886 {
885 ret = LFR_SUCCESSFUL;
887 ret = LFR_SUCCESSFUL;
886 }
888 }
887 else
889 else
888 {
890 {
889 ret = LFR_DEFAULT;
891 ret = LFR_DEFAULT;
890 }
892 }
891 }
893 }
892 else
894 else
893 {
895 {
894 if (currentTimecodeCtr == (previousTimecodeCtr +1))
896 if (currentTimecodeCtr == (previousTimecodeCtr +1))
895 {
897 {
896 ret = LFR_SUCCESSFUL;
898 ret = LFR_SUCCESSFUL;
897 }
899 }
898 else
900 else
899 {
901 {
900 ret = LFR_DEFAULT;
902 ret = LFR_DEFAULT;
901 }
903 }
902 }
904 }
903 }
905 }
904 else
906 else
905 {
907 {
906 firstTickout = 0;
908 firstTickout = 0;
907 ret = LFR_SUCCESSFUL;
909 ret = LFR_SUCCESSFUL;
908 }
910 }
909
911
910 return ret;
912 return ret;
911 }
913 }
912
914
913 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
915 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
914 {
916 {
915 unsigned int ret;
917 unsigned int ret;
916
918
917 ret = LFR_DEFAULT;
919 ret = LFR_DEFAULT;
918
920
919 if (timecode == internalTime)
921 if (timecode == internalTime)
920 {
922 {
921 ret = LFR_SUCCESSFUL;
923 ret = LFR_SUCCESSFUL;
922 }
924 }
923 else
925 else
924 {
926 {
925 ret = LFR_DEFAULT;
927 ret = LFR_DEFAULT;
926 }
928 }
927
929
928 return ret;
930 return ret;
929 }
931 }
930
932
931 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
933 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
932 {
934 {
933 // a tickout has been emitted, perform actions on the incoming timecode
935 // a tickout has been emitted, perform actions on the incoming timecode
934
936
935 unsigned char incomingTimecode;
937 unsigned char incomingTimecode;
936 unsigned char updateTime;
938 unsigned char updateTime;
937 unsigned char internalTime;
939 unsigned char internalTime;
938 rtems_status_code status;
940 rtems_status_code status;
939
941
940 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
942 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
941 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
943 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
942 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
944 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
943
945
944 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
946 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
945
947
946 // update the number of tickout that have been generated
948 // update the number of tickout that have been generated
947 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
949 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
948
950
949 //**************************
951 //**************************
950 // HK_LFR_TIMECODE_ERRONEOUS
952 // HK_LFR_TIMECODE_ERRONEOUS
951 // MISSING and INVALID are handled by the timecode_timer_routine service routine
953 // MISSING and INVALID are handled by the timecode_timer_routine service routine
952 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
954 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
953 {
955 {
954 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
956 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
955 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
957 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
956 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
957 }
959 }
958
960
959 //************************
961 //************************
960 // HK_LFR_TIME_TIMECODE_IT
962 // HK_LFR_TIME_TIMECODE_IT
961 // check the coherency between the SpaceWire timecode and the Internal Time
963 // check the coherency between the SpaceWire timecode and the Internal Time
962 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
964 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
963 {
965 {
964 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
966 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
965 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
967 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
966 }
968 }
967
969
968 //********************
970 //********************
969 // HK_LFR_TIMECODE_CTR
971 // HK_LFR_TIMECODE_CTR
970 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
972 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
971 if (oneTcLfrUpdateTimeReceived == 1)
973 if (oneTcLfrUpdateTimeReceived == 1)
972 {
974 {
973 if ( incomingTimecode != updateTime )
975 if ( incomingTimecode != updateTime )
974 {
976 {
975 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
977 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
976 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
978 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
977 }
979 }
978 }
980 }
979
981
980 // launch the timecode timer to detect missing or invalid timecodes
982 // launch the timecode timer to detect missing or invalid timecodes
981 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
983 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
982 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
984 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
983 if (status != RTEMS_SUCCESSFUL)
985 if (status != RTEMS_SUCCESSFUL)
984 {
986 {
985 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
987 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
986 }
988 }
987 }
989 }
988
990
989 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
991 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
990 {
992 {
991 static unsigned char initStep = 1;
993 static unsigned char initStep = 1;
992
994
993 unsigned char currentTimecodeCtr;
995 unsigned char currentTimecodeCtr;
994
996
995 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
997 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
996
998
997 if (initStep == 1)
999 if (initStep == 1)
998 {
1000 {
999 if (currentTimecodeCtr == previousTimecodeCtr)
1001 if (currentTimecodeCtr == previousTimecodeCtr)
1000 {
1002 {
1001 //************************
1003 //************************
1002 // HK_LFR_TIMECODE_MISSING
1004 // HK_LFR_TIMECODE_MISSING
1003 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1005 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1004 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1005 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1006 }
1008 }
1007 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1009 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1008 {
1010 {
1009 // the timecode value has changed and the value is valid, this is unexpected because
1011 // the timecode value has changed and the value is valid, this is unexpected because
1010 // the timer should not have fired, the timecode_irq_handler should have been raised
1012 // the timer should not have fired, the timecode_irq_handler should have been raised
1011 }
1013 }
1012 else
1014 else
1013 {
1015 {
1014 //************************
1016 //************************
1015 // HK_LFR_TIMECODE_INVALID
1017 // HK_LFR_TIMECODE_INVALID
1016 // the timecode value has changed and the value is not valid, no tickout has been generated
1018 // the timecode value has changed and the value is not valid, no tickout has been generated
1017 // this is why the timer has fired
1019 // this is why the timer has fired
1018 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1020 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1019 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1021 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1020 }
1022 }
1021 }
1023 }
1022 else
1024 else
1023 {
1025 {
1024 initStep = 1;
1026 initStep = 1;
1025 //************************
1027 //************************
1026 // HK_LFR_TIMECODE_MISSING
1028 // HK_LFR_TIMECODE_MISSING
1027 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1029 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1028 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1030 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1029 }
1031 }
1030
1032
1031 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1033 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1032 }
1034 }
1033
1035
1034 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1036 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1035 {
1037 {
1036 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1038 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1037 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1039 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1038 header->reserved = DEFAULT_RESERVED;
1040 header->reserved = DEFAULT_RESERVED;
1039 header->userApplication = CCSDS_USER_APP;
1041 header->userApplication = CCSDS_USER_APP;
1040 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1042 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1041 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1043 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1042 header->packetLength[0] = INIT_CHAR;
1044 header->packetLength[0] = INIT_CHAR;
1043 header->packetLength[1] = INIT_CHAR;
1045 header->packetLength[1] = INIT_CHAR;
1044 // DATA FIELD HEADER
1046 // DATA FIELD HEADER
1045 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1047 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1046 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1048 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1047 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1049 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1048 header->destinationID = TM_DESTINATION_ID_GROUND;
1050 header->destinationID = TM_DESTINATION_ID_GROUND;
1049 header->time[BYTE_0] = INIT_CHAR;
1051 header->time[BYTE_0] = INIT_CHAR;
1050 header->time[BYTE_1] = INIT_CHAR;
1052 header->time[BYTE_1] = INIT_CHAR;
1051 header->time[BYTE_2] = INIT_CHAR;
1053 header->time[BYTE_2] = INIT_CHAR;
1052 header->time[BYTE_3] = INIT_CHAR;
1054 header->time[BYTE_3] = INIT_CHAR;
1053 header->time[BYTE_4] = INIT_CHAR;
1055 header->time[BYTE_4] = INIT_CHAR;
1054 header->time[BYTE_5] = INIT_CHAR;
1056 header->time[BYTE_5] = INIT_CHAR;
1055 // AUXILIARY DATA HEADER
1057 // AUXILIARY DATA HEADER
1056 header->sid = INIT_CHAR;
1058 header->sid = INIT_CHAR;
1057 header->pa_bia_status_info = DEFAULT_HKBIA;
1059 header->pa_bia_status_info = DEFAULT_HKBIA;
1058 header->blkNr[0] = INIT_CHAR;
1060 header->blkNr[0] = INIT_CHAR;
1059 header->blkNr[1] = INIT_CHAR;
1061 header->blkNr[1] = INIT_CHAR;
1060 }
1062 }
1061
1063
1062 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1064 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1063 {
1065 {
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1066 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1067 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1066 header->reserved = DEFAULT_RESERVED;
1068 header->reserved = DEFAULT_RESERVED;
1067 header->userApplication = CCSDS_USER_APP;
1069 header->userApplication = CCSDS_USER_APP;
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1070 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1071 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1072 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1073 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1072 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1074 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1073 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1075 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1074 // DATA FIELD HEADER
1076 // DATA FIELD HEADER
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1077 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1078 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1079 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1080 header->destinationID = TM_DESTINATION_ID_GROUND;
1079 header->time[BYTE_0] = INIT_CHAR;
1081 header->time[BYTE_0] = INIT_CHAR;
1080 header->time[BYTE_1] = INIT_CHAR;
1082 header->time[BYTE_1] = INIT_CHAR;
1081 header->time[BYTE_2] = INIT_CHAR;
1083 header->time[BYTE_2] = INIT_CHAR;
1082 header->time[BYTE_3] = INIT_CHAR;
1084 header->time[BYTE_3] = INIT_CHAR;
1083 header->time[BYTE_4] = INIT_CHAR;
1085 header->time[BYTE_4] = INIT_CHAR;
1084 header->time[BYTE_5] = INIT_CHAR;
1086 header->time[BYTE_5] = INIT_CHAR;
1085 // AUXILIARY DATA HEADER
1087 // AUXILIARY DATA HEADER
1086 header->sid = INIT_CHAR;
1088 header->sid = INIT_CHAR;
1087 header->pa_bia_status_info = DEFAULT_HKBIA;
1089 header->pa_bia_status_info = DEFAULT_HKBIA;
1088 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1090 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1089 header->pktNr = INIT_CHAR;
1091 header->pktNr = INIT_CHAR;
1090 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1092 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1091 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1093 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1092 }
1094 }
1093
1095
1094 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1096 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1095 {
1097 {
1096 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1098 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1097 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1099 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1098 header->reserved = DEFAULT_RESERVED;
1100 header->reserved = DEFAULT_RESERVED;
1099 header->userApplication = CCSDS_USER_APP;
1101 header->userApplication = CCSDS_USER_APP;
1100 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1102 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1101 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1103 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1102 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1104 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1103 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1105 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1104 header->packetLength[0] = INIT_CHAR;
1106 header->packetLength[0] = INIT_CHAR;
1105 header->packetLength[1] = INIT_CHAR;
1107 header->packetLength[1] = INIT_CHAR;
1106 // DATA FIELD HEADER
1108 // DATA FIELD HEADER
1107 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1109 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1108 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1110 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1109 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1111 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1110 header->destinationID = TM_DESTINATION_ID_GROUND;
1112 header->destinationID = TM_DESTINATION_ID_GROUND;
1111 header->time[BYTE_0] = INIT_CHAR;
1113 header->time[BYTE_0] = INIT_CHAR;
1112 header->time[BYTE_1] = INIT_CHAR;
1114 header->time[BYTE_1] = INIT_CHAR;
1113 header->time[BYTE_2] = INIT_CHAR;
1115 header->time[BYTE_2] = INIT_CHAR;
1114 header->time[BYTE_3] = INIT_CHAR;
1116 header->time[BYTE_3] = INIT_CHAR;
1115 header->time[BYTE_4] = INIT_CHAR;
1117 header->time[BYTE_4] = INIT_CHAR;
1116 header->time[BYTE_5] = INIT_CHAR;
1118 header->time[BYTE_5] = INIT_CHAR;
1117 // AUXILIARY DATA HEADER
1119 // AUXILIARY DATA HEADER
1118 header->sid = INIT_CHAR;
1120 header->sid = INIT_CHAR;
1119 header->pa_bia_status_info = INIT_CHAR;
1121 header->pa_bia_status_info = INIT_CHAR;
1120 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1122 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1121 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1123 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1122 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1124 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1123 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1125 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1124 }
1126 }
1125
1127
1126 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1128 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1127 Header_TM_LFR_SCIENCE_CWF_t *header )
1129 Header_TM_LFR_SCIENCE_CWF_t *header )
1128 {
1130 {
1129 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1131 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1130 *
1132 *
1131 * @param waveform points to the buffer containing the data that will be send.
1133 * @param waveform points to the buffer containing the data that will be send.
1132 * @param sid is the source identifier of the data that will be sent.
1134 * @param sid is the source identifier of the data that will be sent.
1133 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1135 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1134 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1136 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1135 * contain information to setup the transmission of the data packets.
1137 * contain information to setup the transmission of the data packets.
1136 *
1138 *
1137 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1139 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1138 *
1140 *
1139 */
1141 */
1140
1142
1141 unsigned int i;
1143 unsigned int i;
1142 int ret;
1144 int ret;
1143 unsigned int coarseTime;
1145 unsigned int coarseTime;
1144 unsigned int fineTime;
1146 unsigned int fineTime;
1145 rtems_status_code status;
1147 rtems_status_code status;
1146 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1148 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1147 int *dataPtr;
1149 int *dataPtr;
1148 unsigned char sid;
1150 unsigned char sid;
1149
1151
1150 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1152 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1151 spw_ioctl_send_CWF.options = 0;
1153 spw_ioctl_send_CWF.options = 0;
1152
1154
1153 ret = LFR_DEFAULT;
1155 ret = LFR_DEFAULT;
1154 sid = (unsigned char) ring_node_to_send->sid;
1156 sid = (unsigned char) ring_node_to_send->sid;
1155
1157
1156 coarseTime = ring_node_to_send->coarseTime;
1158 coarseTime = ring_node_to_send->coarseTime;
1157 fineTime = ring_node_to_send->fineTime;
1159 fineTime = ring_node_to_send->fineTime;
1158 dataPtr = (int*) ring_node_to_send->buffer_address;
1160 dataPtr = (int*) ring_node_to_send->buffer_address;
1159
1161
1160 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1162 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1161 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1163 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1162 header->pa_bia_status_info = pa_bia_status_info;
1164 header->pa_bia_status_info = pa_bia_status_info;
1163 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1165 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1164 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1166 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1165 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1167 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1166
1168
1167 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1169 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1168 {
1170 {
1169 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1171 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1170 spw_ioctl_send_CWF.hdr = (char*) header;
1172 spw_ioctl_send_CWF.hdr = (char*) header;
1171 // BUILD THE DATA
1173 // BUILD THE DATA
1172 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1174 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1173
1175
1174 // SET PACKET SEQUENCE CONTROL
1176 // SET PACKET SEQUENCE CONTROL
1175 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1177 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1176
1178
1177 // SET SID
1179 // SET SID
1178 header->sid = sid;
1180 header->sid = sid;
1179
1181
1180 // SET PACKET TIME
1182 // SET PACKET TIME
1181 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1183 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1182 //
1184 //
1183 header->time[0] = header->acquisitionTime[0];
1185 header->time[0] = header->acquisitionTime[0];
1184 header->time[1] = header->acquisitionTime[1];
1186 header->time[1] = header->acquisitionTime[1];
1185 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1187 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1186 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1188 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1187 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1189 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1188 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1190 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1189
1191
1190 // SET PACKET ID
1192 // SET PACKET ID
1191 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1193 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1192 {
1194 {
1193 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1195 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1194 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1196 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1195 }
1197 }
1196 else
1198 else
1197 {
1199 {
1198 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1200 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1199 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1201 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1200 }
1202 }
1201
1203
1202 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1204 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1203 if (status != RTEMS_SUCCESSFUL) {
1205 if (status != RTEMS_SUCCESSFUL) {
1204 ret = LFR_DEFAULT;
1206 ret = LFR_DEFAULT;
1205 }
1207 }
1206 }
1208 }
1207
1209
1208 return ret;
1210 return ret;
1209 }
1211 }
1210
1212
1211 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1213 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1212 Header_TM_LFR_SCIENCE_SWF_t *header )
1214 Header_TM_LFR_SCIENCE_SWF_t *header )
1213 {
1215 {
1214 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1216 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1215 *
1217 *
1216 * @param waveform points to the buffer containing the data that will be send.
1218 * @param waveform points to the buffer containing the data that will be send.
1217 * @param sid is the source identifier of the data that will be sent.
1219 * @param sid is the source identifier of the data that will be sent.
1218 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1220 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1219 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1221 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1220 * contain information to setup the transmission of the data packets.
1222 * contain information to setup the transmission of the data packets.
1221 *
1223 *
1222 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1224 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1223 *
1225 *
1224 */
1226 */
1225
1227
1226 unsigned int i;
1228 unsigned int i;
1227 int ret;
1229 int ret;
1228 unsigned int coarseTime;
1230 unsigned int coarseTime;
1229 unsigned int fineTime;
1231 unsigned int fineTime;
1230 rtems_status_code status;
1232 rtems_status_code status;
1231 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1233 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1232 int *dataPtr;
1234 int *dataPtr;
1233 unsigned char sid;
1235 unsigned char sid;
1234
1236
1235 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1237 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1236 spw_ioctl_send_SWF.options = 0;
1238 spw_ioctl_send_SWF.options = 0;
1237
1239
1238 ret = LFR_DEFAULT;
1240 ret = LFR_DEFAULT;
1239
1241
1240 coarseTime = ring_node_to_send->coarseTime;
1242 coarseTime = ring_node_to_send->coarseTime;
1241 fineTime = ring_node_to_send->fineTime;
1243 fineTime = ring_node_to_send->fineTime;
1242 dataPtr = (int*) ring_node_to_send->buffer_address;
1244 dataPtr = (int*) ring_node_to_send->buffer_address;
1243 sid = ring_node_to_send->sid;
1245 sid = ring_node_to_send->sid;
1244
1246
1245 header->pa_bia_status_info = pa_bia_status_info;
1247 header->pa_bia_status_info = pa_bia_status_info;
1246 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1248 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1247
1249
1248 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1250 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1249 {
1251 {
1250 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1252 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1251 spw_ioctl_send_SWF.hdr = (char*) header;
1253 spw_ioctl_send_SWF.hdr = (char*) header;
1252
1254
1253 // SET PACKET SEQUENCE CONTROL
1255 // SET PACKET SEQUENCE CONTROL
1254 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1256 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1255
1257
1256 // SET PACKET LENGTH AND BLKNR
1258 // SET PACKET LENGTH AND BLKNR
1257 if (i == (PKTCNT_SWF-1))
1259 if (i == (PKTCNT_SWF-1))
1258 {
1260 {
1259 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1261 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1260 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1262 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1261 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1263 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1262 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1264 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1263 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1265 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1264 }
1266 }
1265 else
1267 else
1266 {
1268 {
1267 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1269 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1268 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1270 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1269 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1271 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1270 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1272 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1271 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1273 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1272 }
1274 }
1273
1275
1274 // SET PACKET TIME
1276 // SET PACKET TIME
1275 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1277 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1276 //
1278 //
1277 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1279 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1278 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1280 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1279 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1281 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1280 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1282 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1281 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1283 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1282 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1284 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1283
1285
1284 // SET SID
1286 // SET SID
1285 header->sid = sid;
1287 header->sid = sid;
1286
1288
1287 // SET PKTNR
1289 // SET PKTNR
1288 header->pktNr = i+1; // PKT_NR
1290 header->pktNr = i+1; // PKT_NR
1289
1291
1290 // SEND PACKET
1292 // SEND PACKET
1291 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1292 if (status != RTEMS_SUCCESSFUL) {
1294 if (status != RTEMS_SUCCESSFUL) {
1293 ret = LFR_DEFAULT;
1295 ret = LFR_DEFAULT;
1294 }
1296 }
1295 }
1297 }
1296
1298
1297 return ret;
1299 return ret;
1298 }
1300 }
1299
1301
1300 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1302 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1301 Header_TM_LFR_SCIENCE_CWF_t *header )
1303 Header_TM_LFR_SCIENCE_CWF_t *header )
1302 {
1304 {
1303 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1305 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1304 *
1306 *
1305 * @param waveform points to the buffer containing the data that will be send.
1307 * @param waveform points to the buffer containing the data that will be send.
1306 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1308 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1307 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1309 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1308 * contain information to setup the transmission of the data packets.
1310 * contain information to setup the transmission of the data packets.
1309 *
1311 *
1310 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1312 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1311 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1313 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1312 *
1314 *
1313 */
1315 */
1314
1316
1315 unsigned int i;
1317 unsigned int i;
1316 int ret;
1318 int ret;
1317 unsigned int coarseTime;
1319 unsigned int coarseTime;
1318 unsigned int fineTime;
1320 unsigned int fineTime;
1319 rtems_status_code status;
1321 rtems_status_code status;
1320 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1322 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1321 char *dataPtr;
1323 char *dataPtr;
1322 unsigned char sid;
1324 unsigned char sid;
1323
1325
1324 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1326 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1325 spw_ioctl_send_CWF.options = 0;
1327 spw_ioctl_send_CWF.options = 0;
1326
1328
1327 ret = LFR_DEFAULT;
1329 ret = LFR_DEFAULT;
1328 sid = ring_node_to_send->sid;
1330 sid = ring_node_to_send->sid;
1329
1331
1330 coarseTime = ring_node_to_send->coarseTime;
1332 coarseTime = ring_node_to_send->coarseTime;
1331 fineTime = ring_node_to_send->fineTime;
1333 fineTime = ring_node_to_send->fineTime;
1332 dataPtr = (char*) ring_node_to_send->buffer_address;
1334 dataPtr = (char*) ring_node_to_send->buffer_address;
1333
1335
1334 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1336 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1335 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1337 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1336 header->pa_bia_status_info = pa_bia_status_info;
1338 header->pa_bia_status_info = pa_bia_status_info;
1337 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1339 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1338 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1340 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1339 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1341 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1340
1342
1341 //*********************
1343 //*********************
1342 // SEND CWF3_light DATA
1344 // SEND CWF3_light DATA
1343 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1345 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1344 {
1346 {
1345 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1347 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1346 spw_ioctl_send_CWF.hdr = (char*) header;
1348 spw_ioctl_send_CWF.hdr = (char*) header;
1347 // BUILD THE DATA
1349 // BUILD THE DATA
1348 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1350 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1349
1351
1350 // SET PACKET SEQUENCE COUNTER
1352 // SET PACKET SEQUENCE COUNTER
1351 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1353 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1352
1354
1353 // SET SID
1355 // SET SID
1354 header->sid = sid;
1356 header->sid = sid;
1355
1357
1356 // SET PACKET TIME
1358 // SET PACKET TIME
1357 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1359 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1358 //
1360 //
1359 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1361 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1360 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1362 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1361 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1363 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1362 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1364 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1363 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1365 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1364 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1366 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1365
1367
1366 // SET PACKET ID
1368 // SET PACKET ID
1367 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1369 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1368 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1370 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1369
1371
1370 // SEND PACKET
1372 // SEND PACKET
1371 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1373 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1372 if (status != RTEMS_SUCCESSFUL) {
1374 if (status != RTEMS_SUCCESSFUL) {
1373 ret = LFR_DEFAULT;
1375 ret = LFR_DEFAULT;
1374 }
1376 }
1375 }
1377 }
1376
1378
1377 return ret;
1379 return ret;
1378 }
1380 }
1379
1381
1380 void spw_send_asm_f0( ring_node *ring_node_to_send,
1382 void spw_send_asm_f0( ring_node *ring_node_to_send,
1381 Header_TM_LFR_SCIENCE_ASM_t *header )
1383 Header_TM_LFR_SCIENCE_ASM_t *header )
1382 {
1384 {
1383 unsigned int i;
1385 unsigned int i;
1384 unsigned int length = 0;
1386 unsigned int length = 0;
1385 rtems_status_code status;
1387 rtems_status_code status;
1386 unsigned int sid;
1388 unsigned int sid;
1387 float *spectral_matrix;
1389 float *spectral_matrix;
1388 int coarseTime;
1390 int coarseTime;
1389 int fineTime;
1391 int fineTime;
1390 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1392 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1391
1393
1392 sid = ring_node_to_send->sid;
1394 sid = ring_node_to_send->sid;
1393 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1395 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1394 coarseTime = ring_node_to_send->coarseTime;
1396 coarseTime = ring_node_to_send->coarseTime;
1395 fineTime = ring_node_to_send->fineTime;
1397 fineTime = ring_node_to_send->fineTime;
1396
1398
1397 header->pa_bia_status_info = pa_bia_status_info;
1399 header->pa_bia_status_info = pa_bia_status_info;
1398 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1400 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1399
1401
1400 for (i=0; i<PKTCNT_ASM; i++)
1402 for (i=0; i<PKTCNT_ASM; i++)
1401 {
1403 {
1402 if ((i==0) || (i==1))
1404 if ((i==0) || (i==1))
1403 {
1405 {
1404 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1406 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1405 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1407 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1406 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1407 ];
1409 ];
1408 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1409 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1411 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1410 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1412 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1411 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1413 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1412 }
1414 }
1413 else
1415 else
1414 {
1416 {
1415 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1417 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1416 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1418 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1417 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1419 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1418 ];
1420 ];
1419 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1421 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1420 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1422 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1421 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1423 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1422 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1424 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1423 }
1425 }
1424
1426
1425 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1427 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1426 spw_ioctl_send_ASM.hdr = (char *) header;
1428 spw_ioctl_send_ASM.hdr = (char *) header;
1427 spw_ioctl_send_ASM.options = 0;
1429 spw_ioctl_send_ASM.options = 0;
1428
1430
1429 // (2) BUILD THE HEADER
1431 // (2) BUILD THE HEADER
1430 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1432 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1431 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1433 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1432 header->packetLength[1] = (unsigned char) (length);
1434 header->packetLength[1] = (unsigned char) (length);
1433 header->sid = (unsigned char) sid; // SID
1435 header->sid = (unsigned char) sid; // SID
1434 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1436 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1435 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1437 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1436
1438
1437 // (3) SET PACKET TIME
1439 // (3) SET PACKET TIME
1438 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1440 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1439 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1441 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1440 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1442 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1441 header->time[BYTE_3] = (unsigned char) (coarseTime);
1443 header->time[BYTE_3] = (unsigned char) (coarseTime);
1442 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1444 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1443 header->time[BYTE_5] = (unsigned char) (fineTime);
1445 header->time[BYTE_5] = (unsigned char) (fineTime);
1444 //
1446 //
1445 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1447 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1446 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1448 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1447 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1449 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1448 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1450 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1449 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1451 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1450 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1452 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1451
1453
1452 // (4) SEND PACKET
1454 // (4) SEND PACKET
1453 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1455 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1454 if (status != RTEMS_SUCCESSFUL) {
1456 if (status != RTEMS_SUCCESSFUL) {
1455 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1457 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1456 }
1458 }
1457 }
1459 }
1458 }
1460 }
1459
1461
1460 void spw_send_asm_f1( ring_node *ring_node_to_send,
1462 void spw_send_asm_f1( ring_node *ring_node_to_send,
1461 Header_TM_LFR_SCIENCE_ASM_t *header )
1463 Header_TM_LFR_SCIENCE_ASM_t *header )
1462 {
1464 {
1463 unsigned int i;
1465 unsigned int i;
1464 unsigned int length = 0;
1466 unsigned int length = 0;
1465 rtems_status_code status;
1467 rtems_status_code status;
1466 unsigned int sid;
1468 unsigned int sid;
1467 float *spectral_matrix;
1469 float *spectral_matrix;
1468 int coarseTime;
1470 int coarseTime;
1469 int fineTime;
1471 int fineTime;
1470 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1472 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1471
1473
1472 sid = ring_node_to_send->sid;
1474 sid = ring_node_to_send->sid;
1473 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1475 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1474 coarseTime = ring_node_to_send->coarseTime;
1476 coarseTime = ring_node_to_send->coarseTime;
1475 fineTime = ring_node_to_send->fineTime;
1477 fineTime = ring_node_to_send->fineTime;
1476
1478
1477 header->pa_bia_status_info = pa_bia_status_info;
1479 header->pa_bia_status_info = pa_bia_status_info;
1478 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1480 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1479
1481
1480 for (i=0; i<PKTCNT_ASM; i++)
1482 for (i=0; i<PKTCNT_ASM; i++)
1481 {
1483 {
1482 if ((i==0) || (i==1))
1484 if ((i==0) || (i==1))
1483 {
1485 {
1484 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1486 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1485 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1487 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1486 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1488 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1487 ];
1489 ];
1488 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1490 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1489 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1490 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1492 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1491 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1493 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1492 }
1494 }
1493 else
1495 else
1494 {
1496 {
1495 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1497 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1496 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1498 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1497 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1499 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1498 ];
1500 ];
1499 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1501 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1500 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1502 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1501 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1503 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1502 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1504 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1503 }
1505 }
1504
1506
1505 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1507 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1506 spw_ioctl_send_ASM.hdr = (char *) header;
1508 spw_ioctl_send_ASM.hdr = (char *) header;
1507 spw_ioctl_send_ASM.options = 0;
1509 spw_ioctl_send_ASM.options = 0;
1508
1510
1509 // (2) BUILD THE HEADER
1511 // (2) BUILD THE HEADER
1510 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1512 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1511 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1513 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1512 header->packetLength[1] = (unsigned char) (length);
1514 header->packetLength[1] = (unsigned char) (length);
1513 header->sid = (unsigned char) sid; // SID
1515 header->sid = (unsigned char) sid; // SID
1514 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1516 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1515 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1517 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1516
1518
1517 // (3) SET PACKET TIME
1519 // (3) SET PACKET TIME
1518 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1520 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1519 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1521 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1520 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1522 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1521 header->time[BYTE_3] = (unsigned char) (coarseTime);
1523 header->time[BYTE_3] = (unsigned char) (coarseTime);
1522 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1524 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1523 header->time[BYTE_5] = (unsigned char) (fineTime);
1525 header->time[BYTE_5] = (unsigned char) (fineTime);
1524 //
1526 //
1525 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1527 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1526 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1528 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1527 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1529 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1528 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1530 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1529 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1531 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1530 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1532 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1531
1533
1532 // (4) SEND PACKET
1534 // (4) SEND PACKET
1533 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1534 if (status != RTEMS_SUCCESSFUL) {
1536 if (status != RTEMS_SUCCESSFUL) {
1535 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1537 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1536 }
1538 }
1537 }
1539 }
1538 }
1540 }
1539
1541
1540 void spw_send_asm_f2( ring_node *ring_node_to_send,
1542 void spw_send_asm_f2( ring_node *ring_node_to_send,
1541 Header_TM_LFR_SCIENCE_ASM_t *header )
1543 Header_TM_LFR_SCIENCE_ASM_t *header )
1542 {
1544 {
1543 unsigned int i;
1545 unsigned int i;
1544 unsigned int length = 0;
1546 unsigned int length = 0;
1545 rtems_status_code status;
1547 rtems_status_code status;
1546 unsigned int sid;
1548 unsigned int sid;
1547 float *spectral_matrix;
1549 float *spectral_matrix;
1548 int coarseTime;
1550 int coarseTime;
1549 int fineTime;
1551 int fineTime;
1550 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1552 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1551
1553
1552 sid = ring_node_to_send->sid;
1554 sid = ring_node_to_send->sid;
1553 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1555 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1554 coarseTime = ring_node_to_send->coarseTime;
1556 coarseTime = ring_node_to_send->coarseTime;
1555 fineTime = ring_node_to_send->fineTime;
1557 fineTime = ring_node_to_send->fineTime;
1556
1558
1557 header->pa_bia_status_info = pa_bia_status_info;
1559 header->pa_bia_status_info = pa_bia_status_info;
1558 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1560 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1559
1561
1560 for (i=0; i<PKTCNT_ASM; i++)
1562 for (i=0; i<PKTCNT_ASM; i++)
1561 {
1563 {
1562
1564
1563 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1565 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1564 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1566 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1565 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1567 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1566 ];
1568 ];
1567 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1569 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1568 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1570 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1569 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1571 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1570 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1572 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1571
1573
1572 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1574 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1573 spw_ioctl_send_ASM.hdr = (char *) header;
1575 spw_ioctl_send_ASM.hdr = (char *) header;
1574 spw_ioctl_send_ASM.options = 0;
1576 spw_ioctl_send_ASM.options = 0;
1575
1577
1576 // (2) BUILD THE HEADER
1578 // (2) BUILD THE HEADER
1577 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1579 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1578 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1580 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1579 header->packetLength[1] = (unsigned char) (length);
1581 header->packetLength[1] = (unsigned char) (length);
1580 header->sid = (unsigned char) sid; // SID
1582 header->sid = (unsigned char) sid; // SID
1581 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1583 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1582 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1584 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1583
1585
1584 // (3) SET PACKET TIME
1586 // (3) SET PACKET TIME
1585 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1587 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1586 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1588 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1587 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1589 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1588 header->time[BYTE_3] = (unsigned char) (coarseTime);
1590 header->time[BYTE_3] = (unsigned char) (coarseTime);
1589 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1591 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1590 header->time[BYTE_5] = (unsigned char) (fineTime);
1592 header->time[BYTE_5] = (unsigned char) (fineTime);
1591 //
1593 //
1592 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1594 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1593 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1595 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1594 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1596 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1595 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1597 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1596 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1598 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1597 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1599 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1598
1600
1599 // (4) SEND PACKET
1601 // (4) SEND PACKET
1600 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1601 if (status != RTEMS_SUCCESSFUL) {
1603 if (status != RTEMS_SUCCESSFUL) {
1602 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1604 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1603 }
1605 }
1604 }
1606 }
1605 }
1607 }
1606
1608
1607 void spw_send_k_dump( ring_node *ring_node_to_send )
1609 void spw_send_k_dump( ring_node *ring_node_to_send )
1608 {
1610 {
1609 rtems_status_code status;
1611 rtems_status_code status;
1610 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1612 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1611 unsigned int packetLength;
1613 unsigned int packetLength;
1612 unsigned int size;
1614 unsigned int size;
1613
1615
1614 PRINTF("spw_send_k_dump\n")
1616 PRINTF("spw_send_k_dump\n")
1615
1617
1616 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1618 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1617
1619
1618 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1620 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1619
1621
1620 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1622 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1621
1623
1622 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1624 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1623
1625
1624 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1626 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1625
1627
1626 if (status == -1){
1628 if (status == -1){
1627 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1629 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1628 }
1630 }
1629
1631
1630 ring_node_to_send->status = INIT_CHAR;
1632 ring_node_to_send->status = INIT_CHAR;
1631 }
1633 }
@@ -1,802 +1,802
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "fsw_processing.h"
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
11 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
12 #include "fsw_init.h"
13
13
14 unsigned int nb_sm_f0 = 0;
14 unsigned int nb_sm_f0 = 0;
15 unsigned int nb_sm_f0_aux_f1= 0;
15 unsigned int nb_sm_f0_aux_f1= 0;
16 unsigned int nb_sm_f1 = 0;
16 unsigned int nb_sm_f1 = 0;
17 unsigned int nb_sm_f0_aux_f2= 0;
17 unsigned int nb_sm_f0_aux_f2= 0;
18
18
19 typedef enum restartState_t
19 typedef enum restartState_t
20 {
20 {
21 WAIT_FOR_F2,
21 WAIT_FOR_F2,
22 WAIT_FOR_F1,
22 WAIT_FOR_F1,
23 WAIT_FOR_F0
23 WAIT_FOR_F0
24 } restartState;
24 } restartState;
25
25
26 //************************
26 //************************
27 // spectral matrices rings
27 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
31 ring_node *current_ring_node_sm_f0 = NULL;
31 ring_node *current_ring_node_sm_f0 = NULL;
32 ring_node *current_ring_node_sm_f1 = NULL;
32 ring_node *current_ring_node_sm_f1 = NULL;
33 ring_node *current_ring_node_sm_f2 = NULL;
33 ring_node *current_ring_node_sm_f2 = NULL;
34 ring_node *ring_node_for_averaging_sm_f0= NULL;
34 ring_node *ring_node_for_averaging_sm_f0= NULL;
35 ring_node *ring_node_for_averaging_sm_f1= NULL;
35 ring_node *ring_node_for_averaging_sm_f1= NULL;
36 ring_node *ring_node_for_averaging_sm_f2= NULL;
36 ring_node *ring_node_for_averaging_sm_f2= NULL;
37
37
38 //
38 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
40 {
41 ring_node *node;
41 ring_node *node;
42
42
43 node = NULL;
43 node = NULL;
44 switch ( frequencyChannel ) {
44 switch ( frequencyChannel ) {
45 case CHANNELF0:
45 case CHANNELF0:
46 node = ring_node_for_averaging_sm_f0;
46 node = ring_node_for_averaging_sm_f0;
47 break;
47 break;
48 case CHANNELF1:
48 case CHANNELF1:
49 node = ring_node_for_averaging_sm_f1;
49 node = ring_node_for_averaging_sm_f1;
50 break;
50 break;
51 case CHANNELF2:
51 case CHANNELF2:
52 node = ring_node_for_averaging_sm_f2;
52 node = ring_node_for_averaging_sm_f2;
53 break;
53 break;
54 default:
54 default:
55 break;
55 break;
56 }
56 }
57
57
58 return node;
58 return node;
59 }
59 }
60
60
61 //***********************************************************
61 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
62 // Interrupt Service Routine for spectral matrices processing
63
63
64 void spectral_matrices_isr_f0( int statusReg )
64 void spectral_matrices_isr_f0( int statusReg )
65 {
65 {
66 unsigned char status;
66 unsigned char status;
67 rtems_status_code status_code;
67 rtems_status_code status_code;
68 ring_node *full_ring_node;
68 ring_node *full_ring_node;
69
69
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
71
71
72 switch(status)
72 switch(status)
73 {
73 {
74 case 0:
74 case 0:
75 break;
75 break;
76 case BIT_READY_0_1:
76 case BIT_READY_0_1:
77 // UNEXPECTED VALUE
77 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
80 break;
81 case BIT_READY_0:
81 case BIT_READY_0:
82 full_ring_node = current_ring_node_sm_f0->previous;
82 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
87 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
88 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
90 {
90 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
91 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
93 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
95 }
96 nb_sm_f0 = 0;
96 nb_sm_f0 = 0;
97 }
97 }
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
99 break;
99 break;
100 case BIT_READY_1:
100 case BIT_READY_1:
101 full_ring_node = current_ring_node_sm_f0->previous;
101 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
106 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
107 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
109 {
109 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
110 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
112 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
114 }
115 nb_sm_f0 = 0;
115 nb_sm_f0 = 0;
116 }
116 }
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
118 break;
118 break;
119 default:
119 default:
120 break;
120 break;
121 }
121 }
122 }
122 }
123
123
124 void spectral_matrices_isr_f1( int statusReg )
124 void spectral_matrices_isr_f1( int statusReg )
125 {
125 {
126 rtems_status_code status_code;
126 rtems_status_code status_code;
127 unsigned char status;
127 unsigned char status;
128 ring_node *full_ring_node;
128 ring_node *full_ring_node;
129
129
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
131
131
132 switch(status)
132 switch(status)
133 {
133 {
134 case 0:
134 case 0:
135 break;
135 break;
136 case BIT_READY_0_1:
136 case BIT_READY_0_1:
137 // UNEXPECTED VALUE
137 // UNEXPECTED VALUE
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
140 break;
140 break;
141 case BIT_READY_0:
141 case BIT_READY_0:
142 full_ring_node = current_ring_node_sm_f1->previous;
142 full_ring_node = current_ring_node_sm_f1->previous;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
147 // if there are enough ring nodes ready, wake up an AVFx task
147 // if there are enough ring nodes ready, wake up an AVFx task
148 nb_sm_f1 = nb_sm_f1 + 1;
148 nb_sm_f1 = nb_sm_f1 + 1;
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
150 {
150 {
151 ring_node_for_averaging_sm_f1 = full_ring_node;
151 ring_node_for_averaging_sm_f1 = full_ring_node;
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
153 {
153 {
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
155 }
155 }
156 nb_sm_f1 = 0;
156 nb_sm_f1 = 0;
157 }
157 }
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
159 break;
159 break;
160 case BIT_READY_1:
160 case BIT_READY_1:
161 full_ring_node = current_ring_node_sm_f1->previous;
161 full_ring_node = current_ring_node_sm_f1->previous;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
166 // if there are enough ring nodes ready, wake up an AVFx task
166 // if there are enough ring nodes ready, wake up an AVFx task
167 nb_sm_f1 = nb_sm_f1 + 1;
167 nb_sm_f1 = nb_sm_f1 + 1;
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
169 {
169 {
170 ring_node_for_averaging_sm_f1 = full_ring_node;
170 ring_node_for_averaging_sm_f1 = full_ring_node;
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
172 {
172 {
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
174 }
174 }
175 nb_sm_f1 = 0;
175 nb_sm_f1 = 0;
176 }
176 }
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
178 break;
178 break;
179 default:
179 default:
180 break;
180 break;
181 }
181 }
182 }
182 }
183
183
184 void spectral_matrices_isr_f2( int statusReg )
184 void spectral_matrices_isr_f2( int statusReg )
185 {
185 {
186 unsigned char status;
186 unsigned char status;
187 rtems_status_code status_code;
187 rtems_status_code status_code;
188
188
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
190
190
191 switch(status)
191 switch(status)
192 {
192 {
193 case 0:
193 case 0:
194 break;
194 break;
195 case BIT_READY_0_1:
195 case BIT_READY_0_1:
196 // UNEXPECTED VALUE
196 // UNEXPECTED VALUE
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
199 break;
199 break;
200 case BIT_READY_0:
200 case BIT_READY_0:
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
208 {
208 {
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
210 }
210 }
211 break;
211 break;
212 case BIT_READY_1:
212 case BIT_READY_1:
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
220 {
220 {
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
222 }
222 }
223 break;
223 break;
224 default:
224 default:
225 break;
225 break;
226 }
226 }
227 }
227 }
228
228
229 void spectral_matrix_isr_error_handler( int statusReg )
229 void spectral_matrix_isr_error_handler( int statusReg )
230 {
230 {
231 // STATUS REGISTER
231 // STATUS REGISTER
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
233 // 10 9 8
233 // 10 9 8
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
235 // 7 6 5 4 3 2 1 0
235 // 7 6 5 4 3 2 1 0
236 // [bad_component_err] not defined in the last version of the VHDL code
236 // [bad_component_err] not defined in the last version of the VHDL code
237
237
238 rtems_status_code status_code;
238 rtems_status_code status_code;
239
239
240 //***************************************************
240 //***************************************************
241 // the ASM status register is copied in the HK packet
241 // the ASM status register is copied in the HK packet
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
243
243
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
245 {
245 {
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
247 }
247 }
248
248
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
250
250
251 }
251 }
252
252
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
254 {
254 {
255 // STATUS REGISTER
255 // STATUS REGISTER
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
257 // 10 9 8
257 // 10 9 8
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
259 // 7 6 5 4 3 2 1 0
259 // 7 6 5 4 3 2 1 0
260
260
261 int statusReg;
261 int statusReg;
262
262
263 static restartState state = WAIT_FOR_F2;
263 static restartState state = WAIT_FOR_F2;
264
264
265 statusReg = spectral_matrix_regs->status;
265 statusReg = spectral_matrix_regs->status;
266
266
267 if (thisIsAnASMRestart == 0)
267 if (thisIsAnASMRestart == 0)
268 { // this is not a restart sequence, process incoming matrices normally
268 { // this is not a restart sequence, process incoming matrices normally
269 spectral_matrices_isr_f0( statusReg );
269 spectral_matrices_isr_f0( statusReg );
270
270
271 spectral_matrices_isr_f1( statusReg );
271 spectral_matrices_isr_f1( statusReg );
272
272
273 spectral_matrices_isr_f2( statusReg );
273 spectral_matrices_isr_f2( statusReg );
274 }
274 }
275 else
275 else
276 { // a restart sequence has to be launched
276 { // a restart sequence has to be launched
277 switch (state) {
277 switch (state) {
278 case WAIT_FOR_F2:
278 case WAIT_FOR_F2:
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
280 {
280 {
281 state = WAIT_FOR_F1;
281 state = WAIT_FOR_F1;
282 }
282 }
283 break;
283 break;
284 case WAIT_FOR_F1:
284 case WAIT_FOR_F1:
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
286 {
286 {
287 state = WAIT_FOR_F0;
287 state = WAIT_FOR_F0;
288 }
288 }
289 break;
289 break;
290 case WAIT_FOR_F0:
290 case WAIT_FOR_F0:
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
292 {
292 {
293 state = WAIT_FOR_F2;
293 state = WAIT_FOR_F2;
294 thisIsAnASMRestart = 0;
294 thisIsAnASMRestart = 0;
295 }
295 }
296 break;
296 break;
297 default:
297 default:
298 break;
298 break;
299 }
299 }
300 reset_sm_status();
300 reset_sm_status();
301 }
301 }
302
302
303 spectral_matrix_isr_error_handler( statusReg );
303 spectral_matrix_isr_error_handler( statusReg );
304
304
305 }
305 }
306
306
307 //******************
307 //******************
308 // Spectral Matrices
308 // Spectral Matrices
309
309
310 void reset_nb_sm( void )
310 void reset_nb_sm( void )
311 {
311 {
312 nb_sm_f0 = 0;
312 nb_sm_f0 = 0;
313 nb_sm_f0_aux_f1 = 0;
313 nb_sm_f0_aux_f1 = 0;
314 nb_sm_f0_aux_f2 = 0;
314 nb_sm_f0_aux_f2 = 0;
315
315
316 nb_sm_f1 = 0;
316 nb_sm_f1 = 0;
317 }
317 }
318
318
319 void SM_init_rings( void )
319 void SM_init_rings( void )
320 {
320 {
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
324
324
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
331 }
331 }
332
332
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
334 {
334 {
335 unsigned char i;
335 unsigned char i;
336
336
337 ring[ nbNodes - 1 ].next
337 ring[ nbNodes - 1 ].next
338 = (ring_node_asm*) &ring[ 0 ];
338 = (ring_node_asm*) &ring[ 0 ];
339
339
340 for(i=0; i<nbNodes-1; i++)
340 for(i=0; i<nbNodes-1; i++)
341 {
341 {
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
343 }
343 }
344 }
344 }
345
345
346 void SM_reset_current_ring_nodes( void )
346 void SM_reset_current_ring_nodes( void )
347 {
347 {
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
351
351
352 ring_node_for_averaging_sm_f0 = NULL;
352 ring_node_for_averaging_sm_f0 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
355 }
355 }
356
356
357 //*****************
357 //*****************
358 // Basic Parameters
358 // Basic Parameters
359
359
360 void BP_init_header( bp_packet *packet,
360 void BP_init_header( bp_packet *packet,
361 unsigned int apid, unsigned char sid,
361 unsigned int apid, unsigned char sid,
362 unsigned int packetLength, unsigned char blkNr )
362 unsigned int packetLength, unsigned char blkNr )
363 {
363 {
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
366 packet->reserved = INIT_CHAR;
366 packet->reserved = INIT_CHAR;
367 packet->userApplication = CCSDS_USER_APP;
367 packet->userApplication = CCSDS_USER_APP;
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
369 packet->packetID[1] = (unsigned char) (apid);
369 packet->packetID[1] = (unsigned char) (apid);
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
371 packet->packetSequenceControl[1] = INIT_CHAR;
371 packet->packetSequenceControl[1] = INIT_CHAR;
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
373 packet->packetLength[1] = (unsigned char) (packetLength);
373 packet->packetLength[1] = (unsigned char) (packetLength);
374 // DATA FIELD HEADER
374 // DATA FIELD HEADER
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
379 packet->time[BYTE_0] = INIT_CHAR;
379 packet->time[BYTE_0] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
385 // AUXILIARY DATA HEADER
385 // AUXILIARY DATA HEADER
386 packet->sid = sid;
386 packet->sid = sid;
387 packet->pa_bia_status_info = INIT_CHAR;
387 packet->pa_bia_status_info = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
398 }
398 }
399
399
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
401 unsigned int apid, unsigned char sid,
401 unsigned int apid, unsigned char sid,
402 unsigned int packetLength , unsigned char blkNr)
402 unsigned int packetLength , unsigned char blkNr)
403 {
403 {
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
406 packet->reserved = INIT_CHAR;
406 packet->reserved = INIT_CHAR;
407 packet->userApplication = CCSDS_USER_APP;
407 packet->userApplication = CCSDS_USER_APP;
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
409 packet->packetID[1] = (unsigned char) (apid);
409 packet->packetID[1] = (unsigned char) (apid);
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
411 packet->packetSequenceControl[1] = INIT_CHAR;
411 packet->packetSequenceControl[1] = INIT_CHAR;
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
413 packet->packetLength[1] = (unsigned char) (packetLength);
413 packet->packetLength[1] = (unsigned char) (packetLength);
414 // DATA FIELD HEADER
414 // DATA FIELD HEADER
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
419 // AUXILIARY DATA HEADER
419 // AUXILIARY DATA HEADER
420 packet->sid = sid;
420 packet->sid = sid;
421 packet->pa_bia_status_info = INIT_CHAR;
421 packet->pa_bia_status_info = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
433 }
433 }
434
434
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
436 {
436 {
437 rtems_status_code status;
437 rtems_status_code status;
438
438
439 // SEND PACKET
439 // SEND PACKET
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
441 if (status != RTEMS_SUCCESSFUL)
441 if (status != RTEMS_SUCCESSFUL)
442 {
442 {
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
444 }
444 }
445 }
445 }
446
446
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
448 {
448 {
449 /** This function is used to send the BP paquets when needed.
449 /** This function is used to send the BP paquets when needed.
450 *
450 *
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
452 *
452 *
453 * @return void
453 * @return void
454 *
454 *
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
456 * BURST paquets are sent everytime.
456 * BURST paquets are sent everytime.
457 *
457 *
458 */
458 */
459
459
460 rtems_status_code status;
460 rtems_status_code status;
461
461
462 // SEND PACKET
462 // SEND PACKET
463 // before lastValidTransitionDate, the data are drops even if they are ready
463 // before lastValidTransitionDate, the data are drops even if they are ready
464 // this guarantees that no SBM packets will be received before the requested enter mode time
464 // this guarantees that no SBM packets will be received before the requested enter mode time
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
466 {
466 {
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
468 if (status != RTEMS_SUCCESSFUL)
468 if (status != RTEMS_SUCCESSFUL)
469 {
469 {
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
471 }
471 }
472 }
472 }
473 }
473 }
474
474
475 //******************
475 //******************
476 // general functions
476 // general functions
477
477
478 void reset_sm_status( void )
478 void reset_sm_status( void )
479 {
479 {
480 // error
480 // error
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
485
485
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
487 }
487 }
488
488
489 void reset_spectral_matrix_regs( void )
489 void reset_spectral_matrix_regs( void )
490 {
490 {
491 /** This function resets the spectral matrices module registers.
491 /** This function resets the spectral matrices module registers.
492 *
492 *
493 * The registers affected by this function are located at the following offset addresses:
493 * The registers affected by this function are located at the following offset addresses:
494 *
494 *
495 * - 0x00 config
495 * - 0x00 config
496 * - 0x04 status
496 * - 0x04 status
497 * - 0x08 matrixF0_Address0
497 * - 0x08 matrixF0_Address0
498 * - 0x10 matrixFO_Address1
498 * - 0x10 matrixFO_Address1
499 * - 0x14 matrixF1_Address
499 * - 0x14 matrixF1_Address
500 * - 0x18 matrixF2_Address
500 * - 0x18 matrixF2_Address
501 *
501 *
502 */
502 */
503
503
504 set_sm_irq_onError( 0 );
504 set_sm_irq_onError( 0 );
505
505
506 set_sm_irq_onNewMatrix( 0 );
506 set_sm_irq_onNewMatrix( 0 );
507
507
508 reset_sm_status();
508 reset_sm_status();
509
509
510 // F1
510 // F1
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
513 // F2
513 // F2
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
516 // F3
516 // F3
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
519
519
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
521 }
521 }
522
522
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
524 {
524 {
525 time[BYTE_0] = timeInBuffer[BYTE_0];
525 time[BYTE_0] = timeInBuffer[BYTE_0];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
531 }
531 }
532
532
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
534 {
534 {
535 unsigned long long int acquisitionTimeAslong;
535 unsigned long long int acquisitionTimeAslong;
536 acquisitionTimeAslong = INIT_CHAR;
536 acquisitionTimeAslong = INIT_CHAR;
537 acquisitionTimeAslong =
537 acquisitionTimeAslong =
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
543 + ( (unsigned long long int) timePtr[BYTE_7] );
543 + ( (unsigned long long int) timePtr[BYTE_7] );
544 return acquisitionTimeAslong;
544 return acquisitionTimeAslong;
545 }
545 }
546
546
547 unsigned char getSID( rtems_event_set event )
547 unsigned char getSID( rtems_event_set event )
548 {
548 {
549 unsigned char sid;
549 unsigned char sid;
550
550
551 rtems_event_set eventSetBURST;
551 rtems_event_set eventSetBURST;
552 rtems_event_set eventSetSBM;
552 rtems_event_set eventSetSBM;
553
553
554 sid = 0;
554 sid = 0;
555
555
556 //******
556 //******
557 // BURST
557 // BURST
558 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
558 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
559 | RTEMS_EVENT_BURST_BP1_F1
559 | RTEMS_EVENT_BURST_BP1_F1
560 | RTEMS_EVENT_BURST_BP2_F0
560 | RTEMS_EVENT_BURST_BP2_F0
561 | RTEMS_EVENT_BURST_BP2_F1;
561 | RTEMS_EVENT_BURST_BP2_F1;
562
562
563 //****
563 //****
564 // SBM
564 // SBM
565 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
565 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
566 | RTEMS_EVENT_SBM_BP1_F1
566 | RTEMS_EVENT_SBM_BP1_F1
567 | RTEMS_EVENT_SBM_BP2_F0
567 | RTEMS_EVENT_SBM_BP2_F0
568 | RTEMS_EVENT_SBM_BP2_F1;
568 | RTEMS_EVENT_SBM_BP2_F1;
569
569
570 if (event & eventSetBURST)
570 if (event & eventSetBURST)
571 {
571 {
572 sid = SID_BURST_BP1_F0;
572 sid = SID_BURST_BP1_F0;
573 }
573 }
574 else if (event & eventSetSBM)
574 else if (event & eventSetSBM)
575 {
575 {
576 sid = SID_SBM1_BP1_F0;
576 sid = SID_SBM1_BP1_F0;
577 }
577 }
578 else
578 else
579 {
579 {
580 sid = 0;
580 sid = 0;
581 }
581 }
582
582
583 return sid;
583 return sid;
584 }
584 }
585
585
586 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
586 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
587 {
587 {
588 unsigned int i;
588 unsigned int i;
589 float re;
589 float re;
590 float im;
590 float im;
591
591
592 for (i=0; i<NB_BINS_PER_SM; i++){
592 for (i=0; i<NB_BINS_PER_SM; i++){
593 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
593 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
594 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
594 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
595 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
595 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
596 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
596 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
597 }
597 }
598 }
598 }
599
599
600 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
600 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
601 {
601 {
602 unsigned int i;
602 unsigned int i;
603 float re;
603 float re;
604
604
605 for (i=0; i<NB_BINS_PER_SM; i++){
605 for (i=0; i<NB_BINS_PER_SM; i++){
606 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
606 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
607 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
607 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
608 }
608 }
609 }
609 }
610
610
611 void ASM_patch( float *inputASM, float *outputASM )
611 void ASM_patch( float *inputASM, float *outputASM )
612 {
612 {
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
620 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
620 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
621 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
621 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
622 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
622 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
623
623
624 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
624 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
625 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
625 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
626 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
626 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
627 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
627 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
628 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
628 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
629 }
629 }
630
630
631 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
631 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
632 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
632 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
633 unsigned char ASMIndexStart,
633 unsigned char ASMIndexStart,
634 unsigned char channel )
634 unsigned char channel )
635 {
635 {
636 //*************
636 //*************
637 // input format
637 // input format
638 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
638 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
639 //**************
639 //**************
640 // output format
640 // output format
641 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
641 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
642 //************
642 //************
643 // compression
643 // compression
644 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
644 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
645 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
645 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
646
646
647 int frequencyBin;
647 int frequencyBin;
648 int asmComponent;
648 int asmComponent;
649 int offsetASM;
649 int offsetASM;
650 int offsetCompressed;
650 int offsetCompressed;
651 int offsetFBin;
651 int offsetFBin;
652 int fBinMask;
652 int fBinMask;
653 int k;
653 int k;
654
654
655 // BUILD DATA
655 // BUILD DATA
656 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
656 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
657 {
657 {
658 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
658 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
659 {
659 {
660 offsetCompressed = // NO TIME OFFSET
660 offsetCompressed = // NO TIME OFFSET
661 (frequencyBin * NB_VALUES_PER_SM)
661 (frequencyBin * NB_VALUES_PER_SM)
662 + asmComponent;
662 + asmComponent;
663 offsetASM = // NO TIME OFFSET
663 offsetASM = // NO TIME OFFSET
664 (asmComponent * NB_BINS_PER_SM)
664 (asmComponent * NB_BINS_PER_SM)
665 + ASMIndexStart
665 + ASMIndexStart
666 + (frequencyBin * nbBinsToAverage);
666 + (frequencyBin * nbBinsToAverage);
667 offsetFBin = ASMIndexStart
667 offsetFBin = ASMIndexStart
668 + (frequencyBin * nbBinsToAverage);
668 + (frequencyBin * nbBinsToAverage);
669 compressed_spec_mat[ offsetCompressed ] = 0;
669 compressed_spec_mat[ offsetCompressed ] = 0;
670 for ( k = 0; k < nbBinsToAverage; k++ )
670 for ( k = 0; k < nbBinsToAverage; k++ )
671 {
671 {
672 fBinMask = getFBinMask( offsetFBin + k, channel );
672 fBinMask = getFBinMask( offsetFBin + k, channel );
673 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
673 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
674 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
674 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
675 }
675 }
676 if (divider != 0)
676 if (divider != 0)
677 {
677 {
678 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
678 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
679 }
679 }
680 else
680 else
681 {
681 {
682 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
682 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
683 }
683 }
684 }
684 }
685 }
685 }
686
686
687 }
687 }
688
688
689 int getFBinMask( int index, unsigned char channel )
689 int getFBinMask( int index, unsigned char channel )
690 {
690 {
691 unsigned int indexInChar;
691 unsigned int indexInChar;
692 unsigned int indexInTheChar;
692 unsigned int indexInTheChar;
693 int fbin;
693 int fbin;
694 unsigned char *sy_lfr_fbins_fx_word1;
694 unsigned char *sy_lfr_fbins_fx_word1;
695
695
696 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
696 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
697
697
698 switch(channel)
698 switch(channel)
699 {
699 {
700 case CHANNELF0:
700 case CHANNELF0:
701 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
701 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
702 break;
702 break;
703 case CHANNELF1:
703 case CHANNELF1:
704 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
704 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
705 break;
705 break;
706 case CHANNELF2:
706 case CHANNELF2:
707 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
707 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
708 break;
708 break;
709 default:
709 default:
710 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
710 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
711 }
711 }
712
712
713 indexInChar = index >> SHIFT_3_BITS;
713 indexInChar = index >> SHIFT_3_BITS;
714 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
714 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
715
715
716 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
716 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
717
717
718 return fbin;
718 return fbin;
719 }
719 }
720
720
721 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
721 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
722 {
722 {
723 u_int64_t acquisitionTime;
723 u_int64_t acquisitionTime;
724 u_int64_t timecodeReference;
724 u_int64_t timecodeReference;
725 u_int64_t offsetInFineTime;
725 u_int64_t offsetInFineTime;
726 u_int64_t shiftInFineTime;
726 u_int64_t shiftInFineTime;
727 u_int64_t tBadInFineTime;
727 u_int64_t tBadInFineTime;
728 u_int64_t acquisitionTimeRangeMin;
728 u_int64_t acquisitionTimeRangeMin;
729 u_int64_t acquisitionTimeRangeMax;
729 u_int64_t acquisitionTimeRangeMax;
730 unsigned char pasFilteringIsEnabled;
730 unsigned char pasFilteringIsEnabled;
731 unsigned char ret;
731 unsigned char ret;
732
732
733 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
733 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
734 ret = 1;
734 ret = 1;
735
735
736 // compute acquisition time from caoarseTime and fineTime
736 // compute acquisition time from caoarseTime and fineTime
737 acquisitionTime = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
737 acquisitionTime = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
738 + (u_int64_t) fineTime;
738 + (u_int64_t) fineTime;
739
739
740 // compute the timecode reference
740 // compute the timecode reference
741 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
741 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
742 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
742 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
743
743
744 // compute the acquitionTime range
744 // compute the acquitionTime range
745 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
745 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
746 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
746 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
747 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
747 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
748
748
749 acquisitionTimeRangeMin =
749 acquisitionTimeRangeMin =
750 timecodeReference
750 timecodeReference
751 + offsetInFineTime
751 + offsetInFineTime
752 + shiftInFineTime
752 + shiftInFineTime
753 - acquisitionDurations[channel];
753 - acquisitionDurations[channel];
754 acquisitionTimeRangeMax =
754 acquisitionTimeRangeMax =
755 timecodeReference
755 timecodeReference
756 + offsetInFineTime
756 + offsetInFineTime
757 + shiftInFineTime
757 + shiftInFineTime
758 + tBadInFineTime;
758 + tBadInFineTime;
759
759
760 if ( (acquisitionTime >= acquisitionTimeRangeMin)
760 if ( (acquisitionTime >= acquisitionTimeRangeMin)
761 && (acquisitionTime <= acquisitionTimeRangeMax)
761 && (acquisitionTime <= acquisitionTimeRangeMax)
762 && (pasFilteringIsEnabled == 1) )
762 && (pasFilteringIsEnabled == 1) )
763 {
763 {
764 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
764 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
765 }
765 }
766 else
766 else
767 {
767 {
768 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
768 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
769 }
769 }
770
770
771 // printf("coarseTime = %x, fineTime = %x\n",
771 // printf("coarseTime = %x, fineTime = %x\n",
772 // coarseTime,
772 // coarseTime,
773 // fineTime);
773 // fineTime);
774
774
775 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
775 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
776 // ret,
776 // ret,
777 // acquisitionTime / 65536.,
777 // acquisitionTime / 65536.,
778 // timecodeReference / 65536.);
778 // timecodeReference / 65536.);
779
779
780 // printf(", Min = %f, Max = %f\n",
780 // printf(", Min = %f, Max = %f\n",
781 // acquisitionTimeRangeMin / 65536.,
781 // acquisitionTimeRangeMin / 65536.,
782 // acquisitionTimeRangeMax / 65536.);
782 // acquisitionTimeRangeMax / 65536.);
783
783
784 return ret;
784 return ret;
785 }
785 }
786
786
787 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
787 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
788 {
788 {
789 unsigned char bin;
789 unsigned char bin;
790 unsigned char kcoeff;
790 unsigned char kcoeff;
791
791
792 for (bin=0; bin<nb_bins_norm; bin++)
792 for (bin=0; bin<nb_bins_norm; bin++)
793 {
793 {
794 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
794 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
795 {
795 {
796 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
796 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
797 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
797 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
798 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF + 1 ]
798 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
799 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
799 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
800 }
800 }
801 }
801 }
802 }
802 }
@@ -1,1657 +1,1657
1 /** Functions to load and dump parameters in the LFR registers.
1 /** Functions to load and dump parameters in the LFR registers.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
12 *
13 */
13 */
14
14
15 #include "tc_load_dump_parameters.h"
15 #include "tc_load_dump_parameters.h"
16
16
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 ring_node kcoefficient_node_1 = {0};
19 ring_node kcoefficient_node_1 = {0};
20 ring_node kcoefficient_node_2 = {0};
20 ring_node kcoefficient_node_2 = {0};
21
21
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
23 {
24 /** This function updates the LFR registers with the incoming common parameters.
24 /** This function updates the LFR registers with the incoming common parameters.
25 *
25 *
26 * @param TC points to the TeleCommand packet that is being processed
26 * @param TC points to the TeleCommand packet that is being processed
27 *
27 *
28 *
28 *
29 */
29 */
30
30
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
33 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
34 return LFR_SUCCESSFUL;
35 }
35 }
36
36
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
38 {
39 /** This function updates the LFR registers with the incoming normal parameters.
39 /** This function updates the LFR registers with the incoming normal parameters.
40 *
40 *
41 * @param TC points to the TeleCommand packet that is being processed
41 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 *
43 *
44 */
44 */
45
45
46 int result;
46 int result;
47 int flag;
47 int flag;
48 rtems_status_code status;
48 rtems_status_code status;
49
49
50 flag = LFR_SUCCESSFUL;
50 flag = LFR_SUCCESSFUL;
51
51
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
55 flag = LFR_DEFAULT;
56 }
56 }
57
57
58 // CHECK THE PARAMETERS SET CONSISTENCY
58 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
59 if (flag == LFR_SUCCESSFUL)
60 {
60 {
61 flag = check_normal_par_consistency( TC, queue_id );
61 flag = check_normal_par_consistency( TC, queue_id );
62 }
62 }
63
63
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
65 if (flag == LFR_SUCCESSFUL)
66 {
66 {
67 result = set_sy_lfr_n_swf_l( TC );
67 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
68 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
71 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
73 }
74
74
75 return flag;
75 return flag;
76 }
76 }
77
77
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
79 {
80 /** This function updates the LFR registers with the incoming burst parameters.
80 /** This function updates the LFR registers with the incoming burst parameters.
81 *
81 *
82 * @param TC points to the TeleCommand packet that is being processed
82 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 *
84 *
85 */
85 */
86
86
87 int flag;
87 int flag;
88 rtems_status_code status;
88 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
89 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
90 unsigned char sy_lfr_b_bp_p1;
91 float aux;
91 float aux;
92
92
93 flag = LFR_SUCCESSFUL;
93 flag = LFR_SUCCESSFUL;
94
94
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
97 flag = LFR_DEFAULT;
98 }
98 }
99
99
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
102
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
104 if (flag == LFR_SUCCESSFUL)
105 {
105 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
107 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
109 flag = WRONG_APP_DATA;
110 }
110 }
111 }
111 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
113 if (flag == LFR_SUCCESSFUL)
114 {
114 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
116 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
118 flag = WRONG_APP_DATA;
119 }
119 }
120 }
120 }
121 //****************************************************************
121 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
123 if (flag == LFR_SUCCESSFUL)
124 {
124 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 if (aux > FLOAT_EQUAL_ZERO)
128 if (aux > FLOAT_EQUAL_ZERO)
129 {
129 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
131 flag = LFR_DEFAULT;
132 }
132 }
133 }
133 }
134
134
135 // SET THE PARAMETERS
135 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
136 if (flag == LFR_SUCCESSFUL)
137 {
137 {
138 flag = set_sy_lfr_b_bp_p0( TC );
138 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
140 }
140 }
141
141
142 return flag;
142 return flag;
143 }
143 }
144
144
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
146 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
148 *
149 * @param TC points to the TeleCommand packet that is being processed
149 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 *
151 *
152 */
152 */
153
153
154 int flag;
154 int flag;
155 rtems_status_code status;
155 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
156 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
157 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
158 float aux;
159
159
160 flag = LFR_SUCCESSFUL;
160 flag = LFR_SUCCESSFUL;
161
161
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
164 flag = LFR_DEFAULT;
165 }
165 }
166
166
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
169
170 // sy_lfr_s1_bp_p0
170 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
171 if (flag == LFR_SUCCESSFUL)
172 {
172 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
174 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
176 flag = WRONG_APP_DATA;
177 }
177 }
178 }
178 }
179 // sy_lfr_s1_bp_p1
179 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
180 if (flag == LFR_SUCCESSFUL)
181 {
181 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
183 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
185 flag = WRONG_APP_DATA;
186 }
186 }
187 }
187 }
188 //******************************************************************
188 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
190 if (flag == LFR_SUCCESSFUL)
191 {
191 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 if (aux > FLOAT_EQUAL_ZERO)
194 if (aux > FLOAT_EQUAL_ZERO)
195 {
195 {
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 flag = LFR_DEFAULT;
197 flag = LFR_DEFAULT;
198 }
198 }
199 }
199 }
200
200
201 // SET THE PARAMETERS
201 // SET THE PARAMETERS
202 if (flag == LFR_SUCCESSFUL)
202 if (flag == LFR_SUCCESSFUL)
203 {
203 {
204 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p0( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
206 }
206 }
207
207
208 return flag;
208 return flag;
209 }
209 }
210
210
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 {
212 {
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 *
214 *
215 * @param TC points to the TeleCommand packet that is being processed
215 * @param TC points to the TeleCommand packet that is being processed
216 * @param queue_id is the id of the queue which handles TM related to this execution step
216 * @param queue_id is the id of the queue which handles TM related to this execution step
217 *
217 *
218 */
218 */
219
219
220 int flag;
220 int flag;
221 rtems_status_code status;
221 rtems_status_code status;
222 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p0;
223 unsigned char sy_lfr_s2_bp_p1;
223 unsigned char sy_lfr_s2_bp_p1;
224 float aux;
224 float aux;
225
225
226 flag = LFR_SUCCESSFUL;
226 flag = LFR_SUCCESSFUL;
227
227
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 flag = LFR_DEFAULT;
230 flag = LFR_DEFAULT;
231 }
231 }
232
232
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235
235
236 // sy_lfr_s2_bp_p0
236 // sy_lfr_s2_bp_p0
237 if (flag == LFR_SUCCESSFUL)
237 if (flag == LFR_SUCCESSFUL)
238 {
238 {
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 {
240 {
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 flag = WRONG_APP_DATA;
242 flag = WRONG_APP_DATA;
243 }
243 }
244 }
244 }
245 // sy_lfr_s2_bp_p1
245 // sy_lfr_s2_bp_p1
246 if (flag == LFR_SUCCESSFUL)
246 if (flag == LFR_SUCCESSFUL)
247 {
247 {
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 {
249 {
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 flag = WRONG_APP_DATA;
251 flag = WRONG_APP_DATA;
252 }
252 }
253 }
253 }
254 //******************************************************************
254 //******************************************************************
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 if (flag == LFR_SUCCESSFUL)
256 if (flag == LFR_SUCCESSFUL)
257 {
257 {
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 if (aux > FLOAT_EQUAL_ZERO)
261 if (aux > FLOAT_EQUAL_ZERO)
262 {
262 {
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 flag = LFR_DEFAULT;
264 flag = LFR_DEFAULT;
265 }
265 }
266 }
266 }
267
267
268 // SET THE PARAMETERS
268 // SET THE PARAMETERS
269 if (flag == LFR_SUCCESSFUL)
269 if (flag == LFR_SUCCESSFUL)
270 {
270 {
271 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p0( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
273 }
273 }
274
274
275 return flag;
275 return flag;
276 }
276 }
277
277
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 {
279 {
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 *
281 *
282 * @param TC points to the TeleCommand packet that is being processed
282 * @param TC points to the TeleCommand packet that is being processed
283 * @param queue_id is the id of the queue which handles TM related to this execution step
283 * @param queue_id is the id of the queue which handles TM related to this execution step
284 *
284 *
285 */
285 */
286
286
287 int flag;
287 int flag;
288
288
289 flag = LFR_DEFAULT;
289 flag = LFR_DEFAULT;
290
290
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
292
292
293 return flag;
293 return flag;
294 }
294 }
295
295
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 {
297 {
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 *
299 *
300 * @param TC points to the TeleCommand packet that is being processed
300 * @param TC points to the TeleCommand packet that is being processed
301 * @param queue_id is the id of the queue which handles TM related to this execution step
301 * @param queue_id is the id of the queue which handles TM related to this execution step
302 *
302 *
303 */
303 */
304
304
305 int flag;
305 int flag;
306
306
307 flag = LFR_DEFAULT;
307 flag = LFR_DEFAULT;
308
308
309 flag = set_sy_lfr_fbins( TC );
309 flag = set_sy_lfr_fbins( TC );
310
310
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 merge_fbins_masks();
312 merge_fbins_masks();
313
313
314 return flag;
314 return flag;
315 }
315 }
316
316
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
318 {
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 *
320 *
321 * @param TC points to the TeleCommand packet that is being processed
321 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM related to this execution step
322 * @param queue_id is the id of the queue which handles TM related to this execution step
323 *
323 *
324 */
324 */
325
325
326 int flag;
326 int flag;
327
327
328 flag = LFR_DEFAULT;
328 flag = LFR_DEFAULT;
329
329
330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
331
331
332 if (flag == LFR_SUCCESSFUL)
332 if (flag == LFR_SUCCESSFUL)
333 {
333 {
334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
349
349
350 //****************************
350 //****************************
351 // store PAS filter parameters
351 // store PAS filter parameters
352 // sy_lfr_pas_filter_enabled
352 // sy_lfr_pas_filter_enabled
353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
355 // sy_lfr_pas_filter_modulus
355 // sy_lfr_pas_filter_modulus
356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
357 // sy_lfr_pas_filter_tbad
357 // sy_lfr_pas_filter_tbad
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
360 // sy_lfr_pas_filter_offset
360 // sy_lfr_pas_filter_offset
361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
362 // sy_lfr_pas_filter_shift
362 // sy_lfr_pas_filter_shift
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
364 parameter_dump_packet.sy_lfr_pas_filter_shift );
364 parameter_dump_packet.sy_lfr_pas_filter_shift );
365
365
366 //****************************************************
366 //****************************************************
367 // store the parameter sy_lfr_sc_rw_delta_f as a float
367 // store the parameter sy_lfr_sc_rw_delta_f as a float
368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
370 }
370 }
371
371
372 return flag;
372 return flag;
373 }
373 }
374
374
375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
376 {
376 {
377 /** This function updates the LFR registers with the incoming sbm2 parameters.
377 /** This function updates the LFR registers with the incoming sbm2 parameters.
378 *
378 *
379 * @param TC points to the TeleCommand packet that is being processed
379 * @param TC points to the TeleCommand packet that is being processed
380 * @param queue_id is the id of the queue which handles TM related to this execution step
380 * @param queue_id is the id of the queue which handles TM related to this execution step
381 *
381 *
382 */
382 */
383
383
384 unsigned int address;
384 unsigned int address;
385 rtems_status_code status;
385 rtems_status_code status;
386 unsigned int freq;
386 unsigned int freq;
387 unsigned int bin;
387 unsigned int bin;
388 unsigned int coeff;
388 unsigned int coeff;
389 unsigned char *kCoeffPtr;
389 unsigned char *kCoeffPtr;
390 unsigned char *kCoeffDumpPtr;
390 unsigned char *kCoeffDumpPtr;
391
391
392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
393 // F0 => 11 bins
393 // F0 => 11 bins
394 // F1 => 13 bins
394 // F1 => 13 bins
395 // F2 => 12 bins
395 // F2 => 12 bins
396 // 36 bins to dump in two packets (30 bins max per packet)
396 // 36 bins to dump in two packets (30 bins max per packet)
397
397
398 //*********
398 //*********
399 // PACKET 1
399 // PACKET 1
400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
401 kcoefficients_dump_1.destinationID = TC->sourceID;
401 kcoefficients_dump_1.destinationID = TC->sourceID;
402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
403 for( freq = 0;
403 for( freq = 0;
404 freq < NB_BINS_COMPRESSED_SM_F0;
404 freq < NB_BINS_COMPRESSED_SM_F0;
405 freq++ )
405 freq++ )
406 {
406 {
407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
408 bin = freq;
408 bin = freq;
409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
411 {
411 {
412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
414 ]; // 2 for the kcoeff_frequency
414 ]; // 2 for the kcoeff_frequency
415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
417 }
417 }
418 }
418 }
419 for( freq = NB_BINS_COMPRESSED_SM_F0;
419 for( freq = NB_BINS_COMPRESSED_SM_F0;
420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
421 freq++ )
421 freq++ )
422 {
422 {
423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
427 {
427 {
428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
430 ]; // 2 for the kcoeff_frequency
430 ]; // 2 for the kcoeff_frequency
431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
433 }
433 }
434 }
434 }
435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
436 freq < KCOEFF_BLK_NR_PKT1 ;
436 freq < KCOEFF_BLK_NR_PKT1 ;
437 freq++ )
437 freq++ )
438 {
438 {
439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
443 {
443 {
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 ]; // 2 for the kcoeff_frequency
446 ]; // 2 for the kcoeff_frequency
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 }
449 }
450 }
450 }
451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
457 // SEND DATA
457 // SEND DATA
458 kcoefficient_node_1.status = 1;
458 kcoefficient_node_1.status = 1;
459 address = (unsigned int) &kcoefficient_node_1;
459 address = (unsigned int) &kcoefficient_node_1;
460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
461 if (status != RTEMS_SUCCESSFUL) {
461 if (status != RTEMS_SUCCESSFUL) {
462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
463 }
463 }
464
464
465 //********
465 //********
466 // PACKET 2
466 // PACKET 2
467 // 6 F2 bins
467 // 6 F2 bins
468 kcoefficients_dump_2.destinationID = TC->sourceID;
468 kcoefficients_dump_2.destinationID = TC->sourceID;
469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
470 for( freq = 0;
470 for( freq = 0;
471 freq < KCOEFF_BLK_NR_PKT2;
471 freq < KCOEFF_BLK_NR_PKT2;
472 freq++ )
472 freq++ )
473 {
473 {
474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
475 bin = freq + KCOEFF_BLK_NR_PKT2;
475 bin = freq + KCOEFF_BLK_NR_PKT2;
476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
478 {
478 {
479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
483 }
483 }
484 }
484 }
485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
491 // SEND DATA
491 // SEND DATA
492 kcoefficient_node_2.status = 1;
492 kcoefficient_node_2.status = 1;
493 address = (unsigned int) &kcoefficient_node_2;
493 address = (unsigned int) &kcoefficient_node_2;
494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
495 if (status != RTEMS_SUCCESSFUL) {
495 if (status != RTEMS_SUCCESSFUL) {
496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
497 }
497 }
498
498
499 return status;
499 return status;
500 }
500 }
501
501
502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
503 {
503 {
504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
505 *
505 *
506 * @param queue_id is the id of the queue which handles TM related to this execution step.
506 * @param queue_id is the id of the queue which handles TM related to this execution step.
507 *
507 *
508 * @return RTEMS directive status codes:
508 * @return RTEMS directive status codes:
509 * - RTEMS_SUCCESSFUL - message sent successfully
509 * - RTEMS_SUCCESSFUL - message sent successfully
510 * - RTEMS_INVALID_ID - invalid queue id
510 * - RTEMS_INVALID_ID - invalid queue id
511 * - RTEMS_INVALID_SIZE - invalid message size
511 * - RTEMS_INVALID_SIZE - invalid message size
512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
513 * - RTEMS_UNSATISFIED - out of message buffers
513 * - RTEMS_UNSATISFIED - out of message buffers
514 * - RTEMS_TOO_MANY - queue s limit has been reached
514 * - RTEMS_TOO_MANY - queue s limit has been reached
515 *
515 *
516 */
516 */
517
517
518 int status;
518 int status;
519
519
520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
521 parameter_dump_packet.destinationID = TC->sourceID;
521 parameter_dump_packet.destinationID = TC->sourceID;
522
522
523 // UPDATE TIME
523 // UPDATE TIME
524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
530 // SEND DATA
530 // SEND DATA
531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
533 if (status != RTEMS_SUCCESSFUL) {
533 if (status != RTEMS_SUCCESSFUL) {
534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
535 }
535 }
536
536
537 return status;
537 return status;
538 }
538 }
539
539
540 //***********************
540 //***********************
541 // NORMAL MODE PARAMETERS
541 // NORMAL MODE PARAMETERS
542
542
543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
544 {
544 {
545 unsigned char msb;
545 unsigned char msb;
546 unsigned char lsb;
546 unsigned char lsb;
547 int flag;
547 int flag;
548 float aux;
548 float aux;
549 rtems_status_code status;
549 rtems_status_code status;
550
550
551 unsigned int sy_lfr_n_swf_l;
551 unsigned int sy_lfr_n_swf_l;
552 unsigned int sy_lfr_n_swf_p;
552 unsigned int sy_lfr_n_swf_p;
553 unsigned int sy_lfr_n_asm_p;
553 unsigned int sy_lfr_n_asm_p;
554 unsigned char sy_lfr_n_bp_p0;
554 unsigned char sy_lfr_n_bp_p0;
555 unsigned char sy_lfr_n_bp_p1;
555 unsigned char sy_lfr_n_bp_p1;
556 unsigned char sy_lfr_n_cwf_long_f3;
556 unsigned char sy_lfr_n_cwf_long_f3;
557
557
558 flag = LFR_SUCCESSFUL;
558 flag = LFR_SUCCESSFUL;
559
559
560 //***************
560 //***************
561 // get parameters
561 // get parameters
562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
565
565
566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
569
569
570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
573
573
574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
575
575
576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
577
577
578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
579
579
580 //******************
580 //******************
581 // check consistency
581 // check consistency
582 // sy_lfr_n_swf_l
582 // sy_lfr_n_swf_l
583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
584 {
584 {
585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
586 flag = WRONG_APP_DATA;
586 flag = WRONG_APP_DATA;
587 }
587 }
588 // sy_lfr_n_swf_p
588 // sy_lfr_n_swf_p
589 if (flag == LFR_SUCCESSFUL)
589 if (flag == LFR_SUCCESSFUL)
590 {
590 {
591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
592 {
592 {
593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
594 flag = WRONG_APP_DATA;
594 flag = WRONG_APP_DATA;
595 }
595 }
596 }
596 }
597 // sy_lfr_n_bp_p0
597 // sy_lfr_n_bp_p0
598 if (flag == LFR_SUCCESSFUL)
598 if (flag == LFR_SUCCESSFUL)
599 {
599 {
600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
601 {
601 {
602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
603 flag = WRONG_APP_DATA;
603 flag = WRONG_APP_DATA;
604 }
604 }
605 }
605 }
606 // sy_lfr_n_asm_p
606 // sy_lfr_n_asm_p
607 if (flag == LFR_SUCCESSFUL)
607 if (flag == LFR_SUCCESSFUL)
608 {
608 {
609 if (sy_lfr_n_asm_p == 0)
609 if (sy_lfr_n_asm_p == 0)
610 {
610 {
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
612 flag = WRONG_APP_DATA;
612 flag = WRONG_APP_DATA;
613 }
613 }
614 }
614 }
615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
616 if (flag == LFR_SUCCESSFUL)
616 if (flag == LFR_SUCCESSFUL)
617 {
617 {
618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
619 if (aux > FLOAT_EQUAL_ZERO)
619 if (aux > FLOAT_EQUAL_ZERO)
620 {
620 {
621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
622 flag = WRONG_APP_DATA;
622 flag = WRONG_APP_DATA;
623 }
623 }
624 }
624 }
625 // sy_lfr_n_bp_p1
625 // sy_lfr_n_bp_p1
626 if (flag == LFR_SUCCESSFUL)
626 if (flag == LFR_SUCCESSFUL)
627 {
627 {
628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
629 {
629 {
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
631 flag = WRONG_APP_DATA;
631 flag = WRONG_APP_DATA;
632 }
632 }
633 }
633 }
634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
635 if (flag == LFR_SUCCESSFUL)
635 if (flag == LFR_SUCCESSFUL)
636 {
636 {
637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
638 if (aux > FLOAT_EQUAL_ZERO)
638 if (aux > FLOAT_EQUAL_ZERO)
639 {
639 {
640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
641 flag = LFR_DEFAULT;
641 flag = LFR_DEFAULT;
642 }
642 }
643 }
643 }
644 // sy_lfr_n_cwf_long_f3
644 // sy_lfr_n_cwf_long_f3
645
645
646 return flag;
646 return flag;
647 }
647 }
648
648
649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
650 {
650 {
651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
652 *
652 *
653 * @param TC points to the TeleCommand packet that is being processed
653 * @param TC points to the TeleCommand packet that is being processed
654 * @param queue_id is the id of the queue which handles TM related to this execution step
654 * @param queue_id is the id of the queue which handles TM related to this execution step
655 *
655 *
656 */
656 */
657
657
658 int result;
658 int result;
659
659
660 result = LFR_SUCCESSFUL;
660 result = LFR_SUCCESSFUL;
661
661
662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
664
664
665 return result;
665 return result;
666 }
666 }
667
667
668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
669 {
669 {
670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
671 *
671 *
672 * @param TC points to the TeleCommand packet that is being processed
672 * @param TC points to the TeleCommand packet that is being processed
673 * @param queue_id is the id of the queue which handles TM related to this execution step
673 * @param queue_id is the id of the queue which handles TM related to this execution step
674 *
674 *
675 */
675 */
676
676
677 int result;
677 int result;
678
678
679 result = LFR_SUCCESSFUL;
679 result = LFR_SUCCESSFUL;
680
680
681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
683
683
684 return result;
684 return result;
685 }
685 }
686
686
687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
688 {
688 {
689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
690 *
690 *
691 * @param TC points to the TeleCommand packet that is being processed
691 * @param TC points to the TeleCommand packet that is being processed
692 * @param queue_id is the id of the queue which handles TM related to this execution step
692 * @param queue_id is the id of the queue which handles TM related to this execution step
693 *
693 *
694 */
694 */
695
695
696 int result;
696 int result;
697
697
698 result = LFR_SUCCESSFUL;
698 result = LFR_SUCCESSFUL;
699
699
700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
702
702
703 return result;
703 return result;
704 }
704 }
705
705
706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
707 {
707 {
708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
709 *
709 *
710 * @param TC points to the TeleCommand packet that is being processed
710 * @param TC points to the TeleCommand packet that is being processed
711 * @param queue_id is the id of the queue which handles TM related to this execution step
711 * @param queue_id is the id of the queue which handles TM related to this execution step
712 *
712 *
713 */
713 */
714
714
715 int status;
715 int status;
716
716
717 status = LFR_SUCCESSFUL;
717 status = LFR_SUCCESSFUL;
718
718
719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
720
720
721 return status;
721 return status;
722 }
722 }
723
723
724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
725 {
725 {
726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
727 *
727 *
728 * @param TC points to the TeleCommand packet that is being processed
728 * @param TC points to the TeleCommand packet that is being processed
729 * @param queue_id is the id of the queue which handles TM related to this execution step
729 * @param queue_id is the id of the queue which handles TM related to this execution step
730 *
730 *
731 */
731 */
732
732
733 int status;
733 int status;
734
734
735 status = LFR_SUCCESSFUL;
735 status = LFR_SUCCESSFUL;
736
736
737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
738
738
739 return status;
739 return status;
740 }
740 }
741
741
742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
743 {
743 {
744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
745 *
745 *
746 * @param TC points to the TeleCommand packet that is being processed
746 * @param TC points to the TeleCommand packet that is being processed
747 * @param queue_id is the id of the queue which handles TM related to this execution step
747 * @param queue_id is the id of the queue which handles TM related to this execution step
748 *
748 *
749 */
749 */
750
750
751 int status;
751 int status;
752
752
753 status = LFR_SUCCESSFUL;
753 status = LFR_SUCCESSFUL;
754
754
755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
756
756
757 return status;
757 return status;
758 }
758 }
759
759
760 //**********************
760 //**********************
761 // BURST MODE PARAMETERS
761 // BURST MODE PARAMETERS
762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
763 {
763 {
764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
765 *
765 *
766 * @param TC points to the TeleCommand packet that is being processed
766 * @param TC points to the TeleCommand packet that is being processed
767 * @param queue_id is the id of the queue which handles TM related to this execution step
767 * @param queue_id is the id of the queue which handles TM related to this execution step
768 *
768 *
769 */
769 */
770
770
771 int status;
771 int status;
772
772
773 status = LFR_SUCCESSFUL;
773 status = LFR_SUCCESSFUL;
774
774
775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
776
776
777 return status;
777 return status;
778 }
778 }
779
779
780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
781 {
781 {
782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
783 *
783 *
784 * @param TC points to the TeleCommand packet that is being processed
784 * @param TC points to the TeleCommand packet that is being processed
785 * @param queue_id is the id of the queue which handles TM related to this execution step
785 * @param queue_id is the id of the queue which handles TM related to this execution step
786 *
786 *
787 */
787 */
788
788
789 int status;
789 int status;
790
790
791 status = LFR_SUCCESSFUL;
791 status = LFR_SUCCESSFUL;
792
792
793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
794
794
795 return status;
795 return status;
796 }
796 }
797
797
798 //*********************
798 //*********************
799 // SBM1 MODE PARAMETERS
799 // SBM1 MODE PARAMETERS
800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
801 {
801 {
802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
803 *
803 *
804 * @param TC points to the TeleCommand packet that is being processed
804 * @param TC points to the TeleCommand packet that is being processed
805 * @param queue_id is the id of the queue which handles TM related to this execution step
805 * @param queue_id is the id of the queue which handles TM related to this execution step
806 *
806 *
807 */
807 */
808
808
809 int status;
809 int status;
810
810
811 status = LFR_SUCCESSFUL;
811 status = LFR_SUCCESSFUL;
812
812
813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
814
814
815 return status;
815 return status;
816 }
816 }
817
817
818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
819 {
819 {
820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
821 *
821 *
822 * @param TC points to the TeleCommand packet that is being processed
822 * @param TC points to the TeleCommand packet that is being processed
823 * @param queue_id is the id of the queue which handles TM related to this execution step
823 * @param queue_id is the id of the queue which handles TM related to this execution step
824 *
824 *
825 */
825 */
826
826
827 int status;
827 int status;
828
828
829 status = LFR_SUCCESSFUL;
829 status = LFR_SUCCESSFUL;
830
830
831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
832
832
833 return status;
833 return status;
834 }
834 }
835
835
836 //*********************
836 //*********************
837 // SBM2 MODE PARAMETERS
837 // SBM2 MODE PARAMETERS
838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
839 {
839 {
840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
841 *
841 *
842 * @param TC points to the TeleCommand packet that is being processed
842 * @param TC points to the TeleCommand packet that is being processed
843 * @param queue_id is the id of the queue which handles TM related to this execution step
843 * @param queue_id is the id of the queue which handles TM related to this execution step
844 *
844 *
845 */
845 */
846
846
847 int status;
847 int status;
848
848
849 status = LFR_SUCCESSFUL;
849 status = LFR_SUCCESSFUL;
850
850
851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
852
852
853 return status;
853 return status;
854 }
854 }
855
855
856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
857 {
857 {
858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
859 *
859 *
860 * @param TC points to the TeleCommand packet that is being processed
860 * @param TC points to the TeleCommand packet that is being processed
861 * @param queue_id is the id of the queue which handles TM related to this execution step
861 * @param queue_id is the id of the queue which handles TM related to this execution step
862 *
862 *
863 */
863 */
864
864
865 int status;
865 int status;
866
866
867 status = LFR_SUCCESSFUL;
867 status = LFR_SUCCESSFUL;
868
868
869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
870
870
871 return status;
871 return status;
872 }
872 }
873
873
874 //*******************
874 //*******************
875 // TC_LFR_UPDATE_INFO
875 // TC_LFR_UPDATE_INFO
876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
877 {
877 {
878 unsigned int status;
878 unsigned int status;
879
879
880 status = LFR_DEFAULT;
880 status = LFR_DEFAULT;
881
881
882 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
882 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
883 || (mode == LFR_MODE_BURST)
883 || (mode == LFR_MODE_BURST)
884 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
884 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
885 {
885 {
886 status = LFR_SUCCESSFUL;
886 status = LFR_SUCCESSFUL;
887 }
887 }
888 else
888 else
889 {
889 {
890 status = LFR_DEFAULT;
890 status = LFR_DEFAULT;
891 }
891 }
892
892
893 return status;
893 return status;
894 }
894 }
895
895
896 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
896 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
897 {
897 {
898 unsigned int status;
898 unsigned int status;
899
899
900 status = LFR_DEFAULT;
900 status = LFR_DEFAULT;
901
901
902 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
902 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
903 || (mode == TDS_MODE_BURST)
903 || (mode == TDS_MODE_BURST)
904 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
904 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
905 || (mode == TDS_MODE_LFM))
905 || (mode == TDS_MODE_LFM))
906 {
906 {
907 status = LFR_SUCCESSFUL;
907 status = LFR_SUCCESSFUL;
908 }
908 }
909 else
909 else
910 {
910 {
911 status = LFR_DEFAULT;
911 status = LFR_DEFAULT;
912 }
912 }
913
913
914 return status;
914 return status;
915 }
915 }
916
916
917 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
917 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
918 {
918 {
919 unsigned int status;
919 unsigned int status;
920
920
921 status = LFR_DEFAULT;
921 status = LFR_DEFAULT;
922
922
923 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
923 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
924 || (mode == THR_MODE_BURST))
924 || (mode == THR_MODE_BURST))
925 {
925 {
926 status = LFR_SUCCESSFUL;
926 status = LFR_SUCCESSFUL;
927 }
927 }
928 else
928 else
929 {
929 {
930 status = LFR_DEFAULT;
930 status = LFR_DEFAULT;
931 }
931 }
932
932
933 return status;
933 return status;
934 }
934 }
935
935
936 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
936 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
937 {
937 {
938 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
938 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
939 *
939 *
940 * @param TC points to the TeleCommand packet that is being processed
940 * @param TC points to the TeleCommand packet that is being processed
941 *
941 *
942 */
942 */
943
943
944 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
944 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
945
945
946 bytePosPtr = (unsigned char *) &TC->packetID;
946 bytePosPtr = (unsigned char *) &TC->packetID;
947
947
948 // cp_rpw_sc_rw1_f1
948 // cp_rpw_sc_rw1_f1
949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
951
951
952 // cp_rpw_sc_rw1_f2
952 // cp_rpw_sc_rw1_f2
953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
955
955
956 // cp_rpw_sc_rw2_f1
956 // cp_rpw_sc_rw2_f1
957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
959
959
960 // cp_rpw_sc_rw2_f2
960 // cp_rpw_sc_rw2_f2
961 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
961 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
962 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
962 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
963
963
964 // cp_rpw_sc_rw3_f1
964 // cp_rpw_sc_rw3_f1
965 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
965 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
966 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
966 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
967
967
968 // cp_rpw_sc_rw3_f2
968 // cp_rpw_sc_rw3_f2
969 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
969 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
970 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
970 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
971
971
972 // cp_rpw_sc_rw4_f1
972 // cp_rpw_sc_rw4_f1
973 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
973 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
974 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
974 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
975
975
976 // cp_rpw_sc_rw4_f2
976 // cp_rpw_sc_rw4_f2
977 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
977 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
978 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
978 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
979 }
979 }
980
980
981 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
981 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
982 {
982 {
983 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
983 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
984 *
984 *
985 * @param fbins_mask
985 * @param fbins_mask
986 * @param rw_f is the reaction wheel frequency to filter
986 * @param rw_f is the reaction wheel frequency to filter
987 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
987 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
988 * @param flag [true] filtering enabled [false] filtering disabled
988 * @param flag [true] filtering enabled [false] filtering disabled
989 *
989 *
990 * @return void
990 * @return void
991 *
991 *
992 */
992 */
993
993
994 float f_RW_min;
994 float f_RW_min;
995 float f_RW_MAX;
995 float f_RW_MAX;
996 float fi_min;
996 float fi_min;
997 float fi_MAX;
997 float fi_MAX;
998 float fi;
998 float fi;
999 float deltaBelow;
999 float deltaBelow;
1000 float deltaAbove;
1000 float deltaAbove;
1001 int binBelow;
1001 int binBelow;
1002 int binAbove;
1002 int binAbove;
1003 int closestBin;
1003 int closestBin;
1004 unsigned int whichByte;
1004 unsigned int whichByte;
1005 int selectedByte;
1005 int selectedByte;
1006 int bin;
1006 int bin;
1007 int binToRemove[NB_BINS_TO_REMOVE];
1007 int binToRemove[NB_BINS_TO_REMOVE];
1008 int k;
1008 int k;
1009
1009
1010 closestBin = 0;
1010 closestBin = 0;
1011 whichByte = 0;
1011 whichByte = 0;
1012 bin = 0;
1012 bin = 0;
1013
1013
1014 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1014 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1015 {
1015 {
1016 binToRemove[k] = -1;
1016 binToRemove[k] = -1;
1017 }
1017 }
1018
1018
1019 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1019 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1020 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1020 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1021 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1021 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1022
1022
1023 // compute the index of the frequency bin immediately below rw_f
1023 // compute the index of the frequency bin immediately below rw_f
1024 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1024 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1025 deltaBelow = rw_f - binBelow * deltaFreq;
1025 deltaBelow = rw_f - binBelow * deltaFreq;
1026
1026
1027 // compute the index of the frequency bin immediately above rw_f
1027 // compute the index of the frequency bin immediately above rw_f
1028 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1028 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1029 deltaAbove = binAbove * deltaFreq - rw_f;
1029 deltaAbove = binAbove * deltaFreq - rw_f;
1030
1030
1031 // search the closest bin
1031 // search the closest bin
1032 if (deltaAbove > deltaBelow)
1032 if (deltaAbove > deltaBelow)
1033 {
1033 {
1034 closestBin = binBelow;
1034 closestBin = binBelow;
1035 }
1035 }
1036 else
1036 else
1037 {
1037 {
1038 closestBin = binAbove;
1038 closestBin = binAbove;
1039 }
1039 }
1040
1040
1041 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1041 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1042 fi = closestBin * deltaFreq;
1042 fi = closestBin * deltaFreq;
1043 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1043 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1044 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1044 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1045
1045
1046 //**************************************************************************************
1046 //**************************************************************************************
1047 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1047 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1048 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1048 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1049 //**************************************************************************************
1049 //**************************************************************************************
1050
1050
1051 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1051 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1052 // => remove f_(i), f_(i-1) and f_(i+1)
1052 // => remove f_(i), f_(i-1) and f_(i+1)
1053 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1053 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1054 {
1054 {
1055 binToRemove[0] = (closestBin - 1) - 1;
1055 binToRemove[0] = (closestBin - 1) - 1;
1056 binToRemove[1] = (closestBin) - 1;
1056 binToRemove[1] = (closestBin) - 1;
1057 binToRemove[2] = (closestBin + 1) - 1;
1057 binToRemove[2] = (closestBin + 1) - 1;
1058 }
1058 }
1059 // 2. ELSE
1059 // 2. ELSE
1060 // => remove the two f_(i) which are around f_RW
1060 // => remove the two f_(i) which are around f_RW
1061 else
1061 else
1062 {
1062 {
1063 binToRemove[0] = (binBelow) - 1;
1063 binToRemove[0] = (binBelow) - 1;
1064 binToRemove[1] = (binAbove) - 1;
1064 binToRemove[1] = (binAbove) - 1;
1065 binToRemove[2] = (-1);
1065 binToRemove[2] = (-1);
1066 }
1066 }
1067
1067
1068 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1068 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1069 {
1069 {
1070 bin = binToRemove[k];
1070 bin = binToRemove[k];
1071 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1071 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1072 {
1072 {
1073 if (flag == 1)
1073 if (flag == 1)
1074 {
1074 {
1075 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1075 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1076 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1076 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1077 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1077 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1078 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1078 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1079 }
1079 }
1080 }
1080 }
1081 }
1081 }
1082 }
1082 }
1083
1083
1084 void build_sy_lfr_rw_mask( unsigned int channel )
1084 void build_sy_lfr_rw_mask( unsigned int channel )
1085 {
1085 {
1086 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1086 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1087 unsigned char *maskPtr;
1087 unsigned char *maskPtr;
1088 double deltaF;
1088 double deltaF;
1089 unsigned k;
1089 unsigned k;
1090
1090
1091 k = 0;
1091 k = 0;
1092
1092
1093 maskPtr = NULL;
1093 maskPtr = NULL;
1094 deltaF = DELTAF_F2;
1094 deltaF = DELTAF_F2;
1095
1095
1096 switch (channel)
1096 switch (channel)
1097 {
1097 {
1098 case CHANNELF0:
1098 case CHANNELF0:
1099 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1099 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1100 deltaF = DELTAF_F0;
1100 deltaF = DELTAF_F0;
1101 break;
1101 break;
1102 case CHANNELF1:
1102 case CHANNELF1:
1103 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1103 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1104 deltaF = DELTAF_F1;
1104 deltaF = DELTAF_F1;
1105 break;
1105 break;
1106 case CHANNELF2:
1106 case CHANNELF2:
1107 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1107 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1108 deltaF = DELTAF_F2;
1108 deltaF = DELTAF_F2;
1109 break;
1109 break;
1110 default:
1110 default:
1111 break;
1111 break;
1112 }
1112 }
1113
1113
1114 for (k = 0; k < BYTES_PER_MASK; k++)
1114 for (k = 0; k < BYTES_PER_MASK; k++)
1115 {
1115 {
1116 local_rw_fbins_mask[k] = INT8_ALL_F;
1116 local_rw_fbins_mask[k] = INT8_ALL_F;
1117 }
1117 }
1118
1118
1119 // RW1 F1
1119 // RW1 F1
1120 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1120 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1121
1121
1122 // RW1 F2
1122 // RW1 F2
1123 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1123 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1124
1124
1125 // RW2 F1
1125 // RW2 F1
1126 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1126 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1127
1127
1128 // RW2 F2
1128 // RW2 F2
1129 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1129 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1130
1130
1131 // RW3 F1
1131 // RW3 F1
1132 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1132 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1133
1133
1134 // RW3 F2
1134 // RW3 F2
1135 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1135 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1136
1136
1137 // RW4 F1
1137 // RW4 F1
1138 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1138 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1139
1139
1140 // RW4 F2
1140 // RW4 F2
1141 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1141 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1142
1142
1143 // update the value of the fbins related to reaction wheels frequency filtering
1143 // update the value of the fbins related to reaction wheels frequency filtering
1144 if (maskPtr != NULL)
1144 if (maskPtr != NULL)
1145 {
1145 {
1146 for (k = 0; k < BYTES_PER_MASK; k++)
1146 for (k = 0; k < BYTES_PER_MASK; k++)
1147 {
1147 {
1148 maskPtr[k] = local_rw_fbins_mask[k];
1148 maskPtr[k] = local_rw_fbins_mask[k];
1149 }
1149 }
1150 }
1150 }
1151 }
1151 }
1152
1152
1153 void build_sy_lfr_rw_masks( void )
1153 void build_sy_lfr_rw_masks( void )
1154 {
1154 {
1155 build_sy_lfr_rw_mask( CHANNELF0 );
1155 build_sy_lfr_rw_mask( CHANNELF0 );
1156 build_sy_lfr_rw_mask( CHANNELF1 );
1156 build_sy_lfr_rw_mask( CHANNELF1 );
1157 build_sy_lfr_rw_mask( CHANNELF2 );
1157 build_sy_lfr_rw_mask( CHANNELF2 );
1158 }
1158 }
1159
1159
1160 void merge_fbins_masks( void )
1160 void merge_fbins_masks( void )
1161 {
1161 {
1162 unsigned char k;
1162 unsigned char k;
1163
1163
1164 unsigned char *fbins_f0;
1164 unsigned char *fbins_f0;
1165 unsigned char *fbins_f1;
1165 unsigned char *fbins_f1;
1166 unsigned char *fbins_f2;
1166 unsigned char *fbins_f2;
1167 unsigned char *rw_mask_f0;
1167 unsigned char *rw_mask_f0;
1168 unsigned char *rw_mask_f1;
1168 unsigned char *rw_mask_f1;
1169 unsigned char *rw_mask_f2;
1169 unsigned char *rw_mask_f2;
1170
1170
1171 fbins_f0 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
1171 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1172 fbins_f1 = parameter_dump_packet.sy_lfr_fbins.fx.f1_word1;
1172 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1173 fbins_f2 = parameter_dump_packet.sy_lfr_fbins.fx.f2_word1;
1173 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1174 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1174 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1175 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1175 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1176 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1176 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1177
1177
1178 for( k=0; k < BYTES_PER_MASK; k++ )
1178 for( k=0; k < BYTES_PER_MASK; k++ )
1179 {
1179 {
1180 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1180 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1181 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1181 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1182 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1182 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1183 }
1183 }
1184 }
1184 }
1185
1185
1186 //***********
1186 //***********
1187 // FBINS MASK
1187 // FBINS MASK
1188
1188
1189 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1189 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1190 {
1190 {
1191 int status;
1191 int status;
1192 unsigned int k;
1192 unsigned int k;
1193 unsigned char *fbins_mask_dump;
1193 unsigned char *fbins_mask_dump;
1194 unsigned char *fbins_mask_TC;
1194 unsigned char *fbins_mask_TC;
1195
1195
1196 status = LFR_SUCCESSFUL;
1196 status = LFR_SUCCESSFUL;
1197
1197
1198 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins.raw;
1198 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1199 fbins_mask_TC = TC->dataAndCRC;
1199 fbins_mask_TC = TC->dataAndCRC;
1200
1200
1201 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1201 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1202 {
1202 {
1203 fbins_mask_dump[k] = fbins_mask_TC[k];
1203 fbins_mask_dump[k] = fbins_mask_TC[k];
1204 }
1204 }
1205
1205
1206 return status;
1206 return status;
1207 }
1207 }
1208
1208
1209 //***************************
1209 //***************************
1210 // TC_LFR_LOAD_PAS_FILTER_PAR
1210 // TC_LFR_LOAD_PAS_FILTER_PAR
1211
1211
1212 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1212 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1213 {
1213 {
1214 int flag;
1214 int flag;
1215 rtems_status_code status;
1215 rtems_status_code status;
1216
1216
1217 unsigned char sy_lfr_pas_filter_enabled;
1217 unsigned char sy_lfr_pas_filter_enabled;
1218 unsigned char sy_lfr_pas_filter_modulus;
1218 unsigned char sy_lfr_pas_filter_modulus;
1219 float sy_lfr_pas_filter_tbad;
1219 float sy_lfr_pas_filter_tbad;
1220 unsigned char sy_lfr_pas_filter_offset;
1220 unsigned char sy_lfr_pas_filter_offset;
1221 float sy_lfr_pas_filter_shift;
1221 float sy_lfr_pas_filter_shift;
1222 float sy_lfr_sc_rw_delta_f;
1222 float sy_lfr_sc_rw_delta_f;
1223 char *parPtr;
1223 char *parPtr;
1224
1224
1225 flag = LFR_SUCCESSFUL;
1225 flag = LFR_SUCCESSFUL;
1226 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1226 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1227 sy_lfr_pas_filter_shift = INIT_FLOAT;
1227 sy_lfr_pas_filter_shift = INIT_FLOAT;
1228 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1228 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1229 parPtr = NULL;
1229 parPtr = NULL;
1230
1230
1231 //***************
1231 //***************
1232 // get parameters
1232 // get parameters
1233 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1233 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1234 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1234 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1235 copyFloatByChar(
1235 copyFloatByChar(
1236 (unsigned char*) &sy_lfr_pas_filter_tbad,
1236 (unsigned char*) &sy_lfr_pas_filter_tbad,
1237 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1237 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1238 );
1238 );
1239 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1239 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1240 copyFloatByChar(
1240 copyFloatByChar(
1241 (unsigned char*) &sy_lfr_pas_filter_shift,
1241 (unsigned char*) &sy_lfr_pas_filter_shift,
1242 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1242 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1243 );
1243 );
1244 copyFloatByChar(
1244 copyFloatByChar(
1245 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1245 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1246 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1246 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1247 );
1247 );
1248
1248
1249 //******************
1249 //******************
1250 // CHECK CONSISTENCY
1250 // CHECK CONSISTENCY
1251
1251
1252 //**************************
1252 //**************************
1253 // sy_lfr_pas_filter_enabled
1253 // sy_lfr_pas_filter_enabled
1254 // nothing to check, value is 0 or 1
1254 // nothing to check, value is 0 or 1
1255
1255
1256 //**************************
1256 //**************************
1257 // sy_lfr_pas_filter_modulus
1257 // sy_lfr_pas_filter_modulus
1258 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1258 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1259 {
1259 {
1260 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1260 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1261 flag = WRONG_APP_DATA;
1261 flag = WRONG_APP_DATA;
1262 }
1262 }
1263
1263
1264 //***********************
1264 //***********************
1265 // sy_lfr_pas_filter_tbad
1265 // sy_lfr_pas_filter_tbad
1266 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1266 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1267 {
1267 {
1268 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1268 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1269 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1269 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1270 flag = WRONG_APP_DATA;
1270 flag = WRONG_APP_DATA;
1271 }
1271 }
1272
1272
1273 //*************************
1273 //*************************
1274 // sy_lfr_pas_filter_offset
1274 // sy_lfr_pas_filter_offset
1275 if (flag == LFR_SUCCESSFUL)
1275 if (flag == LFR_SUCCESSFUL)
1276 {
1276 {
1277 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1277 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1278 {
1278 {
1279 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1279 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1280 flag = WRONG_APP_DATA;
1280 flag = WRONG_APP_DATA;
1281 }
1281 }
1282 }
1282 }
1283
1283
1284 //************************
1284 //************************
1285 // sy_lfr_pas_filter_shift
1285 // sy_lfr_pas_filter_shift
1286 if (flag == LFR_SUCCESSFUL)
1286 if (flag == LFR_SUCCESSFUL)
1287 {
1287 {
1288 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1288 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1289 {
1289 {
1290 parPtr = (char*) &sy_lfr_pas_filter_shift;
1290 parPtr = (char*) &sy_lfr_pas_filter_shift;
1291 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1291 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1292 flag = WRONG_APP_DATA;
1292 flag = WRONG_APP_DATA;
1293 }
1293 }
1294 }
1294 }
1295
1295
1296 //*************************************
1296 //*************************************
1297 // check global coherency of the values
1297 // check global coherency of the values
1298 if (flag == LFR_SUCCESSFUL)
1298 if (flag == LFR_SUCCESSFUL)
1299 {
1299 {
1300 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1300 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1301 {
1301 {
1302 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1302 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1303 flag = WRONG_APP_DATA;
1303 flag = WRONG_APP_DATA;
1304 }
1304 }
1305 }
1305 }
1306
1306
1307 //*********************
1307 //*********************
1308 // sy_lfr_sc_rw_delta_f
1308 // sy_lfr_sc_rw_delta_f
1309 // nothing to check, no default value in the ICD
1309 // nothing to check, no default value in the ICD
1310
1310
1311 return flag;
1311 return flag;
1312 }
1312 }
1313
1313
1314 //**************
1314 //**************
1315 // KCOEFFICIENTS
1315 // KCOEFFICIENTS
1316 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1316 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1317 {
1317 {
1318 unsigned int kcoeff;
1318 unsigned int kcoeff;
1319 unsigned short sy_lfr_kcoeff_frequency;
1319 unsigned short sy_lfr_kcoeff_frequency;
1320 unsigned short bin;
1320 unsigned short bin;
1321 unsigned short *freqPtr;
1321 unsigned short *freqPtr;
1322 float *kcoeffPtr_norm;
1322 float *kcoeffPtr_norm;
1323 float *kcoeffPtr_sbm;
1323 float *kcoeffPtr_sbm;
1324 int status;
1324 int status;
1325 unsigned char *kcoeffLoadPtr;
1325 unsigned char *kcoeffLoadPtr;
1326 unsigned char *kcoeffNormPtr;
1326 unsigned char *kcoeffNormPtr;
1327 unsigned char *kcoeffSbmPtr_a;
1327 unsigned char *kcoeffSbmPtr_a;
1328 unsigned char *kcoeffSbmPtr_b;
1328 unsigned char *kcoeffSbmPtr_b;
1329
1329
1330 status = LFR_SUCCESSFUL;
1330 status = LFR_SUCCESSFUL;
1331
1331
1332 kcoeffPtr_norm = NULL;
1332 kcoeffPtr_norm = NULL;
1333 kcoeffPtr_sbm = NULL;
1333 kcoeffPtr_sbm = NULL;
1334 bin = 0;
1334 bin = 0;
1335
1335
1336 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1336 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1337 sy_lfr_kcoeff_frequency = *freqPtr;
1337 sy_lfr_kcoeff_frequency = *freqPtr;
1338
1338
1339 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1339 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1340 {
1340 {
1341 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1341 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1342 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1342 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1343 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1343 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1344 status = LFR_DEFAULT;
1344 status = LFR_DEFAULT;
1345 }
1345 }
1346 else
1346 else
1347 {
1347 {
1348 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1348 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1349 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1349 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1350 {
1350 {
1351 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1351 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1352 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1352 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1353 bin = sy_lfr_kcoeff_frequency;
1353 bin = sy_lfr_kcoeff_frequency;
1354 }
1354 }
1355 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1355 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1356 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1356 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1357 {
1357 {
1358 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1358 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1359 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1359 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1360 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1360 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1361 }
1361 }
1362 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1362 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1363 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1363 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1364 {
1364 {
1365 kcoeffPtr_norm = k_coeff_intercalib_f2;
1365 kcoeffPtr_norm = k_coeff_intercalib_f2;
1366 kcoeffPtr_sbm = NULL;
1366 kcoeffPtr_sbm = NULL;
1367 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1367 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1368 }
1368 }
1369 }
1369 }
1370
1370
1371 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1371 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1372 {
1372 {
1373 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1373 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1374 {
1374 {
1375 // destination
1375 // destination
1376 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1376 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1377 // source
1377 // source
1378 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1378 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1379 // copy source to destination
1379 // copy source to destination
1380 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1380 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1381 }
1381 }
1382 }
1382 }
1383
1383
1384 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1384 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1385 {
1385 {
1386 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1386 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1387 {
1387 {
1388 // destination
1388 // destination
1389 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1389 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1390 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1390 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1391 // source
1391 // source
1392 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1392 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1393 // copy source to destination
1393 // copy source to destination
1394 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1394 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1395 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1395 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1396 }
1396 }
1397 }
1397 }
1398
1398
1399 // print_k_coeff();
1399 // print_k_coeff();
1400
1400
1401 return status;
1401 return status;
1402 }
1402 }
1403
1403
1404 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1404 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1405 {
1405 {
1406 destination[BYTE_0] = source[BYTE_0];
1406 destination[BYTE_0] = source[BYTE_0];
1407 destination[BYTE_1] = source[BYTE_1];
1407 destination[BYTE_1] = source[BYTE_1];
1408 destination[BYTE_2] = source[BYTE_2];
1408 destination[BYTE_2] = source[BYTE_2];
1409 destination[BYTE_3] = source[BYTE_3];
1409 destination[BYTE_3] = source[BYTE_3];
1410 }
1410 }
1411
1411
1412 void floatToChar( float value, unsigned char* ptr)
1412 void floatToChar( float value, unsigned char* ptr)
1413 {
1413 {
1414 unsigned char* valuePtr;
1414 unsigned char* valuePtr;
1415
1415
1416 valuePtr = (unsigned char*) &value;
1416 valuePtr = (unsigned char*) &value;
1417 ptr[BYTE_0] = valuePtr[BYTE_0];
1417 ptr[BYTE_0] = valuePtr[BYTE_0];
1418 ptr[BYTE_1] = valuePtr[BYTE_1];
1418 ptr[BYTE_1] = valuePtr[BYTE_1];
1419 ptr[BYTE_2] = valuePtr[BYTE_2];
1419 ptr[BYTE_2] = valuePtr[BYTE_2];
1420 ptr[BYTE_3] = valuePtr[BYTE_3];
1420 ptr[BYTE_3] = valuePtr[BYTE_3];
1421 }
1421 }
1422
1422
1423 //**********
1423 //**********
1424 // init dump
1424 // init dump
1425
1425
1426 void init_parameter_dump( void )
1426 void init_parameter_dump( void )
1427 {
1427 {
1428 /** This function initialize the parameter_dump_packet global variable with default values.
1428 /** This function initialize the parameter_dump_packet global variable with default values.
1429 *
1429 *
1430 */
1430 */
1431
1431
1432 unsigned int k;
1432 unsigned int k;
1433
1433
1434 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1434 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1435 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1435 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1436 parameter_dump_packet.reserved = CCSDS_RESERVED;
1436 parameter_dump_packet.reserved = CCSDS_RESERVED;
1437 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1437 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1438 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1438 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1439 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1439 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1440 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1440 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1441 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1441 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1442 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1442 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1443 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1443 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1444 // DATA FIELD HEADER
1444 // DATA FIELD HEADER
1445 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1445 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1446 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1446 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1447 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1447 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1448 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1448 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1449 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1449 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1450 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1450 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1451 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1451 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1452 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1452 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1453 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1453 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1454 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1454 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1455 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1455 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1456
1456
1457 //******************
1457 //******************
1458 // COMMON PARAMETERS
1458 // COMMON PARAMETERS
1459 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1459 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1460 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1460 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1461
1461
1462 //******************
1462 //******************
1463 // NORMAL PARAMETERS
1463 // NORMAL PARAMETERS
1464 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1464 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1465 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1465 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1466 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1466 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1467 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1467 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1468 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1468 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1469 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1469 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1470 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1470 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1471 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1471 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1472 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1472 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1473
1473
1474 //*****************
1474 //*****************
1475 // BURST PARAMETERS
1475 // BURST PARAMETERS
1476 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1476 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1477 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1477 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1478
1478
1479 //****************
1479 //****************
1480 // SBM1 PARAMETERS
1480 // SBM1 PARAMETERS
1481 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1481 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1482 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1482 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1483
1483
1484 //****************
1484 //****************
1485 // SBM2 PARAMETERS
1485 // SBM2 PARAMETERS
1486 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1486 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1487 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1487 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1488
1488
1489 //************
1489 //************
1490 // FBINS MASKS
1490 // FBINS MASKS
1491 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1491 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1492 {
1492 {
1493 parameter_dump_packet.sy_lfr_fbins.raw[k] = INT8_ALL_F;
1493 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1494 }
1494 }
1495
1495
1496 // PAS FILTER PARAMETERS
1496 // PAS FILTER PARAMETERS
1497 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1497 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1498 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1498 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1499 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1499 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1500 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1500 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1501 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1501 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1502 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1502 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1503 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1503 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1504
1504
1505 // LFR_RW_MASK
1505 // LFR_RW_MASK
1506 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1506 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1507 {
1507 {
1508 parameter_dump_packet.sy_lfr_rw_mask.raw[k] = INT8_ALL_F;
1508 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1509 }
1509 }
1510
1510
1511 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1511 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1512 merge_fbins_masks();
1512 merge_fbins_masks();
1513 }
1513 }
1514
1514
1515 void init_kcoefficients_dump( void )
1515 void init_kcoefficients_dump( void )
1516 {
1516 {
1517 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1517 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1518 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1518 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1519
1519
1520 kcoefficient_node_1.previous = NULL;
1520 kcoefficient_node_1.previous = NULL;
1521 kcoefficient_node_1.next = NULL;
1521 kcoefficient_node_1.next = NULL;
1522 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1522 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1523 kcoefficient_node_1.coarseTime = INIT_CHAR;
1523 kcoefficient_node_1.coarseTime = INIT_CHAR;
1524 kcoefficient_node_1.fineTime = INIT_CHAR;
1524 kcoefficient_node_1.fineTime = INIT_CHAR;
1525 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1525 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1526 kcoefficient_node_1.status = INIT_CHAR;
1526 kcoefficient_node_1.status = INIT_CHAR;
1527
1527
1528 kcoefficient_node_2.previous = NULL;
1528 kcoefficient_node_2.previous = NULL;
1529 kcoefficient_node_2.next = NULL;
1529 kcoefficient_node_2.next = NULL;
1530 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1530 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1531 kcoefficient_node_2.coarseTime = INIT_CHAR;
1531 kcoefficient_node_2.coarseTime = INIT_CHAR;
1532 kcoefficient_node_2.fineTime = INIT_CHAR;
1532 kcoefficient_node_2.fineTime = INIT_CHAR;
1533 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1533 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1534 kcoefficient_node_2.status = INIT_CHAR;
1534 kcoefficient_node_2.status = INIT_CHAR;
1535 }
1535 }
1536
1536
1537 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1537 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1538 {
1538 {
1539 unsigned int k;
1539 unsigned int k;
1540 unsigned int packetLength;
1540 unsigned int packetLength;
1541
1541
1542 packetLength =
1542 packetLength =
1543 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1543 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1544
1544
1545 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1545 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1546 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1546 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1547 kcoefficients_dump->reserved = CCSDS_RESERVED;
1547 kcoefficients_dump->reserved = CCSDS_RESERVED;
1548 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1548 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1549 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1549 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1550 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1550 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1551 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1551 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1552 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1552 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1553 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1553 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1554 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1554 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1555 // DATA FIELD HEADER
1555 // DATA FIELD HEADER
1556 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1556 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1557 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1557 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1558 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1558 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1559 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1559 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1560 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1560 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1561 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1561 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1562 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1562 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1563 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1563 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1564 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1564 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1565 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1565 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1566 kcoefficients_dump->sid = SID_K_DUMP;
1566 kcoefficients_dump->sid = SID_K_DUMP;
1567
1567
1568 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1568 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1569 kcoefficients_dump->pkt_nr = PKTNR_1;
1569 kcoefficients_dump->pkt_nr = PKTNR_1;
1570 kcoefficients_dump->blk_nr = blk_nr;
1570 kcoefficients_dump->blk_nr = blk_nr;
1571
1571
1572 //******************
1572 //******************
1573 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1573 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1574 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1574 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1575 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1575 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1576 {
1576 {
1577 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1577 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1578 }
1578 }
1579 }
1579 }
1580
1580
1581 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1581 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1582 {
1582 {
1583 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1583 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1584 *
1584 *
1585 * @param packet_sequence_control points to the packet sequence control which will be incremented
1585 * @param packet_sequence_control points to the packet sequence control which will be incremented
1586 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1586 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1587 *
1587 *
1588 * If the destination ID is not known, a dedicated counter is incremented.
1588 * If the destination ID is not known, a dedicated counter is incremented.
1589 *
1589 *
1590 */
1590 */
1591
1591
1592 unsigned short sequence_cnt;
1592 unsigned short sequence_cnt;
1593 unsigned short segmentation_grouping_flag;
1593 unsigned short segmentation_grouping_flag;
1594 unsigned short new_packet_sequence_control;
1594 unsigned short new_packet_sequence_control;
1595 unsigned char i;
1595 unsigned char i;
1596
1596
1597 switch (destination_id)
1597 switch (destination_id)
1598 {
1598 {
1599 case SID_TC_GROUND:
1599 case SID_TC_GROUND:
1600 i = GROUND;
1600 i = GROUND;
1601 break;
1601 break;
1602 case SID_TC_MISSION_TIMELINE:
1602 case SID_TC_MISSION_TIMELINE:
1603 i = MISSION_TIMELINE;
1603 i = MISSION_TIMELINE;
1604 break;
1604 break;
1605 case SID_TC_TC_SEQUENCES:
1605 case SID_TC_TC_SEQUENCES:
1606 i = TC_SEQUENCES;
1606 i = TC_SEQUENCES;
1607 break;
1607 break;
1608 case SID_TC_RECOVERY_ACTION_CMD:
1608 case SID_TC_RECOVERY_ACTION_CMD:
1609 i = RECOVERY_ACTION_CMD;
1609 i = RECOVERY_ACTION_CMD;
1610 break;
1610 break;
1611 case SID_TC_BACKUP_MISSION_TIMELINE:
1611 case SID_TC_BACKUP_MISSION_TIMELINE:
1612 i = BACKUP_MISSION_TIMELINE;
1612 i = BACKUP_MISSION_TIMELINE;
1613 break;
1613 break;
1614 case SID_TC_DIRECT_CMD:
1614 case SID_TC_DIRECT_CMD:
1615 i = DIRECT_CMD;
1615 i = DIRECT_CMD;
1616 break;
1616 break;
1617 case SID_TC_SPARE_GRD_SRC1:
1617 case SID_TC_SPARE_GRD_SRC1:
1618 i = SPARE_GRD_SRC1;
1618 i = SPARE_GRD_SRC1;
1619 break;
1619 break;
1620 case SID_TC_SPARE_GRD_SRC2:
1620 case SID_TC_SPARE_GRD_SRC2:
1621 i = SPARE_GRD_SRC2;
1621 i = SPARE_GRD_SRC2;
1622 break;
1622 break;
1623 case SID_TC_OBCP:
1623 case SID_TC_OBCP:
1624 i = OBCP;
1624 i = OBCP;
1625 break;
1625 break;
1626 case SID_TC_SYSTEM_CONTROL:
1626 case SID_TC_SYSTEM_CONTROL:
1627 i = SYSTEM_CONTROL;
1627 i = SYSTEM_CONTROL;
1628 break;
1628 break;
1629 case SID_TC_AOCS:
1629 case SID_TC_AOCS:
1630 i = AOCS;
1630 i = AOCS;
1631 break;
1631 break;
1632 case SID_TC_RPW_INTERNAL:
1632 case SID_TC_RPW_INTERNAL:
1633 i = RPW_INTERNAL;
1633 i = RPW_INTERNAL;
1634 break;
1634 break;
1635 default:
1635 default:
1636 i = GROUND;
1636 i = GROUND;
1637 break;
1637 break;
1638 }
1638 }
1639
1639
1640 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1640 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1641 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1641 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1642
1642
1643 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1643 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1644
1644
1645 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1645 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1646 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1646 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1647
1647
1648 // increment the sequence counter
1648 // increment the sequence counter
1649 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1649 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1650 {
1650 {
1651 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1651 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1652 }
1652 }
1653 else
1653 else
1654 {
1654 {
1655 sequenceCounters_TM_DUMP[ i ] = 0;
1655 sequenceCounters_TM_DUMP[ i ] = 0;
1656 }
1656 }
1657 }
1657 }
@@ -1,1343 +1,1343
1 /** Functions and tasks related to waveform packet generation.
1 /** Functions and tasks related to waveform packet generation.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
7 *
8 */
8 */
9
9
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11
11
12 //***************
12 //***************
13 // waveform rings
13 // waveform rings
14 // F0
14 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
15 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
16 ring_node *current_ring_node_f0 = NULL;
16 ring_node *current_ring_node_f0 = NULL;
17 ring_node *ring_node_to_send_swf_f0 = NULL;
17 ring_node *ring_node_to_send_swf_f0 = NULL;
18 // F1
18 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
19 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
20 ring_node *current_ring_node_f1 = NULL;
20 ring_node *current_ring_node_f1 = NULL;
21 ring_node *ring_node_to_send_swf_f1 = NULL;
21 ring_node *ring_node_to_send_swf_f1 = NULL;
22 ring_node *ring_node_to_send_cwf_f1 = NULL;
22 ring_node *ring_node_to_send_cwf_f1 = NULL;
23 // F2
23 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
24 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
25 ring_node *current_ring_node_f2 = NULL;
25 ring_node *current_ring_node_f2 = NULL;
26 ring_node *ring_node_to_send_swf_f2 = NULL;
26 ring_node *ring_node_to_send_swf_f2 = NULL;
27 ring_node *ring_node_to_send_cwf_f2 = NULL;
27 ring_node *ring_node_to_send_cwf_f2 = NULL;
28 // F3
28 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
29 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
30 ring_node *current_ring_node_f3 = NULL;
30 ring_node *current_ring_node_f3 = NULL;
31 ring_node *ring_node_to_send_cwf_f3 = NULL;
31 ring_node *ring_node_to_send_cwf_f3 = NULL;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
33
33
34 bool extractSWF1 = false;
34 bool extractSWF1 = false;
35 bool extractSWF2 = false;
35 bool extractSWF2 = false;
36 bool swf0_ready_flag_f1 = false;
36 bool swf0_ready_flag_f1 = false;
37 bool swf0_ready_flag_f2 = false;
37 bool swf0_ready_flag_f2 = false;
38 bool swf1_ready = false;
38 bool swf1_ready = false;
39 bool swf2_ready = false;
39 bool swf2_ready = false;
40
40
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
43 ring_node ring_node_swf1_extracted = {0};
43 ring_node ring_node_swf1_extracted = {0};
44 ring_node ring_node_swf2_extracted = {0};
44 ring_node ring_node_swf2_extracted = {0};
45
45
46 typedef enum resynchro_state_t
46 typedef enum resynchro_state_t
47 {
47 {
48 MEASURE,
48 MEASURE,
49 CORRECTION
49 CORRECTION
50 } resynchro_state;
50 } resynchro_state;
51
51
52 //*********************
52 //*********************
53 // Interrupt SubRoutine
53 // Interrupt SubRoutine
54
54
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 {
56 {
57 ring_node *node;
57 ring_node *node;
58
58
59 node = NULL;
59 node = NULL;
60 switch ( frequencyChannel ) {
60 switch ( frequencyChannel ) {
61 case CHANNELF1:
61 case CHANNELF1:
62 node = ring_node_to_send_cwf_f1;
62 node = ring_node_to_send_cwf_f1;
63 break;
63 break;
64 case CHANNELF2:
64 case CHANNELF2:
65 node = ring_node_to_send_cwf_f2;
65 node = ring_node_to_send_cwf_f2;
66 break;
66 break;
67 case CHANNELF3:
67 case CHANNELF3:
68 node = ring_node_to_send_cwf_f3;
68 node = ring_node_to_send_cwf_f3;
69 break;
69 break;
70 default:
70 default:
71 break;
71 break;
72 }
72 }
73
73
74 return node;
74 return node;
75 }
75 }
76
76
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 {
78 {
79 ring_node *node;
79 ring_node *node;
80
80
81 node = NULL;
81 node = NULL;
82 switch ( frequencyChannel ) {
82 switch ( frequencyChannel ) {
83 case CHANNELF0:
83 case CHANNELF0:
84 node = ring_node_to_send_swf_f0;
84 node = ring_node_to_send_swf_f0;
85 break;
85 break;
86 case CHANNELF1:
86 case CHANNELF1:
87 node = ring_node_to_send_swf_f1;
87 node = ring_node_to_send_swf_f1;
88 break;
88 break;
89 case CHANNELF2:
89 case CHANNELF2:
90 node = ring_node_to_send_swf_f2;
90 node = ring_node_to_send_swf_f2;
91 break;
91 break;
92 default:
92 default:
93 break;
93 break;
94 }
94 }
95
95
96 return node;
96 return node;
97 }
97 }
98
98
99 void reset_extractSWF( void )
99 void reset_extractSWF( void )
100 {
100 {
101 extractSWF1 = false;
101 extractSWF1 = false;
102 extractSWF2 = false;
102 extractSWF2 = false;
103 swf0_ready_flag_f1 = false;
103 swf0_ready_flag_f1 = false;
104 swf0_ready_flag_f2 = false;
104 swf0_ready_flag_f2 = false;
105 swf1_ready = false;
105 swf1_ready = false;
106 swf2_ready = false;
106 swf2_ready = false;
107 }
107 }
108
108
109 inline void waveforms_isr_f3( void )
109 inline void waveforms_isr_f3( void )
110 {
110 {
111 rtems_status_code spare_status;
111 rtems_status_code spare_status;
112
112
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 //***
116 //***
117 // F3
117 // F3
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 current_ring_node_f3 = current_ring_node_f3->next;
120 current_ring_node_f3 = current_ring_node_f3->next;
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 }
126 }
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 }
132 }
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 }
135 }
136 }
136 }
137 }
137 }
138 }
138 }
139
139
140 inline void waveforms_isr_burst( void )
140 inline void waveforms_isr_burst( void )
141 {
141 {
142 unsigned char status;
142 unsigned char status;
143 rtems_status_code spare_status;
143 rtems_status_code spare_status;
144
144
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146
146
147 switch(status)
147 switch(status)
148 {
148 {
149 case BIT_WFP_BUFFER_0:
149 case BIT_WFP_BUFFER_0:
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
154 current_ring_node_f2 = current_ring_node_f2->next;
154 current_ring_node_f2 = current_ring_node_f2->next;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 }
158 }
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
160 break;
160 break;
161 case BIT_WFP_BUFFER_1:
161 case BIT_WFP_BUFFER_1:
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
166 current_ring_node_f2 = current_ring_node_f2->next;
166 current_ring_node_f2 = current_ring_node_f2->next;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
170 }
170 }
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
172 break;
172 break;
173 default:
173 default:
174 break;
174 break;
175 }
175 }
176 }
176 }
177
177
178 inline void waveform_isr_normal_sbm1_sbm2( void )
178 inline void waveform_isr_normal_sbm1_sbm2( void )
179 {
179 {
180 rtems_status_code status;
180 rtems_status_code status;
181
181
182 //***
182 //***
183 // F0
183 // F0
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
185 {
185 {
186 swf0_ready_flag_f1 = true;
186 swf0_ready_flag_f1 = true;
187 swf0_ready_flag_f2 = true;
187 swf0_ready_flag_f2 = true;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
189 current_ring_node_f0 = current_ring_node_f0->next;
189 current_ring_node_f0 = current_ring_node_f0->next;
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
191 {
191 {
192
192
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
197 }
197 }
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
199 {
199 {
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
204 }
204 }
205 // send an event to the WFRM task for resynchro activities
205 // send an event to the WFRM task for resynchro activities
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
207 }
207 }
208
208
209 //***
209 //***
210 // F1
210 // F1
211 if ( (waveform_picker_regs->status & 0x0c) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
211 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
212 // (1) change the receiving buffer for the waveform picker
212 // (1) change the receiving buffer for the waveform picker
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
214 current_ring_node_f1 = current_ring_node_f1->next;
214 current_ring_node_f1 = current_ring_node_f1->next;
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
216 {
216 {
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
221 }
221 }
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
223 {
223 {
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
228 }
228 }
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
231 }
231 }
232
232
233 //***
233 //***
234 // F2
234 // F2
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
236 // (1) change the receiving buffer for the waveform picker
236 // (1) change the receiving buffer for the waveform picker
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
239 current_ring_node_f2 = current_ring_node_f2->next;
239 current_ring_node_f2 = current_ring_node_f2->next;
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
241 {
241 {
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
246 }
246 }
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
248 {
248 {
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
253 }
253 }
254 // (2) send an event for the waveforms transmission
254 // (2) send an event for the waveforms transmission
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
256 }
256 }
257 }
257 }
258
258
259 rtems_isr waveforms_isr( rtems_vector_number vector )
259 rtems_isr waveforms_isr( rtems_vector_number vector )
260 {
260 {
261 /** This is the interrupt sub routine called by the waveform picker core.
261 /** This is the interrupt sub routine called by the waveform picker core.
262 *
262 *
263 * This ISR launch different actions depending mainly on two pieces of information:
263 * This ISR launch different actions depending mainly on two pieces of information:
264 * 1. the values read in the registers of the waveform picker.
264 * 1. the values read in the registers of the waveform picker.
265 * 2. the current LFR mode.
265 * 2. the current LFR mode.
266 *
266 *
267 */
267 */
268
268
269 // STATUS
269 // STATUS
270 // new error error buffer full
270 // new error error buffer full
271 // 15 14 13 12 11 10 9 8
271 // 15 14 13 12 11 10 9 8
272 // f3 f2 f1 f0 f3 f2 f1 f0
272 // f3 f2 f1 f0 f3 f2 f1 f0
273 //
273 //
274 // ready buffer
274 // ready buffer
275 // 7 6 5 4 3 2 1 0
275 // 7 6 5 4 3 2 1 0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
277
277
278 rtems_status_code spare_status;
278 rtems_status_code spare_status;
279
279
280 waveforms_isr_f3();
280 waveforms_isr_f3();
281
281
282 //*************************************************
282 //*************************************************
283 // copy the status bits in the housekeeping packets
283 // copy the status bits in the housekeeping packets
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
286
286
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
288 {
288 {
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
290 }
290 }
291
291
292 switch(lfrCurrentMode)
292 switch(lfrCurrentMode)
293 {
293 {
294 //********
294 //********
295 // STANDBY
295 // STANDBY
296 case LFR_MODE_STANDBY:
296 case LFR_MODE_STANDBY:
297 break;
297 break;
298 //**************************
298 //**************************
299 // LFR NORMAL, SBM1 and SBM2
299 // LFR NORMAL, SBM1 and SBM2
300 case LFR_MODE_NORMAL:
300 case LFR_MODE_NORMAL:
301 case LFR_MODE_SBM1:
301 case LFR_MODE_SBM1:
302 case LFR_MODE_SBM2:
302 case LFR_MODE_SBM2:
303 waveform_isr_normal_sbm1_sbm2();
303 waveform_isr_normal_sbm1_sbm2();
304 break;
304 break;
305 //******
305 //******
306 // BURST
306 // BURST
307 case LFR_MODE_BURST:
307 case LFR_MODE_BURST:
308 waveforms_isr_burst();
308 waveforms_isr_burst();
309 break;
309 break;
310 //********
310 //********
311 // DEFAULT
311 // DEFAULT
312 default:
312 default:
313 break;
313 break;
314 }
314 }
315 }
315 }
316
316
317 //************
317 //************
318 // RTEMS TASKS
318 // RTEMS TASKS
319
319
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
321 {
321 {
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
323 *
323 *
324 * @param unused is the starting argument of the RTEMS task
324 * @param unused is the starting argument of the RTEMS task
325 *
325 *
326 * The following data packets are sent by this task:
326 * The following data packets are sent by this task:
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
330 *
330 *
331 */
331 */
332
332
333 rtems_event_set event_out;
333 rtems_event_set event_out;
334 rtems_id queue_id;
334 rtems_id queue_id;
335 rtems_status_code status;
335 rtems_status_code status;
336 ring_node *ring_node_swf1_extracted_ptr;
336 ring_node *ring_node_swf1_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
338
338
339 event_out = EVENT_SETS_NONE_PENDING;
339 event_out = EVENT_SETS_NONE_PENDING;
340 queue_id = RTEMS_ID_NONE;
340 queue_id = RTEMS_ID_NONE;
341
341
342 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
342 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
343 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
343 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
344
344
345 status = get_message_queue_id_send( &queue_id );
345 status = get_message_queue_id_send( &queue_id );
346 if (status != RTEMS_SUCCESSFUL)
346 if (status != RTEMS_SUCCESSFUL)
347 {
347 {
348 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
348 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
349 }
349 }
350
350
351 BOOT_PRINTF("in WFRM ***\n");
351 BOOT_PRINTF("in WFRM ***\n");
352
352
353 while(1){
353 while(1){
354 // wait for an RTEMS_EVENT
354 // wait for an RTEMS_EVENT
355 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
355 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
356 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
356 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
357
357
358 if (event_out == RTEMS_EVENT_MODE_NORMAL)
358 if (event_out == RTEMS_EVENT_MODE_NORMAL)
359 {
359 {
360 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
360 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
361 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
361 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
362 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
362 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
363 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
363 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
364 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
364 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
365 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
365 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
366 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
366 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
367 }
367 }
368 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
368 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
369 {
369 {
370 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
370 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
371 }
371 }
372 }
372 }
373 }
373 }
374
374
375 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
375 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
376 {
376 {
377 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
377 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
378 *
378 *
379 * @param unused is the starting argument of the RTEMS task
379 * @param unused is the starting argument of the RTEMS task
380 *
380 *
381 * The following data packet is sent by this task:
381 * The following data packet is sent by this task:
382 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
382 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
383 *
383 *
384 */
384 */
385
385
386 rtems_event_set event_out;
386 rtems_event_set event_out;
387 rtems_id queue_id;
387 rtems_id queue_id;
388 rtems_status_code status;
388 rtems_status_code status;
389 ring_node ring_node_cwf3_light;
389 ring_node ring_node_cwf3_light;
390 ring_node *ring_node_to_send_cwf;
390 ring_node *ring_node_to_send_cwf;
391
391
392 event_out = EVENT_SETS_NONE_PENDING;
392 event_out = EVENT_SETS_NONE_PENDING;
393 queue_id = RTEMS_ID_NONE;
393 queue_id = RTEMS_ID_NONE;
394
394
395 status = get_message_queue_id_send( &queue_id );
395 status = get_message_queue_id_send( &queue_id );
396 if (status != RTEMS_SUCCESSFUL)
396 if (status != RTEMS_SUCCESSFUL)
397 {
397 {
398 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
398 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
399 }
399 }
400
400
401 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
401 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
402
402
403 // init the ring_node_cwf3_light structure
403 // init the ring_node_cwf3_light structure
404 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
404 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
405 ring_node_cwf3_light.coarseTime = INIT_CHAR;
405 ring_node_cwf3_light.coarseTime = INIT_CHAR;
406 ring_node_cwf3_light.fineTime = INIT_CHAR;
406 ring_node_cwf3_light.fineTime = INIT_CHAR;
407 ring_node_cwf3_light.next = NULL;
407 ring_node_cwf3_light.next = NULL;
408 ring_node_cwf3_light.previous = NULL;
408 ring_node_cwf3_light.previous = NULL;
409 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
409 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
410 ring_node_cwf3_light.status = INIT_CHAR;
410 ring_node_cwf3_light.status = INIT_CHAR;
411
411
412 BOOT_PRINTF("in CWF3 ***\n");
412 BOOT_PRINTF("in CWF3 ***\n");
413
413
414 while(1){
414 while(1){
415 // wait for an RTEMS_EVENT
415 // wait for an RTEMS_EVENT
416 rtems_event_receive( RTEMS_EVENT_0,
416 rtems_event_receive( RTEMS_EVENT_0,
417 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
417 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
418 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
418 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
419 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
419 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
420 {
420 {
421 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
421 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
422 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
422 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
423 {
423 {
424 PRINTF("send CWF_LONG_F3\n");
424 PRINTF("send CWF_LONG_F3\n");
425 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
425 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
426 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
426 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
427 }
427 }
428 else
428 else
429 {
429 {
430 PRINTF("send CWF_F3 (light)\n");
430 PRINTF("send CWF_F3 (light)\n");
431 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
431 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
432 }
432 }
433
433
434 }
434 }
435 else
435 else
436 {
436 {
437 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
437 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
438 }
438 }
439 }
439 }
440 }
440 }
441
441
442 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
442 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
443 {
443 {
444 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
444 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
445 *
445 *
446 * @param unused is the starting argument of the RTEMS task
446 * @param unused is the starting argument of the RTEMS task
447 *
447 *
448 * The following data packet is sent by this function:
448 * The following data packet is sent by this function:
449 * - TM_LFR_SCIENCE_BURST_CWF_F2
449 * - TM_LFR_SCIENCE_BURST_CWF_F2
450 * - TM_LFR_SCIENCE_SBM2_CWF_F2
450 * - TM_LFR_SCIENCE_SBM2_CWF_F2
451 *
451 *
452 */
452 */
453
453
454 rtems_event_set event_out;
454 rtems_event_set event_out;
455 rtems_id queue_id;
455 rtems_id queue_id;
456 rtems_status_code status;
456 rtems_status_code status;
457 ring_node *ring_node_to_send;
457 ring_node *ring_node_to_send;
458 unsigned long long int acquisitionTimeF0_asLong;
458 unsigned long long int acquisitionTimeF0_asLong;
459
459
460 event_out = EVENT_SETS_NONE_PENDING;
460 event_out = EVENT_SETS_NONE_PENDING;
461 queue_id = RTEMS_ID_NONE;
461 queue_id = RTEMS_ID_NONE;
462
462
463 acquisitionTimeF0_asLong = INIT_CHAR;
463 acquisitionTimeF0_asLong = INIT_CHAR;
464
464
465 status = get_message_queue_id_send( &queue_id );
465 status = get_message_queue_id_send( &queue_id );
466 if (status != RTEMS_SUCCESSFUL)
466 if (status != RTEMS_SUCCESSFUL)
467 {
467 {
468 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
468 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
469 }
469 }
470
470
471 BOOT_PRINTF("in CWF2 ***\n");
471 BOOT_PRINTF("in CWF2 ***\n");
472
472
473 while(1){
473 while(1){
474 // wait for an RTEMS_EVENT// send the snapshot when built
474 // wait for an RTEMS_EVENT// send the snapshot when built
475 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
475 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
476 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
476 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
477 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
477 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
478 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
478 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
479 if (event_out == RTEMS_EVENT_MODE_BURST)
479 if (event_out == RTEMS_EVENT_MODE_BURST)
480 { // data are sent whatever the transition time
480 { // data are sent whatever the transition time
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
482 }
482 }
483 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
483 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
484 {
484 {
485 if ( lfrCurrentMode == LFR_MODE_SBM2 )
485 if ( lfrCurrentMode == LFR_MODE_SBM2 )
486 {
486 {
487 // data are sent depending on the transition time
487 // data are sent depending on the transition time
488 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
488 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
489 {
489 {
490 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
490 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
491 }
491 }
492 }
492 }
493 // launch snapshot extraction if needed
493 // launch snapshot extraction if needed
494 if (extractSWF2 == true)
494 if (extractSWF2 == true)
495 {
495 {
496 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
496 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
497 // extract the snapshot
497 // extract the snapshot
498 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
498 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
499 &ring_node_swf2_extracted, swf2_extracted );
499 &ring_node_swf2_extracted, swf2_extracted );
500 extractSWF2 = false;
500 extractSWF2 = false;
501 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
501 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
502 }
502 }
503 if (swf0_ready_flag_f2 == true)
503 if (swf0_ready_flag_f2 == true)
504 {
504 {
505 extractSWF2 = true;
505 extractSWF2 = true;
506 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
506 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
507 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
507 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
508 swf0_ready_flag_f2 = false;
508 swf0_ready_flag_f2 = false;
509 }
509 }
510 }
510 }
511 }
511 }
512 }
512 }
513
513
514 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
514 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
515 {
515 {
516 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
516 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
517 *
517 *
518 * @param unused is the starting argument of the RTEMS task
518 * @param unused is the starting argument of the RTEMS task
519 *
519 *
520 * The following data packet is sent by this function:
520 * The following data packet is sent by this function:
521 * - TM_LFR_SCIENCE_SBM1_CWF_F1
521 * - TM_LFR_SCIENCE_SBM1_CWF_F1
522 *
522 *
523 */
523 */
524
524
525 rtems_event_set event_out;
525 rtems_event_set event_out;
526 rtems_id queue_id;
526 rtems_id queue_id;
527 rtems_status_code status;
527 rtems_status_code status;
528
528
529 ring_node *ring_node_to_send_cwf;
529 ring_node *ring_node_to_send_cwf;
530
530
531 event_out = EVENT_SETS_NONE_PENDING;
531 event_out = EVENT_SETS_NONE_PENDING;
532 queue_id = RTEMS_ID_NONE;
532 queue_id = RTEMS_ID_NONE;
533
533
534 status = get_message_queue_id_send( &queue_id );
534 status = get_message_queue_id_send( &queue_id );
535 if (status != RTEMS_SUCCESSFUL)
535 if (status != RTEMS_SUCCESSFUL)
536 {
536 {
537 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
537 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
538 }
538 }
539
539
540 BOOT_PRINTF("in CWF1 ***\n");
540 BOOT_PRINTF("in CWF1 ***\n");
541
541
542 while(1){
542 while(1){
543 // wait for an RTEMS_EVENT
543 // wait for an RTEMS_EVENT
544 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
544 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
545 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
545 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
546 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
546 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
547 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
547 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
548 if (lfrCurrentMode == LFR_MODE_SBM1)
548 if (lfrCurrentMode == LFR_MODE_SBM1)
549 {
549 {
550 // data are sent depending on the transition time
550 // data are sent depending on the transition time
551 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
551 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
552 {
552 {
553 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
553 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
554 }
554 }
555 }
555 }
556 // launch snapshot extraction if needed
556 // launch snapshot extraction if needed
557 if (extractSWF1 == true)
557 if (extractSWF1 == true)
558 {
558 {
559 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
559 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
560 // launch the snapshot extraction
560 // launch the snapshot extraction
561 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
561 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
562 extractSWF1 = false;
562 extractSWF1 = false;
563 }
563 }
564 if (swf0_ready_flag_f1 == true)
564 if (swf0_ready_flag_f1 == true)
565 {
565 {
566 extractSWF1 = true;
566 extractSWF1 = true;
567 swf0_ready_flag_f1 = false; // this step shall be executed only one time
567 swf0_ready_flag_f1 = false; // this step shall be executed only one time
568 }
568 }
569 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
569 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
570 {
570 {
571 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
571 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
572 swf1_ready = false;
572 swf1_ready = false;
573 swf2_ready = false;
573 swf2_ready = false;
574 }
574 }
575 }
575 }
576 }
576 }
577
577
578 rtems_task swbd_task(rtems_task_argument argument)
578 rtems_task swbd_task(rtems_task_argument argument)
579 {
579 {
580 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
580 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
581 *
581 *
582 * @param unused is the starting argument of the RTEMS task
582 * @param unused is the starting argument of the RTEMS task
583 *
583 *
584 */
584 */
585
585
586 rtems_event_set event_out;
586 rtems_event_set event_out;
587 unsigned long long int acquisitionTimeF0_asLong;
587 unsigned long long int acquisitionTimeF0_asLong;
588
588
589 event_out = EVENT_SETS_NONE_PENDING;
589 event_out = EVENT_SETS_NONE_PENDING;
590 acquisitionTimeF0_asLong = INIT_CHAR;
590 acquisitionTimeF0_asLong = INIT_CHAR;
591
591
592 BOOT_PRINTF("in SWBD ***\n")
592 BOOT_PRINTF("in SWBD ***\n")
593
593
594 while(1){
594 while(1){
595 // wait for an RTEMS_EVENT
595 // wait for an RTEMS_EVENT
596 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
596 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
597 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
597 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
598 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
598 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
599 {
599 {
600 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
600 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
601 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
601 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
602 &ring_node_swf1_extracted, swf1_extracted );
602 &ring_node_swf1_extracted, swf1_extracted );
603 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
603 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
604 }
604 }
605 else
605 else
606 {
606 {
607 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
607 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
608 }
608 }
609 }
609 }
610 }
610 }
611
611
612 //******************
612 //******************
613 // general functions
613 // general functions
614
614
615 void WFP_init_rings( void )
615 void WFP_init_rings( void )
616 {
616 {
617 // F0 RING
617 // F0 RING
618 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
618 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
619 // F1 RING
619 // F1 RING
620 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
620 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
621 // F2 RING
621 // F2 RING
622 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
622 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
623 // F3 RING
623 // F3 RING
624 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
624 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
625
625
626 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
626 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
627 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
627 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
628
628
629 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
629 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
630 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
630 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
631 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
631 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
632 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
632 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
633 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
633 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
634 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
634 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
635 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
635 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
636 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
636 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
637
637
638 }
638 }
639
639
640 void WFP_reset_current_ring_nodes( void )
640 void WFP_reset_current_ring_nodes( void )
641 {
641 {
642 current_ring_node_f0 = waveform_ring_f0[0].next;
642 current_ring_node_f0 = waveform_ring_f0[0].next;
643 current_ring_node_f1 = waveform_ring_f1[0].next;
643 current_ring_node_f1 = waveform_ring_f1[0].next;
644 current_ring_node_f2 = waveform_ring_f2[0].next;
644 current_ring_node_f2 = waveform_ring_f2[0].next;
645 current_ring_node_f3 = waveform_ring_f3[0].next;
645 current_ring_node_f3 = waveform_ring_f3[0].next;
646
646
647 ring_node_to_send_swf_f0 = waveform_ring_f0;
647 ring_node_to_send_swf_f0 = waveform_ring_f0;
648 ring_node_to_send_swf_f1 = waveform_ring_f1;
648 ring_node_to_send_swf_f1 = waveform_ring_f1;
649 ring_node_to_send_swf_f2 = waveform_ring_f2;
649 ring_node_to_send_swf_f2 = waveform_ring_f2;
650
650
651 ring_node_to_send_cwf_f1 = waveform_ring_f1;
651 ring_node_to_send_cwf_f1 = waveform_ring_f1;
652 ring_node_to_send_cwf_f2 = waveform_ring_f2;
652 ring_node_to_send_cwf_f2 = waveform_ring_f2;
653 ring_node_to_send_cwf_f3 = waveform_ring_f3;
653 ring_node_to_send_cwf_f3 = waveform_ring_f3;
654 }
654 }
655
655
656 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
656 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
657 {
657 {
658 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
658 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
659 *
659 *
660 * @param waveform points to the buffer containing the data that will be send.
660 * @param waveform points to the buffer containing the data that will be send.
661 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
661 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
662 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
662 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
663 * contain information to setup the transmission of the data packets.
663 * contain information to setup the transmission of the data packets.
664 *
664 *
665 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
665 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
666 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
666 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
667 *
667 *
668 */
668 */
669
669
670 unsigned int i;
670 unsigned int i;
671 unsigned int j;
671 unsigned int j;
672 int ret;
672 int ret;
673 rtems_status_code status;
673 rtems_status_code status;
674
674
675 char *sample;
675 char *sample;
676 int *dataPtr;
676 int *dataPtr;
677
677
678 ret = LFR_DEFAULT;
678 ret = LFR_DEFAULT;
679
679
680 dataPtr = (int*) ring_node_to_send->buffer_address;
680 dataPtr = (int*) ring_node_to_send->buffer_address;
681
681
682 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
682 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
683 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
683 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
684
684
685 //**********************
685 //**********************
686 // BUILD CWF3_light DATA
686 // BUILD CWF3_light DATA
687 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
687 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
688 {
688 {
689 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
689 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
690 for (j=0; j < CWF_BLK_SIZE; j++)
690 for (j=0; j < CWF_BLK_SIZE; j++)
691 {
691 {
692 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
692 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
693 }
693 }
694 }
694 }
695
695
696 // SEND PACKET
696 // SEND PACKET
697 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
697 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
698 if (status != RTEMS_SUCCESSFUL) {
698 if (status != RTEMS_SUCCESSFUL) {
699 ret = LFR_DEFAULT;
699 ret = LFR_DEFAULT;
700 }
700 }
701
701
702 return ret;
702 return ret;
703 }
703 }
704
704
705 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
705 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
706 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
706 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
707 {
707 {
708 unsigned long long int acquisitionTimeAsLong;
708 unsigned long long int acquisitionTimeAsLong;
709 unsigned char localAcquisitionTime[BYTES_PER_TIME];
709 unsigned char localAcquisitionTime[BYTES_PER_TIME];
710 double deltaT;
710 double deltaT;
711
711
712 deltaT = INIT_FLOAT;
712 deltaT = INIT_FLOAT;
713
713
714 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
714 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
715 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
715 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
716 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
716 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
717 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
717 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
718 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
718 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
719 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
719 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
720
720
721 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
721 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
722 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
722 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
723 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
723 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
724 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
724 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
725 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
725 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
726 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
726 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
727
727
728 switch( sid )
728 switch( sid )
729 {
729 {
730 case SID_NORM_SWF_F0:
730 case SID_NORM_SWF_F0:
731 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
731 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
732 break;
732 break;
733
733
734 case SID_NORM_SWF_F1:
734 case SID_NORM_SWF_F1:
735 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
735 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
736 break;
736 break;
737
737
738 case SID_NORM_SWF_F2:
738 case SID_NORM_SWF_F2:
739 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
739 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
740 break;
740 break;
741
741
742 case SID_SBM1_CWF_F1:
742 case SID_SBM1_CWF_F1:
743 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
743 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
744 break;
744 break;
745
745
746 case SID_SBM2_CWF_F2:
746 case SID_SBM2_CWF_F2:
747 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
747 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
748 break;
748 break;
749
749
750 case SID_BURST_CWF_F2:
750 case SID_BURST_CWF_F2:
751 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
751 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
752 break;
752 break;
753
753
754 case SID_NORM_CWF_F3:
754 case SID_NORM_CWF_F3:
755 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
755 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
756 break;
756 break;
757
757
758 case SID_NORM_CWF_LONG_F3:
758 case SID_NORM_CWF_LONG_F3:
759 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
759 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
760 break;
760 break;
761
761
762 default:
762 default:
763 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
763 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
764 deltaT = 0.;
764 deltaT = 0.;
765 break;
765 break;
766 }
766 }
767
767
768 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
768 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
769 //
769 //
770 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
770 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
771 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
771 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
772 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
772 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
773 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
773 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
774 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
774 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
775 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
775 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
776
776
777 }
777 }
778
778
779 void build_snapshot_from_ring( ring_node *ring_node_to_send,
779 void build_snapshot_from_ring( ring_node *ring_node_to_send,
780 unsigned char frequencyChannel,
780 unsigned char frequencyChannel,
781 unsigned long long int acquisitionTimeF0_asLong,
781 unsigned long long int acquisitionTimeF0_asLong,
782 ring_node *ring_node_swf_extracted,
782 ring_node *ring_node_swf_extracted,
783 int *swf_extracted)
783 int *swf_extracted)
784 {
784 {
785 unsigned int i;
785 unsigned int i;
786 unsigned int node;
786 unsigned int node;
787 unsigned long long int centerTime_asLong;
787 unsigned long long int centerTime_asLong;
788 unsigned long long int acquisitionTime_asLong;
788 unsigned long long int acquisitionTime_asLong;
789 unsigned long long int bufferAcquisitionTime_asLong;
789 unsigned long long int bufferAcquisitionTime_asLong;
790 unsigned char *ptr1;
790 unsigned char *ptr1;
791 unsigned char *ptr2;
791 unsigned char *ptr2;
792 unsigned char *timeCharPtr;
792 unsigned char *timeCharPtr;
793 unsigned char nb_ring_nodes;
793 unsigned char nb_ring_nodes;
794 unsigned long long int frequency_asLong;
794 unsigned long long int frequency_asLong;
795 unsigned long long int nbTicksPerSample_asLong;
795 unsigned long long int nbTicksPerSample_asLong;
796 unsigned long long int nbSamplesPart1_asLong;
796 unsigned long long int nbSamplesPart1_asLong;
797 unsigned long long int sampleOffset_asLong;
797 unsigned long long int sampleOffset_asLong;
798
798
799 unsigned int deltaT_F0;
799 unsigned int deltaT_F0;
800 unsigned int deltaT_F1;
800 unsigned int deltaT_F1;
801 unsigned long long int deltaT_F2;
801 unsigned long long int deltaT_F2;
802
802
803 deltaT_F0 = DELTAT_F0;
803 deltaT_F0 = DELTAT_F0;
804 deltaT_F1 = DELTAF_F1;
804 deltaT_F1 = DELTAF_F1;
805 deltaT_F2 = DELTAF_F2;
805 deltaT_F2 = DELTAF_F2;
806 sampleOffset_asLong = INIT_CHAR;
806 sampleOffset_asLong = INIT_CHAR;
807
807
808 // (1) get the f0 acquisition time => the value is passed in argument
808 // (1) get the f0 acquisition time => the value is passed in argument
809
809
810 // (2) compute the central reference time
810 // (2) compute the central reference time
811 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
811 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
812 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
812 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
813 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
813 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
814 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
814 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
815
815
816 // (3) compute the acquisition time of the current snapshot
816 // (3) compute the acquisition time of the current snapshot
817 switch(frequencyChannel)
817 switch(frequencyChannel)
818 {
818 {
819 case CHANNELF1: // 1 is for F1 = 4096 Hz
819 case CHANNELF1: // 1 is for F1 = 4096 Hz
820 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
820 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
821 nb_ring_nodes = NB_RING_NODES_F1;
821 nb_ring_nodes = NB_RING_NODES_F1;
822 frequency_asLong = FREQ_F1;
822 frequency_asLong = FREQ_F1;
823 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
823 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
824 break;
824 break;
825 case CHANNELF2: // 2 is for F2 = 256 Hz
825 case CHANNELF2: // 2 is for F2 = 256 Hz
826 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
826 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
827 nb_ring_nodes = NB_RING_NODES_F2;
827 nb_ring_nodes = NB_RING_NODES_F2;
828 frequency_asLong = FREQ_F2;
828 frequency_asLong = FREQ_F2;
829 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
829 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
830 break;
830 break;
831 default:
831 default:
832 acquisitionTime_asLong = centerTime_asLong;
832 acquisitionTime_asLong = centerTime_asLong;
833 nb_ring_nodes = 0;
833 nb_ring_nodes = 0;
834 frequency_asLong = FREQ_F2;
834 frequency_asLong = FREQ_F2;
835 nbTicksPerSample_asLong = TICKS_PER_T2;
835 nbTicksPerSample_asLong = TICKS_PER_T2;
836 break;
836 break;
837 }
837 }
838
838
839 //*****************************************************************************
839 //*****************************************************************************
840 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
840 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
841 node = 0;
841 node = 0;
842 while ( node < nb_ring_nodes)
842 while ( node < nb_ring_nodes)
843 {
843 {
844 //PRINTF1("%d ... ", node);
844 //PRINTF1("%d ... ", node);
845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
847 {
847 {
848 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
848 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
849 node = nb_ring_nodes;
849 node = nb_ring_nodes;
850 }
850 }
851 else
851 else
852 {
852 {
853 node = node + 1;
853 node = node + 1;
854 ring_node_to_send = ring_node_to_send->previous;
854 ring_node_to_send = ring_node_to_send->previous;
855 }
855 }
856 }
856 }
857
857
858 // (5) compute the number of samples to take in the current buffer
858 // (5) compute the number of samples to take in the current buffer
859 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
859 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
860 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
860 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
861 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
861 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
862
862
863 // (6) compute the final acquisition time
863 // (6) compute the final acquisition time
864 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
864 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
865 (sampleOffset_asLong * nbTicksPerSample_asLong);
865 (sampleOffset_asLong * nbTicksPerSample_asLong);
866
866
867 // (7) copy the acquisition time at the beginning of the extrated snapshot
867 // (7) copy the acquisition time at the beginning of the extrated snapshot
868 ptr1 = (unsigned char*) &acquisitionTime_asLong;
868 ptr1 = (unsigned char*) &acquisitionTime_asLong;
869 // fine time
869 // fine time
870 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
870 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
871 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
871 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
872 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
872 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
873 // coarse time
873 // coarse time
874 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
874 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
875 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
875 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
876 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
876 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
877 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
877 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
878 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
878 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
879
879
880 // re set the synchronization bit
880 // re set the synchronization bit
881 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
881 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
882 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
882 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
883
883
884 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
884 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
885 {
885 {
886 nbSamplesPart1_asLong = 0;
886 nbSamplesPart1_asLong = 0;
887 }
887 }
888 // copy the part 1 of the snapshot in the extracted buffer
888 // copy the part 1 of the snapshot in the extracted buffer
889 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
889 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
890 {
890 {
891 swf_extracted[i] =
891 swf_extracted[i] =
892 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
892 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
893 }
893 }
894 // copy the part 2 of the snapshot in the extracted buffer
894 // copy the part 2 of the snapshot in the extracted buffer
895 ring_node_to_send = ring_node_to_send->next;
895 ring_node_to_send = ring_node_to_send->next;
896 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
896 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
897 {
897 {
898 swf_extracted[i] =
898 swf_extracted[i] =
899 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
899 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
900 }
900 }
901 }
901 }
902
902
903 double computeCorrection( unsigned char *timePtr )
903 double computeCorrection( unsigned char *timePtr )
904 {
904 {
905 unsigned long long int acquisitionTime;
905 unsigned long long int acquisitionTime;
906 unsigned long long int centerTime;
906 unsigned long long int centerTime;
907 unsigned long long int previousTick;
907 unsigned long long int previousTick;
908 unsigned long long int nextTick;
908 unsigned long long int nextTick;
909 unsigned long long int deltaPreviousTick;
909 unsigned long long int deltaPreviousTick;
910 unsigned long long int deltaNextTick;
910 unsigned long long int deltaNextTick;
911 double deltaPrevious_ms;
911 double deltaPrevious_ms;
912 double deltaNext_ms;
912 double deltaNext_ms;
913 double correctionInF2;
913 double correctionInF2;
914
914
915 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
915 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
916
916
917 // get acquisition time in fine time ticks
917 // get acquisition time in fine time ticks
918 acquisitionTime = get_acquisition_time( timePtr );
918 acquisitionTime = get_acquisition_time( timePtr );
919
919
920 // compute center time
920 // compute center time
921 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
921 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
922 previousTick = centerTime - (centerTime & INT16_ALL_F);
922 previousTick = centerTime - (centerTime & INT16_ALL_F);
923 nextTick = previousTick + TICKS_PER_S;
923 nextTick = previousTick + TICKS_PER_S;
924
924
925 deltaPreviousTick = centerTime - previousTick;
925 deltaPreviousTick = centerTime - previousTick;
926 deltaNextTick = nextTick - centerTime;
926 deltaNextTick = nextTick - centerTime;
927
927
928 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
928 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
929 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
929 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
930
930
931 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
931 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
932
932
933 // which tick is the closest?
933 // which tick is the closest?
934 if (deltaPreviousTick > deltaNextTick)
934 if (deltaPreviousTick > deltaNextTick)
935 {
935 {
936 // the snapshot center is just before the second => increase delta_snapshot
936 // the snapshot center is just before the second => increase delta_snapshot
937 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
937 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
938 }
938 }
939 else
939 else
940 {
940 {
941 // the snapshot center is just after the second => decrease delta_snapshot
941 // the snapshot center is just after the second => decrease delta_snapshot
942 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
942 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
943 }
943 }
944
944
945 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
945 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
946
946
947 return correctionInF2;
947 return correctionInF2;
948 }
948 }
949
949
950 void applyCorrection( double correction )
950 void applyCorrection( double correction )
951 {
951 {
952 int correctionInt;
952 int correctionInt;
953
953
954 correctionInt = 0;
954 correctionInt = 0;
955
955
956 if (correction >= 0.)
956 if (correction >= 0.)
957 {
957 {
958 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
958 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
959 {
959 {
960 correctionInt = ONE_TICK_CORR;
960 correctionInt = ONE_TICK_CORR;
961 }
961 }
962 else
962 else
963 {
963 {
964 correctionInt = CORR_MULT * floor(correction);
964 correctionInt = CORR_MULT * floor(correction);
965 }
965 }
966 }
966 }
967 else
967 else
968 {
968 {
969 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
969 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
970 {
970 {
971 correctionInt = -ONE_TICK_CORR;
971 correctionInt = -ONE_TICK_CORR;
972 }
972 }
973 else
973 else
974 {
974 {
975 correctionInt = CORR_MULT * ceil(correction);
975 correctionInt = CORR_MULT * ceil(correction);
976 }
976 }
977 }
977 }
978 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
978 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
979 }
979 }
980
980
981 void snapshot_resynchronization( unsigned char *timePtr )
981 void snapshot_resynchronization( unsigned char *timePtr )
982 {
982 {
983 /** This function compute a correction to apply on delta_snapshot.
983 /** This function compute a correction to apply on delta_snapshot.
984 *
984 *
985 *
985 *
986 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
986 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
987 *
987 *
988 * @return void
988 * @return void
989 *
989 *
990 */
990 */
991
991
992 static double correction = INIT_FLOAT;
992 static double correction = INIT_FLOAT;
993 static resynchro_state state = MEASURE;
993 static resynchro_state state = MEASURE;
994 static unsigned int nbSnapshots = 0;
994 static unsigned int nbSnapshots = 0;
995
995
996 int correctionInt;
996 int correctionInt;
997
997
998 correctionInt = 0;
998 correctionInt = 0;
999
999
1000 switch (state)
1000 switch (state)
1001 {
1001 {
1002
1002
1003 case MEASURE:
1003 case MEASURE:
1004 // ********
1004 // ********
1005 PRINTF1("MEASURE === %d\n", nbSnapshots);
1005 PRINTF1("MEASURE === %d\n", nbSnapshots);
1006 state = CORRECTION;
1006 state = CORRECTION;
1007 correction = computeCorrection( timePtr );
1007 correction = computeCorrection( timePtr );
1008 PRINTF1("MEASURE === correction = %.2f\n", correction );
1008 PRINTF1("MEASURE === correction = %.2f\n", correction );
1009 applyCorrection( correction );
1009 applyCorrection( correction );
1010 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1010 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1011 //****
1011 //****
1012 break;
1012 break;
1013
1013
1014 case CORRECTION:
1014 case CORRECTION:
1015 //************
1015 //************
1016 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1016 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1017 state = MEASURE;
1017 state = MEASURE;
1018 computeCorrection( timePtr );
1018 computeCorrection( timePtr );
1019 set_wfp_delta_snapshot();
1019 set_wfp_delta_snapshot();
1020 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1020 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1021 //****
1021 //****
1022 break;
1022 break;
1023
1023
1024 default:
1024 default:
1025 break;
1025 break;
1026
1026
1027 }
1027 }
1028
1028
1029 nbSnapshots++;
1029 nbSnapshots++;
1030 }
1030 }
1031
1031
1032 //**************
1032 //**************
1033 // wfp registers
1033 // wfp registers
1034 void reset_wfp_burst_enable( void )
1034 void reset_wfp_burst_enable( void )
1035 {
1035 {
1036 /** This function resets the waveform picker burst_enable register.
1036 /** This function resets the waveform picker burst_enable register.
1037 *
1037 *
1038 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1038 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1039 *
1039 *
1040 */
1040 */
1041
1041
1042 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1042 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1043 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1043 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1044 }
1044 }
1045
1045
1046 void reset_wfp_status( void )
1046 void reset_wfp_status( void )
1047 {
1047 {
1048 /** This function resets the waveform picker status register.
1048 /** This function resets the waveform picker status register.
1049 *
1049 *
1050 * All status bits are set to 0 [new_err full_err full].
1050 * All status bits are set to 0 [new_err full_err full].
1051 *
1051 *
1052 */
1052 */
1053
1053
1054 waveform_picker_regs->status = INT16_ALL_F;
1054 waveform_picker_regs->status = INT16_ALL_F;
1055 }
1055 }
1056
1056
1057 void reset_wfp_buffer_addresses( void )
1057 void reset_wfp_buffer_addresses( void )
1058 {
1058 {
1059 // F0
1059 // F0
1060 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1060 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1061 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1061 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1062 // F1
1062 // F1
1063 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1063 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1064 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1064 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1065 // F2
1065 // F2
1066 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1066 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1067 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1067 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1068 // F3
1068 // F3
1069 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1069 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1070 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1070 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1071 }
1071 }
1072
1072
1073 void reset_waveform_picker_regs( void )
1073 void reset_waveform_picker_regs( void )
1074 {
1074 {
1075 /** This function resets the waveform picker module registers.
1075 /** This function resets the waveform picker module registers.
1076 *
1076 *
1077 * The registers affected by this function are located at the following offset addresses:
1077 * The registers affected by this function are located at the following offset addresses:
1078 * - 0x00 data_shaping
1078 * - 0x00 data_shaping
1079 * - 0x04 run_burst_enable
1079 * - 0x04 run_burst_enable
1080 * - 0x08 addr_data_f0
1080 * - 0x08 addr_data_f0
1081 * - 0x0C addr_data_f1
1081 * - 0x0C addr_data_f1
1082 * - 0x10 addr_data_f2
1082 * - 0x10 addr_data_f2
1083 * - 0x14 addr_data_f3
1083 * - 0x14 addr_data_f3
1084 * - 0x18 status
1084 * - 0x18 status
1085 * - 0x1C delta_snapshot
1085 * - 0x1C delta_snapshot
1086 * - 0x20 delta_f0
1086 * - 0x20 delta_f0
1087 * - 0x24 delta_f0_2
1087 * - 0x24 delta_f0_2
1088 * - 0x28 delta_f1 (obsolet parameter)
1088 * - 0x28 delta_f1 (obsolet parameter)
1089 * - 0x2c delta_f2
1089 * - 0x2c delta_f2
1090 * - 0x30 nb_data_by_buffer
1090 * - 0x30 nb_data_by_buffer
1091 * - 0x34 nb_snapshot_param
1091 * - 0x34 nb_snapshot_param
1092 * - 0x38 start_date
1092 * - 0x38 start_date
1093 * - 0x3c nb_word_in_buffer
1093 * - 0x3c nb_word_in_buffer
1094 *
1094 *
1095 */
1095 */
1096
1096
1097 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1097 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1098
1098
1099 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1099 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1100
1100
1101 reset_wfp_buffer_addresses();
1101 reset_wfp_buffer_addresses();
1102
1102
1103 reset_wfp_status(); // 0x18
1103 reset_wfp_status(); // 0x18
1104
1104
1105 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1105 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1106
1106
1107 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1107 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1108
1108
1109 //the parameter delta_f1 [0x28] is not used anymore
1109 //the parameter delta_f1 [0x28] is not used anymore
1110
1110
1111 set_wfp_delta_f2(); // 0x2c
1111 set_wfp_delta_f2(); // 0x2c
1112
1112
1113 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1113 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1114 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1114 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1115 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1115 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1116 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1116 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1117 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1117 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1118 // 2688 = 8 * 336
1118 // 2688 = 8 * 336
1119 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1119 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1120 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1120 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1121 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1121 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1122 //
1122 //
1123 // coarse time and fine time registers are not initialized, they are volatile
1123 // coarse time and fine time registers are not initialized, they are volatile
1124 //
1124 //
1125 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1125 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1126 }
1126 }
1127
1127
1128 void set_wfp_data_shaping( void )
1128 void set_wfp_data_shaping( void )
1129 {
1129 {
1130 /** This function sets the data_shaping register of the waveform picker module.
1130 /** This function sets the data_shaping register of the waveform picker module.
1131 *
1131 *
1132 * The value is read from one field of the parameter_dump_packet structure:\n
1132 * The value is read from one field of the parameter_dump_packet structure:\n
1133 * bw_sp0_sp1_r0_r1
1133 * bw_sp0_sp1_r0_r1
1134 *
1134 *
1135 */
1135 */
1136
1136
1137 unsigned char data_shaping;
1137 unsigned char data_shaping;
1138
1138
1139 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1139 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1140 // waveform picker : [R1 R0 SP1 SP0 BW]
1140 // waveform picker : [R1 R0 SP1 SP0 BW]
1141
1141
1142 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1142 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1143
1143
1144 waveform_picker_regs->data_shaping =
1144 waveform_picker_regs->data_shaping =
1145 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1145 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1146 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1146 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1147 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1147 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1148 + ( (data_shaping & BIT_2) << 1 ) // R0
1148 + ( (data_shaping & BIT_2) << 1 ) // R0
1149 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1149 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1150 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1150 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1151 }
1151 }
1152
1152
1153 void set_wfp_burst_enable_register( unsigned char mode )
1153 void set_wfp_burst_enable_register( unsigned char mode )
1154 {
1154 {
1155 /** This function sets the waveform picker burst_enable register depending on the mode.
1155 /** This function sets the waveform picker burst_enable register depending on the mode.
1156 *
1156 *
1157 * @param mode is the LFR mode to launch.
1157 * @param mode is the LFR mode to launch.
1158 *
1158 *
1159 * The burst bits shall be before the enable bits.
1159 * The burst bits shall be before the enable bits.
1160 *
1160 *
1161 */
1161 */
1162
1162
1163 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1163 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1164 // the burst bits shall be set first, before the enable bits
1164 // the burst bits shall be set first, before the enable bits
1165 switch(mode) {
1165 switch(mode) {
1166 case LFR_MODE_NORMAL:
1166 case LFR_MODE_NORMAL:
1167 case LFR_MODE_SBM1:
1167 case LFR_MODE_SBM1:
1168 case LFR_MODE_SBM2:
1168 case LFR_MODE_SBM2:
1169 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1169 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1170 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1170 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0
1171 break;
1171 break;
1172 case LFR_MODE_BURST:
1172 case LFR_MODE_BURST:
1173 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1173 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1174 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2
1174 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2
1175 break;
1175 break;
1176 default:
1176 default:
1177 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1177 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1178 break;
1178 break;
1179 }
1179 }
1180 }
1180 }
1181
1181
1182 void set_wfp_delta_snapshot( void )
1182 void set_wfp_delta_snapshot( void )
1183 {
1183 {
1184 /** This function sets the delta_snapshot register of the waveform picker module.
1184 /** This function sets the delta_snapshot register of the waveform picker module.
1185 *
1185 *
1186 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1186 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1187 * - sy_lfr_n_swf_p[0]
1187 * - sy_lfr_n_swf_p[0]
1188 * - sy_lfr_n_swf_p[1]
1188 * - sy_lfr_n_swf_p[1]
1189 *
1189 *
1190 */
1190 */
1191
1191
1192 unsigned int delta_snapshot;
1192 unsigned int delta_snapshot;
1193 unsigned int delta_snapshot_in_T2;
1193 unsigned int delta_snapshot_in_T2;
1194
1194
1195 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1195 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1196 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1196 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1197
1197
1198 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1198 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1199 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1199 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1200 }
1200 }
1201
1201
1202 void set_wfp_delta_f0_f0_2( void )
1202 void set_wfp_delta_f0_f0_2( void )
1203 {
1203 {
1204 unsigned int delta_snapshot;
1204 unsigned int delta_snapshot;
1205 unsigned int nb_samples_per_snapshot;
1205 unsigned int nb_samples_per_snapshot;
1206 float delta_f0_in_float;
1206 float delta_f0_in_float;
1207
1207
1208 delta_snapshot = waveform_picker_regs->delta_snapshot;
1208 delta_snapshot = waveform_picker_regs->delta_snapshot;
1209 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1209 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1210 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1210 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1211
1211
1212 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1212 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1213 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; // 48 = 11 0000, max 7 bits
1213 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; // 48 = 11 0000, max 7 bits
1214 }
1214 }
1215
1215
1216 void set_wfp_delta_f1( void )
1216 void set_wfp_delta_f1( void )
1217 {
1217 {
1218 /** Sets the value of the delta_f1 parameter
1218 /** Sets the value of the delta_f1 parameter
1219 *
1219 *
1220 * @param void
1220 * @param void
1221 *
1221 *
1222 * @return void
1222 * @return void
1223 *
1223 *
1224 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1224 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1225 *
1225 *
1226 */
1226 */
1227
1227
1228 unsigned int delta_snapshot;
1228 unsigned int delta_snapshot;
1229 unsigned int nb_samples_per_snapshot;
1229 unsigned int nb_samples_per_snapshot;
1230 float delta_f1_in_float;
1230 float delta_f1_in_float;
1231
1231
1232 delta_snapshot = waveform_picker_regs->delta_snapshot;
1232 delta_snapshot = waveform_picker_regs->delta_snapshot;
1233 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1233 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1234 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1234 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1235
1235
1236 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1236 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1237 }
1237 }
1238
1238
1239 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1239 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1240 {
1240 {
1241 /** Sets the value of the delta_f2 parameter
1241 /** Sets the value of the delta_f2 parameter
1242 *
1242 *
1243 * @param void
1243 * @param void
1244 *
1244 *
1245 * @return void
1245 * @return void
1246 *
1246 *
1247 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1247 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1248 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1248 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1249 *
1249 *
1250 */
1250 */
1251
1251
1252 unsigned int delta_snapshot;
1252 unsigned int delta_snapshot;
1253 unsigned int nb_samples_per_snapshot;
1253 unsigned int nb_samples_per_snapshot;
1254
1254
1255 delta_snapshot = waveform_picker_regs->delta_snapshot;
1255 delta_snapshot = waveform_picker_regs->delta_snapshot;
1256 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1256 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1257
1257
1258 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1258 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1259 }
1259 }
1260
1260
1261 //*****************
1261 //*****************
1262 // local parameters
1262 // local parameters
1263
1263
1264 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1264 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1265 {
1265 {
1266 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1266 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1267 *
1267 *
1268 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1268 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1269 * @param sid is the source identifier of the packet being updated.
1269 * @param sid is the source identifier of the packet being updated.
1270 *
1270 *
1271 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1271 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1272 * The sequence counters shall wrap around from 2^14 to zero.
1272 * The sequence counters shall wrap around from 2^14 to zero.
1273 * The sequence counter shall start at zero at startup.
1273 * The sequence counter shall start at zero at startup.
1274 *
1274 *
1275 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1275 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1276 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1276 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1277 *
1277 *
1278 */
1278 */
1279
1279
1280 unsigned short *sequence_cnt;
1280 unsigned short *sequence_cnt;
1281 unsigned short segmentation_grouping_flag;
1281 unsigned short segmentation_grouping_flag;
1282 unsigned short new_packet_sequence_control;
1282 unsigned short new_packet_sequence_control;
1283 rtems_mode initial_mode_set;
1283 rtems_mode initial_mode_set;
1284 rtems_mode current_mode_set;
1284 rtems_mode current_mode_set;
1285 rtems_status_code status;
1285 rtems_status_code status;
1286
1286
1287 initial_mode_set = RTEMS_DEFAULT_MODES;
1287 initial_mode_set = RTEMS_DEFAULT_MODES;
1288 current_mode_set = RTEMS_DEFAULT_MODES;
1288 current_mode_set = RTEMS_DEFAULT_MODES;
1289 sequence_cnt = NULL;
1289 sequence_cnt = NULL;
1290
1290
1291 //******************************************
1291 //******************************************
1292 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1292 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1293 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1293 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1294
1294
1295 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1295 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1296 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1296 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1297 || (sid == SID_BURST_CWF_F2)
1297 || (sid == SID_BURST_CWF_F2)
1298 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1298 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1299 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1299 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1300 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1300 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1301 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1301 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1302 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1302 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1303 {
1303 {
1304 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1304 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1305 }
1305 }
1306 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1306 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1307 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1307 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1308 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1308 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1309 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1309 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1310 {
1310 {
1311 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1311 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1312 }
1312 }
1313 else
1313 else
1314 {
1314 {
1315 sequence_cnt = (unsigned short *) NULL;
1315 sequence_cnt = (unsigned short *) NULL;
1316 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1316 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1317 }
1317 }
1318
1318
1319 if (sequence_cnt != NULL)
1319 if (sequence_cnt != NULL)
1320 {
1320 {
1321 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1321 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1322 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1322 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1323
1323
1324 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1324 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1325
1325
1326 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1326 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1327 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1327 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1328
1328
1329 // increment the sequence counter
1329 // increment the sequence counter
1330 if ( *sequence_cnt < SEQ_CNT_MAX)
1330 if ( *sequence_cnt < SEQ_CNT_MAX)
1331 {
1331 {
1332 *sequence_cnt = *sequence_cnt + 1;
1332 *sequence_cnt = *sequence_cnt + 1;
1333 }
1333 }
1334 else
1334 else
1335 {
1335 {
1336 *sequence_cnt = 0;
1336 *sequence_cnt = 0;
1337 }
1337 }
1338 }
1338 }
1339
1339
1340 //*************************************
1340 //*************************************
1341 // RESTORE THE MODE OF THE CALLING TASK
1341 // RESTORE THE MODE OF THE CALLING TASK
1342 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1342 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1343 }
1343 }
General Comments 0
You need to be logged in to leave comments. Login now