FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/g23m-aci/aci/cmh_uartf.c @ 775:eedbf248bac0
gsm-fw/g23m-aci subtree: initial import from LoCosto source
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 12 Oct 2014 01:45:14 +0000 |
parents | |
children | c64bfc13292c |
comparison
equal
deleted
inserted
replaced
774:40a721fd9854 | 775:eedbf248bac0 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : GSM-PS (6147) | |
4 | Modul : CMH_UARTF | |
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 : This module defines the functions used by the command | |
18 | handler for the UART module. | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 | |
22 #ifdef UART | |
23 | |
24 #ifndef CMH_UARTF_C | |
25 #define CMH_UARTF_C | |
26 #endif | |
27 | |
28 #include "aci_all.h" | |
29 /*==== INCLUDES ===================================================*/ | |
30 #include "aci_cmh.h" | |
31 #include "ati_cmd.h" | |
32 #include "aci_cmd.h" | |
33 #include "dti.h" /* functionality of the dti library */ | |
34 | |
35 #include "aci_lst.h" | |
36 | |
37 #include "dti_conn_mng.h" | |
38 #include "psa_uart.h" | |
39 #include "cmh_uart.h" | |
40 #include "aci_mem.h" | |
41 | |
42 /* | |
43 +--------------------------------------------------------------------+ | |
44 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
45 | STATE : code ROUTINE : cmhUARTtest_srcId | | |
46 +--------------------------------------------------------------------+ | |
47 | |
48 PURPOSE : search function for source Id in the structure T_ACI_DTI_PRC. | |
49 | |
50 */ | |
51 | |
52 GLOBAL BOOL cmhUARTtest_srcId( UBYTE srcId, void *elem) | |
53 { | |
54 T_ACI_DTI_PRC *compared = (T_ACI_DTI_PRC *)elem; | |
55 | |
56 if (compared -> srcId EQ srcId ) | |
57 return TRUE; | |
58 else | |
59 return FALSE; | |
60 } | |
61 | |
62 /* | |
63 +--------------------------------------------------------------------+ | |
64 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
65 | STATE : code ROUTINE : cmhUARTtest_device | | |
66 +--------------------------------------------------------------------+ | |
67 | |
68 PURPOSE : search function for device number in the structure T_ACI_DTI_PRC. | |
69 | |
70 */ | |
71 | |
72 GLOBAL BOOL cmhUARTtest_device (UBYTE device, void *elem) | |
73 { | |
74 T_ACI_DTI_PRC *compared = (T_ACI_DTI_PRC *)elem; | |
75 | |
76 if (compared -> device EQ device ) | |
77 return TRUE; | |
78 else | |
79 return FALSE; | |
80 } | |
81 | |
82 /* | |
83 +--------------------------------------------------------------------+ | |
84 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
85 | STATE : code ROUTINE : cmhUART_find_dlci | | |
86 +--------------------------------------------------------------------+ | |
87 | |
88 PURPOSE : returns element with corresponding dlci and device. | |
89 | |
90 If called dlci=UART_DLCI_NOT_MULTIPLEXED (UART entity | |
91 value for device not multiplexed) then function returns | |
92 element with corresponding device... | |
93 | |
94 */ | |
95 GLOBAL T_ACI_DTI_PRC *cmhUART_find_dlci (T_ACI_LIST *search_list, | |
96 UBYTE device, UBYTE dlci) | |
97 { | |
98 T_ACI_DTI_PRC *content = NULL; | |
99 | |
100 if (search_list EQ NULL) | |
101 return NULL; | |
102 | |
103 do | |
104 { | |
105 content = find_next_element (search_list, content, device, | |
106 cmhUARTtest_device); | |
107 if (content EQ NULL) | |
108 return NULL; | |
109 | |
110 if( dlci EQ UART_DLCI_NOT_MULTIPLEXED OR | |
111 content->dlci EQ UART_DLCI_NOT_MULTIPLEXED OR | |
112 content->dlci EQ dlci) | |
113 return content; | |
114 } | |
115 while (content NEQ NULL); | |
116 | |
117 return NULL; | |
118 } | |
119 | |
120 /* | |
121 +--------------------------------------------------------------------+ | |
122 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
123 | STATE : code ROUTINE : cmhUART_erase_elem_received_cmd | | |
124 +--------------------------------------------------------------------+ | |
125 | |
126 PURPOSE : erase an entry element from the uart_src_params list. | |
127 | |
128 */ | |
129 | |
130 GLOBAL void cmhUART_erase_elem_received_cmd (UBYTE srcId) | |
131 { | |
132 T_ACI_DTI_PRC *content; | |
133 | |
134 /* find element to be erased */ | |
135 content = remove_element (uart_src_params, (UBYTE)srcId, cmhUARTtest_srcId); | |
136 | |
137 ACI_MFREE (content); | |
138 } | |
139 | |
140 /********************************************************* | |
141 ////////////////////////////////////////////////////////// | |
142 TEMP: rests from aci_urt.c | |
143 | |
144 ready for remove? */ | |
145 | |
146 GLOBAL BOOL atiViaTif = FALSE; | |
147 | |
148 /******************************************************** | |
149 ///////////////////////////////////////////////////////// */ | |
150 | |
151 /* | |
152 +--------------------------------------------------------------------+ | |
153 | PROJECT : GSM-F&D (8411) MODULE : ACI_URT | | |
154 | STATE : code ROUTINE : urt_init | | |
155 +--------------------------------------------------------------------+ | |
156 | |
157 PURPOSE : initialize the module and the UART | |
158 | |
159 */ | |
160 | |
161 GLOBAL void urt_init (void) | |
162 { | |
163 TRACE_FUNCTION ("urt_init()"); | |
164 | |
165 } | |
166 | |
167 /* | |
168 +--------------------------------------------------------------------------------------------+ | |
169 | PROJECT : GSM-F&D (8411) MODULE : ACI_URT | | |
170 | STATE : code ROUTINE : cmhUART_translateBD_RATE_to_UART_IO_SPEED | | |
171 +--------------------------------------------------------------------------------------------+ | |
172 | |
173 PURPOSE: | |
174 */ | |
175 | |
176 LOCAL UBYTE cmhUART_translateBD_RATE_to_UART_IO_SPEED ( T_ACI_BD_RATE rate ) | |
177 { | |
178 | |
179 switch ( rate ) | |
180 { | |
181 case BD_RATE_AUTO: return UART_IO_SPEED_AUTO; | |
182 case BD_RATE_75: return UART_IO_SPEED_75; | |
183 case BD_RATE_150: return UART_IO_SPEED_150; | |
184 case BD_RATE_300: return UART_IO_SPEED_300; | |
185 case BD_RATE_600: return UART_IO_SPEED_600; | |
186 case BD_RATE_1200: return UART_IO_SPEED_1200; | |
187 case BD_RATE_2400: return UART_IO_SPEED_2400; | |
188 case BD_RATE_4800: return UART_IO_SPEED_4800; | |
189 case BD_RATE_7200: return UART_IO_SPEED_7200; | |
190 case BD_RATE_9600: return UART_IO_SPEED_9600; | |
191 case BD_RATE_14400: return UART_IO_SPEED_14400; | |
192 case BD_RATE_19200: return UART_IO_SPEED_19200; | |
193 case BD_RATE_28800: return UART_IO_SPEED_28800; | |
194 case BD_RATE_33900: return UART_IO_SPEED_33900; | |
195 case BD_RATE_38400: return UART_IO_SPEED_38400; | |
196 case BD_RATE_57600: return UART_IO_SPEED_57600; | |
197 case BD_RATE_115200: return UART_IO_SPEED_115200; | |
198 case BD_RATE_203125: return UART_IO_SPEED_203125; | |
199 case BD_RATE_406250: return UART_IO_SPEED_406250; | |
200 case BD_RATE_812500: return UART_IO_SPEED_812500; | |
201 default: return UART_IO_SPEED_UNDEF; | |
202 } | |
203 } | |
204 | |
205 /* | |
206 +-----------------------------------------------------------------------------+ | |
207 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
208 | STATE : code ROUTINE : cmhUART_comParFindDevice | | |
209 +-----------------------------------------------------------------------------+ | |
210 | |
211 PURPOSE: Finding the device entry in the 'uart_com_par' table | |
212 | |
213 */ | |
214 LOCAL BOOL cmhUART_comParFindDevice (UBYTE criterium, void *elem) | |
215 { | |
216 if ( criterium EQ ((T_ACI_DEVICE_ENTRY*)elem)->device ) | |
217 return TRUE; | |
218 | |
219 return FALSE; | |
220 } | |
221 | |
222 /* | |
223 +-----------------------------------------------------------------------------+ | |
224 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
225 | STATE : code ROUTINE : cmhUART_FindAll | | |
226 +-----------------------------------------------------------------------------+ | |
227 | |
228 PURPOSE: Find every entry | |
229 | |
230 */ | |
231 LOCAL BOOL cmhUART_FindAll (UBYTE criterium, void *elem) | |
232 { | |
233 return TRUE; | |
234 } | |
235 | |
236 LOCAL T_ACI_UART_COM_PAR cmhUART_getDefaultUARTParameter(void) | |
237 { | |
238 T_ACI_UART_COM_PAR comPar = | |
239 { | |
240 UART_IO_SPEED_115200, | |
241 UART_IO_BPC_8, | |
242 UART_IO_SB_1, | |
243 UART_IO_PA_NONE, | |
244 UART_IO_FC_RX_RTS, | |
245 UART_IO_FC_TX_RTS, | |
246 UART_IO_XON_VALID, | |
247 UART_IO_XON_DEFAULT, | |
248 UART_IO_XOFF_VALID, | |
249 UART_IO_XOFF_DEFAULT, | |
250 }; | |
251 | |
252 return comPar; | |
253 } | |
254 /* | |
255 +----------------------------------------------------------------------------------+ | |
256 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
257 | STATE : code ROUTINE : cmhUART_AddDeviceToComParameter | | |
258 +----------------------------------------------------------------------------------+ | |
259 | |
260 PURPOSE: add COM parameter for a new device | |
261 | |
262 */ | |
263 GLOBAL void cmhUART_AddDeviceToComParameter( UBYTE device ) | |
264 { | |
265 T_ACI_DEVICE_ENTRY *device_entry; | |
266 | |
267 TRACE_FUNCTION("cmhUART_AddDeviceToComParameter"); | |
268 | |
269 /* | |
270 * try to find the device | |
271 */ | |
272 device_entry = find_element(uart_com_par, device, cmhUART_comParFindDevice); | |
273 | |
274 /* | |
275 * if the device is new add it to the list | |
276 */ | |
277 if ( device_entry EQ NULL ) | |
278 { | |
279 ACI_MALLOC (device_entry, sizeof (T_ACI_DEVICE_ENTRY)); | |
280 | |
281 device_entry->device = device; | |
282 /* | |
283 * Default values by adding a new device | |
284 */ | |
285 device_entry->comPar = cmhUART_getDefaultUARTParameter(); | |
286 | |
287 insert_list (uart_com_par, device_entry); | |
288 } | |
289 } | |
290 | |
291 /* | |
292 +---------------------------------------------------------------------------------------+ | |
293 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
294 | STATE : code ROUTINE : cmhUART_RemoveDeviceFromComParameter | | |
295 +---------------------------------------------------------------------------------------+ | |
296 | |
297 PURPOSE: remove COM parameter for a device from 'uart_com_par' table | |
298 | |
299 */ | |
300 GLOBAL void cmhUART_RemoveDeviceFromComParameter( UBYTE device ) | |
301 { | |
302 T_ACI_DEVICE_ENTRY *device_entry; | |
303 | |
304 TRACE_FUNCTION("cmhUART_RemoveDeviceFromComParameter"); | |
305 | |
306 /* | |
307 * Find the device and remove it. | |
308 */ | |
309 device_entry = remove_element(uart_com_par, device, cmhUART_comParFindDevice); | |
310 | |
311 if ( device_entry NEQ NULL ) | |
312 { | |
313 ACI_MFREE ( device_entry ); | |
314 } | |
315 } | |
316 | |
317 /* | |
318 +---------------------------------------------------------------------------------------+ | |
319 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
320 | STATE : code ROUTINE : cmhUART_RemoveDeviceFromComParameter | | |
321 +---------------------------------------------------------------------------------------+ | |
322 | |
323 PURPOSE: clean the 'uart_com_par' table | |
324 | |
325 */ | |
326 GLOBAL void cmhUART_CleanComParameterList( void ) | |
327 { | |
328 T_ACI_DEVICE_ENTRY *device_entry; | |
329 | |
330 TRACE_FUNCTION("cmhUART_CleanComParameterList"); | |
331 | |
332 /* | |
333 * Find the device and remove it. | |
334 */ | |
335 while ( NULL NEQ (device_entry = remove_element(uart_com_par, 0, cmhUART_FindAll)) ) | |
336 { | |
337 ACI_MFREE ( device_entry ); | |
338 } | |
339 } | |
340 | |
341 /* | |
342 +---------------------------------------------------------------------------------+ | |
343 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
344 | STATE : code ROUTINE : cmhUART_GetDeviceParOverDevice | | |
345 +---------------------------------------------------------------------------------+ | |
346 | |
347 PURPOSE: returns the COM parameter for this device | |
348 | |
349 */ | |
350 GLOBAL T_ACI_DEVICE_ENTRY* cmhUART_GetDeviceParOverDevice( UBYTE device ) | |
351 { | |
352 T_ACI_DEVICE_ENTRY *device_entry; | |
353 | |
354 TRACE_FUNCTION("cmhUART_GetDeviceParOverDevice"); | |
355 | |
356 /* | |
357 * return COM parameter for device | |
358 */ | |
359 device_entry = find_element(uart_com_par, device, cmhUART_comParFindDevice); | |
360 | |
361 if ( device_entry EQ NULL ) | |
362 { | |
363 TRACE_EVENT_P1("[ERR] cmhUART_GetDeviceParOverDevice: device=%d not found", device) ; | |
364 return NULL; | |
365 } | |
366 | |
367 return device_entry; | |
368 } | |
369 | |
370 /* | |
371 +---------------------------------------------------------------------------------+ | |
372 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
373 | STATE : code ROUTINE : cmhUART_GetDeviceParOverDevice | | |
374 +---------------------------------------------------------------------------------+ | |
375 | |
376 PURPOSE: | |
377 | |
378 */ | |
379 GLOBAL T_ACI_DEVICE_TYPE cmhUART_GetDeviceType( UBYTE srcId ) | |
380 { | |
381 T_ACI_DTI_PRC *src_infos; | |
382 | |
383 TRACE_FUNCTION("cmhUART_GetDeviceType"); | |
384 | |
385 src_infos = find_element (uart_src_params, (UBYTE)srcId, cmhUARTtest_srcId); | |
386 | |
387 if (src_infos NEQ NULL) | |
388 { | |
389 return src_infos->device_type; | |
390 } | |
391 else | |
392 { | |
393 return DEVICE_TYPE_UNKNOWN; | |
394 } | |
395 } | |
396 | |
397 /* | |
398 +---------------------------------------------------------------------------------+ | |
399 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
400 | STATE : code ROUTINE : cmhUART_ChangeDeviceParOverDevice | | |
401 +---------------------------------------------------------------------------------+ | |
402 | |
403 PURPOSE: | |
404 | |
405 */ | |
406 GLOBAL BOOL cmhUART_ChangeDeviceType( UBYTE srcId, | |
407 T_ACI_DEVICE_TYPE device_type ) | |
408 { | |
409 T_ACI_DTI_PRC *src_infos; | |
410 | |
411 TRACE_FUNCTION("cmhUART_ChangeDeviceType"); | |
412 | |
413 src_infos = find_element (uart_src_params, (UBYTE)srcId, cmhUARTtest_srcId); | |
414 | |
415 if (src_infos NEQ NULL) | |
416 { | |
417 src_infos->device_type = device_type; | |
418 | |
419 switch (device_type) | |
420 { | |
421 case DEVICE_TYPE_UNKNOWN: | |
422 TRACE_EVENT_P1("Device type of src %u is DEVICE_TYPE_UNKNOWN", srcId); | |
423 break; | |
424 case DEVICE_TYPE_URT: | |
425 TRACE_EVENT_P1("Device type of src %u is DEVICE_TYPE_URT", srcId); | |
426 break; | |
427 case DEVICE_TYPE_MUX: | |
428 TRACE_EVENT_P1("Device type of src %u is DEVICE_TYPE_MUX", srcId); | |
429 break; | |
430 default: | |
431 TRACE_EVENT_P1("Device type of src %u has invalid value", srcId); | |
432 break; | |
433 } | |
434 | |
435 return TRUE; | |
436 } | |
437 else | |
438 { | |
439 return FALSE; | |
440 } | |
441 } | |
442 | |
443 /* | |
444 +---------------------------------------------------------------------------------+ | |
445 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
446 | STATE : code ROUTINE : cmhUART_GetDeviceParOverSrcID | | |
447 +---------------------------------------------------------------------------------+ | |
448 | |
449 PURPOSE: returns the COM parameter for this source ID | |
450 | |
451 */ | |
452 GLOBAL T_ACI_DEVICE_ENTRY* cmhUART_GetDeviceParOverSrcID( UBYTE srcId ) | |
453 { | |
454 T_ACI_DEVICE_ENTRY *device_entry; | |
455 T_ACI_DTI_PRC *cmd_struct; | |
456 | |
457 TRACE_FUNCTION("cmhUART_GetDeviceParOverSrcID()"); | |
458 | |
459 if( !ati_is_src_type(srcId, ATI_SRC_TYPE_UART) ) | |
460 { | |
461 /* not a UART source */ | |
462 return(NULL); | |
463 } | |
464 | |
465 /* | |
466 * find the device connected to this source ID | |
467 */ | |
468 cmd_struct = find_element (uart_src_params, srcId, cmhUARTtest_srcId); | |
469 | |
470 if (cmd_struct EQ NULL) | |
471 { | |
472 TRACE_EVENT_P1("[ERR] cmhUART_GetDeviceParOverSrcID: srcId=%d not found", srcId) ; | |
473 return NULL; | |
474 } | |
475 | |
476 /* | |
477 * return COM parameter for device | |
478 */ | |
479 device_entry = find_element(uart_com_par, cmd_struct->device, cmhUART_comParFindDevice); | |
480 | |
481 if ( device_entry EQ NULL ) | |
482 { | |
483 TRACE_EVENT_P1("[ERR] cmhUART_GetDeviceParOverSrcID: device=%d not found", cmd_struct->device) ; | |
484 return NULL; | |
485 } | |
486 | |
487 return device_entry; | |
488 } | |
489 | |
490 GLOBAL UBYTE cmhUART_GetParityOverSrcID( UBYTE srcId ) | |
491 { | |
492 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( (UBYTE) srcId ); | |
493 | |
494 if ( device_entry EQ NULL ) | |
495 { | |
496 return cmhUART_getDefaultUARTParameter().parity; | |
497 } | |
498 | |
499 return device_entry->comPar.parity; | |
500 } | |
501 | |
502 GLOBAL UBYTE cmhUART_GetDataBitOverSrcID( UBYTE srcId ) | |
503 { | |
504 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( (UBYTE) srcId ); | |
505 | |
506 if ( device_entry EQ NULL ) | |
507 { | |
508 return cmhUART_getDefaultUARTParameter().bpc; | |
509 } | |
510 | |
511 return device_entry->comPar.bpc; | |
512 } | |
513 | |
514 GLOBAL UBYTE cmhUART_GetStopBitOverSrcID( UBYTE srcId ) | |
515 { | |
516 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( (UBYTE) srcId ); | |
517 | |
518 if ( device_entry EQ NULL ) | |
519 { | |
520 return cmhUART_getDefaultUARTParameter().nsb; | |
521 } | |
522 | |
523 return device_entry->comPar.nsb; | |
524 } | |
525 | |
526 /* | |
527 +------------------------------------------------------------------------------+ | |
528 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
529 | STATE : code ROUTINE : cmhUART_SetComParToUnchanged | | |
530 +------------------------------------------------------------------------------+ | |
531 | |
532 PURPOSE: set the UART COM parameter to unchanged | |
533 | |
534 */ | |
535 GLOBAL void cmhUART_SetComParToUnchanged( T_comPar *comPar ) | |
536 { | |
537 comPar->speed = UART_IO_SPEED_UNDEF; /* baud rate */ | |
538 comPar->bpc = UART_IO_BPC_UNDEF; /* bits per character */ | |
539 comPar->nsb = UART_IO_SB_UNDEF; /* stop bits */ | |
540 comPar->parity = UART_IO_PA_UNDEF; /* parity of serial link */ | |
541 comPar->flow_rx = UART_IO_FC_RX_UNDEF; /* flow control mode RX */ | |
542 comPar->flow_tx = UART_IO_FC_TX_UNDEF; /* flow control mode TX */ | |
543 comPar->xon_valid = UART_IO_XON_UNDEF; /* indicator whether xon is valid */ | |
544 comPar->xoff_valid = UART_IO_XOFF_UNDEF; /* indicator whether xoff is valid */ | |
545 | |
546 comPar->xon = UART_IO_XON_DEFAULT; | |
547 comPar->xoff = UART_IO_XOFF_DEFAULT; | |
548 | |
549 /* | |
550 * Set escape parameters | |
551 */ | |
552 comPar->esc_valid = UART_IO_ESC_VALID; | |
553 comPar->esc_char = UART_IO_ESC_CHAR_DEFAULT; | |
554 comPar->esc_gp = UART_IO_ESC_GP_DEFAULT; | |
555 } | |
556 | |
557 /* | |
558 +------------------------------------------------------------------------------+ | |
559 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
560 | STATE : code ROUTINE : cmhUART_SetDataRate | | |
561 +------------------------------------------------------------------------------+ | |
562 | |
563 PURPOSE: set the UART data rate | |
564 | |
565 */ | |
566 GLOBAL T_ACI_RETURN cmhUART_SetDataRate ( UBYTE srcId, T_ACI_BD_RATE rate) | |
567 { | |
568 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( srcId ); | |
569 T_comPar newComPar; | |
570 | |
571 if ( device_entry EQ NULL ) | |
572 { | |
573 TRACE_EVENT_P1("[ERR] cmhUART_SetDataRate: device for source ID = %d not found", srcId); | |
574 return AT_FAIL; | |
575 } | |
576 | |
577 cmhUART_SetComParToUnchanged( &newComPar ); | |
578 | |
579 device_entry->comPar.speed = newComPar.speed = cmhUART_translateBD_RATE_to_UART_IO_SPEED( rate ); | |
580 | |
581 psaUART_SetParameters(device_entry->device, &newComPar); | |
582 | |
583 return AT_EXCT; | |
584 } | |
585 | |
586 /* | |
587 +------------------------------------------------------------------------------+ | |
588 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
589 | STATE : code ROUTINE : cmhUART_SetCharacterFraming | | |
590 +------------------------------------------------------------------------------+ | |
591 | |
592 PURPOSE: set the UART character framing | |
593 | |
594 */ | |
595 GLOBAL T_ACI_RETURN cmhUART_SetCharacterFraming ( UBYTE srcId, | |
596 T_ACI_BS_FRM format, | |
597 T_ACI_BS_PAR parity ) | |
598 { | |
599 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( srcId ); | |
600 T_comPar comPar; | |
601 | |
602 if ( device_entry EQ NULL ) | |
603 { | |
604 TRACE_EVENT_P1("[ERR] cmhUART_SetCharacterFraming: device for source ID = %d not found", srcId); | |
605 return AT_FAIL; | |
606 } | |
607 | |
608 cmhUART_SetComParToUnchanged( &comPar ); | |
609 | |
610 /* | |
611 * translate AT command parameter to UART parameter | |
612 */ | |
613 if ( format NEQ BS_FRM_NotPresent ) | |
614 { | |
615 if ( format & 4 ) | |
616 { | |
617 device_entry->comPar.bpc = comPar.bpc = UART_IO_BPC_7; | |
618 format++; | |
619 } | |
620 else | |
621 { | |
622 device_entry->comPar.bpc = comPar.bpc = UART_IO_BPC_8; | |
623 } | |
624 | |
625 device_entry->comPar.nsb = comPar.nsb = format & 2 ? UART_IO_SB_1 : UART_IO_SB_2; | |
626 | |
627 if ( format & 1 ) | |
628 { | |
629 device_entry->comPar.parity = comPar.parity = UART_IO_PA_NONE; | |
630 parity = BS_PAR_NotPresent; | |
631 } | |
632 else | |
633 { | |
634 if ( parity EQ BS_PAR_NotPresent ) | |
635 { | |
636 if ( device_entry->comPar.parity NEQ UART_IO_PA_NONE ) | |
637 { | |
638 if ( device_entry->comPar.parity EQ NOT_SUPPORTED_UART_IO_PA_MARK ) | |
639 { | |
640 comPar.parity = UART_IO_PA_NONE; | |
641 comPar.nsb = UART_IO_SB_2; | |
642 } | |
643 else | |
644 { | |
645 comPar.parity = device_entry->comPar.parity; | |
646 } | |
647 } | |
648 else | |
649 { | |
650 /* the type of parity is not defined */ | |
651 return AT_FAIL; | |
652 } | |
653 } | |
654 } | |
655 } | |
656 | |
657 switch (parity) | |
658 { | |
659 case BS_PAR_NotPresent: | |
660 /* this case is handled by format translation */ | |
661 break; | |
662 case BS_PAR_Odd: | |
663 device_entry->comPar.parity = comPar.parity = UART_IO_PA_ODD; | |
664 break; | |
665 case BS_PAR_Even: | |
666 device_entry->comPar.parity = comPar.parity = UART_IO_PA_EVEN; | |
667 break; | |
668 case BS_PAR_Mark: | |
669 /* | |
670 * parity mark is not supported by the UART SAP, | |
671 * but it is the same as no parity and 2 stop bit | |
672 */ | |
673 device_entry->comPar.parity = NOT_SUPPORTED_UART_IO_PA_MARK; | |
674 comPar.parity = UART_IO_PA_NONE; | |
675 comPar.nsb = UART_IO_SB_2; | |
676 break; | |
677 case BS_PAR_Space: | |
678 device_entry->comPar.parity = comPar.parity = UART_IO_PA_SPACE; | |
679 break; | |
680 } | |
681 | |
682 psaUART_SetParameters(device_entry->device, &comPar); | |
683 | |
684 return AT_EXCT; | |
685 } | |
686 | |
687 /* | |
688 +------------------------------------------------------------------------------+ | |
689 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
690 | STATE : code ROUTINE : cmhUART_SetFlowControl | | |
691 +------------------------------------------------------------------------------+ | |
692 | |
693 PURPOSE: set the UART flow control | |
694 | |
695 */ | |
696 GLOBAL T_ACI_RETURN cmhUART_SetFlowControl(UBYTE srcId, T_ACI_RX_FLOW_CTRL DCE_by_DTE) | |
697 { | |
698 T_ACI_DEVICE_ENTRY *device_entry = cmhUART_GetDeviceParOverSrcID( srcId ); | |
699 T_comPar comPar; | |
700 | |
701 if ( device_entry EQ NULL ) | |
702 { | |
703 TRACE_EVENT_P1("[ERR] cmhUART_SetFlowControl: device for source ID = %d not found", srcId); | |
704 return AT_FAIL; | |
705 } | |
706 | |
707 cmhUART_SetComParToUnchanged( &comPar ); | |
708 | |
709 /* | |
710 * translate AT command parameter to UART parameter | |
711 */ | |
712 switch ( DCE_by_DTE ) | |
713 { | |
714 case RX_FLOW_NONE: | |
715 comPar.flow_rx = UART_IO_FC_RX_NONE; | |
716 comPar.flow_tx = UART_IO_FC_TX_NONE; | |
717 break; | |
718 case RX_FLOW_SOFTWARE: | |
719 comPar.flow_rx = UART_IO_FC_RX_XOFF; | |
720 comPar.flow_tx = UART_IO_FC_TX_XOFF; | |
721 break; | |
722 case RX_FLOW_HARDWARE: | |
723 comPar.flow_rx = UART_IO_FC_RX_RTS; | |
724 comPar.flow_tx = UART_IO_FC_TX_RTS; | |
725 break; | |
726 case RX_FLOW_NotPresent: | |
727 return AT_CMPL; | |
728 } | |
729 | |
730 device_entry->comPar.flow_rx = comPar.flow_rx; | |
731 device_entry->comPar.flow_tx = comPar.flow_tx; | |
732 | |
733 psaUART_SetParameters(device_entry->device, &comPar); | |
734 | |
735 return AT_EXCT; | |
736 } | |
737 | |
738 /* | |
739 +--------------------------------------------------------------------------------+ | |
740 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
741 | STATE : code ROUTINE : cmhUART_GetFktInterfaceFormat | | |
742 +--------------------------------------------------------------------------------+ | |
743 | |
744 PURPOSE: translate the UART COM parameter to the AT command format parameter | |
745 | |
746 ATTENTION: internal function, COM paramter is is not checking of validity | |
747 | |
748 */ | |
749 GLOBAL T_ACI_BS_FRM cmhUART_GetFktInterfaceFormat( T_ACI_UART_COM_PAR *comPar ) | |
750 { | |
751 UBYTE format = 1; /* 8 Data 2 Stop */ | |
752 | |
753 if ( comPar->bpc EQ UART_IO_BPC_7 ) | |
754 format += 3; | |
755 | |
756 if ( comPar->nsb NEQ UART_IO_SB_2 ) | |
757 format += 2; | |
758 | |
759 if ( comPar->parity NEQ UART_IO_PA_NONE ) | |
760 format -= 1; | |
761 | |
762 return (T_ACI_BS_FRM) format; | |
763 } | |
764 | |
765 /* | |
766 +--------------------------------------------------------------------------------+ | |
767 | PROJECT : GSM-PS (6147) MODULE : CMH_UART | | |
768 | STATE : code ROUTINE : cmhUART_GetFktInterfaceParity | | |
769 +--------------------------------------------------------------------------------+ | |
770 | |
771 PURPOSE: translate the UART COM parameter to the AT command parity parameter | |
772 | |
773 ATTENTION: internal function, COM paramter is is not checking of validity | |
774 | |
775 */ | |
776 GLOBAL T_ACI_BS_PAR cmhUART_GetFktInterfaceParity( T_ACI_UART_COM_PAR *comPar ) | |
777 { | |
778 switch ( comPar->parity ) | |
779 { | |
780 case UART_IO_PA_ODD: | |
781 return (T_ACI_BS_PAR) BS_PAR_Odd; | |
782 case UART_IO_PA_EVEN: | |
783 return (T_ACI_BS_PAR) BS_PAR_Even; | |
784 case NOT_SUPPORTED_UART_IO_PA_MARK: | |
785 return (T_ACI_BS_PAR) BS_PAR_Mark; | |
786 case UART_IO_PA_SPACE: | |
787 return (T_ACI_BS_PAR) BS_PAR_Space; | |
788 } | |
789 return BS_PAR_NotPresent; | |
790 } | |
791 #endif /* UART */ |