@@ -1,119 +1,120 | |||
|
1 | 1 | #ifndef TC_LOAD_DUMP_PARAMETERS_H |
|
2 | 2 | #define TC_LOAD_DUMP_PARAMETERS_H |
|
3 | 3 | |
|
4 | 4 | #include <rtems.h> |
|
5 | 5 | #include <stdio.h> |
|
6 | 6 | |
|
7 | 7 | #include "fsw_params.h" |
|
8 | 8 | #include "wf_handler.h" |
|
9 | 9 | #include "tm_lfr_tc_exe.h" |
|
10 | 10 | #include "fsw_misc.h" |
|
11 | 11 | #include "basic_parameters_params.h" |
|
12 | 12 | #include "avf0_prc0.h" |
|
13 | 13 | |
|
14 | 14 | #define FLOAT_EQUAL_ZERO 0.001 |
|
15 | 15 | #define NB_BINS_TO_REMOVE 3 |
|
16 | 16 | #define FI_INTERVAL_COEFF 0.285 |
|
17 | 17 | #define BIN_MIN 0 |
|
18 | 18 | #define BIN_MAX 127 |
|
19 | 19 | #define DELTAF_F0 96. |
|
20 | 20 | #define DELTAF_F1 16. |
|
21 | 21 | #define DELTAF_F2 1. |
|
22 | 22 | #define DELTAF_DIV 2. |
|
23 | 23 | |
|
24 | 24 | #define BIT_RW1_F1 0x80 |
|
25 | 25 | #define BIT_RW1_F2 0x40 |
|
26 | 26 | #define BIT_RW2_F1 0x20 |
|
27 | 27 | #define BIT_RW2_F2 0x10 |
|
28 | 28 | #define BIT_RW3_F1 0x08 |
|
29 | 29 | #define BIT_RW3_F2 0x04 |
|
30 | 30 | #define BIT_RW4_F1 0x02 |
|
31 | 31 | #define BIT_RW4_F2 0x01 |
|
32 | 32 | |
|
33 | 33 | #define WHEEL_1 1 |
|
34 | 34 | #define WHEEL_2 2 |
|
35 | 35 | #define WHEEL_3 3 |
|
36 | 36 | #define WHEEL_4 4 |
|
37 | 37 | #define FREQ_1 1 |
|
38 | 38 | #define FREQ_2 2 |
|
39 | 39 | #define FREQ_3 3 |
|
40 | 40 | #define FREQ_4 4 |
|
41 | 41 | #define FLAG_OFFSET_WHEELS_1_3 8 |
|
42 | 42 | #define FLAG_OFFSET_WHEELS_2_4 4 |
|
43 | 43 | |
|
44 | 44 | #define FLAG_NAN 0 // Not A NUMBER |
|
45 | 45 | #define FLAG_IAN 1 // Is A Number |
|
46 | 46 | |
|
47 | 47 | #define SBM_KCOEFF_PER_NORM_KCOEFF 2 |
|
48 | 48 | |
|
49 | 49 | extern unsigned short sequenceCounterParameterDump; |
|
50 | 50 | extern unsigned short sequenceCounters_TM_DUMP[]; |
|
51 | 51 | extern float k_coeff_intercalib_f0_norm[ ]; |
|
52 | 52 | extern float k_coeff_intercalib_f0_sbm[ ]; |
|
53 | 53 | extern float k_coeff_intercalib_f1_norm[ ]; |
|
54 | 54 | extern float k_coeff_intercalib_f1_sbm[ ]; |
|
55 | 55 | extern float k_coeff_intercalib_f2[ ]; |
|
56 | 56 | extern fbins_masks_t fbins_masks; |
|
57 | 57 | |
|
58 | 58 | int action_load_common_par( ccsdsTelecommandPacket_t *TC ); |
|
59 | 59 | int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
60 | 60 | int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
61 | 61 | int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
62 | 62 | int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
63 | 63 | int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
64 | 64 | int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
65 | 65 | int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
66 | 66 | int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
67 | 67 | int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
68 | 68 | |
|
69 | 69 | // NORMAL |
|
70 | 70 | int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
71 | 71 | int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ); |
|
72 | 72 | int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC ); |
|
73 | 73 | int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ); |
|
74 | 74 | int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
75 | 75 | int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
76 | 76 | int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC ); |
|
77 | 77 | |
|
78 | 78 | // BURST |
|
79 | 79 | int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
80 | 80 | int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
81 | 81 | |
|
82 | 82 | // SBM1 |
|
83 | 83 | int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
84 | 84 | int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
85 | 85 | |
|
86 | 86 | // SBM2 |
|
87 | 87 | int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
88 | 88 | int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
89 | 89 | |
|
90 | 90 | // TC_LFR_UPDATE_INFO |
|
91 | 91 | unsigned int check_update_info_hk_lfr_mode( unsigned char mode ); |
|
92 | 92 | unsigned int check_update_info_hk_tds_mode( unsigned char mode ); |
|
93 | 93 | unsigned int check_update_info_hk_thr_mode( unsigned char mode ); |
|
94 | 94 | void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value ); |
|
95 | 95 | void set_hk_lfr_sc_rw_f_flags( void ); |
|
96 | 96 | void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC ); |
|
97 | 97 | void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff ); |
|
98 | 98 | void build_sy_lfr_rw_mask( unsigned int channel ); |
|
99 | 99 | void build_sy_lfr_rw_masks(); |
|
100 | 100 | void merge_fbins_masks( void ); |
|
101 | 101 | |
|
102 | 102 | // FBINS_MASK |
|
103 | 103 | int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC ); |
|
104 | 104 | |
|
105 | 105 | // TC_LFR_LOAD_PARS_FILTER_PAR |
|
106 | 106 | int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
107 | 107 | |
|
108 | 108 | // KCOEFFICIENTS |
|
109 | 109 | int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id); |
|
110 | 110 | void copyFloatByChar( unsigned char *destination, unsigned char *source ); |
|
111 | 111 | void copyInt32ByChar( unsigned char *destination, unsigned char *source ); |
|
112 | void copyInt16ByChar( unsigned char *destination, unsigned char *source ); | |
|
112 | 113 | void floatToChar( float value, unsigned char* ptr); |
|
113 | 114 | |
|
114 | 115 | void init_parameter_dump( void ); |
|
115 | 116 | void init_kcoefficients_dump( void ); |
|
116 | 117 | void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr ); |
|
117 | 118 | void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id ); |
|
118 | 119 | |
|
119 | 120 | #endif // TC_LOAD_DUMP_PARAMETERS_H |
@@ -1,1005 +1,1005 | |||
|
1 | 1 | /** General usage functions and RTEMS tasks. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | */ |
|
7 | 7 | |
|
8 | 8 | #include "fsw_misc.h" |
|
9 | 9 | |
|
10 | 10 | int16_t hk_lfr_sc_v_f3_as_int16 = 0; |
|
11 | 11 | int16_t hk_lfr_sc_e1_f3_as_int16 = 0; |
|
12 | 12 | int16_t hk_lfr_sc_e2_f3_as_int16 = 0; |
|
13 | 13 | |
|
14 | 14 | void timer_configure(unsigned char timer, unsigned int clock_divider, |
|
15 | 15 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
16 | 16 | { |
|
17 | 17 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
18 | 18 | * |
|
19 | 19 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
20 | 20 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
21 | 21 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
22 | 22 | * @param interrupt_level is the interrupt level that the timer drives. |
|
23 | 23 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
24 | 24 | * |
|
25 | 25 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
26 | 26 | * |
|
27 | 27 | */ |
|
28 | 28 | |
|
29 | 29 | rtems_status_code status; |
|
30 | 30 | rtems_isr_entry old_isr_handler; |
|
31 | 31 | |
|
32 | 32 | old_isr_handler = NULL; |
|
33 | 33 | |
|
34 | 34 | gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register |
|
35 | 35 | |
|
36 | 36 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
37 | 37 | if (status!=RTEMS_SUCCESSFUL) |
|
38 | 38 | { |
|
39 | 39 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | timer_set_clock_divider( timer, clock_divider); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | void timer_start(unsigned char timer) |
|
46 | 46 | { |
|
47 | 47 | /** This function starts a GPTIMER timer. |
|
48 | 48 | * |
|
49 | 49 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
50 | 50 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
51 | 51 | * |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; |
|
55 | 55 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD; |
|
56 | 56 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN; |
|
57 | 57 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS; |
|
58 | 58 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE; |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | void timer_stop(unsigned char timer) |
|
62 | 62 | { |
|
63 | 63 | /** This function stops a GPTIMER timer. |
|
64 | 64 | * |
|
65 | 65 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
66 | 66 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
67 | 67 | * |
|
68 | 68 | */ |
|
69 | 69 | |
|
70 | 70 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK; |
|
71 | 71 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK; |
|
72 | 72 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider) |
|
76 | 76 | { |
|
77 | 77 | /** This function sets the clock divider of a GPTIMER timer. |
|
78 | 78 | * |
|
79 | 79 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
80 | 80 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
81 | 81 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
82 | 82 | * |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | // WATCHDOG |
|
89 | 89 | |
|
90 | 90 | rtems_isr watchdog_isr( rtems_vector_number vector ) |
|
91 | 91 | { |
|
92 | 92 | rtems_status_code status_code; |
|
93 | 93 | |
|
94 | 94 | status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 ); |
|
95 | 95 | |
|
96 | 96 | PRINTF("watchdog_isr *** this is the end, exit(0)\n"); |
|
97 | 97 | |
|
98 | 98 | exit(0); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void watchdog_configure(void) |
|
102 | 102 | { |
|
103 | 103 | /** This function configure the watchdog. |
|
104 | 104 | * |
|
105 | 105 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
106 | 106 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
107 | 107 | * |
|
108 | 108 | * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB. |
|
109 | 109 | * |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration |
|
113 | 113 | |
|
114 | 114 | timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr ); |
|
115 | 115 | |
|
116 | 116 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | void watchdog_stop(void) |
|
120 | 120 | { |
|
121 | 121 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line |
|
122 | 122 | timer_stop( TIMER_WATCHDOG ); |
|
123 | 123 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void watchdog_reload(void) |
|
127 | 127 | { |
|
128 | 128 | /** This function reloads the watchdog timer counter with the timer reload value. |
|
129 | 129 | * |
|
130 | 130 | * @param void |
|
131 | 131 | * |
|
132 | 132 | * @return void |
|
133 | 133 | * |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | void watchdog_start(void) |
|
140 | 140 | { |
|
141 | 141 | /** This function starts the watchdog timer. |
|
142 | 142 | * |
|
143 | 143 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
144 | 144 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
145 | 145 | * |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
149 | 149 | |
|
150 | 150 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ; |
|
151 | 151 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; |
|
152 | 152 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN; |
|
153 | 153 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE; |
|
154 | 154 | |
|
155 | 155 | LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
156 | 156 | |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
160 | 160 | { |
|
161 | 161 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
162 | 162 | |
|
163 | 163 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
164 | 164 | |
|
165 | 165 | return 0; |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
169 | 169 | { |
|
170 | 170 | /** This function sets the scaler reload register of the apbuart module |
|
171 | 171 | * |
|
172 | 172 | * @param regs is the address of the apbuart registers in memory |
|
173 | 173 | * @param value is the value that will be stored in the scaler register |
|
174 | 174 | * |
|
175 | 175 | * The value shall be set by the software to get data on the serial interface. |
|
176 | 176 | * |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
180 | 180 | |
|
181 | 181 | apbuart_regs->scaler = value; |
|
182 | 182 | |
|
183 | 183 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | //************ |
|
187 | 187 | // RTEMS TASKS |
|
188 | 188 | |
|
189 | 189 | rtems_task load_task(rtems_task_argument argument) |
|
190 | 190 | { |
|
191 | 191 | BOOT_PRINTF("in LOAD *** \n") |
|
192 | 192 | |
|
193 | 193 | rtems_status_code status; |
|
194 | 194 | unsigned int i; |
|
195 | 195 | unsigned int j; |
|
196 | 196 | rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic |
|
197 | 197 | rtems_id watchdog_period_id; // id of the watchdog rate monotonic period |
|
198 | 198 | |
|
199 | 199 | watchdog_period_id = RTEMS_ID_NONE; |
|
200 | 200 | |
|
201 | 201 | name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
202 | 202 | |
|
203 | 203 | status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id ); |
|
204 | 204 | if( status != RTEMS_SUCCESSFUL ) { |
|
205 | 205 | PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | i = 0; |
|
209 | 209 | j = 0; |
|
210 | 210 | |
|
211 | 211 | watchdog_configure(); |
|
212 | 212 | |
|
213 | 213 | watchdog_start(); |
|
214 | 214 | |
|
215 | 215 | set_sy_lfr_watchdog_enabled( true ); |
|
216 | 216 | |
|
217 | 217 | while(1){ |
|
218 | 218 | status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD ); |
|
219 | 219 | watchdog_reload(); |
|
220 | 220 | i = i + 1; |
|
221 | 221 | if ( i == WATCHDOG_LOOP_PRINTF ) |
|
222 | 222 | { |
|
223 | 223 | i = 0; |
|
224 | 224 | j = j + 1; |
|
225 | 225 | PRINTF1("%d\n", j) |
|
226 | 226 | } |
|
227 | 227 | #ifdef DEBUG_WATCHDOG |
|
228 | 228 | if (j == WATCHDOG_LOOP_DEBUG ) |
|
229 | 229 | { |
|
230 | 230 | status = rtems_task_delete(RTEMS_SELF); |
|
231 | 231 | } |
|
232 | 232 | #endif |
|
233 | 233 | } |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | rtems_task hous_task(rtems_task_argument argument) |
|
237 | 237 | { |
|
238 | 238 | rtems_status_code status; |
|
239 | 239 | rtems_status_code spare_status; |
|
240 | 240 | rtems_id queue_id; |
|
241 | 241 | rtems_rate_monotonic_period_status period_status; |
|
242 | 242 | bool isSynchronized; |
|
243 | 243 | |
|
244 | 244 | queue_id = RTEMS_ID_NONE; |
|
245 | 245 | memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status)); |
|
246 | 246 | isSynchronized = false; |
|
247 | 247 | |
|
248 | 248 | status = get_message_queue_id_send( &queue_id ); |
|
249 | 249 | if (status != RTEMS_SUCCESSFUL) |
|
250 | 250 | { |
|
251 | 251 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | BOOT_PRINTF("in HOUS ***\n"); |
|
255 | 255 | |
|
256 | 256 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
257 | 257 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
258 | 258 | if( status != RTEMS_SUCCESSFUL ) { |
|
259 | 259 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
260 | 260 | } |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | status = rtems_rate_monotonic_cancel(HK_id); |
|
264 | 264 | if( status != RTEMS_SUCCESSFUL ) { |
|
265 | 265 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ); |
|
266 | 266 | } |
|
267 | 267 | else { |
|
268 | 268 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n"); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | // startup phase |
|
272 | 272 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
273 | 273 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
274 | 274 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
275 | 275 | while( (period_status.state != RATE_MONOTONIC_EXPIRED) |
|
276 | 276 | && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
277 | 277 | { |
|
278 | 278 | if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization |
|
279 | 279 | { |
|
280 | 280 | isSynchronized = true; |
|
281 | 281 | } |
|
282 | 282 | else |
|
283 | 283 | { |
|
284 | 284 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
285 | 285 | |
|
286 | 286 | status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms |
|
287 | 287 | } |
|
288 | 288 | } |
|
289 | 289 | status = rtems_rate_monotonic_cancel(HK_id); |
|
290 | 290 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
291 | 291 | |
|
292 | 292 | set_hk_lfr_reset_cause( POWER_ON ); |
|
293 | 293 | |
|
294 | 294 | while(1){ // launch the rate monotonic task |
|
295 | 295 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
296 | 296 | if ( status != RTEMS_SUCCESSFUL ) { |
|
297 | 297 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
298 | 298 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
299 | 299 | } |
|
300 | 300 | else { |
|
301 | 301 | housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE); |
|
302 | 302 | housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK ); |
|
303 | 303 | increment_seq_counter( &sequenceCounterHK ); |
|
304 | 304 | |
|
305 | 305 | housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
306 | 306 | housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
307 | 307 | housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
308 | 308 | housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
309 | 309 | housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
310 | 310 | housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
311 | 311 | |
|
312 | 312 | spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] ); |
|
313 | 313 | |
|
314 | 314 | spacewire_read_statistics(); |
|
315 | 315 | |
|
316 | 316 | update_hk_with_grspw_stats(); |
|
317 | 317 | |
|
318 | 318 | set_hk_lfr_time_not_synchro(); |
|
319 | 319 | |
|
320 | 320 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
321 | 321 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
322 | 322 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
323 | 323 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
324 | 324 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
325 | 325 | |
|
326 | 326 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
327 | 327 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
328 | 328 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
329 | 329 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
330 | 330 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
331 | 331 | |
|
332 | 332 | hk_lfr_le_me_he_update(); |
|
333 | 333 | |
|
334 | 334 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = cp_rpw_sc_rw1_rw2_f_flags; |
|
335 | 335 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = cp_rpw_sc_rw3_rw4_f_flags; |
|
336 | 336 | |
|
337 | 337 | // SEND PACKET |
|
338 | 338 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
339 | 339 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
340 | 340 | if (status != RTEMS_SUCCESSFUL) { |
|
341 | 341 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
342 | 342 | } |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | PRINTF("in HOUS *** deleting task\n") |
|
347 | 347 | |
|
348 | 348 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
349 | 349 | |
|
350 | 350 | return; |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | rtems_task avgv_task(rtems_task_argument argument) |
|
354 | 354 | { |
|
355 | 355 | #define MOVING_AVERAGE 16 |
|
356 | 356 | rtems_status_code status; |
|
357 | 357 | static unsigned int v[MOVING_AVERAGE] = {0}; |
|
358 | 358 | static unsigned int e1[MOVING_AVERAGE] = {0}; |
|
359 | 359 | static unsigned int e2[MOVING_AVERAGE] = {0}; |
|
360 | 360 | float average_v; |
|
361 | 361 | float average_e1; |
|
362 | 362 | float average_e2; |
|
363 | 363 | float newValue_v; |
|
364 | 364 | float newValue_e1; |
|
365 | 365 | float newValue_e2; |
|
366 | 366 | unsigned char k; |
|
367 | 367 | unsigned char indexOfOldValue; |
|
368 | 368 | |
|
369 | 369 | BOOT_PRINTF("in AVGV ***\n"); |
|
370 | 370 | |
|
371 | 371 | if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
372 | 372 | status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id ); |
|
373 | 373 | if( status != RTEMS_SUCCESSFUL ) { |
|
374 | 374 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
375 | 375 | } |
|
376 | 376 | } |
|
377 | 377 | |
|
378 | 378 | status = rtems_rate_monotonic_cancel(AVGV_id); |
|
379 | 379 | if( status != RTEMS_SUCCESSFUL ) { |
|
380 | 380 | PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status ); |
|
381 | 381 | } |
|
382 | 382 | else { |
|
383 | 383 | DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n"); |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | // initialize values |
|
387 | 387 | indexOfOldValue = MOVING_AVERAGE - 1; |
|
388 | 388 | average_v = INIT_FLOAT; |
|
389 | 389 | average_e1 = INIT_FLOAT; |
|
390 | 390 | average_e2 = INIT_FLOAT; |
|
391 | 391 | newValue_v = INIT_FLOAT; |
|
392 | 392 | newValue_e1 = INIT_FLOAT; |
|
393 | 393 | newValue_e2 = INIT_FLOAT; |
|
394 | 394 | |
|
395 | 395 | k = INIT_CHAR; |
|
396 | 396 | |
|
397 | 397 | while(1) |
|
398 | 398 | { // launch the rate monotonic task |
|
399 | 399 | status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD ); |
|
400 | 400 | if ( status != RTEMS_SUCCESSFUL ) |
|
401 | 401 | { |
|
402 | 402 | PRINTF1( "in AVGV *** ERR period: %d\n", status); |
|
403 | 403 | } |
|
404 | 404 | else |
|
405 | 405 | { |
|
406 | 406 | // get new values |
|
407 | 407 | newValue_v = waveform_picker_regs->v; |
|
408 | 408 | newValue_e1 = waveform_picker_regs->e1; |
|
409 | 409 | newValue_e2 = waveform_picker_regs->e2; |
|
410 | 410 | |
|
411 | 411 | // compute the moving average |
|
412 | 412 | average_v = average_v + newValue_v - v[k]; |
|
413 | 413 | average_e1 = average_e1 + newValue_e1 - e1[k]; |
|
414 | 414 | average_e2 = average_e2 + newValue_e2 - e2[k]; |
|
415 | 415 | |
|
416 | 416 | // store new values in buffers |
|
417 | 417 | v[k] = newValue_v; |
|
418 | 418 | e1[k] = newValue_e1; |
|
419 | 419 | e2[k] = newValue_e2; |
|
420 | 420 | } |
|
421 | 421 | if (k == (MOVING_AVERAGE-1)) |
|
422 | 422 | { |
|
423 | 423 | k = 0; |
|
424 |
|
|
|
424 | PRINTF("tick\n"); | |
|
425 | 425 | } |
|
426 | 426 | else |
|
427 | 427 | { |
|
428 | 428 | k++; |
|
429 | 429 | } |
|
430 | 430 | //update int16 values |
|
431 | 431 | hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / ((float) MOVING_AVERAGE) ); |
|
432 | 432 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / ((float) MOVING_AVERAGE) ); |
|
433 | 433 | hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / ((float) MOVING_AVERAGE) ); |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | PRINTF("in AVGV *** deleting task\n"); |
|
437 | 437 | |
|
438 | 438 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
439 | 439 | |
|
440 | 440 | return; |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | rtems_task dumb_task( rtems_task_argument unused ) |
|
444 | 444 | { |
|
445 | 445 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
446 | 446 | * |
|
447 | 447 | * @param unused is the starting argument of the RTEMS task |
|
448 | 448 | * |
|
449 | 449 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
450 | 450 | * |
|
451 | 451 | */ |
|
452 | 452 | |
|
453 | 453 | unsigned int i; |
|
454 | 454 | unsigned int intEventOut; |
|
455 | 455 | unsigned int coarse_time = 0; |
|
456 | 456 | unsigned int fine_time = 0; |
|
457 | 457 | rtems_event_set event_out; |
|
458 | 458 | |
|
459 | 459 | event_out = EVENT_SETS_NONE_PENDING; |
|
460 | 460 | |
|
461 | 461 | BOOT_PRINTF("in DUMB *** \n") |
|
462 | 462 | |
|
463 | 463 | while(1){ |
|
464 | 464 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
465 | 465 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
466 | 466 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13 |
|
467 | 467 | | RTEMS_EVENT_14, |
|
468 | 468 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
469 | 469 | intEventOut = (unsigned int) event_out; |
|
470 | 470 | for ( i=0; i<NB_RTEMS_EVENTS; i++) |
|
471 | 471 | { |
|
472 | 472 | if ( ((intEventOut >> i) & 1) != 0) |
|
473 | 473 | { |
|
474 | 474 | coarse_time = time_management_regs->coarse_time; |
|
475 | 475 | fine_time = time_management_regs->fine_time; |
|
476 | 476 | if (i==EVENT_12) |
|
477 | 477 | { |
|
478 | 478 | PRINTF1("%s\n", DUMB_MESSAGE_12) |
|
479 | 479 | } |
|
480 | 480 | if (i==EVENT_13) |
|
481 | 481 | { |
|
482 | 482 | PRINTF1("%s\n", DUMB_MESSAGE_13) |
|
483 | 483 | } |
|
484 | 484 | if (i==EVENT_14) |
|
485 | 485 | { |
|
486 | 486 | PRINTF1("%s\n", DUMB_MESSAGE_1) |
|
487 | 487 | } |
|
488 | 488 | } |
|
489 | 489 | } |
|
490 | 490 | } |
|
491 | 491 | } |
|
492 | 492 | |
|
493 | 493 | //***************************** |
|
494 | 494 | // init housekeeping parameters |
|
495 | 495 | |
|
496 | 496 | void init_housekeeping_parameters( void ) |
|
497 | 497 | { |
|
498 | 498 | /** This function initialize the housekeeping_packet global variable with default values. |
|
499 | 499 | * |
|
500 | 500 | */ |
|
501 | 501 | |
|
502 | 502 | unsigned int i = 0; |
|
503 | 503 | unsigned char *parameters; |
|
504 | 504 | unsigned char sizeOfHK; |
|
505 | 505 | |
|
506 | 506 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
507 | 507 | |
|
508 | 508 | parameters = (unsigned char*) &housekeeping_packet; |
|
509 | 509 | |
|
510 | 510 | for(i = 0; i< sizeOfHK; i++) |
|
511 | 511 | { |
|
512 | 512 | parameters[i] = INIT_CHAR; |
|
513 | 513 | } |
|
514 | 514 | |
|
515 | 515 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
516 | 516 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
517 | 517 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
518 | 518 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
519 | 519 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
520 | 520 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
521 | 521 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
522 | 522 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
523 | 523 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
524 | 524 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
525 | 525 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
526 | 526 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
527 | 527 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
528 | 528 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
529 | 529 | housekeeping_packet.sid = SID_HK; |
|
530 | 530 | |
|
531 | 531 | // init status word |
|
532 | 532 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
533 | 533 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
534 | 534 | // init software version |
|
535 | 535 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
536 | 536 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
537 | 537 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
538 | 538 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
539 | 539 | // init fpga version |
|
540 | 540 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
541 | 541 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
542 | 542 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
543 | 543 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
544 | 544 | |
|
545 | 545 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
546 | 546 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
547 | 547 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
548 | 548 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
549 | 549 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
550 | 550 | } |
|
551 | 551 | |
|
552 | 552 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
553 | 553 | { |
|
554 | 554 | /** This function increment the sequence counter passes in argument. |
|
555 | 555 | * |
|
556 | 556 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
557 | 557 | * |
|
558 | 558 | */ |
|
559 | 559 | |
|
560 | 560 | unsigned short segmentation_grouping_flag; |
|
561 | 561 | unsigned short sequence_cnt; |
|
562 | 562 | |
|
563 | 563 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 |
|
564 | 564 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] |
|
565 | 565 | |
|
566 | 566 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
567 | 567 | { |
|
568 | 568 | sequence_cnt = sequence_cnt + 1; |
|
569 | 569 | } |
|
570 | 570 | else |
|
571 | 571 | { |
|
572 | 572 | sequence_cnt = 0; |
|
573 | 573 | } |
|
574 | 574 | |
|
575 | 575 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
576 | 576 | } |
|
577 | 577 | |
|
578 | 578 | void getTime( unsigned char *time) |
|
579 | 579 | { |
|
580 | 580 | /** This function write the current local time in the time buffer passed in argument. |
|
581 | 581 | * |
|
582 | 582 | */ |
|
583 | 583 | |
|
584 | 584 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); |
|
585 | 585 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); |
|
586 | 586 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); |
|
587 | 587 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
588 | 588 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); |
|
589 | 589 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
593 | 593 | { |
|
594 | 594 | /** This function write the current local time in the time buffer passed in argument. |
|
595 | 595 | * |
|
596 | 596 | */ |
|
597 | 597 | unsigned long long int time; |
|
598 | 598 | |
|
599 | 599 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) |
|
600 | 600 | + time_management_regs->fine_time; |
|
601 | 601 | |
|
602 | 602 | return time; |
|
603 | 603 | } |
|
604 | 604 | |
|
605 | 605 | void send_dumb_hk( void ) |
|
606 | 606 | { |
|
607 | 607 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
608 | 608 | unsigned char *parameters; |
|
609 | 609 | unsigned int i; |
|
610 | 610 | rtems_id queue_id; |
|
611 | 611 | |
|
612 | 612 | queue_id = RTEMS_ID_NONE; |
|
613 | 613 | |
|
614 | 614 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
615 | 615 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
616 | 616 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
617 | 617 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
618 | 618 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
619 | 619 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
620 | 620 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
621 | 621 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
622 | 622 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
623 | 623 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
624 | 624 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
625 | 625 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
626 | 626 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
627 | 627 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
628 | 628 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
629 | 629 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
630 | 630 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
631 | 631 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
632 | 632 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
633 | 633 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
634 | 634 | dummy_hk_packet.sid = SID_HK; |
|
635 | 635 | |
|
636 | 636 | // init status word |
|
637 | 637 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; |
|
638 | 638 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; |
|
639 | 639 | // init software version |
|
640 | 640 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
641 | 641 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
642 | 642 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
643 | 643 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
644 | 644 | // init fpga version |
|
645 | 645 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); |
|
646 | 646 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
647 | 647 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
648 | 648 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
649 | 649 | |
|
650 | 650 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
651 | 651 | |
|
652 | 652 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) |
|
653 | 653 | { |
|
654 | 654 | parameters[i] = INT8_ALL_F; |
|
655 | 655 | } |
|
656 | 656 | |
|
657 | 657 | get_message_queue_id_send( &queue_id ); |
|
658 | 658 | |
|
659 | 659 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
660 | 660 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
661 | 661 | } |
|
662 | 662 | |
|
663 | 663 | void get_temperatures( unsigned char *temperatures ) |
|
664 | 664 | { |
|
665 | 665 | unsigned char* temp_scm_ptr; |
|
666 | 666 | unsigned char* temp_pcb_ptr; |
|
667 | 667 | unsigned char* temp_fpga_ptr; |
|
668 | 668 | |
|
669 | 669 | // SEL1 SEL0 |
|
670 | 670 | // 0 0 => PCB |
|
671 | 671 | // 0 1 => FPGA |
|
672 | 672 | // 1 0 => SCM |
|
673 | 673 | |
|
674 | 674 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
675 | 675 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
676 | 676 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
677 | 677 | |
|
678 | 678 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; |
|
679 | 679 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; |
|
680 | 680 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; |
|
681 | 681 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; |
|
682 | 682 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; |
|
683 | 683 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; |
|
684 | 684 | } |
|
685 | 685 | |
|
686 | 686 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
687 | 687 | { |
|
688 | 688 | unsigned char* v_ptr; |
|
689 | 689 | unsigned char* e1_ptr; |
|
690 | 690 | unsigned char* e2_ptr; |
|
691 | 691 | |
|
692 | 692 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; |
|
693 | 693 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; |
|
694 | 694 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; |
|
695 | 695 | |
|
696 | 696 | spacecraft_potential[BYTE_0] = v_ptr[0]; |
|
697 | 697 | spacecraft_potential[BYTE_1] = v_ptr[1]; |
|
698 | 698 | spacecraft_potential[BYTE_2] = e1_ptr[0]; |
|
699 | 699 | spacecraft_potential[BYTE_3] = e1_ptr[1]; |
|
700 | 700 | spacecraft_potential[BYTE_4] = e2_ptr[0]; |
|
701 | 701 | spacecraft_potential[BYTE_5] = e2_ptr[1]; |
|
702 | 702 | } |
|
703 | 703 | |
|
704 | 704 | void get_cpu_load( unsigned char *resource_statistics ) |
|
705 | 705 | { |
|
706 | 706 | unsigned char cpu_load; |
|
707 | 707 | |
|
708 | 708 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
709 | 709 | |
|
710 | 710 | // HK_LFR_CPU_LOAD |
|
711 | 711 | resource_statistics[0] = cpu_load; |
|
712 | 712 | |
|
713 | 713 | // HK_LFR_CPU_LOAD_MAX |
|
714 | 714 | if (cpu_load > resource_statistics[1]) |
|
715 | 715 | { |
|
716 | 716 | resource_statistics[1] = cpu_load; |
|
717 | 717 | } |
|
718 | 718 | |
|
719 | 719 | // CPU_LOAD_AVE |
|
720 | 720 | resource_statistics[BYTE_2] = 0; |
|
721 | 721 | |
|
722 | 722 | #ifndef PRINT_TASK_STATISTICS |
|
723 | 723 | rtems_cpu_usage_reset(); |
|
724 | 724 | #endif |
|
725 | 725 | |
|
726 | 726 | } |
|
727 | 727 | |
|
728 | 728 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
729 | 729 | { |
|
730 | 730 | if (state == true) |
|
731 | 731 | { |
|
732 | 732 | housekeeping_packet.lfr_status_word[1] = |
|
733 | 733 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] |
|
734 | 734 | } |
|
735 | 735 | else |
|
736 | 736 | { |
|
737 | 737 | housekeeping_packet.lfr_status_word[1] = |
|
738 | 738 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] |
|
739 | 739 | } |
|
740 | 740 | } |
|
741 | 741 | |
|
742 | 742 | void set_sy_lfr_pas_filter_enabled( bool state ) |
|
743 | 743 | { |
|
744 | 744 | if (state == true) |
|
745 | 745 | { |
|
746 | 746 | housekeeping_packet.lfr_status_word[1] = |
|
747 | 747 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000] |
|
748 | 748 | } |
|
749 | 749 | else |
|
750 | 750 | { |
|
751 | 751 | housekeeping_packet.lfr_status_word[1] = |
|
752 | 752 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111] |
|
753 | 753 | } |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | void set_sy_lfr_watchdog_enabled( bool state ) |
|
757 | 757 | { |
|
758 | 758 | if (state == true) |
|
759 | 759 | { |
|
760 | 760 | housekeeping_packet.lfr_status_word[1] = |
|
761 | 761 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] |
|
762 | 762 | } |
|
763 | 763 | else |
|
764 | 764 | { |
|
765 | 765 | housekeeping_packet.lfr_status_word[1] = |
|
766 | 766 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] |
|
767 | 767 | } |
|
768 | 768 | } |
|
769 | 769 | |
|
770 | 770 | void set_hk_lfr_calib_enable( bool state ) |
|
771 | 771 | { |
|
772 | 772 | if (state == true) |
|
773 | 773 | { |
|
774 | 774 | housekeeping_packet.lfr_status_word[1] = |
|
775 | 775 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] |
|
776 | 776 | } |
|
777 | 777 | else |
|
778 | 778 | { |
|
779 | 779 | housekeeping_packet.lfr_status_word[1] = |
|
780 | 780 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] |
|
781 | 781 | } |
|
782 | 782 | } |
|
783 | 783 | |
|
784 | 784 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
785 | 785 | { |
|
786 | 786 | housekeeping_packet.lfr_status_word[1] = |
|
787 | 787 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] |
|
788 | 788 | |
|
789 | 789 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
790 | 790 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] |
|
791 | 791 | |
|
792 | 792 | } |
|
793 | 793 | |
|
794 | 794 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) |
|
795 | 795 | { |
|
796 | 796 | int delta; |
|
797 | 797 | |
|
798 | 798 | delta = 0; |
|
799 | 799 | |
|
800 | 800 | if (newValue >= oldValue) |
|
801 | 801 | { |
|
802 | 802 | delta = newValue - oldValue; |
|
803 | 803 | } |
|
804 | 804 | else |
|
805 | 805 | { |
|
806 | 806 | delta = (255 - oldValue) + newValue; |
|
807 | 807 | } |
|
808 | 808 | |
|
809 | 809 | *counter = *counter + delta; |
|
810 | 810 | } |
|
811 | 811 | |
|
812 | 812 | void hk_lfr_le_update( void ) |
|
813 | 813 | { |
|
814 | 814 | static hk_lfr_le_t old_hk_lfr_le = {0}; |
|
815 | 815 | hk_lfr_le_t new_hk_lfr_le; |
|
816 | 816 | unsigned int counter; |
|
817 | 817 | |
|
818 | 818 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1]; |
|
819 | 819 | |
|
820 | 820 | // DPU |
|
821 | 821 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; |
|
822 | 822 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; |
|
823 | 823 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; |
|
824 | 824 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; |
|
825 | 825 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; |
|
826 | 826 | // TIMECODE |
|
827 | 827 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; |
|
828 | 828 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; |
|
829 | 829 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; |
|
830 | 830 | // TIME |
|
831 | 831 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; |
|
832 | 832 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; |
|
833 | 833 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; |
|
834 | 834 | //AHB |
|
835 | 835 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; |
|
836 | 836 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
837 | 837 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
838 | 838 | |
|
839 | 839 | // update the le counter |
|
840 | 840 | // DPU |
|
841 | 841 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); |
|
842 | 842 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); |
|
843 | 843 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); |
|
844 | 844 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); |
|
845 | 845 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); |
|
846 | 846 | // TIMECODE |
|
847 | 847 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); |
|
848 | 848 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); |
|
849 | 849 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); |
|
850 | 850 | // TIME |
|
851 | 851 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); |
|
852 | 852 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); |
|
853 | 853 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); |
|
854 | 854 | // AHB |
|
855 | 855 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); |
|
856 | 856 | |
|
857 | 857 | // DPU |
|
858 | 858 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; |
|
859 | 859 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; |
|
860 | 860 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; |
|
861 | 861 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; |
|
862 | 862 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; |
|
863 | 863 | // TIMECODE |
|
864 | 864 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; |
|
865 | 865 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; |
|
866 | 866 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; |
|
867 | 867 | // TIME |
|
868 | 868 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; |
|
869 | 869 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; |
|
870 | 870 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; |
|
871 | 871 | //AHB |
|
872 | 872 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; |
|
873 | 873 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
874 | 874 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
875 | 875 | |
|
876 | 876 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
877 | 877 | // LE |
|
878 | 878 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
879 | 879 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
880 | 880 | } |
|
881 | 881 | |
|
882 | 882 | void hk_lfr_me_update( void ) |
|
883 | 883 | { |
|
884 | 884 | static hk_lfr_me_t old_hk_lfr_me = {0}; |
|
885 | 885 | hk_lfr_me_t new_hk_lfr_me; |
|
886 | 886 | unsigned int counter; |
|
887 | 887 | |
|
888 | 888 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1]; |
|
889 | 889 | |
|
890 | 890 | // get the current values |
|
891 | 891 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; |
|
892 | 892 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; |
|
893 | 893 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; |
|
894 | 894 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; |
|
895 | 895 | |
|
896 | 896 | // update the me counter |
|
897 | 897 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); |
|
898 | 898 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); |
|
899 | 899 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); |
|
900 | 900 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); |
|
901 | 901 | |
|
902 | 902 | // store the counters for the next time |
|
903 | 903 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; |
|
904 | 904 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; |
|
905 | 905 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; |
|
906 | 906 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; |
|
907 | 907 | |
|
908 | 908 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
909 | 909 | // ME |
|
910 | 910 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
911 | 911 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
912 | 912 | } |
|
913 | 913 | |
|
914 | 914 | void hk_lfr_le_me_he_update() |
|
915 | 915 | { |
|
916 | 916 | |
|
917 | 917 | unsigned int hk_lfr_he_cnt; |
|
918 | 918 | |
|
919 | 919 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; |
|
920 | 920 | |
|
921 | 921 | //update the low severity error counter |
|
922 | 922 | hk_lfr_le_update( ); |
|
923 | 923 | |
|
924 | 924 | //update the medium severity error counter |
|
925 | 925 | hk_lfr_me_update(); |
|
926 | 926 | |
|
927 | 927 | //update the high severity error counter |
|
928 | 928 | hk_lfr_he_cnt = 0; |
|
929 | 929 | |
|
930 | 930 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
931 | 931 | // HE |
|
932 | 932 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
933 | 933 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); |
|
934 | 934 | |
|
935 | 935 | } |
|
936 | 936 | |
|
937 | 937 | void set_hk_lfr_time_not_synchro() |
|
938 | 938 | { |
|
939 | 939 | static unsigned char synchroLost = 1; |
|
940 | 940 | int synchronizationBit; |
|
941 | 941 | |
|
942 | 942 | // get the synchronization bit |
|
943 | 943 | synchronizationBit = |
|
944 | 944 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 |
|
945 | 945 | |
|
946 | 946 | switch (synchronizationBit) |
|
947 | 947 | { |
|
948 | 948 | case 0: |
|
949 | 949 | if (synchroLost == 1) |
|
950 | 950 | { |
|
951 | 951 | synchroLost = 0; |
|
952 | 952 | } |
|
953 | 953 | break; |
|
954 | 954 | case 1: |
|
955 | 955 | if (synchroLost == 0 ) |
|
956 | 956 | { |
|
957 | 957 | synchroLost = 1; |
|
958 | 958 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); |
|
959 | 959 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); |
|
960 | 960 | } |
|
961 | 961 | break; |
|
962 | 962 | default: |
|
963 | 963 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); |
|
964 | 964 | break; |
|
965 | 965 | } |
|
966 | 966 | |
|
967 | 967 | } |
|
968 | 968 | |
|
969 | 969 | void set_hk_lfr_ahb_correctable() // CRITICITY L |
|
970 | 970 | { |
|
971 | 971 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided |
|
972 | 972 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the |
|
973 | 973 | * detected errors in the cache, in the integer unit and in the floating point unit. |
|
974 | 974 | * |
|
975 | 975 | * @param void |
|
976 | 976 | * |
|
977 | 977 | * @return void |
|
978 | 978 | * |
|
979 | 979 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. |
|
980 | 980 | * |
|
981 | 981 | */ |
|
982 | 982 | |
|
983 | 983 | unsigned int ahb_correctable; |
|
984 | 984 | unsigned int instructionErrorCounter; |
|
985 | 985 | unsigned int dataErrorCounter; |
|
986 | 986 | unsigned int fprfErrorCounter; |
|
987 | 987 | unsigned int iurfErrorCounter; |
|
988 | 988 | |
|
989 | 989 | instructionErrorCounter = 0; |
|
990 | 990 | dataErrorCounter = 0; |
|
991 | 991 | fprfErrorCounter = 0; |
|
992 | 992 | iurfErrorCounter = 0; |
|
993 | 993 | |
|
994 | 994 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); |
|
995 | 995 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); |
|
996 | 996 | |
|
997 | 997 | ahb_correctable = instructionErrorCounter |
|
998 | 998 | + dataErrorCounter |
|
999 | 999 | + fprfErrorCounter |
|
1000 | 1000 | + iurfErrorCounter |
|
1001 | 1001 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
1002 | 1002 | |
|
1003 | 1003 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] |
|
1004 | 1004 | |
|
1005 | 1005 | } |
@@ -1,1633 +1,1633 | |||
|
1 | 1 | /** Functions related to the SpaceWire interface. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle SpaceWire transmissions: |
|
7 | 7 | * - configuration of the SpaceWire link |
|
8 | 8 | * - SpaceWire related interruption requests processing |
|
9 | 9 | * - transmission of TeleMetry packets by a dedicated RTEMS task |
|
10 | 10 | * - reception of TeleCommands by a dedicated RTEMS task |
|
11 | 11 | * |
|
12 | 12 | */ |
|
13 | 13 | |
|
14 | 14 | #include "fsw_spacewire.h" |
|
15 | 15 | |
|
16 | 16 | rtems_name semq_name = 0; |
|
17 | 17 | rtems_id semq_id = RTEMS_ID_NONE; |
|
18 | 18 | |
|
19 | 19 | //***************** |
|
20 | 20 | // waveform headers |
|
21 | 21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0}; |
|
22 | 22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0}; |
|
23 | 23 | Header_TM_LFR_SCIENCE_ASM_t headerASM = {0}; |
|
24 | 24 | |
|
25 | 25 | unsigned char previousTimecodeCtr = 0; |
|
26 | 26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); |
|
27 | 27 | |
|
28 | 28 | //*********** |
|
29 | 29 | // RTEMS TASK |
|
30 | 30 | rtems_task spiq_task(rtems_task_argument unused) |
|
31 | 31 | { |
|
32 | 32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. |
|
33 | 33 | * |
|
34 | 34 | * @param unused is the starting argument of the RTEMS task |
|
35 | 35 | * |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | rtems_event_set event_out; |
|
39 | 39 | rtems_status_code status; |
|
40 | 40 | int linkStatus; |
|
41 | 41 | |
|
42 | 42 | event_out = EVENT_SETS_NONE_PENDING; |
|
43 | 43 | linkStatus = 0; |
|
44 | 44 | |
|
45 | 45 | BOOT_PRINTF("in SPIQ *** \n") |
|
46 | 46 | |
|
47 | 47 | while(true){ |
|
48 | 48 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
49 | 49 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") |
|
50 | 50 | |
|
51 | 51 | // [0] SUSPEND RECV AND SEND TASKS |
|
52 | 52 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); |
|
53 | 53 | if ( status != RTEMS_SUCCESSFUL ) { |
|
54 | 54 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") |
|
55 | 55 | } |
|
56 | 56 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); |
|
57 | 57 | if ( status != RTEMS_SUCCESSFUL ) { |
|
58 | 58 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | // [1] CHECK THE LINK |
|
62 | 62 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) |
|
63 | 63 | if ( linkStatus != SPW_LINK_OK) { |
|
64 | 64 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) |
|
65 | 65 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT |
|
69 | 69 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) |
|
70 | 70 | if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link |
|
71 | 71 | { |
|
72 | 72 | spacewire_read_statistics(); |
|
73 | 73 | status = spacewire_several_connect_attemps( ); |
|
74 | 74 | } |
|
75 | 75 | else // [2.b] in run state, start the link |
|
76 | 76 | { |
|
77 | 77 | status = spacewire_stop_and_start_link( fdSPW ); // start the link |
|
78 | 78 | if ( status != RTEMS_SUCCESSFUL) |
|
79 | 79 | { |
|
80 | 80 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) |
|
81 | 81 | } |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS |
|
85 | 85 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully |
|
86 | 86 | { |
|
87 | 87 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
88 | 88 | if ( status != RTEMS_SUCCESSFUL ) { |
|
89 | 89 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") |
|
90 | 90 | } |
|
91 | 91 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
92 | 92 | if ( status != RTEMS_SUCCESSFUL ) { |
|
93 | 93 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") |
|
94 | 94 | } |
|
95 | 95 | } |
|
96 | 96 | else // [3.b] the link is not in run state, go in STANDBY mode |
|
97 | 97 | { |
|
98 | 98 | status = enter_mode_standby(); |
|
99 | 99 | if ( status != RTEMS_SUCCESSFUL ) |
|
100 | 100 | { |
|
101 | 101 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) |
|
102 | 102 | } |
|
103 | 103 | { |
|
104 | 104 | updateLFRCurrentMode( LFR_MODE_STANDBY ); |
|
105 | 105 | } |
|
106 | 106 | // wake the LINK task up to wait for the link recovery |
|
107 | 107 | status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 ); |
|
108 | 108 | status = rtems_task_suspend( RTEMS_SELF ); |
|
109 | 109 | } |
|
110 | 110 | } |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | rtems_task recv_task( rtems_task_argument unused ) |
|
114 | 114 | { |
|
115 | 115 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. |
|
116 | 116 | * |
|
117 | 117 | * @param unused is the starting argument of the RTEMS task |
|
118 | 118 | * |
|
119 | 119 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: |
|
120 | 120 | * 1. It reads the incoming data. |
|
121 | 121 | * 2. Launches the acceptance procedure. |
|
122 | 122 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. |
|
123 | 123 | * |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | int len; |
|
127 | 127 | ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC; |
|
128 | 128 | unsigned char computed_CRC[ BYTES_PER_CRC ]; |
|
129 | 129 | unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ]; |
|
130 | 130 | unsigned char destinationID; |
|
131 | 131 | unsigned int estimatedPacketLength; |
|
132 | 132 | unsigned int parserCode; |
|
133 | 133 | rtems_status_code status; |
|
134 | 134 | rtems_id queue_recv_id; |
|
135 | 135 | rtems_id queue_send_id; |
|
136 | 136 | |
|
137 | 137 | memset( ¤tTC, 0, sizeof(ccsdsTelecommandPacket_t) ); |
|
138 | 138 | destinationID = 0; |
|
139 | 139 | queue_recv_id = RTEMS_ID_NONE; |
|
140 | 140 | queue_send_id = RTEMS_ID_NONE; |
|
141 | 141 | |
|
142 | 142 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes |
|
143 | 143 | |
|
144 | 144 | status = get_message_queue_id_recv( &queue_recv_id ); |
|
145 | 145 | if (status != RTEMS_SUCCESSFUL) |
|
146 | 146 | { |
|
147 | 147 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | status = get_message_queue_id_send( &queue_send_id ); |
|
151 | 151 | if (status != RTEMS_SUCCESSFUL) |
|
152 | 152 | { |
|
153 | 153 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | BOOT_PRINTF("in RECV *** \n") |
|
157 | 157 | |
|
158 | 158 | while(1) |
|
159 | 159 | { |
|
160 | 160 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking |
|
161 | 161 | if (len == -1){ // error during the read call |
|
162 | 162 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) |
|
163 | 163 | } |
|
164 | 164 | else { |
|
165 | 165 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { |
|
166 | 166 | PRINTF("in RECV *** packet lenght too short\n") |
|
167 | 167 | } |
|
168 | 168 | else { |
|
169 | 169 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes |
|
170 |
|
|
|
170 | PRINTF1("incoming TC with Length (byte): %d\n", len - 3); | |
|
171 | 171 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE); |
|
172 | 172 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); |
|
173 | 173 | // CHECK THE TC |
|
174 | 174 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; |
|
175 | 175 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) |
|
176 | 176 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) |
|
177 | 177 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) |
|
178 | 178 | || (parserCode == WRONG_SRC_ID) ) |
|
179 | 179 | { // send TM_LFR_TC_EXE_CORRUPTED |
|
180 | 180 | PRINTF1("TC corrupted received, with code: %d\n", parserCode); |
|
181 | 181 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
182 | 182 | && |
|
183 | 183 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
184 | 184 | ) |
|
185 | 185 | { |
|
186 | 186 | if ( parserCode == WRONG_SRC_ID ) |
|
187 | 187 | { |
|
188 | 188 | destinationID = SID_TC_GROUND; |
|
189 | 189 | } |
|
190 | 190 | else |
|
191 | 191 | { |
|
192 | 192 | destinationID = currentTC.sourceID; |
|
193 | 193 | } |
|
194 | 194 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, |
|
195 | 195 | computed_CRC, currentTC_LEN_RCV, |
|
196 | 196 | destinationID ); |
|
197 | 197 | } |
|
198 | 198 | } |
|
199 | 199 | else |
|
200 | 200 | { // send valid TC to the action launcher |
|
201 | 201 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, |
|
202 | 202 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP); |
|
203 | 203 | } |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); |
|
208 | 208 | |
|
209 | 209 | } |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | rtems_task send_task( rtems_task_argument argument) |
|
213 | 213 | { |
|
214 | 214 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. |
|
215 | 215 | * |
|
216 | 216 | * @param unused is the starting argument of the RTEMS task |
|
217 | 217 | * |
|
218 | 218 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: |
|
219 | 219 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. |
|
220 | 220 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After |
|
221 | 221 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the |
|
222 | 222 | * data it contains. |
|
223 | 223 | * |
|
224 | 224 | */ |
|
225 | 225 | |
|
226 | 226 | rtems_status_code status; // RTEMS status code |
|
227 | 227 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
228 | 228 | ring_node *incomingRingNodePtr; |
|
229 | 229 | int ring_node_address; |
|
230 | 230 | char *charPtr; |
|
231 | 231 | spw_ioctl_pkt_send *spw_ioctl_send; |
|
232 | 232 | size_t size; // size of the incoming TC packet |
|
233 | 233 | rtems_id queue_send_id; |
|
234 | 234 | unsigned int sid; |
|
235 | 235 | unsigned char sidAsUnsignedChar; |
|
236 | 236 | unsigned char type; |
|
237 | 237 | |
|
238 | 238 | incomingRingNodePtr = NULL; |
|
239 | 239 | ring_node_address = 0; |
|
240 | 240 | charPtr = (char *) &ring_node_address; |
|
241 | 241 | size = 0; |
|
242 | 242 | queue_send_id = RTEMS_ID_NONE; |
|
243 | 243 | sid = 0; |
|
244 | 244 | sidAsUnsignedChar = 0; |
|
245 | 245 | |
|
246 | 246 | init_header_cwf( &headerCWF ); |
|
247 | 247 | init_header_swf( &headerSWF ); |
|
248 | 248 | init_header_asm( &headerASM ); |
|
249 | 249 | |
|
250 | 250 | status = get_message_queue_id_send( &queue_send_id ); |
|
251 | 251 | if (status != RTEMS_SUCCESSFUL) |
|
252 | 252 | { |
|
253 | 253 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | BOOT_PRINTF("in SEND *** \n") |
|
257 | 257 | |
|
258 | 258 | while(1) |
|
259 | 259 | { |
|
260 | 260 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, |
|
261 | 261 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
262 | 262 | |
|
263 | 263 | if (status!=RTEMS_SUCCESSFUL) |
|
264 | 264 | { |
|
265 | 265 | PRINTF1("in SEND *** (1) ERR = %d\n", status) |
|
266 | 266 | } |
|
267 | 267 | else |
|
268 | 268 | { |
|
269 | 269 | if ( size == sizeof(ring_node*) ) |
|
270 | 270 | { |
|
271 | 271 | charPtr[0] = incomingData[0]; |
|
272 | 272 | charPtr[1] = incomingData[1]; |
|
273 | 273 | charPtr[BYTE_2] = incomingData[BYTE_2]; |
|
274 | 274 | charPtr[BYTE_3] = incomingData[BYTE_3]; |
|
275 | 275 | incomingRingNodePtr = (ring_node*) ring_node_address; |
|
276 | 276 | sid = incomingRingNodePtr->sid; |
|
277 | 277 | if ( (sid==SID_NORM_CWF_LONG_F3) |
|
278 | 278 | || (sid==SID_BURST_CWF_F2 ) |
|
279 | 279 | || (sid==SID_SBM1_CWF_F1 ) |
|
280 | 280 | || (sid==SID_SBM2_CWF_F2 )) |
|
281 | 281 | { |
|
282 | 282 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); |
|
283 | 283 | } |
|
284 | 284 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) |
|
285 | 285 | { |
|
286 | 286 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); |
|
287 | 287 | } |
|
288 | 288 | else if ( (sid==SID_NORM_CWF_F3) ) |
|
289 | 289 | { |
|
290 | 290 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); |
|
291 | 291 | } |
|
292 | 292 | else if (sid==SID_NORM_ASM_F0) |
|
293 | 293 | { |
|
294 | 294 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); |
|
295 | 295 | } |
|
296 | 296 | else if (sid==SID_NORM_ASM_F1) |
|
297 | 297 | { |
|
298 | 298 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); |
|
299 | 299 | } |
|
300 | 300 | else if (sid==SID_NORM_ASM_F2) |
|
301 | 301 | { |
|
302 | 302 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); |
|
303 | 303 | } |
|
304 | 304 | else if ( sid==TM_CODE_K_DUMP ) |
|
305 | 305 | { |
|
306 | 306 | spw_send_k_dump( incomingRingNodePtr ); |
|
307 | 307 | } |
|
308 | 308 | else |
|
309 | 309 | { |
|
310 | 310 | PRINTF1("unexpected sid = %d\n", sid); |
|
311 | 311 | } |
|
312 | 312 | } |
|
313 | 313 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet |
|
314 | 314 | { |
|
315 | 315 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; |
|
316 | 316 | sid = sidAsUnsignedChar; |
|
317 | 317 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; |
|
318 | 318 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently |
|
319 | 319 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS |
|
320 | 320 | { |
|
321 | 321 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | status = write( fdSPW, incomingData, size ); |
|
325 | 325 | if (status == -1){ |
|
326 | 326 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
327 | 327 | } |
|
328 | 328 | } |
|
329 | 329 | else // the incoming message is a spw_ioctl_pkt_send structure |
|
330 | 330 | { |
|
331 | 331 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; |
|
332 | 332 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
333 | 333 | if (status == -1){ |
|
334 | 334 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); |
|
340 | 340 | |
|
341 | 341 | } |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | rtems_task link_task( rtems_task_argument argument ) |
|
345 | 345 | { |
|
346 | 346 | rtems_event_set event_out; |
|
347 | 347 | rtems_status_code status; |
|
348 | 348 | int linkStatus; |
|
349 | 349 | |
|
350 | 350 | event_out = EVENT_SETS_NONE_PENDING; |
|
351 | 351 | linkStatus = 0; |
|
352 | 352 | |
|
353 | 353 | BOOT_PRINTF("in LINK ***\n") |
|
354 | 354 | |
|
355 | 355 | while(1) |
|
356 | 356 | { |
|
357 | 357 | // wait for an RTEMS_EVENT |
|
358 | 358 | rtems_event_receive( RTEMS_EVENT_0, |
|
359 | 359 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
360 | 360 | PRINTF("in LINK *** wait for the link\n") |
|
361 | 361 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
362 | 362 | while( linkStatus != SPW_LINK_OK) // wait for the link |
|
363 | 363 | { |
|
364 | 364 | status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms |
|
365 | 365 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
366 | 366 | watchdog_reload(); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | spacewire_read_statistics(); |
|
370 | 370 | status = spacewire_stop_and_start_link( fdSPW ); |
|
371 | 371 | |
|
372 | 372 | if (status != RTEMS_SUCCESSFUL) |
|
373 | 373 | { |
|
374 | 374 | PRINTF1("in LINK *** ERR link not started %d\n", status) |
|
375 | 375 | } |
|
376 | 376 | else |
|
377 | 377 | { |
|
378 | 378 | PRINTF("in LINK *** OK link started\n") |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | // restart the SPIQ task |
|
382 | 382 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); |
|
383 | 383 | if ( status != RTEMS_SUCCESSFUL ) { |
|
384 | 384 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") |
|
385 | 385 | } |
|
386 | 386 | |
|
387 | 387 | // restart RECV and SEND |
|
388 | 388 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
389 | 389 | if ( status != RTEMS_SUCCESSFUL ) { |
|
390 | 390 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") |
|
391 | 391 | } |
|
392 | 392 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
393 | 393 | if ( status != RTEMS_SUCCESSFUL ) { |
|
394 | 394 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") |
|
395 | 395 | } |
|
396 | 396 | } |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | //**************** |
|
400 | 400 | // OTHER FUNCTIONS |
|
401 | 401 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] |
|
402 | 402 | { |
|
403 | 403 | /** This function opens the SpaceWire link. |
|
404 | 404 | * |
|
405 | 405 | * @return a valid file descriptor in case of success, -1 in case of a failure |
|
406 | 406 | * |
|
407 | 407 | */ |
|
408 | 408 | rtems_status_code status; |
|
409 | 409 | |
|
410 | 410 | status = RTEMS_SUCCESSFUL; |
|
411 | 411 | |
|
412 | 412 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware |
|
413 | 413 | if ( fdSPW < 0 ) { |
|
414 | 414 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) |
|
415 | 415 | } |
|
416 | 416 | else |
|
417 | 417 | { |
|
418 | 418 | status = RTEMS_SUCCESSFUL; |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | return status; |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | int spacewire_start_link( int fd ) |
|
425 | 425 | { |
|
426 | 426 | rtems_status_code status; |
|
427 | 427 | |
|
428 | 428 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
429 | 429 | // -1 default hardcoded driver timeout |
|
430 | 430 | |
|
431 | 431 | return status; |
|
432 | 432 | } |
|
433 | 433 | |
|
434 | 434 | int spacewire_stop_and_start_link( int fd ) |
|
435 | 435 | { |
|
436 | 436 | rtems_status_code status; |
|
437 | 437 | |
|
438 | 438 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 |
|
439 | 439 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
440 | 440 | // -1 default hardcoded driver timeout |
|
441 | 441 | |
|
442 | 442 | return status; |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | int spacewire_configure_link( int fd ) |
|
446 | 446 | { |
|
447 | 447 | /** This function configures the SpaceWire link. |
|
448 | 448 | * |
|
449 | 449 | * @return GR-RTEMS-DRIVER directive status codes: |
|
450 | 450 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. |
|
451 | 451 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. |
|
452 | 452 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. |
|
453 | 453 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. |
|
454 | 454 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. |
|
455 | 455 | * - 5 EIO - Error when writing to grswp hardware registers. |
|
456 | 456 | * - 2 ENOENT - No such file or directory |
|
457 | 457 | */ |
|
458 | 458 | |
|
459 | 459 | rtems_status_code status; |
|
460 | 460 | |
|
461 | 461 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force |
|
462 | 462 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration |
|
463 | 463 | spw_ioctl_packetsize packetsize; |
|
464 | 464 | |
|
465 | 465 | packetsize.rxsize = SPW_RXSIZE; |
|
466 | 466 | packetsize.txdsize = SPW_TXDSIZE; |
|
467 | 467 | packetsize.txhsize = SPW_TXHSIZE; |
|
468 | 468 | |
|
469 | 469 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
470 | 470 | if (status!=RTEMS_SUCCESSFUL) { |
|
471 | 471 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
472 | 472 | } |
|
473 | 473 | // |
|
474 | 474 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a |
|
475 | 475 | if (status!=RTEMS_SUCCESSFUL) { |
|
476 | 476 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
477 | 477 | } |
|
478 | 478 | // |
|
479 | 479 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts |
|
480 | 480 | if (status!=RTEMS_SUCCESSFUL) { |
|
481 | 481 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
482 | 482 | } |
|
483 | 483 | // |
|
484 | 484 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
485 | 485 | if (status!=RTEMS_SUCCESSFUL) { |
|
486 | 486 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
487 | 487 | } |
|
488 | 488 | // |
|
489 | 489 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks |
|
490 | 490 | if (status!=RTEMS_SUCCESSFUL) { |
|
491 | 491 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") |
|
492 | 492 | } |
|
493 | 493 | // |
|
494 | 494 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available |
|
495 | 495 | if (status!=RTEMS_SUCCESSFUL) { |
|
496 | 496 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
497 | 497 | } |
|
498 | 498 | // |
|
499 | 499 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ] |
|
500 | 500 | if (status!=RTEMS_SUCCESSFUL) { |
|
501 | 501 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") |
|
502 | 502 | } |
|
503 | 503 | // |
|
504 | 504 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize |
|
505 | 505 | if (status!=RTEMS_SUCCESSFUL) { |
|
506 | 506 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n") |
|
507 | 507 | } |
|
508 | 508 | |
|
509 | 509 | return status; |
|
510 | 510 | } |
|
511 | 511 | |
|
512 | 512 | int spacewire_several_connect_attemps( void ) |
|
513 | 513 | { |
|
514 | 514 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. |
|
515 | 515 | * |
|
516 | 516 | * @return RTEMS directive status code: |
|
517 | 517 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. |
|
518 | 518 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. |
|
519 | 519 | * |
|
520 | 520 | */ |
|
521 | 521 | |
|
522 | 522 | rtems_status_code status_spw; |
|
523 | 523 | rtems_status_code status; |
|
524 | 524 | int i; |
|
525 | 525 | |
|
526 | 526 | status_spw = RTEMS_SUCCESSFUL; |
|
527 | 527 | |
|
528 | 528 | i = 0; |
|
529 | 529 | while (i < SY_LFR_DPU_CONNECT_ATTEMPT) |
|
530 | 530 | { |
|
531 | 531 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); |
|
532 | 532 | |
|
533 | 533 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM |
|
534 | 534 | |
|
535 | 535 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
536 | 536 | |
|
537 | 537 | status_spw = spacewire_stop_and_start_link( fdSPW ); |
|
538 | 538 | |
|
539 | 539 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
540 | 540 | { |
|
541 | 541 | i = i + 1; |
|
542 | 542 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw); |
|
543 | 543 | } |
|
544 | 544 | else |
|
545 | 545 | { |
|
546 | 546 | i = SY_LFR_DPU_CONNECT_ATTEMPT; |
|
547 | 547 | } |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | return status_spw; |
|
551 | 551 | } |
|
552 | 552 | |
|
553 | 553 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force |
|
554 | 554 | { |
|
555 | 555 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. |
|
556 | 556 | * |
|
557 | 557 | * @param val is the value, 0 or 1, used to set the value of the NP bit. |
|
558 | 558 | * @param regAddr is the address of the GRSPW control register. |
|
559 | 559 | * |
|
560 | 560 | * NP is the bit 20 of the GRSPW control register. |
|
561 | 561 | * |
|
562 | 562 | */ |
|
563 | 563 | |
|
564 | 564 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
565 | 565 | |
|
566 | 566 | if (val == 1) { |
|
567 | 567 | *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit |
|
568 | 568 | } |
|
569 | 569 | if (val== 0) { |
|
570 | 570 | *spwptr = *spwptr & SPW_BIT_NP_MASK; |
|
571 | 571 | } |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable |
|
575 | 575 | { |
|
576 | 576 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. |
|
577 | 577 | * |
|
578 | 578 | * @param val is the value, 0 or 1, used to set the value of the RE bit. |
|
579 | 579 | * @param regAddr is the address of the GRSPW control register. |
|
580 | 580 | * |
|
581 | 581 | * RE is the bit 16 of the GRSPW control register. |
|
582 | 582 | * |
|
583 | 583 | */ |
|
584 | 584 | |
|
585 | 585 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
586 | 586 | |
|
587 | 587 | if (val == 1) |
|
588 | 588 | { |
|
589 | 589 | *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit |
|
590 | 590 | } |
|
591 | 591 | if (val== 0) |
|
592 | 592 | { |
|
593 | 593 | *spwptr = *spwptr & SPW_BIT_RE_MASK; |
|
594 | 594 | } |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | void spacewire_read_statistics( void ) |
|
598 | 598 | { |
|
599 | 599 | /** This function reads the SpaceWire statistics from the grspw RTEMS driver. |
|
600 | 600 | * |
|
601 | 601 | * @param void |
|
602 | 602 | * |
|
603 | 603 | * @return void |
|
604 | 604 | * |
|
605 | 605 | * Once they are read, the counters are stored in a global variable used during the building of the |
|
606 | 606 | * HK packets. |
|
607 | 607 | * |
|
608 | 608 | */ |
|
609 | 609 | |
|
610 | 610 | rtems_status_code status; |
|
611 | 611 | spw_stats current; |
|
612 | 612 | |
|
613 | 613 | memset(¤t, 0, sizeof(spw_stats)); |
|
614 | 614 | |
|
615 | 615 | spacewire_get_last_error(); |
|
616 | 616 | |
|
617 | 617 | // read the current statistics |
|
618 | 618 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); |
|
619 | 619 | |
|
620 | 620 | // clear the counters |
|
621 | 621 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS ); |
|
622 | 622 | |
|
623 | 623 | // typedef struct { |
|
624 | 624 | // unsigned int tx_link_err; // NOT IN HK |
|
625 | 625 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK |
|
626 | 626 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK |
|
627 | 627 | // unsigned int rx_eep_err; |
|
628 | 628 | // unsigned int rx_truncated; |
|
629 | 629 | // unsigned int parity_err; |
|
630 | 630 | // unsigned int escape_err; |
|
631 | 631 | // unsigned int credit_err; |
|
632 | 632 | // unsigned int write_sync_err; |
|
633 | 633 | // unsigned int disconnect_err; |
|
634 | 634 | // unsigned int early_ep; |
|
635 | 635 | // unsigned int invalid_address; |
|
636 | 636 | // unsigned int packets_sent; |
|
637 | 637 | // unsigned int packets_received; |
|
638 | 638 | // } spw_stats; |
|
639 | 639 | |
|
640 | 640 | // rx_eep_err |
|
641 | 641 | grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err; |
|
642 | 642 | // rx_truncated |
|
643 | 643 | grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated; |
|
644 | 644 | // parity_err |
|
645 | 645 | grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err; |
|
646 | 646 | // escape_err |
|
647 | 647 | grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err; |
|
648 | 648 | // credit_err |
|
649 | 649 | grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err; |
|
650 | 650 | // write_sync_err |
|
651 | 651 | grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err; |
|
652 | 652 | // disconnect_err |
|
653 | 653 | grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err; |
|
654 | 654 | // early_ep |
|
655 | 655 | grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep; |
|
656 | 656 | // invalid_address |
|
657 | 657 | grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address; |
|
658 | 658 | // packets_sent |
|
659 | 659 | grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent; |
|
660 | 660 | // packets_received |
|
661 | 661 | grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received; |
|
662 | 662 | |
|
663 | 663 | } |
|
664 | 664 | |
|
665 | 665 | void spacewire_get_last_error( void ) |
|
666 | 666 | { |
|
667 | 667 | static spw_stats previous = {0}; |
|
668 | 668 | spw_stats current; |
|
669 | 669 | rtems_status_code status; |
|
670 | 670 | |
|
671 | 671 | unsigned int hk_lfr_last_er_rid; |
|
672 | 672 | unsigned char hk_lfr_last_er_code; |
|
673 | 673 | int coarseTime; |
|
674 | 674 | int fineTime; |
|
675 | 675 | unsigned char update_hk_lfr_last_er; |
|
676 | 676 | |
|
677 | 677 | memset(¤t, 0, sizeof(spw_stats)); |
|
678 | 678 | hk_lfr_last_er_rid = INIT_CHAR; |
|
679 | 679 | hk_lfr_last_er_code = INIT_CHAR; |
|
680 | 680 | update_hk_lfr_last_er = INIT_CHAR; |
|
681 | 681 | |
|
682 | 682 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); |
|
683 | 683 | |
|
684 | 684 | // get current time |
|
685 | 685 | coarseTime = time_management_regs->coarse_time; |
|
686 | 686 | fineTime = time_management_regs->fine_time; |
|
687 | 687 | |
|
688 | 688 | // typedef struct { |
|
689 | 689 | // unsigned int tx_link_err; // NOT IN HK |
|
690 | 690 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK |
|
691 | 691 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK |
|
692 | 692 | // unsigned int rx_eep_err; |
|
693 | 693 | // unsigned int rx_truncated; |
|
694 | 694 | // unsigned int parity_err; |
|
695 | 695 | // unsigned int escape_err; |
|
696 | 696 | // unsigned int credit_err; |
|
697 | 697 | // unsigned int write_sync_err; |
|
698 | 698 | // unsigned int disconnect_err; |
|
699 | 699 | // unsigned int early_ep; |
|
700 | 700 | // unsigned int invalid_address; |
|
701 | 701 | // unsigned int packets_sent; |
|
702 | 702 | // unsigned int packets_received; |
|
703 | 703 | // } spw_stats; |
|
704 | 704 | |
|
705 | 705 | // tx_link_err *** no code associated to this field |
|
706 | 706 | // rx_rmap_header_crc_err *** LE *** in HK |
|
707 | 707 | if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err) |
|
708 | 708 | { |
|
709 | 709 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
710 | 710 | hk_lfr_last_er_code = CODE_HEADER_CRC; |
|
711 | 711 | update_hk_lfr_last_er = 1; |
|
712 | 712 | } |
|
713 | 713 | // rx_rmap_data_crc_err *** LE *** NOT IN HK |
|
714 | 714 | if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err) |
|
715 | 715 | { |
|
716 | 716 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
717 | 717 | hk_lfr_last_er_code = CODE_DATA_CRC; |
|
718 | 718 | update_hk_lfr_last_er = 1; |
|
719 | 719 | } |
|
720 | 720 | // rx_eep_err |
|
721 | 721 | if (previous.rx_eep_err != current.rx_eep_err) |
|
722 | 722 | { |
|
723 | 723 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
724 | 724 | hk_lfr_last_er_code = CODE_EEP; |
|
725 | 725 | update_hk_lfr_last_er = 1; |
|
726 | 726 | } |
|
727 | 727 | // rx_truncated |
|
728 | 728 | if (previous.rx_truncated != current.rx_truncated) |
|
729 | 729 | { |
|
730 | 730 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
731 | 731 | hk_lfr_last_er_code = CODE_RX_TOO_BIG; |
|
732 | 732 | update_hk_lfr_last_er = 1; |
|
733 | 733 | } |
|
734 | 734 | // parity_err |
|
735 | 735 | if (previous.parity_err != current.parity_err) |
|
736 | 736 | { |
|
737 | 737 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
738 | 738 | hk_lfr_last_er_code = CODE_PARITY; |
|
739 | 739 | update_hk_lfr_last_er = 1; |
|
740 | 740 | } |
|
741 | 741 | // escape_err |
|
742 | 742 | if (previous.parity_err != current.parity_err) |
|
743 | 743 | { |
|
744 | 744 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
745 | 745 | hk_lfr_last_er_code = CODE_ESCAPE; |
|
746 | 746 | update_hk_lfr_last_er = 1; |
|
747 | 747 | } |
|
748 | 748 | // credit_err |
|
749 | 749 | if (previous.credit_err != current.credit_err) |
|
750 | 750 | { |
|
751 | 751 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
752 | 752 | hk_lfr_last_er_code = CODE_CREDIT; |
|
753 | 753 | update_hk_lfr_last_er = 1; |
|
754 | 754 | } |
|
755 | 755 | // write_sync_err |
|
756 | 756 | if (previous.write_sync_err != current.write_sync_err) |
|
757 | 757 | { |
|
758 | 758 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
759 | 759 | hk_lfr_last_er_code = CODE_WRITE_SYNC; |
|
760 | 760 | update_hk_lfr_last_er = 1; |
|
761 | 761 | } |
|
762 | 762 | // disconnect_err |
|
763 | 763 | if (previous.disconnect_err != current.disconnect_err) |
|
764 | 764 | { |
|
765 | 765 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
766 | 766 | hk_lfr_last_er_code = CODE_DISCONNECT; |
|
767 | 767 | update_hk_lfr_last_er = 1; |
|
768 | 768 | } |
|
769 | 769 | // early_ep |
|
770 | 770 | if (previous.early_ep != current.early_ep) |
|
771 | 771 | { |
|
772 | 772 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
773 | 773 | hk_lfr_last_er_code = CODE_EARLY_EOP_EEP; |
|
774 | 774 | update_hk_lfr_last_er = 1; |
|
775 | 775 | } |
|
776 | 776 | // invalid_address |
|
777 | 777 | if (previous.invalid_address != current.invalid_address) |
|
778 | 778 | { |
|
779 | 779 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
780 | 780 | hk_lfr_last_er_code = CODE_INVALID_ADDRESS; |
|
781 | 781 | update_hk_lfr_last_er = 1; |
|
782 | 782 | } |
|
783 | 783 | |
|
784 | 784 | // if a field has changed, update the hk_last_er fields |
|
785 | 785 | if (update_hk_lfr_last_er == 1) |
|
786 | 786 | { |
|
787 | 787 | update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code ); |
|
788 | 788 | } |
|
789 | 789 | |
|
790 | 790 | previous = current; |
|
791 | 791 | } |
|
792 | 792 | |
|
793 | 793 | void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code) |
|
794 | 794 | { |
|
795 | 795 | unsigned char *coarseTimePtr; |
|
796 | 796 | unsigned char *fineTimePtr; |
|
797 | 797 | |
|
798 | 798 | coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time; |
|
799 | 799 | fineTimePtr = (unsigned char*) &time_management_regs->fine_time; |
|
800 | 800 | |
|
801 | 801 | housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE ); |
|
802 | 802 | housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK); |
|
803 | 803 | housekeeping_packet.hk_lfr_last_er_code = code; |
|
804 | 804 | housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0]; |
|
805 | 805 | housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1]; |
|
806 | 806 | housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2]; |
|
807 | 807 | housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3]; |
|
808 | 808 | housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2]; |
|
809 | 809 | housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3]; |
|
810 | 810 | } |
|
811 | 811 | |
|
812 | 812 | void update_hk_with_grspw_stats( void ) |
|
813 | 813 | { |
|
814 | 814 | //**************************** |
|
815 | 815 | // DPU_SPACEWIRE_IF_STATISTICS |
|
816 | 816 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE); |
|
817 | 817 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received); |
|
818 | 818 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE); |
|
819 | 819 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent); |
|
820 | 820 | |
|
821 | 821 | //****************************************** |
|
822 | 822 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY |
|
823 | 823 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err; |
|
824 | 824 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err; |
|
825 | 825 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err; |
|
826 | 826 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err; |
|
827 | 827 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err; |
|
828 | 828 | |
|
829 | 829 | //********************************************* |
|
830 | 830 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY |
|
831 | 831 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep; |
|
832 | 832 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address; |
|
833 | 833 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err; |
|
834 | 834 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated; |
|
835 | 835 | } |
|
836 | 836 | |
|
837 | 837 | void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 ) |
|
838 | 838 | { |
|
839 | 839 | unsigned int *statusRegisterPtr; |
|
840 | 840 | unsigned char linkState; |
|
841 | 841 | |
|
842 | 842 | statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER); |
|
843 | 843 | linkState = |
|
844 | 844 | (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111] |
|
845 | 845 | |
|
846 | 846 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0 |
|
847 | 847 | |
|
848 | 848 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state |
|
849 | 849 | } |
|
850 | 850 | |
|
851 | 851 | void increase_unsigned_char_counter( unsigned char *counter ) |
|
852 | 852 | { |
|
853 | 853 | // update the number of valid timecodes that have been received |
|
854 | 854 | if (*counter == UINT8_MAX) |
|
855 | 855 | { |
|
856 | 856 | *counter = 0; |
|
857 | 857 | } |
|
858 | 858 | else |
|
859 | 859 | { |
|
860 | 860 | *counter = *counter + 1; |
|
861 | 861 | } |
|
862 | 862 | } |
|
863 | 863 | |
|
864 | 864 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) |
|
865 | 865 | { |
|
866 | 866 | /** This function checks the coherency between the incoming timecode and the last valid timecode. |
|
867 | 867 | * |
|
868 | 868 | * @param currentTimecodeCtr is the incoming timecode |
|
869 | 869 | * |
|
870 | 870 | * @return returned codes:: |
|
871 | 871 | * - LFR_DEFAULT |
|
872 | 872 | * - LFR_SUCCESSFUL |
|
873 | 873 | * |
|
874 | 874 | */ |
|
875 | 875 | |
|
876 | 876 | static unsigned char firstTickout = 1; |
|
877 | 877 | unsigned char ret; |
|
878 | 878 | |
|
879 | 879 | ret = LFR_DEFAULT; |
|
880 | 880 | |
|
881 | 881 | if (firstTickout == 0) |
|
882 | 882 | { |
|
883 | 883 | if (currentTimecodeCtr == 0) |
|
884 | 884 | { |
|
885 | 885 | if (previousTimecodeCtr == SPW_TIMECODE_MAX) |
|
886 | 886 | { |
|
887 | 887 | ret = LFR_SUCCESSFUL; |
|
888 | 888 | } |
|
889 | 889 | else |
|
890 | 890 | { |
|
891 | 891 | ret = LFR_DEFAULT; |
|
892 | 892 | } |
|
893 | 893 | } |
|
894 | 894 | else |
|
895 | 895 | { |
|
896 | 896 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) |
|
897 | 897 | { |
|
898 | 898 | ret = LFR_SUCCESSFUL; |
|
899 | 899 | } |
|
900 | 900 | else |
|
901 | 901 | { |
|
902 | 902 | ret = LFR_DEFAULT; |
|
903 | 903 | } |
|
904 | 904 | } |
|
905 | 905 | } |
|
906 | 906 | else |
|
907 | 907 | { |
|
908 | 908 | firstTickout = 0; |
|
909 | 909 | ret = LFR_SUCCESSFUL; |
|
910 | 910 | } |
|
911 | 911 | |
|
912 | 912 | return ret; |
|
913 | 913 | } |
|
914 | 914 | |
|
915 | 915 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) |
|
916 | 916 | { |
|
917 | 917 | unsigned int ret; |
|
918 | 918 | |
|
919 | 919 | ret = LFR_DEFAULT; |
|
920 | 920 | |
|
921 | 921 | if (timecode == internalTime) |
|
922 | 922 | { |
|
923 | 923 | ret = LFR_SUCCESSFUL; |
|
924 | 924 | } |
|
925 | 925 | else |
|
926 | 926 | { |
|
927 | 927 | ret = LFR_DEFAULT; |
|
928 | 928 | } |
|
929 | 929 | |
|
930 | 930 | return ret; |
|
931 | 931 | } |
|
932 | 932 | |
|
933 | 933 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) |
|
934 | 934 | { |
|
935 | 935 | // a tickout has been emitted, perform actions on the incoming timecode |
|
936 | 936 | |
|
937 | 937 | unsigned char incomingTimecode; |
|
938 | 938 | unsigned char updateTime; |
|
939 | 939 | unsigned char internalTime; |
|
940 | 940 | rtems_status_code status; |
|
941 | 941 | |
|
942 | 942 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
943 | 943 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; |
|
944 | 944 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; |
|
945 | 945 | |
|
946 | 946 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; |
|
947 | 947 | |
|
948 | 948 | // update the number of tickout that have been generated |
|
949 | 949 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); |
|
950 | 950 | |
|
951 | 951 | //************************** |
|
952 | 952 | // HK_LFR_TIMECODE_ERRONEOUS |
|
953 | 953 | // MISSING and INVALID are handled by the timecode_timer_routine service routine |
|
954 | 954 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) |
|
955 | 955 | { |
|
956 | 956 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous |
|
957 | 957 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); |
|
958 | 958 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS ); |
|
959 | 959 | } |
|
960 | 960 | |
|
961 | 961 | //************************ |
|
962 | 962 | // HK_LFR_TIME_TIMECODE_IT |
|
963 | 963 | // check the coherency between the SpaceWire timecode and the Internal Time |
|
964 | 964 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) |
|
965 | 965 | { |
|
966 | 966 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); |
|
967 | 967 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT ); |
|
968 | 968 | } |
|
969 | 969 | |
|
970 | 970 | //******************** |
|
971 | 971 | // HK_LFR_TIMECODE_CTR |
|
972 | 972 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 |
|
973 | 973 | if (oneTcLfrUpdateTimeReceived == 1) |
|
974 | 974 | { |
|
975 | 975 | if ( incomingTimecode != updateTime ) |
|
976 | 976 | { |
|
977 | 977 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); |
|
978 | 978 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR ); |
|
979 | 979 | } |
|
980 | 980 | } |
|
981 | 981 | |
|
982 | 982 | // launch the timecode timer to detect missing or invalid timecodes |
|
983 | 983 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value |
|
984 | 984 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); |
|
985 | 985 | if (status != RTEMS_SUCCESSFUL) |
|
986 | 986 | { |
|
987 | 987 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 ); |
|
988 | 988 | } |
|
989 | 989 | } |
|
990 | 990 | |
|
991 | 991 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) |
|
992 | 992 | { |
|
993 | 993 | static unsigned char initStep = 1; |
|
994 | 994 | |
|
995 | 995 | unsigned char currentTimecodeCtr; |
|
996 | 996 | |
|
997 | 997 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
998 | 998 | |
|
999 | 999 | if (initStep == 1) |
|
1000 | 1000 | { |
|
1001 | 1001 | if (currentTimecodeCtr == previousTimecodeCtr) |
|
1002 | 1002 | { |
|
1003 | 1003 | //************************ |
|
1004 | 1004 | // HK_LFR_TIMECODE_MISSING |
|
1005 | 1005 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING |
|
1006 | 1006 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
1007 | 1007 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); |
|
1008 | 1008 | } |
|
1009 | 1009 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) |
|
1010 | 1010 | { |
|
1011 | 1011 | // the timecode value has changed and the value is valid, this is unexpected because |
|
1012 | 1012 | // the timer should not have fired, the timecode_irq_handler should have been raised |
|
1013 | 1013 | } |
|
1014 | 1014 | else |
|
1015 | 1015 | { |
|
1016 | 1016 | //************************ |
|
1017 | 1017 | // HK_LFR_TIMECODE_INVALID |
|
1018 | 1018 | // the timecode value has changed and the value is not valid, no tickout has been generated |
|
1019 | 1019 | // this is why the timer has fired |
|
1020 | 1020 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); |
|
1021 | 1021 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID ); |
|
1022 | 1022 | } |
|
1023 | 1023 | } |
|
1024 | 1024 | else |
|
1025 | 1025 | { |
|
1026 | 1026 | initStep = 1; |
|
1027 | 1027 | //************************ |
|
1028 | 1028 | // HK_LFR_TIMECODE_MISSING |
|
1029 | 1029 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
1030 | 1030 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); |
|
1031 | 1031 | } |
|
1032 | 1032 | |
|
1033 | 1033 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); |
|
1034 | 1034 | } |
|
1035 | 1035 | |
|
1036 | 1036 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1037 | 1037 | { |
|
1038 | 1038 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1039 | 1039 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1040 | 1040 | header->reserved = DEFAULT_RESERVED; |
|
1041 | 1041 | header->userApplication = CCSDS_USER_APP; |
|
1042 | 1042 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1043 | 1043 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; |
|
1044 | 1044 | header->packetLength[0] = INIT_CHAR; |
|
1045 | 1045 | header->packetLength[1] = INIT_CHAR; |
|
1046 | 1046 | // DATA FIELD HEADER |
|
1047 | 1047 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1048 | 1048 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1049 | 1049 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
1050 | 1050 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1051 | 1051 | header->time[BYTE_0] = INIT_CHAR; |
|
1052 | 1052 | header->time[BYTE_1] = INIT_CHAR; |
|
1053 | 1053 | header->time[BYTE_2] = INIT_CHAR; |
|
1054 | 1054 | header->time[BYTE_3] = INIT_CHAR; |
|
1055 | 1055 | header->time[BYTE_4] = INIT_CHAR; |
|
1056 | 1056 | header->time[BYTE_5] = INIT_CHAR; |
|
1057 | 1057 | // AUXILIARY DATA HEADER |
|
1058 | 1058 | header->sid = INIT_CHAR; |
|
1059 | 1059 | header->pa_bia_status_info = DEFAULT_HKBIA; |
|
1060 | 1060 | header->blkNr[0] = INIT_CHAR; |
|
1061 | 1061 | header->blkNr[1] = INIT_CHAR; |
|
1062 | 1062 | } |
|
1063 | 1063 | |
|
1064 | 1064 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1065 | 1065 | { |
|
1066 | 1066 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1067 | 1067 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1068 | 1068 | header->reserved = DEFAULT_RESERVED; |
|
1069 | 1069 | header->userApplication = CCSDS_USER_APP; |
|
1070 | 1070 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1071 | 1071 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1072 | 1072 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1073 | 1073 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1074 | 1074 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); |
|
1075 | 1075 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
1076 | 1076 | // DATA FIELD HEADER |
|
1077 | 1077 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1078 | 1078 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1079 | 1079 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
1080 | 1080 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1081 | 1081 | header->time[BYTE_0] = INIT_CHAR; |
|
1082 | 1082 | header->time[BYTE_1] = INIT_CHAR; |
|
1083 | 1083 | header->time[BYTE_2] = INIT_CHAR; |
|
1084 | 1084 | header->time[BYTE_3] = INIT_CHAR; |
|
1085 | 1085 | header->time[BYTE_4] = INIT_CHAR; |
|
1086 | 1086 | header->time[BYTE_5] = INIT_CHAR; |
|
1087 | 1087 | // AUXILIARY DATA HEADER |
|
1088 | 1088 | header->sid = INIT_CHAR; |
|
1089 | 1089 | header->pa_bia_status_info = DEFAULT_HKBIA; |
|
1090 | 1090 | header->pktCnt = PKTCNT_SWF; // PKT_CNT |
|
1091 | 1091 | header->pktNr = INIT_CHAR; |
|
1092 | 1092 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); |
|
1093 | 1093 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
1094 | 1094 | } |
|
1095 | 1095 | |
|
1096 | 1096 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1097 | 1097 | { |
|
1098 | 1098 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1099 | 1099 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1100 | 1100 | header->reserved = DEFAULT_RESERVED; |
|
1101 | 1101 | header->userApplication = CCSDS_USER_APP; |
|
1102 | 1102 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1103 | 1103 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1104 | 1104 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1105 | 1105 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1106 | 1106 | header->packetLength[0] = INIT_CHAR; |
|
1107 | 1107 | header->packetLength[1] = INIT_CHAR; |
|
1108 | 1108 | // DATA FIELD HEADER |
|
1109 | 1109 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1110 | 1110 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1111 | 1111 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype |
|
1112 | 1112 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1113 | 1113 | header->time[BYTE_0] = INIT_CHAR; |
|
1114 | 1114 | header->time[BYTE_1] = INIT_CHAR; |
|
1115 | 1115 | header->time[BYTE_2] = INIT_CHAR; |
|
1116 | 1116 | header->time[BYTE_3] = INIT_CHAR; |
|
1117 | 1117 | header->time[BYTE_4] = INIT_CHAR; |
|
1118 | 1118 | header->time[BYTE_5] = INIT_CHAR; |
|
1119 | 1119 | // AUXILIARY DATA HEADER |
|
1120 | 1120 | header->sid = INIT_CHAR; |
|
1121 | 1121 | header->pa_bia_status_info = INIT_CHAR; |
|
1122 | 1122 | header->pa_lfr_pkt_cnt_asm = INIT_CHAR; |
|
1123 | 1123 | header->pa_lfr_pkt_nr_asm = INIT_CHAR; |
|
1124 | 1124 | header->pa_lfr_asm_blk_nr[0] = INIT_CHAR; |
|
1125 | 1125 | header->pa_lfr_asm_blk_nr[1] = INIT_CHAR; |
|
1126 | 1126 | } |
|
1127 | 1127 | |
|
1128 | 1128 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, |
|
1129 | 1129 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1130 | 1130 | { |
|
1131 | 1131 | /** This function sends CWF CCSDS packets (F2, F1 or F0). |
|
1132 | 1132 | * |
|
1133 | 1133 | * @param waveform points to the buffer containing the data that will be send. |
|
1134 | 1134 | * @param sid is the source identifier of the data that will be sent. |
|
1135 | 1135 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1136 | 1136 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1137 | 1137 | * contain information to setup the transmission of the data packets. |
|
1138 | 1138 | * |
|
1139 | 1139 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1140 | 1140 | * |
|
1141 | 1141 | */ |
|
1142 | 1142 | |
|
1143 | 1143 | unsigned int i; |
|
1144 | 1144 | int ret; |
|
1145 | 1145 | unsigned int coarseTime; |
|
1146 | 1146 | unsigned int fineTime; |
|
1147 | 1147 | rtems_status_code status; |
|
1148 | 1148 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1149 | 1149 | int *dataPtr; |
|
1150 | 1150 | unsigned char sid; |
|
1151 | 1151 | |
|
1152 | 1152 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1153 | 1153 | spw_ioctl_send_CWF.options = 0; |
|
1154 | 1154 | |
|
1155 | 1155 | ret = LFR_DEFAULT; |
|
1156 | 1156 | sid = (unsigned char) ring_node_to_send->sid; |
|
1157 | 1157 | |
|
1158 | 1158 | coarseTime = ring_node_to_send->coarseTime; |
|
1159 | 1159 | fineTime = ring_node_to_send->fineTime; |
|
1160 | 1160 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1161 | 1161 | |
|
1162 | 1162 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); |
|
1163 | 1163 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
1164 | 1164 | header->pa_bia_status_info = pa_bia_status_info; |
|
1165 | 1165 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1166 | 1166 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); |
|
1167 | 1167 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
1168 | 1168 | |
|
1169 | 1169 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform |
|
1170 | 1170 | { |
|
1171 | 1171 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; |
|
1172 | 1172 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1173 | 1173 | // BUILD THE DATA |
|
1174 | 1174 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; |
|
1175 | 1175 | |
|
1176 | 1176 | // SET PACKET SEQUENCE CONTROL |
|
1177 | 1177 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1178 | 1178 | |
|
1179 | 1179 | // SET SID |
|
1180 | 1180 | header->sid = sid; |
|
1181 | 1181 | |
|
1182 | 1182 | // SET PACKET TIME |
|
1183 | 1183 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); |
|
1184 | 1184 | // |
|
1185 | 1185 | header->time[0] = header->acquisitionTime[0]; |
|
1186 | 1186 | header->time[1] = header->acquisitionTime[1]; |
|
1187 | 1187 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1188 | 1188 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1189 | 1189 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1190 | 1190 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1191 | 1191 | |
|
1192 | 1192 | // SET PACKET ID |
|
1193 | 1193 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) |
|
1194 | 1194 | { |
|
1195 | 1195 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE); |
|
1196 | 1196 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); |
|
1197 | 1197 | } |
|
1198 | 1198 | else |
|
1199 | 1199 | { |
|
1200 | 1200 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1201 | 1201 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1202 | 1202 | } |
|
1203 | 1203 | |
|
1204 | 1204 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1205 | 1205 | if (status != RTEMS_SUCCESSFUL) { |
|
1206 | 1206 | ret = LFR_DEFAULT; |
|
1207 | 1207 | } |
|
1208 | 1208 | } |
|
1209 | 1209 | |
|
1210 | 1210 | return ret; |
|
1211 | 1211 | } |
|
1212 | 1212 | |
|
1213 | 1213 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, |
|
1214 | 1214 | Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1215 | 1215 | { |
|
1216 | 1216 | /** This function sends SWF CCSDS packets (F2, F1 or F0). |
|
1217 | 1217 | * |
|
1218 | 1218 | * @param waveform points to the buffer containing the data that will be send. |
|
1219 | 1219 | * @param sid is the source identifier of the data that will be sent. |
|
1220 | 1220 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. |
|
1221 | 1221 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1222 | 1222 | * contain information to setup the transmission of the data packets. |
|
1223 | 1223 | * |
|
1224 | 1224 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1225 | 1225 | * |
|
1226 | 1226 | */ |
|
1227 | 1227 | |
|
1228 | 1228 | unsigned int i; |
|
1229 | 1229 | int ret; |
|
1230 | 1230 | unsigned int coarseTime; |
|
1231 | 1231 | unsigned int fineTime; |
|
1232 | 1232 | rtems_status_code status; |
|
1233 | 1233 | spw_ioctl_pkt_send spw_ioctl_send_SWF; |
|
1234 | 1234 | int *dataPtr; |
|
1235 | 1235 | unsigned char sid; |
|
1236 | 1236 | |
|
1237 | 1237 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; |
|
1238 | 1238 | spw_ioctl_send_SWF.options = 0; |
|
1239 | 1239 | |
|
1240 | 1240 | ret = LFR_DEFAULT; |
|
1241 | 1241 | |
|
1242 | 1242 | coarseTime = ring_node_to_send->coarseTime; |
|
1243 | 1243 | fineTime = ring_node_to_send->fineTime; |
|
1244 | 1244 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1245 | 1245 | sid = ring_node_to_send->sid; |
|
1246 | 1246 | |
|
1247 | 1247 | header->pa_bia_status_info = pa_bia_status_info; |
|
1248 | 1248 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1249 | 1249 | |
|
1250 | 1250 | for (i=0; i<PKTCNT_SWF; i++) // send waveform |
|
1251 | 1251 | { |
|
1252 | 1252 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; |
|
1253 | 1253 | spw_ioctl_send_SWF.hdr = (char*) header; |
|
1254 | 1254 | |
|
1255 | 1255 | // SET PACKET SEQUENCE CONTROL |
|
1256 | 1256 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1257 | 1257 | |
|
1258 | 1258 | // SET PACKET LENGTH AND BLKNR |
|
1259 | 1259 | if (i == (PKTCNT_SWF-1)) |
|
1260 | 1260 | { |
|
1261 | 1261 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; |
|
1262 | 1262 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE); |
|
1263 | 1263 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); |
|
1264 | 1264 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE); |
|
1265 | 1265 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); |
|
1266 | 1266 | } |
|
1267 | 1267 | else |
|
1268 | 1268 | { |
|
1269 | 1269 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; |
|
1270 | 1270 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE); |
|
1271 | 1271 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); |
|
1272 | 1272 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE); |
|
1273 | 1273 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); |
|
1274 | 1274 | } |
|
1275 | 1275 | |
|
1276 | 1276 | // SET PACKET TIME |
|
1277 | 1277 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); |
|
1278 | 1278 | // |
|
1279 | 1279 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; |
|
1280 | 1280 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; |
|
1281 | 1281 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1282 | 1282 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1283 | 1283 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1284 | 1284 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1285 | 1285 | |
|
1286 | 1286 | // SET SID |
|
1287 | 1287 | header->sid = sid; |
|
1288 | 1288 | |
|
1289 | 1289 | // SET PKTNR |
|
1290 | 1290 | header->pktNr = i+1; // PKT_NR |
|
1291 | 1291 | |
|
1292 | 1292 | // SEND PACKET |
|
1293 | 1293 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); |
|
1294 | 1294 | if (status != RTEMS_SUCCESSFUL) { |
|
1295 | 1295 | ret = LFR_DEFAULT; |
|
1296 | 1296 | } |
|
1297 | 1297 | } |
|
1298 | 1298 | |
|
1299 | 1299 | return ret; |
|
1300 | 1300 | } |
|
1301 | 1301 | |
|
1302 | 1302 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, |
|
1303 | 1303 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1304 | 1304 | { |
|
1305 | 1305 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
1306 | 1306 | * |
|
1307 | 1307 | * @param waveform points to the buffer containing the data that will be send. |
|
1308 | 1308 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1309 | 1309 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1310 | 1310 | * contain information to setup the transmission of the data packets. |
|
1311 | 1311 | * |
|
1312 | 1312 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
1313 | 1313 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
1314 | 1314 | * |
|
1315 | 1315 | */ |
|
1316 | 1316 | |
|
1317 | 1317 | unsigned int i; |
|
1318 | 1318 | int ret; |
|
1319 | 1319 | unsigned int coarseTime; |
|
1320 | 1320 | unsigned int fineTime; |
|
1321 | 1321 | rtems_status_code status; |
|
1322 | 1322 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1323 | 1323 | char *dataPtr; |
|
1324 | 1324 | unsigned char sid; |
|
1325 | 1325 | |
|
1326 | 1326 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1327 | 1327 | spw_ioctl_send_CWF.options = 0; |
|
1328 | 1328 | |
|
1329 | 1329 | ret = LFR_DEFAULT; |
|
1330 | 1330 | sid = ring_node_to_send->sid; |
|
1331 | 1331 | |
|
1332 | 1332 | coarseTime = ring_node_to_send->coarseTime; |
|
1333 | 1333 | fineTime = ring_node_to_send->fineTime; |
|
1334 | 1334 | dataPtr = (char*) ring_node_to_send->buffer_address; |
|
1335 | 1335 | |
|
1336 | 1336 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE); |
|
1337 | 1337 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); |
|
1338 | 1338 | header->pa_bia_status_info = pa_bia_status_info; |
|
1339 | 1339 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1340 | 1340 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE); |
|
1341 | 1341 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); |
|
1342 | 1342 | |
|
1343 | 1343 | //********************* |
|
1344 | 1344 | // SEND CWF3_light DATA |
|
1345 | 1345 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform |
|
1346 | 1346 | { |
|
1347 | 1347 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; |
|
1348 | 1348 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1349 | 1349 | // BUILD THE DATA |
|
1350 | 1350 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; |
|
1351 | 1351 | |
|
1352 | 1352 | // SET PACKET SEQUENCE COUNTER |
|
1353 | 1353 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1354 | 1354 | |
|
1355 | 1355 | // SET SID |
|
1356 | 1356 | header->sid = sid; |
|
1357 | 1357 | |
|
1358 | 1358 | // SET PACKET TIME |
|
1359 | 1359 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); |
|
1360 | 1360 | // |
|
1361 | 1361 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; |
|
1362 | 1362 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; |
|
1363 | 1363 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1364 | 1364 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1365 | 1365 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1366 | 1366 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1367 | 1367 | |
|
1368 | 1368 | // SET PACKET ID |
|
1369 | 1369 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1370 | 1370 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1371 | 1371 | |
|
1372 | 1372 | // SEND PACKET |
|
1373 | 1373 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1374 | 1374 | if (status != RTEMS_SUCCESSFUL) { |
|
1375 | 1375 | ret = LFR_DEFAULT; |
|
1376 | 1376 | } |
|
1377 | 1377 | } |
|
1378 | 1378 | |
|
1379 | 1379 | return ret; |
|
1380 | 1380 | } |
|
1381 | 1381 | |
|
1382 | 1382 | void spw_send_asm_f0( ring_node *ring_node_to_send, |
|
1383 | 1383 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1384 | 1384 | { |
|
1385 | 1385 | unsigned int i; |
|
1386 | 1386 | unsigned int length = 0; |
|
1387 | 1387 | rtems_status_code status; |
|
1388 | 1388 | unsigned int sid; |
|
1389 | 1389 | float *spectral_matrix; |
|
1390 | 1390 | int coarseTime; |
|
1391 | 1391 | int fineTime; |
|
1392 | 1392 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1393 | 1393 | |
|
1394 | 1394 | sid = ring_node_to_send->sid; |
|
1395 | 1395 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1396 | 1396 | coarseTime = ring_node_to_send->coarseTime; |
|
1397 | 1397 | fineTime = ring_node_to_send->fineTime; |
|
1398 | 1398 | |
|
1399 | 1399 | header->pa_bia_status_info = pa_bia_status_info; |
|
1400 | 1400 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1401 | 1401 | |
|
1402 | 1402 | for (i=0; i<PKTCNT_ASM; i++) |
|
1403 | 1403 | { |
|
1404 | 1404 | if ((i==0) || (i==1)) |
|
1405 | 1405 | { |
|
1406 | 1406 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; |
|
1407 | 1407 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1408 | 1408 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1409 | 1409 | ]; |
|
1410 | 1410 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; |
|
1411 | 1411 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1412 | 1412 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1413 | 1413 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB |
|
1414 | 1414 | } |
|
1415 | 1415 | else |
|
1416 | 1416 | { |
|
1417 | 1417 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; |
|
1418 | 1418 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1419 | 1419 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1420 | 1420 | ]; |
|
1421 | 1421 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; |
|
1422 | 1422 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1423 | 1423 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1424 | 1424 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB |
|
1425 | 1425 | } |
|
1426 | 1426 | |
|
1427 | 1427 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1428 | 1428 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1429 | 1429 | spw_ioctl_send_ASM.options = 0; |
|
1430 | 1430 | |
|
1431 | 1431 | // (2) BUILD THE HEADER |
|
1432 | 1432 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1433 | 1433 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1434 | 1434 | header->packetLength[1] = (unsigned char) (length); |
|
1435 | 1435 | header->sid = (unsigned char) sid; // SID |
|
1436 | 1436 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1437 | 1437 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1438 | 1438 | |
|
1439 | 1439 | // (3) SET PACKET TIME |
|
1440 | 1440 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1441 | 1441 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1442 | 1442 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1443 | 1443 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1444 | 1444 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1445 | 1445 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1446 | 1446 | // |
|
1447 | 1447 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1448 | 1448 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1449 | 1449 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1450 | 1450 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1451 | 1451 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1452 | 1452 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1453 | 1453 | |
|
1454 | 1454 | // (4) SEND PACKET |
|
1455 | 1455 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1456 | 1456 | if (status != RTEMS_SUCCESSFUL) { |
|
1457 | 1457 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1458 | 1458 | } |
|
1459 | 1459 | } |
|
1460 | 1460 | } |
|
1461 | 1461 | |
|
1462 | 1462 | void spw_send_asm_f1( ring_node *ring_node_to_send, |
|
1463 | 1463 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1464 | 1464 | { |
|
1465 | 1465 | unsigned int i; |
|
1466 | 1466 | unsigned int length = 0; |
|
1467 | 1467 | rtems_status_code status; |
|
1468 | 1468 | unsigned int sid; |
|
1469 | 1469 | float *spectral_matrix; |
|
1470 | 1470 | int coarseTime; |
|
1471 | 1471 | int fineTime; |
|
1472 | 1472 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1473 | 1473 | |
|
1474 | 1474 | sid = ring_node_to_send->sid; |
|
1475 | 1475 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1476 | 1476 | coarseTime = ring_node_to_send->coarseTime; |
|
1477 | 1477 | fineTime = ring_node_to_send->fineTime; |
|
1478 | 1478 | |
|
1479 | 1479 | header->pa_bia_status_info = pa_bia_status_info; |
|
1480 | 1480 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1481 | 1481 | |
|
1482 | 1482 | for (i=0; i<PKTCNT_ASM; i++) |
|
1483 | 1483 | { |
|
1484 | 1484 | if ((i==0) || (i==1)) |
|
1485 | 1485 | { |
|
1486 | 1486 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; |
|
1487 | 1487 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1488 | 1488 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1489 | 1489 | ]; |
|
1490 | 1490 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; |
|
1491 | 1491 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1492 | 1492 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1493 | 1493 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB |
|
1494 | 1494 | } |
|
1495 | 1495 | else |
|
1496 | 1496 | { |
|
1497 | 1497 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; |
|
1498 | 1498 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1499 | 1499 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1500 | 1500 | ]; |
|
1501 | 1501 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; |
|
1502 | 1502 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1503 | 1503 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1504 | 1504 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB |
|
1505 | 1505 | } |
|
1506 | 1506 | |
|
1507 | 1507 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1508 | 1508 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1509 | 1509 | spw_ioctl_send_ASM.options = 0; |
|
1510 | 1510 | |
|
1511 | 1511 | // (2) BUILD THE HEADER |
|
1512 | 1512 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1513 | 1513 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1514 | 1514 | header->packetLength[1] = (unsigned char) (length); |
|
1515 | 1515 | header->sid = (unsigned char) sid; // SID |
|
1516 | 1516 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1517 | 1517 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1518 | 1518 | |
|
1519 | 1519 | // (3) SET PACKET TIME |
|
1520 | 1520 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1521 | 1521 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1522 | 1522 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1523 | 1523 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1524 | 1524 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1525 | 1525 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1526 | 1526 | // |
|
1527 | 1527 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1528 | 1528 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1529 | 1529 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1530 | 1530 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1531 | 1531 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1532 | 1532 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1533 | 1533 | |
|
1534 | 1534 | // (4) SEND PACKET |
|
1535 | 1535 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1536 | 1536 | if (status != RTEMS_SUCCESSFUL) { |
|
1537 | 1537 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1538 | 1538 | } |
|
1539 | 1539 | } |
|
1540 | 1540 | } |
|
1541 | 1541 | |
|
1542 | 1542 | void spw_send_asm_f2( ring_node *ring_node_to_send, |
|
1543 | 1543 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1544 | 1544 | { |
|
1545 | 1545 | unsigned int i; |
|
1546 | 1546 | unsigned int length = 0; |
|
1547 | 1547 | rtems_status_code status; |
|
1548 | 1548 | unsigned int sid; |
|
1549 | 1549 | float *spectral_matrix; |
|
1550 | 1550 | int coarseTime; |
|
1551 | 1551 | int fineTime; |
|
1552 | 1552 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1553 | 1553 | |
|
1554 | 1554 | sid = ring_node_to_send->sid; |
|
1555 | 1555 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1556 | 1556 | coarseTime = ring_node_to_send->coarseTime; |
|
1557 | 1557 | fineTime = ring_node_to_send->fineTime; |
|
1558 | 1558 | |
|
1559 | 1559 | header->pa_bia_status_info = pa_bia_status_info; |
|
1560 | 1560 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1561 | 1561 | |
|
1562 | 1562 | for (i=0; i<PKTCNT_ASM; i++) |
|
1563 | 1563 | { |
|
1564 | 1564 | |
|
1565 | 1565 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; |
|
1566 | 1566 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1567 | 1567 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) |
|
1568 | 1568 | ]; |
|
1569 | 1569 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; |
|
1570 | 1570 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; |
|
1571 | 1571 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1572 | 1572 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB |
|
1573 | 1573 | |
|
1574 | 1574 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1575 | 1575 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1576 | 1576 | spw_ioctl_send_ASM.options = 0; |
|
1577 | 1577 | |
|
1578 | 1578 | // (2) BUILD THE HEADER |
|
1579 | 1579 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1580 | 1580 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1581 | 1581 | header->packetLength[1] = (unsigned char) (length); |
|
1582 | 1582 | header->sid = (unsigned char) sid; // SID |
|
1583 | 1583 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1584 | 1584 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1585 | 1585 | |
|
1586 | 1586 | // (3) SET PACKET TIME |
|
1587 | 1587 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1588 | 1588 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1589 | 1589 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1590 | 1590 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1591 | 1591 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1592 | 1592 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1593 | 1593 | // |
|
1594 | 1594 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1595 | 1595 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1596 | 1596 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1597 | 1597 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1598 | 1598 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1599 | 1599 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1600 | 1600 | |
|
1601 | 1601 | // (4) SEND PACKET |
|
1602 | 1602 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1603 | 1603 | if (status != RTEMS_SUCCESSFUL) { |
|
1604 | 1604 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1605 | 1605 | } |
|
1606 | 1606 | } |
|
1607 | 1607 | } |
|
1608 | 1608 | |
|
1609 | 1609 | void spw_send_k_dump( ring_node *ring_node_to_send ) |
|
1610 | 1610 | { |
|
1611 | 1611 | rtems_status_code status; |
|
1612 | 1612 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; |
|
1613 | 1613 | unsigned int packetLength; |
|
1614 | 1614 | unsigned int size; |
|
1615 | 1615 | |
|
1616 | 1616 | PRINTF("spw_send_k_dump\n") |
|
1617 | 1617 | |
|
1618 | 1618 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; |
|
1619 | 1619 | |
|
1620 | 1620 | packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1]; |
|
1621 | 1621 | |
|
1622 | 1622 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
1623 | 1623 | |
|
1624 | 1624 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) |
|
1625 | 1625 | |
|
1626 | 1626 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); |
|
1627 | 1627 | |
|
1628 | 1628 | if (status == -1){ |
|
1629 | 1629 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
1630 | 1630 | } |
|
1631 | 1631 | |
|
1632 | 1632 | ring_node_to_send->status = INIT_CHAR; |
|
1633 | 1633 | } |
@@ -1,1669 +1,1661 | |||
|
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 __attribute__((aligned(4))) 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[BYTES_PER_TIME]; |
|
36 | 36 | rtems_id queue_rcv_id; |
|
37 | 37 | rtems_id queue_snd_id; |
|
38 | 38 | |
|
39 | 39 | memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t)); |
|
40 | 40 | size = 0; |
|
41 | 41 | queue_rcv_id = RTEMS_ID_NONE; |
|
42 | 42 | queue_snd_id = RTEMS_ID_NONE; |
|
43 | 43 | |
|
44 | 44 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
45 | 45 | if (status != RTEMS_SUCCESSFUL) |
|
46 | 46 | { |
|
47 | 47 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | status = get_message_queue_id_send( &queue_snd_id ); |
|
51 | 51 | if (status != RTEMS_SUCCESSFUL) |
|
52 | 52 | { |
|
53 | 53 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | result = LFR_SUCCESSFUL; |
|
57 | 57 | subtype = 0; // subtype of the current TC packet |
|
58 | 58 | |
|
59 | 59 | BOOT_PRINTF("in ACTN *** \n"); |
|
60 | 60 | |
|
61 | 61 | while(1) |
|
62 | 62 | { |
|
63 | 63 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
64 | 64 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
65 | 65 | getTime( time ); // set time to the current time |
|
66 | 66 | if (status!=RTEMS_SUCCESSFUL) |
|
67 | 67 | { |
|
68 | 68 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
69 | 69 | } |
|
70 | 70 | else |
|
71 | 71 | { |
|
72 | 72 | subtype = TC.serviceSubType; |
|
73 | 73 | switch(subtype) |
|
74 | 74 | { |
|
75 | 75 | case TC_SUBTYPE_RESET: |
|
76 | 76 | result = action_reset( &TC, queue_snd_id, time ); |
|
77 | 77 | close_action( &TC, result, queue_snd_id ); |
|
78 | 78 | break; |
|
79 | 79 | case TC_SUBTYPE_LOAD_COMM: |
|
80 | 80 | result = action_load_common_par( &TC ); |
|
81 | 81 | close_action( &TC, result, queue_snd_id ); |
|
82 | 82 | break; |
|
83 | 83 | case TC_SUBTYPE_LOAD_NORM: |
|
84 | 84 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
85 | 85 | close_action( &TC, result, queue_snd_id ); |
|
86 | 86 | break; |
|
87 | 87 | case TC_SUBTYPE_LOAD_BURST: |
|
88 | 88 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
89 | 89 | close_action( &TC, result, queue_snd_id ); |
|
90 | 90 | break; |
|
91 | 91 | case TC_SUBTYPE_LOAD_SBM1: |
|
92 | 92 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
93 | 93 | close_action( &TC, result, queue_snd_id ); |
|
94 | 94 | break; |
|
95 | 95 | case TC_SUBTYPE_LOAD_SBM2: |
|
96 | 96 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
97 | 97 | close_action( &TC, result, queue_snd_id ); |
|
98 | 98 | break; |
|
99 | 99 | case TC_SUBTYPE_DUMP: |
|
100 | 100 | result = action_dump_par( &TC, queue_snd_id ); |
|
101 | 101 | close_action( &TC, result, queue_snd_id ); |
|
102 | 102 | break; |
|
103 | 103 | case TC_SUBTYPE_ENTER: |
|
104 | 104 | result = action_enter_mode( &TC, queue_snd_id ); |
|
105 | 105 | close_action( &TC, result, queue_snd_id ); |
|
106 | 106 | break; |
|
107 | 107 | case TC_SUBTYPE_UPDT_INFO: |
|
108 | 108 | result = action_update_info( &TC, queue_snd_id ); |
|
109 | 109 | close_action( &TC, result, queue_snd_id ); |
|
110 | 110 | break; |
|
111 | 111 | case TC_SUBTYPE_EN_CAL: |
|
112 | 112 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
113 | 113 | close_action( &TC, result, queue_snd_id ); |
|
114 | 114 | break; |
|
115 | 115 | case TC_SUBTYPE_DIS_CAL: |
|
116 | 116 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
117 | 117 | close_action( &TC, result, queue_snd_id ); |
|
118 | 118 | break; |
|
119 | 119 | case TC_SUBTYPE_LOAD_K: |
|
120 | 120 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
121 | 121 | close_action( &TC, result, queue_snd_id ); |
|
122 | 122 | break; |
|
123 | 123 | case TC_SUBTYPE_DUMP_K: |
|
124 | 124 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
125 | 125 | close_action( &TC, result, queue_snd_id ); |
|
126 | 126 | break; |
|
127 | 127 | case TC_SUBTYPE_LOAD_FBINS: |
|
128 | 128 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
129 | 129 | close_action( &TC, result, queue_snd_id ); |
|
130 | 130 | break; |
|
131 | 131 | case TC_SUBTYPE_LOAD_FILTER_PAR: |
|
132 | 132 | result = action_load_filter_par( &TC, queue_snd_id, time ); |
|
133 | 133 | close_action( &TC, result, queue_snd_id ); |
|
134 | 134 | break; |
|
135 | 135 | case TC_SUBTYPE_UPDT_TIME: |
|
136 | 136 | result = action_update_time( &TC ); |
|
137 | 137 | close_action( &TC, result, queue_snd_id ); |
|
138 | 138 | break; |
|
139 | 139 | default: |
|
140 | 140 | break; |
|
141 | 141 | } |
|
142 | 142 | } |
|
143 | 143 | } |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | //*********** |
|
147 | 147 | // TC ACTIONS |
|
148 | 148 | |
|
149 | 149 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
150 | 150 | { |
|
151 | 151 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
152 | 152 | * |
|
153 | 153 | * @param TC points to the TeleCommand packet that is being processed |
|
154 | 154 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
155 | 155 | * |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | PRINTF("this is the end!!!\n"); |
|
159 | 159 | exit(0); |
|
160 | 160 | |
|
161 | 161 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
162 | 162 | |
|
163 | 163 | return LFR_DEFAULT; |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
167 | 167 | { |
|
168 | 168 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
169 | 169 | * |
|
170 | 170 | * @param TC points to the TeleCommand packet that is being processed |
|
171 | 171 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
172 | 172 | * |
|
173 | 173 | */ |
|
174 | 174 | |
|
175 | 175 | rtems_status_code status; |
|
176 | 176 | unsigned char requestedMode; |
|
177 | 177 | unsigned int transitionCoarseTime; |
|
178 | 178 | unsigned char * bytePosPtr; |
|
179 | 179 | |
|
180 | printf("(0)\n"); | |
|
181 | 180 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
182 | printf("(1)\n"); | |
|
183 | 181 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
184 | printf("(2)\n"); | |
|
185 | 182 | copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
186 | printf("(3)\n"); | |
|
187 | 183 | transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK; |
|
188 | printf("(4)\n"); | |
|
189 | 184 | status = check_mode_value( requestedMode ); |
|
190 | printf("(5)\n"); | |
|
191 | 185 | |
|
192 | 186 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
193 | 187 | { |
|
194 | 188 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
195 | 189 | } |
|
196 | 190 | |
|
197 | 191 | else // the mode value is valid, check the transition |
|
198 | 192 | { |
|
199 | 193 | status = check_mode_transition(requestedMode); |
|
200 | 194 | if (status != LFR_SUCCESSFUL) |
|
201 | 195 | { |
|
202 | 196 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
203 | 197 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
204 | 198 | } |
|
205 | 199 | } |
|
206 | 200 | |
|
207 | 201 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date |
|
208 | 202 | { |
|
209 | 203 | status = check_transition_date( transitionCoarseTime ); |
|
210 | 204 | if (status != LFR_SUCCESSFUL) |
|
211 | 205 | { |
|
212 | 206 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n"); |
|
213 | 207 | send_tm_lfr_tc_exe_not_executable(TC, queue_id ); |
|
214 | 208 | } |
|
215 | 209 | } |
|
216 | 210 | |
|
217 | 211 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
218 | 212 | { |
|
219 | 213 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
220 | 214 | |
|
221 | 215 | switch(requestedMode) |
|
222 | 216 | { |
|
223 | 217 | case LFR_MODE_STANDBY: |
|
224 | 218 | status = enter_mode_standby(); |
|
225 | 219 | break; |
|
226 | 220 | case LFR_MODE_NORMAL: |
|
227 | 221 | status = enter_mode_normal( transitionCoarseTime ); |
|
228 | 222 | break; |
|
229 | 223 | case LFR_MODE_BURST: |
|
230 | 224 | status = enter_mode_burst( transitionCoarseTime ); |
|
231 | 225 | break; |
|
232 | 226 | case LFR_MODE_SBM1: |
|
233 | 227 | status = enter_mode_sbm1( transitionCoarseTime ); |
|
234 | 228 | break; |
|
235 | 229 | case LFR_MODE_SBM2: |
|
236 | 230 | status = enter_mode_sbm2( transitionCoarseTime ); |
|
237 | 231 | break; |
|
238 | 232 | default: |
|
239 | 233 | break; |
|
240 | 234 | } |
|
241 | 235 | |
|
242 | 236 | if (status != RTEMS_SUCCESSFUL) |
|
243 | 237 | { |
|
244 | 238 | status = LFR_EXE_ERROR; |
|
245 | 239 | } |
|
246 | 240 | } |
|
247 | 241 | |
|
248 | 242 | return status; |
|
249 | 243 | } |
|
250 | 244 | |
|
251 | 245 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
252 | 246 | { |
|
253 | 247 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
254 | 248 | * |
|
255 | 249 | * @param TC points to the TeleCommand packet that is being processed |
|
256 | 250 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
257 | 251 | * |
|
258 | 252 | * @return LFR directive status code: |
|
259 | 253 | * - LFR_DEFAULT |
|
260 | 254 | * - LFR_SUCCESSFUL |
|
261 | 255 | * |
|
262 | 256 | */ |
|
263 | 257 | |
|
264 | 258 | unsigned int val; |
|
265 | 259 | int result; |
|
266 | 260 | unsigned int status; |
|
267 | 261 | unsigned char mode; |
|
268 | 262 | unsigned char * bytePosPtr; |
|
269 | 263 | |
|
270 | 264 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
271 | 265 | |
|
272 | 266 | // check LFR mode |
|
273 | 267 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE; |
|
274 | 268 | status = check_update_info_hk_lfr_mode( mode ); |
|
275 | 269 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
276 | 270 | { |
|
277 | 271 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE; |
|
278 | 272 | status = check_update_info_hk_tds_mode( mode ); |
|
279 | 273 | } |
|
280 | 274 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
281 | 275 | { |
|
282 | 276 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE); |
|
283 | 277 | status = check_update_info_hk_thr_mode( mode ); |
|
284 | 278 | } |
|
285 | 279 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
286 | 280 | { |
|
287 | 281 | val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256) |
|
288 | 282 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
289 | 283 | val++; |
|
290 | 284 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
291 | 285 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
292 | 286 | } |
|
293 | 287 | |
|
294 | 288 | // pa_bia_status_info |
|
295 | 289 | // => pa_bia_mode_mux_set 3 bits |
|
296 | 290 | // => pa_bia_mode_hv_enabled 1 bit |
|
297 | 291 | // => pa_bia_mode_bias1_enabled 1 bit |
|
298 | 292 | // => pa_bia_mode_bias2_enabled 1 bit |
|
299 | 293 | // => pa_bia_mode_bias3_enabled 1 bit |
|
300 | 294 | // => pa_bia_on_off (cp_dpu_bias_on_off) |
|
301 | 295 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110] |
|
302 | 296 | pa_bia_status_info = pa_bia_status_info |
|
303 | 297 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1); |
|
304 | 298 | |
|
305 | 299 | // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets) |
|
306 | 300 | |
|
307 | 301 | //cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ]; |
|
308 | 302 | getReactionWheelsFrequencies( TC ); |
|
309 | 303 | set_hk_lfr_sc_rw_f_flags(); |
|
310 | 304 | build_sy_lfr_rw_masks(); |
|
311 | 305 | |
|
312 | 306 | // once the masks are built, they have to be merged with the fbins_mask |
|
313 | 307 | merge_fbins_masks(); |
|
314 | 308 | |
|
315 | 309 | result = status; |
|
316 | 310 | |
|
317 | 311 | return result; |
|
318 | 312 | } |
|
319 | 313 | |
|
320 | 314 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
321 | 315 | { |
|
322 | 316 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
323 | 317 | * |
|
324 | 318 | * @param TC points to the TeleCommand packet that is being processed |
|
325 | 319 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
326 | 320 | * |
|
327 | 321 | */ |
|
328 | 322 | |
|
329 | 323 | int result; |
|
330 | 324 | |
|
331 | 325 | result = LFR_DEFAULT; |
|
332 | 326 | |
|
333 | 327 | setCalibration( true ); |
|
334 | 328 | |
|
335 | 329 | result = LFR_SUCCESSFUL; |
|
336 | 330 | |
|
337 | 331 | return result; |
|
338 | 332 | } |
|
339 | 333 | |
|
340 | 334 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
341 | 335 | { |
|
342 | 336 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
343 | 337 | * |
|
344 | 338 | * @param TC points to the TeleCommand packet that is being processed |
|
345 | 339 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
346 | 340 | * |
|
347 | 341 | */ |
|
348 | 342 | |
|
349 | 343 | int result; |
|
350 | 344 | |
|
351 | 345 | result = LFR_DEFAULT; |
|
352 | 346 | |
|
353 | 347 | setCalibration( false ); |
|
354 | 348 | |
|
355 | 349 | result = LFR_SUCCESSFUL; |
|
356 | 350 | |
|
357 | 351 | return result; |
|
358 | 352 | } |
|
359 | 353 | |
|
360 | 354 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
361 | 355 | { |
|
362 | 356 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
363 | 357 | * |
|
364 | 358 | * @param TC points to the TeleCommand packet that is being processed |
|
365 | 359 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
366 | 360 | * |
|
367 | 361 | * @return LFR_SUCCESSFUL |
|
368 | 362 | * |
|
369 | 363 | */ |
|
370 | 364 | |
|
371 | 365 | unsigned int val; |
|
372 | 366 | |
|
373 | 367 | time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES) |
|
374 | 368 | + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES) |
|
375 | 369 | + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE) |
|
376 | 370 | + TC->dataAndCRC[BYTE_3]; |
|
377 | 371 | |
|
378 | 372 | val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256) |
|
379 | 373 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
380 | 374 | val++; |
|
381 | 375 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
382 | 376 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
383 | 377 | |
|
384 | 378 | oneTcLfrUpdateTimeReceived = 1; |
|
385 | 379 | |
|
386 | 380 | return LFR_SUCCESSFUL; |
|
387 | 381 | } |
|
388 | 382 | |
|
389 | 383 | //******************* |
|
390 | 384 | // ENTERING THE MODES |
|
391 | 385 | int check_mode_value( unsigned char requestedMode ) |
|
392 | 386 | { |
|
393 | 387 | int status; |
|
394 | 388 | |
|
395 | 389 | status = LFR_DEFAULT; |
|
396 | 390 | |
|
397 | 391 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
398 | 392 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
399 | 393 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
400 | 394 | { |
|
401 | 395 | status = LFR_DEFAULT; |
|
402 | 396 | } |
|
403 | 397 | else |
|
404 | 398 | { |
|
405 | 399 | status = LFR_SUCCESSFUL; |
|
406 | 400 | } |
|
407 | 401 | |
|
408 | 402 | return status; |
|
409 | 403 | } |
|
410 | 404 | |
|
411 | 405 | int check_mode_transition( unsigned char requestedMode ) |
|
412 | 406 | { |
|
413 | 407 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
414 | 408 | * |
|
415 | 409 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
416 | 410 | * |
|
417 | 411 | * @return LFR directive status codes: |
|
418 | 412 | * - LFR_SUCCESSFUL - the transition is authorized |
|
419 | 413 | * - LFR_DEFAULT - the transition is not authorized |
|
420 | 414 | * |
|
421 | 415 | */ |
|
422 | 416 | |
|
423 | 417 | int status; |
|
424 | 418 | |
|
425 | 419 | switch (requestedMode) |
|
426 | 420 | { |
|
427 | 421 | case LFR_MODE_STANDBY: |
|
428 | 422 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
429 | 423 | status = LFR_DEFAULT; |
|
430 | 424 | } |
|
431 | 425 | else |
|
432 | 426 | { |
|
433 | 427 | status = LFR_SUCCESSFUL; |
|
434 | 428 | } |
|
435 | 429 | break; |
|
436 | 430 | case LFR_MODE_NORMAL: |
|
437 | 431 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
438 | 432 | status = LFR_DEFAULT; |
|
439 | 433 | } |
|
440 | 434 | else { |
|
441 | 435 | status = LFR_SUCCESSFUL; |
|
442 | 436 | } |
|
443 | 437 | break; |
|
444 | 438 | case LFR_MODE_BURST: |
|
445 | 439 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
446 | 440 | status = LFR_DEFAULT; |
|
447 | 441 | } |
|
448 | 442 | else { |
|
449 | 443 | status = LFR_SUCCESSFUL; |
|
450 | 444 | } |
|
451 | 445 | break; |
|
452 | 446 | case LFR_MODE_SBM1: |
|
453 | 447 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
454 | 448 | status = LFR_DEFAULT; |
|
455 | 449 | } |
|
456 | 450 | else { |
|
457 | 451 | status = LFR_SUCCESSFUL; |
|
458 | 452 | } |
|
459 | 453 | break; |
|
460 | 454 | case LFR_MODE_SBM2: |
|
461 | 455 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
462 | 456 | status = LFR_DEFAULT; |
|
463 | 457 | } |
|
464 | 458 | else { |
|
465 | 459 | status = LFR_SUCCESSFUL; |
|
466 | 460 | } |
|
467 | 461 | break; |
|
468 | 462 | default: |
|
469 | 463 | status = LFR_DEFAULT; |
|
470 | 464 | break; |
|
471 | 465 | } |
|
472 | 466 | |
|
473 | 467 | return status; |
|
474 | 468 | } |
|
475 | 469 | |
|
476 | 470 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) |
|
477 | 471 | { |
|
478 | 472 | if (transitionCoarseTime == 0) |
|
479 | 473 | { |
|
480 | 474 | lastValidEnterModeTime = time_management_regs->coarse_time + 1; |
|
481 | 475 | PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime); |
|
482 | 476 | } |
|
483 | 477 | else |
|
484 | 478 | { |
|
485 | 479 | lastValidEnterModeTime = transitionCoarseTime; |
|
486 | 480 | PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); |
|
487 | 481 | } |
|
488 | 482 | } |
|
489 | 483 | |
|
490 | 484 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
491 | 485 | { |
|
492 | 486 | int status; |
|
493 | 487 | unsigned int localCoarseTime; |
|
494 | 488 | unsigned int deltaCoarseTime; |
|
495 | 489 | |
|
496 | 490 | status = LFR_SUCCESSFUL; |
|
497 | 491 | |
|
498 | 492 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
499 | 493 | { |
|
500 | 494 | status = LFR_SUCCESSFUL; |
|
501 | 495 | } |
|
502 | 496 | else |
|
503 | 497 | { |
|
504 | 498 | localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK; |
|
505 | 499 | |
|
506 | 500 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime); |
|
507 | 501 | |
|
508 | 502 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
509 | 503 | { |
|
510 | 504 | status = LFR_DEFAULT; |
|
511 | 505 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n"); |
|
512 | 506 | } |
|
513 | 507 | |
|
514 | 508 | if (status == LFR_SUCCESSFUL) |
|
515 | 509 | { |
|
516 | 510 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
517 | 511 | if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323 |
|
518 | 512 | { |
|
519 | 513 | status = LFR_DEFAULT; |
|
520 | 514 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
521 | 515 | } |
|
522 | 516 | } |
|
523 | 517 | } |
|
524 | 518 | |
|
525 | 519 | return status; |
|
526 | 520 | } |
|
527 | 521 | |
|
528 | 522 | int restart_asm_activities( unsigned char lfrRequestedMode ) |
|
529 | 523 | { |
|
530 | 524 | rtems_status_code status; |
|
531 | 525 | |
|
532 | 526 | status = stop_spectral_matrices(); |
|
533 | 527 | |
|
534 | 528 | thisIsAnASMRestart = 1; |
|
535 | 529 | |
|
536 | 530 | status = restart_asm_tasks( lfrRequestedMode ); |
|
537 | 531 | |
|
538 | 532 | launch_spectral_matrix(); |
|
539 | 533 | |
|
540 | 534 | return status; |
|
541 | 535 | } |
|
542 | 536 | |
|
543 | 537 | int stop_spectral_matrices( void ) |
|
544 | 538 | { |
|
545 | 539 | /** This function stops and restarts the current mode average spectral matrices activities. |
|
546 | 540 | * |
|
547 | 541 | * @return RTEMS directive status codes: |
|
548 | 542 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
549 | 543 | * - RTEMS_INVALID_ID - task id invalid |
|
550 | 544 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
551 | 545 | * |
|
552 | 546 | */ |
|
553 | 547 | |
|
554 | 548 | rtems_status_code status; |
|
555 | 549 | |
|
556 | 550 | status = RTEMS_SUCCESSFUL; |
|
557 | 551 | |
|
558 | 552 | // (1) mask interruptions |
|
559 | 553 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt |
|
560 | 554 | |
|
561 | 555 | // (2) reset spectral matrices registers |
|
562 | 556 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
563 | 557 | reset_sm_status(); |
|
564 | 558 | |
|
565 | 559 | // (3) clear interruptions |
|
566 | 560 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
567 | 561 | |
|
568 | 562 | // suspend several tasks |
|
569 | 563 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
570 | 564 | status = suspend_asm_tasks(); |
|
571 | 565 | } |
|
572 | 566 | |
|
573 | 567 | if (status != RTEMS_SUCCESSFUL) |
|
574 | 568 | { |
|
575 | 569 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
576 | 570 | } |
|
577 | 571 | |
|
578 | 572 | return status; |
|
579 | 573 | } |
|
580 | 574 | |
|
581 | 575 | int stop_current_mode( void ) |
|
582 | 576 | { |
|
583 | 577 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
584 | 578 | * |
|
585 | 579 | * @return RTEMS directive status codes: |
|
586 | 580 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
587 | 581 | * - RTEMS_INVALID_ID - task id invalid |
|
588 | 582 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
589 | 583 | * |
|
590 | 584 | */ |
|
591 | 585 | |
|
592 | 586 | rtems_status_code status; |
|
593 | 587 | |
|
594 | 588 | status = RTEMS_SUCCESSFUL; |
|
595 | 589 | |
|
596 | 590 | // (1) mask interruptions |
|
597 | 591 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
598 | 592 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
599 | 593 | |
|
600 | 594 | // (2) reset waveform picker registers |
|
601 | 595 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
602 | 596 | reset_wfp_status(); // reset all the status bits |
|
603 | 597 | |
|
604 | 598 | // (3) reset spectral matrices registers |
|
605 | 599 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
606 | 600 | reset_sm_status(); |
|
607 | 601 | |
|
608 | 602 | // reset lfr VHDL module |
|
609 | 603 | reset_lfr(); |
|
610 | 604 | |
|
611 | 605 | reset_extractSWF(); // reset the extractSWF flag to false |
|
612 | 606 | |
|
613 | 607 | // (4) clear interruptions |
|
614 | 608 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
615 | 609 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
616 | 610 | |
|
617 | 611 | // suspend several tasks |
|
618 | 612 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
619 | 613 | status = suspend_science_tasks(); |
|
620 | 614 | } |
|
621 | 615 | |
|
622 | 616 | if (status != RTEMS_SUCCESSFUL) |
|
623 | 617 | { |
|
624 | 618 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
625 | 619 | } |
|
626 | 620 | |
|
627 | 621 | return status; |
|
628 | 622 | } |
|
629 | 623 | |
|
630 | 624 | int enter_mode_standby( void ) |
|
631 | 625 | { |
|
632 | 626 | /** This function is used to put LFR in the STANDBY mode. |
|
633 | 627 | * |
|
634 | 628 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
635 | 629 | * |
|
636 | 630 | * @return RTEMS directive status codes: |
|
637 | 631 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
638 | 632 | * - RTEMS_INVALID_ID - task id invalid |
|
639 | 633 | * - RTEMS_INCORRECT_STATE - task never started |
|
640 | 634 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
641 | 635 | * |
|
642 | 636 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE |
|
643 | 637 | * is immediate. |
|
644 | 638 | * |
|
645 | 639 | */ |
|
646 | 640 | |
|
647 | 641 | int status; |
|
648 | 642 | |
|
649 | 643 | status = stop_current_mode(); // STOP THE CURRENT MODE |
|
650 | 644 | |
|
651 | 645 | #ifdef PRINT_TASK_STATISTICS |
|
652 | 646 | rtems_cpu_usage_report(); |
|
653 | 647 | #endif |
|
654 | 648 | |
|
655 | 649 | #ifdef PRINT_STACK_REPORT |
|
656 | 650 | PRINTF("stack report selected\n") |
|
657 | 651 | rtems_stack_checker_report_usage(); |
|
658 | 652 | #endif |
|
659 | 653 | |
|
660 | 654 | return status; |
|
661 | 655 | } |
|
662 | 656 | |
|
663 | 657 | int enter_mode_normal( unsigned int transitionCoarseTime ) |
|
664 | 658 | { |
|
665 | 659 | /** This function is used to start the NORMAL mode. |
|
666 | 660 | * |
|
667 | 661 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
668 | 662 | * |
|
669 | 663 | * @return RTEMS directive status codes: |
|
670 | 664 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
671 | 665 | * - RTEMS_INVALID_ID - task id invalid |
|
672 | 666 | * - RTEMS_INCORRECT_STATE - task never started |
|
673 | 667 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
674 | 668 | * |
|
675 | 669 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, |
|
676 | 670 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. |
|
677 | 671 | * |
|
678 | 672 | */ |
|
679 | 673 | |
|
680 | 674 | int status; |
|
681 | 675 | |
|
682 | 676 | #ifdef PRINT_TASK_STATISTICS |
|
683 | 677 | rtems_cpu_usage_reset(); |
|
684 | 678 | #endif |
|
685 | 679 | |
|
686 | 680 | status = RTEMS_UNSATISFIED; |
|
687 | 681 | |
|
688 | printf("hop\n"); | |
|
689 | ||
|
690 | 682 | switch( lfrCurrentMode ) |
|
691 | 683 | { |
|
692 | 684 | case LFR_MODE_STANDBY: |
|
693 | 685 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks |
|
694 | 686 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
695 | 687 | { |
|
696 | 688 | launch_spectral_matrix( ); |
|
697 | 689 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
698 | 690 | } |
|
699 | 691 | break; |
|
700 | 692 | case LFR_MODE_BURST: |
|
701 | 693 | status = stop_current_mode(); // stop the current mode |
|
702 | 694 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks |
|
703 | 695 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
704 | 696 | { |
|
705 | 697 | launch_spectral_matrix( ); |
|
706 | 698 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
707 | 699 | } |
|
708 | 700 | break; |
|
709 | 701 | case LFR_MODE_SBM1: |
|
710 | 702 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
711 | 703 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
712 | 704 | update_last_valid_transition_date( transitionCoarseTime ); |
|
713 | 705 | break; |
|
714 | 706 | case LFR_MODE_SBM2: |
|
715 | 707 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
716 | 708 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
717 | 709 | update_last_valid_transition_date( transitionCoarseTime ); |
|
718 | 710 | break; |
|
719 | 711 | default: |
|
720 | 712 | break; |
|
721 | 713 | } |
|
722 | 714 | |
|
723 | 715 | if (status != RTEMS_SUCCESSFUL) |
|
724 | 716 | { |
|
725 | 717 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) |
|
726 | 718 | status = RTEMS_UNSATISFIED; |
|
727 | 719 | } |
|
728 | 720 | |
|
729 | 721 | return status; |
|
730 | 722 | } |
|
731 | 723 | |
|
732 | 724 | int enter_mode_burst( unsigned int transitionCoarseTime ) |
|
733 | 725 | { |
|
734 | 726 | /** This function is used to start the BURST mode. |
|
735 | 727 | * |
|
736 | 728 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
737 | 729 | * |
|
738 | 730 | * @return RTEMS directive status codes: |
|
739 | 731 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
740 | 732 | * - RTEMS_INVALID_ID - task id invalid |
|
741 | 733 | * - RTEMS_INCORRECT_STATE - task never started |
|
742 | 734 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
743 | 735 | * |
|
744 | 736 | * The way the BURST mode is started does not depend on the LFR current mode. |
|
745 | 737 | * |
|
746 | 738 | */ |
|
747 | 739 | |
|
748 | 740 | |
|
749 | 741 | int status; |
|
750 | 742 | |
|
751 | 743 | #ifdef PRINT_TASK_STATISTICS |
|
752 | 744 | rtems_cpu_usage_reset(); |
|
753 | 745 | #endif |
|
754 | 746 | |
|
755 | 747 | status = stop_current_mode(); // stop the current mode |
|
756 | 748 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks |
|
757 | 749 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
758 | 750 | { |
|
759 | 751 | launch_spectral_matrix( ); |
|
760 | 752 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); |
|
761 | 753 | } |
|
762 | 754 | |
|
763 | 755 | if (status != RTEMS_SUCCESSFUL) |
|
764 | 756 | { |
|
765 | 757 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) |
|
766 | 758 | status = RTEMS_UNSATISFIED; |
|
767 | 759 | } |
|
768 | 760 | |
|
769 | 761 | return status; |
|
770 | 762 | } |
|
771 | 763 | |
|
772 | 764 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) |
|
773 | 765 | { |
|
774 | 766 | /** This function is used to start the SBM1 mode. |
|
775 | 767 | * |
|
776 | 768 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
777 | 769 | * |
|
778 | 770 | * @return RTEMS directive status codes: |
|
779 | 771 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
780 | 772 | * - RTEMS_INVALID_ID - task id invalid |
|
781 | 773 | * - RTEMS_INCORRECT_STATE - task never started |
|
782 | 774 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
783 | 775 | * |
|
784 | 776 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, |
|
785 | 777 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
786 | 778 | * cases, the acquisition is completely restarted. |
|
787 | 779 | * |
|
788 | 780 | */ |
|
789 | 781 | |
|
790 | 782 | int status; |
|
791 | 783 | |
|
792 | 784 | #ifdef PRINT_TASK_STATISTICS |
|
793 | 785 | rtems_cpu_usage_reset(); |
|
794 | 786 | #endif |
|
795 | 787 | |
|
796 | 788 | status = RTEMS_UNSATISFIED; |
|
797 | 789 | |
|
798 | 790 | switch( lfrCurrentMode ) |
|
799 | 791 | { |
|
800 | 792 | case LFR_MODE_STANDBY: |
|
801 | 793 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks |
|
802 | 794 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
803 | 795 | { |
|
804 | 796 | launch_spectral_matrix( ); |
|
805 | 797 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
806 | 798 | } |
|
807 | 799 | break; |
|
808 | 800 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action |
|
809 | 801 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
810 | 802 | status = LFR_SUCCESSFUL; |
|
811 | 803 | update_last_valid_transition_date( transitionCoarseTime ); |
|
812 | 804 | break; |
|
813 | 805 | case LFR_MODE_BURST: |
|
814 | 806 | status = stop_current_mode(); // stop the current mode |
|
815 | 807 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks |
|
816 | 808 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
817 | 809 | { |
|
818 | 810 | launch_spectral_matrix( ); |
|
819 | 811 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
820 | 812 | } |
|
821 | 813 | break; |
|
822 | 814 | case LFR_MODE_SBM2: |
|
823 | 815 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
824 | 816 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
825 | 817 | update_last_valid_transition_date( transitionCoarseTime ); |
|
826 | 818 | break; |
|
827 | 819 | default: |
|
828 | 820 | break; |
|
829 | 821 | } |
|
830 | 822 | |
|
831 | 823 | if (status != RTEMS_SUCCESSFUL) |
|
832 | 824 | { |
|
833 | 825 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status); |
|
834 | 826 | status = RTEMS_UNSATISFIED; |
|
835 | 827 | } |
|
836 | 828 | |
|
837 | 829 | return status; |
|
838 | 830 | } |
|
839 | 831 | |
|
840 | 832 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) |
|
841 | 833 | { |
|
842 | 834 | /** This function is used to start the SBM2 mode. |
|
843 | 835 | * |
|
844 | 836 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
845 | 837 | * |
|
846 | 838 | * @return RTEMS directive status codes: |
|
847 | 839 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
848 | 840 | * - RTEMS_INVALID_ID - task id invalid |
|
849 | 841 | * - RTEMS_INCORRECT_STATE - task never started |
|
850 | 842 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
851 | 843 | * |
|
852 | 844 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, |
|
853 | 845 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
854 | 846 | * cases, the acquisition is completely restarted. |
|
855 | 847 | * |
|
856 | 848 | */ |
|
857 | 849 | |
|
858 | 850 | int status; |
|
859 | 851 | |
|
860 | 852 | #ifdef PRINT_TASK_STATISTICS |
|
861 | 853 | rtems_cpu_usage_reset(); |
|
862 | 854 | #endif |
|
863 | 855 | |
|
864 | 856 | status = RTEMS_UNSATISFIED; |
|
865 | 857 | |
|
866 | 858 | switch( lfrCurrentMode ) |
|
867 | 859 | { |
|
868 | 860 | case LFR_MODE_STANDBY: |
|
869 | 861 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks |
|
870 | 862 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
871 | 863 | { |
|
872 | 864 | launch_spectral_matrix( ); |
|
873 | 865 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
874 | 866 | } |
|
875 | 867 | break; |
|
876 | 868 | case LFR_MODE_NORMAL: |
|
877 | 869 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
878 | 870 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
879 | 871 | update_last_valid_transition_date( transitionCoarseTime ); |
|
880 | 872 | break; |
|
881 | 873 | case LFR_MODE_BURST: |
|
882 | 874 | status = stop_current_mode(); // stop the current mode |
|
883 | 875 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks |
|
884 | 876 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
885 | 877 | { |
|
886 | 878 | launch_spectral_matrix( ); |
|
887 | 879 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
888 | 880 | } |
|
889 | 881 | break; |
|
890 | 882 | case LFR_MODE_SBM1: |
|
891 | 883 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
892 | 884 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
893 | 885 | update_last_valid_transition_date( transitionCoarseTime ); |
|
894 | 886 | break; |
|
895 | 887 | default: |
|
896 | 888 | break; |
|
897 | 889 | } |
|
898 | 890 | |
|
899 | 891 | if (status != RTEMS_SUCCESSFUL) |
|
900 | 892 | { |
|
901 | 893 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) |
|
902 | 894 | status = RTEMS_UNSATISFIED; |
|
903 | 895 | } |
|
904 | 896 | |
|
905 | 897 | return status; |
|
906 | 898 | } |
|
907 | 899 | |
|
908 | 900 | int restart_science_tasks( unsigned char lfrRequestedMode ) |
|
909 | 901 | { |
|
910 | 902 | /** This function is used to restart all science tasks. |
|
911 | 903 | * |
|
912 | 904 | * @return RTEMS directive status codes: |
|
913 | 905 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
914 | 906 | * - RTEMS_INVALID_ID - task id invalid |
|
915 | 907 | * - RTEMS_INCORRECT_STATE - task never started |
|
916 | 908 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
917 | 909 | * |
|
918 | 910 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
919 | 911 | * |
|
920 | 912 | */ |
|
921 | 913 | |
|
922 | 914 | rtems_status_code status[NB_SCIENCE_TASKS]; |
|
923 | 915 | rtems_status_code ret; |
|
924 | 916 | |
|
925 | 917 | ret = RTEMS_SUCCESSFUL; |
|
926 | 918 | |
|
927 | 919 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
928 | 920 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) |
|
929 | 921 | { |
|
930 | 922 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) |
|
931 | 923 | } |
|
932 | 924 | |
|
933 | 925 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
934 | 926 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) |
|
935 | 927 | { |
|
936 | 928 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) |
|
937 | 929 | } |
|
938 | 930 | |
|
939 | 931 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
940 | 932 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) |
|
941 | 933 | { |
|
942 | 934 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2]) |
|
943 | 935 | } |
|
944 | 936 | |
|
945 | 937 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
946 | 938 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) |
|
947 | 939 | { |
|
948 | 940 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3]) |
|
949 | 941 | } |
|
950 | 942 | |
|
951 | 943 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
952 | 944 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) |
|
953 | 945 | { |
|
954 | 946 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4]) |
|
955 | 947 | } |
|
956 | 948 | |
|
957 | 949 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
958 | 950 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) |
|
959 | 951 | { |
|
960 | 952 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5]) |
|
961 | 953 | } |
|
962 | 954 | |
|
963 | 955 | status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
964 | 956 | if (status[STATUS_6] != RTEMS_SUCCESSFUL) |
|
965 | 957 | { |
|
966 | 958 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6]) |
|
967 | 959 | } |
|
968 | 960 | |
|
969 | 961 | status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
970 | 962 | if (status[STATUS_7] != RTEMS_SUCCESSFUL) |
|
971 | 963 | { |
|
972 | 964 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7]) |
|
973 | 965 | } |
|
974 | 966 | |
|
975 | 967 | status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
976 | 968 | if (status[STATUS_8] != RTEMS_SUCCESSFUL) |
|
977 | 969 | { |
|
978 | 970 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8]) |
|
979 | 971 | } |
|
980 | 972 | |
|
981 | 973 | status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
982 | 974 | if (status[STATUS_9] != RTEMS_SUCCESSFUL) |
|
983 | 975 | { |
|
984 | 976 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9]) |
|
985 | 977 | } |
|
986 | 978 | |
|
987 | 979 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || |
|
988 | 980 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || |
|
989 | 981 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) || |
|
990 | 982 | (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) || |
|
991 | 983 | (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) ) |
|
992 | 984 | { |
|
993 | 985 | ret = RTEMS_UNSATISFIED; |
|
994 | 986 | } |
|
995 | 987 | |
|
996 | 988 | return ret; |
|
997 | 989 | } |
|
998 | 990 | |
|
999 | 991 | int restart_asm_tasks( unsigned char lfrRequestedMode ) |
|
1000 | 992 | { |
|
1001 | 993 | /** This function is used to restart average spectral matrices tasks. |
|
1002 | 994 | * |
|
1003 | 995 | * @return RTEMS directive status codes: |
|
1004 | 996 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1005 | 997 | * - RTEMS_INVALID_ID - task id invalid |
|
1006 | 998 | * - RTEMS_INCORRECT_STATE - task never started |
|
1007 | 999 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
1008 | 1000 | * |
|
1009 | 1001 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 |
|
1010 | 1002 | * |
|
1011 | 1003 | */ |
|
1012 | 1004 | |
|
1013 | 1005 | rtems_status_code status[NB_ASM_TASKS]; |
|
1014 | 1006 | rtems_status_code ret; |
|
1015 | 1007 | |
|
1016 | 1008 | ret = RTEMS_SUCCESSFUL; |
|
1017 | 1009 | |
|
1018 | 1010 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
1019 | 1011 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) |
|
1020 | 1012 | { |
|
1021 | 1013 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) |
|
1022 | 1014 | } |
|
1023 | 1015 | |
|
1024 | 1016 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
1025 | 1017 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) |
|
1026 | 1018 | { |
|
1027 | 1019 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) |
|
1028 | 1020 | } |
|
1029 | 1021 | |
|
1030 | 1022 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
1031 | 1023 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) |
|
1032 | 1024 | { |
|
1033 | 1025 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2]) |
|
1034 | 1026 | } |
|
1035 | 1027 | |
|
1036 | 1028 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
1037 | 1029 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) |
|
1038 | 1030 | { |
|
1039 | 1031 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3]) |
|
1040 | 1032 | } |
|
1041 | 1033 | |
|
1042 | 1034 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
1043 | 1035 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) |
|
1044 | 1036 | { |
|
1045 | 1037 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4]) |
|
1046 | 1038 | } |
|
1047 | 1039 | |
|
1048 | 1040 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
1049 | 1041 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) |
|
1050 | 1042 | { |
|
1051 | 1043 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5]) |
|
1052 | 1044 | } |
|
1053 | 1045 | |
|
1054 | 1046 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || |
|
1055 | 1047 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || |
|
1056 | 1048 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ) |
|
1057 | 1049 | { |
|
1058 | 1050 | ret = RTEMS_UNSATISFIED; |
|
1059 | 1051 | } |
|
1060 | 1052 | |
|
1061 | 1053 | return ret; |
|
1062 | 1054 | } |
|
1063 | 1055 | |
|
1064 | 1056 | int suspend_science_tasks( void ) |
|
1065 | 1057 | { |
|
1066 | 1058 | /** This function suspends the science tasks. |
|
1067 | 1059 | * |
|
1068 | 1060 | * @return RTEMS directive status codes: |
|
1069 | 1061 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1070 | 1062 | * - RTEMS_INVALID_ID - task id invalid |
|
1071 | 1063 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1072 | 1064 | * |
|
1073 | 1065 | */ |
|
1074 | 1066 | |
|
1075 | 1067 | rtems_status_code status; |
|
1076 | 1068 | |
|
1077 | 1069 | PRINTF("in suspend_science_tasks\n") |
|
1078 | 1070 | |
|
1079 | 1071 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1080 | 1072 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1081 | 1073 | { |
|
1082 | 1074 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1083 | 1075 | } |
|
1084 | 1076 | else |
|
1085 | 1077 | { |
|
1086 | 1078 | status = RTEMS_SUCCESSFUL; |
|
1087 | 1079 | } |
|
1088 | 1080 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1089 | 1081 | { |
|
1090 | 1082 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1091 | 1083 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1092 | 1084 | { |
|
1093 | 1085 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1094 | 1086 | } |
|
1095 | 1087 | else |
|
1096 | 1088 | { |
|
1097 | 1089 | status = RTEMS_SUCCESSFUL; |
|
1098 | 1090 | } |
|
1099 | 1091 | } |
|
1100 | 1092 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1101 | 1093 | { |
|
1102 | 1094 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1103 | 1095 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1104 | 1096 | { |
|
1105 | 1097 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1106 | 1098 | } |
|
1107 | 1099 | else |
|
1108 | 1100 | { |
|
1109 | 1101 | status = RTEMS_SUCCESSFUL; |
|
1110 | 1102 | } |
|
1111 | 1103 | } |
|
1112 | 1104 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1113 | 1105 | { |
|
1114 | 1106 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1115 | 1107 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1116 | 1108 | { |
|
1117 | 1109 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1118 | 1110 | } |
|
1119 | 1111 | else |
|
1120 | 1112 | { |
|
1121 | 1113 | status = RTEMS_SUCCESSFUL; |
|
1122 | 1114 | } |
|
1123 | 1115 | } |
|
1124 | 1116 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1125 | 1117 | { |
|
1126 | 1118 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1127 | 1119 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1128 | 1120 | { |
|
1129 | 1121 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1130 | 1122 | } |
|
1131 | 1123 | else |
|
1132 | 1124 | { |
|
1133 | 1125 | status = RTEMS_SUCCESSFUL; |
|
1134 | 1126 | } |
|
1135 | 1127 | } |
|
1136 | 1128 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1137 | 1129 | { |
|
1138 | 1130 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1139 | 1131 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1140 | 1132 | { |
|
1141 | 1133 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1142 | 1134 | } |
|
1143 | 1135 | else |
|
1144 | 1136 | { |
|
1145 | 1137 | status = RTEMS_SUCCESSFUL; |
|
1146 | 1138 | } |
|
1147 | 1139 | } |
|
1148 | 1140 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
1149 | 1141 | { |
|
1150 | 1142 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
1151 | 1143 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1152 | 1144 | { |
|
1153 | 1145 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
1154 | 1146 | } |
|
1155 | 1147 | else |
|
1156 | 1148 | { |
|
1157 | 1149 | status = RTEMS_SUCCESSFUL; |
|
1158 | 1150 | } |
|
1159 | 1151 | } |
|
1160 | 1152 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
1161 | 1153 | { |
|
1162 | 1154 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
1163 | 1155 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1164 | 1156 | { |
|
1165 | 1157 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
1166 | 1158 | } |
|
1167 | 1159 | else |
|
1168 | 1160 | { |
|
1169 | 1161 | status = RTEMS_SUCCESSFUL; |
|
1170 | 1162 | } |
|
1171 | 1163 | } |
|
1172 | 1164 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
1173 | 1165 | { |
|
1174 | 1166 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
1175 | 1167 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1176 | 1168 | { |
|
1177 | 1169 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
1178 | 1170 | } |
|
1179 | 1171 | else |
|
1180 | 1172 | { |
|
1181 | 1173 | status = RTEMS_SUCCESSFUL; |
|
1182 | 1174 | } |
|
1183 | 1175 | } |
|
1184 | 1176 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
1185 | 1177 | { |
|
1186 | 1178 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
1187 | 1179 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1188 | 1180 | { |
|
1189 | 1181 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
1190 | 1182 | } |
|
1191 | 1183 | else |
|
1192 | 1184 | { |
|
1193 | 1185 | status = RTEMS_SUCCESSFUL; |
|
1194 | 1186 | } |
|
1195 | 1187 | } |
|
1196 | 1188 | |
|
1197 | 1189 | return status; |
|
1198 | 1190 | } |
|
1199 | 1191 | |
|
1200 | 1192 | int suspend_asm_tasks( void ) |
|
1201 | 1193 | { |
|
1202 | 1194 | /** This function suspends the science tasks. |
|
1203 | 1195 | * |
|
1204 | 1196 | * @return RTEMS directive status codes: |
|
1205 | 1197 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1206 | 1198 | * - RTEMS_INVALID_ID - task id invalid |
|
1207 | 1199 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1208 | 1200 | * |
|
1209 | 1201 | */ |
|
1210 | 1202 | |
|
1211 | 1203 | rtems_status_code status; |
|
1212 | 1204 | |
|
1213 | 1205 | PRINTF("in suspend_science_tasks\n") |
|
1214 | 1206 | |
|
1215 | 1207 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1216 | 1208 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1217 | 1209 | { |
|
1218 | 1210 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1219 | 1211 | } |
|
1220 | 1212 | else |
|
1221 | 1213 | { |
|
1222 | 1214 | status = RTEMS_SUCCESSFUL; |
|
1223 | 1215 | } |
|
1224 | 1216 | |
|
1225 | 1217 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1226 | 1218 | { |
|
1227 | 1219 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1228 | 1220 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1229 | 1221 | { |
|
1230 | 1222 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1231 | 1223 | } |
|
1232 | 1224 | else |
|
1233 | 1225 | { |
|
1234 | 1226 | status = RTEMS_SUCCESSFUL; |
|
1235 | 1227 | } |
|
1236 | 1228 | } |
|
1237 | 1229 | |
|
1238 | 1230 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1239 | 1231 | { |
|
1240 | 1232 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1241 | 1233 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1242 | 1234 | { |
|
1243 | 1235 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1244 | 1236 | } |
|
1245 | 1237 | else |
|
1246 | 1238 | { |
|
1247 | 1239 | status = RTEMS_SUCCESSFUL; |
|
1248 | 1240 | } |
|
1249 | 1241 | } |
|
1250 | 1242 | |
|
1251 | 1243 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1252 | 1244 | { |
|
1253 | 1245 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1254 | 1246 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1255 | 1247 | { |
|
1256 | 1248 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1257 | 1249 | } |
|
1258 | 1250 | else |
|
1259 | 1251 | { |
|
1260 | 1252 | status = RTEMS_SUCCESSFUL; |
|
1261 | 1253 | } |
|
1262 | 1254 | } |
|
1263 | 1255 | |
|
1264 | 1256 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1265 | 1257 | { |
|
1266 | 1258 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1267 | 1259 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1268 | 1260 | { |
|
1269 | 1261 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1270 | 1262 | } |
|
1271 | 1263 | else |
|
1272 | 1264 | { |
|
1273 | 1265 | status = RTEMS_SUCCESSFUL; |
|
1274 | 1266 | } |
|
1275 | 1267 | } |
|
1276 | 1268 | |
|
1277 | 1269 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1278 | 1270 | { |
|
1279 | 1271 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1280 | 1272 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1281 | 1273 | { |
|
1282 | 1274 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1283 | 1275 | } |
|
1284 | 1276 | else |
|
1285 | 1277 | { |
|
1286 | 1278 | status = RTEMS_SUCCESSFUL; |
|
1287 | 1279 | } |
|
1288 | 1280 | } |
|
1289 | 1281 | |
|
1290 | 1282 | return status; |
|
1291 | 1283 | } |
|
1292 | 1284 | |
|
1293 | 1285 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
1294 | 1286 | { |
|
1295 | 1287 | |
|
1296 | 1288 | WFP_reset_current_ring_nodes(); |
|
1297 | 1289 | |
|
1298 | 1290 | reset_waveform_picker_regs(); |
|
1299 | 1291 | |
|
1300 | 1292 | set_wfp_burst_enable_register( mode ); |
|
1301 | 1293 | |
|
1302 | 1294 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1303 | 1295 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1304 | 1296 | |
|
1305 | 1297 | if (transitionCoarseTime == 0) |
|
1306 | 1298 | { |
|
1307 | 1299 | // instant transition means transition on the next valid date |
|
1308 | 1300 | // this is mandatory to have a good snapshot period and a good correction of the snapshot period |
|
1309 | 1301 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; |
|
1310 | 1302 | } |
|
1311 | 1303 | else |
|
1312 | 1304 | { |
|
1313 | 1305 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
1314 | 1306 | } |
|
1315 | 1307 | |
|
1316 | 1308 | update_last_valid_transition_date(waveform_picker_regs->start_date); |
|
1317 | 1309 | |
|
1318 | 1310 | } |
|
1319 | 1311 | |
|
1320 | 1312 | void launch_spectral_matrix( void ) |
|
1321 | 1313 | { |
|
1322 | 1314 | SM_reset_current_ring_nodes(); |
|
1323 | 1315 | |
|
1324 | 1316 | reset_spectral_matrix_regs(); |
|
1325 | 1317 | |
|
1326 | 1318 | reset_nb_sm(); |
|
1327 | 1319 | |
|
1328 | 1320 | set_sm_irq_onNewMatrix( 1 ); |
|
1329 | 1321 | |
|
1330 | 1322 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1331 | 1323 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1332 | 1324 | |
|
1333 | 1325 | } |
|
1334 | 1326 | |
|
1335 | 1327 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
1336 | 1328 | { |
|
1337 | 1329 | if (value == 1) |
|
1338 | 1330 | { |
|
1339 | 1331 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX; |
|
1340 | 1332 | } |
|
1341 | 1333 | else |
|
1342 | 1334 | { |
|
1343 | 1335 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110 |
|
1344 | 1336 | } |
|
1345 | 1337 | } |
|
1346 | 1338 | |
|
1347 | 1339 | void set_sm_irq_onError( unsigned char value ) |
|
1348 | 1340 | { |
|
1349 | 1341 | if (value == 1) |
|
1350 | 1342 | { |
|
1351 | 1343 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR; |
|
1352 | 1344 | } |
|
1353 | 1345 | else |
|
1354 | 1346 | { |
|
1355 | 1347 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101 |
|
1356 | 1348 | } |
|
1357 | 1349 | } |
|
1358 | 1350 | |
|
1359 | 1351 | //***************************** |
|
1360 | 1352 | // CONFIGURE CALIBRATION SIGNAL |
|
1361 | 1353 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
1362 | 1354 | { |
|
1363 | 1355 | // prescaling of the master clock (25 MHz) |
|
1364 | 1356 | // master clock is divided by 2^prescaler |
|
1365 | 1357 | time_management_regs->calPrescaler = prescaler; |
|
1366 | 1358 | } |
|
1367 | 1359 | |
|
1368 | 1360 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
1369 | 1361 | { |
|
1370 | 1362 | // division of the prescaled clock by the division factor |
|
1371 | 1363 | time_management_regs->calDivisor = divisionFactor; |
|
1372 | 1364 | } |
|
1373 | 1365 | |
|
1374 | 1366 | void setCalibrationData( void ) |
|
1375 | 1367 | { |
|
1376 | 1368 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal |
|
1377 | 1369 | * |
|
1378 | 1370 | * @param void |
|
1379 | 1371 | * |
|
1380 | 1372 | * @return void |
|
1381 | 1373 | * |
|
1382 | 1374 | */ |
|
1383 | 1375 | |
|
1384 | 1376 | unsigned int k; |
|
1385 | 1377 | unsigned short data; |
|
1386 | 1378 | float val; |
|
1387 | 1379 | float Ts; |
|
1388 | 1380 | |
|
1389 | 1381 | time_management_regs->calDataPtr = INIT_CHAR; |
|
1390 | 1382 | |
|
1391 | 1383 | Ts = 1 / CAL_FS; |
|
1392 | 1384 | |
|
1393 | 1385 | // build the signal for the SCM calibration |
|
1394 | 1386 | for (k = 0; k < CAL_NB_PTS; k++) |
|
1395 | 1387 | { |
|
1396 | 1388 | val = CAL_A0 * sin( CAL_W0 * k * Ts ) |
|
1397 | 1389 | + CAL_A1 * sin( CAL_W1 * k * Ts ); |
|
1398 | 1390 | data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048); |
|
1399 | 1391 | time_management_regs->calData = data & CAL_DATA_MASK; |
|
1400 | 1392 | } |
|
1401 | 1393 | } |
|
1402 | 1394 | |
|
1403 | 1395 | void setCalibrationDataInterleaved( void ) |
|
1404 | 1396 | { |
|
1405 | 1397 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal |
|
1406 | 1398 | * |
|
1407 | 1399 | * @param void |
|
1408 | 1400 | * |
|
1409 | 1401 | * @return void |
|
1410 | 1402 | * |
|
1411 | 1403 | * In interleaved mode, one can store more values than in normal mode. |
|
1412 | 1404 | * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample. |
|
1413 | 1405 | * T store 3 values, one need two write operations. |
|
1414 | 1406 | * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] |
|
1415 | 1407 | * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] |
|
1416 | 1408 | * |
|
1417 | 1409 | */ |
|
1418 | 1410 | |
|
1419 | 1411 | unsigned int k; |
|
1420 | 1412 | float val; |
|
1421 | 1413 | float Ts; |
|
1422 | 1414 | unsigned short data[CAL_NB_PTS_INTER]; |
|
1423 | 1415 | unsigned char *dataPtr; |
|
1424 | 1416 | |
|
1425 | 1417 | Ts = 1 / CAL_FS_INTER; |
|
1426 | 1418 | |
|
1427 | 1419 | time_management_regs->calDataPtr = INIT_CHAR; |
|
1428 | 1420 | |
|
1429 | 1421 | // build the signal for the SCM calibration |
|
1430 | 1422 | for (k=0; k<CAL_NB_PTS_INTER; k++) |
|
1431 | 1423 | { |
|
1432 | 1424 | val = sin( 2 * pi * CAL_F0 * k * Ts ) |
|
1433 | 1425 | + sin( 2 * pi * CAL_F1 * k * Ts ); |
|
1434 | 1426 | data[k] = (unsigned short) ((val * CONST_512) + CONST_2048); |
|
1435 | 1427 | } |
|
1436 | 1428 | |
|
1437 | 1429 | // write the signal in interleaved mode |
|
1438 | 1430 | for (k=0; k < STEPS_FOR_STORAGE_INTER; k++) |
|
1439 | 1431 | { |
|
1440 | 1432 | dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ]; |
|
1441 | 1433 | time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK ) |
|
1442 | 1434 | + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); |
|
1443 | 1435 | time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK ) |
|
1444 | 1436 | + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); |
|
1445 | 1437 | } |
|
1446 | 1438 | } |
|
1447 | 1439 | |
|
1448 | 1440 | void setCalibrationReload( bool state) |
|
1449 | 1441 | { |
|
1450 | 1442 | if (state == true) |
|
1451 | 1443 | { |
|
1452 | 1444 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000] |
|
1453 | 1445 | } |
|
1454 | 1446 | else |
|
1455 | 1447 | { |
|
1456 | 1448 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111] |
|
1457 | 1449 | } |
|
1458 | 1450 | } |
|
1459 | 1451 | |
|
1460 | 1452 | void setCalibrationEnable( bool state ) |
|
1461 | 1453 | { |
|
1462 | 1454 | // this bit drives the multiplexer |
|
1463 | 1455 | if (state == true) |
|
1464 | 1456 | { |
|
1465 | 1457 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000] |
|
1466 | 1458 | } |
|
1467 | 1459 | else |
|
1468 | 1460 | { |
|
1469 | 1461 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111] |
|
1470 | 1462 | } |
|
1471 | 1463 | } |
|
1472 | 1464 | |
|
1473 | 1465 | void setCalibrationInterleaved( bool state ) |
|
1474 | 1466 | { |
|
1475 | 1467 | // this bit drives the multiplexer |
|
1476 | 1468 | if (state == true) |
|
1477 | 1469 | { |
|
1478 | 1470 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000] |
|
1479 | 1471 | } |
|
1480 | 1472 | else |
|
1481 | 1473 | { |
|
1482 | 1474 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111] |
|
1483 | 1475 | } |
|
1484 | 1476 | } |
|
1485 | 1477 | |
|
1486 | 1478 | void setCalibration( bool state ) |
|
1487 | 1479 | { |
|
1488 | 1480 | if (state == true) |
|
1489 | 1481 | { |
|
1490 | 1482 | setCalibrationEnable( true ); |
|
1491 | 1483 | setCalibrationReload( false ); |
|
1492 | 1484 | set_hk_lfr_calib_enable( true ); |
|
1493 | 1485 | } |
|
1494 | 1486 | else |
|
1495 | 1487 | { |
|
1496 | 1488 | setCalibrationEnable( false ); |
|
1497 | 1489 | setCalibrationReload( true ); |
|
1498 | 1490 | set_hk_lfr_calib_enable( false ); |
|
1499 | 1491 | } |
|
1500 | 1492 | } |
|
1501 | 1493 | |
|
1502 | 1494 | void configureCalibration( bool interleaved ) |
|
1503 | 1495 | { |
|
1504 | 1496 | setCalibration( false ); |
|
1505 | 1497 | if ( interleaved == true ) |
|
1506 | 1498 | { |
|
1507 | 1499 | setCalibrationInterleaved( true ); |
|
1508 | 1500 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1509 | 1501 | setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384 |
|
1510 | 1502 | setCalibrationDataInterleaved(); |
|
1511 | 1503 | } |
|
1512 | 1504 | else |
|
1513 | 1505 | { |
|
1514 | 1506 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1515 | 1507 | setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1) |
|
1516 | 1508 | setCalibrationData(); |
|
1517 | 1509 | } |
|
1518 | 1510 | } |
|
1519 | 1511 | |
|
1520 | 1512 | //**************** |
|
1521 | 1513 | // CLOSING ACTIONS |
|
1522 | 1514 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1523 | 1515 | { |
|
1524 | 1516 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1525 | 1517 | * |
|
1526 | 1518 | * @param TC points to the TC being processed |
|
1527 | 1519 | * @param time is the time used to date the TC execution |
|
1528 | 1520 | * |
|
1529 | 1521 | */ |
|
1530 | 1522 | |
|
1531 | 1523 | unsigned int val; |
|
1532 | 1524 | |
|
1533 | 1525 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1534 | 1526 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1535 | 1527 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR; |
|
1536 | 1528 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1537 | 1529 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR; |
|
1538 | 1530 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1539 | 1531 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0]; |
|
1540 | 1532 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1]; |
|
1541 | 1533 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2]; |
|
1542 | 1534 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3]; |
|
1543 | 1535 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4]; |
|
1544 | 1536 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5]; |
|
1545 | 1537 | |
|
1546 | 1538 | val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1547 | 1539 | val++; |
|
1548 | 1540 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
1549 | 1541 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1550 | 1542 | } |
|
1551 | 1543 | |
|
1552 | 1544 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1553 | 1545 | { |
|
1554 | 1546 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1555 | 1547 | * |
|
1556 | 1548 | * @param TC points to the TC being processed |
|
1557 | 1549 | * @param time is the time used to date the TC rejection |
|
1558 | 1550 | * |
|
1559 | 1551 | */ |
|
1560 | 1552 | |
|
1561 | 1553 | unsigned int val; |
|
1562 | 1554 | |
|
1563 | 1555 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1564 | 1556 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1565 | 1557 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR; |
|
1566 | 1558 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1567 | 1559 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR; |
|
1568 | 1560 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1569 | 1561 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0]; |
|
1570 | 1562 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1]; |
|
1571 | 1563 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2]; |
|
1572 | 1564 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3]; |
|
1573 | 1565 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4]; |
|
1574 | 1566 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5]; |
|
1575 | 1567 | |
|
1576 | 1568 | val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1577 | 1569 | val++; |
|
1578 | 1570 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
1579 | 1571 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1580 | 1572 | } |
|
1581 | 1573 | |
|
1582 | 1574 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1583 | 1575 | { |
|
1584 | 1576 | /** This function is the last step of the TC execution workflow. |
|
1585 | 1577 | * |
|
1586 | 1578 | * @param TC points to the TC being processed |
|
1587 | 1579 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1588 | 1580 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1589 | 1581 | * @param time is the time used to date the TC execution |
|
1590 | 1582 | * |
|
1591 | 1583 | */ |
|
1592 | 1584 | |
|
1593 | 1585 | unsigned char requestedMode; |
|
1594 | 1586 | |
|
1595 | 1587 | if (result == LFR_SUCCESSFUL) |
|
1596 | 1588 | { |
|
1597 | 1589 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1598 | 1590 | & |
|
1599 | 1591 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1600 | 1592 | ) |
|
1601 | 1593 | { |
|
1602 | 1594 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1603 | 1595 | } |
|
1604 | 1596 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1605 | 1597 | { |
|
1606 | 1598 | //********************************** |
|
1607 | 1599 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1608 | 1600 | requestedMode = TC->dataAndCRC[1]; |
|
1609 | 1601 | updateLFRCurrentMode( requestedMode ); |
|
1610 | 1602 | } |
|
1611 | 1603 | } |
|
1612 | 1604 | else if (result == LFR_EXE_ERROR) |
|
1613 | 1605 | { |
|
1614 | 1606 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1615 | 1607 | } |
|
1616 | 1608 | } |
|
1617 | 1609 | |
|
1618 | 1610 | //*************************** |
|
1619 | 1611 | // Interrupt Service Routines |
|
1620 | 1612 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1621 | 1613 | { |
|
1622 | 1614 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1623 | 1615 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") |
|
1624 | 1616 | } |
|
1625 | 1617 | } |
|
1626 | 1618 | |
|
1627 | 1619 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1628 | 1620 | { |
|
1629 | 1621 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1630 | 1622 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") |
|
1631 | 1623 | } |
|
1632 | 1624 | } |
|
1633 | 1625 | |
|
1634 | 1626 | //**************** |
|
1635 | 1627 | // OTHER FUNCTIONS |
|
1636 | 1628 | void updateLFRCurrentMode( unsigned char requestedMode ) |
|
1637 | 1629 | { |
|
1638 | 1630 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1639 | 1631 | * |
|
1640 | 1632 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1641 | 1633 | * |
|
1642 | 1634 | */ |
|
1643 | 1635 | |
|
1644 | 1636 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1645 | 1637 | housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK) |
|
1646 | 1638 | + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT ); |
|
1647 | 1639 | lfrCurrentMode = requestedMode; |
|
1648 | 1640 | } |
|
1649 | 1641 | |
|
1650 | 1642 | void set_lfr_soft_reset( unsigned char value ) |
|
1651 | 1643 | { |
|
1652 | 1644 | if (value == 1) |
|
1653 | 1645 | { |
|
1654 | 1646 | time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100] |
|
1655 | 1647 | } |
|
1656 | 1648 | else |
|
1657 | 1649 | { |
|
1658 | 1650 | time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011] |
|
1659 | 1651 | } |
|
1660 | 1652 | } |
|
1661 | 1653 | |
|
1662 | 1654 | void reset_lfr( void ) |
|
1663 | 1655 | { |
|
1664 | 1656 | set_lfr_soft_reset( 1 ); |
|
1665 | 1657 | |
|
1666 | 1658 | set_lfr_soft_reset( 0 ); |
|
1667 | 1659 | |
|
1668 | 1660 | set_hk_lfr_sc_potential_flag( true ); |
|
1669 | 1661 | } |
@@ -1,1788 +1,1794 | |||
|
1 | 1 | /** Functions to load and dump parameters in the LFR registers. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle TC related to parameter loading and dumping.\n |
|
7 | 7 | * TC_LFR_LOAD_COMMON_PAR\n |
|
8 | 8 | * TC_LFR_LOAD_NORMAL_PAR\n |
|
9 | 9 | * TC_LFR_LOAD_BURST_PAR\n |
|
10 | 10 | * TC_LFR_LOAD_SBM1_PAR\n |
|
11 | 11 | * TC_LFR_LOAD_SBM2_PAR\n |
|
12 | 12 | * |
|
13 | 13 | */ |
|
14 | 14 | |
|
15 | 15 | #include "tc_load_dump_parameters.h" |
|
16 | 16 | |
|
17 | 17 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0}; |
|
18 | 18 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0}; |
|
19 | 19 | ring_node kcoefficient_node_1 = {0}; |
|
20 | 20 | ring_node kcoefficient_node_2 = {0}; |
|
21 | 21 | |
|
22 | 22 | int action_load_common_par(ccsdsTelecommandPacket_t *TC) |
|
23 | 23 | { |
|
24 | 24 | /** This function updates the LFR registers with the incoming common parameters. |
|
25 | 25 | * |
|
26 | 26 | * @param TC points to the TeleCommand packet that is being processed |
|
27 | 27 | * |
|
28 | 28 | * |
|
29 | 29 | */ |
|
30 | 30 | |
|
31 | 31 | parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0]; |
|
32 | 32 | parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1]; |
|
33 | 33 | set_wfp_data_shaping( ); |
|
34 | 34 | return LFR_SUCCESSFUL; |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
38 | 38 | { |
|
39 | 39 | /** This function updates the LFR registers with the incoming normal parameters. |
|
40 | 40 | * |
|
41 | 41 | * @param TC points to the TeleCommand packet that is being processed |
|
42 | 42 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
43 | 43 | * |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | int result; |
|
47 | 47 | int flag; |
|
48 | 48 | rtems_status_code status; |
|
49 | 49 | |
|
50 | 50 | flag = LFR_SUCCESSFUL; |
|
51 | 51 | |
|
52 | 52 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || |
|
53 | 53 | (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) { |
|
54 | 54 | status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
55 | 55 | flag = LFR_DEFAULT; |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | // CHECK THE PARAMETERS SET CONSISTENCY |
|
59 | 59 | if (flag == LFR_SUCCESSFUL) |
|
60 | 60 | { |
|
61 | 61 | flag = check_normal_par_consistency( TC, queue_id ); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | // SET THE PARAMETERS IF THEY ARE CONSISTENT |
|
65 | 65 | if (flag == LFR_SUCCESSFUL) |
|
66 | 66 | { |
|
67 | 67 | result = set_sy_lfr_n_swf_l( TC ); |
|
68 | 68 | result = set_sy_lfr_n_swf_p( TC ); |
|
69 | 69 | result = set_sy_lfr_n_bp_p0( TC ); |
|
70 | 70 | result = set_sy_lfr_n_bp_p1( TC ); |
|
71 | 71 | result = set_sy_lfr_n_asm_p( TC ); |
|
72 | 72 | result = set_sy_lfr_n_cwf_long_f3( TC ); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | return flag; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
79 | 79 | { |
|
80 | 80 | /** This function updates the LFR registers with the incoming burst parameters. |
|
81 | 81 | * |
|
82 | 82 | * @param TC points to the TeleCommand packet that is being processed |
|
83 | 83 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
84 | 84 | * |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | int flag; |
|
88 | 88 | rtems_status_code status; |
|
89 | 89 | unsigned char sy_lfr_b_bp_p0; |
|
90 | 90 | unsigned char sy_lfr_b_bp_p1; |
|
91 | 91 | float aux; |
|
92 | 92 | |
|
93 | 93 | flag = LFR_SUCCESSFUL; |
|
94 | 94 | |
|
95 | 95 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
96 | 96 | status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
97 | 97 | flag = LFR_DEFAULT; |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; |
|
101 | 101 | sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; |
|
102 | 102 | |
|
103 | 103 | // sy_lfr_b_bp_p0 shall not be lower than its default value |
|
104 | 104 | if (flag == LFR_SUCCESSFUL) |
|
105 | 105 | { |
|
106 | 106 | if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 ) |
|
107 | 107 | { |
|
108 | 108 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 ); |
|
109 | 109 | flag = WRONG_APP_DATA; |
|
110 | 110 | } |
|
111 | 111 | } |
|
112 | 112 | // sy_lfr_b_bp_p1 shall not be lower than its default value |
|
113 | 113 | if (flag == LFR_SUCCESSFUL) |
|
114 | 114 | { |
|
115 | 115 | if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 ) |
|
116 | 116 | { |
|
117 | 117 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 ); |
|
118 | 118 | flag = WRONG_APP_DATA; |
|
119 | 119 | } |
|
120 | 120 | } |
|
121 | 121 | //**************************************************************** |
|
122 | 122 | // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1 |
|
123 | 123 | if (flag == LFR_SUCCESSFUL) |
|
124 | 124 | { |
|
125 | 125 | sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; |
|
126 | 126 | sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; |
|
127 | 127 | aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0); |
|
128 | 128 | if (aux > FLOAT_EQUAL_ZERO) |
|
129 | 129 | { |
|
130 | 130 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 ); |
|
131 | 131 | flag = LFR_DEFAULT; |
|
132 | 132 | } |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | // SET THE PARAMETERS |
|
136 | 136 | if (flag == LFR_SUCCESSFUL) |
|
137 | 137 | { |
|
138 | 138 | flag = set_sy_lfr_b_bp_p0( TC ); |
|
139 | 139 | flag = set_sy_lfr_b_bp_p1( TC ); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | return flag; |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
146 | 146 | { |
|
147 | 147 | /** This function updates the LFR registers with the incoming sbm1 parameters. |
|
148 | 148 | * |
|
149 | 149 | * @param TC points to the TeleCommand packet that is being processed |
|
150 | 150 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
151 | 151 | * |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | int flag; |
|
155 | 155 | rtems_status_code status; |
|
156 | 156 | unsigned char sy_lfr_s1_bp_p0; |
|
157 | 157 | unsigned char sy_lfr_s1_bp_p1; |
|
158 | 158 | float aux; |
|
159 | 159 | |
|
160 | 160 | flag = LFR_SUCCESSFUL; |
|
161 | 161 | |
|
162 | 162 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
163 | 163 | status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
164 | 164 | flag = LFR_DEFAULT; |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; |
|
168 | 168 | sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; |
|
169 | 169 | |
|
170 | 170 | // sy_lfr_s1_bp_p0 |
|
171 | 171 | if (flag == LFR_SUCCESSFUL) |
|
172 | 172 | { |
|
173 | 173 | if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 ) |
|
174 | 174 | { |
|
175 | 175 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 ); |
|
176 | 176 | flag = WRONG_APP_DATA; |
|
177 | 177 | } |
|
178 | 178 | } |
|
179 | 179 | // sy_lfr_s1_bp_p1 |
|
180 | 180 | if (flag == LFR_SUCCESSFUL) |
|
181 | 181 | { |
|
182 | 182 | if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 ) |
|
183 | 183 | { |
|
184 | 184 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 ); |
|
185 | 185 | flag = WRONG_APP_DATA; |
|
186 | 186 | } |
|
187 | 187 | } |
|
188 | 188 | //****************************************************************** |
|
189 | 189 | // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1 |
|
190 | 190 | if (flag == LFR_SUCCESSFUL) |
|
191 | 191 | { |
|
192 | 192 | aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) ) |
|
193 | 193 | - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE)); |
|
194 | 194 | if (aux > FLOAT_EQUAL_ZERO) |
|
195 | 195 | { |
|
196 | 196 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 ); |
|
197 | 197 | flag = LFR_DEFAULT; |
|
198 | 198 | } |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | // SET THE PARAMETERS |
|
202 | 202 | if (flag == LFR_SUCCESSFUL) |
|
203 | 203 | { |
|
204 | 204 | flag = set_sy_lfr_s1_bp_p0( TC ); |
|
205 | 205 | flag = set_sy_lfr_s1_bp_p1( TC ); |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | return flag; |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
212 | 212 | { |
|
213 | 213 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
214 | 214 | * |
|
215 | 215 | * @param TC points to the TeleCommand packet that is being processed |
|
216 | 216 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
217 | 217 | * |
|
218 | 218 | */ |
|
219 | 219 | |
|
220 | 220 | int flag; |
|
221 | 221 | rtems_status_code status; |
|
222 | 222 | unsigned char sy_lfr_s2_bp_p0; |
|
223 | 223 | unsigned char sy_lfr_s2_bp_p1; |
|
224 | 224 | float aux; |
|
225 | 225 | |
|
226 | 226 | flag = LFR_SUCCESSFUL; |
|
227 | 227 | |
|
228 | 228 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
229 | 229 | status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
230 | 230 | flag = LFR_DEFAULT; |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
234 | 234 | sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
235 | 235 | |
|
236 | 236 | // sy_lfr_s2_bp_p0 |
|
237 | 237 | if (flag == LFR_SUCCESSFUL) |
|
238 | 238 | { |
|
239 | 239 | if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 ) |
|
240 | 240 | { |
|
241 | 241 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 ); |
|
242 | 242 | flag = WRONG_APP_DATA; |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | // sy_lfr_s2_bp_p1 |
|
246 | 246 | if (flag == LFR_SUCCESSFUL) |
|
247 | 247 | { |
|
248 | 248 | if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 ) |
|
249 | 249 | { |
|
250 | 250 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 ); |
|
251 | 251 | flag = WRONG_APP_DATA; |
|
252 | 252 | } |
|
253 | 253 | } |
|
254 | 254 | //****************************************************************** |
|
255 | 255 | // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1 |
|
256 | 256 | if (flag == LFR_SUCCESSFUL) |
|
257 | 257 | { |
|
258 | 258 | sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
259 | 259 | sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
260 | 260 | aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0); |
|
261 | 261 | if (aux > FLOAT_EQUAL_ZERO) |
|
262 | 262 | { |
|
263 | 263 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 ); |
|
264 | 264 | flag = LFR_DEFAULT; |
|
265 | 265 | } |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | // SET THE PARAMETERS |
|
269 | 269 | if (flag == LFR_SUCCESSFUL) |
|
270 | 270 | { |
|
271 | 271 | flag = set_sy_lfr_s2_bp_p0( TC ); |
|
272 | 272 | flag = set_sy_lfr_s2_bp_p1( TC ); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | return flag; |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
279 | 279 | { |
|
280 | 280 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
281 | 281 | * |
|
282 | 282 | * @param TC points to the TeleCommand packet that is being processed |
|
283 | 283 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
284 | 284 | * |
|
285 | 285 | */ |
|
286 | 286 | |
|
287 | 287 | int flag; |
|
288 | 288 | |
|
289 | 289 | flag = LFR_DEFAULT; |
|
290 | 290 | |
|
291 | 291 | flag = set_sy_lfr_kcoeff( TC, queue_id ); |
|
292 | 292 | |
|
293 | 293 | return flag; |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
297 | 297 | { |
|
298 | 298 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
299 | 299 | * |
|
300 | 300 | * @param TC points to the TeleCommand packet that is being processed |
|
301 | 301 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
302 | 302 | * |
|
303 | 303 | */ |
|
304 | 304 | |
|
305 | 305 | int flag; |
|
306 | 306 | |
|
307 | 307 | flag = LFR_DEFAULT; |
|
308 | 308 | |
|
309 | 309 | flag = set_sy_lfr_fbins( TC ); |
|
310 | 310 | |
|
311 | 311 | // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering |
|
312 | 312 | merge_fbins_masks(); |
|
313 | 313 | |
|
314 | 314 | return flag; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
318 | 318 | { |
|
319 | 319 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
320 | 320 | * |
|
321 | 321 | * @param TC points to the TeleCommand packet that is being processed |
|
322 | 322 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
323 | 323 | * |
|
324 | 324 | */ |
|
325 | 325 | |
|
326 | 326 | int flag; |
|
327 | 327 | unsigned char k; |
|
328 | 328 | |
|
329 | 329 | flag = LFR_DEFAULT; |
|
330 | 330 | k = INIT_CHAR; |
|
331 | 331 | |
|
332 | 332 | flag = check_sy_lfr_filter_parameters( TC, queue_id ); |
|
333 | 333 | |
|
334 | 334 | if (flag == LFR_SUCCESSFUL) |
|
335 | 335 | { |
|
336 | 336 | parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ]; |
|
337 | 337 | parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ]; |
|
338 | 338 | parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ]; |
|
339 | 339 | parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ]; |
|
340 | 340 | parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ]; |
|
341 | 341 | parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ]; |
|
342 | 342 | parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ]; |
|
343 | 343 | parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ]; |
|
344 | 344 | parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ]; |
|
345 | 345 | parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ]; |
|
346 | 346 | parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ]; |
|
347 | 347 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ]; |
|
348 | 348 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ]; |
|
349 | 349 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ]; |
|
350 | 350 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ]; |
|
351 | 351 | |
|
352 | 352 | //**************************** |
|
353 | 353 | // store PAS filter parameters |
|
354 | 354 | // sy_lfr_pas_filter_enabled |
|
355 | 355 | filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled; |
|
356 | 356 | set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED ); |
|
357 | 357 | // sy_lfr_pas_filter_modulus |
|
358 | 358 | filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus; |
|
359 | 359 | // sy_lfr_pas_filter_tbad |
|
360 | 360 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad, |
|
361 | 361 | parameter_dump_packet.sy_lfr_pas_filter_tbad ); |
|
362 | 362 | // sy_lfr_pas_filter_offset |
|
363 | 363 | filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset; |
|
364 | 364 | // sy_lfr_pas_filter_shift |
|
365 | 365 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift, |
|
366 | 366 | parameter_dump_packet.sy_lfr_pas_filter_shift ); |
|
367 | 367 | |
|
368 | 368 | //**************************************************** |
|
369 | 369 | // store the parameter sy_lfr_sc_rw_delta_f as a float |
|
370 | 370 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f, |
|
371 | 371 | parameter_dump_packet.sy_lfr_sc_rw_delta_f ); |
|
372 | 372 | |
|
373 | 373 | // copy rw.._k.. from the incoming TC to the local parameter_dump_packet |
|
374 | 374 | for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++) |
|
375 | 375 | { |
|
376 | 376 | parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ]; |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | //*********************************************** |
|
380 | 380 | // store the parameter sy_lfr_rw.._k.. as a float |
|
381 | 381 | // rw1_k |
|
382 | 382 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 ); |
|
383 | 383 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 ); |
|
384 | 384 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 ); |
|
385 | 385 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 ); |
|
386 | 386 | // rw2_k |
|
387 | 387 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 ); |
|
388 | 388 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 ); |
|
389 | 389 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 ); |
|
390 | 390 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 ); |
|
391 | 391 | // rw3_k |
|
392 | 392 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 ); |
|
393 | 393 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 ); |
|
394 | 394 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 ); |
|
395 | 395 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 ); |
|
396 | 396 | // rw4_k |
|
397 | 397 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 ); |
|
398 | 398 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 ); |
|
399 | 399 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 ); |
|
400 | 400 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 ); |
|
401 | 401 | |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | return flag; |
|
405 | 405 | } |
|
406 | 406 | |
|
407 | 407 | int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
408 | 408 | { |
|
409 | 409 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
410 | 410 | * |
|
411 | 411 | * @param TC points to the TeleCommand packet that is being processed |
|
412 | 412 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
413 | 413 | * |
|
414 | 414 | */ |
|
415 | 415 | |
|
416 | 416 | unsigned int address; |
|
417 | 417 | rtems_status_code status; |
|
418 | 418 | unsigned int freq; |
|
419 | 419 | unsigned int bin; |
|
420 | 420 | unsigned int coeff; |
|
421 | 421 | unsigned char *kCoeffPtr; |
|
422 | 422 | unsigned char *kCoeffDumpPtr; |
|
423 | 423 | |
|
424 | 424 | // for each sy_lfr_kcoeff_frequency there is 32 kcoeff |
|
425 | 425 | // F0 => 11 bins |
|
426 | 426 | // F1 => 13 bins |
|
427 | 427 | // F2 => 12 bins |
|
428 | 428 | // 36 bins to dump in two packets (30 bins max per packet) |
|
429 | 429 | |
|
430 | 430 | //********* |
|
431 | 431 | // PACKET 1 |
|
432 | 432 | // 11 F0 bins, 13 F1 bins and 6 F2 bins |
|
433 | 433 | kcoefficients_dump_1.destinationID = TC->sourceID; |
|
434 | 434 | increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID ); |
|
435 | 435 | for( freq = 0; |
|
436 | 436 | freq < NB_BINS_COMPRESSED_SM_F0; |
|
437 | 437 | freq++ ) |
|
438 | 438 | { |
|
439 | 439 | kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq; |
|
440 | 440 | bin = freq; |
|
441 | 441 | // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm); |
|
442 | 442 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
443 | 443 | { |
|
444 | 444 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ |
|
445 | 445 | (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ |
|
446 | 446 | ]; // 2 for the kcoeff_frequency |
|
447 | 447 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
448 | 448 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
449 | 449 | } |
|
450 | 450 | } |
|
451 | 451 | for( freq = NB_BINS_COMPRESSED_SM_F0; |
|
452 | 452 | freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 ); |
|
453 | 453 | freq++ ) |
|
454 | 454 | { |
|
455 | 455 | kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq; |
|
456 | 456 | bin = freq - NB_BINS_COMPRESSED_SM_F0; |
|
457 | 457 | // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm); |
|
458 | 458 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
459 | 459 | { |
|
460 | 460 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ |
|
461 | 461 | (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ |
|
462 | 462 | ]; // 2 for the kcoeff_frequency |
|
463 | 463 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
464 | 464 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
465 | 465 | } |
|
466 | 466 | } |
|
467 | 467 | for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 ); |
|
468 | 468 | freq < KCOEFF_BLK_NR_PKT1 ; |
|
469 | 469 | freq++ ) |
|
470 | 470 | { |
|
471 | 471 | kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq; |
|
472 | 472 | bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1); |
|
473 | 473 | // printKCoefficients( freq, bin, k_coeff_intercalib_f2); |
|
474 | 474 | for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ ) |
|
475 | 475 | { |
|
476 | 476 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ |
|
477 | 477 | (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ |
|
478 | 478 | ]; // 2 for the kcoeff_frequency |
|
479 | 479 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
480 | 480 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
481 | 481 | } |
|
482 | 482 | } |
|
483 | 483 | kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
484 | 484 | kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
485 | 485 | kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
486 | 486 | kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
487 | 487 | kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
488 | 488 | kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
489 | 489 | // SEND DATA |
|
490 | 490 | kcoefficient_node_1.status = 1; |
|
491 | 491 | address = (unsigned int) &kcoefficient_node_1; |
|
492 | 492 | status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) ); |
|
493 | 493 | if (status != RTEMS_SUCCESSFUL) { |
|
494 | 494 | PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status) |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | //******** |
|
498 | 498 | // PACKET 2 |
|
499 | 499 | // 6 F2 bins |
|
500 | 500 | kcoefficients_dump_2.destinationID = TC->sourceID; |
|
501 | 501 | increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID ); |
|
502 | 502 | for( freq = 0; |
|
503 | 503 | freq < KCOEFF_BLK_NR_PKT2; |
|
504 | 504 | freq++ ) |
|
505 | 505 | { |
|
506 | 506 | kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq; |
|
507 | 507 | bin = freq + KCOEFF_BLK_NR_PKT2; |
|
508 | 508 | // printKCoefficients( freq, bin, k_coeff_intercalib_f2); |
|
509 | 509 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
510 | 510 | { |
|
511 | 511 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ |
|
512 | 512 | (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency |
|
513 | 513 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
514 | 514 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
515 | 515 | } |
|
516 | 516 | } |
|
517 | 517 | kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
518 | 518 | kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
519 | 519 | kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
520 | 520 | kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
521 | 521 | kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
522 | 522 | kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
523 | 523 | // SEND DATA |
|
524 | 524 | kcoefficient_node_2.status = 1; |
|
525 | 525 | address = (unsigned int) &kcoefficient_node_2; |
|
526 | 526 | status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) ); |
|
527 | 527 | if (status != RTEMS_SUCCESSFUL) { |
|
528 | 528 | PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status) |
|
529 | 529 | } |
|
530 | 530 | |
|
531 | 531 | return status; |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
535 | 535 | { |
|
536 | 536 | /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue. |
|
537 | 537 | * |
|
538 | 538 | * @param queue_id is the id of the queue which handles TM related to this execution step. |
|
539 | 539 | * |
|
540 | 540 | * @return RTEMS directive status codes: |
|
541 | 541 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
542 | 542 | * - RTEMS_INVALID_ID - invalid queue id |
|
543 | 543 | * - RTEMS_INVALID_SIZE - invalid message size |
|
544 | 544 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
545 | 545 | * - RTEMS_UNSATISFIED - out of message buffers |
|
546 | 546 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
547 | 547 | * |
|
548 | 548 | */ |
|
549 | 549 | |
|
550 | 550 | int status; |
|
551 | 551 | |
|
552 | 552 | increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID ); |
|
553 | 553 | parameter_dump_packet.destinationID = TC->sourceID; |
|
554 | 554 | |
|
555 | 555 | // UPDATE TIME |
|
556 | 556 | parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
557 | 557 | parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
558 | 558 | parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
559 | 559 | parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
560 | 560 | parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
561 | 561 | parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
562 | 562 | // SEND DATA |
|
563 | 563 | status = rtems_message_queue_send( queue_id, ¶meter_dump_packet, |
|
564 | 564 | PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
565 | 565 | if (status != RTEMS_SUCCESSFUL) { |
|
566 | 566 | PRINTF1("in action_dump *** ERR sending packet, code %d", status) |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | return status; |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | //*********************** |
|
573 | 573 | // NORMAL MODE PARAMETERS |
|
574 | 574 | |
|
575 | 575 | int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
576 | 576 | { |
|
577 | 577 | unsigned char msb; |
|
578 | 578 | unsigned char lsb; |
|
579 | 579 | int flag; |
|
580 | 580 | float aux; |
|
581 | 581 | rtems_status_code status; |
|
582 | 582 | |
|
583 | 583 | unsigned int sy_lfr_n_swf_l; |
|
584 | 584 | unsigned int sy_lfr_n_swf_p; |
|
585 | 585 | unsigned int sy_lfr_n_asm_p; |
|
586 | 586 | unsigned char sy_lfr_n_bp_p0; |
|
587 | 587 | unsigned char sy_lfr_n_bp_p1; |
|
588 | 588 | unsigned char sy_lfr_n_cwf_long_f3; |
|
589 | 589 | |
|
590 | 590 | flag = LFR_SUCCESSFUL; |
|
591 | 591 | |
|
592 | 592 | //*************** |
|
593 | 593 | // get parameters |
|
594 | 594 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; |
|
595 | 595 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; |
|
596 | 596 | sy_lfr_n_swf_l = (msb * CONST_256) + lsb; |
|
597 | 597 | |
|
598 | 598 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; |
|
599 | 599 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; |
|
600 | 600 | sy_lfr_n_swf_p = (msb * CONST_256) + lsb; |
|
601 | 601 | |
|
602 | 602 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; |
|
603 | 603 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; |
|
604 | 604 | sy_lfr_n_asm_p = (msb * CONST_256) + lsb; |
|
605 | 605 | |
|
606 | 606 | sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; |
|
607 | 607 | |
|
608 | 608 | sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; |
|
609 | 609 | |
|
610 | 610 | sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; |
|
611 | 611 | |
|
612 | 612 | //****************** |
|
613 | 613 | // check consistency |
|
614 | 614 | // sy_lfr_n_swf_l |
|
615 | 615 | if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L) |
|
616 | 616 | { |
|
617 | 617 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l ); |
|
618 | 618 | flag = WRONG_APP_DATA; |
|
619 | 619 | } |
|
620 | 620 | // sy_lfr_n_swf_p |
|
621 | 621 | if (flag == LFR_SUCCESSFUL) |
|
622 | 622 | { |
|
623 | 623 | if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P ) |
|
624 | 624 | { |
|
625 | 625 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p ); |
|
626 | 626 | flag = WRONG_APP_DATA; |
|
627 | 627 | } |
|
628 | 628 | } |
|
629 | 629 | // sy_lfr_n_bp_p0 |
|
630 | 630 | if (flag == LFR_SUCCESSFUL) |
|
631 | 631 | { |
|
632 | 632 | if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0) |
|
633 | 633 | { |
|
634 | 634 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 ); |
|
635 | 635 | flag = WRONG_APP_DATA; |
|
636 | 636 | } |
|
637 | 637 | } |
|
638 | 638 | // sy_lfr_n_asm_p |
|
639 | 639 | if (flag == LFR_SUCCESSFUL) |
|
640 | 640 | { |
|
641 | 641 | if (sy_lfr_n_asm_p == 0) |
|
642 | 642 | { |
|
643 | 643 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p ); |
|
644 | 644 | flag = WRONG_APP_DATA; |
|
645 | 645 | } |
|
646 | 646 | } |
|
647 | 647 | // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0 |
|
648 | 648 | if (flag == LFR_SUCCESSFUL) |
|
649 | 649 | { |
|
650 | 650 | aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0); |
|
651 | 651 | if (aux > FLOAT_EQUAL_ZERO) |
|
652 | 652 | { |
|
653 | 653 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p ); |
|
654 | 654 | flag = WRONG_APP_DATA; |
|
655 | 655 | } |
|
656 | 656 | } |
|
657 | 657 | // sy_lfr_n_bp_p1 |
|
658 | 658 | if (flag == LFR_SUCCESSFUL) |
|
659 | 659 | { |
|
660 | 660 | if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1) |
|
661 | 661 | { |
|
662 | 662 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 ); |
|
663 | 663 | flag = WRONG_APP_DATA; |
|
664 | 664 | } |
|
665 | 665 | } |
|
666 | 666 | // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0 |
|
667 | 667 | if (flag == LFR_SUCCESSFUL) |
|
668 | 668 | { |
|
669 | 669 | aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0); |
|
670 | 670 | if (aux > FLOAT_EQUAL_ZERO) |
|
671 | 671 | { |
|
672 | 672 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 ); |
|
673 | 673 | flag = LFR_DEFAULT; |
|
674 | 674 | } |
|
675 | 675 | } |
|
676 | 676 | // sy_lfr_n_cwf_long_f3 |
|
677 | 677 | |
|
678 | 678 | return flag; |
|
679 | 679 | } |
|
680 | 680 | |
|
681 | 681 | int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ) |
|
682 | 682 | { |
|
683 | 683 | /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l). |
|
684 | 684 | * |
|
685 | 685 | * @param TC points to the TeleCommand packet that is being processed |
|
686 | 686 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
687 | 687 | * |
|
688 | 688 | */ |
|
689 | 689 | |
|
690 | 690 | int result; |
|
691 | 691 | |
|
692 | 692 | result = LFR_SUCCESSFUL; |
|
693 | 693 | |
|
694 | 694 | parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; |
|
695 | 695 | parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; |
|
696 | 696 | |
|
697 | 697 | return result; |
|
698 | 698 | } |
|
699 | 699 | |
|
700 | 700 | int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC ) |
|
701 | 701 | { |
|
702 | 702 | /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p). |
|
703 | 703 | * |
|
704 | 704 | * @param TC points to the TeleCommand packet that is being processed |
|
705 | 705 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
706 | 706 | * |
|
707 | 707 | */ |
|
708 | 708 | |
|
709 | 709 | int result; |
|
710 | 710 | |
|
711 | 711 | result = LFR_SUCCESSFUL; |
|
712 | 712 | |
|
713 | 713 | parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; |
|
714 | 714 | parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; |
|
715 | 715 | |
|
716 | 716 | return result; |
|
717 | 717 | } |
|
718 | 718 | |
|
719 | 719 | int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ) |
|
720 | 720 | { |
|
721 | 721 | /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P). |
|
722 | 722 | * |
|
723 | 723 | * @param TC points to the TeleCommand packet that is being processed |
|
724 | 724 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
725 | 725 | * |
|
726 | 726 | */ |
|
727 | 727 | |
|
728 | 728 | int result; |
|
729 | 729 | |
|
730 | 730 | result = LFR_SUCCESSFUL; |
|
731 | 731 | |
|
732 | 732 | parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; |
|
733 | 733 | parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; |
|
734 | 734 | |
|
735 | 735 | return result; |
|
736 | 736 | } |
|
737 | 737 | |
|
738 | 738 | int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
739 | 739 | { |
|
740 | 740 | /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0). |
|
741 | 741 | * |
|
742 | 742 | * @param TC points to the TeleCommand packet that is being processed |
|
743 | 743 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
744 | 744 | * |
|
745 | 745 | */ |
|
746 | 746 | |
|
747 | 747 | int status; |
|
748 | 748 | |
|
749 | 749 | status = LFR_SUCCESSFUL; |
|
750 | 750 | |
|
751 | 751 | parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; |
|
752 | 752 | |
|
753 | 753 | return status; |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC ) |
|
757 | 757 | { |
|
758 | 758 | /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1). |
|
759 | 759 | * |
|
760 | 760 | * @param TC points to the TeleCommand packet that is being processed |
|
761 | 761 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
762 | 762 | * |
|
763 | 763 | */ |
|
764 | 764 | |
|
765 | 765 | int status; |
|
766 | 766 | |
|
767 | 767 | status = LFR_SUCCESSFUL; |
|
768 | 768 | |
|
769 | 769 | parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; |
|
770 | 770 | |
|
771 | 771 | return status; |
|
772 | 772 | } |
|
773 | 773 | |
|
774 | 774 | int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC ) |
|
775 | 775 | { |
|
776 | 776 | /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets. |
|
777 | 777 | * |
|
778 | 778 | * @param TC points to the TeleCommand packet that is being processed |
|
779 | 779 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
780 | 780 | * |
|
781 | 781 | */ |
|
782 | 782 | |
|
783 | 783 | int status; |
|
784 | 784 | |
|
785 | 785 | status = LFR_SUCCESSFUL; |
|
786 | 786 | |
|
787 | 787 | parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; |
|
788 | 788 | |
|
789 | 789 | return status; |
|
790 | 790 | } |
|
791 | 791 | |
|
792 | 792 | //********************** |
|
793 | 793 | // BURST MODE PARAMETERS |
|
794 | 794 | int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC) |
|
795 | 795 | { |
|
796 | 796 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0). |
|
797 | 797 | * |
|
798 | 798 | * @param TC points to the TeleCommand packet that is being processed |
|
799 | 799 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
800 | 800 | * |
|
801 | 801 | */ |
|
802 | 802 | |
|
803 | 803 | int status; |
|
804 | 804 | |
|
805 | 805 | status = LFR_SUCCESSFUL; |
|
806 | 806 | |
|
807 | 807 | parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; |
|
808 | 808 | |
|
809 | 809 | return status; |
|
810 | 810 | } |
|
811 | 811 | |
|
812 | 812 | int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
813 | 813 | { |
|
814 | 814 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1). |
|
815 | 815 | * |
|
816 | 816 | * @param TC points to the TeleCommand packet that is being processed |
|
817 | 817 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
818 | 818 | * |
|
819 | 819 | */ |
|
820 | 820 | |
|
821 | 821 | int status; |
|
822 | 822 | |
|
823 | 823 | status = LFR_SUCCESSFUL; |
|
824 | 824 | |
|
825 | 825 | parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; |
|
826 | 826 | |
|
827 | 827 | return status; |
|
828 | 828 | } |
|
829 | 829 | |
|
830 | 830 | //********************* |
|
831 | 831 | // SBM1 MODE PARAMETERS |
|
832 | 832 | int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
833 | 833 | { |
|
834 | 834 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0). |
|
835 | 835 | * |
|
836 | 836 | * @param TC points to the TeleCommand packet that is being processed |
|
837 | 837 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
838 | 838 | * |
|
839 | 839 | */ |
|
840 | 840 | |
|
841 | 841 | int status; |
|
842 | 842 | |
|
843 | 843 | status = LFR_SUCCESSFUL; |
|
844 | 844 | |
|
845 | 845 | parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; |
|
846 | 846 | |
|
847 | 847 | return status; |
|
848 | 848 | } |
|
849 | 849 | |
|
850 | 850 | int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
851 | 851 | { |
|
852 | 852 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1). |
|
853 | 853 | * |
|
854 | 854 | * @param TC points to the TeleCommand packet that is being processed |
|
855 | 855 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
856 | 856 | * |
|
857 | 857 | */ |
|
858 | 858 | |
|
859 | 859 | int status; |
|
860 | 860 | |
|
861 | 861 | status = LFR_SUCCESSFUL; |
|
862 | 862 | |
|
863 | 863 | parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; |
|
864 | 864 | |
|
865 | 865 | return status; |
|
866 | 866 | } |
|
867 | 867 | |
|
868 | 868 | //********************* |
|
869 | 869 | // SBM2 MODE PARAMETERS |
|
870 | 870 | int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
871 | 871 | { |
|
872 | 872 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0). |
|
873 | 873 | * |
|
874 | 874 | * @param TC points to the TeleCommand packet that is being processed |
|
875 | 875 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
876 | 876 | * |
|
877 | 877 | */ |
|
878 | 878 | |
|
879 | 879 | int status; |
|
880 | 880 | |
|
881 | 881 | status = LFR_SUCCESSFUL; |
|
882 | 882 | |
|
883 | 883 | parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
884 | 884 | |
|
885 | 885 | return status; |
|
886 | 886 | } |
|
887 | 887 | |
|
888 | 888 | int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
889 | 889 | { |
|
890 | 890 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1). |
|
891 | 891 | * |
|
892 | 892 | * @param TC points to the TeleCommand packet that is being processed |
|
893 | 893 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
894 | 894 | * |
|
895 | 895 | */ |
|
896 | 896 | |
|
897 | 897 | int status; |
|
898 | 898 | |
|
899 | 899 | status = LFR_SUCCESSFUL; |
|
900 | 900 | |
|
901 | 901 | parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
902 | 902 | |
|
903 | 903 | return status; |
|
904 | 904 | } |
|
905 | 905 | |
|
906 | 906 | //******************* |
|
907 | 907 | // TC_LFR_UPDATE_INFO |
|
908 | 908 | unsigned int check_update_info_hk_lfr_mode( unsigned char mode ) |
|
909 | 909 | { |
|
910 | 910 | unsigned int status; |
|
911 | 911 | |
|
912 | 912 | status = LFR_DEFAULT; |
|
913 | 913 | |
|
914 | 914 | if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL) |
|
915 | 915 | || (mode == LFR_MODE_BURST) |
|
916 | 916 | || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2)) |
|
917 | 917 | { |
|
918 | 918 | status = LFR_SUCCESSFUL; |
|
919 | 919 | } |
|
920 | 920 | else |
|
921 | 921 | { |
|
922 | 922 | status = LFR_DEFAULT; |
|
923 | 923 | } |
|
924 | 924 | |
|
925 | 925 | return status; |
|
926 | 926 | } |
|
927 | 927 | |
|
928 | 928 | unsigned int check_update_info_hk_tds_mode( unsigned char mode ) |
|
929 | 929 | { |
|
930 | 930 | unsigned int status; |
|
931 | 931 | |
|
932 | 932 | status = LFR_DEFAULT; |
|
933 | 933 | |
|
934 | 934 | if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL) |
|
935 | 935 | || (mode == TDS_MODE_BURST) |
|
936 | 936 | || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2) |
|
937 | 937 | || (mode == TDS_MODE_LFM)) |
|
938 | 938 | { |
|
939 | 939 | status = LFR_SUCCESSFUL; |
|
940 | 940 | } |
|
941 | 941 | else |
|
942 | 942 | { |
|
943 | 943 | status = LFR_DEFAULT; |
|
944 | 944 | } |
|
945 | 945 | |
|
946 | 946 | return status; |
|
947 | 947 | } |
|
948 | 948 | |
|
949 | 949 | unsigned int check_update_info_hk_thr_mode( unsigned char mode ) |
|
950 | 950 | { |
|
951 | 951 | unsigned int status; |
|
952 | 952 | |
|
953 | 953 | status = LFR_DEFAULT; |
|
954 | 954 | |
|
955 | 955 | if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL) |
|
956 | 956 | || (mode == THR_MODE_BURST)) |
|
957 | 957 | { |
|
958 | 958 | status = LFR_SUCCESSFUL; |
|
959 | 959 | } |
|
960 | 960 | else |
|
961 | 961 | { |
|
962 | 962 | status = LFR_DEFAULT; |
|
963 | 963 | } |
|
964 | 964 | |
|
965 | 965 | return status; |
|
966 | 966 | } |
|
967 | 967 | |
|
968 | 968 | void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value ) |
|
969 | 969 | { |
|
970 | 970 | unsigned char flag; |
|
971 | 971 | unsigned char flagPosInByte; |
|
972 | 972 | unsigned char newFlag; |
|
973 | 973 | unsigned char flagMask; |
|
974 | 974 | |
|
975 | 975 | // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered |
|
976 | 976 | if (isnan(value)) |
|
977 | 977 | { |
|
978 | 978 | flag = FLAG_NAN; |
|
979 | 979 | } |
|
980 | 980 | else |
|
981 | 981 | { |
|
982 | 982 | flag = FLAG_IAN; |
|
983 | 983 | } |
|
984 | 984 | |
|
985 | 985 | switch(wheel) |
|
986 | 986 | { |
|
987 | 987 | case WHEEL_1: |
|
988 | 988 | flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq; |
|
989 | 989 | flagMask = ~(1 << flagPosInByte); |
|
990 | 990 | newFlag = flag << flagPosInByte; |
|
991 | 991 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag; |
|
992 | 992 | break; |
|
993 | 993 | case WHEEL_2: |
|
994 | 994 | flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq; |
|
995 | 995 | flagMask = ~(1 << flagPosInByte); |
|
996 | 996 | newFlag = flag << flagPosInByte; |
|
997 | 997 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag; |
|
998 | 998 | break; |
|
999 | 999 | case WHEEL_3: |
|
1000 | 1000 | flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq; |
|
1001 | 1001 | flagMask = ~(1 << flagPosInByte); |
|
1002 | 1002 | newFlag = flag << flagPosInByte; |
|
1003 | 1003 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag; |
|
1004 | 1004 | break; |
|
1005 | 1005 | case WHEEL_4: |
|
1006 | 1006 | flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq; |
|
1007 | 1007 | flagMask = ~(1 << flagPosInByte); |
|
1008 | 1008 | newFlag = flag << flagPosInByte; |
|
1009 | 1009 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag; |
|
1010 | 1010 | break; |
|
1011 | 1011 | default: |
|
1012 | 1012 | break; |
|
1013 | 1013 | } |
|
1014 | 1014 | } |
|
1015 | 1015 | |
|
1016 | 1016 | void set_hk_lfr_sc_rw_f_flags( void ) |
|
1017 | 1017 | { |
|
1018 | 1018 | // RW1 |
|
1019 | 1019 | set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 ); |
|
1020 | 1020 | set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 ); |
|
1021 | 1021 | set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 ); |
|
1022 | 1022 | set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 ); |
|
1023 | 1023 | |
|
1024 | 1024 | // RW2 |
|
1025 | 1025 | set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 ); |
|
1026 | 1026 | set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 ); |
|
1027 | 1027 | set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 ); |
|
1028 | 1028 | set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 ); |
|
1029 | 1029 | |
|
1030 | 1030 | // RW3 |
|
1031 | 1031 | set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 ); |
|
1032 | 1032 | set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 ); |
|
1033 | 1033 | set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 ); |
|
1034 | 1034 | set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 ); |
|
1035 | 1035 | |
|
1036 | 1036 | // RW4 |
|
1037 | 1037 | set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 ); |
|
1038 | 1038 | set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 ); |
|
1039 | 1039 | set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 ); |
|
1040 | 1040 | set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 ); |
|
1041 | 1041 | } |
|
1042 | 1042 | |
|
1043 | 1043 | void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC ) |
|
1044 | 1044 | { |
|
1045 | 1045 | /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally. |
|
1046 | 1046 | * |
|
1047 | 1047 | * @param TC points to the TeleCommand packet that is being processed |
|
1048 | 1048 | * |
|
1049 | 1049 | */ |
|
1050 | 1050 | |
|
1051 | 1051 | unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet |
|
1052 | 1052 | |
|
1053 | 1053 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
1054 | 1054 | |
|
1055 | 1055 | // rw1_f |
|
1056 | 1056 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] ); |
|
1057 | 1057 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] ); |
|
1058 | 1058 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] ); |
|
1059 | 1059 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] ); |
|
1060 | 1060 | |
|
1061 | 1061 | // rw2_f |
|
1062 | 1062 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] ); |
|
1063 | 1063 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] ); |
|
1064 | 1064 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] ); |
|
1065 | 1065 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] ); |
|
1066 | 1066 | |
|
1067 | 1067 | // rw3_f |
|
1068 | 1068 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] ); |
|
1069 | 1069 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] ); |
|
1070 | 1070 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] ); |
|
1071 | 1071 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] ); |
|
1072 | 1072 | |
|
1073 | 1073 | // rw4_f |
|
1074 | 1074 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] ); |
|
1075 | 1075 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] ); |
|
1076 | 1076 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] ); |
|
1077 | 1077 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] ); |
|
1078 | 1078 | |
|
1079 | 1079 | // test each reaction wheel frequency value. NaN means that the frequency is not filtered |
|
1080 | 1080 | |
|
1081 | 1081 | } |
|
1082 | 1082 | |
|
1083 | 1083 | void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float kcoeff ) |
|
1084 | 1084 | { |
|
1085 | 1085 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
1086 | 1086 | * |
|
1087 | 1087 | * @param fbins_mask |
|
1088 | 1088 | * @param rw_f is the reaction wheel frequency to filter |
|
1089 | 1089 | * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel |
|
1090 | 1090 | * @param flag [true] filtering enabled [false] filtering disabled |
|
1091 | 1091 | * |
|
1092 | 1092 | * @return void |
|
1093 | 1093 | * |
|
1094 | 1094 | */ |
|
1095 | 1095 | |
|
1096 | 1096 | float f_RW_min; |
|
1097 | 1097 | float f_RW_MAX; |
|
1098 | 1098 | float fi_min; |
|
1099 | 1099 | float fi_MAX; |
|
1100 | 1100 | float fi; |
|
1101 | 1101 | float deltaBelow; |
|
1102 | 1102 | float deltaAbove; |
|
1103 | 1103 | int binBelow; |
|
1104 | 1104 | int binAbove; |
|
1105 | 1105 | int closestBin; |
|
1106 | 1106 | unsigned int whichByte; |
|
1107 | 1107 | int selectedByte; |
|
1108 | 1108 | int bin; |
|
1109 | 1109 | int binToRemove[NB_BINS_TO_REMOVE]; |
|
1110 | 1110 | int i; |
|
1111 | 1111 | |
|
1112 | 1112 | closestBin = 0; |
|
1113 | 1113 | whichByte = 0; |
|
1114 | 1114 | bin = 0; |
|
1115 | 1115 | |
|
1116 | 1116 | for (i = 0; i < NB_BINS_TO_REMOVE; i++) |
|
1117 | 1117 | { |
|
1118 | 1118 | binToRemove[i] = -1; |
|
1119 | 1119 | } |
|
1120 | 1120 | |
|
1121 | 1121 | if (!isnan(rw_f)) |
|
1122 | 1122 | { |
|
1123 | 1123 | |
|
1124 | 1124 | // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ] |
|
1125 | 1125 | f_RW_min = rw_f - ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV); |
|
1126 | 1126 | f_RW_MAX = rw_f + ( (filterPar.sy_lfr_sc_rw_delta_f * kcoeff) / DELTAF_DIV); |
|
1127 | 1127 | |
|
1128 | 1128 | // compute the index of the frequency bin immediately below rw_f |
|
1129 | 1129 | binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) ); |
|
1130 | 1130 | deltaBelow = rw_f - binBelow * deltaFreq; |
|
1131 | 1131 | |
|
1132 | 1132 | // compute the index of the frequency bin immediately above rw_f |
|
1133 | 1133 | binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) ); |
|
1134 | 1134 | deltaAbove = binAbove * deltaFreq - rw_f; |
|
1135 | 1135 | |
|
1136 | 1136 | // search the closest bin |
|
1137 | 1137 | if (deltaAbove > deltaBelow) |
|
1138 | 1138 | { |
|
1139 | 1139 | closestBin = binBelow; |
|
1140 | 1140 | } |
|
1141 | 1141 | else |
|
1142 | 1142 | { |
|
1143 | 1143 | closestBin = binAbove; |
|
1144 | 1144 | } |
|
1145 | 1145 | |
|
1146 | 1146 | // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285] |
|
1147 | 1147 | fi = closestBin * deltaFreq; |
|
1148 | 1148 | fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF); |
|
1149 | 1149 | fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF); |
|
1150 | 1150 | |
|
1151 | 1151 | //************************************************************************************** |
|
1152 | 1152 | // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra |
|
1153 | 1153 | // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum |
|
1154 | 1154 | //************************************************************************************** |
|
1155 | 1155 | |
|
1156 | 1156 | // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ] |
|
1157 | 1157 | // => remove f_(i), f_(i-1) and f_(i+1) |
|
1158 | 1158 | if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) ) |
|
1159 | 1159 | { |
|
1160 | 1160 | binToRemove[0] = (closestBin - 1) - 1; |
|
1161 | 1161 | binToRemove[1] = (closestBin) - 1; |
|
1162 | 1162 | binToRemove[2] = (closestBin + 1) - 1; |
|
1163 | 1163 | } |
|
1164 | 1164 | // 2. ELSE |
|
1165 | 1165 | // => remove the two f_(i) which are around f_RW |
|
1166 | 1166 | else |
|
1167 | 1167 | { |
|
1168 | 1168 | binToRemove[0] = (binBelow) - 1; |
|
1169 | 1169 | binToRemove[1] = (binAbove) - 1; |
|
1170 | 1170 | binToRemove[2] = (-1); |
|
1171 | 1171 | } |
|
1172 | 1172 | |
|
1173 | 1173 | for (i = 0; i < NB_BINS_TO_REMOVE; i++) |
|
1174 | 1174 | { |
|
1175 | 1175 | bin = binToRemove[i]; |
|
1176 | 1176 | if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) ) |
|
1177 | 1177 | { |
|
1178 | 1178 | |
|
1179 | 1179 | whichByte = (bin >> SHIFT_3_BITS); // division by 8 |
|
1180 | 1180 | selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) ); |
|
1181 | 1181 | fbins_mask[BYTES_PER_MASK - 1 - whichByte] = |
|
1182 | 1182 | fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets |
|
1183 | 1183 | } |
|
1184 | 1184 | } |
|
1185 | 1185 | } |
|
1186 | 1186 | } |
|
1187 | 1187 | |
|
1188 | 1188 | void build_sy_lfr_rw_mask( unsigned int channel ) |
|
1189 | 1189 | { |
|
1190 | 1190 | unsigned char local_rw_fbins_mask[BYTES_PER_MASK]; |
|
1191 | 1191 | unsigned char *maskPtr; |
|
1192 | 1192 | double deltaF; |
|
1193 | 1193 | unsigned k; |
|
1194 | 1194 | |
|
1195 | 1195 | maskPtr = NULL; |
|
1196 | 1196 | deltaF = DELTAF_F2; |
|
1197 | 1197 | |
|
1198 | 1198 | switch (channel) |
|
1199 | 1199 | { |
|
1200 | 1200 | case CHANNELF0: |
|
1201 | 1201 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1; |
|
1202 | 1202 | deltaF = DELTAF_F0; |
|
1203 | 1203 | break; |
|
1204 | 1204 | case CHANNELF1: |
|
1205 | 1205 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1; |
|
1206 | 1206 | deltaF = DELTAF_F1; |
|
1207 | 1207 | break; |
|
1208 | 1208 | case CHANNELF2: |
|
1209 | 1209 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1; |
|
1210 | 1210 | deltaF = DELTAF_F2; |
|
1211 | 1211 | break; |
|
1212 | 1212 | default: |
|
1213 | 1213 | break; |
|
1214 | 1214 | } |
|
1215 | 1215 | |
|
1216 | 1216 | for (k = 0; k < BYTES_PER_MASK; k++) |
|
1217 | 1217 | { |
|
1218 | 1218 | local_rw_fbins_mask[k] = INT8_ALL_F; |
|
1219 | 1219 | } |
|
1220 | 1220 | |
|
1221 | 1221 | // RW1 |
|
1222 | 1222 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 ); |
|
1223 | 1223 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 ); |
|
1224 | 1224 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 ); |
|
1225 | 1225 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 ); |
|
1226 | 1226 | |
|
1227 | 1227 | // RW2 |
|
1228 | 1228 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 ); |
|
1229 | 1229 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 ); |
|
1230 | 1230 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 ); |
|
1231 | 1231 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 ); |
|
1232 | 1232 | |
|
1233 | 1233 | // RW3 |
|
1234 | 1234 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 ); |
|
1235 | 1235 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 ); |
|
1236 | 1236 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 ); |
|
1237 | 1237 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 ); |
|
1238 | 1238 | |
|
1239 | 1239 | // RW4 |
|
1240 | 1240 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 ); |
|
1241 | 1241 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 ); |
|
1242 | 1242 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 ); |
|
1243 | 1243 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 ); |
|
1244 | 1244 | |
|
1245 | 1245 | // update the value of the fbins related to reaction wheels frequency filtering |
|
1246 | 1246 | if (maskPtr != NULL) |
|
1247 | 1247 | { |
|
1248 | 1248 | for (k = 0; k < BYTES_PER_MASK; k++) |
|
1249 | 1249 | { |
|
1250 | 1250 | maskPtr[k] = local_rw_fbins_mask[k]; |
|
1251 | 1251 | } |
|
1252 | 1252 | } |
|
1253 | 1253 | } |
|
1254 | 1254 | |
|
1255 | 1255 | void build_sy_lfr_rw_masks( void ) |
|
1256 | 1256 | { |
|
1257 | 1257 | build_sy_lfr_rw_mask( CHANNELF0 ); |
|
1258 | 1258 | build_sy_lfr_rw_mask( CHANNELF1 ); |
|
1259 | 1259 | build_sy_lfr_rw_mask( CHANNELF2 ); |
|
1260 | 1260 | } |
|
1261 | 1261 | |
|
1262 | 1262 | void merge_fbins_masks( void ) |
|
1263 | 1263 | { |
|
1264 | 1264 | unsigned char k; |
|
1265 | 1265 | |
|
1266 | 1266 | unsigned char *fbins_f0; |
|
1267 | 1267 | unsigned char *fbins_f1; |
|
1268 | 1268 | unsigned char *fbins_f2; |
|
1269 | 1269 | unsigned char *rw_mask_f0; |
|
1270 | 1270 | unsigned char *rw_mask_f1; |
|
1271 | 1271 | unsigned char *rw_mask_f2; |
|
1272 | 1272 | |
|
1273 | 1273 | fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1; |
|
1274 | 1274 | fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1; |
|
1275 | 1275 | fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1; |
|
1276 | 1276 | rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1; |
|
1277 | 1277 | rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1; |
|
1278 | 1278 | rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1; |
|
1279 | 1279 | |
|
1280 | 1280 | for( k=0; k < BYTES_PER_MASK; k++ ) |
|
1281 | 1281 | { |
|
1282 | 1282 | fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k]; |
|
1283 | 1283 | fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k]; |
|
1284 | 1284 | fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k]; |
|
1285 | 1285 | } |
|
1286 | 1286 | } |
|
1287 | 1287 | |
|
1288 | 1288 | //*********** |
|
1289 | 1289 | // FBINS MASK |
|
1290 | 1290 | |
|
1291 | 1291 | int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC ) |
|
1292 | 1292 | { |
|
1293 | 1293 | int status; |
|
1294 | 1294 | unsigned int k; |
|
1295 | 1295 | unsigned char *fbins_mask_dump; |
|
1296 | 1296 | unsigned char *fbins_mask_TC; |
|
1297 | 1297 | |
|
1298 | 1298 | status = LFR_SUCCESSFUL; |
|
1299 | 1299 | |
|
1300 | 1300 | fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1; |
|
1301 | 1301 | fbins_mask_TC = TC->dataAndCRC; |
|
1302 | 1302 | |
|
1303 | 1303 | for (k=0; k < BYTES_PER_MASKS_SET; k++) |
|
1304 | 1304 | { |
|
1305 | 1305 | fbins_mask_dump[k] = fbins_mask_TC[k]; |
|
1306 | 1306 | } |
|
1307 | 1307 | |
|
1308 | 1308 | return status; |
|
1309 | 1309 | } |
|
1310 | 1310 | |
|
1311 | 1311 | //*************************** |
|
1312 | 1312 | // TC_LFR_LOAD_PAS_FILTER_PAR |
|
1313 | 1313 | |
|
1314 | 1314 | int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
1315 | 1315 | { |
|
1316 | 1316 | int flag; |
|
1317 | 1317 | rtems_status_code status; |
|
1318 | 1318 | |
|
1319 | 1319 | unsigned char sy_lfr_pas_filter_enabled; |
|
1320 | 1320 | unsigned char sy_lfr_pas_filter_modulus; |
|
1321 | 1321 | float sy_lfr_pas_filter_tbad; |
|
1322 | 1322 | unsigned char sy_lfr_pas_filter_offset; |
|
1323 | 1323 | float sy_lfr_pas_filter_shift; |
|
1324 | 1324 | float sy_lfr_sc_rw_delta_f; |
|
1325 | 1325 | char *parPtr; |
|
1326 | 1326 | |
|
1327 | 1327 | flag = LFR_SUCCESSFUL; |
|
1328 | 1328 | sy_lfr_pas_filter_tbad = INIT_FLOAT; |
|
1329 | 1329 | sy_lfr_pas_filter_shift = INIT_FLOAT; |
|
1330 | 1330 | sy_lfr_sc_rw_delta_f = INIT_FLOAT; |
|
1331 | 1331 | parPtr = NULL; |
|
1332 | 1332 | |
|
1333 | 1333 | //*************** |
|
1334 | 1334 | // get parameters |
|
1335 | 1335 | sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001] |
|
1336 | 1336 | sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ]; |
|
1337 | 1337 | copyFloatByChar( |
|
1338 | 1338 | (unsigned char*) &sy_lfr_pas_filter_tbad, |
|
1339 | 1339 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ] |
|
1340 | 1340 | ); |
|
1341 | 1341 | sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ]; |
|
1342 | 1342 | copyFloatByChar( |
|
1343 | 1343 | (unsigned char*) &sy_lfr_pas_filter_shift, |
|
1344 | 1344 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ] |
|
1345 | 1345 | ); |
|
1346 | 1346 | copyFloatByChar( |
|
1347 | 1347 | (unsigned char*) &sy_lfr_sc_rw_delta_f, |
|
1348 | 1348 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ] |
|
1349 | 1349 | ); |
|
1350 | 1350 | |
|
1351 | 1351 | //****************** |
|
1352 | 1352 | // CHECK CONSISTENCY |
|
1353 | 1353 | |
|
1354 | 1354 | //************************** |
|
1355 | 1355 | // sy_lfr_pas_filter_enabled |
|
1356 | 1356 | // nothing to check, value is 0 or 1 |
|
1357 | 1357 | |
|
1358 | 1358 | //************************** |
|
1359 | 1359 | // sy_lfr_pas_filter_modulus |
|
1360 | 1360 | if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) ) |
|
1361 | 1361 | { |
|
1362 | 1362 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus ); |
|
1363 | 1363 | flag = WRONG_APP_DATA; |
|
1364 | 1364 | } |
|
1365 | 1365 | |
|
1366 | 1366 | //*********************** |
|
1367 | 1367 | // sy_lfr_pas_filter_tbad |
|
1368 | 1368 | if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) ) |
|
1369 | 1369 | { |
|
1370 | 1370 | parPtr = (char*) &sy_lfr_pas_filter_tbad; |
|
1371 | 1371 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] ); |
|
1372 | 1372 | flag = WRONG_APP_DATA; |
|
1373 | 1373 | } |
|
1374 | 1374 | |
|
1375 | 1375 | //************************* |
|
1376 | 1376 | // sy_lfr_pas_filter_offset |
|
1377 | 1377 | if (flag == LFR_SUCCESSFUL) |
|
1378 | 1378 | { |
|
1379 | 1379 | if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) ) |
|
1380 | 1380 | { |
|
1381 | 1381 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset ); |
|
1382 | 1382 | flag = WRONG_APP_DATA; |
|
1383 | 1383 | } |
|
1384 | 1384 | } |
|
1385 | 1385 | |
|
1386 | 1386 | //************************ |
|
1387 | 1387 | // sy_lfr_pas_filter_shift |
|
1388 | 1388 | if (flag == LFR_SUCCESSFUL) |
|
1389 | 1389 | { |
|
1390 | 1390 | if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) ) |
|
1391 | 1391 | { |
|
1392 | 1392 | parPtr = (char*) &sy_lfr_pas_filter_shift; |
|
1393 | 1393 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] ); |
|
1394 | 1394 | flag = WRONG_APP_DATA; |
|
1395 | 1395 | } |
|
1396 | 1396 | } |
|
1397 | 1397 | |
|
1398 | 1398 | //************************************* |
|
1399 | 1399 | // check global coherency of the values |
|
1400 | 1400 | if (flag == LFR_SUCCESSFUL) |
|
1401 | 1401 | { |
|
1402 | 1402 | if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus ) |
|
1403 | 1403 | { |
|
1404 | 1404 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus ); |
|
1405 | 1405 | flag = WRONG_APP_DATA; |
|
1406 | 1406 | } |
|
1407 | 1407 | } |
|
1408 | 1408 | |
|
1409 | 1409 | //********************* |
|
1410 | 1410 | // sy_lfr_sc_rw_delta_f |
|
1411 | 1411 | // nothing to check, no default value in the ICD |
|
1412 | 1412 | |
|
1413 | 1413 | return flag; |
|
1414 | 1414 | } |
|
1415 | 1415 | |
|
1416 | 1416 | //************** |
|
1417 | 1417 | // KCOEFFICIENTS |
|
1418 | 1418 | int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id ) |
|
1419 | 1419 | { |
|
1420 | 1420 | unsigned int kcoeff; |
|
1421 | 1421 | unsigned short sy_lfr_kcoeff_frequency; |
|
1422 | 1422 | unsigned short bin; |
|
1423 | unsigned short *freqPtr; | |
|
1424 | 1423 | float *kcoeffPtr_norm; |
|
1425 | 1424 | float *kcoeffPtr_sbm; |
|
1426 | 1425 | int status; |
|
1427 | 1426 | unsigned char *kcoeffLoadPtr; |
|
1428 | 1427 | unsigned char *kcoeffNormPtr; |
|
1429 | 1428 | unsigned char *kcoeffSbmPtr_a; |
|
1430 | 1429 | unsigned char *kcoeffSbmPtr_b; |
|
1431 | 1430 | |
|
1432 | status = LFR_SUCCESSFUL; | |
|
1433 | ||
|
1431 | sy_lfr_kcoeff_frequency = 0; | |
|
1432 | bin = 0; | |
|
1434 | 1433 | kcoeffPtr_norm = NULL; |
|
1435 | 1434 | kcoeffPtr_sbm = NULL; |
|
1436 | bin = 0; | |
|
1435 | status = LFR_SUCCESSFUL; | |
|
1437 | 1436 | |
|
1438 | freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY]; | |
|
1439 | sy_lfr_kcoeff_frequency = *freqPtr; | |
|
1437 | // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER | |
|
1438 | copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] ); | |
|
1439 | ||
|
1440 | 1440 | |
|
1441 | 1441 | if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM ) |
|
1442 | 1442 | { |
|
1443 | 1443 | PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency) |
|
1444 | 1444 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1, |
|
1445 | 1445 | TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB |
|
1446 | 1446 | status = LFR_DEFAULT; |
|
1447 | 1447 | } |
|
1448 | 1448 | else |
|
1449 | 1449 | { |
|
1450 | 1450 | if ( ( sy_lfr_kcoeff_frequency >= 0 ) |
|
1451 | 1451 | && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) ) |
|
1452 | 1452 | { |
|
1453 | 1453 | kcoeffPtr_norm = k_coeff_intercalib_f0_norm; |
|
1454 | 1454 | kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm; |
|
1455 | 1455 | bin = sy_lfr_kcoeff_frequency; |
|
1456 | 1456 | } |
|
1457 | 1457 | else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 ) |
|
1458 | 1458 | && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) ) |
|
1459 | 1459 | { |
|
1460 | 1460 | kcoeffPtr_norm = k_coeff_intercalib_f1_norm; |
|
1461 | 1461 | kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm; |
|
1462 | 1462 | bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0; |
|
1463 | 1463 | } |
|
1464 | 1464 | else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) |
|
1465 | 1465 | && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) ) |
|
1466 | 1466 | { |
|
1467 | 1467 | kcoeffPtr_norm = k_coeff_intercalib_f2; |
|
1468 | 1468 | kcoeffPtr_sbm = NULL; |
|
1469 | 1469 | bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1); |
|
1470 | 1470 | } |
|
1471 | 1471 | } |
|
1472 | 1472 | |
|
1473 | 1473 | if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products |
|
1474 | 1474 | { |
|
1475 | 1475 | for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++) |
|
1476 | 1476 | { |
|
1477 | 1477 | // destination |
|
1478 | 1478 | kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ]; |
|
1479 | 1479 | // source |
|
1480 | 1480 | kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)]; |
|
1481 | 1481 | // copy source to destination |
|
1482 | 1482 | copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr ); |
|
1483 | 1483 | } |
|
1484 | 1484 | } |
|
1485 | 1485 | |
|
1486 | 1486 | if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products |
|
1487 | 1487 | { |
|
1488 | 1488 | for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++) |
|
1489 | 1489 | { |
|
1490 | 1490 | // destination |
|
1491 | 1491 | kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ]; |
|
1492 | 1492 | kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ]; |
|
1493 | 1493 | // source |
|
1494 | 1494 | kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)]; |
|
1495 | 1495 | // copy source to destination |
|
1496 | 1496 | copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr ); |
|
1497 | 1497 | copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr ); |
|
1498 | 1498 | } |
|
1499 | 1499 | } |
|
1500 | 1500 | |
|
1501 | 1501 | // print_k_coeff(); |
|
1502 | 1502 | |
|
1503 | 1503 | return status; |
|
1504 | 1504 | } |
|
1505 | 1505 | |
|
1506 | 1506 | void copyFloatByChar( unsigned char *destination, unsigned char *source ) |
|
1507 | 1507 | { |
|
1508 | 1508 | destination[BYTE_0] = source[BYTE_0]; |
|
1509 | 1509 | destination[BYTE_1] = source[BYTE_1]; |
|
1510 | 1510 | destination[BYTE_2] = source[BYTE_2]; |
|
1511 | 1511 | destination[BYTE_3] = source[BYTE_3]; |
|
1512 | 1512 | } |
|
1513 | 1513 | |
|
1514 | 1514 | void copyInt32ByChar( unsigned char *destination, unsigned char *source ) |
|
1515 | 1515 | { |
|
1516 | 1516 | destination[BYTE_0] = source[BYTE_0]; |
|
1517 | 1517 | destination[BYTE_1] = source[BYTE_1]; |
|
1518 | 1518 | destination[BYTE_2] = source[BYTE_2]; |
|
1519 | 1519 | destination[BYTE_3] = source[BYTE_3]; |
|
1520 | 1520 | } |
|
1521 | 1521 | |
|
1522 | void copyInt16ByChar( unsigned char *destination, unsigned char *source ) | |
|
1523 | { | |
|
1524 | destination[BYTE_0] = source[BYTE_0]; | |
|
1525 | destination[BYTE_1] = source[BYTE_1]; | |
|
1526 | } | |
|
1527 | ||
|
1522 | 1528 | void floatToChar( float value, unsigned char* ptr) |
|
1523 | 1529 | { |
|
1524 | 1530 | unsigned char* valuePtr; |
|
1525 | 1531 | |
|
1526 | 1532 | valuePtr = (unsigned char*) &value; |
|
1527 | 1533 | ptr[BYTE_0] = valuePtr[BYTE_0]; |
|
1528 | 1534 | ptr[BYTE_1] = valuePtr[BYTE_1]; |
|
1529 | 1535 | ptr[BYTE_2] = valuePtr[BYTE_2]; |
|
1530 | 1536 | ptr[BYTE_3] = valuePtr[BYTE_3]; |
|
1531 | 1537 | } |
|
1532 | 1538 | |
|
1533 | 1539 | //********** |
|
1534 | 1540 | // init dump |
|
1535 | 1541 | |
|
1536 | 1542 | void init_parameter_dump( void ) |
|
1537 | 1543 | { |
|
1538 | 1544 | /** This function initialize the parameter_dump_packet global variable with default values. |
|
1539 | 1545 | * |
|
1540 | 1546 | */ |
|
1541 | 1547 | |
|
1542 | 1548 | unsigned int k; |
|
1543 | 1549 | |
|
1544 | 1550 | parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1545 | 1551 | parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1546 | 1552 | parameter_dump_packet.reserved = CCSDS_RESERVED; |
|
1547 | 1553 | parameter_dump_packet.userApplication = CCSDS_USER_APP; |
|
1548 | 1554 | parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE); |
|
1549 | 1555 | parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP; |
|
1550 | 1556 | parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1551 | 1557 | parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1552 | 1558 | parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE); |
|
1553 | 1559 | parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP; |
|
1554 | 1560 | // DATA FIELD HEADER |
|
1555 | 1561 | parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; |
|
1556 | 1562 | parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP; |
|
1557 | 1563 | parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP; |
|
1558 | 1564 | parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
1559 | 1565 | parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
1560 | 1566 | parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
1561 | 1567 | parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
1562 | 1568 | parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
1563 | 1569 | parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
1564 | 1570 | parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
1565 | 1571 | parameter_dump_packet.sid = SID_PARAMETER_DUMP; |
|
1566 | 1572 | |
|
1567 | 1573 | //****************** |
|
1568 | 1574 | // COMMON PARAMETERS |
|
1569 | 1575 | parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0; |
|
1570 | 1576 | parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1; |
|
1571 | 1577 | |
|
1572 | 1578 | //****************** |
|
1573 | 1579 | // NORMAL PARAMETERS |
|
1574 | 1580 | parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE); |
|
1575 | 1581 | parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L ); |
|
1576 | 1582 | parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE); |
|
1577 | 1583 | parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P ); |
|
1578 | 1584 | parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE); |
|
1579 | 1585 | parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P ); |
|
1580 | 1586 | parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0; |
|
1581 | 1587 | parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1; |
|
1582 | 1588 | parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3; |
|
1583 | 1589 | |
|
1584 | 1590 | //***************** |
|
1585 | 1591 | // BURST PARAMETERS |
|
1586 | 1592 | parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0; |
|
1587 | 1593 | parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1; |
|
1588 | 1594 | |
|
1589 | 1595 | //**************** |
|
1590 | 1596 | // SBM1 PARAMETERS |
|
1591 | 1597 | parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period |
|
1592 | 1598 | parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1; |
|
1593 | 1599 | |
|
1594 | 1600 | //**************** |
|
1595 | 1601 | // SBM2 PARAMETERS |
|
1596 | 1602 | parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0; |
|
1597 | 1603 | parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1; |
|
1598 | 1604 | |
|
1599 | 1605 | //************ |
|
1600 | 1606 | // FBINS MASKS |
|
1601 | 1607 | for (k=0; k < BYTES_PER_MASKS_SET; k++) |
|
1602 | 1608 | { |
|
1603 | 1609 | parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F; |
|
1604 | 1610 | } |
|
1605 | 1611 | |
|
1606 | 1612 | // PAS FILTER PARAMETERS |
|
1607 | 1613 | parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR; |
|
1608 | 1614 | parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR; |
|
1609 | 1615 | parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS; |
|
1610 | 1616 | floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad ); |
|
1611 | 1617 | parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET; |
|
1612 | 1618 | floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift ); |
|
1613 | 1619 | floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f ); |
|
1614 | 1620 | |
|
1615 | 1621 | // RW1_K |
|
1616 | 1622 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1); |
|
1617 | 1623 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2); |
|
1618 | 1624 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3); |
|
1619 | 1625 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4); |
|
1620 | 1626 | // RW2_K |
|
1621 | 1627 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1); |
|
1622 | 1628 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2); |
|
1623 | 1629 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3); |
|
1624 | 1630 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4); |
|
1625 | 1631 | // RW3_K |
|
1626 | 1632 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1); |
|
1627 | 1633 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2); |
|
1628 | 1634 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3); |
|
1629 | 1635 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4); |
|
1630 | 1636 | // RW4_K |
|
1631 | 1637 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1); |
|
1632 | 1638 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2); |
|
1633 | 1639 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3); |
|
1634 | 1640 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4); |
|
1635 | 1641 | |
|
1636 | 1642 | // LFR_RW_MASK |
|
1637 | 1643 | for (k=0; k < BYTES_PER_MASKS_SET; k++) |
|
1638 | 1644 | { |
|
1639 | 1645 | parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F; |
|
1640 | 1646 | } |
|
1641 | 1647 | |
|
1642 | 1648 | // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks |
|
1643 | 1649 | merge_fbins_masks(); |
|
1644 | 1650 | } |
|
1645 | 1651 | |
|
1646 | 1652 | void init_kcoefficients_dump( void ) |
|
1647 | 1653 | { |
|
1648 | 1654 | init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 ); |
|
1649 | 1655 | init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 ); |
|
1650 | 1656 | |
|
1651 | 1657 | kcoefficient_node_1.previous = NULL; |
|
1652 | 1658 | kcoefficient_node_1.next = NULL; |
|
1653 | 1659 | kcoefficient_node_1.sid = TM_CODE_K_DUMP; |
|
1654 | 1660 | kcoefficient_node_1.coarseTime = INIT_CHAR; |
|
1655 | 1661 | kcoefficient_node_1.fineTime = INIT_CHAR; |
|
1656 | 1662 | kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1; |
|
1657 | 1663 | kcoefficient_node_1.status = INIT_CHAR; |
|
1658 | 1664 | |
|
1659 | 1665 | kcoefficient_node_2.previous = NULL; |
|
1660 | 1666 | kcoefficient_node_2.next = NULL; |
|
1661 | 1667 | kcoefficient_node_2.sid = TM_CODE_K_DUMP; |
|
1662 | 1668 | kcoefficient_node_2.coarseTime = INIT_CHAR; |
|
1663 | 1669 | kcoefficient_node_2.fineTime = INIT_CHAR; |
|
1664 | 1670 | kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2; |
|
1665 | 1671 | kcoefficient_node_2.status = INIT_CHAR; |
|
1666 | 1672 | } |
|
1667 | 1673 | |
|
1668 | 1674 | void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr ) |
|
1669 | 1675 | { |
|
1670 | 1676 | unsigned int k; |
|
1671 | 1677 | unsigned int packetLength; |
|
1672 | 1678 | |
|
1673 | 1679 | packetLength = |
|
1674 | 1680 | ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header |
|
1675 | 1681 | |
|
1676 | 1682 | kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1677 | 1683 | kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1678 | 1684 | kcoefficients_dump->reserved = CCSDS_RESERVED; |
|
1679 | 1685 | kcoefficients_dump->userApplication = CCSDS_USER_APP; |
|
1680 | 1686 | kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE); |
|
1681 | 1687 | kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP; |
|
1682 | 1688 | kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1683 | 1689 | kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1684 | 1690 | kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE); |
|
1685 | 1691 | kcoefficients_dump->packetLength[1] = (unsigned char) packetLength; |
|
1686 | 1692 | // DATA FIELD HEADER |
|
1687 | 1693 | kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; |
|
1688 | 1694 | kcoefficients_dump->serviceType = TM_TYPE_K_DUMP; |
|
1689 | 1695 | kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP; |
|
1690 | 1696 | kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND; |
|
1691 | 1697 | kcoefficients_dump->time[BYTE_0] = INIT_CHAR; |
|
1692 | 1698 | kcoefficients_dump->time[BYTE_1] = INIT_CHAR; |
|
1693 | 1699 | kcoefficients_dump->time[BYTE_2] = INIT_CHAR; |
|
1694 | 1700 | kcoefficients_dump->time[BYTE_3] = INIT_CHAR; |
|
1695 | 1701 | kcoefficients_dump->time[BYTE_4] = INIT_CHAR; |
|
1696 | 1702 | kcoefficients_dump->time[BYTE_5] = INIT_CHAR; |
|
1697 | 1703 | kcoefficients_dump->sid = SID_K_DUMP; |
|
1698 | 1704 | |
|
1699 | 1705 | kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT; |
|
1700 | 1706 | kcoefficients_dump->pkt_nr = PKTNR_1; |
|
1701 | 1707 | kcoefficients_dump->blk_nr = blk_nr; |
|
1702 | 1708 | |
|
1703 | 1709 | //****************** |
|
1704 | 1710 | // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR] |
|
1705 | 1711 | // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900) |
|
1706 | 1712 | for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++) |
|
1707 | 1713 | { |
|
1708 | 1714 | kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR; |
|
1709 | 1715 | } |
|
1710 | 1716 | } |
|
1711 | 1717 | |
|
1712 | 1718 | void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id ) |
|
1713 | 1719 | { |
|
1714 | 1720 | /** This function increment the packet sequence control parameter of a TC, depending on its destination ID. |
|
1715 | 1721 | * |
|
1716 | 1722 | * @param packet_sequence_control points to the packet sequence control which will be incremented |
|
1717 | 1723 | * @param destination_id is the destination ID of the TM, there is one counter by destination ID |
|
1718 | 1724 | * |
|
1719 | 1725 | * If the destination ID is not known, a dedicated counter is incremented. |
|
1720 | 1726 | * |
|
1721 | 1727 | */ |
|
1722 | 1728 | |
|
1723 | 1729 | unsigned short sequence_cnt; |
|
1724 | 1730 | unsigned short segmentation_grouping_flag; |
|
1725 | 1731 | unsigned short new_packet_sequence_control; |
|
1726 | 1732 | unsigned char i; |
|
1727 | 1733 | |
|
1728 | 1734 | switch (destination_id) |
|
1729 | 1735 | { |
|
1730 | 1736 | case SID_TC_GROUND: |
|
1731 | 1737 | i = GROUND; |
|
1732 | 1738 | break; |
|
1733 | 1739 | case SID_TC_MISSION_TIMELINE: |
|
1734 | 1740 | i = MISSION_TIMELINE; |
|
1735 | 1741 | break; |
|
1736 | 1742 | case SID_TC_TC_SEQUENCES: |
|
1737 | 1743 | i = TC_SEQUENCES; |
|
1738 | 1744 | break; |
|
1739 | 1745 | case SID_TC_RECOVERY_ACTION_CMD: |
|
1740 | 1746 | i = RECOVERY_ACTION_CMD; |
|
1741 | 1747 | break; |
|
1742 | 1748 | case SID_TC_BACKUP_MISSION_TIMELINE: |
|
1743 | 1749 | i = BACKUP_MISSION_TIMELINE; |
|
1744 | 1750 | break; |
|
1745 | 1751 | case SID_TC_DIRECT_CMD: |
|
1746 | 1752 | i = DIRECT_CMD; |
|
1747 | 1753 | break; |
|
1748 | 1754 | case SID_TC_SPARE_GRD_SRC1: |
|
1749 | 1755 | i = SPARE_GRD_SRC1; |
|
1750 | 1756 | break; |
|
1751 | 1757 | case SID_TC_SPARE_GRD_SRC2: |
|
1752 | 1758 | i = SPARE_GRD_SRC2; |
|
1753 | 1759 | break; |
|
1754 | 1760 | case SID_TC_OBCP: |
|
1755 | 1761 | i = OBCP; |
|
1756 | 1762 | break; |
|
1757 | 1763 | case SID_TC_SYSTEM_CONTROL: |
|
1758 | 1764 | i = SYSTEM_CONTROL; |
|
1759 | 1765 | break; |
|
1760 | 1766 | case SID_TC_AOCS: |
|
1761 | 1767 | i = AOCS; |
|
1762 | 1768 | break; |
|
1763 | 1769 | case SID_TC_RPW_INTERNAL: |
|
1764 | 1770 | i = RPW_INTERNAL; |
|
1765 | 1771 | break; |
|
1766 | 1772 | default: |
|
1767 | 1773 | i = GROUND; |
|
1768 | 1774 | break; |
|
1769 | 1775 | } |
|
1770 | 1776 | |
|
1771 | 1777 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; |
|
1772 | 1778 | sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK; |
|
1773 | 1779 | |
|
1774 | 1780 | new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ; |
|
1775 | 1781 | |
|
1776 | 1782 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); |
|
1777 | 1783 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1778 | 1784 | |
|
1779 | 1785 | // increment the sequence counter |
|
1780 | 1786 | if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX ) |
|
1781 | 1787 | { |
|
1782 | 1788 | sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1; |
|
1783 | 1789 | } |
|
1784 | 1790 | else |
|
1785 | 1791 | { |
|
1786 | 1792 | sequenceCounters_TM_DUMP[ i ] = 0; |
|
1787 | 1793 | } |
|
1788 | 1794 | } |
General Comments 0
You need to be logged in to leave comments.
Login now