comparison g23m-gsm/dl/dl_em.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 :
4 | Modul :
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 : This Module defines the engineering mode (EM) device driver for the
18 | G23 protocol stack. This driver is used to control all engineering
19 | mode related functions.
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef DL_EM_C
24 #define DL_EM_C
25
26 #include "config.h"
27 #include "fixedconf.h"
28 #include "condat-features.h"
29
30 #define ENTITY_DL
31
32 /*==== INCLUDES ===================================================*/
33 #include "typedefs.h"
34 #include <string.h>
35 #include "pconst.cdg"
36 #include "vsi.h"
37 #include "pconst.cdg"
38 #include "custom.h"
39 #include "gsm.h"
40 #include "mon_dl.h"
41 #include "prim.h"
42 #include "pei.h"
43 #include "tok.h"
44 #include "ccdapi.h"
45 #include "dl.h"
46 #include "dl_em.h"
47
48 #ifdef FF_EM_MODE
49 #ifdef _SIMULATION_
50 #pragma message("this build includes engineering mode (FF_EM_MODE)")
51 #endif
52
53 /*==== EXPORT =====================================================*/
54 /*
55 * These variables are used between entities. Even this is not a clean solution
56 * it is a straigth forward way to reduce the overhead to a minimum. A clean
57 * solution would be based on an only usage of primitives which would stress
58 * the OS without aditional advantage!!
59 */
60 GLOBAL UBYTE em_dl_sem_buffer [EM_DL_SEM_SIZE];
61 GLOBAL UBYTE em_dl_sem_index = 0;
62 GLOBAL UBYTE em_dl_sem_read_index = 0;
63
64 /* Event tracing flags for EM */
65 GLOBAL BOOL dl_v[EM_MAX_DL_EVENTS];
66
67 /*==== PRIVAT =====================================================*/
68 static T_HANDLE sem_EM_DL;
69 static UBYTE em_dl_trace_occured;
70
71 #if !defined(INVOKE_SIGNAL)
72 LOCAL UBYTE em_dl_write (UBYTE length, UBYTE * data);
73 LOCAL void dl_em_first_event_check(void);/*for ACI notification of first EM event*/
74 #endif /* !INVOKE_SIGNAL */
75
76 /*==== VARIABLES ==================================================*/
77
78
79
80 /*
81 +------------------------------------------------------------------------------
82 | Function : dl_em_buffer_4
83 +------------------------------------------------------------------------------
84 | Description : Perform buffer check and store corresponding data in it.
85 |
86 | Parameters : Event number, data value1, data value2
87 |
88 | Return : TRUE/FALSE
89 |
90 +------------------------------------------------------------------------------
91 */
92
93 GLOBAL UBYTE em_write_buffer_4 (UBYTE event_no, UBYTE value1, UBYTE value2)
94 {
95 #define THIS_EM_BUFFER_LEN 4
96 UBYTE em_dl_event_buffer[THIS_EM_BUFFER_LEN];
97
98 TRACE_EVENT_WIN ("em_write_buffer_4");
99
100 /*
101 ACI is informed about the first event trace, used for later data processing.
102 */
103
104 dl_em_first_event_check();
105
106 em_dl_event_buffer[0] = event_no; /* Event number */
107 em_dl_event_buffer[1] = THIS_EM_BUFFER_LEN-2; /* Value length - 0 equals no data */
108 em_dl_event_buffer[2] = value1; /* first data info */
109 em_dl_event_buffer[3] = value2; /* second data info */
110
111 return ( em_dl_write (THIS_EM_BUFFER_LEN, em_dl_event_buffer) ); /* Data is stored inside buffer, reset flag */
112 #undef THIS_EM_BUFFER_LEN
113 }
114
115 /*
116 +------------------------------------------------------------------------------
117 | Function : dl_em_write_buffer_5a
118 +------------------------------------------------------------------------------
119 | Description : Perform buffer check and store corresponding data in it.
120 |
121 | Parameters : Event number, data value1, data value2, data cs (USHORT)
122 |
123 | Return : TRUE/FALSE
124 |
125 +------------------------------------------------------------------------------
126 */
127
128 GLOBAL UBYTE em_write_buffer_5a (UBYTE event_no, UBYTE value1, UBYTE value2, USHORT cs)
129 {
130 #define THIS_EM_BUFFER_LEN 6
131 UBYTE em_dl_event_buffer[THIS_EM_BUFFER_LEN];
132
133 TRACE_EVENT_WIN ("em_write_buffer_5a");
134
135 /*
136 ACI is informed about the first event trace, used for later data processing.
137 */
138 dl_em_first_event_check();
139
140 em_dl_event_buffer[0] = event_no; /* Event number */
141 em_dl_event_buffer[1] = THIS_EM_BUFFER_LEN-2; /* Value length - 0 equals no data */
142 em_dl_event_buffer[2] = value1; /* first data info */
143 em_dl_event_buffer[3] = value2; /* second data info */
144 em_dl_event_buffer[4] = (UBYTE)(cs >> 8); /* Data to be stored - MSB first */
145 em_dl_event_buffer[5] = (UBYTE)(cs); /* LSB second */
146
147 return ( em_dl_write (THIS_EM_BUFFER_LEN, em_dl_event_buffer) );/* Data is stored inside buffer, reset flag */
148 #undef THIS_EM_BUFFER_LEN
149 }
150
151 /*
152 +------------------------------------------------------------------------------
153 | Function : em_init_dl_event_trace
154 +------------------------------------------------------------------------------
155 | Description : Initialize the event tracing flags
156 |
157 | Parameters :
158 |
159 | Return :
160 |
161 +------------------------------------------------------------------------------
162 */
163 GLOBAL void em_init_dl_event_trace(void)
164 {
165 UBYTE i;
166
167 TRACE_EVENT_WIN ("em_init_dl_event_trace");
168
169 for(i=1; i<EM_MAX_DL_EVENTS; i++)
170 {
171 dl_v[i] = 0;
172 }
173 }
174
175 /*
176 +------------------------------------------------------------------------------
177 | Function : dl_em_dl_event_req
178 +------------------------------------------------------------------------------
179 | Description : Set the event tracing flags according the bitmask
180 |
181 | Parameters : Primitive - Bitmask
182 |
183 | Return :
184 |
185 +------------------------------------------------------------------------------
186 */
187
188 GLOBAL void dl_em_dl_event_req (T_EM_DL_EVENT_REQ *em_dl_event_req)
189 {
190 UBYTE i;
191
192 TRACE_EVENT_WIN_P1 ("dl_em_dl_event_req: bitmask_dl=%x", em_dl_event_req->bitmask_dl);
193 /*
194 * The event tracing flags are set according the bitmask. dl_v[i] are
195 * the flags belonging to the event number described in 8443.601
196 */
197 for(i=1; i<EM_MAX_DL_EVENTS; i++)
198 {
199 dl_v[i] = ((em_dl_event_req->bitmask_dl & (0x01<<(i-1))) > 0) ? TRUE : FALSE;
200 }
201
202 /*
203 A new event trace is generated therefor the flag is set to 0.
204 */
205 em_dl_trace_occured = 0;
206
207 PFREE(em_dl_event_req);
208 }
209
210 LOCAL void em_dl_sem_clear (void)
211 {
212 ENTER_CRITICAL_SECTION (sem_EM_DL);
213 em_dl_sem_index = em_dl_sem_read_index = 0;
214 LEAVE_CRITICAL_SECTION (sem_EM_DL);
215
216 SYST_TRACE ("DL:em_dl_sem_index cleared");
217 }
218
219 GLOBAL void em_dl_sem_init (void)
220 {
221 sem_EM_DL = vsi_s_open (VSI_CALLER "EM_DL_SEM",1);
222
223 if (sem_EM_DL NEQ VSI_ERROR)
224 {
225 em_dl_sem_clear ();
226 }
227 else
228 {
229 SYST_TRACE ("DL:can't open semaphore \"EM_DL_SEM\"");
230 }
231
232 em_dl_trace_occured = 0;
233 }
234
235 GLOBAL void em_dl_sem_exit (void)
236 {
237 if (sem_EM_DL NEQ VSI_ERROR)
238 vsi_s_close (VSI_CALLER sem_EM_DL);
239 }
240
241 /*
242 To be able to read the dl-buffer from aci, em_dl_sem_read occupies the semaphor with ENTER_CRITICAL_SECTION.
243 After read process toke place the function em_dl_sem_clear must be called to open the semaphor again and
244 reset the read index.
245 */
246 GLOBAL void em_dl_sem_reset (void)
247 {
248 /*
249 ENTER_CRITICAL_SECTION (sem_EM_DL);
250 */
251 em_dl_sem_index = em_dl_sem_read_index = 0;
252 LEAVE_CRITICAL_SECTION (sem_EM_DL);
253
254 SYST_TRACE ("DL:em_dl_sem_index reseted");
255 }
256
257 GLOBAL void em_dl_sem_read (void)
258 {
259 USHORT semCount;
260 TRACE_EVENT_WIN ( "em_dl_sem_read");
261
262 if (vsi_s_status (VSI_CALLER sem_EM_DL, &semCount) NEQ VSI_OK)
263 {
264 com_semaphore_err();
265 return ;
266 }
267 if (semCount EQ 0)
268 {
269 SYST_TRACE ("DL:semCount == 0");
270 return ;
271 }
272 ENTER_CRITICAL_SECTION (sem_EM_DL);
273 /*
274 The dl semaphor will be read by the engineering mode via aci, therefore the functions em_dl_sem_read
275 and em_dl_sem_reset are defined as global. To ensure that during reading only aci has access to
276 the semaphor the macro LEAVE_CRITICAL_SECTION is called after the read process toke place -
277 in the em_dl_sem_reset function.
278 */
279 }
280
281 /*
282 Return value TRUE/FALSE - TRUE keeps the event flag valid, FALSE indicates a successful flag handle
283 */
284 #if defined(INVOKE_SIGNAL)
285 GLOBAL UBYTE em_dl_write (UBYTE length, UBYTE *data)
286 #else /* INVOKE_SIGNAL */
287 LOCAL UBYTE em_dl_write (UBYTE length, UBYTE *data)
288 #endif /* INVOKE_SIGNAL */
289 {
290 USHORT semCount;
291 GET_INSTANCE_DATA;
292
293 TRACE_EVENT_WIN ("em_dl_write");
294
295 if (dl_data->interrupt_context)
296 {
297 sig_invoke_dl_em_write (length, data);
298 return FALSE;
299 }
300
301 if (vsi_s_status (VSI_CALLER sem_EM_DL, &semCount) NEQ VSI_OK)
302 {
303 com_semaphore_err();
304 return TRUE;
305 }
306
307 if (semCount EQ 0)
308 {
309 TRACE_EVENT_WIN ("semCount == 0");
310 return TRUE;
311 }
312
313 /*
314 * buffer overflow protection - EM_DL_SEM_SIZE = 30
315 */
316 if ( (em_dl_sem_index + length) > EM_DL_SEM_SIZE )
317 {
318 TRACE_EVENT_WIN ("dl em buffer full");
319 return FALSE;
320 }
321
322 if (com_enter_critical_section (sem_EM_DL))
323 return TRUE;
324
325 memcpy (&em_dl_sem_buffer[em_dl_sem_index], data, length);
326 em_dl_sem_index += length;
327
328 com_leave_critical_section (sem_EM_DL);
329 return FALSE; /* indicates that flag was handled */
330 } /* endfunc em_dl_write */
331
332 /*
333 +------------------------------------------------------------------------------
334 | Function : dl_em_first_event_check()
335 +------------------------------------------------------------------------------
336 | Description : Checks if first EM-Event ocured
337 |
338 | Parameters : None
339 |
340 | Return : None
341 |
342 +------------------------------------------------------------------------------
343 */
344
345 /*
346 ACI is informed about the first event trace, used for later data processing.
347 */
348 #if defined(INVOKE_SIGNAL)
349 GLOBAL void dl_em_first_event_check(void)
350 #else
351 LOCAL void dl_em_first_event_check(void)
352 #endif /* !INVOKE_SIGNAL */
353 {
354 if(!em_dl_trace_occured)
355 {
356
357 #if defined(INVOKE_SIGNAL)
358 GET_INSTANCE_DATA;
359 if (dl_data->interrupt_context)
360 {
361 sig_invoke_dl_em_first_event_check ();
362 return;
363 }
364 #endif /* INVOKE_SIGNAL */
365
366 TRACE_FUNCTION("dl_em_first_event_check()");
367
368 {
369 PALLOC(em_notification, EM_DATA_IND);
370 em_notification->entity = EM_DL;
371 PSENDX(MMI, em_notification);
372 }
373
374 em_dl_trace_occured++;
375 }
376 }
377
378 #endif /* FF_EM_MODE */
379
380 #endif /* DL_EM_C */