FreeCalypso > hg > freecalypso-citrine
comparison comlib/cl_shrd.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 | Project : COMLIB | |
4 | Modul : cl_shrd.c | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : Definitions of common library functions: Implementation of | |
18 creation of Semaphores and usage of it by any entity in | |
19 PS | |
20 +----------------------------------------------------------------------------- | |
21 */ | |
22 /* | |
23 * Version 1.0 | |
24 */ | |
25 | |
26 /**********************************************************************************/ | |
27 | |
28 /* | |
29 NOTE: | |
30 */ | |
31 | |
32 /**********************************************************************************/ | |
33 #ifndef CL_SHRD_C | |
34 #define CL_SHRD_C | |
35 /*==== INCLUDES ===================================================*/ | |
36 | |
37 #include "config.h" | |
38 #include "fixedconf.h" | |
39 | |
40 #include <string.h> | |
41 #include <stdio.h> | |
42 #include "typedefs.h" | |
43 #include "vsi.h" | |
44 #include "cl_shrd.h" | |
45 | |
46 /*==== VARIABLES ==================================================*/ | |
47 | |
48 static T_HANDLE cl_handle; | |
49 | |
50 #ifdef OPTION_MULTITHREAD | |
51 #define VSI_CALLER cl_handle, | |
52 #else | |
53 #define VSI_CALLER | |
54 #endif | |
55 | |
56 /* Pointer is used for faster memory access */ | |
57 static T_SHRD_DATA shrd_data_base; | |
58 T_SHRD_DATA *shared_data = &shrd_data_base; | |
59 | |
60 static T_HANDLE sem_SHARED = VSI_ERROR; | |
61 static BOOL is_initialized = FALSE; | |
62 | |
63 /*==== FUNCTIONS ==================================================*/ | |
64 | |
65 /* | |
66 +--------------------------------------------------------------------------------- | |
67 | Function : cl_shrd_init | |
68 +--------------------------------------------------------------------------------- | |
69 | Description : Opens counting semaphore specified by its name. | |
70 | If semaphore doesnot exists, creates semaphore with count given. | |
71 | | |
72 | Parameters : T_HANDLE | |
73 | | |
74 | Return : void | |
75 | | |
76 +--------------------------------------------------------------------------------- | |
77 */ | |
78 GLOBAL void cl_shrd_init (T_HANDLE handle) | |
79 { | |
80 TRACE_FUNCTION ("cl_shrd_init()"); | |
81 | |
82 if(is_initialized NEQ TRUE) | |
83 { | |
84 cl_handle = handle; | |
85 | |
86 memset(shared_data, 0, sizeof(T_SHRD_DATA)); | |
87 sem_SHARED = vsi_s_open (VSI_CALLER "SHARED_SEM",1); | |
88 | |
89 if (sem_SHARED NEQ VSI_ERROR) | |
90 { | |
91 TRACE_EVENT ("Semaphore opened successfully \"SHARED_SEM\""); | |
92 is_initialized = TRUE; | |
93 #ifdef TI_PS_FF_AT_P_CMD_CTREG | |
94 /* | |
95 * Initialize the Two tables with the default values | |
96 */ | |
97 memcpy(shared_data->no_serv_mod_time,&no_service_mode_time, | |
98 sizeof(no_service_mode_time)); | |
99 | |
100 memcpy(shared_data->lim_serv_mod_time,&lim_service_mode_time, | |
101 sizeof(lim_service_mode_time)); | |
102 #endif /* TI_PS_FF_AT_P_CMD_CTREG */ | |
103 } | |
104 else | |
105 TRACE_EVENT ("Cant open semaphore \"SHARED_SEM\""); | |
106 } | |
107 } | |
108 | |
109 /* | |
110 +------------------------------------------------------------------------------ | |
111 | Function : cl_shrd_exit | |
112 +------------------------------------------------------------------------------ | |
113 | Description : Close the semaphore. | |
114 | | |
115 | Parameters : void | |
116 | | |
117 | Return : void | |
118 | | |
119 +------------------------------------------------------------------------------ | |
120 */ | |
121 | |
122 GLOBAL void cl_shrd_exit (void) | |
123 { | |
124 TRACE_FUNCTION ("cl_shrd_exit()"); | |
125 if(is_initialized EQ TRUE) | |
126 { | |
127 if (sem_SHARED NEQ VSI_ERROR) | |
128 vsi_s_close (VSI_CALLER sem_SHARED); | |
129 | |
130 memset(shared_data, 0, sizeof(T_SHRD_DATA)); | |
131 is_initialized = FALSE; | |
132 } | |
133 } | |
134 | |
135 /* | |
136 +------------------------------------------------------------------------------ | |
137 | Function : cl_shrd_get_loc | |
138 +------------------------------------------------------------------------------ | |
139 | Description : Copies the content from global T_LOC_INFO to the | |
140 | passed parameter | |
141 | | |
142 | Parameters : <loc_info>: Location information | |
143 | | |
144 | Return : void | |
145 | | |
146 +------------------------------------------------------------------------------ | |
147 */ | |
148 | |
149 GLOBAL BOOL cl_shrd_get_loc (T_LOC_INFO *loc_info) | |
150 { | |
151 BOOL ret = FALSE; | |
152 TRACE_FUNCTION ("cl_shrd_get_loc()"); | |
153 | |
154 if (sem_SHARED NEQ VSI_ERROR) | |
155 { | |
156 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
157 { | |
158 if ( loc_info NEQ NULL ) | |
159 memcpy(loc_info, &shared_data->location_info, sizeof(T_LOC_INFO)); | |
160 vsi_s_release (VSI_CALLER sem_SHARED); | |
161 ret = TRUE; | |
162 } | |
163 else | |
164 { | |
165 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
166 return(ret); | |
167 } | |
168 } | |
169 return(ret); | |
170 } | |
171 | |
172 /* | |
173 +------------------------------------------------------------------------------ | |
174 | Function : cl_shrd_set_loc | |
175 +------------------------------------------------------------------------------ | |
176 | Description : Copies the content from passed parameter to the | |
177 | global structure | |
178 | | |
179 | Parameters : <loc_info>: Location information | |
180 | | |
181 | Return : void | |
182 | | |
183 +------------------------------------------------------------------------------ | |
184 */ | |
185 | |
186 GLOBAL void cl_shrd_set_loc (T_LOC_INFO *loc_info) | |
187 { | |
188 TRACE_FUNCTION ("cl_shrd_set_loc()"); | |
189 | |
190 if (sem_SHARED NEQ VSI_ERROR) | |
191 { | |
192 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
193 { | |
194 if ( loc_info NEQ NULL ) | |
195 memcpy(&shared_data->location_info, loc_info, sizeof(T_LOC_INFO)); | |
196 vsi_s_release (VSI_CALLER sem_SHARED); | |
197 } | |
198 else | |
199 { | |
200 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
201 } | |
202 } | |
203 } | |
204 | |
205 /* | |
206 +------------------------------------------------------------------------------ | |
207 | Function : cl_shrd_get_tim_adv | |
208 +------------------------------------------------------------------------------ | |
209 | Description : Copies the content from global T_TIM_ADV to the | |
210 | passed parameter | |
211 | | |
212 | Parameters : <tim_adv>: Timing Advance and ME status. | |
213 | | |
214 | Return : void | |
215 | | |
216 +------------------------------------------------------------------------------ | |
217 */ | |
218 | |
219 GLOBAL BOOL cl_shrd_get_tim_adv (T_TIM_ADV *tim_adv) | |
220 { | |
221 BOOL ret = FALSE; | |
222 TRACE_FUNCTION ("cl_shrd_get_tim_adv()"); | |
223 | |
224 if (sem_SHARED NEQ VSI_ERROR) | |
225 { | |
226 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
227 { | |
228 if ( tim_adv NEQ NULL ) | |
229 memcpy(tim_adv, &shared_data->timing_advance, sizeof(T_TIM_ADV)); | |
230 vsi_s_release (VSI_CALLER sem_SHARED); | |
231 ret = TRUE; | |
232 } | |
233 else | |
234 { | |
235 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
236 return(ret); | |
237 } | |
238 } | |
239 return(ret); | |
240 } | |
241 | |
242 /* | |
243 +------------------------------------------------------------------------------ | |
244 | Function : cl_shrd_set_tim_adv | |
245 +------------------------------------------------------------------------------ | |
246 | Description : Copies the content from passed parameter to the | |
247 | global structure | |
248 | | |
249 | Parameters : <tim_adv>: Timing Advance and ME status. | |
250 | | |
251 | Return : void | |
252 | | |
253 +------------------------------------------------------------------------------ | |
254 */ | |
255 | |
256 GLOBAL void cl_shrd_set_tim_adv (T_TIM_ADV *tim_adv) | |
257 { | |
258 TRACE_FUNCTION ("cl_shrd_set_tim_adv()"); | |
259 | |
260 if (sem_SHARED NEQ VSI_ERROR) | |
261 { | |
262 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
263 { | |
264 if ( tim_adv NEQ NULL ) | |
265 memcpy(&shared_data->timing_advance, tim_adv, sizeof(T_TIM_ADV)); | |
266 vsi_s_release (VSI_CALLER sem_SHARED); | |
267 } | |
268 else | |
269 { | |
270 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
271 } | |
272 } | |
273 } | |
274 #ifdef TI_PS_FF_AT_P_CMD_CTREG | |
275 /* | |
276 +------------------------------------------------------------------------------ | |
277 | Function : cl_shrd_set_treg_val | |
278 +------------------------------------------------------------------------------ | |
279 | Description : Copies the content from passed parameter to the | |
280 | global structure Used for %CTREG setting the values. | |
281 | | |
282 | Parameters : <mode> : Selects the mode of operation read or write | |
283 | <tab_id> : Selects either no_service_mode_time or | |
284 | lim_service_mode_time for updating. | |
285 | <tab_val>: Table values to be updated in the selcted table. | |
286 | | |
287 | Return : BOOL | |
288 | | |
289 +------------------------------------------------------------------------------ | |
290 */ | |
291 | |
292 GLOBAL BOOL cl_shrd_set_treg_val ( T_TREG *treg ) | |
293 { | |
294 UBYTE i; | |
295 BOOL ret = FALSE; | |
296 | |
297 TRACE_FUNCTION ("cl_shrd_set_treg_val()"); | |
298 | |
299 if (sem_SHARED NEQ VSI_ERROR) | |
300 { | |
301 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
302 { | |
303 if ( treg NEQ NULL ) | |
304 { | |
305 switch(treg->tab_id) | |
306 { | |
307 case NOSERVICE_MODE_TIME: | |
308 memcpy(shared_data->no_serv_mod_time, treg->tab_val, | |
309 MAX_CTREG_TAB_LEN); | |
310 break; | |
311 case LIMSERVICE_MODE_TIME: | |
312 memcpy(shared_data->lim_serv_mod_time, treg->tab_val, | |
313 MAX_CTREG_TAB_LEN); | |
314 break; | |
315 default: | |
316 break; | |
317 } | |
318 ret = TRUE; | |
319 } | |
320 vsi_s_release (VSI_CALLER sem_SHARED); | |
321 } | |
322 else | |
323 { | |
324 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
325 } | |
326 } | |
327 return(ret); | |
328 } | |
329 | |
330 /* | |
331 +------------------------------------------------------------------------------ | |
332 | Function : cl_shrd_get_treg_val | |
333 +------------------------------------------------------------------------------ | |
334 | Description : Reads the content from passed parameter to the | |
335 | global structure. | |
336 | | |
337 | Parameters : <mode> : Selects the mode of operation read or write | |
338 | <tab_id> : Selects either no_service_mode_time or | |
339 | lim_service_mode_time for updating. | |
340 | <tab_val>: Table values to be read from the selected table. | |
341 | | |
342 | Return : BOOL | |
343 | | |
344 +------------------------------------------------------------------------------ | |
345 */ | |
346 | |
347 GLOBAL BOOL cl_shrd_get_treg_val ( T_TREG *treg ) | |
348 { | |
349 UBYTE i; | |
350 BOOL ret = FALSE; | |
351 | |
352 TRACE_FUNCTION ("cl_shrd_get_treg_val()"); | |
353 | |
354 if (sem_SHARED NEQ VSI_ERROR) | |
355 { | |
356 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
357 { | |
358 if ( treg NEQ NULL ) | |
359 { | |
360 switch(treg->tab_id) | |
361 { | |
362 case NOSERVICE_MODE_TIME: | |
363 memcpy(treg->tab_val, shared_data->no_serv_mod_time, | |
364 MAX_CTREG_TAB_LEN); | |
365 break; | |
366 case LIMSERVICE_MODE_TIME: | |
367 memcpy(treg->tab_val, shared_data->lim_serv_mod_time, | |
368 MAX_CTREG_TAB_LEN); | |
369 break; | |
370 default: | |
371 break; | |
372 } | |
373 ret = TRUE; | |
374 } | |
375 vsi_s_release (VSI_CALLER sem_SHARED); | |
376 } | |
377 else | |
378 { | |
379 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
380 } | |
381 } | |
382 return(ret); | |
383 } | |
384 | |
385 /* | |
386 +------------------------------------------------------------------------------ | |
387 | Function : cl_shrd_get_treg | |
388 +------------------------------------------------------------------------------ | |
389 | Description : Reads the TREG Timer value from the selected Table and | |
390 | returns the data to called Entity (RR) | |
391 | | |
392 | Parameters : <tab_id> : Selects either no_service_mode_time or | |
393 | lim_service_mode_time for getting TREG value. | |
394 | <offset> : Offset value to point at exact position in the | |
395 | selected Table for getting TREG value. | |
396 | <tab_val>: Table value in the selcted table. | |
397 | | |
398 | Return : BOOL | |
399 | | |
400 +------------------------------------------------------------------------------ | |
401 */ | |
402 | |
403 GLOBAL BOOL cl_shrd_get_treg (UBYTE tab_id, UBYTE offset, UBYTE *tab_val) | |
404 { | |
405 BOOL ret = FALSE; | |
406 | |
407 TRACE_FUNCTION ("cl_shrd_get_treg()"); | |
408 | |
409 if (sem_SHARED NEQ VSI_ERROR) | |
410 { | |
411 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK) | |
412 { | |
413 /* Check for the proper value of offset, it should be between 0 to 24 */ | |
414 if(offset > (MAX_CTREG_TAB_LEN - 1)) | |
415 { | |
416 return(ret); | |
417 } | |
418 switch(tab_id) | |
419 { | |
420 case NOSERVICE_MODE_TIME: | |
421 *tab_val = shared_data->no_serv_mod_time[offset]; | |
422 break; | |
423 case LIMSERVICE_MODE_TIME: | |
424 *tab_val = shared_data->lim_serv_mod_time[offset]; | |
425 break; | |
426 default: | |
427 break; | |
428 } | |
429 ret = TRUE; | |
430 vsi_s_release (VSI_CALLER sem_SHARED); | |
431 } | |
432 else | |
433 { | |
434 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\""); | |
435 } | |
436 } | |
437 return(ret); | |
438 } | |
439 #endif /* TI_PS_FF_AT_P_CMD_CTREG */ | |
440 | |
441 #endif /* CL_SHRD_C */ |