FreeCalypso > hg > freecalypso-citrine
comparison g23m-aci/aci/ati_src_uart_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 : | |
4 | Modul : J:\g23m-aci\aci\ati_src_uart_io.c | |
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 #include "config.h" | |
22 #include "fixedconf.h" | |
23 #include "condat-features.h" | |
24 #include "aci_conf.h" | |
25 | |
26 #ifdef UART | |
27 | |
28 #ifndef ATI_SRC_UART_IO_C | |
29 #define ATI_SRC_UART_IO_C | |
30 #endif | |
31 | |
32 #include "aci_all.h" | |
33 /*==== INCLUDES ===================================================*/ | |
34 #include "aci_cmh.h" | |
35 #include "ati_cmd.h" | |
36 #include "aci_cmd.h" | |
37 #include "dti.h" /* functionality of the dti library */ | |
38 | |
39 #include "aci_lst.h" | |
40 #include "dti_conn_mng.h" | |
41 | |
42 #include "psa_uart.h" | |
43 #include "cmh_uart.h" | |
44 | |
45 #ifdef _SIMULATION_ | |
46 #include "aci.h" | |
47 #include "ati_src_tst.h" | |
48 | |
49 # ifdef SMI | |
50 # undef hCommMMI | |
51 # define hCommMMI hCommSMI | |
52 # endif | |
53 | |
54 EXTERN T_ACI_LIST *ati_src_list; | |
55 #endif | |
56 | |
57 #include "aci_io.h" | |
58 #include "ati_io.h" | |
59 #include "aci_mem.h" | |
60 #include "ati_src_uart.h" | |
61 #include "aci.h" | |
62 #include "sap_dti.h" | |
63 | |
64 /*==== CONSTANTS ==================================================*/ | |
65 #define MAX_NORMAL_BUFFER_LEN (100-4) // Since Malloc uses 4 additional internal bytes of the Blocks | |
66 #ifdef GPRS | |
67 #define MAX_LARGE_BUFFER_LEN (600-4) | |
68 #else | |
69 #define MAX_LARGE_BUFFER_LEN (400-4) | |
70 #endif | |
71 /*==== TYPES ======================================================*/ | |
72 | |
73 /*==== EXPORT =====================================================*/ | |
74 | |
75 /*==== VARIABLES ==================================================*/ | |
76 /*==== FUNCTIONS ==================================================*/ | |
77 LOCAL void io_DTIsendString (UBYTE *string, USHORT string_len, | |
78 T_ACI_DTI_PRC *src_infos, | |
79 T_ATI_OUTPUT_TYPE output_type); | |
80 | |
81 /* LOCAL void uart_buffer_data(T_ACI_DTI_PRC * src_infos, T_desc2 * send_data); */ | |
82 | |
83 #ifdef _SIMULATION_ | |
84 LOCAL BOOL get_source_type( UBYTE src_id, T_ATI_SRC_TYPE *src_type ); | |
85 #endif | |
86 /*=================================================================*/ | |
87 | |
88 | |
89 GLOBAL void uart_src_result_cb (UBYTE src_id, | |
90 T_ATI_OUTPUT_TYPE output_type, | |
91 UBYTE *output, | |
92 USHORT output_len) | |
93 { | |
94 T_ACI_DTI_PRC *src_infos; | |
95 TRACE_FUNCTION("uart_src_result_cb()"); | |
96 | |
97 #ifdef RMV_01_04_03 | |
98 #ifdef FF_TWO_UART_PORTS | |
99 /* disable output to UART on data channel */ | |
100 if (src_id EQ UART_DATA_CHANNEL) | |
101 { | |
102 return; | |
103 } | |
104 #endif | |
105 #endif | |
106 src_infos = find_element (uart_src_params, (UBYTE)src_id, cmhUARTtest_srcId); | |
107 if (src_infos EQ NULL) | |
108 { | |
109 TRACE_EVENT_P1("[ERR] uart_src_result_cb: src_id=%d not found", src_id) ; | |
110 return ; | |
111 } | |
112 | |
113 switch (src_infos->LineState) | |
114 { | |
115 case LINE_CONNECTING: | |
116 case LINE_CONNECTED: | |
117 case LINE_TMP_CONNECTED: | |
118 break; | |
119 | |
120 case LINE_TMP_DISCONNECTING: | |
121 case LINE_TMP_DISCONNECTED: | |
122 if (IS_FORCED_OUTPUT (output_type) || IS_CONFIRM_OUTPUT (output_type)) | |
123 { | |
124 break; | |
125 } | |
126 return; | |
127 | |
128 case LINE_DISCONNECTED: | |
129 return; | |
130 } | |
131 | |
132 if (src_infos->first_output EQ TRUE) | |
133 { | |
134 src_infos->first_output = FALSE; | |
135 output_type |= ATI_BEGIN_CRLF_OUTPUT; | |
136 } | |
137 io_DTIsendString (output, output_len, src_infos, output_type); | |
138 } | |
139 | |
140 | |
141 GLOBAL void uart_src_line_state_cb (UBYTE src_id, | |
142 T_ATI_LINE_STATE_TYPE line_state_type, | |
143 ULONG line_state_param) | |
144 { | |
145 T_ACI_DTI_PRC *src_infos; | |
146 | |
147 TRACE_FUNCTION("uart_src_line_state_cb()"); | |
148 | |
149 src_infos = find_element (uart_src_params, (UBYTE)src_id, cmhUARTtest_srcId); | |
150 if (src_infos EQ NULL) | |
151 { | |
152 TRACE_EVENT ("[ERR] uart_src_line_state_cb: src_id not found"); | |
153 return; | |
154 } | |
155 | |
156 /* tlu: */ | |
157 /* | |
158 switch (src_infos->LineState) | |
159 { | |
160 case LINE_TMP_DISCONNECTED: | |
161 case LINE_DISCONNECTED: | |
162 return; | |
163 } | |
164 */ | |
165 | |
166 switch (line_state_type) | |
167 { | |
168 case ATI_LINE_STATE_OUTPUT_TYPE: | |
169 TRACE_EVENT_P1 ("output type: %d",line_state_param); | |
170 src_infos->run_cmd = TRUE; | |
171 src_infos->first_output = TRUE; | |
172 | |
173 if( line_state_param EQ ATI_OUTPUT_TYPE_LARGE ) | |
174 { | |
175 src_infos->large_type = TRUE; | |
176 } | |
177 else | |
178 { | |
179 src_infos->large_type = FALSE; | |
180 } | |
181 break; | |
182 | |
183 case ATI_LINE_STATE_DCD: | |
184 | |
185 if(line_state_param EQ IO_DCD_ON) | |
186 { | |
187 BITFIELD_SET (src_infos->data_cntr, UART_DTI_SB_BIT); | |
188 } | |
189 else | |
190 { | |
191 BITFIELD_CLEAR (src_infos->data_cntr, UART_DTI_SB_BIT); | |
192 } | |
193 /* tlu: */ | |
194 /* | |
195 if (src_infos->LineState EQ LINE_CONNECTED) | |
196 { | |
197 psaUART_DCDreq( src_id, (UBYTE)line_state_param ); | |
198 } | |
199 */ | |
200 psaUART_DCDreq( src_id, (UBYTE)line_state_param ); | |
201 | |
202 break; | |
203 | |
204 case ATI_LINE_STATE_RNG: | |
205 { | |
206 T_IO_RING_PARAMS rng_params; | |
207 #ifdef RMV_01_04_03 | |
208 #ifdef FF_TWO_UART_PORTS | |
209 /* disable RING on data channel */ | |
210 if (src_id EQ UART_DATA_CHANNEL) | |
211 { | |
212 break; | |
213 } | |
214 #endif | |
215 #endif | |
216 memcpy (&rng_params, (T_IO_RING_PARAMS*)line_state_param, | |
217 sizeof(T_IO_RING_PARAMS)); | |
218 psaUART_RINGreq( src_id, (UBYTE)rng_params.ring_stat ); | |
219 break; | |
220 } | |
221 | |
222 case ATI_LINE_STATE_START: | |
223 break; | |
224 | |
225 case ATI_LINE_STATE_END: | |
226 src_infos->run_cmd = FALSE; | |
227 break; | |
228 | |
229 default: | |
230 { | |
231 TRACE_EVENT_P1("[WRN] uart_src_line_state_cb (): "\ | |
232 "UNKNOWN line_state_type = %d", line_state_type); | |
233 break; | |
234 } | |
235 } | |
236 } | |
237 | |
238 LOCAL T_desc2 *get_last_buffer (T_desc2 *data_head) | |
239 { | |
240 T_desc2 *next_data; | |
241 | |
242 if (data_head EQ NULL) | |
243 { | |
244 return (NULL); | |
245 } | |
246 | |
247 next_data = data_head; | |
248 while ((T_desc2*)next_data->next NEQ NULL) | |
249 { | |
250 next_data = (T_desc2*)next_data->next; | |
251 } | |
252 | |
253 return (next_data); | |
254 } | |
255 | |
256 | |
257 LOCAL T_desc2 *get_new_buffer (BOOL large_type, USHORT *max_buffer_size) | |
258 { | |
259 T_desc2 *new_buffer; | |
260 | |
261 if (large_type EQ TRUE) | |
262 *max_buffer_size = MAX_LARGE_BUFFER_LEN; | |
263 else | |
264 *max_buffer_size = MAX_NORMAL_BUFFER_LEN; | |
265 | |
266 ACI_MALLOC (new_buffer, *max_buffer_size); | |
267 *max_buffer_size -= (sizeof(T_desc2) - 1); | |
268 | |
269 new_buffer->next = (ULONG)NULL; | |
270 new_buffer->len = 0; | |
271 new_buffer->size = *max_buffer_size; | |
272 new_buffer->offset = 0; | |
273 | |
274 return (new_buffer); | |
275 } | |
276 | |
277 LOCAL void free_data_buffer (T_ACI_DTI_DATA_BUF *data_buffer) | |
278 { | |
279 T_desc2 *p_desc=NULL,*p_desc_next=NULL; | |
280 | |
281 if (data_buffer->data_list EQ NULL) | |
282 { | |
283 return; | |
284 } | |
285 | |
286 p_desc = data_buffer->data_list; | |
287 if (p_desc NEQ NULL) | |
288 { | |
289 p_desc_next = (T_desc2 *)p_desc->next; | |
290 } | |
291 | |
292 while (p_desc NEQ NULL) | |
293 { | |
294 ACI_MFREE (p_desc); | |
295 | |
296 p_desc = p_desc_next; | |
297 if (p_desc NEQ NULL) | |
298 { | |
299 p_desc_next = (T_desc2 *)p_desc->next; | |
300 } | |
301 } | |
302 | |
303 data_buffer->data_list = NULL; | |
304 data_buffer->max_buffer_size = 0; | |
305 data_buffer->create_time = 0; | |
306 } | |
307 | |
308 | |
309 GLOBAL void uart_buffer_data (T_ACI_DTI_PRC *src_infos, T_desc2 *send_data) | |
310 { | |
311 T_desc2 *active_buffer, *last_buffer; | |
312 USHORT i, j; | |
313 T_TIME current_time; | |
314 TRACE_FUNCTION("uart_buffer_data()"); | |
315 | |
316 last_buffer = get_last_buffer(src_infos->data_buffer.data_list); | |
317 active_buffer = last_buffer; | |
318 | |
319 if (last_buffer EQ NULL) | |
320 { | |
321 active_buffer = get_new_buffer (src_infos->large_type, | |
322 &src_infos->data_buffer.max_buffer_size); | |
323 src_infos->data_buffer.data_list = active_buffer; | |
324 last_buffer = active_buffer; | |
325 /* store the creation time for the data buffer */ | |
326 vsi_t_time (VSI_CALLER &src_infos->data_buffer.create_time); | |
327 } | |
328 else | |
329 { | |
330 /* | |
331 If no device is connected to UART it is possible that the buffer | |
332 use all available memory. | |
333 Solution: | |
334 When the line is connected, check the life time of the | |
335 data buffer. Remove the buffer if the live time is greater than | |
336 30 sec. (only if line is in data mode (line is disconnected)). | |
337 */ | |
338 // if (src_infos->LineState EQ LINE_CONNECTED) // line is always connected | |
339 { | |
340 vsi_t_time (VSI_CALLER ¤t_time); | |
341 if ((current_time - src_infos->data_buffer.create_time) > MAX_DATA_BUFFER_LIFE_TIME) | |
342 { | |
343 TRACE_EVENT_P1 ("[WRN] uart_buffer_data(): life time expired, buffer deleted (%d)", | |
344 current_time - src_infos->data_buffer.create_time); | |
345 free_data_buffer (&src_infos->data_buffer); | |
346 return; | |
347 } | |
348 } | |
349 } | |
350 | |
351 i = 0; | |
352 while (i < send_data->len) | |
353 { | |
354 if (active_buffer->len EQ active_buffer->size) // (src_infos->data_buffer.max_buffer_size)) | |
355 { | |
356 active_buffer = get_new_buffer (src_infos->large_type, | |
357 &src_infos->data_buffer.max_buffer_size); | |
358 last_buffer->next = (ULONG)active_buffer; | |
359 last_buffer = active_buffer; | |
360 } | |
361 // Optimize for Speed | |
362 j = MINIMUM((active_buffer->size - active_buffer->len), (send_data->len - i)); | |
363 if (j>1) | |
364 { | |
365 memcpy((char *)&active_buffer->buffer[active_buffer->len], (char *)&send_data->buffer[i], j);/*lint !e670 (Warning: Possible access beyond array for function)*/ | |
366 active_buffer->len += j; | |
367 i += j; | |
368 } | |
369 else | |
370 active_buffer->buffer[active_buffer->len++] = send_data->buffer[i++]; | |
371 } | |
372 } | |
373 | |
374 | |
375 GLOBAL void uart_send_buffer_data (UBYTE src_id) | |
376 { | |
377 T_ACI_DTI_PRC *src_infos = NULL; | |
378 | |
379 TRACE_FUNCTION("uart_send_buffer_data()"); | |
380 | |
381 /* dti_id should be supported by DTI_ENTITY_ID or something, here.. */ | |
382 src_infos = find_element (uart_src_params, src_id, | |
383 cmhUARTtest_srcId); | |
384 #ifdef DTI | |
385 if (aci_src_dti_params[src_id].isDtiConnected EQ FALSE) | |
386 { | |
387 TRACE_EVENT ("DTI_READY_IND: line not connected"); | |
388 return; | |
389 } | |
390 #endif /* DTI */ | |
391 /* | |
392 * send data which may have been stored .. | |
393 */ | |
394 if (src_infos->data_buffer.data_list NEQ NULL) | |
395 { | |
396 #ifdef DTI | |
397 #ifdef _SIMULATION_ | |
398 { | |
399 T_ATI_SRC_TYPE src_type; | |
400 | |
401 if(get_source_type(src_infos->srcId, &src_type)) | |
402 { | |
403 if( ATI_SRC_TYPE_TST EQ src_type ) | |
404 { | |
405 ati_src_tst_sendString(src_infos->data_buffer.data_list, src_infos->srcId); | |
406 } | |
407 else | |
408 { | |
409 psaDTI_data_req (src_infos->data_buffer.data_list, src_infos, DTI_ENTITY_UART); | |
410 } | |
411 } | |
412 } | |
413 #else | |
414 psaDTI_data_req (src_infos->data_buffer.data_list, src_infos, DTI_ENTITY_UART); | |
415 #endif /* _SIMULATION_ */ | |
416 #endif /* DTI */ | |
417 src_infos->data_buffer.data_list = NULL; | |
418 src_infos->data_buffer.max_buffer_size = 0; | |
419 src_infos->data_buffer.create_time = 0; | |
420 } | |
421 | |
422 /* this is wrong here, moved to ati_src_uart.c */ | |
423 /* | |
424 if (uartShrdPrm.dtr_clearcall EQ TRUE) | |
425 { | |
426 T_ACI_RETURN ret; | |
427 | |
428 ret = sAT_H(src_infos->srcId); | |
429 if (ret != AT_EXCT && ret != AT_CMPL) | |
430 { | |
431 uartShrdPrm.dtr_clearcall = FALSE; | |
432 TRACE_ERROR("sAT_H() error"); | |
433 } | |
434 } | |
435 */ | |
436 } | |
437 | |
438 | |
439 LOCAL T_desc2 *make_send_data (UBYTE *data, USHORT data_len, | |
440 T_ATI_OUTPUT_TYPE output_type) | |
441 { | |
442 T_desc2 *send_data; | |
443 USHORT send_len = 0; | |
444 #if !defined (_SIMULATION_) OR defined(ACIDTI_TEST_SIM) | |
445 static UBYTE formated_output[MAX_CMD_LEN+5]; | |
446 USHORT formated_len; | |
447 | |
448 formated_len = format_output (data, data_len, formated_output, output_type); | |
449 send_len = sizeof(T_desc2) - 1 + formated_len; | |
450 | |
451 ACI_MALLOC(send_data, send_len); | |
452 send_data->next = (ULONG)NULL; | |
453 send_data->len = formated_len; | |
454 send_data->size = formated_len; | |
455 send_data->offset = 0; | |
456 memcpy(send_data->buffer, formated_output, formated_len); | |
457 | |
458 #else /* _SIMULATION_ */ | |
459 | |
460 send_len = sizeof(T_desc2) - 1 + data_len; | |
461 | |
462 ACI_MALLOC(send_data, send_len); | |
463 send_data->next = (ULONG)NULL; | |
464 send_data->len = data_len; | |
465 send_data->size = data_len; | |
466 send_data->offset = 0; | |
467 memcpy(send_data->buffer, data, data_len); | |
468 | |
469 #endif /* _SIMULATION_ */ | |
470 | |
471 return (send_data); | |
472 } | |
473 | |
474 | |
475 /* | |
476 +-------------------------------------------------------------------+ | |
477 | PROJECT : GSM-PS (6147) MODULE : CMH_DTIS | | |
478 | ROUTINE : io_DTIsendString | | |
479 +-------------------------------------------------------------------+ | |
480 | |
481 PURPOSE : format output string and send to the UART through DTI | |
482 */ | |
483 | |
484 LOCAL void io_DTIsendString (UBYTE *string, USHORT string_len, | |
485 T_ACI_DTI_PRC *src_infos, | |
486 T_ATI_OUTPUT_TYPE output_type) | |
487 { | |
488 T_desc2 *send_data; | |
489 #ifdef _SIMULATION_ | |
490 T_ATI_SRC_TYPE src_type; | |
491 | |
492 /* | |
493 * get_source_type() writes an trace_event in the error case. | |
494 */ | |
495 if(!get_source_type(src_infos->srcId, &src_type)) | |
496 return; | |
497 #endif /* _SIMULATION_ */ | |
498 | |
499 TRACE_FUNCTION("io_DTIsendString"); | |
500 if (!IS_ECHO_OUTPUT (output_type)) | |
501 { | |
502 #ifdef _SIMULATION_ | |
503 if( ATI_SRC_TYPE_TST NEQ src_type ) | |
504 #endif /* _SIMULATION_ */ | |
505 { | |
506 trace_cmd_line ("OUT:", (CHAR*)string, src_infos->srcId, string_len); | |
507 } | |
508 } | |
509 | |
510 if (string_len > MAX_LARGE_BUFFER_LEN) | |
511 { | |
512 TRACE_ERROR ("String too large for io_DTIsendString!"); | |
513 TRACE_EVENT_P2 ("Truncating string from %d to %d", string_len, MAX_LARGE_BUFFER_LEN); | |
514 string_len = MAX_LARGE_BUFFER_LEN; | |
515 } | |
516 | |
517 send_data = make_send_data (string, string_len, output_type); | |
518 | |
519 #ifdef DTI | |
520 if ((aci_src_dti_params[src_infos->srcId].isDtiConnected) AND | |
521 (aci_src_dti_params[src_infos->srcId].dtxState EQ READY)) | |
522 { | |
523 #ifdef _SIMULATION_ | |
524 if( ATI_SRC_TYPE_TST EQ src_type ) | |
525 { | |
526 ati_src_tst_sendString(send_data, src_infos->srcId); | |
527 ACI_MFREE(send_data); | |
528 } | |
529 else | |
530 { | |
531 psaDTI_data_req (send_data, src_infos, DTI_ENTITY_UART); | |
532 } | |
533 #else | |
534 /* send message through DTI */ | |
535 psaDTI_data_req (send_data, src_infos, DTI_ENTITY_UART); | |
536 #endif /* _SIMULATION_ */ | |
537 } | |
538 else | |
539 { | |
540 /* buffer these datas */ | |
541 uart_buffer_data (src_infos, send_data); | |
542 ACI_MFREE (send_data); | |
543 } | |
544 #else | |
545 ACI_MFREE (send_data); | |
546 #endif /* DTI */ | |
547 } | |
548 | |
549 #ifdef _SIMULATION_ | |
550 | |
551 /* | |
552 +-------------------------------------------------------------------+ | |
553 | PROJECT : GSM-PS (6147) MODULE : ATI_SRC_UART_IO_C | | |
554 | ROUTINE : get_source_type | | |
555 +-------------------------------------------------------------------+ | |
556 | |
557 PURPOSE : provides the source type for a source ID | |
558 | |
559 returns FALSE if source ID is not registered | |
560 */ | |
561 LOCAL BOOL get_source_type( UBYTE src_id, T_ATI_SRC_TYPE *src_type ) | |
562 { | |
563 T_ATI_SRC_PARAMS *src_params = NULL; | |
564 | |
565 src_params = find_element (ati_src_list, src_id, search_ati_src_id); | |
566 if (src_params EQ NULL) | |
567 { | |
568 TRACE_EVENT_P1("[ERR] get_source_type: source ID %d not found", src_id); | |
569 *src_type = ATI_SRC_TYPE_UNKNOWN; | |
570 return FALSE; | |
571 } | |
572 | |
573 *src_type = src_params->src_type; | |
574 return TRUE; | |
575 } | |
576 | |
577 /* | |
578 +--------------------------------------------------------------------+ | |
579 | PROJECT : GSM-PS (6147) MODULE : ATI_SRC_UART_IO_C | | |
580 | ROUTINE : uart_src_test_sendString | | |
581 +--------------------------------------------------------------------+ | |
582 | |
583 PURPOSE : Provides the io_DTIsendString() for the test-source-callback | |
584 and apends a separator to the message. | |
585 The separator is needed to isolates the messages in the | |
586 case of buffering messages during UART is not connected | |
587 with ACI | |
588 */ | |
589 GLOBAL void uart_src_test_sendString (UBYTE *string, USHORT string_len, | |
590 T_ACI_DTI_PRC *src_infos, | |
591 T_ATI_OUTPUT_TYPE output_type) | |
592 { | |
593 UBYTE *tmp; | |
594 | |
595 ACI_MALLOC(tmp, string_len + 1); | |
596 strncpy(tmp, string, string_len); | |
597 tmp[string_len] = (UBYTE) ATI_TEST_SRC_SEPARATOR; | |
598 | |
599 io_DTIsendString(tmp, (USHORT) (string_len + 1), src_infos, output_type); | |
600 | |
601 ACI_MFREE(tmp); | |
602 } | |
603 #endif | |
604 | |
605 #endif /* UART */ |