comparison src/gpf3/frame/vsi_tim.c @ 2:c41a534f33c6

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