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