FreeCalypso > hg > freecalypso-citrine
comparison gpf/tst_drv/tr2.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 | File: tr.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2004 Texas Instruments Deutschland, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Deutschland, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : This Modul contains the TR driver | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 #ifndef __TR_C__ | |
21 #define __TR_C__ | |
22 #endif | |
23 | |
24 #include <string.h> | |
25 #include "gpfconf.h" | |
26 #include "typedefs.h" | |
27 #include "gdi.h" | |
28 #include "vsi.h" | |
29 #include "os.h" | |
30 #ifdef _TOOLS_ | |
31 #include <stdio.h> | |
32 #include "glob_defs.h" | |
33 #include "tstdriver.h" | |
34 #include "frame.h" | |
35 #include "frame_const.h" | |
36 #include "printtofile.h" | |
37 #endif /* _TOOLS_ */ | |
38 #include "tstheader.h" | |
39 #include "tst_mux.h" | |
40 | |
41 | |
42 /*==== TYPES ======================================================*/ | |
43 | |
44 typedef struct | |
45 { | |
46 T_VOID_STRUCT *RcvBuffer; | |
47 USHORT Handle; | |
48 USHORT EnabledSignalType; | |
49 T_DRV_CB_FUNC Callback; | |
50 USHORT config; | |
51 UBYTE rcv_state; | |
52 UBYTE idle_state; | |
53 } T_TR_DATA; | |
54 | |
55 | |
56 /*==== CONSTANTS ==================================================*/ | |
57 | |
58 #define ALLOWED_TR_SIGNALS (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT) | |
59 | |
60 #define STX 0x02 | |
61 #define TI_RIV_ID 0x11 | |
62 #define TI_L1_ID 0x12 | |
63 #define TI_L23_ID 0x13 | |
64 #define TI_STX 0x02 | |
65 #define TI_ESC 0x10 | |
66 #define CHAR_ABORT 'A' | |
67 | |
68 #define DATA_SEGMENT_SIZE 223 | |
69 | |
70 #define WAIT_FOR_STX 0 | |
71 #define WAIT_FOR_IDENT 1 | |
72 #define WAIT_FOR_TIMESTAMP 2 | |
73 #define WAIT_FOR_LENGTH 3 | |
74 #define WAIT_FOR_SND 4 | |
75 #define WAIT_FOR_RCV 5 | |
76 #define WAIT_FOR_DATA 6 | |
77 #define WAIT_FOR_CR 7 | |
78 #define WAIT_FOR_TI_ID 8 | |
79 #define WAIT_FOR_TI_LEN_0 9 | |
80 #define WAIT_FOR_TI_LEN_1 10 | |
81 #define WAIT_FOR_TI_LEN_2 11 | |
82 #define WAIT_FOR_LENGTH1 12 | |
83 #define WAIT_FOR_LENGTH2 13 | |
84 #define WAIT_FOR_RAW_TI_S 14 | |
85 #define WAIT_FOR_RAW_TI_ID 15 | |
86 #define WAIT_FOR_RAW_TI_E 16 | |
87 | |
88 #define WAIT_FOR_MUX_START_STX 1 | |
89 #define WAIT_FOR_MUX_CHAN_ID 2 | |
90 #define WAIT_FOR_MUX_END_STX 3 | |
91 | |
92 #define STX_LF_MODE 0x0001 | |
93 #define TI_TRC_MODE 0x0002 | |
94 #define TI_RAW_TRC_MODE 0x0004 | |
95 | |
96 /*==== EXTERNALS ==================================================*/ | |
97 | |
98 extern ULONG TR_RcvBufferSize; | |
99 extern ULONG TR_MaxInd; | |
100 extern USHORT ext_data_pool_handle; | |
101 extern T_TST_MUX_CHANNEL tst_mux_chan_struct[]; | |
102 | |
103 /*==== VARIABLES ==================================================*/ | |
104 | |
105 #ifndef RUN_INT_RAM | |
106 #ifndef _TARGET_ | |
107 long int accessNum = 0; | |
108 #endif | |
109 T_TR_DATA TR_Data; | |
110 static char *TR_RcvBuffer; | |
111 static ULONG TR_EndInd; | |
112 static ULONG TR_WrInd; | |
113 static ULONG TR_RdInd; | |
114 static ULONG MessageLength; | |
115 static union { | |
116 unsigned short int val; | |
117 char part[2]; | |
118 }tst_trailer_size; | |
119 #else | |
120 extern T_TR_DATA TR_Data; | |
121 #endif | |
122 | |
123 #ifdef _TOOLS_ | |
124 static int ti_id_not_found; | |
125 static int ti_esc_skipped; | |
126 extern int tst_message_received; | |
127 #else | |
128 extern ULONG MaxPrimPartSize; | |
129 #endif | |
130 | |
131 /*==== FUNCTIONS ==================================================*/ | |
132 | |
133 #ifndef RUN_INT_RAM | |
134 USHORT TR_Write ( void *Buffer, ULONG *BytesToWrite ); | |
135 #endif | |
136 | |
137 #ifndef RUN_INT_RAM | |
138 /* | |
139 +--------------------------------------------------------------------+ | |
140 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
141 | STATE : code ROUTINE : TR_Exit | | |
142 +--------------------------------------------------------------------+ | |
143 | |
144 PURPOSE : exit a driver | |
145 | |
146 */ | |
147 LOCAL void TR_Exit ( void ) | |
148 { | |
149 os_DeallocateMemory ( 0, TR_Data.RcvBuffer ); | |
150 } | |
151 #endif | |
152 | |
153 #ifndef RUN_INT_RAM | |
154 /* | |
155 +--------------------------------------------------------------------+ | |
156 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
157 | STATE : code ROUTINE : TR_Read | | |
158 +--------------------------------------------------------------------+ | |
159 | |
160 PURPOSE : read data from driver | |
161 | |
162 */ | |
163 LOCAL USHORT TR_Read ( void *Buffer, ULONG *BytesToRead ) | |
164 { | |
165 ULONG Space = TR_EndInd - (TR_RdInd & TR_MaxInd); | |
166 static ULONG bytes_read; | |
167 | |
168 if ( *BytesToRead == 0 ) | |
169 { | |
170 *BytesToRead = MessageLength; | |
171 bytes_read = 0; | |
172 } | |
173 else | |
174 { | |
175 if ( Space > *BytesToRead ) | |
176 { | |
177 memcpy ( Buffer, &TR_RcvBuffer[TR_RdInd&TR_MaxInd], *BytesToRead ); | |
178 bytes_read += *BytesToRead; | |
179 } | |
180 else | |
181 { | |
182 memcpy ( Buffer, &TR_RcvBuffer[TR_RdInd&TR_MaxInd], (unsigned int)Space ); | |
183 *BytesToRead = Space; | |
184 bytes_read += Space; | |
185 } | |
186 TR_RdInd += *BytesToRead; | |
187 if ( TR_Data.config & STX_LF_MODE ) | |
188 if ( bytes_read == MessageLength ) | |
189 TR_RdInd++; /* skip th LF, its not read by the TIF driver */ | |
190 } | |
191 return DRV_OK; | |
192 } | |
193 #endif | |
194 | |
195 #ifndef RUN_INT_RAM | |
196 /* | |
197 +--------------------------------------------------------------------+ | |
198 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
199 | STATE : code ROUTINE : TR_Write | | |
200 +--------------------------------------------------------------------+ | |
201 | |
202 PURPOSE : write data to driver | |
203 | |
204 */ | |
205 USHORT TR_Write ( void *Buffer, ULONG *BytesToWrite ) | |
206 { | |
207 char *snd_ptr = (char*)Buffer; | |
208 ULONG btw; | |
209 char ti_mode_header[2]; | |
210 | |
211 ti_mode_header[0] = TI_STX; | |
212 ti_mode_header[1] = TI_L23_ID; | |
213 | |
214 #ifdef _TOOLS_ | |
215 btw=(*BytesToWrite) & ~PRIM_FLAG_MASK; | |
216 #else | |
217 btw=(*BytesToWrite); | |
218 #endif | |
219 | |
220 #ifdef _TOOLS_ | |
221 if (TR_Data.config & TI_RAW_TRC_MODE) | |
222 { | |
223 ULONG full_btw, segment_size; | |
224 /*lint -e813, suppress Info 813: auto variable 'osver' has size '148' */ | |
225 char segment[DATA_SEGMENT_SIZE*2+3]; | |
226 /*lint +e813 */ | |
227 ULONG q; | |
228 | |
229 full_btw=btw; | |
230 while (full_btw) | |
231 { | |
232 btw= (full_btw>DATA_SEGMENT_SIZE) ? DATA_SEGMENT_SIZE : full_btw; | |
233 | |
234 /* fill in leading bytes */ | |
235 segment_size=0; | |
236 segment[segment_size++]=TI_STX; | |
237 segment[segment_size++]=TI_L23_ID; | |
238 | |
239 /* fill in payload bytes */ | |
240 for (q=0; q<btw; q++) | |
241 { | |
242 /* evtl insert TI_ESC characters */ | |
243 if (snd_ptr[q]==TI_STX || snd_ptr[q]==TI_ESC) | |
244 { | |
245 segment[segment_size++]=TI_ESC; | |
246 } | |
247 segment[segment_size++]=snd_ptr[q]; | |
248 } | |
249 | |
250 /* fill in trailing bytes */ | |
251 segment[segment_size++]=TI_STX; | |
252 | |
253 /* write segment */ | |
254 if ( vsi_d_write ( TR_Data.Handle, 0, (void*)segment, segment_size) != VSI_OK ) | |
255 { | |
256 return DRV_INTERNAL_ERROR; | |
257 } | |
258 | |
259 full_btw=full_btw-btw; | |
260 if (full_btw) | |
261 { | |
262 snd_ptr=snd_ptr+btw; | |
263 | |
264 /* let the ti driver on target handle the byte-block */ | |
265 vsi_t_sleep ( 0, 100 ); | |
266 } | |
267 } | |
268 | |
269 return DRV_OK; | |
270 } | |
271 #endif /* _TOOLS_ */ | |
272 | |
273 /* | |
274 * To avoid reallocation and memcpy() the STX is written in front of the passed | |
275 * data. This works as long as the sizeof(T_SYST_HEADER) is bigger than the header | |
276 * sent via the test interface. | |
277 */ | |
278 if ( TR_Data.config & STX_LF_MODE ) | |
279 { | |
280 btw=(*BytesToWrite) & ~PRIM_FLAG_MASK; /* not really generic, but we need to mask here */ | |
281 /* we assume that the TITRC driver is not below */ | |
282 if ( *BytesToWrite & PRIM_DATA_FLAG ) /* primitive data -> LF at the end */ | |
283 { | |
284 *(snd_ptr+btw) = '\n'; | |
285 btw = btw + 1; | |
286 } | |
287 else if ( *BytesToWrite & PRIM_HEADER_FLAG ) /* primitive header -> add STX in front */ | |
288 { | |
289 snd_ptr--; /* it is posible to add STX because the first */ | |
290 *snd_ptr = STX; /* byte of TST_SMALL_HEADER/TST_BIG_HEADER in unused */ | |
291 btw = btw + 1; | |
292 } | |
293 else /* trace -> STX in front, LF at the end */ | |
294 { | |
295 *(snd_ptr+btw) = '\n'; | |
296 snd_ptr--; | |
297 *snd_ptr = STX; | |
298 btw = btw + 2; | |
299 } | |
300 } | |
301 | |
302 /* Add mux STX and channel id if not already in */ | |
303 if (TR_Data.config & TI_RAW_TRC_MODE && *snd_ptr != TI_STX ) | |
304 { | |
305 if ( vsi_d_write ( TR_Data.Handle, 0, (void*)ti_mode_header, 2) != VSI_OK ) | |
306 { | |
307 return DRV_INTERNAL_ERROR; | |
308 } | |
309 } | |
310 | |
311 if ( vsi_d_write ( TR_Data.Handle, 0, (void*)snd_ptr, btw) != VSI_OK ) | |
312 { | |
313 return DRV_INTERNAL_ERROR; | |
314 } | |
315 | |
316 return DRV_OK; | |
317 } | |
318 #endif | |
319 | |
320 #ifndef RUN_INT_RAM | |
321 /* | |
322 +--------------------------------------------------------------------+ | |
323 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
324 | STATE : code ROUTINE : TR_SetSignal | | |
325 +--------------------------------------------------------------------+ | |
326 | |
327 PURPOSE : enable signal for the driver | |
328 | |
329 */ | |
330 LOCAL USHORT TR_SetSignal ( USHORT SignalType ) | |
331 { | |
332 if ( !(SignalType & ALLOWED_TR_SIGNALS) ) | |
333 return DRV_INVALID_PARAMS; | |
334 else | |
335 TR_Data.EnabledSignalType |= SignalType; | |
336 | |
337 return DRV_OK; | |
338 } | |
339 #endif | |
340 | |
341 #ifndef RUN_INT_RAM | |
342 /* | |
343 +--------------------------------------------------------------------+ | |
344 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
345 | STATE : code ROUTINE : TR_ResetSignal | | |
346 +--------------------------------------------------------------------+ | |
347 | |
348 PURPOSE : disable signal for the driver | |
349 | |
350 */ | |
351 LOCAL USHORT TR_ResetSignal ( USHORT SignalType ) | |
352 { | |
353 if ( !(SignalType & ALLOWED_TR_SIGNALS) ) | |
354 return DRV_INVALID_PARAMS; | |
355 else | |
356 TR_Data.EnabledSignalType &= ~SignalType; | |
357 | |
358 return DRV_OK; | |
359 } | |
360 #endif | |
361 | |
362 #ifndef RUN_INT_RAM | |
363 /* | |
364 +--------------------------------------------------------------------+ | |
365 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
366 | STATE : code ROUTINE : TR_SetConfig | | |
367 +--------------------------------------------------------------------+ | |
368 | |
369 PURPOSE : set configuration for the driver | |
370 | |
371 */ | |
372 LOCAL USHORT TR_SetConfig ( char *Buffer ) | |
373 { | |
374 if ( !strcmp ( TR_STX_LF, Buffer ) ) | |
375 { | |
376 TR_Data.config = STX_LF_MODE; | |
377 TR_Data.rcv_state = WAIT_FOR_STX; | |
378 TR_Data.idle_state = WAIT_FOR_STX; | |
379 #ifdef _TOOLS_ | |
380 printf ("TR: STX mode enabled\n"); | |
381 #endif /* _TOOLS_ */ | |
382 return DRV_OK; | |
383 } | |
384 #ifdef _TOOLS_ | |
385 else if ( !strcmp ( DRV_TI_MODE, Buffer ) ) | |
386 { | |
387 TR_Data.config = TI_TRC_MODE; | |
388 TR_Data.rcv_state = WAIT_FOR_TI_ID; | |
389 TR_Data.idle_state = WAIT_FOR_TI_ID; | |
390 printf ("TR: TI mode enabled\n"); | |
391 return DRV_OK; | |
392 } | |
393 #endif /* _TOOLS_ */ | |
394 else if ( !strcmp ( DRV_RAW_TI_MODE, Buffer ) ) | |
395 { | |
396 TR_Data.config = TI_RAW_TRC_MODE; | |
397 TR_Data.rcv_state = WAIT_FOR_RAW_TI_S; | |
398 TR_Data.idle_state = WAIT_FOR_RAW_TI_S; | |
399 #ifdef _TOOLS_ | |
400 printf ("TR: raw TI mode enabled\n"); | |
401 #endif | |
402 return DRV_OK; | |
403 } | |
404 else if ( !strcmp ( DRV_DEFAULT, Buffer ) ) | |
405 { | |
406 TR_Data.config = 0; | |
407 TR_Data.rcv_state = WAIT_FOR_IDENT; | |
408 TR_Data.idle_state = WAIT_FOR_IDENT; | |
409 #ifdef _TOOLS_ | |
410 accessNum++; | |
411 PrintToFile("TR: default mode selected __________________________ (%d)\n", accessNum); | |
412 #endif /* _TOOLS_ */ | |
413 return DRV_OK; | |
414 } | |
415 else | |
416 return DRV_INVALID_PARAMS; | |
417 } | |
418 #endif | |
419 | |
420 #ifndef RUN_INT_RAM | |
421 /* | |
422 +--------------------------------------------------------------------+ | |
423 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
424 | STATE : code ROUTINE : Callback | | |
425 +--------------------------------------------------------------------+ | |
426 | |
427 PURPOSE : callback function of the driver | |
428 | |
429 */ | |
430 /*lint -esym(644,infoByteAddr) suppress warning -- Symbol 'infoByteAddr' may not have been initialized */ | |
431 LOCAL void TR_Callback ( T_DRV_SIGNAL *Signal ) | |
432 { | |
433 static T_DRV_SIGNAL TR_Signal; | |
434 static USHORT counter = 0; | |
435 static char* infoByteAddr; | |
436 int tr_abort_discard; | |
437 int tr_abort; | |
438 unsigned char c; | |
439 ULONG i; | |
440 ULONG BytesToRead; | |
441 ULONG BytesRead = 0; | |
442 ULONG TR_WorkInd; | |
443 ULONG Bytes = 0; | |
444 USHORT continue_read; | |
445 //#ifdef _TOOLS_ | |
446 static unsigned int ti_len = 0; | |
447 static char ti_id = 0; | |
448 static int sigtype = 0; | |
449 static int lf_found; | |
450 static int crlf_found; | |
451 static U8 mux_chan_id; | |
452 static U8 mux_chan = 0; | |
453 static U8 mux_status = WAIT_FOR_MUX_CHAN_ID; | |
454 static int stuffed_byte; | |
455 //#endif | |
456 | |
457 tr_abort_discard = 0; | |
458 tr_abort = 0; | |
459 TR_Signal.SignalType = 0; | |
460 switch ( Signal->SignalType ) | |
461 { | |
462 case DRV_SIGTYPE_READ: | |
463 BytesToRead = TR_EndInd - TR_WrInd; | |
464 TR_WorkInd = TR_WrInd; | |
465 | |
466 do | |
467 { | |
468 Bytes = 0; | |
469 do | |
470 { | |
471 continue_read = 0; | |
472 /* | |
473 * write counter must not overtake the read counter. If more bytes to be read | |
474 * than space available, then process the bytes in the buffer first and then | |
475 * continue to store new data in the TR_RcvBuffer. | |
476 */ | |
477 if ( TR_WrInd >= (TR_RdInd&TR_MaxInd) ) | |
478 BytesToRead = TR_EndInd - TR_WrInd; | |
479 else | |
480 BytesToRead = (TR_RdInd&TR_MaxInd) - TR_WrInd; | |
481 BytesRead = BytesToRead; | |
482 vsi_d_read ( TR_Data.Handle, 0, (void*)&TR_RcvBuffer[TR_WrInd], &BytesRead ); | |
483 Bytes += BytesRead; | |
484 if ( BytesRead < BytesToRead ) | |
485 { | |
486 TR_WrInd += BytesRead; | |
487 } | |
488 else | |
489 { | |
490 if ( TR_WrInd >= (TR_RdInd&TR_MaxInd) ) | |
491 TR_WrInd = 0; | |
492 else | |
493 { | |
494 TR_WrInd += BytesRead; | |
495 continue_read = 1; | |
496 break; | |
497 } | |
498 } | |
499 } while ( BytesRead != TR_RcvBufferSize && BytesRead == BytesToRead ); | |
500 | |
501 if ( Bytes ) | |
502 { | |
503 UBYTE cMasked; | |
504 | |
505 i=0; | |
506 | |
507 while (i++ < Bytes) | |
508 { | |
509 c = TR_RcvBuffer[(TR_WorkInd++) & TR_MaxInd]; | |
510 | |
511 #ifdef _TOOLS_ | |
512 if (TR_Data.config & TI_RAW_TRC_MODE) /* we are receiving rawly in TI mode */ | |
513 { | |
514 if (!ti_esc_skipped && c==TI_ESC) | |
515 { | |
516 /* the TI driver has inserted an TI_ESC -> skip it */ | |
517 ULONG q; | |
518 for (q=TR_WorkInd-1; q>TR_RdInd; q--) | |
519 { | |
520 TR_RcvBuffer[q & TR_MaxInd]=TR_RcvBuffer[(q-1) & TR_MaxInd]; | |
521 } | |
522 TR_RdInd++; | |
523 ti_esc_skipped=1; | |
524 continue; | |
525 } | |
526 ti_esc_skipped=0; | |
527 } | |
528 #endif /* _TOOLS_ */ | |
529 | |
530 if ( tr_abort_discard == 1 ) | |
531 { | |
532 TR_RdInd++; | |
533 continue; | |
534 } | |
535 switch (TR_Data.rcv_state) | |
536 { | |
537 case WAIT_FOR_STX: | |
538 if (c == STX) | |
539 { | |
540 #ifdef _TOOLS_ | |
541 ti_len=0; | |
542 #endif | |
543 TR_Data.rcv_state = WAIT_FOR_IDENT; | |
544 TR_RdInd = TR_WorkInd; /* do not pass the STX to TIF */ | |
545 } | |
546 else | |
547 TR_RdInd++; | |
548 break; | |
549 //#ifdef _TOOLS_ | |
550 case WAIT_FOR_RAW_TI_S: | |
551 if (c==TI_STX) | |
552 { | |
553 TR_Data.rcv_state=WAIT_FOR_RAW_TI_ID; | |
554 TR_RdInd = TR_WorkInd; /* do not read TI_STX */ | |
555 } | |
556 break; | |
557 case WAIT_FOR_RAW_TI_ID: | |
558 if (c==TI_STX) | |
559 { | |
560 // last TI_STX was end ID -> ignore this start ID | |
561 } | |
562 else if (c==TI_L23_ID) | |
563 { | |
564 ti_len = 0; | |
565 ti_id = c; | |
566 TR_Data.rcv_state=WAIT_FOR_IDENT; | |
567 } | |
568 else if (c == TI_L1_ID || c == TI_RIV_ID) | |
569 { | |
570 ti_len = 0; | |
571 ti_id = c; | |
572 | |
573 if (ti_id == TI_L1_ID) | |
574 sigtype = DRV_SIGTYPE_READ_L1; | |
575 if (ti_id == TI_RIV_ID) | |
576 sigtype = DRV_SIGTYPE_READ_RIV; | |
577 | |
578 counter = 0; | |
579 TR_RdInd = TR_WorkInd; /* do not read ti_id */ | |
580 crlf_found = 0; | |
581 lf_found = 0; | |
582 TR_Data.rcv_state=WAIT_FOR_RAW_TI_E; | |
583 } | |
584 else | |
585 { | |
586 mux_chan_id = c; | |
587 if ( mux_status == WAIT_FOR_MUX_CHAN_ID ) | |
588 { | |
589 for ( mux_chan = 0; mux_chan < MAX_TST_CHANNEL; mux_chan++ ) | |
590 { | |
591 if ( tst_mux_chan_struct[mux_chan].channel_id == c ) | |
592 { | |
593 mux_status = WAIT_FOR_MUX_END_STX; | |
594 tst_mux_chan_struct[mux_chan].rcv_data_ptr = &TR_RcvBuffer[(TR_WorkInd) & TR_MaxInd]; | |
595 tst_mux_chan_struct[mux_chan].rcv_data_size = 0; | |
596 stuffed_byte = 0; | |
597 TR_RdInd = TR_WorkInd; /* do not read id */ | |
598 TR_Data.rcv_state=WAIT_FOR_RAW_TI_E; | |
599 break; | |
600 } | |
601 } | |
602 } | |
603 } | |
604 break; | |
605 #ifdef _TOOLS_ | |
606 case WAIT_FOR_TI_ID: | |
607 /* skip TI ID byte */ | |
608 if (c == TI_L23_ID || c == TI_L1_ID || c == TI_RIV_ID) | |
609 { | |
610 ti_len = 0; | |
611 ti_id = c; | |
612 TR_Data.rcv_state = WAIT_FOR_TI_LEN_0; | |
613 } | |
614 else | |
615 { | |
616 ti_id_not_found = 1; | |
617 } | |
618 break; | |
619 case WAIT_FOR_TI_LEN_0: | |
620 /* | |
621 * skip length | |
622 * if length byte == 0 then the next 2 bytes are the length | |
623 * (patch to handle messages longer than 255 bytes) | |
624 */ | |
625 if ( c != 0 ) | |
626 { | |
627 if (ti_id == TI_L23_ID) | |
628 TR_Data.rcv_state = WAIT_FOR_IDENT; | |
629 | |
630 if (ti_id == TI_L1_ID || ti_id == TI_RIV_ID) | |
631 { | |
632 if (ti_id == TI_L1_ID) | |
633 sigtype = DRV_SIGTYPE_READ_L1; | |
634 if (ti_id == TI_RIV_ID) | |
635 sigtype = DRV_SIGTYPE_READ_RIV; | |
636 | |
637 TR_Data.rcv_state = WAIT_FOR_DATA; | |
638 counter = 0; | |
639 TR_RdInd += 2; /* do not read ti_id and length */ | |
640 crlf_found = 0; | |
641 lf_found = 0; | |
642 } | |
643 ti_len = c & 0xff; | |
644 } | |
645 else | |
646 TR_Data.rcv_state = WAIT_FOR_TI_LEN_1; | |
647 | |
648 break; | |
649 case WAIT_FOR_TI_LEN_1: | |
650 ti_len = c ; | |
651 TR_Data.rcv_state = WAIT_FOR_TI_LEN_2; | |
652 break; | |
653 case WAIT_FOR_TI_LEN_2: | |
654 ti_len |= c << 8; | |
655 TR_Data.rcv_state = WAIT_FOR_IDENT; | |
656 break; | |
657 #endif /* ifdef _TOOLS_ */ | |
658 | |
659 case WAIT_FOR_IDENT: | |
660 infoByteAddr = &TR_RcvBuffer[(TR_WorkInd - 1) & TR_MaxInd]; | |
661 /* analyze INFO Byte */ | |
662 cMasked = (c & HDR_VERSION_MASK); | |
663 #ifdef _TOOLS_ | |
664 if (cMasked == HDR_VALID_VERSION_0) | |
665 { | |
666 i--; TR_WorkInd--; | |
667 printf ("TR: changed to OLD header format automatically\n"); | |
668 // tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_GET_STACK_TIME ); | |
669 break; | |
670 } | |
671 /* check for lost bytes on interface */ | |
672 if (TR_Data.config & TI_TRC_MODE || | |
673 TR_Data.config & TI_RAW_TRC_MODE) /* we are receiving from a arm 7 TARGET */ | |
674 { /* TR_WorkInd refs position of first size byte now */ | |
675 if (ti_id_not_found) | |
676 { | |
677 *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */ | |
678 } | |
679 } | |
680 #endif /* ifdef _TOOLS_ */ | |
681 cMasked = (c & HDR_IDENT_MASK); | |
682 if (((cMasked == IDENT_PS_PRIM) || (cMasked == IDENT_SYS_PRIM) || | |
683 (cMasked == IDENT_ABORT) || (cMasked == IDENT_TRACE)) | |
684 && | |
685 ((c != PROT_PRIM_ID) && (c != PROT_PRIM_ID_32BIT) && | |
686 (c != SYS_PRIM_ID) && (c != TRACE_ID)) | |
687 ) | |
688 { | |
689 /* Hey fine, everything went OK! */ | |
690 TR_Data.rcv_state = WAIT_FOR_LENGTH1; | |
691 } | |
692 else | |
693 { /* we have to fake a length for abort trace */ | |
694 tst_trailer_size.part[0] = TST_HEADER_LEADING_FIELDS; | |
695 tst_trailer_size.part[1] = 0; | |
696 MessageLength = tst_trailer_size.val + TST_HEADER_TRAILING_FIELDS; | |
697 | |
698 *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */ | |
699 counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */ | |
700 TR_Data.rcv_state = WAIT_FOR_DATA; | |
701 tr_abort = 1; | |
702 } | |
703 TR_RdInd = TR_WorkInd - 1; /* skip all preceeding interface sync bytes before triggering TIF */ | |
704 break; | |
705 case WAIT_FOR_LENGTH1: | |
706 /* the use of the union does rely on identical byte sex! */ | |
707 #ifdef _SOLARIS_ | |
708 /* temporary hack */ | |
709 tst_trailer_size.part[1] = c; | |
710 #else | |
711 tst_trailer_size.part[0] = c; | |
712 #endif | |
713 TR_Data.rcv_state = WAIT_FOR_LENGTH2; | |
714 break; | |
715 case WAIT_FOR_LENGTH2: | |
716 #ifdef _SOLARIS_ | |
717 /* temporary hack */ | |
718 tst_trailer_size.part[0] = c; | |
719 #else | |
720 tst_trailer_size.part[1] = c; | |
721 #endif | |
722 /* Bytes after size + bytes till size (inclusive) */ | |
723 MessageLength = tst_trailer_size.val + TST_HEADER_LEADING_FIELDS; | |
724 #ifdef _TOOLS_ | |
725 /* In case of a lost character the two length information elements mismatch. */ | |
726 if ( (ti_len != 0) && (tst_trailer_size.val != (ti_len - 3)) ) | |
727 { | |
728 tst_trailer_size.val = ti_len - 3; | |
729 } | |
730 ti_len = 0; | |
731 if ((tst_trailer_size.val - TST_HEADER_TRAILING_FIELDS) > (unsigned short int)(MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER))) | |
732 { | |
733 *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */ | |
734 tst_trailer_size.val = (MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) -TST_HEADER_TRAILING_FIELDS); | |
735 counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */ | |
736 tr_abort = 1; | |
737 } | |
738 #else | |
739 if ((tst_trailer_size.val - TST_HEADER_TRAILING_FIELDS) > (unsigned short int)(MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER))) | |
740 { | |
741 *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */ | |
742 tst_trailer_size.val = (USHORT)(MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) -TST_HEADER_TRAILING_FIELDS); | |
743 counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */ | |
744 tr_abort = 1; | |
745 } | |
746 #endif | |
747 TR_Data.rcv_state = WAIT_FOR_DATA; | |
748 counter = 0; | |
749 break; | |
750 case WAIT_FOR_RAW_TI_E: | |
751 if ( mux_status == WAIT_FOR_MUX_END_STX ) | |
752 { | |
753 if ( stuffed_byte ) | |
754 { | |
755 stuffed_byte = 0; | |
756 tst_mux_chan_struct[mux_chan].rcv_data_size++; | |
757 } | |
758 else | |
759 { | |
760 if ( c != TI_STX ) | |
761 { | |
762 if ( c == 0x10 ) | |
763 { | |
764 stuffed_byte = 1; | |
765 } | |
766 tst_mux_chan_struct[mux_chan].rcv_data_size++; | |
767 } | |
768 else | |
769 { | |
770 tst_mux_callback (mux_chan,tst_mux_chan_struct[mux_chan].rcv_data_ptr, tst_mux_chan_struct[mux_chan].rcv_data_size); | |
771 mux_status = WAIT_FOR_MUX_CHAN_ID; | |
772 MessageLength = tst_mux_chan_struct[mux_chan].rcv_data_size; | |
773 TR_Data.rcv_state = WAIT_FOR_RAW_TI_S; | |
774 } | |
775 } | |
776 } | |
777 #ifdef _TOOLS_ | |
778 if (c!=TI_STX) | |
779 { | |
780 if ( counter == 0 && c == 0x0a ) | |
781 { | |
782 lf_found = 1; | |
783 } | |
784 if ( lf_found && counter == 1 && c == 0x0d) | |
785 { | |
786 crlf_found = 1; | |
787 } | |
788 counter++; | |
789 } | |
790 else | |
791 { | |
792 if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ ) | |
793 { | |
794 ti_len=counter; | |
795 if ( crlf_found == 1 ) | |
796 { | |
797 ti_len -= 2; | |
798 TR_RdInd += 2; /* do not read CR and LF at the beginning */ | |
799 } | |
800 MessageLength = ti_len; | |
801 TR_Signal.SignalType = sigtype; | |
802 TR_Signal.DrvHandle = TR_Data.Handle; | |
803 (TR_Data.Callback)( &TR_Signal ); | |
804 } | |
805 TR_Data.rcv_state = TR_Data.idle_state; | |
806 } | |
807 #endif | |
808 break; | |
809 case WAIT_FOR_DATA: | |
810 #ifdef _TOOLS_ | |
811 if ( ti_len ) | |
812 { | |
813 if ( counter == 0 && c == 0x0a ) | |
814 { | |
815 lf_found = 1; | |
816 } | |
817 if ( lf_found && counter == 1 && c == 0x0d) | |
818 { | |
819 crlf_found = 1; | |
820 } | |
821 if ( ++counter >= ti_len ) | |
822 { | |
823 if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ ) | |
824 { | |
825 if ( crlf_found == 1 ) | |
826 { | |
827 ti_len -= 2; | |
828 TR_RdInd += 2; /* do not read CR and LF at the beginning */ | |
829 } | |
830 MessageLength = ti_len; | |
831 TR_Signal.SignalType = sigtype; | |
832 TR_Signal.DrvHandle = TR_Data.Handle; | |
833 (TR_Data.Callback)( &TR_Signal ); | |
834 } | |
835 TR_Data.rcv_state = TR_Data.idle_state; | |
836 } | |
837 break; | |
838 } | |
839 #endif | |
840 if (++counter >= tst_trailer_size.val) /* If all went OK up to now we have to read all remaining bytes from the buffer each for each */ | |
841 { | |
842 if (TR_Data.config & STX_LF_MODE ) | |
843 { | |
844 TR_Data.rcv_state = WAIT_FOR_CR; | |
845 break; | |
846 } | |
847 else | |
848 { | |
849 if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ ) | |
850 { | |
851 #ifdef _TOOLS_ | |
852 tst_message_received = 1; | |
853 #endif | |
854 TR_Signal.SignalType = DRV_SIGTYPE_READ; | |
855 TR_Signal.DrvHandle = TR_Data.Handle; | |
856 (TR_Data.Callback)( &TR_Signal ); | |
857 } | |
858 TR_Data.rcv_state = TR_Data.idle_state; | |
859 tst_trailer_size.val = 0; | |
860 if ( tr_abort == 1 ) /* marked as bad */ | |
861 tr_abort_discard = 1; | |
862 #ifdef _TOOLS_ | |
863 ti_id_not_found = 0; | |
864 #endif | |
865 } | |
866 } | |
867 break; | |
868 case WAIT_FOR_CR: | |
869 #ifdef _TOOLS_ /* check for lost bytes on interface */ | |
870 if (TR_Data.config & STX_LF_MODE ) /* we are receiving from a arm 9 TARGET or Windows stack configured stx */ | |
871 { | |
872 if (c != '\n') | |
873 { | |
874 *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */ | |
875 } | |
876 } | |
877 #endif /* _TOOLS_ check for lost bytes on interface */ | |
878 if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ ) | |
879 { | |
880 #ifdef _TOOLS_ | |
881 tst_message_received = 1; | |
882 #endif | |
883 TR_Signal.SignalType = DRV_SIGTYPE_READ; | |
884 TR_Signal.DrvHandle = TR_Data.Handle; | |
885 (TR_Data.Callback)( &TR_Signal ); | |
886 } | |
887 TR_Data.rcv_state = TR_Data.idle_state; | |
888 tst_trailer_size.val = 0; | |
889 if ( tr_abort == 1 ) /* marked as bad */ | |
890 tr_abort_discard = 1; | |
891 break; | |
892 default: | |
893 break; | |
894 } | |
895 } /* while (i++ < Bytes) */ | |
896 } /* if Bytes loop */ | |
897 } while ( continue_read == 1 ); | |
898 break; | |
899 case DRV_SIGTYPE_CONNECT: | |
900 case DRV_SIGTYPE_DISCONNECT: | |
901 if ( TR_Data.EnabledSignalType & Signal->SignalType ) | |
902 { | |
903 TR_Signal.SignalType = Signal->SignalType; | |
904 TR_Signal.DrvHandle = TR_Data.Handle; | |
905 (TR_Data.Callback)( &TR_Signal ); | |
906 } | |
907 break; | |
908 default: | |
909 break; | |
910 } | |
911 } | |
912 #endif | |
913 | |
914 #ifndef RUN_INT_RAM | |
915 /* | |
916 +--------------------------------------------------------------------+ | |
917 | PROJECT : GSM-Frame (8415) MODULE : TR | | |
918 | STATE : code ROUTINE : TR_Init | | |
919 +--------------------------------------------------------------------+ | |
920 | |
921 PURPOSE : initialize driver | |
922 | |
923 */ | |
924 USHORT TR_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo ) | |
925 { | |
926 USHORT j; | |
927 ULONG size = 0; | |
928 static const T_DRV_EXPORT TR_Info = | |
929 { | |
930 "TR", | |
931 0, | |
932 { | |
933 #ifdef _TOOLS_ | |
934 TR_Init, | |
935 #endif | |
936 TR_Exit, | |
937 TR_Read, | |
938 TR_Write, | |
939 NULL, | |
940 NULL, | |
941 NULL, | |
942 TR_SetSignal, | |
943 TR_ResetSignal, | |
944 TR_SetConfig, | |
945 NULL, | |
946 TR_Callback, | |
947 } | |
948 }; | |
949 | |
950 TR_Data.Handle = DrvHandle; | |
951 | |
952 TR_Data.EnabledSignalType = 0; | |
953 | |
954 TR_Data.config = 0; | |
955 | |
956 TR_Data.rcv_state = WAIT_FOR_IDENT; | |
957 | |
958 TR_Data.idle_state = WAIT_FOR_IDENT; | |
959 | |
960 TR_Data.Callback = CallbackFunc; | |
961 | |
962 *DrvInfo = &TR_Info; | |
963 | |
964 /* | |
965 * TR_RcvBufferSize must be a power of 2 for proper wrap-around | |
966 */ | |
967 #ifndef _TOOLS_ | |
968 TR_RcvBufferSize = MaxPrimPartSize; | |
969 #endif | |
970 j = 0; | |
971 do | |
972 { | |
973 if ( (ULONG)(1 << j) >= TR_RcvBufferSize ) /* Size must be a power of 2 */ | |
974 { | |
975 size = 1 << j; | |
976 break; | |
977 } | |
978 else | |
979 j++; | |
980 } while ( size < 0xffff ); | |
981 | |
982 TR_RcvBufferSize = size; | |
983 TR_MaxInd = TR_RcvBufferSize - 1; | |
984 | |
985 if ( os_AllocateMemory ( NO_TASK, &TR_Data.RcvBuffer, (ULONG)TR_RcvBufferSize, | |
986 OS_NO_SUSPEND, ext_data_pool_handle ) != OS_OK ) | |
987 { | |
988 vsi_o_assert ( NO_TASK, OS_SYST_ERR_NO_MEMORY, __FILE__, __LINE__, | |
989 "No memory available in TR driver, TR_RcvBufferSize = %d", | |
990 TR_RcvBufferSize ); | |
991 return DRV_INITFAILURE; | |
992 } | |
993 | |
994 TR_RcvBuffer = (char*)TR_Data.RcvBuffer; | |
995 TR_EndInd = TR_RcvBufferSize; | |
996 TR_WrInd = 0; | |
997 TR_RdInd = 0; | |
998 tst_trailer_size.val = 0; | |
999 #ifdef _TOOLS_ | |
1000 ti_id_not_found = 0; | |
1001 ti_esc_skipped = 0; | |
1002 #endif | |
1003 | |
1004 return DRV_OK; | |
1005 } | |
1006 #endif |