comparison gsm-fw/g23m-aci/uart/uart_dtxf.c @ 775:eedbf248bac0

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