@@ -1,107 +1,107 | |||
|
1 | 1 | cmake_minimum_required (VERSION 2.6) |
|
2 | 2 | project (fsw) |
|
3 | 3 | |
|
4 | 4 | include(sparc-rtems) |
|
5 | 5 | include(cppcheck) |
|
6 | 6 | |
|
7 | 7 | include_directories("../header" |
|
8 | 8 | "../header/lfr_common_headers" |
|
9 | 9 | "../header/processing" |
|
10 | 10 | "../LFR_basic-parameters" |
|
11 | 11 | "../src") |
|
12 | 12 | |
|
13 | 13 | set(SOURCES wf_handler.c |
|
14 | 14 | tc_handler.c |
|
15 | 15 | fsw_misc.c |
|
16 | 16 | fsw_init.c |
|
17 | 17 | fsw_globals.c |
|
18 | 18 | fsw_spacewire.c |
|
19 | 19 | tc_load_dump_parameters.c |
|
20 | 20 | tm_lfr_tc_exe.c |
|
21 | 21 | tc_acceptance.c |
|
22 | 22 | processing/fsw_processing.c |
|
23 | 23 | processing/avf0_prc0.c |
|
24 | 24 | processing/avf1_prc1.c |
|
25 | 25 | processing/avf2_prc2.c |
|
26 | 26 | lfr_cpu_usage_report.c |
|
27 | 27 | ${LFR_BP_SRC} |
|
28 | 28 | ../header/wf_handler.h |
|
29 | 29 | ../header/tc_handler.h |
|
30 | 30 | ../header/grlib_regs.h |
|
31 | 31 | ../header/fsw_misc.h |
|
32 | 32 | ../header/fsw_init.h |
|
33 | 33 | ../header/fsw_spacewire.h |
|
34 | 34 | ../header/tc_load_dump_parameters.h |
|
35 | 35 | ../header/tm_lfr_tc_exe.h |
|
36 | 36 | ../header/tc_acceptance.h |
|
37 | 37 | ../header/processing/fsw_processing.h |
|
38 | 38 | ../header/processing/avf0_prc0.h |
|
39 | 39 | ../header/processing/avf1_prc1.h |
|
40 | 40 | ../header/processing/avf2_prc2.h |
|
41 | 41 | ../header/fsw_params_wf_handler.h |
|
42 | 42 | ../header/lfr_cpu_usage_report.h |
|
43 | 43 | ../header/lfr_common_headers/ccsds_types.h |
|
44 | 44 | ../header/lfr_common_headers/fsw_params.h |
|
45 | 45 | ../header/lfr_common_headers/fsw_params_nb_bytes.h |
|
46 | 46 | ../header/lfr_common_headers/fsw_params_processing.h |
|
47 | 47 | ../header/lfr_common_headers/tm_byte_positions.h |
|
48 | 48 | ../LFR_basic-parameters/basic_parameters.h |
|
49 | 49 | ../LFR_basic-parameters/basic_parameters_params.h |
|
50 | 50 | ../header/GscMemoryLPP.hpp |
|
51 | 51 | ) |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | option(FSW_verbose "Enable verbose LFR" OFF) |
|
55 | 55 | option(FSW_boot_messages "Enable LFR boot messages" OFF) |
|
56 | 56 | option(FSW_debug_messages "Enable LFR debug messages" OFF) |
|
57 | 57 | option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF) |
|
58 | 58 | option(FSW_stack_report "Enable LFR stack report" OFF) |
|
59 | 59 | option(FSW_vhdl_dev "?" OFF) |
|
60 | 60 | option(FSW_lpp_dpu_destid "Set to debug at LPP" ON) |
|
61 | 61 | option(FSW_debug_watchdog "Enable debug watchdog" OFF) |
|
62 | 62 | option(FSW_debug_tch "?" OFF) |
|
63 | 63 | |
|
64 | 64 | set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) |
|
65 | 65 | set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) |
|
66 | 66 | set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) |
|
67 |
set(SW_VERSION_N4 "1 |
|
|
67 | set(SW_VERSION_N4 "12" CACHE STRING "Choose N4 FSW Version." FORCE) | |
|
68 | 68 | |
|
69 | 69 | if(FSW_verbose) |
|
70 | 70 | add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) |
|
71 | 71 | endif() |
|
72 | 72 | if(FSW_boot_messages) |
|
73 | 73 | add_definitions(-DBOOT_MESSAGES) |
|
74 | 74 | endif() |
|
75 | 75 | if(FSW_debug_messages) |
|
76 | 76 | add_definitions(-DDEBUG_MESSAGES) |
|
77 | 77 | endif() |
|
78 | 78 | if(FSW_cpu_usage_report) |
|
79 | 79 | add_definitions(-DPRINT_TASK_STATISTICS) |
|
80 | 80 | endif() |
|
81 | 81 | if(FSW_stack_report) |
|
82 | 82 | add_definitions(-DPRINT_STACK_REPORT) |
|
83 | 83 | endif() |
|
84 | 84 | if(FSW_vhdl_dev) |
|
85 | 85 | add_definitions(-DVHDL_DEV) |
|
86 | 86 | endif() |
|
87 | 87 | if(FSW_lpp_dpu_destid) |
|
88 | 88 | add_definitions(-DLPP_DPU_DESTID) |
|
89 | 89 | endif() |
|
90 | 90 | if(FSW_debug_watchdog) |
|
91 | 91 | add_definitions(-DDEBUG_WATCHDOG) |
|
92 | 92 | endif() |
|
93 | 93 | if(FSW_debug_tch) |
|
94 | 94 | add_definitions(-DDEBUG_TCH) |
|
95 | 95 | endif() |
|
96 | 96 | |
|
97 | 97 | add_definitions(-DMSB_FIRST_TCH) |
|
98 | 98 | |
|
99 | 99 | add_definitions(-DSWVERSION=-1-0) |
|
100 | 100 | add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1}) |
|
101 | 101 | add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2}) |
|
102 | 102 | add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3}) |
|
103 | 103 | add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4}) |
|
104 | 104 | |
|
105 | 105 | add_executable(fsw ${SOURCES}) |
|
106 | 106 | add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) |
|
107 | 107 |
@@ -1,1036 +1,1036 | |||
|
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 | // SEND PACKET |
|
335 | 335 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
336 | 336 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
337 | 337 | if (status != RTEMS_SUCCESSFUL) { |
|
338 | 338 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
339 | 339 | } |
|
340 | 340 | } |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | PRINTF("in HOUS *** deleting task\n") |
|
344 | 344 | |
|
345 | 345 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
346 | 346 | |
|
347 | 347 | return; |
|
348 | 348 | } |
|
349 | 349 | |
|
350 | 350 | int filter( int x, filter_ctx* ctx ) |
|
351 | 351 | { |
|
352 | 352 | static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} }; |
|
353 | 353 | static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} }; |
|
354 | 354 | static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2}; |
|
355 | 355 | static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2}; |
|
356 | 356 | |
|
357 | 357 | int_fast32_t W; |
|
358 | 358 | int i; |
|
359 | 359 | |
|
360 | 360 | W = INIT_INT; |
|
361 | 361 | i = INIT_INT; |
|
362 | 362 | |
|
363 | 363 | //Direct-Form-II |
|
364 | 364 | for ( i = 0; i < NB_COEFFS; i++ ) |
|
365 | 365 | { |
|
366 | 366 | x = x << a_gain[i]; |
|
367 | 367 | W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] ) |
|
368 | 368 | - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i]; |
|
369 | 369 | x = ( b[i][COEFF0] * W ) |
|
370 | 370 | + ( b[i][COEFF1] * ctx->W[i][COEFF0] ) |
|
371 | 371 | + ( b[i][COEFF2] * ctx->W[i][COEFF1] ); |
|
372 | 372 | x = x >> b_gain[i]; |
|
373 | 373 | ctx->W[i][1] = ctx->W[i][0]; |
|
374 | 374 | ctx->W[i][0] = W; |
|
375 | 375 | } |
|
376 | 376 | return x; |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | rtems_task avgv_task(rtems_task_argument argument) |
|
380 | 380 | { |
|
381 | 381 | #define MOVING_AVERAGE 16 |
|
382 | 382 | rtems_status_code status; |
|
383 | 383 | static int32_t v[MOVING_AVERAGE] = {0}; |
|
384 | 384 | static int32_t e1[MOVING_AVERAGE] = {0}; |
|
385 | 385 | static int32_t e2[MOVING_AVERAGE] = {0}; |
|
386 | 386 | static int old_v = 0; |
|
387 | 387 | static int old_e1 = 0; |
|
388 | 388 | static int old_e2 = 0; |
|
389 | 389 | int32_t current_v; |
|
390 | 390 | int32_t current_e1; |
|
391 | 391 | int32_t current_e2; |
|
392 | 392 | int32_t average_v; |
|
393 | 393 | int32_t average_e1; |
|
394 | 394 | int32_t average_e2; |
|
395 | 395 | int32_t newValue_v; |
|
396 | 396 | int32_t newValue_e1; |
|
397 | 397 | int32_t newValue_e2; |
|
398 | 398 | unsigned char k; |
|
399 | 399 | unsigned char indexOfOldValue; |
|
400 | 400 | |
|
401 | 401 | static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
402 | 402 | static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
403 | 403 | static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
404 | 404 | |
|
405 | 405 | BOOT_PRINTF("in AVGV ***\n"); |
|
406 | 406 | |
|
407 | 407 | if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) { |
|
408 | 408 | status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id ); |
|
409 | 409 | if( status != RTEMS_SUCCESSFUL ) { |
|
410 | 410 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
411 | 411 | } |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | status = rtems_rate_monotonic_cancel(AVGV_id); |
|
415 | 415 | if( status != RTEMS_SUCCESSFUL ) { |
|
416 | 416 | PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status ); |
|
417 | 417 | } |
|
418 | 418 | else { |
|
419 | 419 | DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n"); |
|
420 | 420 | } |
|
421 | 421 | |
|
422 | 422 | // initialize values |
|
423 | 423 | indexOfOldValue = MOVING_AVERAGE - 1; |
|
424 | 424 | current_v = 0; |
|
425 | 425 | current_e1 = 0; |
|
426 | 426 | current_e2 = 0; |
|
427 | 427 | average_v = 0; |
|
428 | 428 | average_e1 = 0; |
|
429 | 429 | average_e2 = 0; |
|
430 | 430 | newValue_v = 0; |
|
431 | 431 | newValue_e1 = 0; |
|
432 | 432 | newValue_e2 = 0; |
|
433 | 433 | |
|
434 | 434 | k = INIT_CHAR; |
|
435 | 435 | |
|
436 | 436 | while(1) |
|
437 | 437 | { // launch the rate monotonic task |
|
438 | 438 | status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD ); |
|
439 | 439 | if ( status != RTEMS_SUCCESSFUL ) |
|
440 | 440 | { |
|
441 | 441 | PRINTF1( "in AVGV *** ERR period: %d\n", status); |
|
442 | 442 | } |
|
443 | 443 | else |
|
444 | 444 | { |
|
445 | 445 | current_v = waveform_picker_regs->v; |
|
446 | 446 | current_e1 = waveform_picker_regs->e1; |
|
447 | 447 | current_e2 = waveform_picker_regs->e2; |
|
448 | 448 | if ( (current_v != old_v) |
|
449 | 449 | || (current_e1 != old_e1) |
|
450 | 450 | || (current_e2 != old_e2)) |
|
451 | 451 | { |
|
452 | 452 | average_v = filter( current_v, &ctx_v ); |
|
453 | 453 | average_e1 = filter( current_e1, &ctx_e1 ); |
|
454 | 454 | average_e2 = filter( current_e2, &ctx_e2 ); |
|
455 | 455 | |
|
456 | 456 | //update int16 values |
|
457 |
hk_lfr_sc_v_f3_as_int16 = (int16_t) |
|
|
458 |
hk_lfr_sc_e1_f3_as_int16 = (int16_t) |
|
|
459 |
hk_lfr_sc_e2_f3_as_int16 = (int16_t) |
|
|
457 | hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v; | |
|
458 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1; | |
|
459 | hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2; | |
|
460 | 460 | } |
|
461 | 461 | old_v = current_v; |
|
462 | 462 | old_e1 = current_e1; |
|
463 | 463 | old_e2 = current_e2; |
|
464 | 464 | } |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | PRINTF("in AVGV *** deleting task\n"); |
|
468 | 468 | |
|
469 | 469 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
470 | 470 | |
|
471 | 471 | return; |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | rtems_task dumb_task( rtems_task_argument unused ) |
|
475 | 475 | { |
|
476 | 476 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
477 | 477 | * |
|
478 | 478 | * @param unused is the starting argument of the RTEMS task |
|
479 | 479 | * |
|
480 | 480 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
481 | 481 | * |
|
482 | 482 | */ |
|
483 | 483 | |
|
484 | 484 | unsigned int i; |
|
485 | 485 | unsigned int intEventOut; |
|
486 | 486 | unsigned int coarse_time = 0; |
|
487 | 487 | unsigned int fine_time = 0; |
|
488 | 488 | rtems_event_set event_out; |
|
489 | 489 | |
|
490 | 490 | event_out = EVENT_SETS_NONE_PENDING; |
|
491 | 491 | |
|
492 | 492 | BOOT_PRINTF("in DUMB *** \n") |
|
493 | 493 | |
|
494 | 494 | while(1){ |
|
495 | 495 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
496 | 496 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
497 | 497 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13 |
|
498 | 498 | | RTEMS_EVENT_14, |
|
499 | 499 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
500 | 500 | intEventOut = (unsigned int) event_out; |
|
501 | 501 | for ( i=0; i<NB_RTEMS_EVENTS; i++) |
|
502 | 502 | { |
|
503 | 503 | if ( ((intEventOut >> i) & 1) != 0) |
|
504 | 504 | { |
|
505 | 505 | coarse_time = time_management_regs->coarse_time; |
|
506 | 506 | fine_time = time_management_regs->fine_time; |
|
507 | 507 | if (i==EVENT_12) |
|
508 | 508 | { |
|
509 | 509 | PRINTF1("%s\n", DUMB_MESSAGE_12) |
|
510 | 510 | } |
|
511 | 511 | if (i==EVENT_13) |
|
512 | 512 | { |
|
513 | 513 | PRINTF1("%s\n", DUMB_MESSAGE_13) |
|
514 | 514 | } |
|
515 | 515 | if (i==EVENT_14) |
|
516 | 516 | { |
|
517 | 517 | PRINTF1("%s\n", DUMB_MESSAGE_1) |
|
518 | 518 | } |
|
519 | 519 | } |
|
520 | 520 | } |
|
521 | 521 | } |
|
522 | 522 | } |
|
523 | 523 | |
|
524 | 524 | //***************************** |
|
525 | 525 | // init housekeeping parameters |
|
526 | 526 | |
|
527 | 527 | void init_housekeeping_parameters( void ) |
|
528 | 528 | { |
|
529 | 529 | /** This function initialize the housekeeping_packet global variable with default values. |
|
530 | 530 | * |
|
531 | 531 | */ |
|
532 | 532 | |
|
533 | 533 | unsigned int i = 0; |
|
534 | 534 | unsigned char *parameters; |
|
535 | 535 | unsigned char sizeOfHK; |
|
536 | 536 | |
|
537 | 537 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
538 | 538 | |
|
539 | 539 | parameters = (unsigned char*) &housekeeping_packet; |
|
540 | 540 | |
|
541 | 541 | for(i = 0; i< sizeOfHK; i++) |
|
542 | 542 | { |
|
543 | 543 | parameters[i] = INIT_CHAR; |
|
544 | 544 | } |
|
545 | 545 | |
|
546 | 546 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
547 | 547 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
548 | 548 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
549 | 549 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
550 | 550 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
551 | 551 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
552 | 552 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
553 | 553 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
554 | 554 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
555 | 555 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
556 | 556 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
557 | 557 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
558 | 558 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
559 | 559 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
560 | 560 | housekeeping_packet.sid = SID_HK; |
|
561 | 561 | |
|
562 | 562 | // init status word |
|
563 | 563 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
564 | 564 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
565 | 565 | // init software version |
|
566 | 566 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
567 | 567 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
568 | 568 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
569 | 569 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
570 | 570 | // init fpga version |
|
571 | 571 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
572 | 572 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
573 | 573 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
574 | 574 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
575 | 575 | |
|
576 | 576 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
577 | 577 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
578 | 578 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
579 | 579 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
580 | 580 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
581 | 581 | } |
|
582 | 582 | |
|
583 | 583 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
584 | 584 | { |
|
585 | 585 | /** This function increment the sequence counter passes in argument. |
|
586 | 586 | * |
|
587 | 587 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
588 | 588 | * |
|
589 | 589 | */ |
|
590 | 590 | |
|
591 | 591 | unsigned short segmentation_grouping_flag; |
|
592 | 592 | unsigned short sequence_cnt; |
|
593 | 593 | |
|
594 | 594 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 |
|
595 | 595 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] |
|
596 | 596 | |
|
597 | 597 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
598 | 598 | { |
|
599 | 599 | sequence_cnt = sequence_cnt + 1; |
|
600 | 600 | } |
|
601 | 601 | else |
|
602 | 602 | { |
|
603 | 603 | sequence_cnt = 0; |
|
604 | 604 | } |
|
605 | 605 | |
|
606 | 606 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
607 | 607 | } |
|
608 | 608 | |
|
609 | 609 | void getTime( unsigned char *time) |
|
610 | 610 | { |
|
611 | 611 | /** This function write the current local time in the time buffer passed in argument. |
|
612 | 612 | * |
|
613 | 613 | */ |
|
614 | 614 | |
|
615 | 615 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); |
|
616 | 616 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); |
|
617 | 617 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); |
|
618 | 618 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
619 | 619 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); |
|
620 | 620 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
621 | 621 | } |
|
622 | 622 | |
|
623 | 623 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
624 | 624 | { |
|
625 | 625 | /** This function write the current local time in the time buffer passed in argument. |
|
626 | 626 | * |
|
627 | 627 | */ |
|
628 | 628 | unsigned long long int time; |
|
629 | 629 | |
|
630 | 630 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) |
|
631 | 631 | + time_management_regs->fine_time; |
|
632 | 632 | |
|
633 | 633 | return time; |
|
634 | 634 | } |
|
635 | 635 | |
|
636 | 636 | void send_dumb_hk( void ) |
|
637 | 637 | { |
|
638 | 638 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
639 | 639 | unsigned char *parameters; |
|
640 | 640 | unsigned int i; |
|
641 | 641 | rtems_id queue_id; |
|
642 | 642 | |
|
643 | 643 | queue_id = RTEMS_ID_NONE; |
|
644 | 644 | |
|
645 | 645 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
646 | 646 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
647 | 647 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
648 | 648 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
649 | 649 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
650 | 650 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
651 | 651 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
652 | 652 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
653 | 653 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
654 | 654 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
655 | 655 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
656 | 656 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
657 | 657 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
658 | 658 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
659 | 659 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
660 | 660 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
661 | 661 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
662 | 662 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
663 | 663 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
664 | 664 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
665 | 665 | dummy_hk_packet.sid = SID_HK; |
|
666 | 666 | |
|
667 | 667 | // init status word |
|
668 | 668 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; |
|
669 | 669 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; |
|
670 | 670 | // init software version |
|
671 | 671 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
672 | 672 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
673 | 673 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
674 | 674 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
675 | 675 | // init fpga version |
|
676 | 676 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); |
|
677 | 677 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
678 | 678 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
679 | 679 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
680 | 680 | |
|
681 | 681 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
682 | 682 | |
|
683 | 683 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) |
|
684 | 684 | { |
|
685 | 685 | parameters[i] = INT8_ALL_F; |
|
686 | 686 | } |
|
687 | 687 | |
|
688 | 688 | get_message_queue_id_send( &queue_id ); |
|
689 | 689 | |
|
690 | 690 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
691 | 691 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | void get_temperatures( unsigned char *temperatures ) |
|
695 | 695 | { |
|
696 | 696 | unsigned char* temp_scm_ptr; |
|
697 | 697 | unsigned char* temp_pcb_ptr; |
|
698 | 698 | unsigned char* temp_fpga_ptr; |
|
699 | 699 | |
|
700 | 700 | // SEL1 SEL0 |
|
701 | 701 | // 0 0 => PCB |
|
702 | 702 | // 0 1 => FPGA |
|
703 | 703 | // 1 0 => SCM |
|
704 | 704 | |
|
705 | 705 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
706 | 706 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
707 | 707 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
708 | 708 | |
|
709 | 709 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; |
|
710 | 710 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; |
|
711 | 711 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; |
|
712 | 712 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; |
|
713 | 713 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; |
|
714 | 714 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; |
|
715 | 715 | } |
|
716 | 716 | |
|
717 | 717 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
718 | 718 | { |
|
719 | 719 | unsigned char* v_ptr; |
|
720 | 720 | unsigned char* e1_ptr; |
|
721 | 721 | unsigned char* e2_ptr; |
|
722 | 722 | |
|
723 | 723 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; |
|
724 | 724 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; |
|
725 | 725 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; |
|
726 | 726 | |
|
727 | 727 | spacecraft_potential[BYTE_0] = v_ptr[0]; |
|
728 | 728 | spacecraft_potential[BYTE_1] = v_ptr[1]; |
|
729 | 729 | spacecraft_potential[BYTE_2] = e1_ptr[0]; |
|
730 | 730 | spacecraft_potential[BYTE_3] = e1_ptr[1]; |
|
731 | 731 | spacecraft_potential[BYTE_4] = e2_ptr[0]; |
|
732 | 732 | spacecraft_potential[BYTE_5] = e2_ptr[1]; |
|
733 | 733 | } |
|
734 | 734 | |
|
735 | 735 | void get_cpu_load( unsigned char *resource_statistics ) |
|
736 | 736 | { |
|
737 | 737 | unsigned char cpu_load; |
|
738 | 738 | |
|
739 | 739 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
740 | 740 | |
|
741 | 741 | // HK_LFR_CPU_LOAD |
|
742 | 742 | resource_statistics[0] = cpu_load; |
|
743 | 743 | |
|
744 | 744 | // HK_LFR_CPU_LOAD_MAX |
|
745 | 745 | if (cpu_load > resource_statistics[1]) |
|
746 | 746 | { |
|
747 | 747 | resource_statistics[1] = cpu_load; |
|
748 | 748 | } |
|
749 | 749 | |
|
750 | 750 | // CPU_LOAD_AVE |
|
751 | 751 | resource_statistics[BYTE_2] = 0; |
|
752 | 752 | |
|
753 | 753 | #ifndef PRINT_TASK_STATISTICS |
|
754 | 754 | rtems_cpu_usage_reset(); |
|
755 | 755 | #endif |
|
756 | 756 | |
|
757 | 757 | } |
|
758 | 758 | |
|
759 | 759 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
760 | 760 | { |
|
761 | 761 | if (state == true) |
|
762 | 762 | { |
|
763 | 763 | housekeeping_packet.lfr_status_word[1] = |
|
764 | 764 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] |
|
765 | 765 | } |
|
766 | 766 | else |
|
767 | 767 | { |
|
768 | 768 | housekeeping_packet.lfr_status_word[1] = |
|
769 | 769 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] |
|
770 | 770 | } |
|
771 | 771 | } |
|
772 | 772 | |
|
773 | 773 | void set_sy_lfr_pas_filter_enabled( bool state ) |
|
774 | 774 | { |
|
775 | 775 | if (state == true) |
|
776 | 776 | { |
|
777 | 777 | housekeeping_packet.lfr_status_word[1] = |
|
778 | 778 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000] |
|
779 | 779 | } |
|
780 | 780 | else |
|
781 | 781 | { |
|
782 | 782 | housekeeping_packet.lfr_status_word[1] = |
|
783 | 783 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111] |
|
784 | 784 | } |
|
785 | 785 | } |
|
786 | 786 | |
|
787 | 787 | void set_sy_lfr_watchdog_enabled( bool state ) |
|
788 | 788 | { |
|
789 | 789 | if (state == true) |
|
790 | 790 | { |
|
791 | 791 | housekeeping_packet.lfr_status_word[1] = |
|
792 | 792 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] |
|
793 | 793 | } |
|
794 | 794 | else |
|
795 | 795 | { |
|
796 | 796 | housekeeping_packet.lfr_status_word[1] = |
|
797 | 797 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] |
|
798 | 798 | } |
|
799 | 799 | } |
|
800 | 800 | |
|
801 | 801 | void set_hk_lfr_calib_enable( bool state ) |
|
802 | 802 | { |
|
803 | 803 | if (state == true) |
|
804 | 804 | { |
|
805 | 805 | housekeeping_packet.lfr_status_word[1] = |
|
806 | 806 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] |
|
807 | 807 | } |
|
808 | 808 | else |
|
809 | 809 | { |
|
810 | 810 | housekeeping_packet.lfr_status_word[1] = |
|
811 | 811 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] |
|
812 | 812 | } |
|
813 | 813 | } |
|
814 | 814 | |
|
815 | 815 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
816 | 816 | { |
|
817 | 817 | housekeeping_packet.lfr_status_word[1] = |
|
818 | 818 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] |
|
819 | 819 | |
|
820 | 820 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
821 | 821 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] |
|
822 | 822 | |
|
823 | 823 | } |
|
824 | 824 | |
|
825 | 825 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) |
|
826 | 826 | { |
|
827 | 827 | int delta; |
|
828 | 828 | |
|
829 | 829 | delta = 0; |
|
830 | 830 | |
|
831 | 831 | if (newValue >= oldValue) |
|
832 | 832 | { |
|
833 | 833 | delta = newValue - oldValue; |
|
834 | 834 | } |
|
835 | 835 | else |
|
836 | 836 | { |
|
837 | 837 | delta = (CONST_256 - oldValue) + newValue; |
|
838 | 838 | } |
|
839 | 839 | |
|
840 | 840 | *counter = *counter + delta; |
|
841 | 841 | } |
|
842 | 842 | |
|
843 | 843 | void hk_lfr_le_update( void ) |
|
844 | 844 | { |
|
845 | 845 | static hk_lfr_le_t old_hk_lfr_le = {0}; |
|
846 | 846 | hk_lfr_le_t new_hk_lfr_le; |
|
847 | 847 | unsigned int counter; |
|
848 | 848 | |
|
849 | 849 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1]; |
|
850 | 850 | |
|
851 | 851 | // DPU |
|
852 | 852 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; |
|
853 | 853 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; |
|
854 | 854 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; |
|
855 | 855 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; |
|
856 | 856 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; |
|
857 | 857 | // TIMECODE |
|
858 | 858 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; |
|
859 | 859 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; |
|
860 | 860 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; |
|
861 | 861 | // TIME |
|
862 | 862 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; |
|
863 | 863 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; |
|
864 | 864 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; |
|
865 | 865 | //AHB |
|
866 | 866 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; |
|
867 | 867 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
868 | 868 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
869 | 869 | |
|
870 | 870 | // update the le counter |
|
871 | 871 | // DPU |
|
872 | 872 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); |
|
873 | 873 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); |
|
874 | 874 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); |
|
875 | 875 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); |
|
876 | 876 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); |
|
877 | 877 | // TIMECODE |
|
878 | 878 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); |
|
879 | 879 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); |
|
880 | 880 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); |
|
881 | 881 | // TIME |
|
882 | 882 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); |
|
883 | 883 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); |
|
884 | 884 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); |
|
885 | 885 | // AHB |
|
886 | 886 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); |
|
887 | 887 | |
|
888 | 888 | // DPU |
|
889 | 889 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; |
|
890 | 890 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; |
|
891 | 891 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; |
|
892 | 892 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; |
|
893 | 893 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; |
|
894 | 894 | // TIMECODE |
|
895 | 895 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; |
|
896 | 896 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; |
|
897 | 897 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; |
|
898 | 898 | // TIME |
|
899 | 899 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; |
|
900 | 900 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; |
|
901 | 901 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; |
|
902 | 902 | //AHB |
|
903 | 903 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; |
|
904 | 904 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
905 | 905 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
906 | 906 | |
|
907 | 907 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
908 | 908 | // LE |
|
909 | 909 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
910 | 910 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
911 | 911 | } |
|
912 | 912 | |
|
913 | 913 | void hk_lfr_me_update( void ) |
|
914 | 914 | { |
|
915 | 915 | static hk_lfr_me_t old_hk_lfr_me = {0}; |
|
916 | 916 | hk_lfr_me_t new_hk_lfr_me; |
|
917 | 917 | unsigned int counter; |
|
918 | 918 | |
|
919 | 919 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1]; |
|
920 | 920 | |
|
921 | 921 | // get the current values |
|
922 | 922 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; |
|
923 | 923 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; |
|
924 | 924 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; |
|
925 | 925 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; |
|
926 | 926 | |
|
927 | 927 | // update the me counter |
|
928 | 928 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); |
|
929 | 929 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); |
|
930 | 930 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); |
|
931 | 931 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); |
|
932 | 932 | |
|
933 | 933 | // store the counters for the next time |
|
934 | 934 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; |
|
935 | 935 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; |
|
936 | 936 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; |
|
937 | 937 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; |
|
938 | 938 | |
|
939 | 939 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
940 | 940 | // ME |
|
941 | 941 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
942 | 942 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
943 | 943 | } |
|
944 | 944 | |
|
945 | 945 | void hk_lfr_le_me_he_update() |
|
946 | 946 | { |
|
947 | 947 | |
|
948 | 948 | unsigned int hk_lfr_he_cnt; |
|
949 | 949 | |
|
950 | 950 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; |
|
951 | 951 | |
|
952 | 952 | //update the low severity error counter |
|
953 | 953 | hk_lfr_le_update( ); |
|
954 | 954 | |
|
955 | 955 | //update the medium severity error counter |
|
956 | 956 | hk_lfr_me_update(); |
|
957 | 957 | |
|
958 | 958 | //update the high severity error counter |
|
959 | 959 | hk_lfr_he_cnt = 0; |
|
960 | 960 | |
|
961 | 961 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
962 | 962 | // HE |
|
963 | 963 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
964 | 964 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); |
|
965 | 965 | |
|
966 | 966 | } |
|
967 | 967 | |
|
968 | 968 | void set_hk_lfr_time_not_synchro() |
|
969 | 969 | { |
|
970 | 970 | static unsigned char synchroLost = 1; |
|
971 | 971 | int synchronizationBit; |
|
972 | 972 | |
|
973 | 973 | // get the synchronization bit |
|
974 | 974 | synchronizationBit = |
|
975 | 975 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 |
|
976 | 976 | |
|
977 | 977 | switch (synchronizationBit) |
|
978 | 978 | { |
|
979 | 979 | case 0: |
|
980 | 980 | if (synchroLost == 1) |
|
981 | 981 | { |
|
982 | 982 | synchroLost = 0; |
|
983 | 983 | } |
|
984 | 984 | break; |
|
985 | 985 | case 1: |
|
986 | 986 | if (synchroLost == 0 ) |
|
987 | 987 | { |
|
988 | 988 | synchroLost = 1; |
|
989 | 989 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); |
|
990 | 990 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); |
|
991 | 991 | } |
|
992 | 992 | break; |
|
993 | 993 | default: |
|
994 | 994 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); |
|
995 | 995 | break; |
|
996 | 996 | } |
|
997 | 997 | |
|
998 | 998 | } |
|
999 | 999 | |
|
1000 | 1000 | void set_hk_lfr_ahb_correctable() // CRITICITY L |
|
1001 | 1001 | { |
|
1002 | 1002 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided |
|
1003 | 1003 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the |
|
1004 | 1004 | * detected errors in the cache, in the integer unit and in the floating point unit. |
|
1005 | 1005 | * |
|
1006 | 1006 | * @param void |
|
1007 | 1007 | * |
|
1008 | 1008 | * @return void |
|
1009 | 1009 | * |
|
1010 | 1010 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. |
|
1011 | 1011 | * |
|
1012 | 1012 | */ |
|
1013 | 1013 | |
|
1014 | 1014 | unsigned int ahb_correctable; |
|
1015 | 1015 | unsigned int instructionErrorCounter; |
|
1016 | 1016 | unsigned int dataErrorCounter; |
|
1017 | 1017 | unsigned int fprfErrorCounter; |
|
1018 | 1018 | unsigned int iurfErrorCounter; |
|
1019 | 1019 | |
|
1020 | 1020 | instructionErrorCounter = 0; |
|
1021 | 1021 | dataErrorCounter = 0; |
|
1022 | 1022 | fprfErrorCounter = 0; |
|
1023 | 1023 | iurfErrorCounter = 0; |
|
1024 | 1024 | |
|
1025 | 1025 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); |
|
1026 | 1026 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); |
|
1027 | 1027 | |
|
1028 | 1028 | ahb_correctable = instructionErrorCounter |
|
1029 | 1029 | + dataErrorCounter |
|
1030 | 1030 | + fprfErrorCounter |
|
1031 | 1031 | + iurfErrorCounter |
|
1032 | 1032 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
1033 | 1033 | |
|
1034 | 1034 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] |
|
1035 | 1035 | |
|
1036 | 1036 | } |
@@ -1,1343 +1,1343 | |||
|
1 | 1 | /** Functions and tasks related to waveform packet generation. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle waveforms, in snapshot or continuous format.\n |
|
7 | 7 | * |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #include "wf_handler.h" |
|
11 | 11 | |
|
12 | 12 | //*************** |
|
13 | 13 | // waveform rings |
|
14 | 14 | // F0 |
|
15 | 15 | ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0}; |
|
16 | 16 | ring_node *current_ring_node_f0 = NULL; |
|
17 | 17 | ring_node *ring_node_to_send_swf_f0 = NULL; |
|
18 | 18 | // F1 |
|
19 | 19 | ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0}; |
|
20 | 20 | ring_node *current_ring_node_f1 = NULL; |
|
21 | 21 | ring_node *ring_node_to_send_swf_f1 = NULL; |
|
22 | 22 | ring_node *ring_node_to_send_cwf_f1 = NULL; |
|
23 | 23 | // F2 |
|
24 | 24 | ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0}; |
|
25 | 25 | ring_node *current_ring_node_f2 = NULL; |
|
26 | 26 | ring_node *ring_node_to_send_swf_f2 = NULL; |
|
27 | 27 | ring_node *ring_node_to_send_cwf_f2 = NULL; |
|
28 | 28 | // F3 |
|
29 | 29 | ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0}; |
|
30 | 30 | ring_node *current_ring_node_f3 = NULL; |
|
31 | 31 | ring_node *ring_node_to_send_cwf_f3 = NULL; |
|
32 | 32 | char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0}; |
|
33 | 33 | |
|
34 | 34 | bool extractSWF1 = false; |
|
35 | 35 | bool extractSWF2 = false; |
|
36 | 36 | bool swf0_ready_flag_f1 = false; |
|
37 | 37 | bool swf0_ready_flag_f2 = false; |
|
38 | 38 | bool swf1_ready = false; |
|
39 | 39 | bool swf2_ready = false; |
|
40 | 40 | |
|
41 | 41 | int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; |
|
42 | 42 | int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; |
|
43 | 43 | ring_node ring_node_swf1_extracted = {0}; |
|
44 | 44 | ring_node ring_node_swf2_extracted = {0}; |
|
45 | 45 | |
|
46 | 46 | typedef enum resynchro_state_t |
|
47 | 47 | { |
|
48 | 48 | MEASURE, |
|
49 | 49 | CORRECTION |
|
50 | 50 | } resynchro_state; |
|
51 | 51 | |
|
52 | 52 | //********************* |
|
53 | 53 | // Interrupt SubRoutine |
|
54 | 54 | |
|
55 | 55 | ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel) |
|
56 | 56 | { |
|
57 | 57 | ring_node *node; |
|
58 | 58 | |
|
59 | 59 | node = NULL; |
|
60 | 60 | switch ( frequencyChannel ) { |
|
61 | 61 | case CHANNELF1: |
|
62 | 62 | node = ring_node_to_send_cwf_f1; |
|
63 | 63 | break; |
|
64 | 64 | case CHANNELF2: |
|
65 | 65 | node = ring_node_to_send_cwf_f2; |
|
66 | 66 | break; |
|
67 | 67 | case CHANNELF3: |
|
68 | 68 | node = ring_node_to_send_cwf_f3; |
|
69 | 69 | break; |
|
70 | 70 | default: |
|
71 | 71 | break; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | return node; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel) |
|
78 | 78 | { |
|
79 | 79 | ring_node *node; |
|
80 | 80 | |
|
81 | 81 | node = NULL; |
|
82 | 82 | switch ( frequencyChannel ) { |
|
83 | 83 | case CHANNELF0: |
|
84 | 84 | node = ring_node_to_send_swf_f0; |
|
85 | 85 | break; |
|
86 | 86 | case CHANNELF1: |
|
87 | 87 | node = ring_node_to_send_swf_f1; |
|
88 | 88 | break; |
|
89 | 89 | case CHANNELF2: |
|
90 | 90 | node = ring_node_to_send_swf_f2; |
|
91 | 91 | break; |
|
92 | 92 | default: |
|
93 | 93 | break; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | return node; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void reset_extractSWF( void ) |
|
100 | 100 | { |
|
101 | 101 | extractSWF1 = false; |
|
102 | 102 | extractSWF2 = false; |
|
103 | 103 | swf0_ready_flag_f1 = false; |
|
104 | 104 | swf0_ready_flag_f2 = false; |
|
105 | 105 | swf1_ready = false; |
|
106 | 106 | swf2_ready = false; |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | inline void waveforms_isr_f3( void ) |
|
110 | 110 | { |
|
111 | 111 | rtems_status_code spare_status; |
|
112 | 112 | |
|
113 | 113 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet |
|
114 | 114 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) |
|
115 | 115 | { // in modes other than STANDBY and BURST, send the CWF_F3 data |
|
116 | 116 | //*** |
|
117 | 117 | // F3 |
|
118 | 118 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits |
|
119 | 119 | ring_node_to_send_cwf_f3 = current_ring_node_f3->previous; |
|
120 | 120 | current_ring_node_f3 = current_ring_node_f3->next; |
|
121 | 121 | if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full |
|
122 | 122 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time; |
|
123 | 123 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time; |
|
124 | 124 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address; |
|
125 | 125 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000] |
|
126 | 126 | } |
|
127 | 127 | else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full |
|
128 | 128 | ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time; |
|
129 | 129 | ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time; |
|
130 | 130 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; |
|
131 | 131 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000] |
|
132 | 132 | } |
|
133 | 133 | if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
134 | 134 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | inline void waveforms_isr_burst( void ) |
|
141 | 141 | { |
|
142 | 142 | unsigned char status; |
|
143 | 143 | rtems_status_code spare_status; |
|
144 | 144 | |
|
145 | 145 | status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2 |
|
146 | 146 | |
|
147 | 147 | switch(status) |
|
148 | 148 | { |
|
149 | 149 | case BIT_WFP_BUFFER_0: |
|
150 | 150 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
151 | 151 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
152 | 152 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
153 | 153 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
154 | 154 | current_ring_node_f2 = current_ring_node_f2->next; |
|
155 | 155 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
156 | 156 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
157 | 157 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
158 | 158 | } |
|
159 | 159 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
160 | 160 | break; |
|
161 | 161 | case BIT_WFP_BUFFER_1: |
|
162 | 162 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
163 | 163 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
164 | 164 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
165 | 165 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
166 | 166 | current_ring_node_f2 = current_ring_node_f2->next; |
|
167 | 167 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
168 | 168 | if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { |
|
169 | 169 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ); |
|
170 | 170 | } |
|
171 | 171 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
172 | 172 | break; |
|
173 | 173 | default: |
|
174 | 174 | break; |
|
175 | 175 | } |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | inline void waveform_isr_normal_sbm1_sbm2( void ) |
|
179 | 179 | { |
|
180 | 180 | rtems_status_code status; |
|
181 | 181 | |
|
182 | 182 | //*** |
|
183 | 183 | // F0 |
|
184 | 184 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits |
|
185 | 185 | { |
|
186 | 186 | swf0_ready_flag_f1 = true; |
|
187 | 187 | swf0_ready_flag_f2 = true; |
|
188 | 188 | ring_node_to_send_swf_f0 = current_ring_node_f0->previous; |
|
189 | 189 | current_ring_node_f0 = current_ring_node_f0->next; |
|
190 | 190 | if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0) |
|
191 | 191 | { |
|
192 | 192 | |
|
193 | 193 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time; |
|
194 | 194 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time; |
|
195 | 195 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address; |
|
196 | 196 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001] |
|
197 | 197 | } |
|
198 | 198 | else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1) |
|
199 | 199 | { |
|
200 | 200 | ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time; |
|
201 | 201 | ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time; |
|
202 | 202 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; |
|
203 | 203 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010] |
|
204 | 204 | } |
|
205 | 205 | // send an event to the WFRM task for resynchro activities |
|
206 | 206 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH ); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | //*** |
|
210 | 210 | // F1 |
|
211 | 211 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits |
|
212 | 212 | // (1) change the receiving buffer for the waveform picker |
|
213 | 213 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; |
|
214 | 214 | current_ring_node_f1 = current_ring_node_f1->next; |
|
215 | 215 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0) |
|
216 | 216 | { |
|
217 | 217 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time; |
|
218 | 218 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time; |
|
219 | 219 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address; |
|
220 | 220 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0 |
|
221 | 221 | } |
|
222 | 222 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1) |
|
223 | 223 | { |
|
224 | 224 | ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time; |
|
225 | 225 | ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time; |
|
226 | 226 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; |
|
227 | 227 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0 |
|
228 | 228 | } |
|
229 | 229 | // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) |
|
230 | 230 | status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | //*** |
|
234 | 234 | // F2 |
|
235 | 235 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit |
|
236 | 236 | // (1) change the receiving buffer for the waveform picker |
|
237 | 237 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
238 | 238 | ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; |
|
239 | 239 | current_ring_node_f2 = current_ring_node_f2->next; |
|
240 | 240 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0) |
|
241 | 241 | { |
|
242 | 242 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time; |
|
243 | 243 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time; |
|
244 | 244 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address; |
|
245 | 245 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
246 | 246 | } |
|
247 | 247 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1) |
|
248 | 248 | { |
|
249 | 249 | ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time; |
|
250 | 250 | ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time; |
|
251 | 251 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; |
|
252 | 252 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
253 | 253 | } |
|
254 | 254 | // (2) send an event for the waveforms transmission |
|
255 | 255 | status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
256 | 256 | } |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | rtems_isr waveforms_isr( rtems_vector_number vector ) |
|
260 | 260 | { |
|
261 | 261 | /** This is the interrupt sub routine called by the waveform picker core. |
|
262 | 262 | * |
|
263 | 263 | * This ISR launch different actions depending mainly on two pieces of information: |
|
264 | 264 | * 1. the values read in the registers of the waveform picker. |
|
265 | 265 | * 2. the current LFR mode. |
|
266 | 266 | * |
|
267 | 267 | */ |
|
268 | 268 | |
|
269 | 269 | // STATUS |
|
270 | 270 | // new error error buffer full |
|
271 | 271 | // 15 14 13 12 11 10 9 8 |
|
272 | 272 | // f3 f2 f1 f0 f3 f2 f1 f0 |
|
273 | 273 | // |
|
274 | 274 | // ready buffer |
|
275 | 275 | // 7 6 5 4 3 2 1 0 |
|
276 | 276 | // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0 |
|
277 | 277 | |
|
278 | 278 | rtems_status_code spare_status; |
|
279 | 279 | |
|
280 | 280 | waveforms_isr_f3(); |
|
281 | 281 | |
|
282 | 282 | //************************************************* |
|
283 | 283 | // copy the status bits in the housekeeping packets |
|
284 | 284 | housekeeping_packet.hk_lfr_vhdl_iir_cal = |
|
285 | 285 | (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
286 | 286 | |
|
287 | 287 | if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits |
|
288 | 288 | { |
|
289 | 289 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 ); |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | switch(lfrCurrentMode) |
|
293 | 293 | { |
|
294 | 294 | //******** |
|
295 | 295 | // STANDBY |
|
296 | 296 | case LFR_MODE_STANDBY: |
|
297 | 297 | break; |
|
298 | 298 | //************************** |
|
299 | 299 | // LFR NORMAL, SBM1 and SBM2 |
|
300 | 300 | case LFR_MODE_NORMAL: |
|
301 | 301 | case LFR_MODE_SBM1: |
|
302 | 302 | case LFR_MODE_SBM2: |
|
303 | 303 | waveform_isr_normal_sbm1_sbm2(); |
|
304 | 304 | break; |
|
305 | 305 | //****** |
|
306 | 306 | // BURST |
|
307 | 307 | case LFR_MODE_BURST: |
|
308 | 308 | waveforms_isr_burst(); |
|
309 | 309 | break; |
|
310 | 310 | //******** |
|
311 | 311 | // DEFAULT |
|
312 | 312 | default: |
|
313 | 313 | break; |
|
314 | 314 | } |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | //************ |
|
318 | 318 | // RTEMS TASKS |
|
319 | 319 | |
|
320 | 320 | rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
321 | 321 | { |
|
322 | 322 | /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. |
|
323 | 323 | * |
|
324 | 324 | * @param unused is the starting argument of the RTEMS task |
|
325 | 325 | * |
|
326 | 326 | * The following data packets are sent by this task: |
|
327 | 327 | * - TM_LFR_SCIENCE_NORMAL_SWF_F0 |
|
328 | 328 | * - TM_LFR_SCIENCE_NORMAL_SWF_F1 |
|
329 | 329 | * - TM_LFR_SCIENCE_NORMAL_SWF_F2 |
|
330 | 330 | * |
|
331 | 331 | */ |
|
332 | 332 | |
|
333 | 333 | rtems_event_set event_out; |
|
334 | 334 | rtems_id queue_id; |
|
335 | 335 | rtems_status_code status; |
|
336 | 336 | ring_node *ring_node_swf1_extracted_ptr; |
|
337 | 337 | ring_node *ring_node_swf2_extracted_ptr; |
|
338 | 338 | |
|
339 | 339 | event_out = EVENT_SETS_NONE_PENDING; |
|
340 | 340 | queue_id = RTEMS_ID_NONE; |
|
341 | 341 | |
|
342 | 342 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; |
|
343 | 343 | ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; |
|
344 | 344 | |
|
345 | 345 | status = get_message_queue_id_send( &queue_id ); |
|
346 | 346 | if (status != RTEMS_SUCCESSFUL) |
|
347 | 347 | { |
|
348 | 348 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | BOOT_PRINTF("in WFRM ***\n"); |
|
352 | 352 | |
|
353 | 353 | while(1){ |
|
354 | 354 | // wait for an RTEMS_EVENT |
|
355 | 355 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, |
|
356 | 356 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
357 | 357 | |
|
358 | 358 | if (event_out == RTEMS_EVENT_MODE_NORMAL) |
|
359 | 359 | { |
|
360 | 360 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); |
|
361 | 361 | ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; |
|
362 | 362 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; |
|
363 | 363 | ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; |
|
364 | 364 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); |
|
365 | 365 | status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); |
|
366 | 366 | status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); |
|
367 | 367 | } |
|
368 | 368 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) |
|
369 | 369 | { |
|
370 | 370 | snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
371 | 371 | } |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
376 | 376 | { |
|
377 | 377 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. |
|
378 | 378 | * |
|
379 | 379 | * @param unused is the starting argument of the RTEMS task |
|
380 | 380 | * |
|
381 | 381 | * The following data packet is sent by this task: |
|
382 | 382 | * - TM_LFR_SCIENCE_NORMAL_CWF_F3 |
|
383 | 383 | * |
|
384 | 384 | */ |
|
385 | 385 | |
|
386 | 386 | rtems_event_set event_out; |
|
387 | 387 | rtems_id queue_id; |
|
388 | 388 | rtems_status_code status; |
|
389 | 389 | ring_node ring_node_cwf3_light; |
|
390 | 390 | ring_node *ring_node_to_send_cwf; |
|
391 | 391 | |
|
392 | 392 | event_out = EVENT_SETS_NONE_PENDING; |
|
393 | 393 | queue_id = RTEMS_ID_NONE; |
|
394 | 394 | |
|
395 | 395 | status = get_message_queue_id_send( &queue_id ); |
|
396 | 396 | if (status != RTEMS_SUCCESSFUL) |
|
397 | 397 | { |
|
398 | 398 | PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) |
|
399 | 399 | } |
|
400 | 400 | |
|
401 | 401 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
402 | 402 | |
|
403 | 403 | // init the ring_node_cwf3_light structure |
|
404 | 404 | ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; |
|
405 | 405 | ring_node_cwf3_light.coarseTime = INIT_CHAR; |
|
406 | 406 | ring_node_cwf3_light.fineTime = INIT_CHAR; |
|
407 | 407 | ring_node_cwf3_light.next = NULL; |
|
408 | 408 | ring_node_cwf3_light.previous = NULL; |
|
409 | 409 | ring_node_cwf3_light.sid = SID_NORM_CWF_F3; |
|
410 | 410 | ring_node_cwf3_light.status = INIT_CHAR; |
|
411 | 411 | |
|
412 | 412 | BOOT_PRINTF("in CWF3 ***\n"); |
|
413 | 413 | |
|
414 | 414 | while(1){ |
|
415 | 415 | // wait for an RTEMS_EVENT |
|
416 | 416 | rtems_event_receive( RTEMS_EVENT_0, |
|
417 | 417 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
418 | 418 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
419 | 419 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) |
|
420 | 420 | { |
|
421 | 421 | ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 ); |
|
422 | 422 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3) |
|
423 | 423 | { |
|
424 | 424 | PRINTF("send CWF_LONG_F3\n"); |
|
425 | 425 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
426 | 426 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
427 | 427 | } |
|
428 | 428 | else |
|
429 | 429 | { |
|
430 | 430 | PRINTF("send CWF_F3 (light)\n"); |
|
431 | 431 | send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); |
|
432 | 432 | } |
|
433 | 433 | |
|
434 | 434 | } |
|
435 | 435 | else |
|
436 | 436 | { |
|
437 | 437 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) |
|
438 | 438 | } |
|
439 | 439 | } |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 |
|
443 | 443 | { |
|
444 | 444 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. |
|
445 | 445 | * |
|
446 | 446 | * @param unused is the starting argument of the RTEMS task |
|
447 | 447 | * |
|
448 | 448 | * The following data packet is sent by this function: |
|
449 | 449 | * - TM_LFR_SCIENCE_BURST_CWF_F2 |
|
450 | 450 | * - TM_LFR_SCIENCE_SBM2_CWF_F2 |
|
451 | 451 | * |
|
452 | 452 | */ |
|
453 | 453 | |
|
454 | 454 | rtems_event_set event_out; |
|
455 | 455 | rtems_id queue_id; |
|
456 | 456 | rtems_status_code status; |
|
457 | 457 | ring_node *ring_node_to_send; |
|
458 | 458 | unsigned long long int acquisitionTimeF0_asLong; |
|
459 | 459 | |
|
460 | 460 | event_out = EVENT_SETS_NONE_PENDING; |
|
461 | 461 | queue_id = RTEMS_ID_NONE; |
|
462 | 462 | |
|
463 | 463 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
464 | 464 | |
|
465 | 465 | status = get_message_queue_id_send( &queue_id ); |
|
466 | 466 | if (status != RTEMS_SUCCESSFUL) |
|
467 | 467 | { |
|
468 | 468 | PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | BOOT_PRINTF("in CWF2 ***\n"); |
|
472 | 472 | |
|
473 | 473 | while(1){ |
|
474 | 474 | // wait for an RTEMS_EVENT// send the snapshot when built |
|
475 | 475 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); |
|
476 | 476 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, |
|
477 | 477 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
478 | 478 | ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 ); |
|
479 | 479 | if (event_out == RTEMS_EVENT_MODE_BURST) |
|
480 | 480 | { // data are sent whatever the transition time |
|
481 | 481 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
482 | 482 | } |
|
483 | 483 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
484 | 484 | { |
|
485 | 485 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
486 | 486 | { |
|
487 | 487 | // data are sent depending on the transition time |
|
488 | 488 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime) |
|
489 | 489 | { |
|
490 | 490 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
491 | 491 | } |
|
492 | 492 | } |
|
493 | 493 | // launch snapshot extraction if needed |
|
494 | 494 | if (extractSWF2 == true) |
|
495 | 495 | { |
|
496 | 496 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; |
|
497 | 497 | // extract the snapshot |
|
498 | 498 | build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong, |
|
499 | 499 | &ring_node_swf2_extracted, swf2_extracted ); |
|
500 | 500 | extractSWF2 = false; |
|
501 | 501 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM |
|
502 | 502 | } |
|
503 | 503 | if (swf0_ready_flag_f2 == true) |
|
504 | 504 | { |
|
505 | 505 | extractSWF2 = true; |
|
506 | 506 | // record the acquition time of the f0 snapshot to use to build the snapshot at f2 |
|
507 | 507 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
508 | 508 | swf0_ready_flag_f2 = false; |
|
509 | 509 | } |
|
510 | 510 | } |
|
511 | 511 | } |
|
512 | 512 | } |
|
513 | 513 | |
|
514 | 514 | rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 |
|
515 | 515 | { |
|
516 | 516 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. |
|
517 | 517 | * |
|
518 | 518 | * @param unused is the starting argument of the RTEMS task |
|
519 | 519 | * |
|
520 | 520 | * The following data packet is sent by this function: |
|
521 | 521 | * - TM_LFR_SCIENCE_SBM1_CWF_F1 |
|
522 | 522 | * |
|
523 | 523 | */ |
|
524 | 524 | |
|
525 | 525 | rtems_event_set event_out; |
|
526 | 526 | rtems_id queue_id; |
|
527 | 527 | rtems_status_code status; |
|
528 | 528 | |
|
529 | 529 | ring_node *ring_node_to_send_cwf; |
|
530 | 530 | |
|
531 | 531 | event_out = EVENT_SETS_NONE_PENDING; |
|
532 | 532 | queue_id = RTEMS_ID_NONE; |
|
533 | 533 | |
|
534 | 534 | status = get_message_queue_id_send( &queue_id ); |
|
535 | 535 | if (status != RTEMS_SUCCESSFUL) |
|
536 | 536 | { |
|
537 | 537 | PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | BOOT_PRINTF("in CWF1 ***\n"); |
|
541 | 541 | |
|
542 | 542 | while(1){ |
|
543 | 543 | // wait for an RTEMS_EVENT |
|
544 | 544 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
545 | 545 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
546 | 546 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); |
|
547 | 547 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; |
|
548 | 548 | if (lfrCurrentMode == LFR_MODE_SBM1) |
|
549 | 549 | { |
|
550 | 550 | // data are sent depending on the transition time |
|
551 | 551 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) |
|
552 | 552 | { |
|
553 | 553 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
554 | 554 | } |
|
555 | 555 | } |
|
556 | 556 | // launch snapshot extraction if needed |
|
557 | 557 | if (extractSWF1 == true) |
|
558 | 558 | { |
|
559 | 559 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; |
|
560 | 560 | // launch the snapshot extraction |
|
561 | 561 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
562 | 562 | extractSWF1 = false; |
|
563 | 563 | } |
|
564 | 564 | if (swf0_ready_flag_f1 == true) |
|
565 | 565 | { |
|
566 | 566 | extractSWF1 = true; |
|
567 | 567 | swf0_ready_flag_f1 = false; // this step shall be executed only one time |
|
568 | 568 | } |
|
569 | 569 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction |
|
570 | 570 | { |
|
571 | 571 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); |
|
572 | 572 | swf1_ready = false; |
|
573 | 573 | swf2_ready = false; |
|
574 | 574 | } |
|
575 | 575 | } |
|
576 | 576 | } |
|
577 | 577 | |
|
578 | 578 | rtems_task swbd_task(rtems_task_argument argument) |
|
579 | 579 | { |
|
580 | 580 | /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. |
|
581 | 581 | * |
|
582 | 582 | * @param unused is the starting argument of the RTEMS task |
|
583 | 583 | * |
|
584 | 584 | */ |
|
585 | 585 | |
|
586 | 586 | rtems_event_set event_out; |
|
587 | 587 | unsigned long long int acquisitionTimeF0_asLong; |
|
588 | 588 | |
|
589 | 589 | event_out = EVENT_SETS_NONE_PENDING; |
|
590 | 590 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
591 | 591 | |
|
592 | 592 | BOOT_PRINTF("in SWBD ***\n") |
|
593 | 593 | |
|
594 | 594 | while(1){ |
|
595 | 595 | // wait for an RTEMS_EVENT |
|
596 | 596 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
597 | 597 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
598 | 598 | if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
599 | 599 | { |
|
600 | 600 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
601 | 601 | build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong, |
|
602 | 602 | &ring_node_swf1_extracted, swf1_extracted ); |
|
603 | 603 | swf1_ready = true; // the snapshot has been extracted and is ready to be sent |
|
604 | 604 | } |
|
605 | 605 | else |
|
606 | 606 | { |
|
607 | 607 | PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) |
|
608 | 608 | } |
|
609 | 609 | } |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | //****************** |
|
613 | 613 | // general functions |
|
614 | 614 | |
|
615 | 615 | void WFP_init_rings( void ) |
|
616 | 616 | { |
|
617 | 617 | // F0 RING |
|
618 | 618 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); |
|
619 | 619 | // F1 RING |
|
620 | 620 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); |
|
621 | 621 | // F2 RING |
|
622 | 622 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); |
|
623 | 623 | // F3 RING |
|
624 | 624 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); |
|
625 | 625 | |
|
626 | 626 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; |
|
627 | 627 | ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; |
|
628 | 628 | |
|
629 | 629 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) |
|
630 | 630 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) |
|
631 | 631 | DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) |
|
632 | 632 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) |
|
633 | 633 | DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) |
|
634 | 634 | DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) |
|
635 | 635 | DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) |
|
636 | 636 | DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) |
|
637 | 637 | |
|
638 | 638 | } |
|
639 | 639 | |
|
640 | 640 | void WFP_reset_current_ring_nodes( void ) |
|
641 | 641 | { |
|
642 | 642 | current_ring_node_f0 = waveform_ring_f0[0].next; |
|
643 | 643 | current_ring_node_f1 = waveform_ring_f1[0].next; |
|
644 | 644 | current_ring_node_f2 = waveform_ring_f2[0].next; |
|
645 | 645 | current_ring_node_f3 = waveform_ring_f3[0].next; |
|
646 | 646 | |
|
647 | 647 | ring_node_to_send_swf_f0 = waveform_ring_f0; |
|
648 | 648 | ring_node_to_send_swf_f1 = waveform_ring_f1; |
|
649 | 649 | ring_node_to_send_swf_f2 = waveform_ring_f2; |
|
650 | 650 | |
|
651 | 651 | ring_node_to_send_cwf_f1 = waveform_ring_f1; |
|
652 | 652 | ring_node_to_send_cwf_f2 = waveform_ring_f2; |
|
653 | 653 | ring_node_to_send_cwf_f3 = waveform_ring_f3; |
|
654 | 654 | } |
|
655 | 655 | |
|
656 | 656 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) |
|
657 | 657 | { |
|
658 | 658 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
659 | 659 | * |
|
660 | 660 | * @param waveform points to the buffer containing the data that will be send. |
|
661 | 661 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
662 | 662 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
663 | 663 | * contain information to setup the transmission of the data packets. |
|
664 | 664 | * |
|
665 | 665 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
666 | 666 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
667 | 667 | * |
|
668 | 668 | */ |
|
669 | 669 | |
|
670 | 670 | unsigned int i; |
|
671 | 671 | unsigned int j; |
|
672 | 672 | int ret; |
|
673 | 673 | rtems_status_code status; |
|
674 | 674 | |
|
675 | 675 | char *sample; |
|
676 | 676 | int *dataPtr; |
|
677 | 677 | |
|
678 | 678 | ret = LFR_DEFAULT; |
|
679 | 679 | |
|
680 | 680 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
681 | 681 | |
|
682 | 682 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; |
|
683 | 683 | ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; |
|
684 | 684 | |
|
685 | 685 | //********************** |
|
686 | 686 | // BUILD CWF3_light DATA |
|
687 | 687 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) |
|
688 | 688 | { |
|
689 | 689 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; |
|
690 | 690 | for (j=0; j < CWF_BLK_SIZE; j++) |
|
691 | 691 | { |
|
692 | 692 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ]; |
|
693 | 693 | } |
|
694 | 694 | } |
|
695 | 695 | |
|
696 | 696 | // SEND PACKET |
|
697 | 697 | status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); |
|
698 | 698 | if (status != RTEMS_SUCCESSFUL) { |
|
699 | 699 | ret = LFR_DEFAULT; |
|
700 | 700 | } |
|
701 | 701 | |
|
702 | 702 | return ret; |
|
703 | 703 | } |
|
704 | 704 | |
|
705 | 705 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, |
|
706 | 706 | unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) |
|
707 | 707 | { |
|
708 | 708 | unsigned long long int acquisitionTimeAsLong; |
|
709 | 709 | unsigned char localAcquisitionTime[BYTES_PER_TIME]; |
|
710 | 710 | double deltaT; |
|
711 | 711 | |
|
712 | 712 | deltaT = INIT_FLOAT; |
|
713 | 713 | |
|
714 | 714 | localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES ); |
|
715 | 715 | localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES ); |
|
716 | 716 | localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE ); |
|
717 | 717 | localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime ); |
|
718 | 718 | localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE ); |
|
719 | 719 | localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime ); |
|
720 | 720 | |
|
721 | 721 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES ) |
|
722 | 722 | + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES ) |
|
723 | 723 | + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES ) |
|
724 | 724 | + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES ) |
|
725 | 725 | + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE ) |
|
726 | 726 | + ( (unsigned long long int) localAcquisitionTime[BYTE_5] ); |
|
727 | 727 | |
|
728 | 728 | switch( sid ) |
|
729 | 729 | { |
|
730 | 730 | case SID_NORM_SWF_F0: |
|
731 | 731 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ; |
|
732 | 732 | break; |
|
733 | 733 | |
|
734 | 734 | case SID_NORM_SWF_F1: |
|
735 | 735 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ; |
|
736 | 736 | break; |
|
737 | 737 | |
|
738 | 738 | case SID_NORM_SWF_F2: |
|
739 | 739 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ; |
|
740 | 740 | break; |
|
741 | 741 | |
|
742 | 742 | case SID_SBM1_CWF_F1: |
|
743 | 743 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ; |
|
744 | 744 | break; |
|
745 | 745 | |
|
746 | 746 | case SID_SBM2_CWF_F2: |
|
747 | 747 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
748 | 748 | break; |
|
749 | 749 | |
|
750 | 750 | case SID_BURST_CWF_F2: |
|
751 | 751 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
752 | 752 | break; |
|
753 | 753 | |
|
754 | 754 | case SID_NORM_CWF_F3: |
|
755 | 755 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ; |
|
756 | 756 | break; |
|
757 | 757 | |
|
758 | 758 | case SID_NORM_CWF_LONG_F3: |
|
759 | 759 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ; |
|
760 | 760 | break; |
|
761 | 761 | |
|
762 | 762 | default: |
|
763 | 763 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) |
|
764 | 764 | deltaT = 0.; |
|
765 | 765 | break; |
|
766 | 766 | } |
|
767 | 767 | |
|
768 | 768 | acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; |
|
769 | 769 | // |
|
770 | 770 | acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES); |
|
771 | 771 | acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES); |
|
772 | 772 | acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES); |
|
773 | 773 | acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES); |
|
774 | 774 | acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE ); |
|
775 | 775 | acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong ); |
|
776 | 776 | |
|
777 | 777 | } |
|
778 | 778 | |
|
779 | 779 | void build_snapshot_from_ring( ring_node *ring_node_to_send, |
|
780 | 780 | unsigned char frequencyChannel, |
|
781 | 781 | unsigned long long int acquisitionTimeF0_asLong, |
|
782 | 782 | ring_node *ring_node_swf_extracted, |
|
783 | 783 | int *swf_extracted) |
|
784 | 784 | { |
|
785 | 785 | unsigned int i; |
|
786 | 786 | unsigned int node; |
|
787 | 787 | unsigned long long int centerTime_asLong; |
|
788 | 788 | unsigned long long int acquisitionTime_asLong; |
|
789 | 789 | unsigned long long int bufferAcquisitionTime_asLong; |
|
790 | 790 | unsigned char *ptr1; |
|
791 | 791 | unsigned char *ptr2; |
|
792 | 792 | unsigned char *timeCharPtr; |
|
793 | 793 | unsigned char nb_ring_nodes; |
|
794 | 794 | unsigned long long int frequency_asLong; |
|
795 | 795 | unsigned long long int nbTicksPerSample_asLong; |
|
796 | 796 | unsigned long long int nbSamplesPart1_asLong; |
|
797 | 797 | unsigned long long int sampleOffset_asLong; |
|
798 | 798 | |
|
799 | 799 | unsigned int deltaT_F0; |
|
800 | 800 | unsigned int deltaT_F1; |
|
801 | 801 | unsigned long long int deltaT_F2; |
|
802 | 802 | |
|
803 | 803 | deltaT_F0 = DELTAT_F0; |
|
804 | 804 | deltaT_F1 = DELTAF_F1; |
|
805 | 805 | deltaT_F2 = DELTAF_F2; |
|
806 | 806 | sampleOffset_asLong = INIT_CHAR; |
|
807 | 807 | |
|
808 | 808 | // (1) get the f0 acquisition time => the value is passed in argument |
|
809 | 809 | |
|
810 | 810 | // (2) compute the central reference time |
|
811 | 811 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; |
|
812 | 812 | acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
813 | 813 | bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
814 | 814 | nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2) |
|
815 | 815 | |
|
816 | 816 | // (3) compute the acquisition time of the current snapshot |
|
817 | 817 | switch(frequencyChannel) |
|
818 | 818 | { |
|
819 | 819 | case CHANNELF1: // 1 is for F1 = 4096 Hz |
|
820 | 820 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; |
|
821 | 821 | nb_ring_nodes = NB_RING_NODES_F1; |
|
822 | 822 | frequency_asLong = FREQ_F1; |
|
823 | 823 | nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096; |
|
824 | 824 | break; |
|
825 | 825 | case CHANNELF2: // 2 is for F2 = 256 Hz |
|
826 | 826 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; |
|
827 | 827 | nb_ring_nodes = NB_RING_NODES_F2; |
|
828 | 828 | frequency_asLong = FREQ_F2; |
|
829 | 829 | nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256; |
|
830 | 830 | break; |
|
831 | 831 | default: |
|
832 | 832 | acquisitionTime_asLong = centerTime_asLong; |
|
833 | 833 | nb_ring_nodes = 0; |
|
834 | 834 | frequency_asLong = FREQ_F2; |
|
835 | 835 | nbTicksPerSample_asLong = TICKS_PER_T2; |
|
836 | 836 | break; |
|
837 | 837 | } |
|
838 | 838 | |
|
839 | 839 | //***************************************************************************** |
|
840 | 840 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong |
|
841 | 841 | node = 0; |
|
842 | 842 | while ( node < nb_ring_nodes) |
|
843 | 843 | { |
|
844 | 844 | //PRINTF1("%d ... ", node); |
|
845 | 845 | bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); |
|
846 | 846 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) |
|
847 | 847 | { |
|
848 | 848 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); |
|
849 | 849 | node = nb_ring_nodes; |
|
850 | 850 | } |
|
851 | 851 | else |
|
852 | 852 | { |
|
853 | 853 | node = node + 1; |
|
854 | 854 | ring_node_to_send = ring_node_to_send->previous; |
|
855 | 855 | } |
|
856 | 856 | } |
|
857 | 857 | |
|
858 | 858 | // (5) compute the number of samples to take in the current buffer |
|
859 | 859 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; |
|
860 | 860 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; |
|
861 | 861 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); |
|
862 | 862 | |
|
863 | 863 | // (6) compute the final acquisition time |
|
864 | 864 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + |
|
865 | 865 | (sampleOffset_asLong * nbTicksPerSample_asLong); |
|
866 | 866 | |
|
867 | 867 | // (7) copy the acquisition time at the beginning of the extrated snapshot |
|
868 | 868 | ptr1 = (unsigned char*) &acquisitionTime_asLong; |
|
869 | 869 | // fine time |
|
870 | 870 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; |
|
871 | 871 | ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ]; |
|
872 | 872 | ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ]; |
|
873 | 873 | // coarse time |
|
874 | 874 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; |
|
875 | 875 | ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ]; |
|
876 | 876 | ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ]; |
|
877 | 877 | ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ]; |
|
878 | 878 | ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ]; |
|
879 | 879 | |
|
880 | 880 | // re set the synchronization bit |
|
881 | 881 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; |
|
882 | 882 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] |
|
883 | 883 | |
|
884 | 884 | if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) |
|
885 | 885 | { |
|
886 | 886 | nbSamplesPart1_asLong = 0; |
|
887 | 887 | } |
|
888 | 888 | // copy the part 1 of the snapshot in the extracted buffer |
|
889 | 889 | for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) |
|
890 | 890 | { |
|
891 | 891 | swf_extracted[i] = |
|
892 | 892 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; |
|
893 | 893 | } |
|
894 | 894 | // copy the part 2 of the snapshot in the extracted buffer |
|
895 | 895 | ring_node_to_send = ring_node_to_send->next; |
|
896 | 896 | for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) |
|
897 | 897 | { |
|
898 | 898 | swf_extracted[i] = |
|
899 | 899 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; |
|
900 | 900 | } |
|
901 | 901 | } |
|
902 | 902 | |
|
903 | 903 | double computeCorrection( unsigned char *timePtr ) |
|
904 | 904 | { |
|
905 | 905 | unsigned long long int acquisitionTime; |
|
906 | 906 | unsigned long long int centerTime; |
|
907 | 907 | unsigned long long int previousTick; |
|
908 | 908 | unsigned long long int nextTick; |
|
909 | 909 | unsigned long long int deltaPreviousTick; |
|
910 | 910 | unsigned long long int deltaNextTick; |
|
911 | 911 | double deltaPrevious_ms; |
|
912 | 912 | double deltaNext_ms; |
|
913 | 913 | double correctionInF2; |
|
914 | 914 | |
|
915 | 915 | correctionInF2 = 0; //set to default value (Don_Initialisation_P2) |
|
916 | 916 | |
|
917 | 917 | // get acquisition time in fine time ticks |
|
918 | 918 | acquisitionTime = get_acquisition_time( timePtr ); |
|
919 | 919 | |
|
920 | 920 | // compute center time |
|
921 | 921 | centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667; |
|
922 | 922 | previousTick = centerTime - (centerTime & INT16_ALL_F); |
|
923 | 923 | nextTick = previousTick + TICKS_PER_S; |
|
924 | 924 | |
|
925 | 925 | deltaPreviousTick = centerTime - previousTick; |
|
926 | 926 | deltaNextTick = nextTick - centerTime; |
|
927 | 927 | |
|
928 | 928 | deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S; |
|
929 | 929 | deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S; |
|
930 | 930 | |
|
931 | 931 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); |
|
932 | 932 | |
|
933 | 933 | // which tick is the closest? |
|
934 | 934 | if (deltaPreviousTick > deltaNextTick) |
|
935 | 935 | { |
|
936 | 936 | // the snapshot center is just before the second => increase delta_snapshot |
|
937 | 937 | correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S ); |
|
938 | 938 | } |
|
939 | 939 | else |
|
940 | 940 | { |
|
941 | 941 | // the snapshot center is just after the second => decrease delta_snapshot |
|
942 | 942 | correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S ); |
|
943 | 943 | } |
|
944 | 944 | |
|
945 | 945 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); |
|
946 | 946 | |
|
947 | 947 | return correctionInF2; |
|
948 | 948 | } |
|
949 | 949 | |
|
950 | 950 | void applyCorrection( double correction ) |
|
951 | 951 | { |
|
952 | 952 | int correctionInt; |
|
953 | 953 | |
|
954 | 954 | correctionInt = 0; |
|
955 | 955 | |
|
956 | 956 | if (correction >= 0.) |
|
957 | 957 | { |
|
958 | 958 | if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) ) |
|
959 | 959 | { |
|
960 | 960 | correctionInt = ONE_TICK_CORR; |
|
961 | 961 | } |
|
962 | 962 | else |
|
963 | 963 | { |
|
964 | 964 | correctionInt = CORR_MULT * floor(correction); |
|
965 | 965 | } |
|
966 | 966 | } |
|
967 | 967 | else |
|
968 | 968 | { |
|
969 | 969 | if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) ) |
|
970 | 970 | { |
|
971 | 971 | correctionInt = -ONE_TICK_CORR; |
|
972 | 972 | } |
|
973 | 973 | else |
|
974 | 974 | { |
|
975 | 975 | correctionInt = CORR_MULT * ceil(correction); |
|
976 | 976 | } |
|
977 | 977 | } |
|
978 | 978 | waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; |
|
979 | 979 | } |
|
980 | 980 | |
|
981 | 981 | void snapshot_resynchronization( unsigned char *timePtr ) |
|
982 | 982 | { |
|
983 | 983 | /** This function compute a correction to apply on delta_snapshot. |
|
984 | 984 | * |
|
985 | 985 | * |
|
986 | 986 | * @param timePtr is a pointer to the acquisition time of the snapshot being considered. |
|
987 | 987 | * |
|
988 | 988 | * @return void |
|
989 | 989 | * |
|
990 | 990 | */ |
|
991 | 991 | |
|
992 | 992 | static double correction = INIT_FLOAT; |
|
993 | 993 | static resynchro_state state = MEASURE; |
|
994 | 994 | static unsigned int nbSnapshots = 0; |
|
995 | 995 | |
|
996 | 996 | int correctionInt; |
|
997 | 997 | |
|
998 | 998 | correctionInt = 0; |
|
999 | 999 | |
|
1000 | 1000 | switch (state) |
|
1001 | 1001 | { |
|
1002 | 1002 | |
|
1003 | 1003 | case MEASURE: |
|
1004 | 1004 | // ******** |
|
1005 | 1005 | PRINTF1("MEASURE === %d\n", nbSnapshots); |
|
1006 | 1006 | state = CORRECTION; |
|
1007 | 1007 | correction = computeCorrection( timePtr ); |
|
1008 | 1008 | PRINTF1("MEASURE === correction = %.2f\n", correction ); |
|
1009 | 1009 | applyCorrection( correction ); |
|
1010 | 1010 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1011 | 1011 | //**** |
|
1012 | 1012 | break; |
|
1013 | 1013 | |
|
1014 | 1014 | case CORRECTION: |
|
1015 | 1015 | //************ |
|
1016 | 1016 | PRINTF1("CORRECTION === %d\n", nbSnapshots); |
|
1017 | 1017 | state = MEASURE; |
|
1018 | 1018 | computeCorrection( timePtr ); |
|
1019 | 1019 | set_wfp_delta_snapshot(); |
|
1020 | 1020 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1021 | 1021 | //**** |
|
1022 | 1022 | break; |
|
1023 | 1023 | |
|
1024 | 1024 | default: |
|
1025 | 1025 | break; |
|
1026 | 1026 | |
|
1027 | 1027 | } |
|
1028 | 1028 | |
|
1029 | 1029 | nbSnapshots++; |
|
1030 | 1030 | } |
|
1031 | 1031 | |
|
1032 | 1032 | //************** |
|
1033 | 1033 | // wfp registers |
|
1034 | 1034 | void reset_wfp_burst_enable( void ) |
|
1035 | 1035 | { |
|
1036 | 1036 | /** This function resets the waveform picker burst_enable register. |
|
1037 | 1037 | * |
|
1038 | 1038 | * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. |
|
1039 | 1039 | * |
|
1040 | 1040 | */ |
|
1041 | 1041 | |
|
1042 | 1042 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 |
|
1043 | 1043 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN; |
|
1044 | 1044 | } |
|
1045 | 1045 | |
|
1046 | 1046 | void reset_wfp_status( void ) |
|
1047 | 1047 | { |
|
1048 | 1048 | /** This function resets the waveform picker status register. |
|
1049 | 1049 | * |
|
1050 | 1050 | * All status bits are set to 0 [new_err full_err full]. |
|
1051 | 1051 | * |
|
1052 | 1052 | */ |
|
1053 | 1053 | |
|
1054 | 1054 | waveform_picker_regs->status = INT16_ALL_F; |
|
1055 | 1055 | } |
|
1056 | 1056 | |
|
1057 | 1057 | void reset_wfp_buffer_addresses( void ) |
|
1058 | 1058 | { |
|
1059 | 1059 | // F0 |
|
1060 | 1060 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 |
|
1061 | 1061 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c |
|
1062 | 1062 | // F1 |
|
1063 | 1063 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 |
|
1064 | 1064 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 |
|
1065 | 1065 | // F2 |
|
1066 | 1066 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 |
|
1067 | 1067 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c |
|
1068 | 1068 | // F3 |
|
1069 | 1069 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 |
|
1070 | 1070 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 |
|
1071 | 1071 | } |
|
1072 | 1072 | |
|
1073 | 1073 | void reset_waveform_picker_regs( void ) |
|
1074 | 1074 | { |
|
1075 | 1075 | /** This function resets the waveform picker module registers. |
|
1076 | 1076 | * |
|
1077 | 1077 | * The registers affected by this function are located at the following offset addresses: |
|
1078 | 1078 | * - 0x00 data_shaping |
|
1079 | 1079 | * - 0x04 run_burst_enable |
|
1080 | 1080 | * - 0x08 addr_data_f0 |
|
1081 | 1081 | * - 0x0C addr_data_f1 |
|
1082 | 1082 | * - 0x10 addr_data_f2 |
|
1083 | 1083 | * - 0x14 addr_data_f3 |
|
1084 | 1084 | * - 0x18 status |
|
1085 | 1085 | * - 0x1C delta_snapshot |
|
1086 | 1086 | * - 0x20 delta_f0 |
|
1087 | 1087 | * - 0x24 delta_f0_2 |
|
1088 | 1088 | * - 0x28 delta_f1 (obsolet parameter) |
|
1089 | 1089 | * - 0x2c delta_f2 |
|
1090 | 1090 | * - 0x30 nb_data_by_buffer |
|
1091 | 1091 | * - 0x34 nb_snapshot_param |
|
1092 | 1092 | * - 0x38 start_date |
|
1093 | 1093 | * - 0x3c nb_word_in_buffer |
|
1094 | 1094 | * |
|
1095 | 1095 | */ |
|
1096 | 1096 | |
|
1097 | 1097 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW |
|
1098 | 1098 | |
|
1099 | 1099 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] |
|
1100 | 1100 | |
|
1101 | 1101 | reset_wfp_buffer_addresses(); |
|
1102 | 1102 | |
|
1103 | 1103 | reset_wfp_status(); // 0x18 |
|
1104 | 1104 | |
|
1105 | 1105 | set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff |
|
1106 | 1106 | |
|
1107 | 1107 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 |
|
1108 | 1108 | |
|
1109 | 1109 | //the parameter delta_f1 [0x28] is not used anymore |
|
1110 | 1110 | |
|
1111 | 1111 | set_wfp_delta_f2(); // 0x2c |
|
1112 | 1112 | |
|
1113 | 1113 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); |
|
1114 | 1114 | DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); |
|
1115 | 1115 | DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); |
|
1116 | 1116 | DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); |
|
1117 | 1117 | DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); |
|
1118 | 1118 | // 2688 = 8 * 336 |
|
1119 | 1119 | waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1 |
|
1120 | 1120 | waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples |
|
1121 | 1121 | waveform_picker_regs->start_date = COARSE_TIME_MASK; |
|
1122 | 1122 | // |
|
1123 | 1123 | // coarse time and fine time registers are not initialized, they are volatile |
|
1124 | 1124 | // |
|
1125 | 1125 | waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 |
|
1126 | 1126 | } |
|
1127 | 1127 | |
|
1128 | 1128 | void set_wfp_data_shaping( void ) |
|
1129 | 1129 | { |
|
1130 | 1130 | /** This function sets the data_shaping register of the waveform picker module. |
|
1131 | 1131 | * |
|
1132 | 1132 | * The value is read from one field of the parameter_dump_packet structure:\n |
|
1133 | 1133 | * bw_sp0_sp1_r0_r1 |
|
1134 | 1134 | * |
|
1135 | 1135 | */ |
|
1136 | 1136 | |
|
1137 | 1137 | unsigned char data_shaping; |
|
1138 | 1138 | |
|
1139 | 1139 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register |
|
1140 | 1140 | // waveform picker : [R1 R0 SP1 SP0 BW] |
|
1141 | 1141 | |
|
1142 | 1142 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; |
|
1143 | 1143 | |
|
1144 | 1144 | waveform_picker_regs->data_shaping = |
|
1145 | 1145 | ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW |
|
1146 | 1146 | + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0 |
|
1147 | 1147 | + ( (data_shaping & BIT_3) >> 1 ) // SP1 |
|
1148 | 1148 | + ( (data_shaping & BIT_2) << 1 ) // R0 |
|
1149 | 1149 | + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1 |
|
1150 | 1150 | + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2 |
|
1151 | 1151 | } |
|
1152 | 1152 | |
|
1153 | 1153 | void set_wfp_burst_enable_register( unsigned char mode ) |
|
1154 | 1154 | { |
|
1155 | 1155 | /** This function sets the waveform picker burst_enable register depending on the mode. |
|
1156 | 1156 | * |
|
1157 | 1157 | * @param mode is the LFR mode to launch. |
|
1158 | 1158 | * |
|
1159 | 1159 | * The burst bits shall be before the enable bits. |
|
1160 | 1160 | * |
|
1161 | 1161 | */ |
|
1162 | 1162 | |
|
1163 | 1163 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 |
|
1164 | 1164 | // the burst bits shall be set first, before the enable bits |
|
1165 | 1165 | switch(mode) { |
|
1166 | 1166 | case LFR_MODE_NORMAL: |
|
1167 | 1167 | case LFR_MODE_SBM1: |
|
1168 | 1168 | case LFR_MODE_SBM2: |
|
1169 | 1169 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst |
|
1170 | 1170 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0 |
|
1171 | 1171 | break; |
|
1172 | 1172 | case LFR_MODE_BURST: |
|
1173 | 1173 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled |
|
1174 | 1174 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2 |
|
1175 | 1175 | break; |
|
1176 | 1176 | default: |
|
1177 | 1177 | waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled |
|
1178 | 1178 | break; |
|
1179 | 1179 | } |
|
1180 | 1180 | } |
|
1181 | 1181 | |
|
1182 | 1182 | void set_wfp_delta_snapshot( void ) |
|
1183 | 1183 | { |
|
1184 | 1184 | /** This function sets the delta_snapshot register of the waveform picker module. |
|
1185 | 1185 | * |
|
1186 | 1186 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: |
|
1187 | 1187 | * - sy_lfr_n_swf_p[0] |
|
1188 | 1188 | * - sy_lfr_n_swf_p[1] |
|
1189 | 1189 | * |
|
1190 | 1190 | */ |
|
1191 | 1191 | |
|
1192 | 1192 | unsigned int delta_snapshot; |
|
1193 | 1193 | unsigned int delta_snapshot_in_T2; |
|
1194 | 1194 | |
|
1195 | 1195 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) |
|
1196 | 1196 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; |
|
1197 | 1197 | |
|
1198 | 1198 | delta_snapshot_in_T2 = delta_snapshot * FREQ_F2; |
|
1199 | 1199 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes |
|
1200 | 1200 | } |
|
1201 | 1201 | |
|
1202 | 1202 | void set_wfp_delta_f0_f0_2( void ) |
|
1203 | 1203 | { |
|
1204 | 1204 | unsigned int delta_snapshot; |
|
1205 | 1205 | unsigned int nb_samples_per_snapshot; |
|
1206 | 1206 | float delta_f0_in_float; |
|
1207 | 1207 | |
|
1208 | 1208 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1209 | 1209 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1210 | 1210 | delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2; |
|
1211 | 1211 | |
|
1212 | 1212 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); |
|
1213 |
waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; |
|
|
1213 | waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; | |
|
1214 | 1214 | } |
|
1215 | 1215 | |
|
1216 | 1216 | void set_wfp_delta_f1( void ) |
|
1217 | 1217 | { |
|
1218 | 1218 | /** Sets the value of the delta_f1 parameter |
|
1219 | 1219 | * |
|
1220 | 1220 | * @param void |
|
1221 | 1221 | * |
|
1222 | 1222 | * @return void |
|
1223 | 1223 | * |
|
1224 | 1224 | * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. |
|
1225 | 1225 | * |
|
1226 | 1226 | */ |
|
1227 | 1227 | |
|
1228 | 1228 | unsigned int delta_snapshot; |
|
1229 | 1229 | unsigned int nb_samples_per_snapshot; |
|
1230 | 1230 | float delta_f1_in_float; |
|
1231 | 1231 | |
|
1232 | 1232 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1233 | 1233 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1234 | 1234 | delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2; |
|
1235 | 1235 | |
|
1236 | 1236 | waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); |
|
1237 | 1237 | } |
|
1238 | 1238 | |
|
1239 | 1239 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used |
|
1240 | 1240 | { |
|
1241 | 1241 | /** Sets the value of the delta_f2 parameter |
|
1242 | 1242 | * |
|
1243 | 1243 | * @param void |
|
1244 | 1244 | * |
|
1245 | 1245 | * @return void |
|
1246 | 1246 | * |
|
1247 | 1247 | * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 |
|
1248 | 1248 | * waveforms (see lpp_waveform_snapshot_controler.vhd for details). |
|
1249 | 1249 | * |
|
1250 | 1250 | */ |
|
1251 | 1251 | |
|
1252 | 1252 | unsigned int delta_snapshot; |
|
1253 | 1253 | unsigned int nb_samples_per_snapshot; |
|
1254 | 1254 | |
|
1255 | 1255 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1256 | 1256 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1257 | 1257 | |
|
1258 | 1258 | waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1; |
|
1259 | 1259 | } |
|
1260 | 1260 | |
|
1261 | 1261 | //***************** |
|
1262 | 1262 | // local parameters |
|
1263 | 1263 | |
|
1264 | 1264 | void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) |
|
1265 | 1265 | { |
|
1266 | 1266 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. |
|
1267 | 1267 | * |
|
1268 | 1268 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. |
|
1269 | 1269 | * @param sid is the source identifier of the packet being updated. |
|
1270 | 1270 | * |
|
1271 | 1271 | * REQ-LFR-SRS-5240 / SSS-CP-FS-590 |
|
1272 | 1272 | * The sequence counters shall wrap around from 2^14 to zero. |
|
1273 | 1273 | * The sequence counter shall start at zero at startup. |
|
1274 | 1274 | * |
|
1275 | 1275 | * REQ-LFR-SRS-5239 / SSS-CP-FS-580 |
|
1276 | 1276 | * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 |
|
1277 | 1277 | * |
|
1278 | 1278 | */ |
|
1279 | 1279 | |
|
1280 | 1280 | unsigned short *sequence_cnt; |
|
1281 | 1281 | unsigned short segmentation_grouping_flag; |
|
1282 | 1282 | unsigned short new_packet_sequence_control; |
|
1283 | 1283 | rtems_mode initial_mode_set; |
|
1284 | 1284 | rtems_mode current_mode_set; |
|
1285 | 1285 | rtems_status_code status; |
|
1286 | 1286 | |
|
1287 | 1287 | initial_mode_set = RTEMS_DEFAULT_MODES; |
|
1288 | 1288 | current_mode_set = RTEMS_DEFAULT_MODES; |
|
1289 | 1289 | sequence_cnt = NULL; |
|
1290 | 1290 | |
|
1291 | 1291 | //****************************************** |
|
1292 | 1292 | // CHANGE THE MODE OF THE CALLING RTEMS TASK |
|
1293 | 1293 | status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); |
|
1294 | 1294 | |
|
1295 | 1295 | if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) |
|
1296 | 1296 | || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) |
|
1297 | 1297 | || (sid == SID_BURST_CWF_F2) |
|
1298 | 1298 | || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) |
|
1299 | 1299 | || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) |
|
1300 | 1300 | || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) |
|
1301 | 1301 | || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) |
|
1302 | 1302 | || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) |
|
1303 | 1303 | { |
|
1304 | 1304 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; |
|
1305 | 1305 | } |
|
1306 | 1306 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) |
|
1307 | 1307 | || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) |
|
1308 | 1308 | || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) |
|
1309 | 1309 | || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) |
|
1310 | 1310 | { |
|
1311 | 1311 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; |
|
1312 | 1312 | } |
|
1313 | 1313 | else |
|
1314 | 1314 | { |
|
1315 | 1315 | sequence_cnt = (unsigned short *) NULL; |
|
1316 | 1316 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) |
|
1317 | 1317 | } |
|
1318 | 1318 | |
|
1319 | 1319 | if (sequence_cnt != NULL) |
|
1320 | 1320 | { |
|
1321 | 1321 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; |
|
1322 | 1322 | *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK; |
|
1323 | 1323 | |
|
1324 | 1324 | new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; |
|
1325 | 1325 | |
|
1326 | 1326 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); |
|
1327 | 1327 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1328 | 1328 | |
|
1329 | 1329 | // increment the sequence counter |
|
1330 | 1330 | if ( *sequence_cnt < SEQ_CNT_MAX) |
|
1331 | 1331 | { |
|
1332 | 1332 | *sequence_cnt = *sequence_cnt + 1; |
|
1333 | 1333 | } |
|
1334 | 1334 | else |
|
1335 | 1335 | { |
|
1336 | 1336 | *sequence_cnt = 0; |
|
1337 | 1337 | } |
|
1338 | 1338 | } |
|
1339 | 1339 | |
|
1340 | 1340 | //************************************* |
|
1341 | 1341 | // RESTORE THE MODE OF THE CALLING TASK |
|
1342 | 1342 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); |
|
1343 | 1343 | } |
General Comments 0
You need to be logged in to leave comments.
Login now