FreeCalypso > hg > tcs211-fcmodem
comparison gpf/tst/DRV/titrc.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: titrc.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 Module defines the functionality of the TITRC driver | |
17 | to communicate with the TI trace task. | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 | |
22 #ifndef __TITRC_C__ | |
23 #define __TITRC_C__ | |
24 #endif | |
25 | |
26 #include "typedefs.h" | |
27 #include "string.h" | |
28 #include "tstheader.h" | |
29 #include "rvt_gen.h" | |
30 #include "gdi.h" | |
31 #include "serialswitch.h" | |
32 | |
33 /*==== TYPES ======================================================*/ | |
34 | |
35 typedef struct | |
36 { | |
37 USHORT Handle; | |
38 USHORT EnabledSignalType; | |
39 T_DRV_CB_FUNC Callback; | |
40 T_RVT_USER_ID trc_id; | |
41 unsigned char connected; | |
42 T_RVT_BUFFER read_ptr; | |
43 unsigned int read_len; | |
44 } T_TITRC_DATA; | |
45 | |
46 /*==== CONSTANTS ==================================================*/ | |
47 | |
48 #define ALLOWED_TITRC_SIGNALS (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT) | |
49 | |
50 | |
51 /*==== EXTERNALS ==================================================*/ | |
52 | |
53 extern USHORT emergeny_trace; | |
54 | |
55 /*==== VARIABLES ==================================================*/ | |
56 | |
57 #ifndef RUN_INT_RAM | |
58 T_TITRC_DATA TITRC_Data; | |
59 T_DRV_SIGNAL Signal; | |
60 #else | |
61 extern T_TITRC_DATA TITRC_Data; | |
62 #endif | |
63 | |
64 #ifndef RUN_FLASH | |
65 char header_buffer[TST_BIG_HEADER_SIZE]; | |
66 #endif | |
67 | |
68 /*==== FUNCTIONS ==================================================*/ | |
69 | |
70 #ifndef RUN_INT_RAM | |
71 extern USHORT TITRC_Write ( void *Buffer, ULONG *BytesToWrite ) ; | |
72 #endif | |
73 | |
74 #ifndef RUN_INT_RAM | |
75 /* | |
76 +--------------------------------------------------------------------+ | |
77 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
78 | STATE : code ROUTINE : TITRC_Read | | |
79 +--------------------------------------------------------------------+ | |
80 | |
81 PURPOSE : read data from driver | |
82 | |
83 */ | |
84 USHORT TITRC_Read ( void *Buffer, ULONG *BytesToRead ) | |
85 { | |
86 | |
87 if ( TITRC_Data.read_ptr ) | |
88 { | |
89 if ( *BytesToRead != 0 ) | |
90 { | |
91 if ( *BytesToRead > TITRC_Data.read_len ) | |
92 *BytesToRead = TITRC_Data.read_len; | |
93 | |
94 memcpy ( Buffer, TITRC_Data.read_ptr, *BytesToRead ); | |
95 | |
96 if ( *BytesToRead < TITRC_Data.read_len ) | |
97 { | |
98 TITRC_Data.read_ptr += *BytesToRead; | |
99 TITRC_Data.read_len -= *BytesToRead; | |
100 } | |
101 else | |
102 TITRC_Data.read_ptr = NULL; | |
103 } | |
104 else | |
105 { | |
106 *BytesToRead = TITRC_Data.read_len; | |
107 } | |
108 } | |
109 else | |
110 { | |
111 *BytesToRead = 0; | |
112 } | |
113 | |
114 return DRV_OK; | |
115 } | |
116 #endif | |
117 | |
118 #ifndef RUN_FLASH | |
119 /* | |
120 +--------------------------------------------------------------------+ | |
121 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
122 | STATE : code ROUTINE : TITRC_Write | | |
123 +--------------------------------------------------------------------+ | |
124 | |
125 PURPOSE : write data to driver | |
126 | |
127 */ | |
128 USHORT TITRC_Write ( void *Buffer, ULONG *BytesToWrite ) | |
129 { | |
130 T_RVT_FORMAT msg_format; | |
131 char *ptr = (char*)Buffer; | |
132 ULONG BytesWritten; | |
133 ULONG ToWrite; | |
134 T_RVT_BUFFER rvt_buffer; | |
135 | |
136 msg_format = RVT_BINARY_FORMAT; | |
137 | |
138 if ( emergeny_trace ) | |
139 { | |
140 ptr--; | |
141 *ptr = 0x13; | |
142 ToWrite = (ULONG)*BytesToWrite; | |
143 ToWrite += 1; | |
144 BytesWritten = (ULONG)SER_tr_WriteNBytes (1, (SYS_UWORD8*)ptr, (SYS_UWORD32)ToWrite); | |
145 *BytesToWrite = BytesWritten; | |
146 } | |
147 else | |
148 { | |
149 if ( *BytesToWrite & PRIM_HEADER_FLAG ) | |
150 { | |
151 memcpy ( header_buffer, (char*)Buffer, TST_BIG_HEADER_SIZE ); | |
152 return DRV_OK; | |
153 } | |
154 if ( *BytesToWrite & PRIM_DATA_FLAG ) | |
155 { | |
156 ToWrite = *BytesToWrite & ~PRIM_DATA_FLAG; | |
157 if ( rvt_mem_alloc(TITRC_Data.trc_id, ToWrite+TST_BIG_HEADER_SIZE, &rvt_buffer) != RVT_OK ) | |
158 return DRV_BUFFER_FULL; | |
159 if ( rvt_buffer != NULL ) | |
160 { | |
161 memcpy ( (char*)rvt_buffer, header_buffer, TST_BIG_HEADER_SIZE ); | |
162 memcpy ( (char*)rvt_buffer+TST_BIG_HEADER_SIZE, (char*)Buffer, ToWrite ); | |
163 if ( rvt_send_trace_no_cpy ( rvt_buffer, TITRC_Data.trc_id, (T_RVT_MSG_LG)ToWrite+TST_BIG_HEADER_SIZE, msg_format ) != RVT_OK ) | |
164 return DRV_BUFFER_FULL; | |
165 else | |
166 return DRV_OK; | |
167 } | |
168 } | |
169 if ( rvt_send_trace_cpy ( (T_RVT_BUFFER)Buffer, TITRC_Data.trc_id, (T_RVT_MSG_LG)*BytesToWrite, msg_format ) != RVT_OK ) | |
170 return DRV_BUFFER_FULL; | |
171 } | |
172 return DRV_OK; | |
173 } | |
174 #endif | |
175 | |
176 #ifndef RUN_INT_RAM | |
177 /* | |
178 +--------------------------------------------------------------------+ | |
179 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
180 | STATE : code ROUTINE : TITRC_SetSignal | | |
181 +--------------------------------------------------------------------+ | |
182 | |
183 PURPOSE : enable signal for the driver | |
184 | |
185 */ | |
186 USHORT TITRC_SetSignal ( USHORT SignalType ) | |
187 { | |
188 if ( !(SignalType & ALLOWED_TITRC_SIGNALS) ) | |
189 return DRV_INVALID_PARAMS; | |
190 else | |
191 TITRC_Data.EnabledSignalType |= SignalType; | |
192 | |
193 return DRV_OK; | |
194 } | |
195 #endif | |
196 | |
197 #ifndef RUN_INT_RAM | |
198 /* | |
199 +--------------------------------------------------------------------+ | |
200 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
201 | STATE : code ROUTINE : TITRC_ResetSignal | | |
202 +--------------------------------------------------------------------+ | |
203 | |
204 PURPOSE : disable signal for the driver | |
205 | |
206 */ | |
207 USHORT TITRC_ResetSignal ( USHORT SignalType ) | |
208 { | |
209 if ( !(SignalType & ALLOWED_TITRC_SIGNALS) ) | |
210 return DRV_INVALID_PARAMS; | |
211 else | |
212 TITRC_Data.EnabledSignalType &= ~SignalType; | |
213 | |
214 return DRV_OK; | |
215 } | |
216 #endif | |
217 | |
218 #ifndef RUN_INT_RAM | |
219 /* | |
220 +--------------------------------------------------------------------+ | |
221 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
222 | STATE : code ROUTINE : TITRC_SetConfig | | |
223 +--------------------------------------------------------------------+ | |
224 | |
225 PURPOSE : set configuration for the driver | |
226 | |
227 */ | |
228 USHORT TITRC_SetConfig ( char *Buffer ) | |
229 { | |
230 | |
231 if ( TITRC_Data.connected == FALSE ) | |
232 { | |
233 Signal.SignalType = DRV_SIGTYPE_CONNECT; | |
234 Signal.DrvHandle = TITRC_Data.Handle; | |
235 (TITRC_Data.Callback)( &Signal ); | |
236 TITRC_Data.connected = TRUE; | |
237 } | |
238 return DRV_OK; | |
239 } | |
240 #endif | |
241 | |
242 #ifndef RUN_INT_RAM | |
243 /* | |
244 +--------------------------------------------------------------------+ | |
245 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
246 | STATE : code ROUTINE : TITRC_Callback | | |
247 +--------------------------------------------------------------------+ | |
248 | |
249 PURPOSE : callback function of the driver | |
250 | |
251 */ | |
252 int callback_busy = 0; | |
253 void TITRC_Callback ( T_RVT_BUFFER ptr, UINT16 len ) | |
254 { | |
255 if ( callback_busy == 1 ) | |
256 for (;;) | |
257 ; | |
258 | |
259 callback_busy = 1; | |
260 if ( TITRC_Data.EnabledSignalType & DRV_SIGTYPE_READ ) | |
261 { | |
262 TITRC_Data.read_ptr = ptr; | |
263 TITRC_Data.read_len = len; | |
264 Signal.SignalType = DRV_SIGTYPE_READ; | |
265 Signal.DrvHandle = TITRC_Data.Handle; | |
266 (TITRC_Data.Callback)( &Signal ); | |
267 } | |
268 callback_busy = 0; | |
269 } | |
270 #endif | |
271 | |
272 #ifndef RUN_INT_RAM | |
273 /* | |
274 +--------------------------------------------------------------------+ | |
275 | PROJECT : GSM-Frame (8415) MODULE : TITRC | | |
276 | STATE : code ROUTINE : TITRC_Init | | |
277 +--------------------------------------------------------------------+ | |
278 | |
279 PURPOSE : initialize driver | |
280 | |
281 */ | |
282 USHORT TITRC_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo ) | |
283 { | |
284 static const T_DRV_EXPORT TITRC_Info = | |
285 { | |
286 "TITRC", | |
287 0, | |
288 { | |
289 #ifdef _TOOLS_ | |
290 TITRC_Init, | |
291 #endif | |
292 NULL, | |
293 TITRC_Read, | |
294 TITRC_Write, | |
295 NULL, | |
296 NULL, | |
297 NULL, | |
298 TITRC_SetSignal, | |
299 TITRC_ResetSignal, | |
300 TITRC_SetConfig, | |
301 NULL, | |
302 NULL, | |
303 } | |
304 }; | |
305 | |
306 TITRC_Data.connected = FALSE; | |
307 | |
308 TITRC_Data.Handle = DrvHandle; | |
309 | |
310 TITRC_Data.EnabledSignalType = 0; | |
311 | |
312 TITRC_Data.Callback = CallbackFunc; | |
313 | |
314 if ( rvt_register_id ( (char*)"L23",&TITRC_Data.trc_id, TITRC_Callback ) == RVT_INVALID_PARAMETER ) | |
315 return DRV_INITFAILURE; | |
316 | |
317 *DrvInfo = &TITRC_Info; | |
318 | |
319 return DRV_OK; | |
320 } | |
321 #endif |