1 |
kusanagi |
1.1 |
/**************************************************************************** |
2 |
|
|
/* F i l e D a t a |
3 |
|
|
/* |
4 |
|
|
/* Module : HK_Manager_INFN |
5 |
|
|
/* C.I. No. : |
6 |
|
|
/* $Revision: 1.51 $ |
7 |
|
|
/* $Date: 2005/03/20 18:19:57 $ |
8 |
|
|
/* $Revision: 1.51 $ |
9 |
|
|
/* $Date: 2005/03/20 18:19:57 $ |
10 |
|
|
/* Belonging to : |
11 |
|
|
/* : |
12 |
|
|
/* $RCSfile: HK_Manager_INFN.c,v $ |
13 |
|
|
/* Program Type : |
14 |
|
|
/* Sub-modules : |
15 |
|
|
/* |
16 |
|
|
/**************************************************************************** |
17 |
|
|
/* S W D e v e l o p m e n t E n v i r o n m e n t |
18 |
|
|
/* |
19 |
|
|
/* Host system : |
20 |
|
|
/* SW Compiler : |
21 |
|
|
/* $Author: sebastiani $ |
22 |
|
|
/* : |
23 |
|
|
/**************************************************************************** |
24 |
|
|
/* U p d a t i n g |
25 |
|
|
/* |
26 |
|
|
/* |
27 |
|
|
/* |
28 |
|
|
/*****************************************************************************/ |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/*============================= Include File ================================*/ |
32 |
|
|
|
33 |
|
|
#include <src/INFN/LU_SourceFileID_INFN.h> |
34 |
|
|
#define __FILEID__ _HK_Manager_INFN__c |
35 |
|
|
#include <src/INFN/PRH_ParamHandler_INFN.h> |
36 |
|
|
#include <src/INFN/LU_LogUtility_INFN.h> |
37 |
|
|
#include <src/INFN/PRH_ParamHandler_INFN_auto.h> |
38 |
|
|
LU_DECL_MASK(); |
39 |
|
|
|
40 |
|
|
#include <src/TM_TCManager/TMTCManager/TM_TMTCManager_op.h> |
41 |
|
|
#include <src/INFN/HK_Manager_INFN.h> |
42 |
|
|
#include <src/INFN/HB_HKBuffer_INFN.h> |
43 |
|
|
#include <src/INFN/KHB_Driver_INFN.h> |
44 |
|
|
#include <src/INFN/GS_Gas_INFN.h> |
45 |
|
|
#include <src/BasicSW/TimingInfo/TI_TimingInfo_p.h> |
46 |
|
|
|
47 |
|
|
static TI_TIME HK_LastTCHLCall = 0; |
48 |
|
|
static int HK_KHBBusyFlag = FALSE; |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
/*****************************************************************************/ |
52 |
|
|
/*============================= Object variables ============================*/ |
53 |
|
|
|
54 |
|
|
/*****************************************************************************/ |
55 |
|
|
|
56 |
|
|
/* P a y l o a d s O P E R A T I O N A L F U N C T I O N S */ |
57 |
|
|
|
58 |
|
|
/*****************************************************************************/ |
59 |
|
|
/* @Function: HK_InitHKManager */ |
60 |
|
|
/* @Purpose : */ |
61 |
|
|
/* Initialialization function of the HK component. */ |
62 |
|
|
/* */ |
63 |
|
|
/* @@ */ |
64 |
|
|
/* @Parameter Name @Mode @Description */ |
65 |
|
|
/* status_code OUT Return code */ |
66 |
|
|
/* @@ */ |
67 |
|
|
/*****************************************************************************/ |
68 |
|
|
|
69 |
|
|
status_code HK_InitHKManager (void) |
70 |
|
|
{ |
71 |
|
|
status_code status; |
72 |
|
|
void * p; |
73 |
|
|
unsigned short * pR; |
74 |
|
|
unsigned int OldPriority; |
75 |
|
|
|
76 |
|
|
// Task initialization |
77 |
|
|
|
78 |
|
|
if ((status=OS_piTaskReady_INFN(HK_INFN_TASK,HK_tkHKManager)) != SUCCESSFUL) |
79 |
|
|
{ |
80 |
|
|
/*@LOG Task is not correctly started - status */ |
81 |
|
|
LU_INFN_LOG (LU_CRITICAL, LU_MASK(__FILEID__), __FILEID__, __LINE__, status); |
82 |
|
|
|
83 |
|
|
status = UNSATISFIED; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
if ( (status=OS_piTaskPriority_INFN(HK_INFN_TASK, HK_MANAGER_PRIORITY, &OldPriority)) != SUCCESSFUL) |
87 |
|
|
{ |
88 |
|
|
/*@LOG Task priority is not correctly updated - status*/ |
89 |
|
|
LU_INFN_LOG (LU_CRITICAL, LU_MASK(__FILEID__), __FILEID__, __LINE__, status); |
90 |
|
|
|
91 |
|
|
status = UNSATISFIED; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
return (status); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/*****************************************************************************/ |
98 |
|
|
/* @Function: HK_SndMsgHKManager */ |
99 |
|
|
/* @Purpose : */ |
100 |
|
|
/* The function invokes the directive of the OS to send a message to the */ |
101 |
|
|
/* HKManager mailbox. */ |
102 |
|
|
/* */ |
103 |
|
|
/* @@ */ |
104 |
|
|
/* @Parameter Name @Mode @Description */ |
105 |
|
|
/* SndMsg IN Message buffer that contains task operation */ |
106 |
|
|
/* status_code OUT Return code */ |
107 |
|
|
/* @@ */ |
108 |
|
|
/*****************************************************************************/ |
109 |
|
|
|
110 |
|
|
status_code HK_SndMsgHKManager (MsgTsk* SndMsg) |
111 |
|
|
{ |
112 |
|
|
status_code status; |
113 |
|
|
|
114 |
|
|
// Send message to HK_SndMsgHKManager task mailbox |
115 |
|
|
|
116 |
|
|
status = OS_piMsgQueueSend_INFN(HK_INFN_MAILBOX, (void *) SndMsg, sizeof(MsgTsk)); |
117 |
|
|
switch(status) { |
118 |
|
|
case RTEMS_TOO_MANY: |
119 |
|
|
/*@LOG Too many messages in task queue - status */ |
120 |
|
|
LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__, status); |
121 |
|
|
break; |
122 |
|
|
case RTEMS_SUCCESSFUL: |
123 |
|
|
break; |
124 |
|
|
default: |
125 |
|
|
/*@LOG unrecognized error in sendin message - status */ |
126 |
|
|
LU_INFN_LOG (LU_CRITICAL, LU_MASK(__FILEID__), __FILEID__, __LINE__, status); |
127 |
|
|
break; |
128 |
|
|
} |
129 |
|
|
return (status); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
#define HK_EndOfOp(status_ptr,stat,taskid) do { \ |
133 |
|
|
*(status_code*)(status_ptr) = (stat); \ |
134 |
|
|
rtems_event_send((taskid),OS_EVENT_HK_DONE); \ |
135 |
|
|
} while (0) |
136 |
|
|
|
137 |
|
|
|
138 |
|
|
status_code HK_RestoreSavedCommands() |
139 |
|
|
{ |
140 |
|
|
UINT32 task_id,status_ptr; |
141 |
|
|
UINT32 size; |
142 |
|
|
MsgTsk Msg; |
143 |
|
|
status_code s; |
144 |
|
|
BYTE *p; |
145 |
|
|
BYTE tmp; |
146 |
|
|
while(OS_piMsgQueueReceive_INFN(SAVED_HK_MAILBOX,&Msg,&size,RTEMS_NO_WAIT,0) == CM_RC_SUCCESSFUL) |
147 |
|
|
{ |
148 |
|
|
s = OS_piMsgQueueSend_INFN(HK_INFN_MAILBOX,&Msg,sizeof(Msg)); |
149 |
|
|
if (s != CM_RC_SUCCESSFUL) |
150 |
|
|
{ |
151 |
|
|
p=Msg.Info; |
152 |
|
|
CM_READ_BE_UINT32(p,task_id,tmp); |
153 |
|
|
CM_READ_BE_UINT32(p,status_ptr,tmp); |
154 |
|
|
HK_EndOfOp(status_ptr,s,task_id); |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
return CM_RC_SUCCESSFUL; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
|
161 |
|
|
#define _HK_FILTER_TM(tm_id,dest,source) do { \ |
162 |
|
|
switch(PRH_ARR_TM_FILTER_OPERATION[tm_id]) { \ |
163 |
|
|
case 1: \ |
164 |
|
|
dest[tm_id]=PRH_ARR_TM_FILTER_VALUE[tm_id]; \ |
165 |
|
|
break; \ |
166 |
|
|
case 2: \ |
167 |
|
|
dest[tm_id]=source[tm_id] | PRH_ARR_TM_FILTER_VALUE[tm_id]; \ |
168 |
|
|
break; \ |
169 |
|
|
case 3: \ |
170 |
|
|
dest[tm_id]=source[tm_id] & PRH_ARR_TM_FILTER_VALUE[tm_id]; \ |
171 |
|
|
break; \ |
172 |
|
|
default: \ |
173 |
|
|
dest[tm_id]=source[tm_id]; \ |
174 |
|
|
break; \ |
175 |
|
|
} } while(0) |
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
void HK_FILTER_TM(TM_TELEMETRY tm_id,UINT32 *value) |
180 |
|
|
{ |
181 |
|
|
switch(PRH_ARR_TM_FILTER_OPERATION[tm_id]) { |
182 |
|
|
case 1: |
183 |
|
|
*value=PRH_ARR_TM_FILTER_VALUE[tm_id]; |
184 |
|
|
break; |
185 |
|
|
case 2: |
186 |
|
|
*value |= PRH_ARR_TM_FILTER_VALUE[tm_id]; |
187 |
|
|
break; |
188 |
|
|
case 3: |
189 |
|
|
*value &= PRH_ARR_TM_FILTER_VALUE[tm_id]; |
190 |
|
|
break; |
191 |
|
|
default: |
192 |
|
|
// let the value untouched |
193 |
|
|
break; |
194 |
|
|
} |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
|
198 |
|
|
/*****************************************************************************/ |
199 |
|
|
/* @Function: HK_tkHKManager */ |
200 |
|
|
/* @Purpose : */ |
201 |
|
|
/* The function is the task handler of the HK_tkHKManager object. */ |
202 |
|
|
/* When a message is received into task mailbox it wakes up. */ |
203 |
|
|
/* The information contained in the message (MsgTsk structure) define */ |
204 |
|
|
/* parameters (Info field), and the operation type that the task performs */ |
205 |
|
|
/* (Code field). */ |
206 |
|
|
/* The HK_tkHKManager task activity is to activate the cyclic telemetry */ |
207 |
|
|
/* acquisitin. */ |
208 |
|
|
/* */ |
209 |
|
|
/* @@ */ |
210 |
|
|
/* @Parameter Name @Mode @Description */ |
211 |
|
|
/* @@ */ |
212 |
|
|
/*****************************************************************************/ |
213 |
|
|
|
214 |
|
|
|
215 |
|
|
task HK_tkHKManager (task_argument unused) |
216 |
|
|
{ |
217 |
|
|
status_code status; |
218 |
|
|
MsgTsk RxMsg; |
219 |
|
|
unsigned int MsgSize; |
220 |
|
|
UINT32 taskid,status_ptr,code,value,value_ptr,all_values_ptr; |
221 |
|
|
BYTE *p,tmp; |
222 |
|
|
BOOL HK_KHB_lock = FALSE; |
223 |
|
|
BYTE counter,link; |
224 |
|
|
UINT32 combuf; |
225 |
|
|
UINT32 saved_outbuf; |
226 |
|
|
UINT32 saved_status_ptr; |
227 |
|
|
UINT32 saved_taskid; |
228 |
|
|
UINT32 saved_expected; |
229 |
|
|
UINT32 timeout = 0; |
230 |
|
|
UINT32 saved_retry_counter; |
231 |
|
|
TM_TELEMETRY tm; |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
while (FOREVER) |
235 |
|
|
{ |
236 |
|
|
|
237 |
|
|
RxMsg.Code = NULL_MSG_TM; |
238 |
|
|
|
239 |
|
|
// Wait for a message to become available |
240 |
|
|
|
241 |
|
|
if ((status = OS_piMsgQueueReceive_INFN(HK_INFN_MAILBOX, (void *) &RxMsg, &MsgSize, WAIT, NO_TIMEOUT)) == SUCCESSFUL) |
242 |
|
|
{ |
243 |
|
|
p = RxMsg.Info; |
244 |
|
|
CM_READ_BE_UINT32(p,taskid,tmp); |
245 |
|
|
CM_READ_BE_UINT32(p,status_ptr,tmp); |
246 |
|
|
|
247 |
|
|
switch (RxMsg.Code) |
248 |
|
|
{ |
249 |
|
|
case HK_SAVE_TMTC_VALUES : |
250 |
|
|
status = HB_StoreTMTC(); |
251 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
252 |
|
|
break; |
253 |
|
|
|
254 |
|
|
case HK_CYCLIC_ACQUISITION : |
255 |
|
|
if (HK_KHB_lock) { |
256 |
|
|
status = OS_piMsgQueueSend_INFN(SAVED_HK_MAILBOX,(void*)&RxMsg,sizeof(RxMsg)); |
257 |
|
|
if(status != CM_RC_SUCCESSFUL) |
258 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
259 |
|
|
} else { |
260 |
|
|
UINT32 *tm_value; |
261 |
|
|
CM_READ_BE_UINT32(p,all_values_ptr,tmp); |
262 |
|
|
TM_DoCyclicAcq(); |
263 |
|
|
TM_piGetAllTMValue((void*)all_values_ptr); |
264 |
|
|
tm_value=(UINT32*)all_values_ptr; |
265 |
|
|
for(tm=TM_MIN_TELEMETRY;tm<TM_MAX_TELEMETRY;tm++,tm_value++) |
266 |
|
|
HK_FILTER_TM(tm,tm_value); |
267 |
|
|
|
268 |
|
|
|
269 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
270 |
|
|
} |
271 |
|
|
break; |
272 |
|
|
|
273 |
|
|
case HK_SEND_TC: |
274 |
|
|
{ |
275 |
|
|
TI_TIME diff; |
276 |
|
|
|
277 |
|
|
CM_READ_BE_UINT32(p,code,tmp); |
278 |
|
|
CM_READ_BE_UINT32(p,value,tmp); |
279 |
|
|
|
280 |
|
|
TI_piGetTimeInfo_ms(&diff); |
281 |
|
|
|
282 |
|
|
diff-= HK_LastTCHLCall; |
283 |
|
|
|
284 |
|
|
if (diff < PRH_VAR_PWR_WAIT_BEFORE_SENDTC) |
285 |
|
|
OS_piTaskSuspend(PRH_VAR_PWR_WAIT_BEFORE_SENDTC-diff); |
286 |
|
|
|
287 |
|
|
status = TM_piSendTC(code,value); |
288 |
|
|
TI_piGetTimeInfo_ms(&HK_LastTCHLCall); |
289 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
290 |
|
|
} |
291 |
|
|
break; |
292 |
|
|
|
293 |
|
|
case HK_GET_TM_VALUE: |
294 |
|
|
|
295 |
|
|
CM_READ_BE_UINT32(p,code,tmp); |
296 |
|
|
CM_READ_BE_UINT32(p,value_ptr,tmp); |
297 |
|
|
status = TM_piGetTMValue(code,TM_CURRENT_VAL,(UINT32*)value_ptr); |
298 |
|
|
|
299 |
|
|
HK_FILTER_TM(code,((UINT32*)value_ptr)); |
300 |
|
|
|
301 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
302 |
|
|
break; |
303 |
|
|
|
304 |
|
|
case HK_KHB_FE_COM_BLOCK: |
305 |
|
|
{ |
306 |
|
|
MsgTsk HK_MsgToFe; |
307 |
|
|
BYTE tmp; |
308 |
|
|
|
309 |
|
|
if (HK_KHB_lock) |
310 |
|
|
status = OS_piMsgQueueSend_INFN(SAVED_HK_MAILBOX,(void*)&RxMsg,sizeof(RxMsg)); |
311 |
|
|
else |
312 |
|
|
{ |
313 |
|
|
saved_taskid=taskid; |
314 |
|
|
saved_status_ptr=status_ptr; |
315 |
|
|
CM_READ_BE_UINT8(p,counter); |
316 |
|
|
CM_READ_BE_UINT8(p,saved_expected); |
317 |
|
|
CM_READ_BE_UINT8(p,link); |
318 |
|
|
CM_READ_BE_UINT32(p,saved_outbuf,tmp); |
319 |
|
|
CM_READ_BE_UINT32(p,combuf,tmp); |
320 |
|
|
CM_READ_BE_UINT32(p,saved_retry_counter,tmp); |
321 |
|
|
|
322 |
|
|
status = KHB_SendFECommand(link,counter,saved_expected,(UINT16*)combuf); |
323 |
|
|
|
324 |
|
|
if(status==CM_RC_SUCCESSFUL) |
325 |
|
|
{ |
326 |
|
|
// if (!saved_expected) {HK_EndOfOp(status_ptr,status,taskid); break;} |
327 |
|
|
HK_KHB_lock = TRUE; |
328 |
|
|
OS_piStartTimer_INFN(HK_POLL_KHB_TIM,KHB_WAIT_TIMEBUF,HK_SendPoll_CallBack,NULL); |
329 |
|
|
} |
330 |
|
|
else |
331 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
332 |
|
|
|
333 |
|
|
} |
334 |
|
|
} |
335 |
|
|
break; |
336 |
|
|
|
337 |
|
|
case HK_POLL_KHB: |
338 |
|
|
{ |
339 |
|
|
UINT16 stw=0xffff; |
340 |
|
|
|
341 |
|
|
if(HK_KHB_lock==TRUE) { |
342 |
|
|
// read status word from kayser |
343 |
|
|
|
344 |
|
|
status = KHB_ReadStatusRegister(&stw); |
345 |
|
|
|
346 |
|
|
if(PRH_VAR_VERBOSE_DEBUG) |
347 |
|
|
/*@LOG KHB Status Register during polling - khb_status_register */ |
348 |
|
|
LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__, stw); |
349 |
|
|
|
350 |
|
|
if (status == CM_RC_SUCCESSFUL) |
351 |
|
|
{ |
352 |
|
|
if ((stw & KHB_STATUS_MASK) == KHB_STATUS_VALUE) |
353 |
|
|
{ |
354 |
|
|
#ifndef SIMULATOR |
355 |
|
|
counter = (stw >> 8) & 0xf; |
356 |
|
|
#else |
357 |
|
|
counter = 0; |
358 |
|
|
#endif |
359 |
|
|
if(saved_retry_counter) |
360 |
|
|
saved_retry_counter--; |
361 |
|
|
|
362 |
|
|
// buffer filled |
363 |
|
|
if (counter >=saved_expected) |
364 |
|
|
{ |
365 |
|
|
if (counter > saved_expected) |
366 |
|
|
/*@LOG paranoia check during polling: counter > expected - counter */ |
367 |
|
|
LU_INFN_LOG (LU_CRITICAL, LU_MASK(__FILEID__), __FILEID__, __LINE__, counter); |
368 |
|
|
if(saved_expected) |
369 |
|
|
status = KHB_ReadBuffer(saved_expected,(UINT16*)saved_outbuf); |
370 |
|
|
HK_KHB_lock = FALSE; |
371 |
|
|
} |
372 |
|
|
else |
373 |
|
|
{ |
374 |
|
|
// buffer not yet complete |
375 |
|
|
if (saved_retry_counter) |
376 |
|
|
OS_piStartTimer_INFN(HK_POLL_KHB_TIM,KHB_WAIT_TIMEBUF,HK_SendPoll_CallBack,NULL); |
377 |
|
|
else |
378 |
|
|
{ |
379 |
|
|
UINT16 * tmpptr = (UINT16*)saved_outbuf; |
380 |
|
|
*tmpptr = counter; |
381 |
|
|
tmpptr++; |
382 |
|
|
if(counter) |
383 |
|
|
status = KHB_ReadBuffer(counter,tmpptr); |
384 |
|
|
status = CM_RC_TIMEOUT; |
385 |
|
|
HK_KHB_lock = FALSE; |
386 |
|
|
/*@LOG KHB polling: saved_retry_counter == 0 - khb_status_register */ |
387 |
|
|
LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__, stw); |
388 |
|
|
|
389 |
|
|
} |
390 |
|
|
} |
391 |
|
|
} |
392 |
|
|
else |
393 |
|
|
{ |
394 |
|
|
status = CM_RC_KHB_ERROR; |
395 |
|
|
HK_KHB_lock = FALSE; |
396 |
|
|
*(UINT16*)saved_outbuf = stw; |
397 |
|
|
/*@LOG KHB Status Register : (stw & KHB_STATUS_MASK) != KHB_STATUS_VALUE) during polling - khb_status_register */ |
398 |
|
|
LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__, stw); |
399 |
|
|
|
400 |
|
|
} |
401 |
|
|
} |
402 |
|
|
else // bad read register |
403 |
|
|
HK_KHB_lock = FALSE; |
404 |
|
|
|
405 |
|
|
// HK_KHB_lock is here well set to the new value . In case its FALSE, then also che 'status' value is |
406 |
|
|
// set to the right status value to notify to the caller task |
407 |
|
|
|
408 |
|
|
if (!HK_KHB_lock) |
409 |
|
|
{ |
410 |
|
|
HK_RestoreSavedCommands(); |
411 |
|
|
HK_EndOfOp(saved_status_ptr,status,saved_taskid); |
412 |
|
|
} |
413 |
|
|
// if HK_KHB_lock is TRUE here, KHB is still locked, and 'status' should be zero. do nothing |
414 |
|
|
} |
415 |
|
|
else |
416 |
|
|
/*@LOG KHB polling: the board software status is unlocked */ |
417 |
|
|
LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__,0); |
418 |
|
|
} |
419 |
|
|
break; |
420 |
|
|
case HK_KHB_INIT_BOARD: |
421 |
|
|
{ |
422 |
|
|
if(HK_KHB_lock) |
423 |
|
|
{ |
424 |
|
|
OS_piCancelTimer_INFN (HK_POLL_KHB_TIM); |
425 |
|
|
HK_RestoreSavedCommands(); |
426 |
|
|
status=CM_RC_HK_CMD_CANCELLED; |
427 |
|
|
HK_EndOfOp(saved_status_ptr,status,saved_taskid); |
428 |
|
|
HK_KHB_lock = FALSE; |
429 |
|
|
} |
430 |
|
|
status=KHB_InitBoard(); |
431 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
432 |
|
|
} |
433 |
|
|
break; |
434 |
|
|
case HK_KHB_HARD_RESET: |
435 |
|
|
{ |
436 |
|
|
if(HK_KHB_lock) |
437 |
|
|
{ |
438 |
|
|
OS_piCancelTimer_INFN (HK_POLL_KHB_TIM); |
439 |
|
|
HK_RestoreSavedCommands(); |
440 |
|
|
status=CM_RC_HK_CMD_CANCELLED; |
441 |
|
|
HK_EndOfOp(saved_status_ptr,status,saved_taskid); |
442 |
|
|
HK_KHB_lock = FALSE; |
443 |
|
|
} |
444 |
|
|
status=KHB_HWReset(); |
445 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
446 |
|
|
} |
447 |
|
|
break; |
448 |
|
|
case HK_KHB_UPDATE_MASK_REG: |
449 |
|
|
{ |
450 |
|
|
UINT16 mask; |
451 |
|
|
BYTE action; |
452 |
|
|
/* are we sure that we can avoid this lock? */ |
453 |
|
|
if (HK_KHB_lock) { |
454 |
|
|
/* postpone request */ |
455 |
|
|
status = OS_piMsgQueueSend_INFN(SAVED_HK_MAILBOX,(void*)&RxMsg,sizeof(RxMsg)); |
456 |
|
|
if(status != CM_RC_SUCCESSFUL) |
457 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
458 |
|
|
} else { |
459 |
|
|
CM_READ_BE_UINT16(p,mask,tmp); |
460 |
|
|
CM_READ_BE_UINT8(p,action); |
461 |
|
|
status = KHB_UpdateMaskRegister(mask,action); |
462 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
463 |
|
|
} |
464 |
|
|
|
465 |
|
|
} |
466 |
|
|
break; |
467 |
|
|
case HK_KHB_READ_ALARM_REG: |
468 |
|
|
{ |
469 |
|
|
UINT32 mask_p; |
470 |
|
|
/* are we sure that we can avoid this lock? */ |
471 |
|
|
if (HK_KHB_lock) { |
472 |
|
|
/* postpone request */ |
473 |
|
|
status = OS_piMsgQueueSend_INFN(SAVED_HK_MAILBOX,(void*)&RxMsg,sizeof(RxMsg)); |
474 |
|
|
if(status != CM_RC_SUCCESSFUL) |
475 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
476 |
|
|
} else { |
477 |
|
|
CM_READ_BE_UINT32(p,mask_p,tmp); |
478 |
|
|
status = KHB_ReadAlarmRegister((UINT32*)mask_p); |
479 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
480 |
|
|
} |
481 |
|
|
} |
482 |
|
|
break; |
483 |
|
|
case HK_KHB_READ_STATUS_REG: |
484 |
|
|
CM_READ_BE_UINT32(p,value_ptr,tmp); |
485 |
|
|
status = KHB_ReadStatusRegister((UINT16*)value_ptr); |
486 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
487 |
|
|
break; |
488 |
|
|
case HK_KHB_SEND_128_TRIGGER: |
489 |
|
|
status = KHB_SendTrigger(); |
490 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
491 |
|
|
break; |
492 |
|
|
case HK_KHB_SET_HOTCOLD: |
493 |
|
|
CM_READ_BE_UINT32(p,value,tmp); |
494 |
|
|
status = KHB_SetSerialLine((CM_HOT_COLD)value); |
495 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
496 |
|
|
break; |
497 |
|
|
case HK_KHB_GET_HOTCOLD: |
498 |
|
|
CM_READ_BE_UINT32(p,value_ptr,tmp); |
499 |
|
|
status = KHB_GetSerialLine((CM_HOT_COLD*)value_ptr); |
500 |
|
|
HK_EndOfOp(status_ptr,status,taskid); |
501 |
|
|
break; |
502 |
|
|
default: |
503 |
|
|
} |
504 |
|
|
} |
505 |
|
|
} |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
|
509 |
|
|
status_code HK_SendMsgAndWait(MsgTsk* Msg) { |
510 |
|
|
status_code status; |
511 |
|
|
rtems_event_set evout; |
512 |
|
|
/* clear the event before sending msg */ |
513 |
|
|
OS_piEventClear(OS_EVENT_HK_DONE); |
514 |
|
|
/*send task msg*/ |
515 |
|
|
status = HK_SndMsgHKManager(Msg); |
516 |
|
|
if(status==RTEMS_SUCCESSFUL) |
517 |
|
|
status = OS_piEventReceive(OS_EVENT_HK_DONE,RTEMS_WAIT, RTEMS_NO_TIMEOUT, &evout); |
518 |
|
|
|
519 |
|
|
return status; |
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
|
|
status_code HK_SendTC(UINT32 code,UINT32 value) |
525 |
|
|
{ |
526 |
|
|
status_code status_sw,status = SUCCESSFUL; |
527 |
|
|
MsgTsk HK_Msg; |
528 |
|
|
rtems_id taskid; |
529 |
|
|
BYTE *p; |
530 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
531 |
|
|
/*fill the task msg*/ |
532 |
|
|
p = &HK_Msg.Info[0]; |
533 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
534 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
535 |
|
|
CM_WRITE_BE_UINT32(p,code); |
536 |
|
|
CM_WRITE_BE_UINT32(p,value); |
537 |
|
|
HK_Msg.LlInfo = 16; |
538 |
|
|
HK_Msg.Code = HK_SEND_TC; |
539 |
|
|
|
540 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
541 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
542 |
|
|
return status_sw; |
543 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
544 |
|
|
return(status); |
545 |
|
|
|
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
status_code HK_GetTMValue(UINT32 code,UINT32 *value) |
549 |
|
|
{ |
550 |
|
|
status_code status_sw,status = SUCCESSFUL; |
551 |
|
|
MsgTsk HK_Msg; |
552 |
|
|
rtems_id taskid; |
553 |
|
|
BYTE *p; |
554 |
|
|
rtems_event_set evout; |
555 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
556 |
|
|
/*fill the task msg*/ |
557 |
|
|
p = &HK_Msg.Info[0]; |
558 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
559 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
560 |
|
|
CM_WRITE_BE_UINT32(p,code); |
561 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)value); |
562 |
|
|
HK_Msg.LlInfo = 16; |
563 |
|
|
HK_Msg.Code = HK_GET_TM_VALUE; |
564 |
|
|
|
565 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
566 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
567 |
|
|
return status_sw; |
568 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
569 |
|
|
return(status); |
570 |
|
|
} |
571 |
|
|
|
572 |
|
|
|
573 |
|
|
status_code HK_ReadKHBStatusRegister(UINT16 *value) |
574 |
|
|
{ |
575 |
|
|
status_code status_sw,status = SUCCESSFUL; |
576 |
|
|
MsgTsk HK_Msg; |
577 |
|
|
rtems_id taskid; |
578 |
|
|
BYTE *p; |
579 |
|
|
rtems_event_set evout; |
580 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
581 |
|
|
/*fill the task msg*/ |
582 |
|
|
p = &HK_Msg.Info[0]; |
583 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
584 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
585 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)value); |
586 |
|
|
HK_Msg.LlInfo = 12; |
587 |
|
|
HK_Msg.Code = HK_KHB_READ_STATUS_REG; |
588 |
|
|
|
589 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
590 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
591 |
|
|
return status_sw; |
592 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
593 |
|
|
return(status); |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
status_code HK_KHBSend128Trigger() |
597 |
|
|
{ |
598 |
|
|
status_code status_sw,status = SUCCESSFUL; |
599 |
|
|
MsgTsk HK_Msg; |
600 |
|
|
rtems_id taskid; |
601 |
|
|
BYTE *p; |
602 |
|
|
rtems_event_set evout; |
603 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
604 |
|
|
/*fill the task msg*/ |
605 |
|
|
p = &HK_Msg.Info[0]; |
606 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
607 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
608 |
|
|
HK_Msg.LlInfo = 8; |
609 |
|
|
HK_Msg.Code = HK_KHB_SEND_128_TRIGGER; |
610 |
|
|
|
611 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
612 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
613 |
|
|
return status_sw; |
614 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
615 |
|
|
return(status); |
616 |
|
|
} |
617 |
|
|
|
618 |
|
|
|
619 |
|
|
status_code HK_UpdateKHBMaskRegister(UINT16 value,BYTE action) |
620 |
|
|
{ |
621 |
|
|
status_code status_sw,status = SUCCESSFUL; |
622 |
|
|
MsgTsk HK_Msg; |
623 |
|
|
rtems_id taskid; |
624 |
|
|
BYTE *p; |
625 |
|
|
rtems_event_set evout; |
626 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
627 |
|
|
/*fill the task msg*/ |
628 |
|
|
p = &HK_Msg.Info[0]; |
629 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
630 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
631 |
|
|
CM_WRITE_BE_UINT16(p,value); |
632 |
|
|
CM_WRITE_BE_UINT8(p,action); |
633 |
|
|
HK_Msg.LlInfo = 11; |
634 |
|
|
HK_Msg.Code = HK_KHB_UPDATE_MASK_REG; |
635 |
|
|
|
636 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
637 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
638 |
|
|
return status_sw; |
639 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
640 |
|
|
return(status); |
641 |
|
|
} |
642 |
|
|
|
643 |
|
|
|
644 |
|
|
status_code HK_ReadKHBAlarmRegister(UINT32* mask) |
645 |
|
|
{ |
646 |
|
|
status_code status_sw,status = SUCCESSFUL; |
647 |
|
|
MsgTsk HK_Msg; |
648 |
|
|
rtems_id taskid; |
649 |
|
|
BYTE *p; |
650 |
|
|
UINT32 tmp_mask; |
651 |
|
|
rtems_event_set evout; |
652 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
653 |
|
|
/*fill the task msg*/ |
654 |
|
|
p = &HK_Msg.Info[0]; |
655 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
656 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
657 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&tmp_mask); |
658 |
|
|
HK_Msg.LlInfo = 12; |
659 |
|
|
HK_Msg.Code = HK_KHB_READ_ALARM_REG; |
660 |
|
|
|
661 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
662 |
|
|
if(status_sw==CM_RC_SUCCESSFUL) |
663 |
|
|
*mask=tmp_mask; |
664 |
|
|
else |
665 |
|
|
return status_sw; |
666 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
667 |
|
|
return(status); |
668 |
|
|
} |
669 |
|
|
|
670 |
|
|
status_code HK_DoCyclicAcquisition(void *all_values_ptr) |
671 |
|
|
{ |
672 |
|
|
status_code status_sw,status = SUCCESSFUL; |
673 |
|
|
MsgTsk HK_Msg; |
674 |
|
|
rtems_id taskid; |
675 |
|
|
BYTE *p; |
676 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
677 |
|
|
/*fill the task msg*/ |
678 |
|
|
p = &HK_Msg.Info[0]; |
679 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
680 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
681 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)all_values_ptr); |
682 |
|
|
HK_Msg.LlInfo = 12; |
683 |
|
|
HK_Msg.Code = HK_CYCLIC_ACQUISITION; |
684 |
|
|
|
685 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
686 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
687 |
|
|
return status_sw; |
688 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
689 |
|
|
return(status); |
690 |
|
|
|
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
status_code HK_SaveTMTCValues() |
694 |
|
|
{ |
695 |
|
|
status_code status_sw,status = SUCCESSFUL; |
696 |
|
|
MsgTsk HK_Msg; |
697 |
|
|
rtems_id taskid; |
698 |
|
|
BYTE *p; |
699 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
700 |
|
|
/*fill the task msg*/ |
701 |
|
|
p = &HK_Msg.Info[0]; |
702 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
703 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
704 |
|
|
HK_Msg.LlInfo = 8; |
705 |
|
|
HK_Msg.Code = HK_SAVE_TMTC_VALUES; |
706 |
|
|
|
707 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
708 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
709 |
|
|
return status_sw; |
710 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
711 |
|
|
return(status); |
712 |
|
|
|
713 |
|
|
} |
714 |
|
|
|
715 |
|
|
void HK_SendPoll_CallBack(rtems_id timer_id, void *suspend) |
716 |
|
|
{ |
717 |
|
|
static MsgTsk Msg; |
718 |
|
|
status_code status; |
719 |
|
|
|
720 |
|
|
Msg.Code = HK_POLL_KHB; |
721 |
|
|
status = HK_SndMsgHKManager(&Msg); |
722 |
|
|
|
723 |
|
|
} |
724 |
|
|
|
725 |
|
|
|
726 |
|
|
|
727 |
|
|
status_code HK_KHB_Cmd2FE(BYTE link,BYTE counter,BYTE expected,UINT16 *combuf,UINT16 *outbuf, UINT32 timeout) |
728 |
|
|
{ |
729 |
|
|
status_code status_sw,status = SUCCESSFUL; |
730 |
|
|
MsgTsk HK_MsgToFe; |
731 |
|
|
rtems_id taskid; |
732 |
|
|
BYTE *p; |
733 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
734 |
|
|
/*fill the task msg*/ |
735 |
|
|
p = &HK_MsgToFe.Info[0]; |
736 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
737 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
738 |
|
|
CM_WRITE_BE_UINT8(p,counter); |
739 |
|
|
CM_WRITE_BE_UINT8(p,expected); |
740 |
|
|
CM_WRITE_BE_UINT8(p,link); |
741 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)outbuf); |
742 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)combuf); |
743 |
|
|
CM_WRITE_BE_UINT32(p,timeout); |
744 |
|
|
HK_MsgToFe.LlInfo = 23; |
745 |
|
|
HK_MsgToFe.Code = HK_KHB_FE_COM_BLOCK; |
746 |
|
|
|
747 |
|
|
status_sw = HK_SendMsgAndWait(&HK_MsgToFe); |
748 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
749 |
|
|
return status_sw; |
750 |
|
|
/* status has been set by the other task. if all is OK, return it */ |
751 |
|
|
return(status); |
752 |
|
|
} |
753 |
|
|
|
754 |
|
|
|
755 |
|
|
status_code HK_KHB_HardReset() |
756 |
|
|
{ |
757 |
|
|
status_code status_sw,status = SUCCESSFUL; |
758 |
|
|
MsgTsk HK_Msg; |
759 |
|
|
rtems_id taskid; |
760 |
|
|
BYTE *p; |
761 |
|
|
|
762 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
763 |
|
|
/*fill the task msg*/ |
764 |
|
|
p = &HK_Msg.Info[0]; |
765 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
766 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
767 |
|
|
HK_Msg.LlInfo = 8; |
768 |
|
|
HK_Msg.Code = HK_KHB_HARD_RESET; |
769 |
|
|
|
770 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
771 |
|
|
|
772 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
773 |
|
|
return status_sw; |
774 |
|
|
|
775 |
|
|
return(status); |
776 |
|
|
} |
777 |
|
|
|
778 |
|
|
|
779 |
|
|
status_code HK_KHB_SetHotCold(CM_HOT_COLD hc) |
780 |
|
|
{ |
781 |
|
|
status_code status_sw,status = SUCCESSFUL; |
782 |
|
|
MsgTsk HK_Msg; |
783 |
|
|
rtems_id taskid; |
784 |
|
|
BYTE *p; |
785 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
786 |
|
|
/*fill the task msg*/ |
787 |
|
|
p = &HK_Msg.Info[0]; |
788 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
789 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
790 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)hc); |
791 |
|
|
HK_Msg.LlInfo = 12; |
792 |
|
|
HK_Msg.Code =HK_KHB_SET_HOTCOLD; |
793 |
|
|
|
794 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
795 |
|
|
|
796 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
797 |
|
|
return status_sw; |
798 |
|
|
|
799 |
|
|
return(status); |
800 |
|
|
} |
801 |
|
|
|
802 |
|
|
status_code HK_KHB_GetHotCold(CM_HOT_COLD *hc) |
803 |
|
|
{ |
804 |
|
|
status_code status_sw,status = SUCCESSFUL; |
805 |
|
|
MsgTsk HK_Msg; |
806 |
|
|
rtems_id taskid; |
807 |
|
|
BYTE *p; |
808 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
809 |
|
|
/*fill the task msg*/ |
810 |
|
|
p = &HK_Msg.Info[0]; |
811 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
812 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
813 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)hc); |
814 |
|
|
HK_Msg.LlInfo = 12; |
815 |
|
|
HK_Msg.Code =HK_KHB_GET_HOTCOLD; |
816 |
|
|
|
817 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
818 |
|
|
|
819 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
820 |
|
|
return status_sw; |
821 |
|
|
|
822 |
|
|
return(status); |
823 |
|
|
} |
824 |
|
|
|
825 |
|
|
|
826 |
|
|
|
827 |
|
|
|
828 |
|
|
status_code HK_KHB_InitBoard() |
829 |
|
|
{ |
830 |
|
|
status_code status_sw,status = SUCCESSFUL; |
831 |
|
|
MsgTsk HK_Msg; |
832 |
|
|
rtems_id taskid; |
833 |
|
|
BYTE *p; |
834 |
|
|
rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&taskid); |
835 |
|
|
/*fill the task msg*/ |
836 |
|
|
p = &HK_Msg.Info[0]; |
837 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)taskid); |
838 |
|
|
CM_WRITE_BE_UINT32(p,(UINT32)&status); |
839 |
|
|
HK_Msg.LlInfo = 8; |
840 |
|
|
HK_Msg.Code = HK_KHB_INIT_BOARD; |
841 |
|
|
|
842 |
|
|
status_sw = HK_SendMsgAndWait(&HK_Msg); |
843 |
|
|
|
844 |
|
|
if(status_sw != CM_RC_SUCCESSFUL) |
845 |
|
|
return status_sw; |
846 |
|
|
|
847 |
|
|
return(status); |
848 |
|
|
} |