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