comparison src/g23m-gsm/dl/dl_em.c @ 104:27a4235405c6

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