comparison g23m-gsm/alr/alr_trc.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 : GSM-PS
4 | Modul : ALR_TRC
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 Modul defines functions for the offline trace
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ALR_TRC_C
22 #define ALR_TRC_C
23
24 #include "config.h"
25 #include "fixedconf.h"
26 #include "condat-features.h"
27
28 #define ENTITY_PL
29
30 /*==== INCLUDES ===================================================*/
31 #include <string.h>
32 #include <stdlib.h>
33 #include <ctype.h>
34 #include "typedefs.h"
35 #include "pconst.cdg"
36 #include "mconst.cdg"
37 #include "message.h"
38 #include "ccdapi.h"
39 #include "vsi.h"
40 #include "custom.h"
41 #include "gsm.h"
42 #include "prim.h"
43 #include "cnf_alr.h"
44 #include "mon_alr.h"
45 #include "pei.h"
46 #include "tok.h"
47 #include "pcm.h"
48
49 #ifdef GPRS
50 #include "alr_gprs.h"
51 #endif
52
53 #include "alr.h"
54
55 #if defined (ALR_TRACE_ENABLED)
56 /*
57 * The ALR Trace is a cyclic buffer for
58 * debugging ALR problems.
59 *
60 * The buffer will be initialized at startup and will
61 * be filled by the function alr_trc_dl_trace() until it is full.
62 * The size of the buffer is ALR_TRC_SIZE.
63 *
64 * The content is
65 *
66 * actual_channel
67 * State
68 * sysclock
69 * L2 data
70 *
71 * During IDLE mode (triggered by RX_PERIODIC_IND in ALR/TIL_main.c)
72 * an output is written to the _PL.dbg (ALR_TRC_MAX_READED traces each trigger)
73 */
74
75 /* prototypes */
76 void alr_trc_clear (void);
77 #define ALR_TRC_SIZE 90
78 #define ALR_TRC_MAX_READED 8
79
80 #if (((ALR_TRC_SIZE-1) & (~ALR_TRC_SIZE)) == (ALR_TRC_SIZE-1))
81 #define POWER_OF_2
82 #pragma message("ALR_TRC_SIZE is power of 2")
83 #else
84 #pragma message("ALR_TRC_SIZE is NOT power of 2")
85 #endif
86
87 typedef struct
88 {
89 UCHAR event;
90 UCHAR state;
91 UCHAR actual_channel;
92 USHORT sysclock;
93 UCHAR data [ALR_TRC_DATA_SIZE];
94 } T_IDLE_TRACE_DATA;
95
96 T_IDLE_TRACE_DATA alr_csIDLE_Trace_buffer [ALR_TRC_SIZE];
97 USHORT alr_csIDLE_Trace_index = 0;
98 USHORT alr_csIDLE_Trace_read_index = 0;
99
100 static T_HANDLE sem_ALR_TRC;
101
102 #define ENTER_CRITICAL_SECTION(sem) if (alr_trc_enter_critical_section(sem))return;
103 #define LEAVE_CRITICAL_SECTION(sem) if (alr_trc_leave_critical_section(sem))return;
104
105
106 /*
107 +-----------------------------------------------------------------------------+
108 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
109 | STATE : code ROUTINE : alr_trc_semaphore_err |
110 +-----------------------------------------------------------------------------+
111
112 PURPOSE : Handles semaphore error situation
113
114 */
115
116 static void alr_trc_semaphore_err (void)
117 {
118 static UCHAR out = 0;
119 if (!out)
120 {
121 out = 1;
122 vsi_o_ttrace(VSI_CALLER TC_EVENT, "semaphore error");
123 }
124 }//endfunc alr_trc_dl_trace_cs_err
125
126
127 /*
128 +-----------------------------------------------------------------------------+
129 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
130 | STATE : code ROUTINE : alr_trc_enter_critical_section |
131 +-----------------------------------------------------------------------------+
132
133 PURPOSE : Enters critical section
134
135 */
136
137 static int alr_trc_enter_critical_section (T_HANDLE sem)
138 {
139 if (vsi_s_get (VSI_CALLER sem) NEQ VSI_OK)
140 {
141 alr_trc_semaphore_err();
142 return -1;
143 }
144 else
145 {
146 return 0;
147 }
148 }//endfunc alr_trc_enter_critical_section
149
150
151 /*
152 +-----------------------------------------------------------------------------+
153 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
154 | STATE : code ROUTINE : alr_trc_leave_critical_section |
155 +-----------------------------------------------------------------------------+
156
157 PURPOSE : Leaves critical section
158
159 */
160
161 static int alr_trc_leave_critical_section (T_HANDLE sem)
162 {
163 if (vsi_s_release (VSI_CALLER sem) NEQ VSI_OK)
164 {
165 alr_trc_semaphore_err();
166 return -1;
167 }
168 else
169 {
170 return 0;
171 }
172 }//endfunc alr_trc_leave_critical_section
173
174
175 /*
176 +--------------------------------------------------------------------+
177 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
178 | STATE : code ROUTINE : alr_trc_init |
179 +--------------------------------------------------------------------+
180
181 PURPOSE : Init tracing
182
183 */
184
185
186 void alr_trc_init (void)
187 {
188 sem_ALR_TRC = vsi_s_open (VSI_CALLER "ALR_IDLE_TRACE",1);
189 if (sem_ALR_TRC NEQ VSI_ERROR)
190 alr_trc_clear ();
191 else
192 vsi_o_ttrace(VSI_CALLER TC_EVENT, "can't open semaphore \"ALR_IDLE_TRACE\"");
193 }
194
195 /*
196 +--------------------------------------------------------------------+
197 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
198 | STATE : code ROUTINE : alr_trc_exit |
199 +--------------------------------------------------------------------+
200
201 PURPOSE : Close tracing
202
203 */
204
205 void alr_trc_exit (void)
206 {
207 if (sem_ALR_TRC NEQ VSI_ERROR)
208 vsi_s_close (VSI_CALLER sem_ALR_TRC);
209 }
210
211 /*
212 +--------------------------------------------------------------------+
213 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
214 | STATE : code ROUTINE : alr_trc_clear |
215 +--------------------------------------------------------------------+
216
217 PURPOSE : Clears trace index
218
219 */
220
221
222 void alr_trc_clear (void)
223 {
224 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
225 alr_csIDLE_Trace_index = alr_csIDLE_Trace_read_index = 0;
226 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
227
228 vsi_o_ttrace(VSI_CALLER TC_EVENT, "IDLE_Trace_index reseted");
229 }
230
231 #if 0
232 static void alr_trc_sleep_mode (void)
233 {
234 static UCHAR sleep_mode_disabled = FALSE;
235
236 if (!sleep_mode_disabled)
237 {
238 #define NO_SLEEP 0
239 #define ARMIO_CLK 0x0001
240 #define UWIRE_CLK 0x0020
241 #define SIM_CLK 0x0040
242 #define UART_CLK 0x0400
243
244 #if defined (_TARGET_)
245 #if !defined( GPRS )
246 power_down_config(NO_SLEEP, ARMIO_CLK | UWIRE_CLK | SIM_CLK | UART_CLK);
247 #endif
248 #endif /* _TARGET_ */
249 sleep_mode_disabled = TRUE;
250 }
251 }//endfunc alr_trc_sleep_mode
252 #endif /* 0|1 */
253 /*
254 +--------------------------------------------------------------------+
255 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
256 | STATE : code ROUTINE : alr_trc_store |
257 +--------------------------------------------------------------------+
258
259 PURPOSE : Fill in a trace.
260
261 */
262
263 void alr_trc_store (UCHAR event, UCHAR actual_channel, UCHAR state, void* data)
264 {
265 T_IDLE_TRACE_DATA* trace_data;
266 USHORT write_index;
267 USHORT length;
268 T_TIME sysClock;
269
270
271 #if 0
272 {
273 USHORT semCount;
274
275 if (vsi_s_status (VSI_CALLER sem_ALR_TRC, &semCount) NEQ VSI_OK)
276 {
277 alr_trc_semaphore_err();
278 return;
279 }
280 if (semCount EQ 0)
281 {
282 vsi_o_ttrace(VSI_CALLER TC_EVENT, "semCount == 0");
283 return;
284 }
285 }
286 #endif /* 0|1 */
287
288 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
289
290 #if defined(POWER_OF_2)
291 write_index = (alr_csIDLE_Trace_index + 1) & (ALR_TRC_SIZE - 1); /* if ALR_TRC_SIZE power of 2 */
292 #else
293 write_index = (alr_csIDLE_Trace_index + 1) % ALR_TRC_SIZE; /* if ALR_TRC_SIZE not power of 2 */
294 #endif /* POWER_OF_2 */
295 if (write_index NEQ alr_csIDLE_Trace_read_index)
296 {/* buffer is not full */
297 trace_data = &alr_csIDLE_Trace_buffer[alr_csIDLE_Trace_index];
298
299 trace_data->event = event;
300 if (actual_channel >= ALR_TRC_CH_UNKNOWN)
301 trace_data->actual_channel = ALR_TRC_CH_UNKNOWN;
302 else
303 trace_data->actual_channel = actual_channel;
304 trace_data->state = state;
305 vsi_t_time (VSI_CALLER &sysClock);
306 trace_data->sysclock = (USHORT)sysClock;
307
308 if (event EQ ALR_TRC_DOWNLINK OR event EQ ALR_TRC_UPLINK)
309 length = 23;
310 else
311 length = ALR_TRC_DATA_SIZE;
312
313 if (event EQ ALR_TRC_STRING)
314 strncpy ((char*)trace_data->data, (char*)data, length);
315 else
316 memcpy (trace_data->data, (UCHAR*)data, length);
317
318 alr_csIDLE_Trace_index = write_index;
319 }/* endif buffer is not full */
320
321 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
322 }/* endfunc alr_trc_store */
323
324 /*
325 +--------------------------------------------------------------------+
326 | PROJECT : GSM-PS (6147) MODULE : ALT_TRC |
327 | STATE : code ROUTINE : alr_trc_read |
328 +--------------------------------------------------------------------+
329
330 PURPOSE : Read and output stored trace.
331
332 */
333
334
335 void alr_trc_read_all (void)
336 {
337 USHORT write_index, read_index;
338
339 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
340 write_index = alr_csIDLE_Trace_index;
341 read_index = alr_csIDLE_Trace_read_index;
342 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
343
344 while (read_index NEQ write_index)
345 {
346 alr_trc_read (20);
347 vsi_t_sleep(VSI_CALLER 0);
348
349 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
350 write_index = alr_csIDLE_Trace_index;
351 read_index = alr_csIDLE_Trace_read_index;
352 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
353 }
354 }/* endfunc alr_trc_dl_trace_read_all */
355
356 static const char * ALR_TRC_CHANNEL[7] = { " ", "Ff", "Fh", "S4", "S8", "SA", "??" };
357 static const char * ALR_TRC_EVENTS[4] = { "UL", "DL", "Ev", "ev" };
358
359 void alr_trc_read (int count)
360 {
361 T_IDLE_TRACE_DATA trace_data;
362 USHORT write_index, read_index;
363 static char buffer[ALR_TRC_DATA_SIZE*2+50];
364 UCHAR j, o, readed = 0;
365
366 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
367 write_index = alr_csIDLE_Trace_index;
368 read_index = alr_csIDLE_Trace_read_index;
369 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
370
371 #if 0
372 if (read_index EQ write_index)
373 {
374 alr_trc_sleep_mode ();
375 return;
376 }
377 #endif /* 0|1 */
378
379 while (read_index NEQ write_index)
380 {
381 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
382 trace_data = alr_csIDLE_Trace_buffer[read_index];
383 alr_csIDLE_Trace_buffer[read_index].sysclock = 0xffff; /* readed */
384 alr_csIDLE_Trace_read_index++;
385 #if defined(POWER_OF_2)
386 alr_csIDLE_Trace_read_index&= (ALR_TRC_SIZE-1); /* if power of 2 */
387 #else
388 alr_csIDLE_Trace_read_index%= ALR_TRC_SIZE; /* if not power of 2 */
389 #endif /* POWER_OF_2 */
390 read_index = alr_csIDLE_Trace_read_index;
391 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
392
393 sprintf (buffer, "[%03d]:%05d %d %s %s ",
394 #if defined(POWER_OF_2)
395 (write_index - read_index) & (ALR_TRC_SIZE-1), /* if ALR_TRC_SIZE power of 2 */
396 #else
397 (ALR_TRC_SIZE + write_index - read_index) % ALR_TRC_SIZE, /* if ALR_TRC_SIZE not power of 2 */
398 #endif /* POWER_OF_2 */
399 trace_data.sysclock,
400 trace_data.state,
401 ALR_TRC_EVENTS[trace_data.event],
402 ALR_TRC_CHANNEL[trace_data.actual_channel]);
403 o = strlen (buffer);
404
405 switch (trace_data.event)
406 {
407 case ALR_TRC_STRING:
408 strncpy (buffer+o, (char*)&trace_data.data[0], ALR_TRC_DATA_SIZE);
409 buffer[o+ALR_TRC_DATA_SIZE] = 0;
410 break;
411 case ALR_TRC_DOWNLINK:
412 case ALR_TRC_UPLINK:
413 for (j=0;j<23;j++, o+=2)
414 {
415 sprintf (buffer+o, "%02x", trace_data.data[j]);
416 }
417 break;
418 default:
419 for (j=0;j<ALR_TRC_DATA_SIZE;j++, o+=2)
420 {
421 sprintf (buffer+o, "%02x", trace_data.data[j]);
422 }
423 break;
424 }
425
426 if (buffer[0])
427 {
428 vsi_o_ttrace(VSI_CALLER TC_EVENT, buffer);
429 }
430 else
431 {
432 vsi_o_ttrace(VSI_CALLER TC_EVENT, "alr_trc_read() failed");
433 }
434
435 ENTER_CRITICAL_SECTION (sem_ALR_TRC);
436 write_index = (UCHAR)alr_csIDLE_Trace_index;
437 LEAVE_CRITICAL_SECTION (sem_ALR_TRC);
438
439 if (++readed >= count)
440 break;
441 }/* endwhile */
442
443 }//endfunc alr_trc_read */
444
445 #else /* ALR_TRACE_ENABLED */
446 #endif /* ALR_TRACE_ENABLED */
447 #endif /* ALR_TRC_C */