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