comparison gsm-fw/g23m-gsm/dl/dl_trc.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : DL_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 tracing (only simulation)
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef DL_TRC_C
22 #define DL_TRC_C
23
24 #define ENTITY_DL
25
26
27 /*==== INCLUDES ===================================================*/
28 #if defined (NEW_FRAME)
29
30 #include <stdio.h>
31 #include <stdarg.h>
32 #include <string.h>
33 #include "typedefs.h"
34 #include "pconst.cdg"
35 #include "vsi.h"
36 #include "custom.h"
37 #include "gsm.h"
38 #include "mon_dl.h"
39 #include "prim.h"
40 #include "pei.h"
41 #include "tok.h"
42 #include "ccdapi.h"
43 #include "dl.h"
44
45 #else
46
47 #include <stdio.h>
48 #include <stdarg.h>
49 #include <string.h>
50 #include "stddefs.h"
51 #include "pconst.cdg"
52 #include "custom.h"
53 #include "gsm.h"
54 #include "mon_dl.h"
55 #include "prim.h"
56 #include "vsi.h"
57 #include "pei.h"
58 #include "tok.h"
59 #include "ccdapi.h"
60 #include "dl.h"
61
62 #endif
63
64 #include "DL_trc.h"
65
66 #if defined(DL_TRACE_WIN32)
67
68 #define DL_TRC_DELAY() /* vsi_t_sleep (VSI_CALLER 1) */
69
70 #define MY_ENTER_CRITICAL_SECTION(s) dl_trc_enter_critical_section(s)
71 #define MY_LEAVE_CRITICAL_SECTION(s) dl_trc_leave_critical_section(s)
72
73 LOCAL char local_buffer[300];
74 LOCAL int idx;
75 #if defined (NEW_FRAME)
76 LOCAL T_HANDLE sem_buf_acces;
77 #else
78 LOCAL T_VSI_SHANDLE sem_buf_acces;
79 #endif
80
81 LOCAL const char * const FrameName[] =
82 {
83 "I", /* 0 I */
84 "RR", /* 1 S */
85 "RNR", /* 2 S */
86 "REJ", /* 3 S */
87 "SABM", /* 4 U */
88 "DM", /* 5 U */
89 "UI", /* 6 U */
90 "DISC", /* 7 U */
91 "UA", /* 8 U */
92 "unknown"
93 };
94 LOCAL const char * const ChannelType[] =
95 {
96 "?<", "SA", "SD", "FH", "FF", "?>"
97 };
98 enum frame_type_e
99 {
100 FT_I,
101 FT_RR,
102 FT_RNR,
103 FT_REJ,
104 FT_SABM,
105 FT_DM,
106 FT_UI,
107 FT_DISC,
108 FT_UA,
109 FT_UNKNOWN
110 };
111
112
113 #if defined (NEW_FRAME)
114 GLOBAL int dl_trc_enter_critical_section (T_HANDLE sem)
115 #else
116 GLOBAL int dl_trc_enter_critical_section (T_VSI_SHANDLE sem)
117 #endif /* NEW_FRAME */
118 {
119 idx++;
120 if (idx > 1)
121 {
122 sprintf (local_buffer, "idx=%d!", idx);
123 TRACE_EVENT (local_buffer);
124 vsi_t_sleep (VSI_CALLER 50);
125 }
126
127 if (vsi_s_get (VSI_CALLER sem) NEQ VSI_OK)
128 {
129 TRACE_EVENT ("dl_trc_enter_critical_section() semaphore error");
130 return -1;
131 }
132 else
133 {
134 /*
135 vsi_t_sleep (VSI_CALLER 1);
136 TRACE_EVENT ("dl_trc_enter_critical_section()");
137 */
138 return 0;
139 }
140 }/* endfunc dl_trc_enter_critical_section */
141
142 #if defined (NEW_FRAME)
143 GLOBAL int dl_trc_leave_critical_section (T_HANDLE sem)
144 #else
145 GLOBAL int dl_trc_leave_critical_section (T_VSI_SHANDLE sem)
146 #endif /* NEW_FRAME */
147 {
148 idx--;
149 if (vsi_s_release (VSI_CALLER sem) NEQ VSI_OK)
150 {
151 TRACE_EVENT ("dl_trc_leave_critical_section() semaphore error");
152 return -1;
153 }
154 else
155 {
156 /*
157 vsi_t_sleep (VSI_CALLER 1);
158 TRACE_EVENT ("dl_trc_leave_critical_section()");
159 */
160 return 0;
161 }
162 }/* endfunc dl_trc_leave_critical_section */
163
164 GLOBAL void dl_trc_init ()
165 {
166 TRACE_FUNCTION ("dl_trc_init()");
167 idx = 0;
168 #ifdef NEW_FRAME
169 sem_buf_acces = vsi_s_open (VSI_CALLER "DL_TRC",1);
170 #else
171 sem_buf_acces = vsi_s_open (VSI_CALLER "DL_TRC");
172 #endif /* NEW_FRAME */
173
174 if (sem_buf_acces EQ VSI_ERROR)
175 {
176 TRACE_FUNCTION ("open semaphore error \"sem_buf_acces\"");
177 }
178 #if 1
179 else if (!MY_ENTER_CRITICAL_SECTION (sem_buf_acces))
180 {
181 TRACE_FUNCTION ("open semaphore \"sem_buf_acces\"");
182 MY_LEAVE_CRITICAL_SECTION (sem_buf_acces);
183 }
184 #endif /* 0|1 */
185 }/* endfunc dl_trc_init */
186
187 GLOBAL void dl_trc_exit ()
188 {
189 TRACE_FUNCTION ("dl_trc_exit()");
190 vsi_s_close (VSI_CALLER sem_buf_acces);
191 }/* endfunc dl_trc_exit */
192
193
194 GLOBAL void dl_trc_printf (char *fmt, ...)
195 {
196 if (!MY_ENTER_CRITICAL_SECTION (sem_buf_acces))
197 {
198 va_list vl;
199 char *buf = local_buffer;
200 va_start( vl, fmt ); /* Initialize variable arguments. */
201 vsprintf (buf, fmt, vl);
202 va_end ( vl ); /* Reset variable arguments. */
203
204 DL_TRC_DELAY ();
205 TRACE_FUNCTION (buf);
206 DL_TRC_DELAY ();
207 MY_LEAVE_CRITICAL_SECTION (sem_buf_acces);
208 }
209 }
210
211 GLOBAL void dl_trc_print_array(unsigned char *pArray, int nLength)
212 {
213 if (!MY_ENTER_CRITICAL_SECTION (sem_buf_acces))
214 {
215 int n, o;
216 char *buf = local_buffer;
217
218 for (n = 0, o = 0; (n < nLength) AND (o < ((int)sizeof (local_buffer)) - 7); n++)
219 {
220 o += sprintf (buf + o, "%02X ", *(pArray + n));
221 }
222
223 if (n < nLength)
224 {
225 o += sprintf (buf + o, "...");
226 }
227
228 DL_TRC_DELAY ();
229 TRACE_FUNCTION (buf);
230 DL_TRC_DELAY ();
231 MY_LEAVE_CRITICAL_SECTION (sem_buf_acces);
232 }
233 }
234
235 GLOBAL void dl_trc_frame(unsigned char ch_type, unsigned char *pFrame, int direction)
236 {
237 /* direction 0: down, 1: up */
238
239 if (!MY_ENTER_CRITICAL_SECTION (sem_buf_acces))
240 {
241 int o = 0, n, l, m;
242 int frametype;
243 int cmd = 0;
244 int pf = ((*(pFrame + 1)) & 0x10) >> 4;
245 char *buf = local_buffer;
246
247 if (ch_type >= 5)
248 ch_type = 5;
249
250 if (((*pFrame) & (BTER_FORMAT_MASK)) EQ (SHORT_L2_HEADER_TYPE_1))
251 {
252 int len = ch_type EQ L2_CHANNEL_SACCH ? DL_N201_SACCH_Bter : DL_N201_DCCH_Bter;
253
254 /* format type Bter */
255 o += sprintf (buf+o, "--- %2s short PD: SAPI 0 ",
256 ChannelType[ch_type]);
257 o += sprintf (buf+o, "%2s %s %2s",
258 direction ? " " : "<-", FrameName[FT_UI], direction ? "->" : " ");
259 while (o < 60)
260 buf[o++] = 0x20;
261 o += sprintf (buf+o, " l=%-2u ", len);
262 for (n = 0; n < len; n++)
263 o += sprintf (buf+o, " %02X", *(pFrame + n));
264 }
265 else
266 {
267 /* address field */
268 cmd = ((*pFrame)&0x02) ? direction ? 0 : 1
269 : direction ? 1 : 0;
270 o += sprintf (buf+o, "--- %2s %02X %02X %02X: SAPI %u %s ",
271 ChannelType[ch_type],
272 *(pFrame + 0), *(pFrame + 1), *(pFrame + 2),
273 /*direction?"UL->":"<-DL",*/
274 ((*pFrame)&0x1f)>>2,
275 cmd ? "cmd" : "rsp");
276 /* control field */
277 if ((*(pFrame + 1)) & 0x01)
278 {
279 if (((*(pFrame + 1)) & 0x03) EQ 0x03)
280 {
281 switch ((*(pFrame + 1)) & 0xef) /* unnumbered */
282 {
283 case 0x2f: frametype = FT_SABM; break;
284 case 0x0f: frametype = FT_DM; break;
285 case 0x03: frametype = FT_UI; break;
286 case 0x43: frametype = FT_DISC; break;
287 case 0x63: frametype = FT_UA; break;
288 default: frametype = FT_UNKNOWN; break;
289 }
290 o += sprintf (buf+o, "%c %14s",
291 pf ? (cmd ? 'P' : 'F') : ' ', "");
292 }
293 else
294 {
295 switch ((*(pFrame + 1)) & 0x0f) /* supervisory */
296 {
297 case 0x01: frametype = FT_RR; break;
298 case 0x05: frametype = FT_RNR; break;
299 case 0x09: frametype = FT_REJ; break;
300 default: frametype = FT_UNKNOWN; break;
301 }
302 o += sprintf (buf+o, "%c %s=%u %7s",
303 pf ? (cmd ? 'P' : 'F') : ' ',
304 direction ? "N(R)" : "n(r)",
305 ((*(pFrame + 1)) & 0xe0) >> 5,
306 "");
307 }
308 }
309 else
310 {
311 frametype = FT_I;
312 o += sprintf (buf+o, "%c %s=%u %s=%u ",
313 pf ? (cmd ? 'P' : 'F') : ' ',
314 direction ? "N(R)" : "n(r)",
315 ((*(pFrame + 1)) & 0xe0) >> 5,
316 direction ? "N(S)" : "n(s)",
317 ((*(pFrame + 1)) & 0x0e) >> 1);
318 }
319
320 o += sprintf (buf+o, "%2s %s %2s",
321 direction ? " " : "<-", FrameName[frametype], direction ? "->" : " ");
322
323 /* length field */
324 l = (*(pFrame + 2)) >> 2;
325 m = (*(pFrame + 2)) & 0x02;
326 if (l OR m)
327 {
328 while (o < 60)
329 buf[o++] = 0x20;
330 o += sprintf (buf+o, "%c l=%-2u ", m ? 'M':' ', l);
331
332 for (n = 0; (n < l) AND (n < 20); n++)
333 o += sprintf (buf+o, " %02X", *(pFrame + 3 + n));
334 }
335 }
336
337 DL_TRC_DELAY ();
338 TRACE_FUNCTION (buf);
339 DL_TRC_DELAY ();
340 MY_LEAVE_CRITICAL_SECTION (sem_buf_acces);
341 }
342 }/* endfunc dl_trc_frame */
343 #endif /* DL_TRACE_WIN32 */
344
345 #endif /* DL_TRC_C */
346