comparison g23m-aci/uart/uart_dtxf.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 | procedures and functions as described in the
19 | SDL-documentation (DTX-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef UART_DTXF_C
24 #define UART_DTXF_C
25 #endif /* !UART_DTXF_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 WIN32
36 #include "nucleus.h"
37 #endif /* WIN32 */
38 #include "typedefs.h" /* to get Condat data types */
39 #include "vsi.h" /* to get a lot of macros */
40 #include "macdef.h" /* to get a lot of macros */
41 #include "custom.h"
42 #include "gsm.h" /* to get a lot of macros */
43 #include "cnf_uart.h" /* to get cnf-definitions */
44 #include "mon_uart.h" /* to get mon-definitions */
45 #include "prim.h" /* to get the definitions of used SAP and directions */
46 #include "dti.h" /* to get dti lib */
47 #include "pei.h" /* to get PEI interface */
48 #ifdef FF_MULTI_PORT
49 #include "gsi.h" /* to get definitions of serial driver */
50 #else /* FF_MULTI_PORT */
51 #ifdef _TARGET_
52 #include "../../serial/serialswitch.h"
53 #include "../../serial/traceswitch.h"
54 #else /* _TARGET_ */
55 #include "serial_dat.h" /* to get definitions of serial driver */
56 #endif /* _TARGET_ */
57 #endif /* FF_MULTI_PORT */
58 #include "uart.h" /* to get the global entity definitions */
59
60 /*==== CONST ================================================================*/
61
62 /*
63 * names of escape sequence detection state machine
64 */
65 #ifdef _SIMULATION_
66 char * uart_esd_state_names[] =
67 {
68 "UART_ESD_NULL",
69 "UART_ESD_CHAR_1",
70 "UART_ESD_CHAR_2",
71 "UART_ESD_CHAR_3",
72 "UART_ESD_DETECTED"
73 };
74 #endif /* _SIMULATION_ */
75
76 /*==== LOCAL VARS ===========================================================*/
77
78 /*==== PRIVATE FUNCTIONS ====================================================*/
79
80 /*==== PUBLIC FUNCTIONS =====================================================*/
81
82
83
84 /*
85 +------------------------------------------------------------------------------
86 | Function : dtx_get_esd_state
87 +------------------------------------------------------------------------------
88 | Description : This function returns the current state of the Escape Sequence
89 | Detection.
90 |
91 | Parameters : none
92 |
93 | Return : ESD State
94 |
95 +------------------------------------------------------------------------------
96 */
97 GLOBAL T_ESD_STATE dtx_get_esd_state()
98 {
99 TRACE_FUNCTION ("dtx_get_esd_state");
100
101 #ifdef _SIMULATION_
102 TRACE_EVENT_P1 ("esd_state is [%s]",
103 uart_esd_state_names[uart_data->dtx->esd_state]);
104 #endif /* _SIMULATION_ */
105
106 return uart_data->dtx->esd_state;
107 } /* dtx_get_esd_state() */
108
109
110
111 /*
112 +------------------------------------------------------------------------------
113 | Function : dtx_set_esd_state
114 +------------------------------------------------------------------------------
115 | Description : This function sets the state of the Escape Sequence Detection.
116 |
117 | Parameters : new ESD State
118 |
119 | Return : none
120 |
121 +------------------------------------------------------------------------------
122 */
123 GLOBAL void dtx_set_esd_state( T_ESD_STATE new_esd_state )
124 {
125 TRACE_FUNCTION ("dtx_set_esd_state");
126
127 #ifdef _SIMULATION_
128 if(uart_data->dtx->esd_state != new_esd_state)
129 {
130 TRACE_EVENT_P2 ("esd_state [%s] -> [%s]",
131 uart_esd_state_names[uart_data->dtx->esd_state],
132 uart_esd_state_names[new_esd_state]);
133 uart_data->dtx->esd_state = new_esd_state;
134 uart_data->dtx->esd_state_name = uart_esd_state_names[new_esd_state];
135 }
136 else
137 {
138 TRACE_EVENT_P1 ("esd_state remains [%s]",
139 uart_esd_state_names[uart_data->dtx->esd_state]);
140 }
141 #else /* _SIMULATION_ */
142 if(uart_data->dtx->esd_state != new_esd_state)
143 uart_data->dtx->esd_state = new_esd_state;
144 #endif /* _SIMULATION_ */
145 } /* dtx_set_esd_state() */
146
147
148
149 /*
150 +------------------------------------------------------------------------------
151 | Function : dtx_init
152 +------------------------------------------------------------------------------
153 | Description : The function dtx_init() initializes the service DTX
154 |
155 | Parameters : none
156 |
157 +------------------------------------------------------------------------------
158 */
159 GLOBAL void dtx_init ()
160 {
161 USHORT i;
162
163 TRACE_FUNCTION( "dtx_init" );
164
165 for( i = 0; i < UART_MAX_NUMBER_OF_CHANNELS; i++ )
166 {
167 /*
168 * select next instance of service DTX
169 */
170 uart_data->dtx = &( uart_data->dtx_base[i] );
171
172 /*
173 * initialize service specific variables
174 */
175 uart_data->dtx->to_send_data = NULL;
176 uart_data->dtx->cur_desc_size = 0;
177 uart_data->dtx->write_pos = 0;
178 uart_data->dtx->size_multiplier = 3;
179 uart_data->dtx->st_flow = DTI_FLOW_ON;
180 uart_data->dtx->st_line_sa = DTI_SA_ON;
181 uart_data->dtx->st_line_sb = DTI_SB_ON;
182 uart_data->dtx->st_break_len = DTI_BREAK_OFF;
183 uart_data->dtx->detect_escape = TRUE;
184 uart_data->dtx->lines_changed = FALSE;
185 uart_data->dtx->receiving_state = UART_DTX_NOT_RECEIVING;
186 uart_data->dtx->data_flow = UART_FLOW_DISABLED;
187 dtx_set_esd_state( UART_ESD_NULL );
188 uart_data->dtx->esd_guard_time = 0;
189 uart_data->dtx->esd_pos = 0;
190 uart_data->dtx->dti_dtx_state = DTI_CLOSED;
191
192 INIT_STATE( UART_SERVICE_DTX , DTX_DEAD );
193 }
194 } /* dtx_init() */
195
196
197
198 /*
199 +------------------------------------------------------------------------------
200 | Function : dtx_free_resources
201 +------------------------------------------------------------------------------
202 | Description : The function dtx_free_resources() frees the currently allocated
203 | resources of the service DTX.
204 |
205 | Parameters : none
206 |
207 +------------------------------------------------------------------------------
208 */
209 GLOBAL void dtx_free_resources ()
210 {
211 TRACE_FUNCTION( "dtx_free_resources()" );
212
213 /*
214 * free all resources
215 */
216 if(uart_data->dtx->to_send_data)
217 {
218 MFREE_DESC2( uart_data->dtx->to_send_data );
219 uart_data->dtx->to_send_data = NULL;
220 }
221 uart_data->dtx->cur_desc_size = 0;
222 uart_data->dtx->write_pos = 0;
223
224 } /* dtx_free_resources() */
225
226 /*
227 +------------------------------------------------------------------------------
228 | Function : dtx_exit
229 +------------------------------------------------------------------------------
230 | Description : The function dtx_exit() frees the currently allocated
231 | resources of the service DTX.
232 |
233 | Parameters : none
234 |
235 +------------------------------------------------------------------------------
236 */
237 GLOBAL void dtx_exit ()
238 {
239 ULONG i;
240
241 TRACE_FUNCTION( "dtx_exit()" );
242
243 /*
244 * free all resources
245 */
246 if(uart_data->dtx->to_send_data)
247 {
248 MFREE_DESC2( uart_data->dtx->to_send_data );
249 uart_data->dtx->to_send_data = NULL;
250 }
251 uart_data->dtx->cur_desc_size = 0;
252 uart_data->dtx->write_pos = 0;
253
254 if(uart_data->ker.tx_data_waiting)
255 {
256 MFREE_DESC2(uart_data->ker.tx_data_waiting);
257 uart_data->ker.tx_data_waiting = NULL;
258 }
259 for(i = 0; i < UART_MAX_NUMBER_OF_CHANNELS; i++)
260 {
261 if(uart_data->dlc_table[i].transmit_data)
262 {
263 MFREE_DESC2(uart_data->dlc_table[i].transmit_data);
264 uart_data->dlc_table[i].transmit_data = NULL;
265 }
266
267 if(uart_data->dlc_table[i].receive_data)
268 {
269 MFREE_DESC2(uart_data->dlc_table[i].receive_data);
270 uart_data->dlc_table[i].receive_data = NULL;
271 }
272 }
273
274 } /* dtx_exit() */
275
276
277 /*
278 +------------------------------------------------------------------------------
279 | Function : dtx_allocate_resources
280 +------------------------------------------------------------------------------
281 | Description : The function dtx_allocate_resources() allocates a new set of
282 | resources for the service DTX.
283 |
284 | Parameters : none
285 |
286 +------------------------------------------------------------------------------
287 */
288 GLOBAL void dtx_allocate_resources ()
289 {
290 TRACE_FUNCTION( "dtx_allocate_resources()" );
291
292 /*
293 * allocate a new descriptor
294 * with a size of: size_multiplier * N1 (frame size)
295 */
296 uart_data->dtx->cur_desc_size = uart_data->n1 *
297 uart_data->dtx->size_multiplier;
298 MALLOC(uart_data->dtx->to_send_data,
299 (USHORT)(sizeof(T_desc2) - 1 + uart_data->dtx->cur_desc_size));
300 uart_data->dtx->to_send_data->len = 0;
301 uart_data->dtx->to_send_data->size = 0;
302 uart_data->dtx->to_send_data->offset = 0;
303 uart_data->dtx->to_send_data->next = (ULONG) NULL;
304 uart_data->dtx->write_pos = 0;
305 } /* dtx_allocate_resources() */
306
307
308
309 /*
310 +------------------------------------------------------------------------------
311 | Function : dtx_calculate_size_multiplier
312 +------------------------------------------------------------------------------
313 | Description : The function dtx_calculate_size_multiplier() calculates the new
314 | size_multiplier value.
315 |
316 | Parameters : desc_to_send - data descriptor that should be sent
317 | data_flow - state of data flow befor we want to sent
318 |
319 +------------------------------------------------------------------------------
320 */
321 GLOBAL void dtx_calculate_size_multiplier (T_desc2* desc_to_send,
322 T_DATA_FLOW_STATE data_flow)
323 {
324 TRACE_FUNCTION( "dtx_calculate_size_multiplier()" );
325
326 /*
327 * calculate new size multiplier according to fillrate of buffer
328 */
329 if((uart_data->dtx->size_multiplier < UART_DTX_MAX_SIZE_MULTIPLIER ) &&
330 (data_flow EQ UART_FLOW_DISABLED))
331 {
332 /*
333 * buffer is rather full, so increase the multiplier
334 */
335 #ifdef _SIMULATION_
336 TRACE_EVENT( " sig_rx_dtx_data_received_ind(): buffer size_multiplier increased " );
337 #endif /* _SIMULATION_ */
338 uart_data->dtx->size_multiplier++;
339 }
340 else if((uart_data->dtx->size_multiplier > 3) &&
341 (data_flow EQ UART_FLOW_ENABLED) &&
342 ((uart_data->dtx->cur_desc_size - desc_to_send->len) >
343 ((USHORT)uart_data->n1 << 1)))
344 {
345 /*
346 * buffer is rather empty, so decrease the multiplier
347 */
348 #ifdef _SIMULATION_
349 TRACE_EVENT( " sig_rx_dtx_data_received_ind(): buffer size_multiplier decreased " );
350 #endif /* _SIMULATION_ */
351 uart_data->dtx->size_multiplier--;
352 }
353 } /* dtx_calculate_size_multiplier() */