comparison src/aci2/alr/alr_trc.c @ 3:93999a60b835

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