comparison g23m/condat/com/src/comlib/cl_shrd.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
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 }
91 else
92 TRACE_EVENT ("Cant open semaphore \"SHARED_SEM\"");
93 }
94 }
95
96 /*
97 +------------------------------------------------------------------------------
98 | Function : cl_shrd_exit
99 +------------------------------------------------------------------------------
100 | Description : Close the semaphore.
101 |
102 | Parameters : void
103 |
104 | Return : void
105 |
106 +------------------------------------------------------------------------------
107 */
108
109 GLOBAL void cl_shrd_exit (void)
110 {
111 TRACE_FUNCTION ("cl_shrd_exit()");
112 if(is_initialized EQ TRUE)
113 {
114 if (sem_SHARED NEQ VSI_ERROR)
115 vsi_s_close (VSI_CALLER sem_SHARED);
116
117 memset(shared_data, 0, sizeof(T_SHRD_DATA));
118 is_initialized = FALSE;
119 }
120 }
121
122 /*
123 +------------------------------------------------------------------------------
124 | Function : cl_shrd_get_loc
125 +------------------------------------------------------------------------------
126 | Description : Copies the content from global T_LOC_INFO to the
127 | passed parameter
128 |
129 | Parameters : <loc_info>: Location information
130 |
131 | Return : void
132 |
133 +------------------------------------------------------------------------------
134 */
135
136 GLOBAL BOOL cl_shrd_get_loc (T_LOC_INFO *loc_info)
137 {
138 BOOL ret = FALSE;
139 TRACE_FUNCTION ("cl_shrd_get_loc()");
140
141 if (sem_SHARED NEQ VSI_ERROR)
142 {
143 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK)
144 {
145 if ( loc_info NEQ NULL )
146 memcpy(loc_info, &shared_data->location_info, sizeof(T_LOC_INFO));
147 vsi_s_release (VSI_CALLER sem_SHARED);
148 ret = TRUE;
149 }
150 else
151 {
152 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\"");
153 return(ret);
154 }
155 }
156 return(ret);
157 }
158
159 /*
160 +------------------------------------------------------------------------------
161 | Function : cl_shrd_set_loc
162 +------------------------------------------------------------------------------
163 | Description : Copies the content from passed parameter to the
164 | global structure
165 |
166 | Parameters : <loc_info>: Location information
167 |
168 | Return : void
169 |
170 +------------------------------------------------------------------------------
171 */
172
173 GLOBAL void cl_shrd_set_loc (T_LOC_INFO *loc_info)
174 {
175 TRACE_FUNCTION ("cl_shrd_set_loc()");
176
177 if (sem_SHARED NEQ VSI_ERROR)
178 {
179 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK)
180 {
181 if ( loc_info NEQ NULL )
182 memcpy(&shared_data->location_info, loc_info, sizeof(T_LOC_INFO));
183 vsi_s_release (VSI_CALLER sem_SHARED);
184 }
185 else
186 {
187 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\"");
188 }
189 }
190 }
191
192 /*
193 +------------------------------------------------------------------------------
194 | Function : cl_shrd_get_tim_adv
195 +------------------------------------------------------------------------------
196 | Description : Copies the content from global T_TIM_ADV to the
197 | passed parameter
198 |
199 | Parameters : <tim_adv>: Timing Advance and ME status.
200 |
201 | Return : void
202 |
203 +------------------------------------------------------------------------------
204 */
205
206 GLOBAL BOOL cl_shrd_get_tim_adv (T_TIM_ADV *tim_adv)
207 {
208 BOOL ret = FALSE;
209 TRACE_FUNCTION ("cl_shrd_get_tim_adv()");
210
211 if (sem_SHARED NEQ VSI_ERROR)
212 {
213 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK)
214 {
215 if ( tim_adv NEQ NULL )
216 memcpy(tim_adv, &shared_data->timing_advance, sizeof(T_TIM_ADV));
217 vsi_s_release (VSI_CALLER sem_SHARED);
218 ret = TRUE;
219 }
220 else
221 {
222 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\"");
223 return(ret);
224 }
225 }
226 return(ret);
227 }
228
229 /*
230 +------------------------------------------------------------------------------
231 | Function : cl_shrd_set_tim_adv
232 +------------------------------------------------------------------------------
233 | Description : Copies the content from passed parameter to the
234 | global structure
235 |
236 | Parameters : <tim_adv>: Timing Advance and ME status.
237 |
238 | Return : void
239 |
240 +------------------------------------------------------------------------------
241 */
242
243 GLOBAL void cl_shrd_set_tim_adv (T_TIM_ADV *tim_adv)
244 {
245 TRACE_FUNCTION ("cl_shrd_set_tim_adv()");
246
247 if (sem_SHARED NEQ VSI_ERROR)
248 {
249 if (vsi_s_get (VSI_CALLER sem_SHARED) EQ VSI_OK)
250 {
251 if ( tim_adv NEQ NULL )
252 memcpy(&shared_data->timing_advance, tim_adv, sizeof(T_TIM_ADV));
253 vsi_s_release (VSI_CALLER sem_SHARED);
254 }
255 else
256 {
257 TRACE_EVENT ("Semaphore not free or Invalid handle \"sem_SHARED\"");
258 }
259 }
260 }
261
262 #endif /* CL_SHRD_C */