@@ -1,771 +1,771 | |||
|
1 | 1 | /** Functions and tasks related to TeleCommand handling. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle TeleCommands:\n |
|
7 | 7 | * action launching\n |
|
8 | 8 | * TC parsing\n |
|
9 | 9 | * ... |
|
10 | 10 | * |
|
11 | 11 | */ |
|
12 | 12 | |
|
13 | 13 | #include "tc_handler.h" |
|
14 | 14 | |
|
15 | 15 | //*********** |
|
16 | 16 | // RTEMS TASK |
|
17 | 17 | |
|
18 | 18 | rtems_task actn_task( rtems_task_argument unused ) |
|
19 | 19 | { |
|
20 | 20 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. |
|
21 | 21 | * |
|
22 | 22 | * @param unused is the starting argument of the RTEMS task |
|
23 | 23 | * |
|
24 | 24 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending |
|
25 | 25 | * on the incoming TeleCommand. |
|
26 | 26 | * |
|
27 | 27 | */ |
|
28 | 28 | |
|
29 | 29 | int result; |
|
30 | 30 | rtems_status_code status; // RTEMS status code |
|
31 | 31 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task |
|
32 | 32 | size_t size; // size of the incoming TC packet |
|
33 | 33 | unsigned char subtype; // subtype of the current TC packet |
|
34 | 34 | unsigned char time[6]; |
|
35 | 35 | rtems_id queue_rcv_id; |
|
36 | 36 | rtems_id queue_snd_id; |
|
37 | 37 | |
|
38 | 38 | status = rtems_message_queue_ident( misc_name[QUEUE_RECV], 0, &queue_rcv_id ); |
|
39 | 39 | if (status != RTEMS_SUCCESSFUL) |
|
40 | 40 | { |
|
41 | 41 | PRINTF1("in ACTN *** ERR getting queue_rcv_id %d\n", status) |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_snd_id ); |
|
45 | 45 | if (status != RTEMS_SUCCESSFUL) |
|
46 | 46 | { |
|
47 | 47 | PRINTF1("in ACTN *** ERR getting queue_snd_id %d\n", status) |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | result = LFR_SUCCESSFUL; |
|
51 | 51 | subtype = 0; // subtype of the current TC packet |
|
52 | 52 | |
|
53 | 53 | BOOT_PRINTF("in ACTN *** \n") |
|
54 | 54 | |
|
55 | 55 | while(1) |
|
56 | 56 | { |
|
57 | 57 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
58 | 58 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
59 | 59 | getTime( time ); // set time to the current time |
|
60 | 60 | if (status!=RTEMS_SUCCESSFUL) PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
61 | 61 | else |
|
62 | 62 | { |
|
63 | 63 | subtype = TC.serviceSubType; |
|
64 | 64 | switch(subtype) |
|
65 | 65 | { |
|
66 | 66 | case TC_SUBTYPE_RESET: |
|
67 | 67 | result = action_reset( &TC, queue_snd_id, time ); |
|
68 | 68 | close_action( &TC, result, queue_snd_id, time ); |
|
69 | 69 | break; |
|
70 | 70 | // |
|
71 | 71 | case TC_SUBTYPE_LOAD_COMM: |
|
72 | 72 | result = action_load_common_par( &TC ); |
|
73 | 73 | close_action( &TC, result, queue_snd_id, time ); |
|
74 | 74 | break; |
|
75 | 75 | // |
|
76 | 76 | case TC_SUBTYPE_LOAD_NORM: |
|
77 | 77 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
78 | 78 | close_action( &TC, result, queue_snd_id, time ); |
|
79 | 79 | break; |
|
80 | 80 | // |
|
81 | 81 | case TC_SUBTYPE_LOAD_BURST: |
|
82 | 82 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
83 | 83 | close_action( &TC, result, queue_snd_id, time ); |
|
84 | 84 | break; |
|
85 | 85 | // |
|
86 | 86 | case TC_SUBTYPE_LOAD_SBM1: |
|
87 | 87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
88 | 88 | close_action( &TC, result, queue_snd_id, time ); |
|
89 | 89 | break; |
|
90 | 90 | // |
|
91 | 91 | case TC_SUBTYPE_LOAD_SBM2: |
|
92 | 92 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
93 | 93 | close_action( &TC, result, queue_snd_id, time ); |
|
94 | 94 | break; |
|
95 | 95 | // |
|
96 | 96 | case TC_SUBTYPE_DUMP: |
|
97 | 97 | result = action_dump_par( queue_snd_id ); |
|
98 | 98 | close_action( &TC, result, queue_snd_id, time ); |
|
99 | 99 | break; |
|
100 | 100 | // |
|
101 | 101 | case TC_SUBTYPE_ENTER: |
|
102 | 102 | result = action_enter_mode( &TC, queue_snd_id, time ); |
|
103 | 103 | close_action( &TC, result, queue_snd_id, time ); |
|
104 | 104 | break; |
|
105 | 105 | // |
|
106 | 106 | case TC_SUBTYPE_UPDT_INFO: |
|
107 | 107 | result = action_update_info( &TC, queue_snd_id ); |
|
108 | 108 | close_action( &TC, result, queue_snd_id, time ); |
|
109 | 109 | break; |
|
110 | 110 | // |
|
111 | 111 | case TC_SUBTYPE_EN_CAL: |
|
112 | 112 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
113 | 113 | close_action( &TC, result, queue_snd_id, time ); |
|
114 | 114 | break; |
|
115 | 115 | // |
|
116 | 116 | case TC_SUBTYPE_DIS_CAL: |
|
117 | 117 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
118 | 118 | close_action( &TC, result, queue_snd_id, time ); |
|
119 | 119 | break; |
|
120 | 120 | // |
|
121 | 121 | case TC_SUBTYPE_UPDT_TIME: |
|
122 | 122 | result = action_update_time( &TC ); |
|
123 | 123 | close_action( &TC, result, queue_snd_id, time ); |
|
124 | 124 | break; |
|
125 | 125 | // |
|
126 | 126 | default: |
|
127 | 127 | break; |
|
128 | 128 | } |
|
129 | 129 | } |
|
130 | 130 | } |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | //*********** |
|
134 | 134 | // TC ACTIONS |
|
135 | 135 | |
|
136 | 136 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
137 | 137 | { |
|
138 | 138 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
139 | 139 | * |
|
140 | 140 | * @param TC points to the TeleCommand packet that is being processed |
|
141 | 141 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
142 | 142 | * |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
146 | 146 | return LFR_DEFAULT; |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
150 | 150 | { |
|
151 | 151 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
152 | 152 | * |
|
153 | 153 | * @param TC points to the TeleCommand packet that is being processed |
|
154 | 154 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
155 | 155 | * |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | rtems_status_code status; |
|
159 | 159 | unsigned char requestedMode; |
|
160 | 160 | |
|
161 | 161 | requestedMode = TC->dataAndCRC[1]; |
|
162 | 162 | |
|
163 | 163 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
164 | 164 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
165 | 165 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
166 | 166 | { |
|
167 | 167 | status = RTEMS_UNSATISFIED; |
|
168 | 168 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_LFR_MODE, requestedMode, time ); |
|
169 | 169 | } |
|
170 | 170 | else |
|
171 | 171 | { |
|
172 | 172 | printf("try to enter mode %d\n", requestedMode); |
|
173 | 173 | |
|
174 | 174 | #ifdef PRINT_TASK_STATISTICS |
|
175 | 175 | if (requestedMode != LFR_MODE_STANDBY) |
|
176 | 176 | { |
|
177 | 177 | rtems_cpu_usage_reset(); |
|
178 | 178 | maxCount = 0; |
|
179 | 179 | } |
|
180 | 180 | #endif |
|
181 | 181 | |
|
182 | 182 | status = transition_validation(requestedMode); |
|
183 | 183 | |
|
184 | 184 | if ( status == LFR_SUCCESSFUL ) { |
|
185 | 185 | if ( lfrCurrentMode != LFR_MODE_STANDBY) |
|
186 | 186 | { |
|
187 | 187 | status = stop_current_mode(); |
|
188 | 188 | } |
|
189 | 189 | if (status != RTEMS_SUCCESSFUL) |
|
190 | 190 | { |
|
191 | 191 | PRINTF("ERR *** in action_enter *** stop_current_mode\n") |
|
192 | 192 | } |
|
193 | 193 | status = enter_mode(requestedMode, TC); |
|
194 | 194 | } |
|
195 | 195 | else |
|
196 | 196 | { |
|
197 | 197 | PRINTF("ERR *** in action_enter *** transition rejected\n") |
|
198 | 198 | send_tm_lfr_tc_exe_not_executable( TC, queue_id, time ); |
|
199 | 199 | } |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | return status; |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
206 | 206 | { |
|
207 | 207 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
208 | 208 | * |
|
209 | 209 | * @param TC points to the TeleCommand packet that is being processed |
|
210 | 210 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
211 | 211 | * |
|
212 | 212 | * @return LFR directive status code: |
|
213 | 213 | * - LFR_DEFAULT |
|
214 | 214 | * - LFR_SUCCESSFUL |
|
215 | 215 | * |
|
216 | 216 | */ |
|
217 | 217 | |
|
218 | 218 | unsigned int val; |
|
219 | 219 | int result; |
|
220 | 220 | |
|
221 |
result = LFR_ |
|
|
221 | result = LFR_SUCCESSFUL; | |
|
222 | 222 | |
|
223 | 223 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 |
|
224 | 224 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
225 | 225 | val++; |
|
226 | 226 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); |
|
227 | 227 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
228 | 228 | |
|
229 | 229 | return result; |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
233 | 233 | { |
|
234 | 234 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
235 | 235 | * |
|
236 | 236 | * @param TC points to the TeleCommand packet that is being processed |
|
237 | 237 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
238 | 238 | * |
|
239 | 239 | */ |
|
240 | 240 | |
|
241 | 241 | int result; |
|
242 | 242 | unsigned char lfrMode; |
|
243 | 243 | |
|
244 | 244 | result = LFR_DEFAULT; |
|
245 | 245 | lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
246 | 246 | |
|
247 | 247 | if ( (lfrMode == LFR_MODE_STANDBY) || (lfrMode == LFR_MODE_BURST) || (lfrMode == LFR_MODE_SBM2) ) { |
|
248 | 248 | send_tm_lfr_tc_exe_not_executable( TC, queue_id, time ); |
|
249 | 249 | result = LFR_DEFAULT; |
|
250 | 250 | } |
|
251 | 251 | else { |
|
252 | 252 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
253 | 253 | result = LFR_DEFAULT; |
|
254 | 254 | } |
|
255 | 255 | return result; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
259 | 259 | { |
|
260 | 260 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
261 | 261 | * |
|
262 | 262 | * @param TC points to the TeleCommand packet that is being processed |
|
263 | 263 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
264 | 264 | * |
|
265 | 265 | */ |
|
266 | 266 | |
|
267 | 267 | int result; |
|
268 | 268 | unsigned char lfrMode; |
|
269 | 269 | |
|
270 | 270 | result = LFR_DEFAULT; |
|
271 | 271 | lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
272 | 272 | |
|
273 | 273 | if ( (lfrMode == LFR_MODE_STANDBY) || (lfrMode == LFR_MODE_BURST) || (lfrMode == LFR_MODE_SBM2) ) { |
|
274 | 274 | send_tm_lfr_tc_exe_not_executable( TC, queue_id, time ); |
|
275 | 275 | result = LFR_DEFAULT; |
|
276 | 276 | } |
|
277 | 277 | else { |
|
278 | 278 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
279 | 279 | result = LFR_DEFAULT; |
|
280 | 280 | } |
|
281 | 281 | return result; |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
285 | 285 | { |
|
286 | 286 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
287 | 287 | * |
|
288 | 288 | * @param TC points to the TeleCommand packet that is being processed |
|
289 | 289 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
290 | 290 | * |
|
291 | 291 | * @return LFR_SUCCESSFUL |
|
292 | 292 | * |
|
293 | 293 | */ |
|
294 | 294 | |
|
295 | 295 | unsigned int val; |
|
296 | 296 | |
|
297 | 297 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
298 | 298 | + (TC->dataAndCRC[1] << 16) |
|
299 | 299 | + (TC->dataAndCRC[2] << 8) |
|
300 | 300 | + TC->dataAndCRC[3]; |
|
301 | 301 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 |
|
302 | 302 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
303 | 303 | val++; |
|
304 | 304 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); |
|
305 | 305 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
306 | 306 | time_management_regs->ctrl = time_management_regs->ctrl | 1; |
|
307 | 307 | |
|
308 | 308 | return LFR_SUCCESSFUL; |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | //******************* |
|
312 | 312 | // ENTERING THE MODES |
|
313 | 313 | |
|
314 | 314 | int transition_validation(unsigned char requestedMode) |
|
315 | 315 | { |
|
316 | 316 | int status; |
|
317 | 317 | |
|
318 | 318 | switch (requestedMode) |
|
319 | 319 | { |
|
320 | 320 | case LFR_MODE_STANDBY: |
|
321 | 321 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
322 | 322 | status = LFR_DEFAULT; |
|
323 | 323 | } |
|
324 | 324 | else |
|
325 | 325 | { |
|
326 | 326 | status = LFR_SUCCESSFUL; |
|
327 | 327 | } |
|
328 | 328 | break; |
|
329 | 329 | case LFR_MODE_NORMAL: |
|
330 | 330 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
331 | 331 | status = LFR_DEFAULT; |
|
332 | 332 | } |
|
333 | 333 | else { |
|
334 | 334 | status = LFR_SUCCESSFUL; |
|
335 | 335 | } |
|
336 | 336 | break; |
|
337 | 337 | case LFR_MODE_BURST: |
|
338 | 338 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
339 | 339 | status = LFR_DEFAULT; |
|
340 | 340 | } |
|
341 | 341 | else { |
|
342 | 342 | status = LFR_SUCCESSFUL; |
|
343 | 343 | } |
|
344 | 344 | break; |
|
345 | 345 | case LFR_MODE_SBM1: |
|
346 | 346 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
347 | 347 | status = LFR_DEFAULT; |
|
348 | 348 | } |
|
349 | 349 | else { |
|
350 | 350 | status = LFR_SUCCESSFUL; |
|
351 | 351 | } |
|
352 | 352 | break; |
|
353 | 353 | case LFR_MODE_SBM2: |
|
354 | 354 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
355 | 355 | status = LFR_DEFAULT; |
|
356 | 356 | } |
|
357 | 357 | else { |
|
358 | 358 | status = LFR_SUCCESSFUL; |
|
359 | 359 | } |
|
360 | 360 | break; |
|
361 | 361 | default: |
|
362 | 362 | status = LFR_DEFAULT; |
|
363 | 363 | break; |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | return status; |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | int stop_current_mode() |
|
370 | 370 | { |
|
371 | 371 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
372 | 372 | * |
|
373 | 373 | * @return RTEMS directive status codes: |
|
374 | 374 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
375 | 375 | * - RTEMS_INVALID_ID - task id invalid |
|
376 | 376 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
377 | 377 | * |
|
378 | 378 | */ |
|
379 | 379 | |
|
380 | 380 | rtems_status_code status; |
|
381 | 381 | |
|
382 | 382 | status = RTEMS_SUCCESSFUL; |
|
383 | 383 | |
|
384 | 384 | #ifdef GSA |
|
385 | 385 | LEON_Mask_interrupt( IRQ_WF ); // mask waveform interrupt (coming from the timer VHDL IP) |
|
386 | 386 | LEON_Clear_interrupt( IRQ_WF ); // clear waveform interrupt (coming from the timer VHDL IP) |
|
387 | 387 | timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR ); |
|
388 | 388 | #else |
|
389 | 389 | // mask interruptions |
|
390 | 390 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
391 | 391 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt |
|
392 | 392 | // reset registers |
|
393 | 393 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
394 | 394 | reset_wfp_status(); // reset all the status bits |
|
395 | 395 | // creal interruptions |
|
396 | 396 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
397 | 397 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectarl matrix interrupt |
|
398 | 398 | #endif |
|
399 | 399 | //********************** |
|
400 | 400 | // suspend several tasks |
|
401 | 401 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
402 | 402 | status = suspend_science_tasks(); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | if (status != RTEMS_SUCCESSFUL) |
|
406 | 406 | { |
|
407 | 407 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
408 | 408 | } |
|
409 | 409 | |
|
410 | 410 | return status; |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | int enter_mode(unsigned char mode, ccsdsTelecommandPacket_t *TC ) |
|
414 | 414 | { |
|
415 | 415 | rtems_status_code status; |
|
416 | 416 | |
|
417 | 417 | status = RTEMS_UNSATISFIED; |
|
418 | 418 | |
|
419 | 419 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d); |
|
420 | 420 | updateLFRCurrentMode(); |
|
421 | 421 | |
|
422 | 422 | switch(mode){ |
|
423 | 423 | case LFR_MODE_STANDBY: |
|
424 | 424 | status = enter_standby_mode( ); |
|
425 | 425 | break; |
|
426 | 426 | case LFR_MODE_NORMAL: |
|
427 | 427 | status = enter_normal_mode( ); |
|
428 | 428 | break; |
|
429 | 429 | case LFR_MODE_BURST: |
|
430 | 430 | status = enter_burst_mode( ); |
|
431 | 431 | break; |
|
432 | 432 | case LFR_MODE_SBM1: |
|
433 | 433 | status = enter_sbm1_mode( ); |
|
434 | 434 | break; |
|
435 | 435 | case LFR_MODE_SBM2: |
|
436 | 436 | status = enter_sbm2_mode( ); |
|
437 | 437 | break; |
|
438 | 438 | default: |
|
439 | 439 | status = RTEMS_UNSATISFIED; |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | if (status != RTEMS_SUCCESSFUL) |
|
443 | 443 | { |
|
444 | 444 | PRINTF("in enter_mode *** ERR\n") |
|
445 | 445 | status = RTEMS_UNSATISFIED; |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | 448 | return status; |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | int enter_standby_mode() |
|
452 | 452 | { |
|
453 | 453 | PRINTF1("maxCount = %d\n", maxCount) |
|
454 | 454 | |
|
455 | 455 | #ifdef PRINT_TASK_STATISTICS |
|
456 | 456 | rtems_cpu_usage_report(); |
|
457 | 457 | #endif |
|
458 | 458 | |
|
459 | 459 | #ifdef PRINT_STACK_REPORT |
|
460 | 460 | rtems_stack_checker_report_usage(); |
|
461 | 461 | #endif |
|
462 | 462 | |
|
463 | 463 | return LFR_SUCCESSFUL; |
|
464 | 464 | } |
|
465 | 465 | |
|
466 | 466 | int enter_normal_mode() |
|
467 | 467 | { |
|
468 | 468 | rtems_status_code status; |
|
469 | 469 | |
|
470 | 470 | status = restart_science_tasks(); |
|
471 | 471 | |
|
472 | 472 | #ifdef GSA |
|
473 | 473 | timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR ); |
|
474 | 474 | timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); |
|
475 | 475 | LEON_Clear_interrupt( IRQ_WF ); |
|
476 | 476 | LEON_Unmask_interrupt( IRQ_WF ); |
|
477 | 477 | // |
|
478 | 478 | set_local_nb_interrupt_f0_MAX(); |
|
479 | 479 | LEON_Clear_interrupt( IRQ_SM ); // the IRQ_SM seems to be incompatible with the IRQ_WF on the xilinx board |
|
480 | 480 | LEON_Unmask_interrupt( IRQ_SM ); |
|
481 | 481 | #else |
|
482 | 482 | //**************** |
|
483 | 483 | // waveform picker |
|
484 | 484 | reset_waveform_picker_regs(); |
|
485 | 485 | set_wfp_burst_enable_register(LFR_MODE_NORMAL); |
|
486 | 486 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
487 | 487 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
488 | 488 | //**************** |
|
489 | 489 | // spectral matrix |
|
490 | 490 | #endif |
|
491 | 491 | |
|
492 | 492 | return status; |
|
493 | 493 | } |
|
494 | 494 | |
|
495 | 495 | int enter_burst_mode() |
|
496 | 496 | { |
|
497 | 497 | rtems_status_code status; |
|
498 | 498 | |
|
499 | 499 | status = restart_science_tasks(); |
|
500 | 500 | |
|
501 | 501 | #ifdef GSA |
|
502 | 502 | LEON_Unmask_interrupt( IRQ_SM ); |
|
503 | 503 | #else |
|
504 | 504 | reset_waveform_picker_regs(); |
|
505 | 505 | set_wfp_burst_enable_register(LFR_MODE_BURST); |
|
506 | 506 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
507 | 507 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
508 | 508 | #endif |
|
509 | 509 | |
|
510 | 510 | return status; |
|
511 | 511 | } |
|
512 | 512 | |
|
513 | 513 | int enter_sbm1_mode() |
|
514 | 514 | { |
|
515 | 515 | rtems_status_code status; |
|
516 | 516 | |
|
517 | 517 | status = restart_science_tasks(); |
|
518 | 518 | |
|
519 | 519 | set_local_sbm1_nb_cwf_max(); |
|
520 | 520 | |
|
521 | 521 | reset_local_sbm1_nb_cwf_sent(); |
|
522 | 522 | |
|
523 | 523 | #ifdef GSA |
|
524 | 524 | LEON_Unmask_interrupt( IRQ_SM ); |
|
525 | 525 | #else |
|
526 | 526 | reset_waveform_picker_regs(); |
|
527 | 527 | set_wfp_burst_enable_register(LFR_MODE_SBM1); |
|
528 | 528 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
529 | 529 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
530 | 530 | // SM simulation |
|
531 | 531 | // timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); |
|
532 | 532 | // LEON_Clear_interrupt( IRQ_SM ); // the IRQ_SM seems to be incompatible with the IRQ_WF on the xilinx board |
|
533 | 533 | // LEON_Unmask_interrupt( IRQ_SM ); |
|
534 | 534 | #endif |
|
535 | 535 | |
|
536 | 536 | return status; |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | int enter_sbm2_mode() |
|
540 | 540 | { |
|
541 | 541 | rtems_status_code status; |
|
542 | 542 | |
|
543 | 543 | status = restart_science_tasks(); |
|
544 | 544 | |
|
545 | 545 | set_local_sbm2_nb_cwf_max(); |
|
546 | 546 | |
|
547 | 547 | reset_local_sbm2_nb_cwf_sent(); |
|
548 | 548 | |
|
549 | 549 | #ifdef GSA |
|
550 | 550 | LEON_Unmask_interrupt( IRQ_SM ); |
|
551 | 551 | #else |
|
552 | 552 | reset_waveform_picker_regs(); |
|
553 | 553 | set_wfp_burst_enable_register(LFR_MODE_SBM2); |
|
554 | 554 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
555 | 555 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
556 | 556 | #endif |
|
557 | 557 | |
|
558 | 558 | return status; |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | int restart_science_tasks() |
|
562 | 562 | { |
|
563 | 563 | rtems_status_code status[6]; |
|
564 | 564 | rtems_status_code ret; |
|
565 | 565 | |
|
566 | 566 | ret = RTEMS_SUCCESSFUL; |
|
567 | 567 | |
|
568 | 568 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], 1 ); |
|
569 | 569 | if (status[0] != RTEMS_SUCCESSFUL) |
|
570 | 570 | { |
|
571 | 571 | PRINTF1("in restart_science_task *** 0 ERR %d\n", status[0]) |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | status[1] = rtems_task_restart( Task_id[TASKID_BPF0],1 ); |
|
575 | 575 | if (status[1] != RTEMS_SUCCESSFUL) |
|
576 | 576 | { |
|
577 | 577 | PRINTF1("in restart_science_task *** 1 ERR %d\n", status[1]) |
|
578 | 578 | } |
|
579 | 579 | |
|
580 | 580 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
581 | 581 | if (status[2] != RTEMS_SUCCESSFUL) |
|
582 | 582 | { |
|
583 | 583 | PRINTF1("in restart_science_task *** 2 ERR %d\n", status[2]) |
|
584 | 584 | } |
|
585 | 585 | |
|
586 | 586 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
587 | 587 | if (status[3] != RTEMS_SUCCESSFUL) |
|
588 | 588 | { |
|
589 | 589 | PRINTF1("in restart_science_task *** 3 ERR %d\n", status[3]) |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
593 | 593 | if (status[4] != RTEMS_SUCCESSFUL) |
|
594 | 594 | { |
|
595 | 595 | PRINTF1("in restart_science_task *** 4 ERR %d\n", status[4]) |
|
596 | 596 | } |
|
597 | 597 | |
|
598 | 598 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
599 | 599 | if (status[5] != RTEMS_SUCCESSFUL) |
|
600 | 600 | { |
|
601 | 601 | PRINTF1("in restart_science_task *** 5 ERR %d\n", status[5]) |
|
602 | 602 | } |
|
603 | 603 | |
|
604 | 604 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || (status[2] != RTEMS_SUCCESSFUL) || |
|
605 | 605 | (status[3] != RTEMS_SUCCESSFUL) || (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) |
|
606 | 606 | { |
|
607 | 607 | ret = RTEMS_UNSATISFIED; |
|
608 | 608 | } |
|
609 | 609 | |
|
610 | 610 | return ret; |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | int suspend_science_tasks() |
|
614 | 614 | { |
|
615 | 615 | /** This function suspends the science tasks. |
|
616 | 616 | * |
|
617 | 617 | * @return RTEMS directive status codes: |
|
618 | 618 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
619 | 619 | * - RTEMS_INVALID_ID - task id invalid |
|
620 | 620 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
621 | 621 | * |
|
622 | 622 | */ |
|
623 | 623 | |
|
624 | 624 | rtems_status_code status; |
|
625 | 625 | |
|
626 | 626 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); |
|
627 | 627 | if (status != RTEMS_SUCCESSFUL) |
|
628 | 628 | { |
|
629 | 629 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
630 | 630 | } |
|
631 | 631 | |
|
632 | 632 | if (status == RTEMS_SUCCESSFUL) // suspend BPF0 |
|
633 | 633 | { |
|
634 | 634 | status = rtems_task_suspend( Task_id[TASKID_BPF0] ); |
|
635 | 635 | if (status != RTEMS_SUCCESSFUL) |
|
636 | 636 | { |
|
637 | 637 | PRINTF1("in suspend_science_task *** BPF0 ERR %d\n", status) |
|
638 | 638 | } |
|
639 | 639 | } |
|
640 | 640 | |
|
641 | 641 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
642 | 642 | { |
|
643 | 643 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
644 | 644 | if (status != RTEMS_SUCCESSFUL) |
|
645 | 645 | { |
|
646 | 646 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
647 | 647 | } |
|
648 | 648 | } |
|
649 | 649 | |
|
650 | 650 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
651 | 651 | { |
|
652 | 652 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
653 | 653 | if (status != RTEMS_SUCCESSFUL) |
|
654 | 654 | { |
|
655 | 655 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
656 | 656 | } |
|
657 | 657 | } |
|
658 | 658 | |
|
659 | 659 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
660 | 660 | { |
|
661 | 661 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
662 | 662 | if (status != RTEMS_SUCCESSFUL) |
|
663 | 663 | { |
|
664 | 664 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
665 | 665 | } |
|
666 | 666 | } |
|
667 | 667 | |
|
668 | 668 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
669 | 669 | { |
|
670 | 670 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
671 | 671 | if (status != RTEMS_SUCCESSFUL) |
|
672 | 672 | { |
|
673 | 673 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
674 | 674 | } |
|
675 | 675 | } |
|
676 | 676 | |
|
677 | 677 | return status; |
|
678 | 678 | } |
|
679 | 679 | |
|
680 | 680 | //**************** |
|
681 | 681 | // CLOSING ACTIONS |
|
682 | 682 | void update_last_TC_exe(ccsdsTelecommandPacket_t *TC, unsigned char *time) |
|
683 | 683 | { |
|
684 | 684 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
685 | 685 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
686 | 686 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; |
|
687 | 687 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
688 | 688 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; |
|
689 | 689 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
690 | 690 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; |
|
691 | 691 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; |
|
692 | 692 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; |
|
693 | 693 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; |
|
694 | 694 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; |
|
695 | 695 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; |
|
696 | 696 | } |
|
697 | 697 | |
|
698 | 698 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char *time) |
|
699 | 699 | { |
|
700 | 700 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
701 | 701 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
702 | 702 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; |
|
703 | 703 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
704 | 704 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; |
|
705 | 705 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
706 | 706 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; |
|
707 | 707 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; |
|
708 | 708 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; |
|
709 | 709 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; |
|
710 | 710 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; |
|
711 | 711 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; |
|
712 | 712 | } |
|
713 | 713 | |
|
714 | 714 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id, unsigned char *time) |
|
715 | 715 | { |
|
716 | 716 | unsigned int val = 0; |
|
717 | 717 | |
|
718 | 718 | if (result == LFR_SUCCESSFUL) |
|
719 | 719 | { |
|
720 | 720 | if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
721 | 721 | && |
|
722 | 722 | !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
723 | 723 | ) |
|
724 | 724 | { |
|
725 | 725 | send_tm_lfr_tc_exe_success( TC, queue_id, time ); |
|
726 | 726 | } |
|
727 | 727 | update_last_TC_exe( TC, time ); |
|
728 | 728 | val = housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[0] * 256 + housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[1]; |
|
729 | 729 | val++; |
|
730 | 730 | housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[0] = (unsigned char) (val >> 8); |
|
731 | 731 | housekeeping_packet.hk_dpu_exe_tc_lfr_cnt[1] = (unsigned char) (val); |
|
732 | 732 | } |
|
733 | 733 | else |
|
734 | 734 | { |
|
735 | 735 | update_last_TC_rej( TC, time ); |
|
736 | 736 | val = housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[0] * 256 + housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[1]; |
|
737 | 737 | val++; |
|
738 | 738 | housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[0] = (unsigned char) (val >> 8); |
|
739 | 739 | housekeeping_packet.hk_dpu_rej_tc_lfr_cnt[1] = (unsigned char) (val); |
|
740 | 740 | } |
|
741 | 741 | } |
|
742 | 742 | |
|
743 | 743 | //*************************** |
|
744 | 744 | // Interrupt Service Routines |
|
745 | 745 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
746 | 746 | { |
|
747 | 747 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
748 | 748 | printf("In commutation_isr1 *** Error sending event to DUMB\n"); |
|
749 | 749 | } |
|
750 | 750 | } |
|
751 | 751 | |
|
752 | 752 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
753 | 753 | { |
|
754 | 754 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
755 | 755 | printf("In commutation_isr2 *** Error sending event to DUMB\n"); |
|
756 | 756 | } |
|
757 | 757 | } |
|
758 | 758 | |
|
759 | 759 | //**************** |
|
760 | 760 | // OTHER FUNCTIONS |
|
761 | 761 | void updateLFRCurrentMode() |
|
762 | 762 | { |
|
763 | 763 | /** This function updates the value of the global variable lfrCurrentMode. |
|
764 | 764 | * |
|
765 | 765 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
766 | 766 | * |
|
767 | 767 | */ |
|
768 | 768 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
769 | 769 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
770 | 770 | } |
|
771 | 771 |
General Comments 0
You need to be logged in to leave comments.
Login now