comparison src/g23m-aci/gdd_dio/gdd_dio_pei.c @ 162:53929b40109c

src/g23m-aci: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2016 02:02:43 +0000
parents
children
comparison
equal deleted inserted replaced
161:4557e2a9c18e 162:53929b40109c
1 /*
2 +------------------------------------------------------------------------------
3 | File: gdd_dio_pei.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 implements the PEI interface
17 | for the entity gdd_dio.
18 +-----------------------------------------------------------------------------
19 */
20
21 #define GDD_DIO_PEI_C
22
23 #define ENTITY_GDD_DIO
24
25 /*==== INCLUDES =============================================================*/
26
27 #include "typedefs.h" /* to get standard types */
28 #include "vsi.h" /* to get a lot of macros */
29 #include "gsm.h" /* to get a lot of macros */
30 #include "custom.h" /* to get GDD_DIO_NAME */
31 #include "prim.h" /* to get the definitions of used SAP and directions */
32 #include "pei.h" /* to get PEI interface */
33 #include "tools.h" /* to get common tools */
34 #include "mon_gdd_dio.h" /* to get mon-definitions */
35 #include "gdd_dio.h" /* to get the global entity definitions */
36 #include "string.h" /* for strncmp */
37
38 #include "gdd_dio_kerf.h"
39
40 #include "gdd_dio_rxf.h" /* Needed for gdd_dio_rx_sig_send_data() */
41 #include "gdd_dio_drxf.h" /* Needed for gdd_dio_drx_sig_receive_data */
42
43
44 /*==== CONSTS ================================================================*/
45
46 /*
47 * Wait as long as possible. This is the time in ms that is waited for a
48 * message in the input queue in the active variant.
49 * It can be decreased by the customer.
50 */
51 #define GDD_DIO_TIMEOUT 0xffffffff
52
53 /*==== TYPES =================================================================*/
54
55 /* Entry point for testing BAT via the BAT adapter (this entity) */
56 GLOBAL void gdd_dio_test_bat(const char * in_string);
57
58 /*==== LOCALS ================================================================*/
59
60 static T_MONITOR gdd_dio_mon;
61
62 /*
63 * Function is needed for grr_table[]. This declaration can be removed
64 * as soon as this function is no more called (i.e. all primitives are
65 * handled).
66 */
67 static void primitive_not_supported (void *data);
68
69
70
71 #ifdef _SIMULATION_
72 /* Function to activate/de-activate the PSI STUB for simulation */
73 void dio_il_sim_activate_psi_stub(BOOL b);
74 void dio_il_psi_stub_activate_batlib_test(BOOL b);
75 #endif /* _SIMULATION */
76
77
78 /*==== PRIVATE FUNCTIONS ====================================================*/
79
80 /*
81 +------------------------------------------------------------------------------
82 | Function : primitive_not_supported
83 +------------------------------------------------------------------------------
84 | Description : This function handles unsupported primitives.
85 |
86 | Parameters : data - not used
87 |
88 | Return : void
89 +------------------------------------------------------------------------------
90 */
91 static void primitive_not_supported (void *data)
92 {
93 TRACE_FUNCTION ("[GDD] primitive_not_supported()");
94
95 PFREE (data);
96 }
97
98 /*
99 +------------------------------------------------------------------------------
100 | Function : pei_primitive
101 +------------------------------------------------------------------------------
102 | Description : Process protocol specific primitive.
103 |
104 | Parameters : prim - pointer to the received primitive
105 |
106 | Return : PEI_OK - function succeeded
107 | PEI_ERROR - function failed
108 +------------------------------------------------------------------------------
109 */
110 static short pei_primitive (void * ptr)
111 {
112 T_PRIM *prim = (T_PRIM*)ptr;
113
114
115 TRACE_FUNCTION ("[GDD] pei_primitive()");
116
117 if (prim NEQ NULL)
118 {
119 unsigned long opc = prim->custom.opc;
120 unsigned short n;
121 const T_FUNC *table;
122
123 /*
124 * This must be called for Partition Pool supervision. Will be replaced
125 * by another macro some time.
126 */
127 VSI_PPM_REC (&prim->custom, __FILE__, __LINE__);
128
129 PTRACE_IN (opc);
130
131 switch (opc & OPC_MASK)
132 {
133 default:
134 table = NULL;
135 n = 0;
136 break;
137 }
138
139 if (table != NULL)
140 {
141 if ((opc & PRM_MASK) < n)
142 {
143 table += opc & PRM_MASK;
144 #ifdef PALLOC_TRANSITION
145 P_SDU(prim) = table->soff ?
146 (T_sdu*) (((char*)&prim->data) + table->soff) : 0;
147 #ifndef NO_COPY_ROUTING
148 P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
149 #endif /* #ifndef NO_COPY_ROUTING */
150 #endif /* #ifdef PALLOC_TRANSITION */
151 JUMP (table->func) (P2D(prim));
152 }
153 else
154 {
155 primitive_not_supported (P2D(prim));
156 }
157 return PEI_OK;
158 }
159
160 /*
161 * primitive is not a GSM primitive - forward it to the environment
162 */
163 if (opc & SYS_MASK)
164 vsi_c_primitive (VSI_CALLER prim);
165 else
166 {
167 PFREE (P2D(prim));
168 return PEI_ERROR;
169 }
170 }
171 return PEI_OK;
172 }
173
174 /*
175 +------------------------------------------------------------------------------
176 | Function : pei_init
177 +------------------------------------------------------------------------------
178 | Description : Initialize Protocol Stack Entity
179 |
180 | Parameters : handle - task handle
181 |
182 | Return : PEI_OK - entity initialised
183 | PEI_ERROR - entity not (yet) initialised
184 +------------------------------------------------------------------------------
185 */
186 static short pei_init (T_HANDLE handle)
187 {
188 TRACE_FUNCTION ("[GDD] pei_init()");
189
190 /* Initialize task handle */
191 GDD_DIO_handle = handle;
192
193 /*
194 * Open communication channels
195 */
196 if (hCommGDD_DIO < VSI_OK)
197 {
198 if ((hCommGDD_DIO = vsi_c_open (VSI_CALLER GDD_DIO_NAME)) < VSI_OK)
199 return PEI_ERROR;
200 }
201 /*
202 * Initialize entity data (call init function of every service)
203 */
204 gdd_dio_ker_init();
205
206 return (PEI_OK);
207 }
208
209 /*
210 +------------------------------------------------------------------------------
211 | Function : pei_timeout
212 +------------------------------------------------------------------------------
213 | Description : Process timeout.
214 |
215 | Parameters : index - timer index
216 |
217 | Return : PEI_OK - timeout processed
218 | PEI_ERROR - timeout not processed
219 +------------------------------------------------------------------------------
220 */
221 static short pei_timeout (unsigned short index)
222 {
223 TRACE_FUNCTION ("[GDD] pei_timeout()");
224
225 /* Process timeout */
226 switch (index)
227 {
228 case 0:
229 /* Call of timeout routine */
230 break;
231 default:
232 TRACE_ERROR("[GDD] Unknown Timeout()");
233 return PEI_ERROR;
234 }
235
236 return PEI_OK;
237 }
238
239 /*
240 +------------------------------------------------------------------------------
241 | Function : pei_signal
242 +------------------------------------------------------------------------------
243 | Description : Process signal.
244 |
245 | Parameters : opc - signal operation code
246 | data - pointer to primitive
247 |
248 | Return : PEI_OK - signal processed
249 | PEI_ERROR - signal not processed
250 +------------------------------------------------------------------------------
251 */
252 static short pei_signal (unsigned long opc, void* data)
253 {
254 #ifdef GDD_MAKE_DTX_CONTEXT_SWITCH
255 U32 con_handle = opc & GDD_DIO_SIGNAL_CON_HANDLE_MASK;
256 #else /* GDD_MAKE_DTX_CONTEXT_SWITCH */
257 U32 con_handle = opc;
258 #endif /* GDD_MAKE_DTX_CONTEXT_SWITCH */
259
260 TRACE_FUNCTION ("[GDD] pei_signal()");
261
262 #ifdef GDD_MAKE_DTX_CONTEXT_SWITCH
263 /* Process signal */
264 switch (opc & GDD_DIO_SIGNAL_MASK)
265 {
266 case GDD_DIO_SIGNAL_SEND_DATA:
267 gdd_dio_rx_sig_send_data(con_handle, (T_dio_buffer *)data);
268 break;
269
270 case GDD_DIO_SIGNAL_RECEIVE_DATA:
271 gdd_dio_drx_sig_receive_data(con_handle, (T_dio_buffer *)data);
272 break;
273
274 default:
275 TRACE_ERROR("[GDD] Unknown Signal OPC");
276 return PEI_ERROR;
277 }
278 #else /* GDD_MAKE_DTX_CONTEXT_SWITCH */
279 /* If no context switch is done, there is only one signal to be handled. */
280 gdd_dio_drx_sig_receive_data(con_handle, (T_dio_buffer *)data);
281 #endif /* GDD_MAKE_DTX_CONTEXT_SWITCH */
282
283 return PEI_OK;
284 }
285
286 /*
287 +------------------------------------------------------------------------------
288 | Function : pei_exit
289 +------------------------------------------------------------------------------
290 | Description : Close Resources and terminate.
291 |
292 | Parameters : -
293 |
294 | Return : PEI_OK - exit sucessful
295 +------------------------------------------------------------------------------
296 */
297 static short pei_exit (void)
298 {
299 TRACE_FUNCTION ("[GDD] pei_exit");
300
301 /*
302 * Close communication channels
303 */
304 vsi_c_close (VSI_CALLER hCommGDD_DIO);
305 hCommGDD_DIO = VSI_ERROR;
306
307
308 return PEI_OK;
309 }
310
311
312 /*
313 +------------------------------------------------------------------------------
314 | Function : pei_config
315 +------------------------------------------------------------------------------
316 | Description : Dynamic Configuration.
317 |
318 | Parameters : in_string - configuration string
319 |
320 | Return : PEI_OK - sucessful
321 | PEI_ERROR - not successful
322 +------------------------------------------------------------------------------
323 */
324 static short pei_config (char *in_string)
325 {
326 TRACE_FUNCTION ("[GDD] pei_config()");
327 TRACE_FUNCTION (in_string);
328
329 if ( ConfigTimer ( VSI_CALLER in_string, NULL ) == VSI_OK )
330 return PEI_OK;
331
332 /*
333 * further dynamic configuration
334 */
335 #ifdef _SIMULATION_
336 if (!strncmp("sizeof(T_GDD_DIO_CON_DATA)",in_string,7))
337 {
338 TRACE_EVENT_P1("[GDD] sizeof(T_GDD_DIO_CON_DATA) = %d", sizeof(T_GDD_DIO_CON_DATA));
339 }
340 else if (!strncmp("PSI STUB ON",in_string, 11))
341 {
342 TRACE_EVENT("[GDD] Activating the PSI STUB");
343 dio_il_sim_activate_psi_stub (TRUE);
344 }
345 else if (!strncmp("PSI STUB OFF",in_string, 12))
346 {
347 TRACE_EVENT("[GDD] Deactivating the PSI STUB");
348 dio_il_sim_activate_psi_stub (FALSE);
349 }
350 else if (!strncmp("BATLIB TEST ON",in_string, 14))
351 {
352 TRACE_EVENT("[GDD] Activating BATlib testing in PSI stub");
353 dio_il_psi_stub_activate_batlib_test (TRUE);
354 }
355 else if (!strncmp("BATLIB TEST OFF",in_string, 15))
356 {
357 TRACE_EVENT("[GDD] Deactivating BATlib testing in PSI stub");
358 dio_il_psi_stub_activate_batlib_test (FALSE);
359 }
360
361 #endif /* _SIMULATION_ */
362
363 return PEI_OK;
364 }
365
366 /*
367 +------------------------------------------------------------------------------
368 | Function : pei_monitor
369 +------------------------------------------------------------------------------
370 | Description : Monitoring of physical Parameters.
371 |
372 | Parameters : out_monitor - return the address of the data to be monitored
373 |
374 | Return : PEI_OK - sucessful (address in out_monitor is valid)
375 | PEI_ERROR - not successful
376 +------------------------------------------------------------------------------
377 */
378 static short pei_monitor (void ** out_monitor)
379 {
380 TRACE_FUNCTION ("[GDD] pei_monitor()");
381
382 /*
383 * Version = "0.S" (S = Step).
384 */
385 gdd_dio_mon.version = "gdd_dio 0.1";
386 *out_monitor = &gdd_dio_mon;
387
388 return PEI_OK;
389 }
390
391 /*==== PUBLIC FUNCTIONS =====================================================*/
392
393 /*
394 +------------------------------------------------------------------------------
395 | Function : pei_create
396 +------------------------------------------------------------------------------
397 | Description : Create the Protocol Stack Entity.
398 |
399 | Parameters : info - Pointer to the structure of entity parameters
400 |
401 | Return : PEI_OK - entity created successfully
402 |
403 +------------------------------------------------------------------------------
404 */
405 short gdd_dio_pei_create (T_PEI_INFO **info)
406 {
407 static T_PEI_INFO pei_info =
408 {
409 GDD_DIO_NAME, /* name */
410 { /* pei-table */
411 pei_init,
412 #ifdef _SIMULATION_
413 pei_exit,
414 #else
415 NULL,
416 #endif
417 pei_primitive,
418 pei_timeout,
419 pei_signal,
420 NULL, /* No pei_run function */
421 pei_config,
422 pei_monitor
423 },
424 /*1024,*/ /* stack size */
425 2048, /* :TODO: check why we need to increase the stack size */
426 10, /* queue entries */
427 100, /* priority (1->low, 255->high) */
428 0, /* number of timers */
429 0x03 /* flags: bit 0 active(0) body/passive(1) */
430 }; /* bit 1 com by copy(0)/reference(1) */
431
432 /*
433 * Export startup configuration data
434 */
435 *info = &pei_info;
436
437 return PEI_OK;
438 }
439
440 /*==== END OF FILE ==========================================================*/