comparison g23m-aci/uart/uart_dtxs.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 modul is part of the entity UART and implements all
18 | functions to handles the incoming process internal signals as
19 | described in the SDL-documentation (DTX-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef UART_DTXS_C
24 #define UART_DTXS_C
25 #endif /* !UART_DTXS_C */
26
27 #include "config.h"
28 #include "fixedconf.h"
29 #include "condat-features.h"
30
31 #define ENTITY_UART
32
33 /*==== INCLUDES =============================================================*/
34
35 #ifdef _SIMULATION_
36 #include <stdio.h>
37 #endif
38 #ifdef WIN32
39 #include "nucleus.h"
40 #endif /* WIN32 */
41 #include "typedefs.h" /* to get Condat data types */
42 #include "vsi.h" /* to get a lot of macros */
43 #include "macdef.h" /* to get a lot of macros */
44 #include "custom.h"
45 #include "gsm.h" /* to get a lot of macros */
46 #include "cnf_uart.h" /* to get cnf-definitions */
47 #include "mon_uart.h" /* to get mon-definitions */
48 #include "prim.h" /* to get the definitions of used SAP and directions */
49 #include "dti.h" /* to get dti lib */
50 #include "pei.h" /* to get PEI interface */
51 #ifdef FF_MULTI_PORT
52 #include "gsi.h" /* to get definitions of serial driver */
53 #else /* FF_MULTI_PORT */
54 #ifdef _TARGET_
55 #include "../../serial/serialswitch.h"
56 #include "../../serial/traceswitch.h"
57 #else /* _TARGET_ */
58 #include "serial_dat.h" /* to get definitions of serial driver */
59 #endif /* _TARGET_ */
60 #endif /* FF_MULTI_PORT */
61 #include "uart.h" /* to get the global entity definitions */
62
63 #include "uart_dtxf.h" /* to get DTX function definitions */
64 #include "uart_dtxp.h" /* to get DTX primitive definitions */
65 #include "uart_kers.h" /* to get KER signal definitions */
66 #include "uart_rts.h" /* to get RT signal definitions */
67 #ifdef FF_MULTI_PORT
68 #include "uart_prxs.h" /* to get signal definitions for service TX */
69 #else /* FF_MULTI_PORT */
70 #include "uart_rxs.h" /* to get TX signal definitions */
71 #endif /* FF_MULTI_PORT */
72 #include <string.h> /* JK, delete warnings: to get memmove, memcpy */
73
74 /*==== CONST ================================================================*/
75
76 /*==== LOCAL VARS ===========================================================*/
77
78 /*==== PRIVATE FUNCTIONS ====================================================*/
79
80 /*==== PUBLIC FUNCTIONS =====================================================*/
81
82
83
84 /*
85 +------------------------------------------------------------------------------
86 | Function : sig_ker_dtx_ready_mode_req
87 +------------------------------------------------------------------------------
88 | Description : Handles the internal signal SIG_KER_DTX_READY_MODE_REQ
89 |
90 | Parameters : dlc_instance - dlc instance wich belongs to this DTX instance
91 |
92 +------------------------------------------------------------------------------
93 */
94 GLOBAL void sig_ker_dtx_ready_mode_req (UBYTE dlc_instance)
95 {
96 TRACE_ISIG( "sig_ker_dtx_ready_mode_req" );
97
98 uart_data->dtx->dlc_instance = dlc_instance;
99
100 switch( GET_STATE( UART_SERVICE_DTX ) )
101 {
102 case DTX_DEAD:
103 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
104
105 /*
106 * reset line states
107 */
108 uart_data->dtx->st_flow = DTI_FLOW_ON;
109 uart_data->dtx->st_line_sa = DTI_SA_ON;
110 uart_data->dtx->st_line_sb = DTI_SB_ON;
111 uart_data->dtx->st_break_len = DTI_BREAK_OFF;
112 uart_data->dtx->detect_escape = TRUE;
113
114 uart_data->dtx->data_flow = UART_FLOW_ENABLED;
115 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
116 {
117 /*
118 * reset escape sequence detection
119 */
120 dtx_set_esd_state( UART_ESD_NULL );
121 uart_data->dtx->detect_escape = TRUE;
122 if(vsi_t_time (VSI_CALLER &(uart_data->dtx->esd_guard_time))
123 NEQ VSI_OK)
124 {
125 TRACE_ERROR_P1("VSI entity: Can't restart timer, uart_dtxs.c(%d)",
126 __LINE__);
127 }
128 uart_data->dtx->esd_pos = 0;
129 /*
130 * start reception
131 */
132 dtx_allocate_resources();
133 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance,
134 uart_data->dtx->to_send_data,
135 uart_data->dtx->write_pos,
136 uart_data->dtx->cur_desc_size );
137 }
138 break;
139
140 case DTX_READY:
141 case DTX_NOT_READY:
142 break;
143
144 default:
145 TRACE_ERROR( "SIG_KER_DTX_READY_MODE_REQ unexpected" );
146 break;
147 }
148 } /* sig_ker_dtx_ready_mode_req() */
149
150
151
152 /*
153 +------------------------------------------------------------------------------
154 | Function : sig_ker_dtx_dead_mode_req
155 +------------------------------------------------------------------------------
156 | Description : Handles the internal signal SIG_KER_DTX_DEAD_MODE_REQ
157 |
158 | Parameters : none
159 |
160 +------------------------------------------------------------------------------
161 */
162 GLOBAL void sig_ker_dtx_dead_mode_req ()
163 {
164 TRACE_ISIG( "sig_ker_dtx_dead_mode_req" );
165
166 switch( GET_STATE( UART_SERVICE_DTX ) )
167 {
168 case DTX_READY:
169 case DTX_NOT_READY:
170 SET_STATE( UART_SERVICE_DTX, DTX_DEAD );
171 /*
172 * reset hComm_DTX_UPLINK and size_multiplier
173 */
174 uart_data->dtx->dti_dtx_state = DTI_CLOSED;
175 uart_data->dtx->size_multiplier = 3;
176
177 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
178 {
179 /*
180 * free recources and stop receiving
181 */
182 sig_dtx_rx_not_ready_to_receive_req(uart_data->dtx->dlc_instance);
183 dtx_free_resources();
184 }
185 else
186 uart_data->dtx->receiving_state = UART_DTX_INVALID;
187 break;
188
189 case DTX_DEAD:
190 break;
191
192 default:
193 TRACE_ERROR( "SIG_KER_DTX_DEAD_MODE_REQ unexpected" );
194 break;
195 }
196 } /* sig_ker_dtx_dead_mode_req() */
197
198
199
200 /*
201 +------------------------------------------------------------------------------
202 | Function : sig_rx_dtx_receiving_ind
203 +------------------------------------------------------------------------------
204 | Description : Handles the internal signal SIG_RX_DTX_RECEIVING_IND
205 |
206 | Parameters : none
207 |
208 +------------------------------------------------------------------------------
209 */
210 GLOBAL void sig_rx_dtx_receiving_ind ()
211 {
212 TRACE_ISIG( "sig_rx_dtx_receiving_ind" );
213
214 uart_data->dtx->receiving_state = UART_DTX_RECEIVING;
215
216 switch( GET_STATE( UART_SERVICE_DTX ) )
217 {
218 case DTX_READY:
219 case DTX_NOT_READY:
220 break;
221
222 default:
223 TRACE_ERROR( "SIG_RX_DTX_RECEIVING_IND unexpected" );
224 break;
225 }
226 } /* sig_ker_dtx_receiving_ind() */
227
228
229
230 /*
231 +------------------------------------------------------------------------------
232 | Function : sig_rx_dtx_data_received_ind
233 +------------------------------------------------------------------------------
234 | Description : Handles the internal signal SIG_RX_DTX_DATA_RECEIVED_IND
235 |
236 | Parameters : none
237 |
238 +------------------------------------------------------------------------------
239 */
240 GLOBAL void sig_rx_dtx_data_received_ind (T_desc2* received_data,
241 USHORT write_pos)
242 {
243 T_DATA_FLOW_STATE old_data_flow;
244 T_desc2* temp_desc;
245 USHORT esd_pos;
246 T_TIME cur_time;
247
248 TRACE_ISIG( "sig_rx_dtx_data_received_ind" );
249
250 #ifdef UART_RANGE_CHECK
251 if(received_data EQ NULL)
252 {
253 TRACE_EVENT("ERROR: received_data is NULL");
254 }
255 else if((*((ULONG*)((UBYTE*)received_data - 8))) NEQ 0)
256 {
257 TRACE_EVENT_P1("ERROR: received_data=%08x is not allocated",
258 received_data);
259 }
260 if(uart_data->dtx->to_send_data NEQ received_data)
261 {
262 TRACE_EVENT_P2("ERROR: to_send_data=%08x NEQ received_data=%08x",
263 uart_data->dtx->to_send_data,
264 received_data);
265 }
266 if(uart_data->dtx->to_send_data->len > uart_data->dtx->cur_desc_size)
267 {
268 TRACE_EVENT_P2("ERROR: to_send_data->len=%d > cur_desc_size=%d",
269 uart_data->dtx->to_send_data->len,
270 uart_data->dtx->cur_desc_size);
271 }
272 if(write_pos > uart_data->dtx->cur_desc_size)
273 {
274 TRACE_EVENT_P2("ERROR: write_pos=%d > cur_desc_size=%d",
275 write_pos,
276 uart_data->dtx->cur_desc_size);
277 }
278 if(uart_data->dtx->to_send_data->len > write_pos)
279 {
280 TRACE_EVENT_P2("ERROR: to_send_data->len=%d > write_pos=%d",
281 uart_data->dtx->to_send_data->len,
282 write_pos);
283 }
284 if(uart_data->dtx->esd_pos > write_pos)
285 {
286 TRACE_EVENT_P2("ERROR: esd_pos=%d > write_pos=%d",
287 uart_data->dtx->esd_pos,
288 write_pos);
289 }
290 switch(dtx_get_esd_state())
291 {
292 case UART_ESD_DETECTED:
293 if(uart_data->dtx->esd_pos < 3)
294 {
295 TRACE_EVENT_P1("ERROR: esd_pos=%d < 3 in UART_ESD_DETECTED state",
296 uart_data->dtx->esd_pos);
297 }
298 break;
299 case UART_ESD_CHAR_1:
300 if(uart_data->dtx->esd_pos < 1)
301 {
302 TRACE_EVENT_P1("ERROR: esd_pos=%d < 1 in UART_ESD_CHAR_1 state",
303 uart_data->dtx->esd_pos);
304 }
305 break;
306 case UART_ESD_CHAR_2:
307 if(uart_data->dtx->esd_pos < 2)
308 {
309 TRACE_EVENT_P1("ERROR: esd_pos=%d < 2 in UART_ESD_CHAR_2 state",
310 uart_data->dtx->esd_pos);
311 }
312 break;
313 case UART_ESD_CHAR_3:
314 if(uart_data->dtx->esd_pos < 3)
315 {
316 TRACE_EVENT_P1("ERROR: esd_pos=%d < 3 in UART_ESD_CHAR_3 state",
317 uart_data->dtx->esd_pos);
318 }
319 break;
320 }
321 #endif /* UART_RANGE_CHECK */
322
323 /*
324 * store new write position,
325 * current data_flow state and
326 * current data descriptor
327 */
328 uart_data->dtx->write_pos = write_pos;
329 old_data_flow = uart_data->dtx->data_flow;
330 temp_desc = received_data;
331
332 /*
333 * Introduce local variable here in order to prevent
334 * the target compiler from doing wrong calculations ...
335 */
336 esd_pos = uart_data->dtx->esd_pos;
337
338 /*
339 * escape sequence detection
340 */
341 if(uart_data->dtx->receiving_state EQ UART_DTX_RECEIVING &&
342 uart_data->dtx->detect_escape EQ TRUE)
343 {
344 if (vsi_t_time (VSI_CALLER &cur_time) EQ VSI_OK)
345 {
346 switch(dtx_get_esd_state())
347 {
348 case UART_ESD_DETECTED:
349 /*
350 * remove escape characters because escape sequence was detected
351 */
352 if(uart_data->dtx->write_pos > esd_pos)
353 {
354 memmove(&temp_desc->buffer[esd_pos - 3],
355 &temp_desc->buffer[esd_pos],
356 uart_data->dtx->write_pos - esd_pos);
357 }
358 uart_data->dtx->write_pos-= 3;
359 esd_pos -= 3;
360 uart_data->dtx->esd_pos = esd_pos;
361 dtx_set_esd_state( UART_ESD_NULL );
362 /* fall through */
363 case UART_ESD_NULL:
364 #ifdef _SIMULATION_
365 TRACE_EVENT_P2("uart_data->act_gp: %d, silence: %d",
366 uart_data->act_gp,
367 (cur_time - uart_data->dtx->esd_guard_time));
368 #endif /* _SIMULATION_ */
369 if(esd_pos >= temp_desc->len)
370 break;
371
372 if(((cur_time -
373 uart_data->dtx->esd_guard_time) < uart_data->act_gp) ||
374 (temp_desc->
375 buffer[esd_pos] NEQ uart_data->act_ec))
376 {
377 /*
378 * set new reference time and
379 * update esd_pos
380 */
381 esd_pos = temp_desc->len;
382 uart_data->dtx->esd_pos = esd_pos;
383 uart_data->dtx->esd_guard_time = cur_time;
384 break;
385 }
386 /*
387 * first guard period complete and
388 * first escape character detected
389 */
390 #ifdef _SIMULATION_
391 TRACE_EVENT("+ + + first guard period complete + + +");
392 #endif /* _SIMULATION_ */
393 dtx_set_esd_state( UART_ESD_CHAR_1 );
394 esd_pos++;
395 uart_data->dtx->esd_pos = esd_pos;
396 uart_data->dtx->esd_guard_time = cur_time;
397 sig_dtx_rt_start_tesd_req (uart_data->act_gp);
398 /* fall trough */
399 case UART_ESD_CHAR_1:
400 if(esd_pos >= temp_desc->len)
401 {
402 /*
403 * hide 1 character
404 */
405 temp_desc->len = esd_pos - 1;
406 temp_desc->size = temp_desc->len;
407 break;
408 }
409
410 if(temp_desc->
411 buffer[esd_pos] NEQ uart_data->act_ec)
412 {
413 /*
414 * second character is not an escape character
415 */
416 dtx_set_esd_state( UART_ESD_NULL );
417 esd_pos = temp_desc->len;
418 uart_data->dtx->esd_pos = esd_pos;
419 uart_data->dtx->esd_guard_time = cur_time;
420 break;
421 }
422 /*
423 * second escape character received
424 */
425 dtx_set_esd_state( UART_ESD_CHAR_2 );
426 esd_pos++;
427 uart_data->dtx->esd_pos = esd_pos;
428 /* fall trough */
429 case UART_ESD_CHAR_2:
430 if(esd_pos >= temp_desc->len)
431 {
432 /*
433 * hide 2 characters
434 */
435 temp_desc->len = esd_pos - 2;
436 temp_desc->size = temp_desc->len;
437 break;
438 }
439 /*
440 * set new reference time
441 */
442 uart_data->dtx->esd_guard_time = cur_time;
443
444 if(temp_desc->
445 buffer[esd_pos] NEQ uart_data->act_ec)
446 {
447 /*
448 * third character is not an escape character
449 */
450 dtx_set_esd_state( UART_ESD_NULL );
451 esd_pos = temp_desc->len;
452 uart_data->dtx->esd_pos = esd_pos;
453 break;
454 }
455 /*
456 * third escape character received
457 */
458 dtx_set_esd_state( UART_ESD_CHAR_3 );
459 esd_pos++;
460 uart_data->dtx->esd_pos = esd_pos;
461 sig_dtx_rt_start_tesd_req (uart_data->act_gp);
462 /* fall trough */
463 case UART_ESD_CHAR_3:
464 if(esd_pos >= temp_desc->len)
465 {
466 /*
467 * hide 3 characters
468 */
469 temp_desc->len = esd_pos - 3;
470 temp_desc->size = temp_desc->len;
471 break;
472 }
473 /*
474 * fourth character received
475 */
476 dtx_set_esd_state( UART_ESD_NULL );
477 esd_pos = temp_desc->len;
478 uart_data->dtx->esd_pos = esd_pos;
479 uart_data->dtx->esd_guard_time = cur_time;
480 break;
481
482 default:
483 TRACE_ERROR("wrong esd state");
484 break;
485 }
486 }
487 else
488 {
489 TRACE_ERROR_P1("VSI entity: Can't restart timer, uart_dtxs.c(%d)",
490 __LINE__);
491 }
492 }
493
494 switch( GET_STATE( UART_SERVICE_DTX ) )
495 {
496 case DTX_DEAD:
497 dtx_free_resources();
498 uart_data->dtx->receiving_state = UART_DTX_NOT_RECEIVING;
499 break;
500
501 case DTX_READY:
502 /*
503 * enable data flow if necessary
504 */
505 if(old_data_flow NEQ UART_FLOW_ENABLED)
506 {
507 uart_data->dtx->data_flow = UART_FLOW_ENABLED;
508 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance);
509 }
510
511 if(uart_data->dtx->receiving_state EQ UART_DTX_RECEIVING)
512 {
513 /*
514 * if data to send available or
515 * line states changed
516 */
517 if((temp_desc->len) ||
518 (uart_data->dtx->lines_changed))
519 {
520 PALLOC_DESC2 (dti_data_ind, DTI2_DATA_IND);
521 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
522
523 if(temp_desc->len)
524 {
525 /*
526 * mark entity descriptor as invalid, since data will be forwarded
527 */
528 uart_data->dtx->to_send_data = NULL;
529
530 dti_data_ind->desc_list2.first = (ULONG)temp_desc;
531 dti_data_ind->desc_list2.list_len = temp_desc->len;
532
533 /*
534 * calculate new size multiplier according to fillrate of buffer
535 */
536 dtx_calculate_size_multiplier (temp_desc, old_data_flow);
537 /*
538 * allocate a new descriptor with size according to new size_multiplier
539 */
540 dtx_allocate_resources();
541 /*
542 * Check for data which has not yet been validated, i.e. because
543 * the frame containing the data has not yet been received completely.
544 * In this case, the not yet validated data is copied to the newly
545 * allocated descriptor.
546 */
547 if(uart_data->dtx->write_pos > temp_desc->len)
548 {
549 memcpy(uart_data->dtx->to_send_data->buffer,
550 &temp_desc->buffer[temp_desc->len],
551 uart_data->dtx->write_pos - temp_desc->len);
552 uart_data->dtx->write_pos-= temp_desc->len;
553 }
554 esd_pos-= temp_desc->len;
555 uart_data->dtx->esd_pos = esd_pos;
556 }
557 else
558 {
559 /*
560 * just line states has been changed
561 */
562 dti_data_ind->desc_list2.first = (ULONG)NULL;
563 dti_data_ind->desc_list2.list_len = 0;
564 }
565
566 /*
567 * set line states and
568 * mark line states as unchanged;
569 */
570 dti_data_ind->parameters.st_lines.st_flow = uart_data->dtx->st_flow;
571 dti_data_ind->parameters.st_lines.st_line_sa = uart_data->dtx->st_line_sa;
572 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb;
573 dti_data_ind->parameters.st_lines.st_break_len = uart_data->dtx->st_break_len;
574
575 uart_data->dtx->lines_changed = FALSE;
576 uart_data->dtx->st_break_len = DTI_BREAK_OFF;
577
578 dti_send_data(
579 uart_hDTI,
580 uart_data->device,
581 UART_DTI_UP_INTERFACE,
582 uart_data->dtx->dlc_instance,
583 dti_data_ind
584 );
585 }
586 }
587 else
588 {
589 /*
590 * invalid data
591 * free recources and allocate a new descriptor because
592 * size_multiplier may have changed
593 */
594 dtx_free_resources();
595 dtx_allocate_resources();
596 /*
597 * reset escape sequence detection
598 */
599 dtx_set_esd_state( UART_ESD_NULL );
600 if(vsi_t_time (VSI_CALLER &(uart_data->dtx->esd_guard_time)) NEQ VSI_OK)
601 {
602 TRACE_ERROR_P1("VSI entity: Can't restart timer, uart_dtxs.c(%d)",
603 __LINE__);
604 }
605
606 esd_pos = 0;
607 uart_data->dtx->esd_pos = esd_pos;
608 }
609
610 /*
611 * signal availability to receive to RX service
612 */
613 uart_data->dtx->receiving_state = UART_DTX_NOT_RECEIVING;
614 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance,
615 uart_data->dtx->to_send_data,
616 uart_data->dtx->write_pos,
617 uart_data->dtx->cur_desc_size );
618 break;
619
620 case DTX_NOT_READY:
621 if(uart_data->dtx->receiving_state EQ UART_DTX_RECEIVING)
622 {
623 uart_data->dtx->receiving_state = UART_DTX_NOT_RECEIVING;
624 if((old_data_flow NEQ UART_FLOW_DISABLED) &&
625 ((uart_data->dtx->cur_desc_size - temp_desc->len) <
626 ((USHORT)uart_data->n1 << 1)))
627 {
628 /*
629 * the service DTX is receiving but there is not enough space left
630 * therefore it is necessary to disable the data flow
631 */
632 uart_data->dtx->data_flow = UART_FLOW_DISABLED;
633 sig_dtx_ker_disable_ind(uart_data->dtx->dlc_instance);
634 }
635 if((uart_data->dtx->cur_desc_size -
636 esd_pos) >= uart_data->n1)
637 {
638 /*
639 * there is still enough space left to continue reception
640 */
641 sig_dtx_rx_ready_to_receive_req(uart_data->dtx->dlc_instance,
642 uart_data->dtx->to_send_data,
643 uart_data->dtx->write_pos,
644 uart_data->dtx->cur_desc_size);
645 }
646 }
647 else
648 {
649 /*
650 * invalid data
651 * free recources and allocate a new descriptor
652 * because size_multiplier may have changed
653 */
654 dtx_free_resources();
655 dtx_allocate_resources();
656 /*
657 * reset escape sequence detection
658 */
659 dtx_set_esd_state( UART_ESD_NULL );
660 if(vsi_t_time (VSI_CALLER &(uart_data->dtx->esd_guard_time)) NEQ VSI_OK)
661 {
662 TRACE_ERROR_P1("VSI entity: Can't restart timer, uart_dtxs.c(%d)",
663 __LINE__);
664 }
665
666 esd_pos = 0;
667 uart_data->dtx->esd_pos = esd_pos;
668 /*
669 * enable flow control if necessary
670 */
671 if(old_data_flow NEQ UART_FLOW_ENABLED)
672 {
673 uart_data->dtx->data_flow = UART_FLOW_ENABLED;
674 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance);
675 }
676 /*
677 * signal availability to receive to RX service
678 */
679 uart_data->dtx->receiving_state = UART_DTX_NOT_RECEIVING;
680 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance,
681 uart_data->dtx->to_send_data,
682 uart_data->dtx->write_pos,
683 uart_data->dtx->cur_desc_size );
684 }
685 break;
686
687 default:
688 TRACE_ERROR( "SIG_RX_DTX_DATA_RECEIVED_IND unexpected" );
689 break;
690
691 }
692 } /* sig_rx_dtx_data_received_ind() */
693
694
695 /*
696 +------------------------------------------------------------------------------
697 | Function : sig_ker_dtx_line_states_req
698 +------------------------------------------------------------------------------
699 | Description : Handles the internal signal SIG_KER_DTX_LINE_STATES_REQ
700 | which indicates that one or more line status signals have
701 | changed
702 |
703 | Parameters : st_flow - flow control state (X bit)
704 | st_line_sa - line state SA
705 | st_line_sa - line state SB
706 | st_break_len - break length
707 |
708 +------------------------------------------------------------------------------
709 */
710 GLOBAL void sig_ker_dtx_line_states_req(UBYTE st_flow,
711 UBYTE st_line_sa,
712 UBYTE st_line_sb,
713 UBYTE st_break_len)
714 {
715 TRACE_ISIG( "sig_ker_dtx_line_states_req" );
716
717 switch( GET_STATE( UART_SERVICE_DTX ) )
718 {
719 case DTX_READY:
720 if((st_flow NEQ uart_data->dtx->st_flow) ||
721 (st_line_sa NEQ uart_data->dtx->st_line_sa) ||
722 (st_line_sb NEQ uart_data->dtx->st_line_sb) ||
723 (st_break_len NEQ uart_data->dtx->st_break_len))
724 {
725 /*
726 * send line states to DTI peer
727 */
728 PALLOC_DESC2 (dti_data_ind, DTI2_DATA_IND);
729 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
730
731 /*
732 * store new line states
733 */
734 uart_data->dtx->st_flow = st_flow;
735 uart_data->dtx->st_line_sa = st_line_sa;
736 uart_data->dtx->st_line_sb = st_line_sb;
737 uart_data->dtx->st_break_len = st_break_len;
738
739 /*
740 * just line states has been changed
741 */
742 dti_data_ind->desc_list2.first = (ULONG)NULL;
743 dti_data_ind->desc_list2.list_len = 0;
744 /*
745 * set line states and
746 * mark line states as unchanged;
747 */
748 dti_data_ind->parameters.st_lines.st_flow = uart_data->dtx->st_flow;
749 dti_data_ind->parameters.st_lines.st_line_sa = uart_data->dtx->st_line_sa;
750 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb;
751 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb;
752 dti_data_ind->parameters.st_lines.st_break_len = uart_data->dtx->st_break_len;
753
754 uart_data->dtx->lines_changed = FALSE;
755 uart_data->dtx->st_break_len = DTI_BREAK_OFF;
756
757 dti_send_data(
758 uart_hDTI,
759 uart_data->device,
760 UART_DTI_UP_INTERFACE,
761 uart_data->dtx->dlc_instance,
762 dti_data_ind
763 );
764 }
765 break;
766
767 case DTX_NOT_READY:
768 if((st_flow NEQ uart_data->dtx->st_flow) ||
769 (st_line_sa NEQ uart_data->dtx->st_line_sa) ||
770 (st_line_sb NEQ uart_data->dtx->st_line_sb) ||
771 (st_break_len NEQ uart_data->dtx->st_break_len))
772 {
773 /*
774 * If previously break detected keep information in
775 * uart_data->dtx->st_break_len
776 */
777 if(uart_data->dtx->st_break_len EQ DTI_BREAK_OFF)
778 uart_data->dtx->st_break_len = st_break_len;
779 /*
780 * store new line states
781 */
782 uart_data->dtx->st_flow = st_flow;
783 uart_data->dtx->st_line_sa = st_line_sa;
784 uart_data->dtx->st_line_sb = st_line_sb;
785 /*
786 * mark line states as changed
787 */
788 uart_data->dtx->lines_changed = TRUE;
789 }
790 break;
791
792 default:
793 TRACE_ERROR( "SIG_KER_DTX_LINE_STATES_REQ unexpected" );
794 break;
795 }
796 } /* sig_ker_dtx_line_states_req */
797
798
799
800 /*
801 +------------------------------------------------------------------------------
802 | Function : sig_ker_dtx_detect_escape_req
803 +------------------------------------------------------------------------------
804 | Description : Handles the internal signal SIG_KER_DTX_DETECT_ESCAPE_REQ
805 | which enables escape sequence detection
806 |
807 | Parameters : detect_escape - TRUE/FALSE
808 |
809 +------------------------------------------------------------------------------
810 */
811 GLOBAL void sig_ker_dtx_detect_escape_req (UBYTE detect_escape)
812 {
813 TRACE_ISIG( "sig_ker_dtx_detect_req" );
814
815 uart_data->dtx->detect_escape = detect_escape;
816 } /* sig_ker_dtx_detect_req() */
817
818
819 /*
820 +------------------------------------------------------------------------------
821 | Function : sig_ker_dtx_disconnected_mode_req
822 +------------------------------------------------------------------------------
823 | Description : Handles the internal signal SIG_KER_DTX_DISCONNECTED_MODE_REQ
824 |
825 | Parameters : none
826 |
827 +------------------------------------------------------------------------------
828 */
829 GLOBAL void sig_ker_dtx_disconnected_mode_req ()
830 {
831 TRACE_ISIG( "sig_ker_dtx_disconnected_mode_req" );
832
833 uart_data->dtx->dti_dtx_state = DTI_CLOSED;
834
835 switch(GET_STATE( UART_SERVICE_DTX) )
836 {
837 case DTX_READY:
838 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
839 break;
840 case DTX_NOT_READY:
841 break;
842 default:
843 TRACE_ERROR( "SIG_KER_DTX_DISCONNECTED_MODE_REQ unexpected" );
844 break;
845 }
846
847 } /* sig_ker_dtx_disconnected_mode_req() */
848
849
850
851 /*
852 +------------------------------------------------------------------------------
853 | Function : sig_ker_dtx_set_dtilib_peer_req
854 +------------------------------------------------------------------------------
855 | Description : Handles the internal signal SIG_KER_DTX_SET_DTI_PEER_REQ
856 | which is used to inform the service DTX that from now on it
857 | needs to communicate with a (new) peer
858 |
859 | Parameters : -
860 |
861 +------------------------------------------------------------------------------
862 */
863 GLOBAL void sig_ker_dtx_set_dtilib_peer_req ()
864
865 {
866 TRACE_ISIG( "sig_ker_dtx_set_dtilib_peer_req" );
867
868 /*
869 * set dtilib parameters
870 */
871 uart_data->dtx->dti_dtx_state = DTI_IDLE;
872
873 /*
874 * reset size_multiplier
875 */
876 uart_data->dtx->size_multiplier = 3;
877
878 /*
879 * switch to new DTX state depending on current state
880 */
881 switch( GET_STATE( UART_SERVICE_DTX ) )
882 {
883 case DTX_READY:
884 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
885 /* fall through */
886 case DTX_NOT_READY:
887 {
888 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
889 {
890 /*
891 * reset received data
892 */
893 dtx_free_resources();
894 dtx_allocate_resources();
895 /*
896 * reset escape sequence detection
897 */
898 dtx_set_esd_state( UART_ESD_NULL );
899 if(vsi_t_time (VSI_CALLER &(uart_data->dtx->esd_guard_time)) NEQ VSI_OK)
900 {
901 TRACE_ERROR_P1("VSI entity: Can't restart timer, uart_dtxs.c(%d)",
902 __LINE__);
903 }
904
905 uart_data->dtx->esd_pos = 0;
906 /*
907 * enable flow control if necessary
908 */
909 if(uart_data->dtx->data_flow NEQ UART_FLOW_ENABLED)
910 {
911 uart_data->dtx->data_flow = UART_FLOW_ENABLED;
912 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance);
913 }
914 /*
915 * signal availability to receive to RX service
916 */
917 sig_dtx_rx_ready_to_receive_req( uart_data->dtx->dlc_instance,
918 uart_data->dtx->to_send_data,
919 uart_data->dtx->write_pos,
920 uart_data->dtx->cur_desc_size );
921 }
922 else
923 uart_data->dtx->receiving_state = UART_DTX_INVALID;
924 }
925 break;
926
927 case DTX_DEAD:
928 break;
929
930 default:
931 TRACE_ERROR( "SIG_KER_DTX_SET_DTI_PEER_REQ unexpected" );
932 break;
933 }
934 } /* sig_ker_dtx_set_dtilib_peer_req() */
935
936
937
938 /*
939 +------------------------------------------------------------------------------
940 | Function : sig_ker_dtx_timeout_tesd_req
941 +------------------------------------------------------------------------------
942 | Description : Handles the internal signal SIG_KER_DTX_TIMEOUT_TESD_REQ
943 | which is used to inform the service DTX that the Escape
944 | Sequence Guard Period timer has expired.
945 |
946 | Parameters : none
947 |
948 +------------------------------------------------------------------------------
949 */
950 GLOBAL void sig_ker_dtx_timeout_tesd_req()
951 {
952 T_DATA_FLOW_STATE old_data_flow;
953 T_TIME cur_time;
954 T_TIME elapsed;
955 T_desc2* temp_desc;
956
957 TRACE_ISIG( "sig_ker_dtx_timeout_tesd_req" );
958
959 switch( GET_STATE( UART_SERVICE_DTX ) )
960 {
961 case DTX_READY:
962 if (vsi_t_time (VSI_CALLER &cur_time) EQ VSI_OK)
963 {
964 elapsed = cur_time - uart_data->dtx->esd_guard_time;
965 switch (dtx_get_esd_state())
966 {
967 case UART_ESD_DETECTED:
968 case UART_ESD_NULL:
969 break;
970
971 case UART_ESD_CHAR_1:
972 case UART_ESD_CHAR_2:
973 if(elapsed < uart_data->act_gp)
974 {
975 /*
976 * escape sequence guard period not complete: start timer
977 * with remaining time value
978 */
979 sig_dtx_rt_start_tesd_req (uart_data->act_gp - elapsed);
980 }
981 else
982 {
983 /*
984 * Guard Period complete
985 * reset detection because detected characters do not belong to
986 * an escape sequence
987 */
988 dtx_set_esd_state( UART_ESD_NULL );
989
990 /*
991 * if possible send the escape character
992 */
993 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
994 {
995 /*
996 * Guard Period complete
997 * send one escape character to DTI peer and reset detection
998 */
999 PALLOC_DESC2 (dti_data_ind, DTI2_DATA_IND);
1000 SET_STATE( UART_SERVICE_DTX, DTX_NOT_READY );
1001
1002 /*
1003 * enable data flow if necessary
1004 */
1005 old_data_flow = uart_data->dtx->data_flow;
1006 if(uart_data->dtx->data_flow NEQ UART_FLOW_ENABLED)
1007 {
1008 uart_data->dtx->data_flow = UART_FLOW_ENABLED;
1009 sig_dtx_ker_enable_ind(uart_data->dtx->dlc_instance);
1010 }
1011 /*
1012 * mark entity descriptor as invalid, since data will be
1013 * forwarded
1014 */
1015 temp_desc = uart_data->dtx->to_send_data;
1016 uart_data->dtx->to_send_data = NULL;
1017
1018 /*
1019 * make escape character valid to send and insert values in
1020 * primitive
1021 */
1022 temp_desc->len = uart_data->dtx->esd_pos;
1023 temp_desc->size = temp_desc->len;
1024
1025 dti_data_ind->desc_list2.first = (ULONG)temp_desc;
1026 dti_data_ind->desc_list2.list_len = temp_desc->len;
1027
1028 /*
1029 * calculate new size multiplier according to fillrate of buffer
1030 */
1031 dtx_calculate_size_multiplier (temp_desc, old_data_flow);
1032 /*
1033 * allocate a new descriptor with size according to new size_multiplier
1034 */
1035 dtx_allocate_resources();
1036 /*
1037 * Check for data which has not yet been validated, i.e. because
1038 * the frame containing the data has not yet been received completely.
1039 * In this case, the not yet validated data is copied to the newly
1040 * allocated descriptor.
1041 */
1042 if(uart_data->dtx->write_pos > temp_desc->len)
1043 {
1044 memcpy(uart_data->dtx->to_send_data->buffer,
1045 &temp_desc->buffer[temp_desc->len],
1046 uart_data->dtx->write_pos - temp_desc->len);
1047 uart_data->dtx->write_pos-= temp_desc->len;
1048 }
1049 uart_data->dtx->esd_pos = 0;
1050 sig_dtx_rx_ready_to_receive_req(uart_data->dtx->dlc_instance,
1051 uart_data->dtx->to_send_data,
1052 uart_data->dtx->write_pos,
1053 uart_data->dtx->cur_desc_size);
1054
1055 /*
1056 * set line states
1057 */
1058 dti_data_ind->parameters.st_lines.st_flow = uart_data->dtx->st_flow;
1059 dti_data_ind->parameters.st_lines.st_line_sa = uart_data->dtx->st_line_sa;
1060 dti_data_ind->parameters.st_lines.st_line_sb = uart_data->dtx->st_line_sb;
1061 dti_data_ind->parameters.st_lines.st_break_len = uart_data->dtx->st_break_len;
1062
1063 uart_data->dtx->lines_changed = FALSE;
1064 uart_data->dtx->st_break_len = DTI_BREAK_OFF;
1065
1066 #ifdef _SIMULATION_
1067 dti_data_ind->parameters.p_id = DTI_PID_UOS;
1068 #endif /* _SIMULATION_ */
1069 dti_send_data(
1070 uart_hDTI,
1071 uart_data->device,
1072 UART_DTI_UP_INTERFACE,
1073 uart_data->dtx->dlc_instance,
1074 dti_data_ind
1075 );
1076 }
1077 }
1078 break;
1079
1080 case UART_ESD_CHAR_3:
1081 if(elapsed < uart_data->act_gp)
1082 {
1083 /*
1084 * escape sequence guard period not complete: start timer
1085 * with remaining time value
1086 */
1087 sig_dtx_rt_start_tesd_req (uart_data->act_gp - elapsed);
1088 }
1089 else
1090 {
1091 /*
1092 * Guard Period complete
1093 * Escape Sequence detected
1094 */
1095 /*
1096 * remove escape characters from data stream
1097 */
1098 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
1099 {
1100 if(uart_data->dtx->write_pos > 3)
1101 {
1102 memmove(uart_data->dtx->to_send_data->buffer,
1103 &uart_data->dtx->to_send_data->buffer[3],
1104 uart_data->dtx->write_pos - 3)
1105 ; /*lint !e416 creation of out-of-bounds pointer */
1106 uart_data->dtx->write_pos-= 3;
1107 }
1108 else
1109 uart_data->dtx->write_pos = 0;
1110 uart_data->dtx->esd_pos = 0;
1111 sig_dtx_rx_ready_to_receive_req(uart_data->dtx->dlc_instance,
1112 uart_data->dtx->to_send_data,
1113 uart_data->dtx->write_pos,
1114 uart_data->dtx->cur_desc_size);
1115 /*
1116 * Reset the state of the Escape Sequence Detection
1117 */
1118 dtx_set_esd_state( UART_ESD_NULL );
1119 }
1120 else
1121 {
1122 /*
1123 * escape characters are not removeable
1124 * so we will do this later
1125 */
1126 #ifdef _SIMULATION_
1127 TRACE_EVENT("ESD: escape characters are not removeable");
1128 #endif /* _SIMULATION_ */
1129 dtx_set_esd_state( UART_ESD_DETECTED );
1130 }
1131 #ifdef _SIMULATION_
1132 TRACE_EVENT_P3("+ + + dlc_instance: %d, silence %d \
1133 (from %d) Escape Sequence Detected + + + ",
1134 uart_data->dtx->dlc_instance,
1135 elapsed,
1136 uart_data->dtx->esd_guard_time);
1137 #endif /* _SIMULATION_ */
1138
1139 /*
1140 * send detected escape sequence to MMI
1141 */
1142 sig_dtx_ker_escape_detected_ind(uart_data->dtx->dlc_instance);
1143 }
1144 break;
1145
1146 default:
1147 {
1148 TRACE_ERROR_P1("Error: wrong ESD state, uart_dtxs.c(%d)", __LINE__);
1149 }
1150 break;
1151 }
1152 }
1153 else
1154 {
1155 TRACE_ERROR_P1("VSI entity: Cannot restart timer, uart_dtxs.c(%d)",
1156 __LINE__);
1157 }
1158 break;
1159
1160 case DTX_NOT_READY:
1161 if (vsi_t_time (VSI_CALLER &cur_time) EQ VSI_OK)
1162 {
1163 elapsed = cur_time - uart_data->dtx->esd_guard_time;
1164 switch (dtx_get_esd_state())
1165 {
1166 case UART_ESD_DETECTED:
1167 case UART_ESD_NULL:
1168 break;
1169
1170 case UART_ESD_CHAR_1:
1171 case UART_ESD_CHAR_2:
1172 if(elapsed < uart_data->act_gp)
1173 {
1174 /*
1175 * escape sequence guard period not complete: start timer
1176 * with remaining time value
1177 */
1178 sig_dtx_rt_start_tesd_req (uart_data->act_gp - elapsed);
1179 }
1180 else
1181 {
1182 /*
1183 * Guard Period complete
1184 * reset detection because detected characters do not belong to
1185 * an escape sequence
1186 */
1187 dtx_set_esd_state( UART_ESD_NULL );
1188
1189 /*
1190 * if possible insert escape characters to usual data stream
1191 */
1192 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
1193 {
1194 /*
1195 * make escape character valid to send and insert values in
1196 * primitive
1197 */
1198 uart_data->dtx->to_send_data->len = uart_data->dtx->esd_pos;
1199 uart_data->dtx->to_send_data->size = uart_data->dtx->esd_pos;
1200 uart_data->dtx->to_send_data->offset = 0;
1201
1202 if((uart_data->dtx->cur_desc_size -
1203 uart_data->dtx->esd_pos) >= uart_data->n1)
1204 {
1205 /*
1206 * there is still enough space left to continue reception
1207 */
1208 sig_dtx_rx_ready_to_receive_req(
1209 uart_data->dtx->dlc_instance,
1210 uart_data->dtx->to_send_data,
1211 uart_data->dtx->write_pos,
1212 uart_data->dtx->cur_desc_size);
1213 }
1214
1215 }
1216 }
1217 break;
1218
1219 case UART_ESD_CHAR_3:
1220 if(elapsed < uart_data->act_gp)
1221 {
1222 /*
1223 * escape sequence guard period not complete: start timer
1224 * with remaining time value
1225 */
1226 sig_dtx_rt_start_tesd_req (uart_data->act_gp - elapsed);
1227 }
1228 else
1229 {
1230 /*
1231 * Guard Period complete
1232 * Escape Sequence detected
1233 * store the occurence of the Escape Sequence
1234 */
1235 #ifdef _SIMULATION_
1236 TRACE_EVENT_P3("+ + + dlc_instance: %d, silence %d \
1237 (from %d) Escape Sequence Detected + + + ",
1238 uart_data->dtx->dlc_instance,
1239 elapsed,
1240 uart_data->dtx->esd_guard_time);
1241 #endif /* _SIMULATION_ */
1242 /*
1243 * remove escape characters from data stream
1244 */
1245 if(uart_data->dtx->receiving_state EQ UART_DTX_NOT_RECEIVING)
1246 {
1247 if(uart_data->dtx->write_pos > uart_data->dtx->esd_pos)
1248 {
1249 memmove(
1250 &uart_data->dtx->to_send_data->buffer[
1251 uart_data->dtx->esd_pos - 3],
1252 &uart_data->dtx->to_send_data->buffer[
1253 uart_data->dtx->esd_pos],
1254 uart_data->dtx->write_pos - uart_data->dtx->esd_pos);
1255 }
1256 uart_data->dtx->write_pos-= 3;
1257 uart_data->dtx->esd_pos -= 3;
1258 /*
1259 * Reset the state of the Escape Sequence Detection
1260 */
1261 dtx_set_esd_state( UART_ESD_NULL );
1262
1263 if((uart_data->dtx->cur_desc_size -
1264 uart_data->dtx->esd_pos) >= uart_data->n1)
1265 {
1266 /*
1267 * there is still enough space left to continue reception
1268 */
1269 sig_dtx_rx_ready_to_receive_req(
1270 uart_data->dtx->dlc_instance,
1271 uart_data->dtx->to_send_data,
1272 uart_data->dtx->write_pos,
1273 uart_data->dtx->cur_desc_size);
1274 }
1275 }
1276 else
1277 {
1278 /*
1279 * escape characters are not removeable
1280 * so we will do this later
1281 */
1282 #ifdef _SIMULATION_
1283 TRACE_EVENT("ESD: escape characters are not removeable");
1284 #endif /* _SIMULATION_ */
1285 dtx_set_esd_state( UART_ESD_DETECTED );
1286 }
1287
1288 /*
1289 * send detected escape sequence to MMI
1290 */
1291 sig_dtx_ker_escape_detected_ind(uart_data->dtx->dlc_instance);
1292 }
1293 break;
1294
1295 default:
1296 TRACE_ERROR("wrong esd state");
1297 break;
1298 }
1299 }
1300 break;
1301
1302 case DTX_DEAD:
1303 break;
1304
1305 default:
1306 TRACE_ERROR( "SIG_KER_DTX_TIMEOUT_TESD_REQ unexpected" );
1307 break;
1308 }
1309 } /* sig_ker_dtx_timeout_tesd_req() */