comparison gsm-fw/comlib/cl_shrd.c @ 664:d36f647c2432

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