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