FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/gpf/tst_drv/mux.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 |
comparison
equal
deleted
inserted
replaced
321:439afc1139b2 | 322:5d1e22505446 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: mux.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2002 Texas Instruments Berlin, 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 Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : This Module defines the adaptation of the MUX_tr driver | |
17 | to the GDI. | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifdef __MUX_C__ | |
22 #define __MUX_C__ | |
23 #endif | |
24 | |
25 #include "stdlib.h" | |
26 #include <stdio.h> | |
27 #include "string.h" | |
28 #include "typedefs.h" | |
29 | |
30 #include "tools.h" | |
31 #include "os.h" | |
32 #include "gdi.h" | |
33 #include "vsi.h" | |
34 #include "glob_defs.h" | |
35 #undef VSI_CALLER | |
36 #include "frame.h" | |
37 #include "prim.h" /* to get the definitions of used SAP and directions */ | |
38 #include "gsm.h" | |
39 #include "pei.h" | |
40 #include "route.h" | |
41 #include "dti.h" /* functionality of the dti library */ | |
42 #include "mux.h" /* to get the global entity definitions */ | |
43 #include "frame.h" | |
44 | |
45 /*==== TYPES ======================================================*/ | |
46 | |
47 /*==== CONSTANTS ==================================================*/ | |
48 | |
49 #define VSI_CALLER m_tst_handle, | |
50 #define VSI_CALLER_SINGLE m_tst_handle | |
51 | |
52 #define ALLOWED_MUX_SIGNALS (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT) | |
53 | |
54 #define TST_NAME "TST" | |
55 /*==== EXTERNALS ==================================================*/ | |
56 | |
57 extern T_HANDLE ext_data_pool_handle; | |
58 extern T_QMSG QueueMsg; | |
59 | |
60 /*==== GLOBAL VARIABLES ==================================================*/ | |
61 | |
62 /*==== LOCAL VARIABLES ==================================================*/ | |
63 static T_DRV_SIGNAL Signal; | |
64 | |
65 T_HANDLE m_tst_handle; | |
66 | |
67 /*==== FUNCTIONS ==================================================*/ | |
68 | |
69 /* | |
70 +--------------------------------------------------------------------+ | |
71 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
72 | STATE : code ROUTINE : mux_Exit | | |
73 +--------------------------------------------------------------------+ | |
74 | |
75 PURPOSE : exit a driver | |
76 | |
77 */ | |
78 void mux_Exit ( void ) | |
79 { | |
80 //vsi_p_delete (0, vsi_p_handle (0,"MTST")); | |
81 mux_data.Connected = FALSE; | |
82 } | |
83 | |
84 /* | |
85 +--------------------------------------------------------------------+ | |
86 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
87 | STATE : code ROUTINE : mux_Read | | |
88 +--------------------------------------------------------------------+ | |
89 | |
90 PURPOSE : read data from driver | |
91 | |
92 */ | |
93 USHORT mux_Read ( void *Buffer, ULONG *BytesToRead ) | |
94 { | |
95 T_desc2 *d; | |
96 T_desc2 *d_new; | |
97 | |
98 /* copy data into buffer */ | |
99 *BytesToRead=0; | |
100 d=mux_data.recv_data; | |
101 while (d) | |
102 { | |
103 d_new=(T_desc2 *)d->next; | |
104 *BytesToRead += d->len; | |
105 memcpy(Buffer, d->buffer, d->len); | |
106 /* free memory */ | |
107 MFREE(d); | |
108 | |
109 d=d_new; | |
110 } | |
111 | |
112 if (mux_data.dti_state NEQ IDLE) /* not yet configured */ | |
113 { | |
114 return DRV_NOTCONFIGURED; | |
115 } | |
116 else | |
117 { | |
118 /* inform UART that we are ready to receive next data package */ | |
119 dti_start | |
120 ( | |
121 mtst_hDTI, | |
122 MTST_DTI_DN_INSTANCE, | |
123 MTST_DTI_DN_INTERFACE, | |
124 MTST_DTI_DN_CHANNEL | |
125 ); | |
126 } | |
127 | |
128 return DRV_OK; | |
129 } | |
130 | |
131 | |
132 /* | |
133 +--------------------------------------------------------------------+ | |
134 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
135 | STATE : code ROUTINE : mux_Write | | |
136 +--------------------------------------------------------------------+ | |
137 | |
138 PURPOSE : write data to driver | |
139 | |
140 */ | |
141 USHORT mux_Write ( void *Buffer, ULONG *BytesToWrite ) | |
142 { | |
143 USHORT ret = DRV_OK; | |
144 | |
145 if (mux_data.h_comm_mtst==VSI_ERROR) /* not yet configured */ | |
146 { | |
147 ret=DRV_NOTCONFIGURED; | |
148 } | |
149 else | |
150 { | |
151 T_desc2 *d; | |
152 T_QMSG *pMsg = &QueueMsg; | |
153 | |
154 PALLOC(localPrimPtr, DTI2_DATA_IND); | |
155 | |
156 /* fill in parameters */ | |
157 localPrimPtr->parameters.p_id=DTI_PID_UOS; /* protocol identifier */ | |
158 /* flow control state */ | |
159 localPrimPtr->parameters.st_lines.st_flow=DTI_FLOW_ON; | |
160 /* line state sa */ | |
161 localPrimPtr->parameters.st_lines.st_line_sa=DTI_SA_ON; | |
162 /* line state sb */ | |
163 localPrimPtr->parameters.st_lines.st_line_sb=DTI_SB_ON; | |
164 /* break length */ | |
165 localPrimPtr->parameters.st_lines.st_break_len=DTI_BREAK_OFF; | |
166 | |
167 /* list of generic data descriptors */ | |
168 MALLOC(d,(ULONG)(sizeof(T_desc2)+*BytesToWrite-1)); | |
169 localPrimPtr->desc_list2.first=(ULONG)d; | |
170 localPrimPtr->desc_list2.list_len= (USHORT)*BytesToWrite; | |
171 d->next = 0; | |
172 d->len = (USHORT)*BytesToWrite; | |
173 d->size = *BytesToWrite; | |
174 d->offset = 0; | |
175 memcpy(d->buffer,Buffer,*BytesToWrite); | |
176 | |
177 /* PSEND without tracing */ | |
178 pMsg->Msg.Primitive.Prim = (T_VOID_STRUCT*)(D2P(localPrimPtr)); | |
179 pMsg->Msg.Primitive.PrimLen = PSIZE(localPrimPtr); | |
180 pMsg->MsgType = MSG_PRIMITIVE; | |
181 #ifdef MEMORY_SUPERVISION | |
182 vsi_c_send (VSI_CALLER mux_data.h_comm_mtst,pMsg,__FILE__,__LINE__); | |
183 #else | |
184 vsi_c_send (VSI_CALLER mux_data.h_comm_mtst,pMsg); | |
185 #endif | |
186 } | |
187 | |
188 return ( ret ); | |
189 } | |
190 /* | |
191 +--------------------------------------------------------------------+ | |
192 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
193 | STATE : code ROUTINE : mux_SetSignal | | |
194 +--------------------------------------------------------------------+ | |
195 | |
196 PURPOSE : enable signal for the driver | |
197 | |
198 */ | |
199 USHORT mux_SetSignal ( USHORT SignalType ) | |
200 { | |
201 if ( !(SignalType & ALLOWED_MUX_SIGNALS) ) | |
202 return DRV_INVALID_PARAMS; | |
203 else | |
204 mux_data.EnabledSignalType |= SignalType; | |
205 | |
206 return DRV_OK; | |
207 } | |
208 | |
209 /* | |
210 +--------------------------------------------------------------------+ | |
211 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
212 | STATE : code ROUTINE : mux_ResetSignal | | |
213 +--------------------------------------------------------------------+ | |
214 | |
215 PURPOSE : disable signal for the driver | |
216 | |
217 */ | |
218 USHORT mux_ResetSignal ( USHORT SignalType ) | |
219 { | |
220 if ( !(SignalType & ALLOWED_MUX_SIGNALS) ) | |
221 return DRV_INVALID_PARAMS; | |
222 else | |
223 mux_data.EnabledSignalType &= ~SignalType; | |
224 | |
225 return DRV_OK; | |
226 } | |
227 | |
228 /* | |
229 +--------------------------------------------------------------------+ | |
230 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
231 | STATE : code ROUTINE : mux_SetConfig | | |
232 +--------------------------------------------------------------------+ | |
233 | |
234 PURPOSE : set configuration for the driver | |
235 | |
236 PARAMS: Buffer - configuration string ("<DTI-partner> <tui> <c_id>") | |
237 | |
238 | |
239 */ | |
240 USHORT mux_SetConfig ( char *Buffer ) | |
241 { | |
242 char token [10]; | |
243 char peer_name [10]; | |
244 USHORT len; | |
245 ULONG link_id; | |
246 | |
247 if ( !mux_data.Connected ) | |
248 { | |
249 Signal.SignalType = DRV_SIGTYPE_CONNECT; | |
250 Signal.DrvHandle = mux_data.Handle; | |
251 (mux_data.Callback)( &Signal ); | |
252 mux_data.Connected = TRUE; | |
253 | |
254 return DRV_OK; | |
255 } | |
256 | |
257 /* interprete configuration string */ | |
258 if (!(len = GetNextToken (Buffer, token, " #"))) | |
259 { | |
260 return DRV_INVALID_PARAMS; | |
261 } | |
262 else | |
263 { | |
264 Buffer += (len+1); | |
265 } | |
266 if (strcmp(token,"STOP")==0) | |
267 { | |
268 dti_close | |
269 ( | |
270 mtst_hDTI, | |
271 MTST_DTI_DN_INSTANCE, | |
272 MTST_DTI_DN_INTERFACE, | |
273 MTST_DTI_DN_CHANNEL, | |
274 FALSE | |
275 ); | |
276 | |
277 mux_data.dti_state=CLOSED; | |
278 mux_data.h_comm_mtst=VSI_ERROR; | |
279 /* xxxxx set m_uart_ready = 0 ?! */ | |
280 if (mux_data.send_data_buf_count>0) { | |
281 /* xxxxx clear send_buffer ?! */ | |
282 mux_data.send_data_buf_count=0; | |
283 } | |
284 | |
285 return DRV_OK; | |
286 } | |
287 strcpy(peer_name, token); | |
288 | |
289 if (!(len = GetNextToken (Buffer, token, " #"))) | |
290 { | |
291 return DRV_INVALID_PARAMS; | |
292 } | |
293 else | |
294 { | |
295 Buffer += (len+1); | |
296 } | |
297 link_id=atoi(token); | |
298 | |
299 if( | |
300 dti_open | |
301 ( | |
302 mtst_hDTI, | |
303 MTST_DTI_DN_INSTANCE, | |
304 MTST_DTI_DN_INTERFACE, | |
305 MTST_DTI_DN_CHANNEL, | |
306 DTI_QUEUE_DISABLED, /* DTI_QUEUE_UNLIMITED in order to queue data */ | |
307 DTI_CHANNEL_TO_LOWER_LAYER, | |
308 FLOW_CNTRL_ENABLED, | |
309 DTI_VERSION_10, | |
310 (U8*)peer_name, | |
311 link_id | |
312 ) EQ FALSE) | |
313 return DRV_INVALID_PARAMS; | |
314 | |
315 /* reset send_data_buf counter */ | |
316 mux_data.send_data_buf_count=0; | |
317 | |
318 /* set internal communication handle */ | |
319 while ( (mux_data.h_comm_mtst=vsi_c_open (0, "MTST")) == VSI_ERROR) | |
320 { | |
321 vsi_t_sleep(0,100); | |
322 }; | |
323 | |
324 /* inform UART that we are ready to receive next data package */ | |
325 { | |
326 dti_start | |
327 ( | |
328 mtst_hDTI, | |
329 MTST_DTI_DN_INSTANCE, | |
330 MTST_DTI_DN_INTERFACE, | |
331 MTST_DTI_DN_CHANNEL | |
332 ); | |
333 } | |
334 | |
335 return DRV_OK; | |
336 } | |
337 | |
338 /* | |
339 +--------------------------------------------------------------------+ | |
340 | PROJECT : GSM-Frame (8415) MODULE : MUX | | |
341 | STATE : code ROUTINE : mux_Init | | |
342 +--------------------------------------------------------------------+ | |
343 | |
344 PURPOSE : initialize driver | |
345 | |
346 */ | |
347 USHORT mux_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo ) | |
348 { | |
349 T_HANDLE mux_handle; | |
350 | |
351 static const T_DRV_EXPORT mux_Info = | |
352 { | |
353 "MUX", | |
354 CALLED_FROM_ISR, | |
355 { | |
356 /*mux_Init,*/ | |
357 mux_Exit, | |
358 mux_Read, | |
359 mux_Write, | |
360 NULL, | |
361 NULL, | |
362 NULL, | |
363 mux_SetSignal, | |
364 mux_ResetSignal, | |
365 mux_SetConfig, | |
366 NULL, | |
367 NULL, | |
368 } | |
369 }; | |
370 | |
371 mux_data.Handle = DrvHandle; | |
372 | |
373 mux_data.EnabledSignalType = 0; | |
374 | |
375 mux_data.Callback = CallbackFunc; | |
376 | |
377 mux_data.Connected = FALSE; | |
378 | |
379 mux_data.dti_state = CLOSED; | |
380 mux_data.h_comm_mtst = VSI_ERROR; | |
381 | |
382 mux_handle = vsi_p_create (0, mux_pei_create, NULL, ext_data_pool_handle); | |
383 if (vsi_p_start (0, mux_handle) != VSI_OK) | |
384 { | |
385 return DRV_INITFAILURE; | |
386 }; | |
387 | |
388 *DrvInfo = &mux_Info; | |
389 | |
390 m_tst_handle=vsi_c_open (0,TST_NAME); | |
391 | |
392 return DRV_OK; | |
393 } | |
394 |