comparison src/g23m-aci/uart/uart_pei.c @ 1:fa8dc04885d8

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