comparison gsm-fw/gpf/tst_pei/tstdriver.c @ 322:5d1e22505446

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