FreeCalypso > hg > freecalypso-citrine
comparison gpf/frame/vsi_tim.c @ 0:75a11d740a02
initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 Jun 2016 00:02:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: vsi_tim.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2002 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : This Module defines the virtual system interface part | |
17 | for the timer handling. | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef __VSI_TIM_C__ | |
22 #define __VSI_TIM_C__ | |
23 #endif | |
24 | |
25 /*==== INCLUDES ===================================================*/ | |
26 | |
27 #include <string.h> | |
28 | |
29 #include "gpfconf.h" | |
30 #include "typedefs.h" | |
31 | |
32 #include "vsi.h" | |
33 #include "os.h" | |
34 #include "tools.h" | |
35 #include "frm_defs.h" | |
36 #include "frm_types.h" | |
37 #include "frm_glob.h" | |
38 #include "frame.h" | |
39 | |
40 /*==== TYPES ======================================================*/ | |
41 | |
42 typedef struct _T_TIMER_CONFIG_ENTRY | |
43 { | |
44 T_HANDLE entity; | |
45 T_TIME value; | |
46 USHORT index; | |
47 USHORT mode; | |
48 struct _T_TIMER_CONFIG_ENTRY *next; | |
49 } T_TIMER_CONFIG_ENTRY; | |
50 | |
51 /*==== CONSTANTS ==================================================*/ | |
52 | |
53 LOCAL const T_STR_IND StrInd[] = | |
54 { | |
55 "TIMER_SET", TIMER_SET, | |
56 "TIMER_RESET", TIMER_RESET, | |
57 "TIMER_SPEED_UP", TIMER_SPEED_UP, | |
58 "TIMER_SLOW_DOWN", TIMER_SLOW_DOWN, | |
59 "TIMER_SUPPRESS", TIMER_SUPPRESS, | |
60 "TIMER_CLEAN", TIMER_CLEAN, | |
61 NULL, 0 | |
62 }; | |
63 | |
64 /*==== EXTERNALS ==================================================*/ | |
65 /* -------------- S H A R E D - BEGIN ---------------- */ | |
66 #ifdef _TOOLS_ | |
67 #pragma data_seg("FRAME_SHARED") | |
68 #endif | |
69 | |
70 extern OS_HANDLE ext_data_pool_handle; | |
71 extern T_HANDLE TimerHandleField[]; | |
72 | |
73 /*==== VARIABLES ==================================================*/ | |
74 | |
75 #ifndef RUN_INT_RAM | |
76 char timer_configured; | |
77 T_TIMER_CONFIG_ENTRY *t_config; | |
78 #else | |
79 extern char timer_configured; | |
80 extern T_TIMER_CONFIG_ENTRY *t_config; | |
81 #endif | |
82 | |
83 #ifdef _TOOLS_ | |
84 #pragma data_seg() | |
85 #endif | |
86 /* -------------- S H A R E D - END ---------------- */ | |
87 | |
88 /*==== FUNCTIONS ==================================================*/ | |
89 | |
90 int GetTimerStartValue ( T_HANDLE Caller, USHORT TimerIndex, T_TIME OrgValue, T_TIME *NewValue ); | |
91 | |
92 #ifndef RUN_FLASH | |
93 /* | |
94 +--------------------------------------------------------------------+ | |
95 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
96 | STATE : code ROUTINE : GetTimerStartValue | | |
97 +--------------------------------------------------------------------+ | |
98 | |
99 PURPOSE : get start time modified by dynamic configuration | |
100 | |
101 */ | |
102 | |
103 int GetTimerStartValue ( T_HANDLE caller, USHORT index, T_TIME org_value, T_TIME *new_value ) | |
104 { | |
105 T_TIMER_CONFIG_ENTRY *t_config_entry; | |
106 int found; | |
107 | |
108 if ( t_config != NULL ) | |
109 { | |
110 found = FALSE; | |
111 t_config_entry = t_config; | |
112 while ( found == FALSE && t_config_entry != NULL ) | |
113 { | |
114 if ( t_config_entry->entity == caller | |
115 && t_config_entry->index == index ) | |
116 { | |
117 found = TRUE; | |
118 switch (t_config_entry->mode) | |
119 { | |
120 case TIMER_SET: | |
121 *new_value = t_config_entry->value; | |
122 break; | |
123 | |
124 case TIMER_RESET: | |
125 *new_value = org_value; | |
126 break; | |
127 | |
128 case TIMER_SPEED_UP: | |
129 *new_value = org_value / t_config_entry->value; | |
130 break; | |
131 | |
132 case TIMER_SLOW_DOWN: | |
133 *new_value = org_value * t_config_entry->value; | |
134 break; | |
135 | |
136 default: | |
137 return VSI_ERROR; | |
138 } | |
139 vsi_o_ttrace ( caller, TC_TIMER, "Timerstart: Index %d, Time %d -> %d",index, org_value, *new_value ); | |
140 } | |
141 t_config_entry = t_config_entry->next; | |
142 } | |
143 if ( found == FALSE ) | |
144 { | |
145 *new_value = org_value; | |
146 } | |
147 } | |
148 else | |
149 { | |
150 *new_value = org_value; | |
151 } | |
152 if (*new_value == 0) | |
153 { | |
154 *new_value = 1; | |
155 } | |
156 return VSI_OK; | |
157 } | |
158 #endif | |
159 | |
160 #ifndef RUN_FLASH | |
161 /* | |
162 +--------------------------------------------------------------------+ | |
163 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
164 | STATE : code ROUTINE : vsi_t_start | | |
165 +--------------------------------------------------------------------+ | |
166 | |
167 PURPOSE : start timer that expires only once | |
168 | |
169 */ | |
170 | |
171 int vsi_t_start (T_HANDLE Caller, USHORT TimerIndex, T_TIME Value) | |
172 { | |
173 OS_HANDLE TimerHandle; | |
174 | |
175 vsi_o_ttrace ( Caller, TC_TIMER, "Timerstart: Index %d, Time %d",TimerIndex, Value) ; | |
176 | |
177 if ( TimerIndex >= pf_TaskTable[Caller].NumOfTimers ) | |
178 vsi_o_assert( NO_TASK, OS_SYST_ERR_TASK_TIMER, __FILE__, __LINE__, | |
179 "TimerIndex > NumOfTimers for entity %s", pf_TaskTable[Caller].Name ); | |
180 | |
181 TimerHandle = (*(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) & TIMER_HANDLE_MASK); | |
182 | |
183 if ( !TimerHandle ) | |
184 { | |
185 if ( os_CreateTimer ( Caller, pf_Timeout, &TimerHandle, pf_TaskTable[Caller].MemPoolHandle ) == OS_ERROR ) | |
186 vsi_o_assert( Caller, OS_SYST_ERR_SIMUL_TIMER, __FILE__, __LINE__, | |
187 "Number of started timers > MAX_SIMULTANEOUS_TIMER" ); | |
188 } | |
189 if ( timer_configured && GetTimerStartValue ( Caller, TimerIndex, Value, &Value ) == VSI_ERROR ) | |
190 return VSI_ERROR; | |
191 | |
192 *(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) = TimerHandle; | |
193 | |
194 if ( os_StartTimer ( Caller, TimerHandle, TimerIndex, Value, 0 ) == OS_ERROR ) | |
195 return VSI_ERROR; | |
196 | |
197 return VSI_OK; | |
198 } | |
199 #endif | |
200 | |
201 #ifndef RUN_INT_RAM | |
202 /* | |
203 +--------------------------------------------------------------------+ | |
204 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
205 | STATE : code ROUTINE : vsi_t_pstart | | |
206 +--------------------------------------------------------------------+ | |
207 | |
208 PURPOSE : start periodic timer | |
209 | |
210 */ | |
211 | |
212 int vsi_t_pstart (T_HANDLE Caller, USHORT TimerIndex, T_TIME Value1, T_TIME Value2 ) | |
213 { | |
214 OS_HANDLE TimerHandle; | |
215 | |
216 vsi_o_ttrace ( Caller, TC_TIMER, "Timerstart: Index %d, ITime %d PTime %d",TimerIndex, Value1, Value2) ; | |
217 | |
218 if ( TimerIndex >= pf_TaskTable[Caller].NumOfTimers ) | |
219 vsi_o_assert( NO_TASK, OS_SYST_ERR_TASK_TIMER, __FILE__, __LINE__, | |
220 "TimerIndex > NumOfTimers for entity %s", pf_TaskTable[Caller].Name ); | |
221 | |
222 TimerHandle = (*(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) & TIMER_HANDLE_MASK); | |
223 | |
224 if ( !TimerHandle ) | |
225 { | |
226 if ( os_CreateTimer ( Caller, pf_Timeout, &TimerHandle, pf_TaskTable[Caller].MemPoolHandle ) == OS_ERROR ) | |
227 vsi_o_assert( Caller, OS_SYST_ERR_SIMUL_TIMER, __FILE__, __LINE__, | |
228 "Number of started timers > MAX_SIMULTANEOUS_TIMER" ); | |
229 } | |
230 | |
231 if ( timer_configured && GetTimerStartValue ( Caller, TimerIndex, Value1, &Value1 ) == VSI_ERROR ) | |
232 return VSI_ERROR; | |
233 | |
234 if ( timer_configured && GetTimerStartValue ( Caller, TimerIndex, Value2, &Value2 ) == VSI_ERROR ) | |
235 return VSI_ERROR; | |
236 | |
237 *(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) = TimerHandle | PERIODIC_TIMER; | |
238 | |
239 if ( os_StartTimer ( Caller, TimerHandle, TimerIndex, Value1, Value2 ) == OS_ERROR ) | |
240 return VSI_ERROR; | |
241 | |
242 return VSI_OK; | |
243 } | |
244 #endif | |
245 | |
246 #ifndef RUN_FLASH | |
247 /* | |
248 +--------------------------------------------------------------------+ | |
249 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
250 | STATE : code ROUTINE : vsi_t_stop | | |
251 +--------------------------------------------------------------------+ | |
252 | |
253 PURPOSE : stop timer | |
254 | |
255 */ | |
256 | |
257 int vsi_t_stop (T_HANDLE Caller, USHORT TimerIndex ) | |
258 { | |
259 OS_HANDLE TimerHandle; | |
260 | |
261 vsi_o_ttrace ( Caller, TC_TIMER, "Timerstop: Index %d",TimerIndex) ; | |
262 TimerHandle = (*(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) & TIMER_HANDLE_MASK); | |
263 if ( TimerHandle && ( (TimerHandle & TIMER_HANDLE_MASK) < MaxTimer ) ) | |
264 { | |
265 /* | |
266 if ( os_StopTimer ( Caller, TimerHandle ) == OS_ERROR ) | |
267 return VSI_ERROR; | |
268 | |
269 if ( os_DestroyTimer ( Caller, TimerHandle ) == OS_ERROR ) | |
270 return VSI_ERROR; | |
271 */ | |
272 os_StopTimer ( Caller, TimerHandle ); | |
273 os_DestroyTimer ( Caller, TimerHandle ); | |
274 | |
275 *(pf_TaskTable[Caller].FirstTimerEntry + TimerIndex) = 0; | |
276 return VSI_OK; | |
277 } | |
278 return VSI_ERROR; | |
279 | |
280 } | |
281 #endif | |
282 | |
283 #ifndef RUN_INT_RAM | |
284 /* | |
285 +--------------------------------------------------------------------+ | |
286 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
287 | STATE : code ROUTINE : vsi_t_status | | |
288 +--------------------------------------------------------------------+ | |
289 | |
290 PURPOSE : request remaining time | |
291 | |
292 */ | |
293 | |
294 int vsi_t_status (T_HANDLE Caller, USHORT Index, T_TIME *Value ) | |
295 { | |
296 OS_HANDLE TimerHandle; | |
297 | |
298 if ( (TimerHandle = (*(pf_TaskTable[Caller].FirstTimerEntry + Index) & TIMER_HANDLE_MASK) ) < MaxTimer ) | |
299 { | |
300 if ( TimerHandle == 0 || (*(pf_TaskTable[Caller].FirstTimerEntry + Index) & TIMEOUT_OCCURRED) ) | |
301 { | |
302 *Value = 0; | |
303 vsi_o_ttrace ( Caller, TC_TIMER, "Timerstatus: Index %d, Remaining_time %d",Index, *Value) ; | |
304 return VSI_OK; | |
305 } | |
306 /* | |
307 In case the timer interrupt occurrs just after the check 5 lines above, this will be handled by | |
308 os_QueryTimer() returning a Value of 0 because thew expired timer can no longer be found in the list. | |
309 */ | |
310 if ( os_QueryTimer ( Caller, TimerHandle, Value ) == OS_ERROR ) | |
311 { | |
312 *Value = 0; | |
313 return VSI_ERROR; | |
314 } | |
315 vsi_o_ttrace ( Caller, TC_TIMER, "Timerstatus: Index %d, Remaining time %d",Index, *Value) ; | |
316 return VSI_OK; | |
317 } | |
318 vsi_o_ttrace ( Caller, TC_TIMER, "TimerHandle out of range: Index %d, TimerHandle %d",Index, TimerHandle ) ; | |
319 return VSI_ERROR; | |
320 | |
321 } | |
322 #endif | |
323 | |
324 #ifndef RUN_INT_RAM | |
325 /* | |
326 +--------------------------------------------------------------------+ | |
327 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
328 | STATE : code ROUTINE : vsi_t_config | | |
329 +--------------------------------------------------------------------+ | |
330 | |
331 PURPOSE : timer configuration | |
332 | |
333 */ | |
334 int vsi_t_config (T_HANDLE caller, USHORT index, UBYTE mode, ULONG value ) | |
335 { | |
336 T_TIMER_CONFIG_ENTRY *t_config_entry = NULL; | |
337 T_TIMER_CONFIG_ENTRY *t_next_entry; | |
338 T_TIMER_CONFIG_ENTRY *t_new_entry = NULL; | |
339 int found = FALSE; | |
340 | |
341 if ( index < pf_TaskTable[caller].NumOfTimers ) | |
342 { | |
343 if ( t_config != NULL ) | |
344 { | |
345 t_next_entry = t_config; | |
346 do | |
347 { | |
348 t_config_entry = t_next_entry; | |
349 if ( t_config_entry->entity == caller | |
350 && t_config_entry->index == index ) | |
351 { | |
352 found = TRUE; | |
353 break; | |
354 } | |
355 t_next_entry = t_config_entry->next; | |
356 } while ( t_next_entry != NULL ); | |
357 } | |
358 | |
359 if ( found == FALSE ) | |
360 { | |
361 if ( os_AllocateMemory ( caller, (T_VOID_STRUCT**)&t_new_entry, sizeof(T_TIMER_CONFIG_ENTRY), OS_NO_SUSPEND, ext_data_pool_handle ) == OS_TIMEOUT ) | |
362 return VSI_ERROR; | |
363 t_new_entry->next = NULL; | |
364 } | |
365 | |
366 if ( t_config == NULL ) | |
367 { | |
368 t_config = t_new_entry; | |
369 t_config_entry = t_new_entry; | |
370 } | |
371 else | |
372 { | |
373 if ( found == FALSE && t_config_entry != NULL ) | |
374 { | |
375 t_config_entry->next = t_new_entry; | |
376 t_config_entry = t_new_entry; | |
377 } | |
378 } | |
379 | |
380 if ( t_config_entry != NULL ) | |
381 { | |
382 t_config_entry->entity = caller; | |
383 t_config_entry->index = index; | |
384 t_config_entry->mode = mode; | |
385 t_config_entry->value = value; | |
386 timer_configured = TRUE; | |
387 return VSI_OK; | |
388 } | |
389 } | |
390 return VSI_ERROR; | |
391 } | |
392 #endif | |
393 | |
394 #ifndef RUN_INT_RAM | |
395 /* | |
396 +------------------------------------------------------------------------------ | |
397 | Function : _vsi_t_config | |
398 +------------------------------------------------------------------------------ | |
399 | Description : Parse a timer configuration string into the components | |
400 | timer index, timer mode, timer value. | |
401 | | |
402 | Parameters : Caller - calling task | |
403 | *CfgString - configuration string | |
404 | *pTable - pointer to configuration string table | |
405 | | |
406 | Return : VSI_OK | |
407 | VSI_ERROR | |
408 +------------------------------------------------------------------------------ | |
409 */ | |
410 int _vsi_t_config ( T_HANDLE Caller, char *CfgString, const T_STR_IND *pTable ) | |
411 { | |
412 T_TIMER_CONFIG_ENTRY *t_config_entry; | |
413 T_TIMER_CONFIG_ENTRY *t_next; | |
414 char token[20]; | |
415 unsigned int offset = 0,len; | |
416 USHORT Index; | |
417 BYTE Mode; | |
418 int i = 0; | |
419 unsigned int Value; | |
420 | |
421 if ( pTable != NULL ) | |
422 { | |
423 len = GetNextToken (CfgString, token, " #"); | |
424 offset = offset + len +1; | |
425 while ( StrInd[i].Str && strcmp ( token, StrInd[i].Str ) ) | |
426 { i++; } | |
427 if ( StrInd[i].Str == NULL ) | |
428 return VSI_ERROR; | |
429 | |
430 if ( (Mode = (BYTE)StrInd[i].Ind) == TIMER_CLEAN ) | |
431 { | |
432 t_config_entry = t_config; | |
433 while ( t_config_entry != NULL ) | |
434 { | |
435 t_next = t_config_entry->next; | |
436 os_DeallocateMemory ( Caller, (T_VOID_STRUCT*)t_config_entry ); | |
437 t_config_entry = t_next; | |
438 } | |
439 t_config = NULL; | |
440 return VSI_OK; | |
441 } | |
442 len = GetNextToken (CfgString+offset, token, " #"); | |
443 offset = offset + len +1; | |
444 while ( pTable->Str && strcmp ( token, pTable->Str ) ) | |
445 { pTable++; } | |
446 if ( pTable->Str == NULL ) | |
447 { | |
448 vsi_o_ttrace ( 0, TC_SYSTEM, "Timer not found!") ; | |
449 return VSI_OK; /* VSI_OK is returned to avoid creating a new return code */ | |
450 } | |
451 Index = pTable->Ind; | |
452 len = GetNextToken (CfgString+offset, token, " #"); | |
453 Value = ASCIIToHex (token, CHARS_FOR_32BIT); | |
454 | |
455 return ( vsi_t_config ( Caller, Index, Mode, Value ) ); | |
456 } | |
457 return VSI_ERROR; | |
458 | |
459 } | |
460 #endif | |
461 | |
462 #ifndef RUN_INT_RAM | |
463 /* | |
464 +---------------------------------------------------------------------+ | |
465 | PROJECT : GSM-Frame (8415) MODULE : VSI_TIM | | |
466 | STATE : code ROUTINE : InitializeTimerConfig| | |
467 +---------------------------------------------------------------------+ | |
468 | |
469 PURPOSE : initialize timer configuration | |
470 | |
471 */ | |
472 | |
473 void InitializeTimer ( void ) | |
474 { | |
475 int i; | |
476 | |
477 for ( i = 0; i <= MaxTimer; i++) | |
478 { | |
479 TimerHandleField[i] = 0; | |
480 } | |
481 timer_configured = FALSE; | |
482 t_config = NULL; | |
483 } | |
484 #endif | |
485 | |
486 |