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