##// END OF EJS Templates
AVGV modified...
paul -
r352:c07c16776bd4 R3++ draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 e01ac8bd125a79a7af38b0e3ba0330f5be1a3c92 header/lfr_common_headers
2 7ee7da2ed42fbc9cd673ae7f3a865345cea0f83f header/lfr_common_headers
@@ -1,238 +1,235
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 #include <stdint.h>
6 #include <stdint.h>
7
7
8 struct apbuart_regs_str{
8 struct apbuart_regs_str{
9 volatile unsigned int data;
9 volatile unsigned int data;
10 volatile unsigned int status;
10 volatile unsigned int status;
11 volatile unsigned int ctrl;
11 volatile unsigned int ctrl;
12 volatile unsigned int scaler;
12 volatile unsigned int scaler;
13 volatile unsigned int fifoDebug;
13 volatile unsigned int fifoDebug;
14 };
14 };
15
15
16 struct grgpio_regs_str{
16 struct grgpio_regs_str{
17 volatile int io_port_data_register;
17 volatile int io_port_data_register;
18 int io_port_output_register;
18 int io_port_output_register;
19 int io_port_direction_register;
19 int io_port_direction_register;
20 int interrupt_mak_register;
20 int interrupt_mak_register;
21 int interrupt_polarity_register;
21 int interrupt_polarity_register;
22 int interrupt_edge_register;
22 int interrupt_edge_register;
23 int bypass_register;
23 int bypass_register;
24 int reserved;
24 int reserved;
25 // 0x20-0x3c interrupt map register(s)
25 // 0x20-0x3c interrupt map register(s)
26 };
26 };
27
27
28 typedef struct {
28 typedef struct {
29 volatile unsigned int counter;
29 volatile unsigned int counter;
30 volatile unsigned int reload;
30 volatile unsigned int reload;
31 volatile unsigned int ctrl;
31 volatile unsigned int ctrl;
32 volatile unsigned int unused;
32 volatile unsigned int unused;
33 } timer_regs_t;
33 } timer_regs_t;
34
34
35 //*************
35 //*************
36 //*************
36 //*************
37 // GPTIMER_REGS
37 // GPTIMER_REGS
38
38
39 #define GPTIMER_CLEAR_IRQ 0x00000010 // clear pending IRQ if any
39 #define GPTIMER_CLEAR_IRQ 0x00000010 // clear pending IRQ if any
40 #define GPTIMER_LD 0x00000004 // LD load value from the reload register
40 #define GPTIMER_LD 0x00000004 // LD load value from the reload register
41 #define GPTIMER_EN 0x00000001 // EN enable the timer
41 #define GPTIMER_EN 0x00000001 // EN enable the timer
42 #define GPTIMER_EN_MASK 0xfffffffe // EN enable the timer
42 #define GPTIMER_EN_MASK 0xfffffffe // EN enable the timer
43 #define GPTIMER_RS 0x00000002 // RS restart
43 #define GPTIMER_RS 0x00000002 // RS restart
44 #define GPTIMER_IE 0x00000008 // IE interrupt enable
44 #define GPTIMER_IE 0x00000008 // IE interrupt enable
45 #define GPTIMER_IE_MASK 0xffffffef // IE interrupt enable
45 #define GPTIMER_IE_MASK 0xffffffef // IE interrupt enable
46
46
47 typedef struct {
47 typedef struct {
48 volatile unsigned int scaler_value;
48 volatile unsigned int scaler_value;
49 volatile unsigned int scaler_reload;
49 volatile unsigned int scaler_reload;
50 volatile unsigned int conf;
50 volatile unsigned int conf;
51 volatile unsigned int unused0;
51 volatile unsigned int unused0;
52 timer_regs_t timer[NB_GPTIMER];
52 timer_regs_t timer[NB_GPTIMER];
53 } gptimer_regs_t;
53 } gptimer_regs_t;
54
54
55 //*********************
55 //*********************
56 //*********************
56 //*********************
57 // TIME_MANAGEMENT_REGS
57 // TIME_MANAGEMENT_REGS
58
58
59 #define VAL_SOFTWARE_RESET 0x02 // [0010] software reset
59 #define VAL_SOFTWARE_RESET 0x02 // [0010] software reset
60 #define VAL_LFR_SYNCHRONIZED 0x80000000
60 #define VAL_LFR_SYNCHRONIZED 0x80000000
61 #define BIT_SYNCHRONIZATION 31
61 #define BIT_SYNCHRONIZATION 31
62 #define COARSE_TIME_MASK 0x7fffffff
62 #define COARSE_TIME_MASK 0x7fffffff
63 #define SYNC_BIT_MASK 0x7f
63 #define SYNC_BIT_MASK 0x7f
64 #define SYNC_BIT 0x80
64 #define SYNC_BIT 0x80
65 #define BIT_CAL_RELOAD 0x00000010
65 #define BIT_CAL_RELOAD 0x00000010
66 #define MASK_CAL_RELOAD 0xffffffef // [1110 1111]
66 #define MASK_CAL_RELOAD 0xffffffef // [1110 1111]
67 #define BIT_CAL_ENABLE 0x00000040
67 #define BIT_CAL_ENABLE 0x00000040
68 #define MASK_CAL_ENABLE 0xffffffbf // [1011 1111]
68 #define MASK_CAL_ENABLE 0xffffffbf // [1011 1111]
69 #define BIT_SET_INTERLEAVED 0x00000020 // [0010 0000]
69 #define BIT_SET_INTERLEAVED 0x00000020 // [0010 0000]
70 #define MASK_SET_INTERLEAVED 0xffffffdf // [1101 1111]
70 #define MASK_SET_INTERLEAVED 0xffffffdf // [1101 1111]
71 #define BIT_SOFT_RESET 0x00000004 // [0100]
71 #define BIT_SOFT_RESET 0x00000004 // [0100]
72 #define MASK_SOFT_RESET 0xfffffffb // [1011]
72 #define MASK_SOFT_RESET 0xfffffffb // [1011]
73
73
74 typedef struct {
74 typedef struct {
75 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
75 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
76 // bit 1 is the soft reset for the time management module
76 // bit 1 is the soft reset for the time management module
77 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
77 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
78 volatile int coarse_time_load;
78 volatile int coarse_time_load;
79 volatile int coarse_time;
79 volatile int coarse_time;
80 volatile int fine_time;
80 volatile int fine_time;
81 // TEMPERATURES
81 // TEMPERATURES
82 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
82 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
83 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
83 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
84 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
84 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
85 // CALIBRATION
85 // CALIBRATION
86 volatile unsigned int calDACCtrl;
86 volatile unsigned int calDACCtrl;
87 volatile unsigned int calPrescaler;
87 volatile unsigned int calPrescaler;
88 volatile unsigned int calDivisor;
88 volatile unsigned int calDivisor;
89 volatile unsigned int calDataPtr;
89 volatile unsigned int calDataPtr;
90 volatile unsigned int calData;
90 volatile unsigned int calData;
91 } time_management_regs_t;
91 } time_management_regs_t;
92
92
93 //*********************
93 //*********************
94 //*********************
94 //*********************
95 // WAVEFORM_PICKER_REGS
95 // WAVEFORM_PICKER_REGS
96
96
97 #define BITS_WFP_STATUS_F3 0xc0 // [1100 0000] check the f3 full bits
97 #define BITS_WFP_STATUS_F3 0xc0 // [1100 0000] check the f3 full bits
98 #define BIT_WFP_BUF_F3_0 0x40 // [0100 0000] f3 buffer 0 is full
98 #define BIT_WFP_BUF_F3_0 0x40 // [0100 0000] f3 buffer 0 is full
99 #define BIT_WFP_BUF_F3_1 0x80 // [1000 0000] f3 buffer 1 is full
99 #define BIT_WFP_BUF_F3_1 0x80 // [1000 0000] f3 buffer 1 is full
100 #define RST_WFP_F3_0 0x00008840 // [1000 1000 0100 0000]
100 #define RST_WFP_F3_0 0x00008840 // [1000 1000 0100 0000]
101 #define RST_WFP_F3_1 0x00008880 // [1000 1000 1000 0000]
101 #define RST_WFP_F3_1 0x00008880 // [1000 1000 1000 0000]
102
102
103 #define BITS_WFP_STATUS_F2 0x30 // [0011 0000] get the status bits for f2
103 #define BITS_WFP_STATUS_F2 0x30 // [0011 0000] get the status bits for f2
104 #define SHIFT_WFP_STATUS_F2 4
104 #define SHIFT_WFP_STATUS_F2 4
105 #define BIT_WFP_BUF_F2_0 0x10 // [0001 0000] f2 buffer 0 is full
105 #define BIT_WFP_BUF_F2_0 0x10 // [0001 0000] f2 buffer 0 is full
106 #define BIT_WFP_BUF_F2_1 0x20 // [0010 0000] f2 buffer 1 is full
106 #define BIT_WFP_BUF_F2_1 0x20 // [0010 0000] f2 buffer 1 is full
107 #define RST_WFP_F2_0 0x00004410 // [0100 0100 0001 0000]
107 #define RST_WFP_F2_0 0x00004410 // [0100 0100 0001 0000]
108 #define RST_WFP_F2_1 0x00004420 // [0100 0100 0010 0000]
108 #define RST_WFP_F2_1 0x00004420 // [0100 0100 0010 0000]
109
109
110 #define BITS_WFP_STATUS_F1 0x0c // [0000 1100] check the f1 full bits
110 #define BITS_WFP_STATUS_F1 0x0c // [0000 1100] check the f1 full bits
111 #define BIT_WFP_BUF_F1_0 0x04 // [0000 0100] f1 buffer 0 is full
111 #define BIT_WFP_BUF_F1_0 0x04 // [0000 0100] f1 buffer 0 is full
112 #define BIT_WFP_BUF_F1_1 0x08 // [0000 1000] f1 buffer 1 is full
112 #define BIT_WFP_BUF_F1_1 0x08 // [0000 1000] f1 buffer 1 is full
113 #define RST_WFP_F1_0 0x00002204 // [0010 0010 0000 0100] f1 bits = 0
113 #define RST_WFP_F1_0 0x00002204 // [0010 0010 0000 0100] f1 bits = 0
114 #define RST_WFP_F1_1 0x00002208 // [0010 0010 0000 1000] f1 bits = 0
114 #define RST_WFP_F1_1 0x00002208 // [0010 0010 0000 1000] f1 bits = 0
115
115
116 #define BITS_WFP_STATUS_F0 0x03 // [0000 0011] check the f0 full bits
116 #define BITS_WFP_STATUS_F0 0x03 // [0000 0011] check the f0 full bits
117 #define RST_WFP_F0_0 0x00001101 // [0001 0001 0000 0001]
117 #define RST_WFP_F0_0 0x00001101 // [0001 0001 0000 0001]
118 #define RST_WFP_F0_1 0x00001102 // [0001 0001 0000 0010]
118 #define RST_WFP_F0_1 0x00001102 // [0001 0001 0000 0010]
119
119
120 #define BIT_WFP_BUFFER_0 0x01
120 #define BIT_WFP_BUFFER_0 0x01
121 #define BIT_WFP_BUFFER_1 0x02
121 #define BIT_WFP_BUFFER_1 0x02
122
122
123 #define RST_BITS_RUN_BURST_EN 0x80 // [1000 0000] burst f2, f1, f0 enable f3, f2, f1, f0
123 #define RST_BITS_RUN_BURST_EN 0x80 // [1000 0000] burst f2, f1, f0 enable f3, f2, f1, f0
124 #define BITS_WFP_ENABLE_ALL 0x0f // [0000 1111] enable f3, f2, f1, f0
124 #define BITS_WFP_ENABLE_ALL 0x0f // [0000 1111] enable f3, f2, f1, f0
125 #define BITS_WFP_ENABLE_BURST 0x0c // [0000 1100] enable f3, f2
125 #define BITS_WFP_ENABLE_BURST 0x0c // [0000 1100] enable f3, f2
126 #define RUN_BURST_ENABLE_SBM2 0x60 // [0110 0000] enable f2 and f1 burst
126 #define RUN_BURST_ENABLE_SBM2 0x60 // [0110 0000] enable f2 and f1 burst
127 #define RUN_BURST_ENABLE_BURST 0x40 // [0100 0000] f2 burst enabled
127 #define RUN_BURST_ENABLE_BURST 0x40 // [0100 0000] f2 burst enabled
128
128
129 #define DFLT_WFP_NB_DATA_BY_BUFFER 0xa7f // 0x30 *** 2688 - 1 => nb samples -1
129 #define DFLT_WFP_NB_DATA_BY_BUFFER 0xa7f // 0x30 *** 2688 - 1 => nb samples -1
130 #define DFLT_WFP_SNAPSHOT_PARAM 0xa80 // 0x34 *** 2688 => nb samples
130 #define DFLT_WFP_SNAPSHOT_PARAM 0xa80 // 0x34 *** 2688 => nb samples
131 #define DFLT_WFP_BUFFER_LENGTH 0x1f8 // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
131 #define DFLT_WFP_BUFFER_LENGTH 0x1f8 // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
132 #define DFLT_WFP_DELTA_F0_2 0x30 // 48 = 11 0000, max 7 bits
132 #define DFLT_WFP_DELTA_F0_2 0x30 // 48 = 11 0000, max 7 bits
133
133
134 // PDB >= 0.1.28, 0x80000f54
134 // PDB >= 0.1.28, 0x80000f54
135 typedef struct{
135 typedef struct{
136 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
136 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
137 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
137 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
138 int addr_data_f0_0; // 0x08
138 int addr_data_f0_0; // 0x08
139 int addr_data_f0_1; // 0x0c
139 int addr_data_f0_1; // 0x0c
140 int addr_data_f1_0; // 0x10
140 int addr_data_f1_0; // 0x10
141 int addr_data_f1_1; // 0x14
141 int addr_data_f1_1; // 0x14
142 int addr_data_f2_0; // 0x18
142 int addr_data_f2_0; // 0x18
143 int addr_data_f2_1; // 0x1c
143 int addr_data_f2_1; // 0x1c
144 int addr_data_f3_0; // 0x20
144 int addr_data_f3_0; // 0x20
145 int addr_data_f3_1; // 0x24
145 int addr_data_f3_1; // 0x24
146 volatile int status; // 0x28
146 volatile int status; // 0x28
147 volatile int delta_snapshot; // 0x2c
147 volatile int delta_snapshot; // 0x2c
148 int delta_f0; // 0x30
148 int delta_f0; // 0x30
149 int delta_f0_2; // 0x34
149 int delta_f0_2; // 0x34
150 int delta_f1; // 0x38
150 int delta_f1; // 0x38
151 int delta_f2; // 0x3c
151 int delta_f2; // 0x3c
152 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
152 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
153 int snapshot_param; // 0x44
153 int snapshot_param; // 0x44
154 int start_date; // 0x48
154 int start_date; // 0x48
155 //
155 //
156 volatile unsigned int f0_0_coarse_time; // 0x4c
156 volatile unsigned int f0_0_coarse_time; // 0x4c
157 volatile unsigned int f0_0_fine_time; // 0x50
157 volatile unsigned int f0_0_fine_time; // 0x50
158 volatile unsigned int f0_1_coarse_time; // 0x54
158 volatile unsigned int f0_1_coarse_time; // 0x54
159 volatile unsigned int f0_1_fine_time; // 0x58
159 volatile unsigned int f0_1_fine_time; // 0x58
160 //
160 //
161 volatile unsigned int f1_0_coarse_time; // 0x5c
161 volatile unsigned int f1_0_coarse_time; // 0x5c
162 volatile unsigned int f1_0_fine_time; // 0x60
162 volatile unsigned int f1_0_fine_time; // 0x60
163 volatile unsigned int f1_1_coarse_time; // 0x64
163 volatile unsigned int f1_1_coarse_time; // 0x64
164 volatile unsigned int f1_1_fine_time; // 0x68
164 volatile unsigned int f1_1_fine_time; // 0x68
165 //
165 //
166 volatile unsigned int f2_0_coarse_time; // 0x6c
166 volatile unsigned int f2_0_coarse_time; // 0x6c
167 volatile unsigned int f2_0_fine_time; // 0x70
167 volatile unsigned int f2_0_fine_time; // 0x70
168 volatile unsigned int f2_1_coarse_time; // 0x74
168 volatile unsigned int f2_1_coarse_time; // 0x74
169 volatile unsigned int f2_1_fine_time; // 0x78
169 volatile unsigned int f2_1_fine_time; // 0x78
170 //
170 //
171 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
171 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
172 volatile unsigned int f3_0_fine_time; // 0x80
172 volatile unsigned int f3_0_fine_time; // 0x80
173 volatile unsigned int f3_1_coarse_time; // 0x84
173 volatile unsigned int f3_1_coarse_time; // 0x84
174 volatile unsigned int f3_1_fine_time; // 0x88
174 volatile unsigned int f3_1_fine_time; // 0x88
175 //
175 //
176 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
176 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
177 //
177 //
178 volatile int16_t v_dummy; // 0x90
178 volatile int v; // 0x90
179 volatile int16_t v; // 0x90
179 volatile int e1; // 0x94
180 volatile int16_t e1_dummy; // 0x94
180 volatile int e2; // 0x98
181 volatile int16_t e1; // 0x94
182 volatile int16_t e2_dummy; // 0x98
183 volatile int16_t e2; // 0x98
184 } waveform_picker_regs_0_1_18_t;
181 } waveform_picker_regs_0_1_18_t;
185
182
186 //*********************
183 //*********************
187 //*********************
184 //*********************
188 // SPECTRAL_MATRIX_REGS
185 // SPECTRAL_MATRIX_REGS
189
186
190 #define BITS_STATUS_F0 0x03 // [0011]
187 #define BITS_STATUS_F0 0x03 // [0011]
191 #define BITS_STATUS_F1 0x0c // [1100]
188 #define BITS_STATUS_F1 0x0c // [1100]
192 #define BITS_STATUS_F2 0x30 // [0011 0000]
189 #define BITS_STATUS_F2 0x30 // [0011 0000]
193 #define BITS_HK_AA_SM 0x780 // [0111 1000 0000]
190 #define BITS_HK_AA_SM 0x780 // [0111 1000 0000]
194 #define BITS_SM_ERR 0x7c0 // [0111 1100 0000]
191 #define BITS_SM_ERR 0x7c0 // [0111 1100 0000]
195 #define BITS_STATUS_REG 0x7ff // [0111 1111 1111]
192 #define BITS_STATUS_REG 0x7ff // [0111 1111 1111]
196 #define BIT_READY_0 0x1 // [01]
193 #define BIT_READY_0 0x1 // [01]
197 #define BIT_READY_1 0x2 // [10]
194 #define BIT_READY_1 0x2 // [10]
198 #define BIT_READY_0_1 0x3 // [11]
195 #define BIT_READY_0_1 0x3 // [11]
199 #define BIT_STATUS_F1_0 0x04 // [0100]
196 #define BIT_STATUS_F1_0 0x04 // [0100]
200 #define BIT_STATUS_F1_1 0x08 // [1000]
197 #define BIT_STATUS_F1_1 0x08 // [1000]
201 #define BIT_STATUS_F2_0 0x10 // [0001 0000]
198 #define BIT_STATUS_F2_0 0x10 // [0001 0000]
202 #define BIT_STATUS_F2_1 0x20 // [0010 0000]
199 #define BIT_STATUS_F2_1 0x20 // [0010 0000]
203 #define DEFAULT_MATRIX_LENGTH 0xc8 // 25 * 128 / 16 = 200 = 0xc8
200 #define DEFAULT_MATRIX_LENGTH 0xc8 // 25 * 128 / 16 = 200 = 0xc8
204 #define BIT_IRQ_ON_NEW_MATRIX 0x01
201 #define BIT_IRQ_ON_NEW_MATRIX 0x01
205 #define MASK_IRQ_ON_NEW_MATRIX 0xfffffffe
202 #define MASK_IRQ_ON_NEW_MATRIX 0xfffffffe
206 #define BIT_IRQ_ON_ERROR 0x02
203 #define BIT_IRQ_ON_ERROR 0x02
207 #define MASK_IRQ_ON_ERROR 0xfffffffd
204 #define MASK_IRQ_ON_ERROR 0xfffffffd
208
205
209 typedef struct {
206 typedef struct {
210 volatile int config; // 0x00
207 volatile int config; // 0x00
211 volatile int status; // 0x04
208 volatile int status; // 0x04
212 volatile int f0_0_address; // 0x08
209 volatile int f0_0_address; // 0x08
213 volatile int f0_1_address; // 0x0C
210 volatile int f0_1_address; // 0x0C
214 //
211 //
215 volatile int f1_0_address; // 0x10
212 volatile int f1_0_address; // 0x10
216 volatile int f1_1_address; // 0x14
213 volatile int f1_1_address; // 0x14
217 volatile int f2_0_address; // 0x18
214 volatile int f2_0_address; // 0x18
218 volatile int f2_1_address; // 0x1C
215 volatile int f2_1_address; // 0x1C
219 //
216 //
220 volatile unsigned int f0_0_coarse_time; // 0x20
217 volatile unsigned int f0_0_coarse_time; // 0x20
221 volatile unsigned int f0_0_fine_time; // 0x24
218 volatile unsigned int f0_0_fine_time; // 0x24
222 volatile unsigned int f0_1_coarse_time; // 0x28
219 volatile unsigned int f0_1_coarse_time; // 0x28
223 volatile unsigned int f0_1_fine_time; // 0x2C
220 volatile unsigned int f0_1_fine_time; // 0x2C
224 //
221 //
225 volatile unsigned int f1_0_coarse_time; // 0x30
222 volatile unsigned int f1_0_coarse_time; // 0x30
226 volatile unsigned int f1_0_fine_time; // 0x34
223 volatile unsigned int f1_0_fine_time; // 0x34
227 volatile unsigned int f1_1_coarse_time; // 0x38
224 volatile unsigned int f1_1_coarse_time; // 0x38
228 volatile unsigned int f1_1_fine_time; // 0x3C
225 volatile unsigned int f1_1_fine_time; // 0x3C
229 //
226 //
230 volatile unsigned int f2_0_coarse_time; // 0x40
227 volatile unsigned int f2_0_coarse_time; // 0x40
231 volatile unsigned int f2_0_fine_time; // 0x44
228 volatile unsigned int f2_0_fine_time; // 0x44
232 volatile unsigned int f2_1_coarse_time; // 0x48
229 volatile unsigned int f2_1_coarse_time; // 0x48
233 volatile unsigned int f2_1_fine_time; // 0x4C
230 volatile unsigned int f2_1_fine_time; // 0x4C
234 //
231 //
235 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
232 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
236 } spectral_matrix_regs_t;
233 } spectral_matrix_regs_t;
237
234
238 #endif // GRLIB_REGS_H_INCLUDED
235 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,122 +1,124
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6
6
7 #include "fsw_params.h"
7 #include "fsw_params.h"
8 #include "wf_handler.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "fsw_misc.h"
10 #include "fsw_misc.h"
11 #include "basic_parameters_params.h"
11 #include "basic_parameters_params.h"
12 #include "avf0_prc0.h"
12 #include "avf0_prc0.h"
13
13
14 #define FLOAT_EQUAL_ZERO 0.001
14 #define FLOAT_EQUAL_ZERO 0.001
15 #define NB_BINS_TO_REMOVE 3
15 #define NB_BINS_TO_REMOVE 3
16 #define FI_INTERVAL_COEFF 0.285
16 #define FI_INTERVAL_COEFF 0.285
17 #define BIN_MIN 0
17 #define BIN_MIN 0
18 #define BIN_MAX 127
18 #define BIN_MAX 127
19 #define DELTAF_F0 96.
19 #define DELTAF_F0 96.
20 #define DELTAF_F1 16.
20 #define DELTAF_F1 16.
21 #define DELTAF_F2 1.
21 #define DELTAF_F2 1.
22 #define DELTAF_DIV 2.
22 #define DELTAF_DIV 2.
23
23
24 #define BIT_RW1_F1 0x80
24 #define BIT_RW1_F1 0x80
25 #define BIT_RW1_F2 0x40
25 #define BIT_RW1_F2 0x40
26 #define BIT_RW2_F1 0x20
26 #define BIT_RW2_F1 0x20
27 #define BIT_RW2_F2 0x10
27 #define BIT_RW2_F2 0x10
28 #define BIT_RW3_F1 0x08
28 #define BIT_RW3_F1 0x08
29 #define BIT_RW3_F2 0x04
29 #define BIT_RW3_F2 0x04
30 #define BIT_RW4_F1 0x02
30 #define BIT_RW4_F1 0x02
31 #define BIT_RW4_F2 0x01
31 #define BIT_RW4_F2 0x01
32
32
33 #define WHEEL_1 1
33 #define WHEEL_1 1
34 #define WHEEL_2 2
34 #define WHEEL_2 2
35 #define WHEEL_3 3
35 #define WHEEL_3 3
36 #define WHEEL_4 4
36 #define WHEEL_4 4
37 #define FREQ_1 1
37 #define FREQ_1 1
38 #define FREQ_2 2
38 #define FREQ_2 2
39 #define FREQ_3 3
39 #define FREQ_3 3
40 #define FREQ_4 4
40 #define FREQ_4 4
41 #define FLAG_OFFSET_WHEELS_1_3 8
41 #define FLAG_OFFSET_WHEELS_1_3 8
42 #define FLAG_OFFSET_WHEELS_2_4 4
42 #define FLAG_OFFSET_WHEELS_2_4 4
43
43
44 #define FLAG_NAN 0 // Not A NUMBER
44 #define FLAG_NAN 0 // Not A NUMBER
45 #define FLAG_IAN 1 // Is A Number
45 #define FLAG_IAN 1 // Is A Number
46
46
47 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
47 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
48
48
49 extern unsigned short sequenceCounterParameterDump;
49 extern unsigned short sequenceCounterParameterDump;
50 extern unsigned short sequenceCounters_TM_DUMP[];
50 extern unsigned short sequenceCounters_TM_DUMP[];
51 extern float k_coeff_intercalib_f0_norm[ ];
51 extern float k_coeff_intercalib_f0_norm[ ];
52 extern float k_coeff_intercalib_f0_sbm[ ];
52 extern float k_coeff_intercalib_f0_sbm[ ];
53 extern float k_coeff_intercalib_f1_norm[ ];
53 extern float k_coeff_intercalib_f1_norm[ ];
54 extern float k_coeff_intercalib_f1_sbm[ ];
54 extern float k_coeff_intercalib_f1_sbm[ ];
55 extern float k_coeff_intercalib_f2[ ];
55 extern float k_coeff_intercalib_f2[ ];
56 extern fbins_masks_t fbins_masks;
56 extern fbins_masks_t fbins_masks;
57
57
58 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
58 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
59 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
59 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
60 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
60 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
61 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
61 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
62 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
62 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
63 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
63 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
64 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
64 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
65 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
65 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
66 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
66 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
67 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
67 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
68
68
69 // NORMAL
69 // NORMAL
70 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
70 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
71 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
71 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
74 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
75 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
75 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
76 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
76 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
77
77
78 // BURST
78 // BURST
79 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
79 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
80 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
80 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
81
81
82 // SBM1
82 // SBM1
83 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
83 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
84 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
84 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
85
85
86 // SBM2
86 // SBM2
87 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
87 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
88 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
88 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
89
89
90 // TC_LFR_UPDATE_INFO
90 // TC_LFR_UPDATE_INFO
91 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
91 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
92 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
92 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
93 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
93 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
94 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
94 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value );
95 void set_hk_lfr_sc_rw_f_flags( void );
95 void set_hk_lfr_sc_rw_f_flags( void );
96 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
97 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
96 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
98 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
97 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k );
99 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k );
98 void build_sy_lfr_rw_mask( unsigned int channel );
100 void build_sy_lfr_rw_mask( unsigned int channel );
99 void build_sy_lfr_rw_masks();
101 void build_sy_lfr_rw_masks();
100 void merge_fbins_masks( void );
102 void merge_fbins_masks( void );
101
103
102 // FBINS_MASK
104 // FBINS_MASK
103 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
105 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
104
106
105 // TC_LFR_LOAD_PARS_FILTER_PAR
107 // TC_LFR_LOAD_PARS_FILTER_PAR
106 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
108 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value );
107 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
109 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float*value );
108 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
110 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
109
111
110 // KCOEFFICIENTS
112 // KCOEFFICIENTS
111 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
113 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
112 void copyFloatByChar( unsigned char *destination, unsigned char *source );
114 void copyFloatByChar( unsigned char *destination, unsigned char *source );
113 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
115 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
114 void copyInt16ByChar( unsigned char *destination, unsigned char *source );
116 void copyInt16ByChar( unsigned char *destination, unsigned char *source );
115 void floatToChar( float value, unsigned char* ptr);
117 void floatToChar( float value, unsigned char* ptr);
116
118
117 void init_parameter_dump( void );
119 void init_parameter_dump( void );
118 void init_kcoefficients_dump( void );
120 void init_kcoefficients_dump( void );
119 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
121 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
120 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
122 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
121
123
122 #endif // TC_LOAD_DUMP_PARAMETERS_H
124 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -1,98 +1,98
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 // message queues occupancy
76 // message queues occupancy
77 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
77 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
78 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
78 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
79 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
79 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
82 // sequence counters are incremented by APID (PID + CAT) and destination ID
82 // sequence counters are incremented by APID (PID + CAT) and destination ID
83 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST = 0;
83 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST __attribute__((aligned(0x4))) = 0;
84 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 = 0;
84 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 __attribute__((aligned(0x4))) = 0;
85 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] = {0};
85 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
86 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] = {0};
86 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
87 unsigned short sequenceCounterHK = {0};
87 unsigned short sequenceCounterHK __attribute__((aligned(0x4))) = {0};
88 spw_stats grspw_stats = {0};
88 spw_stats grspw_stats __attribute__((aligned(0x4))) = {0};
89
89
90 // TC_LFR_UPDATE_INFO
90 // TC_LFR_UPDATE_INFO
91 rw_f_t rw_f;
91 rw_f_t rw_f;
92
92
93 // TC_LFR_LOAD_FILTER_PAR
93 // TC_LFR_LOAD_FILTER_PAR
94 filterPar_t filterPar = {0};
94 filterPar_t filterPar = {0};
95
95
96 fbins_masks_t fbins_masks = {0};
96 fbins_masks_t fbins_masks = {0};
97 unsigned int acquisitionDurations[NB_ACQUISITION_DURATION]
97 unsigned int acquisitionDurations[NB_ACQUISITION_DURATION]
98 = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
98 = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
@@ -1,972 +1,972
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT
29 #define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5 // [hous] [load] [avgv]
37 #define CONFIGURE_MAXIMUM_PERIODS 6 // [hous] [load] [avgv]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
38 #define CONFIGURE_MAXIMUM_TIMERS 6 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50
50
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
53 #endif
54
54
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
57 #endif
58
58
59 #endif
59 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
61
62 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
63 #endif
63 #endif
64
64
65 #include "fsw_init.h"
65 #include "fsw_init.h"
66 #include "fsw_config.c"
66 #include "fsw_config.c"
67 #include "GscMemoryLPP.hpp"
67 #include "GscMemoryLPP.hpp"
68
68
69 void initCache()
69 void initCache()
70 {
70 {
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
72 // These should only be read and written using 32-bit LDA/STA instructions.
72 // These should only be read and written using 32-bit LDA/STA instructions.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
74 // The table below shows the register addresses:
74 // The table below shows the register addresses:
75 // 0x00 Cache control register
75 // 0x00 Cache control register
76 // 0x04 Reserved
76 // 0x04 Reserved
77 // 0x08 Instruction cache configuration register
77 // 0x08 Instruction cache configuration register
78 // 0x0C Data cache configuration register
78 // 0x0C Data cache configuration register
79
79
80 // Cache Control Register Leon3 / Leon3FT
80 // Cache Control Register Leon3 / Leon3FT
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
82 // RFT PS TB DS FD FI FT ST IB
82 // RFT PS TB DS FD FI FT ST IB
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
85
85
86 unsigned int cacheControlRegister;
86 unsigned int cacheControlRegister;
87
87
88 CCR_resetCacheControlRegister();
88 CCR_resetCacheControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
90
90
91 cacheControlRegister = CCR_getValue();
91 cacheControlRegister = CCR_getValue();
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
94
94
95 CCR_enableInstructionCache(); // ICS bits
95 CCR_enableInstructionCache(); // ICS bits
96 CCR_enableDataCache(); // DCS bits
96 CCR_enableDataCache(); // DCS bits
97 CCR_enableInstructionBurstFetch(); // IB bit
97 CCR_enableInstructionBurstFetch(); // IB bit
98
98
99 faultTolerantScheme();
99 faultTolerantScheme();
100
100
101 cacheControlRegister = CCR_getValue();
101 cacheControlRegister = CCR_getValue();
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
104
104
105 PRINTF("\n");
105 PRINTF("\n");
106 }
106 }
107
107
108 rtems_task Init( rtems_task_argument ignored )
108 rtems_task Init( rtems_task_argument ignored )
109 {
109 {
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
111 *
111 *
112 * @param unused is the starting argument of the RTEMS task
112 * @param unused is the starting argument of the RTEMS task
113 *
113 *
114 * The INIT task create and run all other RTEMS tasks.
114 * The INIT task create and run all other RTEMS tasks.
115 *
115 *
116 */
116 */
117
117
118 //***********
118 //***********
119 // INIT CACHE
119 // INIT CACHE
120
120
121 unsigned char *vhdlVersion;
121 unsigned char *vhdlVersion;
122
122
123 reset_lfr();
123 reset_lfr();
124
124
125 reset_local_time();
125 reset_local_time();
126
126
127 rtems_cpu_usage_reset();
127 rtems_cpu_usage_reset();
128
128
129 rtems_status_code status;
129 rtems_status_code status;
130 rtems_status_code status_spw;
130 rtems_status_code status_spw;
131 rtems_isr_entry old_isr_handler;
131 rtems_isr_entry old_isr_handler;
132
132
133 old_isr_handler = NULL;
133 old_isr_handler = NULL;
134
134
135 // UART settings
135 // UART settings
136 enable_apbuart_transmitter();
136 enable_apbuart_transmitter();
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
138
138
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
140
140
141
141
142 PRINTF("\n\n\n\n\n")
142 PRINTF("\n\n\n\n\n")
143
143
144 initCache();
144 initCache();
145
145
146 PRINTF("*************************\n")
146 PRINTF("*************************\n")
147 PRINTF("** LFR Flight Software **\n")
147 PRINTF("** LFR Flight Software **\n")
148
148
149 PRINTF1("** %d-", SW_VERSION_N1)
149 PRINTF1("** %d-", SW_VERSION_N1)
150 PRINTF1("%d-" , SW_VERSION_N2)
150 PRINTF1("%d-" , SW_VERSION_N2)
151 PRINTF1("%d-" , SW_VERSION_N3)
151 PRINTF1("%d-" , SW_VERSION_N3)
152 PRINTF1("%d **\n", SW_VERSION_N4)
152 PRINTF1("%d **\n", SW_VERSION_N4)
153
153
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
155 PRINTF("** VHDL **\n")
155 PRINTF("** VHDL **\n")
156 PRINTF1("** %d-", vhdlVersion[1])
156 PRINTF1("** %d-", vhdlVersion[1])
157 PRINTF1("%d-" , vhdlVersion[2])
157 PRINTF1("%d-" , vhdlVersion[2])
158 PRINTF1("%d **\n", vhdlVersion[3])
158 PRINTF1("%d **\n", vhdlVersion[3])
159 PRINTF("*************************\n")
159 PRINTF("*************************\n")
160 PRINTF("\n\n")
160 PRINTF("\n\n")
161
161
162 init_parameter_dump();
162 init_parameter_dump();
163 init_kcoefficients_dump();
163 init_kcoefficients_dump();
164 init_local_mode_parameters();
164 init_local_mode_parameters();
165 init_housekeeping_parameters();
165 init_housekeeping_parameters();
166 init_k_coefficients_prc0();
166 init_k_coefficients_prc0();
167 init_k_coefficients_prc1();
167 init_k_coefficients_prc1();
168 init_k_coefficients_prc2();
168 init_k_coefficients_prc2();
169 pa_bia_status_info = INIT_CHAR;
169 pa_bia_status_info = INIT_CHAR;
170
170
171 // initialize all reaction wheels frequencies to NaN
171 // initialize all reaction wheels frequencies to NaN
172 rw_f.cp_rpw_sc_rw1_f1 = NAN;
172 rw_f.cp_rpw_sc_rw1_f1 = NAN;
173 rw_f.cp_rpw_sc_rw1_f2 = NAN;
173 rw_f.cp_rpw_sc_rw1_f2 = NAN;
174 rw_f.cp_rpw_sc_rw1_f3 = NAN;
174 rw_f.cp_rpw_sc_rw1_f3 = NAN;
175 rw_f.cp_rpw_sc_rw1_f4 = NAN;
175 rw_f.cp_rpw_sc_rw1_f4 = NAN;
176 rw_f.cp_rpw_sc_rw2_f1 = NAN;
176 rw_f.cp_rpw_sc_rw2_f1 = NAN;
177 rw_f.cp_rpw_sc_rw2_f2 = NAN;
177 rw_f.cp_rpw_sc_rw2_f2 = NAN;
178 rw_f.cp_rpw_sc_rw2_f3 = NAN;
178 rw_f.cp_rpw_sc_rw2_f3 = NAN;
179 rw_f.cp_rpw_sc_rw2_f4 = NAN;
179 rw_f.cp_rpw_sc_rw2_f4 = NAN;
180 rw_f.cp_rpw_sc_rw3_f1 = NAN;
180 rw_f.cp_rpw_sc_rw3_f1 = NAN;
181 rw_f.cp_rpw_sc_rw3_f2 = NAN;
181 rw_f.cp_rpw_sc_rw3_f2 = NAN;
182 rw_f.cp_rpw_sc_rw3_f3 = NAN;
182 rw_f.cp_rpw_sc_rw3_f3 = NAN;
183 rw_f.cp_rpw_sc_rw3_f4 = NAN;
183 rw_f.cp_rpw_sc_rw3_f4 = NAN;
184 rw_f.cp_rpw_sc_rw4_f1 = NAN;
184 rw_f.cp_rpw_sc_rw4_f1 = NAN;
185 rw_f.cp_rpw_sc_rw4_f2 = NAN;
185 rw_f.cp_rpw_sc_rw4_f2 = NAN;
186 rw_f.cp_rpw_sc_rw4_f3 = NAN;
186 rw_f.cp_rpw_sc_rw4_f3 = NAN;
187 rw_f.cp_rpw_sc_rw4_f4 = NAN;
187 rw_f.cp_rpw_sc_rw4_f4 = NAN;
188
188
189 // initialize filtering parameters
189 // initialize filtering parameters
190 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
190 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
191 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
191 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
192 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
192 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
193 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
193 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
194 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
194 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
195 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
195 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
196 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
196 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
197
197
198 // waveform picker initialization
198 // waveform picker initialization
199 WFP_init_rings();
199 WFP_init_rings();
200 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
200 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
201 WFP_reset_current_ring_nodes();
201 WFP_reset_current_ring_nodes();
202 reset_waveform_picker_regs();
202 reset_waveform_picker_regs();
203
203
204 // spectral matrices initialization
204 // spectral matrices initialization
205 SM_init_rings(); // initialize spectral matrices rings
205 SM_init_rings(); // initialize spectral matrices rings
206 SM_reset_current_ring_nodes();
206 SM_reset_current_ring_nodes();
207 reset_spectral_matrix_regs();
207 reset_spectral_matrix_regs();
208
208
209 // configure calibration
209 // configure calibration
210 configureCalibration( false ); // true means interleaved mode, false is for normal mode
210 configureCalibration( false ); // true means interleaved mode, false is for normal mode
211
211
212 updateLFRCurrentMode( LFR_MODE_STANDBY );
212 updateLFRCurrentMode( LFR_MODE_STANDBY );
213
213
214 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
214 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
215
215
216 create_names(); // create all names
216 create_names(); // create all names
217
217
218 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
218 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
219 if (status != RTEMS_SUCCESSFUL)
219 if (status != RTEMS_SUCCESSFUL)
220 {
220 {
221 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
221 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
222 }
222 }
223
223
224 status = create_message_queues(); // create message queues
224 status = create_message_queues(); // create message queues
225 if (status != RTEMS_SUCCESSFUL)
225 if (status != RTEMS_SUCCESSFUL)
226 {
226 {
227 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
227 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
228 }
228 }
229
229
230 status = create_all_tasks(); // create all tasks
230 status = create_all_tasks(); // create all tasks
231 if (status != RTEMS_SUCCESSFUL)
231 if (status != RTEMS_SUCCESSFUL)
232 {
232 {
233 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
233 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
234 }
234 }
235
235
236 // **************************
236 // **************************
237 // <SPACEWIRE INITIALIZATION>
237 // <SPACEWIRE INITIALIZATION>
238 status_spw = spacewire_open_link(); // (1) open the link
238 status_spw = spacewire_open_link(); // (1) open the link
239 if ( status_spw != RTEMS_SUCCESSFUL )
239 if ( status_spw != RTEMS_SUCCESSFUL )
240 {
240 {
241 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
241 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
242 }
242 }
243
243
244 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
244 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
245 {
245 {
246 status_spw = spacewire_configure_link( fdSPW );
246 status_spw = spacewire_configure_link( fdSPW );
247 if ( status_spw != RTEMS_SUCCESSFUL )
247 if ( status_spw != RTEMS_SUCCESSFUL )
248 {
248 {
249 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
249 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
250 }
250 }
251 }
251 }
252
252
253 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
253 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
254 {
254 {
255 status_spw = spacewire_start_link( fdSPW );
255 status_spw = spacewire_start_link( fdSPW );
256 if ( status_spw != RTEMS_SUCCESSFUL )
256 if ( status_spw != RTEMS_SUCCESSFUL )
257 {
257 {
258 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
258 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
259 }
259 }
260 }
260 }
261 // </SPACEWIRE INITIALIZATION>
261 // </SPACEWIRE INITIALIZATION>
262 // ***************************
262 // ***************************
263
263
264 status = start_all_tasks(); // start all tasks
264 status = start_all_tasks(); // start all tasks
265 if (status != RTEMS_SUCCESSFUL)
265 if (status != RTEMS_SUCCESSFUL)
266 {
266 {
267 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
267 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
268 }
268 }
269
269
270 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
270 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
271 status = start_recv_send_tasks();
271 status = start_recv_send_tasks();
272 if ( status != RTEMS_SUCCESSFUL )
272 if ( status != RTEMS_SUCCESSFUL )
273 {
273 {
274 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
274 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
275 }
275 }
276
276
277 // suspend science tasks, they will be restarted later depending on the mode
277 // suspend science tasks, they will be restarted later depending on the mode
278 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
278 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
279 if (status != RTEMS_SUCCESSFUL)
279 if (status != RTEMS_SUCCESSFUL)
280 {
280 {
281 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
281 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
282 }
282 }
283
283
284 // configure IRQ handling for the waveform picker unit
284 // configure IRQ handling for the waveform picker unit
285 status = rtems_interrupt_catch( waveforms_isr,
285 status = rtems_interrupt_catch( waveforms_isr,
286 IRQ_SPARC_WAVEFORM_PICKER,
286 IRQ_SPARC_WAVEFORM_PICKER,
287 &old_isr_handler) ;
287 &old_isr_handler) ;
288 // configure IRQ handling for the spectral matrices unit
288 // configure IRQ handling for the spectral matrices unit
289 status = rtems_interrupt_catch( spectral_matrices_isr,
289 status = rtems_interrupt_catch( spectral_matrices_isr,
290 IRQ_SPARC_SPECTRAL_MATRIX,
290 IRQ_SPARC_SPECTRAL_MATRIX,
291 &old_isr_handler) ;
291 &old_isr_handler) ;
292
292
293 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
293 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
294 if ( status_spw != RTEMS_SUCCESSFUL )
294 if ( status_spw != RTEMS_SUCCESSFUL )
295 {
295 {
296 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
296 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
297 if ( status != RTEMS_SUCCESSFUL ) {
297 if ( status != RTEMS_SUCCESSFUL ) {
298 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
298 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
299 }
299 }
300 }
300 }
301
301
302 BOOT_PRINTF("delete INIT\n")
302 BOOT_PRINTF("delete INIT\n")
303
303
304 set_hk_lfr_sc_potential_flag( true );
304 set_hk_lfr_sc_potential_flag( true );
305
305
306 // start the timer to detect a missing spacewire timecode
306 // start the timer to detect a missing spacewire timecode
307 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
307 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
308 // if a tickout is generated, the timer is restarted
308 // if a tickout is generated, the timer is restarted
309 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
309 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
310
310
311 grspw_timecode_callback = &timecode_irq_handler;
311 grspw_timecode_callback = &timecode_irq_handler;
312
312
313 status = rtems_task_delete(RTEMS_SELF);
313 status = rtems_task_delete(RTEMS_SELF);
314
314
315 }
315 }
316
316
317 void init_local_mode_parameters( void )
317 void init_local_mode_parameters( void )
318 {
318 {
319 /** This function initialize the param_local global variable with default values.
319 /** This function initialize the param_local global variable with default values.
320 *
320 *
321 */
321 */
322
322
323 unsigned int i;
323 unsigned int i;
324
324
325 // LOCAL PARAMETERS
325 // LOCAL PARAMETERS
326
326
327 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
327 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
328 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
328 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
329
329
330 // init sequence counters
330 // init sequence counters
331
331
332 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
332 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
333 {
333 {
334 sequenceCounters_TC_EXE[i] = INIT_CHAR;
334 sequenceCounters_TC_EXE[i] = INIT_CHAR;
335 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
335 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
336 }
336 }
337 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
337 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
338 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
338 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
339 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
339 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
340 }
340 }
341
341
342 void reset_local_time( void )
342 void reset_local_time( void )
343 {
343 {
344 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
344 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
345 }
345 }
346
346
347 void create_names( void ) // create all names for tasks and queues
347 void create_names( void ) // create all names for tasks and queues
348 {
348 {
349 /** This function creates all RTEMS names used in the software for tasks and queues.
349 /** This function creates all RTEMS names used in the software for tasks and queues.
350 *
350 *
351 * @return RTEMS directive status codes:
351 * @return RTEMS directive status codes:
352 * - RTEMS_SUCCESSFUL - successful completion
352 * - RTEMS_SUCCESSFUL - successful completion
353 *
353 *
354 */
354 */
355
355
356 // task names
356 // task names
357 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
357 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
358 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
358 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
359 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
359 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
360 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
360 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
361 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
361 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
362 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
362 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
363 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
363 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
364 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
364 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
365 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
365 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
366 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
366 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
367 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
367 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
368 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
368 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
369 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
369 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
370 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
370 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
371 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
371 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
372 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
372 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
373 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
373 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
374 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
374 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
375 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
375 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
376 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
376 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
377
377
378 // rate monotonic period names
378 // rate monotonic period names
379 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
379 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
380 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
380 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
381
381
382 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
382 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
383 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
383 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
384 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
384 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
385 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
385 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
386 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
386 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
387
387
388 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
388 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
389 }
389 }
390
390
391 int create_all_tasks( void ) // create all tasks which run in the software
391 int create_all_tasks( void ) // create all tasks which run in the software
392 {
392 {
393 /** This function creates all RTEMS tasks used in the software.
393 /** This function creates all RTEMS tasks used in the software.
394 *
394 *
395 * @return RTEMS directive status codes:
395 * @return RTEMS directive status codes:
396 * - RTEMS_SUCCESSFUL - task created successfully
396 * - RTEMS_SUCCESSFUL - task created successfully
397 * - RTEMS_INVALID_ADDRESS - id is NULL
397 * - RTEMS_INVALID_ADDRESS - id is NULL
398 * - RTEMS_INVALID_NAME - invalid task name
398 * - RTEMS_INVALID_NAME - invalid task name
399 * - RTEMS_INVALID_PRIORITY - invalid task priority
399 * - RTEMS_INVALID_PRIORITY - invalid task priority
400 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
400 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
401 * - RTEMS_TOO_MANY - too many tasks created
401 * - RTEMS_TOO_MANY - too many tasks created
402 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
402 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
403 * - RTEMS_TOO_MANY - too many global objects
403 * - RTEMS_TOO_MANY - too many global objects
404 *
404 *
405 */
405 */
406
406
407 rtems_status_code status;
407 rtems_status_code status;
408
408
409 //**********
409 //**********
410 // SPACEWIRE
410 // SPACEWIRE
411 // RECV
411 // RECV
412 status = rtems_task_create(
412 status = rtems_task_create(
413 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
413 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
414 RTEMS_DEFAULT_MODES,
414 RTEMS_DEFAULT_MODES,
415 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
415 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
416 );
416 );
417 if (status == RTEMS_SUCCESSFUL) // SEND
417 if (status == RTEMS_SUCCESSFUL) // SEND
418 {
418 {
419 status = rtems_task_create(
419 status = rtems_task_create(
420 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
420 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
421 RTEMS_DEFAULT_MODES,
421 RTEMS_DEFAULT_MODES,
422 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
422 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
423 );
423 );
424 }
424 }
425 if (status == RTEMS_SUCCESSFUL) // LINK
425 if (status == RTEMS_SUCCESSFUL) // LINK
426 {
426 {
427 status = rtems_task_create(
427 status = rtems_task_create(
428 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
428 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
429 RTEMS_DEFAULT_MODES,
429 RTEMS_DEFAULT_MODES,
430 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
430 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
431 );
431 );
432 }
432 }
433 if (status == RTEMS_SUCCESSFUL) // ACTN
433 if (status == RTEMS_SUCCESSFUL) // ACTN
434 {
434 {
435 status = rtems_task_create(
435 status = rtems_task_create(
436 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
436 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
437 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
437 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
438 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
438 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
439 );
439 );
440 }
440 }
441 if (status == RTEMS_SUCCESSFUL) // SPIQ
441 if (status == RTEMS_SUCCESSFUL) // SPIQ
442 {
442 {
443 status = rtems_task_create(
443 status = rtems_task_create(
444 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
444 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
445 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
445 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
446 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
446 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
447 );
447 );
448 }
448 }
449
449
450 //******************
450 //******************
451 // SPECTRAL MATRICES
451 // SPECTRAL MATRICES
452 if (status == RTEMS_SUCCESSFUL) // AVF0
452 if (status == RTEMS_SUCCESSFUL) // AVF0
453 {
453 {
454 status = rtems_task_create(
454 status = rtems_task_create(
455 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
455 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
456 RTEMS_DEFAULT_MODES,
456 RTEMS_DEFAULT_MODES,
457 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
457 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
458 );
458 );
459 }
459 }
460 if (status == RTEMS_SUCCESSFUL) // PRC0
460 if (status == RTEMS_SUCCESSFUL) // PRC0
461 {
461 {
462 status = rtems_task_create(
462 status = rtems_task_create(
463 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
463 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
464 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
464 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
466 );
466 );
467 }
467 }
468 if (status == RTEMS_SUCCESSFUL) // AVF1
468 if (status == RTEMS_SUCCESSFUL) // AVF1
469 {
469 {
470 status = rtems_task_create(
470 status = rtems_task_create(
471 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
471 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
472 RTEMS_DEFAULT_MODES,
472 RTEMS_DEFAULT_MODES,
473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
474 );
474 );
475 }
475 }
476 if (status == RTEMS_SUCCESSFUL) // PRC1
476 if (status == RTEMS_SUCCESSFUL) // PRC1
477 {
477 {
478 status = rtems_task_create(
478 status = rtems_task_create(
479 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
479 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
480 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
480 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
481 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
481 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
482 );
482 );
483 }
483 }
484 if (status == RTEMS_SUCCESSFUL) // AVF2
484 if (status == RTEMS_SUCCESSFUL) // AVF2
485 {
485 {
486 status = rtems_task_create(
486 status = rtems_task_create(
487 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
487 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
488 RTEMS_DEFAULT_MODES,
488 RTEMS_DEFAULT_MODES,
489 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
489 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
490 );
490 );
491 }
491 }
492 if (status == RTEMS_SUCCESSFUL) // PRC2
492 if (status == RTEMS_SUCCESSFUL) // PRC2
493 {
493 {
494 status = rtems_task_create(
494 status = rtems_task_create(
495 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
495 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
496 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
496 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
498 );
498 );
499 }
499 }
500
500
501 //****************
501 //****************
502 // WAVEFORM PICKER
502 // WAVEFORM PICKER
503 if (status == RTEMS_SUCCESSFUL) // WFRM
503 if (status == RTEMS_SUCCESSFUL) // WFRM
504 {
504 {
505 status = rtems_task_create(
505 status = rtems_task_create(
506 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
506 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
507 RTEMS_DEFAULT_MODES,
507 RTEMS_DEFAULT_MODES,
508 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
508 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
509 );
509 );
510 }
510 }
511 if (status == RTEMS_SUCCESSFUL) // CWF3
511 if (status == RTEMS_SUCCESSFUL) // CWF3
512 {
512 {
513 status = rtems_task_create(
513 status = rtems_task_create(
514 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
514 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
515 RTEMS_DEFAULT_MODES,
515 RTEMS_DEFAULT_MODES,
516 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
516 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
517 );
517 );
518 }
518 }
519 if (status == RTEMS_SUCCESSFUL) // CWF2
519 if (status == RTEMS_SUCCESSFUL) // CWF2
520 {
520 {
521 status = rtems_task_create(
521 status = rtems_task_create(
522 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
522 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
523 RTEMS_DEFAULT_MODES,
523 RTEMS_DEFAULT_MODES,
524 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
524 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
525 );
525 );
526 }
526 }
527 if (status == RTEMS_SUCCESSFUL) // CWF1
527 if (status == RTEMS_SUCCESSFUL) // CWF1
528 {
528 {
529 status = rtems_task_create(
529 status = rtems_task_create(
530 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
530 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
531 RTEMS_DEFAULT_MODES,
531 RTEMS_DEFAULT_MODES,
532 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
532 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
533 );
533 );
534 }
534 }
535 if (status == RTEMS_SUCCESSFUL) // SWBD
535 if (status == RTEMS_SUCCESSFUL) // SWBD
536 {
536 {
537 status = rtems_task_create(
537 status = rtems_task_create(
538 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
538 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
539 RTEMS_DEFAULT_MODES,
539 RTEMS_DEFAULT_MODES,
540 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
540 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
541 );
541 );
542 }
542 }
543
543
544 //*****
544 //*****
545 // MISC
545 // MISC
546 if (status == RTEMS_SUCCESSFUL) // LOAD
546 if (status == RTEMS_SUCCESSFUL) // LOAD
547 {
547 {
548 status = rtems_task_create(
548 status = rtems_task_create(
549 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
549 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
550 RTEMS_DEFAULT_MODES,
550 RTEMS_DEFAULT_MODES,
551 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
551 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
552 );
552 );
553 }
553 }
554 if (status == RTEMS_SUCCESSFUL) // DUMB
554 if (status == RTEMS_SUCCESSFUL) // DUMB
555 {
555 {
556 status = rtems_task_create(
556 status = rtems_task_create(
557 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
557 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
558 RTEMS_DEFAULT_MODES,
558 RTEMS_DEFAULT_MODES,
559 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
559 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
560 );
560 );
561 }
561 }
562 if (status == RTEMS_SUCCESSFUL) // HOUS
562 if (status == RTEMS_SUCCESSFUL) // HOUS
563 {
563 {
564 status = rtems_task_create(
564 status = rtems_task_create(
565 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
565 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
566 RTEMS_DEFAULT_MODES,
566 RTEMS_DEFAULT_MODES,
567 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
567 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
568 );
568 );
569 }
569 }
570 if (status == RTEMS_SUCCESSFUL) // AVGV
570 if (status == RTEMS_SUCCESSFUL) // AVGV
571 {
571 {
572 status = rtems_task_create(
572 status = rtems_task_create(
573 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
573 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
574 RTEMS_DEFAULT_MODES,
574 RTEMS_DEFAULT_MODES,
575 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
575 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
576 );
576 );
577 }
577 }
578
578
579 return status;
579 return status;
580 }
580 }
581
581
582 int start_recv_send_tasks( void )
582 int start_recv_send_tasks( void )
583 {
583 {
584 rtems_status_code status;
584 rtems_status_code status;
585
585
586 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
586 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
587 if (status!=RTEMS_SUCCESSFUL) {
587 if (status!=RTEMS_SUCCESSFUL) {
588 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
588 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
589 }
589 }
590
590
591 if (status == RTEMS_SUCCESSFUL) // SEND
591 if (status == RTEMS_SUCCESSFUL) // SEND
592 {
592 {
593 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
593 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
594 if (status!=RTEMS_SUCCESSFUL) {
594 if (status!=RTEMS_SUCCESSFUL) {
595 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
595 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
596 }
596 }
597 }
597 }
598
598
599 return status;
599 return status;
600 }
600 }
601
601
602 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
602 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
603 {
603 {
604 /** This function starts all RTEMS tasks used in the software.
604 /** This function starts all RTEMS tasks used in the software.
605 *
605 *
606 * @return RTEMS directive status codes:
606 * @return RTEMS directive status codes:
607 * - RTEMS_SUCCESSFUL - ask started successfully
607 * - RTEMS_SUCCESSFUL - ask started successfully
608 * - RTEMS_INVALID_ADDRESS - invalid task entry point
608 * - RTEMS_INVALID_ADDRESS - invalid task entry point
609 * - RTEMS_INVALID_ID - invalid task id
609 * - RTEMS_INVALID_ID - invalid task id
610 * - RTEMS_INCORRECT_STATE - task not in the dormant state
610 * - RTEMS_INCORRECT_STATE - task not in the dormant state
611 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
611 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
612 *
612 *
613 */
613 */
614 // starts all the tasks fot eh flight software
614 // starts all the tasks fot eh flight software
615
615
616 rtems_status_code status;
616 rtems_status_code status;
617
617
618 //**********
618 //**********
619 // SPACEWIRE
619 // SPACEWIRE
620 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
620 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
621 if (status!=RTEMS_SUCCESSFUL) {
621 if (status!=RTEMS_SUCCESSFUL) {
622 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
622 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
623 }
623 }
624
624
625 if (status == RTEMS_SUCCESSFUL) // LINK
625 if (status == RTEMS_SUCCESSFUL) // LINK
626 {
626 {
627 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
627 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
628 if (status!=RTEMS_SUCCESSFUL) {
628 if (status!=RTEMS_SUCCESSFUL) {
629 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
629 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
630 }
630 }
631 }
631 }
632
632
633 if (status == RTEMS_SUCCESSFUL) // ACTN
633 if (status == RTEMS_SUCCESSFUL) // ACTN
634 {
634 {
635 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
635 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
636 if (status!=RTEMS_SUCCESSFUL) {
636 if (status!=RTEMS_SUCCESSFUL) {
637 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
637 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
638 }
638 }
639 }
639 }
640
640
641 //******************
641 //******************
642 // SPECTRAL MATRICES
642 // SPECTRAL MATRICES
643 if (status == RTEMS_SUCCESSFUL) // AVF0
643 if (status == RTEMS_SUCCESSFUL) // AVF0
644 {
644 {
645 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
645 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
646 if (status!=RTEMS_SUCCESSFUL) {
646 if (status!=RTEMS_SUCCESSFUL) {
647 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
647 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
648 }
648 }
649 }
649 }
650 if (status == RTEMS_SUCCESSFUL) // PRC0
650 if (status == RTEMS_SUCCESSFUL) // PRC0
651 {
651 {
652 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
652 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
653 if (status!=RTEMS_SUCCESSFUL) {
653 if (status!=RTEMS_SUCCESSFUL) {
654 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
654 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
655 }
655 }
656 }
656 }
657 if (status == RTEMS_SUCCESSFUL) // AVF1
657 if (status == RTEMS_SUCCESSFUL) // AVF1
658 {
658 {
659 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
659 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
660 if (status!=RTEMS_SUCCESSFUL) {
660 if (status!=RTEMS_SUCCESSFUL) {
661 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
661 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
662 }
662 }
663 }
663 }
664 if (status == RTEMS_SUCCESSFUL) // PRC1
664 if (status == RTEMS_SUCCESSFUL) // PRC1
665 {
665 {
666 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
666 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
667 if (status!=RTEMS_SUCCESSFUL) {
667 if (status!=RTEMS_SUCCESSFUL) {
668 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
668 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
669 }
669 }
670 }
670 }
671 if (status == RTEMS_SUCCESSFUL) // AVF2
671 if (status == RTEMS_SUCCESSFUL) // AVF2
672 {
672 {
673 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
673 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
674 if (status!=RTEMS_SUCCESSFUL) {
674 if (status!=RTEMS_SUCCESSFUL) {
675 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
675 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
676 }
676 }
677 }
677 }
678 if (status == RTEMS_SUCCESSFUL) // PRC2
678 if (status == RTEMS_SUCCESSFUL) // PRC2
679 {
679 {
680 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
680 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
681 if (status!=RTEMS_SUCCESSFUL) {
681 if (status!=RTEMS_SUCCESSFUL) {
682 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
682 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
683 }
683 }
684 }
684 }
685
685
686 //****************
686 //****************
687 // WAVEFORM PICKER
687 // WAVEFORM PICKER
688 if (status == RTEMS_SUCCESSFUL) // WFRM
688 if (status == RTEMS_SUCCESSFUL) // WFRM
689 {
689 {
690 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
690 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
691 if (status!=RTEMS_SUCCESSFUL) {
691 if (status!=RTEMS_SUCCESSFUL) {
692 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
692 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
693 }
693 }
694 }
694 }
695 if (status == RTEMS_SUCCESSFUL) // CWF3
695 if (status == RTEMS_SUCCESSFUL) // CWF3
696 {
696 {
697 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
697 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
698 if (status!=RTEMS_SUCCESSFUL) {
698 if (status!=RTEMS_SUCCESSFUL) {
699 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
699 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
700 }
700 }
701 }
701 }
702 if (status == RTEMS_SUCCESSFUL) // CWF2
702 if (status == RTEMS_SUCCESSFUL) // CWF2
703 {
703 {
704 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
704 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
705 if (status!=RTEMS_SUCCESSFUL) {
705 if (status!=RTEMS_SUCCESSFUL) {
706 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
706 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
707 }
707 }
708 }
708 }
709 if (status == RTEMS_SUCCESSFUL) // CWF1
709 if (status == RTEMS_SUCCESSFUL) // CWF1
710 {
710 {
711 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
711 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
712 if (status!=RTEMS_SUCCESSFUL) {
712 if (status!=RTEMS_SUCCESSFUL) {
713 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
713 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
714 }
714 }
715 }
715 }
716 if (status == RTEMS_SUCCESSFUL) // SWBD
716 if (status == RTEMS_SUCCESSFUL) // SWBD
717 {
717 {
718 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
718 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
719 if (status!=RTEMS_SUCCESSFUL) {
719 if (status!=RTEMS_SUCCESSFUL) {
720 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
720 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
721 }
721 }
722 }
722 }
723
723
724 //*****
724 //*****
725 // MISC
725 // MISC
726 if (status == RTEMS_SUCCESSFUL) // HOUS
726 if (status == RTEMS_SUCCESSFUL) // HOUS
727 {
727 {
728 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
728 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
729 if (status!=RTEMS_SUCCESSFUL) {
729 if (status!=RTEMS_SUCCESSFUL) {
730 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
730 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
731 }
731 }
732 }
732 }
733 if (status == RTEMS_SUCCESSFUL) // AVGV
733 if (status == RTEMS_SUCCESSFUL) // AVGV
734 {
734 {
735 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
735 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
736 if (status!=RTEMS_SUCCESSFUL) {
736 if (status!=RTEMS_SUCCESSFUL) {
737 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
737 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
738 }
738 }
739 }
739 }
740 if (status == RTEMS_SUCCESSFUL) // DUMB
740 if (status == RTEMS_SUCCESSFUL) // DUMB
741 {
741 {
742 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
742 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
743 if (status!=RTEMS_SUCCESSFUL) {
743 if (status!=RTEMS_SUCCESSFUL) {
744 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
744 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
745 }
745 }
746 }
746 }
747 if (status == RTEMS_SUCCESSFUL) // LOAD
747 if (status == RTEMS_SUCCESSFUL) // LOAD
748 {
748 {
749 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
749 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
750 if (status!=RTEMS_SUCCESSFUL) {
750 if (status!=RTEMS_SUCCESSFUL) {
751 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
751 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
752 }
752 }
753 }
753 }
754
754
755 return status;
755 return status;
756 }
756 }
757
757
758 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
758 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
759 {
759 {
760 rtems_status_code status_recv;
760 rtems_status_code status_recv;
761 rtems_status_code status_send;
761 rtems_status_code status_send;
762 rtems_status_code status_q_p0;
762 rtems_status_code status_q_p0;
763 rtems_status_code status_q_p1;
763 rtems_status_code status_q_p1;
764 rtems_status_code status_q_p2;
764 rtems_status_code status_q_p2;
765 rtems_status_code ret;
765 rtems_status_code ret;
766 rtems_id queue_id;
766 rtems_id queue_id;
767
767
768 ret = RTEMS_SUCCESSFUL;
768 ret = RTEMS_SUCCESSFUL;
769 queue_id = RTEMS_ID_NONE;
769 queue_id = RTEMS_ID_NONE;
770
770
771 //****************************************
771 //****************************************
772 // create the queue for handling valid TCs
772 // create the queue for handling valid TCs
773 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
773 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
774 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
774 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
775 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
775 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
776 if ( status_recv != RTEMS_SUCCESSFUL ) {
776 if ( status_recv != RTEMS_SUCCESSFUL ) {
777 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
777 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
778 }
778 }
779
779
780 //************************************************
780 //************************************************
781 // create the queue for handling TM packet sending
781 // create the queue for handling TM packet sending
782 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
782 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
783 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
783 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
784 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
784 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
785 if ( status_send != RTEMS_SUCCESSFUL ) {
785 if ( status_send != RTEMS_SUCCESSFUL ) {
786 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
786 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
787 }
787 }
788
788
789 //*****************************************************************************
789 //*****************************************************************************
790 // create the queue for handling averaged spectral matrices for processing @ f0
790 // create the queue for handling averaged spectral matrices for processing @ f0
791 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
791 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
792 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
792 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
793 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
793 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
794 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
794 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
795 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
795 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
796 }
796 }
797
797
798 //*****************************************************************************
798 //*****************************************************************************
799 // create the queue for handling averaged spectral matrices for processing @ f1
799 // create the queue for handling averaged spectral matrices for processing @ f1
800 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
800 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
801 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
801 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
802 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
802 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
803 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
803 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
804 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
804 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
805 }
805 }
806
806
807 //*****************************************************************************
807 //*****************************************************************************
808 // create the queue for handling averaged spectral matrices for processing @ f2
808 // create the queue for handling averaged spectral matrices for processing @ f2
809 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
809 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
810 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
810 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
811 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
811 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
812 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
812 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
813 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
813 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
814 }
814 }
815
815
816 if ( status_recv != RTEMS_SUCCESSFUL )
816 if ( status_recv != RTEMS_SUCCESSFUL )
817 {
817 {
818 ret = status_recv;
818 ret = status_recv;
819 }
819 }
820 else if( status_send != RTEMS_SUCCESSFUL )
820 else if( status_send != RTEMS_SUCCESSFUL )
821 {
821 {
822 ret = status_send;
822 ret = status_send;
823 }
823 }
824 else if( status_q_p0 != RTEMS_SUCCESSFUL )
824 else if( status_q_p0 != RTEMS_SUCCESSFUL )
825 {
825 {
826 ret = status_q_p0;
826 ret = status_q_p0;
827 }
827 }
828 else if( status_q_p1 != RTEMS_SUCCESSFUL )
828 else if( status_q_p1 != RTEMS_SUCCESSFUL )
829 {
829 {
830 ret = status_q_p1;
830 ret = status_q_p1;
831 }
831 }
832 else
832 else
833 {
833 {
834 ret = status_q_p2;
834 ret = status_q_p2;
835 }
835 }
836
836
837 return ret;
837 return ret;
838 }
838 }
839
839
840 rtems_status_code create_timecode_timer( void )
840 rtems_status_code create_timecode_timer( void )
841 {
841 {
842 rtems_status_code status;
842 rtems_status_code status;
843
843
844 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
844 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
845
845
846 if ( status != RTEMS_SUCCESSFUL )
846 if ( status != RTEMS_SUCCESSFUL )
847 {
847 {
848 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
848 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
849 }
849 }
850 else
850 else
851 {
851 {
852 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
852 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
853 }
853 }
854
854
855 return status;
855 return status;
856 }
856 }
857
857
858 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
858 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
859 {
859 {
860 rtems_status_code status;
860 rtems_status_code status;
861 rtems_name queue_name;
861 rtems_name queue_name;
862
862
863 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
863 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
864
864
865 status = rtems_message_queue_ident( queue_name, 0, queue_id );
865 status = rtems_message_queue_ident( queue_name, 0, queue_id );
866
866
867 return status;
867 return status;
868 }
868 }
869
869
870 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
870 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
871 {
871 {
872 rtems_status_code status;
872 rtems_status_code status;
873 rtems_name queue_name;
873 rtems_name queue_name;
874
874
875 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
875 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
876
876
877 status = rtems_message_queue_ident( queue_name, 0, queue_id );
877 status = rtems_message_queue_ident( queue_name, 0, queue_id );
878
878
879 return status;
879 return status;
880 }
880 }
881
881
882 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
882 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
883 {
883 {
884 rtems_status_code status;
884 rtems_status_code status;
885 rtems_name queue_name;
885 rtems_name queue_name;
886
886
887 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
887 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
888
888
889 status = rtems_message_queue_ident( queue_name, 0, queue_id );
889 status = rtems_message_queue_ident( queue_name, 0, queue_id );
890
890
891 return status;
891 return status;
892 }
892 }
893
893
894 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
894 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
895 {
895 {
896 rtems_status_code status;
896 rtems_status_code status;
897 rtems_name queue_name;
897 rtems_name queue_name;
898
898
899 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
899 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
900
900
901 status = rtems_message_queue_ident( queue_name, 0, queue_id );
901 status = rtems_message_queue_ident( queue_name, 0, queue_id );
902
902
903 return status;
903 return status;
904 }
904 }
905
905
906 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
906 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
907 {
907 {
908 rtems_status_code status;
908 rtems_status_code status;
909 rtems_name queue_name;
909 rtems_name queue_name;
910
910
911 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
911 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
912
912
913 status = rtems_message_queue_ident( queue_name, 0, queue_id );
913 status = rtems_message_queue_ident( queue_name, 0, queue_id );
914
914
915 return status;
915 return status;
916 }
916 }
917
917
918 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
918 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
919 {
919 {
920 u_int32_t count;
920 u_int32_t count;
921 rtems_status_code status;
921 rtems_status_code status;
922
922
923 count = 0;
923 count = 0;
924
924
925 status = rtems_message_queue_get_number_pending( queue_id, &count );
925 status = rtems_message_queue_get_number_pending( queue_id, &count );
926
926
927 count = count + 1;
927 count = count + 1;
928
928
929 if (status != RTEMS_SUCCESSFUL)
929 if (status != RTEMS_SUCCESSFUL)
930 {
930 {
931 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
931 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
932 }
932 }
933 else
933 else
934 {
934 {
935 if (count > *fifo_size_max)
935 if (count > *fifo_size_max)
936 {
936 {
937 *fifo_size_max = count;
937 *fifo_size_max = count;
938 }
938 }
939 }
939 }
940 }
940 }
941
941
942 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
942 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
943 {
943 {
944 unsigned char i;
944 unsigned char i;
945
945
946 //***************
946 //***************
947 // BUFFER ADDRESS
947 // BUFFER ADDRESS
948 for(i=0; i<nbNodes; i++)
948 for(i=0; i<nbNodes; i++)
949 {
949 {
950 ring[i].coarseTime = INT32_ALL_F;
950 ring[i].coarseTime = INT32_ALL_F;
951 ring[i].fineTime = INT32_ALL_F;
951 ring[i].fineTime = INT32_ALL_F;
952 ring[i].sid = INIT_CHAR;
952 ring[i].sid = INIT_CHAR;
953 ring[i].status = INIT_CHAR;
953 ring[i].status = INIT_CHAR;
954 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
954 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
955 }
955 }
956
956
957 //*****
957 //*****
958 // NEXT
958 // NEXT
959 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
959 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
960 for(i=0; i<nbNodes-1; i++)
960 for(i=0; i<nbNodes-1; i++)
961 {
961 {
962 ring[i].next = (ring_node*) &ring[ i + 1 ];
962 ring[i].next = (ring_node*) &ring[ i + 1 ];
963 }
963 }
964
964
965 //*********
965 //*********
966 // PREVIOUS
966 // PREVIOUS
967 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
967 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
968 for(i=1; i<nbNodes; i++)
968 for(i=1; i<nbNodes; i++)
969 {
969 {
970 ring[i].previous = (ring_node*) &ring[ i - 1 ];
970 ring[i].previous = (ring_node*) &ring[ i - 1 ];
971 }
971 }
972 }
972 }
@@ -1,1001 +1,1019
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 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
13
13
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
16 {
16 {
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
18 *
18 *
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
22 * @param interrupt_level is the interrupt level that the timer drives.
22 * @param interrupt_level is the interrupt level that the timer drives.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
24 *
24 *
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
26 *
26 *
27 */
27 */
28
28
29 rtems_status_code status;
29 rtems_status_code status;
30 rtems_isr_entry old_isr_handler;
30 rtems_isr_entry old_isr_handler;
31
31
32 old_isr_handler = NULL;
32 old_isr_handler = NULL;
33
33
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
35
35
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
37 if (status!=RTEMS_SUCCESSFUL)
37 if (status!=RTEMS_SUCCESSFUL)
38 {
38 {
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
40 }
40 }
41
41
42 timer_set_clock_divider( timer, clock_divider);
42 timer_set_clock_divider( timer, clock_divider);
43 }
43 }
44
44
45 void timer_start(unsigned char timer)
45 void timer_start(unsigned char timer)
46 {
46 {
47 /** This function starts a GPTIMER timer.
47 /** This function starts a GPTIMER timer.
48 *
48 *
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
51 *
51 *
52 */
52 */
53
53
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
59 }
59 }
60
60
61 void timer_stop(unsigned char timer)
61 void timer_stop(unsigned char timer)
62 {
62 {
63 /** This function stops a GPTIMER timer.
63 /** This function stops a GPTIMER timer.
64 *
64 *
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
67 *
67 *
68 */
68 */
69
69
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
73 }
73 }
74
74
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
76 {
76 {
77 /** This function sets the clock divider of a GPTIMER timer.
77 /** This function sets the clock divider of a GPTIMER timer.
78 *
78 *
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
82 *
82 *
83 */
83 */
84
84
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
86 }
86 }
87
87
88 // WATCHDOG
88 // WATCHDOG
89
89
90 rtems_isr watchdog_isr( rtems_vector_number vector )
90 rtems_isr watchdog_isr( rtems_vector_number vector )
91 {
91 {
92 rtems_status_code status_code;
92 rtems_status_code status_code;
93
93
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
95
95
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
97
97
98 exit(0);
98 exit(0);
99 }
99 }
100
100
101 void watchdog_configure(void)
101 void watchdog_configure(void)
102 {
102 {
103 /** This function configure the watchdog.
103 /** This function configure the watchdog.
104 *
104 *
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
107 *
107 *
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
109 *
109 *
110 */
110 */
111
111
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
113
113
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
115
115
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 }
117 }
118
118
119 void watchdog_stop(void)
119 void watchdog_stop(void)
120 {
120 {
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
122 timer_stop( TIMER_WATCHDOG );
122 timer_stop( TIMER_WATCHDOG );
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
124 }
124 }
125
125
126 void watchdog_reload(void)
126 void watchdog_reload(void)
127 {
127 {
128 /** This function reloads the watchdog timer counter with the timer reload value.
128 /** This function reloads the watchdog timer counter with the timer reload value.
129 *
129 *
130 * @param void
130 * @param void
131 *
131 *
132 * @return void
132 * @return void
133 *
133 *
134 */
134 */
135
135
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
137 }
137 }
138
138
139 void watchdog_start(void)
139 void watchdog_start(void)
140 {
140 {
141 /** This function starts the watchdog timer.
141 /** This function starts the watchdog timer.
142 *
142 *
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
145 *
145 *
146 */
146 */
147
147
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
149
149
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
154
154
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
156
156
157 }
157 }
158
158
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
160 {
160 {
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
162
162
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
164
164
165 return 0;
165 return 0;
166 }
166 }
167
167
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
169 {
169 {
170 /** This function sets the scaler reload register of the apbuart module
170 /** This function sets the scaler reload register of the apbuart module
171 *
171 *
172 * @param regs is the address of the apbuart registers in memory
172 * @param regs is the address of the apbuart registers in memory
173 * @param value is the value that will be stored in the scaler register
173 * @param value is the value that will be stored in the scaler register
174 *
174 *
175 * The value shall be set by the software to get data on the serial interface.
175 * The value shall be set by the software to get data on the serial interface.
176 *
176 *
177 */
177 */
178
178
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
180
180
181 apbuart_regs->scaler = value;
181 apbuart_regs->scaler = value;
182
182
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
184 }
184 }
185
185
186 //************
186 //************
187 // RTEMS TASKS
187 // RTEMS TASKS
188
188
189 rtems_task load_task(rtems_task_argument argument)
189 rtems_task load_task(rtems_task_argument argument)
190 {
190 {
191 BOOT_PRINTF("in LOAD *** \n")
191 BOOT_PRINTF("in LOAD *** \n")
192
192
193 rtems_status_code status;
193 rtems_status_code status;
194 unsigned int i;
194 unsigned int i;
195 unsigned int j;
195 unsigned int j;
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
198
198
199 watchdog_period_id = RTEMS_ID_NONE;
199 watchdog_period_id = RTEMS_ID_NONE;
200
200
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
202
202
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
204 if( status != RTEMS_SUCCESSFUL ) {
204 if( status != RTEMS_SUCCESSFUL ) {
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
206 }
206 }
207
207
208 i = 0;
208 i = 0;
209 j = 0;
209 j = 0;
210
210
211 watchdog_configure();
211 watchdog_configure();
212
212
213 watchdog_start();
213 watchdog_start();
214
214
215 set_sy_lfr_watchdog_enabled( true );
215 set_sy_lfr_watchdog_enabled( true );
216
216
217 while(1){
217 while(1){
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
219 watchdog_reload();
219 watchdog_reload();
220 i = i + 1;
220 i = i + 1;
221 if ( i == WATCHDOG_LOOP_PRINTF )
221 if ( i == WATCHDOG_LOOP_PRINTF )
222 {
222 {
223 i = 0;
223 i = 0;
224 j = j + 1;
224 j = j + 1;
225 PRINTF1("%d\n", j)
225 PRINTF1("%d\n", j)
226 }
226 }
227 #ifdef DEBUG_WATCHDOG
227 #ifdef DEBUG_WATCHDOG
228 if (j == WATCHDOG_LOOP_DEBUG )
228 if (j == WATCHDOG_LOOP_DEBUG )
229 {
229 {
230 status = rtems_task_delete(RTEMS_SELF);
230 status = rtems_task_delete(RTEMS_SELF);
231 }
231 }
232 #endif
232 #endif
233 }
233 }
234 }
234 }
235
235
236 rtems_task hous_task(rtems_task_argument argument)
236 rtems_task hous_task(rtems_task_argument argument)
237 {
237 {
238 rtems_status_code status;
238 rtems_status_code status;
239 rtems_status_code spare_status;
239 rtems_status_code spare_status;
240 rtems_id queue_id;
240 rtems_id queue_id;
241 rtems_rate_monotonic_period_status period_status;
241 rtems_rate_monotonic_period_status period_status;
242 bool isSynchronized;
242 bool isSynchronized;
243
243
244 queue_id = RTEMS_ID_NONE;
244 queue_id = RTEMS_ID_NONE;
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
246 isSynchronized = false;
246 isSynchronized = false;
247
247
248 status = get_message_queue_id_send( &queue_id );
248 status = get_message_queue_id_send( &queue_id );
249 if (status != RTEMS_SUCCESSFUL)
249 if (status != RTEMS_SUCCESSFUL)
250 {
250 {
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
252 }
252 }
253
253
254 BOOT_PRINTF("in HOUS ***\n");
254 BOOT_PRINTF("in HOUS ***\n");
255
255
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
258 if( status != RTEMS_SUCCESSFUL ) {
258 if( status != RTEMS_SUCCESSFUL ) {
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
260 }
260 }
261 }
261 }
262
262
263 status = rtems_rate_monotonic_cancel(HK_id);
263 status = rtems_rate_monotonic_cancel(HK_id);
264 if( status != RTEMS_SUCCESSFUL ) {
264 if( status != RTEMS_SUCCESSFUL ) {
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
266 }
266 }
267 else {
267 else {
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
269 }
269 }
270
270
271 // startup phase
271 // startup phase
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
277 {
277 {
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
279 {
279 {
280 isSynchronized = true;
280 isSynchronized = true;
281 }
281 }
282 else
282 else
283 {
283 {
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
285
285
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
287 }
287 }
288 }
288 }
289 status = rtems_rate_monotonic_cancel(HK_id);
289 status = rtems_rate_monotonic_cancel(HK_id);
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
291
291
292 set_hk_lfr_reset_cause( POWER_ON );
292 set_hk_lfr_reset_cause( POWER_ON );
293
293
294 while(1){ // launch the rate monotonic task
294 while(1){ // launch the rate monotonic task
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
296 if ( status != RTEMS_SUCCESSFUL ) {
296 if ( status != RTEMS_SUCCESSFUL ) {
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
299 }
299 }
300 else {
300 else {
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
304
304
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
311
311
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
313
313
314 spacewire_read_statistics();
314 spacewire_read_statistics();
315
315
316 update_hk_with_grspw_stats();
316 update_hk_with_grspw_stats();
317
317
318 set_hk_lfr_time_not_synchro();
318 set_hk_lfr_time_not_synchro();
319
319
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
325
325
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
331
331
332 hk_lfr_le_me_he_update();
332 hk_lfr_le_me_he_update();
333
333
334 // SEND PACKET
334 // SEND PACKET
335 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
335 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
336 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
336 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
337 if (status != RTEMS_SUCCESSFUL) {
337 if (status != RTEMS_SUCCESSFUL) {
338 PRINTF1("in HOUS *** ERR send: %d\n", status)
338 PRINTF1("in HOUS *** ERR send: %d\n", status)
339 }
339 }
340 }
340 }
341 }
341 }
342
342
343 PRINTF("in HOUS *** deleting task\n")
343 PRINTF("in HOUS *** deleting task\n")
344
344
345 status = rtems_task_delete( RTEMS_SELF ); // should not return
345 status = rtems_task_delete( RTEMS_SELF ); // should not return
346
346
347 return;
347 return;
348 }
348 }
349
349
350 int32_t getIntFromShort( int reg )
351 {
352 int16_t ret_as_int16;
353 int32_t ret_as_int32;
354 char *regPtr;
355 char *ret_as_int16_ptr;
356
357 regPtr = (char*) &reg;
358 ret_as_int16_ptr = (char*) &ret_as_int16;
359
360 ret_as_int16_ptr[BYTE_0] = regPtr[BYTE_3];
361 ret_as_int16_ptr[BYTE_1] = regPtr[BYTE_4];
362
363 ret_as_int32 = (int32_t) ret_as_int16;
364
365 return ret_as_int32;
366 }
367
350 rtems_task avgv_task(rtems_task_argument argument)
368 rtems_task avgv_task(rtems_task_argument argument)
351 {
369 {
352 #define MOVING_AVERAGE 16
370 #define MOVING_AVERAGE 16
353 rtems_status_code status;
371 rtems_status_code status;
354 static int32_t v[MOVING_AVERAGE] = {0};
372 static int32_t v[MOVING_AVERAGE] = {0};
355 static int32_t e1[MOVING_AVERAGE] = {0};
373 static int32_t e1[MOVING_AVERAGE] = {0};
356 static int32_t e2[MOVING_AVERAGE] = {0};
374 static int32_t e2[MOVING_AVERAGE] = {0};
357 int32_t average_v;
375 int32_t average_v;
358 int32_t average_e1;
376 int32_t average_e1;
359 int32_t average_e2;
377 int32_t average_e2;
360 int32_t newValue_v;
378 int32_t newValue_v;
361 int32_t newValue_e1;
379 int32_t newValue_e1;
362 int32_t newValue_e2;
380 int32_t newValue_e2;
363 unsigned char k;
381 unsigned char k;
364 unsigned char indexOfOldValue;
382 unsigned char indexOfOldValue;
365
383
366 BOOT_PRINTF("in AVGV ***\n");
384 BOOT_PRINTF("in AVGV ***\n");
367
385
368 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
386 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
369 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
387 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
370 if( status != RTEMS_SUCCESSFUL ) {
388 if( status != RTEMS_SUCCESSFUL ) {
371 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
389 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
372 }
390 }
373 }
391 }
374
392
375 status = rtems_rate_monotonic_cancel(AVGV_id);
393 status = rtems_rate_monotonic_cancel(AVGV_id);
376 if( status != RTEMS_SUCCESSFUL ) {
394 if( status != RTEMS_SUCCESSFUL ) {
377 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
395 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
378 }
396 }
379 else {
397 else {
380 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
398 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
381 }
399 }
382
400
383 // initialize values
401 // initialize values
384 indexOfOldValue = MOVING_AVERAGE - 1;
402 indexOfOldValue = MOVING_AVERAGE - 1;
385 average_v = 0;
403 average_v = 0;
386 average_e1 = 0;
404 average_e1 = 0;
387 average_e2 = 0;
405 average_e2 = 0;
388 newValue_v = 0;
406 newValue_v = 0;
389 newValue_e1 = 0;
407 newValue_e1 = 0;
390 newValue_e2 = 0;
408 newValue_e2 = 0;
391
409
392 k = INIT_CHAR;
410 k = INIT_CHAR;
393
411
394 while(1)
412 while(1)
395 { // launch the rate monotonic task
413 { // launch the rate monotonic task
396 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
414 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
397 if ( status != RTEMS_SUCCESSFUL )
415 if ( status != RTEMS_SUCCESSFUL )
398 {
416 {
399 PRINTF1( "in AVGV *** ERR period: %d\n", status);
417 PRINTF1( "in AVGV *** ERR period: %d\n", status);
400 }
418 }
401 else
419 else
402 {
420 {
403 // get new values
421 // get new values
404 newValue_v = (int32_t) waveform_picker_regs->v;
422 newValue_v = getIntFromShort( waveform_picker_regs->v );
405 newValue_e1 = (int32_t) waveform_picker_regs->e1;
423 newValue_e1 = getIntFromShort( waveform_picker_regs->e1 );
406 newValue_e2 = (int32_t) waveform_picker_regs->e2;
424 newValue_e2 = getIntFromShort( waveform_picker_regs->e2 );
407
425
408 // compute the moving average
426 // compute the moving average
409 average_v = average_v + newValue_v - v[k];
427 average_v = average_v + newValue_v - v[k];
410 average_e1 = average_e1 + newValue_e1 - e1[k];
428 average_e1 = average_e1 + newValue_e1 - e1[k];
411 average_e2 = average_e2 + newValue_e2 - e2[k];
429 average_e2 = average_e2 + newValue_e2 - e2[k];
412
430
413 // store new values in buffers
431 // store new values in buffers
414 v[k] = newValue_v;
432 v[k] = newValue_v;
415 e1[k] = newValue_e1;
433 e1[k] = newValue_e1;
416 e2[k] = newValue_e2;
434 e2[k] = newValue_e2;
417 }
435 }
418 if (k == (MOVING_AVERAGE-1))
436 if (k == (MOVING_AVERAGE-1))
419 {
437 {
420 k = 0;
438 k = 0;
421 }
439 }
422 else
440 else
423 {
441 {
424 k++;
442 k++;
425 }
443 }
426 //update int16 values
444 //update int16 values
427 hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / MOVING_AVERAGE );
445 hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / MOVING_AVERAGE );
428 hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / MOVING_AVERAGE );
446 hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / MOVING_AVERAGE );
429 hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / MOVING_AVERAGE );
447 hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / MOVING_AVERAGE );
430 }
448 }
431
449
432 PRINTF("in AVGV *** deleting task\n");
450 PRINTF("in AVGV *** deleting task\n");
433
451
434 status = rtems_task_delete( RTEMS_SELF ); // should not return
452 status = rtems_task_delete( RTEMS_SELF ); // should not return
435
453
436 return;
454 return;
437 }
455 }
438
456
439 rtems_task dumb_task( rtems_task_argument unused )
457 rtems_task dumb_task( rtems_task_argument unused )
440 {
458 {
441 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
459 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
442 *
460 *
443 * @param unused is the starting argument of the RTEMS task
461 * @param unused is the starting argument of the RTEMS task
444 *
462 *
445 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
463 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
446 *
464 *
447 */
465 */
448
466
449 unsigned int i;
467 unsigned int i;
450 unsigned int intEventOut;
468 unsigned int intEventOut;
451 unsigned int coarse_time = 0;
469 unsigned int coarse_time = 0;
452 unsigned int fine_time = 0;
470 unsigned int fine_time = 0;
453 rtems_event_set event_out;
471 rtems_event_set event_out;
454
472
455 event_out = EVENT_SETS_NONE_PENDING;
473 event_out = EVENT_SETS_NONE_PENDING;
456
474
457 BOOT_PRINTF("in DUMB *** \n")
475 BOOT_PRINTF("in DUMB *** \n")
458
476
459 while(1){
477 while(1){
460 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
478 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
461 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
479 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
462 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
480 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
463 | RTEMS_EVENT_14,
481 | RTEMS_EVENT_14,
464 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
482 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
465 intEventOut = (unsigned int) event_out;
483 intEventOut = (unsigned int) event_out;
466 for ( i=0; i<NB_RTEMS_EVENTS; i++)
484 for ( i=0; i<NB_RTEMS_EVENTS; i++)
467 {
485 {
468 if ( ((intEventOut >> i) & 1) != 0)
486 if ( ((intEventOut >> i) & 1) != 0)
469 {
487 {
470 coarse_time = time_management_regs->coarse_time;
488 coarse_time = time_management_regs->coarse_time;
471 fine_time = time_management_regs->fine_time;
489 fine_time = time_management_regs->fine_time;
472 if (i==EVENT_12)
490 if (i==EVENT_12)
473 {
491 {
474 PRINTF1("%s\n", DUMB_MESSAGE_12)
492 PRINTF1("%s\n", DUMB_MESSAGE_12)
475 }
493 }
476 if (i==EVENT_13)
494 if (i==EVENT_13)
477 {
495 {
478 PRINTF1("%s\n", DUMB_MESSAGE_13)
496 PRINTF1("%s\n", DUMB_MESSAGE_13)
479 }
497 }
480 if (i==EVENT_14)
498 if (i==EVENT_14)
481 {
499 {
482 PRINTF1("%s\n", DUMB_MESSAGE_1)
500 PRINTF1("%s\n", DUMB_MESSAGE_1)
483 }
501 }
484 }
502 }
485 }
503 }
486 }
504 }
487 }
505 }
488
506
489 //*****************************
507 //*****************************
490 // init housekeeping parameters
508 // init housekeeping parameters
491
509
492 void init_housekeeping_parameters( void )
510 void init_housekeeping_parameters( void )
493 {
511 {
494 /** This function initialize the housekeeping_packet global variable with default values.
512 /** This function initialize the housekeeping_packet global variable with default values.
495 *
513 *
496 */
514 */
497
515
498 unsigned int i = 0;
516 unsigned int i = 0;
499 unsigned char *parameters;
517 unsigned char *parameters;
500 unsigned char sizeOfHK;
518 unsigned char sizeOfHK;
501
519
502 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
520 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
503
521
504 parameters = (unsigned char*) &housekeeping_packet;
522 parameters = (unsigned char*) &housekeeping_packet;
505
523
506 for(i = 0; i< sizeOfHK; i++)
524 for(i = 0; i< sizeOfHK; i++)
507 {
525 {
508 parameters[i] = INIT_CHAR;
526 parameters[i] = INIT_CHAR;
509 }
527 }
510
528
511 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
529 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
512 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
530 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
513 housekeeping_packet.reserved = DEFAULT_RESERVED;
531 housekeeping_packet.reserved = DEFAULT_RESERVED;
514 housekeeping_packet.userApplication = CCSDS_USER_APP;
532 housekeeping_packet.userApplication = CCSDS_USER_APP;
515 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
533 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
516 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
534 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
517 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
535 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
518 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
536 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
519 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
537 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
520 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
538 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
521 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
539 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
522 housekeeping_packet.serviceType = TM_TYPE_HK;
540 housekeeping_packet.serviceType = TM_TYPE_HK;
523 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
541 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
524 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
542 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
525 housekeeping_packet.sid = SID_HK;
543 housekeeping_packet.sid = SID_HK;
526
544
527 // init status word
545 // init status word
528 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
546 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
529 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
547 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
530 // init software version
548 // init software version
531 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
549 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
532 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
550 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
533 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
551 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
534 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
552 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
535 // init fpga version
553 // init fpga version
536 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
554 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
537 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
555 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
538 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
556 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
539 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
557 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
540
558
541 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
559 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
542 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
560 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
543 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
561 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
544 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
562 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
545 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
563 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
546 }
564 }
547
565
548 void increment_seq_counter( unsigned short *packetSequenceControl )
566 void increment_seq_counter( unsigned short *packetSequenceControl )
549 {
567 {
550 /** This function increment the sequence counter passes in argument.
568 /** This function increment the sequence counter passes in argument.
551 *
569 *
552 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
570 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
553 *
571 *
554 */
572 */
555
573
556 unsigned short segmentation_grouping_flag;
574 unsigned short segmentation_grouping_flag;
557 unsigned short sequence_cnt;
575 unsigned short sequence_cnt;
558
576
559 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
577 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
560 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
578 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
561
579
562 if ( sequence_cnt < SEQ_CNT_MAX)
580 if ( sequence_cnt < SEQ_CNT_MAX)
563 {
581 {
564 sequence_cnt = sequence_cnt + 1;
582 sequence_cnt = sequence_cnt + 1;
565 }
583 }
566 else
584 else
567 {
585 {
568 sequence_cnt = 0;
586 sequence_cnt = 0;
569 }
587 }
570
588
571 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
589 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
572 }
590 }
573
591
574 void getTime( unsigned char *time)
592 void getTime( unsigned char *time)
575 {
593 {
576 /** This function write the current local time in the time buffer passed in argument.
594 /** This function write the current local time in the time buffer passed in argument.
577 *
595 *
578 */
596 */
579
597
580 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
598 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
581 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
599 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
582 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
600 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
583 time[3] = (unsigned char) (time_management_regs->coarse_time);
601 time[3] = (unsigned char) (time_management_regs->coarse_time);
584 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
602 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
585 time[5] = (unsigned char) (time_management_regs->fine_time);
603 time[5] = (unsigned char) (time_management_regs->fine_time);
586 }
604 }
587
605
588 unsigned long long int getTimeAsUnsignedLongLongInt( )
606 unsigned long long int getTimeAsUnsignedLongLongInt( )
589 {
607 {
590 /** This function write the current local time in the time buffer passed in argument.
608 /** This function write the current local time in the time buffer passed in argument.
591 *
609 *
592 */
610 */
593 unsigned long long int time;
611 unsigned long long int time;
594
612
595 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
613 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
596 + time_management_regs->fine_time;
614 + time_management_regs->fine_time;
597
615
598 return time;
616 return time;
599 }
617 }
600
618
601 void send_dumb_hk( void )
619 void send_dumb_hk( void )
602 {
620 {
603 Packet_TM_LFR_HK_t dummy_hk_packet;
621 Packet_TM_LFR_HK_t dummy_hk_packet;
604 unsigned char *parameters;
622 unsigned char *parameters;
605 unsigned int i;
623 unsigned int i;
606 rtems_id queue_id;
624 rtems_id queue_id;
607
625
608 queue_id = RTEMS_ID_NONE;
626 queue_id = RTEMS_ID_NONE;
609
627
610 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
628 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
611 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
629 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
612 dummy_hk_packet.reserved = DEFAULT_RESERVED;
630 dummy_hk_packet.reserved = DEFAULT_RESERVED;
613 dummy_hk_packet.userApplication = CCSDS_USER_APP;
631 dummy_hk_packet.userApplication = CCSDS_USER_APP;
614 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
632 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
615 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
633 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
616 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
634 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
617 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
635 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
618 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
636 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
619 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
637 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
620 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
638 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
621 dummy_hk_packet.serviceType = TM_TYPE_HK;
639 dummy_hk_packet.serviceType = TM_TYPE_HK;
622 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
640 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
623 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
641 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
624 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
642 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
625 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
643 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
626 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
644 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
627 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
645 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
628 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
646 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
629 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
647 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
630 dummy_hk_packet.sid = SID_HK;
648 dummy_hk_packet.sid = SID_HK;
631
649
632 // init status word
650 // init status word
633 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
651 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
634 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
652 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
635 // init software version
653 // init software version
636 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
654 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
637 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
655 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
638 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
656 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
639 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
657 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
640 // init fpga version
658 // init fpga version
641 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
659 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
642 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
660 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
643 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
661 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
644 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
662 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
645
663
646 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
664 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
647
665
648 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
666 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
649 {
667 {
650 parameters[i] = INT8_ALL_F;
668 parameters[i] = INT8_ALL_F;
651 }
669 }
652
670
653 get_message_queue_id_send( &queue_id );
671 get_message_queue_id_send( &queue_id );
654
672
655 rtems_message_queue_send( queue_id, &dummy_hk_packet,
673 rtems_message_queue_send( queue_id, &dummy_hk_packet,
656 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
674 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
657 }
675 }
658
676
659 void get_temperatures( unsigned char *temperatures )
677 void get_temperatures( unsigned char *temperatures )
660 {
678 {
661 unsigned char* temp_scm_ptr;
679 unsigned char* temp_scm_ptr;
662 unsigned char* temp_pcb_ptr;
680 unsigned char* temp_pcb_ptr;
663 unsigned char* temp_fpga_ptr;
681 unsigned char* temp_fpga_ptr;
664
682
665 // SEL1 SEL0
683 // SEL1 SEL0
666 // 0 0 => PCB
684 // 0 0 => PCB
667 // 0 1 => FPGA
685 // 0 1 => FPGA
668 // 1 0 => SCM
686 // 1 0 => SCM
669
687
670 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
688 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
671 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
689 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
672 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
690 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
673
691
674 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
692 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
675 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
693 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
676 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
694 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
677 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
695 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
678 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
696 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
679 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
697 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
680 }
698 }
681
699
682 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
700 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
683 {
701 {
684 unsigned char* v_ptr;
702 unsigned char* v_ptr;
685 unsigned char* e1_ptr;
703 unsigned char* e1_ptr;
686 unsigned char* e2_ptr;
704 unsigned char* e2_ptr;
687
705
688 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
706 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
689 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
707 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
690 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
708 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
691
709
692 spacecraft_potential[BYTE_0] = v_ptr[0];
710 spacecraft_potential[BYTE_0] = v_ptr[0];
693 spacecraft_potential[BYTE_1] = v_ptr[1];
711 spacecraft_potential[BYTE_1] = v_ptr[1];
694 spacecraft_potential[BYTE_2] = e1_ptr[0];
712 spacecraft_potential[BYTE_2] = e1_ptr[0];
695 spacecraft_potential[BYTE_3] = e1_ptr[1];
713 spacecraft_potential[BYTE_3] = e1_ptr[1];
696 spacecraft_potential[BYTE_4] = e2_ptr[0];
714 spacecraft_potential[BYTE_4] = e2_ptr[0];
697 spacecraft_potential[BYTE_5] = e2_ptr[1];
715 spacecraft_potential[BYTE_5] = e2_ptr[1];
698 }
716 }
699
717
700 void get_cpu_load( unsigned char *resource_statistics )
718 void get_cpu_load( unsigned char *resource_statistics )
701 {
719 {
702 unsigned char cpu_load;
720 unsigned char cpu_load;
703
721
704 cpu_load = lfr_rtems_cpu_usage_report();
722 cpu_load = lfr_rtems_cpu_usage_report();
705
723
706 // HK_LFR_CPU_LOAD
724 // HK_LFR_CPU_LOAD
707 resource_statistics[0] = cpu_load;
725 resource_statistics[0] = cpu_load;
708
726
709 // HK_LFR_CPU_LOAD_MAX
727 // HK_LFR_CPU_LOAD_MAX
710 if (cpu_load > resource_statistics[1])
728 if (cpu_load > resource_statistics[1])
711 {
729 {
712 resource_statistics[1] = cpu_load;
730 resource_statistics[1] = cpu_load;
713 }
731 }
714
732
715 // CPU_LOAD_AVE
733 // CPU_LOAD_AVE
716 resource_statistics[BYTE_2] = 0;
734 resource_statistics[BYTE_2] = 0;
717
735
718 #ifndef PRINT_TASK_STATISTICS
736 #ifndef PRINT_TASK_STATISTICS
719 rtems_cpu_usage_reset();
737 rtems_cpu_usage_reset();
720 #endif
738 #endif
721
739
722 }
740 }
723
741
724 void set_hk_lfr_sc_potential_flag( bool state )
742 void set_hk_lfr_sc_potential_flag( bool state )
725 {
743 {
726 if (state == true)
744 if (state == true)
727 {
745 {
728 housekeeping_packet.lfr_status_word[1] =
746 housekeeping_packet.lfr_status_word[1] =
729 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
747 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
730 }
748 }
731 else
749 else
732 {
750 {
733 housekeeping_packet.lfr_status_word[1] =
751 housekeeping_packet.lfr_status_word[1] =
734 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
752 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
735 }
753 }
736 }
754 }
737
755
738 void set_sy_lfr_pas_filter_enabled( bool state )
756 void set_sy_lfr_pas_filter_enabled( bool state )
739 {
757 {
740 if (state == true)
758 if (state == true)
741 {
759 {
742 housekeeping_packet.lfr_status_word[1] =
760 housekeeping_packet.lfr_status_word[1] =
743 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
761 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
744 }
762 }
745 else
763 else
746 {
764 {
747 housekeeping_packet.lfr_status_word[1] =
765 housekeeping_packet.lfr_status_word[1] =
748 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
766 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
749 }
767 }
750 }
768 }
751
769
752 void set_sy_lfr_watchdog_enabled( bool state )
770 void set_sy_lfr_watchdog_enabled( bool state )
753 {
771 {
754 if (state == true)
772 if (state == true)
755 {
773 {
756 housekeeping_packet.lfr_status_word[1] =
774 housekeeping_packet.lfr_status_word[1] =
757 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
775 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
758 }
776 }
759 else
777 else
760 {
778 {
761 housekeeping_packet.lfr_status_word[1] =
779 housekeeping_packet.lfr_status_word[1] =
762 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
780 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
763 }
781 }
764 }
782 }
765
783
766 void set_hk_lfr_calib_enable( bool state )
784 void set_hk_lfr_calib_enable( bool state )
767 {
785 {
768 if (state == true)
786 if (state == true)
769 {
787 {
770 housekeeping_packet.lfr_status_word[1] =
788 housekeeping_packet.lfr_status_word[1] =
771 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
789 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
772 }
790 }
773 else
791 else
774 {
792 {
775 housekeeping_packet.lfr_status_word[1] =
793 housekeeping_packet.lfr_status_word[1] =
776 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
794 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
777 }
795 }
778 }
796 }
779
797
780 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
798 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
781 {
799 {
782 housekeeping_packet.lfr_status_word[1] =
800 housekeeping_packet.lfr_status_word[1] =
783 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
801 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
784
802
785 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
803 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
786 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
804 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
787
805
788 }
806 }
789
807
790 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
808 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
791 {
809 {
792 int delta;
810 int delta;
793
811
794 delta = 0;
812 delta = 0;
795
813
796 if (newValue >= oldValue)
814 if (newValue >= oldValue)
797 {
815 {
798 delta = newValue - oldValue;
816 delta = newValue - oldValue;
799 }
817 }
800 else
818 else
801 {
819 {
802 delta = (CONST_256 - oldValue) + newValue;
820 delta = (CONST_256 - oldValue) + newValue;
803 }
821 }
804
822
805 *counter = *counter + delta;
823 *counter = *counter + delta;
806 }
824 }
807
825
808 void hk_lfr_le_update( void )
826 void hk_lfr_le_update( void )
809 {
827 {
810 static hk_lfr_le_t old_hk_lfr_le = {0};
828 static hk_lfr_le_t old_hk_lfr_le = {0};
811 hk_lfr_le_t new_hk_lfr_le;
829 hk_lfr_le_t new_hk_lfr_le;
812 unsigned int counter;
830 unsigned int counter;
813
831
814 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
832 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
815
833
816 // DPU
834 // DPU
817 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
835 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
818 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
836 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
819 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
837 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
820 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
838 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
821 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
839 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
822 // TIMECODE
840 // TIMECODE
823 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
841 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
824 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
842 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
825 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
843 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
826 // TIME
844 // TIME
827 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
845 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
828 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
846 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
829 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
847 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
830 //AHB
848 //AHB
831 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
849 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
832 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
850 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
833 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
851 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
834
852
835 // update the le counter
853 // update the le counter
836 // DPU
854 // DPU
837 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
855 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
838 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
856 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
839 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
857 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
840 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
858 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
841 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
859 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
842 // TIMECODE
860 // TIMECODE
843 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
861 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
844 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
862 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
845 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
863 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
846 // TIME
864 // TIME
847 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
865 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
848 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
866 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
849 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
867 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
850 // AHB
868 // AHB
851 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
869 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
852
870
853 // DPU
871 // DPU
854 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
872 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
855 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
873 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
856 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
874 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
857 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
875 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
858 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
876 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
859 // TIMECODE
877 // TIMECODE
860 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
878 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
861 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
879 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
862 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
880 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
863 // TIME
881 // TIME
864 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
882 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
865 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
883 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
866 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
884 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
867 //AHB
885 //AHB
868 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
886 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
869 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
887 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
870 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
888 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
871
889
872 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
890 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
873 // LE
891 // LE
874 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
892 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
875 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
893 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
876 }
894 }
877
895
878 void hk_lfr_me_update( void )
896 void hk_lfr_me_update( void )
879 {
897 {
880 static hk_lfr_me_t old_hk_lfr_me = {0};
898 static hk_lfr_me_t old_hk_lfr_me = {0};
881 hk_lfr_me_t new_hk_lfr_me;
899 hk_lfr_me_t new_hk_lfr_me;
882 unsigned int counter;
900 unsigned int counter;
883
901
884 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
902 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
885
903
886 // get the current values
904 // get the current values
887 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
905 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
888 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
906 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
889 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
907 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
890 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
908 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
891
909
892 // update the me counter
910 // update the me counter
893 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
911 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
894 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
912 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
895 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
913 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
896 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
914 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
897
915
898 // store the counters for the next time
916 // store the counters for the next time
899 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
917 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
900 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
918 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
901 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
919 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
902 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
920 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
903
921
904 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
922 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
905 // ME
923 // ME
906 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
924 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
907 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
925 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
908 }
926 }
909
927
910 void hk_lfr_le_me_he_update()
928 void hk_lfr_le_me_he_update()
911 {
929 {
912
930
913 unsigned int hk_lfr_he_cnt;
931 unsigned int hk_lfr_he_cnt;
914
932
915 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
933 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
916
934
917 //update the low severity error counter
935 //update the low severity error counter
918 hk_lfr_le_update( );
936 hk_lfr_le_update( );
919
937
920 //update the medium severity error counter
938 //update the medium severity error counter
921 hk_lfr_me_update();
939 hk_lfr_me_update();
922
940
923 //update the high severity error counter
941 //update the high severity error counter
924 hk_lfr_he_cnt = 0;
942 hk_lfr_he_cnt = 0;
925
943
926 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
944 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
927 // HE
945 // HE
928 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
946 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
929 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
947 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
930
948
931 }
949 }
932
950
933 void set_hk_lfr_time_not_synchro()
951 void set_hk_lfr_time_not_synchro()
934 {
952 {
935 static unsigned char synchroLost = 1;
953 static unsigned char synchroLost = 1;
936 int synchronizationBit;
954 int synchronizationBit;
937
955
938 // get the synchronization bit
956 // get the synchronization bit
939 synchronizationBit =
957 synchronizationBit =
940 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
958 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
941
959
942 switch (synchronizationBit)
960 switch (synchronizationBit)
943 {
961 {
944 case 0:
962 case 0:
945 if (synchroLost == 1)
963 if (synchroLost == 1)
946 {
964 {
947 synchroLost = 0;
965 synchroLost = 0;
948 }
966 }
949 break;
967 break;
950 case 1:
968 case 1:
951 if (synchroLost == 0 )
969 if (synchroLost == 0 )
952 {
970 {
953 synchroLost = 1;
971 synchroLost = 1;
954 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
972 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
955 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
956 }
974 }
957 break;
975 break;
958 default:
976 default:
959 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
977 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
960 break;
978 break;
961 }
979 }
962
980
963 }
981 }
964
982
965 void set_hk_lfr_ahb_correctable() // CRITICITY L
983 void set_hk_lfr_ahb_correctable() // CRITICITY L
966 {
984 {
967 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
985 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
968 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
986 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
969 * detected errors in the cache, in the integer unit and in the floating point unit.
987 * detected errors in the cache, in the integer unit and in the floating point unit.
970 *
988 *
971 * @param void
989 * @param void
972 *
990 *
973 * @return void
991 * @return void
974 *
992 *
975 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
993 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
976 *
994 *
977 */
995 */
978
996
979 unsigned int ahb_correctable;
997 unsigned int ahb_correctable;
980 unsigned int instructionErrorCounter;
998 unsigned int instructionErrorCounter;
981 unsigned int dataErrorCounter;
999 unsigned int dataErrorCounter;
982 unsigned int fprfErrorCounter;
1000 unsigned int fprfErrorCounter;
983 unsigned int iurfErrorCounter;
1001 unsigned int iurfErrorCounter;
984
1002
985 instructionErrorCounter = 0;
1003 instructionErrorCounter = 0;
986 dataErrorCounter = 0;
1004 dataErrorCounter = 0;
987 fprfErrorCounter = 0;
1005 fprfErrorCounter = 0;
988 iurfErrorCounter = 0;
1006 iurfErrorCounter = 0;
989
1007
990 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
1008 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
991 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
1009 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
992
1010
993 ahb_correctable = instructionErrorCounter
1011 ahb_correctable = instructionErrorCounter
994 + dataErrorCounter
1012 + dataErrorCounter
995 + fprfErrorCounter
1013 + fprfErrorCounter
996 + iurfErrorCounter
1014 + iurfErrorCounter
997 + housekeeping_packet.hk_lfr_ahb_correctable;
1015 + housekeeping_packet.hk_lfr_ahb_correctable;
998
1016
999 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1017 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1000
1018
1001 }
1019 }
@@ -1,817 +1,818
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_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 acquisitionTimeStart;
723 u_int64_t acquisitionTimeStart;
724 u_int64_t acquisitionTimeStop;
724 u_int64_t acquisitionTimeStop;
725 u_int64_t timecodeReference;
725 u_int64_t timecodeReference;
726 u_int64_t offsetInFineTime;
726 u_int64_t offsetInFineTime;
727 u_int64_t shiftInFineTime;
727 u_int64_t shiftInFineTime;
728 u_int64_t tBadInFineTime;
728 u_int64_t tBadInFineTime;
729 u_int64_t acquisitionTimeRangeMin;
729 u_int64_t acquisitionTimeRangeMin;
730 u_int64_t acquisitionTimeRangeMax;
730 u_int64_t acquisitionTimeRangeMax;
731 unsigned char pasFilteringIsEnabled;
731 unsigned char pasFilteringIsEnabled;
732 unsigned char ret;
732 unsigned char ret;
733
733
734 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
734 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
735 ret = 1;
735 ret = 1;
736
736
737 // compute acquisition time from caoarseTime and fineTime
737 // compute acquisition time from caoarseTime and fineTime
738 acquisitionTimeStart = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
738 acquisitionTimeStart = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
739 + (u_int64_t) fineTime;
739 + (u_int64_t) fineTime;
740 switch(channel)
740 switch(channel)
741 {
741 {
742 case CHANNELF0:
742 case CHANNELF0:
743 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F0;
743 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F0;
744 break;
744 break;
745 case CHANNELF1:
745 case CHANNELF1:
746 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F1;
746 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F1;
747 break;
747 break;
748 case CHANNELF2:
748 case CHANNELF2:
749 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F2;
749 acquisitionTimeStop = acquisitionTimeStart + FINETIME_PER_SM_F2;
750 break;
750 break;
751 }
751 }
752
752
753 // compute the timecode reference
753 // compute the timecode reference
754 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
754 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
755 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
755 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
756
756
757 // compute the acquitionTime range
757 // compute the acquitionTime range
758 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
758 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
759 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
759 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
760 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
760 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
761
761
762 acquisitionTimeRangeMin =
762 acquisitionTimeRangeMin =
763 timecodeReference
763 timecodeReference
764 + offsetInFineTime
764 + offsetInFineTime
765 + shiftInFineTime
765 + shiftInFineTime
766 - acquisitionDurations[channel];
766 - acquisitionDurations[channel];
767
767 acquisitionTimeRangeMax =
768 acquisitionTimeRangeMax =
768 timecodeReference
769 timecodeReference
769 + offsetInFineTime
770 + offsetInFineTime
770 + shiftInFineTime
771 + shiftInFineTime
771 + tBadInFineTime;
772 + tBadInFineTime;
772
773
773 if ( (acquisitionTimeStart >= acquisitionTimeRangeMin)
774 if ( (acquisitionTimeStart >= acquisitionTimeRangeMin)
774 && (acquisitionTimeStart <= acquisitionTimeRangeMax)
775 && (acquisitionTimeStart <= acquisitionTimeRangeMax)
775 && (pasFilteringIsEnabled == 1) )
776 && (pasFilteringIsEnabled == 1) )
776 {
777 {
777 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
778 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
778 }
779 }
779 else
780 else
780 {
781 {
781 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
782 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
782 }
783 }
783
784
784 // the last sample of the data used to compute the matrix shall not be INSIDE the range, test it now, it depends on the channel
785 // the last sample of the data used to compute the matrix shall not be INSIDE the range, test it now, it depends on the channel
785 if (ret == 1)
786 if (ret == 1)
786 {
787 {
787 if ( (acquisitionTimeStop >= acquisitionTimeRangeMin)
788 if ( (acquisitionTimeStop >= acquisitionTimeRangeMin)
788 && (acquisitionTimeStop <= acquisitionTimeRangeMax)
789 && (acquisitionTimeStop <= acquisitionTimeRangeMax)
789 && (pasFilteringIsEnabled == 1) )
790 && (pasFilteringIsEnabled == 1) )
790 {
791 {
791 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
792 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
792 }
793 }
793 else
794 else
794 {
795 {
795 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
796 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
796 }
797 }
797 }
798 }
798
799
799 return ret;
800 return ret;
800 }
801 }
801
802
802 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
803 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
803 {
804 {
804 unsigned char bin;
805 unsigned char bin;
805 unsigned char kcoeff;
806 unsigned char kcoeff;
806
807
807 for (bin=0; bin<nb_bins_norm; bin++)
808 for (bin=0; bin<nb_bins_norm; bin++)
808 {
809 {
809 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
810 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
810 {
811 {
811 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
812 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
812 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
813 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
813 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
814 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
814 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
815 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
815 }
816 }
816 }
817 }
817 }
818 }
@@ -1,1659 +1,1673
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
35 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
40 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
41 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
43
43
44 status = get_message_queue_id_recv( &queue_rcv_id );
44 status = get_message_queue_id_recv( &queue_rcv_id );
45 if (status != RTEMS_SUCCESSFUL)
45 if (status != RTEMS_SUCCESSFUL)
46 {
46 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 }
48 }
49
49
50 status = get_message_queue_id_send( &queue_snd_id );
50 status = get_message_queue_id_send( &queue_snd_id );
51 if (status != RTEMS_SUCCESSFUL)
51 if (status != RTEMS_SUCCESSFUL)
52 {
52 {
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 }
54 }
55
55
56 result = LFR_SUCCESSFUL;
56 result = LFR_SUCCESSFUL;
57 subtype = 0; // subtype of the current TC packet
57 subtype = 0; // subtype of the current TC packet
58
58
59 BOOT_PRINTF("in ACTN *** \n");
59 BOOT_PRINTF("in ACTN *** \n");
60
60
61 while(1)
61 while(1)
62 {
62 {
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 getTime( time ); // set time to the current time
65 getTime( time ); // set time to the current time
66 if (status!=RTEMS_SUCCESSFUL)
66 if (status!=RTEMS_SUCCESSFUL)
67 {
67 {
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 }
69 }
70 else
70 else
71 {
71 {
72 subtype = TC.serviceSubType;
72 subtype = TC.serviceSubType;
73 switch(subtype)
73 switch(subtype)
74 {
74 {
75 case TC_SUBTYPE_RESET:
75 case TC_SUBTYPE_RESET:
76 result = action_reset( &TC, queue_snd_id, time );
76 result = action_reset( &TC, queue_snd_id, time );
77 close_action( &TC, result, queue_snd_id );
77 close_action( &TC, result, queue_snd_id );
78 break;
78 break;
79 case TC_SUBTYPE_LOAD_COMM:
79 case TC_SUBTYPE_LOAD_COMM:
80 result = action_load_common_par( &TC );
80 result = action_load_common_par( &TC );
81 close_action( &TC, result, queue_snd_id );
81 close_action( &TC, result, queue_snd_id );
82 break;
82 break;
83 case TC_SUBTYPE_LOAD_NORM:
83 case TC_SUBTYPE_LOAD_NORM:
84 result = action_load_normal_par( &TC, queue_snd_id, time );
84 result = action_load_normal_par( &TC, queue_snd_id, time );
85 close_action( &TC, result, queue_snd_id );
85 close_action( &TC, result, queue_snd_id );
86 break;
86 break;
87 case TC_SUBTYPE_LOAD_BURST:
87 case TC_SUBTYPE_LOAD_BURST:
88 result = action_load_burst_par( &TC, queue_snd_id, time );
88 result = action_load_burst_par( &TC, queue_snd_id, time );
89 close_action( &TC, result, queue_snd_id );
89 close_action( &TC, result, queue_snd_id );
90 break;
90 break;
91 case TC_SUBTYPE_LOAD_SBM1:
91 case TC_SUBTYPE_LOAD_SBM1:
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 close_action( &TC, result, queue_snd_id );
93 close_action( &TC, result, queue_snd_id );
94 break;
94 break;
95 case TC_SUBTYPE_LOAD_SBM2:
95 case TC_SUBTYPE_LOAD_SBM2:
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 close_action( &TC, result, queue_snd_id );
97 close_action( &TC, result, queue_snd_id );
98 break;
98 break;
99 case TC_SUBTYPE_DUMP:
99 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( &TC, queue_snd_id );
100 result = action_dump_par( &TC, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
102 break;
102 break;
103 case TC_SUBTYPE_ENTER:
103 case TC_SUBTYPE_ENTER:
104 result = action_enter_mode( &TC, queue_snd_id );
104 result = action_enter_mode( &TC, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
106 break;
106 break;
107 case TC_SUBTYPE_UPDT_INFO:
107 case TC_SUBTYPE_UPDT_INFO:
108 result = action_update_info( &TC, queue_snd_id );
108 result = action_update_info( &TC, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
110 break;
110 break;
111 case TC_SUBTYPE_EN_CAL:
111 case TC_SUBTYPE_EN_CAL:
112 result = action_enable_calibration( &TC, queue_snd_id, time );
112 result = action_enable_calibration( &TC, queue_snd_id, time );
113 close_action( &TC, result, queue_snd_id );
113 close_action( &TC, result, queue_snd_id );
114 break;
114 break;
115 case TC_SUBTYPE_DIS_CAL:
115 case TC_SUBTYPE_DIS_CAL:
116 result = action_disable_calibration( &TC, queue_snd_id, time );
116 result = action_disable_calibration( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
118 break;
118 break;
119 case TC_SUBTYPE_LOAD_K:
119 case TC_SUBTYPE_LOAD_K:
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
121 close_action( &TC, result, queue_snd_id );
122 break;
122 break;
123 case TC_SUBTYPE_DUMP_K:
123 case TC_SUBTYPE_DUMP_K:
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
125 close_action( &TC, result, queue_snd_id );
126 break;
126 break;
127 case TC_SUBTYPE_LOAD_FBINS:
127 case TC_SUBTYPE_LOAD_FBINS:
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 close_action( &TC, result, queue_snd_id );
129 close_action( &TC, result, queue_snd_id );
130 break;
130 break;
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 result = action_load_filter_par( &TC, queue_snd_id, time );
132 result = action_load_filter_par( &TC, queue_snd_id, time );
133 close_action( &TC, result, queue_snd_id );
133 close_action( &TC, result, queue_snd_id );
134 break;
134 break;
135 case TC_SUBTYPE_UPDT_TIME:
135 case TC_SUBTYPE_UPDT_TIME:
136 result = action_update_time( &TC );
136 result = action_update_time( &TC );
137 close_action( &TC, result, queue_snd_id );
137 close_action( &TC, result, queue_snd_id );
138 break;
138 break;
139 default:
139 default:
140 break;
140 break;
141 }
141 }
142 }
142 }
143 }
143 }
144 }
144 }
145
145
146 //***********
146 //***********
147 // TC ACTIONS
147 // TC ACTIONS
148
148
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 {
150 {
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 *
152 *
153 * @param TC points to the TeleCommand packet that is being processed
153 * @param TC points to the TeleCommand packet that is being processed
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 *
155 *
156 */
156 */
157
157
158 PRINTF("this is the end!!!\n");
158 PRINTF("this is the end!!!\n");
159 exit(0);
159 exit(0);
160
160
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162
162
163 return LFR_DEFAULT;
163 return LFR_DEFAULT;
164 }
164 }
165
165
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 {
167 {
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 *
169 *
170 * @param TC points to the TeleCommand packet that is being processed
170 * @param TC points to the TeleCommand packet that is being processed
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 *
172 *
173 */
173 */
174
174
175 rtems_status_code status;
175 rtems_status_code status;
176 unsigned char requestedMode;
176 unsigned char requestedMode;
177 unsigned int transitionCoarseTime;
177 unsigned int transitionCoarseTime;
178 unsigned char * bytePosPtr;
178 unsigned char * bytePosPtr;
179
179
180 bytePosPtr = (unsigned char *) &TC->packetID;
180 bytePosPtr = (unsigned char *) &TC->packetID;
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
184 status = check_mode_value( requestedMode );
184 status = check_mode_value( requestedMode );
185
185
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
187 {
187 {
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
189 }
189 }
190
190
191 else // the mode value is valid, check the transition
191 else // the mode value is valid, check the transition
192 {
192 {
193 status = check_mode_transition(requestedMode);
193 status = check_mode_transition(requestedMode);
194 if (status != LFR_SUCCESSFUL)
194 if (status != LFR_SUCCESSFUL)
195 {
195 {
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
198 }
198 }
199 }
199 }
200
200
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
202 {
202 {
203 status = check_transition_date( transitionCoarseTime );
203 status = check_transition_date( transitionCoarseTime );
204 if (status != LFR_SUCCESSFUL)
204 if (status != LFR_SUCCESSFUL)
205 {
205 {
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
208 }
208 }
209 }
209 }
210
210
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
212 {
212 {
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
214
214
215 switch(requestedMode)
215 switch(requestedMode)
216 {
216 {
217 case LFR_MODE_STANDBY:
217 case LFR_MODE_STANDBY:
218 status = enter_mode_standby();
218 status = enter_mode_standby();
219 break;
219 break;
220 case LFR_MODE_NORMAL:
220 case LFR_MODE_NORMAL:
221 status = enter_mode_normal( transitionCoarseTime );
221 status = enter_mode_normal( transitionCoarseTime );
222 break;
222 break;
223 case LFR_MODE_BURST:
223 case LFR_MODE_BURST:
224 status = enter_mode_burst( transitionCoarseTime );
224 status = enter_mode_burst( transitionCoarseTime );
225 break;
225 break;
226 case LFR_MODE_SBM1:
226 case LFR_MODE_SBM1:
227 status = enter_mode_sbm1( transitionCoarseTime );
227 status = enter_mode_sbm1( transitionCoarseTime );
228 break;
228 break;
229 case LFR_MODE_SBM2:
229 case LFR_MODE_SBM2:
230 status = enter_mode_sbm2( transitionCoarseTime );
230 status = enter_mode_sbm2( transitionCoarseTime );
231 break;
231 break;
232 default:
232 default:
233 break;
233 break;
234 }
234 }
235
235
236 if (status != RTEMS_SUCCESSFUL)
236 if (status != RTEMS_SUCCESSFUL)
237 {
237 {
238 status = LFR_EXE_ERROR;
238 status = LFR_EXE_ERROR;
239 }
239 }
240 }
240 }
241
241
242 return status;
242 return status;
243 }
243 }
244
244
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
246 {
246 {
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
248 *
248 *
249 * @param TC points to the TeleCommand packet that is being processed
249 * @param TC points to the TeleCommand packet that is being processed
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
251 *
251 *
252 * @return LFR directive status code:
252 * @return LFR directive status code:
253 * - LFR_DEFAULT
253 * - LFR_DEFAULT
254 * - LFR_SUCCESSFUL
254 * - LFR_SUCCESSFUL
255 *
255 *
256 */
256 */
257
257
258 unsigned int val;
258 unsigned int val;
259 int result;
260 unsigned int status;
259 unsigned int status;
261 unsigned char mode;
260 unsigned char mode;
262 unsigned char * bytePosPtr;
261 unsigned char * bytePosPtr;
262 int pos;
263 float value;
264
265 pos = INIT_CHAR;
266 value = INIT_FLOAT;
267
268 status = LFR_DEFAULT;
263
269
264 bytePosPtr = (unsigned char *) &TC->packetID;
270 bytePosPtr = (unsigned char *) &TC->packetID;
265
271
266 // check LFR mode
272 // check LFR mode
267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
273 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
268 status = check_update_info_hk_lfr_mode( mode );
274 status = check_update_info_hk_lfr_mode( mode );
269 if (status == LFR_SUCCESSFUL) // check TDS mode
275 if (status == LFR_SUCCESSFUL) // check TDS mode
270 {
276 {
271 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
277 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
272 status = check_update_info_hk_tds_mode( mode );
278 status = check_update_info_hk_tds_mode( mode );
273 }
279 }
274 if (status == LFR_SUCCESSFUL) // check THR mode
280 if (status == LFR_SUCCESSFUL) // check THR mode
275 {
281 {
276 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
282 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
277 status = check_update_info_hk_thr_mode( mode );
283 status = check_update_info_hk_thr_mode( mode );
278 }
284 }
279 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
285 if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies
280 {
286 {
281 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
287 status = check_all_sy_lfr_rw_f(TC, &pos, &value);
282 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
283 val++;
284 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
285 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
286 }
288 }
287
289
288 // pa_bia_status_info
290 // if the parameters checking succeeds, udpate all parameters
289 // => pa_bia_mode_mux_set 3 bits
291 if (status == LFR_SUCCESSFUL)
290 // => pa_bia_mode_hv_enabled 1 bit
292 {
291 // => pa_bia_mode_bias1_enabled 1 bit
293 // pa_bia_status_info
292 // => pa_bia_mode_bias2_enabled 1 bit
294 // => pa_bia_mode_mux_set 3 bits
293 // => pa_bia_mode_bias3_enabled 1 bit
295 // => pa_bia_mode_hv_enabled 1 bit
294 // => pa_bia_on_off (cp_dpu_bias_on_off)
296 // => pa_bia_mode_bias1_enabled 1 bit
295 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
297 // => pa_bia_mode_bias2_enabled 1 bit
296 pa_bia_status_info = pa_bia_status_info
298 // => pa_bia_mode_bias3_enabled 1 bit
297 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
299 // => pa_bia_on_off (cp_dpu_bias_on_off)
300 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
301 pa_bia_status_info = pa_bia_status_info
302 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
298
303
299 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
304 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
300 getReactionWheelsFrequencies( TC );
305 getReactionWheelsFrequencies( TC );
301 set_hk_lfr_sc_rw_f_flags();
306 set_hk_lfr_sc_rw_f_flags();
302 build_sy_lfr_rw_masks();
307 build_sy_lfr_rw_masks();
308
309 // once the masks are built, they have to be merged with the fbins_mask
310 merge_fbins_masks();
303
311
304 // once the masks are built, they have to be merged with the fbins_mask
312 // increase the TC_LFR_UPDATE_INFO counter
305 merge_fbins_masks();
313 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
314 {
315 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
316 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
317 val++;
318 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
319 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
320 }
321 }
306
322
307 result = status;
323 return status;
308
309 return result;
310 }
324 }
311
325
312 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
326 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
313 {
327 {
314 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
328 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
315 *
329 *
316 * @param TC points to the TeleCommand packet that is being processed
330 * @param TC points to the TeleCommand packet that is being processed
317 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
331 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
318 *
332 *
319 */
333 */
320
334
321 int result;
335 int result;
322
336
323 result = LFR_DEFAULT;
337 result = LFR_DEFAULT;
324
338
325 setCalibration( true );
339 setCalibration( true );
326
340
327 result = LFR_SUCCESSFUL;
341 result = LFR_SUCCESSFUL;
328
342
329 return result;
343 return result;
330 }
344 }
331
345
332 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
346 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
333 {
347 {
334 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
348 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
335 *
349 *
336 * @param TC points to the TeleCommand packet that is being processed
350 * @param TC points to the TeleCommand packet that is being processed
337 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
351 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
338 *
352 *
339 */
353 */
340
354
341 int result;
355 int result;
342
356
343 result = LFR_DEFAULT;
357 result = LFR_DEFAULT;
344
358
345 setCalibration( false );
359 setCalibration( false );
346
360
347 result = LFR_SUCCESSFUL;
361 result = LFR_SUCCESSFUL;
348
362
349 return result;
363 return result;
350 }
364 }
351
365
352 int action_update_time(ccsdsTelecommandPacket_t *TC)
366 int action_update_time(ccsdsTelecommandPacket_t *TC)
353 {
367 {
354 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
368 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
355 *
369 *
356 * @param TC points to the TeleCommand packet that is being processed
370 * @param TC points to the TeleCommand packet that is being processed
357 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
371 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
358 *
372 *
359 * @return LFR_SUCCESSFUL
373 * @return LFR_SUCCESSFUL
360 *
374 *
361 */
375 */
362
376
363 unsigned int val;
377 unsigned int val;
364
378
365 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
379 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
366 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
380 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
367 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
381 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
368 + TC->dataAndCRC[BYTE_3];
382 + TC->dataAndCRC[BYTE_3];
369
383
370 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
384 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
371 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
385 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
372 val++;
386 val++;
373 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
387 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
374 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
388 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
375
389
376 oneTcLfrUpdateTimeReceived = 1;
390 oneTcLfrUpdateTimeReceived = 1;
377
391
378 return LFR_SUCCESSFUL;
392 return LFR_SUCCESSFUL;
379 }
393 }
380
394
381 //*******************
395 //*******************
382 // ENTERING THE MODES
396 // ENTERING THE MODES
383 int check_mode_value( unsigned char requestedMode )
397 int check_mode_value( unsigned char requestedMode )
384 {
398 {
385 int status;
399 int status;
386
400
387 status = LFR_DEFAULT;
401 status = LFR_DEFAULT;
388
402
389 if ( (requestedMode != LFR_MODE_STANDBY)
403 if ( (requestedMode != LFR_MODE_STANDBY)
390 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
404 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
391 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
405 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
392 {
406 {
393 status = LFR_DEFAULT;
407 status = LFR_DEFAULT;
394 }
408 }
395 else
409 else
396 {
410 {
397 status = LFR_SUCCESSFUL;
411 status = LFR_SUCCESSFUL;
398 }
412 }
399
413
400 return status;
414 return status;
401 }
415 }
402
416
403 int check_mode_transition( unsigned char requestedMode )
417 int check_mode_transition( unsigned char requestedMode )
404 {
418 {
405 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
419 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
406 *
420 *
407 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
421 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
408 *
422 *
409 * @return LFR directive status codes:
423 * @return LFR directive status codes:
410 * - LFR_SUCCESSFUL - the transition is authorized
424 * - LFR_SUCCESSFUL - the transition is authorized
411 * - LFR_DEFAULT - the transition is not authorized
425 * - LFR_DEFAULT - the transition is not authorized
412 *
426 *
413 */
427 */
414
428
415 int status;
429 int status;
416
430
417 switch (requestedMode)
431 switch (requestedMode)
418 {
432 {
419 case LFR_MODE_STANDBY:
433 case LFR_MODE_STANDBY:
420 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
434 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
421 status = LFR_DEFAULT;
435 status = LFR_DEFAULT;
422 }
436 }
423 else
437 else
424 {
438 {
425 status = LFR_SUCCESSFUL;
439 status = LFR_SUCCESSFUL;
426 }
440 }
427 break;
441 break;
428 case LFR_MODE_NORMAL:
442 case LFR_MODE_NORMAL:
429 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
443 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
430 status = LFR_DEFAULT;
444 status = LFR_DEFAULT;
431 }
445 }
432 else {
446 else {
433 status = LFR_SUCCESSFUL;
447 status = LFR_SUCCESSFUL;
434 }
448 }
435 break;
449 break;
436 case LFR_MODE_BURST:
450 case LFR_MODE_BURST:
437 if ( lfrCurrentMode == LFR_MODE_BURST ) {
451 if ( lfrCurrentMode == LFR_MODE_BURST ) {
438 status = LFR_DEFAULT;
452 status = LFR_DEFAULT;
439 }
453 }
440 else {
454 else {
441 status = LFR_SUCCESSFUL;
455 status = LFR_SUCCESSFUL;
442 }
456 }
443 break;
457 break;
444 case LFR_MODE_SBM1:
458 case LFR_MODE_SBM1:
445 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
459 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
446 status = LFR_DEFAULT;
460 status = LFR_DEFAULT;
447 }
461 }
448 else {
462 else {
449 status = LFR_SUCCESSFUL;
463 status = LFR_SUCCESSFUL;
450 }
464 }
451 break;
465 break;
452 case LFR_MODE_SBM2:
466 case LFR_MODE_SBM2:
453 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
467 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
454 status = LFR_DEFAULT;
468 status = LFR_DEFAULT;
455 }
469 }
456 else {
470 else {
457 status = LFR_SUCCESSFUL;
471 status = LFR_SUCCESSFUL;
458 }
472 }
459 break;
473 break;
460 default:
474 default:
461 status = LFR_DEFAULT;
475 status = LFR_DEFAULT;
462 break;
476 break;
463 }
477 }
464
478
465 return status;
479 return status;
466 }
480 }
467
481
468 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
482 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
469 {
483 {
470 if (transitionCoarseTime == 0)
484 if (transitionCoarseTime == 0)
471 {
485 {
472 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
486 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
473 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
487 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
474 }
488 }
475 else
489 else
476 {
490 {
477 lastValidEnterModeTime = transitionCoarseTime;
491 lastValidEnterModeTime = transitionCoarseTime;
478 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
492 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
479 }
493 }
480 }
494 }
481
495
482 int check_transition_date( unsigned int transitionCoarseTime )
496 int check_transition_date( unsigned int transitionCoarseTime )
483 {
497 {
484 int status;
498 int status;
485 unsigned int localCoarseTime;
499 unsigned int localCoarseTime;
486 unsigned int deltaCoarseTime;
500 unsigned int deltaCoarseTime;
487
501
488 status = LFR_SUCCESSFUL;
502 status = LFR_SUCCESSFUL;
489
503
490 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
504 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
491 {
505 {
492 status = LFR_SUCCESSFUL;
506 status = LFR_SUCCESSFUL;
493 }
507 }
494 else
508 else
495 {
509 {
496 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
510 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
497
511
498 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
512 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
499
513
500 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
514 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
501 {
515 {
502 status = LFR_DEFAULT;
516 status = LFR_DEFAULT;
503 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
517 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
504 }
518 }
505
519
506 if (status == LFR_SUCCESSFUL)
520 if (status == LFR_SUCCESSFUL)
507 {
521 {
508 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
522 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
509 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
523 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
510 {
524 {
511 status = LFR_DEFAULT;
525 status = LFR_DEFAULT;
512 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
526 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
513 }
527 }
514 }
528 }
515 }
529 }
516
530
517 return status;
531 return status;
518 }
532 }
519
533
520 int restart_asm_activities( unsigned char lfrRequestedMode )
534 int restart_asm_activities( unsigned char lfrRequestedMode )
521 {
535 {
522 rtems_status_code status;
536 rtems_status_code status;
523
537
524 status = stop_spectral_matrices();
538 status = stop_spectral_matrices();
525
539
526 thisIsAnASMRestart = 1;
540 thisIsAnASMRestart = 1;
527
541
528 status = restart_asm_tasks( lfrRequestedMode );
542 status = restart_asm_tasks( lfrRequestedMode );
529
543
530 launch_spectral_matrix();
544 launch_spectral_matrix();
531
545
532 return status;
546 return status;
533 }
547 }
534
548
535 int stop_spectral_matrices( void )
549 int stop_spectral_matrices( void )
536 {
550 {
537 /** This function stops and restarts the current mode average spectral matrices activities.
551 /** This function stops and restarts the current mode average spectral matrices activities.
538 *
552 *
539 * @return RTEMS directive status codes:
553 * @return RTEMS directive status codes:
540 * - RTEMS_SUCCESSFUL - task restarted successfully
554 * - RTEMS_SUCCESSFUL - task restarted successfully
541 * - RTEMS_INVALID_ID - task id invalid
555 * - RTEMS_INVALID_ID - task id invalid
542 * - RTEMS_ALREADY_SUSPENDED - task already suspended
556 * - RTEMS_ALREADY_SUSPENDED - task already suspended
543 *
557 *
544 */
558 */
545
559
546 rtems_status_code status;
560 rtems_status_code status;
547
561
548 status = RTEMS_SUCCESSFUL;
562 status = RTEMS_SUCCESSFUL;
549
563
550 // (1) mask interruptions
564 // (1) mask interruptions
551 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
565 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
552
566
553 // (2) reset spectral matrices registers
567 // (2) reset spectral matrices registers
554 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
568 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
555 reset_sm_status();
569 reset_sm_status();
556
570
557 // (3) clear interruptions
571 // (3) clear interruptions
558 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
572 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
559
573
560 // suspend several tasks
574 // suspend several tasks
561 if (lfrCurrentMode != LFR_MODE_STANDBY) {
575 if (lfrCurrentMode != LFR_MODE_STANDBY) {
562 status = suspend_asm_tasks();
576 status = suspend_asm_tasks();
563 }
577 }
564
578
565 if (status != RTEMS_SUCCESSFUL)
579 if (status != RTEMS_SUCCESSFUL)
566 {
580 {
567 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
581 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
568 }
582 }
569
583
570 return status;
584 return status;
571 }
585 }
572
586
573 int stop_current_mode( void )
587 int stop_current_mode( void )
574 {
588 {
575 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
589 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
576 *
590 *
577 * @return RTEMS directive status codes:
591 * @return RTEMS directive status codes:
578 * - RTEMS_SUCCESSFUL - task restarted successfully
592 * - RTEMS_SUCCESSFUL - task restarted successfully
579 * - RTEMS_INVALID_ID - task id invalid
593 * - RTEMS_INVALID_ID - task id invalid
580 * - RTEMS_ALREADY_SUSPENDED - task already suspended
594 * - RTEMS_ALREADY_SUSPENDED - task already suspended
581 *
595 *
582 */
596 */
583
597
584 rtems_status_code status;
598 rtems_status_code status;
585
599
586 status = RTEMS_SUCCESSFUL;
600 status = RTEMS_SUCCESSFUL;
587
601
588 // (1) mask interruptions
602 // (1) mask interruptions
589 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
603 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
590 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
604 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
591
605
592 // (2) reset waveform picker registers
606 // (2) reset waveform picker registers
593 reset_wfp_burst_enable(); // reset burst and enable bits
607 reset_wfp_burst_enable(); // reset burst and enable bits
594 reset_wfp_status(); // reset all the status bits
608 reset_wfp_status(); // reset all the status bits
595
609
596 // (3) reset spectral matrices registers
610 // (3) reset spectral matrices registers
597 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
611 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
598 reset_sm_status();
612 reset_sm_status();
599
613
600 // reset lfr VHDL module
614 // reset lfr VHDL module
601 reset_lfr();
615 reset_lfr();
602
616
603 reset_extractSWF(); // reset the extractSWF flag to false
617 reset_extractSWF(); // reset the extractSWF flag to false
604
618
605 // (4) clear interruptions
619 // (4) clear interruptions
606 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
620 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
607 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
621 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
608
622
609 // suspend several tasks
623 // suspend several tasks
610 if (lfrCurrentMode != LFR_MODE_STANDBY) {
624 if (lfrCurrentMode != LFR_MODE_STANDBY) {
611 status = suspend_science_tasks();
625 status = suspend_science_tasks();
612 }
626 }
613
627
614 if (status != RTEMS_SUCCESSFUL)
628 if (status != RTEMS_SUCCESSFUL)
615 {
629 {
616 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
630 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
617 }
631 }
618
632
619 return status;
633 return status;
620 }
634 }
621
635
622 int enter_mode_standby( void )
636 int enter_mode_standby( void )
623 {
637 {
624 /** This function is used to put LFR in the STANDBY mode.
638 /** This function is used to put LFR in the STANDBY mode.
625 *
639 *
626 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
640 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
627 *
641 *
628 * @return RTEMS directive status codes:
642 * @return RTEMS directive status codes:
629 * - RTEMS_SUCCESSFUL - task restarted successfully
643 * - RTEMS_SUCCESSFUL - task restarted successfully
630 * - RTEMS_INVALID_ID - task id invalid
644 * - RTEMS_INVALID_ID - task id invalid
631 * - RTEMS_INCORRECT_STATE - task never started
645 * - RTEMS_INCORRECT_STATE - task never started
632 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
646 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
633 *
647 *
634 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
648 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
635 * is immediate.
649 * is immediate.
636 *
650 *
637 */
651 */
638
652
639 int status;
653 int status;
640
654
641 status = stop_current_mode(); // STOP THE CURRENT MODE
655 status = stop_current_mode(); // STOP THE CURRENT MODE
642
656
643 #ifdef PRINT_TASK_STATISTICS
657 #ifdef PRINT_TASK_STATISTICS
644 rtems_cpu_usage_report();
658 rtems_cpu_usage_report();
645 #endif
659 #endif
646
660
647 #ifdef PRINT_STACK_REPORT
661 #ifdef PRINT_STACK_REPORT
648 PRINTF("stack report selected\n")
662 PRINTF("stack report selected\n")
649 rtems_stack_checker_report_usage();
663 rtems_stack_checker_report_usage();
650 #endif
664 #endif
651
665
652 return status;
666 return status;
653 }
667 }
654
668
655 int enter_mode_normal( unsigned int transitionCoarseTime )
669 int enter_mode_normal( unsigned int transitionCoarseTime )
656 {
670 {
657 /** This function is used to start the NORMAL mode.
671 /** This function is used to start the NORMAL mode.
658 *
672 *
659 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
673 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
660 *
674 *
661 * @return RTEMS directive status codes:
675 * @return RTEMS directive status codes:
662 * - RTEMS_SUCCESSFUL - task restarted successfully
676 * - RTEMS_SUCCESSFUL - task restarted successfully
663 * - RTEMS_INVALID_ID - task id invalid
677 * - RTEMS_INVALID_ID - task id invalid
664 * - RTEMS_INCORRECT_STATE - task never started
678 * - RTEMS_INCORRECT_STATE - task never started
665 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
679 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
666 *
680 *
667 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
681 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
668 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
682 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
669 *
683 *
670 */
684 */
671
685
672 int status;
686 int status;
673
687
674 #ifdef PRINT_TASK_STATISTICS
688 #ifdef PRINT_TASK_STATISTICS
675 rtems_cpu_usage_reset();
689 rtems_cpu_usage_reset();
676 #endif
690 #endif
677
691
678 status = RTEMS_UNSATISFIED;
692 status = RTEMS_UNSATISFIED;
679
693
680 switch( lfrCurrentMode )
694 switch( lfrCurrentMode )
681 {
695 {
682 case LFR_MODE_STANDBY:
696 case LFR_MODE_STANDBY:
683 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
697 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
684 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
698 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
685 {
699 {
686 launch_spectral_matrix( );
700 launch_spectral_matrix( );
687 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
701 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
688 }
702 }
689 break;
703 break;
690 case LFR_MODE_BURST:
704 case LFR_MODE_BURST:
691 status = stop_current_mode(); // stop the current mode
705 status = stop_current_mode(); // stop the current mode
692 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
706 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
693 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
707 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
694 {
708 {
695 launch_spectral_matrix( );
709 launch_spectral_matrix( );
696 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
710 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
697 }
711 }
698 break;
712 break;
699 case LFR_MODE_SBM1:
713 case LFR_MODE_SBM1:
700 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
714 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
701 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
715 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
702 update_last_valid_transition_date( transitionCoarseTime );
716 update_last_valid_transition_date( transitionCoarseTime );
703 break;
717 break;
704 case LFR_MODE_SBM2:
718 case LFR_MODE_SBM2:
705 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
719 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
706 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
720 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
707 update_last_valid_transition_date( transitionCoarseTime );
721 update_last_valid_transition_date( transitionCoarseTime );
708 break;
722 break;
709 default:
723 default:
710 break;
724 break;
711 }
725 }
712
726
713 if (status != RTEMS_SUCCESSFUL)
727 if (status != RTEMS_SUCCESSFUL)
714 {
728 {
715 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
729 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
716 status = RTEMS_UNSATISFIED;
730 status = RTEMS_UNSATISFIED;
717 }
731 }
718
732
719 return status;
733 return status;
720 }
734 }
721
735
722 int enter_mode_burst( unsigned int transitionCoarseTime )
736 int enter_mode_burst( unsigned int transitionCoarseTime )
723 {
737 {
724 /** This function is used to start the BURST mode.
738 /** This function is used to start the BURST mode.
725 *
739 *
726 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
740 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
727 *
741 *
728 * @return RTEMS directive status codes:
742 * @return RTEMS directive status codes:
729 * - RTEMS_SUCCESSFUL - task restarted successfully
743 * - RTEMS_SUCCESSFUL - task restarted successfully
730 * - RTEMS_INVALID_ID - task id invalid
744 * - RTEMS_INVALID_ID - task id invalid
731 * - RTEMS_INCORRECT_STATE - task never started
745 * - RTEMS_INCORRECT_STATE - task never started
732 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
746 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
733 *
747 *
734 * The way the BURST mode is started does not depend on the LFR current mode.
748 * The way the BURST mode is started does not depend on the LFR current mode.
735 *
749 *
736 */
750 */
737
751
738
752
739 int status;
753 int status;
740
754
741 #ifdef PRINT_TASK_STATISTICS
755 #ifdef PRINT_TASK_STATISTICS
742 rtems_cpu_usage_reset();
756 rtems_cpu_usage_reset();
743 #endif
757 #endif
744
758
745 status = stop_current_mode(); // stop the current mode
759 status = stop_current_mode(); // stop the current mode
746 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
760 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
747 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
761 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
748 {
762 {
749 launch_spectral_matrix( );
763 launch_spectral_matrix( );
750 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
764 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
751 }
765 }
752
766
753 if (status != RTEMS_SUCCESSFUL)
767 if (status != RTEMS_SUCCESSFUL)
754 {
768 {
755 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
769 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
756 status = RTEMS_UNSATISFIED;
770 status = RTEMS_UNSATISFIED;
757 }
771 }
758
772
759 return status;
773 return status;
760 }
774 }
761
775
762 int enter_mode_sbm1( unsigned int transitionCoarseTime )
776 int enter_mode_sbm1( unsigned int transitionCoarseTime )
763 {
777 {
764 /** This function is used to start the SBM1 mode.
778 /** This function is used to start the SBM1 mode.
765 *
779 *
766 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
780 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
767 *
781 *
768 * @return RTEMS directive status codes:
782 * @return RTEMS directive status codes:
769 * - RTEMS_SUCCESSFUL - task restarted successfully
783 * - RTEMS_SUCCESSFUL - task restarted successfully
770 * - RTEMS_INVALID_ID - task id invalid
784 * - RTEMS_INVALID_ID - task id invalid
771 * - RTEMS_INCORRECT_STATE - task never started
785 * - RTEMS_INCORRECT_STATE - task never started
772 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
786 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
773 *
787 *
774 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
788 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
775 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
789 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
776 * cases, the acquisition is completely restarted.
790 * cases, the acquisition is completely restarted.
777 *
791 *
778 */
792 */
779
793
780 int status;
794 int status;
781
795
782 #ifdef PRINT_TASK_STATISTICS
796 #ifdef PRINT_TASK_STATISTICS
783 rtems_cpu_usage_reset();
797 rtems_cpu_usage_reset();
784 #endif
798 #endif
785
799
786 status = RTEMS_UNSATISFIED;
800 status = RTEMS_UNSATISFIED;
787
801
788 switch( lfrCurrentMode )
802 switch( lfrCurrentMode )
789 {
803 {
790 case LFR_MODE_STANDBY:
804 case LFR_MODE_STANDBY:
791 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
805 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
792 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
806 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
793 {
807 {
794 launch_spectral_matrix( );
808 launch_spectral_matrix( );
795 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
809 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
796 }
810 }
797 break;
811 break;
798 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
812 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
799 status = restart_asm_activities( LFR_MODE_SBM1 );
813 status = restart_asm_activities( LFR_MODE_SBM1 );
800 status = LFR_SUCCESSFUL;
814 status = LFR_SUCCESSFUL;
801 update_last_valid_transition_date( transitionCoarseTime );
815 update_last_valid_transition_date( transitionCoarseTime );
802 break;
816 break;
803 case LFR_MODE_BURST:
817 case LFR_MODE_BURST:
804 status = stop_current_mode(); // stop the current mode
818 status = stop_current_mode(); // stop the current mode
805 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
819 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
806 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
820 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
807 {
821 {
808 launch_spectral_matrix( );
822 launch_spectral_matrix( );
809 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
823 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
810 }
824 }
811 break;
825 break;
812 case LFR_MODE_SBM2:
826 case LFR_MODE_SBM2:
813 status = restart_asm_activities( LFR_MODE_SBM1 );
827 status = restart_asm_activities( LFR_MODE_SBM1 );
814 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
828 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
815 update_last_valid_transition_date( transitionCoarseTime );
829 update_last_valid_transition_date( transitionCoarseTime );
816 break;
830 break;
817 default:
831 default:
818 break;
832 break;
819 }
833 }
820
834
821 if (status != RTEMS_SUCCESSFUL)
835 if (status != RTEMS_SUCCESSFUL)
822 {
836 {
823 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
837 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
824 status = RTEMS_UNSATISFIED;
838 status = RTEMS_UNSATISFIED;
825 }
839 }
826
840
827 return status;
841 return status;
828 }
842 }
829
843
830 int enter_mode_sbm2( unsigned int transitionCoarseTime )
844 int enter_mode_sbm2( unsigned int transitionCoarseTime )
831 {
845 {
832 /** This function is used to start the SBM2 mode.
846 /** This function is used to start the SBM2 mode.
833 *
847 *
834 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
848 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
835 *
849 *
836 * @return RTEMS directive status codes:
850 * @return RTEMS directive status codes:
837 * - RTEMS_SUCCESSFUL - task restarted successfully
851 * - RTEMS_SUCCESSFUL - task restarted successfully
838 * - RTEMS_INVALID_ID - task id invalid
852 * - RTEMS_INVALID_ID - task id invalid
839 * - RTEMS_INCORRECT_STATE - task never started
853 * - RTEMS_INCORRECT_STATE - task never started
840 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
854 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
841 *
855 *
842 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
856 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
843 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
857 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
844 * cases, the acquisition is completely restarted.
858 * cases, the acquisition is completely restarted.
845 *
859 *
846 */
860 */
847
861
848 int status;
862 int status;
849
863
850 #ifdef PRINT_TASK_STATISTICS
864 #ifdef PRINT_TASK_STATISTICS
851 rtems_cpu_usage_reset();
865 rtems_cpu_usage_reset();
852 #endif
866 #endif
853
867
854 status = RTEMS_UNSATISFIED;
868 status = RTEMS_UNSATISFIED;
855
869
856 switch( lfrCurrentMode )
870 switch( lfrCurrentMode )
857 {
871 {
858 case LFR_MODE_STANDBY:
872 case LFR_MODE_STANDBY:
859 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
873 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
860 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
874 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
861 {
875 {
862 launch_spectral_matrix( );
876 launch_spectral_matrix( );
863 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
877 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
864 }
878 }
865 break;
879 break;
866 case LFR_MODE_NORMAL:
880 case LFR_MODE_NORMAL:
867 status = restart_asm_activities( LFR_MODE_SBM2 );
881 status = restart_asm_activities( LFR_MODE_SBM2 );
868 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
882 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
869 update_last_valid_transition_date( transitionCoarseTime );
883 update_last_valid_transition_date( transitionCoarseTime );
870 break;
884 break;
871 case LFR_MODE_BURST:
885 case LFR_MODE_BURST:
872 status = stop_current_mode(); // stop the current mode
886 status = stop_current_mode(); // stop the current mode
873 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
887 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
874 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
888 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
875 {
889 {
876 launch_spectral_matrix( );
890 launch_spectral_matrix( );
877 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
891 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
878 }
892 }
879 break;
893 break;
880 case LFR_MODE_SBM1:
894 case LFR_MODE_SBM1:
881 status = restart_asm_activities( LFR_MODE_SBM2 );
895 status = restart_asm_activities( LFR_MODE_SBM2 );
882 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
896 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
883 update_last_valid_transition_date( transitionCoarseTime );
897 update_last_valid_transition_date( transitionCoarseTime );
884 break;
898 break;
885 default:
899 default:
886 break;
900 break;
887 }
901 }
888
902
889 if (status != RTEMS_SUCCESSFUL)
903 if (status != RTEMS_SUCCESSFUL)
890 {
904 {
891 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
905 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
892 status = RTEMS_UNSATISFIED;
906 status = RTEMS_UNSATISFIED;
893 }
907 }
894
908
895 return status;
909 return status;
896 }
910 }
897
911
898 int restart_science_tasks( unsigned char lfrRequestedMode )
912 int restart_science_tasks( unsigned char lfrRequestedMode )
899 {
913 {
900 /** This function is used to restart all science tasks.
914 /** This function is used to restart all science tasks.
901 *
915 *
902 * @return RTEMS directive status codes:
916 * @return RTEMS directive status codes:
903 * - RTEMS_SUCCESSFUL - task restarted successfully
917 * - RTEMS_SUCCESSFUL - task restarted successfully
904 * - RTEMS_INVALID_ID - task id invalid
918 * - RTEMS_INVALID_ID - task id invalid
905 * - RTEMS_INCORRECT_STATE - task never started
919 * - RTEMS_INCORRECT_STATE - task never started
906 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
920 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
907 *
921 *
908 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
922 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
909 *
923 *
910 */
924 */
911
925
912 rtems_status_code status[NB_SCIENCE_TASKS];
926 rtems_status_code status[NB_SCIENCE_TASKS];
913 rtems_status_code ret;
927 rtems_status_code ret;
914
928
915 ret = RTEMS_SUCCESSFUL;
929 ret = RTEMS_SUCCESSFUL;
916
930
917 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
931 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
918 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
932 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
919 {
933 {
920 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
934 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
921 }
935 }
922
936
923 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
937 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
924 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
938 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
925 {
939 {
926 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
940 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
927 }
941 }
928
942
929 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
943 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
930 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
944 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
931 {
945 {
932 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
946 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
933 }
947 }
934
948
935 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
949 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
936 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
950 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
937 {
951 {
938 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
952 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
939 }
953 }
940
954
941 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
955 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
942 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
956 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
943 {
957 {
944 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
958 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
945 }
959 }
946
960
947 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
961 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
948 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
962 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
949 {
963 {
950 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
964 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
951 }
965 }
952
966
953 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
967 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
954 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
968 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
955 {
969 {
956 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
970 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
957 }
971 }
958
972
959 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
973 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
960 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
974 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
961 {
975 {
962 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
976 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
963 }
977 }
964
978
965 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
979 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
966 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
980 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
967 {
981 {
968 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
982 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
969 }
983 }
970
984
971 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
985 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
972 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
986 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
973 {
987 {
974 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
988 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
975 }
989 }
976
990
977 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
991 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
978 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
992 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
979 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
993 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
980 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
994 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
981 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
995 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
982 {
996 {
983 ret = RTEMS_UNSATISFIED;
997 ret = RTEMS_UNSATISFIED;
984 }
998 }
985
999
986 return ret;
1000 return ret;
987 }
1001 }
988
1002
989 int restart_asm_tasks( unsigned char lfrRequestedMode )
1003 int restart_asm_tasks( unsigned char lfrRequestedMode )
990 {
1004 {
991 /** This function is used to restart average spectral matrices tasks.
1005 /** This function is used to restart average spectral matrices tasks.
992 *
1006 *
993 * @return RTEMS directive status codes:
1007 * @return RTEMS directive status codes:
994 * - RTEMS_SUCCESSFUL - task restarted successfully
1008 * - RTEMS_SUCCESSFUL - task restarted successfully
995 * - RTEMS_INVALID_ID - task id invalid
1009 * - RTEMS_INVALID_ID - task id invalid
996 * - RTEMS_INCORRECT_STATE - task never started
1010 * - RTEMS_INCORRECT_STATE - task never started
997 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1011 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
998 *
1012 *
999 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1013 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1000 *
1014 *
1001 */
1015 */
1002
1016
1003 rtems_status_code status[NB_ASM_TASKS];
1017 rtems_status_code status[NB_ASM_TASKS];
1004 rtems_status_code ret;
1018 rtems_status_code ret;
1005
1019
1006 ret = RTEMS_SUCCESSFUL;
1020 ret = RTEMS_SUCCESSFUL;
1007
1021
1008 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1022 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1009 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1023 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1010 {
1024 {
1011 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1025 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1012 }
1026 }
1013
1027
1014 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1028 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1015 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1029 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1016 {
1030 {
1017 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1031 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1018 }
1032 }
1019
1033
1020 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1034 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1021 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1035 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1022 {
1036 {
1023 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1037 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1024 }
1038 }
1025
1039
1026 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1040 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1027 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1041 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1028 {
1042 {
1029 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1043 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1030 }
1044 }
1031
1045
1032 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1046 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1033 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1047 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1034 {
1048 {
1035 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1049 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1036 }
1050 }
1037
1051
1038 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1052 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1039 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1053 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1040 {
1054 {
1041 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1055 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1042 }
1056 }
1043
1057
1044 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1058 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1045 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1059 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1046 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1060 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1047 {
1061 {
1048 ret = RTEMS_UNSATISFIED;
1062 ret = RTEMS_UNSATISFIED;
1049 }
1063 }
1050
1064
1051 return ret;
1065 return ret;
1052 }
1066 }
1053
1067
1054 int suspend_science_tasks( void )
1068 int suspend_science_tasks( void )
1055 {
1069 {
1056 /** This function suspends the science tasks.
1070 /** This function suspends the science tasks.
1057 *
1071 *
1058 * @return RTEMS directive status codes:
1072 * @return RTEMS directive status codes:
1059 * - RTEMS_SUCCESSFUL - task restarted successfully
1073 * - RTEMS_SUCCESSFUL - task restarted successfully
1060 * - RTEMS_INVALID_ID - task id invalid
1074 * - RTEMS_INVALID_ID - task id invalid
1061 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1075 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1062 *
1076 *
1063 */
1077 */
1064
1078
1065 rtems_status_code status;
1079 rtems_status_code status;
1066
1080
1067 PRINTF("in suspend_science_tasks\n")
1081 PRINTF("in suspend_science_tasks\n")
1068
1082
1069 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1083 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1070 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1084 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1071 {
1085 {
1072 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1086 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1073 }
1087 }
1074 else
1088 else
1075 {
1089 {
1076 status = RTEMS_SUCCESSFUL;
1090 status = RTEMS_SUCCESSFUL;
1077 }
1091 }
1078 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1092 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1079 {
1093 {
1080 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1094 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1081 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1095 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1082 {
1096 {
1083 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1097 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1084 }
1098 }
1085 else
1099 else
1086 {
1100 {
1087 status = RTEMS_SUCCESSFUL;
1101 status = RTEMS_SUCCESSFUL;
1088 }
1102 }
1089 }
1103 }
1090 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1104 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1091 {
1105 {
1092 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1106 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1093 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1094 {
1108 {
1095 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1109 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1096 }
1110 }
1097 else
1111 else
1098 {
1112 {
1099 status = RTEMS_SUCCESSFUL;
1113 status = RTEMS_SUCCESSFUL;
1100 }
1114 }
1101 }
1115 }
1102 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1116 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1103 {
1117 {
1104 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1118 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1105 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1119 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1106 {
1120 {
1107 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1121 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1108 }
1122 }
1109 else
1123 else
1110 {
1124 {
1111 status = RTEMS_SUCCESSFUL;
1125 status = RTEMS_SUCCESSFUL;
1112 }
1126 }
1113 }
1127 }
1114 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1128 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1115 {
1129 {
1116 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1130 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1117 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1131 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1118 {
1132 {
1119 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1133 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1120 }
1134 }
1121 else
1135 else
1122 {
1136 {
1123 status = RTEMS_SUCCESSFUL;
1137 status = RTEMS_SUCCESSFUL;
1124 }
1138 }
1125 }
1139 }
1126 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1140 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1127 {
1141 {
1128 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1142 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1129 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1143 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1130 {
1144 {
1131 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1145 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1132 }
1146 }
1133 else
1147 else
1134 {
1148 {
1135 status = RTEMS_SUCCESSFUL;
1149 status = RTEMS_SUCCESSFUL;
1136 }
1150 }
1137 }
1151 }
1138 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1152 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1139 {
1153 {
1140 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1154 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1141 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1155 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1142 {
1156 {
1143 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1157 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1144 }
1158 }
1145 else
1159 else
1146 {
1160 {
1147 status = RTEMS_SUCCESSFUL;
1161 status = RTEMS_SUCCESSFUL;
1148 }
1162 }
1149 }
1163 }
1150 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1164 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1151 {
1165 {
1152 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1166 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1153 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1167 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1154 {
1168 {
1155 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1169 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1156 }
1170 }
1157 else
1171 else
1158 {
1172 {
1159 status = RTEMS_SUCCESSFUL;
1173 status = RTEMS_SUCCESSFUL;
1160 }
1174 }
1161 }
1175 }
1162 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1176 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1163 {
1177 {
1164 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1178 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1165 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1179 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1166 {
1180 {
1167 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1181 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1168 }
1182 }
1169 else
1183 else
1170 {
1184 {
1171 status = RTEMS_SUCCESSFUL;
1185 status = RTEMS_SUCCESSFUL;
1172 }
1186 }
1173 }
1187 }
1174 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1188 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1175 {
1189 {
1176 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1190 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1177 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1191 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1178 {
1192 {
1179 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1193 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1180 }
1194 }
1181 else
1195 else
1182 {
1196 {
1183 status = RTEMS_SUCCESSFUL;
1197 status = RTEMS_SUCCESSFUL;
1184 }
1198 }
1185 }
1199 }
1186
1200
1187 return status;
1201 return status;
1188 }
1202 }
1189
1203
1190 int suspend_asm_tasks( void )
1204 int suspend_asm_tasks( void )
1191 {
1205 {
1192 /** This function suspends the science tasks.
1206 /** This function suspends the science tasks.
1193 *
1207 *
1194 * @return RTEMS directive status codes:
1208 * @return RTEMS directive status codes:
1195 * - RTEMS_SUCCESSFUL - task restarted successfully
1209 * - RTEMS_SUCCESSFUL - task restarted successfully
1196 * - RTEMS_INVALID_ID - task id invalid
1210 * - RTEMS_INVALID_ID - task id invalid
1197 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1211 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1198 *
1212 *
1199 */
1213 */
1200
1214
1201 rtems_status_code status;
1215 rtems_status_code status;
1202
1216
1203 PRINTF("in suspend_science_tasks\n")
1217 PRINTF("in suspend_science_tasks\n")
1204
1218
1205 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1219 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1206 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1220 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1207 {
1221 {
1208 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1222 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1209 }
1223 }
1210 else
1224 else
1211 {
1225 {
1212 status = RTEMS_SUCCESSFUL;
1226 status = RTEMS_SUCCESSFUL;
1213 }
1227 }
1214
1228
1215 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1229 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1216 {
1230 {
1217 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1231 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1218 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1232 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1219 {
1233 {
1220 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1234 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1221 }
1235 }
1222 else
1236 else
1223 {
1237 {
1224 status = RTEMS_SUCCESSFUL;
1238 status = RTEMS_SUCCESSFUL;
1225 }
1239 }
1226 }
1240 }
1227
1241
1228 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1242 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1229 {
1243 {
1230 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1244 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1231 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1245 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1232 {
1246 {
1233 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1247 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1234 }
1248 }
1235 else
1249 else
1236 {
1250 {
1237 status = RTEMS_SUCCESSFUL;
1251 status = RTEMS_SUCCESSFUL;
1238 }
1252 }
1239 }
1253 }
1240
1254
1241 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1255 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1242 {
1256 {
1243 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1257 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1244 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1258 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1245 {
1259 {
1246 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1260 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1247 }
1261 }
1248 else
1262 else
1249 {
1263 {
1250 status = RTEMS_SUCCESSFUL;
1264 status = RTEMS_SUCCESSFUL;
1251 }
1265 }
1252 }
1266 }
1253
1267
1254 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1268 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1255 {
1269 {
1256 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1270 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1257 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1271 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1258 {
1272 {
1259 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1273 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1260 }
1274 }
1261 else
1275 else
1262 {
1276 {
1263 status = RTEMS_SUCCESSFUL;
1277 status = RTEMS_SUCCESSFUL;
1264 }
1278 }
1265 }
1279 }
1266
1280
1267 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1281 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1268 {
1282 {
1269 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1283 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1270 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1284 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1271 {
1285 {
1272 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1286 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1273 }
1287 }
1274 else
1288 else
1275 {
1289 {
1276 status = RTEMS_SUCCESSFUL;
1290 status = RTEMS_SUCCESSFUL;
1277 }
1291 }
1278 }
1292 }
1279
1293
1280 return status;
1294 return status;
1281 }
1295 }
1282
1296
1283 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1297 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1284 {
1298 {
1285
1299
1286 WFP_reset_current_ring_nodes();
1300 WFP_reset_current_ring_nodes();
1287
1301
1288 reset_waveform_picker_regs();
1302 reset_waveform_picker_regs();
1289
1303
1290 set_wfp_burst_enable_register( mode );
1304 set_wfp_burst_enable_register( mode );
1291
1305
1292 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1306 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1293 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1307 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1294
1308
1295 if (transitionCoarseTime == 0)
1309 if (transitionCoarseTime == 0)
1296 {
1310 {
1297 // instant transition means transition on the next valid date
1311 // instant transition means transition on the next valid date
1298 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1312 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1299 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1313 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1300 }
1314 }
1301 else
1315 else
1302 {
1316 {
1303 waveform_picker_regs->start_date = transitionCoarseTime;
1317 waveform_picker_regs->start_date = transitionCoarseTime;
1304 }
1318 }
1305
1319
1306 update_last_valid_transition_date(waveform_picker_regs->start_date);
1320 update_last_valid_transition_date(waveform_picker_regs->start_date);
1307
1321
1308 }
1322 }
1309
1323
1310 void launch_spectral_matrix( void )
1324 void launch_spectral_matrix( void )
1311 {
1325 {
1312 SM_reset_current_ring_nodes();
1326 SM_reset_current_ring_nodes();
1313
1327
1314 reset_spectral_matrix_regs();
1328 reset_spectral_matrix_regs();
1315
1329
1316 reset_nb_sm();
1330 reset_nb_sm();
1317
1331
1318 set_sm_irq_onNewMatrix( 1 );
1332 set_sm_irq_onNewMatrix( 1 );
1319
1333
1320 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1334 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1321 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1335 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1322
1336
1323 }
1337 }
1324
1338
1325 void set_sm_irq_onNewMatrix( unsigned char value )
1339 void set_sm_irq_onNewMatrix( unsigned char value )
1326 {
1340 {
1327 if (value == 1)
1341 if (value == 1)
1328 {
1342 {
1329 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1343 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1330 }
1344 }
1331 else
1345 else
1332 {
1346 {
1333 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1347 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1334 }
1348 }
1335 }
1349 }
1336
1350
1337 void set_sm_irq_onError( unsigned char value )
1351 void set_sm_irq_onError( unsigned char value )
1338 {
1352 {
1339 if (value == 1)
1353 if (value == 1)
1340 {
1354 {
1341 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1355 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1342 }
1356 }
1343 else
1357 else
1344 {
1358 {
1345 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1359 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1346 }
1360 }
1347 }
1361 }
1348
1362
1349 //*****************************
1363 //*****************************
1350 // CONFIGURE CALIBRATION SIGNAL
1364 // CONFIGURE CALIBRATION SIGNAL
1351 void setCalibrationPrescaler( unsigned int prescaler )
1365 void setCalibrationPrescaler( unsigned int prescaler )
1352 {
1366 {
1353 // prescaling of the master clock (25 MHz)
1367 // prescaling of the master clock (25 MHz)
1354 // master clock is divided by 2^prescaler
1368 // master clock is divided by 2^prescaler
1355 time_management_regs->calPrescaler = prescaler;
1369 time_management_regs->calPrescaler = prescaler;
1356 }
1370 }
1357
1371
1358 void setCalibrationDivisor( unsigned int divisionFactor )
1372 void setCalibrationDivisor( unsigned int divisionFactor )
1359 {
1373 {
1360 // division of the prescaled clock by the division factor
1374 // division of the prescaled clock by the division factor
1361 time_management_regs->calDivisor = divisionFactor;
1375 time_management_regs->calDivisor = divisionFactor;
1362 }
1376 }
1363
1377
1364 void setCalibrationData( void )
1378 void setCalibrationData( void )
1365 {
1379 {
1366 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1380 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1367 *
1381 *
1368 * @param void
1382 * @param void
1369 *
1383 *
1370 * @return void
1384 * @return void
1371 *
1385 *
1372 */
1386 */
1373
1387
1374 unsigned int k;
1388 unsigned int k;
1375 unsigned short data;
1389 unsigned short data;
1376 float val;
1390 float val;
1377 float Ts;
1391 float Ts;
1378
1392
1379 time_management_regs->calDataPtr = INIT_CHAR;
1393 time_management_regs->calDataPtr = INIT_CHAR;
1380
1394
1381 Ts = 1 / CAL_FS;
1395 Ts = 1 / CAL_FS;
1382
1396
1383 // build the signal for the SCM calibration
1397 // build the signal for the SCM calibration
1384 for (k = 0; k < CAL_NB_PTS; k++)
1398 for (k = 0; k < CAL_NB_PTS; k++)
1385 {
1399 {
1386 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1400 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1387 + CAL_A1 * sin( CAL_W1 * k * Ts );
1401 + CAL_A1 * sin( CAL_W1 * k * Ts );
1388 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1402 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1389 time_management_regs->calData = data & CAL_DATA_MASK;
1403 time_management_regs->calData = data & CAL_DATA_MASK;
1390 }
1404 }
1391 }
1405 }
1392
1406
1393 void setCalibrationDataInterleaved( void )
1407 void setCalibrationDataInterleaved( void )
1394 {
1408 {
1395 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1409 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1396 *
1410 *
1397 * @param void
1411 * @param void
1398 *
1412 *
1399 * @return void
1413 * @return void
1400 *
1414 *
1401 * In interleaved mode, one can store more values than in normal mode.
1415 * In interleaved mode, one can store more values than in normal mode.
1402 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1416 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1403 * T store 3 values, one need two write operations.
1417 * T store 3 values, one need two write operations.
1404 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1418 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1405 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1419 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1406 *
1420 *
1407 */
1421 */
1408
1422
1409 unsigned int k;
1423 unsigned int k;
1410 float val;
1424 float val;
1411 float Ts;
1425 float Ts;
1412 unsigned short data[CAL_NB_PTS_INTER];
1426 unsigned short data[CAL_NB_PTS_INTER];
1413 unsigned char *dataPtr;
1427 unsigned char *dataPtr;
1414
1428
1415 Ts = 1 / CAL_FS_INTER;
1429 Ts = 1 / CAL_FS_INTER;
1416
1430
1417 time_management_regs->calDataPtr = INIT_CHAR;
1431 time_management_regs->calDataPtr = INIT_CHAR;
1418
1432
1419 // build the signal for the SCM calibration
1433 // build the signal for the SCM calibration
1420 for (k=0; k<CAL_NB_PTS_INTER; k++)
1434 for (k=0; k<CAL_NB_PTS_INTER; k++)
1421 {
1435 {
1422 val = sin( 2 * pi * CAL_F0 * k * Ts )
1436 val = sin( 2 * pi * CAL_F0 * k * Ts )
1423 + sin( 2 * pi * CAL_F1 * k * Ts );
1437 + sin( 2 * pi * CAL_F1 * k * Ts );
1424 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1438 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1425 }
1439 }
1426
1440
1427 // write the signal in interleaved mode
1441 // write the signal in interleaved mode
1428 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1442 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1429 {
1443 {
1430 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1444 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1431 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1445 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1432 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1446 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1433 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1447 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1434 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1448 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1435 }
1449 }
1436 }
1450 }
1437
1451
1438 void setCalibrationReload( bool state)
1452 void setCalibrationReload( bool state)
1439 {
1453 {
1440 if (state == true)
1454 if (state == true)
1441 {
1455 {
1442 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1456 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1443 }
1457 }
1444 else
1458 else
1445 {
1459 {
1446 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1460 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1447 }
1461 }
1448 }
1462 }
1449
1463
1450 void setCalibrationEnable( bool state )
1464 void setCalibrationEnable( bool state )
1451 {
1465 {
1452 // this bit drives the multiplexer
1466 // this bit drives the multiplexer
1453 if (state == true)
1467 if (state == true)
1454 {
1468 {
1455 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1469 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1456 }
1470 }
1457 else
1471 else
1458 {
1472 {
1459 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1473 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1460 }
1474 }
1461 }
1475 }
1462
1476
1463 void setCalibrationInterleaved( bool state )
1477 void setCalibrationInterleaved( bool state )
1464 {
1478 {
1465 // this bit drives the multiplexer
1479 // this bit drives the multiplexer
1466 if (state == true)
1480 if (state == true)
1467 {
1481 {
1468 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1482 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1469 }
1483 }
1470 else
1484 else
1471 {
1485 {
1472 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1486 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1473 }
1487 }
1474 }
1488 }
1475
1489
1476 void setCalibration( bool state )
1490 void setCalibration( bool state )
1477 {
1491 {
1478 if (state == true)
1492 if (state == true)
1479 {
1493 {
1480 setCalibrationEnable( true );
1494 setCalibrationEnable( true );
1481 setCalibrationReload( false );
1495 setCalibrationReload( false );
1482 set_hk_lfr_calib_enable( true );
1496 set_hk_lfr_calib_enable( true );
1483 }
1497 }
1484 else
1498 else
1485 {
1499 {
1486 setCalibrationEnable( false );
1500 setCalibrationEnable( false );
1487 setCalibrationReload( true );
1501 setCalibrationReload( true );
1488 set_hk_lfr_calib_enable( false );
1502 set_hk_lfr_calib_enable( false );
1489 }
1503 }
1490 }
1504 }
1491
1505
1492 void configureCalibration( bool interleaved )
1506 void configureCalibration( bool interleaved )
1493 {
1507 {
1494 setCalibration( false );
1508 setCalibration( false );
1495 if ( interleaved == true )
1509 if ( interleaved == true )
1496 {
1510 {
1497 setCalibrationInterleaved( true );
1511 setCalibrationInterleaved( true );
1498 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1512 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1499 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1513 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1500 setCalibrationDataInterleaved();
1514 setCalibrationDataInterleaved();
1501 }
1515 }
1502 else
1516 else
1503 {
1517 {
1504 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1518 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1505 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1519 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1506 setCalibrationData();
1520 setCalibrationData();
1507 }
1521 }
1508 }
1522 }
1509
1523
1510 //****************
1524 //****************
1511 // CLOSING ACTIONS
1525 // CLOSING ACTIONS
1512 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1526 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1513 {
1527 {
1514 /** This function is used to update the HK packets statistics after a successful TC execution.
1528 /** This function is used to update the HK packets statistics after a successful TC execution.
1515 *
1529 *
1516 * @param TC points to the TC being processed
1530 * @param TC points to the TC being processed
1517 * @param time is the time used to date the TC execution
1531 * @param time is the time used to date the TC execution
1518 *
1532 *
1519 */
1533 */
1520
1534
1521 unsigned int val;
1535 unsigned int val;
1522
1536
1523 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1537 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1524 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1538 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1525 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1539 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1526 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1540 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1527 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1541 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1528 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1542 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1529 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1543 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1530 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1544 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1531 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1545 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1532 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1546 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1533 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1547 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1548 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1535
1549
1536 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1550 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1537 val++;
1551 val++;
1538 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1552 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1539 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1553 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1540 }
1554 }
1541
1555
1542 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1556 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1543 {
1557 {
1544 /** This function is used to update the HK packets statistics after a TC rejection.
1558 /** This function is used to update the HK packets statistics after a TC rejection.
1545 *
1559 *
1546 * @param TC points to the TC being processed
1560 * @param TC points to the TC being processed
1547 * @param time is the time used to date the TC rejection
1561 * @param time is the time used to date the TC rejection
1548 *
1562 *
1549 */
1563 */
1550
1564
1551 unsigned int val;
1565 unsigned int val;
1552
1566
1553 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1567 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1554 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1568 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1555 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1569 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1556 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1570 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1557 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1571 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1558 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1572 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1559 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1573 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1560 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1574 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1561 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1575 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1562 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1576 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1563 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1577 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1578 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1565
1579
1566 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1580 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1567 val++;
1581 val++;
1568 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1582 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1569 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1583 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1570 }
1584 }
1571
1585
1572 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1586 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1573 {
1587 {
1574 /** This function is the last step of the TC execution workflow.
1588 /** This function is the last step of the TC execution workflow.
1575 *
1589 *
1576 * @param TC points to the TC being processed
1590 * @param TC points to the TC being processed
1577 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1591 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1578 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1592 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1579 * @param time is the time used to date the TC execution
1593 * @param time is the time used to date the TC execution
1580 *
1594 *
1581 */
1595 */
1582
1596
1583 unsigned char requestedMode;
1597 unsigned char requestedMode;
1584
1598
1585 if (result == LFR_SUCCESSFUL)
1599 if (result == LFR_SUCCESSFUL)
1586 {
1600 {
1587 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1601 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1588 &
1602 &
1589 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1603 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1590 )
1604 )
1591 {
1605 {
1592 send_tm_lfr_tc_exe_success( TC, queue_id );
1606 send_tm_lfr_tc_exe_success( TC, queue_id );
1593 }
1607 }
1594 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1608 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1595 {
1609 {
1596 //**********************************
1610 //**********************************
1597 // UPDATE THE LFRMODE LOCAL VARIABLE
1611 // UPDATE THE LFRMODE LOCAL VARIABLE
1598 requestedMode = TC->dataAndCRC[1];
1612 requestedMode = TC->dataAndCRC[1];
1599 updateLFRCurrentMode( requestedMode );
1613 updateLFRCurrentMode( requestedMode );
1600 }
1614 }
1601 }
1615 }
1602 else if (result == LFR_EXE_ERROR)
1616 else if (result == LFR_EXE_ERROR)
1603 {
1617 {
1604 send_tm_lfr_tc_exe_error( TC, queue_id );
1618 send_tm_lfr_tc_exe_error( TC, queue_id );
1605 }
1619 }
1606 }
1620 }
1607
1621
1608 //***************************
1622 //***************************
1609 // Interrupt Service Routines
1623 // Interrupt Service Routines
1610 rtems_isr commutation_isr1( rtems_vector_number vector )
1624 rtems_isr commutation_isr1( rtems_vector_number vector )
1611 {
1625 {
1612 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1626 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1613 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1627 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1614 }
1628 }
1615 }
1629 }
1616
1630
1617 rtems_isr commutation_isr2( rtems_vector_number vector )
1631 rtems_isr commutation_isr2( rtems_vector_number vector )
1618 {
1632 {
1619 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1633 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1620 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1634 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1621 }
1635 }
1622 }
1636 }
1623
1637
1624 //****************
1638 //****************
1625 // OTHER FUNCTIONS
1639 // OTHER FUNCTIONS
1626 void updateLFRCurrentMode( unsigned char requestedMode )
1640 void updateLFRCurrentMode( unsigned char requestedMode )
1627 {
1641 {
1628 /** This function updates the value of the global variable lfrCurrentMode.
1642 /** This function updates the value of the global variable lfrCurrentMode.
1629 *
1643 *
1630 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1644 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1631 *
1645 *
1632 */
1646 */
1633
1647
1634 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1648 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1635 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1649 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1636 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1650 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1637 lfrCurrentMode = requestedMode;
1651 lfrCurrentMode = requestedMode;
1638 }
1652 }
1639
1653
1640 void set_lfr_soft_reset( unsigned char value )
1654 void set_lfr_soft_reset( unsigned char value )
1641 {
1655 {
1642 if (value == 1)
1656 if (value == 1)
1643 {
1657 {
1644 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1658 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1645 }
1659 }
1646 else
1660 else
1647 {
1661 {
1648 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1662 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1649 }
1663 }
1650 }
1664 }
1651
1665
1652 void reset_lfr( void )
1666 void reset_lfr( void )
1653 {
1667 {
1654 set_lfr_soft_reset( 1 );
1668 set_lfr_soft_reset( 1 );
1655
1669
1656 set_lfr_soft_reset( 0 );
1670 set_lfr_soft_reset( 0 );
1657
1671
1658 set_hk_lfr_sc_potential_flag( true );
1672 set_hk_lfr_sc_potential_flag( true );
1659 }
1673 }
@@ -1,1951 +1,2061
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 unsigned char k;
327 unsigned char k;
328
328
329 flag = LFR_DEFAULT;
329 flag = LFR_DEFAULT;
330 k = INIT_CHAR;
330 k = INIT_CHAR;
331
331
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
333
333
334 if (flag == LFR_SUCCESSFUL)
334 if (flag == LFR_SUCCESSFUL)
335 {
335 {
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
351
351
352 //****************************
352 //****************************
353 // store PAS filter parameters
353 // store PAS filter parameters
354 // sy_lfr_pas_filter_enabled
354 // sy_lfr_pas_filter_enabled
355 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
355 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
356 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
356 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
357 // sy_lfr_pas_filter_modulus
357 // sy_lfr_pas_filter_modulus
358 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
358 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
359 // sy_lfr_pas_filter_tbad
359 // sy_lfr_pas_filter_tbad
360 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
360 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
361 parameter_dump_packet.sy_lfr_pas_filter_tbad );
361 parameter_dump_packet.sy_lfr_pas_filter_tbad );
362 // sy_lfr_pas_filter_offset
362 // sy_lfr_pas_filter_offset
363 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
363 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
364 // sy_lfr_pas_filter_shift
364 // sy_lfr_pas_filter_shift
365 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
365 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
366 parameter_dump_packet.sy_lfr_pas_filter_shift );
366 parameter_dump_packet.sy_lfr_pas_filter_shift );
367
367
368 //****************************************************
368 //****************************************************
369 // store the parameter sy_lfr_sc_rw_delta_f as a float
369 // store the parameter sy_lfr_sc_rw_delta_f as a float
370 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
370 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
372
372
373 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
373 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
374 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
374 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
375 {
375 {
376 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
376 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
377 }
377 }
378
378
379 //***********************************************
379 //***********************************************
380 // store the parameter sy_lfr_rw.._k.. as a float
380 // store the parameter sy_lfr_rw.._k.. as a float
381 // rw1_k
381 // rw1_k
382 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
382 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
383 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
383 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
384 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
384 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
385 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
385 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
386 // rw2_k
386 // rw2_k
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
388 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
388 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
391 // rw3_k
391 // rw3_k
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
393 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
393 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
396 // rw4_k
396 // rw4_k
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
398 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
398 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
401
401
402 }
402 }
403
403
404 return flag;
404 return flag;
405 }
405 }
406
406
407 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
407 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
408 {
408 {
409 /** This function updates the LFR registers with the incoming sbm2 parameters.
409 /** This function updates the LFR registers with the incoming sbm2 parameters.
410 *
410 *
411 * @param TC points to the TeleCommand packet that is being processed
411 * @param TC points to the TeleCommand packet that is being processed
412 * @param queue_id is the id of the queue which handles TM related to this execution step
412 * @param queue_id is the id of the queue which handles TM related to this execution step
413 *
413 *
414 */
414 */
415
415
416 unsigned int address;
416 unsigned int address;
417 rtems_status_code status;
417 rtems_status_code status;
418 unsigned int freq;
418 unsigned int freq;
419 unsigned int bin;
419 unsigned int bin;
420 unsigned int coeff;
420 unsigned int coeff;
421 unsigned char *kCoeffPtr;
421 unsigned char *kCoeffPtr;
422 unsigned char *kCoeffDumpPtr;
422 unsigned char *kCoeffDumpPtr;
423
423
424 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
424 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
425 // F0 => 11 bins
425 // F0 => 11 bins
426 // F1 => 13 bins
426 // F1 => 13 bins
427 // F2 => 12 bins
427 // F2 => 12 bins
428 // 36 bins to dump in two packets (30 bins max per packet)
428 // 36 bins to dump in two packets (30 bins max per packet)
429
429
430 //*********
430 //*********
431 // PACKET 1
431 // PACKET 1
432 // 11 F0 bins, 13 F1 bins and 6 F2 bins
432 // 11 F0 bins, 13 F1 bins and 6 F2 bins
433 kcoefficients_dump_1.destinationID = TC->sourceID;
433 kcoefficients_dump_1.destinationID = TC->sourceID;
434 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
434 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
435 for( freq = 0;
435 for( freq = 0;
436 freq < NB_BINS_COMPRESSED_SM_F0;
436 freq < NB_BINS_COMPRESSED_SM_F0;
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;
440 bin = freq;
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
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_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 }
449 }
450 }
450 }
451 for( freq = NB_BINS_COMPRESSED_SM_F0;
451 for( freq = NB_BINS_COMPRESSED_SM_F0;
452 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
452 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
453 freq++ )
453 freq++ )
454 {
454 {
455 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
455 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
456 bin = freq - NB_BINS_COMPRESSED_SM_F0;
456 bin = freq - NB_BINS_COMPRESSED_SM_F0;
457 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
457 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
458 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
458 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
459 {
459 {
460 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
460 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
461 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
461 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
462 ]; // 2 for the kcoeff_frequency
462 ]; // 2 for the kcoeff_frequency
463 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
463 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
464 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
464 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
465 }
465 }
466 }
466 }
467 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
467 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
468 freq < KCOEFF_BLK_NR_PKT1 ;
468 freq < KCOEFF_BLK_NR_PKT1 ;
469 freq++ )
469 freq++ )
470 {
470 {
471 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
471 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
472 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
472 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
473 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
473 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
474 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
474 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
475 {
475 {
476 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
476 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
477 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
477 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
478 ]; // 2 for the kcoeff_frequency
478 ]; // 2 for the kcoeff_frequency
479 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
479 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
480 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
480 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
481 }
481 }
482 }
482 }
483 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
483 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
484 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
484 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
485 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
485 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
486 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
486 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
487 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
487 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
488 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
488 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
489 // SEND DATA
489 // SEND DATA
490 kcoefficient_node_1.status = 1;
490 kcoefficient_node_1.status = 1;
491 address = (unsigned int) &kcoefficient_node_1;
491 address = (unsigned int) &kcoefficient_node_1;
492 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
492 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
493 if (status != RTEMS_SUCCESSFUL) {
493 if (status != RTEMS_SUCCESSFUL) {
494 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
494 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
495 }
495 }
496
496
497 //********
497 //********
498 // PACKET 2
498 // PACKET 2
499 // 6 F2 bins
499 // 6 F2 bins
500 kcoefficients_dump_2.destinationID = TC->sourceID;
500 kcoefficients_dump_2.destinationID = TC->sourceID;
501 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
501 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
502 for( freq = 0;
502 for( freq = 0;
503 freq < KCOEFF_BLK_NR_PKT2;
503 freq < KCOEFF_BLK_NR_PKT2;
504 freq++ )
504 freq++ )
505 {
505 {
506 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
506 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
507 bin = freq + KCOEFF_BLK_NR_PKT2;
507 bin = freq + KCOEFF_BLK_NR_PKT2;
508 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
508 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
509 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
509 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
510 {
510 {
511 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
511 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
512 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
512 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
513 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
513 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
514 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
514 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
515 }
515 }
516 }
516 }
517 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
517 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
518 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
518 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
519 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
519 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
520 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
520 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
521 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
521 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
522 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
522 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
523 // SEND DATA
523 // SEND DATA
524 kcoefficient_node_2.status = 1;
524 kcoefficient_node_2.status = 1;
525 address = (unsigned int) &kcoefficient_node_2;
525 address = (unsigned int) &kcoefficient_node_2;
526 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
526 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
527 if (status != RTEMS_SUCCESSFUL) {
527 if (status != RTEMS_SUCCESSFUL) {
528 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
528 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
529 }
529 }
530
530
531 return status;
531 return status;
532 }
532 }
533
533
534 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
534 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
535 {
535 {
536 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
536 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
537 *
537 *
538 * @param queue_id is the id of the queue which handles TM related to this execution step.
538 * @param queue_id is the id of the queue which handles TM related to this execution step.
539 *
539 *
540 * @return RTEMS directive status codes:
540 * @return RTEMS directive status codes:
541 * - RTEMS_SUCCESSFUL - message sent successfully
541 * - RTEMS_SUCCESSFUL - message sent successfully
542 * - RTEMS_INVALID_ID - invalid queue id
542 * - RTEMS_INVALID_ID - invalid queue id
543 * - RTEMS_INVALID_SIZE - invalid message size
543 * - RTEMS_INVALID_SIZE - invalid message size
544 * - RTEMS_INVALID_ADDRESS - buffer is NULL
544 * - RTEMS_INVALID_ADDRESS - buffer is NULL
545 * - RTEMS_UNSATISFIED - out of message buffers
545 * - RTEMS_UNSATISFIED - out of message buffers
546 * - RTEMS_TOO_MANY - queue s limit has been reached
546 * - RTEMS_TOO_MANY - queue s limit has been reached
547 *
547 *
548 */
548 */
549
549
550 int status;
550 int status;
551
551
552 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
552 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
553 parameter_dump_packet.destinationID = TC->sourceID;
553 parameter_dump_packet.destinationID = TC->sourceID;
554
554
555 // UPDATE TIME
555 // UPDATE TIME
556 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
556 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
557 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
557 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
558 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
558 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
559 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
559 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
560 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
560 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
561 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
561 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
562 // SEND DATA
562 // SEND DATA
563 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
563 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
564 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
564 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
565 if (status != RTEMS_SUCCESSFUL) {
565 if (status != RTEMS_SUCCESSFUL) {
566 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
566 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
567 }
567 }
568
568
569 return status;
569 return status;
570 }
570 }
571
571
572 //***********************
572 //***********************
573 // NORMAL MODE PARAMETERS
573 // NORMAL MODE PARAMETERS
574
574
575 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
575 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
576 {
576 {
577 unsigned char msb;
577 unsigned char msb;
578 unsigned char lsb;
578 unsigned char lsb;
579 int flag;
579 int flag;
580 float aux;
580 float aux;
581 rtems_status_code status;
581 rtems_status_code status;
582
582
583 unsigned int sy_lfr_n_swf_l;
583 unsigned int sy_lfr_n_swf_l;
584 unsigned int sy_lfr_n_swf_p;
584 unsigned int sy_lfr_n_swf_p;
585 unsigned int sy_lfr_n_asm_p;
585 unsigned int sy_lfr_n_asm_p;
586 unsigned char sy_lfr_n_bp_p0;
586 unsigned char sy_lfr_n_bp_p0;
587 unsigned char sy_lfr_n_bp_p1;
587 unsigned char sy_lfr_n_bp_p1;
588 unsigned char sy_lfr_n_cwf_long_f3;
588 unsigned char sy_lfr_n_cwf_long_f3;
589
589
590 flag = LFR_SUCCESSFUL;
590 flag = LFR_SUCCESSFUL;
591
591
592 //***************
592 //***************
593 // get parameters
593 // get parameters
594 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
594 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
595 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
595 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
596 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
596 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
597
597
598 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
598 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
599 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
599 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
600 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
600 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
601
601
602 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
602 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
603 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
603 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
604 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
604 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
605
605
606 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
606 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
607
607
608 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
608 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
609
609
610 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
610 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
611
611
612 //******************
612 //******************
613 // check consistency
613 // check consistency
614 // sy_lfr_n_swf_l
614 // sy_lfr_n_swf_l
615 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
615 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
616 {
616 {
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
618 flag = WRONG_APP_DATA;
618 flag = WRONG_APP_DATA;
619 }
619 }
620 // sy_lfr_n_swf_p
620 // sy_lfr_n_swf_p
621 if (flag == LFR_SUCCESSFUL)
621 if (flag == LFR_SUCCESSFUL)
622 {
622 {
623 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
623 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
624 {
624 {
625 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
625 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
626 flag = WRONG_APP_DATA;
626 flag = WRONG_APP_DATA;
627 }
627 }
628 }
628 }
629 // sy_lfr_n_bp_p0
629 // sy_lfr_n_bp_p0
630 if (flag == LFR_SUCCESSFUL)
630 if (flag == LFR_SUCCESSFUL)
631 {
631 {
632 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
632 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
633 {
633 {
634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
634 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
635 flag = WRONG_APP_DATA;
635 flag = WRONG_APP_DATA;
636 }
636 }
637 }
637 }
638 // sy_lfr_n_asm_p
638 // sy_lfr_n_asm_p
639 if (flag == LFR_SUCCESSFUL)
639 if (flag == LFR_SUCCESSFUL)
640 {
640 {
641 if (sy_lfr_n_asm_p == 0)
641 if (sy_lfr_n_asm_p == 0)
642 {
642 {
643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
644 flag = WRONG_APP_DATA;
644 flag = WRONG_APP_DATA;
645 }
645 }
646 }
646 }
647 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
647 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
648 if (flag == LFR_SUCCESSFUL)
648 if (flag == LFR_SUCCESSFUL)
649 {
649 {
650 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
650 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
651 if (aux > FLOAT_EQUAL_ZERO)
651 if (aux > FLOAT_EQUAL_ZERO)
652 {
652 {
653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
654 flag = WRONG_APP_DATA;
654 flag = WRONG_APP_DATA;
655 }
655 }
656 }
656 }
657 // sy_lfr_n_bp_p1
657 // sy_lfr_n_bp_p1
658 if (flag == LFR_SUCCESSFUL)
658 if (flag == LFR_SUCCESSFUL)
659 {
659 {
660 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
660 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
661 {
661 {
662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
663 flag = WRONG_APP_DATA;
663 flag = WRONG_APP_DATA;
664 }
664 }
665 }
665 }
666 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
666 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
667 if (flag == LFR_SUCCESSFUL)
667 if (flag == LFR_SUCCESSFUL)
668 {
668 {
669 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
669 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
670 if (aux > FLOAT_EQUAL_ZERO)
670 if (aux > FLOAT_EQUAL_ZERO)
671 {
671 {
672 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
672 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
673 flag = LFR_DEFAULT;
673 flag = LFR_DEFAULT;
674 }
674 }
675 }
675 }
676 // sy_lfr_n_cwf_long_f3
676 // sy_lfr_n_cwf_long_f3
677
677
678 return flag;
678 return flag;
679 }
679 }
680
680
681 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
681 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
682 {
682 {
683 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
683 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
684 *
684 *
685 * @param TC points to the TeleCommand packet that is being processed
685 * @param TC points to the TeleCommand packet that is being processed
686 * @param queue_id is the id of the queue which handles TM related to this execution step
686 * @param queue_id is the id of the queue which handles TM related to this execution step
687 *
687 *
688 */
688 */
689
689
690 int result;
690 int result;
691
691
692 result = LFR_SUCCESSFUL;
692 result = LFR_SUCCESSFUL;
693
693
694 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
694 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
695 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
695 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
696
696
697 return result;
697 return result;
698 }
698 }
699
699
700 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
700 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
701 {
701 {
702 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
702 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
703 *
703 *
704 * @param TC points to the TeleCommand packet that is being processed
704 * @param TC points to the TeleCommand packet that is being processed
705 * @param queue_id is the id of the queue which handles TM related to this execution step
705 * @param queue_id is the id of the queue which handles TM related to this execution step
706 *
706 *
707 */
707 */
708
708
709 int result;
709 int result;
710
710
711 result = LFR_SUCCESSFUL;
711 result = LFR_SUCCESSFUL;
712
712
713 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
713 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
714 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
714 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
715
715
716 return result;
716 return result;
717 }
717 }
718
718
719 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
719 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
720 {
720 {
721 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
721 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
722 *
722 *
723 * @param TC points to the TeleCommand packet that is being processed
723 * @param TC points to the TeleCommand packet that is being processed
724 * @param queue_id is the id of the queue which handles TM related to this execution step
724 * @param queue_id is the id of the queue which handles TM related to this execution step
725 *
725 *
726 */
726 */
727
727
728 int result;
728 int result;
729
729
730 result = LFR_SUCCESSFUL;
730 result = LFR_SUCCESSFUL;
731
731
732 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
732 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
733 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
733 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
734
734
735 return result;
735 return result;
736 }
736 }
737
737
738 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
738 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
739 {
739 {
740 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
740 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
741 *
741 *
742 * @param TC points to the TeleCommand packet that is being processed
742 * @param TC points to the TeleCommand packet that is being processed
743 * @param queue_id is the id of the queue which handles TM related to this execution step
743 * @param queue_id is the id of the queue which handles TM related to this execution step
744 *
744 *
745 */
745 */
746
746
747 int status;
747 int status;
748
748
749 status = LFR_SUCCESSFUL;
749 status = LFR_SUCCESSFUL;
750
750
751 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
751 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
752
752
753 return status;
753 return status;
754 }
754 }
755
755
756 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
756 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
757 {
757 {
758 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
758 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
759 *
759 *
760 * @param TC points to the TeleCommand packet that is being processed
760 * @param TC points to the TeleCommand packet that is being processed
761 * @param queue_id is the id of the queue which handles TM related to this execution step
761 * @param queue_id is the id of the queue which handles TM related to this execution step
762 *
762 *
763 */
763 */
764
764
765 int status;
765 int status;
766
766
767 status = LFR_SUCCESSFUL;
767 status = LFR_SUCCESSFUL;
768
768
769 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
769 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
770
770
771 return status;
771 return status;
772 }
772 }
773
773
774 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
774 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
775 {
775 {
776 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
776 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
777 *
777 *
778 * @param TC points to the TeleCommand packet that is being processed
778 * @param TC points to the TeleCommand packet that is being processed
779 * @param queue_id is the id of the queue which handles TM related to this execution step
779 * @param queue_id is the id of the queue which handles TM related to this execution step
780 *
780 *
781 */
781 */
782
782
783 int status;
783 int status;
784
784
785 status = LFR_SUCCESSFUL;
785 status = LFR_SUCCESSFUL;
786
786
787 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
787 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
788
788
789 return status;
789 return status;
790 }
790 }
791
791
792 //**********************
792 //**********************
793 // BURST MODE PARAMETERS
793 // BURST MODE PARAMETERS
794
794 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
795 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
795 {
796 {
796 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
797 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
797 *
798 *
798 * @param TC points to the TeleCommand packet that is being processed
799 * @param TC points to the TeleCommand packet that is being processed
799 * @param queue_id is the id of the queue which handles TM related to this execution step
800 * @param queue_id is the id of the queue which handles TM related to this execution step
800 *
801 *
801 */
802 */
802
803
803 int status;
804 int status;
804
805
805 status = LFR_SUCCESSFUL;
806 status = LFR_SUCCESSFUL;
806
807
807 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
808 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
808
809
809 return status;
810 return status;
810 }
811 }
811
812
812 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
813 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
813 {
814 {
814 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
815 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
815 *
816 *
816 * @param TC points to the TeleCommand packet that is being processed
817 * @param TC points to the TeleCommand packet that is being processed
817 * @param queue_id is the id of the queue which handles TM related to this execution step
818 * @param queue_id is the id of the queue which handles TM related to this execution step
818 *
819 *
819 */
820 */
820
821
821 int status;
822 int status;
822
823
823 status = LFR_SUCCESSFUL;
824 status = LFR_SUCCESSFUL;
824
825
825 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
826 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
826
827
827 return status;
828 return status;
828 }
829 }
829
830
830 //*********************
831 //*********************
831 // SBM1 MODE PARAMETERS
832 // SBM1 MODE PARAMETERS
833
832 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
834 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
833 {
835 {
834 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
836 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
835 *
837 *
836 * @param TC points to the TeleCommand packet that is being processed
838 * @param TC points to the TeleCommand packet that is being processed
837 * @param queue_id is the id of the queue which handles TM related to this execution step
839 * @param queue_id is the id of the queue which handles TM related to this execution step
838 *
840 *
839 */
841 */
840
842
841 int status;
843 int status;
842
844
843 status = LFR_SUCCESSFUL;
845 status = LFR_SUCCESSFUL;
844
846
845 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
847 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
846
848
847 return status;
849 return status;
848 }
850 }
849
851
850 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
852 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
851 {
853 {
852 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
854 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
853 *
855 *
854 * @param TC points to the TeleCommand packet that is being processed
856 * @param TC points to the TeleCommand packet that is being processed
855 * @param queue_id is the id of the queue which handles TM related to this execution step
857 * @param queue_id is the id of the queue which handles TM related to this execution step
856 *
858 *
857 */
859 */
858
860
859 int status;
861 int status;
860
862
861 status = LFR_SUCCESSFUL;
863 status = LFR_SUCCESSFUL;
862
864
863 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
865 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
864
866
865 return status;
867 return status;
866 }
868 }
867
869
868 //*********************
870 //*********************
869 // SBM2 MODE PARAMETERS
871 // SBM2 MODE PARAMETERS
872
870 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
873 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
871 {
874 {
872 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
875 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
873 *
876 *
874 * @param TC points to the TeleCommand packet that is being processed
877 * @param TC points to the TeleCommand packet that is being processed
875 * @param queue_id is the id of the queue which handles TM related to this execution step
878 * @param queue_id is the id of the queue which handles TM related to this execution step
876 *
879 *
877 */
880 */
878
881
879 int status;
882 int status;
880
883
881 status = LFR_SUCCESSFUL;
884 status = LFR_SUCCESSFUL;
882
885
883 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
886 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
884
887
885 return status;
888 return status;
886 }
889 }
887
890
888 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
891 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
889 {
892 {
890 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
893 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
891 *
894 *
892 * @param TC points to the TeleCommand packet that is being processed
895 * @param TC points to the TeleCommand packet that is being processed
893 * @param queue_id is the id of the queue which handles TM related to this execution step
896 * @param queue_id is the id of the queue which handles TM related to this execution step
894 *
897 *
895 */
898 */
896
899
897 int status;
900 int status;
898
901
899 status = LFR_SUCCESSFUL;
902 status = LFR_SUCCESSFUL;
900
903
901 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
904 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
902
905
903 return status;
906 return status;
904 }
907 }
905
908
906 //*******************
909 //*******************
907 // TC_LFR_UPDATE_INFO
910 // TC_LFR_UPDATE_INFO
911
908 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
912 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
909 {
913 {
910 unsigned int status;
914 unsigned int status;
911
915
912 status = LFR_DEFAULT;
916 status = LFR_DEFAULT;
913
917
914 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
918 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
915 || (mode == LFR_MODE_BURST)
919 || (mode == LFR_MODE_BURST)
916 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
920 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
917 {
921 {
918 status = LFR_SUCCESSFUL;
922 status = LFR_SUCCESSFUL;
919 }
923 }
920 else
924 else
921 {
925 {
922 status = LFR_DEFAULT;
926 status = LFR_DEFAULT;
923 }
927 }
924
928
925 return status;
929 return status;
926 }
930 }
927
931
928 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
932 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
929 {
933 {
930 unsigned int status;
934 unsigned int status;
931
935
932 status = LFR_DEFAULT;
936 status = LFR_DEFAULT;
933
937
934 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
938 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
935 || (mode == TDS_MODE_BURST)
939 || (mode == TDS_MODE_BURST)
936 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
940 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
937 || (mode == TDS_MODE_LFM))
941 || (mode == TDS_MODE_LFM))
938 {
942 {
939 status = LFR_SUCCESSFUL;
943 status = LFR_SUCCESSFUL;
940 }
944 }
941 else
945 else
942 {
946 {
943 status = LFR_DEFAULT;
947 status = LFR_DEFAULT;
944 }
948 }
945
949
946 return status;
950 return status;
947 }
951 }
948
952
949 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
953 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
950 {
954 {
951 unsigned int status;
955 unsigned int status;
952
956
953 status = LFR_DEFAULT;
957 status = LFR_DEFAULT;
954
958
955 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
959 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
956 || (mode == THR_MODE_BURST))
960 || (mode == THR_MODE_BURST))
957 {
961 {
958 status = LFR_SUCCESSFUL;
962 status = LFR_SUCCESSFUL;
959 }
963 }
960 else
964 else
961 {
965 {
962 status = LFR_DEFAULT;
966 status = LFR_DEFAULT;
963 }
967 }
964
968
965 return status;
969 return status;
966 }
970 }
967
971
968 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
972 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
969 {
973 {
970 unsigned char flag;
974 unsigned char flag;
971 unsigned char flagPosInByte;
975 unsigned char flagPosInByte;
972 unsigned char newFlag;
976 unsigned char newFlag;
973 unsigned char flagMask;
977 unsigned char flagMask;
974
978
975 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
979 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
976 if (isnan(value))
980 if (isnan(value))
977 {
981 {
978 flag = FLAG_NAN;
982 flag = FLAG_NAN;
979 }
983 }
980 else
984 else
981 {
985 {
982 flag = FLAG_IAN;
986 flag = FLAG_IAN;
983 }
987 }
984
988
985 switch(wheel)
989 switch(wheel)
986 {
990 {
987 case WHEEL_1:
991 case WHEEL_1:
988 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
992 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
989 flagMask = ~(1 << flagPosInByte);
993 flagMask = ~(1 << flagPosInByte);
990 newFlag = flag << flagPosInByte;
994 newFlag = flag << flagPosInByte;
991 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
995 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
992 break;
996 break;
993 case WHEEL_2:
997 case WHEEL_2:
994 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
998 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
995 flagMask = ~(1 << flagPosInByte);
999 flagMask = ~(1 << flagPosInByte);
996 newFlag = flag << flagPosInByte;
1000 newFlag = flag << flagPosInByte;
997 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1001 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
998 break;
1002 break;
999 case WHEEL_3:
1003 case WHEEL_3:
1000 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1004 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1001 flagMask = ~(1 << flagPosInByte);
1005 flagMask = ~(1 << flagPosInByte);
1002 newFlag = flag << flagPosInByte;
1006 newFlag = flag << flagPosInByte;
1003 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1007 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1004 break;
1008 break;
1005 case WHEEL_4:
1009 case WHEEL_4:
1006 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1010 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1007 flagMask = ~(1 << flagPosInByte);
1011 flagMask = ~(1 << flagPosInByte);
1008 newFlag = flag << flagPosInByte;
1012 newFlag = flag << flagPosInByte;
1009 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1013 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1010 break;
1014 break;
1011 default:
1015 default:
1012 break;
1016 break;
1013 }
1017 }
1014 }
1018 }
1015
1019
1016 void set_hk_lfr_sc_rw_f_flags( void )
1020 void set_hk_lfr_sc_rw_f_flags( void )
1017 {
1021 {
1018 // RW1
1022 // RW1
1019 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1023 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1020 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1024 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1021 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1025 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1022 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1026 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1023
1027
1024 // RW2
1028 // RW2
1025 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1029 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1026 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1030 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1027 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1031 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1028 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1029
1033
1030 // RW3
1034 // RW3
1031 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1035 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1036 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1033 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1037 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1034 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1035
1039
1036 // RW4
1040 // RW4
1037 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1041 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1042 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1039 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1043 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1040 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1044 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1041 }
1045 }
1042
1046
1047 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1048 {
1049 float rw_k;
1050 int ret;
1051
1052 ret = LFR_SUCCESSFUL;
1053 rw_k = INIT_FLOAT;
1054
1055 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->packetID[ offset ] );
1056
1057 *pos = offset;
1058 *value = rw_k;
1059
1060 if (rw_k < MIN_SY_LFR_RW_F)
1061 {
1062 ret = WRONG_APP_DATA;
1063 }
1064
1065 return ret;
1066 }
1067
1068 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1069 {
1070 int ret;
1071
1072 ret = LFR_SUCCESSFUL;
1073
1074 //****
1075 //****
1076 // RW1
1077 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1, pos, value ); // F1
1078 if (ret == LFR_SUCCESSFUL) // F2
1079 {
1080 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2, pos, value );
1081 }
1082 if (ret == LFR_SUCCESSFUL) // F3
1083 {
1084 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3, pos, value );
1085 }
1086 if (ret == LFR_SUCCESSFUL) // F4
1087 {
1088 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4, pos, value );
1089 }
1090
1091 //****
1092 //****
1093 // RW2
1094 if (ret == LFR_SUCCESSFUL) // F1
1095 {
1096 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1, pos, value );
1097 }
1098 if (ret == LFR_SUCCESSFUL) // F2
1099 {
1100 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2, pos, value );
1101 }
1102 if (ret == LFR_SUCCESSFUL) // F3
1103 {
1104 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3, pos, value );
1105 }
1106 if (ret == LFR_SUCCESSFUL) // F4
1107 {
1108 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4, pos, value );
1109 }
1110
1111 //****
1112 //****
1113 // RW3
1114 if (ret == LFR_SUCCESSFUL) // F1
1115 {
1116 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1, pos, value );
1117 }
1118 if (ret == LFR_SUCCESSFUL) // F2
1119 {
1120 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2, pos, value );
1121 }
1122 if (ret == LFR_SUCCESSFUL) // F3
1123 {
1124 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3, pos, value );
1125 }
1126 if (ret == LFR_SUCCESSFUL) // F4
1127 {
1128 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4, pos, value );
1129 }
1130
1131 //****
1132 //****
1133 // RW4
1134 if (ret == LFR_SUCCESSFUL) // F1
1135 {
1136 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1, pos, value );
1137 }
1138 if (ret == LFR_SUCCESSFUL) // F2
1139 {
1140 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2, pos, value );
1141 }
1142 if (ret == LFR_SUCCESSFUL) // F3
1143 {
1144 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3, pos, value );
1145 }
1146 if (ret == LFR_SUCCESSFUL) // F4
1147 {
1148 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4, pos, value );
1149 }
1150
1151 return ret;
1152 }
1153
1043 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1154 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1044 {
1155 {
1045 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1156 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1046 *
1157 *
1047 * @param TC points to the TeleCommand packet that is being processed
1158 * @param TC points to the TeleCommand packet that is being processed
1048 *
1159 *
1049 */
1160 */
1050
1161
1051 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1162 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1052
1163
1053 bytePosPtr = (unsigned char *) &TC->packetID;
1164 bytePosPtr = (unsigned char *) &TC->packetID;
1054
1165
1055 // rw1_f
1166 // rw1_f
1056 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1167 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1057 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1168 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1058 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1169 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1059 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1170 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1060
1171
1061 // rw2_f
1172 // rw2_f
1062 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1173 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1063 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1174 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1064 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1175 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1065 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1176 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1066
1177
1067 // rw3_f
1178 // rw3_f
1068 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1179 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1069 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1180 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1070 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1181 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1071 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1182 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1072
1183
1073 // rw4_f
1184 // rw4_f
1074 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1185 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1075 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1186 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1076 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1187 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1077 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1188 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1078
1189
1079 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1190 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1080
1191
1081 }
1192 }
1082
1193
1083 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1194 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1084 {
1195 {
1085 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1196 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1086 *
1197 *
1087 * @param fbins_mask
1198 * @param fbins_mask
1088 * @param rw_f is the reaction wheel frequency to filter
1199 * @param rw_f is the reaction wheel frequency to filter
1089 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1200 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1090 * @param flag [true] filtering enabled [false] filtering disabled
1201 * @param flag [true] filtering enabled [false] filtering disabled
1091 *
1202 *
1092 * @return void
1203 * @return void
1093 *
1204 *
1094 */
1205 */
1095
1206
1096 float f_RW_min;
1207 float f_RW_min;
1097 float f_RW_MAX;
1208 float f_RW_MAX;
1098 float fi_min;
1209 float fi_min;
1099 float fi_MAX;
1210 float fi_MAX;
1100 float fi;
1211 float fi;
1101 float deltaBelow;
1212 float deltaBelow;
1102 float deltaAbove;
1213 float deltaAbove;
1103 float freqToFilterOut;
1214 float freqToFilterOut;
1104 int binBelow;
1215 int binBelow;
1105 int binAbove;
1216 int binAbove;
1106 int closestBin;
1217 int closestBin;
1107 unsigned int whichByte;
1218 unsigned int whichByte;
1108 int selectedByte;
1219 int selectedByte;
1109 int bin;
1220 int bin;
1110 int binToRemove[NB_BINS_TO_REMOVE];
1221 int binToRemove[NB_BINS_TO_REMOVE];
1111 int k;
1222 int k;
1112 bool filteringSet;
1223 bool filteringSet;
1113
1224
1114 closestBin = 0;
1225 closestBin = 0;
1115 whichByte = 0;
1226 whichByte = 0;
1116 bin = 0;
1227 bin = 0;
1117 filteringSet = false;
1228 filteringSet = false;
1118
1229
1119 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1230 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1120 {
1231 {
1121 binToRemove[k] = -1;
1232 binToRemove[k] = -1;
1122 }
1233 }
1123
1234
1124 if (!isnan(rw_f))
1235 if (!isnan(rw_f))
1125 {
1236 {
1126 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1237 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1127 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1238 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1128 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1239 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1129
1240
1130 freqToFilterOut = f_RW_min;
1241 freqToFilterOut = f_RW_min;
1131 while ( filteringSet == false )
1242 while ( filteringSet == false )
1132 {
1243 {
1133 // compute the index of the frequency bin immediately below rw_f
1244 // compute the index of the frequency bin immediately below rw_f
1134 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1245 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1135 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1246 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1136
1247
1137 // compute the index of the frequency bin immediately above rw_f
1248 // compute the index of the frequency bin immediately above rw_f
1138 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1249 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1139 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1250 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1140
1251
1141 // search the closest bin
1252 // search the closest bin
1142 if (deltaAbove > deltaBelow)
1253 if (deltaAbove > deltaBelow)
1143 {
1254 {
1144 closestBin = binBelow;
1255 closestBin = binBelow;
1145 }
1256 }
1146 else
1257 else
1147 {
1258 {
1148 closestBin = binAbove;
1259 closestBin = binAbove;
1149 }
1260 }
1150
1261
1151 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1262 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1152 fi = closestBin * deltaFreq;
1263 fi = closestBin * deltaFreq;
1153 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1264 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1154 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1265 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1155
1266
1156 //**************************************************************************************
1267 //**************************************************************************************
1157 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1268 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1158 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1269 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1159 //**************************************************************************************
1270 //**************************************************************************************
1160
1271
1161 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1272 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1162 // => remove f_(i), f_(i-1) and f_(i+1)
1273 // => remove f_(i), f_(i-1) and f_(i+1)
1163 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1274 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1164 {
1275 {
1165 binToRemove[0] = (closestBin - 1) - 1;
1276 binToRemove[0] = (closestBin - 1) - 1;
1166 binToRemove[1] = (closestBin) - 1;
1277 binToRemove[1] = (closestBin) - 1;
1167 binToRemove[2] = (closestBin + 1) - 1;
1278 binToRemove[2] = (closestBin + 1) - 1;
1168 }
1279 }
1169 // 2. ELSE
1280 // 2. ELSE
1170 // => remove the two f_(i) which are around f_RW
1281 // => remove the two f_(i) which are around f_RW
1171 else
1282 else
1172 {
1283 {
1173 binToRemove[0] = (binBelow) - 1;
1284 binToRemove[0] = (binBelow) - 1;
1174 binToRemove[1] = (binAbove) - 1;
1285 binToRemove[1] = (binAbove) - 1;
1175 binToRemove[2] = (-1);
1286 binToRemove[2] = (-1);
1176 }
1287 }
1177
1288
1178 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1289 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1179 {
1290 {
1180 bin = binToRemove[k];
1291 bin = binToRemove[k];
1181 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1292 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1182 {
1293 {
1183 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1294 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1184 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1295 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1185 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1296 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1186 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1297 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1187
1298
1188 }
1299 }
1189 }
1300 }
1190
1301
1191 // update freqToFilterOut
1302 // update freqToFilterOut
1192 if ( freqToFilterOut == f_RW_MAX )
1303 if ( freqToFilterOut == f_RW_MAX )
1193 {
1304 {
1194 filteringSet = true; // end of the loop
1305 filteringSet = true; // end of the loop
1195 }
1306 }
1196 else
1307 else
1197 {
1308 {
1198 freqToFilterOut = freqToFilterOut + deltaFreq;
1309 freqToFilterOut = freqToFilterOut + deltaFreq;
1199 }
1310 }
1200
1311
1201 if ( freqToFilterOut > f_RW_MAX)
1312 if ( freqToFilterOut > f_RW_MAX)
1202 {
1313 {
1203 freqToFilterOut = f_RW_MAX;
1314 freqToFilterOut = f_RW_MAX;
1204 }
1315 }
1205 }
1316 }
1206 }
1317 }
1207 }
1318 }
1208
1319
1209 void build_sy_lfr_rw_mask( unsigned int channel )
1320 void build_sy_lfr_rw_mask( unsigned int channel )
1210 {
1321 {
1211 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1322 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1212 unsigned char *maskPtr;
1323 unsigned char *maskPtr;
1213 double deltaF;
1324 double deltaF;
1214 unsigned k;
1325 unsigned k;
1215
1326
1216 maskPtr = NULL;
1327 maskPtr = NULL;
1217 deltaF = DELTAF_F2;
1328 deltaF = DELTAF_F2;
1218
1329
1219 switch (channel)
1330 switch (channel)
1220 {
1331 {
1221 case CHANNELF0:
1332 case CHANNELF0:
1222 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1333 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1223 deltaF = DELTAF_F0;
1334 deltaF = DELTAF_F0;
1224 break;
1335 break;
1225 case CHANNELF1:
1336 case CHANNELF1:
1226 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1337 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1227 deltaF = DELTAF_F1;
1338 deltaF = DELTAF_F1;
1228 break;
1339 break;
1229 case CHANNELF2:
1340 case CHANNELF2:
1230 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1341 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1231 deltaF = DELTAF_F2;
1342 deltaF = DELTAF_F2;
1232 break;
1343 break;
1233 default:
1344 default:
1234 break;
1345 break;
1235 }
1346 }
1236
1347
1237 for (k = 0; k < BYTES_PER_MASK; k++)
1348 for (k = 0; k < BYTES_PER_MASK; k++)
1238 {
1349 {
1239 local_rw_fbins_mask[k] = INT8_ALL_F;
1350 local_rw_fbins_mask[k] = INT8_ALL_F;
1240 }
1351 }
1241
1352
1242 // RW1
1353 // RW1
1243 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1354 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1244 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1355 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1245 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1356 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1246 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1357 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1247
1358
1248 // RW2
1359 // RW2
1249 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1360 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1250 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1361 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1251 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1362 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1252 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1363 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1253
1364
1254 // RW3
1365 // RW3
1255 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1366 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1256 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1367 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1257 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1368 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1258 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1369 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1259
1370
1260 // RW4
1371 // RW4
1261 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1372 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1262 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1373 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1263 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1374 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1264 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1375 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1265
1376
1266 // update the value of the fbins related to reaction wheels frequency filtering
1377 // update the value of the fbins related to reaction wheels frequency filtering
1267 if (maskPtr != NULL)
1378 if (maskPtr != NULL)
1268 {
1379 {
1269 for (k = 0; k < BYTES_PER_MASK; k++)
1380 for (k = 0; k < BYTES_PER_MASK; k++)
1270 {
1381 {
1271 maskPtr[k] = local_rw_fbins_mask[k];
1382 maskPtr[k] = local_rw_fbins_mask[k];
1272 }
1383 }
1273 }
1384 }
1274 }
1385 }
1275
1386
1276 void build_sy_lfr_rw_masks( void )
1387 void build_sy_lfr_rw_masks( void )
1277 {
1388 {
1278 build_sy_lfr_rw_mask( CHANNELF0 );
1389 build_sy_lfr_rw_mask( CHANNELF0 );
1279 build_sy_lfr_rw_mask( CHANNELF1 );
1390 build_sy_lfr_rw_mask( CHANNELF1 );
1280 build_sy_lfr_rw_mask( CHANNELF2 );
1391 build_sy_lfr_rw_mask( CHANNELF2 );
1281 }
1392 }
1282
1393
1283 void merge_fbins_masks( void )
1394 void merge_fbins_masks( void )
1284 {
1395 {
1285 unsigned char k;
1396 unsigned char k;
1286
1397
1287 unsigned char *fbins_f0;
1398 unsigned char *fbins_f0;
1288 unsigned char *fbins_f1;
1399 unsigned char *fbins_f1;
1289 unsigned char *fbins_f2;
1400 unsigned char *fbins_f2;
1290 unsigned char *rw_mask_f0;
1401 unsigned char *rw_mask_f0;
1291 unsigned char *rw_mask_f1;
1402 unsigned char *rw_mask_f1;
1292 unsigned char *rw_mask_f2;
1403 unsigned char *rw_mask_f2;
1293
1404
1294 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1405 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1295 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1406 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1296 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1407 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1297 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1408 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1298 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1409 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1299 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1410 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1300
1411
1301 for( k=0; k < BYTES_PER_MASK; k++ )
1412 for( k=0; k < BYTES_PER_MASK; k++ )
1302 {
1413 {
1303 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1414 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1304 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1415 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1305 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1416 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1306 }
1417 }
1307 }
1418 }
1308
1419
1309 //***********
1420 //***********
1310 // FBINS MASK
1421 // FBINS MASK
1311
1422
1312 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1423 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1313 {
1424 {
1314 int status;
1425 int status;
1315 unsigned int k;
1426 unsigned int k;
1316 unsigned char *fbins_mask_dump;
1427 unsigned char *fbins_mask_dump;
1317 unsigned char *fbins_mask_TC;
1428 unsigned char *fbins_mask_TC;
1318
1429
1319 status = LFR_SUCCESSFUL;
1430 status = LFR_SUCCESSFUL;
1320
1431
1321 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1432 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1322 fbins_mask_TC = TC->dataAndCRC;
1433 fbins_mask_TC = TC->dataAndCRC;
1323
1434
1324 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1435 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1325 {
1436 {
1326 fbins_mask_dump[k] = fbins_mask_TC[k];
1437 fbins_mask_dump[k] = fbins_mask_TC[k];
1327 }
1438 }
1328
1439
1329 return status;
1440 return status;
1330 }
1441 }
1331
1442
1332 //***************************
1443 //***************************
1333 // TC_LFR_LOAD_PAS_FILTER_PAR
1444 // TC_LFR_LOAD_PAS_FILTER_PAR
1334
1445
1335 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1446 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1336 {
1447 {
1337 float rw_k;
1448 float rw_k;
1338 int ret;
1449 int ret;
1339
1450
1340 ret = LFR_SUCCESSFUL;
1451 ret = LFR_SUCCESSFUL;
1341 rw_k = INIT_FLOAT;
1452 rw_k = INIT_FLOAT;
1342
1453
1343 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1454 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1344
1455
1345 *pos = offset;
1456 *pos = offset;
1346 *value = rw_k;
1457 *value = rw_k;
1347
1458
1348 if (rw_k < MIN_SY_LFR_RW_K)
1459 if (rw_k < MIN_SY_LFR_RW_F)
1349 {
1460 {
1350 ret = WRONG_APP_DATA;
1461 ret = WRONG_APP_DATA;
1351 }
1462 }
1352
1463
1353 return ret;
1464 return ret;
1354 }
1465 }
1355
1466
1356 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1467 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float *value )
1357 {
1468 {
1358 int ret;
1469 int ret;
1359
1470
1360 ret = LFR_SUCCESSFUL;
1471 ret = LFR_SUCCESSFUL;
1361
1472
1362 //****
1473 //****
1363 //****
1474 //****
1364 // RW1
1475 // RW1
1365 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1476 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1366 if (ret == LFR_SUCCESSFUL) // K2
1477 if (ret == LFR_SUCCESSFUL) // K2
1367 {
1478 {
1368 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1479 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1369 }
1480 }
1370 if (ret == LFR_SUCCESSFUL) // K3
1481 if (ret == LFR_SUCCESSFUL) // K3
1371 {
1482 {
1372 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1483 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1373 }
1484 }
1374 if (ret == LFR_SUCCESSFUL) // K4
1485 if (ret == LFR_SUCCESSFUL) // K4
1375 {
1486 {
1376 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1487 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1377 }
1488 }
1378
1489
1379 //****
1490 //****
1380 //****
1491 //****
1381 // RW2
1492 // RW2
1382 if (ret == LFR_SUCCESSFUL) // K1
1493 if (ret == LFR_SUCCESSFUL) // K1
1383 {
1494 {
1384 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1495 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1385 }
1496 }
1386 if (ret == LFR_SUCCESSFUL) // K2
1497 if (ret == LFR_SUCCESSFUL) // K2
1387 {
1498 {
1388 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1499 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1389 }
1500 }
1390 if (ret == LFR_SUCCESSFUL) // K3
1501 if (ret == LFR_SUCCESSFUL) // K3
1391 {
1502 {
1392 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1503 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1393 }
1504 }
1394 if (ret == LFR_SUCCESSFUL) // K4
1505 if (ret == LFR_SUCCESSFUL) // K4
1395 {
1506 {
1396 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1507 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1397 }
1508 }
1398
1509
1399 //****
1510 //****
1400 //****
1511 //****
1401 // RW3
1512 // RW3
1402 if (ret == LFR_SUCCESSFUL) // K1
1513 if (ret == LFR_SUCCESSFUL) // K1
1403 {
1514 {
1404 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1515 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1405 }
1516 }
1406 if (ret == LFR_SUCCESSFUL) // K2
1517 if (ret == LFR_SUCCESSFUL) // K2
1407 {
1518 {
1408 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1519 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1409 }
1520 }
1410 if (ret == LFR_SUCCESSFUL) // K3
1521 if (ret == LFR_SUCCESSFUL) // K3
1411 {
1522 {
1412 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1523 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1413 }
1524 }
1414 if (ret == LFR_SUCCESSFUL) // K4
1525 if (ret == LFR_SUCCESSFUL) // K4
1415 {
1526 {
1416 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1527 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1417 }
1528 }
1418
1529
1419 //****
1530 //****
1420 //****
1531 //****
1421 // RW4
1532 // RW4
1422 if (ret == LFR_SUCCESSFUL) // K1
1533 if (ret == LFR_SUCCESSFUL) // K1
1423 {
1534 {
1424 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1535 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1425 }
1536 }
1426 if (ret == LFR_SUCCESSFUL) // K2
1537 if (ret == LFR_SUCCESSFUL) // K2
1427 {
1538 {
1428 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1539 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1429 }
1540 }
1430 if (ret == LFR_SUCCESSFUL) // K3
1541 if (ret == LFR_SUCCESSFUL) // K3
1431 {
1542 {
1432 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1543 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1433 }
1544 }
1434 if (ret == LFR_SUCCESSFUL) // K4
1545 if (ret == LFR_SUCCESSFUL) // K4
1435 {
1546 {
1436 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1547 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1437 }
1548 }
1438
1549
1439
1440
1441 return ret;
1550 return ret;
1442 }
1551 }
1443
1552
1444 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1553 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1445 {
1554 {
1446 int flag;
1555 int flag;
1447 rtems_status_code status;
1556 rtems_status_code status;
1448
1557
1449 unsigned char sy_lfr_pas_filter_enabled;
1558 unsigned char sy_lfr_pas_filter_enabled;
1450 unsigned char sy_lfr_pas_filter_modulus;
1559 unsigned char sy_lfr_pas_filter_modulus;
1451 float sy_lfr_pas_filter_tbad;
1560 float sy_lfr_pas_filter_tbad;
1452 unsigned char sy_lfr_pas_filter_offset;
1561 unsigned char sy_lfr_pas_filter_offset;
1453 float sy_lfr_pas_filter_shift;
1562 float sy_lfr_pas_filter_shift;
1454 float sy_lfr_sc_rw_delta_f;
1563 float sy_lfr_sc_rw_delta_f;
1455 char *parPtr;
1564 char *parPtr;
1456 int *datafield_pos;
1565 int datafield_pos;
1457 float *rw_k;
1566 float rw_k;
1458
1567
1459 flag = LFR_SUCCESSFUL;
1568 flag = LFR_SUCCESSFUL;
1460 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1569 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1461 sy_lfr_pas_filter_shift = INIT_FLOAT;
1570 sy_lfr_pas_filter_shift = INIT_FLOAT;
1462 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1571 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1463 parPtr = NULL;
1572 parPtr = NULL;
1464 datafield_pos = NULL;
1573 datafield_pos = INIT_INT;
1465 rw_k = NULL;
1574 rw_k = INIT_FLOAT;
1466
1467 *datafield_pos = LFR_DEFAULT_ALT;
1468 *rw_k = INIT_FLOAT;
1469
1575
1470 //***************
1576 //***************
1471 // get parameters
1577 // get parameters
1472 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1578 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1473 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1579 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1474 copyFloatByChar(
1580 copyFloatByChar(
1475 (unsigned char*) &sy_lfr_pas_filter_tbad,
1581 (unsigned char*) &sy_lfr_pas_filter_tbad,
1476 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1582 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1477 );
1583 );
1478 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1584 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1479 copyFloatByChar(
1585 copyFloatByChar(
1480 (unsigned char*) &sy_lfr_pas_filter_shift,
1586 (unsigned char*) &sy_lfr_pas_filter_shift,
1481 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1587 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1482 );
1588 );
1483 copyFloatByChar(
1589 copyFloatByChar(
1484 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1590 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1485 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1591 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1486 );
1592 );
1487
1593
1488 //******************
1594 //******************
1489 // CHECK CONSISTENCY
1595 // CHECK CONSISTENCY
1490
1596
1491 //**************************
1597 //**************************
1492 // sy_lfr_pas_filter_enabled
1598 // sy_lfr_pas_filter_enabled
1493 // nothing to check, value is 0 or 1
1599 // nothing to check, value is 0 or 1
1494
1600
1495 //**************************
1601 //**************************
1496 // sy_lfr_pas_filter_modulus
1602 // sy_lfr_pas_filter_modulus
1497 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1603 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1498 {
1604 {
1499 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1605 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1500 flag = WRONG_APP_DATA;
1606 flag = WRONG_APP_DATA;
1501 }
1607 }
1502
1608
1503 //***********************
1609 //***********************
1504 // sy_lfr_pas_filter_tbad
1610 // sy_lfr_pas_filter_tbad
1505 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1611 if (flag == LFR_SUCCESSFUL)
1506 {
1612 {
1507 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1613 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1508 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1614 {
1509 flag = WRONG_APP_DATA;
1615 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1616 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1617 flag = WRONG_APP_DATA;
1618 }
1510 }
1619 }
1511
1620
1512 //*************************
1621 //*************************
1513 // sy_lfr_pas_filter_offset
1622 // sy_lfr_pas_filter_offset
1514 if (flag == LFR_SUCCESSFUL)
1623 if (flag == LFR_SUCCESSFUL)
1515 {
1624 {
1516 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1625 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1517 {
1626 {
1518 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1519 flag = WRONG_APP_DATA;
1628 flag = WRONG_APP_DATA;
1520 }
1629 }
1521 }
1630 }
1522
1631
1523 //************************
1632 //************************
1524 // sy_lfr_pas_filter_shift
1633 // sy_lfr_pas_filter_shift
1525 if (flag == LFR_SUCCESSFUL)
1634 if (flag == LFR_SUCCESSFUL)
1526 {
1635 {
1527 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1636 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1528 {
1637 {
1529 parPtr = (char*) &sy_lfr_pas_filter_shift;
1638 parPtr = (char*) &sy_lfr_pas_filter_shift;
1530 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1639 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1531 flag = WRONG_APP_DATA;
1640 flag = WRONG_APP_DATA;
1532 }
1641 }
1533 }
1642 }
1534
1643
1535 //*************************************
1644 //*************************************
1536 // check global coherency of the values
1645 // check global coherency of the values
1537 if (flag == LFR_SUCCESSFUL)
1646 if (flag == LFR_SUCCESSFUL)
1538 {
1647 {
1539 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1648 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1540 {
1649 {
1541 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1650 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1542 flag = WRONG_APP_DATA;
1651 flag = WRONG_APP_DATA;
1543 }
1652 }
1544 }
1653 }
1545
1654
1546 //*********************
1655 //*********************
1547 // sy_lfr_sc_rw_delta_f
1656 // sy_lfr_sc_rw_delta_f
1548 if (flag == LFR_SUCCESSFUL)
1657 if (flag == LFR_SUCCESSFUL)
1549 {
1658 {
1550 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1659 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1551 {
1660 {
1661 parPtr = (char*) &sy_lfr_pas_filter_shift;
1552 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, sy_lfr_sc_rw_delta_f );
1662 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, sy_lfr_sc_rw_delta_f );
1553 flag = WRONG_APP_DATA;
1663 flag = WRONG_APP_DATA;
1554 }
1664 }
1555 }
1665 }
1556
1666
1557 //************
1667 //************
1558 // sy_lfr_rw_k
1668 // sy_lfr_rw_k
1559 if (flag == LFR_SUCCESSFUL)
1669 if (flag == LFR_SUCCESSFUL)
1560 {
1670 {
1561 flag = check_all_sy_lfr_rw_k( TC, datafield_pos, rw_k );
1671 flag = check_all_sy_lfr_rw_k( TC, &datafield_pos, &rw_k );
1562 if (flag != LFR_SUCCESSFUL)
1672 if (flag != LFR_SUCCESSFUL)
1563 {
1673 {
1564 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, *datafield_pos + DATAFIELD_OFFSET, *rw_k );
1674 parPtr = (char*) &sy_lfr_pas_filter_shift;
1675 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, datafield_pos + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1565 }
1676 }
1566 }
1677 }
1567
1678
1568
1569 return flag;
1679 return flag;
1570 }
1680 }
1571
1681
1572 //**************
1682 //**************
1573 // KCOEFFICIENTS
1683 // KCOEFFICIENTS
1574 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1684 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1575 {
1685 {
1576 unsigned int kcoeff;
1686 unsigned int kcoeff;
1577 unsigned short sy_lfr_kcoeff_frequency;
1687 unsigned short sy_lfr_kcoeff_frequency;
1578 unsigned short bin;
1688 unsigned short bin;
1579 float *kcoeffPtr_norm;
1689 float *kcoeffPtr_norm;
1580 float *kcoeffPtr_sbm;
1690 float *kcoeffPtr_sbm;
1581 int status;
1691 int status;
1582 unsigned char *kcoeffLoadPtr;
1692 unsigned char *kcoeffLoadPtr;
1583 unsigned char *kcoeffNormPtr;
1693 unsigned char *kcoeffNormPtr;
1584 unsigned char *kcoeffSbmPtr_a;
1694 unsigned char *kcoeffSbmPtr_a;
1585 unsigned char *kcoeffSbmPtr_b;
1695 unsigned char *kcoeffSbmPtr_b;
1586
1696
1587 sy_lfr_kcoeff_frequency = 0;
1697 sy_lfr_kcoeff_frequency = 0;
1588 bin = 0;
1698 bin = 0;
1589 kcoeffPtr_norm = NULL;
1699 kcoeffPtr_norm = NULL;
1590 kcoeffPtr_sbm = NULL;
1700 kcoeffPtr_sbm = NULL;
1591 status = LFR_SUCCESSFUL;
1701 status = LFR_SUCCESSFUL;
1592
1702
1593 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1703 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1594 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1704 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1595
1705
1596
1706
1597 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1707 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1598 {
1708 {
1599 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1709 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1600 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1710 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1601 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1711 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1602 status = LFR_DEFAULT;
1712 status = LFR_DEFAULT;
1603 }
1713 }
1604 else
1714 else
1605 {
1715 {
1606 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1716 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1607 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1717 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1608 {
1718 {
1609 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1719 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1610 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1720 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1611 bin = sy_lfr_kcoeff_frequency;
1721 bin = sy_lfr_kcoeff_frequency;
1612 }
1722 }
1613 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1723 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1614 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1724 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1615 {
1725 {
1616 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1726 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1617 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1727 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1618 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1728 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1619 }
1729 }
1620 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1730 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1621 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1731 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1622 {
1732 {
1623 kcoeffPtr_norm = k_coeff_intercalib_f2;
1733 kcoeffPtr_norm = k_coeff_intercalib_f2;
1624 kcoeffPtr_sbm = NULL;
1734 kcoeffPtr_sbm = NULL;
1625 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1735 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1626 }
1736 }
1627 }
1737 }
1628
1738
1629 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1739 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1630 {
1740 {
1631 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1741 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1632 {
1742 {
1633 // destination
1743 // destination
1634 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1744 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1635 // source
1745 // source
1636 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1746 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1637 // copy source to destination
1747 // copy source to destination
1638 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1748 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1639 }
1749 }
1640 }
1750 }
1641
1751
1642 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1752 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1643 {
1753 {
1644 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1754 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1645 {
1755 {
1646 // destination
1756 // destination
1647 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1757 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1648 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1758 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1649 // source
1759 // source
1650 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1760 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1651 // copy source to destination
1761 // copy source to destination
1652 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1762 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1653 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1763 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1654 }
1764 }
1655 }
1765 }
1656
1766
1657 // print_k_coeff();
1767 // print_k_coeff();
1658
1768
1659 return status;
1769 return status;
1660 }
1770 }
1661
1771
1662 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1772 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1663 {
1773 {
1664 destination[BYTE_0] = source[BYTE_0];
1774 destination[BYTE_0] = source[BYTE_0];
1665 destination[BYTE_1] = source[BYTE_1];
1775 destination[BYTE_1] = source[BYTE_1];
1666 destination[BYTE_2] = source[BYTE_2];
1776 destination[BYTE_2] = source[BYTE_2];
1667 destination[BYTE_3] = source[BYTE_3];
1777 destination[BYTE_3] = source[BYTE_3];
1668 }
1778 }
1669
1779
1670 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1780 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1671 {
1781 {
1672 destination[BYTE_0] = source[BYTE_0];
1782 destination[BYTE_0] = source[BYTE_0];
1673 destination[BYTE_1] = source[BYTE_1];
1783 destination[BYTE_1] = source[BYTE_1];
1674 destination[BYTE_2] = source[BYTE_2];
1784 destination[BYTE_2] = source[BYTE_2];
1675 destination[BYTE_3] = source[BYTE_3];
1785 destination[BYTE_3] = source[BYTE_3];
1676 }
1786 }
1677
1787
1678 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1788 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1679 {
1789 {
1680 destination[BYTE_0] = source[BYTE_0];
1790 destination[BYTE_0] = source[BYTE_0];
1681 destination[BYTE_1] = source[BYTE_1];
1791 destination[BYTE_1] = source[BYTE_1];
1682 }
1792 }
1683
1793
1684 void floatToChar( float value, unsigned char* ptr)
1794 void floatToChar( float value, unsigned char* ptr)
1685 {
1795 {
1686 unsigned char* valuePtr;
1796 unsigned char* valuePtr;
1687
1797
1688 valuePtr = (unsigned char*) &value;
1798 valuePtr = (unsigned char*) &value;
1689
1799
1690 ptr[BYTE_0] = valuePtr[BYTE_0];
1800 ptr[BYTE_0] = valuePtr[BYTE_0];
1691 ptr[BYTE_1] = valuePtr[BYTE_1];
1801 ptr[BYTE_1] = valuePtr[BYTE_1];
1692 ptr[BYTE_2] = valuePtr[BYTE_2];
1802 ptr[BYTE_2] = valuePtr[BYTE_2];
1693 ptr[BYTE_3] = valuePtr[BYTE_3];
1803 ptr[BYTE_3] = valuePtr[BYTE_3];
1694 }
1804 }
1695
1805
1696 //**********
1806 //**********
1697 // init dump
1807 // init dump
1698
1808
1699 void init_parameter_dump( void )
1809 void init_parameter_dump( void )
1700 {
1810 {
1701 /** This function initialize the parameter_dump_packet global variable with default values.
1811 /** This function initialize the parameter_dump_packet global variable with default values.
1702 *
1812 *
1703 */
1813 */
1704
1814
1705 unsigned int k;
1815 unsigned int k;
1706
1816
1707 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1817 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1708 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1818 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1709 parameter_dump_packet.reserved = CCSDS_RESERVED;
1819 parameter_dump_packet.reserved = CCSDS_RESERVED;
1710 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1820 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1711 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1821 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1712 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1822 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1713 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1823 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1714 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1824 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1715 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1825 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1716 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1826 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1717 // DATA FIELD HEADER
1827 // DATA FIELD HEADER
1718 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1828 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1719 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1829 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1720 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1830 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1721 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1831 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1722 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1832 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1723 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1833 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1724 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1834 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1725 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1835 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1726 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1836 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1727 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1837 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1728 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1838 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1729
1839
1730 //******************
1840 //******************
1731 // COMMON PARAMETERS
1841 // COMMON PARAMETERS
1732 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1842 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1733 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1843 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1734
1844
1735 //******************
1845 //******************
1736 // NORMAL PARAMETERS
1846 // NORMAL PARAMETERS
1737 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1847 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1738 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1848 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1739 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1849 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1740 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1850 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1741 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1851 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1742 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1852 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1743 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1853 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1744 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1854 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1745 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1855 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1746
1856
1747 //*****************
1857 //*****************
1748 // BURST PARAMETERS
1858 // BURST PARAMETERS
1749 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1859 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1750 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1860 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1751
1861
1752 //****************
1862 //****************
1753 // SBM1 PARAMETERS
1863 // SBM1 PARAMETERS
1754 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
1864 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
1755 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1865 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1756
1866
1757 //****************
1867 //****************
1758 // SBM2 PARAMETERS
1868 // SBM2 PARAMETERS
1759 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1869 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1760 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1870 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1761
1871
1762 //************
1872 //************
1763 // FBINS MASKS
1873 // FBINS MASKS
1764 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1874 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1765 {
1875 {
1766 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1876 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1767 }
1877 }
1768
1878
1769 // PAS FILTER PARAMETERS
1879 // PAS FILTER PARAMETERS
1770 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1880 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1771 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1881 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1772 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1882 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1773 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1883 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1774 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1884 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1775 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1885 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1776 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1886 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1777
1887
1778 // RW1_K
1888 // RW1_K
1779 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1889 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1780 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1890 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1781 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1891 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1782 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1892 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1783 // RW2_K
1893 // RW2_K
1784 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1894 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1785 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1895 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1786 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1896 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1787 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1897 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1788 // RW3_K
1898 // RW3_K
1789 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1899 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1790 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1900 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1791 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1901 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1792 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1902 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1793 // RW4_K
1903 // RW4_K
1794 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1904 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1795 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1905 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1796 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1906 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1797 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1907 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1798
1908
1799 // LFR_RW_MASK
1909 // LFR_RW_MASK
1800 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1910 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1801 {
1911 {
1802 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1912 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1803 }
1913 }
1804
1914
1805 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1915 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1806 merge_fbins_masks();
1916 merge_fbins_masks();
1807 }
1917 }
1808
1918
1809 void init_kcoefficients_dump( void )
1919 void init_kcoefficients_dump( void )
1810 {
1920 {
1811 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1921 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1812 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1922 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1813
1923
1814 kcoefficient_node_1.previous = NULL;
1924 kcoefficient_node_1.previous = NULL;
1815 kcoefficient_node_1.next = NULL;
1925 kcoefficient_node_1.next = NULL;
1816 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1926 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1817 kcoefficient_node_1.coarseTime = INIT_CHAR;
1927 kcoefficient_node_1.coarseTime = INIT_CHAR;
1818 kcoefficient_node_1.fineTime = INIT_CHAR;
1928 kcoefficient_node_1.fineTime = INIT_CHAR;
1819 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1929 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1820 kcoefficient_node_1.status = INIT_CHAR;
1930 kcoefficient_node_1.status = INIT_CHAR;
1821
1931
1822 kcoefficient_node_2.previous = NULL;
1932 kcoefficient_node_2.previous = NULL;
1823 kcoefficient_node_2.next = NULL;
1933 kcoefficient_node_2.next = NULL;
1824 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1934 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1825 kcoefficient_node_2.coarseTime = INIT_CHAR;
1935 kcoefficient_node_2.coarseTime = INIT_CHAR;
1826 kcoefficient_node_2.fineTime = INIT_CHAR;
1936 kcoefficient_node_2.fineTime = INIT_CHAR;
1827 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1937 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1828 kcoefficient_node_2.status = INIT_CHAR;
1938 kcoefficient_node_2.status = INIT_CHAR;
1829 }
1939 }
1830
1940
1831 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1941 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1832 {
1942 {
1833 unsigned int k;
1943 unsigned int k;
1834 unsigned int packetLength;
1944 unsigned int packetLength;
1835
1945
1836 packetLength =
1946 packetLength =
1837 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1947 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1838
1948
1839 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1949 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1840 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1950 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1841 kcoefficients_dump->reserved = CCSDS_RESERVED;
1951 kcoefficients_dump->reserved = CCSDS_RESERVED;
1842 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1952 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1843 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1953 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1844 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1954 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1845 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1955 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1846 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1956 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1847 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1957 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1848 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1958 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1849 // DATA FIELD HEADER
1959 // DATA FIELD HEADER
1850 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1960 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1851 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1961 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1852 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1962 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1853 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1963 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1854 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1964 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1855 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1965 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1856 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1966 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1857 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1967 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1858 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1968 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1859 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1969 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1860 kcoefficients_dump->sid = SID_K_DUMP;
1970 kcoefficients_dump->sid = SID_K_DUMP;
1861
1971
1862 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1972 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1863 kcoefficients_dump->pkt_nr = PKTNR_1;
1973 kcoefficients_dump->pkt_nr = PKTNR_1;
1864 kcoefficients_dump->blk_nr = blk_nr;
1974 kcoefficients_dump->blk_nr = blk_nr;
1865
1975
1866 //******************
1976 //******************
1867 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1977 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1868 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1978 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1869 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1979 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1870 {
1980 {
1871 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1981 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1872 }
1982 }
1873 }
1983 }
1874
1984
1875 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1985 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1876 {
1986 {
1877 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1987 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1878 *
1988 *
1879 * @param packet_sequence_control points to the packet sequence control which will be incremented
1989 * @param packet_sequence_control points to the packet sequence control which will be incremented
1880 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1990 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1881 *
1991 *
1882 * If the destination ID is not known, a dedicated counter is incremented.
1992 * If the destination ID is not known, a dedicated counter is incremented.
1883 *
1993 *
1884 */
1994 */
1885
1995
1886 unsigned short sequence_cnt;
1996 unsigned short sequence_cnt;
1887 unsigned short segmentation_grouping_flag;
1997 unsigned short segmentation_grouping_flag;
1888 unsigned short new_packet_sequence_control;
1998 unsigned short new_packet_sequence_control;
1889 unsigned char i;
1999 unsigned char i;
1890
2000
1891 switch (destination_id)
2001 switch (destination_id)
1892 {
2002 {
1893 case SID_TC_GROUND:
2003 case SID_TC_GROUND:
1894 i = GROUND;
2004 i = GROUND;
1895 break;
2005 break;
1896 case SID_TC_MISSION_TIMELINE:
2006 case SID_TC_MISSION_TIMELINE:
1897 i = MISSION_TIMELINE;
2007 i = MISSION_TIMELINE;
1898 break;
2008 break;
1899 case SID_TC_TC_SEQUENCES:
2009 case SID_TC_TC_SEQUENCES:
1900 i = TC_SEQUENCES;
2010 i = TC_SEQUENCES;
1901 break;
2011 break;
1902 case SID_TC_RECOVERY_ACTION_CMD:
2012 case SID_TC_RECOVERY_ACTION_CMD:
1903 i = RECOVERY_ACTION_CMD;
2013 i = RECOVERY_ACTION_CMD;
1904 break;
2014 break;
1905 case SID_TC_BACKUP_MISSION_TIMELINE:
2015 case SID_TC_BACKUP_MISSION_TIMELINE:
1906 i = BACKUP_MISSION_TIMELINE;
2016 i = BACKUP_MISSION_TIMELINE;
1907 break;
2017 break;
1908 case SID_TC_DIRECT_CMD:
2018 case SID_TC_DIRECT_CMD:
1909 i = DIRECT_CMD;
2019 i = DIRECT_CMD;
1910 break;
2020 break;
1911 case SID_TC_SPARE_GRD_SRC1:
2021 case SID_TC_SPARE_GRD_SRC1:
1912 i = SPARE_GRD_SRC1;
2022 i = SPARE_GRD_SRC1;
1913 break;
2023 break;
1914 case SID_TC_SPARE_GRD_SRC2:
2024 case SID_TC_SPARE_GRD_SRC2:
1915 i = SPARE_GRD_SRC2;
2025 i = SPARE_GRD_SRC2;
1916 break;
2026 break;
1917 case SID_TC_OBCP:
2027 case SID_TC_OBCP:
1918 i = OBCP;
2028 i = OBCP;
1919 break;
2029 break;
1920 case SID_TC_SYSTEM_CONTROL:
2030 case SID_TC_SYSTEM_CONTROL:
1921 i = SYSTEM_CONTROL;
2031 i = SYSTEM_CONTROL;
1922 break;
2032 break;
1923 case SID_TC_AOCS:
2033 case SID_TC_AOCS:
1924 i = AOCS;
2034 i = AOCS;
1925 break;
2035 break;
1926 case SID_TC_RPW_INTERNAL:
2036 case SID_TC_RPW_INTERNAL:
1927 i = RPW_INTERNAL;
2037 i = RPW_INTERNAL;
1928 break;
2038 break;
1929 default:
2039 default:
1930 i = GROUND;
2040 i = GROUND;
1931 break;
2041 break;
1932 }
2042 }
1933
2043
1934 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
2044 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1935 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
2045 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1936
2046
1937 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
2047 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1938
2048
1939 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
2049 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1940 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
2050 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1941
2051
1942 // increment the sequence counter
2052 // increment the sequence counter
1943 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
2053 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1944 {
2054 {
1945 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
2055 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1946 }
2056 }
1947 else
2057 else
1948 {
2058 {
1949 sequenceCounters_TM_DUMP[ i ] = 0;
2059 sequenceCounters_TM_DUMP[ i ] = 0;
1950 }
2060 }
1951 }
2061 }
General Comments 0
You need to be logged in to leave comments. Login now