comparison src/g23m-aci/aci/ati_src_uart.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 : GSM-PS (6147)
4 | Modul : ATI_SRC_UARTC
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 : .
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifdef UART
22
23 #ifndef ATI_SRC_UART_C
24 #define ATI_SRC_UART_C
25 #endif
26
27 #include "aci_all.h"
28 /*==== INCLUDES ===================================================*/
29 #include "aci_cmh.h"
30 #include "ati_cmd.h"
31 #include "aci_cmd.h"
32 #include "dti.h" /* functionality of the dti library */
33
34 #include "aci_lst.h"
35 #include "dti_conn_mng.h"
36 #include "dti_cntrl_mng.h"
37
38 #ifdef UART
39 #include "psa_uart.h"
40 #include "cmh_uart.h"
41 #endif
42
43 #include "aci_io.h"
44
45 #ifdef UART
46 #include "ati_src_uart.h"
47 #endif
48
49 #include "aci_mem.h"
50 #include "aci.h"
51 #include "psa.h"
52 #include "cmh.h"
53
54 /*==== CONSTANTS ==================================================*/
55
56 /*==== TYPES ======================================================*/
57
58 /*==== EXPORT =====================================================*/
59
60 EXTERN T_ACI_LIST *uart_src_params;
61 #ifdef _SIMULATION_
62 EXTERN T_ACI_LIST *ati_src_list;
63 #endif /* _SIMULATION_ */
64
65 /*==== VARIABLES ==================================================*/
66
67 /*==== FUNCTIONS ==================================================*/
68
69 /*
70 +-------------------------------------------------------------------+
71 | PROJECT : GSM-PS (6147) MODULE : CMH_DTIR |
72 | ROUTINE : uart_new_source |
73 +-------------------------------------------------------------------+
74
75 PURPOSE : Create a new source for ATI with the corresponding struct.
76 */
77
78 #ifdef UART
79 GLOBAL void uart_InitCmdStruct( T_ACI_DTI_PRC *cmd_struct )
80 {
81 cmd_struct->device = 0;
82 cmd_struct->dlci = NOT_PRESENT_8BIT;
83 cmd_struct->RecState = NOT_INITIALIZED;
84 cmd_struct->LineState = LINE_CONNECTING;
85 cmd_struct->run_cmd = FALSE;
86 cmd_struct->first_output = FALSE;
87 cmd_struct->data_cntr = 0;
88 cmd_struct->MuxParms = NULL;
89 cmd_struct->large_type = FALSE;
90 cmd_struct->data_buffer.data_list = NULL;
91 cmd_struct->data_buffer.max_buffer_size = 0;
92 cmd_struct->data_buffer.create_time = 0;
93 cmd_struct->device_type = DEVICE_TYPE_UNKNOWN;
94 }
95 #endif
96
97 GLOBAL UBYTE uart_new_source( UBYTE device, UBYTE dlci )
98 {
99 T_ACI_DTI_PRC *cmd_struct;
100 UBYTE src_id;
101
102 TRACE_FUNCTION("uart_new_source");
103
104 src_id = ati_init(ATI_SRC_TYPE_UART, uart_src_result_cb, uart_src_line_state_cb);
105
106 TRACE_EVENT_P1 ("uart_new_source: srcId=%d", src_id);
107
108 ACI_MALLOC (cmd_struct, sizeof(T_ACI_DTI_PRC));
109
110 #ifdef UART
111 uart_InitCmdStruct( cmd_struct );
112 #endif
113
114 cmd_struct->srcId = src_id;
115 cmd_struct->device = device;
116 cmd_struct->dlci = dlci;
117
118 /*
119 * Determine the mode of the command source based on the
120 * source ID.
121 */
122 if (src_id<CMD_SRC_MAX)
123 {
124 if (src_id==CMD_SRC_LCL)
125 {
126 aci_cmd_src_mode_set(src_id,CMD_MODE_ACI);
127 }
128 else
129 {
130 #ifdef FF_ATI_BAT
131 aci_cmd_src_mode_set(src_id,CMD_MODE_BAT);
132 #else
133 aci_cmd_src_mode_set(src_id,CMD_MODE_ATI);
134 #endif
135 }
136 }
137
138 insert_list (uart_src_params, cmd_struct);
139 cmhUART_AddDeviceToComParameter( device );
140
141 return(src_id);
142 }
143
144 #ifdef _SIMULATION_
145 GLOBAL void uart_new_source_for_aci_src_tst( UBYTE src_id, UBYTE device, UBYTE dlci )
146 {
147 T_ACI_DTI_PRC *cmd_struct;
148
149 TRACE_FUNCTION("uart_new_source_for_aci_src_tst");
150
151 ACI_MALLOC (cmd_struct, sizeof(T_ACI_DTI_PRC));
152
153 #ifdef UART
154 uart_InitCmdStruct( cmd_struct );
155 #endif
156
157 cmd_struct->srcId = src_id;
158 cmd_struct->device = device;
159 cmd_struct->dlci = dlci;
160
161 /*
162 * Determine the mode of the command source based on the
163 * source ID.
164 */
165 if (src_id<CMD_SRC_MAX)
166 {
167 if (src_id==CMD_SRC_LCL)
168 {
169 aci_cmd_src_mode_set(src_id,CMD_MODE_ACI);
170 }
171 else
172 {
173 #ifdef FF_ATI_BAT
174 aci_cmd_src_mode_set(src_id,CMD_MODE_BAT);
175 #else
176 aci_cmd_src_mode_set(src_id,CMD_MODE_ATI);
177 #endif
178 }
179 }
180
181 insert_list (uart_src_params, cmd_struct);
182 cmhUART_AddDeviceToComParameter( device );
183 }
184 #endif
185 /*
186 +-------------------------------------------------------------------+
187 | PROJECT : GSM-PS (6147) MODULE : CMH_DTIR |
188 | ROUTINE : uart_erase_source |
189 +-------------------------------------------------------------------+
190
191 PURPOSE : erase an entry element from the uart_src_params list.
192 */
193 #ifdef DTI
194 EXTERN void dti_cntrl_erase_entry(UBYTE dti_id);
195 #endif
196
197 GLOBAL void uart_erase_source( UBYTE srcId )
198 {
199 #ifdef DTI
200 T_DTI_CNTRL info;
201 #endif
202
203 TRACE_FUNCTION("uart_erase_source");
204
205 ati_finit (srcId);
206 #ifdef DTI
207 dti_cntrl_get_info_from_src_id (srcId, &info);
208
209 dti_cntrl_erase_entry( info.dti_id );
210
211 dti_cntrl_clear_conn_parms( info.dti_id );
212 #endif
213 TRACE_EVENT_P1("Source nb %d deleted", srcId);
214
215 }
216 #ifdef DTI
217 /*
218 +-------------------------------------------------------------------+
219 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
220 | ROUTINE : atiUART_dti_callback |
221 +-------------------------------------------------------------------+
222
223 PURPOSE : callback for dti manager.
224
225 */
226 GLOBAL BOOL atiUART_dti_cb( UBYTE dti_id, T_DTI_CONN_STATE result_type )
227 {
228 #ifdef _SIMULATION_
229 T_ATI_SRC_PARAMS *src_params;
230 #endif /* _SIMULATION_ */
231
232 T_ACI_DTI_PRC *srcInfos = NULL;
233 UBYTE saveState;
234 BOOL is_uart_src = TRUE; /* for simulation */
235 T_DTI_CNTRL info;
236
237 TRACE_FUNCTION("atiUART_dti_cb");
238
239
240 if (dti_cntrl_get_info_from_dti_id( dti_id, &info) EQ FALSE)
241 {
242 TRACE_EVENT_P1("cannot find info for dti_id=%d", dti_id);
243 return FALSE;
244 }
245
246 srcInfos = find_element (uart_src_params, info.src_id, cmhUARTtest_srcId);
247 if (srcInfos EQ NULL)
248 {
249 TRACE_EVENT_P1 ("[ERR] atiUART_dti_cb: srcId=%d not found", info.src_id) ;
250 return FALSE ;
251 }
252
253 saveState = srcInfos->LineState;
254
255 #ifdef _SIMULATION_
256 src_params = find_element (ati_src_list, info.src_id, search_ati_src_id);
257 if (src_params EQ NULL)
258 {
259 TRACE_EVENT ("[ERR] SIMULATION: atiUART_dti_cb: source ID not found");
260 return FALSE;
261 }
262 if (src_params->src_type EQ ATI_SRC_TYPE_TST)
263 {
264 is_uart_src = FALSE;
265 }
266 #endif /* _SIMULATION_ */
267
268
269
270
271 switch(result_type)
272 {
273 /* UART and ACI connected */
274 /* UART and ACI connected */
275 case(DTI_CONN_STATE_CONNECTED):
276 #ifdef RMV_01_04_03
277 #ifdef FF_TWO_UART_PORTS
278 if (srcInfos->srcId EQ UART_DATA_CHANNEL)
279 {
280 srcInfos->LineState = LINE_CONNECTED;
281 return (TRUE);
282 }
283 #endif /* FF_MULTI_PORT */
284 #endif
285
286 /* first set the line state, then care for DCD */
287 srcInfos->LineState = LINE_CONNECTED;
288
289 ati_switch_mode(info.src_id, ATI_CMD_MODE);
290
291 if (saveState EQ LINE_CONNECTING)
292 {
293
294 if (is_uart_src)
295 {
296 /* creation of a new connection: set DCD */
297 io_setDCD ((T_ACI_CMD_SRC)info.src_id, IO_DCD_OFF);
298 }
299
300 #ifndef _SIMULATION_
301 /* AV2-Plattform: Inform the user about the cause for the last stack crash.
302 not (yet) enabled since this could cause problems with other customers.
303 setatPercentDAR("", srcInfos->srcId);
304 */
305 #ifdef FF_BAT
306 if (aci_cmd_src_mode_get((T_ACI_CMD_SRC)info.src_id) NEQ CMD_MODE_BAT)
307 #endif
308 {
309 io_sendMessage (srcInfos->srcId, "AT-Command Interpreter ready",
310 ATI_NORMAL_OUTPUT);
311 }
312 #endif /* _SIMULATION_ */
313 }
314
315 if (is_uart_src)
316 {
317 /* tells UART that ACI is ready to get some data */
318 cmhUART_getdata ((T_ACI_CMD_SRC)srcInfos->srcId);
319 }
320 break;
321 /* UART and data entity temporary disconnected */
322 case(DTI_CONN_STATE_CONNECTING):
323 break;
324
325 case(DTI_CONN_STATE_DISCONNECTING):
326 srcInfos->LineState = LINE_TMP_DISCONNECTING;
327 ati_switch_mode(info.src_id, ATI_DATA_MODE);
328 break;
329
330 case(DTI_CONN_STATE_DISCONNECTED):
331 srcInfos->LineState = LINE_TMP_DISCONNECTED;
332 #ifdef DTI
333 dti_cntrl_clear_conn_parms( dti_id );
334 #endif /* DTI */
335 break;
336
337 case(DTI_CONN_STATE_ERROR):
338 #ifdef DTI
339 dti_cntrl_close_dpath_from_dti_id( dti_id );
340 #endif /* DTI */
341 break;
342 default:
343 break;
344 }
345
346 /* Maybe drop call if DTR is asserted */
347 if (uartShrdPrm.dtr_clearcall EQ TRUE)
348 {
349 T_ACI_RETURN l_ret;
350
351 l_ret = sAT_H((T_ACI_CMD_SRC)info.src_id);
352 if (l_ret NEQ AT_EXCT AND l_ret NEQ AT_CMPL)
353 {
354 uartShrdPrm.dtr_clearcall = FALSE;
355 TRACE_ERROR("DTR-Drop sAT_H() error");
356 }
357 }
358
359 return TRUE;
360 }
361 #endif /* DTI */
362
363 /*
364 +-------------------------------------------------------------------+
365 | PROJECT : GSM-PS (6147) MODULE : CMH_DTIR |
366 | ROUTINE : uart_src_proc_chars |
367 +-------------------------------------------------------------------+
368
369 PURPOSE : Check if characters received are ok, and pack them into the command line.
370 return TRUE if ACI allows more data from DTI.
371 */
372
373 GLOBAL BOOL uart_src_proc_chars ( UBYTE *chars,
374 USHORT len,
375 T_ACI_DTI_PRC *elem )
376 {
377 if (len >= MAX_CMD_LEN)
378 {
379 TRACE_ERROR ("[ERR] [ATI]: command line too long");
380 return (TRUE);
381 }
382 if (elem->run_cmd)
383 {
384 ati_abort (elem->srcId);
385 }
386 else
387 {
388 ati_execute (elem->srcId, chars, len);
389 }
390 return (TRUE);
391 }
392
393 #endif /* UART */