comparison gpf/TEMPLATE/PEI/xxx_pei.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +------------------------------------------------------------------------------
3 | File: xxx_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 xxx.
18 +-----------------------------------------------------------------------------
19 */
20
21 #define XXX_PEI_C
22
23 #define ENTITY_XXX
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 "prim.h" /* to get the definitions of used SAP and directions */
31 #include "pei.h" /* to get PEI interface */
32 #include "tools.h" /* to get common tools */
33 #include "mon_xxx.h" /* to get mon-definitions */
34 #include "xxx.h" /* to get the global entity definitions */
35
36 /*==== CONSTS ================================================================*/
37
38 /*
39 * Wait as long as possible. This is the time in ms that is waited for a
40 * message in the input queue in the active variant.
41 * It can be decreased by the customer.
42 */
43 #define XXX_TIMEOUT 0xffffffff
44
45 /*==== TYPES =================================================================*/
46
47 /*==== LOCALS ================================================================*/
48
49 static BOOL first_access = TRUE;
50 static BOOL exit_flag = FALSE;
51 static T_MONITOR xxx_mon;
52
53
54 /*
55 * Jumptables to primitive handler functions. One table per SAP.
56 *
57 * Use MAK_FUNC_0 for primitives which contains no SDU.
58 * Use MAK_FUNC_S for primitives which contains a SDU.
59 */
60
61 static const T_FUNC aaa_table[] =
62 {
63 /*------------------------------------------------------------------------
64 The code below can be enabled when the service access points are defined
65 ------------------------------------------------------------------------*/
66 #if 1
67 0
68 #else
69 MAK_FUNC_S(aaa_establish_req, AAA_ESTABLISH_REQ),
70 #endif
71 /*------------------------------------------------------------------------
72 The code above can be enabled when the service access points are defined
73 ------------------------------------------------------------------------*/
74 };
75
76 static const T_FUNC bbb_table[] =
77 {
78 /*------------------------------------------------------------------------
79 The code below can be enabled when the service access points are defined
80 ------------------------------------------------------------------------*/
81 #if 1
82 0
83 #else
84 MAK_FUNC_S(bbb_establish_req, BBB_ESTABLISH_REQ),
85 #endif
86 /*------------------------------------------------------------------------
87 The code above can be enabled when the service access points are defined
88 ------------------------------------------------------------------------*/
89 };
90
91 static const T_FUNC yyy_table[] =
92 {
93 /*------------------------------------------------------------------------
94 The code below can be enabled when the service access points are defined
95 ------------------------------------------------------------------------*/
96 #if 1
97 0
98 #else
99 MAK_FUNC_0(rx_yyy_data_ind, YYY_DATA_IND),
100 #endif
101 /*------------------------------------------------------------------------
102 The code above can be enabled when the service access points are defined
103 ------------------------------------------------------------------------*/
104 };
105
106 /*
107 * Function is needed for grr_table[]. This declaration can be removed
108 * as soon as this function is no more called (i.e. all primitives are
109 * handled).
110 */
111 static const void primitive_not_supported (void *data);
112
113 /*==== PRIVATE FUNCTIONS ====================================================*/
114
115 /*
116 +------------------------------------------------------------------------------
117 | Function : primitive_not_supported
118 +------------------------------------------------------------------------------
119 | Description : This function handles unsupported primitives.
120 |
121 | Parameters : data - not used
122 |
123 | Return : void
124 +------------------------------------------------------------------------------
125 */
126 static const void primitive_not_supported (void *data)
127 {
128 TRACE_FUNCTION ("primitive_not_supported");
129
130 PFREE (data);
131 }
132
133 /*
134 +------------------------------------------------------------------------------
135 | Function : pei_primitive
136 +------------------------------------------------------------------------------
137 | Description : Process protocol specific primitive.
138 |
139 | Parameters : prim - pointer to the received primitive
140 |
141 | Return : PEI_OK - function succeeded
142 | PEI_ERROR - function failed
143 +------------------------------------------------------------------------------
144
145 | |
146 AAA BBB UPLINK
147 | |
148 +------v-----------v-------+
149 | |
150 | XXX |
151 | |
152 +-------------^------------+
153 |
154 YYY DOWNLINK
155 |
156
157 */
158 static short pei_primitive (void * ptr)
159 {
160 T_PRIM *prim = (T_PRIM*)ptr;
161
162
163 TRACE_FUNCTION ("pei_primitive");
164
165 if (prim NEQ NULL)
166 {
167 unsigned long opc = prim->custom.opc;
168 unsigned short n;
169 const T_FUNC *table;
170
171 PTRACE_IN (opc);
172
173 switch (SAP_NR(opc))
174 {
175 /*------------------------------------------------------------------------
176 The code below can be enabled when the service access points are defined
177 ------------------------------------------------------------------------*/
178 #if 0
179 case SAP_NR(AAA_UL): /* defined in prim.h */
180 table = aaa_table;
181 n = TAB_SIZE (aaa_table);
182 break;
183 case SAP_NR(BBB_UL): /* defined in prim.h */
184 table = bbb_table;
185 n = TAB_SIZE (bbb_table);
186 break;
187 case SAP_NR(YYY_DL): /* defined in prim.h */
188 table = yyy_table;
189 n = TAB_SIZE (yyy_table);
190 break;
191 #endif
192 /*------------------------------------------------------------------------
193 The code above can be enabled when the service access points are defined
194 ------------------------------------------------------------------------*/
195 default:
196 table = NULL;
197 n = 0;
198 break;
199 }
200
201 if (table != NULL)
202 {
203 if (PRIM_NR(opc) < n)
204 {
205 table += PRIM_NR(opc);
206 #ifdef PALLOC_TRANSITION
207 P_SDU(prim) = table->soff ? (T_sdu*) (((char*)&prim->data) + table->soff) : 0;
208 #ifndef NO_COPY_ROUTING
209 P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
210 #endif /* #ifndef NO_COPY_ROUTING */
211 #endif /* #ifdef PALLOC_TRANSITION */
212 JUMP (table->func) (P2D(prim));
213 }
214 else
215 {
216 primitive_not_supported (P2D(prim));
217 }
218 return PEI_OK;
219 }
220
221 /*
222 * primitive is not a GSM primitive - forward it to the environment
223 */
224 if (opc & SYS_MASK)
225 vsi_c_primitive (VSI_CALLER prim);
226 else
227 {
228 PFREE (P2D(prim));
229 return PEI_ERROR;
230 }
231 }
232 return PEI_OK;
233 }
234
235 /*
236 +------------------------------------------------------------------------------
237 | Function : pei_init
238 +------------------------------------------------------------------------------
239 | Description : Initialize Protocol Stack Entity
240 |
241 | Parameters : handle - task handle
242 |
243 | Return : PEI_OK - entity initialised
244 | PEI_ERROR - entity not (yet) initialised
245 +------------------------------------------------------------------------------
246 */
247 static short pei_init (T_HANDLE handle)
248 {
249 TRACE_FUNCTION ("pei_init");
250
251 /* Initialize task handle */
252 XXX_handle = handle;
253
254 /*----------------------------------------------------------
255 The code below can be enabled when the YYY_NAME is defined
256 ----------------------------------------------------------*/
257 #if 0
258 /*
259 * Open communication channels
260 */
261 if (hCommYYY < VSI_OK)
262 {
263 if ((hCommYYY = vsi_c_open (VSI_CALLER YYY_NAME)) < VSI_OK)
264 return PEI_ERROR;
265 }
266
267 #endif
268 /*----------------------------------------------------------
269 The code above can be enabled when the YYY_NAME is defined
270 ----------------------------------------------------------*/
271
272 /*
273 * Get my own handle. Needed in pei_run() for ACTIVE_BODY configuration
274 */
275 if (hCommXXX < VSI_OK)
276 {
277 if ((hCommXXX = vsi_c_open (VSI_CALLER MY_NAME)) < VSI_OK)
278 return PEI_ERROR;
279 }
280
281 /*
282 * Initialize global pointer xxx_data. This is required to access all
283 * entity data.
284 */
285 xxx_data = &xxx_data_base;
286
287 /*
288 * Initialize entity data (call init function of every service)
289 */
290
291 return (PEI_OK);
292 }
293
294 /*
295 +------------------------------------------------------------------------------
296 | Function : pei_timeout
297 +------------------------------------------------------------------------------
298 | Description : Process timeout.
299 |
300 | Parameters : index - timer index
301 |
302 | Return : PEI_OK - timeout processed
303 | PEI_ERROR - timeout not processed
304 +------------------------------------------------------------------------------
305 */
306 static short pei_timeout (unsigned short index)
307 {
308 TRACE_FUNCTION ("pei_timeout");
309
310 /* Process timeout */
311 switch (index)
312 {
313 case 0:
314 /* Call of timeout routine */
315 break;
316 default:
317 TRACE_ERROR("Unknown Timeout");
318 return PEI_ERROR;
319 }
320
321 return PEI_OK;
322 }
323
324 /*
325 +------------------------------------------------------------------------------
326 | Function : pei_signal
327 +------------------------------------------------------------------------------
328 | Description : Process signal.
329 |
330 | Parameters : opc - signal operation code
331 | data - pointer to primitive
332 |
333 | Return : PEI_OK - signal processed
334 | PEI_ERROR - signal not processed
335 +------------------------------------------------------------------------------
336 */
337 static short pei_signal (unsigned long opc, void* data)
338 {
339 TRACE_FUNCTION ("pei_signal");
340
341 /* Process signal */
342 switch (opc)
343 {
344 default:
345 TRACE_ERROR("Unknown Signal OPC");
346 return PEI_ERROR;
347 }
348
349 return PEI_OK;
350 }
351
352 /*
353 +------------------------------------------------------------------------------
354 | Function : pei_exit
355 +------------------------------------------------------------------------------
356 | Description : Close Resources and terminate.
357 |
358 | Parameters : -
359 |
360 | Return : PEI_OK - exit sucessful
361 +------------------------------------------------------------------------------
362 */
363 static short pei_exit (void)
364 {
365 TRACE_FUNCTION ("pei_exit");
366
367 /*
368 * Close communication channels
369 */
370 vsi_c_close (VSI_CALLER hCommYYY);
371 hCommYYY = VSI_ERROR;
372
373 vsi_c_close (VSI_CALLER hCommXXX);
374 hCommXXX = VSI_ERROR;
375
376 exit_flag = TRUE;
377
378 return PEI_OK;
379 }
380
381 /*
382 +------------------------------------------------------------------------------
383 | Function : pei_run
384 +------------------------------------------------------------------------------
385 | Description : Process Primitives, main loop is located in the
386 | Protocol Stack Entity.
387 | Only needed in active body variant
388 |
389 | Parameters : taskhandle - handle of current process
390 | comhandle - queue handle of current process
391 |
392 | Return : PEI_OK - sucessful
393 | PEI_ERROR - not successful
394 +------------------------------------------------------------------------------
395 */
396 static short pei_run (T_HANDLE taskhandle, T_HANDLE comhandle )
397 {
398 T_QMSG message;
399 unsigned long timeout = XXX_TIMEOUT;
400
401 TRACE_FUNCTION ("pei_run");
402
403 while (!exit_flag)
404 {
405 vsi_c_await (hCommXXX, hCommXXX, &message, timeout);
406 switch (message.MsgType)
407 {
408 case MSG_PRIMITIVE:
409 pei_primitive (message.Msg.Primitive.Prim );
410 break;
411 case MSG_SIGNAL:
412 pei_signal ( (USHORT)message.Msg.Signal.SigOPC, message.Msg.Signal.SigBuffer );
413 break;
414 case MSG_TIMEOUT:
415 pei_timeout ( (USHORT)message.Msg.Timer.Index );
416 break;
417 default:
418 TRACE_ERROR("Unknown Message Type");
419 break;
420 }
421 }
422
423 exit_flag = FALSE;
424
425 return PEI_OK;
426 }
427
428 /*
429 +------------------------------------------------------------------------------
430 | Function : pei_config
431 +------------------------------------------------------------------------------
432 | Description : Dynamic Configuration.
433 |
434 | Parameters : in_string - configuration string
435 |
436 | Return : PEI_OK - sucessful
437 | PEI_ERROR - not successful
438 +------------------------------------------------------------------------------
439 */
440 static short pei_config (char *in_string)
441 {
442 TRACE_FUNCTION ("pei_config");
443 TRACE_FUNCTION (in_string);
444
445 if ( ConfigTimer ( VSI_CALLER in_string, NULL ) == VSI_OK )
446 return PEI_OK;
447
448 /*
449 * further dynamic configuration
450 */
451 return PEI_OK;
452 }
453
454 /*
455 +------------------------------------------------------------------------------
456 | Function : pei_monitor
457 +------------------------------------------------------------------------------
458 | Description : Monitoring of physical Parameters.
459 |
460 | Parameters : out_monitor - return the address of the data to be monitored
461 |
462 | Return : PEI_OK - sucessful (address in out_monitor is valid)
463 | PEI_ERROR - not successful
464 +------------------------------------------------------------------------------
465 */
466 static short pei_monitor (void ** out_monitor)
467 {
468 TRACE_FUNCTION ("pei_monitor");
469
470 /*
471 * Version = "0.S" (S = Step).
472 */
473 xxx_mon.version = "xxx 0.1";
474 *out_monitor = &xxx_mon;
475
476 return PEI_OK;
477 }
478
479 /*==== PUBLIC FUNCTIONS =====================================================*/
480
481 /*
482 +------------------------------------------------------------------------------
483 | Function : pei_create
484 +------------------------------------------------------------------------------
485 | Description : Create the Protocol Stack Entity.
486 |
487 | Parameters : info - Pointer to the structure of entity parameters
488 |
489 | Return : PEI_OK - entity created successfully
490 |
491 +------------------------------------------------------------------------------
492 */
493 short pei_create (T_PEI_INFO **info)
494 {
495 static T_PEI_INFO pei_info =
496 {
497 MY_NAME, /* name */
498 { /* pei-table */
499 pei_init,
500 pei_exit,
501 pei_primitive,
502 pei_timeout,
503 pei_signal,
504 pei_run,
505 pei_config,
506 pei_monitor
507 },
508 1024, /* stack size */
509 10, /* queue entries */
510 100, /* priority (1->low, 255->high) */
511 10, /* number of timers */
512 0x03 /* flags: bit 0 active(0) body/passive(1) */
513 }; /* bit 1 com by copy(0)/reference(1) */
514
515 /*
516 * Export startup configuration data
517 */
518 *info = &pei_info;
519
520 return PEI_OK;
521 }
522
523 /*==== END OF FILE ==========================================================*/