comparison g23m-gsm/alr/alr_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 ALR_EM_C
24 #define ALR_EM_C
25
26 #include "config.h"
27 #include "fixedconf.h"
28 #include "condat-features.h"
29
30 #define ENTITY_PL
31
32 /*==== INCLUDES ===================================================*/
33 #include <string.h>
34 #include <stdlib.h>
35 #include <ctype.h>
36 #include "typedefs.h"
37 #include "pconst.cdg"
38 #include "mconst.cdg"
39 #include "message.h"
40 #include "ccdapi.h"
41 #include "vsi.h"
42 #include "custom.h"
43 #include "gsm.h"
44 #include "prim.h"
45 #include "cnf_alr.h"
46 #include "mon_alr.h"
47 #include "pei.h"
48 #include "tok.h"
49 #include "pcm.h"
50
51 #ifdef GPRS
52 #include "alr_gprs.h"
53 #endif
54
55 #if 0 //#ifdef GPRS
56 #ifdef _TARGET_
57 #include "inth/iq.h"
58 #endif
59 /*
60 * obsolete (msb / 2002-04-25)
61 #include "armio/armio.h"
62 */
63 #endif
64
65 #include "alr.h"
66 #include "alr_em.h"
67
68
69 /*==== IMPORT =====================================================*/
70
71 /*==== EXPORT =====================================================*/
72
73 /*==== PRIVAT =====================================================*/
74
75 /*==== VARIABLES ==================================================*/
76 #if defined (FF_EM_MODE) AND defined (ALR)
77
78 /* Event tracing flags for EM */
79 GLOBAL BOOL alr_v[EM_MAX_ALR_EVENTS];
80
81 LOCAL UBYTE em_alr_trace_occured = 0;
82
83
84 /*
85 These variables are used between entities. Even this is not a clean solution it is a straigth forward
86 way to reduce the overhead to a minimum. A clean solution would be based on an only usage of primitives
87 which would stress the os with no aditional advantage!!
88 */
89 GLOBAL volatile UBYTE em_l1_sem_buffer [EM_L1_SEM_SIZE]; /*lint -esym(765,em_l1_sem_buffer) | external could be made static | used externally */
90 GLOBAL volatile UBYTE em_l1_sem_index = 0; /*lint -esym(765,em_l1_sem_index) | external could be made static | used externally */
91
92 static T_HANDLE sem_EM_L1;
93
94 #define ENTER_CRITICAL_SECTION(sem) if (alr_em_enter_critical_section(sem))return FALSE;
95 #define LEAVE_CRITICAL_SECTION(sem) if (alr_em_leave_critical_section(sem))return FALSE;
96
97 #endif /* FF_EM_MODE */
98
99 /*==== FUNCTIONS ==================================================*/
100 #if defined (FF_EM_MODE) AND defined (ALR)
101
102 LOCAL UBYTE em_l1_sem (UBYTE length, UBYTE * data);
103 LOCAL int em_l1_sem_clear (void);
104 LOCAL void alr_em_first_event_check (void); /*Check for ACI - Notification*/
105
106 static void alr_em_semaphore_err (void);
107
108 #if !defined(SYST_TRACE)
109 #define SYST_TRACE(a) vsi_o_ttrace(0, TC_SYSTEM, a);
110 #endif /* !SYST_TRACE */
111
112 static int alr_em_enter_critical_section (T_HANDLE sem);
113 static int alr_em_leave_critical_section (T_HANDLE sem);
114
115
116 /*
117 +------------------------------------------------------------------------------
118 | Function : em_init_l1_event_trace
119 +------------------------------------------------------------------------------
120 | Description : Initialize the event tracing flags
121 |
122 | Parameters :
123 |
124 | Return :
125 |
126 +------------------------------------------------------------------------------
127 */
128 GLOBAL void em_init_l1_event_trace(void)
129 {
130 UBYTE i;
131
132 TRACE_FUNCTION("em_init_l1_event_trace ()");
133
134 for(i=0; i<EM_MAX_ALR_EVENTS; i++)
135 alr_v[i] = 0;
136 }
137
138 /*
139 +------------------------------------------------------------------------------
140 | Function : l1_em_l1_event_req
141 +------------------------------------------------------------------------------
142 | Description : Set the event tracing flags according the bitmask
143 |
144 | Parameters : Primitive - Bitmask
145 |
146 | Return :
147 |
148 +------------------------------------------------------------------------------
149 */
150
151 GLOBAL void l1_em_l1_event_req (T_EM_L1_EVENT_REQ *em_l1_event_req)
152 {
153 UBYTE i;
154
155 TRACE_FUNCTION("l1_em_l1_event_req ()");
156
157 /*
158 * The event tracing flags are set according the bitmask. alr_v[i] are
159 * the flags belonging to the event number described in 8443.601
160 */
161 for(i=1; i<33; i++) {
162 alr_v[i] = ((em_l1_event_req->bitmask_l1_l & (0x01<<(i-1))) > 0) ? TRUE : FALSE;
163 }
164
165 for(i=33; i<(EM_MAX_ALR_EVENTS); i++) {
166 alr_v[i] = ((em_l1_event_req->bitmask_l1_h & (0x01<<(i-1))) > 0) ? TRUE : FALSE;
167 }
168
169 /*
170 * A new event trace is generated therefor the flag is set to zero.
171 */
172 em_alr_trace_occured = 0;
173
174 PFREE(em_l1_event_req);
175 }
176
177 /*
178 +------------------------------------------------------------------------------
179 | Function : em_write_buffer_2
180 +------------------------------------------------------------------------------
181 | Description : Perform buffer check and store corresponding data in it.
182 |
183 | Parameters : Event number
184 |
185 | Return : TRUE/FALSE
186 |
187 +------------------------------------------------------------------------------
188 */
189 GLOBAL UBYTE em_write_buffer_2 (UBYTE event_no)
190 {
191 UBYTE em_l1_event_buffer[2];
192 UBYTE em_l1_buffer_write = 0;
193 UBYTE length = 2;
194
195 TRACE_FUNCTION("alr_em_write_buffer_2 ()");
196
197 /*
198 ACI is informed about the first event trace, used for later data processing.
199 */
200 alr_em_first_event_check();
201
202 memset(em_l1_event_buffer, 0, 2);
203
204 em_l1_event_buffer[em_l1_buffer_write++] = event_no; /* Event number */
205 em_l1_event_buffer[em_l1_buffer_write++] = length-2; /* Value length - 0 equals no data */
206
207 return (em_l1_sem (length, em_l1_event_buffer)); /* Data is stored inside buffer, reset flag */
208 }
209
210 /*
211 +------------------------------------------------------------------------------
212 | Function : em_write_buffer_3
213 +------------------------------------------------------------------------------
214 | Description : Perform buffer check and store corresponding data in it.
215 |
216 | Parameters : Event number, data value
217 |
218 | Return : TRUE/FALSE
219 |
220 +------------------------------------------------------------------------------
221 */
222 GLOBAL UBYTE em_write_buffer_3 (UBYTE event_no, UBYTE value)
223 {
224 UBYTE em_l1_event_buffer[3];
225 UBYTE em_l1_buffer_write = 0;
226 UBYTE length = 3;
227
228 TRACE_FUNCTION("alr_em_write_buffer_3 ()");
229
230 /*
231 ACI is informed about the first event trace, used for later data processing.
232 */
233 alr_em_first_event_check();
234
235 memset(em_l1_event_buffer, 0, 3);
236
237 em_l1_event_buffer[em_l1_buffer_write++] = event_no; /* Event number */
238 em_l1_event_buffer[em_l1_buffer_write++] = length-2; /* Value length - 0 equals no value */
239 em_l1_event_buffer[em_l1_buffer_write++] = value; /* Data to be stored */
240
241 return (em_l1_sem (length, em_l1_event_buffer)); /* Data is stored inside buffer, reset flag */
242 }
243
244 /*
245 +------------------------------------------------------------------------------
246 | Function : em_write_buffer_3a
247 +------------------------------------------------------------------------------
248 | Description : Perform buffer check and store corresponding data in it.
249 |
250 | Parameters : Event number, data value (USHORT)
251 |
252 | Return : TRUE/FALSE
253 |
254 +------------------------------------------------------------------------------
255 */
256 GLOBAL UBYTE em_write_buffer_3a (UBYTE event_no, USHORT value)
257 {
258 UBYTE em_l1_event_buffer[4];
259 UBYTE em_l1_buffer_write = 0;
260 UBYTE length = 4;
261
262 TRACE_FUNCTION("alr_em_write_buffer_4 ()");
263
264 /*
265 ACI is informed about the first event trace, used for later data processing.
266 */
267 alr_em_first_event_check();
268
269 memset(em_l1_event_buffer, 0, 4);
270
271 em_l1_event_buffer[em_l1_buffer_write++] = event_no; /* Event number */
272 em_l1_event_buffer[em_l1_buffer_write++] = length-2; /* Value length - 0 equals no value */
273 em_l1_event_buffer[em_l1_buffer_write++] = (UBYTE)(value >> 8); /* Data to be stored - MSB first */
274 em_l1_event_buffer[em_l1_buffer_write++] = (UBYTE)(value); /* LSB second */
275
276 return (em_l1_sem (length, em_l1_event_buffer)); /* Data is stored inside buffer, reset flag */
277 }
278
279 /*
280 +------------------------------------------------------------------------------
281 | Function : em_write_buffer_4
282 +------------------------------------------------------------------------------
283 | Description : Perform buffer check and store corresponding data in it.
284 |
285 | Parameters : Event number, data value1 & value2
286 |
287 | Return : TRUE/FALSE
288 |
289 +------------------------------------------------------------------------------
290 */
291 GLOBAL UBYTE em_write_buffer_4 (UBYTE event_no, UBYTE value1, UBYTE value2)
292 {
293 UBYTE em_l1_event_buffer[4];
294 UBYTE em_l1_buffer_write = 0;
295 UBYTE length = 4;
296
297 TRACE_FUNCTION("alr_em_write_buffer_4 ()");
298
299 /*
300 ACI is informed about the first event trace, used for later data processing.
301 */
302 alr_em_first_event_check();
303
304 memset(em_l1_event_buffer, 0, 4);
305
306 em_l1_event_buffer[em_l1_buffer_write++] = event_no; /* Event number */
307 em_l1_event_buffer[em_l1_buffer_write++] = length-2; /* Value length - 0 equals no value */
308 em_l1_event_buffer[em_l1_buffer_write++] = value1; /* Data to be stored */
309 em_l1_event_buffer[em_l1_buffer_write++] = value2; /* Data to be stored */
310
311 return (em_l1_sem (length, em_l1_event_buffer)); /* Data is stored inside buffer, reset flag */
312 }
313
314 /*
315 +------------------------------------------------------------------------------
316 | Function : em_l1_sem_init
317 +------------------------------------------------------------------------------
318 | Description : Initialize the semaphor for alr event traces.
319 |
320 | Parameters : void
321 |
322 | Return : void
323 |
324 +------------------------------------------------------------------------------
325 */
326 GLOBAL void em_l1_sem_init (void)
327 {
328 sem_EM_L1 = vsi_s_open (VSI_CALLER "EM_L1_SEM",1);
329
330 if (sem_EM_L1 NEQ VSI_ERROR)
331 em_l1_sem_clear ();
332 else
333 SYST_TRACE ("D1:can't open semaphore \"EM_D1_SEM\"");
334 }
335
336 /*
337 +------------------------------------------------------------------------------
338 | Function : em_l1_sem_exit
339 +------------------------------------------------------------------------------
340 | Description : Close the semaphor for alr event traces.
341 |
342 | Parameters : void
343 |
344 | Return : void
345 |
346 +------------------------------------------------------------------------------
347 */
348 GLOBAL void em_l1_sem_exit (void)
349 {
350 if (sem_EM_L1 NEQ VSI_ERROR)
351 vsi_s_close (VSI_CALLER sem_EM_L1);
352 }
353
354 /*
355 +------------------------------------------------------------------------------
356 | Function : em_l1_sem_clear
357 +------------------------------------------------------------------------------
358 | Description : Reset the index of the semaphor.
359 |
360 | Parameters : void
361 |
362 | Return : UBYTE
363 |
364 +------------------------------------------------------------------------------
365 */
366 LOCAL int em_l1_sem_clear (void)
367 {
368 ENTER_CRITICAL_SECTION (sem_EM_L1);
369 em_l1_sem_index = 0;
370 LEAVE_CRITICAL_SECTION (sem_EM_L1);
371
372 SYST_TRACE ("L1:em_l1_sem_index cleared");
373 return TRUE;
374 }
375
376 /*
377 +------------------------------------------------------------------------------
378 | Function : em_l1_sem_reset
379 +------------------------------------------------------------------------------
380 | Description : Clears the content of the semaphor, must called after em_l1_sem_read.
381 |
382 | Parameters : void
383 |
384 | Return : UBYTE
385 |
386 +------------------------------------------------------------------------------
387 */
388 GLOBAL int em_l1_sem_reset (void) /*lint -esym(765,em_l1_sem_reset) | external could be made static | used externally */
389 {
390 /* ENTER_CRITICAL_SECTION (sem_EM_L1); */
391 em_l1_sem_index = 0;
392 LEAVE_CRITICAL_SECTION (sem_EM_L1);
393
394 SYST_TRACE ("L1:em_l1_sem_index reseted");
395 return TRUE;
396 }
397
398 /*
399 +------------------------------------------------------------------------------
400 | Function : em_l1_sem_read
401 +------------------------------------------------------------------------------
402 | Description : Reads the content of the semaphor.
403 |
404 | Parameters : void
405 |
406 | Return : UBYTE
407 |
408 +------------------------------------------------------------------------------
409 */
410 GLOBAL int em_l1_sem_read (void) /*lint -esym(765,em_l1_sem_read) | external could be made static | used externally */
411 {
412 USHORT semCount;
413 TRACE_FUNCTION ("em_l1_sem_read()");
414
415 if (vsi_s_status (VSI_CALLER sem_EM_L1, &semCount) NEQ VSI_OK)
416 {
417 alr_em_semaphore_err();
418 return TRUE;
419 }
420 if (semCount EQ 0)
421 {
422 vsi_o_ttrace(VSI_CALLER TC_EVENT, "semCount = %d", semCount);
423 SYST_TRACE ("semCount EQ 0");
424 return TRUE;
425 }
426
427 ENTER_CRITICAL_SECTION (sem_EM_L1);
428 /*
429 * The l1/alr semaphor will be read by the engineering mode via aci,
430 * therefore the functions em_l1_sem_read and em_l1_sem_reset are defined
431 * as global. To ensure that during reading only aci has access to the
432 * semaphor the macro LEAVE_CRITICAL_SECTION is called after the read process
433 * toke place - in the em_l1_sem_resest function.
434 */
435 return TRUE;
436 }
437
438 /*
439 Return value TRUE/FALSE - TRUE keeps the event flag valid, FALSE indicates a successful flag handle
440 */
441 /*
442 +------------------------------------------------------------------------------
443 | Function : em_l1_sem
444 +------------------------------------------------------------------------------
445 | Description : Writes the data inside the semaphor.
446 |
447 | Parameters : void
448 |
449 | Return : UBYTE
450 |
451 +------------------------------------------------------------------------------
452 */
453 LOCAL UBYTE em_l1_sem (UBYTE length, UBYTE *data)
454 {
455 USHORT semCount;
456 UBYTE i;
457
458 TRACE_FUNCTION ("em_l1_sem()");
459
460
461 if (vsi_s_status (VSI_CALLER sem_EM_L1, &semCount) NEQ VSI_OK)
462 {
463 alr_em_semaphore_err();
464 return TRUE;
465 }
466 if (semCount EQ 0)
467 {
468 vsi_o_ttrace(VSI_CALLER TC_EVENT, "semCount = %d", semCount);
469 SYST_TRACE ("semCount EQ 0");
470 return TRUE;
471 }
472
473 /*
474 * buffer overflow protection
475 */
476 if ( (em_l1_sem_index + length) > EM_L1_SEM_SIZE )
477 {
478 TRACE_FUNCTION ("alr buffer full");
479 return FALSE;
480 }
481
482 ENTER_CRITICAL_SECTION(sem_EM_L1);
483
484 for (i=0; i<length; i++)
485 em_l1_sem_buffer[em_l1_sem_index++] = *(data++);
486
487
488 LEAVE_CRITICAL_SECTION (sem_EM_L1);
489 return FALSE; /* indicates that flag was handled */
490 } /* endfunc em_l1_sem */
491
492 /*
493 +------------------------------------------------------------------------------
494 | Function : alr_em_semaphore_err
495 +------------------------------------------------------------------------------
496 | Description : Semaphor error
497 |
498 |
499 | Parameters : void
500 |
501 | Return : void
502 |
503 +------------------------------------------------------------------------------
504 */
505 static void alr_em_semaphore_err (void)
506 {
507 static UCHAR out = 0;
508 if (!out)
509 {
510 out = 1;
511
512 /* Implements Measure#32: Row 56 */
513 TRACE_EVENT ("semaphore error");
514 }
515 }
516
517 /*
518 +------------------------------------------------------------------------------
519 | Function : alr_em_enter_critical_section
520 +------------------------------------------------------------------------------
521 | Description : Check on critical section entrance
522 |
523 |
524 | Parameters : Handle
525 |
526 | Return : -1 semaphore error
527 | 0 Ok.
528 |
529 +------------------------------------------------------------------------------
530 */
531
532 #if defined (NEW_FRAME)
533 static int alr_em_enter_critical_section (T_HANDLE sem)
534 #else
535 static int alr_em_enter_critical_section (T_VSI_SHANDLE sem)
536 #endif /* NEW_FRAME */
537 {
538 if (vsi_s_get (VSI_CALLER sem) NEQ VSI_OK)
539 {
540 alr_em_semaphore_err();
541 return -1;
542 }
543 else
544 {
545 return 0;
546 }
547 }/* endfunc rr_enter_critical_section */
548
549
550 /*
551 +------------------------------------------------------------------------------
552 | Function : alr_em_leave_critical_section
553 +------------------------------------------------------------------------------
554 | Description : Check on critical section exit
555 |
556 |
557 | Parameters : Handle
558 |
559 | Return : -1 semaphore error
560 | 0 Ok.
561 |
562 +------------------------------------------------------------------------------
563 */
564 #if defined (NEW_FRAME)
565 static int alr_em_leave_critical_section (T_HANDLE sem)
566 #else
567 static int alr_em_leave_critical_section (T_VSI_SHANDLE sem)
568 #endif /* NEW_FRAME */
569 {
570 if (vsi_s_release (VSI_CALLER sem) NEQ VSI_OK)
571 {
572 alr_em_semaphore_err();
573 return -1;
574 }
575 else
576 {
577 return 0;
578 }
579 }/* endfunc rr_leave_critical_section */
580
581 /*
582 +------------------------------------------------------------------------------
583 | Function : alr_em_error_cause
584 +------------------------------------------------------------------------------
585 | Description : Check the error cause and store it in the event buffer
586 |
587 | Parameters : Cause
588 |
589 | Return : None
590 |
591 +------------------------------------------------------------------------------
592 */
593
594 GLOBAL void alr_em_error_cause (UBYTE cause, USHORT arfcn)
595
596 {
597 switch(cause)
598 {
599 case CS_BCCH_READ_ERROR:
600 { /* Power measurement request */
601 ALR_EM_BCCH_READ_ERROR;
602 break;
603 }
604 case CS_DOWN_LINK_FAIL:
605 { /* Downlink signalling failure */
606 ALR_EM_DOWNLINK_FAILURE;
607 break;
608 }
609 case CS_NO_BCCH_AVAIL:
610 { /* neighbourcell BCCH not available */
611 ALR_EM_NEIGHBOURCELL_BCCH(EM_NOT_AVAIL);
612 break;
613 }
614 }/*switch*/
615 }/* alr_em_error_cause */
616
617
618 /*
619 +------------------------------------------------------------------------------
620 | Function : alr_em_first_event_check()
621 +------------------------------------------------------------------------------
622 | Description : Checks if first EM-Event ocured
623 |
624 | Parameters : None
625 |
626 | Return : None
627 |
628 +------------------------------------------------------------------------------
629 */
630
631 /*
632 ACI is informed about the first event trace, used for later data processing.
633 */
634 LOCAL void alr_em_first_event_check (void)
635
636 {
637 TRACE_FUNCTION("alr_em_first_event_check()");
638 if(em_alr_trace_occured EQ 0)
639 {
640 PALLOC(em_notification, EM_DATA_IND);
641 em_notification->entity = EM_L1;
642 PSENDX(MMI, em_notification);
643 em_alr_trace_occured++;
644 }
645 }/* alr_em_first_event_check */
646
647
648
649 #endif /* FF_EM_MODE */
650
651
652
653 #endif /* ALR_EM_C */