comparison g23m-aci/aci/ati_io.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 : GSM-F&D (8411)
4 | Modul : ATI
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 #ifndef ATI_IO_C
22 #define ATI_IO_C
23
24 #include "config.h"
25 #include "fixedconf.h"
26 #include "condat-features.h"
27 #include "aci_conf.h"
28
29 #undef DUMMY_ATI_STRINGS
30
31 #include "aci_all.h"
32 #include "aci.h"
33 #ifdef UART
34 #include "dti.h" /* functionality of the dti library */
35 #endif
36 #include "aci_cmh.h"
37 #include "ati_cmd.h"
38 #include "aci_io.h"
39 #include "aci_cmd.h"
40 #include "l4_tim.h"
41
42 #include "aci_lst.h"
43
44 #ifdef UART
45 #include "dti_conn_mng.h"
46 #include "psa_uart.h"
47 #include "cmh_uart.h"
48 #endif
49
50 #include "ati_io.h"
51 #include "aci_mem.h"
52 #include "aci_fd.h"
53 #include "psa.h"
54 #include "cmh.h"
55
56 #include "cmh_cc.h"
57 #include "psa_cc.h"
58
59 #include "ati_int.h"
60
61 #if !defined (STRACE_LEN)
62 #define STRACE_LEN 80
63 #endif
64
65 #define LIST_MAX_LENGTH 30
66
67 /*
68 +--------------------------------------------------------------------+
69 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
70 | STATE : code ROUTINE : io_SendMessage |
71 +--------------------------------------------------------------------+
72
73 PURPOSE :
74 */
75
76 GLOBAL void io_sendMessage(UBYTE srcId, CHAR *msg,
77 T_ATI_OUTPUT_TYPE output_type)
78 {
79 T_ATI_SRC_PARAMS *src_params;
80
81 src_params = find_element (ati_src_list, srcId, search_ati_src_id);
82 if (src_params EQ NULL)
83 {
84 TRACE_EVENT_P1 ("[ERR] io_sendMessage: srcId=%d not found", srcId);
85 return;
86 }
87 if (IS_INDICATION_OUTPUT (output_type))
88 {
89 io_sendIndication(srcId, msg, output_type);
90 return;
91 }
92 else if (!IS_ECHO_OUTPUT ( output_type)) /* ECHO_OUTPUT must not be terminated */
93 { /* with CRLF, see definition in ati_cmh.h */
94 output_type |= ATI_END_CRLF_OUTPUT;
95 }
96
97 if (src_params->result_cb NEQ NULL)
98 {
99 src_params->result_cb (srcId, output_type,
100 (UBYTE*)msg, (USHORT)strlen (msg));
101 }
102 else
103 {
104 TRACE_EVENT_P1 ("[WRN] io_sendMessage: no result callback srcId=%d",
105 srcId);
106
107 if ( (strlen (msg)) >= STRACE_LEN )
108 {
109 /* terminate traced string if too long */
110 msg[STRACE_LEN-1] = '\0';
111 }
112
113 TRACE_EVENT_P1 ("%s", msg);
114 }
115 }
116
117
118 /*
119 +--------------------------------------------------------------------+
120 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
121 | STATE : code ROUTINE : io_SendMessageEx |
122 +--------------------------------------------------------------------+
123
124 PURPOSE :
125 */
126
127 GLOBAL BOOL check_should_buffer_ind(T_ATI_SRC_PARAMS *src_params)
128 {
129
130 switch(src_params->buff_uns_mode)
131 {
132 case(NO_BUFF):
133 break;
134
135 case(BUFF_TYPING):
136 if(src_params->cmd_state EQ CMD_TYPING)
137 {
138 TRACE_EVENT("check_should_buffer_ind(): cmd_state EQ CMD_TYPING");
139 return(TRUE);
140 }
141 break;
142
143 case(BUFF_RUNNING):
144 if(src_params->cmd_state NEQ CMD_IDLE )
145 {
146 TRACE_EVENT("check_should_buffer_ind(): cmd_state NEQ CMD_IDLE");
147 return(TRUE);
148 }
149 break;
150 }
151 return(FALSE);
152 }
153
154 LOCAL void buffer_indication( T_ATI_SRC_PARAMS *src_params,
155 CHAR *msg,
156 T_ATI_OUTPUT_TYPE output_type )
157 {
158 T_ATI_INDIC_BUFF *buff_indic_elem;
159 CHAR *output;
160
161 if(src_params->indication_buffer EQ NULL)
162 {
163 src_params->indication_buffer = new_list ();
164 }
165
166 ACI_MALLOC(output, (USHORT)(strlen(msg)+1));
167 memcpy(output, msg, (USHORT)(strlen(msg)+1));
168
169 ACI_MALLOC( buff_indic_elem, sizeof(T_ATI_INDIC_BUFF) );
170 buff_indic_elem->output = output;
171 buff_indic_elem->output_type = output_type;
172 /* if list count is the maximum then the available elements are reused*/
173 if(get_list_count(src_params->indication_buffer) >= LIST_MAX_LENGTH)
174 {
175 insert_shift_list(src_params->indication_buffer, buff_indic_elem);
176 }
177 else
178 {
179 insert_list( src_params->indication_buffer, buff_indic_elem);
180 }
181
182 if ( (strlen (msg)) >= STRACE_LEN )
183 {
184 /* terminate traced string if too long */
185 msg[STRACE_LEN-1] = '\0';
186 }
187
188 TRACE_EVENT_P2("buffering on src %d: %s", src_params->src_id, msg);
189 }
190
191 GLOBAL void io_sendMessageEx (UBYTE srcId, CHAR *msg,
192 T_ATI_OUTPUT_TYPE output_type)
193 {
194 T_ATI_SRC_PARAMS *src_params;
195
196 src_params = find_element (ati_src_list, srcId, search_ati_src_id);
197 if (src_params EQ NULL)
198 {
199 TRACE_EVENT_P1 ("[ERR] io_sendMessageEx: srcId=%d not found", srcId);
200 return;
201 }
202
203 /*
204 * ATQ suppesses intermidiate, final and unsolicited result codes.
205 * Only information text in responce to commands is not affected.
206 */
207 if(IS_CONFIRM_OUTPUT(output_type))
208 {
209 io_setCommandState(src_params, ATI_LINE_STATE_END);
210 }
211
212 if (ati_user_output_cfg[srcId].atQ)
213 {
214 if(! IS_NORMAL_OUTPUT(output_type) AND ! IS_ECHO_OUTPUT(output_type))
215 {
216 return;
217 }
218 }
219
220 if ( IS_INDICATION_OUTPUT (output_type)
221 AND check_should_buffer_ind(src_params) )
222 {
223 buffer_indication( src_params, msg, output_type );
224 return;
225 }
226
227 if (src_params->result_cb NEQ NULL)
228 {
229 src_params->result_cb (srcId, output_type,
230 (UBYTE*)msg, (USHORT)strlen (msg));
231 }
232 else
233 {
234 TRACE_EVENT_P1 ("[WRN] io_sendMessageEx: no result callback srcId=%d",
235 srcId);
236
237 if ( (strlen (msg)) >= STRACE_LEN )
238 {
239 /* terminate traced string if too long */
240 msg[STRACE_LEN-1] = '\0';
241 }
242
243 TRACE_EVENT_P1 ("%s", msg);
244 }
245 }
246
247 /*
248 +--------------------------------------------------------------------+
249 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
250 | STATE : code ROUTINE : io_SendIndication |
251 +--------------------------------------------------------------------+
252
253 PURPOSE :
254 */
255
256 GLOBAL void io_sendIndication(UBYTE srcId, CHAR *msg,
257 T_ATI_OUTPUT_TYPE output_type)
258 {
259 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
260
261 if (src_params EQ NULL)
262 {
263 TRACE_EVENT_P1 ("[ERR] io_sendIndication: srcId=%d not found", srcId);
264 return;
265 }
266
267 /*
268 * ATQ suppesses intermidiate, final and unsolicited result codes.
269 * Only information text in responce to commands is not affected.
270 */
271 if (ati_user_output_cfg[srcId].atQ)
272 {
273 return;
274 }
275
276 output_type |= ATI_INDICATION_OUTPUT |
277 ATI_BEGIN_CRLF_OUTPUT |
278 ATI_END_CRLF_OUTPUT;
279
280 if ( check_should_buffer_ind(src_params) )
281 {
282 buffer_indication( src_params, msg, output_type );
283 return;
284 }
285 if (src_params->result_cb NEQ NULL)
286 {
287 src_params->result_cb (srcId, output_type,
288 (UBYTE*)msg, (USHORT)strlen (msg));
289 }
290 else
291 {
292 TRACE_EVENT_P1 ("[WRN] io_sendIndication: no result callback srcId=%d",
293 srcId);
294
295 if ( (strlen (msg)) >= STRACE_LEN )
296 {
297 /* terminate traced string if too long */
298 msg[STRACE_LEN-1] = '\0';
299 }
300
301 TRACE_EVENT_P1 ("%s", msg);
302 }
303 }
304
305
306
307 /*
308 +--------------------------------------------------------------------+
309 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
310 | STATE : code ROUTINE : io_sendConfirm |
311 +--------------------------------------------------------------------+
312
313 PURPOSE : output to AT interface
314 */
315
316 GLOBAL void send_buffered_indication( T_ATI_SRC_PARAMS *src_params )
317 {
318 BOOL go_on = TRUE;
319 T_ATI_INDIC_BUFF *indic = src_params->indication_buffer; /* to be sure it's not NULL */
320
321 TRACE_EVENT_P1("send buffered indications for source: %d", src_params->src_id);
322 while( go_on )
323 {
324 indic = remove_first_element( src_params->indication_buffer );
325
326 if( indic NEQ NULL )
327 {
328 io_sendIndication( src_params->src_id,
329 indic->output,
330 indic->output_type );
331 ACI_MFREE( indic->output );
332 ACI_MFREE( indic );
333 }
334 else
335 {
336 ACI_MFREE( src_params->indication_buffer );
337 src_params->indication_buffer = NULL;
338 go_on = FALSE;
339 }
340 }
341 }
342
343 GLOBAL void io_sendConfirm(UBYTE srcId, CHAR *msg,
344 T_ATI_OUTPUT_TYPE output_type)
345 {
346 BOOL is_CONNECT = FALSE;
347 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
348
349 TRACE_FUNCTION("io_sendConfirm()");
350
351 if (src_params EQ NULL)
352 {
353 TRACE_EVENT_P1 ("[ERR] io_sendConfirm: srcId=%d not found", srcId);
354 return;
355 }
356
357 if (BITFIELD_CHECK (output_type, ATI_CONNECT_OUTPUT))
358 {
359 is_CONNECT = TRUE;
360 BITFIELD_CLEAR (output_type, ATI_CONNECT_OUTPUT);/*lint !e64 (Warning: type mismatch)*/
361 }
362
363 output_type |= ATI_CONFIRM_OUTPUT |
364 ATI_BEGIN_CRLF_OUTPUT |
365 ATI_END_CRLF_OUTPUT;
366
367 if (src_params->result_cb NEQ NULL)
368 {
369 /*
370 * ATQ suppesses intermidiate, final and unsolicited result codes.
371 * Only information text in responce to commands is not affected.
372 */
373 if (ati_user_output_cfg[srcId].atQ EQ 0)
374 {
375 src_params->result_cb (srcId, output_type,
376 (UBYTE*)msg, (USHORT)strlen (msg));
377 }
378 }
379 else
380 {
381 TRACE_EVENT_P1 ("[WRN] io_sendConfirm: no result callback srcId=%d",
382 srcId);
383
384 if ( (strlen (msg)) >= STRACE_LEN )
385 {
386 /* terminate traced string if too long */
387 msg[STRACE_LEN-1] = '\0';
388 }
389
390 TRACE_EVENT_P1 ("%s", msg);
391 }
392
393 io_setCommandState(src_params, ATI_LINE_STATE_END);
394 trace_cmd_state(src_params->src_id, src_params->cmd_state, CMD_IDLE);
395 src_params->cmd_state = CMD_IDLE;
396
397 if ((src_params->indication_buffer NEQ NULL) /* send buffered indications */
398 AND (is_CONNECT EQ FALSE)) /* but for data call not yet --> when back in CMD mode */
399 {
400 send_buffered_indication( src_params );
401 }
402 }
403
404 /*
405 +-------------------------------------------------------------------+
406 | PROJECT : GSM-PS (6147) MODULE : CMH_DTIS |
407 | ROUTINE : io_sendChar |
408 +-------------------------------------------------------------------+
409
410 PURPOSE : send one character through DTI
411 */
412
413 GLOBAL void io_sendChar (CHAR out, UBYTE srcId)
414 {
415 T_ATI_SRC_PARAMS *src_params;
416
417 src_params = find_element (ati_src_list, srcId, search_ati_src_id);
418 if (src_params EQ NULL)
419 {
420 TRACE_EVENT_P1 ("[ERR] io_sendChar: srcId=%d not found", srcId);
421 return;
422 }
423 if (src_params->result_cb NEQ NULL)
424 {
425 src_params->result_cb (srcId, ATI_ECHO_OUTPUT, (UBYTE*)&out, 1);
426 }
427 else
428 {
429 TRACE_EVENT_P1 ("[WRN] io_sendChar: no result callback srcId=%d",
430 srcId);
431 }
432 }
433
434
435 /*
436 +--------------------------------------------------------------------+
437 | PROJECT : GSM-F&D (8411) MODULE : ACI_URT |
438 | STATE : code ROUTINE : io_setRngInd |
439 +--------------------------------------------------------------------+
440
441 PURPOSE: sets the V.24 ring indicator line
442
443 */
444 GLOBAL void io_setRngInd (T_IO_RING_STAT state, T_ACI_CRING_SERV_TYP bt1, T_ACI_CRING_SERV_TYP bt2)
445 {
446 T_ATI_SRC_PARAMS *src_params;
447 T_IO_RING_PARAMS ring_params;
448
449 src_params = get_next_element (ati_src_list, NULL);
450 while (src_params NEQ NULL)
451 {
452 if (src_params->line_state_cb NEQ NULL)
453 {
454 ring_params.ring_stat = state;
455 ring_params.b_cap_1 = bt1;
456 ring_params.b_cap_2 = bt2;
457
458 src_params->line_state_cb (src_params->src_id,
459 ATI_LINE_STATE_RNG,
460 (ULONG)&ring_params);
461 }
462 src_params = get_next_element (ati_src_list, src_params);
463 }
464 }
465
466 /*
467 +--------------------------------------------------------------------+
468 | PROJECT : GSM-F&D (8411) MODULE : ACI_URT |
469 | STATE : code ROUTINE : io_setDCD |
470 +--------------------------------------------------------------------+
471
472 PURPOSE: sets the V.24 data carrier detect line
473
474 */
475 #ifdef UART
476 GLOBAL void io_setDCD (T_ACI_CMD_SRC src_id, T_IO_DCD_STAT state)
477 {
478 T_ATI_SRC_PARAMS *src_params;
479 T_ACI_DCD_MOD ATandC_setting;
480
481 TRACE_FUNCTION("io_setDCD()");
482
483 src_params = find_element (ati_src_list, (UBYTE)src_id, search_ati_src_id);
484 if (src_params EQ NULL)
485 {
486 TRACE_EVENT_P1 ("[ERR] io_setDCD: srcId=%d not found", src_id);
487 return;
488 }
489
490 qAT_AndC(src_id, &ATandC_setting);
491
492 /* don't set DCD off if DCD shall be allways on */
493 if( (ATandC_setting EQ DCD_ALWAYS_ON) AND
494 (state EQ IO_DCD_OFF ) )
495 {
496 TRACE_EVENT ("[DBG] io_setDCD: DCD_ALWAYS_ON");
497 return;
498 }
499
500 if (src_params->line_state_cb NEQ NULL)
501 {
502 src_params->line_state_cb ((UBYTE)src_id, ATI_LINE_STATE_DCD, (ULONG)state);
503 }
504 else
505 {
506 TRACE_EVENT_P1 ("[WRN] io_setDCD: no callback for srcId=%d", src_id);
507 }
508 }
509 #endif /* UART */
510 /*
511 +--------------------------------------------------------------------+
512 | PROJECT : GSM-F&D (8411) MODULE : ACI_URT |
513 | STATE : code ROUTINE : io_setCommandState |
514 +--------------------------------------------------------------------+
515
516 PURPOSE: sets the command state to start or end
517
518 */
519 #define UNUSED_ULONG_PARAMETER (ULONG) 0L
520
521 GLOBAL void io_setCommandState(T_ATI_SRC_PARAMS *src_params, T_ATI_LINE_STATE_TYPE line_state_type)
522 {
523
524 TRACE_FUNCTION("io_setCommandState()");
525
526 if (src_params->line_state_cb NEQ NULL)
527 {
528 src_params->line_state_cb (src_params->src_id, line_state_type, UNUSED_ULONG_PARAMETER);
529 }
530 else
531 {
532 TRACE_EVENT_P1 ("[WRN] io_setCommandState: no callback for srcId=%d",
533 src_params->src_id);
534 }
535 }
536
537 #endif /* ATI_IO_C */
538