comparison src/g23m-aci/aci/ati_io.c @ 162:53929b40109c

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