comparison src/g23m-fad/app/app_pei.c @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +------------------------------------------------------------------------------
3 | File: app_pei.c
4 +------------------------------------------------------------------------------
5 | Copyright 2003 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 app.
18 +-----------------------------------------------------------------------------
19 */
20
21 #define APP_PEI_C
22
23 #define ENTITY_APP
24 /* this #define SAP_TCPIP and #define SAP_DCM in prim.h - */
25
26 #define APP_STACK_SIZE 1500
27 #define APP_QUEUE_SIZE 10 /* queue entries */
28 #define APP_PRIORITY 90 /* priority (1->low, 255->high) */
29 #define APP_NUM_TIMER 10 /* number of timers */
30
31
32 /*==== INCLUDES =============================================================*/
33
34 #include <string.h> /* to get strcmp() */
35 #include <stdlib.h> /* to get atoi() */
36 #include <stdio.h> /* to get sprintf() */
37
38 #include "typedefs.h" /* to get Condat data types */
39 #include "vsi.h" /* to get a lot of macros */
40 #include "gsm.h" /* to get a lot of macros */
41 #include "prim.h" /* to get the definitions of used SAP and directions */
42 #include "pei.h" /* to get PEI interface */
43 #include "tools.h" /* to get common tools */
44
45 #ifdef FF_GPF_TCPIP
46 #include "socket_api.h" /* to get sockets' definitions */
47 #endif /* FF_GPF_TCPIP */
48
49 #include "mon_app.h" /* to get mon-definitions */
50 #include "app.h" /* to get the global entity definitions */
51
52
53 /*==== EXTERNAL FUNCTIONS ====================================================*/
54
55 EXTERN char *app_handle_command_gdd(char *);
56 EXTERN char *app_handle_at_command(char *);
57 EXTERN char* app_handle_command_bat(char *);
58
59 /*==== CONSTS ================================================================*/
60
61 /*
62 * Wait as long as possible. This is the time in ms that is waited for a
63 * message in the input queue in the active variant.
64 * It can be decreased by the customer.
65 */
66 #define APP_TIMEOUT 0xffffffff
67
68 /* Entity name
69 */
70 #define ENTITY_NAME_APP "APP"
71
72 /*==== TYPES =================================================================*/
73
74 /*==== LOCALS ================================================================*/
75
76 static BOOL first_access = TRUE;
77 static BOOL exit_flag = FALSE;
78 static T_MONITOR app_mon;
79
80
81 #ifdef FF_GPF_TCPIP
82 T_SOCK_API_INSTANCE sock_api_inst = 0 ; /* Also needed by the appl. core. */
83 // System wide handle of a bearer connection. For future use (multiple PDP contexts)!!
84 T_SOCK_BEARER_HANDLE sock_bearer_handle = 0;
85 #endif /* FF_GPF_TCPIP */
86
87 /*==== PRIVATE FUNCTIONS ====================================================*/
88
89 /*
90 +------------------------------------------------------------------------------
91 | Function : primitive_not_supported
92 +------------------------------------------------------------------------------
93 | Description : This function handles unsupported primitives.
94 |
95 | Parameters : data - not used
96 |
97 | Return : void
98 +------------------------------------------------------------------------------
99 */
100 LOCAL void primitive_not_supported (void *data)
101 {
102 TRACE_FUNCTION ("primitive_not_supported");
103
104 PFREE (data);
105 }
106
107
108 /*
109 +------------------------------------------------------------------------------
110 | Function : pei_primitive
111 +------------------------------------------------------------------------------
112 | Description : Process protocol specific primitive.
113 |
114 | Parameters : prim - pointer to the received primitive
115 |
116 | Return : PEI_OK - function succeeded
117 | PEI_ERROR - function failed
118 +------------------------------------------------------------------------------
119 */
120 static short pei_primitive (void * ptr)
121 {
122 T_PRIM * prim = (T_PRIM *) ptr;
123 unsigned long opc;
124 BOOL result = FALSE;
125
126 TRACE_FUNCTION ("pei_primitive");
127
128 if (prim EQ NULL)
129 {
130 TRACE_EVENT("Empty primitive");
131 return PEI_OK;
132 }
133
134 /*
135 * This must be called for Partition Pool supervision. Will be replaced
136 * by another macro some time.
137 */
138 VSI_PPM_REC (&prim->custom, __FILE__, __LINE__);
139
140 opc = prim->custom.opc;
141 PTRACE_IN(opc);
142
143 #ifdef FF_GPF_TCPIP
144 result = sock_api_handles_primitive(sock_api_inst, prim);
145 #endif /* FF_GPF_TCPIP */
146 if(FALSE EQ result)
147 {
148 // primitive is not a GSM primitive - forward it to the environment
149 if(opc & SYS_MASK)
150 {
151 vsi_c_primitive (VSI_CALLER prim);
152 }
153 else
154 {
155 primitive_not_supported (P2D(prim));
156 return PEI_ERROR;
157 }
158 }
159 return PEI_OK;
160 }
161
162
163 /*
164 +------------------------------------------------------------------------------
165 | Function : pei_init
166 +------------------------------------------------------------------------------
167 | Description : Initialize Protocol Stack Entity
168 |
169 | Parameters : handle - task handle
170 |
171 | Return : PEI_OK - entity initialised
172 | PEI_ERROR - entity not (yet) initialised
173 +------------------------------------------------------------------------------
174 */
175 static short pei_init (T_HANDLE handle)
176 {
177 short ret_value = PEI_OK;
178 BOOL ret = FALSE;
179 TRACE_FUNCTION ("pei_init()");
180
181 /* Initialize task handle */
182 APP_handle = handle;
183
184 /*
185 * Initialize global pointer app_data. This is required to access all
186 * entity data.
187 */
188 app_data = &app_data_base;
189
190 #ifdef FF_GPF_TCPIP
191 /* initialize socket API */
192 ret = sock_api_initialize(&sock_api_inst, handle, ENTITY_NAME_APP);
193 if (FALSE == ret)
194 {
195 TRACE_ERROR("sock_api_initialize() failed") ;
196 return PEI_ERROR ;
197 }
198 TRACE_EVENT("sock_api_initialize()d successfully") ;
199 ret_value = app_initialize_tcpip(handle) ;
200 #endif /* FF_GPF_TCPIP */
201
202 return ret_value;
203 }
204
205 /*
206 +------------------------------------------------------------------------------
207 | Function : pei_timeout
208 +------------------------------------------------------------------------------
209 | Description : Process timeout.
210 |
211 | Parameters : index - timer index
212 |
213 | Return : PEI_OK - timeout processed
214 | PEI_ERROR - timeout not processed
215 +------------------------------------------------------------------------------
216 */
217 static short pei_timeout (unsigned short index)
218 {
219 TRACE_FUNCTION ("pei_timeout");
220
221 /* Process timeout */
222 switch (index)
223 {
224 case 0:
225 /* Call of timeout routine */
226 break;
227 default:
228 TRACE_ERROR("Unknown Timeout");
229 return PEI_ERROR;
230 }
231 return PEI_OK;
232 }
233
234 /*
235 +------------------------------------------------------------------------------
236 | Function : pei_signal
237 +------------------------------------------------------------------------------
238 | Description : Process signal.
239 |
240 | Parameters : opc - signal operation code
241 | data - pointer to primitive
242 |
243 | Return : PEI_OK - signal processed
244 | PEI_ERROR - signal not processed
245 +------------------------------------------------------------------------------
246 */
247 static short pei_signal (unsigned long opc, void* data)
248 {
249 TRACE_FUNCTION ("pei_signal()");
250
251 /* Process signal */
252 TRACE_ERROR("Unknown Signal OPC");
253 return PEI_ERROR;
254 }
255
256 /*
257 +------------------------------------------------------------------------------
258 | Function : pei_exit
259 +------------------------------------------------------------------------------
260 | Description : Close Resources and terminate.
261 |
262 | Parameters : -
263 |
264 | Return : PEI_OK - exit sucessful
265 +------------------------------------------------------------------------------
266 */
267 static short pei_exit (void)
268 {
269 TRACE_FUNCTION ("pei_exit()");
270
271 #ifdef FF_GPF_TCPIP
272 sock_api_deinitialize(sock_api_inst) ;
273 #endif /* FF_GPF_TCPIP */
274
275 exit_flag = TRUE;
276
277 return PEI_OK;
278 }
279
280 /*
281 +------------------------------------------------------------------------------
282 | Function : pei_run
283 +------------------------------------------------------------------------------
284 | Description : Process Primitives, main loop is located in the
285 | Protocol Stack Entity.
286 | Only needed in active body variant
287 |
288 | Parameters : taskhandle - handle of current process
289 | comhandle - queue handle of current process
290 |
291 | Return : PEI_OK - sucessful
292 | PEI_ERROR - not successful
293 +------------------------------------------------------------------------------
294 */
295 static short pei_run (T_HANDLE taskhandle, T_HANDLE comhandle )
296 {
297 T_QMSG message;
298 unsigned long timeout = APP_TIMEOUT;
299
300 TRACE_FUNCTION ("pei_run()");
301
302 while (!exit_flag)
303 {
304 vsi_c_await (VSI_CALLER comhandle, &message, timeout);
305 switch (message.MsgType)
306 {
307 case MSG_PRIMITIVE:
308 pei_primitive (message.Msg.Primitive.Prim );
309 break;
310 case MSG_SIGNAL:
311 pei_signal ( (USHORT)message.Msg.Signal.SigOPC,
312 message.Msg.Signal.SigBuffer );
313 break;
314 case MSG_TIMEOUT:
315 pei_timeout ( (USHORT)message.Msg.Timer.Index );
316 break;
317 default:
318 TRACE_ERROR("Unknown Message Type");
319 break;
320 }
321 }
322
323 exit_flag = FALSE;
324
325 return PEI_OK;
326 }
327
328
329 /*
330 +------------------------------------------------------------------------------
331 | Function : pei_config
332 +------------------------------------------------------------------------------
333 | Description : Dynamic Configuration.
334 |
335 | Parameters : in_string - configuration string
336 |
337 | Return : PEI_OK - sucessful
338 | PEI_ERROR - not successful
339 +------------------------------------------------------------------------------
340 */
341 static short pei_config (char * in_string)
342 {
343 char *errmsg = 0 ; /* Error message from application. */
344
345 TRACE_FUNCTION ("pei_config()");
346 TRACE_EVENT_P1 ("Command:%s",in_string);
347
348 if (ConfigTimer (VSI_CALLER in_string, NULL) == VSI_OK)
349 {
350 return PEI_OK;
351 }
352
353 /* BEGIN testing via PCO config strings */
354 if (in_string)
355 {
356 /* Test commands for GDD (BAT adapter) are prefixed with 'gdd' */
357 if(!strncmp("gdd", in_string, 3))
358 {
359 errmsg = app_handle_command_gdd(in_string);
360 }
361 else if (!strncmp("at_", in_string, 3))
362 {
363 errmsg = app_handle_at_command(in_string);
364 }
365 /* else if(!strncmp("batcfg_", in_string, 7))
366 {
367 errmsg = app_handle_command_bat(in_string);
368 }*/
369 /* Test commands for BAT Lib are prefixed with 'bat' */
370 else if(!strncmp("bat", in_string, 3))
371 {
372 errmsg = app_handle_command_bat(in_string);
373 }
374
375 #ifdef FF_GPF_TCPIP
376 else
377 {
378 // returns '0' in case of success, errorstring else
379 errmsg = app_handle_command_tcpip(in_string) ;
380 }
381 #endif /* FF_GPF_TCPIP */
382 if (errmsg)
383 {
384 TRACE_ERROR(errmsg) ;
385 }
386 else
387 {
388 TRACE_EVENT("command successful") ;
389 }
390 }
391 else
392 {
393 TRACE_ERROR("empty config primitive") ;
394 }
395 return PEI_OK;
396 }
397
398 /*
399 +------------------------------------------------------------------------------
400 | Function : pei_monitor
401 +------------------------------------------------------------------------------
402 | Description : Monitoring of physical Parameters.
403 |
404 | Parameters : out_monitor - return the address of the data to be monitored
405 |
406 | Return : PEI_OK - sucessful (address in out_monitor is valid)
407 | PEI_ERROR - not successful
408 +------------------------------------------------------------------------------
409 */
410 static short pei_monitor (void ** out_monitor)
411 {
412 TRACE_FUNCTION ("pei_monitor()");
413
414 /*
415 * Version = "0.S" (S = Step).
416 */
417 app_mon.version = "app 0.1";
418 *out_monitor = &app_mon;
419
420 return PEI_OK;
421 }
422
423 /*==== PUBLIC FUNCTIONS =====================================================*/
424
425 /*
426 +------------------------------------------------------------------------------
427 | Function : app_pei_create
428 +------------------------------------------------------------------------------
429 | Description : Create the Protocol Stack Entity.
430 |
431 | Parameters : info - Pointer to the structure of entity parameters
432 |
433 | Return : PEI_OK - entity created successfully
434 |
435 +------------------------------------------------------------------------------
436 */
437 short app_pei_create (T_PEI_INFO **info)
438 {
439 static T_PEI_INFO pei_info =
440 {
441 ENTITY_NAME_APP, /* name */
442 { /* pei-table */
443 pei_init,
444 pei_exit,
445 pei_primitive,
446 pei_timeout,
447 pei_signal,
448 pei_run,
449 pei_config,
450 pei_monitor
451 },
452 APP_STACK_SIZE,
453 APP_QUEUE_SIZE,
454 APP_PRIORITY,
455 APP_NUM_TIMER,
456 0x03 /* flags: bit 0 active(0) body/passive(1) */
457 }; /* bit 1 com by copy(0)/reference(1) */
458
459 /* Close Resources if open */
460 if (first_access) {
461 first_access = FALSE;
462 }
463 else {
464 pei_exit ();
465 }
466
467 /* Export startup configuration data */
468 *info = &pei_info;
469
470 return PEI_OK;
471 }
472
473
474 /*==== END OF FILE ==========================================================*/
475