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