comparison g23m-aci/uart/uart_pei.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This module implements the process body interface
18 | for the entity Universal Asynchronous Receiver Transmitter(UART)
19 |
20 | Exported functions:
21 |
22 | pei_create - Create the Protocol Stack Entity
23 | pei_init - Initialize Protocol Stack Entity
24 | pei_primitive - Process Primitive
25 | pei_timeout - Process Timeout
26 | pei_exit - Close resources and terminate
27 | pei_run - Process Primitive
28 | pei_config - Dynamic Configuration
29 | pei_monitor - Monitoring of physical Parameters
30 +-----------------------------------------------------------------------------
31 */
32
33 #define UART_PEI_C
34
35 #include "config.h"
36 #include "fixedconf.h"
37 #include "condat-features.h"
38
39 #define ENTITY_UART
40
41 /*==== INCLUDES =============================================================*/
42
43 #ifdef _SIMULATION_
44 #include <stdio.h>
45 #endif /* _SIMULATION_ */
46 #ifdef WIN32
47 #include "nucleus.h"
48 #endif /* WIN32 */
49 #include "typedefs.h" /* to get Condat data types */
50 #include "vsi.h" /* to get a lot of macros */
51 #include "macdef.h" /* to get a lot of macros */
52 #include "custom.h"
53 #include "gsm.h" /* to get a lot of macros */
54 #include "cnf_uart.h" /* to get cnf-definitions */
55 #include "mon_uart.h" /* to get mon-definitions */
56 #include "prim.h" /* to get the definitions of used SAP and directions */
57 #ifdef DTILIB
58 #ifdef _SIMULATION_
59 /* #define UART_DTI_CONFIG -- presently not needed -- */
60 #include "tok.h" /* string management for pei_config() */
61 #endif /* _SIMULATION_ */
62 #include "dti.h" /* to get dti lib */
63 #endif /* DTILIB */
64 #include "pei.h" /* to get PEI interface */
65 #ifdef FF_MULTI_PORT
66 #include "gsi.h" /* to get definitions of serial driver */
67 #else /* FF_MULTI_PORT */
68 #ifdef _TARGET_
69 #include "../../serial/serialswitch.h"
70 #include "../../serial/traceswitch.h"
71 #else /* _TARGET_ */
72 #include "serial_dat.h" /* to get definitions of serial driver */
73 #endif /* _TARGET_ */
74 #endif /* FF_MULTI_PORT */
75 #include "uart.h" /* to get the global entity definitions */
76
77 #include "uart_kerf.h" /* to get ker functions */
78 #include "uart_kerp.h" /* to get ker primitives */
79 #include "uart_kers.h" /* to get ker signals */
80
81 #ifndef FF_MULTI_PORT
82 #include "uart_rxf.h" /* to get rx functions */
83 #include "uart_rxp.h" /* to get rx primitives */
84 #include "uart_rxs.h" /* to get rx signals */
85
86 #include "uart_txf.h" /* to get tx functions */
87 #include "uart_txp.h" /* to get tx primitives */
88 #include "uart_txs.h" /* to get tx signals */
89 #else
90 #include "uart_prxf.h" /* to get rx functions */
91 #include "uart_prxp.h" /* to get rx primitives */
92 #include "uart_prxs.h" /* to get rx signals */
93
94 #include "uart_ptxf.h" /* to get tx functions */
95 #include "uart_ptxp.h" /* to get tx primitives */
96 #include "uart_ptxs.h" /* to get tx signals */
97 #endif /* FF_MULTI_PORT */
98
99 #include "uart_drxf.h" /* to get drx functions */
100 #include "uart_drxp.h" /* to get drx primitives */
101 #include "uart_drxs.h" /* to get drx signals */
102
103 #include "uart_dtxf.h" /* to get dtx functions */
104 #include "uart_dtxp.h" /* to get dtx primitives */
105 #include "uart_dtxs.h" /* to get dtx signals */
106
107 #include "uart_rtf.h" /* to get dtx functions */
108 #include "uart_rtp.h" /* to get dtx primitives */
109 #include "uart_rts.h" /* to get dtx signals */
110
111
112 /*==== DEFINITIONS ==========================================================*/
113
114 /*
115 * Prototypes for DTILIB wrap functions
116 */
117 LOCAL void pei_dti_dti_connect_req (T_DTI2_CONNECT_REQ* dti_connect_req);
118 LOCAL void pei_dti_dti_connect_res (T_DTI2_CONNECT_RES* dti_connect_res);
119 LOCAL void pei_dti_dti_disconnect_req (T_DTI2_DISCONNECT_REQ*
120 dti_disconnect_req);
121 LOCAL void pei_dti_dti_getdata_req (T_DTI2_GETDATA_REQ* dti_getdata_req);
122 LOCAL void pei_dti_dti_data_req (T_DTI2_DATA_REQ* dti_data_req);
123 LOCAL void pei_dti_dti_connect_ind (T_DTI2_CONNECT_IND* dti_connect_ind);
124 LOCAL void pei_dti_dti_connect_cnf (T_DTI2_CONNECT_CNF* dti_connect_cnf);
125 LOCAL void pei_dti_dti_disconnect_ind (T_DTI2_DISCONNECT_IND*
126 dti_disconnect_ind);
127 LOCAL void pei_sig_callback(U8 instance,
128 U8 interfac,
129 U8 channel,
130 U8 reason,
131 T_DTI2_DATA_IND *dti_data2_ind);
132 #ifdef _SIMULATION_
133 LOCAL void pei_dti_dti_data_test_req (T_DTI2_DATA_TEST_REQ* dti_data_test_req);
134 LOCAL void pei_dti_dti_ready_ind (T_DTI2_READY_IND* dti_ready_ind);
135 LOCAL void pei_dti_dti_data_ind (T_DTI2_DATA_IND* dti_data_ind);
136 #endif /* _SIMULATION_ */
137
138 /*==== TYPES ================================================================*/
139
140 /*
141 * global table which maps a timer index to an UART instancen and timer number
142 */
143 typedef struct /* T_UART_TIMER_TABLE */
144 {
145 T_UART_DATA* uart_data; /* pointer to UART data of the instance */
146 UBYTE timer_number; /* number of timer within the instance */
147 } T_UART_TIMER_TABLE;
148
149 /*==== GLOBAL VARS ==========================================================*/
150
151 /*
152 * global table which maps a timer index to an UART instancen and timer number
153 */
154 T_UART_TIMER_TABLE uart_timer_table[ UART_TIMER_MAX ];
155
156 #ifdef DTILIB
157 DTI_HANDLE uart_hDTI = D_NO_DATA_BASE;
158 #endif /* DTILIB */
159 #ifdef UART_DTI_CONFIG
160 ULONG drv_link_id = -1;
161 #endif /* UART_DTI_CONFIG */
162 /*==== LOCAL VARS ===========================================================*/
163
164 static BOOL first_access = TRUE;
165 static T_MONITOR uart_mon;
166
167 /*
168 * Jumptables to primitive handler functions. One table per SAP.
169 *
170 * Use MAK_FUNC_0 for primitives which contains no SDU.
171 * Use MAK_FUNC_S for primitives which contains a SDU.
172 */
173
174 /*
175 * Function is needed for developing. This declaration can be removed
176 * as soon as this function is no more called (i.e. all primitives are
177 * handled).
178 */
179 LOCAL void primitive_not_supported (void *data);
180
181 /*qqq hier reinkommende, mit SAP vergleichen, S: mit sdu*/
182 static const T_FUNC uart_table[] =
183 {
184 MAK_FUNC_0(ker_uart_parameters_req, UART_PARAMETERS_REQ), /* 0x7400 */
185 MAK_FUNC_0(ker_uart_dti_req, UART_DTI_REQ), /* 0x7401 */
186 MAK_FUNC_0(ker_uart_disable_req, UART_DISABLE_REQ), /* 0x7402 */
187 MAK_FUNC_0(ker_uart_ring_req, UART_RING_REQ), /* 0x7403 */
188 MAK_FUNC_0(ker_uart_dcd_req, UART_DCD_REQ), /* 0x7404 */
189 MAK_FUNC_0(ker_uart_escape_req, UART_ESCAPE_REQ), /* 0x7405 */
190 MAK_FUNC_0(ker_uart_mux_start_req, UART_MUX_START_REQ), /* 0x7406 */
191 MAK_FUNC_0(ker_uart_mux_dlc_establish_res,
192 UART_MUX_DLC_ESTABLISH_RES), /* 0x7408 */
193 MAK_FUNC_0(ker_uart_mux_dlc_release_req,UART_MUX_DLC_RELEASE_REQ),/* 0x7409 */
194 MAK_FUNC_0(ker_uart_mux_sleep_req, UART_MUX_SLEEP_REQ), /* 0x740a */
195 MAK_FUNC_0(ker_uart_mux_wakeup_req, UART_MUX_WAKEUP_REQ), /* 0x740b */
196 MAK_FUNC_0(ker_uart_mux_close_req, UART_MUX_CLOSE_REQ), /* 0x740c */
197 /*
198 UART_DRIVER_SENT_IND 0x740d
199 UART_DRIVER_RECEIVED_IND 0x740e
200 UART_DRIVER_FLUSHED_IND 0x740f
201 */
202 };
203
204 /*
205 * Jumptable for the DTI service access point for uplink data transmission.
206 * Contains the processing-function addresses and opcodes of
207 * request and response primitives. Use of DTILIB can be selected.
208 *
209 */
210 static const T_FUNC dti_dti_ul_table[] = {
211 MAK_FUNC_0( pei_dti_dti_connect_req , DTI2_CONNECT_REQ ),
212 MAK_FUNC_0( pei_dti_dti_connect_res , DTI2_CONNECT_RES ),
213 MAK_FUNC_0( pei_dti_dti_disconnect_req, DTI2_DISCONNECT_REQ),
214 MAK_FUNC_0( pei_dti_dti_getdata_req , DTI2_GETDATA_REQ ),
215 MAK_FUNC_0( pei_dti_dti_data_req , DTI2_DATA_REQ ),
216 #if defined (_SIMULATION_)
217 MAK_FUNC_S( pei_dti_dti_data_test_req , DTI2_DATA_TEST_REQ )
218 #else /* _SIMULATION_ */
219 MAK_FUNC_S( primitive_not_supported , DTI2_DATA_TEST_REQ )
220 #endif /* _SIMULATION_ */
221 };
222 #if defined (DTILIB) && defined (_SIMULATION_)
223 static const T_FUNC dti_dti_dl_table[] = {
224 MAK_FUNC_0( pei_dti_dti_connect_ind , DTI2_CONNECT_IND ),
225 MAK_FUNC_0( pei_dti_dti_connect_cnf , DTI2_CONNECT_CNF ),
226 MAK_FUNC_0( pei_dti_dti_disconnect_ind , DTI2_DISCONNECT_IND),
227 MAK_FUNC_0( tx_dti_ready_ind , DTI2_READY_IND ),
228 MAK_FUNC_0( primitive_not_supported , DTI2_DATA_IND ),
229 MAK_FUNC_S( rx_dti_data_test_ind , DTI2_DATA_TEST_IND ),
230 MAK_FUNC_0( pei_dti_dti_ready_ind , DTI2_READY_IND ),
231 MAK_FUNC_0( pei_dti_dti_data_ind , DTI2_DATA_IND ),
232 MAK_FUNC_S( primitive_not_supported , DTI2_DATA_TEST_IND )
233 };
234 #endif /*defined (DTILIB) && defined (_SIMULATION_)*/
235
236 /*==== DIAGNOSTICS ==========================================================*/
237 #ifdef _DEBUG
238 #endif /* _DEBUG */
239
240 /*==== END DIAGNOSTICS ======================================================*/
241
242 /*==== PRIVATE FUNCTIONS ====================================================*/
243
244 /*
245 +------------------------------------------------------------------------------
246 | Function : primitive_not_supported
247 +------------------------------------------------------------------------------
248 | Description : This function handles unsupported primitives.
249 |
250 | Parameters : -
251 |
252 | Return : -
253 |
254 +------------------------------------------------------------------------------
255 */
256 LOCAL void primitive_not_supported (void *data)
257 {
258 TRACE_FUNCTION ("primitive_not_supported");
259
260 PFREE (data);
261 }
262
263
264 /*==== PUBLIC FUNCTIONS =====================================================*/
265
266 /* qqq hier malen
267 +------------------------------------------------------------------------------
268 | Function : pei_primitive
269 +------------------------------------------------------------------------------
270 | Description : This function is called by the frame when a primitive
271 | is received and needs to be processed.
272 |
273 | | |
274 | ACI DTI UPLINK
275 | | |
276 | +--------v--------v--------+
277 | | |
278 | | UART |
279 | | |
280 | +--------------------------+
281 |
282 |
283 | Parameters : prim - Pointer to the received primitive
284 |
285 | Return : PEI_OK - function succeeded
286 | PEI_ERROR - function failed
287 |
288 +------------------------------------------------------------------------------
289 */
290
291 /*qqq hier kucken*/
292 LOCAL SHORT pei_primitive (void * primptr)
293 {
294 TRACE_FUNCTION ("pei_primitive");
295
296 if (primptr NEQ NULL)
297 {
298 T_PRIM* prim = (T_PRIM*)primptr;
299 USHORT opc = (USHORT)prim->custom.opc;
300 USHORT n;
301 const T_FUNC *table;
302
303 /*
304 * This must be called for Partition Pool supervision. Will be replaced
305 * by another macro some time.
306 */
307 VSI_PPM_REC (&prim->custom, __FILE__, __LINE__);
308 PTRACE_IN (opc);
309
310 switch (opc & OPC_MASK)
311 {
312 case UART_DL:
313 table = uart_table;
314 n = TAB_SIZE (uart_table);
315 break;
316 case DTI2_UL:
317 #ifdef DTILIB
318 table = dti_dti_ul_table;
319 n = TAB_SIZE (dti_dti_ul_table);
320 #ifdef DTI2
321 /*
322 * to be able to distinguish DTI1/DTI2 opcodes,
323 * the ones for DTI2 start at 0x50
324 */
325 opc -= 0x50;
326 #endif /* DTI2*/
327 #else /* DTILIB */
328 table = dti_ul_table;
329 n = TAB_SIZE (dti_ul_table);
330 #endif /* DTILIB */
331 break;
332 #ifdef _SIMULATION_
333 case DTI2_DL:
334 #ifdef DTILIB
335 table = dti_dti_dl_table;
336 n = TAB_SIZE (dti_dti_dl_table);
337 #ifdef DTI2
338 /*
339 * to be able to distinguish DTI1/DTI2 opcodes,
340 * the ones for DTI2 start at 0x50
341 */
342 opc -= 0x50;
343 #endif /* DTI2*/
344 #else /* DTILIB */
345 table = dti_dl_table;
346 n = TAB_SIZE (dti_dl_table);
347 #endif /* DTILIB */
348 break;
349 #endif /* _SIMULATION_ */
350 default:
351 table = NULL;
352 n = 0;
353 break;
354 }
355
356 if (table != NULL)
357 {
358 if ((opc & PRM_MASK) < n)
359 {
360 table += opc & PRM_MASK;
361 #ifdef PALLOC_TRANSITION
362 P_SDU(prim) = table->soff ? (T_sdu*) (((char*)&prim->data)
363 + table->soff) : 0;
364 #ifndef NO_COPY_ROUTING
365 P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
366 #endif /* NO_COPY_ROUTING */
367 #endif /* PALLOC_TRANSITION */
368 JUMP (table->func) (P2D(prim));
369 }
370 else
371 {
372 primitive_not_supported (P2D(prim));
373 }
374 return PEI_OK;
375 }
376
377 /*
378 * primitive is not a GSM primitive - forward it to the environment
379 */
380 if (opc & SYS_MASK)
381 {
382 if(vsi_c_primitive (VSI_CALLER prim) NEQ VSI_OK)
383 {
384 TRACE_ERROR_P1("VSI entity: Can't forward a primitive, uart_pei.c(%d)",
385 __LINE__);
386 }
387 }
388 else
389 {
390 PFREE (P2D(prim));
391 return PEI_ERROR;
392 }
393 }
394 return PEI_OK;
395 }
396
397
398
399 #ifdef FF_MULTI_PORT
400 /*
401 +------------------------------------------------------------------------------
402 | Function : pei_uart_driver_signal
403 +------------------------------------------------------------------------------
404 | Description : The function pei_uart_driver_signal() is the callback function
405 | of the UART driver to indicate events of the driver. This
406 | function is called in interrupt context. It converts the given
407 | opcode to a signal.
408 |
409 | Parameters : usartNo - affected UART port
410 | opcode - opcode of the event
411 |
412 +------------------------------------------------------------------------------
413 */
414 GLOBAL void pei_uart_driver_signal (T_DRV_SIGNAL *SigPtr)
415 {
416 T_UART_DATA* uart_device;
417
418 TRACE_FUNCTION( "pei_uart_driver_signal" );
419
420 /*
421 * set UART instance
422 */
423 uart_device = &uart_data_base[SigPtr->DrvHandle];
424 /*
425 * activate signal
426 */
427 switch (SigPtr->SignalType)
428 {
429 case DRV_SIGTYPE_READ:
430 PSIGNAL(hCommUART, UART_DRIVER_RECEIVED_IND, uart_device);
431 break;
432
433 case DRV_SIGTYPE_WRITE:
434 PSIGNAL(hCommUART, UART_DRIVER_SENT_IND, uart_device);
435 break;
436
437 case DRV_SIGTYPE_FLUSH:
438 PSIGNAL(hCommUART, UART_DRIVER_FLUSHED_IND, uart_device);
439 break;
440
441 default:
442 TRACE_ERROR( "pei_uart_driver_signal: unknown signal" );
443 break;
444 }
445 } /* pei_uart_driver_signal() */
446 #endif /* FF_MULTI_PORT */
447
448
449
450 /*
451 +------------------------------------------------------------------------------
452 | Function : pei_init
453 +------------------------------------------------------------------------------
454 | Description : This function is called by the frame. It is used to
455 | initialise the entitiy.
456 |
457 | Parameters : handle - task handle
458 |
459 | Return : PEI_OK - entity initialised
460 | PEI_ERROR - entity not (yet) initialised
461 |
462 +------------------------------------------------------------------------------
463 */
464
465 /*qqq hier Kommunikationskanaele eintragen*/
466 LOCAL SHORT pei_init (T_HANDLE handle)
467 {
468 USHORT i;
469 UBYTE instance;
470
471 /*
472 * Initialize task handle
473 */
474 UART_handle = handle;
475
476 TRACE_FUNCTION ("pei_init");
477 /*
478 * Open communication channel
479 */
480 if (hCommMMI < VSI_OK)
481 {
482 if ((hCommMMI = vsi_c_open (VSI_CALLER ACI_NAME)) < VSI_OK)
483 return PEI_ERROR;
484 }
485
486 if (hCommUART < VSI_OK)
487 {
488 if ((hCommUART = vsi_c_open (VSI_CALLER UART_NAME)) < VSI_OK)
489 return PEI_ERROR;
490 }
491
492 #ifdef DTILIB
493 /*
494 * initialize dtilib for this entity
495 */
496 uart_hDTI = dti_init (UART_INSTANCES * UART_MAX_NUMBER_OF_CHANNELS,
497 handle,
498 DTI_DEFAULT_OPTIONS,
499 pei_sig_callback);
500 if(!uart_hDTI)
501 return PEI_ERROR;
502
503 #else /* DTILIB */
504 /*
505 * Initialize table with channel ids
506 */
507 for( i = 0; i < (UART_INSTANCES * UART_MAX_NUMBER_OF_CHANNELS); i++)
508 {
509 uart_cid_table[i].c_id = 0;
510 uart_cid_table[i].uart_data = NULL;
511 uart_cid_table[i].dtx = NULL;
512 uart_cid_table[i].drx = NULL;
513 }
514 #endif /* DTILIB */
515
516 /*
517 * send parameters primitive
518 */
519 {
520 PALLOC (uart_parameters_ind, UART_PARAMETERS_IND);
521 uart_parameters_ind->uart_instances = UART_INSTANCES;
522 PSEND (hCommMMI, uart_parameters_ind);
523 }
524
525 /*
526 * Initialize timer table
527 */
528 for( i = 0; i < UART_TIMER_MAX; i++)
529 {
530 uart_timer_table[i].uart_data = &(uart_data_base
531 [(UBYTE)(i /
532 UART_TIMER_PER_INSTANCE)]);
533 uart_timer_table[i].timer_number = (UBYTE)(i % UART_TIMER_PER_INSTANCE);
534 }
535
536 for( instance = 0; instance < UART_INSTANCES; instance++ )
537 {
538 /*
539 * Initialize global pointer uart_data. This is required to access all
540 * entity data.
541 */
542 uart_data = &(uart_data_base[instance]);
543
544 /*
545 * Initialize DLC table
546 */
547 for( i = 0; i <= UART_MAX_NUMBER_OF_CHANNELS; i++)
548 {
549 uart_data->dlc_table[i].dlci = UART_DLCI_INVALID;
550 uart_data->dlc_table[i].priority = 0;
551 #ifdef DTILIB
552 uart_data->dlc_table[i].dti_state = DTI_CLOSED;
553 #else /* DTILIB */
554 uart_data->dlc_table[i].hCommUPLINK = VSI_ERROR;
555 #endif /* DTILIB */
556 uart_data->dlc_table[i].connection_state = UART_CONNECTION_DEAD;
557 if(i EQ UART_CONTROL_INSTANCE)
558 {
559 uart_data->dlc_table[i].drx = &uart_data->drx_base[0];
560 uart_data->dlc_table[i].dtx = &uart_data->dtx_base[0];
561 }
562 else
563 {
564 uart_data->dlc_table[i].drx = &uart_data->drx_base[i];
565 uart_data->dlc_table[i].dtx = &uart_data->dtx_base[i];
566 }
567
568 uart_data->dlc_table[i].transmit_data = NULL;
569 uart_data->dlc_table[i].transmit_pos = 0;
570 uart_data->dlc_table[i].p_counter = 0;
571
572 uart_data->dlc_table[i].receive_data = NULL;
573 uart_data->dlc_table[i].receive_pos = 0;
574 uart_data->dlc_table[i].receive_size = 0;
575 uart_data->dlc_table[i].receive_process = UART_RX_PROCESS_STOP;
576
577 uart_data->dlc_table[i].last_command = NULL;
578 uart_data->dlc_table[i].next_command = NULL;
579 uart_data->dlc_table[i].retransmissions = 0;
580 uart_data->dlc_table[i].lines = 0;
581 uart_data->dlc_table[i].service = 0;
582 uart_data->dlc_table[i].codec = 0;
583 uart_data->dlc_table[i].received_prim = 0;
584 uart_data->dlc_table[i].flushed = TRUE;
585 }
586
587 /*
588 * Initialize DLCI instance table
589 */
590 for( i = 0; i < 64; i++ )
591 {
592 uart_data->dlc_instance[i] = UART_EMPTY_INSTANCE;
593 }
594
595 /*
596 * timer values for this instance
597 */
598 uart_data->timer_t1_index = (USHORT)(instance * UART_TIMER_PER_INSTANCE)
599 + UART_RT_INDEX_T1;
600 uart_data->timer_t2_index = (USHORT)(instance * UART_TIMER_PER_INSTANCE)
601 + UART_RT_INDEX_T2;
602 uart_data->timer_t3_index = (USHORT)(instance * UART_TIMER_PER_INSTANCE)
603 + UART_RT_INDEX_T3;
604 uart_data->timer_tesd_index = (USHORT)(instance * UART_TIMER_PER_INSTANCE)
605 + UART_RT_INDEX_TESD;
606 /*
607 * set device for this instance
608 */
609 uart_data->device = instance;
610 uart_data->fcstab = uart_fcstable_base;
611
612 /*
613 * set device specific values
614 */
615 uart_data->xon = UART_IO_XON_DEFAULT;
616 uart_data->xoff = UART_IO_XOFF_DEFAULT;
617 uart_data->n1 = UART_N1_READY_MODE;
618 /*
619 * set initial DTX/DRX services
620 */
621 uart_data->dtx = &(uart_data->dtx_base[0]);
622 uart_data->drx = &(uart_data->drx_base[0]);
623 /*
624 * escape sequence detection
625 */
626 uart_data->act_ec = 0x2b; /* Escape Character '+' */
627 uart_data->act_gp = 1000; /* Guard Period */
628 }
629
630 /*
631 * qqq Initialize entity data (call init function of every service)
632 * the order of function calls is important
633 */
634 for( i = 0; i < UART_INSTANCES; i++ )
635 {
636 uart_data = &(uart_data_base[i]);
637 rt_init();
638 ker_init();
639 rx_init();
640 tx_init();
641 drx_init();
642 dtx_init();
643 }
644 uart_data = &(uart_data_base[0]);
645
646 return (PEI_OK);
647 }
648
649
650
651 /*
652 +------------------------------------------------------------------------------
653 | Function : pei_timeout
654 +------------------------------------------------------------------------------
655 | Description : This function is called by the frame when a timer
656 | has expired.
657 |
658 | Parameters : index - timer index
659 |
660 | Return : PEI_OK - timeout processed
661 | PEI_ERROR - timeout not processed
662 |
663 +------------------------------------------------------------------------------
664 */
665 LOCAL SHORT pei_timeout (USHORT index)
666 {
667 TRACE_FUNCTION ("pei_timeout");
668
669 /*
670 * set UART instance
671 */
672 uart_data = uart_timer_table[index].uart_data;
673
674 /*
675 * Process timeout
676 */
677 switch (uart_timer_table[index].timer_number)
678 {
679 case UART_RT_INDEX_T1:
680 /*
681 * timer T1 expired.
682 */
683 rt_t1_expired();
684 break;
685 case UART_RT_INDEX_T2:
686 /*
687 * timer T2 expired.
688 */
689 rt_t2_expired();
690 break;
691 case UART_RT_INDEX_T3:
692 /*
693 * timer T3 expired.
694 */
695 rt_t3_expired();
696 break;
697 case UART_RT_INDEX_TESD:
698 /*
699 * Escape Sequence Detection timer expired.
700 */
701 rt_tesd_expired();
702 break;
703 default:
704 TRACE_ERROR("pei_timeout: Unknown Timeout");
705 break;
706 }
707
708 return PEI_OK;
709 }
710
711
712
713 /*
714 +------------------------------------------------------------------------------
715 | Function : pei_signal
716 +------------------------------------------------------------------------------
717 | Description : This function is called by the frame when a signal
718 | has been received.
719 |
720 | Parameters : opc - signal operation code
721 | *data - pointer to primitive
722 |
723 | Return : PEI_OK - signal processed
724 | PEI_ERROR - signal not processed
725 |
726 +------------------------------------------------------------------------------
727 */
728 LOCAL SHORT pei_signal (ULONG opc, void *data)
729 {
730 TRACE_FUNCTION ("pei_signal");
731
732 #ifdef FF_MULTI_PORT
733 /*
734 * Process signal
735 */
736 switch (opc)
737 {
738 case UART_DRIVER_SENT_IND:
739 tx_uart_driver_sent_ind(data);
740 break;
741
742 case UART_DRIVER_RECEIVED_IND:
743 rx_uart_driver_received_ind(data);
744 break;
745
746 case UART_DRIVER_FLUSHED_IND:
747 tx_uart_driver_flushed_ind(data);
748 break;
749
750 default:
751 TRACE_ERROR("Unknown Signal OPC");
752 return PEI_ERROR;
753 }
754 #else /* FF_MULTI_PORT */
755 /*
756 * Process signal
757 */
758 switch (opc)
759 {
760 case UART_DRIVER_SENT_IND:
761 tx_uart_driver_sent_ind(data);
762 break;
763
764 case UART_DRIVER_RECEIVED_IND:
765 rx_uart_driver_received_ind(data);
766 break;
767
768 default:
769 TRACE_ERROR("Unknown Signal OPC");
770 break;
771 }
772 #endif /* FF_MULTI_PORT */
773
774 return PEI_OK;
775 }
776
777
778
779 /*
780 +------------------------------------------------------------------------------
781 | Function : pei_exit
782 +------------------------------------------------------------------------------
783 | Description : This function is called by the frame when the entity
784 | is terminated. All open resources are freed.
785 |
786 | Parameters : -
787 |
788 | Return : PEI_OK - exit sucessful
789 | PEI_ERROR - exit not sueccessful
790 |
791 +------------------------------------------------------------------------------
792 */
793 LOCAL SHORT pei_exit (void)
794 {
795 TRACE_FUNCTION ("pei_exit");
796
797 #ifdef DTILIB
798 #ifdef _SIMULATION_
799
800 /*
801 * close test channel
802 */
803 #endif /* _SIMULATION_ */
804
805 /*
806 * Shut down dtilib communication
807 */
808 dti_deinit(uart_hDTI);
809 #endif /* DTILIB */
810 /*
811 * Close communication channel to MMI
812 */
813 if(vsi_c_close (VSI_CALLER hCommMMI) NEQ VSI_OK)
814 {
815 TRACE_ERROR_P1("VSI entity: CloseComChannel to MMI failed, uart_pei.c(%d)",
816 __LINE__);
817 return PEI_ERROR;
818 }
819 hCommMMI = VSI_ERROR;
820
821
822 /*
823 * Free all resources
824 */
825 drx_free_resources();
826 dtx_exit();
827
828 return PEI_OK;
829 }
830
831
832
833 /*
834 +------------------------------------------------------------------------------
835 | Function : pei_run
836 +------------------------------------------------------------------------------
837 | Description : This function is called by the frame when entering
838 | the main loop. This function is only required in the
839 | active variant.
840 |
841 | This function is not used.
842 |
843 | Parameters : handle - Communication handle
844 |
845 | Return : PEI_OK - sucessful
846 | PEI_ERROR - not successful
847 |
848 +------------------------------------------------------------------------------
849 */
850 LOCAL SHORT pei_run (T_HANDLE TaskHandle, T_HANDLE ComHandle )
851 {
852 return PEI_OK;
853 } /* pei_run() */
854
855
856
857 /*
858 +------------------------------------------------------------------------------
859 | Function : pei_monitor
860 +------------------------------------------------------------------------------
861 | Description : This function is called by the frame in case sudden
862 | entity specific data is requested
863 | (e.g. entity Version).
864 |
865 | Parameters : out_monitor - return the address of the data to be
866 | monitoredCommunication handle
867 |
868 | Return : PEI_OK - sucessful
869 | (address in out_monitor is valid)
870 | PEI_ERROR - not successful
871 |
872 +------------------------------------------------------------------------------
873 */
874 LOCAL SHORT pei_monitor (void ** out_monitor)
875 {
876 TRACE_FUNCTION ("pei_monitor");
877
878 /*
879 * Version = "0.S" (S = Step).
880 */
881 uart_mon.version = VERSION_UART;
882 *out_monitor = &uart_mon;
883
884 return PEI_OK;
885 }
886
887
888 /*
889 +------------------------------------------------------------------------------
890 | Function : pei_config
891 +------------------------------------------------------------------------------
892 | Description : This function is called by the frame when a primitive
893 | is received indicating dynamic configuration.
894 |
895 | This function is not used in this entity.
896 |
897 | Parameters : handle - Communication handle
898 |
899 | Return : PEI_OK - sucessful
900 | PEI_ERROR - not successful
901 |
902 +------------------------------------------------------------------------------
903 */
904 LOCAL SHORT pei_config (T_PEI_CONFIG inString)
905 {
906 TRACE_FUNCTION ("pei_config");
907 TRACE_FUNCTION (inString);
908
909 return PEI_OK;
910 }
911
912 /*
913 +------------------------------------------------------------------------------
914 | Function : pei_create
915 +------------------------------------------------------------------------------
916 | Description : This function is called by the frame when the process
917 | is created.
918 |
919 | Parameters : out_name - Pointer to the buffer in which to
920 | locate the name of this entity
921 |
922 | Return : PEI_OK - entity created successfuly
923 | PEI_ERROR - entity could not be created
924 |
925 +------------------------------------------------------------------------------
926 */
927 GLOBAL SHORT pei_create (T_PEI_INFO **info)
928 {
929 static T_PEI_INFO pei_info =
930 {
931 "UART", /* name */
932 { /* pei-table */
933 pei_init,
934 #ifdef _SIMULATION_
935 pei_exit,
936 #else
937 NULL,
938 #endif
939 pei_primitive,
940 pei_timeout,
941 pei_signal,
942 pei_run,
943 pei_config,
944 pei_monitor
945 },
946 1024, /* stack size */
947 10, /* queue entries */
948 200, /* priority (1->low, 255->high) */
949 UART_TIMER_MAX, /* number of timers */
950 0x03|PRIM_NO_SUSPEND /* flags: bit 0 active(0) body/passive(1) */
951 }; /* bit 1 com by copy(0)/reference(1) */
952
953
954 TRACE_FUNCTION ("pei_create");
955
956 /*
957 * Close Resources if open
958 */
959 #ifdef _SIMULATION_
960 if (first_access)
961 {
962 first_access = FALSE;
963 }
964 else
965 {
966 if(pei_exit() NEQ PEI_OK)
967 {
968 TRACE_ERROR_P1("UART PEI: Can't free open recources, uart_pei.c(%d)",
969 __LINE__);
970 }
971 }
972 #endif
973
974 /*
975 * Export startup configuration data
976 */
977 *info = &pei_info;
978
979 return PEI_OK;
980 }
981
982
983 #ifndef DTILIB
984 /*
985 +------------------------------------------------------------------------------
986 | Function : pei_select_instances
987 +------------------------------------------------------------------------------
988 | Description : This function selects the correct UART and DTX/DRX services
989 | for an incoming DTI interface primitive. This is done by a
990 | lookup in the UART channel id table in order to determine
991 | the correct UART, DTX and DRX data structures.
992 |
993 | Parameters : c_id - channel id of incoming primitive
994 |
995 | Return : TRUE - successful
996 | FALSE - not successful
997 |
998 +------------------------------------------------------------------------------
999 */
1000 GLOBAL UBYTE pei_select_instances( UBYTE incoming_c_id )
1001 {
1002 USHORT i;
1003 UBYTE found = FALSE;
1004
1005 TRACE_FUNCTION ("pei_select_instances");
1006
1007 /*
1008 * locate the channel id in the global cid table
1009 */
1010 for( i = 0; i < UART_INSTANCES * UART_MAX_NUMBER_OF_CHANNELS; i++ )
1011 if( uart_cid_table[i].c_id EQ incoming_c_id )
1012 if( ( uart_cid_table[i].dtx NEQ NULL ) &&
1013 ( uart_cid_table[i].drx NEQ NULL ) &&
1014 ( uart_cid_table[i].uart_data NEQ NULL ) )
1015 {
1016 /*
1017 * channel id found. select service structures
1018 */
1019 uart_data = uart_cid_table[i].uart_data;
1020 uart_data->dtx = uart_cid_table[i].dtx;
1021 uart_data->drx = uart_cid_table[i].drx;
1022
1023 found = TRUE;
1024 break;
1025 }
1026
1027 if( found EQ FALSE )
1028 {
1029 TRACE_EVENT(" pei_select_instances: unknown c_id ");
1030 }
1031 #ifdef _SIMULATION_
1032 {
1033 char buf[64];
1034 sprintf(buf,"found incoming_c_id: 0x%02X in uart_cid_table[%d]",incoming_c_id, i);
1035 TRACE_EVENT(buf);
1036 }
1037 #endif
1038 return( found );
1039 } /* pei_select_instances */
1040 #endif /* DTILIB */
1041
1042
1043 /*
1044 * maps for DTILIB functions
1045 */
1046
1047 #ifdef DTILIB
1048 /*
1049 +------------------------------------------------------------------------------
1050 | Function : pei_dti_dti_connect_req
1051 +------------------------------------------------------------------------------
1052 | PURPOSE : Call the process function dti_dti_connect_req
1053 +------------------------------------------------------------------------------
1054 */
1055 LOCAL void pei_dti_dti_connect_req (T_DTI2_CONNECT_REQ* dti_connect_req)
1056 {
1057 dti_dti_connect_req (uart_hDTI, dti_connect_req);
1058 } /* pei_dti_dti_connect_req() */
1059
1060
1061
1062 /*
1063 +------------------------------------------------------------------------------
1064 | Function : pei_dti_dti_connect_res
1065 +------------------------------------------------------------------------------
1066 | PURPOSE : Call the process function dti_dti_connect_res
1067 +------------------------------------------------------------------------------
1068 */
1069 LOCAL void pei_dti_dti_connect_res (T_DTI2_CONNECT_RES* dti_connect_res)
1070 {
1071 dti_dti_connect_res(uart_hDTI, dti_connect_res);
1072 } /* pei_dti_dti_connect_res() */
1073
1074
1075
1076 /*
1077 +------------------------------------------------------------------------------
1078 | Function : pei_dti_dti_disconnect_req
1079 +------------------------------------------------------------------------------
1080 | PURPOSE : Call the process function dti_dti_disconnect_req
1081 +------------------------------------------------------------------------------
1082 */
1083 LOCAL void pei_dti_dti_disconnect_req (T_DTI2_DISCONNECT_REQ*
1084 dti_disconnect_req)
1085 {
1086 dti_dti_disconnect_req (uart_hDTI, dti_disconnect_req);
1087 } /* pei_dti_dti_disconnect_req() */
1088
1089
1090 #ifdef _SIMULATION_
1091 /*
1092 +------------------------------------------------------------------------------
1093 | Function : pei_dti_dti_connect_ind
1094 +------------------------------------------------------------------------------
1095 | PURPOSE : Call the process function dti_dti_connect_ind
1096 +------------------------------------------------------------------------------
1097 */
1098 LOCAL void pei_dti_dti_connect_ind (T_DTI2_CONNECT_IND* dti_connect_ind)
1099 {
1100 dti_dti_connect_ind (uart_hDTI, dti_connect_ind);
1101 } /* pei_dti_dti_connect_ind() */
1102
1103
1104
1105 /*
1106 +------------------------------------------------------------------------------
1107 | Function : pei_dti_dti_connect_cnf
1108 +------------------------------------------------------------------------------
1109 | PURPOSE : Call the process function dti_dti_connect_cnf
1110 +------------------------------------------------------------------------------
1111 */
1112 LOCAL void pei_dti_dti_connect_cnf (T_DTI2_CONNECT_CNF* dti_connect_cnf)
1113 {
1114 dti_dti_connect_cnf(uart_hDTI, dti_connect_cnf);
1115 } /* pei_dti_dti_connect_cnf() */
1116
1117
1118
1119 /*
1120 +------------------------------------------------------------------------------
1121 | Function : pei_dti_dti_disconnect_ind
1122 +------------------------------------------------------------------------------
1123 | PURPOSE : Call the process function dti_dti_disconnect_ind
1124 +------------------------------------------------------------------------------
1125 */
1126 LOCAL void pei_dti_dti_disconnect_ind (T_DTI2_DISCONNECT_IND*
1127 dti_disconnect_ind)
1128 {
1129 dti_dti_disconnect_ind (uart_hDTI, dti_disconnect_ind);
1130 } /* pei_dti_dti_disconnect_ind() */
1131
1132 #endif /*_SIMULATION_*/
1133
1134 /*
1135 +------------------------------------------------------------------------------
1136 | Function : pei_dti_dti_data_req
1137 +------------------------------------------------------------------------------
1138 | PURPOSE : Call the process function dti_dti_data_req
1139 +------------------------------------------------------------------------------
1140 */
1141 LOCAL void pei_dti_dti_data_req (T_DTI2_DATA_REQ* dti_data_req)
1142 {
1143 dti_dti_data_req (uart_hDTI, dti_data_req);
1144 } /* pei_dti_dti_data_req() */
1145
1146
1147
1148 /*
1149 +------------------------------------------------------------------------------
1150 | Function : pei_dti_dti_getdata_req
1151 +------------------------------------------------------------------------------
1152 | PURPOSE : Call the process function dti_dti_getdata_req
1153 +------------------------------------------------------------------------------
1154 */
1155 LOCAL void pei_dti_dti_getdata_req (T_DTI2_GETDATA_REQ* dti_getdata_req)
1156 {
1157 dti_dti_getdata_req (uart_hDTI, dti_getdata_req);
1158 } /* pei_dti_dti_getdata_req() */
1159
1160
1161 /*==== Start functions only use with Windows ===============================*/
1162
1163 #ifdef _SIMULATION_
1164
1165 /*
1166 +------------------------------------------------------------------------------
1167 | Function : pei_dti_dti_data_test_req
1168 +------------------------------------------------------------------------------
1169 | PURPOSE : Call the process function dti_dti_data_test_req
1170 +------------------------------------------------------------------------------
1171 */
1172 LOCAL void pei_dti_dti_data_test_req (T_DTI2_DATA_TEST_REQ* dti_data_test_req)
1173 {
1174 dti_dti_data_test_req (uart_hDTI, dti_data_test_req);
1175 } /* pei_dti_dti_data_test_req() */
1176
1177 /*==== End functions only used with testing from WIN32 =====================*/
1178
1179
1180
1181 /*
1182 +------------------------------------------------------------------------------
1183 | Function : pei_dti_dti_ready_ind
1184 +------------------------------------------------------------------------------
1185 | PURPOSE : Call the process function dti_dti_ready_ind
1186 +------------------------------------------------------------------------------
1187 */
1188 LOCAL void pei_dti_dti_ready_ind (T_DTI2_READY_IND* dti_ready_ind)
1189 {
1190 dti_dti_ready_ind (uart_hDTI, dti_ready_ind);
1191 } /* pei_dti_dti_ready_ind() */
1192
1193
1194
1195 /*
1196 +------------------------------------------------------------------------------
1197 | Function : pei_dti_dti_data_ind
1198 +------------------------------------------------------------------------------
1199 | PURPOSE : Call the process function dti_dti_data_ind
1200 +------------------------------------------------------------------------------
1201 */
1202 LOCAL void pei_dti_dti_data_ind (T_DTI2_DATA_IND* dti_data_ind)
1203 {
1204 dti_dti_data_ind (uart_hDTI, dti_data_ind);
1205 } /* pei_dti_dti_data_ind() */
1206 #endif /* _SIMULATION_ */
1207
1208 /*
1209 +------------------------------------------------------------------------------
1210 | Function : pei_sig_callback
1211 +------------------------------------------------------------------------------
1212 | PURPOSE : Callback function for DTILIB
1213 +------------------------------------------------------------------------------
1214 */
1215
1216 LOCAL void pei_sig_callback(U8 instance,
1217 U8 interfac,
1218 U8 channel,
1219 U8 reason,
1220 T_DTI2_DATA_IND *dti_data2_ind)
1221 {
1222 T_DLC *dlc;
1223
1224 TRACE_FUNCTION("pei_sig_callback");
1225
1226 if(interfac NEQ UART_DTI_UP_INTERFACE)
1227 {
1228 TRACE_ERROR("[PEI_SIG_CALLBACK] interface not valid!");
1229 return; /* error, not found */
1230 }
1231
1232 uart_data = &uart_data_base[instance];
1233
1234 if (uart_hDTI NEQ D_NO_DATA_BASE)
1235 {
1236 switch (reason)
1237 {
1238 case DTI_REASON_CONNECTION_OPENED:
1239 dlc = &uart_data->dlc_table[channel]; /* channel is dlci */
1240 uart_data->drx = dlc->drx;
1241 uart_data->dtx = dlc->dtx;
1242
1243 sig_dti_ker_connection_opened_ind(channel);
1244 break;
1245
1246 case DTI_REASON_CONNECTION_CLOSED:
1247 dlc = &uart_data->dlc_table[channel]; /* channel is dlci */
1248 uart_data->drx = dlc->drx;
1249 uart_data->dtx = dlc->dtx;
1250
1251 sig_dti_ker_connection_closed_ind(channel);
1252 break;
1253
1254 case DTI_REASON_DATA_RECEIVED:
1255 if(!uart_data)
1256 {
1257 /*
1258 * instance not found, primitive was invalid, discard it
1259 */
1260 PFREE_DESC2( dti_data2_ind );
1261 }
1262 else
1263 {
1264 dlc = &uart_data->dlc_table[channel]; /* channel is dlci */
1265 uart_data->drx = dlc->drx;
1266 uart_data->dtx = dlc->dtx;
1267
1268 sig_dti_drx_data_received_ind(dti_data2_ind);
1269 }
1270 break;
1271
1272 case DTI_REASON_TX_BUFFER_FULL:
1273 if(!uart_data)
1274 {
1275 TRACE_ERROR("[PEI_SIG_CALLBACK] instance not valid!");
1276 return; /* error, not found */
1277 }
1278 dlc = &uart_data->dlc_table[channel]; /* channel is dlci */
1279 uart_data->drx = dlc->drx;
1280 uart_data->dtx = dlc->dtx;
1281
1282 sig_dti_dtx_tx_buffer_full_ind();
1283 break;
1284
1285 case DTI_REASON_TX_BUFFER_READY:
1286 if(!uart_data)
1287 {
1288 TRACE_ERROR("[PEI_SIG_CALLBACK] instance not valid!");
1289 return; /* error, not found */
1290 }
1291 dlc = &uart_data->dlc_table[channel]; /* channel is dlci */
1292 uart_data->drx = dlc->drx;
1293 uart_data->dtx = dlc->dtx;
1294
1295 sig_dti_dtx_tx_buffer_ready_ind();
1296 break;
1297 default:
1298 TRACE_ERROR("unknown DTILIB reason parameter");
1299 break;
1300 } /* end switch */
1301 } /* end if */
1302 else
1303 {
1304 TRACE_ERROR("Pointer to DTILIB database not existing");
1305 }
1306 } /* pei_sig_callback() */
1307
1308 /*==== End of functions only used with DTILIB =================================*/
1309
1310 #endif /* DTILIB */
1311
1312 /*==== END OF FILE ==========================================================*/