1 |
kusanagi |
1.1 |
/**************************************************************************** |
2 |
|
|
/* F i l e D a t a |
3 |
|
|
/* |
4 |
|
|
/* Module : BasicSW |
5 |
|
|
/* C.I. No. : |
6 |
|
|
/* $Revision: 1.26 $ |
7 |
|
|
/* $Date: 2005/02/21 08:58:28 $ |
8 |
|
|
/* Belonging to : |
9 |
|
|
/* : |
10 |
|
|
/* $RCSfile: TI_TimingInfo_op.c,v $ |
11 |
|
|
/* Program Type : |
12 |
|
|
/* Sub-modules : |
13 |
|
|
/* |
14 |
|
|
/**************************************************************************** |
15 |
|
|
/* S W D e v e l o p m e n t E n v i r o n m e n t |
16 |
|
|
/* |
17 |
|
|
/* Host system : |
18 |
|
|
/* SW Compiler : |
19 |
|
|
/* $Author: sebastiani $ |
20 |
|
|
/* : |
21 |
|
|
/**************************************************************************** |
22 |
|
|
/* U p d a t i n g |
23 |
|
|
/* |
24 |
|
|
/* $Log: TI_TimingInfo_op.c,v $ |
25 |
|
|
/* Revision 1.26 2005/02/21 08:58:28 sebastiani |
26 |
|
|
/* all log comments completed |
27 |
|
|
/* |
28 |
|
|
/* Revision 1.25 2005/02/19 10:16:47 sebastiani |
29 |
|
|
/* disable GPT |
30 |
|
|
/* |
31 |
|
|
/* Revision 1.24 2005/01/26 18:46:26 sebastiani |
32 |
|
|
/* *** empty log message *** |
33 |
|
|
/* |
34 |
|
|
/* Revision 1.23 2004/09/17 15:01:00 faber |
35 |
|
|
/* LU_INFN_LOG flags fixing |
36 |
|
|
/* |
37 |
|
|
/* Revision 1.22 2004/09/08 10:39:12 faber |
38 |
|
|
/* *** empty log message *** |
39 |
|
|
/* |
40 |
|
|
/* Revision 1.21 2004/08/26 16:54:01 sebastiani |
41 |
|
|
/* fix some bug |
42 |
|
|
/* |
43 |
|
|
/* Revision 1.20 2004/07/27 17:30:17 faber |
44 |
|
|
/* OBT can be now in second or milliseconds, depending of the situazion. |
45 |
|
|
/* OBT_s is used for FM compatibility, OBT_ms basically for MM infos |
46 |
|
|
/* |
47 |
|
|
/* Revision 1.19 2004/07/08 16:23:35 sebastiani |
48 |
|
|
/* *** empty log message *** |
49 |
|
|
/* |
50 |
|
|
/* Revision 1.18 2004/05/27 17:50:38 sebastiani |
51 |
|
|
/* *** empty log message *** |
52 |
|
|
/* |
53 |
|
|
/* Revision 1.17 2004/05/07 08:01:05 faber |
54 |
|
|
/* *** empty log message *** |
55 |
|
|
/* |
56 |
|
|
/* Revision 1.16 2004/05/06 15:50:57 faber |
57 |
|
|
/* GetTimeSyncInfo introduced |
58 |
|
|
/* |
59 |
|
|
/* Revision 1.15 2004/04/29 07:11:43 faber |
60 |
|
|
/* pached GetOrbitOffset |
61 |
|
|
/* |
62 |
|
|
/* Revision 1.14 2003/12/04 17:16:08 sebastiani |
63 |
|
|
/* GS debug/tests, and other |
64 |
|
|
/* |
65 |
|
|
/* Revision 1.13 2003/12/01 09:27:16 sebastiani |
66 |
|
|
/* CCA info for Gas Module and first implementation of IPM infos. |
67 |
|
|
/* |
68 |
|
|
/* Revision 1.12 2003/11/18 17:13:15 sebastiani |
69 |
|
|
/* GPT enabled to print a "\n" every 60s directly on UART, only to check if the CPU is |
70 |
|
|
/* alive |
71 |
|
|
/* |
72 |
|
|
/* Revision 1.11 2003/11/04 11:36:35 alfarano |
73 |
|
|
/* deleted task in TM_TMTC manager and added to HK_Manager, added KHB buffer read task |
74 |
|
|
/* |
75 |
|
|
/* Revision 1.10 2003/10/30 16:10:48 faber |
76 |
|
|
/* GPT disabled. the callback function is a null function |
77 |
|
|
/* |
78 |
|
|
/* Revision 1.9 2003/10/21 16:09:12 alfarano |
79 |
|
|
/* LU_LOG_INFN replacement for all remaining original log functions |
80 |
|
|
/* |
81 |
|
|
/* Revision 1.8 2003/09/15 09:20:23 faber |
82 |
|
|
/* GTP function modification for simulator mode (TimedFunction) |
83 |
|
|
/* |
84 |
|
|
/* Revision 1.7 2003/09/12 10:52:56 faber |
85 |
|
|
/* introduced PTH_VAR_TC_CYC_RATE |
86 |
|
|
/* |
87 |
|
|
/* Revision 1.6 2003/09/10 16:15:51 faber |
88 |
|
|
/* PRH_EXTERN_VAR(XX_LOGMASK) removed (not needed any more) |
89 |
|
|
/* |
90 |
|
|
/* Revision 1.5 2003/09/10 11:55:07 faber |
91 |
|
|
/* LU_MASK introduced. Log mask for module is now an unique array (PRH_ARR_LOG_MASK) indexed by __FILEID__ |
92 |
|
|
/* |
93 |
|
|
/* Revision 1.4 2003/08/29 11:13:30 faber |
94 |
|
|
/* TI_StartTimerMoscowTime introduced |
95 |
|
|
/* |
96 |
|
|
/* Revision 1.3 2003/08/28 10:11:44 faber |
97 |
|
|
/* New timer management. GPT is now possible to be disabled. (DisableGPT,EnableGPT) |
98 |
|
|
/* GetTimeInfo now use the RTEMS clock instead reading the TI_SystemTime. |
99 |
|
|
/* GetTimeInfo now returns seconds, instead of milliseconds. |
100 |
|
|
/* |
101 |
|
|
/* Revision 1.2 2003/08/22 07:47:35 sebastiani |
102 |
|
|
/* Timer behavior change: TYME_SYNC / OBT_ORBIT / OBT introduced. |
103 |
|
|
/* TymeSync MCMD now doesn't affect OBT (TI_SystemTime) any more |
104 |
|
|
/* |
105 |
|
|
/* Revision 1.1.1.1 2003/08/04 09:40:21 sebastiani |
106 |
|
|
/* Imported sources laben rel. 19.06.2003 integrated with pam2 |
107 |
|
|
/* |
108 |
|
|
/* Revision 1.2 2003/06/18 16:53:19 sebastiani |
109 |
|
|
/* Pam/Run Manager development update. ExpSeq sequence is receiven from the RunManager (simulator mode) |
110 |
|
|
/* |
111 |
|
|
/* Revision 1.1.1.1 2003/05/27 08:13:24 wizard |
112 |
|
|
/* Import of the Official Laben CD Release Software as the pamela-EM_delivery_20030521_1454.tar.bz2 |
113 |
|
|
/* |
114 |
|
|
/* Revision 1.9 2003/01/30 09:43:49 aurora |
115 |
|
|
/* introduced ifdef for EM and FM |
116 |
|
|
/* |
117 |
|
|
/* Revision 1.8 2002/11/14 09:46:42 zulia |
118 |
|
|
/* removed unsed status variable |
119 |
|
|
/* |
120 |
|
|
/* Revision 1.7 2002/09/11 15:34:17 zulia |
121 |
|
|
/* comment |
122 |
|
|
/* |
123 |
|
|
/* Revision 1.6 2002/05/09 08:16:34 zulia |
124 |
|
|
/* * acceptance release |
125 |
|
|
/* |
126 |
|
|
/* |
127 |
|
|
/*****************************************************************************/ |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
/*============================= Include File ================================*/ |
131 |
|
|
#include <src/INFN/LU_SourceFileID_INFN.h> |
132 |
|
|
#define __FILEID__ _TI_TimingInfo_op__c |
133 |
|
|
#include <src/INFN/PRH_ParamHandler_INFN_auto.h> |
134 |
|
|
#include <src/INFN/PRH_ParamHandler_INFN.h> |
135 |
|
|
#include <src/INFN/LU_LogUtility_INFN.h> |
136 |
|
|
|
137 |
|
|
LU_DECL_MASK(); |
138 |
|
|
|
139 |
|
|
|
140 |
|
|
#include <src/INFN/OS_rtems_INFN_p.h> |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
#include <src/BasicSW/TimingInfo/TI_TimingInfo_op.h> |
144 |
|
|
|
145 |
|
|
//##FS 17.6.03 |
146 |
|
|
#ifdef SIMULATOR |
147 |
|
|
#include <src/INFN/PM_PamManager_INFN.h> |
148 |
|
|
#endif |
149 |
|
|
//##FS END 17.6.03 |
150 |
|
|
|
151 |
|
|
/*****************************************************************************/ |
152 |
|
|
/*============================= Object variables ============================*/ |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
/*****************************************************************************/ |
156 |
|
|
/* @Variable: TI_ObtTimeSync */ |
157 |
|
|
/* @Purpose : */ |
158 |
|
|
/* TI_TIME type */ |
159 |
|
|
/* is the OBT in the moment in which the Time Sync MCMD arrived. */ |
160 |
|
|
/* if zero, means not set. */ |
161 |
|
|
/* in milliseconds */ |
162 |
|
|
/* @@ */ |
163 |
|
|
/*****************************************************************************/ |
164 |
|
|
static TI_TIME TI_ObtTimeSync_s; |
165 |
|
|
static TI_TIME TI_ObtTimeSync_ms; |
166 |
|
|
|
167 |
|
|
volatile static BOOL TimeSyncExtInt_enabled = FALSE; |
168 |
|
|
|
169 |
|
|
/*****************************************************************************/ |
170 |
|
|
/* @Variable: TI_TimeSync */ |
171 |
|
|
/* @Purpose : */ |
172 |
|
|
/* TI_TIME type */ |
173 |
|
|
/* is the "Moscow Time" arrived by the MCMD */ |
174 |
|
|
/* if zero, means not set. */ |
175 |
|
|
/* in seconds */ |
176 |
|
|
/* @@ */ |
177 |
|
|
/*****************************************************************************/ |
178 |
|
|
static TI_TIME TI_TimeSync_s; |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
/*****************************************************************************/ |
183 |
|
|
/* @Variable: TI_ObtOrbit */ |
184 |
|
|
/* @Purpose : */ |
185 |
|
|
/* TI_TIME type */ |
186 |
|
|
/* is the OBT in the moment of the Ascending Node (CALIBRATE MCMD) */ |
187 |
|
|
/* To know the tim of the (last) ascending node, calculate: */ |
188 |
|
|
/* OBT - ObtOrbit */ |
189 |
|
|
/* zero means not set. */ |
190 |
|
|
/* in seconds */ |
191 |
|
|
/* @@ */ |
192 |
|
|
/*****************************************************************************/ |
193 |
|
|
static TI_TIME TI_ObtOrbit_s; |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
/*****************************************************************************/ |
198 |
|
|
/* @Variable: TI_TimeSyncCounter */ |
199 |
|
|
/* @Purpose : */ |
200 |
|
|
/* unsigned int type */ |
201 |
|
|
/* store the number times the TimeSync MCMD was received. */ |
202 |
|
|
/* if zero means that the Time Sync */ |
203 |
|
|
/* MCMD has never arrived (in this case time-variables should be TI_UNSET).*/ |
204 |
|
|
/* in seconds */ |
205 |
|
|
/* @@ */ |
206 |
|
|
/*****************************************************************************/ |
207 |
|
|
static unsigned int TI_TimeSyncCounter; |
208 |
|
|
|
209 |
|
|
/*===========================================================================*/ |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
/* External Parameters */ |
214 |
|
|
|
215 |
|
|
/*****************************************************************************/ |
216 |
|
|
|
217 |
|
|
/*===== T i m i n g I n f o O P E R A T I O N A L F U N C T I O N S =====*/ |
218 |
|
|
|
219 |
|
|
/*****************************************************************************/ |
220 |
|
|
/* @Function: TI_opInitTimingInfo */ |
221 |
|
|
/* @Purpose : */ |
222 |
|
|
/* The function performs the following initialization: */ |
223 |
|
|
/* - Establishes an ISR for ERC 32 General Purpos Timer (GPT). */ |
224 |
|
|
/* - Initializes the GPT Scaler and Couter. */ |
225 |
|
|
/* - Initializes global object variables. */ |
226 |
|
|
/* */ |
227 |
|
|
/* @@ */ |
228 |
|
|
/* @Parameter Name @Mode @Description */ |
229 |
|
|
/* @@ */ |
230 |
|
|
/*****************************************************************************/ |
231 |
|
|
|
232 |
|
|
status_code TI_opInitTimingInfo (void) |
233 |
|
|
{ |
234 |
|
|
status_code status; |
235 |
|
|
void* OldHandler; |
236 |
|
|
|
237 |
|
|
/* the rtems epoch is 01.01.1988 00:00 */ |
238 |
|
|
static rtems_time_of_day epoch = {1988,1,1,0,0,0,0}; |
239 |
|
|
|
240 |
|
|
/*===========================================================================*/ |
241 |
|
|
/*================ GENERAL PURPOSE TIMER (ERC32) ========================*/ |
242 |
|
|
/* |
243 |
|
|
status =OS_piIsrCatch ( TI_opNull, |
244 |
|
|
ERC32_INTERRUPT_GENERAL_PURPOSE_TIMER+0x10, |
245 |
|
|
&OldHandler); |
246 |
|
|
*/ |
247 |
|
|
#if TI_GPT_ENABLED |
248 |
|
|
status =OS_piIsrCatch ( TI_ihTimingInfo, |
249 |
|
|
ERC32_INTERRUPT_GENERAL_PURPOSE_TIMER+0x10, |
250 |
|
|
&OldHandler); |
251 |
|
|
|
252 |
|
|
if (status==SUCCESSFUL) |
253 |
|
|
{ |
254 |
|
|
/*==== INIT OF THE GENERAL PURPOSE TIMER (ERC32) ====================*/ |
255 |
|
|
ERC32_MEC.General_Purpose_Timer_Counter =TI_GPT_COUNTER_VALUE*1000*5; |
256 |
|
|
ERC32_MEC.General_Purpose_Timer_Scalar =TI_GPT_SCALER_VALUE; |
257 |
|
|
ERC32_MEC_Set_General_Purpose_Timer_Control( |
258 |
|
|
ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO | |
259 |
|
|
ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER | |
260 |
|
|
ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | |
261 |
|
|
ERC32_MEC_TIMER_COUNTER_LOAD_SCALER); |
262 |
|
|
TI_opEnableGPT(); |
263 |
|
|
} |
264 |
|
|
else |
265 |
|
|
{ |
266 |
|
|
/* ISR not successfully established */ |
267 |
|
|
// LOG_INFN HA_piLogHistoryEntry10(HA_E10_SW_TI,HA_E10_INT_CATCH_ERR,status); |
268 |
|
|
/*@LOG Isr not successfully enstablisched - status */ |
269 |
|
|
LU_INFN_LOG(LU_FATAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
270 |
|
|
} |
271 |
|
|
#else |
272 |
|
|
TI_opDisableGPT(); |
273 |
|
|
#endif |
274 |
|
|
/*===========================================================================*/ |
275 |
|
|
/*=================== SYSTEM TIME INITIALIZATION ========================*/ |
276 |
|
|
|
277 |
|
|
|
278 |
|
|
TI_ObtTimeSync_s =TI_UNSET; |
279 |
|
|
TI_ObtTimeSync_ms =TI_UNSET; |
280 |
|
|
TI_TimeSync_s =TI_UNSET; |
281 |
|
|
TI_ObtOrbit_s =TI_UNSET; |
282 |
|
|
TI_TimeSyncCounter = 0; |
283 |
|
|
|
284 |
|
|
/* init the RTEMS system clock to the RTEMS epoch: */ |
285 |
|
|
status = rtems_clock_set(&epoch); |
286 |
|
|
if(status) |
287 |
|
|
/*@LOG invalid time of day - statys */ |
288 |
|
|
LU_INFN_LOG(LU_FATAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
289 |
|
|
return (status); |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
/*****************************************************************************/ |
295 |
|
|
/* @Function: TI_OBT */ |
296 |
|
|
/* @Purpose : */ |
297 |
|
|
/* Get the OBT using the rtems clock. The function returns the number of */ |
298 |
|
|
/* seconds since bootstrap (pamela initialization) */ |
299 |
|
|
/*****************************************************************************/ |
300 |
|
|
|
301 |
|
|
static TI_TIME TI_OBT_s() { |
302 |
|
|
rtems_interval sse; |
303 |
|
|
rtems_clock_get(RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH,&sse); |
304 |
|
|
/* TI_TIME is unsigned long (uint32). rtems_interval is unsigned32 too. */ |
305 |
|
|
return sse; |
306 |
|
|
} |
307 |
|
|
|
308 |
|
|
static TI_TIME TI_OBT_ms() { |
309 |
|
|
rtems_clock_time_value t; |
310 |
|
|
rtems_clock_get(RTEMS_CLOCK_GET_TIME_VALUE,&t); |
311 |
|
|
return (t.seconds*1000)+(t.microseconds/1000); |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
void TI_opDisableGPT() { |
315 |
|
|
ERC32_Mask_interrupt( ERC32_INTERRUPT_GENERAL_PURPOSE_TIMER ); |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
|
319 |
|
|
void TI_opEnableGPT() { |
320 |
|
|
ERC32_Unmask_interrupt( ERC32_INTERRUPT_GENERAL_PURPOSE_TIMER ); |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
|
324 |
|
|
/*****************************************************************************/ |
325 |
|
|
/* @Function: TI_opTimingOperation */ |
326 |
|
|
/* @Purpose : */ |
327 |
|
|
/* The function implements the OBT interrupt handler. The interrupt rate */ |
328 |
|
|
/* is every 1 ms. The function provides for the following actions: */ |
329 |
|
|
/* - Increment the variable TI_SystemTime (OBT). */ |
330 |
|
|
/* - Decrement the Monitoring counter, and whenever this counter goes to */ |
331 |
|
|
/* zero (every second) send a message to Monitoring to start parameters */ |
332 |
|
|
/* check. */ |
333 |
|
|
/* - Send message to TTMANAGER every 128 ms for MCMD timetag. */ |
334 |
|
|
/* check. */ |
335 |
|
|
/* */ |
336 |
|
|
/* @@ */ |
337 |
|
|
/* @Parameter Name @Mode @Description */ |
338 |
|
|
/* @@ */ |
339 |
|
|
/*****************************************************************************/ |
340 |
|
|
|
341 |
|
|
void TI_opNull(void) { |
342 |
|
|
return; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
void TI_opTimingOperation (void) |
346 |
|
|
{ |
347 |
|
|
// MsgTsk SndMsg; |
348 |
|
|
static unsigned int t=0; |
349 |
|
|
t++; |
350 |
|
|
console_outbyte_polled(0,'-'); |
351 |
|
|
console_outbyte_polled(0,'0'+t%10); |
352 |
|
|
console_outbyte_polled(0,'\n'); |
353 |
|
|
LU_UART_CR('-'); |
354 |
|
|
#ifdef SIMULATOR |
355 |
|
|
PM_SendTestCommand(105,0,0,0,0); |
356 |
|
|
#endif |
357 |
|
|
/* |
358 |
|
|
if(TI_SystemTime == MAX_SYSTEM_TIME) { |
359 |
|
|
TI_SystemTimeRestart++; |
360 |
|
|
TI_SystemTime=1; |
361 |
|
|
LU_INFN_LOG(LU_WARNING,LU_MASK(__FILEID__),__FILEID__,__LINE__,TI_SystemTimeRestart ); |
362 |
|
|
} |
363 |
|
|
*/ |
364 |
|
|
} |
365 |
|
|
|
366 |
|
|
|
367 |
|
|
/*****************************************************************************/ |
368 |
|
|
/* @Function: TI_opGetTimeInfo */ |
369 |
|
|
/* @Purpose : */ |
370 |
|
|
/* The function returns the On Board Time (OBT) information. */ |
371 |
|
|
/* */ |
372 |
|
|
/* @@ */ |
373 |
|
|
/* @Parameter Name @Mode @Description */ |
374 |
|
|
/* IN */ |
375 |
|
|
/* status_code OUT Return code */ |
376 |
|
|
/* @@ */ |
377 |
|
|
/*****************************************************************************/ |
378 |
|
|
|
379 |
|
|
|
380 |
|
|
void TI_opGetTimeInfo_s (TI_TIME* Time) |
381 |
|
|
{ |
382 |
|
|
*Time = TI_OBT_s(); |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
void TI_opGetTimeInfo_ms (TI_TIME* Time) |
386 |
|
|
{ |
387 |
|
|
*Time = TI_OBT_ms(); |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
|
391 |
|
|
status_code TI_opResourceObtain() { |
392 |
|
|
status_code s; |
393 |
|
|
if(rtems_interrupt_is_in_progress()) |
394 |
|
|
return TI_SUCCESSFUL; |
395 |
|
|
s=OS_piResourceObtain(TI_RES,WAIT,NO_TIMEOUT); |
396 |
|
|
if(s != SUCCESSFUL) { |
397 |
|
|
/*@LOG TI_opResourceObtain(): error - status */ |
398 |
|
|
LU_INFN_LOG(LU_CRITICAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,s); |
399 |
|
|
s=TI_RESERROR; |
400 |
|
|
}else |
401 |
|
|
s=TI_SUCCESSFUL; |
402 |
|
|
return s; |
403 |
|
|
} |
404 |
|
|
|
405 |
|
|
status_code TI_opResourceRelease() { |
406 |
|
|
status_code s; |
407 |
|
|
if(rtems_interrupt_is_in_progress()) |
408 |
|
|
return TI_SUCCESSFUL; |
409 |
|
|
s=OS_piResourceRelease(TI_RES); |
410 |
|
|
if(s != SUCCESSFUL) { |
411 |
|
|
/*@LOG TI_opResourceRelease(): error - status */ |
412 |
|
|
LU_INFN_LOG(LU_CRITICAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,s); |
413 |
|
|
s=TI_RESERROR; |
414 |
|
|
}else |
415 |
|
|
s=TI_SUCCESSFUL; |
416 |
|
|
return s; |
417 |
|
|
} |
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
void TI_opSetObtTimeSync(TI_TIME ms,BOOL enable_next) { |
422 |
|
|
UINT32 intLevel; |
423 |
|
|
OS_PROTECTED_INT(intLevel, |
424 |
|
|
do { |
425 |
|
|
if(TimeSyncExtInt_enabled) { |
426 |
|
|
TI_ObtTimeSync_ms = ms; |
427 |
|
|
TI_ObtTimeSync_s = ms / 1000; |
428 |
|
|
TimeSyncExtInt_enabled = enable_next; |
429 |
|
|
} |
430 |
|
|
} while(0) |
431 |
|
|
); |
432 |
|
|
} |
433 |
|
|
|
434 |
|
|
|
435 |
|
|
void TI_opTimeSyncExtInterrupt() |
436 |
|
|
{ |
437 |
|
|
volatile BOOL doit; |
438 |
|
|
UINT32 intLevel; |
439 |
|
|
OS_PROTECTED_INT(intLevel,doit = TimeSyncExtInt_enabled); |
440 |
|
|
if(doit) |
441 |
|
|
TI_opSetObtTimeSync(TI_OBT_ms(),FALSE); |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
/*****************************************************************************/ |
445 |
|
|
/* @Function: TI_opUpdateTimeInfo */ |
446 |
|
|
/* @Purpose : */ |
447 |
|
|
/* The function updates the Time Information when a TimeSync MCMD arrive. */ |
448 |
|
|
/* */ |
449 |
|
|
/* @@ */ |
450 |
|
|
/* @Parameter Name @Mode @Description */ |
451 |
|
|
/* Time IN The "Moscow Time" in seconds */ |
452 |
|
|
/* @@ */ |
453 |
|
|
/*****************************************************************************/ |
454 |
|
|
void TI_opUpdateTimeInfo_s (TI_TIME Time) |
455 |
|
|
{ |
456 |
|
|
UINT32 intLevel; |
457 |
|
|
OS_PROTECTED_INT(intLevel,TimeSyncExtInt_enabled = TRUE); |
458 |
|
|
|
459 |
|
|
if( (TI_opResourceObtain()) == SUCCESSFUL) { |
460 |
|
|
TI_TimeSyncCounter++; |
461 |
|
|
TI_TimeSync_s = Time; |
462 |
|
|
/* this is incorrect, but it will fix if the interrupt will not come: */ |
463 |
|
|
TI_opSetObtTimeSync(TI_OBT_ms(),TRUE); |
464 |
|
|
OS_PROTECTED_INT(intLevel,TimeSyncExtInt_enabled = TRUE); |
465 |
|
|
} |
466 |
|
|
TI_opResourceRelease(); |
467 |
|
|
|
468 |
|
|
|
469 |
|
|
} |
470 |
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
/*****************************************************************************/ |
474 |
|
|
/* @Function: TI_GetTimeSyncInfo */ |
475 |
|
|
/* @Purpose : */ |
476 |
|
|
/* The function return the time sync infos stored wten the time sync arrived*/ |
477 |
|
|
/* if info is not available, put 0 into both output params and return error */ |
478 |
|
|
/* @@ */ |
479 |
|
|
/* @Parameter Name @Mode @Description */ |
480 |
|
|
/* OBT OUT OBT at the moment of the TSYNC */ |
481 |
|
|
/* TimeSync OUT MoscowTime arrived */ |
482 |
|
|
/* @@ */ |
483 |
|
|
/*****************************************************************************/ |
484 |
|
|
|
485 |
|
|
|
486 |
|
|
status_code TI_opGetTimeSyncInfo_s(TI_TIME *obt_ts,TI_TIME *ts) { |
487 |
|
|
status_code status; |
488 |
|
|
volatile TI_TIME TI_ObtTimeSync_s_local; |
489 |
|
|
UINT32 intLevel; |
490 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
491 |
|
|
if(TI_TimeSyncCounter > 0) { |
492 |
|
|
OS_PROTECTED_INT(intLevel,TI_ObtTimeSync_s_local = TI_ObtTimeSync_s); |
493 |
|
|
*obt_ts = TI_ObtTimeSync_s_local; |
494 |
|
|
*ts = TI_TimeSync_s; |
495 |
|
|
status=TI_SUCCESSFUL; |
496 |
|
|
} else { |
497 |
|
|
status=TI_NOTIMESYNC; |
498 |
|
|
*obt_ts = 0; |
499 |
|
|
*ts = 0; |
500 |
|
|
} |
501 |
|
|
} |
502 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
503 |
|
|
status = TI_RESERROR; |
504 |
|
|
return status; |
505 |
|
|
} |
506 |
|
|
|
507 |
|
|
/*****************************************************************************/ |
508 |
|
|
/* @Function: TI_GetTimeSyncOffset */ |
509 |
|
|
/* @Purpose : */ |
510 |
|
|
/* The function return the TIME_SYNC_OFFSET that is TI_OBT - */ |
511 |
|
|
/* TI_ObtTimeSync. */ |
512 |
|
|
/* @@ */ |
513 |
|
|
/* @Parameter Name @Mode @Description */ |
514 |
|
|
/* Time IN The "Moscow Time" in seconds */ |
515 |
|
|
/* @@ */ |
516 |
|
|
/*****************************************************************************/ |
517 |
|
|
|
518 |
|
|
status_code TI_opGetTimeSyncOffset_s(TI_TIME *t) { |
519 |
|
|
status_code status; |
520 |
|
|
volatile TI_TIME TI_ObtTimeSync_s_local; |
521 |
|
|
UINT32 intLevel; |
522 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
523 |
|
|
if(TI_TimeSyncCounter > 0) { |
524 |
|
|
OS_PROTECTED_INT(intLevel,TI_ObtTimeSync_s_local = TI_ObtTimeSync_s); |
525 |
|
|
*t = TI_OBT_s() - TI_ObtTimeSync_s_local; |
526 |
|
|
status=TI_SUCCESSFUL; |
527 |
|
|
} else |
528 |
|
|
status=TI_NOTIMESYNC; |
529 |
|
|
} |
530 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
531 |
|
|
status = TI_RESERROR; |
532 |
|
|
return status; |
533 |
|
|
} |
534 |
|
|
|
535 |
|
|
|
536 |
|
|
/*****************************************************************************/ |
537 |
|
|
/* @Function: TI_GetCurrentMoscowTime */ |
538 |
|
|
/* @Purpose : */ |
539 |
|
|
/* The current moscow time is the TimeSync plus the "time sync offset", */ |
540 |
|
|
/* that is TI_OBT - TI_ObtTimeSync */ |
541 |
|
|
/* @@ */ |
542 |
|
|
/* @Parameter Name @Mode @Description */ |
543 |
|
|
/* t OUT The "Moscow Time" in seconds */ |
544 |
|
|
/* @@ */ |
545 |
|
|
/*****************************************************************************/ |
546 |
|
|
|
547 |
|
|
status_code TI_opGetCurrentMoscowTime_s(TI_TIME *t) { |
548 |
|
|
status_code status; |
549 |
|
|
volatile TI_TIME TI_ObtTimeSync_s_local; |
550 |
|
|
UINT32 intLevel; |
551 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
552 |
|
|
if(TI_TimeSyncCounter != 0) { |
553 |
|
|
OS_PROTECTED_INT(intLevel,TI_ObtTimeSync_s_local = TI_ObtTimeSync_s); |
554 |
|
|
*t = TI_TimeSync_s + (TI_OBT_s() - TI_ObtTimeSync_s_local); |
555 |
|
|
status=TI_SUCCESSFUL; |
556 |
|
|
} else { |
557 |
|
|
*t = 0; |
558 |
|
|
status=TI_NOTIMESYNC; |
559 |
|
|
} |
560 |
|
|
} |
561 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
562 |
|
|
status = TI_RESERROR; |
563 |
|
|
return status; |
564 |
|
|
} |
565 |
|
|
|
566 |
|
|
|
567 |
|
|
/*****************************************************************************/ |
568 |
|
|
/* @Function: TI_TimeSyncIsAvailable */ |
569 |
|
|
/* @Purpose : */ |
570 |
|
|
/* The information of the TimeSync is available if UpdateTimeInfo has called*/ |
571 |
|
|
/* at least one time, that means a TimeSync MCMD was coming. */ |
572 |
|
|
/* if TI_TimeSyncCounter == 0, then the information is not available. */ |
573 |
|
|
/* @@ */ |
574 |
|
|
/* @Parameter Name @Mode @Description */ |
575 |
|
|
/* t OUT The "Moscow Time" in seconds */ |
576 |
|
|
/* @@ */ |
577 |
|
|
/*****************************************************************************/ |
578 |
|
|
|
579 |
|
|
status_code TI_opTimeSyncIsAvailable(BOOL* avail) { |
580 |
|
|
status_code status; |
581 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
582 |
|
|
*avail = (TI_TimeSyncCounter != 0); |
583 |
|
|
} |
584 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
585 |
|
|
status = TI_RESERROR; |
586 |
|
|
return status; |
587 |
|
|
} |
588 |
|
|
|
589 |
|
|
|
590 |
|
|
/*****************************************************************************/ |
591 |
|
|
/* @Function: TI_SetObtOrbit */ |
592 |
|
|
/* @Purpose : */ |
593 |
|
|
/* The TI_ObtOrbit is defined to be the OBT (TI_OBT) in the moment */ |
594 |
|
|
/* of the ascending node. This function sets the TI_ObtOrbit properly and */ |
595 |
|
|
/* it sshould be called only when the */ |
596 |
|
|
/* ascending node MCMD (CALIBRATE) cames. */ |
597 |
|
|
/* @@ */ |
598 |
|
|
/* @Parameter Name @Mode @Description */ |
599 |
|
|
/* t OUT The "Moscow Time" in seconds */ |
600 |
|
|
/* @@ */ |
601 |
|
|
/*****************************************************************************/ |
602 |
|
|
|
603 |
|
|
status_code TI_opSetObtOrbit_s() { |
604 |
|
|
status_code status; |
605 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
606 |
|
|
TI_ObtOrbit_s = TI_OBT_s(); |
607 |
|
|
} |
608 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
609 |
|
|
status = TI_RESERROR; |
610 |
|
|
return status; |
611 |
|
|
} |
612 |
|
|
|
613 |
|
|
status_code TI_opGetObtOrbit_s(TI_TIME* t) { |
614 |
|
|
status_code status; |
615 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
616 |
|
|
if(TI_ObtOrbit_s != TI_UNSET) { |
617 |
|
|
*t=TI_ObtOrbit_s; |
618 |
|
|
status=TI_SUCCESSFUL; |
619 |
|
|
}else |
620 |
|
|
status=TI_NOORBIT; |
621 |
|
|
} |
622 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
623 |
|
|
status = TI_RESERROR; |
624 |
|
|
return status; |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
/*****************************************************************************/ |
628 |
|
|
/* @Function: TI_GetOrbitOffset */ |
629 |
|
|
/* @Purpose : */ |
630 |
|
|
/* The Orbit Offset is the time in seconds elapsed since the last ascendind */ |
631 |
|
|
/* node (CALIBRATE) MCMD */ |
632 |
|
|
/* that is TI_OBT-TI_ObtOrbit */ |
633 |
|
|
/* @@ */ |
634 |
|
|
/* @Parameter Name @Mode @Description */ |
635 |
|
|
/* @@ */ |
636 |
|
|
/*****************************************************************************/ |
637 |
|
|
|
638 |
|
|
status_code TI_opGetOrbitOffset_s(TI_TIME *t) { |
639 |
|
|
status_code status; |
640 |
|
|
if( (status=TI_opResourceObtain()) == SUCCESSFUL) { |
641 |
|
|
if(TI_ObtOrbit_s != TI_UNSET) { |
642 |
|
|
*t = TI_OBT_s() - TI_ObtOrbit_s; |
643 |
|
|
status=TI_SUCCESSFUL; |
644 |
|
|
}else |
645 |
|
|
status=TI_NOORBIT; |
646 |
|
|
} |
647 |
|
|
if(TI_opResourceRelease() == TI_RESERROR) |
648 |
|
|
status = TI_RESERROR; |
649 |
|
|
return status; |
650 |
|
|
} |
651 |
|
|
|
652 |
|
|
|
653 |
|
|
/*****************************************************************************/ |
654 |
|
|
/* @Function: TI_StartTimerMoscowTime */ |
655 |
|
|
/* @Purpose : */ |
656 |
|
|
/* This function is a wrapper of the OS_StartTimer_INFN function. */ |
657 |
|
|
/* but the time info is expressed in absolute MoscowTime. */ |
658 |
|
|
/* the function computes the remaining time before the event, */ |
659 |
|
|
/* if the time is elapled (belong into the past, the function return */ |
660 |
|
|
/* TI_ELAPSED */ |
661 |
|
|
/* if the OS_StartTimer returns an error, its logged and return */ |
662 |
|
|
/* TI_TIMERERROR */ |
663 |
|
|
/* this function cannot be called into an ISR becasue the semaphore */ |
664 |
|
|
/* @@ */ |
665 |
|
|
/* @Parameter Name @Mode @Description */ |
666 |
|
|
/* t OUT The "Moscow Time" in seconds */ |
667 |
|
|
/* @@ */ |
668 |
|
|
/*****************************************************************************/ |
669 |
|
|
status_code TI_opStartTimer_INFN_MoscowTime_s(unsigned int Tim,TI_TIME Time,void* Routine,void* UserData) { |
670 |
|
|
status_code status; |
671 |
|
|
TI_TIME now,after; |
672 |
|
|
status = TI_opGetCurrentMoscowTime_s(&now); |
673 |
|
|
if(status == TI_SUCCESSFUL) { |
674 |
|
|
if(now > Time) /* time is elapsed */ |
675 |
|
|
status = TI_ELAPSED; |
676 |
|
|
else { |
677 |
|
|
after = Time - now; |
678 |
|
|
status = OS_piStartTimer_INFN (Tim,after,Routine,UserData); |
679 |
|
|
if (status != SUCCESSFUL) { |
680 |
|
|
/*@LOG StartTimer_INFN error - status */ |
681 |
|
|
LU_INFN_LOG(LU_CRITICAL|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,status); |
682 |
|
|
status=TI_TIMERERROR; |
683 |
|
|
} |
684 |
|
|
} |
685 |
|
|
} |
686 |
|
|
return status; |
687 |
|
|
} |