FreeCalypso > hg > freecalypso-citrine
comparison gpf/tst_pei/tstdriver.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: tstdriver.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 a table of all the drivers that may be | |
17 | used for the test interface. | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef __TST_DRV_C__ | |
22 #define __TST_DRV_C__ | |
23 #endif | |
24 | |
25 /*==== INCLUDES ===================================================*/ | |
26 | |
27 #include <string.h> | |
28 | |
29 #include "gpfconf.h" | |
30 #include "typedefs.h" | |
31 #include "os.h" | |
32 #include "vsi.h" | |
33 #include "gdi.h" | |
34 #include "drvconf.h" | |
35 #include "tstdriver.h" | |
36 #include "tst_mux.h" | |
37 | |
38 /*==== TYPES ======================================================*/ | |
39 | |
40 | |
41 /*==== VARIABLES ==================================================*/ | |
42 | |
43 T_TST_MUX_CHANNEL tst_mux_chan_struct[ MAX_TST_CHANNEL ]; | |
44 T_HANDLE tst_mux_drv_handle; | |
45 | |
46 /* | |
47 * just a hack - clean up needed | |
48 */ | |
49 #define MAX_PROT_PRIM_SIZE 236 | |
50 ULONG DrvSndData[(MAX_PROT_PRIM_SIZE + sizeof(T_PRIM_HEADER) + 3) / 4]; | |
51 ULONG X_PrimData[(sizeof(T_PRIM_X) + sizeof(T_S_HEADER) + 3) / 4 ]; | |
52 | |
53 /*==== EXTERNALS ==================================================*/ | |
54 | |
55 extern T_HANDLE TST_Handle; | |
56 extern T_HANDLE TIF_Handle; | |
57 extern UBYTE TST_DrvState; | |
58 | |
59 #ifndef _TARGET_ | |
60 extern USHORT TIF_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, | |
61 T_DRV_EXPORT const **DrvInfo ); | |
62 extern USHORT TR_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, | |
63 T_DRV_EXPORT const **DrvInfo ); | |
64 extern USHORT NODRV_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, | |
65 T_DRV_EXPORT const **DrvInfo ); | |
66 extern USHORT socket_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, | |
67 T_DRV_EXPORT const **DrvInfo ); | |
68 extern USHORT SER_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, | |
69 T_DRV_EXPORT const **DrvInfo ); | |
70 #endif | |
71 | |
72 /*==== CONSTANTS ==================================================*/ | |
73 #ifdef _TARGET_ | |
74 #ifndef RUN_INT_RAM | |
75 const T_TST_DRV_ENTRY tst_drv_list[ MAX_AVAILABLE_DRV ] = | |
76 { | |
77 { { NULL, NULL, NULL, NULL }, 0 } | |
78 }; | |
79 #endif /* RUN_INT_RAM */ | |
80 #else /* _TARGET_ */ | |
81 | |
82 const T_TST_DRV_ENTRY tst_drv_list[ MAX_AVAILABLE_DRV ] = | |
83 { | |
84 { { TIF_NAME, TIF_Init, "TST", NULL }, 1 }, | |
85 { { TR_NAME, TR_Init, NULL, NULL }, 2 }, | |
86 { { SOCKET_NAME, socket_Init, NULL, NULL }, 3 }, | |
87 #if !defined (_LINUX_) && !defined (_SOLARIS_) | |
88 { { SER_NAME, SER_Init, NULL, "" }, 3 }, | |
89 #endif | |
90 { { NODRV_NAME, NODRV_Init, NULL, NULL }, 3 }, | |
91 { { NULL, NULL, NULL, NULL }, 0 } | |
92 }; | |
93 #endif /* _TARGET_ */ | |
94 | |
95 | |
96 /*==== VARIABLES ==================================================*/ | |
97 | |
98 | |
99 /*==== FUNCTIONS ==================================================*/ | |
100 | |
101 | |
102 #ifndef _TARGET_ | |
103 /* | |
104 +--------------------------------------------------------------------+ | |
105 | PROJECT : GPF MODULE : TSTDRIVER | | |
106 | STATE : code ROUTINE : NODRV_Init | | |
107 +--------------------------------------------------------------------+ | |
108 | |
109 PURPOSE : initialize empty driver | |
110 | |
111 */ | |
112 GLOBAL USHORT NODRV_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo ) | |
113 { | |
114 static const T_DRV_EXPORT NODRV_Info = | |
115 { | |
116 NODRV_NAME, | |
117 0, | |
118 { | |
119 #ifdef _TOOLS_ | |
120 NULL, | |
121 #endif | |
122 NULL, | |
123 NULL, | |
124 NULL, | |
125 NULL, | |
126 NULL, | |
127 NULL, | |
128 NULL, | |
129 NULL, | |
130 NULL, | |
131 NULL, | |
132 NULL, | |
133 } | |
134 }; | |
135 | |
136 *DrvInfo = &NODRV_Info; | |
137 return DRV_OK; | |
138 } | |
139 #endif /* ndef _TARGET_ */ | |
140 | |
141 | |
142 #ifndef RUN_INT_RAM | |
143 /* | |
144 +--------------------------------------------------------------------+ | |
145 | PROJECT : GPF MODULE : TSTDRIVER | | |
146 | STATE : code ROUTINE : tst_drv_open | | |
147 +--------------------------------------------------------------------+ | |
148 */ | |
149 | |
150 SHORT tst_drv_open (char *drv_name, T_TST_DRV_ENTRY **drv_info ) | |
151 { | |
152 USHORT i; | |
153 | |
154 for ( i = 0; i < MAX_AVAILABLE_DRV; i++ ) | |
155 { | |
156 if ( tst_drv_list[i].entry.Name && drv_name | |
157 && !strcmp ( drv_name, tst_drv_list[i].entry.Name ) ) | |
158 { | |
159 *drv_info = (T_TST_DRV_ENTRY*)&tst_drv_list[i]; | |
160 return VSI_OK; | |
161 } | |
162 } | |
163 return VSI_ERROR; | |
164 } | |
165 #endif | |
166 | |
167 #ifndef RUN_INT_RAM | |
168 /* | |
169 +--------------------------------------------------------------------+ | |
170 | PROJECT : GSM-GPF (8415) MODULE : TSTDRIVER | | |
171 | STATE : code ROUTINE : tst_drv_write | | |
172 +--------------------------------------------------------------------+ | |
173 | |
174 PURPOSE: Send a message via the test interface | |
175 | |
176 */ | |
177 GLOBAL SHORT tst_drv_write ( T_HANDLE caller, ULONG opc, char *dest, char *Buffer ) | |
178 { | |
179 T_PRIM_HEADER *prim; | |
180 T_S_HEADER *s_hdr; | |
181 T_VOID_STRUCT *ptr = (T_VOID_STRUCT*)Buffer; /* just to reduce number of alignment warnings */ | |
182 T_VOID_STRUCT *snd_ptr; | |
183 T_PRIM_X *x_prim = (T_PRIM_X*)X_PrimData; | |
184 | |
185 x_prim->prim_ptr = NULL; | |
186 prim = (T_PRIM_HEADER*)DrvSndData; | |
187 prim->opc = opc; | |
188 if ( opc == 0 || opc == SYS_MASK ) /* opc = 0 -> trace -> to PCO */ | |
189 { | |
190 prim->len = sizeof(T_PRIM_HEADER); | |
191 if ( Buffer != NULL ) | |
192 { | |
193 prim->len += strlen(Buffer); | |
194 strcpy ((char*)P2D(prim), Buffer ); | |
195 } | |
196 } | |
197 else | |
198 { | |
199 x_prim->prim_ptr = prim; | |
200 x_prim->p_hdr.opc = opc; | |
201 if ( D_LEN(ptr) <= MAX_PROT_PRIM_SIZE ) | |
202 { | |
203 prim->len = D_LEN(ptr); | |
204 memcpy ((char*)P2D(prim), Buffer, (D_LEN(ptr)-sizeof(T_PRIM_HEADER))); | |
205 } | |
206 else | |
207 { | |
208 /* | |
209 * modify type to trace and send warning | |
210 */ | |
211 prim->opc = 0; | |
212 strcpy ((char*)P2D(prim), "Error: DirectDrvWrite -> Primitive to large to be transmitted"); | |
213 prim->len = strlen((char*)P2D(prim)) + sizeof(T_PRIM_HEADER); | |
214 } | |
215 } | |
216 prim->sh_offset = S_HDR_OFFSET(prim->len); | |
217 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset); | |
218 os_GetTime(TST_Handle,&s_hdr->time); | |
219 s_hdr->snd[0] = (char)caller; | |
220 if ( caller ) | |
221 s_hdr->snd[0] |= (char)HANDLE_BIT; | |
222 if ( dest ) | |
223 strcpy (s_hdr->rcv, dest); | |
224 | |
225 if ( TST_DrvState == TST_DRV_CONNECTED ) | |
226 { | |
227 if ( x_prim->prim_ptr != NULL ) | |
228 { | |
229 /*lint -e419 suppress - Warning -- Apparent data overrun for function 'memcpy... */ | |
230 memcpy ( ((char*)x_prim) + sizeof(T_PRIM_X), s_hdr, sizeof(T_S_HEADER) ); | |
231 /*lint +e419 */ | |
232 x_prim->p_hdr.sh_offset = sizeof(T_PRIM_X)>>2; | |
233 snd_ptr = (T_VOID_STRUCT*)x_prim; | |
234 } | |
235 else | |
236 snd_ptr = (T_VOID_STRUCT*)prim; | |
237 if ( vsi_d_write ( TST_Handle, TIF_Handle, (void*)snd_ptr, prim->len ) != VSI_OK ) | |
238 return DRV_BUFFER_FULL; | |
239 else | |
240 return DRV_OK; | |
241 } | |
242 return DRV_OK; | |
243 } | |
244 #endif | |
245 | |
246 #ifndef RUN_INT_RAM | |
247 /* | |
248 +------------------------------------------------------------------------------ | |
249 | Function : tst_mux_send | |
250 +------------------------------------------------------------------------------ | |
251 | Description : send message via specified test interface channnel | |
252 | | |
253 | Parameters : id - channel ID | |
254 | buffer - pointer to message | |
255 | size - message length | |
256 | | |
257 | Return : DRV_OK | |
258 | DRV_BUFFER_FULL | |
259 | DRV_BUFFER_FULL | |
260 +------------------------------------------------------------------------------ | |
261 */ | |
262 int tst_mux_send ( U8 id, void * buffer, int size ) | |
263 { | |
264 int chan_id; | |
265 int i; | |
266 int snd_size; | |
267 char *p_dst; | |
268 char *p_src; | |
269 | |
270 snd_size = size + 3; /* 3 additional bytes for framing and chan id */ | |
271 if ( size > MAX_TST_MUX_CMD_LEN-3) | |
272 { | |
273 return DRV_INVALID_PARAMS; | |
274 } | |
275 | |
276 for ( chan_id = 0; chan_id < MAX_TST_CHANNEL; chan_id++ ) | |
277 { | |
278 if ( tst_mux_chan_struct[chan_id].channel_id == id ) | |
279 { | |
280 p_dst = (char*)tst_mux_chan_struct[chan_id].send_data; | |
281 p_src = (char*)buffer; | |
282 *p_dst++ = 0x02; | |
283 *p_dst++ = id; | |
284 for ( i = 0; i < size; i++ ) | |
285 { | |
286 if ( *p_src == 0x10 || *p_src == 0x02 ) | |
287 { | |
288 if ( snd_size < MAX_TST_MUX_CMD_LEN-1 ) | |
289 { | |
290 *p_dst++ = 0x10; | |
291 snd_size++; | |
292 } | |
293 } | |
294 *p_dst++ = *p_src++; | |
295 } | |
296 *p_dst = 0x02; | |
297 | |
298 if ( vsi_d_write ( 0, tst_mux_drv_handle, tst_mux_chan_struct[chan_id].send_data, snd_size) != VSI_OK ) | |
299 { | |
300 return DRV_BUFFER_FULL; | |
301 } | |
302 return DRV_OK; | |
303 } | |
304 } | |
305 return DRV_INVALID_PARAMS; | |
306 } | |
307 #endif | |
308 | |
309 #ifndef RUN_INT_RAM | |
310 /* | |
311 +------------------------------------------------------------------------------ | |
312 | Function : tst_mux_register | |
313 +------------------------------------------------------------------------------ | |
314 | Description : register callback that is called if data is received on | |
315 | specified test interface channnel | |
316 | | |
317 | Parameters : id - channel ID | |
318 | callback - callback function | |
319 | | |
320 | Return : DRV_OK | |
321 | DRV_INITFAILURE | |
322 +------------------------------------------------------------------------------ | |
323 */ | |
324 int tst_mux_register ( U8 id, void (*callback)(void * buffer, int size)) | |
325 { | |
326 int i; | |
327 | |
328 for ( i = 0; i < MAX_TST_CHANNEL; i++ ) | |
329 { | |
330 if ( tst_mux_chan_struct[i].channel_id == 0 ) | |
331 { | |
332 tst_mux_chan_struct[i].channel_id = id; | |
333 tst_mux_chan_struct[i].rcv_callback = callback; | |
334 MALLOC(tst_mux_chan_struct[i].send_data,MAX_TST_MUX_CMD_LEN); | |
335 return DRV_OK; | |
336 } | |
337 } | |
338 return DRV_INITFAILURE; | |
339 } | |
340 #endif | |
341 | |
342 #ifndef RUN_INT_RAM | |
343 /* | |
344 +------------------------------------------------------------------------------ | |
345 | Function : tst_mux_callback | |
346 +------------------------------------------------------------------------------ | |
347 | Description : callback that is called if data is received on | |
348 | specified test interface channnel | |
349 | | |
350 | Parameters : id - channel ID | |
351 | buffer - data | |
352 | size - number of received bytes | |
353 | | |
354 | Return : DRV_OK | |
355 | DRV_INITFAILURE | |
356 +------------------------------------------------------------------------------ | |
357 */ | |
358 void tst_mux_callback ( U8 id, void * buffer, int size ) | |
359 { | |
360 char * rcv_ptr; | |
361 char * dta_ptr; | |
362 char * p_rd; | |
363 char * p_wr; | |
364 int rd_bytes = size; | |
365 int bytes_to_read = size; | |
366 int total_wr_bytes = size; | |
367 int total_rd_bytes = 0; | |
368 int i; | |
369 int stuffed_byte = 0; | |
370 | |
371 | |
372 MALLOC(rcv_ptr, size); | |
373 p_rd = rcv_ptr; | |
374 do | |
375 { | |
376 vsi_d_read ( 0, tst_mux_drv_handle, (void*)rcv_ptr, (ULONG*)&rd_bytes ); | |
377 total_rd_bytes += rd_bytes; | |
378 if ( total_rd_bytes < bytes_to_read ) | |
379 { | |
380 rcv_ptr += rd_bytes; | |
381 rd_bytes = bytes_to_read - total_rd_bytes; | |
382 } | |
383 } while ( total_rd_bytes < bytes_to_read ); | |
384 | |
385 | |
386 MALLOC(dta_ptr, size); | |
387 p_wr = dta_ptr; | |
388 for ( i = 0; i < size; i++ ) | |
389 { | |
390 if ( stuffed_byte == 1 ) | |
391 { | |
392 stuffed_byte = 0; | |
393 *p_wr++ = *p_rd++; | |
394 } | |
395 if ( *p_rd == 0x10 ) | |
396 { | |
397 stuffed_byte = 1; | |
398 p_rd++; | |
399 total_wr_bytes--; | |
400 } | |
401 else | |
402 { | |
403 *p_wr++ = *p_rd++; | |
404 } | |
405 } | |
406 MFREE(rcv_ptr); | |
407 | |
408 if ( tst_mux_chan_struct[id].rcv_callback != NULL ) | |
409 { | |
410 (tst_mux_chan_struct[id].rcv_callback)(dta_ptr,total_wr_bytes); | |
411 } | |
412 MFREE(dta_ptr); | |
413 | |
414 } | |
415 #endif | |
416 | |
417 #ifndef RUN_INT_RAM | |
418 /* | |
419 +------------------------------------------------------------------------------ | |
420 | Function : tst_mux_init | |
421 +------------------------------------------------------------------------------ | |
422 | Description : register callback that is called if data is received on | |
423 | specified test interface channnel | |
424 | | |
425 | Parameters : id - channel ID | |
426 | callback - callback function | |
427 | | |
428 | Return : DRV_OK | |
429 | DRV_INITFAILURE | |
430 +------------------------------------------------------------------------------ | |
431 */ | |
432 int tst_mux_init ( void ) | |
433 { | |
434 int i; | |
435 | |
436 if ( (tst_mux_drv_handle = vsi_d_open ( TST_Handle, (char*)TR_NAME )) == VSI_ERROR ) | |
437 { | |
438 return DRV_INITFAILURE; | |
439 } | |
440 for ( i = 0; i < MAX_TST_CHANNEL; i++ ) | |
441 { | |
442 tst_mux_chan_struct[i].channel_id = 0; | |
443 tst_mux_chan_struct[i].rcv_callback = NULL; | |
444 tst_mux_chan_struct[i].rcv_data_ptr = NULL; | |
445 tst_mux_chan_struct[i].rcv_data_size = 0; | |
446 } | |
447 return DRV_OK; | |
448 } | |
449 #endif |