##// END OF EJS Templates
Bug 354, hk_sy_lfr_calib_enabled is set in TM_LFR_HK packets
paul -
r206:f4c6f6db73fc R3
parent child
Show More
@@ -1,112 +1,112
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 4 # lpp_dpu_destid
5 5 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
6 6 CONFIG -= qt
7 7
8 8 include(./sparc.pri)
9 9
10 10 # flight software version
11 11 SWVERSION=-1-0
12 12 DEFINES += SW_VERSION_N1=3 # major
13 13 DEFINES += SW_VERSION_N2=0 # minor
14 14 DEFINES += SW_VERSION_N3=0 # patch
15 DEFINES += SW_VERSION_N4=2 # internal
15 DEFINES += SW_VERSION_N4=3 # internal
16 16
17 17 # <GCOV>
18 18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
20 20 # </GCOV>
21 21
22 22 # <CHANGE BEFORE FLIGHT>
23 23 contains( CONFIG, lpp_dpu_destid ) {
24 24 DEFINES += LPP_DPU_DESTID
25 25 }
26 26 # </CHANGE BEFORE FLIGHT>
27 27
28 28 contains( CONFIG, debug_tch ) {
29 29 DEFINES += DEBUG_TCH
30 30 }
31 31 DEFINES += MSB_FIRST_TCH
32 32
33 33 contains( CONFIG, vhdl_dev ) {
34 34 DEFINES += VHDL_DEV
35 35 }
36 36
37 37 contains( CONFIG, verbose ) {
38 38 DEFINES += PRINT_MESSAGES_ON_CONSOLE
39 39 }
40 40
41 41 contains( CONFIG, debug_messages ) {
42 42 DEFINES += DEBUG_MESSAGES
43 43 }
44 44
45 45 contains( CONFIG, cpu_usage_report ) {
46 46 DEFINES += PRINT_TASK_STATISTICS
47 47 }
48 48
49 49 contains( CONFIG, stack_report ) {
50 50 DEFINES += PRINT_STACK_REPORT
51 51 }
52 52
53 53 contains( CONFIG, boot_messages ) {
54 54 DEFINES += BOOT_MESSAGES
55 55 }
56 56
57 57 #doxygen.target = doxygen
58 58 #doxygen.commands = doxygen ../doc/Doxyfile
59 59 #QMAKE_EXTRA_TARGETS += doxygen
60 60
61 61 TARGET = fsw
62 62
63 63 INCLUDEPATH += \
64 64 $${PWD}/../src \
65 65 $${PWD}/../header \
66 66 $${PWD}/../header/lfr_common_headers \
67 67 $${PWD}/../header/processing \
68 68 $${PWD}/../LFR_basic-parameters
69 69
70 70 SOURCES += \
71 71 ../src/wf_handler.c \
72 72 ../src/tc_handler.c \
73 73 ../src/fsw_misc.c \
74 74 ../src/fsw_init.c \
75 75 ../src/fsw_globals.c \
76 76 ../src/fsw_spacewire.c \
77 77 ../src/tc_load_dump_parameters.c \
78 78 ../src/tm_lfr_tc_exe.c \
79 79 ../src/tc_acceptance.c \
80 80 ../src/processing/fsw_processing.c \
81 81 ../src/processing/avf0_prc0.c \
82 82 ../src/processing/avf1_prc1.c \
83 83 ../src/processing/avf2_prc2.c \
84 84 ../src/lfr_cpu_usage_report.c \
85 85 ../LFR_basic-parameters/basic_parameters.c
86 86
87 87 HEADERS += \
88 88 ../header/wf_handler.h \
89 89 ../header/tc_handler.h \
90 90 ../header/grlib_regs.h \
91 91 ../header/fsw_misc.h \
92 92 ../header/fsw_init.h \
93 93 ../header/fsw_spacewire.h \
94 94 ../header/tc_load_dump_parameters.h \
95 95 ../header/tm_lfr_tc_exe.h \
96 96 ../header/tc_acceptance.h \
97 97 ../header/processing/fsw_processing.h \
98 98 ../header/processing/avf0_prc0.h \
99 99 ../header/processing/avf1_prc1.h \
100 100 ../header/processing/avf2_prc2.h \
101 101 ../header/fsw_params_wf_handler.h \
102 102 ../header/lfr_cpu_usage_report.h \
103 103 ../header/lfr_common_headers/ccsds_types.h \
104 104 ../header/lfr_common_headers/fsw_params.h \
105 105 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
106 106 ../header/lfr_common_headers/fsw_params_processing.h \
107 107 ../header/lfr_common_headers/TC_types.h \
108 108 ../header/lfr_common_headers/tm_byte_positions.h \
109 109 ../LFR_basic-parameters/basic_parameters.h \
110 110 ../LFR_basic-parameters/basic_parameters_params.h \
111 111 ../header/GscMemoryLPP.hpp
112 112
@@ -1,138 +1,138
1 1 #ifndef GRLIB_REGS_H_INCLUDED
2 2 #define GRLIB_REGS_H_INCLUDED
3 3
4 4 #define NB_GPTIMER 3
5 5
6 6 struct apbuart_regs_str{
7 7 volatile unsigned int data;
8 8 volatile unsigned int status;
9 9 volatile unsigned int ctrl;
10 10 volatile unsigned int scaler;
11 11 volatile unsigned int fifoDebug;
12 12 };
13 13
14 14 struct grgpio_regs_str{
15 15 volatile int io_port_data_register;
16 16 int io_port_output_register;
17 17 int io_port_direction_register;
18 18 int interrupt_mak_register;
19 19 int interrupt_polarity_register;
20 20 int interrupt_edge_register;
21 21 int bypass_register;
22 22 int reserved;
23 23 // 0x20-0x3c interrupt map register(s)
24 24 };
25 25
26 26 typedef struct {
27 27 volatile unsigned int counter;
28 28 volatile unsigned int reload;
29 29 volatile unsigned int ctrl;
30 30 volatile unsigned int unused;
31 31 } timer_regs_t;
32 32
33 33 typedef struct {
34 34 volatile unsigned int scaler_value;
35 35 volatile unsigned int scaler_reload;
36 36 volatile unsigned int conf;
37 37 volatile unsigned int unused0;
38 38 timer_regs_t timer[NB_GPTIMER];
39 39 } gptimer_regs_t;
40 40
41 41 typedef struct {
42 42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 43 // bit 1 is the soft reset for the time management module
44 44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
45 45 volatile int coarse_time_load;
46 46 volatile int coarse_time;
47 47 volatile int fine_time;
48 48 // TEMPERATURES
49 49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
50 50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
51 51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
52 52 // CALIBRATION
53 53 volatile unsigned int calDACCtrl;
54 54 volatile unsigned int calPrescaler;
55 55 volatile unsigned int calDivisor;
56 56 volatile unsigned int calDataPtr;
57 57 volatile unsigned int calData;
58 58 } time_management_regs_t;
59 59
60 // PDB >= 0.1.28
60 // PDB >= 0.1.28, 0x80000f54
61 61 typedef struct{
62 62 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
63 63 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
64 64 int addr_data_f0_0; // 0x08
65 65 int addr_data_f0_1; // 0x0c
66 66 int addr_data_f1_0; // 0x10
67 67 int addr_data_f1_1; // 0x14
68 68 int addr_data_f2_0; // 0x18
69 69 int addr_data_f2_1; // 0x1c
70 70 int addr_data_f3_0; // 0x20
71 71 int addr_data_f3_1; // 0x24
72 72 volatile int status; // 0x28
73 73 int delta_snapshot; // 0x2c
74 74 int delta_f0; // 0x30
75 75 int delta_f0_2; // 0x34
76 76 int delta_f1; // 0x38
77 77 int delta_f2; // 0x3c
78 78 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
79 79 int snapshot_param; // 0x44
80 80 int start_date; // 0x48
81 81 //
82 82 volatile unsigned int f0_0_coarse_time; // 0x4c
83 83 volatile unsigned int f0_0_fine_time; // 0x50
84 84 volatile unsigned int f0_1_coarse_time; // 0x54
85 85 volatile unsigned int f0_1_fine_time; // 0x58
86 86 //
87 87 volatile unsigned int f1_0_coarse_time; // 0x5c
88 88 volatile unsigned int f1_0_fine_time; // 0x60
89 89 volatile unsigned int f1_1_coarse_time; // 0x64
90 90 volatile unsigned int f1_1_fine_time; // 0x68
91 91 //
92 92 volatile unsigned int f2_0_coarse_time; // 0x6c
93 93 volatile unsigned int f2_0_fine_time; // 0x70
94 94 volatile unsigned int f2_1_coarse_time; // 0x74
95 95 volatile unsigned int f2_1_fine_time; // 0x78
96 96 //
97 volatile unsigned int f3_0_coarse_time; // 0x7c
97 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
98 98 volatile unsigned int f3_0_fine_time; // 0x80
99 99 volatile unsigned int f3_1_coarse_time; // 0x84
100 100 volatile unsigned int f3_1_fine_time; // 0x88
101 101 //
102 102 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
103 103 //
104 104 volatile unsigned int v; // 0x90
105 105 volatile unsigned int e1; // 0x94
106 106 volatile unsigned int e2; // 0x98
107 107 } waveform_picker_regs_0_1_18_t;
108 108
109 109 typedef struct {
110 110 volatile int config; // 0x00
111 111 volatile int status; // 0x04
112 112 volatile int f0_0_address; // 0x08
113 113 volatile int f0_1_address; // 0x0C
114 114 //
115 115 volatile int f1_0_address; // 0x10
116 116 volatile int f1_1_address; // 0x14
117 117 volatile int f2_0_address; // 0x18
118 118 volatile int f2_1_address; // 0x1C
119 119 //
120 120 volatile unsigned int f0_0_coarse_time; // 0x20
121 121 volatile unsigned int f0_0_fine_time; // 0x24
122 122 volatile unsigned int f0_1_coarse_time; // 0x28
123 123 volatile unsigned int f0_1_fine_time; // 0x2C
124 124 //
125 125 volatile unsigned int f1_0_coarse_time; // 0x30
126 126 volatile unsigned int f1_0_fine_time; // 0x34
127 127 volatile unsigned int f1_1_coarse_time; // 0x38
128 128 volatile unsigned int f1_1_fine_time; // 0x3C
129 129 //
130 130 volatile unsigned int f2_0_coarse_time; // 0x40
131 131 volatile unsigned int f2_0_fine_time; // 0x44
132 132 volatile unsigned int f2_1_coarse_time; // 0x48
133 133 volatile unsigned int f2_1_fine_time; // 0x4C
134 134 //
135 135 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
136 136 } spectral_matrix_regs_t;
137 137
138 138 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,72 +1,72
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 #include "lfr_cpu_usage_report.h"
14 14
15 15 //****
16 16 // ISR
17 17 rtems_isr commutation_isr1( rtems_vector_number vector );
18 18 rtems_isr commutation_isr2( rtems_vector_number vector );
19 19
20 20 //***********
21 21 // RTEMS TASK
22 22 rtems_task actn_task( rtems_task_argument unused );
23 23
24 24 //***********
25 25 // TC ACTIONS
26 26 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
27 27 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
28 28 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
29 29 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 30 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
31 31 int action_update_time( ccsdsTelecommandPacket_t *TC);
32 32
33 33 // mode transition
34 34 int check_mode_value( unsigned char requestedMode );
35 35 int check_mode_transition( unsigned char requestedMode );
36 36 int check_transition_date( unsigned int transitionCoarseTime );
37 37 int stop_current_mode( void );
38 38 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
39 39 int restart_science_tasks( unsigned char lfrRequestedMode );
40 40 int suspend_science_tasks();
41 41 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
42 42 void launch_spectral_matrix( void );
43 43 void launch_spectral_matrix_simu( void );
44 44 void set_sm_irq_onNewMatrix( unsigned char value );
45 45 void set_sm_irq_onError( unsigned char value );
46 46
47 47 // other functions
48 48 void updateLFRCurrentMode();
49 49 void set_lfr_soft_reset( unsigned char value );
50 50 void reset_lfr( void );
51 51 // CALIBRATION
52 52 void setCalibrationPrescaler( unsigned int prescaler );
53 53 void setCalibrationDivisor( unsigned int divisionFactor );
54 54 void setCalibrationData( void );
55 55 void setCalibrationReload( bool state);
56 56 void setCalibrationEnable( bool state );
57 57 void setCalibrationInterleaved( bool state );
58 void startCalibration( void );
59 void stopCalibration( void );
58 void setCalibration( bool state );
59 void set_hk_lfr_calib_enable( bool state );
60 60 void configureCalibration( bool interleaved );
61 61 //
62 62 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
63 63 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
64 64 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
65 65
66 66 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
67 67 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
68 68
69 69 #endif // TC_HANDLER_H_INCLUDED
70 70
71 71
72 72
@@ -1,1159 +1,1175
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14 #include "math.h"
15 15
16 16 //***********
17 17 // RTEMS TASK
18 18
19 19 rtems_task actn_task( rtems_task_argument unused )
20 20 {
21 21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 22 *
23 23 * @param unused is the starting argument of the RTEMS task
24 24 *
25 25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 26 * on the incoming TeleCommand.
27 27 *
28 28 */
29 29
30 30 int result;
31 31 rtems_status_code status; // RTEMS status code
32 32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 33 size_t size; // size of the incoming TC packet
34 34 unsigned char subtype; // subtype of the current TC packet
35 35 unsigned char time[6];
36 36 rtems_id queue_rcv_id;
37 37 rtems_id queue_snd_id;
38 38
39 39 status = get_message_queue_id_recv( &queue_rcv_id );
40 40 if (status != RTEMS_SUCCESSFUL)
41 41 {
42 42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
43 43 }
44 44
45 45 status = get_message_queue_id_send( &queue_snd_id );
46 46 if (status != RTEMS_SUCCESSFUL)
47 47 {
48 48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
49 49 }
50 50
51 51 result = LFR_SUCCESSFUL;
52 52 subtype = 0; // subtype of the current TC packet
53 53
54 54 BOOT_PRINTF("in ACTN *** \n")
55 55
56 56 while(1)
57 57 {
58 58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 60 getTime( time ); // set time to the current time
61 61 if (status!=RTEMS_SUCCESSFUL)
62 62 {
63 63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
64 64 }
65 65 else
66 66 {
67 67 subtype = TC.serviceSubType;
68 68 switch(subtype)
69 69 {
70 70 case TC_SUBTYPE_RESET:
71 71 result = action_reset( &TC, queue_snd_id, time );
72 72 close_action( &TC, result, queue_snd_id );
73 73 break;
74 74 case TC_SUBTYPE_LOAD_COMM:
75 75 result = action_load_common_par( &TC );
76 76 close_action( &TC, result, queue_snd_id );
77 77 break;
78 78 case TC_SUBTYPE_LOAD_NORM:
79 79 result = action_load_normal_par( &TC, queue_snd_id, time );
80 80 close_action( &TC, result, queue_snd_id );
81 81 break;
82 82 case TC_SUBTYPE_LOAD_BURST:
83 83 result = action_load_burst_par( &TC, queue_snd_id, time );
84 84 close_action( &TC, result, queue_snd_id );
85 85 break;
86 86 case TC_SUBTYPE_LOAD_SBM1:
87 87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 88 close_action( &TC, result, queue_snd_id );
89 89 break;
90 90 case TC_SUBTYPE_LOAD_SBM2:
91 91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 92 close_action( &TC, result, queue_snd_id );
93 93 break;
94 94 case TC_SUBTYPE_DUMP:
95 95 result = action_dump_par( queue_snd_id );
96 96 close_action( &TC, result, queue_snd_id );
97 97 break;
98 98 case TC_SUBTYPE_ENTER:
99 99 result = action_enter_mode( &TC, queue_snd_id );
100 100 close_action( &TC, result, queue_snd_id );
101 101 break;
102 102 case TC_SUBTYPE_UPDT_INFO:
103 103 result = action_update_info( &TC, queue_snd_id );
104 104 close_action( &TC, result, queue_snd_id );
105 105 break;
106 106 case TC_SUBTYPE_EN_CAL:
107 107 result = action_enable_calibration( &TC, queue_snd_id, time );
108 108 close_action( &TC, result, queue_snd_id );
109 109 break;
110 110 case TC_SUBTYPE_DIS_CAL:
111 111 result = action_disable_calibration( &TC, queue_snd_id, time );
112 112 close_action( &TC, result, queue_snd_id );
113 113 break;
114 114 case TC_SUBTYPE_LOAD_K:
115 115 printf("TC_SUBTYPE_LOAD_K\n");
116 116 result = action_load_kcoefficients( &TC, queue_snd_id, time );
117 117 close_action( &TC, result, queue_snd_id );
118 118 break;
119 119 case TC_SUBTYPE_DUMP_K:
120 120 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
121 121 close_action( &TC, result, queue_snd_id );
122 122 break;
123 123 case TC_SUBTYPE_LOAD_FBINS:
124 124 result = action_load_fbins_mask( &TC, queue_snd_id, time );
125 125 close_action( &TC, result, queue_snd_id );
126 126 break;
127 127 case TC_SUBTYPE_UPDT_TIME:
128 128 result = action_update_time( &TC );
129 129 close_action( &TC, result, queue_snd_id );
130 130 break;
131 131 default:
132 132 break;
133 133 }
134 134 }
135 135 }
136 136 }
137 137
138 138 //***********
139 139 // TC ACTIONS
140 140
141 141 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
142 142 {
143 143 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
144 144 *
145 145 * @param TC points to the TeleCommand packet that is being processed
146 146 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
147 147 *
148 148 */
149 149
150 150 printf("this is the end!!!\n");
151 151 exit(0);
152 152 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
153 153 return LFR_DEFAULT;
154 154 }
155 155
156 156 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
157 157 {
158 158 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
159 159 *
160 160 * @param TC points to the TeleCommand packet that is being processed
161 161 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
162 162 *
163 163 */
164 164
165 165 rtems_status_code status;
166 166 unsigned char requestedMode;
167 167 unsigned int *transitionCoarseTime_ptr;
168 168 unsigned int transitionCoarseTime;
169 169 unsigned char * bytePosPtr;
170 170
171 171 bytePosPtr = (unsigned char *) &TC->packetID;
172 172
173 173 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
174 174 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
175 175 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
176 176
177 177 status = check_mode_value( requestedMode );
178 178
179 179 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
180 180 {
181 181 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
182 182 }
183 183 else // the mode value is consistent, check the transition
184 184 {
185 185 status = check_mode_transition(requestedMode);
186 186 if (status != LFR_SUCCESSFUL)
187 187 {
188 188 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 189 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 190 }
191 191 }
192 192
193 193 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
194 194 {
195 195 status = check_transition_date( transitionCoarseTime );
196 196 if (status != LFR_SUCCESSFUL)
197 197 {
198 198 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
199 199 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
200 200 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
201 201 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
202 202 }
203 203 }
204 204
205 205 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
206 206 {
207 207 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
208 208 status = enter_mode( requestedMode, transitionCoarseTime );
209 209 }
210 210
211 211 return status;
212 212 }
213 213
214 214 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
215 215 {
216 216 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
217 217 *
218 218 * @param TC points to the TeleCommand packet that is being processed
219 219 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
220 220 *
221 221 * @return LFR directive status code:
222 222 * - LFR_DEFAULT
223 223 * - LFR_SUCCESSFUL
224 224 *
225 225 */
226 226
227 227 unsigned int val;
228 228 int result;
229 229 unsigned int status;
230 230 unsigned char mode;
231 231 unsigned char * bytePosPtr;
232 232
233 233 bytePosPtr = (unsigned char *) &TC->packetID;
234 234
235 235 // check LFR mode
236 236 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
237 237 status = check_update_info_hk_lfr_mode( mode );
238 238 if (status == LFR_SUCCESSFUL) // check TDS mode
239 239 {
240 240 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
241 241 status = check_update_info_hk_tds_mode( mode );
242 242 }
243 243 if (status == LFR_SUCCESSFUL) // check THR mode
244 244 {
245 245 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
246 246 status = check_update_info_hk_thr_mode( mode );
247 247 }
248 248 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
249 249 {
250 250 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
251 251 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
252 252 val++;
253 253 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
254 254 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
255 255 }
256 256
257 257 result = status;
258 258
259 259 return result;
260 260 }
261 261
262 262 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
263 263 {
264 264 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
265 265 *
266 266 * @param TC points to the TeleCommand packet that is being processed
267 267 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
268 268 *
269 269 */
270 270
271 271 int result;
272 272
273 273 result = LFR_DEFAULT;
274 274
275 startCalibration();
275 setCalibration( true );
276 276
277 277 result = LFR_SUCCESSFUL;
278 278
279 279 return result;
280 280 }
281 281
282 282 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
283 283 {
284 284 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
285 285 *
286 286 * @param TC points to the TeleCommand packet that is being processed
287 287 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
288 288 *
289 289 */
290 290
291 291 int result;
292 292
293 293 result = LFR_DEFAULT;
294 294
295 stopCalibration();
295 setCalibration( false );
296 296
297 297 result = LFR_SUCCESSFUL;
298 298
299 299 return result;
300 300 }
301 301
302 302 int action_update_time(ccsdsTelecommandPacket_t *TC)
303 303 {
304 304 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
305 305 *
306 306 * @param TC points to the TeleCommand packet that is being processed
307 307 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
308 308 *
309 309 * @return LFR_SUCCESSFUL
310 310 *
311 311 */
312 312
313 313 unsigned int val;
314 314
315 315 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
316 316 + (TC->dataAndCRC[1] << 16)
317 317 + (TC->dataAndCRC[2] << 8)
318 318 + TC->dataAndCRC[3];
319 319
320 320 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 321 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 322 val++;
323 323 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
324 324 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325 325
326 326 return LFR_SUCCESSFUL;
327 327 }
328 328
329 329 //*******************
330 330 // ENTERING THE MODES
331 331 int check_mode_value( unsigned char requestedMode )
332 332 {
333 333 int status;
334 334
335 335 if ( (requestedMode != LFR_MODE_STANDBY)
336 336 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
337 337 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
338 338 {
339 339 status = LFR_DEFAULT;
340 340 }
341 341 else
342 342 {
343 343 status = LFR_SUCCESSFUL;
344 344 }
345 345
346 346 return status;
347 347 }
348 348
349 349 int check_mode_transition( unsigned char requestedMode )
350 350 {
351 351 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
352 352 *
353 353 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
354 354 *
355 355 * @return LFR directive status codes:
356 356 * - LFR_SUCCESSFUL - the transition is authorized
357 357 * - LFR_DEFAULT - the transition is not authorized
358 358 *
359 359 */
360 360
361 361 int status;
362 362
363 363 switch (requestedMode)
364 364 {
365 365 case LFR_MODE_STANDBY:
366 366 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
367 367 status = LFR_DEFAULT;
368 368 }
369 369 else
370 370 {
371 371 status = LFR_SUCCESSFUL;
372 372 }
373 373 break;
374 374 case LFR_MODE_NORMAL:
375 375 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
376 376 status = LFR_DEFAULT;
377 377 }
378 378 else {
379 379 status = LFR_SUCCESSFUL;
380 380 }
381 381 break;
382 382 case LFR_MODE_BURST:
383 383 if ( lfrCurrentMode == LFR_MODE_BURST ) {
384 384 status = LFR_DEFAULT;
385 385 }
386 386 else {
387 387 status = LFR_SUCCESSFUL;
388 388 }
389 389 break;
390 390 case LFR_MODE_SBM1:
391 391 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
392 392 status = LFR_DEFAULT;
393 393 }
394 394 else {
395 395 status = LFR_SUCCESSFUL;
396 396 }
397 397 break;
398 398 case LFR_MODE_SBM2:
399 399 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
400 400 status = LFR_DEFAULT;
401 401 }
402 402 else {
403 403 status = LFR_SUCCESSFUL;
404 404 }
405 405 break;
406 406 default:
407 407 status = LFR_DEFAULT;
408 408 break;
409 409 }
410 410
411 411 return status;
412 412 }
413 413
414 414 int check_transition_date( unsigned int transitionCoarseTime )
415 415 {
416 416 int status;
417 417 unsigned int localCoarseTime;
418 418 unsigned int deltaCoarseTime;
419 419
420 420 status = LFR_SUCCESSFUL;
421 421
422 422 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
423 423 {
424 424 status = LFR_SUCCESSFUL;
425 425 }
426 426 else
427 427 {
428 428 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
429 429
430 430 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime)
431 431
432 432 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
433 433 {
434 434 status = LFR_DEFAULT;
435 435 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n")
436 436 }
437 437
438 438 if (status == LFR_SUCCESSFUL)
439 439 {
440 440 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
441 441 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
442 442 {
443 443 status = LFR_DEFAULT;
444 444 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
445 445 }
446 446 }
447 447 }
448 448
449 449 return status;
450 450 }
451 451
452 452 int stop_current_mode( void )
453 453 {
454 454 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
455 455 *
456 456 * @return RTEMS directive status codes:
457 457 * - RTEMS_SUCCESSFUL - task restarted successfully
458 458 * - RTEMS_INVALID_ID - task id invalid
459 459 * - RTEMS_ALREADY_SUSPENDED - task already suspended
460 460 *
461 461 */
462 462
463 463 rtems_status_code status;
464 464
465 465 status = RTEMS_SUCCESSFUL;
466 466
467 467 // (1) mask interruptions
468 468 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
469 469 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
470 470
471 471 // (2) reset waveform picker registers
472 472 reset_wfp_burst_enable(); // reset burst and enable bits
473 473 reset_wfp_status(); // reset all the status bits
474 474
475 475 // (3) reset spectral matrices registers
476 476 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
477 477 reset_sm_status();
478 478
479 479 // reset lfr VHDL module
480 480 reset_lfr();
481 481
482 482 reset_extractSWF(); // reset the extractSWF flag to false
483 483
484 484 // (4) clear interruptions
485 485 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
486 486 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
487 487
488 488 // <Spectral Matrices simulator>
489 489 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
490 490 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
491 491 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
492 492 // </Spectral Matrices simulator>
493 493
494 494 // suspend several tasks
495 495 if (lfrCurrentMode != LFR_MODE_STANDBY) {
496 496 status = suspend_science_tasks();
497 497 }
498 498
499 499 if (status != RTEMS_SUCCESSFUL)
500 500 {
501 501 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
502 502 }
503 503
504 504 return status;
505 505 }
506 506
507 507 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
508 508 {
509 509 /** This function is launched after a mode transition validation.
510 510 *
511 511 * @param mode is the mode in which LFR will be put.
512 512 *
513 513 * @return RTEMS directive status codes:
514 514 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
515 515 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
516 516 *
517 517 */
518 518
519 519 rtems_status_code status;
520 520
521 521 //**********************
522 522 // STOP THE CURRENT MODE
523 523 status = stop_current_mode();
524 524 if (status != RTEMS_SUCCESSFUL)
525 525 {
526 526 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
527 527 }
528 528
529 529 //*************************
530 530 // ENTER THE REQUESTED MODE
531 531 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
532 532 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
533 533 {
534 534 #ifdef PRINT_TASK_STATISTICS
535 535 rtems_cpu_usage_reset();
536 536 #endif
537 537 status = restart_science_tasks( mode );
538 538 launch_spectral_matrix( );
539 539 launch_waveform_picker( mode, transitionCoarseTime );
540 540 // launch_spectral_matrix_simu( );
541 541 }
542 542 else if ( mode == LFR_MODE_STANDBY )
543 543 {
544 544 #ifdef PRINT_TASK_STATISTICS
545 545 rtems_cpu_usage_report();
546 546 #endif
547 547
548 548 #ifdef PRINT_STACK_REPORT
549 549 PRINTF("stack report selected\n")
550 550 rtems_stack_checker_report_usage();
551 551 #endif
552 552 }
553 553 else
554 554 {
555 555 status = RTEMS_UNSATISFIED;
556 556 }
557 557
558 558 if (status != RTEMS_SUCCESSFUL)
559 559 {
560 560 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
561 561 status = RTEMS_UNSATISFIED;
562 562 }
563 563
564 564 return status;
565 565 }
566 566
567 567 int restart_science_tasks(unsigned char lfrRequestedMode )
568 568 {
569 569 /** This function is used to restart all science tasks.
570 570 *
571 571 * @return RTEMS directive status codes:
572 572 * - RTEMS_SUCCESSFUL - task restarted successfully
573 573 * - RTEMS_INVALID_ID - task id invalid
574 574 * - RTEMS_INCORRECT_STATE - task never started
575 575 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 576 *
577 577 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
578 578 *
579 579 */
580 580
581 581 rtems_status_code status[10];
582 582 rtems_status_code ret;
583 583
584 584 ret = RTEMS_SUCCESSFUL;
585 585
586 586 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
587 587 if (status[0] != RTEMS_SUCCESSFUL)
588 588 {
589 589 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
590 590 }
591 591
592 592 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
593 593 if (status[1] != RTEMS_SUCCESSFUL)
594 594 {
595 595 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
596 596 }
597 597
598 598 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 599 if (status[2] != RTEMS_SUCCESSFUL)
600 600 {
601 601 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
602 602 }
603 603
604 604 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 605 if (status[3] != RTEMS_SUCCESSFUL)
606 606 {
607 607 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
608 608 }
609 609
610 610 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 611 if (status[4] != RTEMS_SUCCESSFUL)
612 612 {
613 613 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
614 614 }
615 615
616 616 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 617 if (status[5] != RTEMS_SUCCESSFUL)
618 618 {
619 619 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
620 620 }
621 621
622 622 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
623 623 if (status[6] != RTEMS_SUCCESSFUL)
624 624 {
625 625 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
626 626 }
627 627
628 628 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
629 629 if (status[7] != RTEMS_SUCCESSFUL)
630 630 {
631 631 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
632 632 }
633 633
634 634 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
635 635 if (status[8] != RTEMS_SUCCESSFUL)
636 636 {
637 637 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
638 638 }
639 639
640 640 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
641 641 if (status[9] != RTEMS_SUCCESSFUL)
642 642 {
643 643 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
644 644 }
645 645
646 646 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
647 647 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
648 648 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
649 649 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
650 650 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
651 651 {
652 652 ret = RTEMS_UNSATISFIED;
653 653 }
654 654
655 655 return ret;
656 656 }
657 657
658 658 int suspend_science_tasks()
659 659 {
660 660 /** This function suspends the science tasks.
661 661 *
662 662 * @return RTEMS directive status codes:
663 663 * - RTEMS_SUCCESSFUL - task restarted successfully
664 664 * - RTEMS_INVALID_ID - task id invalid
665 665 * - RTEMS_ALREADY_SUSPENDED - task already suspended
666 666 *
667 667 */
668 668
669 669 rtems_status_code status;
670 670
671 671 printf("in suspend_science_tasks\n");
672 672
673 673 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
674 674 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
675 675 {
676 676 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
677 677 }
678 678 else
679 679 {
680 680 status = RTEMS_SUCCESSFUL;
681 681 }
682 682 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
683 683 {
684 684 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
685 685 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
686 686 {
687 687 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
688 688 }
689 689 else
690 690 {
691 691 status = RTEMS_SUCCESSFUL;
692 692 }
693 693 }
694 694 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
695 695 {
696 696 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
697 697 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
698 698 {
699 699 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
700 700 }
701 701 else
702 702 {
703 703 status = RTEMS_SUCCESSFUL;
704 704 }
705 705 }
706 706 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
707 707 {
708 708 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
709 709 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
710 710 {
711 711 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
712 712 }
713 713 else
714 714 {
715 715 status = RTEMS_SUCCESSFUL;
716 716 }
717 717 }
718 718 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
719 719 {
720 720 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
721 721 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
722 722 {
723 723 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
724 724 }
725 725 else
726 726 {
727 727 status = RTEMS_SUCCESSFUL;
728 728 }
729 729 }
730 730 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
731 731 {
732 732 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
733 733 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
734 734 {
735 735 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
736 736 }
737 737 else
738 738 {
739 739 status = RTEMS_SUCCESSFUL;
740 740 }
741 741 }
742 742 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
743 743 {
744 744 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
745 745 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
746 746 {
747 747 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
748 748 }
749 749 else
750 750 {
751 751 status = RTEMS_SUCCESSFUL;
752 752 }
753 753 }
754 754 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
755 755 {
756 756 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
757 757 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
758 758 {
759 759 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
760 760 }
761 761 else
762 762 {
763 763 status = RTEMS_SUCCESSFUL;
764 764 }
765 765 }
766 766 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
767 767 {
768 768 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
769 769 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
770 770 {
771 771 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
772 772 }
773 773 else
774 774 {
775 775 status = RTEMS_SUCCESSFUL;
776 776 }
777 777 }
778 778 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
779 779 {
780 780 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
781 781 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
782 782 {
783 783 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
784 784 }
785 785 else
786 786 {
787 787 status = RTEMS_SUCCESSFUL;
788 788 }
789 789 }
790 790
791 791 return status;
792 792 }
793 793
794 794 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
795 795 {
796 796 WFP_reset_current_ring_nodes();
797 797
798 798 reset_waveform_picker_regs();
799 799
800 800 set_wfp_burst_enable_register( mode );
801 801
802 802 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
803 803 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
804 804
805 805 if (transitionCoarseTime == 0)
806 806 {
807 807 waveform_picker_regs->start_date = time_management_regs->coarse_time;
808 808 }
809 809 else
810 810 {
811 811 waveform_picker_regs->start_date = transitionCoarseTime;
812 812 }
813 813
814 814 }
815 815
816 816 void launch_spectral_matrix( void )
817 817 {
818 818 SM_reset_current_ring_nodes();
819 819
820 820 reset_spectral_matrix_regs();
821 821
822 822 reset_nb_sm();
823 823
824 824 set_sm_irq_onNewMatrix( 1 );
825 825
826 826 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
827 827 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
828 828
829 829 }
830 830
831 831 void launch_spectral_matrix_simu( void )
832 832 {
833 833 SM_reset_current_ring_nodes();
834 834 reset_spectral_matrix_regs();
835 835 reset_nb_sm();
836 836
837 837 // Spectral Matrices simulator
838 838 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
839 839 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
840 840 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
841 841 }
842 842
843 843 void set_sm_irq_onNewMatrix( unsigned char value )
844 844 {
845 845 if (value == 1)
846 846 {
847 847 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
848 848 }
849 849 else
850 850 {
851 851 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
852 852 }
853 853 }
854 854
855 855 void set_sm_irq_onError( unsigned char value )
856 856 {
857 857 if (value == 1)
858 858 {
859 859 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
860 860 }
861 861 else
862 862 {
863 863 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
864 864 }
865 865 }
866 866
867 867 //*****************************
868 868 // CONFIGURE CALIBRATION SIGNAL
869 869 void setCalibrationPrescaler( unsigned int prescaler )
870 870 {
871 871 // prescaling of the master clock (25 MHz)
872 872 // master clock is divided by 2^prescaler
873 873 time_management_regs->calPrescaler = prescaler;
874 874 }
875 875
876 876 void setCalibrationDivisor( unsigned int divisionFactor )
877 877 {
878 878 // division of the prescaled clock by the division factor
879 879 time_management_regs->calDivisor = divisionFactor;
880 880 }
881 881
882 882 void setCalibrationData( void ){
883 883 unsigned int k;
884 884 unsigned short data;
885 885 float val;
886 886 float f0;
887 887 float f1;
888 888 float fs;
889 889 float Ts;
890 890 float scaleFactor;
891 891
892 892 f0 = 625;
893 893 f1 = 10000;
894 894 fs = 160256.410;
895 895 Ts = 1. / fs;
896 896 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
897 897
898 898 time_management_regs->calDataPtr = 0x00;
899 899
900 900 // build the signal for the SCM calibration
901 901 for (k=0; k<256; k++)
902 902 {
903 903 val = sin( 2 * pi * f0 * k * Ts )
904 904 + sin( 2 * pi * f1 * k * Ts );
905 905 data = (unsigned short) ((val * scaleFactor) + 2048);
906 906 time_management_regs->calData = data & 0xfff;
907 907 }
908 908 }
909 909
910 910 void setCalibrationDataInterleaved( void ){
911 911 unsigned int k;
912 912 float val;
913 913 float f0;
914 914 float f1;
915 915 float fs;
916 916 float Ts;
917 917 unsigned short data[384];
918 918 unsigned char *dataPtr;
919 919
920 920 f0 = 625;
921 921 f1 = 10000;
922 922 fs = 240384.615;
923 923 Ts = 1. / fs;
924 924
925 925 time_management_regs->calDataPtr = 0x00;
926 926
927 927 // build the signal for the SCM calibration
928 928 for (k=0; k<384; k++)
929 929 {
930 930 val = sin( 2 * pi * f0 * k * Ts )
931 931 + sin( 2 * pi * f1 * k * Ts );
932 932 data[k] = (unsigned short) (val * 512 + 2048);
933 933 }
934 934
935 935 // write the signal in interleaved mode
936 936 for (k=0; k<128; k++)
937 937 {
938 938 dataPtr = (unsigned char*) &data[k*3 + 2];
939 939 time_management_regs->calData = (data[k*3] & 0xfff)
940 940 + ( (dataPtr[0] & 0x3f) << 12);
941 941 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
942 942 + ( (dataPtr[1] & 0x3f) << 12);
943 943 }
944 944 }
945 945
946 946 void setCalibrationReload( bool state)
947 947 {
948 948 if (state == true)
949 949 {
950 950 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
951 951 }
952 952 else
953 953 {
954 954 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
955 955 }
956 956 }
957 957
958 958 void setCalibrationEnable( bool state )
959 959 {
960 960 // this bit drives the multiplexer
961 961 if (state == true)
962 962 {
963 963 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
964 964 }
965 965 else
966 966 {
967 967 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
968 968 }
969 969 }
970 970
971 971 void setCalibrationInterleaved( bool state )
972 972 {
973 973 // this bit drives the multiplexer
974 974 if (state == true)
975 975 {
976 976 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
977 977 }
978 978 else
979 979 {
980 980 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
981 981 }
982 982 }
983 983
984 void startCalibration( void )
984 void setCalibration( bool state )
985 {
986 if (state == true)
985 987 {
986 988 setCalibrationEnable( true );
987 989 setCalibrationReload( false );
990 set_hk_lfr_calib_enable( true );
988 991 }
989
990 void stopCalibration( void )
992 else
991 993 {
992 994 setCalibrationEnable( false );
993 995 setCalibrationReload( true );
996 set_hk_lfr_calib_enable( false );
997 }
998 }
999
1000 void set_hk_lfr_calib_enable( bool state )
1001 {
1002 if (state == true)
1003 {
1004 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
1005 }
1006 else
1007 {
1008 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
1009 }
994 1010 }
995 1011
996 1012 void configureCalibration( bool interleaved )
997 1013 {
998 stopCalibration();
1014 setCalibration( false );
999 1015 if ( interleaved == true )
1000 1016 {
1001 1017 setCalibrationInterleaved( true );
1002 1018 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1003 1019 setCalibrationDivisor( 26 ); // => 240 384
1004 1020 setCalibrationDataInterleaved();
1005 1021 }
1006 1022 else
1007 1023 {
1008 1024 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1009 1025 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1010 1026 setCalibrationData();
1011 1027 }
1012 1028 }
1013 1029
1014 1030 //****************
1015 1031 // CLOSING ACTIONS
1016 1032 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1017 1033 {
1018 1034 /** This function is used to update the HK packets statistics after a successful TC execution.
1019 1035 *
1020 1036 * @param TC points to the TC being processed
1021 1037 * @param time is the time used to date the TC execution
1022 1038 *
1023 1039 */
1024 1040
1025 1041 unsigned int val;
1026 1042
1027 1043 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1028 1044 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1029 1045 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1030 1046 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1031 1047 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1032 1048 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1033 1049 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1034 1050 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1035 1051 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1036 1052 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1037 1053 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1038 1054 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1039 1055
1040 1056 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1041 1057 val++;
1042 1058 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1043 1059 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1044 1060 }
1045 1061
1046 1062 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1047 1063 {
1048 1064 /** This function is used to update the HK packets statistics after a TC rejection.
1049 1065 *
1050 1066 * @param TC points to the TC being processed
1051 1067 * @param time is the time used to date the TC rejection
1052 1068 *
1053 1069 */
1054 1070
1055 1071 unsigned int val;
1056 1072
1057 1073 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1058 1074 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1059 1075 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1060 1076 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1061 1077 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1062 1078 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1063 1079 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1064 1080 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1065 1081 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1066 1082 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1067 1083 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1068 1084 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1069 1085
1070 1086 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1071 1087 val++;
1072 1088 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1073 1089 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1074 1090 }
1075 1091
1076 1092 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1077 1093 {
1078 1094 /** This function is the last step of the TC execution workflow.
1079 1095 *
1080 1096 * @param TC points to the TC being processed
1081 1097 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1082 1098 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1083 1099 * @param time is the time used to date the TC execution
1084 1100 *
1085 1101 */
1086 1102
1087 1103 unsigned char requestedMode;
1088 1104
1089 1105 if (result == LFR_SUCCESSFUL)
1090 1106 {
1091 1107 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1092 1108 &
1093 1109 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1094 1110 )
1095 1111 {
1096 1112 send_tm_lfr_tc_exe_success( TC, queue_id );
1097 1113 }
1098 1114 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1099 1115 {
1100 1116 //**********************************
1101 1117 // UPDATE THE LFRMODE LOCAL VARIABLE
1102 1118 requestedMode = TC->dataAndCRC[1];
1103 1119 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1104 1120 updateLFRCurrentMode();
1105 1121 }
1106 1122 }
1107 1123 else if (result == LFR_EXE_ERROR)
1108 1124 {
1109 1125 send_tm_lfr_tc_exe_error( TC, queue_id );
1110 1126 }
1111 1127 }
1112 1128
1113 1129 //***************************
1114 1130 // Interrupt Service Routines
1115 1131 rtems_isr commutation_isr1( rtems_vector_number vector )
1116 1132 {
1117 1133 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1118 1134 printf("In commutation_isr1 *** Error sending event to DUMB\n");
1119 1135 }
1120 1136 }
1121 1137
1122 1138 rtems_isr commutation_isr2( rtems_vector_number vector )
1123 1139 {
1124 1140 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1125 1141 printf("In commutation_isr2 *** Error sending event to DUMB\n");
1126 1142 }
1127 1143 }
1128 1144
1129 1145 //****************
1130 1146 // OTHER FUNCTIONS
1131 1147 void updateLFRCurrentMode()
1132 1148 {
1133 1149 /** This function updates the value of the global variable lfrCurrentMode.
1134 1150 *
1135 1151 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1136 1152 *
1137 1153 */
1138 1154 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1139 1155 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1140 1156 }
1141 1157
1142 1158 void set_lfr_soft_reset( unsigned char value )
1143 1159 {
1144 1160 if (value == 1)
1145 1161 {
1146 1162 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1147 1163 }
1148 1164 else
1149 1165 {
1150 1166 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1151 1167 }
1152 1168 }
1153 1169
1154 1170 void reset_lfr( void )
1155 1171 {
1156 1172 set_lfr_soft_reset( 1 );
1157 1173
1158 1174 set_lfr_soft_reset( 0 );
1159 1175 }
General Comments 0
You need to be logged in to leave comments. Login now