##// END OF EJS Templates
enum transition_type_t removed
paul -
r245:7b784bd3b88b R3a
parent child
Show More
@@ -1,81 +1,80
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 #include "lfr_cpu_usage_report.h"
14 14
15 15 extern unsigned int lastValidEnterModeTime;
16 extern enum lfr_transition_type_t lfrTransitionType;
17 16
18 17 //****
19 18 // ISR
20 19 rtems_isr commutation_isr1( rtems_vector_number vector );
21 20 rtems_isr commutation_isr2( rtems_vector_number vector );
22 21
23 22 //***********
24 23 // RTEMS TASK
25 24 rtems_task actn_task( rtems_task_argument unused );
26 25
27 26 //***********
28 27 // TC ACTIONS
29 28 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 29 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
31 30 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
32 31 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
33 32 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
34 33 int action_update_time( ccsdsTelecommandPacket_t *TC);
35 34
36 35 // mode transition
37 36 int check_mode_value( unsigned char requestedMode );
38 37 int check_mode_transition( unsigned char requestedMode );
39 38 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
40 39 int check_transition_date( unsigned int transitionCoarseTime );
41 40 int stop_spectral_matrices( void );
42 41 int stop_current_mode( void );
43 42 int enter_mode_standby( void );
44 43 int enter_mode_normal( unsigned int transitionCoarseTime );
45 44 int enter_mode_burst( unsigned int transitionCoarseTime );
46 45 int enter_mode_sbm1( unsigned int transitionCoarseTime );
47 46 int enter_mode_sbm2( unsigned int transitionCoarseTime );
48 47 int restart_science_tasks( unsigned char lfrRequestedMode );
49 48 int restart_asm_tasks(unsigned char lfrRequestedMode );
50 49 int suspend_science_tasks(void);
51 50 int suspend_asm_tasks( void );
52 51 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
53 52 void launch_spectral_matrix( void );
54 53 void set_sm_irq_onNewMatrix( unsigned char value );
55 54 void set_sm_irq_onError( unsigned char value );
56 55
57 56 // other functions
58 57 void updateLFRCurrentMode();
59 58 void set_lfr_soft_reset( unsigned char value );
60 59 void reset_lfr( void );
61 60 // CALIBRATION
62 61 void setCalibrationPrescaler( unsigned int prescaler );
63 62 void setCalibrationDivisor( unsigned int divisionFactor );
64 63 void setCalibrationData( void );
65 64 void setCalibrationReload( bool state);
66 65 void setCalibrationEnable( bool state );
67 66 void setCalibrationInterleaved( bool state );
68 67 void setCalibration( bool state );
69 68 void configureCalibration( bool interleaved );
70 69 //
71 70 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
72 71 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
73 72 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
74 73
75 74 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
76 75 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
77 76
78 77 #endif // TC_HANDLER_H_INCLUDED
79 78
80 79
81 80
@@ -1,81 +1,80
1 1 /** Global variables of the LFR flight software.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * Among global variables, there are:
7 7 * - RTEMS names and id.
8 8 * - APB configuration registers.
9 9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 10 * - spectral matrices buffesr, used by the hardware module to store data.
11 11 * - variable related to LFR modes parameters.
12 12 * - the global HK packet buffer.
13 13 * - the global dump parameter buffer.
14 14 *
15 15 */
16 16
17 17 #include <rtems.h>
18 18 #include <grspw.h>
19 19
20 20 #include "ccsds_types.h"
21 21 #include "grlib_regs.h"
22 22 #include "fsw_params.h"
23 23 #include "fsw_params_wf_handler.h"
24 24
25 25 // RTEMS GLOBAL VARIABLES
26 26 rtems_name misc_name[5];
27 27 rtems_name Task_name[20]; /* array of task names */
28 28 rtems_id Task_id[20]; /* array of task ids */
29 29 int fdSPW = 0;
30 30 int fdUART = 0;
31 31 unsigned char lfrCurrentMode;
32 32 unsigned char pa_bia_status_info;
33 33
34 34 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
35 35 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
36 36 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
37 37 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
38 38 // F0 F1 F2 F3
39 39 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
40 40 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 41 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 42 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 43
44 44 //***********************************
45 45 // SPECTRAL MATRICES GLOBAL VARIABLES
46 46
47 47 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
48 48 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
49 49 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
50 50 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
51 51
52 52 // APB CONFIGURATION REGISTERS
53 53 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
54 54 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
55 55 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
56 56 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
57 57
58 58 // MODE PARAMETERS
59 59 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
60 60 struct param_local_str param_local;
61 61 unsigned int lastValidEnterModeTime;
62 enum lfr_transition_type_t lfrTransitionType;
63 62
64 63 // HK PACKETS
65 64 Packet_TM_LFR_HK_t housekeeping_packet;
66 65 // message queues occupancy
67 66 unsigned char hk_lfr_q_sd_fifo_size_max;
68 67 unsigned char hk_lfr_q_rv_fifo_size_max;
69 68 unsigned char hk_lfr_q_p0_fifo_size_max;
70 69 unsigned char hk_lfr_q_p1_fifo_size_max;
71 70 unsigned char hk_lfr_q_p2_fifo_size_max;
72 71 // sequence counters are incremented by APID (PID + CAT) and destination ID
73 72 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
74 73 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
75 74 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
76 75 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
77 76 unsigned short sequenceCounterHK;
78 77 spw_stats spacewire_stats;
79 78 spw_stats spacewire_stats_backup;
80 79
81 80
@@ -1,1618 +1,1604
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14 #include "math.h"
15 15
16 16 //***********
17 17 // RTEMS TASK
18 18
19 19 rtems_task actn_task( rtems_task_argument unused )
20 20 {
21 21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 22 *
23 23 * @param unused is the starting argument of the RTEMS task
24 24 *
25 25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 26 * on the incoming TeleCommand.
27 27 *
28 28 */
29 29
30 30 int result;
31 31 rtems_status_code status; // RTEMS status code
32 32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 33 size_t size; // size of the incoming TC packet
34 34 unsigned char subtype; // subtype of the current TC packet
35 35 unsigned char time[6];
36 36 rtems_id queue_rcv_id;
37 37 rtems_id queue_snd_id;
38 38
39 39 status = get_message_queue_id_recv( &queue_rcv_id );
40 40 if (status != RTEMS_SUCCESSFUL)
41 41 {
42 42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
43 43 }
44 44
45 45 status = get_message_queue_id_send( &queue_snd_id );
46 46 if (status != RTEMS_SUCCESSFUL)
47 47 {
48 48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
49 49 }
50 50
51 51 result = LFR_SUCCESSFUL;
52 52 subtype = 0; // subtype of the current TC packet
53 53
54 54 BOOT_PRINTF("in ACTN *** \n")
55 55
56 56 while(1)
57 57 {
58 58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 60 getTime( time ); // set time to the current time
61 61 if (status!=RTEMS_SUCCESSFUL)
62 62 {
63 63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
64 64 }
65 65 else
66 66 {
67 67 subtype = TC.serviceSubType;
68 68 switch(subtype)
69 69 {
70 70 case TC_SUBTYPE_RESET:
71 71 result = action_reset( &TC, queue_snd_id, time );
72 72 close_action( &TC, result, queue_snd_id );
73 73 break;
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id );
77 77 break;
78 78 case TC_SUBTYPE_LOAD_NORM:
79 79 result = action_load_normal_par( &TC, queue_snd_id, time );
80 80 close_action( &TC, result, queue_snd_id );
81 81 break;
82 82 case TC_SUBTYPE_LOAD_BURST:
83 83 result = action_load_burst_par( &TC, queue_snd_id, time );
84 84 close_action( &TC, result, queue_snd_id );
85 85 break;
86 86 case TC_SUBTYPE_LOAD_SBM1:
87 87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 88 close_action( &TC, result, queue_snd_id );
89 89 break;
90 90 case TC_SUBTYPE_LOAD_SBM2:
91 91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 92 close_action( &TC, result, queue_snd_id );
93 93 break;
94 94 case TC_SUBTYPE_DUMP:
95 95 result = action_dump_par( &TC, queue_snd_id );
96 96 close_action( &TC, result, queue_snd_id );
97 97 break;
98 98 case TC_SUBTYPE_ENTER:
99 99 result = action_enter_mode( &TC, queue_snd_id );
100 100 close_action( &TC, result, queue_snd_id );
101 101 break;
102 102 case TC_SUBTYPE_UPDT_INFO:
103 103 result = action_update_info( &TC, queue_snd_id );
104 104 close_action( &TC, result, queue_snd_id );
105 105 break;
106 106 case TC_SUBTYPE_EN_CAL:
107 107 result = action_enable_calibration( &TC, queue_snd_id, time );
108 108 close_action( &TC, result, queue_snd_id );
109 109 break;
110 110 case TC_SUBTYPE_DIS_CAL:
111 111 result = action_disable_calibration( &TC, queue_snd_id, time );
112 112 close_action( &TC, result, queue_snd_id );
113 113 break;
114 114 case TC_SUBTYPE_LOAD_K:
115 115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
116 116 close_action( &TC, result, queue_snd_id );
117 117 break;
118 118 case TC_SUBTYPE_DUMP_K:
119 119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
120 120 close_action( &TC, result, queue_snd_id );
121 121 break;
122 122 case TC_SUBTYPE_LOAD_FBINS:
123 123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
124 124 close_action( &TC, result, queue_snd_id );
125 125 break;
126 126 case TC_SUBTYPE_UPDT_TIME:
127 127 result = action_update_time( &TC );
128 128 close_action( &TC, result, queue_snd_id );
129 129 break;
130 130 default:
131 131 break;
132 132 }
133 133 }
134 134 }
135 135 }
136 136
137 137 //***********
138 138 // TC ACTIONS
139 139
140 140 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
141 141 {
142 142 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
143 143 *
144 144 * @param TC points to the TeleCommand packet that is being processed
145 145 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
146 146 *
147 147 */
148 148
149 149 PRINTF("this is the end!!!\n")
150 150 exit(0);
151 151 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
152 152 return LFR_DEFAULT;
153 153 }
154 154
155 155 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
156 156 {
157 157 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
158 158 *
159 159 * @param TC points to the TeleCommand packet that is being processed
160 160 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
161 161 *
162 162 */
163 163
164 164 rtems_status_code status;
165 165 unsigned char requestedMode;
166 166 unsigned int *transitionCoarseTime_ptr;
167 167 unsigned int transitionCoarseTime;
168 168 unsigned char * bytePosPtr;
169 169
170 170 bytePosPtr = (unsigned char *) &TC->packetID;
171 171
172 172 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
173 173 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
174 174 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
175 175
176 176 status = check_mode_value( requestedMode );
177 177
178 178 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
179 179 {
180 180 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
181 181 }
182 182
183 183 else // the mode value is valid, check the transition
184 184 {
185 185 status = check_mode_transition(requestedMode);
186 186 if (status != LFR_SUCCESSFUL)
187 187 {
188 188 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 189 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 190 }
191 191 }
192 192
193 193 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
194 194 {
195 195 status = check_transition_date( transitionCoarseTime );
196 196 if (status != LFR_SUCCESSFUL)
197 197 {
198 198 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
199 199 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
200 200 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
201 201 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
202 202 }
203 203 }
204 204
205 205 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
206 206 {
207 207 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
208 208
209 209 update_last_valid_transition_date( transitionCoarseTime );
210 210
211 211 switch(requestedMode)
212 212 {
213 213 case LFR_MODE_STANDBY:
214 214 status = enter_mode_standby();
215 215 break;
216 216 case LFR_MODE_NORMAL:
217 217 status = enter_mode_normal( transitionCoarseTime );
218 218 break;
219 219 case LFR_MODE_BURST:
220 220 status = enter_mode_burst( transitionCoarseTime );
221 221 break;
222 222 case LFR_MODE_SBM1:
223 223 status = enter_mode_sbm1( transitionCoarseTime );
224 224 break;
225 225 case LFR_MODE_SBM2:
226 226 status = enter_mode_sbm2( transitionCoarseTime );
227 227 break;
228 228 default:
229 229 break;
230 230 }
231 231 }
232 232
233 233 return status;
234 234 }
235 235
236 236 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
237 237 {
238 238 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
239 239 *
240 240 * @param TC points to the TeleCommand packet that is being processed
241 241 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
242 242 *
243 243 * @return LFR directive status code:
244 244 * - LFR_DEFAULT
245 245 * - LFR_SUCCESSFUL
246 246 *
247 247 */
248 248
249 249 unsigned int val;
250 250 int result;
251 251 unsigned int status;
252 252 unsigned char mode;
253 253 unsigned char * bytePosPtr;
254 254
255 255 bytePosPtr = (unsigned char *) &TC->packetID;
256 256
257 257 // check LFR mode
258 258 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
259 259 status = check_update_info_hk_lfr_mode( mode );
260 260 if (status == LFR_SUCCESSFUL) // check TDS mode
261 261 {
262 262 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
263 263 status = check_update_info_hk_tds_mode( mode );
264 264 }
265 265 if (status == LFR_SUCCESSFUL) // check THR mode
266 266 {
267 267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
268 268 status = check_update_info_hk_thr_mode( mode );
269 269 }
270 270 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
271 271 {
272 272 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
273 273 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
274 274 val++;
275 275 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
276 276 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
277 277 }
278 278
279 279 // pa_bia_status_info
280 280 // => pa_bia_mode_mux_set 3 bits
281 281 // => pa_bia_mode_hv_enabled 1 bit
282 282 // => pa_bia_mode_bias1_enabled 1 bit
283 283 // => pa_bia_mode_bias2_enabled 1 bit
284 284 // => pa_bia_mode_bias3_enabled 1 bit
285 285 // => pa_bia_on_off (cp_dpu_bias_on_off)
286 286 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110]
287 287 pa_bia_status_info = pa_bia_status_info
288 288 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1);
289 289
290 290 result = status;
291 291
292 292 return result;
293 293 }
294 294
295 295 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 296 {
297 297 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
298 298 *
299 299 * @param TC points to the TeleCommand packet that is being processed
300 300 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
301 301 *
302 302 */
303 303
304 304 int result;
305 305
306 306 result = LFR_DEFAULT;
307 307
308 308 setCalibration( true );
309 309
310 310 result = LFR_SUCCESSFUL;
311 311
312 312 return result;
313 313 }
314 314
315 315 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
316 316 {
317 317 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
318 318 *
319 319 * @param TC points to the TeleCommand packet that is being processed
320 320 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
321 321 *
322 322 */
323 323
324 324 int result;
325 325
326 326 result = LFR_DEFAULT;
327 327
328 328 setCalibration( false );
329 329
330 330 result = LFR_SUCCESSFUL;
331 331
332 332 return result;
333 333 }
334 334
335 335 int action_update_time(ccsdsTelecommandPacket_t *TC)
336 336 {
337 337 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
338 338 *
339 339 * @param TC points to the TeleCommand packet that is being processed
340 340 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
341 341 *
342 342 * @return LFR_SUCCESSFUL
343 343 *
344 344 */
345 345
346 346 unsigned int val;
347 347
348 348 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
349 349 + (TC->dataAndCRC[1] << 16)
350 350 + (TC->dataAndCRC[2] << 8)
351 351 + TC->dataAndCRC[3];
352 352
353 353 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
354 354 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
355 355 val++;
356 356 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
357 357 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
358 358
359 359 return LFR_SUCCESSFUL;
360 360 }
361 361
362 362 //*******************
363 363 // ENTERING THE MODES
364 364 int check_mode_value( unsigned char requestedMode )
365 365 {
366 366 int status;
367 367
368 368 if ( (requestedMode != LFR_MODE_STANDBY)
369 369 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
370 370 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
371 371 {
372 372 status = LFR_DEFAULT;
373 373 }
374 374 else
375 375 {
376 376 status = LFR_SUCCESSFUL;
377 377 }
378 378
379 379 return status;
380 380 }
381 381
382 382 int check_mode_transition( unsigned char requestedMode )
383 383 {
384 384 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
385 385 *
386 386 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
387 387 *
388 388 * @return LFR directive status codes:
389 389 * - LFR_SUCCESSFUL - the transition is authorized
390 390 * - LFR_DEFAULT - the transition is not authorized
391 391 *
392 392 */
393 393
394 394 int status;
395 395
396 396 switch (requestedMode)
397 397 {
398 398 case LFR_MODE_STANDBY:
399 399 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
400 400 status = LFR_DEFAULT;
401 401 }
402 402 else
403 403 {
404 404 status = LFR_SUCCESSFUL;
405 405 }
406 406 break;
407 407 case LFR_MODE_NORMAL:
408 408 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
409 409 status = LFR_DEFAULT;
410 410 }
411 411 else {
412 412 status = LFR_SUCCESSFUL;
413 413 }
414 414 break;
415 415 case LFR_MODE_BURST:
416 416 if ( lfrCurrentMode == LFR_MODE_BURST ) {
417 417 status = LFR_DEFAULT;
418 418 }
419 419 else {
420 420 status = LFR_SUCCESSFUL;
421 421 }
422 422 break;
423 423 case LFR_MODE_SBM1:
424 424 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
425 425 status = LFR_DEFAULT;
426 426 }
427 427 else {
428 428 status = LFR_SUCCESSFUL;
429 429 }
430 430 break;
431 431 case LFR_MODE_SBM2:
432 432 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
433 433 status = LFR_DEFAULT;
434 434 }
435 435 else {
436 436 status = LFR_SUCCESSFUL;
437 437 }
438 438 break;
439 439 default:
440 440 status = LFR_DEFAULT;
441 441 break;
442 442 }
443 443
444 444 return status;
445 445 }
446 446
447 void update_last_valid_transition_date(unsigned int transitionCoarseTime)
447 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
448 448 {
449 449 lastValidEnterModeTime = transitionCoarseTime;
450 450 }
451 451
452 452 int check_transition_date( unsigned int transitionCoarseTime )
453 453 {
454 454 int status;
455 455 unsigned int localCoarseTime;
456 456 unsigned int deltaCoarseTime;
457 457
458 458 status = LFR_SUCCESSFUL;
459 459
460 460 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
461 461 {
462 462 status = LFR_SUCCESSFUL;
463 463 }
464 464 else
465 465 {
466 466 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
467 467
468 468 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime)
469 469
470 470 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
471 471 {
472 472 status = LFR_DEFAULT;
473 473 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n")
474 474 }
475 475
476 476 if (status == LFR_SUCCESSFUL)
477 477 {
478 478 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
479 479 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
480 480 {
481 481 status = LFR_DEFAULT;
482 482 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
483 483 }
484 484 }
485 485 }
486 486
487 487 return status;
488 488 }
489 489
490 490 int restart_asm_activities( unsigned char lfrRequestedMode )
491 491 {
492 492 rtems_status_code status;
493 493
494 494 status = stop_spectral_matrices();
495 495
496 496 status = restart_asm_tasks( lfrRequestedMode );
497 497
498 498 launch_spectral_matrix();
499 499
500 500 return status;
501 501 }
502 502
503 503 int stop_spectral_matrices( void )
504 504 {
505 505 /** This function stops and restarts the current mode average spectral matrices activities.
506 506 *
507 507 * @return RTEMS directive status codes:
508 508 * - RTEMS_SUCCESSFUL - task restarted successfully
509 509 * - RTEMS_INVALID_ID - task id invalid
510 510 * - RTEMS_ALREADY_SUSPENDED - task already suspended
511 511 *
512 512 */
513 513
514 514 rtems_status_code status;
515 515
516 516 status = RTEMS_SUCCESSFUL;
517 517
518 518 // (1) mask interruptions
519 519 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
520 520
521 521 // (2) reset spectral matrices registers
522 522 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
523 523 reset_sm_status();
524 524
525 525 // (3) clear interruptions
526 526 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
527 527
528 528 // suspend several tasks
529 529 if (lfrCurrentMode != LFR_MODE_STANDBY) {
530 530 status = suspend_asm_tasks();
531 531 }
532 532
533 533 if (status != RTEMS_SUCCESSFUL)
534 534 {
535 535 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
536 536 }
537 537
538 538 return status;
539 539 }
540 540
541 541 int stop_current_mode( void )
542 542 {
543 543 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
544 544 *
545 545 * @return RTEMS directive status codes:
546 546 * - RTEMS_SUCCESSFUL - task restarted successfully
547 547 * - RTEMS_INVALID_ID - task id invalid
548 548 * - RTEMS_ALREADY_SUSPENDED - task already suspended
549 549 *
550 550 */
551 551
552 552 rtems_status_code status;
553 553
554 554 status = RTEMS_SUCCESSFUL;
555 555
556 556 // (1) mask interruptions
557 557 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
558 558 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
559 559
560 560 // (2) reset waveform picker registers
561 561 reset_wfp_burst_enable(); // reset burst and enable bits
562 562 reset_wfp_status(); // reset all the status bits
563 563
564 564 // (3) reset spectral matrices registers
565 565 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
566 566 reset_sm_status();
567 567
568 568 // reset lfr VHDL module
569 569 reset_lfr();
570 570
571 571 reset_extractSWF(); // reset the extractSWF flag to false
572 572
573 573 // (4) clear interruptions
574 574 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
575 575 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
576 576
577 577 // suspend several tasks
578 578 if (lfrCurrentMode != LFR_MODE_STANDBY) {
579 579 status = suspend_science_tasks();
580 580 }
581 581
582 582 if (status != RTEMS_SUCCESSFUL)
583 583 {
584 584 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
585 585 }
586 586
587 587 return status;
588 588 }
589 589
590 590 int enter_mode_standby()
591 591 {
592 592 /** This function is used to put LFR in the STANDBY mode.
593 593 *
594 594 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
595 595 *
596 596 * @return RTEMS directive status codes:
597 597 * - RTEMS_SUCCESSFUL - task restarted successfully
598 598 * - RTEMS_INVALID_ID - task id invalid
599 599 * - RTEMS_INCORRECT_STATE - task never started
600 600 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
601 601 *
602 602 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
603 603 * is immediate.
604 604 *
605 605 */
606 606
607 607 int status;
608 608
609 609 status = stop_current_mode(); // STOP THE CURRENT MODE
610 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
611 610
612 611 #ifdef PRINT_TASK_STATISTICS
613 612 rtems_cpu_usage_report();
614 613 #endif
615 614
616 615 #ifdef PRINT_STACK_REPORT
617 616 PRINTF("stack report selected\n")
618 617 rtems_stack_checker_report_usage();
619 618 #endif
620 619
621 620 return status;
622 621 }
623 622
624 623 int enter_mode_normal( unsigned int transitionCoarseTime )
625 624 {
626 625 /** This function is used to start the NORMAL mode.
627 626 *
628 627 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
629 628 *
630 629 * @return RTEMS directive status codes:
631 630 * - RTEMS_SUCCESSFUL - task restarted successfully
632 631 * - RTEMS_INVALID_ID - task id invalid
633 632 * - RTEMS_INCORRECT_STATE - task never started
634 633 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
635 634 *
636 635 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
637 636 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
638 637 *
639 638 */
640 639
641 640 int status;
642 641
643 642 #ifdef PRINT_TASK_STATISTICS
644 643 rtems_cpu_usage_reset();
645 644 #endif
646 645
647 646 status = RTEMS_UNSATISFIED;
648 647
649 648 switch( lfrCurrentMode )
650 649 {
651 650 case LFR_MODE_STANDBY:
652 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
653 651 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
654 652 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
655 653 {
656 654 launch_spectral_matrix( );
657 655 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
658 656 }
659 657 break;
660 658 case LFR_MODE_BURST:
661 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
662 659 status = stop_current_mode(); // stop the current mode
663 660 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
664 661 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
665 662 {
666 663 launch_spectral_matrix( );
667 664 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
668 665 }
669 666 break;
670 667 case LFR_MODE_SBM1:
671 lfrTransitionType = TRANSITION_S1_TO_NORM;
672 668 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
673 669 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
674 670 break;
675 671 case LFR_MODE_SBM2:
676 lfrTransitionType = TRANSITION_S2_TO_NORM;
677 672 restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
678 673 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
679 674 break;
680 675 default:
681 676 break;
682 677 }
683 678
684 679 if (status != RTEMS_SUCCESSFUL)
685 680 {
686 681 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
687 682 status = RTEMS_UNSATISFIED;
688 683 }
689 684
690 685 return status;
691 686 }
692 687
693 688 int enter_mode_burst( unsigned int transitionCoarseTime )
694 689 {
695 690 /** This function is used to start the BURST mode.
696 691 *
697 692 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
698 693 *
699 694 * @return RTEMS directive status codes:
700 695 * - RTEMS_SUCCESSFUL - task restarted successfully
701 696 * - RTEMS_INVALID_ID - task id invalid
702 697 * - RTEMS_INCORRECT_STATE - task never started
703 698 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
704 699 *
705 700 * The way the BURST mode is started does not depend on the LFR current mode.
706 701 *
707 702 */
708 703
709 704
710 705 int status;
711 706
712 707 #ifdef PRINT_TASK_STATISTICS
713 708 rtems_cpu_usage_reset();
714 709 #endif
715 710
716 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
717 711 status = stop_current_mode(); // stop the current mode
718 712 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
719 713 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
720 714 {
721 715 launch_spectral_matrix( );
722 716 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
723 717 }
724 718
725 719 if (status != RTEMS_SUCCESSFUL)
726 720 {
727 721 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
728 722 status = RTEMS_UNSATISFIED;
729 723 }
730 724
731 725 return status;
732 726 }
733 727
734 728 int enter_mode_sbm1( unsigned int transitionCoarseTime )
735 729 {
736 730 /** This function is used to start the SBM1 mode.
737 731 *
738 732 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
739 733 *
740 734 * @return RTEMS directive status codes:
741 735 * - RTEMS_SUCCESSFUL - task restarted successfully
742 736 * - RTEMS_INVALID_ID - task id invalid
743 737 * - RTEMS_INCORRECT_STATE - task never started
744 738 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
745 739 *
746 740 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
747 741 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
748 742 * cases, the acquisition is completely restarted.
749 743 *
750 744 */
751 745
752 746 int status;
753 747
754 748 #ifdef PRINT_TASK_STATISTICS
755 749 rtems_cpu_usage_reset();
756 750 #endif
757 751
758 752 status = RTEMS_UNSATISFIED;
759 753
760 754 switch( lfrCurrentMode )
761 755 {
762 756 case LFR_MODE_STANDBY:
763 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
764 757 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
765 758 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
766 759 {
767 760 launch_spectral_matrix( );
768 761 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
769 762 }
770 763 break;
771 764 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
772 lfrTransitionType = TRANSITION_NORM_TO_S1;
773 765 restart_asm_activities( LFR_MODE_SBM1 );
774 766 status = LFR_SUCCESSFUL;
775 767 break;
776 768 case LFR_MODE_BURST:
777 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
778 769 status = stop_current_mode(); // stop the current mode
779 770 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
780 771 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
781 772 {
782 773 launch_spectral_matrix( );
783 774 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
784 775 }
785 776 break;
786 777 case LFR_MODE_SBM2:
787 lfrTransitionType = TRANSITION_S2_TO_S1;
788 778 restart_asm_activities( LFR_MODE_SBM1 );
789 779 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
790 780 break;
791 781 default:
792 782 break;
793 783 }
794 784
795 785 if (status != RTEMS_SUCCESSFUL)
796 786 {
797 787 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status)
798 788 status = RTEMS_UNSATISFIED;
799 789 }
800 790
801 791 return status;
802 792 }
803 793
804 794 int enter_mode_sbm2( unsigned int transitionCoarseTime )
805 795 {
806 796 /** This function is used to start the SBM2 mode.
807 797 *
808 798 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
809 799 *
810 800 * @return RTEMS directive status codes:
811 801 * - RTEMS_SUCCESSFUL - task restarted successfully
812 802 * - RTEMS_INVALID_ID - task id invalid
813 803 * - RTEMS_INCORRECT_STATE - task never started
814 804 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
815 805 *
816 806 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
817 807 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
818 808 * cases, the acquisition is completely restarted.
819 809 *
820 810 */
821 811
822 812 int status;
823 813
824 814 #ifdef PRINT_TASK_STATISTICS
825 815 rtems_cpu_usage_reset();
826 816 #endif
827 817
828 818 status = RTEMS_UNSATISFIED;
829 819
830 820 switch( lfrCurrentMode )
831 821 {
832 822 case LFR_MODE_STANDBY:
833 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
834 823 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
835 824 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
836 825 {
837 826 launch_spectral_matrix( );
838 827 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
839 828 }
840 829 break;
841 830 case LFR_MODE_NORMAL:
842 lfrTransitionType = TRANSITION_NORM_TO_S2;
843 831 restart_asm_activities( LFR_MODE_SBM2 );
844 832 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
845 833 break;
846 834 case LFR_MODE_BURST:
847 lfrTransitionType = TRANSITION_NOT_SPECIFIC;
848 835 status = stop_current_mode(); // stop the current mode
849 836 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
850 837 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
851 838 {
852 839 launch_spectral_matrix( );
853 840 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
854 841 }
855 842 break;
856 843 case LFR_MODE_SBM1:
857 lfrTransitionType = TRANSITION_S1_TO_S2;
858 844 restart_asm_activities( LFR_MODE_SBM2 );
859 845 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
860 846 break;
861 847 default:
862 848 break;
863 849 }
864 850
865 851 if (status != RTEMS_SUCCESSFUL)
866 852 {
867 853 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
868 854 status = RTEMS_UNSATISFIED;
869 855 }
870 856
871 857 return status;
872 858 }
873 859
874 860 int restart_science_tasks( unsigned char lfrRequestedMode )
875 861 {
876 862 /** This function is used to restart all science tasks.
877 863 *
878 864 * @return RTEMS directive status codes:
879 865 * - RTEMS_SUCCESSFUL - task restarted successfully
880 866 * - RTEMS_INVALID_ID - task id invalid
881 867 * - RTEMS_INCORRECT_STATE - task never started
882 868 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
883 869 *
884 870 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
885 871 *
886 872 */
887 873
888 874 rtems_status_code status[10];
889 875 rtems_status_code ret;
890 876
891 877 ret = RTEMS_SUCCESSFUL;
892 878
893 879 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
894 880 if (status[0] != RTEMS_SUCCESSFUL)
895 881 {
896 882 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
897 883 }
898 884
899 885 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
900 886 if (status[1] != RTEMS_SUCCESSFUL)
901 887 {
902 888 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
903 889 }
904 890
905 891 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
906 892 if (status[2] != RTEMS_SUCCESSFUL)
907 893 {
908 894 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
909 895 }
910 896
911 897 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
912 898 if (status[3] != RTEMS_SUCCESSFUL)
913 899 {
914 900 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
915 901 }
916 902
917 903 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
918 904 if (status[4] != RTEMS_SUCCESSFUL)
919 905 {
920 906 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
921 907 }
922 908
923 909 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
924 910 if (status[5] != RTEMS_SUCCESSFUL)
925 911 {
926 912 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
927 913 }
928 914
929 915 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
930 916 if (status[6] != RTEMS_SUCCESSFUL)
931 917 {
932 918 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
933 919 }
934 920
935 921 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
936 922 if (status[7] != RTEMS_SUCCESSFUL)
937 923 {
938 924 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
939 925 }
940 926
941 927 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
942 928 if (status[8] != RTEMS_SUCCESSFUL)
943 929 {
944 930 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
945 931 }
946 932
947 933 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
948 934 if (status[9] != RTEMS_SUCCESSFUL)
949 935 {
950 936 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
951 937 }
952 938
953 939 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
954 940 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
955 941 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
956 942 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
957 943 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
958 944 {
959 945 ret = RTEMS_UNSATISFIED;
960 946 }
961 947
962 948 return ret;
963 949 }
964 950
965 951 int restart_asm_tasks( unsigned char lfrRequestedMode )
966 952 {
967 953 /** This function is used to restart average spectral matrices tasks.
968 954 *
969 955 * @return RTEMS directive status codes:
970 956 * - RTEMS_SUCCESSFUL - task restarted successfully
971 957 * - RTEMS_INVALID_ID - task id invalid
972 958 * - RTEMS_INCORRECT_STATE - task never started
973 959 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
974 960 *
975 961 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
976 962 *
977 963 */
978 964
979 965 rtems_status_code status[6];
980 966 rtems_status_code ret;
981 967
982 968 ret = RTEMS_SUCCESSFUL;
983 969
984 970 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
985 971 if (status[0] != RTEMS_SUCCESSFUL)
986 972 {
987 973 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
988 974 }
989 975
990 976 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
991 977 if (status[1] != RTEMS_SUCCESSFUL)
992 978 {
993 979 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
994 980 }
995 981
996 982 status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
997 983 if (status[2] != RTEMS_SUCCESSFUL)
998 984 {
999 985 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2])
1000 986 }
1001 987
1002 988 status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1003 989 if (status[3] != RTEMS_SUCCESSFUL)
1004 990 {
1005 991 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3])
1006 992 }
1007 993
1008 994 status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1009 995 if (status[4] != RTEMS_SUCCESSFUL)
1010 996 {
1011 997 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4])
1012 998 }
1013 999
1014 1000 status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1015 1001 if (status[5] != RTEMS_SUCCESSFUL)
1016 1002 {
1017 1003 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5])
1018 1004 }
1019 1005
1020 1006 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
1021 1007 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
1022 1008 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) )
1023 1009 {
1024 1010 ret = RTEMS_UNSATISFIED;
1025 1011 }
1026 1012
1027 1013 return ret;
1028 1014 }
1029 1015
1030 1016 int suspend_science_tasks( void )
1031 1017 {
1032 1018 /** This function suspends the science tasks.
1033 1019 *
1034 1020 * @return RTEMS directive status codes:
1035 1021 * - RTEMS_SUCCESSFUL - task restarted successfully
1036 1022 * - RTEMS_INVALID_ID - task id invalid
1037 1023 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1038 1024 *
1039 1025 */
1040 1026
1041 1027 rtems_status_code status;
1042 1028
1043 1029 PRINTF("in suspend_science_tasks\n")
1044 1030
1045 1031 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1046 1032 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1047 1033 {
1048 1034 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1049 1035 }
1050 1036 else
1051 1037 {
1052 1038 status = RTEMS_SUCCESSFUL;
1053 1039 }
1054 1040 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1055 1041 {
1056 1042 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1057 1043 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1058 1044 {
1059 1045 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1060 1046 }
1061 1047 else
1062 1048 {
1063 1049 status = RTEMS_SUCCESSFUL;
1064 1050 }
1065 1051 }
1066 1052 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1067 1053 {
1068 1054 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1069 1055 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1070 1056 {
1071 1057 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1072 1058 }
1073 1059 else
1074 1060 {
1075 1061 status = RTEMS_SUCCESSFUL;
1076 1062 }
1077 1063 }
1078 1064 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1079 1065 {
1080 1066 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1081 1067 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1082 1068 {
1083 1069 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1084 1070 }
1085 1071 else
1086 1072 {
1087 1073 status = RTEMS_SUCCESSFUL;
1088 1074 }
1089 1075 }
1090 1076 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1091 1077 {
1092 1078 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1093 1079 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1094 1080 {
1095 1081 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1096 1082 }
1097 1083 else
1098 1084 {
1099 1085 status = RTEMS_SUCCESSFUL;
1100 1086 }
1101 1087 }
1102 1088 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1103 1089 {
1104 1090 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1105 1091 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1106 1092 {
1107 1093 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1108 1094 }
1109 1095 else
1110 1096 {
1111 1097 status = RTEMS_SUCCESSFUL;
1112 1098 }
1113 1099 }
1114 1100 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1115 1101 {
1116 1102 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1117 1103 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1118 1104 {
1119 1105 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1120 1106 }
1121 1107 else
1122 1108 {
1123 1109 status = RTEMS_SUCCESSFUL;
1124 1110 }
1125 1111 }
1126 1112 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1127 1113 {
1128 1114 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1129 1115 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1130 1116 {
1131 1117 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1132 1118 }
1133 1119 else
1134 1120 {
1135 1121 status = RTEMS_SUCCESSFUL;
1136 1122 }
1137 1123 }
1138 1124 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1139 1125 {
1140 1126 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1141 1127 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1142 1128 {
1143 1129 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1144 1130 }
1145 1131 else
1146 1132 {
1147 1133 status = RTEMS_SUCCESSFUL;
1148 1134 }
1149 1135 }
1150 1136 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1151 1137 {
1152 1138 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1153 1139 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1154 1140 {
1155 1141 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1156 1142 }
1157 1143 else
1158 1144 {
1159 1145 status = RTEMS_SUCCESSFUL;
1160 1146 }
1161 1147 }
1162 1148
1163 1149 return status;
1164 1150 }
1165 1151
1166 1152 int suspend_asm_tasks( void )
1167 1153 {
1168 1154 /** This function suspends the science tasks.
1169 1155 *
1170 1156 * @return RTEMS directive status codes:
1171 1157 * - RTEMS_SUCCESSFUL - task restarted successfully
1172 1158 * - RTEMS_INVALID_ID - task id invalid
1173 1159 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1174 1160 *
1175 1161 */
1176 1162
1177 1163 rtems_status_code status;
1178 1164
1179 1165 PRINTF("in suspend_science_tasks\n")
1180 1166
1181 1167 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1182 1168 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1183 1169 {
1184 1170 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1185 1171 }
1186 1172 else
1187 1173 {
1188 1174 status = RTEMS_SUCCESSFUL;
1189 1175 }
1190 1176
1191 1177 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1192 1178 {
1193 1179 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1194 1180 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1195 1181 {
1196 1182 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1197 1183 }
1198 1184 else
1199 1185 {
1200 1186 status = RTEMS_SUCCESSFUL;
1201 1187 }
1202 1188 }
1203 1189
1204 1190 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1205 1191 {
1206 1192 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1207 1193 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1208 1194 {
1209 1195 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1210 1196 }
1211 1197 else
1212 1198 {
1213 1199 status = RTEMS_SUCCESSFUL;
1214 1200 }
1215 1201 }
1216 1202
1217 1203 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1218 1204 {
1219 1205 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1220 1206 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1221 1207 {
1222 1208 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1223 1209 }
1224 1210 else
1225 1211 {
1226 1212 status = RTEMS_SUCCESSFUL;
1227 1213 }
1228 1214 }
1229 1215
1230 1216 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1231 1217 {
1232 1218 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1233 1219 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1234 1220 {
1235 1221 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1236 1222 }
1237 1223 else
1238 1224 {
1239 1225 status = RTEMS_SUCCESSFUL;
1240 1226 }
1241 1227 }
1242 1228
1243 1229 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1244 1230 {
1245 1231 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1246 1232 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1247 1233 {
1248 1234 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1249 1235 }
1250 1236 else
1251 1237 {
1252 1238 status = RTEMS_SUCCESSFUL;
1253 1239 }
1254 1240 }
1255 1241
1256 1242 return status;
1257 1243 }
1258 1244
1259 1245 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1260 1246 {
1261 1247 WFP_reset_current_ring_nodes();
1262 1248
1263 1249 reset_waveform_picker_regs();
1264 1250
1265 1251 set_wfp_burst_enable_register( mode );
1266 1252
1267 1253 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1268 1254 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1269 1255
1270 1256 if (transitionCoarseTime == 0)
1271 1257 {
1272 1258 waveform_picker_regs->start_date = time_management_regs->coarse_time;
1273 1259 }
1274 1260 else
1275 1261 {
1276 1262 waveform_picker_regs->start_date = transitionCoarseTime;
1277 1263 }
1278 1264
1279 1265 }
1280 1266
1281 1267 void launch_spectral_matrix( void )
1282 1268 {
1283 1269 SM_reset_current_ring_nodes();
1284 1270
1285 1271 reset_spectral_matrix_regs();
1286 1272
1287 1273 reset_nb_sm();
1288 1274
1289 1275 set_sm_irq_onNewMatrix( 1 );
1290 1276
1291 1277 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1292 1278 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1293 1279
1294 1280 }
1295 1281
1296 1282 void set_sm_irq_onNewMatrix( unsigned char value )
1297 1283 {
1298 1284 if (value == 1)
1299 1285 {
1300 1286 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
1301 1287 }
1302 1288 else
1303 1289 {
1304 1290 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
1305 1291 }
1306 1292 }
1307 1293
1308 1294 void set_sm_irq_onError( unsigned char value )
1309 1295 {
1310 1296 if (value == 1)
1311 1297 {
1312 1298 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
1313 1299 }
1314 1300 else
1315 1301 {
1316 1302 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
1317 1303 }
1318 1304 }
1319 1305
1320 1306 //*****************************
1321 1307 // CONFIGURE CALIBRATION SIGNAL
1322 1308 void setCalibrationPrescaler( unsigned int prescaler )
1323 1309 {
1324 1310 // prescaling of the master clock (25 MHz)
1325 1311 // master clock is divided by 2^prescaler
1326 1312 time_management_regs->calPrescaler = prescaler;
1327 1313 }
1328 1314
1329 1315 void setCalibrationDivisor( unsigned int divisionFactor )
1330 1316 {
1331 1317 // division of the prescaled clock by the division factor
1332 1318 time_management_regs->calDivisor = divisionFactor;
1333 1319 }
1334 1320
1335 1321 void setCalibrationData( void ){
1336 1322 unsigned int k;
1337 1323 unsigned short data;
1338 1324 float val;
1339 1325 float f0;
1340 1326 float f1;
1341 1327 float fs;
1342 1328 float Ts;
1343 1329 float scaleFactor;
1344 1330
1345 1331 f0 = 625;
1346 1332 f1 = 10000;
1347 1333 fs = 160256.410;
1348 1334 Ts = 1. / fs;
1349 1335 scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
1350 1336
1351 1337 time_management_regs->calDataPtr = 0x00;
1352 1338
1353 1339 // build the signal for the SCM calibration
1354 1340 for (k=0; k<256; k++)
1355 1341 {
1356 1342 val = sin( 2 * pi * f0 * k * Ts )
1357 1343 + sin( 2 * pi * f1 * k * Ts );
1358 1344 data = (unsigned short) ((val * scaleFactor) + 2048);
1359 1345 time_management_regs->calData = data & 0xfff;
1360 1346 }
1361 1347 }
1362 1348
1363 1349 void setCalibrationDataInterleaved( void ){
1364 1350 unsigned int k;
1365 1351 float val;
1366 1352 float f0;
1367 1353 float f1;
1368 1354 float fs;
1369 1355 float Ts;
1370 1356 unsigned short data[384];
1371 1357 unsigned char *dataPtr;
1372 1358
1373 1359 f0 = 625;
1374 1360 f1 = 10000;
1375 1361 fs = 240384.615;
1376 1362 Ts = 1. / fs;
1377 1363
1378 1364 time_management_regs->calDataPtr = 0x00;
1379 1365
1380 1366 // build the signal for the SCM calibration
1381 1367 for (k=0; k<384; k++)
1382 1368 {
1383 1369 val = sin( 2 * pi * f0 * k * Ts )
1384 1370 + sin( 2 * pi * f1 * k * Ts );
1385 1371 data[k] = (unsigned short) (val * 512 + 2048);
1386 1372 }
1387 1373
1388 1374 // write the signal in interleaved mode
1389 1375 for (k=0; k<128; k++)
1390 1376 {
1391 1377 dataPtr = (unsigned char*) &data[k*3 + 2];
1392 1378 time_management_regs->calData = (data[k*3] & 0xfff)
1393 1379 + ( (dataPtr[0] & 0x3f) << 12);
1394 1380 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
1395 1381 + ( (dataPtr[1] & 0x3f) << 12);
1396 1382 }
1397 1383 }
1398 1384
1399 1385 void setCalibrationReload( bool state)
1400 1386 {
1401 1387 if (state == true)
1402 1388 {
1403 1389 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
1404 1390 }
1405 1391 else
1406 1392 {
1407 1393 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
1408 1394 }
1409 1395 }
1410 1396
1411 1397 void setCalibrationEnable( bool state )
1412 1398 {
1413 1399 // this bit drives the multiplexer
1414 1400 if (state == true)
1415 1401 {
1416 1402 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
1417 1403 }
1418 1404 else
1419 1405 {
1420 1406 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
1421 1407 }
1422 1408 }
1423 1409
1424 1410 void setCalibrationInterleaved( bool state )
1425 1411 {
1426 1412 // this bit drives the multiplexer
1427 1413 if (state == true)
1428 1414 {
1429 1415 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
1430 1416 }
1431 1417 else
1432 1418 {
1433 1419 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
1434 1420 }
1435 1421 }
1436 1422
1437 1423 void setCalibration( bool state )
1438 1424 {
1439 1425 if (state == true)
1440 1426 {
1441 1427 setCalibrationEnable( true );
1442 1428 setCalibrationReload( false );
1443 1429 set_hk_lfr_calib_enable( true );
1444 1430 }
1445 1431 else
1446 1432 {
1447 1433 setCalibrationEnable( false );
1448 1434 setCalibrationReload( true );
1449 1435 set_hk_lfr_calib_enable( false );
1450 1436 }
1451 1437 }
1452 1438
1453 1439 void configureCalibration( bool interleaved )
1454 1440 {
1455 1441 setCalibration( false );
1456 1442 if ( interleaved == true )
1457 1443 {
1458 1444 setCalibrationInterleaved( true );
1459 1445 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1460 1446 setCalibrationDivisor( 26 ); // => 240 384
1461 1447 setCalibrationDataInterleaved();
1462 1448 }
1463 1449 else
1464 1450 {
1465 1451 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1466 1452 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1467 1453 setCalibrationData();
1468 1454 }
1469 1455 }
1470 1456
1471 1457 //****************
1472 1458 // CLOSING ACTIONS
1473 1459 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1474 1460 {
1475 1461 /** This function is used to update the HK packets statistics after a successful TC execution.
1476 1462 *
1477 1463 * @param TC points to the TC being processed
1478 1464 * @param time is the time used to date the TC execution
1479 1465 *
1480 1466 */
1481 1467
1482 1468 unsigned int val;
1483 1469
1484 1470 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1485 1471 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1486 1472 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1487 1473 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1488 1474 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1489 1475 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1490 1476 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1491 1477 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1492 1478 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1493 1479 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1494 1480 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1495 1481 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1496 1482
1497 1483 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1498 1484 val++;
1499 1485 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1500 1486 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1501 1487 }
1502 1488
1503 1489 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1504 1490 {
1505 1491 /** This function is used to update the HK packets statistics after a TC rejection.
1506 1492 *
1507 1493 * @param TC points to the TC being processed
1508 1494 * @param time is the time used to date the TC rejection
1509 1495 *
1510 1496 */
1511 1497
1512 1498 unsigned int val;
1513 1499
1514 1500 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1515 1501 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1516 1502 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1517 1503 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1518 1504 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1519 1505 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1520 1506 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1521 1507 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1522 1508 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1523 1509 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1524 1510 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1525 1511 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1526 1512
1527 1513 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1528 1514 val++;
1529 1515 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1530 1516 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1531 1517 }
1532 1518
1533 1519 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1534 1520 {
1535 1521 /** This function is the last step of the TC execution workflow.
1536 1522 *
1537 1523 * @param TC points to the TC being processed
1538 1524 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1539 1525 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1540 1526 * @param time is the time used to date the TC execution
1541 1527 *
1542 1528 */
1543 1529
1544 1530 unsigned char requestedMode;
1545 1531
1546 1532 if (result == LFR_SUCCESSFUL)
1547 1533 {
1548 1534 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1549 1535 &
1550 1536 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1551 1537 )
1552 1538 {
1553 1539 send_tm_lfr_tc_exe_success( TC, queue_id );
1554 1540 }
1555 1541 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1556 1542 {
1557 1543 //**********************************
1558 1544 // UPDATE THE LFRMODE LOCAL VARIABLE
1559 1545 requestedMode = TC->dataAndCRC[1];
1560 1546 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1561 1547 updateLFRCurrentMode();
1562 1548 }
1563 1549 }
1564 1550 else if (result == LFR_EXE_ERROR)
1565 1551 {
1566 1552 send_tm_lfr_tc_exe_error( TC, queue_id );
1567 1553 }
1568 1554 }
1569 1555
1570 1556 //***************************
1571 1557 // Interrupt Service Routines
1572 1558 rtems_isr commutation_isr1( rtems_vector_number vector )
1573 1559 {
1574 1560 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1575 1561 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1576 1562 }
1577 1563 }
1578 1564
1579 1565 rtems_isr commutation_isr2( rtems_vector_number vector )
1580 1566 {
1581 1567 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1582 1568 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1583 1569 }
1584 1570 }
1585 1571
1586 1572 //****************
1587 1573 // OTHER FUNCTIONS
1588 1574 void updateLFRCurrentMode()
1589 1575 {
1590 1576 /** This function updates the value of the global variable lfrCurrentMode.
1591 1577 *
1592 1578 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1593 1579 *
1594 1580 */
1595 1581 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1596 1582 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1597 1583 }
1598 1584
1599 1585 void set_lfr_soft_reset( unsigned char value )
1600 1586 {
1601 1587 if (value == 1)
1602 1588 {
1603 1589 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1604 1590 }
1605 1591 else
1606 1592 {
1607 1593 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1608 1594 }
1609 1595 }
1610 1596
1611 1597 void reset_lfr( void )
1612 1598 {
1613 1599 set_lfr_soft_reset( 1 );
1614 1600
1615 1601 set_lfr_soft_reset( 0 );
1616 1602
1617 1603 set_hk_lfr_sc_potential_flag( true );
1618 1604 }
General Comments 0
You need to be logged in to leave comments. Login now